aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-01-10 19:04:53 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-10 19:04:53 -0500
commit949f6711b83d2809d1ccb9d830155a65fdacdff9 (patch)
tree4b8bdb0e98489bc8ad77fa144926931c37e2e4f2
parent443e6221e465efa8efb752a8405a759ef1161af9 (diff)
parent7959d55679e4360205c9ebc89d40a5503c53bae2 (diff)
Merge branch 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
* 'staging-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6: (510 commits) staging: speakup: fix failure handling staging: usbip: remove double giveback of URB Staging: batman-adv: Remove batman-adv from staging Staging: hv: Use only one txf buffer per channel and kmalloc/GFP_KERNEL on initialize staging: hv: remove unneeded osd_schedule_callback staging: hv: convert channel_mgmt.c to not call osd_schedule_callback staging: hv: convert vmbus_on_msg_dpc to not call osd_schedule_callback staging: brcm80211: Fix WL_<type> logging macros Staging: IIO: DDS: AD9833 / AD9834 driver Staging: IIO: dds.h convenience macros Staging: IIO: Direct digital synthesis abi documentation staging: brcm80211: Convert ETHER_TYPE_802_1X to ETH_P_PAE staging: brcm80211: Remove unused ETHER_TYPE_<foo> #defines staging: brcm80211: Remove ETHER_HDR_LEN, use ETH_HLEN staging: brcm80211: Convert ETHER_ADDR_LEN to ETH_ALEN staging: brcm80211: Convert ETHER_IS<FOO> to is_<foo>_ether_addr staging: brcm80211: Remove unused ether_<foo> #defines and struct staging: brcm80211: Convert ETHER_IS_MULTI to is_multicast_ether_addr staging: brcm80211: Remove unused #defines ETHER_<foo>_LOCALADDR Staging: comedi: Fix checkpatch.pl issues in file s526.c ... Fix up trivial conflict in drivers/video/udlfb.c
-rw-r--r--MAINTAINERS4
-rw-r--r--drivers/staging/Kconfig10
-rw-r--r--drivers/staging/Makefile5
-rw-r--r--drivers/staging/adis16255/Kconfig11
-rw-r--r--drivers/staging/adis16255/Makefile1
-rw-r--r--drivers/staging/adis16255/adis16255.c468
-rw-r--r--drivers/staging/adis16255/adis16255.h12
-rw-r--r--drivers/staging/asus_oled/asus_oled.c2
-rw-r--r--drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif.c4
-rw-r--r--drivers/staging/ath6kl/os/linux/ar6000_drv.c2
-rw-r--r--drivers/staging/autofs/dirhash.c87
-rw-r--r--drivers/staging/batman-adv/Kconfig26
-rw-r--r--drivers/staging/batman-adv/Makefile22
-rw-r--r--drivers/staging/batman-adv/README240
-rw-r--r--drivers/staging/batman-adv/TODO14
-rw-r--r--drivers/staging/batman-adv/aggregation.c275
-rw-r--r--drivers/staging/batman-adv/aggregation.h43
-rw-r--r--drivers/staging/batman-adv/bat_debugfs.c343
-rw-r--r--drivers/staging/batman-adv/bat_debugfs.h33
-rw-r--r--drivers/staging/batman-adv/bat_sysfs.c558
-rw-r--r--drivers/staging/batman-adv/bat_sysfs.h42
-rw-r--r--drivers/staging/batman-adv/bitarray.c201
-rw-r--r--drivers/staging/batman-adv/bitarray.h47
-rw-r--r--drivers/staging/batman-adv/hard-interface.c647
-rw-r--r--drivers/staging/batman-adv/hard-interface.h58
-rw-r--r--drivers/staging/batman-adv/hash.c306
-rw-r--r--drivers/staging/batman-adv/hash.h100
-rw-r--r--drivers/staging/batman-adv/icmp_socket.c359
-rw-r--r--drivers/staging/batman-adv/icmp_socket.h34
-rw-r--r--drivers/staging/batman-adv/main.c217
-rw-r--r--drivers/staging/batman-adv/main.h183
-rw-r--r--drivers/staging/batman-adv/originator.c533
-rw-r--r--drivers/staging/batman-adv/originator.h36
-rw-r--r--drivers/staging/batman-adv/packet.h134
-rw-r--r--drivers/staging/batman-adv/ring_buffer.c52
-rw-r--r--drivers/staging/batman-adv/ring_buffer.h28
-rw-r--r--drivers/staging/batman-adv/routing.c1389
-rw-r--r--drivers/staging/batman-adv/routing.h46
-rw-r--r--drivers/staging/batman-adv/send.c580
-rw-r--r--drivers/staging/batman-adv/send.h41
-rw-r--r--drivers/staging/batman-adv/soft-interface.c398
-rw-r--r--drivers/staging/batman-adv/soft-interface.h32
-rw-r--r--drivers/staging/batman-adv/sysfs-class-net-batman-adv14
-rw-r--r--drivers/staging/batman-adv/sysfs-class-net-mesh41
-rw-r--r--drivers/staging/batman-adv/translation-table.c518
-rw-r--r--drivers/staging/batman-adv/translation-table.h45
-rw-r--r--drivers/staging/batman-adv/types.h241
-rw-r--r--drivers/staging/batman-adv/unicast.c269
-rw-r--r--drivers/staging/batman-adv/unicast.h39
-rw-r--r--drivers/staging/batman-adv/vis.c895
-rw-r--r--drivers/staging/batman-adv/vis.h37
-rw-r--r--drivers/staging/bcm/Adapter.h134
-rw-r--r--drivers/staging/bcm/Arp.c94
-rw-r--r--drivers/staging/bcm/Bcmchar.c967
-rw-r--r--drivers/staging/bcm/Bcmnet.c404
-rw-r--r--drivers/staging/bcm/CmHost.c139
-rw-r--r--drivers/staging/bcm/CmHost.h3
-rw-r--r--drivers/staging/bcm/DDRInit.c17
-rw-r--r--drivers/staging/bcm/Debug.c41
-rw-r--r--drivers/staging/bcm/Debug.h88
-rw-r--r--drivers/staging/bcm/HandleControlPacket.c39
-rw-r--r--drivers/staging/bcm/HostMibs.h7
-rw-r--r--drivers/staging/bcm/IPv6Protocol.c10
-rw-r--r--drivers/staging/bcm/IPv6ProtocolHdr.h3
-rw-r--r--drivers/staging/bcm/InterfaceDld.c136
-rw-r--r--drivers/staging/bcm/InterfaceIdleMode.c20
-rw-r--r--drivers/staging/bcm/InterfaceIdleMode.h2
-rw-r--r--drivers/staging/bcm/InterfaceInit.c854
-rw-r--r--drivers/staging/bcm/InterfaceInit.h28
-rw-r--r--drivers/staging/bcm/InterfaceIsr.c44
-rw-r--r--drivers/staging/bcm/InterfaceMisc.c29
-rw-r--r--drivers/staging/bcm/InterfaceMisc.h3
-rw-r--r--drivers/staging/bcm/InterfaceRx.c40
-rw-r--r--drivers/staging/bcm/InterfaceTx.c74
-rw-r--r--drivers/staging/bcm/InterfaceTx.h6
-rw-r--r--drivers/staging/bcm/Interfacemain.h10
-rw-r--r--drivers/staging/bcm/LeakyBucket.c72
-rw-r--r--drivers/staging/bcm/Macros.h40
-rw-r--r--drivers/staging/bcm/Makefile4
-rw-r--r--drivers/staging/bcm/Misc.c536
-rw-r--r--drivers/staging/bcm/Osal_Misc.c27
-rw-r--r--drivers/staging/bcm/PHSModule.c234
-rw-r--r--drivers/staging/bcm/PHSModule.h45
-rw-r--r--drivers/staging/bcm/Protocol.h6
-rw-r--r--drivers/staging/bcm/Prototypes.h122
-rw-r--r--drivers/staging/bcm/Qos.c106
-rw-r--r--drivers/staging/bcm/TODO25
-rw-r--r--drivers/staging/bcm/Transmit.c393
-rw-r--r--drivers/staging/bcm/cntrl_SignalingInterface.h254
-rw-r--r--drivers/staging/bcm/headers.h40
-rw-r--r--drivers/staging/bcm/hostmibs.c35
-rw-r--r--drivers/staging/bcm/led_control.c135
-rw-r--r--drivers/staging/bcm/nvm.c642
-rw-r--r--drivers/staging/bcm/nvm.h80
-rw-r--r--drivers/staging/bcm/osal_misc.h49
-rw-r--r--drivers/staging/brcm80211/README10
-rw-r--r--drivers/staging/brcm80211/brcmfmac/README5
-rw-r--r--drivers/staging/brcm80211/brcmfmac/bcmsdh.c12
-rw-r--r--drivers/staging/brcm80211/brcmfmac/bcmsdh_linux.c270
-rw-r--r--drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc.c59
-rw-r--r--drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc_linux.c4
-rw-r--r--drivers/staging/brcm80211/brcmfmac/dhd.h19
-rw-r--r--drivers/staging/brcm80211/brcmfmac/dhd_bus.h6
-rw-r--r--drivers/staging/brcm80211/brcmfmac/dhd_cdc.c40
-rw-r--r--drivers/staging/brcm80211/brcmfmac/dhd_common.c18
-rw-r--r--drivers/staging/brcm80211/brcmfmac/dhd_custom_gpio.c36
-rw-r--r--drivers/staging/brcm80211/brcmfmac/dhd_linux.c148
-rw-r--r--drivers/staging/brcm80211/brcmfmac/dhd_linux_sched.c1
-rw-r--r--drivers/staging/brcm80211/brcmfmac/dhd_proto.h7
-rw-r--r--drivers/staging/brcm80211/brcmfmac/dhd_sdio.c348
-rw-r--r--drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c586
-rw-r--r--drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h48
-rw-r--r--drivers/staging/brcm80211/brcmfmac/wl_iw.c578
-rw-r--r--drivers/staging/brcm80211/brcmfmac/wl_iw.h2
-rw-r--r--drivers/staging/brcm80211/include/bcm_rpc.h79
-rw-r--r--drivers/staging/brcm80211/include/bcm_rpc_tp.h137
-rw-r--r--drivers/staging/brcm80211/include/bcm_xdr.h60
-rw-r--r--drivers/staging/brcm80211/include/bcmdefs.h63
-rw-r--r--drivers/staging/brcm80211/include/bcmsdbus.h6
-rw-r--r--drivers/staging/brcm80211/include/bcmsdh.h12
-rw-r--r--drivers/staging/brcm80211/include/bcmsdh_sdmmc.h6
-rw-r--r--drivers/staging/brcm80211/include/bcmsrom.h8
-rw-r--r--drivers/staging/brcm80211/include/bcmutils.h60
-rw-r--r--drivers/staging/brcm80211/include/d11.h7
-rw-r--r--drivers/staging/brcm80211/include/dbus.h353
-rw-r--r--drivers/staging/brcm80211/include/epivers.h44
-rw-r--r--drivers/staging/brcm80211/include/hnddma.h91
-rw-r--r--drivers/staging/brcm80211/include/hndpmu.h44
-rw-r--r--drivers/staging/brcm80211/include/linux_osl.h407
-rw-r--r--drivers/staging/brcm80211/include/linuxver.h38
-rw-r--r--drivers/staging/brcm80211/include/nicpci.h12
-rw-r--r--drivers/staging/brcm80211/include/osl.h209
-rw-r--r--drivers/staging/brcm80211/include/proto/ethernet.h54
-rw-r--r--drivers/staging/brcm80211/include/proto/wpa.h94
-rw-r--r--drivers/staging/brcm80211/include/rpc_osl.h2
-rw-r--r--drivers/staging/brcm80211/include/siutils.h28
-rw-r--r--drivers/staging/brcm80211/include/wlioctl.h342
-rw-r--r--drivers/staging/brcm80211/phy/wlc_phy_cmn.c63
-rw-r--r--drivers/staging/brcm80211/phy/wlc_phy_hal.h6
-rw-r--r--drivers/staging/brcm80211/phy/wlc_phy_int.h4
-rw-r--r--drivers/staging/brcm80211/phy/wlc_phy_lcn.c13
-rw-r--r--drivers/staging/brcm80211/phy/wlc_phy_n.c59
-rw-r--r--drivers/staging/brcm80211/phy/wlc_phytbl_lcn.c3
-rw-r--r--drivers/staging/brcm80211/phy/wlc_phytbl_n.c3
-rw-r--r--drivers/staging/brcm80211/sys/wl_dbg.h72
-rw-r--r--drivers/staging/brcm80211/sys/wl_export.h8
-rw-r--r--drivers/staging/brcm80211/sys/wl_mac80211.c1026
-rw-r--r--drivers/staging/brcm80211/sys/wl_mac80211.h50
-rw-r--r--drivers/staging/brcm80211/sys/wl_ucode.h12
-rw-r--r--drivers/staging/brcm80211/sys/wl_ucode_loader.c13
-rw-r--r--drivers/staging/brcm80211/sys/wlc_alloc.c70
-rw-r--r--drivers/staging/brcm80211/sys/wlc_alloc.h12
-rw-r--r--drivers/staging/brcm80211/sys/wlc_ampdu.c316
-rw-r--r--drivers/staging/brcm80211/sys/wlc_ampdu.h30
-rw-r--r--drivers/staging/brcm80211/sys/wlc_antsel.c49
-rw-r--r--drivers/staging/brcm80211/sys/wlc_antsel.h16
-rw-r--r--drivers/staging/brcm80211/sys/wlc_bmac.c806
-rw-r--r--drivers/staging/brcm80211/sys/wlc_bmac.h182
-rw-r--r--drivers/staging/brcm80211/sys/wlc_bsscfg.h3
-rw-r--r--drivers/staging/brcm80211/sys/wlc_cfg.h24
-rw-r--r--drivers/staging/brcm80211/sys/wlc_channel.c102
-rw-r--r--drivers/staging/brcm80211/sys/wlc_event.c16
-rw-r--r--drivers/staging/brcm80211/sys/wlc_event.h5
-rw-r--r--drivers/staging/brcm80211/sys/wlc_mac80211.c1297
-rw-r--r--drivers/staging/brcm80211/sys/wlc_mac80211.h312
-rw-r--r--drivers/staging/brcm80211/sys/wlc_phy_shim.c14
-rw-r--r--drivers/staging/brcm80211/sys/wlc_pub.h48
-rw-r--r--drivers/staging/brcm80211/sys/wlc_rate.c6
-rw-r--r--drivers/staging/brcm80211/sys/wlc_rpc.h527
-rw-r--r--drivers/staging/brcm80211/sys/wlc_rpctx.h71
-rw-r--r--drivers/staging/brcm80211/sys/wlc_scb.h2
-rw-r--r--drivers/staging/brcm80211/sys/wlc_stf.c72
-rw-r--r--drivers/staging/brcm80211/sys/wlc_stf.h31
-rw-r--r--drivers/staging/brcm80211/sys/wlc_types.h31
-rw-r--r--drivers/staging/brcm80211/util/aiutils.c25
-rw-r--r--drivers/staging/brcm80211/util/bcmotp.c22
-rw-r--r--drivers/staging/brcm80211/util/bcmsrom.c95
-rw-r--r--drivers/staging/brcm80211/util/bcmutils.c112
-rw-r--r--drivers/staging/brcm80211/util/bcmwifi.c4
-rw-r--r--drivers/staging/brcm80211/util/hnddma.c136
-rw-r--r--drivers/staging/brcm80211/util/hndpmu.c174
-rw-r--r--drivers/staging/brcm80211/util/linux_osl.c247
-rw-r--r--drivers/staging/brcm80211/util/nicpci.c125
-rw-r--r--drivers/staging/brcm80211/util/nvram/nvram_ro.c4
-rw-r--r--drivers/staging/brcm80211/util/sbutils.c13
-rw-r--r--drivers/staging/brcm80211/util/siutils.c206
-rw-r--r--drivers/staging/comedi/drivers.c30
-rw-r--r--drivers/staging/comedi/drivers/addi-data/APCI1710_Tor.c2
-rw-r--r--drivers/staging/comedi/drivers/addi-data/addi_common.c4
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_APCI1710.c2
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c2
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci1516.c2
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c2
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c2
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci230.c2
-rw-r--r--drivers/staging/comedi/drivers/cb_das16_cs.c2
-rw-r--r--drivers/staging/comedi/drivers/comedi_bond.c2
-rw-r--r--drivers/staging/comedi/drivers/ii_pci20kc.c66
-rw-r--r--drivers/staging/comedi/drivers/jr3_pci.c7
-rw-r--r--drivers/staging/comedi/drivers/ni_tiocmd.c71
-rw-r--r--drivers/staging/comedi/drivers/rtd520.c2
-rw-r--r--drivers/staging/comedi/drivers/s526.c139
-rw-r--r--drivers/staging/comedi/drivers/usbdux.c2
-rw-r--r--drivers/staging/cptm1217/Kconfig12
-rw-r--r--drivers/staging/cptm1217/Makefile2
-rw-r--r--drivers/staging/cptm1217/TODO5
-rw-r--r--drivers/staging/cptm1217/clearpad_tm1217.c675
-rw-r--r--drivers/staging/cptm1217/cp_tm1217.h9
-rw-r--r--drivers/staging/crystalhd/crystalhd_hw.c2
-rw-r--r--drivers/staging/crystalhd/crystalhd_lnx.c6
-rw-r--r--drivers/staging/cx25821/cx25821-alsa.c2
-rw-r--r--drivers/staging/cxt1e1/comet.c8
-rw-r--r--drivers/staging/cxt1e1/functions.c8
-rw-r--r--drivers/staging/cxt1e1/hwprobe.c4
-rw-r--r--drivers/staging/cxt1e1/linux.c18
-rw-r--r--drivers/staging/cxt1e1/musycc.c58
-rw-r--r--drivers/staging/cxt1e1/pmcc4_drv.c38
-rw-r--r--drivers/staging/cxt1e1/sbecom_inline_linux.h4
-rw-r--r--drivers/staging/easycap/Kconfig1
-rw-r--r--drivers/staging/easycap/Makefile1
-rw-r--r--drivers/staging/easycap/README93
-rw-r--r--drivers/staging/easycap/easycap.h186
-rw-r--r--drivers/staging/easycap/easycap_debug.h2
-rw-r--r--drivers/staging/easycap/easycap_ioctl.c2286
-rw-r--r--drivers/staging/easycap/easycap_low.c895
-rw-r--r--drivers/staging/easycap/easycap_main.c2774
-rw-r--r--drivers/staging/easycap/easycap_settings.c272
-rw-r--r--drivers/staging/easycap/easycap_sound.c603
-rw-r--r--drivers/staging/easycap/easycap_testcard.c372
-rw-r--r--drivers/staging/et131x/et131x_initpci.c2
-rw-r--r--drivers/staging/frontier/alphatrack.c4
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c54
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c8
-rw-r--r--drivers/staging/ft1000/ft1000-usb/Makefile2
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_debug.c (renamed from drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c)435
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_download.c386
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_hw.c433
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_hw.h4
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_proc.c373
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_usb.c34
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_usb.h62
-rw-r--r--drivers/staging/go7007/go7007-driver.c2
-rw-r--r--drivers/staging/hv/Makefile2
-rw-r--r--drivers/staging/hv/blkvsc.c52
-rw-r--r--drivers/staging/hv/blkvsc_drv.c117
-rw-r--r--drivers/staging/hv/channel.c338
-rw-r--r--drivers/staging/hv/channel_mgmt.c244
-rw-r--r--drivers/staging/hv/channel_mgmt.h245
-rw-r--r--drivers/staging/hv/connection.c56
-rw-r--r--drivers/staging/hv/hv.c346
-rw-r--r--drivers/staging/hv/hv.h36
-rw-r--r--drivers/staging/hv/hv_api.h278
-rw-r--r--drivers/staging/hv/hv_utils.c99
-rw-r--r--drivers/staging/hv/netvsc.c937
-rw-r--r--drivers/staging/hv/netvsc.h164
-rw-r--r--drivers/staging/hv/netvsc_api.h64
-rw-r--r--drivers/staging/hv/netvsc_drv.c83
-rw-r--r--drivers/staging/hv/osd.c108
-rw-r--r--drivers/staging/hv/osd.h22
-rw-r--r--drivers/staging/hv/ring_buffer.c404
-rw-r--r--drivers/staging/hv/ring_buffer.h56
-rw-r--r--drivers/staging/hv/rndis.h353
-rw-r--r--drivers/staging/hv/rndis_filter.c640
-rw-r--r--drivers/staging/hv/rndis_filter.h2
-rw-r--r--drivers/staging/hv/storvsc.c584
-rw-r--r--drivers/staging/hv/storvsc_api.h54
-rw-r--r--drivers/staging/hv/storvsc_drv.c95
-rw-r--r--drivers/staging/hv/vmbus.c274
-rw-r--r--drivers/staging/hv/vmbus_api.h24
-rw-r--r--drivers/staging/hv/vmbus_drv.c351
-rw-r--r--drivers/staging/hv/vmbus_private.h7
-rw-r--r--drivers/staging/hv/vstorage.h106
-rw-r--r--drivers/staging/iio/Documentation/sysfs-bus-iio627
-rw-r--r--drivers/staging/iio/Documentation/sysfs-bus-iio-dds93
-rw-r--r--drivers/staging/iio/Kconfig6
-rw-r--r--drivers/staging/iio/Makefile7
-rw-r--r--drivers/staging/iio/TODO4
-rw-r--r--drivers/staging/iio/accel/Kconfig27
-rw-r--r--drivers/staging/iio/accel/Makefile12
-rw-r--r--drivers/staging/iio/accel/accel.h20
-rw-r--r--drivers/staging/iio/accel/adis16201.h150
-rw-r--r--drivers/staging/iio/accel/adis16201_core.c659
-rw-r--r--drivers/staging/iio/accel/adis16201_ring.c218
-rw-r--r--drivers/staging/iio/accel/adis16201_trigger.c122
-rw-r--r--drivers/staging/iio/accel/adis16203.h143
-rw-r--r--drivers/staging/iio/accel/adis16203_core.c568
-rw-r--r--drivers/staging/iio/accel/adis16203_ring.c211
-rw-r--r--drivers/staging/iio/accel/adis16203_trigger.c122
-rw-r--r--drivers/staging/iio/accel/adis16204.h151
-rw-r--r--drivers/staging/iio/accel/adis16204_core.c613
-rw-r--r--drivers/staging/iio/accel/adis16204_ring.c206
-rw-r--r--drivers/staging/iio/accel/adis16204_trigger.c122
-rw-r--r--drivers/staging/iio/accel/adis16209_ring.c2
-rw-r--r--drivers/staging/iio/accel/lis3l02dq_ring.c2
-rw-r--r--drivers/staging/iio/adc/Kconfig91
-rw-r--r--drivers/staging/iio/adc/Makefile15
-rw-r--r--drivers/staging/iio/adc/ad7150.c877
-rw-r--r--drivers/staging/iio/adc/ad7152.c610
-rw-r--r--drivers/staging/iio/adc/ad7291.c1039
-rw-r--r--drivers/staging/iio/adc/ad7298.c501
-rw-r--r--drivers/staging/iio/adc/ad7314.c308
-rw-r--r--drivers/staging/iio/adc/ad7745.c734
-rw-r--r--drivers/staging/iio/adc/ad7816.c535
-rw-r--r--drivers/staging/iio/adc/ad7887.h105
-rw-r--r--drivers/staging/iio/adc/ad7887_core.c305
-rw-r--r--drivers/staging/iio/adc/ad7887_ring.c266
-rw-r--r--drivers/staging/iio/adc/adt7310.c952
-rw-r--r--drivers/staging/iio/adc/adt7410.c915
-rw-r--r--drivers/staging/iio/adc/adt75.c732
-rw-r--r--drivers/staging/iio/addac/Kconfig25
-rw-r--r--drivers/staging/iio/addac/Makefile7
-rw-r--r--drivers/staging/iio/addac/adt7316-i2c.c170
-rw-r--r--drivers/staging/iio/addac/adt7316-spi.c180
-rw-r--r--drivers/staging/iio/addac/adt7316.c2402
-rw-r--r--drivers/staging/iio/addac/adt7316.h33
-rw-r--r--drivers/staging/iio/dac/Kconfig21
-rw-r--r--drivers/staging/iio/dac/Makefile6
-rw-r--r--drivers/staging/iio/dac/ad5446.c323
-rw-r--r--drivers/staging/iio/dac/ad5446.h96
-rw-r--r--drivers/staging/iio/dac/ad5624r.h21
-rw-r--r--drivers/staging/iio/dac/ad5624r_spi.c300
-rw-r--r--drivers/staging/iio/dac/dac.h6
-rw-r--r--drivers/staging/iio/dds/Kconfig56
-rw-r--r--drivers/staging/iio/dds/Makefile11
-rw-r--r--drivers/staging/iio/dds/ad5930.c170
-rw-r--r--drivers/staging/iio/dds/ad9832.c264
-rw-r--r--drivers/staging/iio/dds/ad9834.c477
-rw-r--r--drivers/staging/iio/dds/ad9834.h112
-rw-r--r--drivers/staging/iio/dds/ad9850.c156
-rw-r--r--drivers/staging/iio/dds/ad9852.c305
-rw-r--r--drivers/staging/iio/dds/ad9910.c440
-rw-r--r--drivers/staging/iio/dds/ad9951.c249
-rw-r--r--drivers/staging/iio/dds/dds.h110
-rw-r--r--drivers/staging/iio/gyro/Kconfig38
-rw-r--r--drivers/staging/iio/gyro/Makefile12
-rw-r--r--drivers/staging/iio/gyro/adis16060.h101
-rw-r--r--drivers/staging/iio/gyro/adis16060_core.c319
-rw-r--r--drivers/staging/iio/gyro/adis16080.h102
-rw-r--r--drivers/staging/iio/gyro/adis16080_core.c271
-rw-r--r--drivers/staging/iio/gyro/adis16130.h108
-rw-r--r--drivers/staging/iio/gyro/adis16130_core.c313
-rw-r--r--drivers/staging/iio/gyro/adis16251.h185
-rw-r--r--drivers/staging/iio/gyro/adis16251_core.c777
-rw-r--r--drivers/staging/iio/gyro/adis16260.h3
-rw-r--r--drivers/staging/iio/gyro/adis16260_core.c142
-rw-r--r--drivers/staging/iio/gyro/adis16260_platform_data.h19
-rw-r--r--drivers/staging/iio/gyro/gyro.h9
-rw-r--r--drivers/staging/iio/imu/adis16350_core.c1
-rw-r--r--drivers/staging/iio/meter/Kconfig61
-rw-r--r--drivers/staging/iio/meter/Makefile15
-rw-r--r--drivers/staging/iio/meter/ade7753.c730
-rw-r--r--drivers/staging/iio/meter/ade7753.h140
-rw-r--r--drivers/staging/iio/meter/ade7754.c756
-rw-r--r--drivers/staging/iio/meter/ade7754.h161
-rw-r--r--drivers/staging/iio/meter/ade7758.h171
-rw-r--r--drivers/staging/iio/meter/ade7758_core.c866
-rw-r--r--drivers/staging/iio/meter/ade7758_ring.c212
-rw-r--r--drivers/staging/iio/meter/ade7758_trigger.c125
-rw-r--r--drivers/staging/iio/meter/ade7759.c670
-rw-r--r--drivers/staging/iio/meter/ade7759.h122
-rw-r--r--drivers/staging/iio/meter/ade7854-i2c.c272
-rw-r--r--drivers/staging/iio/meter/ade7854-spi.c360
-rw-r--r--drivers/staging/iio/meter/ade7854.c680
-rw-r--r--drivers/staging/iio/meter/ade7854.h245
-rw-r--r--drivers/staging/iio/meter/meter.h396
-rw-r--r--drivers/staging/iio/resolver/Kconfig54
-rw-r--r--drivers/staging/iio/resolver/Makefile7
-rw-r--r--drivers/staging/iio/resolver/ad2s120x.c310
-rw-r--r--drivers/staging/iio/resolver/ad2s1210.c872
-rw-r--r--drivers/staging/iio/resolver/ad2s90.c159
-rw-r--r--drivers/staging/iio/sysfs.h6
-rw-r--r--drivers/staging/intel_sst/Kconfig1
-rw-r--r--drivers/staging/intel_sst/intel_sst.c116
-rw-r--r--drivers/staging/intel_sst/intel_sst.h8
-rw-r--r--drivers/staging/intel_sst/intel_sst_app_interface.c314
-rw-r--r--drivers/staging/intel_sst/intel_sst_common.h10
-rw-r--r--drivers/staging/intel_sst/intel_sst_drv_interface.c209
-rw-r--r--drivers/staging/intel_sst/intel_sst_dsp.c70
-rw-r--r--drivers/staging/intel_sst/intel_sst_fw_ipc.h113
-rw-r--r--drivers/staging/intel_sst/intel_sst_ioctl.h15
-rw-r--r--drivers/staging/intel_sst/intel_sst_ipc.c194
-rw-r--r--drivers/staging/intel_sst/intel_sst_pvt.c36
-rw-r--r--drivers/staging/intel_sst/intel_sst_stream.c20
-rw-r--r--drivers/staging/intel_sst/intel_sst_stream_encoded.c214
-rw-r--r--drivers/staging/intel_sst/intelmid.c192
-rw-r--r--drivers/staging/intel_sst/intelmid.h5
-rw-r--r--drivers/staging/intel_sst/intelmid_ctrl.c28
-rw-r--r--drivers/staging/intel_sst/intelmid_msic_control.c24
-rw-r--r--drivers/staging/intel_sst/intelmid_pvt.c54
-rw-r--r--drivers/staging/intel_sst/intelmid_v0_control.c32
-rw-r--r--drivers/staging/intel_sst/intelmid_v1_control.c70
-rw-r--r--drivers/staging/intel_sst/intelmid_v2_control.c96
-rw-r--r--drivers/staging/keucr/init.c420
-rw-r--r--drivers/staging/keucr/init.h3
-rw-r--r--drivers/staging/keucr/ms.c10
-rw-r--r--drivers/staging/keucr/smilmain.c4
-rw-r--r--drivers/staging/keucr/smilsub.c4
-rw-r--r--drivers/staging/line6/capture.c2
-rw-r--r--drivers/staging/line6/midi.c4
-rw-r--r--drivers/staging/line6/playback.c2
-rw-r--r--drivers/staging/memrar/memrar.h19
-rw-r--r--drivers/staging/msm/Makefile4
-rw-r--r--drivers/staging/msm/lcdc_toshiba_wvga_pt.c2
-rw-r--r--drivers/staging/msm/tvenc.c5
-rw-r--r--drivers/staging/phison/phison.c2
-rw-r--r--drivers/staging/pohmelfs/crypto.c6
-rw-r--r--drivers/staging/rt2860/chip/mac_pci.h7
-rw-r--r--drivers/staging/rt2860/chip/mac_usb.h5
-rw-r--r--drivers/staging/rt2860/chip/rtmp_mac.h19
-rw-r--r--drivers/staging/rt2860/chip/rtmp_phy.h14
-rw-r--r--drivers/staging/rt2860/chips/rt3090.c8
-rw-r--r--drivers/staging/rt2860/chips/rt30xx.c13
-rw-r--r--drivers/staging/rt2860/common/ba_action.c18
-rw-r--r--drivers/staging/rt2860/common/cmm_data.c2
-rw-r--r--drivers/staging/rt2860/common/cmm_data_pci.c4
-rw-r--r--drivers/staging/rt2860/common/cmm_mac_pci.c10
-rw-r--r--drivers/staging/rt2860/common/cmm_mac_usb.c2
-rw-r--r--drivers/staging/rt2860/common/cmm_wpa.c22
-rw-r--r--drivers/staging/rt2860/common/ee_efuse.c15
-rw-r--r--drivers/staging/rt2860/common/mlme.c13
-rw-r--r--drivers/staging/rt2860/common/rt_rf.c3
-rw-r--r--drivers/staging/rt2860/common/rtmp_init.c24
-rw-r--r--drivers/staging/rt2860/common/rtmp_mcu.c4
-rw-r--r--drivers/staging/rt2860/common/spectrum.c2
-rw-r--r--drivers/staging/rt2860/mlme.h41
-rw-r--r--drivers/staging/rt2860/oid.h15
-rw-r--r--drivers/staging/rt2860/pci_main_dev.c22
-rw-r--r--drivers/staging/rt2860/rt_linux.c35
-rw-r--r--drivers/staging/rt2860/rt_linux.h11
-rw-r--r--drivers/staging/rt2860/rt_main_dev.c18
-rw-r--r--drivers/staging/rt2860/rt_pci_rbus.c7
-rw-r--r--drivers/staging/rt2860/rt_usb.c45
-rw-r--r--drivers/staging/rt2860/rtmp.h71
-rw-r--r--drivers/staging/rt2860/rtmp_def.h37
-rw-r--r--drivers/staging/rt2860/rtmp_timer.h13
-rw-r--r--drivers/staging/rt2860/spectrum.h12
-rw-r--r--drivers/staging/rt2860/sta/assoc.c15
-rw-r--r--drivers/staging/rt2860/sta/auth.c10
-rw-r--r--drivers/staging/rt2860/sta/connect.c38
-rw-r--r--drivers/staging/rt2860/sta/rtmp_data.c35
-rw-r--r--drivers/staging/rt2860/sta/sanity.c5
-rw-r--r--drivers/staging/rt2860/sta/sync.c25
-rw-r--r--drivers/staging/rt2860/sta/wpa.c5
-rw-r--r--drivers/staging/rt2860/sta_ioctl.c25
-rw-r--r--drivers/staging/rt2860/usb_main_dev.c20
-rw-r--r--drivers/staging/rt2860/wpa.h5
-rw-r--r--drivers/staging/rtl8192e/ieee80211/ieee80211_tx.c2
-rw-r--r--drivers/staging/rtl8192e/r8192E_core.c6
-rw-r--r--drivers/staging/rtl8192e/r819xE_phy.c2
-rw-r--r--drivers/staging/rtl8192u/Makefile1
-rw-r--r--drivers/staging/rtl8192u/dot11d.h2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/Makefile2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/dot11d.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/dot11d.h3
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211.h8
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c12
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c47
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c2
-rw-r--r--drivers/staging/rtl8192u/r8192U_core.c27
-rw-r--r--drivers/staging/rtl8192u/r8192U_wx.c6
-rw-r--r--drivers/staging/rtl8192u/r819xU_phy.c6
-rw-r--r--drivers/staging/rtl8712/TODO1
-rw-r--r--drivers/staging/rtl8712/osdep_service.h25
-rw-r--r--drivers/staging/rtl8712/rtl8712_efuse.c2
-rw-r--r--drivers/staging/rtl8712/rtl8712_xmit.c2
-rw-r--r--drivers/staging/rtl8712/rtl871x_xmit.c2
-rw-r--r--drivers/staging/rtl8712/usb_intf.c2
-rw-r--r--drivers/staging/sep/Kconfig10
-rw-r--r--drivers/staging/sep/Makefile2
-rw-r--r--drivers/staging/sep/TODO5
-rw-r--r--drivers/staging/sep/sep_dev.h156
-rw-r--r--drivers/staging/sep/sep_driver.c3577
-rw-r--r--drivers/staging/sep/sep_driver_api.h297
-rw-r--r--drivers/staging/sep/sep_driver_config.h239
-rw-r--r--drivers/staging/sep/sep_driver_hw_defs.h233
-rw-r--r--drivers/staging/sm7xx/smtcfb.c2
-rw-r--r--drivers/staging/solo6x10/Kconfig4
-rw-r--r--drivers/staging/solo6x10/TODO4
-rw-r--r--drivers/staging/solo6x10/solo6010-core.c42
-rw-r--r--drivers/staging/solo6x10/solo6010-disp.c6
-rw-r--r--drivers/staging/solo6x10/solo6010-enc.c6
-rw-r--r--drivers/staging/solo6x10/solo6010-g723.c22
-rw-r--r--drivers/staging/solo6x10/solo6010-gpio.c4
-rw-r--r--drivers/staging/solo6x10/solo6010-i2c.c13
-rw-r--r--drivers/staging/solo6x10/solo6010-osd-font.h60
-rw-r--r--drivers/staging/solo6x10/solo6010-p2m.c156
-rw-r--r--drivers/staging/solo6x10/solo6010-tw28.c118
-rw-r--r--drivers/staging/solo6x10/solo6010-v4l2-enc.c370
-rw-r--r--drivers/staging/solo6x10/solo6010-v4l2.c197
-rw-r--r--drivers/staging/solo6x10/solo6010.h39
-rw-r--r--drivers/staging/speakup/kobjects.c9
-rw-r--r--drivers/staging/speakup/main.c33
-rw-r--r--drivers/staging/speakup/spk_types.h2
-rw-r--r--drivers/staging/spectra/ffsport.c61
-rw-r--r--drivers/staging/spectra/ffsport.h1
-rw-r--r--drivers/staging/spectra/flash.c4
-rw-r--r--drivers/staging/spectra/lld_emu.c6
-rw-r--r--drivers/staging/spectra/lld_nand.c177
-rw-r--r--drivers/staging/ste_rmi4/Kconfig9
-rw-r--r--drivers/staging/ste_rmi4/Makefile4
-rw-r--r--drivers/staging/ste_rmi4/TODO7
-rw-r--r--drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c1179
-rw-r--r--drivers/staging/ste_rmi4/synaptics_i2c_rmi4.h50
-rw-r--r--drivers/staging/tidspbridge/core/tiomap3430.c4
-rw-r--r--drivers/staging/tidspbridge/rmgr/nldr.c2
-rw-r--r--drivers/staging/usbip/vhci_hcd.c14
-rw-r--r--drivers/staging/vme/bridges/Module.symvers0
-rw-r--r--drivers/staging/vme/bridges/vme_ca91cx42.c235
-rw-r--r--drivers/staging/vme/bridges/vme_ca91cx42.h2
-rw-r--r--drivers/staging/vme/bridges/vme_tsi148.c264
-rw-r--r--drivers/staging/vme/bridges/vme_tsi148.h2
-rw-r--r--drivers/staging/vme/devices/vme_user.c79
-rw-r--r--drivers/staging/vme/vme.c116
-rw-r--r--drivers/staging/vme/vme_bridge.h2
-rw-r--r--drivers/staging/vt6655/card.c2
-rw-r--r--drivers/staging/vt6655/iwctl.c2
-rw-r--r--drivers/staging/vt6655/wpa2.c4
-rw-r--r--drivers/staging/vt6656/baseband.c2
-rw-r--r--drivers/staging/vt6656/card.c2
-rw-r--r--drivers/staging/vt6656/dpc.c4
-rw-r--r--drivers/staging/vt6656/iwctl.c2
-rw-r--r--drivers/staging/vt6656/power.c2
-rw-r--r--drivers/staging/vt6656/rxtx.c3
-rw-r--r--drivers/staging/vt6656/tkip.c37
-rw-r--r--drivers/staging/vt6656/wpa2.c4
-rw-r--r--drivers/staging/westbridge/astoria/arch/arm/mach-omap2/cyashalomap_kernel.c10
-rw-r--r--drivers/staging/winbond/Makefile1
-rw-r--r--drivers/staging/winbond/core.h2
-rw-r--r--drivers/staging/winbond/mac_structures.h545
-rw-r--r--drivers/staging/winbond/mds.c70
-rw-r--r--drivers/staging/winbond/mds_f.h3
-rw-r--r--drivers/staging/winbond/mds_s.h4
-rw-r--r--drivers/staging/winbond/mlmetxrx.c62
-rw-r--r--drivers/staging/winbond/mlmetxrx_f.h23
-rw-r--r--drivers/staging/winbond/mto.c5
-rw-r--r--drivers/staging/winbond/phy_calibration.c5
-rw-r--r--drivers/staging/winbond/phy_calibration.h2
-rw-r--r--drivers/staging/winbond/reg.c36
-rw-r--r--drivers/staging/winbond/sysdef.h31
-rw-r--r--drivers/staging/winbond/wb35reg.c33
-rw-r--r--drivers/staging/winbond/wb35reg_f.h2
-rw-r--r--drivers/staging/winbond/wb35reg_s.h77
-rw-r--r--drivers/staging/winbond/wb35rx.c30
-rw-r--r--drivers/staging/winbond/wb35rx_f.h2
-rw-r--r--drivers/staging/winbond/wb35tx.c31
-rw-r--r--drivers/staging/winbond/wb35tx_f.h1
-rw-r--r--drivers/staging/winbond/wbhal.h (renamed from drivers/staging/winbond/wbhal_s.h)14
-rw-r--r--drivers/staging/winbond/wbhal_f.h81
-rw-r--r--drivers/staging/winbond/wblinux_f.h17
-rw-r--r--drivers/staging/winbond/wbusb.c50
-rw-r--r--drivers/staging/winbond/wbusb_s.h18
-rw-r--r--drivers/staging/wlags49_h2/wl_pci.c2
-rw-r--r--drivers/staging/wlags49_h2/wl_profile.c2
-rw-r--r--drivers/staging/wlags49_h2/wl_sysfs.c4
-rw-r--r--drivers/staging/wlan-ng/p80211conv.c45
-rw-r--r--drivers/staging/wlan-ng/p80211conv.h6
-rw-r--r--drivers/staging/wlan-ng/p80211netdev.c6
-rw-r--r--drivers/staging/wlan-ng/p80211netdev.h10
-rw-r--r--drivers/staging/wlan-ng/p80211types.h4
-rw-r--r--drivers/staging/wlan-ng/prism2mgmt.c26
-rw-r--r--drivers/staging/xgifb/XGI_main_26.c9
-rw-r--r--drivers/staging/zram/xvmalloc.c6
-rw-r--r--drivers/staging/zram/zram_drv.c3
-rw-r--r--drivers/usb/serial/option.c1
-rw-r--r--drivers/video/udlfb.c5
-rw-r--r--include/linux/rar_register.h16
567 files changed, 51143 insertions, 32278 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index 5181828012ce..aca102f758ba 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1423,7 +1423,9 @@ F: drivers/net/tg3.*
1423BROADCOM BRCM80211 IEEE802.11n WIRELESS DRIVER 1423BROADCOM BRCM80211 IEEE802.11n WIRELESS DRIVER
1424M: Brett Rudley <brudley@broadcom.com> 1424M: Brett Rudley <brudley@broadcom.com>
1425M: Henry Ptasinski <henryp@broadcom.com> 1425M: Henry Ptasinski <henryp@broadcom.com>
1426M: Nohee Ko <noheek@broadcom.com> 1426M: Dowan Kim <dowan@broadcom.com>
1427M: Roland Vossen <rvossen@broadcom.com>
1428M: Arend van Spriel <arend@broadcom.com>
1427L: linux-wireless@vger.kernel.org 1429L: linux-wireless@vger.kernel.org
1428S: Supported 1430S: Supported
1429F: drivers/staging/brcm80211/ 1431F: drivers/staging/brcm80211/
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index bdc632b6b586..e2d586903432 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -119,6 +119,8 @@ source "drivers/staging/vme/Kconfig"
119 119
120source "drivers/staging/memrar/Kconfig" 120source "drivers/staging/memrar/Kconfig"
121 121
122source "drivers/staging/sep/Kconfig"
123
122source "drivers/staging/iio/Kconfig" 124source "drivers/staging/iio/Kconfig"
123 125
124source "drivers/staging/zram/Kconfig" 126source "drivers/staging/zram/Kconfig"
@@ -127,8 +129,6 @@ source "drivers/staging/wlags49_h2/Kconfig"
127 129
128source "drivers/staging/wlags49_h25/Kconfig" 130source "drivers/staging/wlags49_h25/Kconfig"
129 131
130source "drivers/staging/batman-adv/Kconfig"
131
132source "drivers/staging/samsung-laptop/Kconfig" 132source "drivers/staging/samsung-laptop/Kconfig"
133 133
134source "drivers/staging/sm7xx/Kconfig" 134source "drivers/staging/sm7xx/Kconfig"
@@ -141,8 +141,6 @@ source "drivers/staging/cxt1e1/Kconfig"
141 141
142source "drivers/staging/ti-st/Kconfig" 142source "drivers/staging/ti-st/Kconfig"
143 143
144source "drivers/staging/adis16255/Kconfig"
145
146source "drivers/staging/xgifb/Kconfig" 144source "drivers/staging/xgifb/Kconfig"
147 145
148source "drivers/staging/msm/Kconfig" 146source "drivers/staging/msm/Kconfig"
@@ -175,5 +173,9 @@ source "drivers/staging/intel_sst/Kconfig"
175 173
176source "drivers/staging/speakup/Kconfig" 174source "drivers/staging/speakup/Kconfig"
177 175
176source "drivers/staging/cptm1217/Kconfig"
177
178source "drivers/staging/ste_rmi4/Kconfig"
179
178endif # !STAGING_EXCLUDE_BUILD 180endif # !STAGING_EXCLUDE_BUILD
179endif # STAGING 181endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 3eda5c73a50a..c7d222413c07 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -42,18 +42,17 @@ obj-$(CONFIG_VT6656) += vt6656/
42obj-$(CONFIG_HYPERV) += hv/ 42obj-$(CONFIG_HYPERV) += hv/
43obj-$(CONFIG_VME_BUS) += vme/ 43obj-$(CONFIG_VME_BUS) += vme/
44obj-$(CONFIG_MRST_RAR_HANDLER) += memrar/ 44obj-$(CONFIG_MRST_RAR_HANDLER) += memrar/
45obj-$(CONFIG_DX_SEP) += sep/
45obj-$(CONFIG_IIO) += iio/ 46obj-$(CONFIG_IIO) += iio/
46obj-$(CONFIG_ZRAM) += zram/ 47obj-$(CONFIG_ZRAM) += zram/
47obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/ 48obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/
48obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/ 49obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/
49obj-$(CONFIG_BATMAN_ADV) += batman-adv/
50obj-$(CONFIG_SAMSUNG_LAPTOP) += samsung-laptop/ 50obj-$(CONFIG_SAMSUNG_LAPTOP) += samsung-laptop/
51obj-$(CONFIG_FB_SM7XX) += sm7xx/ 51obj-$(CONFIG_FB_SM7XX) += sm7xx/
52obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/ 52obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/
53obj-$(CONFIG_CRYSTALHD) += crystalhd/ 53obj-$(CONFIG_CRYSTALHD) += crystalhd/
54obj-$(CONFIG_CXT1E1) += cxt1e1/ 54obj-$(CONFIG_CXT1E1) += cxt1e1/
55obj-$(CONFIG_TI_ST) += ti-st/ 55obj-$(CONFIG_TI_ST) += ti-st/
56obj-$(CONFIG_ADIS16255) += adis16255/
57obj-$(CONFIG_FB_XGI) += xgifb/ 56obj-$(CONFIG_FB_XGI) += xgifb/
58obj-$(CONFIG_MSM_STAGING) += msm/ 57obj-$(CONFIG_MSM_STAGING) += msm/
59obj-$(CONFIG_EASYCAP) += easycap/ 58obj-$(CONFIG_EASYCAP) += easycap/
@@ -68,3 +67,5 @@ obj-$(CONFIG_BCM_WIMAX) += bcm/
68obj-$(CONFIG_FT1000) += ft1000/ 67obj-$(CONFIG_FT1000) += ft1000/
69obj-$(CONFIG_SND_INTEL_SST) += intel_sst/ 68obj-$(CONFIG_SND_INTEL_SST) += intel_sst/
70obj-$(CONFIG_SPEAKUP) += speakup/ 69obj-$(CONFIG_SPEAKUP) += speakup/
70obj-$(CONFIG_TOUCHSCREEN_CLEARPAD_TM1217) += cptm1217/
71obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4) += ste_rmi4/
diff --git a/drivers/staging/adis16255/Kconfig b/drivers/staging/adis16255/Kconfig
deleted file mode 100644
index a883c1f4478b..000000000000
--- a/drivers/staging/adis16255/Kconfig
+++ /dev/null
@@ -1,11 +0,0 @@
1config ADIS16255
2 tristate "Analog Devices ADIS16250/16255"
3 depends on SPI && SYSFS
4 ---help---
5 If you say yes here you get support for the Analog Devices
6 ADIS16250/16255 Low Power Gyroscope. The driver exposes
7 orientation and gyroscope value, as well as sample rate
8 to the sysfs.
9
10 This driver can also be built as a module. If so, the module
11 will be called adis16255.
diff --git a/drivers/staging/adis16255/Makefile b/drivers/staging/adis16255/Makefile
deleted file mode 100644
index 8c3908106bfa..000000000000
--- a/drivers/staging/adis16255/Makefile
+++ /dev/null
@@ -1 +0,0 @@
1obj-$(CONFIG_ADIS16255) += adis16255.o
diff --git a/drivers/staging/adis16255/adis16255.c b/drivers/staging/adis16255/adis16255.c
deleted file mode 100644
index 8d4d7cbab979..000000000000
--- a/drivers/staging/adis16255/adis16255.c
+++ /dev/null
@@ -1,468 +0,0 @@
1/*
2 * Analog Devices ADIS16250/ADIS16255 Low Power Gyroscope
3 *
4 * Written by: Matthias Brugger <m_brugger@web.de>
5 *
6 * Copyright (C) 2010 Fraunhofer Institute for Integrated Circuits
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the
20 * Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24/*
25 * The driver just has a bare interface to the sysfs (sample rate in Hz,
26 * orientation (x, y, z) and gyroscope data in °/sec.
27 *
28 * It should be added to iio subsystem when this has left staging.
29 *
30 */
31
32#include <linux/init.h>
33#include <linux/module.h>
34#include <linux/device.h>
35#include <linux/list.h>
36#include <linux/errno.h>
37#include <linux/mutex.h>
38#include <linux/slab.h>
39
40#include <linux/interrupt.h>
41#include <linux/sysfs.h>
42#include <linux/stat.h>
43#include <linux/delay.h>
44
45#include <linux/gpio.h>
46
47#include <linux/spi/spi.h>
48#include <linux/workqueue.h>
49
50#include "adis16255.h"
51
52#define ADIS_STATUS 0x3d
53#define ADIS_SMPL_PRD_MSB 0x37
54#define ADIS_SMPL_PRD_LSB 0x36
55#define ADIS_MSC_CTRL_MSB 0x35
56#define ADIS_MSC_CTRL_LSB 0x34
57#define ADIS_GPIO_CTRL 0x33
58#define ADIS_ALM_SMPL1 0x25
59#define ADIS_ALM_MAG1 0x21
60#define ADIS_GYRO_SCALE 0x17
61#define ADIS_GYRO_OUT 0x05
62#define ADIS_SUPPLY_OUT 0x03
63#define ADIS_ENDURANCE 0x01
64
65/*
66 * data structure for every sensor
67 *
68 * @dev: Driver model representation of the device.
69 * @spi: Pointer to the spi device which will manage i/o to spi bus.
70 * @data: Last read data from device.
71 * @irq_adis: GPIO Number of IRQ signal
72 * @irq: irq line manage by kernel
73 * @negative: indicates if sensor is upside down (negative == 1)
74 * @direction: indicates axis (x, y, z) the sensor is meassuring
75 */
76struct spi_adis16255_data {
77 struct device dev;
78 struct spi_device *spi;
79 s16 data;
80 int irq;
81 u8 negative;
82 char direction;
83};
84
85/*-------------------------------------------------------------------------*/
86
87static int spi_adis16255_read_data(struct spi_adis16255_data *spiadis,
88 u8 adr,
89 u8 *rbuf)
90{
91 struct spi_device *spi = spiadis->spi;
92 struct spi_message msg;
93 struct spi_transfer xfer1, xfer2;
94 u8 *buf, *rx;
95 int ret;
96
97 buf = kzalloc(4, GFP_KERNEL);
98 if (buf == NULL)
99 return -ENOMEM;
100
101 rx = kzalloc(4, GFP_KERNEL);
102 if (rx == NULL) {
103 ret = -ENOMEM;
104 goto err_buf;
105 }
106
107 buf[0] = adr;
108
109 spi_message_init(&msg);
110 memset(&xfer1, 0, sizeof(xfer1));
111 memset(&xfer2, 0, sizeof(xfer2));
112
113 xfer1.tx_buf = buf;
114 xfer1.rx_buf = buf + 2;
115 xfer1.len = 2;
116 xfer1.delay_usecs = 9;
117
118 xfer2.tx_buf = rx + 2;
119 xfer2.rx_buf = rx;
120 xfer2.len = 2;
121
122 spi_message_add_tail(&xfer1, &msg);
123 spi_message_add_tail(&xfer2, &msg);
124
125 ret = spi_sync(spi, &msg);
126 if (ret == 0) {
127 rbuf[0] = rx[0];
128 rbuf[1] = rx[1];
129 }
130
131 kfree(rx);
132err_buf:
133 kfree(buf);
134
135 return ret;
136}
137
138static int spi_adis16255_write_data(struct spi_adis16255_data *spiadis,
139 u8 adr1,
140 u8 adr2,
141 u8 *wbuf)
142{
143 struct spi_device *spi = spiadis->spi;
144 struct spi_message msg;
145 struct spi_transfer xfer1, xfer2;
146 u8 *buf, *rx;
147 int ret;
148
149 buf = kmalloc(4, GFP_KERNEL);
150 if (buf == NULL)
151 return -ENOMEM;
152
153 rx = kzalloc(4, GFP_KERNEL);
154 if (rx == NULL) {
155 ret = -ENOMEM;
156 goto err_buf;
157 }
158
159 spi_message_init(&msg);
160 memset(&xfer1, 0, sizeof(xfer1));
161 memset(&xfer2, 0, sizeof(xfer2));
162
163 buf[0] = adr1 | 0x80;
164 buf[1] = *wbuf;
165
166 buf[2] = adr2 | 0x80;
167 buf[3] = *(wbuf + 1);
168
169 xfer1.tx_buf = buf;
170 xfer1.rx_buf = rx;
171 xfer1.len = 2;
172 xfer1.delay_usecs = 9;
173
174 xfer2.tx_buf = buf+2;
175 xfer2.rx_buf = rx+2;
176 xfer2.len = 2;
177
178 spi_message_add_tail(&xfer1, &msg);
179 spi_message_add_tail(&xfer2, &msg);
180
181 ret = spi_sync(spi, &msg);
182 if (ret != 0)
183 dev_warn(&spi->dev, "write data to %#x %#x failed\n",
184 buf[0], buf[2]);
185
186 kfree(rx);
187err_buf:
188 kfree(buf);
189 return ret;
190}
191
192/*-------------------------------------------------------------------------*/
193
194static irqreturn_t adis_irq_thread(int irq, void *dev_id)
195{
196 struct spi_adis16255_data *spiadis = dev_id;
197 int status;
198 u16 value = 0;
199
200 status = spi_adis16255_read_data(spiadis, ADIS_GYRO_OUT, (u8 *)&value);
201 if (status != 0) {
202 dev_warn(&spiadis->spi->dev, "SPI FAILED\n");
203 goto exit;
204 }
205
206 /* perform on new data only... */
207 if (value & 0x8000) {
208 /* delete error and new data bit */
209 value = value & 0x3fff;
210 /* set negative value */
211 if (value & 0x2000)
212 value = value | 0xe000;
213
214 if (likely(spiadis->negative))
215 value = -value;
216
217 spiadis->data = (s16) value;
218 }
219
220exit:
221 return IRQ_HANDLED;
222}
223
224/*-------------------------------------------------------------------------*/
225
226ssize_t adis16255_show_data(struct device *device,
227 struct device_attribute *da,
228 char *buf)
229{
230 struct spi_adis16255_data *spiadis = dev_get_drvdata(device);
231 return snprintf(buf, PAGE_SIZE, "%d\n", spiadis->data);
232}
233DEVICE_ATTR(data, S_IRUGO , adis16255_show_data, NULL);
234
235ssize_t adis16255_show_direction(struct device *device,
236 struct device_attribute *da,
237 char *buf)
238{
239 struct spi_adis16255_data *spiadis = dev_get_drvdata(device);
240 return snprintf(buf, PAGE_SIZE, "%c\n", spiadis->direction);
241}
242DEVICE_ATTR(direction, S_IRUGO , adis16255_show_direction, NULL);
243
244ssize_t adis16255_show_sample_rate(struct device *device,
245 struct device_attribute *da,
246 char *buf)
247{
248 struct spi_adis16255_data *spiadis = dev_get_drvdata(device);
249 int status = 0;
250 u16 value = 0;
251 int ts = 0;
252
253 status = spi_adis16255_read_data(spiadis, ADIS_SMPL_PRD_MSB,
254 (u8 *)&value);
255 if (status != 0)
256 return -EINVAL;
257
258 if (value & 0x80) {
259 /* timebase = 60.54 ms */
260 ts = 60540 * ((0x7f & value) + 1);
261 } else {
262 /* timebase = 1.953 ms */
263 ts = 1953 * ((0x7f & value) + 1);
264 }
265
266 return snprintf(buf, PAGE_SIZE, "%d\n", (1000*1000)/ts);
267}
268DEVICE_ATTR(sample_rate, S_IRUGO , adis16255_show_sample_rate, NULL);
269
270static struct attribute *adis16255_attributes[] = {
271 &dev_attr_data.attr,
272 &dev_attr_direction.attr,
273 &dev_attr_sample_rate.attr,
274 NULL
275};
276
277static const struct attribute_group adis16255_attr_group = {
278 .attrs = adis16255_attributes,
279};
280
281/*-------------------------------------------------------------------------*/
282
283static int spi_adis16255_shutdown(struct spi_adis16255_data *spiadis)
284{
285 u16 value = 0;
286 /* turn sensor off */
287 spi_adis16255_write_data(spiadis,
288 ADIS_SMPL_PRD_MSB, ADIS_SMPL_PRD_LSB,
289 (u8 *)&value);
290 spi_adis16255_write_data(spiadis,
291 ADIS_MSC_CTRL_MSB, ADIS_MSC_CTRL_LSB,
292 (u8 *)&value);
293 return 0;
294}
295
296static int spi_adis16255_bringup(struct spi_adis16255_data *spiadis)
297{
298 int status = 0;
299 u16 value = 0;
300
301 status = spi_adis16255_read_data(spiadis, ADIS_GYRO_SCALE,
302 (u8 *)&value);
303 if (status != 0)
304 goto err;
305 if (value != 0x0800) {
306 dev_warn(&spiadis->spi->dev, "Scale factor is none default "
307 "value (%.4x)\n", value);
308 }
309
310 /* timebase = 1.953 ms, Ns = 0 -> 512 Hz sample rate */
311 value = 0x0001;
312 status = spi_adis16255_write_data(spiadis,
313 ADIS_SMPL_PRD_MSB, ADIS_SMPL_PRD_LSB,
314 (u8 *)&value);
315 if (status != 0)
316 goto err;
317
318 /* start internal self-test */
319 value = 0x0400;
320 status = spi_adis16255_write_data(spiadis,
321 ADIS_MSC_CTRL_MSB, ADIS_MSC_CTRL_LSB,
322 (u8 *)&value);
323 if (status != 0)
324 goto err;
325
326 /* wait 35 ms to finish self-test */
327 msleep(35);
328
329 value = 0x0000;
330 status = spi_adis16255_read_data(spiadis, ADIS_STATUS,
331 (u8 *)&value);
332 if (status != 0)
333 goto err;
334
335 if (value & 0x23) {
336 if (value & 0x20) {
337 dev_warn(&spiadis->spi->dev, "self-test error\n");
338 status = -ENODEV;
339 goto err;
340 } else if (value & 0x3) {
341 dev_warn(&spiadis->spi->dev, "Sensor voltage "
342 "out of range.\n");
343 status = -ENODEV;
344 goto err;
345 }
346 }
347
348 /* set interrupt to active high on DIO0 when data ready */
349 value = 0x0006;
350 status = spi_adis16255_write_data(spiadis,
351 ADIS_MSC_CTRL_MSB, ADIS_MSC_CTRL_LSB,
352 (u8 *)&value);
353 if (status != 0)
354 goto err;
355 return status;
356
357err:
358 spi_adis16255_shutdown(spiadis);
359 return status;
360}
361
362/*-------------------------------------------------------------------------*/
363
364static int __devinit spi_adis16255_probe(struct spi_device *spi)
365{
366
367 struct adis16255_init_data *init_data = spi->dev.platform_data;
368 struct spi_adis16255_data *spiadis;
369 int status = 0;
370
371 spiadis = kzalloc(sizeof(*spiadis), GFP_KERNEL);
372 if (!spiadis)
373 return -ENOMEM;
374
375 spiadis->spi = spi;
376 spiadis->direction = init_data->direction;
377
378 if (init_data->negative)
379 spiadis->negative = 1;
380
381 status = gpio_request(init_data->irq, "adis16255");
382 if (status != 0)
383 goto err;
384
385 status = gpio_direction_input(init_data->irq);
386 if (status != 0)
387 goto gpio_err;
388
389 spiadis->irq = gpio_to_irq(init_data->irq);
390
391 status = request_threaded_irq(spiadis->irq,
392 NULL, adis_irq_thread,
393 IRQF_DISABLED, "adis-driver", spiadis);
394
395 if (status != 0) {
396 dev_err(&spi->dev, "IRQ request failed\n");
397 goto gpio_err;
398 }
399
400 dev_dbg(&spi->dev, "GPIO %d IRQ %d\n", init_data->irq, spiadis->irq);
401
402 dev_set_drvdata(&spi->dev, spiadis);
403 status = sysfs_create_group(&spi->dev.kobj, &adis16255_attr_group);
404 if (status != 0)
405 goto irq_err;
406
407 status = spi_adis16255_bringup(spiadis);
408 if (status != 0)
409 goto sysfs_err;
410
411 dev_info(&spi->dev, "spi_adis16255 driver added!\n");
412
413 return status;
414
415sysfs_err:
416 sysfs_remove_group(&spiadis->spi->dev.kobj, &adis16255_attr_group);
417irq_err:
418 free_irq(spiadis->irq, spiadis);
419gpio_err:
420 gpio_free(init_data->irq);
421err:
422 kfree(spiadis);
423 return status;
424}
425
426static int __devexit spi_adis16255_remove(struct spi_device *spi)
427{
428 struct spi_adis16255_data *spiadis = dev_get_drvdata(&spi->dev);
429
430 spi_adis16255_shutdown(spiadis);
431
432 free_irq(spiadis->irq, spiadis);
433 gpio_free(irq_to_gpio(spiadis->irq));
434
435 sysfs_remove_group(&spiadis->spi->dev.kobj, &adis16255_attr_group);
436
437 kfree(spiadis);
438
439 dev_info(&spi->dev, "spi_adis16255 driver removed!\n");
440 return 0;
441}
442
443static struct spi_driver spi_adis16255_drv = {
444 .driver = {
445 .name = "spi_adis16255",
446 .owner = THIS_MODULE,
447 },
448 .probe = spi_adis16255_probe,
449 .remove = __devexit_p(spi_adis16255_remove),
450};
451
452/*-------------------------------------------------------------------------*/
453
454static int __init spi_adis16255_init(void)
455{
456 return spi_register_driver(&spi_adis16255_drv);
457}
458module_init(spi_adis16255_init);
459
460static void __exit spi_adis16255_exit(void)
461{
462 spi_unregister_driver(&spi_adis16255_drv);
463}
464module_exit(spi_adis16255_exit);
465
466MODULE_AUTHOR("Matthias Brugger");
467MODULE_DESCRIPTION("SPI device driver for ADIS16255 sensor");
468MODULE_LICENSE("GPL");
diff --git a/drivers/staging/adis16255/adis16255.h b/drivers/staging/adis16255/adis16255.h
deleted file mode 100644
index 03e07001bab2..000000000000
--- a/drivers/staging/adis16255/adis16255.h
+++ /dev/null
@@ -1,12 +0,0 @@
1#ifndef ADIS16255_H
2#define ADIS16255_H
3
4#include <linux/types.h>
5
6struct adis16255_init_data {
7 char direction;
8 u8 negative;
9 int irq;
10};
11
12#endif
diff --git a/drivers/staging/asus_oled/asus_oled.c b/drivers/staging/asus_oled/asus_oled.c
index 016c6f7f8630..7bb7da7959a2 100644
--- a/drivers/staging/asus_oled/asus_oled.c
+++ b/drivers/staging/asus_oled/asus_oled.c
@@ -70,7 +70,7 @@ module_param(start_off, uint, 0644);
70MODULE_PARM_DESC(start_off, 70MODULE_PARM_DESC(start_off,
71 "Set to 1 to switch off OLED display after it is attached"); 71 "Set to 1 to switch off OLED display after it is attached");
72 72
73enum oled_pack_mode{ 73enum oled_pack_mode {
74 PACK_MODE_G1, 74 PACK_MODE_G1,
75 PACK_MODE_G50, 75 PACK_MODE_G50,
76 PACK_MODE_LAST 76 PACK_MODE_LAST
diff --git a/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif.c b/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif.c
index c307a5559362..e96662b84ed9 100644
--- a/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif.c
+++ b/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif.c
@@ -876,7 +876,7 @@ HIFAckInterrupt(HIF_DEVICE *device)
876void 876void
877HIFUnMaskInterrupt(HIF_DEVICE *device) 877HIFUnMaskInterrupt(HIF_DEVICE *device)
878{ 878{
879 int ret;; 879 int ret;
880 880
881 AR_DEBUG_ASSERT(device != NULL); 881 AR_DEBUG_ASSERT(device != NULL);
882 AR_DEBUG_ASSERT(device->func != NULL); 882 AR_DEBUG_ASSERT(device->func != NULL);
@@ -1188,7 +1188,7 @@ addHifDevice(struct sdio_func *func)
1188 HIF_DEVICE *hifdevice; 1188 HIF_DEVICE *hifdevice;
1189 AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: addHifDevice\n")); 1189 AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: addHifDevice\n"));
1190 AR_DEBUG_ASSERT(func != NULL); 1190 AR_DEBUG_ASSERT(func != NULL);
1191 hifdevice = (HIF_DEVICE *)kzalloc(sizeof(HIF_DEVICE), GFP_KERNEL); 1191 hifdevice = kzalloc(sizeof(HIF_DEVICE), GFP_KERNEL);
1192 AR_DEBUG_ASSERT(hifdevice != NULL); 1192 AR_DEBUG_ASSERT(hifdevice != NULL);
1193#if HIF_USE_DMA_BOUNCE_BUFFER 1193#if HIF_USE_DMA_BOUNCE_BUFFER
1194 hifdevice->dma_buffer = kmalloc(HIF_DMA_BUFFER_SIZE, GFP_KERNEL); 1194 hifdevice->dma_buffer = kmalloc(HIF_DMA_BUFFER_SIZE, GFP_KERNEL);
diff --git a/drivers/staging/ath6kl/os/linux/ar6000_drv.c b/drivers/staging/ath6kl/os/linux/ar6000_drv.c
index a659f7047373..126a36a2daa6 100644
--- a/drivers/staging/ath6kl/os/linux/ar6000_drv.c
+++ b/drivers/staging/ath6kl/os/linux/ar6000_drv.c
@@ -4439,7 +4439,7 @@ skip_key:
4439 for (i = assoc_req_ie_pos; i < assoc_req_ie_pos + assocReqLen - 4; i++) { 4439 for (i = assoc_req_ie_pos; i < assoc_req_ie_pos + assocReqLen - 4; i++) {
4440 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i])); 4440 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("%2.2x ", assocInfo[i]));
4441 sprintf(pos, "%2.2x", assocInfo[i]); 4441 sprintf(pos, "%2.2x", assocInfo[i]);
4442 pos += 2;; 4442 pos += 2;
4443 } 4443 }
4444 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n")); 4444 AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("\n"));
4445 4445
diff --git a/drivers/staging/autofs/dirhash.c b/drivers/staging/autofs/dirhash.c
index 8f3e2b816129..d3f42c8325f7 100644
--- a/drivers/staging/autofs/dirhash.c
+++ b/drivers/staging/autofs/dirhash.c
@@ -30,7 +30,7 @@ void autofs_update_usage(struct autofs_dirhash *dh,
30 struct autofs_dir_ent *ent) 30 struct autofs_dir_ent *ent)
31{ 31{
32 autofs_delete_usage(ent); /* Unlink from current position */ 32 autofs_delete_usage(ent); /* Unlink from current position */
33 autofs_init_usage(dh,ent); /* Relink at queue tail */ 33 autofs_init_usage(dh, ent); /* Relink at queue tail */
34} 34}
35 35
36struct autofs_dir_ent *autofs_expire(struct super_block *sb, 36struct autofs_dir_ent *autofs_expire(struct super_block *sb,
@@ -45,17 +45,18 @@ struct autofs_dir_ent *autofs_expire(struct super_block *sb,
45 struct path path; 45 struct path path;
46 int umount_ok; 46 int umount_ok;
47 47
48 if ( list_empty(&dh->expiry_head) || sbi->catatonic ) 48 if (list_empty(&dh->expiry_head) || sbi->catatonic)
49 return NULL; /* No entries */ 49 return NULL; /* No entries */
50 /* We keep the list sorted by last_usage and want old stuff */ 50 /* We keep the list sorted by last_usage and want old stuff */
51 ent = list_entry(dh->expiry_head.next, struct autofs_dir_ent, exp); 51 ent = list_entry(dh->expiry_head.next,
52 struct autofs_dir_ent, exp);
52 if (jiffies - ent->last_usage < timeout) 53 if (jiffies - ent->last_usage < timeout)
53 break; 54 break;
54 /* Move to end of list in case expiry isn't desirable */ 55 /* Move to end of list in case expiry isn't desirable */
55 autofs_update_usage(dh, ent); 56 autofs_update_usage(dh, ent);
56 57
57 /* Check to see that entry is expirable */ 58 /* Check to see that entry is expirable */
58 if ( ent->ino < AUTOFS_FIRST_DIR_INO ) 59 if (ent->ino < AUTOFS_FIRST_DIR_INO)
59 return ent; /* Symlinks are always expirable */ 60 return ent; /* Symlinks are always expirable */
60 61
61 /* Get the dentry for the autofs subdirectory */ 62 /* Get the dentry for the autofs subdirectory */
@@ -63,14 +64,15 @@ struct autofs_dir_ent *autofs_expire(struct super_block *sb,
63 64
64 if (!path.dentry) { 65 if (!path.dentry) {
65 /* Should only happen in catatonic mode */ 66 /* Should only happen in catatonic mode */
66 printk("autofs: dentry == NULL but inode range is directory, entry %s\n", ent->name); 67 printk(KERN_DEBUG "autofs: dentry == NULL but inode \
68 range is directory, entry %s\n", ent->name);
67 autofs_delete_usage(ent); 69 autofs_delete_usage(ent);
68 continue; 70 continue;
69 } 71 }
70 72
71 if (!path.dentry->d_inode) { 73 if (!path.dentry->d_inode) {
72 dput(path.dentry); 74 dput(path.dentry);
73 printk("autofs: negative dentry on expiry queue: %s\n", 75 printk(KERN_DEBUG "autofs: negative dentry on expiry queue: %s\n",
74 ent->name); 76 ent->name);
75 autofs_delete_usage(ent); 77 autofs_delete_usage(ent);
76 continue; 78 continue;
@@ -80,14 +82,16 @@ struct autofs_dir_ent *autofs_expire(struct super_block *sb,
80 point to the mounted-on-top root. */ 82 point to the mounted-on-top root. */
81 if (!S_ISDIR(path.dentry->d_inode->i_mode) || 83 if (!S_ISDIR(path.dentry->d_inode->i_mode) ||
82 !d_mountpoint(path.dentry)) { 84 !d_mountpoint(path.dentry)) {
83 DPRINTK(("autofs: not expirable (not a mounted directory): %s\n", ent->name)); 85 DPRINTK(("autofs: not expirable \
86 (not a mounted directory): %s\n", ent->name));
84 continue; 87 continue;
85 } 88 }
86 path.mnt = mnt; 89 path.mnt = mnt;
87 path_get(&path); 90 path_get(&path);
88 if (!follow_down(&path)) { 91 if (!follow_down(&path)) {
89 path_put(&path); 92 path_put(&path);
90 DPRINTK(("autofs: not expirable (not a mounted directory): %s\n", ent->name)); 93 DPRINTK(("autofs: not expirable\
94 (not a mounted directory): %s\n", ent->name));
91 continue; 95 continue;
92 } 96 }
93 while (d_mountpoint(path.dentry) && follow_down(&path)) 97 while (d_mountpoint(path.dentry) && follow_down(&path))
@@ -96,30 +100,37 @@ struct autofs_dir_ent *autofs_expire(struct super_block *sb,
96 path_put(&path); 100 path_put(&path);
97 101
98 if (umount_ok) { 102 if (umount_ok) {
99 DPRINTK(("autofs: signaling expire on %s\n", ent->name)); 103 DPRINTK(("autofs: signaling expire on %s\n",
104 ent->name));
100 return ent; /* Expirable! */ 105 return ent; /* Expirable! */
101 } 106 }
102 DPRINTK(("autofs: didn't expire due to may_umount: %s\n", ent->name)); 107
108 DPRINTK(("autofs: didn't expire due to may_umount: %s\n",
109 ent->name));
103 } 110 }
104 return NULL; /* No expirable entries */ 111 return NULL; /* No expirable entries */
105} 112}
106 113
107void autofs_initialize_hash(struct autofs_dirhash *dh) { 114void autofs_initialize_hash(struct autofs_dirhash *dh)
115{
108 memset(&dh->h, 0, AUTOFS_HASH_SIZE*sizeof(struct autofs_dir_ent *)); 116 memset(&dh->h, 0, AUTOFS_HASH_SIZE*sizeof(struct autofs_dir_ent *));
109 INIT_LIST_HEAD(&dh->expiry_head); 117 INIT_LIST_HEAD(&dh->expiry_head);
110} 118}
111 119
112struct autofs_dir_ent *autofs_hash_lookup(const struct autofs_dirhash *dh, struct qstr *name) 120struct autofs_dir_ent *autofs_hash_lookup(const struct autofs_dirhash *dh,
121 struct qstr *name)
113{ 122{
114 struct autofs_dir_ent *dhn; 123 struct autofs_dir_ent *dhn;
115 124
116 DPRINTK(("autofs_hash_lookup: hash = 0x%08x, name = ", name->hash)); 125 DPRINTK(("autofs_hash_lookup: hash = 0x%08x, name = ", name->hash));
117 autofs_say(name->name,name->len); 126 autofs_say(name->name, name->len);
118 127
119 for ( dhn = dh->h[(unsigned) name->hash % AUTOFS_HASH_SIZE] ; dhn ; dhn = dhn->next ) { 128 for (dhn = dh->h[(unsigned) name->hash % AUTOFS_HASH_SIZE];
120 if ( name->hash == dhn->hash && 129 dhn;
130 dhn = dhn->next) {
131 if (name->hash == dhn->hash &&
121 name->len == dhn->len && 132 name->len == dhn->len &&
122 !memcmp(name->name, dhn->name, name->len) ) 133 !memcmp(name->name, dhn->name, name->len))
123 break; 134 break;
124 } 135 }
125 136
@@ -131,9 +142,9 @@ void autofs_hash_insert(struct autofs_dirhash *dh, struct autofs_dir_ent *ent)
131 struct autofs_dir_ent **dhnp; 142 struct autofs_dir_ent **dhnp;
132 143
133 DPRINTK(("autofs_hash_insert: hash = 0x%08x, name = ", ent->hash)); 144 DPRINTK(("autofs_hash_insert: hash = 0x%08x, name = ", ent->hash));
134 autofs_say(ent->name,ent->len); 145 autofs_say(ent->name, ent->len);
135 146
136 autofs_init_usage(dh,ent); 147 autofs_init_usage(dh, ent);
137 if (ent->dentry) 148 if (ent->dentry)
138 dget(ent->dentry); 149 dget(ent->dentry);
139 150
@@ -141,19 +152,19 @@ void autofs_hash_insert(struct autofs_dirhash *dh, struct autofs_dir_ent *ent)
141 ent->next = *dhnp; 152 ent->next = *dhnp;
142 ent->back = dhnp; 153 ent->back = dhnp;
143 *dhnp = ent; 154 *dhnp = ent;
144 if ( ent->next ) 155 if (ent->next)
145 ent->next->back = &(ent->next); 156 ent->next->back = &(ent->next);
146} 157}
147 158
148void autofs_hash_delete(struct autofs_dir_ent *ent) 159void autofs_hash_delete(struct autofs_dir_ent *ent)
149{ 160{
150 *(ent->back) = ent->next; 161 *(ent->back) = ent->next;
151 if ( ent->next ) 162 if (ent->next)
152 ent->next->back = ent->back; 163 ent->next->back = ent->back;
153 164
154 autofs_delete_usage(ent); 165 autofs_delete_usage(ent);
155 166
156 if ( ent->dentry ) 167 if (ent->dentry)
157 dput(ent->dentry); 168 dput(ent->dentry);
158 kfree(ent->name); 169 kfree(ent->name);
159 kfree(ent); 170 kfree(ent);
@@ -176,37 +187,37 @@ struct autofs_dir_ent *autofs_hash_enum(const struct autofs_dirhash *dh,
176 bucket = (*ptr >> 16) - 1; 187 bucket = (*ptr >> 16) - 1;
177 ecount = *ptr & 0xffff; 188 ecount = *ptr & 0xffff;
178 189
179 if ( bucket < 0 ) { 190 if (bucket < 0)
180 bucket = ecount = 0; 191 bucket = ecount = 0;
181 }
182 192
183 DPRINTK(("autofs_hash_enum: bucket %d, entry %d\n", bucket, ecount)); 193 DPRINTK(("autofs_hash_enum: bucket %d, entry %d\n", bucket, ecount));
184 194
185 ent = last ? last->next : NULL; 195 ent = last ? last->next : NULL;
186 196
187 if ( ent ) { 197 if (ent) {
188 ecount++; 198 ecount++;
189 } else { 199 } else {
190 while ( bucket < AUTOFS_HASH_SIZE ) { 200 while (bucket < AUTOFS_HASH_SIZE) {
191 ent = dh->h[bucket]; 201 ent = dh->h[bucket];
192 for ( i = ecount ; ent && i ; i-- ) 202 for (i = ecount ; ent && i ; i--)
193 ent = ent->next; 203 ent = ent->next;
194 204
195 if (ent) { 205 if (ent) {
196 ecount++; /* Point to *next* entry */ 206 ecount++; /* Point to *next* entry */
197 break; 207 break;
198 } 208 }
199 209
200 bucket++; ecount = 0; 210 bucket++; ecount = 0;
201 } 211 }
202 } 212 }
203 213
204#ifdef DEBUG 214#ifdef DEBUG
205 if ( !ent ) 215 if (!ent)
206 printk("autofs_hash_enum: nothing found\n"); 216 printk(KERN_DEBUG "autofs_hash_enum: nothing found\n");
207 else { 217 else {
208 printk("autofs_hash_enum: found hash %08x, name", ent->hash); 218 printk(KERN_DEBUG "autofs_hash_enum: found hash %08x, name",
209 autofs_say(ent->name,ent->len); 219 ent->hash);
220 autofs_say(ent->name, ent->len);
210 } 221 }
211#endif 222#endif
212 223
@@ -221,9 +232,9 @@ void autofs_hash_dputall(struct autofs_dirhash *dh)
221 int i; 232 int i;
222 struct autofs_dir_ent *ent; 233 struct autofs_dir_ent *ent;
223 234
224 for ( i = 0 ; i < AUTOFS_HASH_SIZE ; i++ ) { 235 for (i = 0 ; i < AUTOFS_HASH_SIZE ; i++) {
225 for ( ent = dh->h[i] ; ent ; ent = ent->next ) { 236 for (ent = dh->h[i] ; ent ; ent = ent->next) {
226 if ( ent->dentry ) { 237 if (ent->dentry) {
227 dput(ent->dentry); 238 dput(ent->dentry);
228 ent->dentry = NULL; 239 ent->dentry = NULL;
229 } 240 }
@@ -238,10 +249,10 @@ void autofs_hash_nuke(struct autofs_sb_info *sbi)
238 int i; 249 int i;
239 struct autofs_dir_ent *ent, *nent; 250 struct autofs_dir_ent *ent, *nent;
240 251
241 for ( i = 0 ; i < AUTOFS_HASH_SIZE ; i++ ) { 252 for (i = 0 ; i < AUTOFS_HASH_SIZE ; i++) {
242 for ( ent = sbi->dirhash.h[i] ; ent ; ent = nent ) { 253 for (ent = sbi->dirhash.h[i] ; ent ; ent = nent) {
243 nent = ent->next; 254 nent = ent->next;
244 if ( ent->dentry ) 255 if (ent->dentry)
245 dput(ent->dentry); 256 dput(ent->dentry);
246 kfree(ent->name); 257 kfree(ent->name);
247 kfree(ent); 258 kfree(ent);
diff --git a/drivers/staging/batman-adv/Kconfig b/drivers/staging/batman-adv/Kconfig
deleted file mode 100644
index 8553f3517454..000000000000
--- a/drivers/staging/batman-adv/Kconfig
+++ /dev/null
@@ -1,26 +0,0 @@
1#
2# B.A.T.M.A.N meshing protocol
3#
4
5config BATMAN_ADV
6 tristate "B.A.T.M.A.N. Advanced Meshing Protocol"
7 depends on NET
8 default n
9 ---help---
10
11 B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is
12 a routing protocol for multi-hop ad-hoc mesh networks. The
13 networks may be wired or wireless. See
14 http://www.open-mesh.org/ for more information and user space
15 tools.
16
17config BATMAN_ADV_DEBUG
18 bool "B.A.T.M.A.N. debugging"
19 depends on BATMAN_ADV != n
20 ---help---
21
22 This is an option for use by developers; most people should
23 say N here. This enables compilation of support for
24 outputting debugging information to the kernel log. The
25 output is controlled via the module parameter debug.
26
diff --git a/drivers/staging/batman-adv/Makefile b/drivers/staging/batman-adv/Makefile
deleted file mode 100644
index 78924283ea74..000000000000
--- a/drivers/staging/batman-adv/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
1#
2# Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3#
4# Marek Lindner, Simon Wunderlich
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of version 2 of the GNU General Public
8# License as published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18# 02110-1301, USA
19#
20
21obj-$(CONFIG_BATMAN_ADV) += batman-adv.o
22batman-adv-y := main.o bat_debugfs.o bat_sysfs.o send.o routing.o soft-interface.o icmp_socket.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o originator.o unicast.o
diff --git a/drivers/staging/batman-adv/README b/drivers/staging/batman-adv/README
deleted file mode 100644
index 7c878bb07f3a..000000000000
--- a/drivers/staging/batman-adv/README
+++ /dev/null
@@ -1,240 +0,0 @@
1[state: 04-09-2010]
2
3BATMAN-ADV
4----------
5
6Batman advanced is a new approach to wireless networking which
7does no longer operate on the IP basis. Unlike the batman daemon,
8which exchanges information using UDP packets and sets routing
9tables, batman-advanced operates on ISO/OSI Layer 2 only and uses
10and routes (or better: bridges) Ethernet Frames. It emulates a
11virtual network switch of all nodes participating. Therefore all
12nodes appear to be link local, thus all higher operating proto-
13cols won't be affected by any changes within the network. You can
14run almost any protocol above batman advanced, prominent examples
15are: IPv4, IPv6, DHCP, IPX.
16
17Batman advanced was implemented as a Linux kernel driver to re-
18duce the overhead to a minimum. It does not depend on any (other)
19network driver, and can be used on wifi as well as ethernet lan,
20vpn, etc ... (anything with ethernet-style layer 2).
21
22CONFIGURATION
23-------------
24
25Load the batman-adv module into your kernel:
26
27# insmod batman-adv.ko
28
29The module is now waiting for activation. You must add some in-
30terfaces on which batman can operate. After loading the module
31batman advanced will scan your systems interfaces to search for
32compatible interfaces. Once found, it will create subfolders in
33the /sys directories of each supported interface, e.g.
34
35# ls /sys/class/net/eth0/batman_adv/
36# iface_status mesh_iface
37
38If an interface does not have the "batman_adv" subfolder it prob-
39ably is not supported. Not supported interfaces are: loopback,
40non-ethernet and batman's own interfaces.
41
42Note: After the module was loaded it will continuously watch for
43new interfaces to verify the compatibility. There is no need to
44reload the module if you plug your USB wifi adapter into your ma-
45chine after batman advanced was initially loaded.
46
47To activate a given interface simply write "bat0" into its
48"mesh_iface" file inside the batman_adv subfolder:
49
50# echo bat0 > /sys/class/net/eth0/batman_adv/mesh_iface
51
52Repeat this step for all interfaces you wish to add. Now batman
53starts using/broadcasting on this/these interface(s).
54
55By reading the "iface_status" file you can check its status:
56
57# cat /sys/class/net/eth0/batman_adv/iface_status
58# active
59
60To deactivate an interface you have to write "none" into its
61"mesh_iface" file:
62
63# echo none > /sys/class/net/eth0/batman_adv/mesh_iface
64
65
66All mesh wide settings can be found in batman's own interface
67folder:
68
69# ls /sys/class/net/bat0/mesh/
70# aggregated_ogms bonding orig_interval vis_mode
71
72
73There is a special folder for debugging informations:
74
75# ls /sys/kernel/debug/batman_adv/bat0/
76# originators socket transtable_global transtable_local
77# vis_data
78
79
80Some of the files contain all sort of status information regard-
81ing the mesh network. For example, you can view the table of
82originators (mesh participants) with:
83
84# cat /sys/kernel/debug/batman_adv/bat0/originators
85
86Other files allow to change batman's behaviour to better fit your
87requirements. For instance, you can check the current originator
88interval (value in milliseconds which determines how often batman
89sends its broadcast packets):
90
91# cat /sys/class/net/bat0/mesh/orig_interval
92# 1000
93
94and also change its value:
95
96# echo 3000 > /sys/class/net/bat0/mesh/orig_interval
97
98In very mobile scenarios, you might want to adjust the originator
99interval to a lower value. This will make the mesh more respon-
100sive to topology changes, but will also increase the overhead.
101
102
103USAGE
104-----
105
106To make use of your newly created mesh, batman advanced provides
107a new interface "bat0" which you should use from this point on.
108All interfaces added to batman advanced are not relevant any
109longer because batman handles them for you. Basically, one "hands
110over" the data by using the batman interface and batman will make
111sure it reaches its destination.
112
113The "bat0" interface can be used like any other regular inter-
114face. It needs an IP address which can be either statically con-
115figured or dynamically (by using DHCP or similar services):
116
117# NodeA: ifconfig bat0 192.168.0.1
118# NodeB: ifconfig bat0 192.168.0.2
119# NodeB: ping 192.168.0.1
120
121Note: In order to avoid problems remove all IP addresses previ-
122ously assigned to interfaces now used by batman advanced, e.g.
123
124# ifconfig eth0 0.0.0.0
125
126
127VISUALIZATION
128-------------
129
130If you want topology visualization, at least one mesh node must
131be configured as VIS-server:
132
133# echo "server" > /sys/class/net/bat0/mesh/vis_mode
134
135Each node is either configured as "server" or as "client" (de-
136fault: "client"). Clients send their topology data to the server
137next to them, and server synchronize with other servers. If there
138is no server configured (default) within the mesh, no topology
139information will be transmitted. With these "synchronizing
140servers", there can be 1 or more vis servers sharing the same (or
141at least very similar) data.
142
143When configured as server, you can get a topology snapshot of
144your mesh:
145
146# cat /sys/kernel/debug/batman_adv/bat0/vis_data
147
148This raw output is intended to be easily parsable and convertable
149with other tools. Have a look at the batctl README if you want a
150vis output in dot or json format for instance and how those out-
151puts could then be visualised in an image.
152
153The raw format consists of comma separated values per entry where
154each entry is giving information about a certain source inter-
155face. Each entry can/has to have the following values:
156-> "mac" - mac address of an originator's source interface
157 (each line begins with it)
158-> "TQ mac value" - src mac's link quality towards mac address
159 of a neighbor originator's interface which
160 is being used for routing
161-> "HNA mac" - HNA announced by source mac
162-> "PRIMARY" - this is a primary interface
163-> "SEC mac" - secondary mac address of source
164 (requires preceding PRIMARY)
165
166The TQ value has a range from 4 to 255 with 255 being the best.
167The HNA entries are showing which hosts are connected to the mesh
168via bat0 or being bridged into the mesh network. The PRIMARY/SEC
169values are only applied on primary interfaces
170
171
172LOGGING/DEBUGGING
173-----------------
174
175All error messages, warnings and information messages are sent to
176the kernel log. Depending on your operating system distribution
177this can be read in one of a number of ways. Try using the com-
178mands: dmesg, logread, or looking in the files /var/log/kern.log
179or /var/log/syslog. All batman-adv messages are prefixed with
180"batman-adv:" So to see just these messages try
181
182# dmesg | grep batman-adv
183
184When investigating problems with your mesh network it is some-
185times necessary to see more detail debug messages. This must be
186enabled when compiling the batman-adv module. When building bat-
187man-adv as part of kernel, use "make menuconfig" and enable the
188option "B.A.T.M.A.N. debugging".
189
190Those additional debug messages can be accessed using a special
191file in debugfs
192
193# cat /sys/kernel/debug/batman_adv/bat0/log
194
195The additional debug output is by default disabled. It can be en-
196abled during run time. Following log_levels are defined:
197
1980 - All debug output disabled
1991 - Enable messages related to routing / flooding / broadcasting
2002 - Enable route or hna added / changed / deleted
2013 - Enable all messages
202
203The debug output can be changed at runtime using the file
204/sys/class/net/bat0/mesh/log_level. e.g.
205
206# echo 2 > /sys/class/net/bat0/mesh/log_level
207
208will enable debug messages for when routes or HNAs change.
209
210
211BATCTL
212------
213
214As batman advanced operates on layer 2 all hosts participating in
215the virtual switch are completely transparent for all protocols
216above layer 2. Therefore the common diagnosis tools do not work
217as expected. To overcome these problems batctl was created. At
218the moment the batctl contains ping, traceroute, tcpdump and
219interfaces to the kernel module settings.
220
221For more information, please see the manpage (man batctl).
222
223batctl is available on http://www.open-mesh.org/
224
225
226CONTACT
227-------
228
229Please send us comments, experiences, questions, anything :)
230
231IRC: #batman on irc.freenode.org
232Mailing-list: b.a.t.m.a.n@b.a.t.m.a.n@lists.open-mesh.org
233 (optional subscription at
234 https://lists.open-mesh.org/mm/listinfo/b.a.t.m.a.n)
235
236You can also contact the Authors:
237
238Marek Lindner <lindner_marek@yahoo.de>
239Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
240
diff --git a/drivers/staging/batman-adv/TODO b/drivers/staging/batman-adv/TODO
deleted file mode 100644
index 11c384f8b063..000000000000
--- a/drivers/staging/batman-adv/TODO
+++ /dev/null
@@ -1,14 +0,0 @@
1 * remove own list functionality from hash
2 * use hlist_head, hlist_node in hash
3 * don't use callbacks for compare+choose in hash
4 * think about more efficient ways instead of abstraction of hash
5 * Request a new review
6 * Process the comments from the review
7 * Move into mainline proper
8
9Please send all patches to:
10 Marek Lindner <lindner_marek@yahoo.de>
11 Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
12 Andrew Lunn <andrew@lunn.ch>
13 b.a.t.m.a.n@lists.open-mesh.org
14 Greg Kroah-Hartman <gregkh@suse.de>
diff --git a/drivers/staging/batman-adv/aggregation.c b/drivers/staging/batman-adv/aggregation.c
deleted file mode 100644
index 08624d44e231..000000000000
--- a/drivers/staging/batman-adv/aggregation.c
+++ /dev/null
@@ -1,275 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "aggregation.h"
24#include "send.h"
25#include "routing.h"
26
27/* calculate the size of the hna information for a given packet */
28static int hna_len(struct batman_packet *batman_packet)
29{
30 return batman_packet->num_hna * ETH_ALEN;
31}
32
33/* return true if new_packet can be aggregated with forw_packet */
34static bool can_aggregate_with(struct batman_packet *new_batman_packet,
35 int packet_len,
36 unsigned long send_time,
37 bool directlink,
38 struct batman_if *if_incoming,
39 struct forw_packet *forw_packet)
40{
41 struct batman_packet *batman_packet =
42 (struct batman_packet *)forw_packet->skb->data;
43 int aggregated_bytes = forw_packet->packet_len + packet_len;
44
45 /**
46 * we can aggregate the current packet to this aggregated packet
47 * if:
48 *
49 * - the send time is within our MAX_AGGREGATION_MS time
50 * - the resulting packet wont be bigger than
51 * MAX_AGGREGATION_BYTES
52 */
53
54 if (time_before(send_time, forw_packet->send_time) &&
55 time_after_eq(send_time + msecs_to_jiffies(MAX_AGGREGATION_MS),
56 forw_packet->send_time) &&
57 (aggregated_bytes <= MAX_AGGREGATION_BYTES)) {
58
59 /**
60 * check aggregation compatibility
61 * -> direct link packets are broadcasted on
62 * their interface only
63 * -> aggregate packet if the current packet is
64 * a "global" packet as well as the base
65 * packet
66 */
67
68 /* packets without direct link flag and high TTL
69 * are flooded through the net */
70 if ((!directlink) &&
71 (!(batman_packet->flags & DIRECTLINK)) &&
72 (batman_packet->ttl != 1) &&
73
74 /* own packets originating non-primary
75 * interfaces leave only that interface */
76 ((!forw_packet->own) ||
77 (forw_packet->if_incoming->if_num == 0)))
78 return true;
79
80 /* if the incoming packet is sent via this one
81 * interface only - we still can aggregate */
82 if ((directlink) &&
83 (new_batman_packet->ttl == 1) &&
84 (forw_packet->if_incoming == if_incoming) &&
85
86 /* packets from direct neighbors or
87 * own secondary interface packets
88 * (= secondary interface packets in general) */
89 (batman_packet->flags & DIRECTLINK ||
90 (forw_packet->own &&
91 forw_packet->if_incoming->if_num != 0)))
92 return true;
93 }
94
95 return false;
96}
97
98#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
99/* create a new aggregated packet and add this packet to it */
100static void new_aggregated_packet(unsigned char *packet_buff, int packet_len,
101 unsigned long send_time, bool direct_link,
102 struct batman_if *if_incoming,
103 int own_packet)
104{
105 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
106 struct forw_packet *forw_packet_aggr;
107 unsigned long flags;
108 unsigned char *skb_buff;
109
110 /* own packet should always be scheduled */
111 if (!own_packet) {
112 if (!atomic_dec_not_zero(&bat_priv->batman_queue_left)) {
113 bat_dbg(DBG_BATMAN, bat_priv,
114 "batman packet queue full\n");
115 return;
116 }
117 }
118
119 forw_packet_aggr = kmalloc(sizeof(struct forw_packet), GFP_ATOMIC);
120 if (!forw_packet_aggr) {
121 if (!own_packet)
122 atomic_inc(&bat_priv->batman_queue_left);
123 return;
124 }
125
126 if ((atomic_read(&bat_priv->aggregation_enabled)) &&
127 (packet_len < MAX_AGGREGATION_BYTES))
128 forw_packet_aggr->skb = dev_alloc_skb(MAX_AGGREGATION_BYTES +
129 sizeof(struct ethhdr));
130 else
131 forw_packet_aggr->skb = dev_alloc_skb(packet_len +
132 sizeof(struct ethhdr));
133
134 if (!forw_packet_aggr->skb) {
135 if (!own_packet)
136 atomic_inc(&bat_priv->batman_queue_left);
137 kfree(forw_packet_aggr);
138 return;
139 }
140 skb_reserve(forw_packet_aggr->skb, sizeof(struct ethhdr));
141
142 INIT_HLIST_NODE(&forw_packet_aggr->list);
143
144 skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
145 forw_packet_aggr->packet_len = packet_len;
146 memcpy(skb_buff, packet_buff, packet_len);
147
148 forw_packet_aggr->own = own_packet;
149 forw_packet_aggr->if_incoming = if_incoming;
150 forw_packet_aggr->num_packets = 0;
151 forw_packet_aggr->direct_link_flags = 0;
152 forw_packet_aggr->send_time = send_time;
153
154 /* save packet direct link flag status */
155 if (direct_link)
156 forw_packet_aggr->direct_link_flags |= 1;
157
158 /* add new packet to packet list */
159 spin_lock_irqsave(&bat_priv->forw_bat_list_lock, flags);
160 hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list);
161 spin_unlock_irqrestore(&bat_priv->forw_bat_list_lock, flags);
162
163 /* start timer for this packet */
164 INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
165 send_outstanding_bat_packet);
166 queue_delayed_work(bat_event_workqueue,
167 &forw_packet_aggr->delayed_work,
168 send_time - jiffies);
169}
170
171/* aggregate a new packet into the existing aggregation */
172static void aggregate(struct forw_packet *forw_packet_aggr,
173 unsigned char *packet_buff,
174 int packet_len,
175 bool direct_link)
176{
177 unsigned char *skb_buff;
178
179 skb_buff = skb_put(forw_packet_aggr->skb, packet_len);
180 memcpy(skb_buff, packet_buff, packet_len);
181 forw_packet_aggr->packet_len += packet_len;
182 forw_packet_aggr->num_packets++;
183
184 /* save packet direct link flag status */
185 if (direct_link)
186 forw_packet_aggr->direct_link_flags |=
187 (1 << forw_packet_aggr->num_packets);
188}
189
190void add_bat_packet_to_list(struct bat_priv *bat_priv,
191 unsigned char *packet_buff, int packet_len,
192 struct batman_if *if_incoming, char own_packet,
193 unsigned long send_time)
194{
195 /**
196 * _aggr -> pointer to the packet we want to aggregate with
197 * _pos -> pointer to the position in the queue
198 */
199 struct forw_packet *forw_packet_aggr = NULL, *forw_packet_pos = NULL;
200 struct hlist_node *tmp_node;
201 struct batman_packet *batman_packet =
202 (struct batman_packet *)packet_buff;
203 bool direct_link = batman_packet->flags & DIRECTLINK ? 1 : 0;
204 unsigned long flags;
205
206 /* find position for the packet in the forward queue */
207 spin_lock_irqsave(&bat_priv->forw_bat_list_lock, flags);
208 /* own packets are not to be aggregated */
209 if ((atomic_read(&bat_priv->aggregation_enabled)) && (!own_packet)) {
210 hlist_for_each_entry(forw_packet_pos, tmp_node,
211 &bat_priv->forw_bat_list, list) {
212 if (can_aggregate_with(batman_packet,
213 packet_len,
214 send_time,
215 direct_link,
216 if_incoming,
217 forw_packet_pos)) {
218 forw_packet_aggr = forw_packet_pos;
219 break;
220 }
221 }
222 }
223
224 /* nothing to aggregate with - either aggregation disabled or no
225 * suitable aggregation packet found */
226 if (forw_packet_aggr == NULL) {
227 /* the following section can run without the lock */
228 spin_unlock_irqrestore(&bat_priv->forw_bat_list_lock, flags);
229
230 /**
231 * if we could not aggregate this packet with one of the others
232 * we hold it back for a while, so that it might be aggregated
233 * later on
234 */
235 if ((!own_packet) &&
236 (atomic_read(&bat_priv->aggregation_enabled)))
237 send_time += msecs_to_jiffies(MAX_AGGREGATION_MS);
238
239 new_aggregated_packet(packet_buff, packet_len,
240 send_time, direct_link,
241 if_incoming, own_packet);
242 } else {
243 aggregate(forw_packet_aggr,
244 packet_buff, packet_len,
245 direct_link);
246 spin_unlock_irqrestore(&bat_priv->forw_bat_list_lock, flags);
247 }
248}
249
250/* unpack the aggregated packets and process them one by one */
251void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff,
252 int packet_len, struct batman_if *if_incoming)
253{
254 struct batman_packet *batman_packet;
255 int buff_pos = 0;
256 unsigned char *hna_buff;
257
258 batman_packet = (struct batman_packet *)packet_buff;
259
260 do {
261 /* network to host order for our 32bit seqno, and the
262 orig_interval. */
263 batman_packet->seqno = ntohl(batman_packet->seqno);
264
265 hna_buff = packet_buff + buff_pos + BAT_PACKET_LEN;
266 receive_bat_packet(ethhdr, batman_packet,
267 hna_buff, hna_len(batman_packet),
268 if_incoming);
269
270 buff_pos += BAT_PACKET_LEN + hna_len(batman_packet);
271 batman_packet = (struct batman_packet *)
272 (packet_buff + buff_pos);
273 } while (aggregated_packet(buff_pos, packet_len,
274 batman_packet->num_hna));
275}
diff --git a/drivers/staging/batman-adv/aggregation.h b/drivers/staging/batman-adv/aggregation.h
deleted file mode 100644
index 71a91b3da913..000000000000
--- a/drivers/staging/batman-adv/aggregation.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_AGGREGATION_H_
23#define _NET_BATMAN_ADV_AGGREGATION_H_
24
25#include "main.h"
26
27/* is there another aggregated packet here? */
28static inline int aggregated_packet(int buff_pos, int packet_len, int num_hna)
29{
30 int next_buff_pos = buff_pos + BAT_PACKET_LEN + (num_hna * ETH_ALEN);
31
32 return (next_buff_pos <= packet_len) &&
33 (next_buff_pos <= MAX_AGGREGATION_BYTES);
34}
35
36void add_bat_packet_to_list(struct bat_priv *bat_priv,
37 unsigned char *packet_buff, int packet_len,
38 struct batman_if *if_incoming, char own_packet,
39 unsigned long send_time);
40void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff,
41 int packet_len, struct batman_if *if_incoming);
42
43#endif /* _NET_BATMAN_ADV_AGGREGATION_H_ */
diff --git a/drivers/staging/batman-adv/bat_debugfs.c b/drivers/staging/batman-adv/bat_debugfs.c
deleted file mode 100644
index 57f84a9f8234..000000000000
--- a/drivers/staging/batman-adv/bat_debugfs.c
+++ /dev/null
@@ -1,343 +0,0 @@
1/*
2 * Copyright (C) 2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23
24#include <linux/debugfs.h>
25
26#include "bat_debugfs.h"
27#include "translation-table.h"
28#include "originator.h"
29#include "hard-interface.h"
30#include "vis.h"
31#include "icmp_socket.h"
32
33static struct dentry *bat_debugfs;
34
35#ifdef CONFIG_BATMAN_ADV_DEBUG
36#define LOG_BUFF_MASK (log_buff_len-1)
37#define LOG_BUFF(idx) (debug_log->log_buff[(idx) & LOG_BUFF_MASK])
38
39static int log_buff_len = LOG_BUF_LEN;
40
41static void emit_log_char(struct debug_log *debug_log, char c)
42{
43 LOG_BUFF(debug_log->log_end) = c;
44 debug_log->log_end++;
45
46 if (debug_log->log_end - debug_log->log_start > log_buff_len)
47 debug_log->log_start = debug_log->log_end - log_buff_len;
48}
49
50static int fdebug_log(struct debug_log *debug_log, char *fmt, ...)
51{
52 int printed_len;
53 va_list args;
54 static char debug_log_buf[256];
55 char *p;
56 unsigned long flags;
57
58 if (!debug_log)
59 return 0;
60
61 spin_lock_irqsave(&debug_log->lock, flags);
62 va_start(args, fmt);
63 printed_len = vscnprintf(debug_log_buf, sizeof(debug_log_buf),
64 fmt, args);
65 va_end(args);
66
67 for (p = debug_log_buf; *p != 0; p++)
68 emit_log_char(debug_log, *p);
69
70 spin_unlock_irqrestore(&debug_log->lock, flags);
71
72 wake_up(&debug_log->queue_wait);
73
74 return 0;
75}
76
77int debug_log(struct bat_priv *bat_priv, char *fmt, ...)
78{
79 va_list args;
80 char tmp_log_buf[256];
81
82 va_start(args, fmt);
83 vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args);
84 fdebug_log(bat_priv->debug_log, "[%10u] %s",
85 (jiffies / HZ), tmp_log_buf);
86 va_end(args);
87
88 return 0;
89}
90
91static int log_open(struct inode *inode, struct file *file)
92{
93 nonseekable_open(inode, file);
94 file->private_data = inode->i_private;
95 inc_module_count();
96 return 0;
97}
98
99static int log_release(struct inode *inode, struct file *file)
100{
101 dec_module_count();
102 return 0;
103}
104
105static ssize_t log_read(struct file *file, char __user *buf,
106 size_t count, loff_t *ppos)
107{
108 struct bat_priv *bat_priv = file->private_data;
109 struct debug_log *debug_log = bat_priv->debug_log;
110 int error, i = 0;
111 char c;
112 unsigned long flags;
113
114 if ((file->f_flags & O_NONBLOCK) &&
115 !(debug_log->log_end - debug_log->log_start))
116 return -EAGAIN;
117
118 if ((!buf) || (count < 0))
119 return -EINVAL;
120
121 if (count == 0)
122 return 0;
123
124 if (!access_ok(VERIFY_WRITE, buf, count))
125 return -EFAULT;
126
127 error = wait_event_interruptible(debug_log->queue_wait,
128 (debug_log->log_start - debug_log->log_end));
129
130 if (error)
131 return error;
132
133 spin_lock_irqsave(&debug_log->lock, flags);
134
135 while ((!error) && (i < count) &&
136 (debug_log->log_start != debug_log->log_end)) {
137 c = LOG_BUFF(debug_log->log_start);
138
139 debug_log->log_start++;
140
141 spin_unlock_irqrestore(&debug_log->lock, flags);
142
143 error = __put_user(c, buf);
144
145 spin_lock_irqsave(&debug_log->lock, flags);
146
147 buf++;
148 i++;
149
150 }
151
152 spin_unlock_irqrestore(&debug_log->lock, flags);
153
154 if (!error)
155 return i;
156
157 return error;
158}
159
160static unsigned int log_poll(struct file *file, poll_table *wait)
161{
162 struct bat_priv *bat_priv = file->private_data;
163 struct debug_log *debug_log = bat_priv->debug_log;
164
165 poll_wait(file, &debug_log->queue_wait, wait);
166
167 if (debug_log->log_end - debug_log->log_start)
168 return POLLIN | POLLRDNORM;
169
170 return 0;
171}
172
173static const struct file_operations log_fops = {
174 .open = log_open,
175 .release = log_release,
176 .read = log_read,
177 .poll = log_poll,
178 .llseek = no_llseek,
179};
180
181static int debug_log_setup(struct bat_priv *bat_priv)
182{
183 struct dentry *d;
184
185 if (!bat_priv->debug_dir)
186 goto err;
187
188 bat_priv->debug_log = kzalloc(sizeof(struct debug_log), GFP_ATOMIC);
189 if (!bat_priv->debug_log)
190 goto err;
191
192 spin_lock_init(&bat_priv->debug_log->lock);
193 init_waitqueue_head(&bat_priv->debug_log->queue_wait);
194
195 d = debugfs_create_file("log", S_IFREG | S_IRUSR,
196 bat_priv->debug_dir, bat_priv, &log_fops);
197 if (d)
198 goto err;
199
200 return 0;
201
202err:
203 return 1;
204}
205
206static void debug_log_cleanup(struct bat_priv *bat_priv)
207{
208 kfree(bat_priv->debug_log);
209 bat_priv->debug_log = NULL;
210}
211#else /* CONFIG_BATMAN_ADV_DEBUG */
212static int debug_log_setup(struct bat_priv *bat_priv)
213{
214 bat_priv->debug_log = NULL;
215 return 0;
216}
217
218static void debug_log_cleanup(struct bat_priv *bat_priv)
219{
220 return;
221}
222#endif
223
224static int originators_open(struct inode *inode, struct file *file)
225{
226 struct net_device *net_dev = (struct net_device *)inode->i_private;
227 return single_open(file, orig_seq_print_text, net_dev);
228}
229
230static int transtable_global_open(struct inode *inode, struct file *file)
231{
232 struct net_device *net_dev = (struct net_device *)inode->i_private;
233 return single_open(file, hna_global_seq_print_text, net_dev);
234}
235
236static int transtable_local_open(struct inode *inode, struct file *file)
237{
238 struct net_device *net_dev = (struct net_device *)inode->i_private;
239 return single_open(file, hna_local_seq_print_text, net_dev);
240}
241
242static int vis_data_open(struct inode *inode, struct file *file)
243{
244 struct net_device *net_dev = (struct net_device *)inode->i_private;
245 return single_open(file, vis_seq_print_text, net_dev);
246}
247
248struct bat_debuginfo {
249 struct attribute attr;
250 const struct file_operations fops;
251};
252
253#define BAT_DEBUGINFO(_name, _mode, _open) \
254struct bat_debuginfo bat_debuginfo_##_name = { \
255 .attr = { .name = __stringify(_name), \
256 .mode = _mode, }, \
257 .fops = { .owner = THIS_MODULE, \
258 .open = _open, \
259 .read = seq_read, \
260 .llseek = seq_lseek, \
261 .release = single_release, \
262 } \
263};
264
265static BAT_DEBUGINFO(originators, S_IRUGO, originators_open);
266static BAT_DEBUGINFO(transtable_global, S_IRUGO, transtable_global_open);
267static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open);
268static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open);
269
270static struct bat_debuginfo *mesh_debuginfos[] = {
271 &bat_debuginfo_originators,
272 &bat_debuginfo_transtable_global,
273 &bat_debuginfo_transtable_local,
274 &bat_debuginfo_vis_data,
275 NULL,
276};
277
278void debugfs_init(void)
279{
280 bat_debugfs = debugfs_create_dir(DEBUGFS_BAT_SUBDIR, NULL);
281 if (bat_debugfs == ERR_PTR(-ENODEV))
282 bat_debugfs = NULL;
283}
284
285void debugfs_destroy(void)
286{
287 if (bat_debugfs) {
288 debugfs_remove_recursive(bat_debugfs);
289 bat_debugfs = NULL;
290 }
291}
292
293int debugfs_add_meshif(struct net_device *dev)
294{
295 struct bat_priv *bat_priv = netdev_priv(dev);
296 struct bat_debuginfo **bat_debug;
297 struct dentry *file;
298
299 if (!bat_debugfs)
300 goto out;
301
302 bat_priv->debug_dir = debugfs_create_dir(dev->name, bat_debugfs);
303 if (!bat_priv->debug_dir)
304 goto out;
305
306 bat_socket_setup(bat_priv);
307 debug_log_setup(bat_priv);
308
309 for (bat_debug = mesh_debuginfos; *bat_debug; ++bat_debug) {
310 file = debugfs_create_file(((*bat_debug)->attr).name,
311 S_IFREG | ((*bat_debug)->attr).mode,
312 bat_priv->debug_dir,
313 dev, &(*bat_debug)->fops);
314 if (!file) {
315 bat_err(dev, "Can't add debugfs file: %s/%s\n",
316 dev->name, ((*bat_debug)->attr).name);
317 goto rem_attr;
318 }
319 }
320
321 return 0;
322rem_attr:
323 debugfs_remove_recursive(bat_priv->debug_dir);
324 bat_priv->debug_dir = NULL;
325out:
326#ifdef CONFIG_DEBUG_FS
327 return -ENOMEM;
328#else
329 return 0;
330#endif /* CONFIG_DEBUG_FS */
331}
332
333void debugfs_del_meshif(struct net_device *dev)
334{
335 struct bat_priv *bat_priv = netdev_priv(dev);
336
337 debug_log_cleanup(bat_priv);
338
339 if (bat_debugfs) {
340 debugfs_remove_recursive(bat_priv->debug_dir);
341 bat_priv->debug_dir = NULL;
342 }
343}
diff --git a/drivers/staging/batman-adv/bat_debugfs.h b/drivers/staging/batman-adv/bat_debugfs.h
deleted file mode 100644
index 72df532b7d5f..000000000000
--- a/drivers/staging/batman-adv/bat_debugfs.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 * Copyright (C) 2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22
23#ifndef _NET_BATMAN_ADV_DEBUGFS_H_
24#define _NET_BATMAN_ADV_DEBUGFS_H_
25
26#define DEBUGFS_BAT_SUBDIR "batman_adv"
27
28void debugfs_init(void);
29void debugfs_destroy(void);
30int debugfs_add_meshif(struct net_device *dev);
31void debugfs_del_meshif(struct net_device *dev);
32
33#endif /* _NET_BATMAN_ADV_DEBUGFS_H_ */
diff --git a/drivers/staging/batman-adv/bat_sysfs.c b/drivers/staging/batman-adv/bat_sysfs.c
deleted file mode 100644
index bc17fb816300..000000000000
--- a/drivers/staging/batman-adv/bat_sysfs.c
+++ /dev/null
@@ -1,558 +0,0 @@
1/*
2 * Copyright (C) 2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "bat_sysfs.h"
24#include "translation-table.h"
25#include "originator.h"
26#include "hard-interface.h"
27#include "vis.h"
28
29#define to_dev(obj) container_of(obj, struct device, kobj)
30
31#define BAT_ATTR(_name, _mode, _show, _store) \
32struct bat_attribute bat_attr_##_name = { \
33 .attr = {.name = __stringify(_name), \
34 .mode = _mode }, \
35 .show = _show, \
36 .store = _store, \
37};
38
39static ssize_t show_aggr_ogms(struct kobject *kobj, struct attribute *attr,
40 char *buff)
41{
42 struct device *dev = to_dev(kobj->parent);
43 struct bat_priv *bat_priv = netdev_priv(to_net_dev(dev));
44 int aggr_status = atomic_read(&bat_priv->aggregation_enabled);
45
46 return sprintf(buff, "%s\n",
47 aggr_status == 0 ? "disabled" : "enabled");
48}
49
50static ssize_t store_aggr_ogms(struct kobject *kobj, struct attribute *attr,
51 char *buff, size_t count)
52{
53 struct device *dev = to_dev(kobj->parent);
54 struct net_device *net_dev = to_net_dev(dev);
55 struct bat_priv *bat_priv = netdev_priv(net_dev);
56 int aggr_tmp = -1;
57
58 if (((count == 2) && (buff[0] == '1')) ||
59 (strncmp(buff, "enable", 6) == 0))
60 aggr_tmp = 1;
61
62 if (((count == 2) && (buff[0] == '0')) ||
63 (strncmp(buff, "disable", 7) == 0))
64 aggr_tmp = 0;
65
66 if (aggr_tmp < 0) {
67 if (buff[count - 1] == '\n')
68 buff[count - 1] = '\0';
69
70 bat_info(net_dev,
71 "Invalid parameter for 'aggregate OGM' setting"
72 "received: %s\n", buff);
73 return -EINVAL;
74 }
75
76 if (atomic_read(&bat_priv->aggregation_enabled) == aggr_tmp)
77 return count;
78
79 bat_info(net_dev, "Changing aggregation from: %s to: %s\n",
80 atomic_read(&bat_priv->aggregation_enabled) == 1 ?
81 "enabled" : "disabled", aggr_tmp == 1 ? "enabled" :
82 "disabled");
83
84 atomic_set(&bat_priv->aggregation_enabled, (unsigned)aggr_tmp);
85 return count;
86}
87
88static ssize_t show_bond(struct kobject *kobj, struct attribute *attr,
89 char *buff)
90{
91 struct device *dev = to_dev(kobj->parent);
92 struct bat_priv *bat_priv = netdev_priv(to_net_dev(dev));
93 int bond_status = atomic_read(&bat_priv->bonding_enabled);
94
95 return sprintf(buff, "%s\n",
96 bond_status == 0 ? "disabled" : "enabled");
97}
98
99static ssize_t store_bond(struct kobject *kobj, struct attribute *attr,
100 char *buff, size_t count)
101{
102 struct device *dev = to_dev(kobj->parent);
103 struct net_device *net_dev = to_net_dev(dev);
104 struct bat_priv *bat_priv = netdev_priv(net_dev);
105 int bonding_enabled_tmp = -1;
106
107 if (((count == 2) && (buff[0] == '1')) ||
108 (strncmp(buff, "enable", 6) == 0))
109 bonding_enabled_tmp = 1;
110
111 if (((count == 2) && (buff[0] == '0')) ||
112 (strncmp(buff, "disable", 7) == 0))
113 bonding_enabled_tmp = 0;
114
115 if (bonding_enabled_tmp < 0) {
116 if (buff[count - 1] == '\n')
117 buff[count - 1] = '\0';
118
119 bat_err(net_dev,
120 "Invalid parameter for 'bonding' setting received: "
121 "%s\n", buff);
122 return -EINVAL;
123 }
124
125 if (atomic_read(&bat_priv->bonding_enabled) == bonding_enabled_tmp)
126 return count;
127
128 bat_info(net_dev, "Changing bonding from: %s to: %s\n",
129 atomic_read(&bat_priv->bonding_enabled) == 1 ?
130 "enabled" : "disabled",
131 bonding_enabled_tmp == 1 ? "enabled" : "disabled");
132
133 atomic_set(&bat_priv->bonding_enabled, (unsigned)bonding_enabled_tmp);
134 return count;
135}
136
137static ssize_t show_frag(struct kobject *kobj, struct attribute *attr,
138 char *buff)
139{
140 struct device *dev = to_dev(kobj->parent);
141 struct bat_priv *bat_priv = netdev_priv(to_net_dev(dev));
142 int frag_status = atomic_read(&bat_priv->frag_enabled);
143
144 return sprintf(buff, "%s\n",
145 frag_status == 0 ? "disabled" : "enabled");
146}
147
148static ssize_t store_frag(struct kobject *kobj, struct attribute *attr,
149 char *buff, size_t count)
150{
151 struct device *dev = to_dev(kobj->parent);
152 struct net_device *net_dev = to_net_dev(dev);
153 struct bat_priv *bat_priv = netdev_priv(net_dev);
154 int frag_enabled_tmp = -1;
155
156 if (((count == 2) && (buff[0] == '1')) ||
157 (strncmp(buff, "enable", 6) == 0))
158 frag_enabled_tmp = 1;
159
160 if (((count == 2) && (buff[0] == '0')) ||
161 (strncmp(buff, "disable", 7) == 0))
162 frag_enabled_tmp = 0;
163
164 if (frag_enabled_tmp < 0) {
165 if (buff[count - 1] == '\n')
166 buff[count - 1] = '\0';
167
168 bat_err(net_dev,
169 "Invalid parameter for 'fragmentation' setting on mesh"
170 "received: %s\n", buff);
171 return -EINVAL;
172 }
173
174 if (atomic_read(&bat_priv->frag_enabled) == frag_enabled_tmp)
175 return count;
176
177 bat_info(net_dev, "Changing fragmentation from: %s to: %s\n",
178 atomic_read(&bat_priv->frag_enabled) == 1 ?
179 "enabled" : "disabled",
180 frag_enabled_tmp == 1 ? "enabled" : "disabled");
181
182 atomic_set(&bat_priv->frag_enabled, (unsigned)frag_enabled_tmp);
183 update_min_mtu(net_dev);
184 return count;
185}
186
187static ssize_t show_vis_mode(struct kobject *kobj, struct attribute *attr,
188 char *buff)
189{
190 struct device *dev = to_dev(kobj->parent);
191 struct bat_priv *bat_priv = netdev_priv(to_net_dev(dev));
192 int vis_mode = atomic_read(&bat_priv->vis_mode);
193
194 return sprintf(buff, "%s\n",
195 vis_mode == VIS_TYPE_CLIENT_UPDATE ?
196 "client" : "server");
197}
198
199static ssize_t store_vis_mode(struct kobject *kobj, struct attribute *attr,
200 char *buff, size_t count)
201{
202 struct device *dev = to_dev(kobj->parent);
203 struct net_device *net_dev = to_net_dev(dev);
204 struct bat_priv *bat_priv = netdev_priv(net_dev);
205 unsigned long val;
206 int ret, vis_mode_tmp = -1;
207
208 ret = strict_strtoul(buff, 10, &val);
209
210 if (((count == 2) && (!ret) && (val == VIS_TYPE_CLIENT_UPDATE)) ||
211 (strncmp(buff, "client", 6) == 0) ||
212 (strncmp(buff, "off", 3) == 0))
213 vis_mode_tmp = VIS_TYPE_CLIENT_UPDATE;
214
215 if (((count == 2) && (!ret) && (val == VIS_TYPE_SERVER_SYNC)) ||
216 (strncmp(buff, "server", 6) == 0))
217 vis_mode_tmp = VIS_TYPE_SERVER_SYNC;
218
219 if (vis_mode_tmp < 0) {
220 if (buff[count - 1] == '\n')
221 buff[count - 1] = '\0';
222
223 bat_info(net_dev,
224 "Invalid parameter for 'vis mode' setting received: "
225 "%s\n", buff);
226 return -EINVAL;
227 }
228
229 if (atomic_read(&bat_priv->vis_mode) == vis_mode_tmp)
230 return count;
231
232 bat_info(net_dev, "Changing vis mode from: %s to: %s\n",
233 atomic_read(&bat_priv->vis_mode) == VIS_TYPE_CLIENT_UPDATE ?
234 "client" : "server", vis_mode_tmp == VIS_TYPE_CLIENT_UPDATE ?
235 "client" : "server");
236
237 atomic_set(&bat_priv->vis_mode, (unsigned)vis_mode_tmp);
238 return count;
239}
240
241static ssize_t show_orig_interval(struct kobject *kobj, struct attribute *attr,
242 char *buff)
243{
244 struct device *dev = to_dev(kobj->parent);
245 struct bat_priv *bat_priv = netdev_priv(to_net_dev(dev));
246
247 return sprintf(buff, "%i\n",
248 atomic_read(&bat_priv->orig_interval));
249}
250
251static ssize_t store_orig_interval(struct kobject *kobj, struct attribute *attr,
252 char *buff, size_t count)
253{
254 struct device *dev = to_dev(kobj->parent);
255 struct net_device *net_dev = to_net_dev(dev);
256 struct bat_priv *bat_priv = netdev_priv(net_dev);
257 unsigned long orig_interval_tmp;
258 int ret;
259
260 ret = strict_strtoul(buff, 10, &orig_interval_tmp);
261 if (ret) {
262 bat_info(net_dev, "Invalid parameter for 'orig_interval' "
263 "setting received: %s\n", buff);
264 return -EINVAL;
265 }
266
267 if (orig_interval_tmp < JITTER * 2) {
268 bat_info(net_dev, "New originator interval too small: %li "
269 "(min: %i)\n", orig_interval_tmp, JITTER * 2);
270 return -EINVAL;
271 }
272
273 if (atomic_read(&bat_priv->orig_interval) == orig_interval_tmp)
274 return count;
275
276 bat_info(net_dev, "Changing originator interval from: %i to: %li\n",
277 atomic_read(&bat_priv->orig_interval),
278 orig_interval_tmp);
279
280 atomic_set(&bat_priv->orig_interval, orig_interval_tmp);
281 return count;
282}
283
284#ifdef CONFIG_BATMAN_ADV_DEBUG
285static ssize_t show_log_level(struct kobject *kobj, struct attribute *attr,
286 char *buff)
287{
288 struct device *dev = to_dev(kobj->parent);
289 struct bat_priv *bat_priv = netdev_priv(to_net_dev(dev));
290 int log_level = atomic_read(&bat_priv->log_level);
291
292 return sprintf(buff, "%d\n", log_level);
293}
294
295static ssize_t store_log_level(struct kobject *kobj, struct attribute *attr,
296 char *buff, size_t count)
297{
298 struct device *dev = to_dev(kobj->parent);
299 struct net_device *net_dev = to_net_dev(dev);
300 struct bat_priv *bat_priv = netdev_priv(net_dev);
301 unsigned long log_level_tmp;
302 int ret;
303
304 ret = strict_strtoul(buff, 10, &log_level_tmp);
305 if (ret) {
306 bat_info(net_dev, "Invalid parameter for 'log_level' "
307 "setting received: %s\n", buff);
308 return -EINVAL;
309 }
310
311 if (log_level_tmp > 3) {
312 bat_info(net_dev, "New log level too big: %li "
313 "(max: %i)\n", log_level_tmp, 3);
314 return -EINVAL;
315 }
316
317 if (atomic_read(&bat_priv->log_level) == log_level_tmp)
318 return count;
319
320 bat_info(net_dev, "Changing log level from: %i to: %li\n",
321 atomic_read(&bat_priv->log_level),
322 log_level_tmp);
323
324 atomic_set(&bat_priv->log_level, (unsigned)log_level_tmp);
325 return count;
326}
327#endif
328
329static BAT_ATTR(aggregated_ogms, S_IRUGO | S_IWUSR,
330 show_aggr_ogms, store_aggr_ogms);
331static BAT_ATTR(bonding, S_IRUGO | S_IWUSR, show_bond, store_bond);
332static BAT_ATTR(fragmentation, S_IRUGO | S_IWUSR, show_frag, store_frag);
333static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, show_vis_mode, store_vis_mode);
334static BAT_ATTR(orig_interval, S_IRUGO | S_IWUSR,
335 show_orig_interval, store_orig_interval);
336#ifdef CONFIG_BATMAN_ADV_DEBUG
337static BAT_ATTR(log_level, S_IRUGO | S_IWUSR, show_log_level, store_log_level);
338#endif
339
340static struct bat_attribute *mesh_attrs[] = {
341 &bat_attr_aggregated_ogms,
342 &bat_attr_bonding,
343 &bat_attr_fragmentation,
344 &bat_attr_vis_mode,
345 &bat_attr_orig_interval,
346#ifdef CONFIG_BATMAN_ADV_DEBUG
347 &bat_attr_log_level,
348#endif
349 NULL,
350};
351
352int sysfs_add_meshif(struct net_device *dev)
353{
354 struct kobject *batif_kobject = &dev->dev.kobj;
355 struct bat_priv *bat_priv = netdev_priv(dev);
356 struct bat_attribute **bat_attr;
357 int err;
358
359 bat_priv->mesh_obj = kobject_create_and_add(SYSFS_IF_MESH_SUBDIR,
360 batif_kobject);
361 if (!bat_priv->mesh_obj) {
362 bat_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
363 SYSFS_IF_MESH_SUBDIR);
364 goto out;
365 }
366
367 for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr) {
368 err = sysfs_create_file(bat_priv->mesh_obj,
369 &((*bat_attr)->attr));
370 if (err) {
371 bat_err(dev, "Can't add sysfs file: %s/%s/%s\n",
372 dev->name, SYSFS_IF_MESH_SUBDIR,
373 ((*bat_attr)->attr).name);
374 goto rem_attr;
375 }
376 }
377
378 return 0;
379
380rem_attr:
381 for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr)
382 sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
383
384 kobject_put(bat_priv->mesh_obj);
385 bat_priv->mesh_obj = NULL;
386out:
387 return -ENOMEM;
388}
389
390void sysfs_del_meshif(struct net_device *dev)
391{
392 struct bat_priv *bat_priv = netdev_priv(dev);
393 struct bat_attribute **bat_attr;
394
395 for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr)
396 sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
397
398 kobject_put(bat_priv->mesh_obj);
399 bat_priv->mesh_obj = NULL;
400}
401
402static ssize_t show_mesh_iface(struct kobject *kobj, struct attribute *attr,
403 char *buff)
404{
405 struct device *dev = to_dev(kobj->parent);
406 struct net_device *net_dev = to_net_dev(dev);
407 struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);
408 ssize_t length;
409
410 if (!batman_if)
411 return 0;
412
413 length = sprintf(buff, "%s\n", batman_if->if_status == IF_NOT_IN_USE ?
414 "none" : batman_if->soft_iface->name);
415
416 hardif_put(batman_if);
417
418 return length;
419}
420
421static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr,
422 char *buff, size_t count)
423{
424 struct device *dev = to_dev(kobj->parent);
425 struct net_device *net_dev = to_net_dev(dev);
426 struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);
427 int status_tmp = -1;
428 int ret;
429
430 if (!batman_if)
431 return count;
432
433 if (buff[count - 1] == '\n')
434 buff[count - 1] = '\0';
435
436 if (strlen(buff) >= IFNAMSIZ) {
437 pr_err("Invalid parameter for 'mesh_iface' setting received: "
438 "interface name too long '%s'\n", buff);
439 hardif_put(batman_if);
440 return -EINVAL;
441 }
442
443 if (strncmp(buff, "none", 4) == 0)
444 status_tmp = IF_NOT_IN_USE;
445 else
446 status_tmp = IF_I_WANT_YOU;
447
448 if ((batman_if->if_status == status_tmp) || ((batman_if->soft_iface) &&
449 (strncmp(batman_if->soft_iface->name, buff, IFNAMSIZ) == 0))) {
450 hardif_put(batman_if);
451 return count;
452 }
453
454 if (status_tmp == IF_NOT_IN_USE) {
455 rtnl_lock();
456 hardif_disable_interface(batman_if);
457 rtnl_unlock();
458 hardif_put(batman_if);
459 return count;
460 }
461
462 /* if the interface already is in use */
463 if (batman_if->if_status != IF_NOT_IN_USE) {
464 rtnl_lock();
465 hardif_disable_interface(batman_if);
466 rtnl_unlock();
467 }
468
469 ret = hardif_enable_interface(batman_if, buff);
470 hardif_put(batman_if);
471
472 return ret;
473}
474
475static ssize_t show_iface_status(struct kobject *kobj, struct attribute *attr,
476 char *buff)
477{
478 struct device *dev = to_dev(kobj->parent);
479 struct net_device *net_dev = to_net_dev(dev);
480 struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);
481 ssize_t length;
482
483 if (!batman_if)
484 return 0;
485
486 switch (batman_if->if_status) {
487 case IF_TO_BE_REMOVED:
488 length = sprintf(buff, "disabling\n");
489 break;
490 case IF_INACTIVE:
491 length = sprintf(buff, "inactive\n");
492 break;
493 case IF_ACTIVE:
494 length = sprintf(buff, "active\n");
495 break;
496 case IF_TO_BE_ACTIVATED:
497 length = sprintf(buff, "enabling\n");
498 break;
499 case IF_NOT_IN_USE:
500 default:
501 length = sprintf(buff, "not in use\n");
502 break;
503 }
504
505 hardif_put(batman_if);
506
507 return length;
508}
509
510static BAT_ATTR(mesh_iface, S_IRUGO | S_IWUSR,
511 show_mesh_iface, store_mesh_iface);
512static BAT_ATTR(iface_status, S_IRUGO, show_iface_status, NULL);
513
514static struct bat_attribute *batman_attrs[] = {
515 &bat_attr_mesh_iface,
516 &bat_attr_iface_status,
517 NULL,
518};
519
520int sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev)
521{
522 struct kobject *hardif_kobject = &dev->dev.kobj;
523 struct bat_attribute **bat_attr;
524 int err;
525
526 *hardif_obj = kobject_create_and_add(SYSFS_IF_BAT_SUBDIR,
527 hardif_kobject);
528
529 if (!*hardif_obj) {
530 bat_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
531 SYSFS_IF_BAT_SUBDIR);
532 goto out;
533 }
534
535 for (bat_attr = batman_attrs; *bat_attr; ++bat_attr) {
536 err = sysfs_create_file(*hardif_obj, &((*bat_attr)->attr));
537 if (err) {
538 bat_err(dev, "Can't add sysfs file: %s/%s/%s\n",
539 dev->name, SYSFS_IF_BAT_SUBDIR,
540 ((*bat_attr)->attr).name);
541 goto rem_attr;
542 }
543 }
544
545 return 0;
546
547rem_attr:
548 for (bat_attr = batman_attrs; *bat_attr; ++bat_attr)
549 sysfs_remove_file(*hardif_obj, &((*bat_attr)->attr));
550out:
551 return -ENOMEM;
552}
553
554void sysfs_del_hardif(struct kobject **hardif_obj)
555{
556 kobject_put(*hardif_obj);
557 *hardif_obj = NULL;
558}
diff --git a/drivers/staging/batman-adv/bat_sysfs.h b/drivers/staging/batman-adv/bat_sysfs.h
deleted file mode 100644
index 7f186c007b4f..000000000000
--- a/drivers/staging/batman-adv/bat_sysfs.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright (C) 2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22
23#ifndef _NET_BATMAN_ADV_SYSFS_H_
24#define _NET_BATMAN_ADV_SYSFS_H_
25
26#define SYSFS_IF_MESH_SUBDIR "mesh"
27#define SYSFS_IF_BAT_SUBDIR "batman_adv"
28
29struct bat_attribute {
30 struct attribute attr;
31 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
32 char *buf);
33 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
34 char *buf, size_t count);
35};
36
37int sysfs_add_meshif(struct net_device *dev);
38void sysfs_del_meshif(struct net_device *dev);
39int sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev);
40void sysfs_del_hardif(struct kobject **hardif_obj);
41
42#endif /* _NET_BATMAN_ADV_SYSFS_H_ */
diff --git a/drivers/staging/batman-adv/bitarray.c b/drivers/staging/batman-adv/bitarray.c
deleted file mode 100644
index 814274fbaa2f..000000000000
--- a/drivers/staging/batman-adv/bitarray.c
+++ /dev/null
@@ -1,201 +0,0 @@
1/*
2 * Copyright (C) 2006-2010 B.A.T.M.A.N. contributors:
3 *
4 * Simon Wunderlich, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "bitarray.h"
24
25#include <linux/bitops.h>
26
27/* returns true if the corresponding bit in the given seq_bits indicates true
28 * and curr_seqno is within range of last_seqno */
29uint8_t get_bit_status(TYPE_OF_WORD *seq_bits, uint32_t last_seqno,
30 uint32_t curr_seqno)
31{
32 int32_t diff, word_offset, word_num;
33
34 diff = last_seqno - curr_seqno;
35 if (diff < 0 || diff >= TQ_LOCAL_WINDOW_SIZE) {
36 return 0;
37 } else {
38 /* which word */
39 word_num = (last_seqno - curr_seqno) / WORD_BIT_SIZE;
40 /* which position in the selected word */
41 word_offset = (last_seqno - curr_seqno) % WORD_BIT_SIZE;
42
43 if (seq_bits[word_num] & 1 << word_offset)
44 return 1;
45 else
46 return 0;
47 }
48}
49
50/* turn corresponding bit on, so we can remember that we got the packet */
51void bit_mark(TYPE_OF_WORD *seq_bits, int32_t n)
52{
53 int32_t word_offset, word_num;
54
55 /* if too old, just drop it */
56 if (n < 0 || n >= TQ_LOCAL_WINDOW_SIZE)
57 return;
58
59 /* which word */
60 word_num = n / WORD_BIT_SIZE;
61 /* which position in the selected word */
62 word_offset = n % WORD_BIT_SIZE;
63
64 seq_bits[word_num] |= 1 << word_offset; /* turn the position on */
65}
66
67/* shift the packet array by n places. */
68static void bit_shift(TYPE_OF_WORD *seq_bits, int32_t n)
69{
70 int32_t word_offset, word_num;
71 int32_t i;
72
73 if (n <= 0 || n >= TQ_LOCAL_WINDOW_SIZE)
74 return;
75
76 word_offset = n % WORD_BIT_SIZE;/* shift how much inside each word */
77 word_num = n / WORD_BIT_SIZE; /* shift over how much (full) words */
78
79 for (i = NUM_WORDS - 1; i > word_num; i--) {
80 /* going from old to new, so we don't overwrite the data we copy
81 * from.
82 *
83 * left is high, right is low: FEDC BA98 7654 3210
84 * ^^ ^^
85 * vvvv
86 * ^^^^ = from, vvvvv =to, we'd have word_num==1 and
87 * word_offset==WORD_BIT_SIZE/2 ????? in this example.
88 * (=24 bits)
89 *
90 * our desired output would be: 9876 5432 1000 0000
91 * */
92
93 seq_bits[i] =
94 (seq_bits[i - word_num] << word_offset) +
95 /* take the lower port from the left half, shift it left
96 * to its final position */
97 (seq_bits[i - word_num - 1] >>
98 (WORD_BIT_SIZE-word_offset));
99 /* and the upper part of the right half and shift it left to
100 * it's position */
101 /* for our example that would be: word[0] = 9800 + 0076 =
102 * 9876 */
103 }
104 /* now for our last word, i==word_num, we only have the it's "left"
105 * half. that's the 1000 word in our example.*/
106
107 seq_bits[i] = (seq_bits[i - word_num] << word_offset);
108
109 /* pad the rest with 0, if there is anything */
110 i--;
111
112 for (; i >= 0; i--)
113 seq_bits[i] = 0;
114}
115
116static void bit_reset_window(TYPE_OF_WORD *seq_bits)
117{
118 int i;
119 for (i = 0; i < NUM_WORDS; i++)
120 seq_bits[i] = 0;
121}
122
123
124/* receive and process one packet within the sequence number window.
125 *
126 * returns:
127 * 1 if the window was moved (either new or very old)
128 * 0 if the window was not moved/shifted.
129 */
130char bit_get_packet(void *priv, TYPE_OF_WORD *seq_bits,
131 int32_t seq_num_diff, int8_t set_mark)
132{
133 struct bat_priv *bat_priv = (struct bat_priv *)priv;
134
135 /* sequence number is slightly older. We already got a sequence number
136 * higher than this one, so we just mark it. */
137
138 if ((seq_num_diff <= 0) && (seq_num_diff > -TQ_LOCAL_WINDOW_SIZE)) {
139 if (set_mark)
140 bit_mark(seq_bits, -seq_num_diff);
141 return 0;
142 }
143
144 /* sequence number is slightly newer, so we shift the window and
145 * set the mark if required */
146
147 if ((seq_num_diff > 0) && (seq_num_diff < TQ_LOCAL_WINDOW_SIZE)) {
148 bit_shift(seq_bits, seq_num_diff);
149
150 if (set_mark)
151 bit_mark(seq_bits, 0);
152 return 1;
153 }
154
155 /* sequence number is much newer, probably missed a lot of packets */
156
157 if ((seq_num_diff >= TQ_LOCAL_WINDOW_SIZE)
158 || (seq_num_diff < EXPECTED_SEQNO_RANGE)) {
159 bat_dbg(DBG_BATMAN, bat_priv,
160 "We missed a lot of packets (%i) !\n",
161 seq_num_diff - 1);
162 bit_reset_window(seq_bits);
163 if (set_mark)
164 bit_mark(seq_bits, 0);
165 return 1;
166 }
167
168 /* received a much older packet. The other host either restarted
169 * or the old packet got delayed somewhere in the network. The
170 * packet should be dropped without calling this function if the
171 * seqno window is protected. */
172
173 if ((seq_num_diff <= -TQ_LOCAL_WINDOW_SIZE)
174 || (seq_num_diff >= EXPECTED_SEQNO_RANGE)) {
175
176 bat_dbg(DBG_BATMAN, bat_priv,
177 "Other host probably restarted!\n");
178
179 bit_reset_window(seq_bits);
180 if (set_mark)
181 bit_mark(seq_bits, 0);
182
183 return 1;
184 }
185
186 /* never reached */
187 return 0;
188}
189
190/* count the hamming weight, how many good packets did we receive? just count
191 * the 1's.
192 */
193int bit_packet_count(TYPE_OF_WORD *seq_bits)
194{
195 int i, hamming = 0;
196
197 for (i = 0; i < NUM_WORDS; i++)
198 hamming += hweight_long(seq_bits[i]);
199
200 return hamming;
201}
diff --git a/drivers/staging/batman-adv/bitarray.h b/drivers/staging/batman-adv/bitarray.h
deleted file mode 100644
index 77b1e61847e8..000000000000
--- a/drivers/staging/batman-adv/bitarray.h
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * Copyright (C) 2006-2010 B.A.T.M.A.N. contributors:
3 *
4 * Simon Wunderlich, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_BITARRAY_H_
23#define _NET_BATMAN_ADV_BITARRAY_H_
24
25/* you should choose something big, if you don't want to waste cpu
26 * and keep the type in sync with bit_packet_count */
27#define TYPE_OF_WORD unsigned long
28#define WORD_BIT_SIZE (sizeof(TYPE_OF_WORD) * 8)
29
30/* returns true if the corresponding bit in the given seq_bits indicates true
31 * and curr_seqno is within range of last_seqno */
32uint8_t get_bit_status(TYPE_OF_WORD *seq_bits, uint32_t last_seqno,
33 uint32_t curr_seqno);
34
35/* turn corresponding bit on, so we can remember that we got the packet */
36void bit_mark(TYPE_OF_WORD *seq_bits, int32_t n);
37
38
39/* receive and process one packet, returns 1 if received seq_num is considered
40 * new, 0 if old */
41char bit_get_packet(void *priv, TYPE_OF_WORD *seq_bits,
42 int32_t seq_num_diff, int8_t set_mark);
43
44/* count the hamming weight, how many good packets did we receive? */
45int bit_packet_count(TYPE_OF_WORD *seq_bits);
46
47#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */
diff --git a/drivers/staging/batman-adv/hard-interface.c b/drivers/staging/batman-adv/hard-interface.c
deleted file mode 100644
index d85de82f941a..000000000000
--- a/drivers/staging/batman-adv/hard-interface.c
+++ /dev/null
@@ -1,647 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "hard-interface.h"
24#include "soft-interface.h"
25#include "send.h"
26#include "translation-table.h"
27#include "routing.h"
28#include "bat_sysfs.h"
29#include "originator.h"
30#include "hash.h"
31
32#include <linux/if_arp.h>
33
34#define MIN(x, y) ((x) < (y) ? (x) : (y))
35
36/* protect update critical side of if_list - but not the content */
37static DEFINE_SPINLOCK(if_list_lock);
38
39struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev)
40{
41 struct batman_if *batman_if;
42
43 rcu_read_lock();
44 list_for_each_entry_rcu(batman_if, &if_list, list) {
45 if (batman_if->net_dev == net_dev)
46 goto out;
47 }
48
49 batman_if = NULL;
50
51out:
52 if (batman_if)
53 hardif_hold(batman_if);
54
55 rcu_read_unlock();
56 return batman_if;
57}
58
59static int is_valid_iface(struct net_device *net_dev)
60{
61 if (net_dev->flags & IFF_LOOPBACK)
62 return 0;
63
64 if (net_dev->type != ARPHRD_ETHER)
65 return 0;
66
67 if (net_dev->addr_len != ETH_ALEN)
68 return 0;
69
70 /* no batman over batman */
71#ifdef HAVE_NET_DEVICE_OPS
72 if (net_dev->netdev_ops->ndo_start_xmit == interface_tx)
73 return 0;
74#else
75 if (net_dev->hard_start_xmit == interface_tx)
76 return 0;
77#endif
78
79 /* Device is being bridged */
80 /* if (net_dev->priv_flags & IFF_BRIDGE_PORT)
81 return 0; */
82
83 return 1;
84}
85
86static struct batman_if *get_active_batman_if(struct net_device *soft_iface)
87{
88 struct batman_if *batman_if;
89
90 rcu_read_lock();
91 list_for_each_entry_rcu(batman_if, &if_list, list) {
92 if (batman_if->soft_iface != soft_iface)
93 continue;
94
95 if (batman_if->if_status == IF_ACTIVE)
96 goto out;
97 }
98
99 batman_if = NULL;
100
101out:
102 if (batman_if)
103 hardif_hold(batman_if);
104
105 rcu_read_unlock();
106 return batman_if;
107}
108
109static void update_primary_addr(struct bat_priv *bat_priv)
110{
111 struct vis_packet *vis_packet;
112
113 vis_packet = (struct vis_packet *)
114 bat_priv->my_vis_info->skb_packet->data;
115 memcpy(vis_packet->vis_orig,
116 bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
117 memcpy(vis_packet->sender_orig,
118 bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
119}
120
121static void set_primary_if(struct bat_priv *bat_priv,
122 struct batman_if *batman_if)
123{
124 struct batman_packet *batman_packet;
125 struct batman_if *old_if;
126
127 if (batman_if)
128 hardif_hold(batman_if);
129
130 old_if = bat_priv->primary_if;
131 bat_priv->primary_if = batman_if;
132
133 if (old_if)
134 hardif_put(old_if);
135
136 if (!bat_priv->primary_if)
137 return;
138
139 batman_packet = (struct batman_packet *)(batman_if->packet_buff);
140 batman_packet->flags = PRIMARIES_FIRST_HOP;
141 batman_packet->ttl = TTL;
142
143 update_primary_addr(bat_priv);
144
145 /***
146 * hacky trick to make sure that we send the HNA information via
147 * our new primary interface
148 */
149 atomic_set(&bat_priv->hna_local_changed, 1);
150}
151
152static bool hardif_is_iface_up(struct batman_if *batman_if)
153{
154 if (batman_if->net_dev->flags & IFF_UP)
155 return true;
156
157 return false;
158}
159
160static void update_mac_addresses(struct batman_if *batman_if)
161{
162 memcpy(((struct batman_packet *)(batman_if->packet_buff))->orig,
163 batman_if->net_dev->dev_addr, ETH_ALEN);
164 memcpy(((struct batman_packet *)(batman_if->packet_buff))->prev_sender,
165 batman_if->net_dev->dev_addr, ETH_ALEN);
166}
167
168static void check_known_mac_addr(struct net_device *net_dev)
169{
170 struct batman_if *batman_if;
171
172 rcu_read_lock();
173 list_for_each_entry_rcu(batman_if, &if_list, list) {
174 if ((batman_if->if_status != IF_ACTIVE) &&
175 (batman_if->if_status != IF_TO_BE_ACTIVATED))
176 continue;
177
178 if (batman_if->net_dev == net_dev)
179 continue;
180
181 if (!compare_orig(batman_if->net_dev->dev_addr,
182 net_dev->dev_addr))
183 continue;
184
185 pr_warning("The newly added mac address (%pM) already exists "
186 "on: %s\n", net_dev->dev_addr,
187 batman_if->net_dev->name);
188 pr_warning("It is strongly recommended to keep mac addresses "
189 "unique to avoid problems!\n");
190 }
191 rcu_read_unlock();
192}
193
194int hardif_min_mtu(struct net_device *soft_iface)
195{
196 struct bat_priv *bat_priv = netdev_priv(soft_iface);
197 struct batman_if *batman_if;
198 /* allow big frames if all devices are capable to do so
199 * (have MTU > 1500 + BAT_HEADER_LEN) */
200 int min_mtu = ETH_DATA_LEN;
201
202 if (atomic_read(&bat_priv->frag_enabled))
203 goto out;
204
205 rcu_read_lock();
206 list_for_each_entry_rcu(batman_if, &if_list, list) {
207 if ((batman_if->if_status != IF_ACTIVE) &&
208 (batman_if->if_status != IF_TO_BE_ACTIVATED))
209 continue;
210
211 if (batman_if->soft_iface != soft_iface)
212 continue;
213
214 min_mtu = MIN(batman_if->net_dev->mtu - BAT_HEADER_LEN,
215 min_mtu);
216 }
217 rcu_read_unlock();
218out:
219 return min_mtu;
220}
221
222/* adjusts the MTU if a new interface with a smaller MTU appeared. */
223void update_min_mtu(struct net_device *soft_iface)
224{
225 int min_mtu;
226
227 min_mtu = hardif_min_mtu(soft_iface);
228 if (soft_iface->mtu != min_mtu)
229 soft_iface->mtu = min_mtu;
230}
231
232static void hardif_activate_interface(struct batman_if *batman_if)
233{
234 struct bat_priv *bat_priv;
235
236 if (batman_if->if_status != IF_INACTIVE)
237 return;
238
239 bat_priv = netdev_priv(batman_if->soft_iface);
240
241 update_mac_addresses(batman_if);
242 batman_if->if_status = IF_TO_BE_ACTIVATED;
243
244 /**
245 * the first active interface becomes our primary interface or
246 * the next active interface after the old primay interface was removed
247 */
248 if (!bat_priv->primary_if)
249 set_primary_if(bat_priv, batman_if);
250
251 bat_info(batman_if->soft_iface, "Interface activated: %s\n",
252 batman_if->net_dev->name);
253
254 update_min_mtu(batman_if->soft_iface);
255 return;
256}
257
258static void hardif_deactivate_interface(struct batman_if *batman_if)
259{
260 if ((batman_if->if_status != IF_ACTIVE) &&
261 (batman_if->if_status != IF_TO_BE_ACTIVATED))
262 return;
263
264 batman_if->if_status = IF_INACTIVE;
265
266 bat_info(batman_if->soft_iface, "Interface deactivated: %s\n",
267 batman_if->net_dev->name);
268
269 update_min_mtu(batman_if->soft_iface);
270}
271
272int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
273{
274 struct bat_priv *bat_priv;
275 struct batman_packet *batman_packet;
276
277 if (batman_if->if_status != IF_NOT_IN_USE)
278 goto out;
279
280 batman_if->soft_iface = dev_get_by_name(&init_net, iface_name);
281
282 if (!batman_if->soft_iface) {
283 batman_if->soft_iface = softif_create(iface_name);
284
285 if (!batman_if->soft_iface)
286 goto err;
287
288 /* dev_get_by_name() increases the reference counter for us */
289 dev_hold(batman_if->soft_iface);
290 }
291
292 bat_priv = netdev_priv(batman_if->soft_iface);
293 batman_if->packet_len = BAT_PACKET_LEN;
294 batman_if->packet_buff = kmalloc(batman_if->packet_len, GFP_ATOMIC);
295
296 if (!batman_if->packet_buff) {
297 bat_err(batman_if->soft_iface, "Can't add interface packet "
298 "(%s): out of memory\n", batman_if->net_dev->name);
299 goto err;
300 }
301
302 batman_packet = (struct batman_packet *)(batman_if->packet_buff);
303 batman_packet->packet_type = BAT_PACKET;
304 batman_packet->version = COMPAT_VERSION;
305 batman_packet->flags = 0;
306 batman_packet->ttl = 2;
307 batman_packet->tq = TQ_MAX_VALUE;
308 batman_packet->num_hna = 0;
309
310 batman_if->if_num = bat_priv->num_ifaces;
311 bat_priv->num_ifaces++;
312 batman_if->if_status = IF_INACTIVE;
313 orig_hash_add_if(batman_if, bat_priv->num_ifaces);
314
315 batman_if->batman_adv_ptype.type = __constant_htons(ETH_P_BATMAN);
316 batman_if->batman_adv_ptype.func = batman_skb_recv;
317 batman_if->batman_adv_ptype.dev = batman_if->net_dev;
318 hardif_hold(batman_if);
319 dev_add_pack(&batman_if->batman_adv_ptype);
320
321 atomic_set(&batman_if->seqno, 1);
322 atomic_set(&batman_if->frag_seqno, 1);
323 bat_info(batman_if->soft_iface, "Adding interface: %s\n",
324 batman_if->net_dev->name);
325
326 if (atomic_read(&bat_priv->frag_enabled) && batman_if->net_dev->mtu <
327 ETH_DATA_LEN + BAT_HEADER_LEN)
328 bat_info(batman_if->soft_iface,
329 "The MTU of interface %s is too small (%i) to handle "
330 "the transport of batman-adv packets. Packets going "
331 "over this interface will be fragmented on layer2 "
332 "which could impact the performance. Setting the MTU "
333 "to %zi would solve the problem.\n",
334 batman_if->net_dev->name, batman_if->net_dev->mtu,
335 ETH_DATA_LEN + BAT_HEADER_LEN);
336
337 if (!atomic_read(&bat_priv->frag_enabled) && batman_if->net_dev->mtu <
338 ETH_DATA_LEN + BAT_HEADER_LEN)
339 bat_info(batman_if->soft_iface,
340 "The MTU of interface %s is too small (%i) to handle "
341 "the transport of batman-adv packets. If you experience"
342 " problems getting traffic through try increasing the "
343 "MTU to %zi.\n",
344 batman_if->net_dev->name, batman_if->net_dev->mtu,
345 ETH_DATA_LEN + BAT_HEADER_LEN);
346
347 if (hardif_is_iface_up(batman_if))
348 hardif_activate_interface(batman_if);
349 else
350 bat_err(batman_if->soft_iface, "Not using interface %s "
351 "(retrying later): interface not active\n",
352 batman_if->net_dev->name);
353
354 /* begin scheduling originator messages on that interface */
355 schedule_own_packet(batman_if);
356
357out:
358 return 0;
359
360err:
361 return -ENOMEM;
362}
363
364void hardif_disable_interface(struct batman_if *batman_if)
365{
366 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
367
368 if (batman_if->if_status == IF_ACTIVE)
369 hardif_deactivate_interface(batman_if);
370
371 if (batman_if->if_status != IF_INACTIVE)
372 return;
373
374 bat_info(batman_if->soft_iface, "Removing interface: %s\n",
375 batman_if->net_dev->name);
376 dev_remove_pack(&batman_if->batman_adv_ptype);
377 hardif_put(batman_if);
378
379 bat_priv->num_ifaces--;
380 orig_hash_del_if(batman_if, bat_priv->num_ifaces);
381
382 if (batman_if == bat_priv->primary_if) {
383 struct batman_if *new_if;
384
385 new_if = get_active_batman_if(batman_if->soft_iface);
386 set_primary_if(bat_priv, new_if);
387
388 if (new_if)
389 hardif_put(new_if);
390 }
391
392 kfree(batman_if->packet_buff);
393 batman_if->packet_buff = NULL;
394 batman_if->if_status = IF_NOT_IN_USE;
395
396 /* delete all references to this batman_if */
397 purge_orig_ref(bat_priv);
398 purge_outstanding_packets(bat_priv, batman_if);
399 dev_put(batman_if->soft_iface);
400
401 /* nobody uses this interface anymore */
402 if (!bat_priv->num_ifaces)
403 softif_destroy(batman_if->soft_iface);
404
405 batman_if->soft_iface = NULL;
406}
407
408static struct batman_if *hardif_add_interface(struct net_device *net_dev)
409{
410 struct batman_if *batman_if;
411 int ret;
412
413 ret = is_valid_iface(net_dev);
414 if (ret != 1)
415 goto out;
416
417 dev_hold(net_dev);
418
419 batman_if = kmalloc(sizeof(struct batman_if), GFP_ATOMIC);
420 if (!batman_if) {
421 pr_err("Can't add interface (%s): out of memory\n",
422 net_dev->name);
423 goto release_dev;
424 }
425
426 ret = sysfs_add_hardif(&batman_if->hardif_obj, net_dev);
427 if (ret)
428 goto free_if;
429
430 batman_if->if_num = -1;
431 batman_if->net_dev = net_dev;
432 batman_if->soft_iface = NULL;
433 batman_if->if_status = IF_NOT_IN_USE;
434 INIT_LIST_HEAD(&batman_if->list);
435 atomic_set(&batman_if->refcnt, 0);
436 hardif_hold(batman_if);
437
438 check_known_mac_addr(batman_if->net_dev);
439
440 spin_lock(&if_list_lock);
441 list_add_tail_rcu(&batman_if->list, &if_list);
442 spin_unlock(&if_list_lock);
443
444 /* extra reference for return */
445 hardif_hold(batman_if);
446 return batman_if;
447
448free_if:
449 kfree(batman_if);
450release_dev:
451 dev_put(net_dev);
452out:
453 return NULL;
454}
455
456static void hardif_remove_interface(struct batman_if *batman_if)
457{
458 /* first deactivate interface */
459 if (batman_if->if_status != IF_NOT_IN_USE)
460 hardif_disable_interface(batman_if);
461
462 if (batman_if->if_status != IF_NOT_IN_USE)
463 return;
464
465 batman_if->if_status = IF_TO_BE_REMOVED;
466 synchronize_rcu();
467 sysfs_del_hardif(&batman_if->hardif_obj);
468 hardif_put(batman_if);
469}
470
471void hardif_remove_interfaces(void)
472{
473 struct batman_if *batman_if, *batman_if_tmp;
474 struct list_head if_queue;
475
476 INIT_LIST_HEAD(&if_queue);
477
478 spin_lock(&if_list_lock);
479 list_for_each_entry_safe(batman_if, batman_if_tmp, &if_list, list) {
480 list_del_rcu(&batman_if->list);
481 list_add_tail(&batman_if->list, &if_queue);
482 }
483 spin_unlock(&if_list_lock);
484
485 rtnl_lock();
486 list_for_each_entry_safe(batman_if, batman_if_tmp, &if_queue, list) {
487 hardif_remove_interface(batman_if);
488 }
489 rtnl_unlock();
490}
491
492static int hard_if_event(struct notifier_block *this,
493 unsigned long event, void *ptr)
494{
495 struct net_device *net_dev = (struct net_device *)ptr;
496 struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);
497 struct bat_priv *bat_priv;
498
499 if (!batman_if && event == NETDEV_REGISTER)
500 batman_if = hardif_add_interface(net_dev);
501
502 if (!batman_if)
503 goto out;
504
505 switch (event) {
506 case NETDEV_UP:
507 hardif_activate_interface(batman_if);
508 break;
509 case NETDEV_GOING_DOWN:
510 case NETDEV_DOWN:
511 hardif_deactivate_interface(batman_if);
512 break;
513 case NETDEV_UNREGISTER:
514 spin_lock(&if_list_lock);
515 list_del_rcu(&batman_if->list);
516 spin_unlock(&if_list_lock);
517
518 hardif_remove_interface(batman_if);
519 break;
520 case NETDEV_CHANGEMTU:
521 if (batman_if->soft_iface)
522 update_min_mtu(batman_if->soft_iface);
523 break;
524 case NETDEV_CHANGEADDR:
525 if (batman_if->if_status == IF_NOT_IN_USE) {
526 hardif_put(batman_if);
527 goto out;
528 }
529
530 check_known_mac_addr(batman_if->net_dev);
531 update_mac_addresses(batman_if);
532
533 bat_priv = netdev_priv(batman_if->soft_iface);
534 if (batman_if == bat_priv->primary_if)
535 update_primary_addr(bat_priv);
536 break;
537 default:
538 break;
539 };
540 hardif_put(batman_if);
541
542out:
543 return NOTIFY_DONE;
544}
545
546/* receive a packet with the batman ethertype coming on a hard
547 * interface */
548int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
549 struct packet_type *ptype, struct net_device *orig_dev)
550{
551 struct bat_priv *bat_priv;
552 struct batman_packet *batman_packet;
553 struct batman_if *batman_if;
554 int ret;
555
556 batman_if = container_of(ptype, struct batman_if, batman_adv_ptype);
557 skb = skb_share_check(skb, GFP_ATOMIC);
558
559 /* skb was released by skb_share_check() */
560 if (!skb)
561 goto err_out;
562
563 /* packet should hold at least type and version */
564 if (unlikely(!pskb_may_pull(skb, 2)))
565 goto err_free;
566
567 /* expect a valid ethernet header here. */
568 if (unlikely(skb->mac_len != sizeof(struct ethhdr)
569 || !skb_mac_header(skb)))
570 goto err_free;
571
572 if (!batman_if->soft_iface)
573 goto err_free;
574
575 bat_priv = netdev_priv(batman_if->soft_iface);
576
577 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
578 goto err_free;
579
580 /* discard frames on not active interfaces */
581 if (batman_if->if_status != IF_ACTIVE)
582 goto err_free;
583
584 batman_packet = (struct batman_packet *)skb->data;
585
586 if (batman_packet->version != COMPAT_VERSION) {
587 bat_dbg(DBG_BATMAN, bat_priv,
588 "Drop packet: incompatible batman version (%i)\n",
589 batman_packet->version);
590 goto err_free;
591 }
592
593 /* all receive handlers return whether they received or reused
594 * the supplied skb. if not, we have to free the skb. */
595
596 switch (batman_packet->packet_type) {
597 /* batman originator packet */
598 case BAT_PACKET:
599 ret = recv_bat_packet(skb, batman_if);
600 break;
601
602 /* batman icmp packet */
603 case BAT_ICMP:
604 ret = recv_icmp_packet(skb, batman_if);
605 break;
606
607 /* unicast packet */
608 case BAT_UNICAST:
609 ret = recv_unicast_packet(skb, batman_if);
610 break;
611
612 /* fragmented unicast packet */
613 case BAT_UNICAST_FRAG:
614 ret = recv_ucast_frag_packet(skb, batman_if);
615 break;
616
617 /* broadcast packet */
618 case BAT_BCAST:
619 ret = recv_bcast_packet(skb, batman_if);
620 break;
621
622 /* vis packet */
623 case BAT_VIS:
624 ret = recv_vis_packet(skb, batman_if);
625 break;
626 default:
627 ret = NET_RX_DROP;
628 }
629
630 if (ret == NET_RX_DROP)
631 kfree_skb(skb);
632
633 /* return NET_RX_SUCCESS in any case as we
634 * most probably dropped the packet for
635 * routing-logical reasons. */
636
637 return NET_RX_SUCCESS;
638
639err_free:
640 kfree_skb(skb);
641err_out:
642 return NET_RX_DROP;
643}
644
645struct notifier_block hard_if_notifier = {
646 .notifier_call = hard_if_event,
647};
diff --git a/drivers/staging/batman-adv/hard-interface.h b/drivers/staging/batman-adv/hard-interface.h
deleted file mode 100644
index d5508899065b..000000000000
--- a/drivers/staging/batman-adv/hard-interface.h
+++ /dev/null
@@ -1,58 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_HARD_INTERFACE_H_
23#define _NET_BATMAN_ADV_HARD_INTERFACE_H_
24
25#define IF_NOT_IN_USE 0
26#define IF_TO_BE_REMOVED 1
27#define IF_INACTIVE 2
28#define IF_ACTIVE 3
29#define IF_TO_BE_ACTIVATED 4
30#define IF_I_WANT_YOU 5
31
32extern struct notifier_block hard_if_notifier;
33
34struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev);
35int hardif_enable_interface(struct batman_if *batman_if, char *iface_name);
36void hardif_disable_interface(struct batman_if *batman_if);
37void hardif_remove_interfaces(void);
38int batman_skb_recv(struct sk_buff *skb,
39 struct net_device *dev,
40 struct packet_type *ptype,
41 struct net_device *orig_dev);
42int hardif_min_mtu(struct net_device *soft_iface);
43void update_min_mtu(struct net_device *soft_iface);
44
45static inline void hardif_hold(struct batman_if *batman_if)
46{
47 atomic_inc(&batman_if->refcnt);
48}
49
50static inline void hardif_put(struct batman_if *batman_if)
51{
52 if (atomic_dec_and_test(&batman_if->refcnt)) {
53 dev_put(batman_if->net_dev);
54 kfree(batman_if);
55 }
56}
57
58#endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */
diff --git a/drivers/staging/batman-adv/hash.c b/drivers/staging/batman-adv/hash.c
deleted file mode 100644
index 8ef26eb4949d..000000000000
--- a/drivers/staging/batman-adv/hash.c
+++ /dev/null
@@ -1,306 +0,0 @@
1/*
2 * Copyright (C) 2006-2010 B.A.T.M.A.N. contributors:
3 *
4 * Simon Wunderlich, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "hash.h"
24
25/* clears the hash */
26static void hash_init(struct hashtable_t *hash)
27{
28 int i;
29
30 hash->elements = 0;
31
32 for (i = 0 ; i < hash->size; i++)
33 hash->table[i] = NULL;
34}
35
36/* remove the hash structure. if hashdata_free_cb != NULL, this function will be
37 * called to remove the elements inside of the hash. if you don't remove the
38 * elements, memory might be leaked. */
39void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb, void *arg)
40{
41 struct element_t *bucket, *last_bucket;
42 int i;
43
44 for (i = 0; i < hash->size; i++) {
45 bucket = hash->table[i];
46
47 while (bucket != NULL) {
48 if (free_cb != NULL)
49 free_cb(bucket->data, arg);
50
51 last_bucket = bucket;
52 bucket = bucket->next;
53 kfree(last_bucket);
54 }
55 }
56
57 hash_destroy(hash);
58}
59
60/* free only the hashtable and the hash itself. */
61void hash_destroy(struct hashtable_t *hash)
62{
63 kfree(hash->table);
64 kfree(hash);
65}
66
67/* iterate though the hash. First element is selected if an iterator
68 * initialized with HASHIT() is supplied as iter. Use the returned
69 * (or supplied) iterator to access the elements until hash_iterate returns
70 * NULL. */
71
72struct hash_it_t *hash_iterate(struct hashtable_t *hash,
73 struct hash_it_t *iter)
74{
75 if (!hash)
76 return NULL;
77 if (!iter)
78 return NULL;
79
80 /* sanity checks first (if our bucket got deleted in the last
81 * iteration): */
82 if (iter->bucket != NULL) {
83 if (iter->first_bucket != NULL) {
84 /* we're on the first element and it got removed after
85 * the last iteration. */
86 if ((*iter->first_bucket) != iter->bucket) {
87 /* there are still other elements in the list */
88 if ((*iter->first_bucket) != NULL) {
89 iter->prev_bucket = NULL;
90 iter->bucket = (*iter->first_bucket);
91 iter->first_bucket =
92 &hash->table[iter->index];
93 return iter;
94 } else {
95 iter->bucket = NULL;
96 }
97 }
98 } else if (iter->prev_bucket != NULL) {
99 /*
100 * we're not on the first element, and the bucket got
101 * removed after the last iteration. the last bucket's
102 * next pointer is not pointing to our actual bucket
103 * anymore. select the next.
104 */
105 if (iter->prev_bucket->next != iter->bucket)
106 iter->bucket = iter->prev_bucket;
107 }
108 }
109
110 /* now as we are sane, select the next one if there is some */
111 if (iter->bucket != NULL) {
112 if (iter->bucket->next != NULL) {
113 iter->prev_bucket = iter->bucket;
114 iter->bucket = iter->bucket->next;
115 iter->first_bucket = NULL;
116 return iter;
117 }
118 }
119
120 /* if not returned yet, we've reached the last one on the index and have
121 * to search forward */
122 iter->index++;
123 /* go through the entries of the hash table */
124 while (iter->index < hash->size) {
125 if ((hash->table[iter->index]) != NULL) {
126 iter->prev_bucket = NULL;
127 iter->bucket = hash->table[iter->index];
128 iter->first_bucket = &hash->table[iter->index];
129 return iter;
130 } else {
131 iter->index++;
132 }
133 }
134
135 /* nothing to iterate over anymore */
136 return NULL;
137}
138
139/* allocates and clears the hash */
140struct hashtable_t *hash_new(int size, hashdata_compare_cb compare,
141 hashdata_choose_cb choose)
142{
143 struct hashtable_t *hash;
144
145 hash = kmalloc(sizeof(struct hashtable_t) , GFP_ATOMIC);
146
147 if (hash == NULL)
148 return NULL;
149
150 hash->size = size;
151 hash->table = kmalloc(sizeof(struct element_t *) * size, GFP_ATOMIC);
152
153 if (hash->table == NULL) {
154 kfree(hash);
155 return NULL;
156 }
157
158 hash_init(hash);
159
160 hash->compare = compare;
161 hash->choose = choose;
162
163 return hash;
164}
165
166/* adds data to the hashtable. returns 0 on success, -1 on error */
167int hash_add(struct hashtable_t *hash, void *data)
168{
169 int index;
170 struct element_t *bucket, *prev_bucket = NULL;
171
172 if (!hash)
173 return -1;
174
175 index = hash->choose(data, hash->size);
176 bucket = hash->table[index];
177
178 while (bucket != NULL) {
179 if (hash->compare(bucket->data, data))
180 return -1;
181
182 prev_bucket = bucket;
183 bucket = bucket->next;
184 }
185
186 /* found the tail of the list, add new element */
187 bucket = kmalloc(sizeof(struct element_t), GFP_ATOMIC);
188
189 if (bucket == NULL)
190 return -1;
191
192 bucket->data = data;
193 bucket->next = NULL;
194
195 /* and link it */
196 if (prev_bucket == NULL)
197 hash->table[index] = bucket;
198 else
199 prev_bucket->next = bucket;
200
201 hash->elements++;
202 return 0;
203}
204
205/* finds data, based on the key in keydata. returns the found data on success,
206 * or NULL on error */
207void *hash_find(struct hashtable_t *hash, void *keydata)
208{
209 int index;
210 struct element_t *bucket;
211
212 if (!hash)
213 return NULL;
214
215 index = hash->choose(keydata , hash->size);
216 bucket = hash->table[index];
217
218 while (bucket != NULL) {
219 if (hash->compare(bucket->data, keydata))
220 return bucket->data;
221
222 bucket = bucket->next;
223 }
224
225 return NULL;
226}
227
228/* remove bucket (this might be used in hash_iterate() if you already found the
229 * bucket you want to delete and don't need the overhead to find it again with
230 * hash_remove(). But usually, you don't want to use this function, as it
231 * fiddles with hash-internals. */
232void *hash_remove_bucket(struct hashtable_t *hash, struct hash_it_t *hash_it_t)
233{
234 void *data_save;
235
236 data_save = hash_it_t->bucket->data;
237
238 if (hash_it_t->prev_bucket != NULL)
239 hash_it_t->prev_bucket->next = hash_it_t->bucket->next;
240 else if (hash_it_t->first_bucket != NULL)
241 (*hash_it_t->first_bucket) = hash_it_t->bucket->next;
242
243 kfree(hash_it_t->bucket);
244 hash->elements--;
245
246 return data_save;
247}
248
249/* removes data from hash, if found. returns pointer do data on success, so you
250 * can remove the used structure yourself, or NULL on error . data could be the
251 * structure you use with just the key filled, we just need the key for
252 * comparing. */
253void *hash_remove(struct hashtable_t *hash, void *data)
254{
255 struct hash_it_t hash_it_t;
256
257 hash_it_t.index = hash->choose(data, hash->size);
258 hash_it_t.bucket = hash->table[hash_it_t.index];
259 hash_it_t.prev_bucket = NULL;
260
261 while (hash_it_t.bucket != NULL) {
262 if (hash->compare(hash_it_t.bucket->data, data)) {
263 hash_it_t.first_bucket =
264 (hash_it_t.bucket ==
265 hash->table[hash_it_t.index] ?
266 &hash->table[hash_it_t.index] : NULL);
267 return hash_remove_bucket(hash, &hash_it_t);
268 }
269
270 hash_it_t.prev_bucket = hash_it_t.bucket;
271 hash_it_t.bucket = hash_it_t.bucket->next;
272 }
273
274 return NULL;
275}
276
277/* resize the hash, returns the pointer to the new hash or NULL on
278 * error. removes the old hash on success. */
279struct hashtable_t *hash_resize(struct hashtable_t *hash, int size)
280{
281 struct hashtable_t *new_hash;
282 struct element_t *bucket;
283 int i;
284
285 /* initialize a new hash with the new size */
286 new_hash = hash_new(size, hash->compare, hash->choose);
287
288 if (new_hash == NULL)
289 return NULL;
290
291 /* copy the elements */
292 for (i = 0; i < hash->size; i++) {
293 bucket = hash->table[i];
294
295 while (bucket != NULL) {
296 hash_add(new_hash, bucket->data);
297 bucket = bucket->next;
298 }
299 }
300
301 /* remove hash and eventual overflow buckets but not the content
302 * itself. */
303 hash_delete(hash, NULL, NULL);
304
305 return new_hash;
306}
diff --git a/drivers/staging/batman-adv/hash.h b/drivers/staging/batman-adv/hash.h
deleted file mode 100644
index 2c8e1762389f..000000000000
--- a/drivers/staging/batman-adv/hash.h
+++ /dev/null
@@ -1,100 +0,0 @@
1/*
2 * Copyright (C) 2006-2010 B.A.T.M.A.N. contributors:
3 *
4 * Simon Wunderlich, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_HASH_H_
23#define _NET_BATMAN_ADV_HASH_H_
24
25#define HASHIT(name) struct hash_it_t name = { \
26 .index = -1, .bucket = NULL, \
27 .prev_bucket = NULL, \
28 .first_bucket = NULL }
29
30
31typedef int (*hashdata_compare_cb)(void *, void *);
32typedef int (*hashdata_choose_cb)(void *, int);
33typedef void (*hashdata_free_cb)(void *, void *);
34
35struct element_t {
36 void *data; /* pointer to the data */
37 struct element_t *next; /* overflow bucket pointer */
38};
39
40struct hash_it_t {
41 int index;
42 struct element_t *bucket;
43 struct element_t *prev_bucket;
44 struct element_t **first_bucket;
45};
46
47struct hashtable_t {
48 struct element_t **table; /* the hashtable itself, with the buckets */
49 int elements; /* number of elements registered */
50 int size; /* size of hashtable */
51 hashdata_compare_cb compare;/* callback to a compare function. should
52 * compare 2 element datas for their keys,
53 * return 0 if same and not 0 if not
54 * same */
55 hashdata_choose_cb choose; /* the hashfunction, should return an index
56 * based on the key in the data of the first
57 * argument and the size the second */
58};
59
60/* allocates and clears the hash */
61struct hashtable_t *hash_new(int size, hashdata_compare_cb compare,
62 hashdata_choose_cb choose);
63
64/* remove bucket (this might be used in hash_iterate() if you already found the
65 * bucket you want to delete and don't need the overhead to find it again with
66 * hash_remove(). But usually, you don't want to use this function, as it
67 * fiddles with hash-internals. */
68void *hash_remove_bucket(struct hashtable_t *hash, struct hash_it_t *hash_it_t);
69
70/* remove the hash structure. if hashdata_free_cb != NULL, this function will be
71 * called to remove the elements inside of the hash. if you don't remove the
72 * elements, memory might be leaked. */
73void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb, void *arg);
74
75/* free only the hashtable and the hash itself. */
76void hash_destroy(struct hashtable_t *hash);
77
78/* adds data to the hashtable. returns 0 on success, -1 on error */
79int hash_add(struct hashtable_t *hash, void *data);
80
81/* removes data from hash, if found. returns pointer do data on success, so you
82 * can remove the used structure yourself, or NULL on error . data could be the
83 * structure you use with just the key filled, we just need the key for
84 * comparing. */
85void *hash_remove(struct hashtable_t *hash, void *data);
86
87/* finds data, based on the key in keydata. returns the found data on success,
88 * or NULL on error */
89void *hash_find(struct hashtable_t *hash, void *keydata);
90
91/* resize the hash, returns the pointer to the new hash or NULL on
92 * error. removes the old hash on success */
93struct hashtable_t *hash_resize(struct hashtable_t *hash, int size);
94
95/* iterate though the hash. first element is selected with iter_in NULL. use
96 * the returned iterator to access the elements until hash_it_t returns NULL. */
97struct hash_it_t *hash_iterate(struct hashtable_t *hash,
98 struct hash_it_t *iter_in);
99
100#endif /* _NET_BATMAN_ADV_HASH_H_ */
diff --git a/drivers/staging/batman-adv/icmp_socket.c b/drivers/staging/batman-adv/icmp_socket.c
deleted file mode 100644
index 48856ca73b6a..000000000000
--- a/drivers/staging/batman-adv/icmp_socket.c
+++ /dev/null
@@ -1,359 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include <linux/debugfs.h>
24#include <linux/slab.h>
25#include "icmp_socket.h"
26#include "send.h"
27#include "types.h"
28#include "hash.h"
29#include "hard-interface.h"
30
31
32static struct socket_client *socket_client_hash[256];
33
34static void bat_socket_add_packet(struct socket_client *socket_client,
35 struct icmp_packet_rr *icmp_packet,
36 size_t icmp_len);
37
38void bat_socket_init(void)
39{
40 memset(socket_client_hash, 0, sizeof(socket_client_hash));
41}
42
43static int bat_socket_open(struct inode *inode, struct file *file)
44{
45 unsigned int i;
46 struct socket_client *socket_client;
47
48 nonseekable_open(inode, file);
49
50 socket_client = kmalloc(sizeof(struct socket_client), GFP_KERNEL);
51
52 if (!socket_client)
53 return -ENOMEM;
54
55 for (i = 0; i < ARRAY_SIZE(socket_client_hash); i++) {
56 if (!socket_client_hash[i]) {
57 socket_client_hash[i] = socket_client;
58 break;
59 }
60 }
61
62 if (i == ARRAY_SIZE(socket_client_hash)) {
63 pr_err("Error - can't add another packet client: "
64 "maximum number of clients reached\n");
65 kfree(socket_client);
66 return -EXFULL;
67 }
68
69 INIT_LIST_HEAD(&socket_client->queue_list);
70 socket_client->queue_len = 0;
71 socket_client->index = i;
72 socket_client->bat_priv = inode->i_private;
73 spin_lock_init(&socket_client->lock);
74 init_waitqueue_head(&socket_client->queue_wait);
75
76 file->private_data = socket_client;
77
78 inc_module_count();
79 return 0;
80}
81
82static int bat_socket_release(struct inode *inode, struct file *file)
83{
84 struct socket_client *socket_client = file->private_data;
85 struct socket_packet *socket_packet;
86 struct list_head *list_pos, *list_pos_tmp;
87 unsigned long flags;
88
89 spin_lock_irqsave(&socket_client->lock, flags);
90
91 /* for all packets in the queue ... */
92 list_for_each_safe(list_pos, list_pos_tmp, &socket_client->queue_list) {
93 socket_packet = list_entry(list_pos,
94 struct socket_packet, list);
95
96 list_del(list_pos);
97 kfree(socket_packet);
98 }
99
100 socket_client_hash[socket_client->index] = NULL;
101 spin_unlock_irqrestore(&socket_client->lock, flags);
102
103 kfree(socket_client);
104 dec_module_count();
105
106 return 0;
107}
108
109static ssize_t bat_socket_read(struct file *file, char __user *buf,
110 size_t count, loff_t *ppos)
111{
112 struct socket_client *socket_client = file->private_data;
113 struct socket_packet *socket_packet;
114 size_t packet_len;
115 int error;
116 unsigned long flags;
117
118 if ((file->f_flags & O_NONBLOCK) && (socket_client->queue_len == 0))
119 return -EAGAIN;
120
121 if ((!buf) || (count < sizeof(struct icmp_packet)))
122 return -EINVAL;
123
124 if (!access_ok(VERIFY_WRITE, buf, count))
125 return -EFAULT;
126
127 error = wait_event_interruptible(socket_client->queue_wait,
128 socket_client->queue_len);
129
130 if (error)
131 return error;
132
133 spin_lock_irqsave(&socket_client->lock, flags);
134
135 socket_packet = list_first_entry(&socket_client->queue_list,
136 struct socket_packet, list);
137 list_del(&socket_packet->list);
138 socket_client->queue_len--;
139
140 spin_unlock_irqrestore(&socket_client->lock, flags);
141
142 error = __copy_to_user(buf, &socket_packet->icmp_packet,
143 socket_packet->icmp_len);
144
145 packet_len = socket_packet->icmp_len;
146 kfree(socket_packet);
147
148 if (error)
149 return -EFAULT;
150
151 return packet_len;
152}
153
154static ssize_t bat_socket_write(struct file *file, const char __user *buff,
155 size_t len, loff_t *off)
156{
157 struct socket_client *socket_client = file->private_data;
158 struct bat_priv *bat_priv = socket_client->bat_priv;
159 struct sk_buff *skb;
160 struct icmp_packet_rr *icmp_packet;
161
162 struct orig_node *orig_node;
163 struct batman_if *batman_if;
164 size_t packet_len = sizeof(struct icmp_packet);
165 uint8_t dstaddr[ETH_ALEN];
166 unsigned long flags;
167
168 if (len < sizeof(struct icmp_packet)) {
169 bat_dbg(DBG_BATMAN, bat_priv,
170 "Error - can't send packet from char device: "
171 "invalid packet size\n");
172 return -EINVAL;
173 }
174
175 if (!bat_priv->primary_if)
176 return -EFAULT;
177
178 if (len >= sizeof(struct icmp_packet_rr))
179 packet_len = sizeof(struct icmp_packet_rr);
180
181 skb = dev_alloc_skb(packet_len + sizeof(struct ethhdr));
182 if (!skb)
183 return -ENOMEM;
184
185 skb_reserve(skb, sizeof(struct ethhdr));
186 icmp_packet = (struct icmp_packet_rr *)skb_put(skb, packet_len);
187
188 if (!access_ok(VERIFY_READ, buff, packet_len)) {
189 len = -EFAULT;
190 goto free_skb;
191 }
192
193 if (__copy_from_user(icmp_packet, buff, packet_len)) {
194 len = -EFAULT;
195 goto free_skb;
196 }
197
198 if (icmp_packet->packet_type != BAT_ICMP) {
199 bat_dbg(DBG_BATMAN, bat_priv,
200 "Error - can't send packet from char device: "
201 "got bogus packet type (expected: BAT_ICMP)\n");
202 len = -EINVAL;
203 goto free_skb;
204 }
205
206 if (icmp_packet->msg_type != ECHO_REQUEST) {
207 bat_dbg(DBG_BATMAN, bat_priv,
208 "Error - can't send packet from char device: "
209 "got bogus message type (expected: ECHO_REQUEST)\n");
210 len = -EINVAL;
211 goto free_skb;
212 }
213
214 icmp_packet->uid = socket_client->index;
215
216 if (icmp_packet->version != COMPAT_VERSION) {
217 icmp_packet->msg_type = PARAMETER_PROBLEM;
218 icmp_packet->ttl = COMPAT_VERSION;
219 bat_socket_add_packet(socket_client, icmp_packet, packet_len);
220 goto free_skb;
221 }
222
223 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
224 goto dst_unreach;
225
226 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
227 orig_node = ((struct orig_node *)hash_find(bat_priv->orig_hash,
228 icmp_packet->dst));
229
230 if (!orig_node)
231 goto unlock;
232
233 if (!orig_node->router)
234 goto unlock;
235
236 batman_if = orig_node->router->if_incoming;
237 memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
238
239 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
240
241 if (!batman_if)
242 goto dst_unreach;
243
244 if (batman_if->if_status != IF_ACTIVE)
245 goto dst_unreach;
246
247 memcpy(icmp_packet->orig,
248 bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
249
250 if (packet_len == sizeof(struct icmp_packet_rr))
251 memcpy(icmp_packet->rr, batman_if->net_dev->dev_addr, ETH_ALEN);
252
253
254 send_skb_packet(skb, batman_if, dstaddr);
255
256 goto out;
257
258unlock:
259 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
260dst_unreach:
261 icmp_packet->msg_type = DESTINATION_UNREACHABLE;
262 bat_socket_add_packet(socket_client, icmp_packet, packet_len);
263free_skb:
264 kfree_skb(skb);
265out:
266 return len;
267}
268
269static unsigned int bat_socket_poll(struct file *file, poll_table *wait)
270{
271 struct socket_client *socket_client = file->private_data;
272
273 poll_wait(file, &socket_client->queue_wait, wait);
274
275 if (socket_client->queue_len > 0)
276 return POLLIN | POLLRDNORM;
277
278 return 0;
279}
280
281static const struct file_operations fops = {
282 .owner = THIS_MODULE,
283 .open = bat_socket_open,
284 .release = bat_socket_release,
285 .read = bat_socket_read,
286 .write = bat_socket_write,
287 .poll = bat_socket_poll,
288 .llseek = no_llseek,
289};
290
291int bat_socket_setup(struct bat_priv *bat_priv)
292{
293 struct dentry *d;
294
295 if (!bat_priv->debug_dir)
296 goto err;
297
298 d = debugfs_create_file(ICMP_SOCKET, S_IFREG | S_IWUSR | S_IRUSR,
299 bat_priv->debug_dir, bat_priv, &fops);
300 if (d)
301 goto err;
302
303 return 0;
304
305err:
306 return 1;
307}
308
309static void bat_socket_add_packet(struct socket_client *socket_client,
310 struct icmp_packet_rr *icmp_packet,
311 size_t icmp_len)
312{
313 struct socket_packet *socket_packet;
314 unsigned long flags;
315
316 socket_packet = kmalloc(sizeof(struct socket_packet), GFP_ATOMIC);
317
318 if (!socket_packet)
319 return;
320
321 INIT_LIST_HEAD(&socket_packet->list);
322 memcpy(&socket_packet->icmp_packet, icmp_packet, icmp_len);
323 socket_packet->icmp_len = icmp_len;
324
325 spin_lock_irqsave(&socket_client->lock, flags);
326
327 /* while waiting for the lock the socket_client could have been
328 * deleted */
329 if (!socket_client_hash[icmp_packet->uid]) {
330 spin_unlock_irqrestore(&socket_client->lock, flags);
331 kfree(socket_packet);
332 return;
333 }
334
335 list_add_tail(&socket_packet->list, &socket_client->queue_list);
336 socket_client->queue_len++;
337
338 if (socket_client->queue_len > 100) {
339 socket_packet = list_first_entry(&socket_client->queue_list,
340 struct socket_packet, list);
341
342 list_del(&socket_packet->list);
343 kfree(socket_packet);
344 socket_client->queue_len--;
345 }
346
347 spin_unlock_irqrestore(&socket_client->lock, flags);
348
349 wake_up(&socket_client->queue_wait);
350}
351
352void bat_socket_receive_packet(struct icmp_packet_rr *icmp_packet,
353 size_t icmp_len)
354{
355 struct socket_client *hash = socket_client_hash[icmp_packet->uid];
356
357 if (hash)
358 bat_socket_add_packet(hash, icmp_packet, icmp_len);
359}
diff --git a/drivers/staging/batman-adv/icmp_socket.h b/drivers/staging/batman-adv/icmp_socket.h
deleted file mode 100644
index bf9b348cde27..000000000000
--- a/drivers/staging/batman-adv/icmp_socket.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_ICMP_SOCKET_H_
23#define _NET_BATMAN_ADV_ICMP_SOCKET_H_
24
25#include "types.h"
26
27#define ICMP_SOCKET "socket"
28
29void bat_socket_init(void);
30int bat_socket_setup(struct bat_priv *bat_priv);
31void bat_socket_receive_packet(struct icmp_packet_rr *icmp_packet,
32 size_t icmp_len);
33
34#endif /* _NET_BATMAN_ADV_ICMP_SOCKET_H_ */
diff --git a/drivers/staging/batman-adv/main.c b/drivers/staging/batman-adv/main.c
deleted file mode 100644
index 0587940d2723..000000000000
--- a/drivers/staging/batman-adv/main.c
+++ /dev/null
@@ -1,217 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "bat_sysfs.h"
24#include "bat_debugfs.h"
25#include "routing.h"
26#include "send.h"
27#include "originator.h"
28#include "soft-interface.h"
29#include "icmp_socket.h"
30#include "translation-table.h"
31#include "hard-interface.h"
32#include "types.h"
33#include "vis.h"
34#include "hash.h"
35
36struct list_head if_list;
37
38unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
39
40struct workqueue_struct *bat_event_workqueue;
41
42static int __init batman_init(void)
43{
44 INIT_LIST_HEAD(&if_list);
45
46 /* the name should not be longer than 10 chars - see
47 * http://lwn.net/Articles/23634/ */
48 bat_event_workqueue = create_singlethread_workqueue("bat_events");
49
50 if (!bat_event_workqueue)
51 return -ENOMEM;
52
53 bat_socket_init();
54 debugfs_init();
55
56 register_netdevice_notifier(&hard_if_notifier);
57
58 pr_info("B.A.T.M.A.N. advanced %s%s (compatibility version %i) "
59 "loaded\n", SOURCE_VERSION, REVISION_VERSION_STR,
60 COMPAT_VERSION);
61
62 return 0;
63}
64
65static void __exit batman_exit(void)
66{
67 debugfs_destroy();
68 unregister_netdevice_notifier(&hard_if_notifier);
69 hardif_remove_interfaces();
70
71 flush_workqueue(bat_event_workqueue);
72 destroy_workqueue(bat_event_workqueue);
73 bat_event_workqueue = NULL;
74
75 rcu_barrier();
76}
77
78int mesh_init(struct net_device *soft_iface)
79{
80 struct bat_priv *bat_priv = netdev_priv(soft_iface);
81
82 spin_lock_init(&bat_priv->orig_hash_lock);
83 spin_lock_init(&bat_priv->forw_bat_list_lock);
84 spin_lock_init(&bat_priv->forw_bcast_list_lock);
85 spin_lock_init(&bat_priv->hna_lhash_lock);
86 spin_lock_init(&bat_priv->hna_ghash_lock);
87 spin_lock_init(&bat_priv->vis_hash_lock);
88 spin_lock_init(&bat_priv->vis_list_lock);
89
90 INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
91 INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
92
93 if (originator_init(bat_priv) < 1)
94 goto err;
95
96 if (hna_local_init(bat_priv) < 1)
97 goto err;
98
99 if (hna_global_init(bat_priv) < 1)
100 goto err;
101
102 hna_local_add(soft_iface, soft_iface->dev_addr);
103
104 if (vis_init(bat_priv) < 1)
105 goto err;
106
107 atomic_set(&bat_priv->mesh_state, MESH_ACTIVE);
108 goto end;
109
110err:
111 pr_err("Unable to allocate memory for mesh information structures: "
112 "out of mem ?\n");
113 mesh_free(soft_iface);
114 return -1;
115
116end:
117 return 0;
118}
119
120void mesh_free(struct net_device *soft_iface)
121{
122 struct bat_priv *bat_priv = netdev_priv(soft_iface);
123
124 atomic_set(&bat_priv->mesh_state, MESH_DEACTIVATING);
125
126 purge_outstanding_packets(bat_priv, NULL);
127
128 vis_quit(bat_priv);
129
130 originator_free(bat_priv);
131
132 hna_local_free(bat_priv);
133 hna_global_free(bat_priv);
134
135 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
136}
137
138void inc_module_count(void)
139{
140 try_module_get(THIS_MODULE);
141}
142
143void dec_module_count(void)
144{
145 module_put(THIS_MODULE);
146}
147
148/* returns 1 if they are the same originator */
149
150int compare_orig(void *data1, void *data2)
151{
152 return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
153}
154
155/* hashfunction to choose an entry in a hash table of given size */
156/* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */
157int choose_orig(void *data, int32_t size)
158{
159 unsigned char *key = data;
160 uint32_t hash = 0;
161 size_t i;
162
163 for (i = 0; i < 6; i++) {
164 hash += key[i];
165 hash += (hash << 10);
166 hash ^= (hash >> 6);
167 }
168
169 hash += (hash << 3);
170 hash ^= (hash >> 11);
171 hash += (hash << 15);
172
173 return hash % size;
174}
175
176int is_my_mac(uint8_t *addr)
177{
178 struct batman_if *batman_if;
179
180 rcu_read_lock();
181 list_for_each_entry_rcu(batman_if, &if_list, list) {
182 if (batman_if->if_status != IF_ACTIVE)
183 continue;
184
185 if (compare_orig(batman_if->net_dev->dev_addr, addr)) {
186 rcu_read_unlock();
187 return 1;
188 }
189 }
190 rcu_read_unlock();
191 return 0;
192
193}
194
195int is_bcast(uint8_t *addr)
196{
197 return (addr[0] == (uint8_t)0xff) && (addr[1] == (uint8_t)0xff);
198}
199
200int is_mcast(uint8_t *addr)
201{
202 return *addr & 0x01;
203}
204
205module_init(batman_init);
206module_exit(batman_exit);
207
208MODULE_LICENSE("GPL");
209
210MODULE_AUTHOR(DRIVER_AUTHOR);
211MODULE_DESCRIPTION(DRIVER_DESC);
212MODULE_SUPPORTED_DEVICE(DRIVER_DEVICE);
213#ifdef REVISION_VERSION
214MODULE_VERSION(SOURCE_VERSION "-" REVISION_VERSION);
215#else
216MODULE_VERSION(SOURCE_VERSION);
217#endif
diff --git a/drivers/staging/batman-adv/main.h b/drivers/staging/batman-adv/main.h
deleted file mode 100644
index 5e3f51681f5e..000000000000
--- a/drivers/staging/batman-adv/main.h
+++ /dev/null
@@ -1,183 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_MAIN_H_
23#define _NET_BATMAN_ADV_MAIN_H_
24
25/* Kernel Programming */
26#define LINUX
27
28#define DRIVER_AUTHOR "Marek Lindner <lindner_marek@yahoo.de>, " \
29 "Simon Wunderlich <siwu@hrz.tu-chemnitz.de>"
30#define DRIVER_DESC "B.A.T.M.A.N. advanced"
31#define DRIVER_DEVICE "batman-adv"
32
33#define SOURCE_VERSION "next"
34
35
36/* B.A.T.M.A.N. parameters */
37
38#define TQ_MAX_VALUE 255
39#define JITTER 20
40#define TTL 50 /* Time To Live of broadcast messages */
41
42#define PURGE_TIMEOUT 200 /* purge originators after time in seconds if no
43 * valid packet comes in -> TODO: check
44 * influence on TQ_LOCAL_WINDOW_SIZE */
45#define LOCAL_HNA_TIMEOUT 3600 /* in seconds */
46
47#define TQ_LOCAL_WINDOW_SIZE 64 /* sliding packet range of received originator
48 * messages in squence numbers (should be a
49 * multiple of our word size) */
50#define TQ_GLOBAL_WINDOW_SIZE 5
51#define TQ_LOCAL_BIDRECT_SEND_MINIMUM 1
52#define TQ_LOCAL_BIDRECT_RECV_MINIMUM 1
53#define TQ_TOTAL_BIDRECT_LIMIT 1
54
55#define TQ_HOP_PENALTY 10
56
57#define NUM_WORDS (TQ_LOCAL_WINDOW_SIZE / WORD_BIT_SIZE)
58
59#define PACKBUFF_SIZE 2000
60#define LOG_BUF_LEN 8192 /* has to be a power of 2 */
61
62#define VIS_INTERVAL 5000 /* 5 seconds */
63
64/* how much worse secondary interfaces may be to
65 * to be considered as bonding candidates */
66
67#define BONDING_TQ_THRESHOLD 50
68
69#define MAX_AGGREGATION_BYTES 512 /* should not be bigger than 512 bytes or
70 * change the size of
71 * forw_packet->direct_link_flags */
72#define MAX_AGGREGATION_MS 100
73
74#define RESET_PROTECTION_MS 30000
75#define EXPECTED_SEQNO_RANGE 65536
76/* don't reset again within 30 seconds */
77
78#define MESH_INACTIVE 0
79#define MESH_ACTIVE 1
80#define MESH_DEACTIVATING 2
81
82#define BCAST_QUEUE_LEN 256
83#define BATMAN_QUEUE_LEN 256
84
85/*
86 * Debug Messages
87 */
88#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt /* Append 'batman-adv: ' before
89 * kernel messages */
90
91#define DBG_BATMAN 1 /* all messages related to routing / flooding /
92 * broadcasting / etc */
93#define DBG_ROUTES 2 /* route or hna added / changed / deleted */
94#define DBG_ALL 3
95
96#define LOG_BUF_LEN 8192 /* has to be a power of 2 */
97
98
99/*
100 * Vis
101 */
102
103/* #define VIS_SUBCLUSTERS_DISABLED */
104
105/*
106 * Kernel headers
107 */
108
109#include <linux/mutex.h> /* mutex */
110#include <linux/module.h> /* needed by all modules */
111#include <linux/netdevice.h> /* netdevice */
112#include <linux/if_ether.h> /* ethernet header */
113#include <linux/poll.h> /* poll_table */
114#include <linux/kthread.h> /* kernel threads */
115#include <linux/pkt_sched.h> /* schedule types */
116#include <linux/workqueue.h> /* workqueue */
117#include <linux/slab.h>
118#include <net/sock.h> /* struct sock */
119#include <linux/jiffies.h>
120#include <linux/seq_file.h>
121#include "types.h"
122
123#ifndef REVISION_VERSION
124#define REVISION_VERSION_STR ""
125#else
126#define REVISION_VERSION_STR " "REVISION_VERSION
127#endif
128
129extern struct list_head if_list;
130
131extern unsigned char broadcast_addr[];
132extern struct workqueue_struct *bat_event_workqueue;
133
134int mesh_init(struct net_device *soft_iface);
135void mesh_free(struct net_device *soft_iface);
136void inc_module_count(void);
137void dec_module_count(void);
138int compare_orig(void *data1, void *data2);
139int choose_orig(void *data, int32_t size);
140int is_my_mac(uint8_t *addr);
141int is_bcast(uint8_t *addr);
142int is_mcast(uint8_t *addr);
143
144#ifdef CONFIG_BATMAN_ADV_DEBUG
145int debug_log(struct bat_priv *bat_priv, char *fmt, ...);
146
147#define bat_dbg(type, bat_priv, fmt, arg...) \
148 do { \
149 if (atomic_read(&bat_priv->log_level) & type) \
150 debug_log(bat_priv, fmt, ## arg); \
151 } \
152 while (0)
153#else /* !CONFIG_BATMAN_ADV_DEBUG */
154static inline void bat_dbg(char type __attribute__((unused)),
155 struct bat_priv *bat_priv __attribute__((unused)),
156 char *fmt __attribute__((unused)), ...)
157{
158}
159#endif
160
161#define bat_warning(net_dev, fmt, arg...) \
162 do { \
163 struct net_device *_netdev = (net_dev); \
164 struct bat_priv *_batpriv = netdev_priv(_netdev); \
165 bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
166 pr_warning("%s: " fmt, _netdev->name, ## arg); \
167 } while (0)
168#define bat_info(net_dev, fmt, arg...) \
169 do { \
170 struct net_device *_netdev = (net_dev); \
171 struct bat_priv *_batpriv = netdev_priv(_netdev); \
172 bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
173 pr_info("%s: " fmt, _netdev->name, ## arg); \
174 } while (0)
175#define bat_err(net_dev, fmt, arg...) \
176 do { \
177 struct net_device *_netdev = (net_dev); \
178 struct bat_priv *_batpriv = netdev_priv(_netdev); \
179 bat_dbg(DBG_ALL, _batpriv, fmt, ## arg); \
180 pr_err("%s: " fmt, _netdev->name, ## arg); \
181 } while (0)
182
183#endif /* _NET_BATMAN_ADV_MAIN_H_ */
diff --git a/drivers/staging/batman-adv/originator.c b/drivers/staging/batman-adv/originator.c
deleted file mode 100644
index 55270080a44b..000000000000
--- a/drivers/staging/batman-adv/originator.c
+++ /dev/null
@@ -1,533 +0,0 @@
1/*
2 * Copyright (C) 2009-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22/* increase the reference counter for this originator */
23
24#include "main.h"
25#include "originator.h"
26#include "hash.h"
27#include "translation-table.h"
28#include "routing.h"
29#include "hard-interface.h"
30#include "unicast.h"
31
32static void purge_orig(struct work_struct *work);
33
34static void start_purge_timer(struct bat_priv *bat_priv)
35{
36 INIT_DELAYED_WORK(&bat_priv->orig_work, purge_orig);
37 queue_delayed_work(bat_event_workqueue, &bat_priv->orig_work, 1 * HZ);
38}
39
40int originator_init(struct bat_priv *bat_priv)
41{
42 unsigned long flags;
43 if (bat_priv->orig_hash)
44 return 1;
45
46 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
47 bat_priv->orig_hash = hash_new(128, compare_orig, choose_orig);
48
49 if (!bat_priv->orig_hash)
50 goto err;
51
52 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
53 start_purge_timer(bat_priv);
54 return 1;
55
56err:
57 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
58 return 0;
59}
60
61struct neigh_node *
62create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
63 uint8_t *neigh, struct batman_if *if_incoming)
64{
65 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
66 struct neigh_node *neigh_node;
67
68 bat_dbg(DBG_BATMAN, bat_priv,
69 "Creating new last-hop neighbor of originator\n");
70
71 neigh_node = kzalloc(sizeof(struct neigh_node), GFP_ATOMIC);
72 if (!neigh_node)
73 return NULL;
74
75 INIT_LIST_HEAD(&neigh_node->list);
76
77 memcpy(neigh_node->addr, neigh, ETH_ALEN);
78 neigh_node->orig_node = orig_neigh_node;
79 neigh_node->if_incoming = if_incoming;
80
81 list_add_tail(&neigh_node->list, &orig_node->neigh_list);
82 return neigh_node;
83}
84
85static void free_orig_node(void *data, void *arg)
86{
87 struct list_head *list_pos, *list_pos_tmp;
88 struct neigh_node *neigh_node;
89 struct orig_node *orig_node = (struct orig_node *)data;
90 struct bat_priv *bat_priv = (struct bat_priv *)arg;
91
92 /* for all neighbors towards this originator ... */
93 list_for_each_safe(list_pos, list_pos_tmp, &orig_node->neigh_list) {
94 neigh_node = list_entry(list_pos, struct neigh_node, list);
95
96 list_del(list_pos);
97 kfree(neigh_node);
98 }
99
100 frag_list_free(&orig_node->frag_list);
101 hna_global_del_orig(bat_priv, orig_node, "originator timed out");
102
103 kfree(orig_node->bcast_own);
104 kfree(orig_node->bcast_own_sum);
105 kfree(orig_node);
106}
107
108void originator_free(struct bat_priv *bat_priv)
109{
110 unsigned long flags;
111
112 if (!bat_priv->orig_hash)
113 return;
114
115 cancel_delayed_work_sync(&bat_priv->orig_work);
116
117 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
118 hash_delete(bat_priv->orig_hash, free_orig_node, bat_priv);
119 bat_priv->orig_hash = NULL;
120 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
121}
122
123/* this function finds or creates an originator entry for the given
124 * address if it does not exits */
125struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr)
126{
127 struct orig_node *orig_node;
128 struct hashtable_t *swaphash;
129 int size;
130
131 orig_node = ((struct orig_node *)hash_find(bat_priv->orig_hash, addr));
132
133 if (orig_node)
134 return orig_node;
135
136 bat_dbg(DBG_BATMAN, bat_priv,
137 "Creating new originator: %pM\n", addr);
138
139 orig_node = kzalloc(sizeof(struct orig_node), GFP_ATOMIC);
140 if (!orig_node)
141 return NULL;
142
143 INIT_LIST_HEAD(&orig_node->neigh_list);
144
145 memcpy(orig_node->orig, addr, ETH_ALEN);
146 orig_node->router = NULL;
147 orig_node->hna_buff = NULL;
148 orig_node->bcast_seqno_reset = jiffies - 1
149 - msecs_to_jiffies(RESET_PROTECTION_MS);
150 orig_node->batman_seqno_reset = jiffies - 1
151 - msecs_to_jiffies(RESET_PROTECTION_MS);
152
153 size = bat_priv->num_ifaces * sizeof(TYPE_OF_WORD) * NUM_WORDS;
154
155 orig_node->bcast_own = kzalloc(size, GFP_ATOMIC);
156 if (!orig_node->bcast_own)
157 goto free_orig_node;
158
159 size = bat_priv->num_ifaces * sizeof(uint8_t);
160 orig_node->bcast_own_sum = kzalloc(size, GFP_ATOMIC);
161
162 INIT_LIST_HEAD(&orig_node->frag_list);
163 orig_node->last_frag_packet = 0;
164
165 if (!orig_node->bcast_own_sum)
166 goto free_bcast_own;
167
168 if (hash_add(bat_priv->orig_hash, orig_node) < 0)
169 goto free_bcast_own_sum;
170
171 if (bat_priv->orig_hash->elements * 4 > bat_priv->orig_hash->size) {
172 swaphash = hash_resize(bat_priv->orig_hash,
173 bat_priv->orig_hash->size * 2);
174
175 if (!swaphash)
176 bat_dbg(DBG_BATMAN, bat_priv,
177 "Couldn't resize orig hash table\n");
178 else
179 bat_priv->orig_hash = swaphash;
180 }
181
182 return orig_node;
183free_bcast_own_sum:
184 kfree(orig_node->bcast_own_sum);
185free_bcast_own:
186 kfree(orig_node->bcast_own);
187free_orig_node:
188 kfree(orig_node);
189 return NULL;
190}
191
192static bool purge_orig_neighbors(struct bat_priv *bat_priv,
193 struct orig_node *orig_node,
194 struct neigh_node **best_neigh_node)
195{
196 struct list_head *list_pos, *list_pos_tmp;
197 struct neigh_node *neigh_node;
198 bool neigh_purged = false;
199
200 *best_neigh_node = NULL;
201
202 /* for all neighbors towards this originator ... */
203 list_for_each_safe(list_pos, list_pos_tmp, &orig_node->neigh_list) {
204 neigh_node = list_entry(list_pos, struct neigh_node, list);
205
206 if ((time_after(jiffies,
207 neigh_node->last_valid + PURGE_TIMEOUT * HZ)) ||
208 (neigh_node->if_incoming->if_status == IF_INACTIVE) ||
209 (neigh_node->if_incoming->if_status == IF_TO_BE_REMOVED)) {
210
211 if (neigh_node->if_incoming->if_status ==
212 IF_TO_BE_REMOVED)
213 bat_dbg(DBG_BATMAN, bat_priv,
214 "neighbor purge: originator %pM, "
215 "neighbor: %pM, iface: %s\n",
216 orig_node->orig, neigh_node->addr,
217 neigh_node->if_incoming->net_dev->name);
218 else
219 bat_dbg(DBG_BATMAN, bat_priv,
220 "neighbor timeout: originator %pM, "
221 "neighbor: %pM, last_valid: %lu\n",
222 orig_node->orig, neigh_node->addr,
223 (neigh_node->last_valid / HZ));
224
225 neigh_purged = true;
226 list_del(list_pos);
227 kfree(neigh_node);
228 } else {
229 if ((*best_neigh_node == NULL) ||
230 (neigh_node->tq_avg > (*best_neigh_node)->tq_avg))
231 *best_neigh_node = neigh_node;
232 }
233 }
234 return neigh_purged;
235}
236
237static bool purge_orig_node(struct bat_priv *bat_priv,
238 struct orig_node *orig_node)
239{
240 struct neigh_node *best_neigh_node;
241
242 if (time_after(jiffies,
243 orig_node->last_valid + 2 * PURGE_TIMEOUT * HZ)) {
244
245 bat_dbg(DBG_BATMAN, bat_priv,
246 "Originator timeout: originator %pM, last_valid %lu\n",
247 orig_node->orig, (orig_node->last_valid / HZ));
248 return true;
249 } else {
250 if (purge_orig_neighbors(bat_priv, orig_node,
251 &best_neigh_node)) {
252 update_routes(bat_priv, orig_node,
253 best_neigh_node,
254 orig_node->hna_buff,
255 orig_node->hna_buff_len);
256 /* update bonding candidates, we could have lost
257 * some candidates. */
258 update_bonding_candidates(bat_priv, orig_node);
259 }
260 }
261
262 return false;
263}
264
265static void _purge_orig(struct bat_priv *bat_priv)
266{
267 HASHIT(hashit);
268 struct orig_node *orig_node;
269 unsigned long flags;
270
271 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
272
273 /* for all origins... */
274 while (hash_iterate(bat_priv->orig_hash, &hashit)) {
275 orig_node = hashit.bucket->data;
276
277 if (purge_orig_node(bat_priv, orig_node)) {
278 hash_remove_bucket(bat_priv->orig_hash, &hashit);
279 free_orig_node(orig_node, bat_priv);
280 }
281
282 if (time_after(jiffies, (orig_node->last_frag_packet +
283 msecs_to_jiffies(FRAG_TIMEOUT))))
284 frag_list_free(&orig_node->frag_list);
285 }
286
287 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
288
289}
290
291static void purge_orig(struct work_struct *work)
292{
293 struct delayed_work *delayed_work =
294 container_of(work, struct delayed_work, work);
295 struct bat_priv *bat_priv =
296 container_of(delayed_work, struct bat_priv, orig_work);
297
298 _purge_orig(bat_priv);
299 start_purge_timer(bat_priv);
300}
301
302void purge_orig_ref(struct bat_priv *bat_priv)
303{
304 _purge_orig(bat_priv);
305}
306
307int orig_seq_print_text(struct seq_file *seq, void *offset)
308{
309 HASHIT(hashit);
310 struct net_device *net_dev = (struct net_device *)seq->private;
311 struct bat_priv *bat_priv = netdev_priv(net_dev);
312 struct orig_node *orig_node;
313 struct neigh_node *neigh_node;
314 int batman_count = 0;
315 int last_seen_secs;
316 int last_seen_msecs;
317 unsigned long flags;
318
319 if ((!bat_priv->primary_if) ||
320 (bat_priv->primary_if->if_status != IF_ACTIVE)) {
321 if (!bat_priv->primary_if)
322 return seq_printf(seq, "BATMAN mesh %s disabled - "
323 "please specify interfaces to enable it\n",
324 net_dev->name);
325
326 return seq_printf(seq, "BATMAN mesh %s "
327 "disabled - primary interface not active\n",
328 net_dev->name);
329 }
330
331 seq_printf(seq, "[B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%pM (%s)]\n",
332 SOURCE_VERSION, REVISION_VERSION_STR,
333 bat_priv->primary_if->net_dev->name,
334 bat_priv->primary_if->net_dev->dev_addr, net_dev->name);
335 seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
336 "Originator", "last-seen", "#", TQ_MAX_VALUE, "Nexthop",
337 "outgoingIF", "Potential nexthops");
338
339 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
340
341 while (hash_iterate(bat_priv->orig_hash, &hashit)) {
342
343 orig_node = hashit.bucket->data;
344
345 if (!orig_node->router)
346 continue;
347
348 if (orig_node->router->tq_avg == 0)
349 continue;
350
351 last_seen_secs = jiffies_to_msecs(jiffies -
352 orig_node->last_valid) / 1000;
353 last_seen_msecs = jiffies_to_msecs(jiffies -
354 orig_node->last_valid) % 1000;
355
356 seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:",
357 orig_node->orig, last_seen_secs, last_seen_msecs,
358 orig_node->router->tq_avg, orig_node->router->addr,
359 orig_node->router->if_incoming->net_dev->name);
360
361 list_for_each_entry(neigh_node, &orig_node->neigh_list, list) {
362 seq_printf(seq, " %pM (%3i)", neigh_node->addr,
363 neigh_node->tq_avg);
364 }
365
366 seq_printf(seq, "\n");
367 batman_count++;
368 }
369
370 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
371
372 if ((batman_count == 0))
373 seq_printf(seq, "No batman nodes in range ...\n");
374
375 return 0;
376}
377
378static int orig_node_add_if(struct orig_node *orig_node, int max_if_num)
379{
380 void *data_ptr;
381
382 data_ptr = kmalloc(max_if_num * sizeof(TYPE_OF_WORD) * NUM_WORDS,
383 GFP_ATOMIC);
384 if (!data_ptr) {
385 pr_err("Can't resize orig: out of memory\n");
386 return -1;
387 }
388
389 memcpy(data_ptr, orig_node->bcast_own,
390 (max_if_num - 1) * sizeof(TYPE_OF_WORD) * NUM_WORDS);
391 kfree(orig_node->bcast_own);
392 orig_node->bcast_own = data_ptr;
393
394 data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
395 if (!data_ptr) {
396 pr_err("Can't resize orig: out of memory\n");
397 return -1;
398 }
399
400 memcpy(data_ptr, orig_node->bcast_own_sum,
401 (max_if_num - 1) * sizeof(uint8_t));
402 kfree(orig_node->bcast_own_sum);
403 orig_node->bcast_own_sum = data_ptr;
404
405 return 0;
406}
407
408int orig_hash_add_if(struct batman_if *batman_if, int max_if_num)
409{
410 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
411 struct orig_node *orig_node;
412 unsigned long flags;
413 HASHIT(hashit);
414
415 /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
416 * if_num */
417 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
418
419 while (hash_iterate(bat_priv->orig_hash, &hashit)) {
420 orig_node = hashit.bucket->data;
421
422 if (orig_node_add_if(orig_node, max_if_num) == -1)
423 goto err;
424 }
425
426 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
427 return 0;
428
429err:
430 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
431 return -ENOMEM;
432}
433
434static int orig_node_del_if(struct orig_node *orig_node,
435 int max_if_num, int del_if_num)
436{
437 void *data_ptr = NULL;
438 int chunk_size;
439
440 /* last interface was removed */
441 if (max_if_num == 0)
442 goto free_bcast_own;
443
444 chunk_size = sizeof(TYPE_OF_WORD) * NUM_WORDS;
445 data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
446 if (!data_ptr) {
447 pr_err("Can't resize orig: out of memory\n");
448 return -1;
449 }
450
451 /* copy first part */
452 memcpy(data_ptr, orig_node->bcast_own, del_if_num * chunk_size);
453
454 /* copy second part */
455 memcpy(data_ptr + del_if_num * chunk_size,
456 orig_node->bcast_own + ((del_if_num + 1) * chunk_size),
457 (max_if_num - del_if_num) * chunk_size);
458
459free_bcast_own:
460 kfree(orig_node->bcast_own);
461 orig_node->bcast_own = data_ptr;
462
463 if (max_if_num == 0)
464 goto free_own_sum;
465
466 data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
467 if (!data_ptr) {
468 pr_err("Can't resize orig: out of memory\n");
469 return -1;
470 }
471
472 memcpy(data_ptr, orig_node->bcast_own_sum,
473 del_if_num * sizeof(uint8_t));
474
475 memcpy(data_ptr + del_if_num * sizeof(uint8_t),
476 orig_node->bcast_own_sum + ((del_if_num + 1) * sizeof(uint8_t)),
477 (max_if_num - del_if_num) * sizeof(uint8_t));
478
479free_own_sum:
480 kfree(orig_node->bcast_own_sum);
481 orig_node->bcast_own_sum = data_ptr;
482
483 return 0;
484}
485
486int orig_hash_del_if(struct batman_if *batman_if, int max_if_num)
487{
488 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
489 struct batman_if *batman_if_tmp;
490 struct orig_node *orig_node;
491 unsigned long flags;
492 HASHIT(hashit);
493 int ret;
494
495 /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
496 * if_num */
497 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
498
499 while (hash_iterate(bat_priv->orig_hash, &hashit)) {
500 orig_node = hashit.bucket->data;
501
502 ret = orig_node_del_if(orig_node, max_if_num,
503 batman_if->if_num);
504
505 if (ret == -1)
506 goto err;
507 }
508
509 /* renumber remaining batman interfaces _inside_ of orig_hash_lock */
510 rcu_read_lock();
511 list_for_each_entry_rcu(batman_if_tmp, &if_list, list) {
512 if (batman_if_tmp->if_status == IF_NOT_IN_USE)
513 continue;
514
515 if (batman_if == batman_if_tmp)
516 continue;
517
518 if (batman_if->soft_iface != batman_if_tmp->soft_iface)
519 continue;
520
521 if (batman_if_tmp->if_num > batman_if->if_num)
522 batman_if_tmp->if_num--;
523 }
524 rcu_read_unlock();
525
526 batman_if->if_num = -1;
527 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
528 return 0;
529
530err:
531 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
532 return -ENOMEM;
533}
diff --git a/drivers/staging/batman-adv/originator.h b/drivers/staging/batman-adv/originator.h
deleted file mode 100644
index a97c4004776a..000000000000
--- a/drivers/staging/batman-adv/originator.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_ORIGINATOR_H_
23#define _NET_BATMAN_ADV_ORIGINATOR_H_
24
25int originator_init(struct bat_priv *bat_priv);
26void originator_free(struct bat_priv *bat_priv);
27void purge_orig_ref(struct bat_priv *bat_priv);
28struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr);
29struct neigh_node *
30create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
31 uint8_t *neigh, struct batman_if *if_incoming);
32int orig_seq_print_text(struct seq_file *seq, void *offset);
33int orig_hash_add_if(struct batman_if *batman_if, int max_if_num);
34int orig_hash_del_if(struct batman_if *batman_if, int max_if_num);
35
36#endif /* _NET_BATMAN_ADV_ORIGINATOR_H_ */
diff --git a/drivers/staging/batman-adv/packet.h b/drivers/staging/batman-adv/packet.h
deleted file mode 100644
index 2693383889a4..000000000000
--- a/drivers/staging/batman-adv/packet.h
+++ /dev/null
@@ -1,134 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_PACKET_H_
23#define _NET_BATMAN_ADV_PACKET_H_
24
25#define ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */
26
27#define BAT_PACKET 0x01
28#define BAT_ICMP 0x02
29#define BAT_UNICAST 0x03
30#define BAT_BCAST 0x04
31#define BAT_VIS 0x05
32#define BAT_UNICAST_FRAG 0x06
33
34/* this file is included by batctl which needs these defines */
35#define COMPAT_VERSION 13
36#define DIRECTLINK 0x40
37#define VIS_SERVER 0x20
38#define PRIMARIES_FIRST_HOP 0x10
39
40/* ICMP message types */
41#define ECHO_REPLY 0
42#define DESTINATION_UNREACHABLE 3
43#define ECHO_REQUEST 8
44#define TTL_EXCEEDED 11
45#define PARAMETER_PROBLEM 12
46
47/* vis defines */
48#define VIS_TYPE_SERVER_SYNC 0
49#define VIS_TYPE_CLIENT_UPDATE 1
50
51/* fragmentation defines */
52#define UNI_FRAG_HEAD 0x01
53
54struct batman_packet {
55 uint8_t packet_type;
56 uint8_t version; /* batman version field */
57 uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
58 uint8_t tq;
59 uint32_t seqno;
60 uint8_t orig[6];
61 uint8_t prev_sender[6];
62 uint8_t ttl;
63 uint8_t num_hna;
64} __attribute__((packed));
65
66#define BAT_PACKET_LEN sizeof(struct batman_packet)
67
68struct icmp_packet {
69 uint8_t packet_type;
70 uint8_t version; /* batman version field */
71 uint8_t msg_type; /* see ICMP message types above */
72 uint8_t ttl;
73 uint8_t dst[6];
74 uint8_t orig[6];
75 uint16_t seqno;
76 uint8_t uid;
77} __attribute__((packed));
78
79#define BAT_RR_LEN 16
80
81/* icmp_packet_rr must start with all fields from imcp_packet
82 * as this is assumed by code that handles ICMP packets */
83struct icmp_packet_rr {
84 uint8_t packet_type;
85 uint8_t version; /* batman version field */
86 uint8_t msg_type; /* see ICMP message types above */
87 uint8_t ttl;
88 uint8_t dst[6];
89 uint8_t orig[6];
90 uint16_t seqno;
91 uint8_t uid;
92 uint8_t rr_cur;
93 uint8_t rr[BAT_RR_LEN][ETH_ALEN];
94} __attribute__((packed));
95
96struct unicast_packet {
97 uint8_t packet_type;
98 uint8_t version; /* batman version field */
99 uint8_t dest[6];
100 uint8_t ttl;
101} __attribute__((packed));
102
103struct unicast_frag_packet {
104 uint8_t packet_type;
105 uint8_t version; /* batman version field */
106 uint8_t dest[6];
107 uint8_t ttl;
108 uint8_t flags;
109 uint8_t orig[6];
110 uint16_t seqno;
111} __attribute__((packed));
112
113struct bcast_packet {
114 uint8_t packet_type;
115 uint8_t version; /* batman version field */
116 uint8_t orig[6];
117 uint8_t ttl;
118 uint32_t seqno;
119} __attribute__((packed));
120
121struct vis_packet {
122 uint8_t packet_type;
123 uint8_t version; /* batman version field */
124 uint8_t vis_type; /* which type of vis-participant sent this? */
125 uint8_t entries; /* number of entries behind this struct */
126 uint32_t seqno; /* sequence number */
127 uint8_t ttl; /* TTL */
128 uint8_t vis_orig[6]; /* originator that informs about its
129 * neighbors */
130 uint8_t target_orig[6]; /* who should receive this packet */
131 uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */
132} __attribute__((packed));
133
134#endif /* _NET_BATMAN_ADV_PACKET_H_ */
diff --git a/drivers/staging/batman-adv/ring_buffer.c b/drivers/staging/batman-adv/ring_buffer.c
deleted file mode 100644
index defd37c9be1f..000000000000
--- a/drivers/staging/batman-adv/ring_buffer.c
+++ /dev/null
@@ -1,52 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "ring_buffer.h"
24
25void ring_buffer_set(uint8_t lq_recv[], uint8_t *lq_index, uint8_t value)
26{
27 lq_recv[*lq_index] = value;
28 *lq_index = (*lq_index + 1) % TQ_GLOBAL_WINDOW_SIZE;
29}
30
31uint8_t ring_buffer_avg(uint8_t lq_recv[])
32{
33 uint8_t *ptr;
34 uint16_t count = 0, i = 0, sum = 0;
35
36 ptr = lq_recv;
37
38 while (i < TQ_GLOBAL_WINDOW_SIZE) {
39 if (*ptr != 0) {
40 count++;
41 sum += *ptr;
42 }
43
44 i++;
45 ptr++;
46 }
47
48 if (count == 0)
49 return 0;
50
51 return (uint8_t)(sum / count);
52}
diff --git a/drivers/staging/batman-adv/ring_buffer.h b/drivers/staging/batman-adv/ring_buffer.h
deleted file mode 100644
index 6b0cb9aaeba5..000000000000
--- a/drivers/staging/batman-adv/ring_buffer.h
+++ /dev/null
@@ -1,28 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_RING_BUFFER_H_
23#define _NET_BATMAN_ADV_RING_BUFFER_H_
24
25void ring_buffer_set(uint8_t lq_recv[], uint8_t *lq_index, uint8_t value);
26uint8_t ring_buffer_avg(uint8_t lq_recv[]);
27
28#endif /* _NET_BATMAN_ADV_RING_BUFFER_H_ */
diff --git a/drivers/staging/batman-adv/routing.c b/drivers/staging/batman-adv/routing.c
deleted file mode 100644
index 657b69e6b957..000000000000
--- a/drivers/staging/batman-adv/routing.c
+++ /dev/null
@@ -1,1389 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "routing.h"
24#include "send.h"
25#include "hash.h"
26#include "soft-interface.h"
27#include "hard-interface.h"
28#include "icmp_socket.h"
29#include "translation-table.h"
30#include "originator.h"
31#include "types.h"
32#include "ring_buffer.h"
33#include "vis.h"
34#include "aggregation.h"
35#include "unicast.h"
36
37void slide_own_bcast_window(struct batman_if *batman_if)
38{
39 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
40 HASHIT(hashit);
41 struct orig_node *orig_node;
42 TYPE_OF_WORD *word;
43 unsigned long flags;
44
45 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
46
47 while (hash_iterate(bat_priv->orig_hash, &hashit)) {
48 orig_node = hashit.bucket->data;
49 word = &(orig_node->bcast_own[batman_if->if_num * NUM_WORDS]);
50
51 bit_get_packet(bat_priv, word, 1, 0);
52 orig_node->bcast_own_sum[batman_if->if_num] =
53 bit_packet_count(word);
54 }
55
56 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
57}
58
59static void update_HNA(struct bat_priv *bat_priv, struct orig_node *orig_node,
60 unsigned char *hna_buff, int hna_buff_len)
61{
62 if ((hna_buff_len != orig_node->hna_buff_len) ||
63 ((hna_buff_len > 0) &&
64 (orig_node->hna_buff_len > 0) &&
65 (memcmp(orig_node->hna_buff, hna_buff, hna_buff_len) != 0))) {
66
67 if (orig_node->hna_buff_len > 0)
68 hna_global_del_orig(bat_priv, orig_node,
69 "originator changed hna");
70
71 if ((hna_buff_len > 0) && (hna_buff != NULL))
72 hna_global_add_orig(bat_priv, orig_node,
73 hna_buff, hna_buff_len);
74 }
75}
76
77static void update_route(struct bat_priv *bat_priv,
78 struct orig_node *orig_node,
79 struct neigh_node *neigh_node,
80 unsigned char *hna_buff, int hna_buff_len)
81{
82 /* route deleted */
83 if ((orig_node->router != NULL) && (neigh_node == NULL)) {
84
85 bat_dbg(DBG_ROUTES, bat_priv, "Deleting route towards: %pM\n",
86 orig_node->orig);
87 hna_global_del_orig(bat_priv, orig_node,
88 "originator timed out");
89
90 /* route added */
91 } else if ((orig_node->router == NULL) && (neigh_node != NULL)) {
92
93 bat_dbg(DBG_ROUTES, bat_priv,
94 "Adding route towards: %pM (via %pM)\n",
95 orig_node->orig, neigh_node->addr);
96 hna_global_add_orig(bat_priv, orig_node,
97 hna_buff, hna_buff_len);
98
99 /* route changed */
100 } else {
101 bat_dbg(DBG_ROUTES, bat_priv,
102 "Changing route towards: %pM "
103 "(now via %pM - was via %pM)\n",
104 orig_node->orig, neigh_node->addr,
105 orig_node->router->addr);
106 }
107
108 orig_node->router = neigh_node;
109}
110
111
112void update_routes(struct bat_priv *bat_priv, struct orig_node *orig_node,
113 struct neigh_node *neigh_node, unsigned char *hna_buff,
114 int hna_buff_len)
115{
116
117 if (orig_node == NULL)
118 return;
119
120 if (orig_node->router != neigh_node)
121 update_route(bat_priv, orig_node, neigh_node,
122 hna_buff, hna_buff_len);
123 /* may be just HNA changed */
124 else
125 update_HNA(bat_priv, orig_node, hna_buff, hna_buff_len);
126}
127
128static int is_bidirectional_neigh(struct orig_node *orig_node,
129 struct orig_node *orig_neigh_node,
130 struct batman_packet *batman_packet,
131 struct batman_if *if_incoming)
132{
133 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
134 struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
135 unsigned char total_count;
136
137 if (orig_node == orig_neigh_node) {
138 list_for_each_entry(tmp_neigh_node,
139 &orig_node->neigh_list,
140 list) {
141
142 if (compare_orig(tmp_neigh_node->addr,
143 orig_neigh_node->orig) &&
144 (tmp_neigh_node->if_incoming == if_incoming))
145 neigh_node = tmp_neigh_node;
146 }
147
148 if (!neigh_node)
149 neigh_node = create_neighbor(orig_node,
150 orig_neigh_node,
151 orig_neigh_node->orig,
152 if_incoming);
153 /* create_neighbor failed, return 0 */
154 if (!neigh_node)
155 return 0;
156
157 neigh_node->last_valid = jiffies;
158 } else {
159 /* find packet count of corresponding one hop neighbor */
160 list_for_each_entry(tmp_neigh_node,
161 &orig_neigh_node->neigh_list, list) {
162
163 if (compare_orig(tmp_neigh_node->addr,
164 orig_neigh_node->orig) &&
165 (tmp_neigh_node->if_incoming == if_incoming))
166 neigh_node = tmp_neigh_node;
167 }
168
169 if (!neigh_node)
170 neigh_node = create_neighbor(orig_neigh_node,
171 orig_neigh_node,
172 orig_neigh_node->orig,
173 if_incoming);
174 /* create_neighbor failed, return 0 */
175 if (!neigh_node)
176 return 0;
177 }
178
179 orig_node->last_valid = jiffies;
180
181 /* pay attention to not get a value bigger than 100 % */
182 total_count = (orig_neigh_node->bcast_own_sum[if_incoming->if_num] >
183 neigh_node->real_packet_count ?
184 neigh_node->real_packet_count :
185 orig_neigh_node->bcast_own_sum[if_incoming->if_num]);
186
187 /* if we have too few packets (too less data) we set tq_own to zero */
188 /* if we receive too few packets it is not considered bidirectional */
189 if ((total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM) ||
190 (neigh_node->real_packet_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM))
191 orig_neigh_node->tq_own = 0;
192 else
193 /* neigh_node->real_packet_count is never zero as we
194 * only purge old information when getting new
195 * information */
196 orig_neigh_node->tq_own = (TQ_MAX_VALUE * total_count) /
197 neigh_node->real_packet_count;
198
199 /*
200 * 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
201 * affect the nearly-symmetric links only a little, but
202 * punishes asymmetric links more. This will give a value
203 * between 0 and TQ_MAX_VALUE
204 */
205 orig_neigh_node->tq_asym_penalty =
206 TQ_MAX_VALUE -
207 (TQ_MAX_VALUE *
208 (TQ_LOCAL_WINDOW_SIZE - neigh_node->real_packet_count) *
209 (TQ_LOCAL_WINDOW_SIZE - neigh_node->real_packet_count) *
210 (TQ_LOCAL_WINDOW_SIZE - neigh_node->real_packet_count)) /
211 (TQ_LOCAL_WINDOW_SIZE *
212 TQ_LOCAL_WINDOW_SIZE *
213 TQ_LOCAL_WINDOW_SIZE);
214
215 batman_packet->tq = ((batman_packet->tq *
216 orig_neigh_node->tq_own *
217 orig_neigh_node->tq_asym_penalty) /
218 (TQ_MAX_VALUE * TQ_MAX_VALUE));
219
220 bat_dbg(DBG_BATMAN, bat_priv,
221 "bidirectional: "
222 "orig = %-15pM neigh = %-15pM => own_bcast = %2i, "
223 "real recv = %2i, local tq: %3i, asym_penalty: %3i, "
224 "total tq: %3i\n",
225 orig_node->orig, orig_neigh_node->orig, total_count,
226 neigh_node->real_packet_count, orig_neigh_node->tq_own,
227 orig_neigh_node->tq_asym_penalty, batman_packet->tq);
228
229 /* if link has the minimum required transmission quality
230 * consider it bidirectional */
231 if (batman_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT)
232 return 1;
233
234 return 0;
235}
236
237static void update_orig(struct bat_priv *bat_priv,
238 struct orig_node *orig_node,
239 struct ethhdr *ethhdr,
240 struct batman_packet *batman_packet,
241 struct batman_if *if_incoming,
242 unsigned char *hna_buff, int hna_buff_len,
243 char is_duplicate)
244{
245 struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
246 int tmp_hna_buff_len;
247
248 bat_dbg(DBG_BATMAN, bat_priv, "update_originator(): "
249 "Searching and updating originator entry of received packet\n");
250
251 list_for_each_entry(tmp_neigh_node, &orig_node->neigh_list, list) {
252 if (compare_orig(tmp_neigh_node->addr, ethhdr->h_source) &&
253 (tmp_neigh_node->if_incoming == if_incoming)) {
254 neigh_node = tmp_neigh_node;
255 continue;
256 }
257
258 if (is_duplicate)
259 continue;
260
261 ring_buffer_set(tmp_neigh_node->tq_recv,
262 &tmp_neigh_node->tq_index, 0);
263 tmp_neigh_node->tq_avg =
264 ring_buffer_avg(tmp_neigh_node->tq_recv);
265 }
266
267 if (!neigh_node) {
268 struct orig_node *orig_tmp;
269
270 orig_tmp = get_orig_node(bat_priv, ethhdr->h_source);
271 if (!orig_tmp)
272 return;
273
274 neigh_node = create_neighbor(orig_node, orig_tmp,
275 ethhdr->h_source, if_incoming);
276 if (!neigh_node)
277 return;
278 } else
279 bat_dbg(DBG_BATMAN, bat_priv,
280 "Updating existing last-hop neighbor of originator\n");
281
282 orig_node->flags = batman_packet->flags;
283 neigh_node->last_valid = jiffies;
284
285 ring_buffer_set(neigh_node->tq_recv,
286 &neigh_node->tq_index,
287 batman_packet->tq);
288 neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv);
289
290 if (!is_duplicate) {
291 orig_node->last_ttl = batman_packet->ttl;
292 neigh_node->last_ttl = batman_packet->ttl;
293 }
294
295 tmp_hna_buff_len = (hna_buff_len > batman_packet->num_hna * ETH_ALEN ?
296 batman_packet->num_hna * ETH_ALEN : hna_buff_len);
297
298 /* if this neighbor already is our next hop there is nothing
299 * to change */
300 if (orig_node->router == neigh_node)
301 goto update_hna;
302
303 /* if this neighbor does not offer a better TQ we won't consider it */
304 if ((orig_node->router) &&
305 (orig_node->router->tq_avg > neigh_node->tq_avg))
306 goto update_hna;
307
308 /* if the TQ is the same and the link not more symetric we
309 * won't consider it either */
310 if ((orig_node->router) &&
311 ((neigh_node->tq_avg == orig_node->router->tq_avg) &&
312 (orig_node->router->orig_node->bcast_own_sum[if_incoming->if_num]
313 >= neigh_node->orig_node->bcast_own_sum[if_incoming->if_num])))
314 goto update_hna;
315
316 update_routes(bat_priv, orig_node, neigh_node,
317 hna_buff, tmp_hna_buff_len);
318 return;
319
320update_hna:
321 update_routes(bat_priv, orig_node, orig_node->router,
322 hna_buff, tmp_hna_buff_len);
323}
324
325/* checks whether the host restarted and is in the protection time.
326 * returns:
327 * 0 if the packet is to be accepted
328 * 1 if the packet is to be ignored.
329 */
330static int window_protected(struct bat_priv *bat_priv,
331 int32_t seq_num_diff,
332 unsigned long *last_reset)
333{
334 if ((seq_num_diff <= -TQ_LOCAL_WINDOW_SIZE)
335 || (seq_num_diff >= EXPECTED_SEQNO_RANGE)) {
336 if (time_after(jiffies, *last_reset +
337 msecs_to_jiffies(RESET_PROTECTION_MS))) {
338
339 *last_reset = jiffies;
340 bat_dbg(DBG_BATMAN, bat_priv,
341 "old packet received, start protection\n");
342
343 return 0;
344 } else
345 return 1;
346 }
347 return 0;
348}
349
350/* processes a batman packet for all interfaces, adjusts the sequence number and
351 * finds out whether it is a duplicate.
352 * returns:
353 * 1 the packet is a duplicate
354 * 0 the packet has not yet been received
355 * -1 the packet is old and has been received while the seqno window
356 * was protected. Caller should drop it.
357 */
358static char count_real_packets(struct ethhdr *ethhdr,
359 struct batman_packet *batman_packet,
360 struct batman_if *if_incoming)
361{
362 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
363 struct orig_node *orig_node;
364 struct neigh_node *tmp_neigh_node;
365 char is_duplicate = 0;
366 int32_t seq_diff;
367 int need_update = 0;
368 int set_mark;
369
370 orig_node = get_orig_node(bat_priv, batman_packet->orig);
371 if (orig_node == NULL)
372 return 0;
373
374 seq_diff = batman_packet->seqno - orig_node->last_real_seqno;
375
376 /* signalize caller that the packet is to be dropped. */
377 if (window_protected(bat_priv, seq_diff,
378 &orig_node->batman_seqno_reset))
379 return -1;
380
381 list_for_each_entry(tmp_neigh_node, &orig_node->neigh_list, list) {
382
383 is_duplicate |= get_bit_status(tmp_neigh_node->real_bits,
384 orig_node->last_real_seqno,
385 batman_packet->seqno);
386
387 if (compare_orig(tmp_neigh_node->addr, ethhdr->h_source) &&
388 (tmp_neigh_node->if_incoming == if_incoming))
389 set_mark = 1;
390 else
391 set_mark = 0;
392
393 /* if the window moved, set the update flag. */
394 need_update |= bit_get_packet(bat_priv,
395 tmp_neigh_node->real_bits,
396 seq_diff, set_mark);
397
398 tmp_neigh_node->real_packet_count =
399 bit_packet_count(tmp_neigh_node->real_bits);
400 }
401
402 if (need_update) {
403 bat_dbg(DBG_BATMAN, bat_priv,
404 "updating last_seqno: old %d, new %d\n",
405 orig_node->last_real_seqno, batman_packet->seqno);
406 orig_node->last_real_seqno = batman_packet->seqno;
407 }
408
409 return is_duplicate;
410}
411
412/* copy primary address for bonding */
413static void mark_bonding_address(struct bat_priv *bat_priv,
414 struct orig_node *orig_node,
415 struct orig_node *orig_neigh_node,
416 struct batman_packet *batman_packet)
417
418{
419 if (batman_packet->flags & PRIMARIES_FIRST_HOP)
420 memcpy(orig_neigh_node->primary_addr,
421 orig_node->orig, ETH_ALEN);
422
423 return;
424}
425
426/* mark possible bond.candidates in the neighbor list */
427void update_bonding_candidates(struct bat_priv *bat_priv,
428 struct orig_node *orig_node)
429{
430 int candidates;
431 int interference_candidate;
432 int best_tq;
433 struct neigh_node *tmp_neigh_node, *tmp_neigh_node2;
434 struct neigh_node *first_candidate, *last_candidate;
435
436 /* update the candidates for this originator */
437 if (!orig_node->router) {
438 orig_node->bond.candidates = 0;
439 return;
440 }
441
442 best_tq = orig_node->router->tq_avg;
443
444 /* update bond.candidates */
445
446 candidates = 0;
447
448 /* mark other nodes which also received "PRIMARIES FIRST HOP" packets
449 * as "bonding partner" */
450
451 /* first, zero the list */
452 list_for_each_entry(tmp_neigh_node, &orig_node->neigh_list, list) {
453 tmp_neigh_node->next_bond_candidate = NULL;
454 }
455
456 first_candidate = NULL;
457 last_candidate = NULL;
458 list_for_each_entry(tmp_neigh_node, &orig_node->neigh_list, list) {
459
460 /* only consider if it has the same primary address ... */
461 if (memcmp(orig_node->orig,
462 tmp_neigh_node->orig_node->primary_addr,
463 ETH_ALEN) != 0)
464 continue;
465
466 /* ... and is good enough to be considered */
467 if (tmp_neigh_node->tq_avg < best_tq - BONDING_TQ_THRESHOLD)
468 continue;
469
470 /* check if we have another candidate with the same
471 * mac address or interface. If we do, we won't
472 * select this candidate because of possible interference. */
473
474 interference_candidate = 0;
475 list_for_each_entry(tmp_neigh_node2,
476 &orig_node->neigh_list, list) {
477
478 if (tmp_neigh_node2 == tmp_neigh_node)
479 continue;
480
481 /* we only care if the other candidate is even
482 * considered as candidate. */
483 if (tmp_neigh_node2->next_bond_candidate == NULL)
484 continue;
485
486
487 if ((tmp_neigh_node->if_incoming ==
488 tmp_neigh_node2->if_incoming)
489 || (memcmp(tmp_neigh_node->addr,
490 tmp_neigh_node2->addr, ETH_ALEN) == 0)) {
491
492 interference_candidate = 1;
493 break;
494 }
495 }
496 /* don't care further if it is an interference candidate */
497 if (interference_candidate)
498 continue;
499
500 if (first_candidate == NULL) {
501 first_candidate = tmp_neigh_node;
502 tmp_neigh_node->next_bond_candidate = first_candidate;
503 } else
504 tmp_neigh_node->next_bond_candidate = last_candidate;
505
506 last_candidate = tmp_neigh_node;
507
508 candidates++;
509 }
510
511 if (candidates > 0) {
512 first_candidate->next_bond_candidate = last_candidate;
513 orig_node->bond.selected = first_candidate;
514 }
515
516 orig_node->bond.candidates = candidates;
517}
518
519void receive_bat_packet(struct ethhdr *ethhdr,
520 struct batman_packet *batman_packet,
521 unsigned char *hna_buff, int hna_buff_len,
522 struct batman_if *if_incoming)
523{
524 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
525 struct batman_if *batman_if;
526 struct orig_node *orig_neigh_node, *orig_node;
527 char has_directlink_flag;
528 char is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0;
529 char is_broadcast = 0, is_bidirectional, is_single_hop_neigh;
530 char is_duplicate;
531 uint32_t if_incoming_seqno;
532
533 /* Silently drop when the batman packet is actually not a
534 * correct packet.
535 *
536 * This might happen if a packet is padded (e.g. Ethernet has a
537 * minimum frame length of 64 byte) and the aggregation interprets
538 * it as an additional length.
539 *
540 * TODO: A more sane solution would be to have a bit in the
541 * batman_packet to detect whether the packet is the last
542 * packet in an aggregation. Here we expect that the padding
543 * is always zero (or not 0x01)
544 */
545 if (batman_packet->packet_type != BAT_PACKET)
546 return;
547
548 /* could be changed by schedule_own_packet() */
549 if_incoming_seqno = atomic_read(&if_incoming->seqno);
550
551 has_directlink_flag = (batman_packet->flags & DIRECTLINK ? 1 : 0);
552
553 is_single_hop_neigh = (compare_orig(ethhdr->h_source,
554 batman_packet->orig) ? 1 : 0);
555
556 bat_dbg(DBG_BATMAN, bat_priv,
557 "Received BATMAN packet via NB: %pM, IF: %s [%pM] "
558 "(from OG: %pM, via prev OG: %pM, seqno %d, tq %d, "
559 "TTL %d, V %d, IDF %d)\n",
560 ethhdr->h_source, if_incoming->net_dev->name,
561 if_incoming->net_dev->dev_addr, batman_packet->orig,
562 batman_packet->prev_sender, batman_packet->seqno,
563 batman_packet->tq, batman_packet->ttl, batman_packet->version,
564 has_directlink_flag);
565
566 rcu_read_lock();
567 list_for_each_entry_rcu(batman_if, &if_list, list) {
568 if (batman_if->if_status != IF_ACTIVE)
569 continue;
570
571 if (batman_if->soft_iface != if_incoming->soft_iface)
572 continue;
573
574 if (compare_orig(ethhdr->h_source,
575 batman_if->net_dev->dev_addr))
576 is_my_addr = 1;
577
578 if (compare_orig(batman_packet->orig,
579 batman_if->net_dev->dev_addr))
580 is_my_orig = 1;
581
582 if (compare_orig(batman_packet->prev_sender,
583 batman_if->net_dev->dev_addr))
584 is_my_oldorig = 1;
585
586 if (compare_orig(ethhdr->h_source, broadcast_addr))
587 is_broadcast = 1;
588 }
589 rcu_read_unlock();
590
591 if (batman_packet->version != COMPAT_VERSION) {
592 bat_dbg(DBG_BATMAN, bat_priv,
593 "Drop packet: incompatible batman version (%i)\n",
594 batman_packet->version);
595 return;
596 }
597
598 if (is_my_addr) {
599 bat_dbg(DBG_BATMAN, bat_priv,
600 "Drop packet: received my own broadcast (sender: %pM"
601 ")\n",
602 ethhdr->h_source);
603 return;
604 }
605
606 if (is_broadcast) {
607 bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
608 "ignoring all packets with broadcast source addr (sender: %pM"
609 ")\n", ethhdr->h_source);
610 return;
611 }
612
613 if (is_my_orig) {
614 TYPE_OF_WORD *word;
615 int offset;
616
617 orig_neigh_node = get_orig_node(bat_priv, ethhdr->h_source);
618
619 if (!orig_neigh_node)
620 return;
621
622 /* neighbor has to indicate direct link and it has to
623 * come via the corresponding interface */
624 /* if received seqno equals last send seqno save new
625 * seqno for bidirectional check */
626 if (has_directlink_flag &&
627 compare_orig(if_incoming->net_dev->dev_addr,
628 batman_packet->orig) &&
629 (batman_packet->seqno - if_incoming_seqno + 2 == 0)) {
630 offset = if_incoming->if_num * NUM_WORDS;
631 word = &(orig_neigh_node->bcast_own[offset]);
632 bit_mark(word, 0);
633 orig_neigh_node->bcast_own_sum[if_incoming->if_num] =
634 bit_packet_count(word);
635 }
636
637 bat_dbg(DBG_BATMAN, bat_priv, "Drop packet: "
638 "originator packet from myself (via neighbor)\n");
639 return;
640 }
641
642 if (is_my_oldorig) {
643 bat_dbg(DBG_BATMAN, bat_priv,
644 "Drop packet: ignoring all rebroadcast echos (sender: "
645 "%pM)\n", ethhdr->h_source);
646 return;
647 }
648
649 orig_node = get_orig_node(bat_priv, batman_packet->orig);
650 if (orig_node == NULL)
651 return;
652
653 is_duplicate = count_real_packets(ethhdr, batman_packet, if_incoming);
654
655 if (is_duplicate == -1) {
656 bat_dbg(DBG_BATMAN, bat_priv,
657 "Drop packet: packet within seqno protection time "
658 "(sender: %pM)\n", ethhdr->h_source);
659 return;
660 }
661
662 if (batman_packet->tq == 0) {
663 bat_dbg(DBG_BATMAN, bat_priv,
664 "Drop packet: originator packet with tq equal 0\n");
665 return;
666 }
667
668 /* avoid temporary routing loops */
669 if ((orig_node->router) &&
670 (orig_node->router->orig_node->router) &&
671 (compare_orig(orig_node->router->addr,
672 batman_packet->prev_sender)) &&
673 !(compare_orig(batman_packet->orig, batman_packet->prev_sender)) &&
674 (compare_orig(orig_node->router->addr,
675 orig_node->router->orig_node->router->addr))) {
676 bat_dbg(DBG_BATMAN, bat_priv,
677 "Drop packet: ignoring all rebroadcast packets that "
678 "may make me loop (sender: %pM)\n", ethhdr->h_source);
679 return;
680 }
681
682 /* if sender is a direct neighbor the sender mac equals
683 * originator mac */
684 orig_neigh_node = (is_single_hop_neigh ?
685 orig_node :
686 get_orig_node(bat_priv, ethhdr->h_source));
687 if (orig_neigh_node == NULL)
688 return;
689
690 /* drop packet if sender is not a direct neighbor and if we
691 * don't route towards it */
692 if (!is_single_hop_neigh &&
693 (orig_neigh_node->router == NULL)) {
694 bat_dbg(DBG_BATMAN, bat_priv,
695 "Drop packet: OGM via unknown neighbor!\n");
696 return;
697 }
698
699 is_bidirectional = is_bidirectional_neigh(orig_node, orig_neigh_node,
700 batman_packet, if_incoming);
701
702 /* update ranking if it is not a duplicate or has the same
703 * seqno and similar ttl as the non-duplicate */
704 if (is_bidirectional &&
705 (!is_duplicate ||
706 ((orig_node->last_real_seqno == batman_packet->seqno) &&
707 (orig_node->last_ttl - 3 <= batman_packet->ttl))))
708 update_orig(bat_priv, orig_node, ethhdr, batman_packet,
709 if_incoming, hna_buff, hna_buff_len, is_duplicate);
710
711 mark_bonding_address(bat_priv, orig_node,
712 orig_neigh_node, batman_packet);
713 update_bonding_candidates(bat_priv, orig_node);
714
715 /* is single hop (direct) neighbor */
716 if (is_single_hop_neigh) {
717
718 /* mark direct link on incoming interface */
719 schedule_forward_packet(orig_node, ethhdr, batman_packet,
720 1, hna_buff_len, if_incoming);
721
722 bat_dbg(DBG_BATMAN, bat_priv, "Forwarding packet: "
723 "rebroadcast neighbor packet with direct link flag\n");
724 return;
725 }
726
727 /* multihop originator */
728 if (!is_bidirectional) {
729 bat_dbg(DBG_BATMAN, bat_priv,
730 "Drop packet: not received via bidirectional link\n");
731 return;
732 }
733
734 if (is_duplicate) {
735 bat_dbg(DBG_BATMAN, bat_priv,
736 "Drop packet: duplicate packet received\n");
737 return;
738 }
739
740 bat_dbg(DBG_BATMAN, bat_priv,
741 "Forwarding packet: rebroadcast originator packet\n");
742 schedule_forward_packet(orig_node, ethhdr, batman_packet,
743 0, hna_buff_len, if_incoming);
744}
745
746int recv_bat_packet(struct sk_buff *skb, struct batman_if *batman_if)
747{
748 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
749 struct ethhdr *ethhdr;
750 unsigned long flags;
751
752 /* drop packet if it has not necessary minimum size */
753 if (unlikely(!pskb_may_pull(skb, sizeof(struct batman_packet))))
754 return NET_RX_DROP;
755
756 ethhdr = (struct ethhdr *)skb_mac_header(skb);
757
758 /* packet with broadcast indication but unicast recipient */
759 if (!is_bcast(ethhdr->h_dest))
760 return NET_RX_DROP;
761
762 /* packet with broadcast sender address */
763 if (is_bcast(ethhdr->h_source))
764 return NET_RX_DROP;
765
766 /* create a copy of the skb, if needed, to modify it. */
767 if (skb_cow(skb, 0) < 0)
768 return NET_RX_DROP;
769
770 /* keep skb linear */
771 if (skb_linearize(skb) < 0)
772 return NET_RX_DROP;
773
774 ethhdr = (struct ethhdr *)skb_mac_header(skb);
775
776 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
777 receive_aggr_bat_packet(ethhdr,
778 skb->data,
779 skb_headlen(skb),
780 batman_if);
781 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
782
783 kfree_skb(skb);
784 return NET_RX_SUCCESS;
785}
786
787static int recv_my_icmp_packet(struct bat_priv *bat_priv,
788 struct sk_buff *skb, size_t icmp_len)
789{
790 struct orig_node *orig_node;
791 struct icmp_packet_rr *icmp_packet;
792 struct ethhdr *ethhdr;
793 struct batman_if *batman_if;
794 int ret;
795 unsigned long flags;
796 uint8_t dstaddr[ETH_ALEN];
797
798 icmp_packet = (struct icmp_packet_rr *)skb->data;
799 ethhdr = (struct ethhdr *)skb_mac_header(skb);
800
801 /* add data to device queue */
802 if (icmp_packet->msg_type != ECHO_REQUEST) {
803 bat_socket_receive_packet(icmp_packet, icmp_len);
804 return NET_RX_DROP;
805 }
806
807 if (!bat_priv->primary_if)
808 return NET_RX_DROP;
809
810 /* answer echo request (ping) */
811 /* get routing information */
812 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
813 orig_node = ((struct orig_node *)hash_find(bat_priv->orig_hash,
814 icmp_packet->orig));
815 ret = NET_RX_DROP;
816
817 if ((orig_node != NULL) &&
818 (orig_node->router != NULL)) {
819
820 /* don't lock while sending the packets ... we therefore
821 * copy the required data before sending */
822 batman_if = orig_node->router->if_incoming;
823 memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
824 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
825
826 /* create a copy of the skb, if needed, to modify it. */
827 if (skb_cow(skb, sizeof(struct ethhdr)) < 0)
828 return NET_RX_DROP;
829
830 icmp_packet = (struct icmp_packet_rr *)skb->data;
831 ethhdr = (struct ethhdr *)skb_mac_header(skb);
832
833 memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
834 memcpy(icmp_packet->orig,
835 bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
836 icmp_packet->msg_type = ECHO_REPLY;
837 icmp_packet->ttl = TTL;
838
839 send_skb_packet(skb, batman_if, dstaddr);
840 ret = NET_RX_SUCCESS;
841
842 } else
843 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
844
845 return ret;
846}
847
848static int recv_icmp_ttl_exceeded(struct bat_priv *bat_priv,
849 struct sk_buff *skb, size_t icmp_len)
850{
851 struct orig_node *orig_node;
852 struct icmp_packet *icmp_packet;
853 struct ethhdr *ethhdr;
854 struct batman_if *batman_if;
855 int ret;
856 unsigned long flags;
857 uint8_t dstaddr[ETH_ALEN];
858
859 icmp_packet = (struct icmp_packet *)skb->data;
860 ethhdr = (struct ethhdr *)skb_mac_header(skb);
861
862 /* send TTL exceeded if packet is an echo request (traceroute) */
863 if (icmp_packet->msg_type != ECHO_REQUEST) {
864 pr_debug("Warning - can't forward icmp packet from %pM to "
865 "%pM: ttl exceeded\n", icmp_packet->orig,
866 icmp_packet->dst);
867 return NET_RX_DROP;
868 }
869
870 if (!bat_priv->primary_if)
871 return NET_RX_DROP;
872
873 /* get routing information */
874 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
875 orig_node = ((struct orig_node *)
876 hash_find(bat_priv->orig_hash, icmp_packet->orig));
877 ret = NET_RX_DROP;
878
879 if ((orig_node != NULL) &&
880 (orig_node->router != NULL)) {
881
882 /* don't lock while sending the packets ... we therefore
883 * copy the required data before sending */
884 batman_if = orig_node->router->if_incoming;
885 memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
886 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
887
888 /* create a copy of the skb, if needed, to modify it. */
889 if (skb_cow(skb, sizeof(struct ethhdr)) < 0)
890 return NET_RX_DROP;
891
892 icmp_packet = (struct icmp_packet *) skb->data;
893 ethhdr = (struct ethhdr *)skb_mac_header(skb);
894
895 memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
896 memcpy(icmp_packet->orig,
897 bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
898 icmp_packet->msg_type = TTL_EXCEEDED;
899 icmp_packet->ttl = TTL;
900
901 send_skb_packet(skb, batman_if, dstaddr);
902 ret = NET_RX_SUCCESS;
903
904 } else
905 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
906
907 return ret;
908}
909
910
911int recv_icmp_packet(struct sk_buff *skb, struct batman_if *recv_if)
912{
913 struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface);
914 struct icmp_packet_rr *icmp_packet;
915 struct ethhdr *ethhdr;
916 struct orig_node *orig_node;
917 struct batman_if *batman_if;
918 int hdr_size = sizeof(struct icmp_packet);
919 int ret;
920 unsigned long flags;
921 uint8_t dstaddr[ETH_ALEN];
922
923 /**
924 * we truncate all incoming icmp packets if they don't match our size
925 */
926 if (skb->len >= sizeof(struct icmp_packet_rr))
927 hdr_size = sizeof(struct icmp_packet_rr);
928
929 /* drop packet if it has not necessary minimum size */
930 if (unlikely(!pskb_may_pull(skb, hdr_size)))
931 return NET_RX_DROP;
932
933 ethhdr = (struct ethhdr *)skb_mac_header(skb);
934
935 /* packet with unicast indication but broadcast recipient */
936 if (is_bcast(ethhdr->h_dest))
937 return NET_RX_DROP;
938
939 /* packet with broadcast sender address */
940 if (is_bcast(ethhdr->h_source))
941 return NET_RX_DROP;
942
943 /* not for me */
944 if (!is_my_mac(ethhdr->h_dest))
945 return NET_RX_DROP;
946
947 icmp_packet = (struct icmp_packet_rr *)skb->data;
948
949 /* add record route information if not full */
950 if ((hdr_size == sizeof(struct icmp_packet_rr)) &&
951 (icmp_packet->rr_cur < BAT_RR_LEN)) {
952 memcpy(&(icmp_packet->rr[icmp_packet->rr_cur]),
953 ethhdr->h_dest, ETH_ALEN);
954 icmp_packet->rr_cur++;
955 }
956
957 /* packet for me */
958 if (is_my_mac(icmp_packet->dst))
959 return recv_my_icmp_packet(bat_priv, skb, hdr_size);
960
961 /* TTL exceeded */
962 if (icmp_packet->ttl < 2)
963 return recv_icmp_ttl_exceeded(bat_priv, skb, hdr_size);
964
965 ret = NET_RX_DROP;
966
967 /* get routing information */
968 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
969 orig_node = ((struct orig_node *)
970 hash_find(bat_priv->orig_hash, icmp_packet->dst));
971
972 if ((orig_node != NULL) &&
973 (orig_node->router != NULL)) {
974
975 /* don't lock while sending the packets ... we therefore
976 * copy the required data before sending */
977 batman_if = orig_node->router->if_incoming;
978 memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
979 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
980
981 /* create a copy of the skb, if needed, to modify it. */
982 if (skb_cow(skb, sizeof(struct ethhdr)) < 0)
983 return NET_RX_DROP;
984
985 icmp_packet = (struct icmp_packet_rr *)skb->data;
986 ethhdr = (struct ethhdr *)skb_mac_header(skb);
987
988 /* decrement ttl */
989 icmp_packet->ttl--;
990
991 /* route it */
992 send_skb_packet(skb, batman_if, dstaddr);
993 ret = NET_RX_SUCCESS;
994
995 } else
996 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
997
998 return ret;
999}
1000
1001/* find a suitable router for this originator, and use
1002 * bonding if possible. */
1003struct neigh_node *find_router(struct bat_priv *bat_priv,
1004 struct orig_node *orig_node,
1005 struct batman_if *recv_if)
1006{
1007 struct orig_node *primary_orig_node;
1008 struct orig_node *router_orig;
1009 struct neigh_node *router, *first_candidate, *best_router;
1010 static uint8_t zero_mac[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
1011 int bonding_enabled;
1012
1013 if (!orig_node)
1014 return NULL;
1015
1016 if (!orig_node->router)
1017 return NULL;
1018
1019 /* without bonding, the first node should
1020 * always choose the default router. */
1021
1022 bonding_enabled = atomic_read(&bat_priv->bonding_enabled);
1023
1024 if ((!recv_if) && (!bonding_enabled))
1025 return orig_node->router;
1026
1027 router_orig = orig_node->router->orig_node;
1028
1029 /* if we have something in the primary_addr, we can search
1030 * for a potential bonding candidate. */
1031 if (memcmp(router_orig->primary_addr, zero_mac, ETH_ALEN) == 0)
1032 return orig_node->router;
1033
1034 /* find the orig_node which has the primary interface. might
1035 * even be the same as our router_orig in many cases */
1036
1037 if (memcmp(router_orig->primary_addr,
1038 router_orig->orig, ETH_ALEN) == 0) {
1039 primary_orig_node = router_orig;
1040 } else {
1041 primary_orig_node = hash_find(bat_priv->orig_hash,
1042 router_orig->primary_addr);
1043
1044 if (!primary_orig_node)
1045 return orig_node->router;
1046 }
1047
1048 /* with less than 2 candidates, we can't do any
1049 * bonding and prefer the original router. */
1050
1051 if (primary_orig_node->bond.candidates < 2)
1052 return orig_node->router;
1053
1054
1055 /* all nodes between should choose a candidate which
1056 * is is not on the interface where the packet came
1057 * in. */
1058 first_candidate = primary_orig_node->bond.selected;
1059 router = first_candidate;
1060
1061 if (bonding_enabled) {
1062 /* in the bonding case, send the packets in a round
1063 * robin fashion over the remaining interfaces. */
1064 do {
1065 /* recv_if == NULL on the first node. */
1066 if (router->if_incoming != recv_if)
1067 break;
1068
1069 router = router->next_bond_candidate;
1070 } while (router != first_candidate);
1071
1072 primary_orig_node->bond.selected = router->next_bond_candidate;
1073
1074 } else {
1075 /* if bonding is disabled, use the best of the
1076 * remaining candidates which are not using
1077 * this interface. */
1078 best_router = first_candidate;
1079
1080 do {
1081 /* recv_if == NULL on the first node. */
1082 if ((router->if_incoming != recv_if) &&
1083 (router->tq_avg > best_router->tq_avg))
1084 best_router = router;
1085
1086 router = router->next_bond_candidate;
1087 } while (router != first_candidate);
1088
1089 router = best_router;
1090 }
1091
1092 return router;
1093}
1094
1095static int check_unicast_packet(struct sk_buff *skb, int hdr_size)
1096{
1097 struct ethhdr *ethhdr;
1098
1099 /* drop packet if it has not necessary minimum size */
1100 if (unlikely(!pskb_may_pull(skb, hdr_size)))
1101 return -1;
1102
1103 ethhdr = (struct ethhdr *)skb_mac_header(skb);
1104
1105 /* packet with unicast indication but broadcast recipient */
1106 if (is_bcast(ethhdr->h_dest))
1107 return -1;
1108
1109 /* packet with broadcast sender address */
1110 if (is_bcast(ethhdr->h_source))
1111 return -1;
1112
1113 /* not for me */
1114 if (!is_my_mac(ethhdr->h_dest))
1115 return -1;
1116
1117 return 0;
1118}
1119
1120static int route_unicast_packet(struct sk_buff *skb,
1121 struct batman_if *recv_if, int hdr_size)
1122{
1123 struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface);
1124 struct orig_node *orig_node;
1125 struct neigh_node *router;
1126 struct batman_if *batman_if;
1127 uint8_t dstaddr[ETH_ALEN];
1128 unsigned long flags;
1129 struct unicast_packet *unicast_packet;
1130 struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb);
1131
1132 unicast_packet = (struct unicast_packet *)skb->data;
1133
1134 /* packet for me */
1135 if (is_my_mac(unicast_packet->dest)) {
1136 interface_rx(recv_if->soft_iface, skb, hdr_size);
1137 return NET_RX_SUCCESS;
1138 }
1139
1140 /* TTL exceeded */
1141 if (unicast_packet->ttl < 2) {
1142 pr_debug("Warning - can't forward unicast packet from %pM to "
1143 "%pM: ttl exceeded\n", ethhdr->h_source,
1144 unicast_packet->dest);
1145 return NET_RX_DROP;
1146 }
1147
1148 /* get routing information */
1149 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
1150 orig_node = ((struct orig_node *)
1151 hash_find(bat_priv->orig_hash, unicast_packet->dest));
1152
1153 router = find_router(bat_priv, orig_node, recv_if);
1154
1155 if (!router) {
1156 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
1157 return NET_RX_DROP;
1158 }
1159
1160 /* don't lock while sending the packets ... we therefore
1161 * copy the required data before sending */
1162
1163 batman_if = router->if_incoming;
1164 memcpy(dstaddr, router->addr, ETH_ALEN);
1165
1166 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
1167
1168 /* create a copy of the skb, if needed, to modify it. */
1169 if (skb_cow(skb, sizeof(struct ethhdr)) < 0)
1170 return NET_RX_DROP;
1171
1172 unicast_packet = (struct unicast_packet *)skb->data;
1173 ethhdr = (struct ethhdr *)skb_mac_header(skb);
1174
1175 /* decrement ttl */
1176 unicast_packet->ttl--;
1177
1178 /* route it */
1179 send_skb_packet(skb, batman_if, dstaddr);
1180
1181 return NET_RX_SUCCESS;
1182}
1183
1184int recv_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if)
1185{
1186 struct unicast_packet *unicast_packet;
1187 int hdr_size = sizeof(struct unicast_packet);
1188
1189 if (check_unicast_packet(skb, hdr_size) < 0)
1190 return NET_RX_DROP;
1191
1192 unicast_packet = (struct unicast_packet *)skb->data;
1193
1194 /* packet for me */
1195 if (is_my_mac(unicast_packet->dest)) {
1196 interface_rx(recv_if->soft_iface, skb, hdr_size);
1197 return NET_RX_SUCCESS;
1198 }
1199
1200 return route_unicast_packet(skb, recv_if, hdr_size);
1201}
1202
1203int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if)
1204{
1205 struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface);
1206 struct unicast_frag_packet *unicast_packet;
1207 struct orig_node *orig_node;
1208 struct frag_packet_list_entry *tmp_frag_entry;
1209 int hdr_size = sizeof(struct unicast_frag_packet);
1210 unsigned long flags;
1211
1212 if (check_unicast_packet(skb, hdr_size) < 0)
1213 return NET_RX_DROP;
1214
1215 unicast_packet = (struct unicast_frag_packet *)skb->data;
1216
1217 /* packet for me */
1218 if (is_my_mac(unicast_packet->dest)) {
1219
1220 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
1221 orig_node = ((struct orig_node *)
1222 hash_find(bat_priv->orig_hash, unicast_packet->orig));
1223
1224 if (!orig_node) {
1225 pr_debug("couldn't find orig node for fragmentation\n");
1226 spin_unlock_irqrestore(&bat_priv->orig_hash_lock,
1227 flags);
1228 return NET_RX_DROP;
1229 }
1230
1231 orig_node->last_frag_packet = jiffies;
1232
1233 if (list_empty(&orig_node->frag_list) &&
1234 create_frag_buffer(&orig_node->frag_list)) {
1235 spin_unlock_irqrestore(&bat_priv->orig_hash_lock,
1236 flags);
1237 return NET_RX_DROP;
1238 }
1239
1240 tmp_frag_entry =
1241 search_frag_packet(&orig_node->frag_list,
1242 unicast_packet);
1243
1244 if (!tmp_frag_entry) {
1245 create_frag_entry(&orig_node->frag_list, skb);
1246 spin_unlock_irqrestore(&bat_priv->orig_hash_lock,
1247 flags);
1248 return NET_RX_SUCCESS;
1249 }
1250
1251 skb = merge_frag_packet(&orig_node->frag_list,
1252 tmp_frag_entry, skb);
1253 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
1254 if (!skb)
1255 return NET_RX_DROP;
1256
1257 interface_rx(recv_if->soft_iface, skb, hdr_size);
1258 return NET_RX_SUCCESS;
1259 }
1260
1261 return route_unicast_packet(skb, recv_if, hdr_size);
1262}
1263
1264
1265int recv_bcast_packet(struct sk_buff *skb, struct batman_if *recv_if)
1266{
1267 struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface);
1268 struct orig_node *orig_node;
1269 struct bcast_packet *bcast_packet;
1270 struct ethhdr *ethhdr;
1271 int hdr_size = sizeof(struct bcast_packet);
1272 int32_t seq_diff;
1273 unsigned long flags;
1274
1275 /* drop packet if it has not necessary minimum size */
1276 if (unlikely(!pskb_may_pull(skb, hdr_size)))
1277 return NET_RX_DROP;
1278
1279 ethhdr = (struct ethhdr *)skb_mac_header(skb);
1280
1281 /* packet with broadcast indication but unicast recipient */
1282 if (!is_bcast(ethhdr->h_dest))
1283 return NET_RX_DROP;
1284
1285 /* packet with broadcast sender address */
1286 if (is_bcast(ethhdr->h_source))
1287 return NET_RX_DROP;
1288
1289 /* ignore broadcasts sent by myself */
1290 if (is_my_mac(ethhdr->h_source))
1291 return NET_RX_DROP;
1292
1293 bcast_packet = (struct bcast_packet *)skb->data;
1294
1295 /* ignore broadcasts originated by myself */
1296 if (is_my_mac(bcast_packet->orig))
1297 return NET_RX_DROP;
1298
1299 if (bcast_packet->ttl < 2)
1300 return NET_RX_DROP;
1301
1302 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
1303 orig_node = ((struct orig_node *)
1304 hash_find(bat_priv->orig_hash, bcast_packet->orig));
1305
1306 if (orig_node == NULL) {
1307 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
1308 return NET_RX_DROP;
1309 }
1310
1311 /* check whether the packet is a duplicate */
1312 if (get_bit_status(orig_node->bcast_bits,
1313 orig_node->last_bcast_seqno,
1314 ntohl(bcast_packet->seqno))) {
1315 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
1316 return NET_RX_DROP;
1317 }
1318
1319 seq_diff = ntohl(bcast_packet->seqno) - orig_node->last_bcast_seqno;
1320
1321 /* check whether the packet is old and the host just restarted. */
1322 if (window_protected(bat_priv, seq_diff,
1323 &orig_node->bcast_seqno_reset)) {
1324 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
1325 return NET_RX_DROP;
1326 }
1327
1328 /* mark broadcast in flood history, update window position
1329 * if required. */
1330 if (bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1))
1331 orig_node->last_bcast_seqno = ntohl(bcast_packet->seqno);
1332
1333 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
1334 /* rebroadcast packet */
1335 add_bcast_packet_to_list(bat_priv, skb);
1336
1337 /* broadcast for me */
1338 interface_rx(recv_if->soft_iface, skb, hdr_size);
1339
1340 return NET_RX_SUCCESS;
1341}
1342
1343int recv_vis_packet(struct sk_buff *skb, struct batman_if *recv_if)
1344{
1345 struct vis_packet *vis_packet;
1346 struct ethhdr *ethhdr;
1347 struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface);
1348 int hdr_size = sizeof(struct vis_packet);
1349
1350 /* keep skb linear */
1351 if (skb_linearize(skb) < 0)
1352 return NET_RX_DROP;
1353
1354 if (unlikely(!pskb_may_pull(skb, hdr_size)))
1355 return NET_RX_DROP;
1356
1357 vis_packet = (struct vis_packet *)skb->data;
1358 ethhdr = (struct ethhdr *)skb_mac_header(skb);
1359
1360 /* not for me */
1361 if (!is_my_mac(ethhdr->h_dest))
1362 return NET_RX_DROP;
1363
1364 /* ignore own packets */
1365 if (is_my_mac(vis_packet->vis_orig))
1366 return NET_RX_DROP;
1367
1368 if (is_my_mac(vis_packet->sender_orig))
1369 return NET_RX_DROP;
1370
1371 switch (vis_packet->vis_type) {
1372 case VIS_TYPE_SERVER_SYNC:
1373 receive_server_sync_packet(bat_priv, vis_packet,
1374 skb_headlen(skb));
1375 break;
1376
1377 case VIS_TYPE_CLIENT_UPDATE:
1378 receive_client_update_packet(bat_priv, vis_packet,
1379 skb_headlen(skb));
1380 break;
1381
1382 default: /* ignore unknown packet */
1383 break;
1384 }
1385
1386 /* We take a copy of the data in the packet, so we should
1387 always free the skbuf. */
1388 return NET_RX_DROP;
1389}
diff --git a/drivers/staging/batman-adv/routing.h b/drivers/staging/batman-adv/routing.h
deleted file mode 100644
index 92674c8d9c03..000000000000
--- a/drivers/staging/batman-adv/routing.h
+++ /dev/null
@@ -1,46 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_ROUTING_H_
23#define _NET_BATMAN_ADV_ROUTING_H_
24
25#include "types.h"
26
27void slide_own_bcast_window(struct batman_if *batman_if);
28void receive_bat_packet(struct ethhdr *ethhdr,
29 struct batman_packet *batman_packet,
30 unsigned char *hna_buff, int hna_buff_len,
31 struct batman_if *if_incoming);
32void update_routes(struct bat_priv *bat_priv, struct orig_node *orig_node,
33 struct neigh_node *neigh_node, unsigned char *hna_buff,
34 int hna_buff_len);
35int recv_icmp_packet(struct sk_buff *skb, struct batman_if *recv_if);
36int recv_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if);
37int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if);
38int recv_bcast_packet(struct sk_buff *skb, struct batman_if *recv_if);
39int recv_vis_packet(struct sk_buff *skb, struct batman_if *recv_if);
40int recv_bat_packet(struct sk_buff *skb, struct batman_if *recv_if);
41struct neigh_node *find_router(struct bat_priv *bat_priv,
42 struct orig_node *orig_node, struct batman_if *recv_if);
43void update_bonding_candidates(struct bat_priv *bat_priv,
44 struct orig_node *orig_node);
45
46#endif /* _NET_BATMAN_ADV_ROUTING_H_ */
diff --git a/drivers/staging/batman-adv/send.c b/drivers/staging/batman-adv/send.c
deleted file mode 100644
index 7adf76ddd0ba..000000000000
--- a/drivers/staging/batman-adv/send.c
+++ /dev/null
@@ -1,580 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "send.h"
24#include "routing.h"
25#include "translation-table.h"
26#include "soft-interface.h"
27#include "hard-interface.h"
28#include "types.h"
29#include "vis.h"
30#include "aggregation.h"
31
32
33static void send_outstanding_bcast_packet(struct work_struct *work);
34
35/* apply hop penalty for a normal link */
36static uint8_t hop_penalty(const uint8_t tq)
37{
38 return (tq * (TQ_MAX_VALUE - TQ_HOP_PENALTY)) / (TQ_MAX_VALUE);
39}
40
41/* when do we schedule our own packet to be sent */
42static unsigned long own_send_time(struct bat_priv *bat_priv)
43{
44 return jiffies + msecs_to_jiffies(
45 atomic_read(&bat_priv->orig_interval) -
46 JITTER + (random32() % 2*JITTER));
47}
48
49/* when do we schedule a forwarded packet to be sent */
50static unsigned long forward_send_time(struct bat_priv *bat_priv)
51{
52 return jiffies + msecs_to_jiffies(random32() % (JITTER/2));
53}
54
55/* send out an already prepared packet to the given address via the
56 * specified batman interface */
57int send_skb_packet(struct sk_buff *skb,
58 struct batman_if *batman_if,
59 uint8_t *dst_addr)
60{
61 struct ethhdr *ethhdr;
62
63 if (batman_if->if_status != IF_ACTIVE)
64 goto send_skb_err;
65
66 if (unlikely(!batman_if->net_dev))
67 goto send_skb_err;
68
69 if (!(batman_if->net_dev->flags & IFF_UP)) {
70 pr_warning("Interface %s is not up - can't send packet via "
71 "that interface!\n", batman_if->net_dev->name);
72 goto send_skb_err;
73 }
74
75 /* push to the ethernet header. */
76 if (my_skb_head_push(skb, sizeof(struct ethhdr)) < 0)
77 goto send_skb_err;
78
79 skb_reset_mac_header(skb);
80
81 ethhdr = (struct ethhdr *) skb_mac_header(skb);
82 memcpy(ethhdr->h_source, batman_if->net_dev->dev_addr, ETH_ALEN);
83 memcpy(ethhdr->h_dest, dst_addr, ETH_ALEN);
84 ethhdr->h_proto = __constant_htons(ETH_P_BATMAN);
85
86 skb_set_network_header(skb, ETH_HLEN);
87 skb->priority = TC_PRIO_CONTROL;
88 skb->protocol = __constant_htons(ETH_P_BATMAN);
89
90 skb->dev = batman_if->net_dev;
91
92 /* dev_queue_xmit() returns a negative result on error. However on
93 * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
94 * (which is > 0). This will not be treated as an error. */
95
96 return dev_queue_xmit(skb);
97send_skb_err:
98 kfree_skb(skb);
99 return NET_XMIT_DROP;
100}
101
102/* Send a packet to a given interface */
103static void send_packet_to_if(struct forw_packet *forw_packet,
104 struct batman_if *batman_if)
105{
106 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
107 char *fwd_str;
108 uint8_t packet_num;
109 int16_t buff_pos;
110 struct batman_packet *batman_packet;
111 struct sk_buff *skb;
112
113 if (batman_if->if_status != IF_ACTIVE)
114 return;
115
116 packet_num = 0;
117 buff_pos = 0;
118 batman_packet = (struct batman_packet *)forw_packet->skb->data;
119
120 /* adjust all flags and log packets */
121 while (aggregated_packet(buff_pos,
122 forw_packet->packet_len,
123 batman_packet->num_hna)) {
124
125 /* we might have aggregated direct link packets with an
126 * ordinary base packet */
127 if ((forw_packet->direct_link_flags & (1 << packet_num)) &&
128 (forw_packet->if_incoming == batman_if))
129 batman_packet->flags |= DIRECTLINK;
130 else
131 batman_packet->flags &= ~DIRECTLINK;
132
133 fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ?
134 "Sending own" :
135 "Forwarding"));
136 bat_dbg(DBG_BATMAN, bat_priv,
137 "%s %spacket (originator %pM, seqno %d, TQ %d, TTL %d,"
138 " IDF %s) on interface %s [%pM]\n",
139 fwd_str, (packet_num > 0 ? "aggregated " : ""),
140 batman_packet->orig, ntohl(batman_packet->seqno),
141 batman_packet->tq, batman_packet->ttl,
142 (batman_packet->flags & DIRECTLINK ?
143 "on" : "off"),
144 batman_if->net_dev->name, batman_if->net_dev->dev_addr);
145
146 buff_pos += sizeof(struct batman_packet) +
147 (batman_packet->num_hna * ETH_ALEN);
148 packet_num++;
149 batman_packet = (struct batman_packet *)
150 (forw_packet->skb->data + buff_pos);
151 }
152
153 /* create clone because function is called more than once */
154 skb = skb_clone(forw_packet->skb, GFP_ATOMIC);
155 if (skb)
156 send_skb_packet(skb, batman_if, broadcast_addr);
157}
158
159/* send a batman packet */
160static void send_packet(struct forw_packet *forw_packet)
161{
162 struct batman_if *batman_if;
163 struct net_device *soft_iface;
164 struct bat_priv *bat_priv;
165 struct batman_packet *batman_packet =
166 (struct batman_packet *)(forw_packet->skb->data);
167 unsigned char directlink = (batman_packet->flags & DIRECTLINK ? 1 : 0);
168
169 if (!forw_packet->if_incoming) {
170 pr_err("Error - can't forward packet: incoming iface not "
171 "specified\n");
172 return;
173 }
174
175 soft_iface = forw_packet->if_incoming->soft_iface;
176 bat_priv = netdev_priv(soft_iface);
177
178 if (forw_packet->if_incoming->if_status != IF_ACTIVE)
179 return;
180
181 /* multihomed peer assumed */
182 /* non-primary OGMs are only broadcasted on their interface */
183 if ((directlink && (batman_packet->ttl == 1)) ||
184 (forw_packet->own && (forw_packet->if_incoming->if_num > 0))) {
185
186 /* FIXME: what about aggregated packets ? */
187 bat_dbg(DBG_BATMAN, bat_priv,
188 "%s packet (originator %pM, seqno %d, TTL %d) "
189 "on interface %s [%pM]\n",
190 (forw_packet->own ? "Sending own" : "Forwarding"),
191 batman_packet->orig, ntohl(batman_packet->seqno),
192 batman_packet->ttl,
193 forw_packet->if_incoming->net_dev->name,
194 forw_packet->if_incoming->net_dev->dev_addr);
195
196 /* skb is only used once and than forw_packet is free'd */
197 send_skb_packet(forw_packet->skb, forw_packet->if_incoming,
198 broadcast_addr);
199 forw_packet->skb = NULL;
200
201 return;
202 }
203
204 /* broadcast on every interface */
205 rcu_read_lock();
206 list_for_each_entry_rcu(batman_if, &if_list, list) {
207 if (batman_if->soft_iface != soft_iface)
208 continue;
209
210 send_packet_to_if(forw_packet, batman_if);
211 }
212 rcu_read_unlock();
213}
214
215static void rebuild_batman_packet(struct bat_priv *bat_priv,
216 struct batman_if *batman_if)
217{
218 int new_len;
219 unsigned char *new_buff;
220 struct batman_packet *batman_packet;
221
222 new_len = sizeof(struct batman_packet) +
223 (bat_priv->num_local_hna * ETH_ALEN);
224 new_buff = kmalloc(new_len, GFP_ATOMIC);
225
226 /* keep old buffer if kmalloc should fail */
227 if (new_buff) {
228 memcpy(new_buff, batman_if->packet_buff,
229 sizeof(struct batman_packet));
230 batman_packet = (struct batman_packet *)new_buff;
231
232 batman_packet->num_hna = hna_local_fill_buffer(bat_priv,
233 new_buff + sizeof(struct batman_packet),
234 new_len - sizeof(struct batman_packet));
235
236 kfree(batman_if->packet_buff);
237 batman_if->packet_buff = new_buff;
238 batman_if->packet_len = new_len;
239 }
240}
241
242void schedule_own_packet(struct batman_if *batman_if)
243{
244 struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
245 unsigned long send_time;
246 struct batman_packet *batman_packet;
247 int vis_server;
248
249 if ((batman_if->if_status == IF_NOT_IN_USE) ||
250 (batman_if->if_status == IF_TO_BE_REMOVED))
251 return;
252
253 vis_server = atomic_read(&bat_priv->vis_mode);
254
255 /**
256 * the interface gets activated here to avoid race conditions between
257 * the moment of activating the interface in
258 * hardif_activate_interface() where the originator mac is set and
259 * outdated packets (especially uninitialized mac addresses) in the
260 * packet queue
261 */
262 if (batman_if->if_status == IF_TO_BE_ACTIVATED)
263 batman_if->if_status = IF_ACTIVE;
264
265 /* if local hna has changed and interface is a primary interface */
266 if ((atomic_read(&bat_priv->hna_local_changed)) &&
267 (batman_if == bat_priv->primary_if))
268 rebuild_batman_packet(bat_priv, batman_if);
269
270 /**
271 * NOTE: packet_buff might just have been re-allocated in
272 * rebuild_batman_packet()
273 */
274 batman_packet = (struct batman_packet *)batman_if->packet_buff;
275
276 /* change sequence number to network order */
277 batman_packet->seqno =
278 htonl((uint32_t)atomic_read(&batman_if->seqno));
279
280 if (vis_server == VIS_TYPE_SERVER_SYNC)
281 batman_packet->flags |= VIS_SERVER;
282 else
283 batman_packet->flags &= ~VIS_SERVER;
284
285 atomic_inc(&batman_if->seqno);
286
287 slide_own_bcast_window(batman_if);
288 send_time = own_send_time(bat_priv);
289 add_bat_packet_to_list(bat_priv,
290 batman_if->packet_buff,
291 batman_if->packet_len,
292 batman_if, 1, send_time);
293}
294
295void schedule_forward_packet(struct orig_node *orig_node,
296 struct ethhdr *ethhdr,
297 struct batman_packet *batman_packet,
298 uint8_t directlink, int hna_buff_len,
299 struct batman_if *if_incoming)
300{
301 struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
302 unsigned char in_tq, in_ttl, tq_avg = 0;
303 unsigned long send_time;
304
305 if (batman_packet->ttl <= 1) {
306 bat_dbg(DBG_BATMAN, bat_priv, "ttl exceeded\n");
307 return;
308 }
309
310 in_tq = batman_packet->tq;
311 in_ttl = batman_packet->ttl;
312
313 batman_packet->ttl--;
314 memcpy(batman_packet->prev_sender, ethhdr->h_source, ETH_ALEN);
315
316 /* rebroadcast tq of our best ranking neighbor to ensure the rebroadcast
317 * of our best tq value */
318 if ((orig_node->router) && (orig_node->router->tq_avg != 0)) {
319
320 /* rebroadcast ogm of best ranking neighbor as is */
321 if (!compare_orig(orig_node->router->addr, ethhdr->h_source)) {
322 batman_packet->tq = orig_node->router->tq_avg;
323
324 if (orig_node->router->last_ttl)
325 batman_packet->ttl = orig_node->router->last_ttl
326 - 1;
327 }
328
329 tq_avg = orig_node->router->tq_avg;
330 }
331
332 /* apply hop penalty */
333 batman_packet->tq = hop_penalty(batman_packet->tq);
334
335 bat_dbg(DBG_BATMAN, bat_priv,
336 "Forwarding packet: tq_orig: %i, tq_avg: %i, "
337 "tq_forw: %i, ttl_orig: %i, ttl_forw: %i\n",
338 in_tq, tq_avg, batman_packet->tq, in_ttl - 1,
339 batman_packet->ttl);
340
341 batman_packet->seqno = htonl(batman_packet->seqno);
342
343 /* switch of primaries first hop flag when forwarding */
344 batman_packet->flags &= ~PRIMARIES_FIRST_HOP;
345 if (directlink)
346 batman_packet->flags |= DIRECTLINK;
347 else
348 batman_packet->flags &= ~DIRECTLINK;
349
350 send_time = forward_send_time(bat_priv);
351 add_bat_packet_to_list(bat_priv,
352 (unsigned char *)batman_packet,
353 sizeof(struct batman_packet) + hna_buff_len,
354 if_incoming, 0, send_time);
355}
356
357static void forw_packet_free(struct forw_packet *forw_packet)
358{
359 if (forw_packet->skb)
360 kfree_skb(forw_packet->skb);
361 kfree(forw_packet);
362}
363
364static void _add_bcast_packet_to_list(struct bat_priv *bat_priv,
365 struct forw_packet *forw_packet,
366 unsigned long send_time)
367{
368 unsigned long flags;
369 INIT_HLIST_NODE(&forw_packet->list);
370
371 /* add new packet to packet list */
372 spin_lock_irqsave(&bat_priv->forw_bcast_list_lock, flags);
373 hlist_add_head(&forw_packet->list, &bat_priv->forw_bcast_list);
374 spin_unlock_irqrestore(&bat_priv->forw_bcast_list_lock, flags);
375
376 /* start timer for this packet */
377 INIT_DELAYED_WORK(&forw_packet->delayed_work,
378 send_outstanding_bcast_packet);
379 queue_delayed_work(bat_event_workqueue, &forw_packet->delayed_work,
380 send_time);
381}
382
383#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
384/* add a broadcast packet to the queue and setup timers. broadcast packets
385 * are sent multiple times to increase probability for beeing received.
386 *
387 * This function returns NETDEV_TX_OK on success and NETDEV_TX_BUSY on
388 * errors.
389 *
390 * The skb is not consumed, so the caller should make sure that the
391 * skb is freed. */
392int add_bcast_packet_to_list(struct bat_priv *bat_priv, struct sk_buff *skb)
393{
394 struct forw_packet *forw_packet;
395 struct bcast_packet *bcast_packet;
396
397 if (!atomic_dec_not_zero(&bat_priv->bcast_queue_left)) {
398 bat_dbg(DBG_BATMAN, bat_priv, "bcast packet queue full\n");
399 goto out;
400 }
401
402 if (!bat_priv->primary_if)
403 goto out;
404
405 forw_packet = kmalloc(sizeof(struct forw_packet), GFP_ATOMIC);
406
407 if (!forw_packet)
408 goto out_and_inc;
409
410 skb = skb_copy(skb, GFP_ATOMIC);
411 if (!skb)
412 goto packet_free;
413
414 /* as we have a copy now, it is safe to decrease the TTL */
415 bcast_packet = (struct bcast_packet *)skb->data;
416 bcast_packet->ttl--;
417
418 skb_reset_mac_header(skb);
419
420 forw_packet->skb = skb;
421 forw_packet->if_incoming = bat_priv->primary_if;
422
423 /* how often did we send the bcast packet ? */
424 forw_packet->num_packets = 0;
425
426 _add_bcast_packet_to_list(bat_priv, forw_packet, 1);
427 return NETDEV_TX_OK;
428
429packet_free:
430 kfree(forw_packet);
431out_and_inc:
432 atomic_inc(&bat_priv->bcast_queue_left);
433out:
434 return NETDEV_TX_BUSY;
435}
436
437static void send_outstanding_bcast_packet(struct work_struct *work)
438{
439 struct batman_if *batman_if;
440 struct delayed_work *delayed_work =
441 container_of(work, struct delayed_work, work);
442 struct forw_packet *forw_packet =
443 container_of(delayed_work, struct forw_packet, delayed_work);
444 unsigned long flags;
445 struct sk_buff *skb1;
446 struct net_device *soft_iface = forw_packet->if_incoming->soft_iface;
447 struct bat_priv *bat_priv = netdev_priv(soft_iface);
448
449 spin_lock_irqsave(&bat_priv->forw_bcast_list_lock, flags);
450 hlist_del(&forw_packet->list);
451 spin_unlock_irqrestore(&bat_priv->forw_bcast_list_lock, flags);
452
453 if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING)
454 goto out;
455
456 /* rebroadcast packet */
457 rcu_read_lock();
458 list_for_each_entry_rcu(batman_if, &if_list, list) {
459 if (batman_if->soft_iface != soft_iface)
460 continue;
461
462 /* send a copy of the saved skb */
463 skb1 = skb_clone(forw_packet->skb, GFP_ATOMIC);
464 if (skb1)
465 send_skb_packet(skb1, batman_if, broadcast_addr);
466 }
467 rcu_read_unlock();
468
469 forw_packet->num_packets++;
470
471 /* if we still have some more bcasts to send */
472 if (forw_packet->num_packets < 3) {
473 _add_bcast_packet_to_list(bat_priv, forw_packet,
474 ((5 * HZ) / 1000));
475 return;
476 }
477
478out:
479 forw_packet_free(forw_packet);
480 atomic_inc(&bat_priv->bcast_queue_left);
481}
482
483void send_outstanding_bat_packet(struct work_struct *work)
484{
485 struct delayed_work *delayed_work =
486 container_of(work, struct delayed_work, work);
487 struct forw_packet *forw_packet =
488 container_of(delayed_work, struct forw_packet, delayed_work);
489 unsigned long flags;
490 struct bat_priv *bat_priv;
491
492 bat_priv = netdev_priv(forw_packet->if_incoming->soft_iface);
493 spin_lock_irqsave(&bat_priv->forw_bat_list_lock, flags);
494 hlist_del(&forw_packet->list);
495 spin_unlock_irqrestore(&bat_priv->forw_bat_list_lock, flags);
496
497 if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING)
498 goto out;
499
500 send_packet(forw_packet);
501
502 /**
503 * we have to have at least one packet in the queue
504 * to determine the queues wake up time unless we are
505 * shutting down
506 */
507 if (forw_packet->own)
508 schedule_own_packet(forw_packet->if_incoming);
509
510out:
511 /* don't count own packet */
512 if (!forw_packet->own)
513 atomic_inc(&bat_priv->batman_queue_left);
514
515 forw_packet_free(forw_packet);
516}
517
518void purge_outstanding_packets(struct bat_priv *bat_priv,
519 struct batman_if *batman_if)
520{
521 struct forw_packet *forw_packet;
522 struct hlist_node *tmp_node, *safe_tmp_node;
523 unsigned long flags;
524
525 if (batman_if)
526 bat_dbg(DBG_BATMAN, bat_priv,
527 "purge_outstanding_packets(): %s\n",
528 batman_if->net_dev->name);
529 else
530 bat_dbg(DBG_BATMAN, bat_priv,
531 "purge_outstanding_packets()\n");
532
533 /* free bcast list */
534 spin_lock_irqsave(&bat_priv->forw_bcast_list_lock, flags);
535 hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
536 &bat_priv->forw_bcast_list, list) {
537
538 /**
539 * if purge_outstanding_packets() was called with an argmument
540 * we delete only packets belonging to the given interface
541 */
542 if ((batman_if) &&
543 (forw_packet->if_incoming != batman_if))
544 continue;
545
546 spin_unlock_irqrestore(&bat_priv->forw_bcast_list_lock, flags);
547
548 /**
549 * send_outstanding_bcast_packet() will lock the list to
550 * delete the item from the list
551 */
552 cancel_delayed_work_sync(&forw_packet->delayed_work);
553 spin_lock_irqsave(&bat_priv->forw_bcast_list_lock, flags);
554 }
555 spin_unlock_irqrestore(&bat_priv->forw_bcast_list_lock, flags);
556
557 /* free batman packet list */
558 spin_lock_irqsave(&bat_priv->forw_bat_list_lock, flags);
559 hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
560 &bat_priv->forw_bat_list, list) {
561
562 /**
563 * if purge_outstanding_packets() was called with an argmument
564 * we delete only packets belonging to the given interface
565 */
566 if ((batman_if) &&
567 (forw_packet->if_incoming != batman_if))
568 continue;
569
570 spin_unlock_irqrestore(&bat_priv->forw_bat_list_lock, flags);
571
572 /**
573 * send_outstanding_bat_packet() will lock the list to
574 * delete the item from the list
575 */
576 cancel_delayed_work_sync(&forw_packet->delayed_work);
577 spin_lock_irqsave(&bat_priv->forw_bat_list_lock, flags);
578 }
579 spin_unlock_irqrestore(&bat_priv->forw_bat_list_lock, flags);
580}
diff --git a/drivers/staging/batman-adv/send.h b/drivers/staging/batman-adv/send.h
deleted file mode 100644
index c4cefa8e4f85..000000000000
--- a/drivers/staging/batman-adv/send.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_SEND_H_
23#define _NET_BATMAN_ADV_SEND_H_
24
25#include "types.h"
26
27int send_skb_packet(struct sk_buff *skb,
28 struct batman_if *batman_if,
29 uint8_t *dst_addr);
30void schedule_own_packet(struct batman_if *batman_if);
31void schedule_forward_packet(struct orig_node *orig_node,
32 struct ethhdr *ethhdr,
33 struct batman_packet *batman_packet,
34 uint8_t directlink, int hna_buff_len,
35 struct batman_if *if_outgoing);
36int add_bcast_packet_to_list(struct bat_priv *bat_priv, struct sk_buff *skb);
37void send_outstanding_bat_packet(struct work_struct *work);
38void purge_outstanding_packets(struct bat_priv *bat_priv,
39 struct batman_if *batman_if);
40
41#endif /* _NET_BATMAN_ADV_SEND_H_ */
diff --git a/drivers/staging/batman-adv/soft-interface.c b/drivers/staging/batman-adv/soft-interface.c
deleted file mode 100644
index 0e996181daf7..000000000000
--- a/drivers/staging/batman-adv/soft-interface.c
+++ /dev/null
@@ -1,398 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "soft-interface.h"
24#include "hard-interface.h"
25#include "routing.h"
26#include "send.h"
27#include "bat_debugfs.h"
28#include "translation-table.h"
29#include "types.h"
30#include "hash.h"
31#include "send.h"
32#include "bat_sysfs.h"
33#include <linux/slab.h>
34#include <linux/ethtool.h>
35#include <linux/etherdevice.h>
36#include "unicast.h"
37
38
39static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
40static void bat_get_drvinfo(struct net_device *dev,
41 struct ethtool_drvinfo *info);
42static u32 bat_get_msglevel(struct net_device *dev);
43static void bat_set_msglevel(struct net_device *dev, u32 value);
44static u32 bat_get_link(struct net_device *dev);
45static u32 bat_get_rx_csum(struct net_device *dev);
46static int bat_set_rx_csum(struct net_device *dev, u32 data);
47
48static const struct ethtool_ops bat_ethtool_ops = {
49 .get_settings = bat_get_settings,
50 .get_drvinfo = bat_get_drvinfo,
51 .get_msglevel = bat_get_msglevel,
52 .set_msglevel = bat_set_msglevel,
53 .get_link = bat_get_link,
54 .get_rx_csum = bat_get_rx_csum,
55 .set_rx_csum = bat_set_rx_csum
56};
57
58int my_skb_head_push(struct sk_buff *skb, unsigned int len)
59{
60 int result;
61
62 /**
63 * TODO: We must check if we can release all references to non-payload
64 * data using skb_header_release in our skbs to allow skb_cow_header to
65 * work optimally. This means that those skbs are not allowed to read
66 * or write any data which is before the current position of skb->data
67 * after that call and thus allow other skbs with the same data buffer
68 * to write freely in that area.
69 */
70 result = skb_cow_head(skb, len);
71 if (result < 0)
72 return result;
73
74 skb_push(skb, len);
75 return 0;
76}
77
78static int interface_open(struct net_device *dev)
79{
80 netif_start_queue(dev);
81 return 0;
82}
83
84static int interface_release(struct net_device *dev)
85{
86 netif_stop_queue(dev);
87 return 0;
88}
89
90static struct net_device_stats *interface_stats(struct net_device *dev)
91{
92 struct bat_priv *bat_priv = netdev_priv(dev);
93 return &bat_priv->stats;
94}
95
96static int interface_set_mac_addr(struct net_device *dev, void *p)
97{
98 struct bat_priv *bat_priv = netdev_priv(dev);
99 struct sockaddr *addr = p;
100
101 if (!is_valid_ether_addr(addr->sa_data))
102 return -EADDRNOTAVAIL;
103
104 /* only modify hna-table if it has been initialised before */
105 if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) {
106 hna_local_remove(bat_priv, dev->dev_addr,
107 "mac address changed");
108 hna_local_add(dev, addr->sa_data);
109 }
110
111 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
112
113 return 0;
114}
115
116static int interface_change_mtu(struct net_device *dev, int new_mtu)
117{
118 /* check ranges */
119 if ((new_mtu < 68) || (new_mtu > hardif_min_mtu(dev)))
120 return -EINVAL;
121
122 dev->mtu = new_mtu;
123
124 return 0;
125}
126
127int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
128{
129 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
130 struct bat_priv *bat_priv = netdev_priv(soft_iface);
131 struct bcast_packet *bcast_packet;
132 int data_len = skb->len, ret;
133
134 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
135 goto dropped;
136
137 soft_iface->trans_start = jiffies;
138
139 /* TODO: check this for locks */
140 hna_local_add(soft_iface, ethhdr->h_source);
141
142 /* ethernet packet should be broadcasted */
143 if (is_bcast(ethhdr->h_dest) || is_mcast(ethhdr->h_dest)) {
144 if (!bat_priv->primary_if)
145 goto dropped;
146
147 if (my_skb_head_push(skb, sizeof(struct bcast_packet)) < 0)
148 goto dropped;
149
150 bcast_packet = (struct bcast_packet *)skb->data;
151 bcast_packet->version = COMPAT_VERSION;
152 bcast_packet->ttl = TTL;
153
154 /* batman packet type: broadcast */
155 bcast_packet->packet_type = BAT_BCAST;
156
157 /* hw address of first interface is the orig mac because only
158 * this mac is known throughout the mesh */
159 memcpy(bcast_packet->orig,
160 bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
161
162 /* set broadcast sequence number */
163 bcast_packet->seqno =
164 htonl(atomic_inc_return(&bat_priv->bcast_seqno));
165
166 add_bcast_packet_to_list(bat_priv, skb);
167
168 /* a copy is stored in the bcast list, therefore removing
169 * the original skb. */
170 kfree_skb(skb);
171
172 /* unicast packet */
173 } else {
174 ret = unicast_send_skb(skb, bat_priv);
175 if (ret != 0)
176 goto dropped_freed;
177 }
178
179 bat_priv->stats.tx_packets++;
180 bat_priv->stats.tx_bytes += data_len;
181 goto end;
182
183dropped:
184 kfree_skb(skb);
185dropped_freed:
186 bat_priv->stats.tx_dropped++;
187end:
188 return NETDEV_TX_OK;
189}
190
191void interface_rx(struct net_device *soft_iface,
192 struct sk_buff *skb, int hdr_size)
193{
194 struct bat_priv *priv = netdev_priv(soft_iface);
195
196 /* check if enough space is available for pulling, and pull */
197 if (!pskb_may_pull(skb, hdr_size))
198 goto dropped;
199
200 skb_pull_rcsum(skb, hdr_size);
201/* skb_set_mac_header(skb, -sizeof(struct ethhdr));*/
202
203 /* skb->dev & skb->pkt_type are set here */
204 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
205 goto dropped;
206 skb->protocol = eth_type_trans(skb, soft_iface);
207
208 /* should not be neccesary anymore as we use skb_pull_rcsum()
209 * TODO: please verify this and remove this TODO
210 * -- Dec 21st 2009, Simon Wunderlich */
211
212/* skb->ip_summed = CHECKSUM_UNNECESSARY;*/
213
214 priv->stats.rx_packets++;
215 priv->stats.rx_bytes += skb->len + sizeof(struct ethhdr);
216
217 soft_iface->last_rx = jiffies;
218
219 netif_rx(skb);
220 return;
221
222dropped:
223 kfree_skb(skb);
224 return;
225}
226
227#ifdef HAVE_NET_DEVICE_OPS
228static const struct net_device_ops bat_netdev_ops = {
229 .ndo_open = interface_open,
230 .ndo_stop = interface_release,
231 .ndo_get_stats = interface_stats,
232 .ndo_set_mac_address = interface_set_mac_addr,
233 .ndo_change_mtu = interface_change_mtu,
234 .ndo_start_xmit = interface_tx,
235 .ndo_validate_addr = eth_validate_addr
236};
237#endif
238
239static void interface_setup(struct net_device *dev)
240{
241 struct bat_priv *priv = netdev_priv(dev);
242 char dev_addr[ETH_ALEN];
243
244 ether_setup(dev);
245
246#ifdef HAVE_NET_DEVICE_OPS
247 dev->netdev_ops = &bat_netdev_ops;
248#else
249 dev->open = interface_open;
250 dev->stop = interface_release;
251 dev->get_stats = interface_stats;
252 dev->set_mac_address = interface_set_mac_addr;
253 dev->change_mtu = interface_change_mtu;
254 dev->hard_start_xmit = interface_tx;
255#endif
256 dev->destructor = free_netdev;
257
258 /**
259 * can't call min_mtu, because the needed variables
260 * have not been initialized yet
261 */
262 dev->mtu = ETH_DATA_LEN;
263 dev->hard_header_len = BAT_HEADER_LEN; /* reserve more space in the
264 * skbuff for our header */
265
266 /* generate random address */
267 random_ether_addr(dev_addr);
268 memcpy(dev->dev_addr, dev_addr, ETH_ALEN);
269
270 SET_ETHTOOL_OPS(dev, &bat_ethtool_ops);
271
272 memset(priv, 0, sizeof(struct bat_priv));
273}
274
275struct net_device *softif_create(char *name)
276{
277 struct net_device *soft_iface;
278 struct bat_priv *bat_priv;
279 int ret;
280
281 soft_iface = alloc_netdev(sizeof(struct bat_priv) , name,
282 interface_setup);
283
284 if (!soft_iface) {
285 pr_err("Unable to allocate the batman interface: %s\n", name);
286 goto out;
287 }
288
289 ret = register_netdev(soft_iface);
290 if (ret < 0) {
291 pr_err("Unable to register the batman interface '%s': %i\n",
292 name, ret);
293 goto free_soft_iface;
294 }
295
296 bat_priv = netdev_priv(soft_iface);
297
298 atomic_set(&bat_priv->aggregation_enabled, 1);
299 atomic_set(&bat_priv->bonding_enabled, 0);
300 atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
301 atomic_set(&bat_priv->orig_interval, 1000);
302 atomic_set(&bat_priv->log_level, 0);
303 atomic_set(&bat_priv->frag_enabled, 1);
304 atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN);
305 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
306
307 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
308 atomic_set(&bat_priv->bcast_seqno, 1);
309 atomic_set(&bat_priv->hna_local_changed, 0);
310
311 bat_priv->primary_if = NULL;
312 bat_priv->num_ifaces = 0;
313
314 ret = sysfs_add_meshif(soft_iface);
315 if (ret < 0)
316 goto unreg_soft_iface;
317
318 ret = debugfs_add_meshif(soft_iface);
319 if (ret < 0)
320 goto unreg_sysfs;
321
322 ret = mesh_init(soft_iface);
323 if (ret < 0)
324 goto unreg_debugfs;
325
326 return soft_iface;
327
328unreg_debugfs:
329 debugfs_del_meshif(soft_iface);
330unreg_sysfs:
331 sysfs_del_meshif(soft_iface);
332unreg_soft_iface:
333 unregister_netdev(soft_iface);
334 return NULL;
335
336free_soft_iface:
337 free_netdev(soft_iface);
338out:
339 return NULL;
340}
341
342void softif_destroy(struct net_device *soft_iface)
343{
344 debugfs_del_meshif(soft_iface);
345 sysfs_del_meshif(soft_iface);
346 mesh_free(soft_iface);
347 unregister_netdevice(soft_iface);
348}
349
350/* ethtool */
351static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
352{
353 cmd->supported = 0;
354 cmd->advertising = 0;
355 cmd->speed = SPEED_10;
356 cmd->duplex = DUPLEX_FULL;
357 cmd->port = PORT_TP;
358 cmd->phy_address = 0;
359 cmd->transceiver = XCVR_INTERNAL;
360 cmd->autoneg = AUTONEG_DISABLE;
361 cmd->maxtxpkt = 0;
362 cmd->maxrxpkt = 0;
363
364 return 0;
365}
366
367static void bat_get_drvinfo(struct net_device *dev,
368 struct ethtool_drvinfo *info)
369{
370 strcpy(info->driver, "B.A.T.M.A.N. advanced");
371 strcpy(info->version, SOURCE_VERSION);
372 strcpy(info->fw_version, "N/A");
373 strcpy(info->bus_info, "batman");
374}
375
376static u32 bat_get_msglevel(struct net_device *dev)
377{
378 return -EOPNOTSUPP;
379}
380
381static void bat_set_msglevel(struct net_device *dev, u32 value)
382{
383}
384
385static u32 bat_get_link(struct net_device *dev)
386{
387 return 1;
388}
389
390static u32 bat_get_rx_csum(struct net_device *dev)
391{
392 return 0;
393}
394
395static int bat_set_rx_csum(struct net_device *dev, u32 data)
396{
397 return -EOPNOTSUPP;
398}
diff --git a/drivers/staging/batman-adv/soft-interface.h b/drivers/staging/batman-adv/soft-interface.h
deleted file mode 100644
index 843a7ec082fe..000000000000
--- a/drivers/staging/batman-adv/soft-interface.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_SOFT_INTERFACE_H_
23#define _NET_BATMAN_ADV_SOFT_INTERFACE_H_
24
25int my_skb_head_push(struct sk_buff *skb, unsigned int len);
26int interface_tx(struct sk_buff *skb, struct net_device *soft_iface);
27void interface_rx(struct net_device *soft_iface,
28 struct sk_buff *skb, int hdr_size);
29struct net_device *softif_create(char *name);
30void softif_destroy(struct net_device *soft_iface);
31
32#endif /* _NET_BATMAN_ADV_SOFT_INTERFACE_H_ */
diff --git a/drivers/staging/batman-adv/sysfs-class-net-batman-adv b/drivers/staging/batman-adv/sysfs-class-net-batman-adv
deleted file mode 100644
index 38dd762def4b..000000000000
--- a/drivers/staging/batman-adv/sysfs-class-net-batman-adv
+++ /dev/null
@@ -1,14 +0,0 @@
1
2What: /sys/class/net/<iface>/batman-adv/mesh_iface
3Date: May 2010
4Contact: Marek Lindner <lindner_marek@yahoo.de>
5Description:
6 The /sys/class/net/<iface>/batman-adv/mesh_iface file
7 displays the batman mesh interface this <iface>
8 currently is associated with.
9
10What: /sys/class/net/<iface>/batman-adv/iface_status
11Date: May 2010
12Contact: Marek Lindner <lindner_marek@yahoo.de>
13Description:
14 Indicates the status of <iface> as it is seen by batman.
diff --git a/drivers/staging/batman-adv/sysfs-class-net-mesh b/drivers/staging/batman-adv/sysfs-class-net-mesh
deleted file mode 100644
index b4cdb6038bf1..000000000000
--- a/drivers/staging/batman-adv/sysfs-class-net-mesh
+++ /dev/null
@@ -1,41 +0,0 @@
1
2What: /sys/class/net/<mesh_iface>/mesh/aggregated_ogms
3Date: May 2010
4Contact: Marek Lindner <lindner_marek@yahoo.de>
5Description:
6 Indicates whether the batman protocol messages of the
7 mesh <mesh_iface> shall be aggregated or not.
8
9What: /sys/class/net/<mesh_iface>/mesh/bonding
10Date: June 2010
11Contact: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
12Description:
13 Indicates whether the data traffic going through the
14 mesh will be sent using multiple interfaces at the
15 same time (if available).
16
17What: /sys/class/net/<mesh_iface>/mesh/fragmentation
18Date: October 2010
19Contact: Andreas Langer <an.langer@gmx.de>
20Description:
21 Indicates whether the data traffic going through the
22 mesh will be fragmented or silently discarded if the
23 packet size exceeds the outgoing interface MTU.
24
25What: /sys/class/net/<mesh_iface>/mesh/orig_interval
26Date: May 2010
27Contact: Marek Lindner <lindner_marek@yahoo.de>
28Description:
29 Defines the interval in milliseconds in which batman
30 sends its protocol messages.
31
32What: /sys/class/net/<mesh_iface>/mesh/vis_mode
33Date: May 2010
34Contact: Marek Lindner <lindner_marek@yahoo.de>
35Description:
36 Each batman node only maintains information about its
37 own local neighborhood, therefore generating graphs
38 showing the topology of the entire mesh is not easily
39 feasible without having a central instance to collect
40 the local topologies from all nodes. This file allows
41 to activate the collecting (server) mode.
diff --git a/drivers/staging/batman-adv/translation-table.c b/drivers/staging/batman-adv/translation-table.c
deleted file mode 100644
index 681ccbda3eac..000000000000
--- a/drivers/staging/batman-adv/translation-table.c
+++ /dev/null
@@ -1,518 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "translation-table.h"
24#include "soft-interface.h"
25#include "types.h"
26#include "hash.h"
27
28static void hna_local_purge(struct work_struct *work);
29static void _hna_global_del_orig(struct bat_priv *bat_priv,
30 struct hna_global_entry *hna_global_entry,
31 char *message);
32
33static void hna_local_start_timer(struct bat_priv *bat_priv)
34{
35 INIT_DELAYED_WORK(&bat_priv->hna_work, hna_local_purge);
36 queue_delayed_work(bat_event_workqueue, &bat_priv->hna_work, 10 * HZ);
37}
38
39int hna_local_init(struct bat_priv *bat_priv)
40{
41 if (bat_priv->hna_local_hash)
42 return 1;
43
44 bat_priv->hna_local_hash = hash_new(128, compare_orig, choose_orig);
45
46 if (!bat_priv->hna_local_hash)
47 return 0;
48
49 atomic_set(&bat_priv->hna_local_changed, 0);
50 hna_local_start_timer(bat_priv);
51
52 return 1;
53}
54
55void hna_local_add(struct net_device *soft_iface, uint8_t *addr)
56{
57 struct bat_priv *bat_priv = netdev_priv(soft_iface);
58 struct hna_local_entry *hna_local_entry;
59 struct hna_global_entry *hna_global_entry;
60 struct hashtable_t *swaphash;
61 unsigned long flags;
62 int required_bytes;
63
64 spin_lock_irqsave(&bat_priv->hna_lhash_lock, flags);
65 hna_local_entry =
66 ((struct hna_local_entry *)hash_find(bat_priv->hna_local_hash,
67 addr));
68 spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags);
69
70 if (hna_local_entry) {
71 hna_local_entry->last_seen = jiffies;
72 return;
73 }
74
75 /* only announce as many hosts as possible in the batman-packet and
76 space in batman_packet->num_hna That also should give a limit to
77 MAC-flooding. */
78 required_bytes = (bat_priv->num_local_hna + 1) * ETH_ALEN;
79 required_bytes += BAT_PACKET_LEN;
80
81 if ((required_bytes > ETH_DATA_LEN) ||
82 (atomic_read(&bat_priv->aggregation_enabled) &&
83 required_bytes > MAX_AGGREGATION_BYTES) ||
84 (bat_priv->num_local_hna + 1 > 255)) {
85 bat_dbg(DBG_ROUTES, bat_priv,
86 "Can't add new local hna entry (%pM): "
87 "number of local hna entries exceeds packet size\n",
88 addr);
89 return;
90 }
91
92 bat_dbg(DBG_ROUTES, bat_priv,
93 "Creating new local hna entry: %pM\n", addr);
94
95 hna_local_entry = kmalloc(sizeof(struct hna_local_entry), GFP_ATOMIC);
96 if (!hna_local_entry)
97 return;
98
99 memcpy(hna_local_entry->addr, addr, ETH_ALEN);
100 hna_local_entry->last_seen = jiffies;
101
102 /* the batman interface mac address should never be purged */
103 if (compare_orig(addr, soft_iface->dev_addr))
104 hna_local_entry->never_purge = 1;
105 else
106 hna_local_entry->never_purge = 0;
107
108 spin_lock_irqsave(&bat_priv->hna_lhash_lock, flags);
109
110 hash_add(bat_priv->hna_local_hash, hna_local_entry);
111 bat_priv->num_local_hna++;
112 atomic_set(&bat_priv->hna_local_changed, 1);
113
114 if (bat_priv->hna_local_hash->elements * 4 >
115 bat_priv->hna_local_hash->size) {
116 swaphash = hash_resize(bat_priv->hna_local_hash,
117 bat_priv->hna_local_hash->size * 2);
118
119 if (!swaphash)
120 pr_err("Couldn't resize local hna hash table\n");
121 else
122 bat_priv->hna_local_hash = swaphash;
123 }
124
125 spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags);
126
127 /* remove address from global hash if present */
128 spin_lock_irqsave(&bat_priv->hna_ghash_lock, flags);
129
130 hna_global_entry = ((struct hna_global_entry *)
131 hash_find(bat_priv->hna_global_hash, addr));
132
133 if (hna_global_entry)
134 _hna_global_del_orig(bat_priv, hna_global_entry,
135 "local hna received");
136
137 spin_unlock_irqrestore(&bat_priv->hna_ghash_lock, flags);
138}
139
140int hna_local_fill_buffer(struct bat_priv *bat_priv,
141 unsigned char *buff, int buff_len)
142{
143 struct hna_local_entry *hna_local_entry;
144 HASHIT(hashit);
145 int i = 0;
146 unsigned long flags;
147
148 spin_lock_irqsave(&bat_priv->hna_lhash_lock, flags);
149
150 while (hash_iterate(bat_priv->hna_local_hash, &hashit)) {
151
152 if (buff_len < (i + 1) * ETH_ALEN)
153 break;
154
155 hna_local_entry = hashit.bucket->data;
156 memcpy(buff + (i * ETH_ALEN), hna_local_entry->addr, ETH_ALEN);
157
158 i++;
159 }
160
161 /* if we did not get all new local hnas see you next time ;-) */
162 if (i == bat_priv->num_local_hna)
163 atomic_set(&bat_priv->hna_local_changed, 0);
164
165 spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags);
166 return i;
167}
168
169int hna_local_seq_print_text(struct seq_file *seq, void *offset)
170{
171 struct net_device *net_dev = (struct net_device *)seq->private;
172 struct bat_priv *bat_priv = netdev_priv(net_dev);
173 struct hna_local_entry *hna_local_entry;
174 HASHIT(hashit);
175 HASHIT(hashit_count);
176 unsigned long flags;
177 size_t buf_size, pos;
178 char *buff;
179
180 if (!bat_priv->primary_if) {
181 return seq_printf(seq, "BATMAN mesh %s disabled - "
182 "please specify interfaces to enable it\n",
183 net_dev->name);
184 }
185
186 seq_printf(seq, "Locally retrieved addresses (from %s) "
187 "announced via HNA:\n",
188 net_dev->name);
189
190 spin_lock_irqsave(&bat_priv->hna_lhash_lock, flags);
191
192 buf_size = 1;
193 /* Estimate length for: " * xx:xx:xx:xx:xx:xx\n" */
194 while (hash_iterate(bat_priv->hna_local_hash, &hashit_count))
195 buf_size += 21;
196
197 buff = kmalloc(buf_size, GFP_ATOMIC);
198 if (!buff) {
199 spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags);
200 return -ENOMEM;
201 }
202 buff[0] = '\0';
203 pos = 0;
204
205 while (hash_iterate(bat_priv->hna_local_hash, &hashit)) {
206 hna_local_entry = hashit.bucket->data;
207
208 pos += snprintf(buff + pos, 22, " * %pM\n",
209 hna_local_entry->addr);
210 }
211
212 spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags);
213
214 seq_printf(seq, "%s", buff);
215 kfree(buff);
216 return 0;
217}
218
219static void _hna_local_del(void *data, void *arg)
220{
221 struct bat_priv *bat_priv = (struct bat_priv *)arg;
222
223 kfree(data);
224 bat_priv->num_local_hna--;
225 atomic_set(&bat_priv->hna_local_changed, 1);
226}
227
228static void hna_local_del(struct bat_priv *bat_priv,
229 struct hna_local_entry *hna_local_entry,
230 char *message)
231{
232 bat_dbg(DBG_ROUTES, bat_priv, "Deleting local hna entry (%pM): %s\n",
233 hna_local_entry->addr, message);
234
235 hash_remove(bat_priv->hna_local_hash, hna_local_entry->addr);
236 _hna_local_del(hna_local_entry, bat_priv);
237}
238
239void hna_local_remove(struct bat_priv *bat_priv,
240 uint8_t *addr, char *message)
241{
242 struct hna_local_entry *hna_local_entry;
243 unsigned long flags;
244
245 spin_lock_irqsave(&bat_priv->hna_lhash_lock, flags);
246
247 hna_local_entry = (struct hna_local_entry *)
248 hash_find(bat_priv->hna_local_hash, addr);
249 if (hna_local_entry)
250 hna_local_del(bat_priv, hna_local_entry, message);
251
252 spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags);
253}
254
255static void hna_local_purge(struct work_struct *work)
256{
257 struct delayed_work *delayed_work =
258 container_of(work, struct delayed_work, work);
259 struct bat_priv *bat_priv =
260 container_of(delayed_work, struct bat_priv, hna_work);
261 struct hna_local_entry *hna_local_entry;
262 HASHIT(hashit);
263 unsigned long flags;
264 unsigned long timeout;
265
266 spin_lock_irqsave(&bat_priv->hna_lhash_lock, flags);
267
268 while (hash_iterate(bat_priv->hna_local_hash, &hashit)) {
269 hna_local_entry = hashit.bucket->data;
270
271 timeout = hna_local_entry->last_seen + LOCAL_HNA_TIMEOUT * HZ;
272
273 if ((!hna_local_entry->never_purge) &&
274 time_after(jiffies, timeout))
275 hna_local_del(bat_priv, hna_local_entry,
276 "address timed out");
277 }
278
279 spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags);
280 hna_local_start_timer(bat_priv);
281}
282
283void hna_local_free(struct bat_priv *bat_priv)
284{
285 if (!bat_priv->hna_local_hash)
286 return;
287
288 cancel_delayed_work_sync(&bat_priv->hna_work);
289 hash_delete(bat_priv->hna_local_hash, _hna_local_del, bat_priv);
290 bat_priv->hna_local_hash = NULL;
291}
292
293int hna_global_init(struct bat_priv *bat_priv)
294{
295 if (bat_priv->hna_global_hash)
296 return 1;
297
298 bat_priv->hna_global_hash = hash_new(128, compare_orig, choose_orig);
299
300 if (!bat_priv->hna_global_hash)
301 return 0;
302
303 return 1;
304}
305
306void hna_global_add_orig(struct bat_priv *bat_priv,
307 struct orig_node *orig_node,
308 unsigned char *hna_buff, int hna_buff_len)
309{
310 struct hna_global_entry *hna_global_entry;
311 struct hna_local_entry *hna_local_entry;
312 struct hashtable_t *swaphash;
313 int hna_buff_count = 0;
314 unsigned long flags;
315 unsigned char *hna_ptr;
316
317 while ((hna_buff_count + 1) * ETH_ALEN <= hna_buff_len) {
318 spin_lock_irqsave(&bat_priv->hna_ghash_lock, flags);
319
320 hna_ptr = hna_buff + (hna_buff_count * ETH_ALEN);
321 hna_global_entry = (struct hna_global_entry *)
322 hash_find(bat_priv->hna_global_hash, hna_ptr);
323
324 if (!hna_global_entry) {
325 spin_unlock_irqrestore(&bat_priv->hna_ghash_lock,
326 flags);
327
328 hna_global_entry =
329 kmalloc(sizeof(struct hna_global_entry),
330 GFP_ATOMIC);
331
332 if (!hna_global_entry)
333 break;
334
335 memcpy(hna_global_entry->addr, hna_ptr, ETH_ALEN);
336
337 bat_dbg(DBG_ROUTES, bat_priv,
338 "Creating new global hna entry: "
339 "%pM (via %pM)\n",
340 hna_global_entry->addr, orig_node->orig);
341
342 spin_lock_irqsave(&bat_priv->hna_ghash_lock, flags);
343 hash_add(bat_priv->hna_global_hash, hna_global_entry);
344
345 }
346
347 hna_global_entry->orig_node = orig_node;
348 spin_unlock_irqrestore(&bat_priv->hna_ghash_lock, flags);
349
350 /* remove address from local hash if present */
351 spin_lock_irqsave(&bat_priv->hna_lhash_lock, flags);
352
353 hna_ptr = hna_buff + (hna_buff_count * ETH_ALEN);
354 hna_local_entry = (struct hna_local_entry *)
355 hash_find(bat_priv->hna_local_hash, hna_ptr);
356
357 if (hna_local_entry)
358 hna_local_del(bat_priv, hna_local_entry,
359 "global hna received");
360
361 spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags);
362
363 hna_buff_count++;
364 }
365
366 /* initialize, and overwrite if malloc succeeds */
367 orig_node->hna_buff = NULL;
368 orig_node->hna_buff_len = 0;
369
370 if (hna_buff_len > 0) {
371 orig_node->hna_buff = kmalloc(hna_buff_len, GFP_ATOMIC);
372 if (orig_node->hna_buff) {
373 memcpy(orig_node->hna_buff, hna_buff, hna_buff_len);
374 orig_node->hna_buff_len = hna_buff_len;
375 }
376 }
377
378 spin_lock_irqsave(&bat_priv->hna_ghash_lock, flags);
379
380 if (bat_priv->hna_global_hash->elements * 4 >
381 bat_priv->hna_global_hash->size) {
382 swaphash = hash_resize(bat_priv->hna_global_hash,
383 bat_priv->hna_global_hash->size * 2);
384
385 if (!swaphash)
386 pr_err("Couldn't resize global hna hash table\n");
387 else
388 bat_priv->hna_global_hash = swaphash;
389 }
390
391 spin_unlock_irqrestore(&bat_priv->hna_ghash_lock, flags);
392}
393
394int hna_global_seq_print_text(struct seq_file *seq, void *offset)
395{
396 struct net_device *net_dev = (struct net_device *)seq->private;
397 struct bat_priv *bat_priv = netdev_priv(net_dev);
398 struct hna_global_entry *hna_global_entry;
399 HASHIT(hashit);
400 HASHIT(hashit_count);
401 unsigned long flags;
402 size_t buf_size, pos;
403 char *buff;
404
405 if (!bat_priv->primary_if) {
406 return seq_printf(seq, "BATMAN mesh %s disabled - "
407 "please specify interfaces to enable it\n",
408 net_dev->name);
409 }
410
411 seq_printf(seq, "Globally announced HNAs received via the mesh %s\n",
412 net_dev->name);
413
414 spin_lock_irqsave(&bat_priv->hna_ghash_lock, flags);
415
416 buf_size = 1;
417 /* Estimate length for: " * xx:xx:xx:xx:xx:xx via xx:xx:xx:xx:xx:xx\n"*/
418 while (hash_iterate(bat_priv->hna_global_hash, &hashit_count))
419 buf_size += 43;
420
421 buff = kmalloc(buf_size, GFP_ATOMIC);
422 if (!buff) {
423 spin_unlock_irqrestore(&bat_priv->hna_ghash_lock, flags);
424 return -ENOMEM;
425 }
426 buff[0] = '\0';
427 pos = 0;
428
429 while (hash_iterate(bat_priv->hna_global_hash, &hashit)) {
430 hna_global_entry = hashit.bucket->data;
431
432 pos += snprintf(buff + pos, 44,
433 " * %pM via %pM\n", hna_global_entry->addr,
434 hna_global_entry->orig_node->orig);
435 }
436
437 spin_unlock_irqrestore(&bat_priv->hna_ghash_lock, flags);
438
439 seq_printf(seq, "%s", buff);
440 kfree(buff);
441 return 0;
442}
443
444static void _hna_global_del_orig(struct bat_priv *bat_priv,
445 struct hna_global_entry *hna_global_entry,
446 char *message)
447{
448 bat_dbg(DBG_ROUTES, bat_priv,
449 "Deleting global hna entry %pM (via %pM): %s\n",
450 hna_global_entry->addr, hna_global_entry->orig_node->orig,
451 message);
452
453 hash_remove(bat_priv->hna_global_hash, hna_global_entry->addr);
454 kfree(hna_global_entry);
455}
456
457void hna_global_del_orig(struct bat_priv *bat_priv,
458 struct orig_node *orig_node, char *message)
459{
460 struct hna_global_entry *hna_global_entry;
461 int hna_buff_count = 0;
462 unsigned long flags;
463 unsigned char *hna_ptr;
464
465 if (orig_node->hna_buff_len == 0)
466 return;
467
468 spin_lock_irqsave(&bat_priv->hna_ghash_lock, flags);
469
470 while ((hna_buff_count + 1) * ETH_ALEN <= orig_node->hna_buff_len) {
471 hna_ptr = orig_node->hna_buff + (hna_buff_count * ETH_ALEN);
472 hna_global_entry = (struct hna_global_entry *)
473 hash_find(bat_priv->hna_global_hash, hna_ptr);
474
475 if ((hna_global_entry) &&
476 (hna_global_entry->orig_node == orig_node))
477 _hna_global_del_orig(bat_priv, hna_global_entry,
478 message);
479
480 hna_buff_count++;
481 }
482
483 spin_unlock_irqrestore(&bat_priv->hna_ghash_lock, flags);
484
485 orig_node->hna_buff_len = 0;
486 kfree(orig_node->hna_buff);
487 orig_node->hna_buff = NULL;
488}
489
490static void hna_global_del(void *data, void *arg)
491{
492 kfree(data);
493}
494
495void hna_global_free(struct bat_priv *bat_priv)
496{
497 if (!bat_priv->hna_global_hash)
498 return;
499
500 hash_delete(bat_priv->hna_global_hash, hna_global_del, NULL);
501 bat_priv->hna_global_hash = NULL;
502}
503
504struct orig_node *transtable_search(struct bat_priv *bat_priv, uint8_t *addr)
505{
506 struct hna_global_entry *hna_global_entry;
507 unsigned long flags;
508
509 spin_lock_irqsave(&bat_priv->hna_ghash_lock, flags);
510 hna_global_entry = (struct hna_global_entry *)
511 hash_find(bat_priv->hna_global_hash, addr);
512 spin_unlock_irqrestore(&bat_priv->hna_ghash_lock, flags);
513
514 if (!hna_global_entry)
515 return NULL;
516
517 return hna_global_entry->orig_node;
518}
diff --git a/drivers/staging/batman-adv/translation-table.h b/drivers/staging/batman-adv/translation-table.h
deleted file mode 100644
index 10c4c5c319b6..000000000000
--- a/drivers/staging/batman-adv/translation-table.h
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_TRANSLATION_TABLE_H_
23#define _NET_BATMAN_ADV_TRANSLATION_TABLE_H_
24
25#include "types.h"
26
27int hna_local_init(struct bat_priv *bat_priv);
28void hna_local_add(struct net_device *soft_iface, uint8_t *addr);
29void hna_local_remove(struct bat_priv *bat_priv,
30 uint8_t *addr, char *message);
31int hna_local_fill_buffer(struct bat_priv *bat_priv,
32 unsigned char *buff, int buff_len);
33int hna_local_seq_print_text(struct seq_file *seq, void *offset);
34void hna_local_free(struct bat_priv *bat_priv);
35int hna_global_init(struct bat_priv *bat_priv);
36void hna_global_add_orig(struct bat_priv *bat_priv,
37 struct orig_node *orig_node,
38 unsigned char *hna_buff, int hna_buff_len);
39int hna_global_seq_print_text(struct seq_file *seq, void *offset);
40void hna_global_del_orig(struct bat_priv *bat_priv,
41 struct orig_node *orig_node, char *message);
42void hna_global_free(struct bat_priv *bat_priv);
43struct orig_node *transtable_search(struct bat_priv *bat_priv, uint8_t *addr);
44
45#endif /* _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ */
diff --git a/drivers/staging/batman-adv/types.h b/drivers/staging/batman-adv/types.h
deleted file mode 100644
index f3f7366231e7..000000000000
--- a/drivers/staging/batman-adv/types.h
+++ /dev/null
@@ -1,241 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
3 *
4 * Marek Lindner, Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22
23
24#ifndef _NET_BATMAN_ADV_TYPES_H_
25#define _NET_BATMAN_ADV_TYPES_H_
26
27#include "packet.h"
28#include "bitarray.h"
29
30#define BAT_HEADER_LEN (sizeof(struct ethhdr) + \
31 ((sizeof(struct unicast_packet) > sizeof(struct bcast_packet) ? \
32 sizeof(struct unicast_packet) : \
33 sizeof(struct bcast_packet))))
34
35
36struct batman_if {
37 struct list_head list;
38 int16_t if_num;
39 char if_status;
40 struct net_device *net_dev;
41 atomic_t seqno;
42 atomic_t frag_seqno;
43 unsigned char *packet_buff;
44 int packet_len;
45 struct kobject *hardif_obj;
46 atomic_t refcnt;
47 struct packet_type batman_adv_ptype;
48 struct net_device *soft_iface;
49};
50
51/**
52 * orig_node - structure for orig_list maintaining nodes of mesh
53 * @primary_addr: hosts primary interface address
54 * @last_valid: when last packet from this node was received
55 * @bcast_seqno_reset: time when the broadcast seqno window was reset
56 * @batman_seqno_reset: time when the batman seqno window was reset
57 * @flags: for now only VIS_SERVER flag
58 * @last_real_seqno: last and best known squence number
59 * @last_ttl: ttl of last received packet
60 * @last_bcast_seqno: last broadcast sequence number received by this host
61 *
62 * @candidates: how many candidates are available
63 * @selected: next bonding candidate
64 */
65struct orig_node {
66 uint8_t orig[ETH_ALEN];
67 uint8_t primary_addr[ETH_ALEN];
68 struct neigh_node *router;
69 TYPE_OF_WORD *bcast_own;
70 uint8_t *bcast_own_sum;
71 uint8_t tq_own;
72 int tq_asym_penalty;
73 unsigned long last_valid;
74 unsigned long bcast_seqno_reset;
75 unsigned long batman_seqno_reset;
76 uint8_t flags;
77 unsigned char *hna_buff;
78 int16_t hna_buff_len;
79 uint32_t last_real_seqno;
80 uint8_t last_ttl;
81 TYPE_OF_WORD bcast_bits[NUM_WORDS];
82 uint32_t last_bcast_seqno;
83 struct list_head neigh_list;
84 struct list_head frag_list;
85 unsigned long last_frag_packet;
86 struct {
87 uint8_t candidates;
88 struct neigh_node *selected;
89 } bond;
90};
91
92/**
93 * neigh_node
94 * @last_valid: when last packet via this neighbor was received
95 */
96struct neigh_node {
97 struct list_head list;
98 uint8_t addr[ETH_ALEN];
99 uint8_t real_packet_count;
100 uint8_t tq_recv[TQ_GLOBAL_WINDOW_SIZE];
101 uint8_t tq_index;
102 uint8_t tq_avg;
103 uint8_t last_ttl;
104 struct neigh_node *next_bond_candidate;
105 unsigned long last_valid;
106 TYPE_OF_WORD real_bits[NUM_WORDS];
107 struct orig_node *orig_node;
108 struct batman_if *if_incoming;
109};
110
111
112struct bat_priv {
113 atomic_t mesh_state;
114 struct net_device_stats stats;
115 atomic_t aggregation_enabled;
116 atomic_t bonding_enabled;
117 atomic_t frag_enabled;
118 atomic_t vis_mode;
119 atomic_t orig_interval;
120 atomic_t log_level;
121 atomic_t bcast_seqno;
122 atomic_t bcast_queue_left;
123 atomic_t batman_queue_left;
124 char num_ifaces;
125 struct debug_log *debug_log;
126 struct batman_if *primary_if;
127 struct kobject *mesh_obj;
128 struct dentry *debug_dir;
129 struct hlist_head forw_bat_list;
130 struct hlist_head forw_bcast_list;
131 struct list_head vis_send_list;
132 struct hashtable_t *orig_hash;
133 struct hashtable_t *hna_local_hash;
134 struct hashtable_t *hna_global_hash;
135 struct hashtable_t *vis_hash;
136 spinlock_t orig_hash_lock; /* protects orig_hash */
137 spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
138 spinlock_t forw_bcast_list_lock; /* protects */
139 spinlock_t hna_lhash_lock; /* protects hna_local_hash */
140 spinlock_t hna_ghash_lock; /* protects hna_global_hash */
141 spinlock_t vis_hash_lock; /* protects vis_hash */
142 spinlock_t vis_list_lock; /* protects vis_info::recv_list */
143 int16_t num_local_hna;
144 atomic_t hna_local_changed;
145 struct delayed_work hna_work;
146 struct delayed_work orig_work;
147 struct delayed_work vis_work;
148 struct vis_info *my_vis_info;
149};
150
151struct socket_client {
152 struct list_head queue_list;
153 unsigned int queue_len;
154 unsigned char index;
155 spinlock_t lock; /* protects queue_list, queue_len, index */
156 wait_queue_head_t queue_wait;
157 struct bat_priv *bat_priv;
158};
159
160struct socket_packet {
161 struct list_head list;
162 size_t icmp_len;
163 struct icmp_packet_rr icmp_packet;
164};
165
166struct hna_local_entry {
167 uint8_t addr[ETH_ALEN];
168 unsigned long last_seen;
169 char never_purge;
170};
171
172struct hna_global_entry {
173 uint8_t addr[ETH_ALEN];
174 struct orig_node *orig_node;
175};
176
177/**
178 * forw_packet - structure for forw_list maintaining packets to be
179 * send/forwarded
180 */
181struct forw_packet {
182 struct hlist_node list;
183 unsigned long send_time;
184 uint8_t own;
185 struct sk_buff *skb;
186 uint16_t packet_len;
187 uint32_t direct_link_flags;
188 uint8_t num_packets;
189 struct delayed_work delayed_work;
190 struct batman_if *if_incoming;
191};
192
193/* While scanning for vis-entries of a particular vis-originator
194 * this list collects its interfaces to create a subgraph/cluster
195 * out of them later
196 */
197struct if_list_entry {
198 uint8_t addr[ETH_ALEN];
199 bool primary;
200 struct hlist_node list;
201};
202
203struct debug_log {
204 char log_buff[LOG_BUF_LEN];
205 unsigned long log_start;
206 unsigned long log_end;
207 spinlock_t lock; /* protects log_buff, log_start and log_end */
208 wait_queue_head_t queue_wait;
209};
210
211struct frag_packet_list_entry {
212 struct list_head list;
213 uint16_t seqno;
214 struct sk_buff *skb;
215};
216
217struct vis_info {
218 unsigned long first_seen;
219 struct list_head recv_list;
220 /* list of server-neighbors we received a vis-packet
221 * from. we should not reply to them. */
222 struct list_head send_list;
223 struct kref refcount;
224 struct bat_priv *bat_priv;
225 /* this packet might be part of the vis send queue. */
226 struct sk_buff *skb_packet;
227 /* vis_info may follow here*/
228} __attribute__((packed));
229
230struct vis_info_entry {
231 uint8_t src[ETH_ALEN];
232 uint8_t dest[ETH_ALEN];
233 uint8_t quality; /* quality = 0 means HNA */
234} __attribute__((packed));
235
236struct recvlist_node {
237 struct list_head list;
238 uint8_t mac[ETH_ALEN];
239};
240
241#endif /* _NET_BATMAN_ADV_TYPES_H_ */
diff --git a/drivers/staging/batman-adv/unicast.c b/drivers/staging/batman-adv/unicast.c
deleted file mode 100644
index 0459413ff67f..000000000000
--- a/drivers/staging/batman-adv/unicast.c
+++ /dev/null
@@ -1,269 +0,0 @@
1/*
2 * Copyright (C) 2010 B.A.T.M.A.N. contributors:
3 *
4 * Andreas Langer
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "unicast.h"
24#include "send.h"
25#include "soft-interface.h"
26#include "hash.h"
27#include "translation-table.h"
28#include "routing.h"
29#include "hard-interface.h"
30
31
32struct sk_buff *merge_frag_packet(struct list_head *head,
33 struct frag_packet_list_entry *tfp,
34 struct sk_buff *skb)
35{
36 struct unicast_frag_packet *up =
37 (struct unicast_frag_packet *)skb->data;
38 struct sk_buff *tmp_skb;
39
40 /* set skb to the first part and tmp_skb to the second part */
41 if (up->flags & UNI_FRAG_HEAD) {
42 tmp_skb = tfp->skb;
43 } else {
44 tmp_skb = skb;
45 skb = tfp->skb;
46 }
47
48 skb_pull(tmp_skb, sizeof(struct unicast_frag_packet));
49 if (pskb_expand_head(skb, 0, tmp_skb->len, GFP_ATOMIC) < 0) {
50 /* free buffered skb, skb will be freed later */
51 kfree_skb(tfp->skb);
52 return NULL;
53 }
54
55 /* move free entry to end */
56 tfp->skb = NULL;
57 tfp->seqno = 0;
58 list_move_tail(&tfp->list, head);
59
60 memcpy(skb_put(skb, tmp_skb->len), tmp_skb->data, tmp_skb->len);
61 kfree_skb(tmp_skb);
62 return skb;
63}
64
65void create_frag_entry(struct list_head *head, struct sk_buff *skb)
66{
67 struct frag_packet_list_entry *tfp;
68 struct unicast_frag_packet *up =
69 (struct unicast_frag_packet *)skb->data;
70
71 /* free and oldest packets stand at the end */
72 tfp = list_entry((head)->prev, typeof(*tfp), list);
73 kfree_skb(tfp->skb);
74
75 tfp->seqno = ntohs(up->seqno);
76 tfp->skb = skb;
77 list_move(&tfp->list, head);
78 return;
79}
80
81int create_frag_buffer(struct list_head *head)
82{
83 int i;
84 struct frag_packet_list_entry *tfp;
85
86 for (i = 0; i < FRAG_BUFFER_SIZE; i++) {
87 tfp = kmalloc(sizeof(struct frag_packet_list_entry),
88 GFP_ATOMIC);
89 if (!tfp) {
90 frag_list_free(head);
91 return -ENOMEM;
92 }
93 tfp->skb = NULL;
94 tfp->seqno = 0;
95 INIT_LIST_HEAD(&tfp->list);
96 list_add(&tfp->list, head);
97 }
98
99 return 0;
100}
101
102struct frag_packet_list_entry *search_frag_packet(struct list_head *head,
103 struct unicast_frag_packet *up)
104{
105 struct frag_packet_list_entry *tfp;
106 struct unicast_frag_packet *tmp_up = NULL;
107 uint16_t search_seqno;
108
109 if (up->flags & UNI_FRAG_HEAD)
110 search_seqno = ntohs(up->seqno)+1;
111 else
112 search_seqno = ntohs(up->seqno)-1;
113
114 list_for_each_entry(tfp, head, list) {
115
116 if (!tfp->skb)
117 continue;
118
119 if (tfp->seqno == ntohs(up->seqno))
120 goto mov_tail;
121
122 tmp_up = (struct unicast_frag_packet *)tfp->skb->data;
123
124 if (tfp->seqno == search_seqno) {
125
126 if ((tmp_up->flags & UNI_FRAG_HEAD) !=
127 (up->flags & UNI_FRAG_HEAD))
128 return tfp;
129 else
130 goto mov_tail;
131 }
132 }
133 return NULL;
134
135mov_tail:
136 list_move_tail(&tfp->list, head);
137 return NULL;
138}
139
140void frag_list_free(struct list_head *head)
141{
142 struct frag_packet_list_entry *pf, *tmp_pf;
143
144 if (!list_empty(head)) {
145
146 list_for_each_entry_safe(pf, tmp_pf, head, list) {
147 kfree_skb(pf->skb);
148 list_del(&pf->list);
149 kfree(pf);
150 }
151 }
152 return;
153}
154
155static int unicast_send_frag_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
156 struct batman_if *batman_if, uint8_t dstaddr[],
157 struct orig_node *orig_node)
158{
159 struct unicast_frag_packet *ucast_frag1, *ucast_frag2;
160 int hdr_len = sizeof(struct unicast_frag_packet);
161 struct sk_buff *frag_skb;
162 int data_len = skb->len;
163
164 if (!bat_priv->primary_if)
165 goto dropped;
166
167 frag_skb = dev_alloc_skb(data_len - (data_len / 2) + hdr_len);
168 skb_split(skb, frag_skb, data_len / 2);
169
170 if (my_skb_head_push(frag_skb, hdr_len) < 0 ||
171 my_skb_head_push(skb, hdr_len) < 0)
172 goto drop_frag;
173
174 ucast_frag1 = (struct unicast_frag_packet *)skb->data;
175 ucast_frag2 = (struct unicast_frag_packet *)frag_skb->data;
176
177 ucast_frag1->version = COMPAT_VERSION;
178 ucast_frag1->packet_type = BAT_UNICAST_FRAG;
179 ucast_frag1->ttl = TTL;
180 memcpy(ucast_frag1->orig,
181 bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
182 memcpy(ucast_frag1->dest, orig_node->orig, ETH_ALEN);
183
184 memcpy(ucast_frag2, ucast_frag1, sizeof(struct unicast_frag_packet));
185
186 ucast_frag1->flags |= UNI_FRAG_HEAD;
187 ucast_frag2->flags &= ~UNI_FRAG_HEAD;
188
189 ucast_frag1->seqno = htons((uint16_t)atomic_inc_return(
190 &batman_if->frag_seqno));
191
192 ucast_frag2->seqno = htons((uint16_t)atomic_inc_return(
193 &batman_if->frag_seqno));
194
195 send_skb_packet(skb, batman_if, dstaddr);
196 send_skb_packet(frag_skb, batman_if, dstaddr);
197 return 0;
198
199drop_frag:
200 kfree_skb(frag_skb);
201dropped:
202 kfree_skb(skb);
203 return 1;
204}
205
206int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
207{
208 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
209 struct unicast_packet *unicast_packet;
210 struct orig_node *orig_node;
211 struct batman_if *batman_if;
212 struct neigh_node *router;
213 int data_len = skb->len;
214 uint8_t dstaddr[6];
215 unsigned long flags;
216
217 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
218
219 /* get routing information */
220 orig_node = ((struct orig_node *)hash_find(bat_priv->orig_hash,
221 ethhdr->h_dest));
222
223 /* check for hna host */
224 if (!orig_node)
225 orig_node = transtable_search(bat_priv, ethhdr->h_dest);
226
227 router = find_router(bat_priv, orig_node, NULL);
228
229 if (!router)
230 goto unlock;
231
232 /* don't lock while sending the packets ... we therefore
233 * copy the required data before sending */
234
235 batman_if = router->if_incoming;
236 memcpy(dstaddr, router->addr, ETH_ALEN);
237
238 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
239
240 if (batman_if->if_status != IF_ACTIVE)
241 goto dropped;
242
243 if (atomic_read(&bat_priv->frag_enabled) &&
244 data_len + sizeof(struct unicast_packet) > batman_if->net_dev->mtu)
245 return unicast_send_frag_skb(skb, bat_priv, batman_if,
246 dstaddr, orig_node);
247
248 if (my_skb_head_push(skb, sizeof(struct unicast_packet)) < 0)
249 goto dropped;
250
251 unicast_packet = (struct unicast_packet *)skb->data;
252
253 unicast_packet->version = COMPAT_VERSION;
254 /* batman packet type: unicast */
255 unicast_packet->packet_type = BAT_UNICAST;
256 /* set unicast ttl */
257 unicast_packet->ttl = TTL;
258 /* copy the destination for faster routing */
259 memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN);
260
261 send_skb_packet(skb, batman_if, dstaddr);
262 return 0;
263
264unlock:
265 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
266dropped:
267 kfree_skb(skb);
268 return 1;
269}
diff --git a/drivers/staging/batman-adv/unicast.h b/drivers/staging/batman-adv/unicast.h
deleted file mode 100644
index 797369771900..000000000000
--- a/drivers/staging/batman-adv/unicast.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 * Copyright (C) 2010 B.A.T.M.A.N. contributors:
3 *
4 * Andreas Langer
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_UNICAST_H_
23#define _NET_BATMAN_ADV_UNICAST_H_
24
25#define FRAG_TIMEOUT 10000 /* purge frag list entrys after time in ms */
26#define FRAG_BUFFER_SIZE 6 /* number of list elements in buffer */
27
28struct sk_buff *merge_frag_packet(struct list_head *head,
29 struct frag_packet_list_entry *tfp,
30 struct sk_buff *skb);
31
32void create_frag_entry(struct list_head *head, struct sk_buff *skb);
33int create_frag_buffer(struct list_head *head);
34struct frag_packet_list_entry *search_frag_packet(struct list_head *head,
35 struct unicast_frag_packet *up);
36void frag_list_free(struct list_head *head);
37int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv);
38
39#endif /* _NET_BATMAN_ADV_UNICAST_H_ */
diff --git a/drivers/staging/batman-adv/vis.c b/drivers/staging/batman-adv/vis.c
deleted file mode 100644
index 3d2c1bccf2e6..000000000000
--- a/drivers/staging/batman-adv/vis.c
+++ /dev/null
@@ -1,895 +0,0 @@
1/*
2 * Copyright (C) 2008-2010 B.A.T.M.A.N. contributors:
3 *
4 * Simon Wunderlich
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "send.h"
24#include "translation-table.h"
25#include "vis.h"
26#include "soft-interface.h"
27#include "hard-interface.h"
28#include "hash.h"
29
30#define MAX_VIS_PACKET_SIZE 1000
31
32/* Returns the smallest signed integer in two's complement with the sizeof x */
33#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
34
35/* Checks if a sequence number x is a predecessor/successor of y.
36 * they handle overflows/underflows and can correctly check for a
37 * predecessor/successor unless the variable sequence number has grown by
38 * more then 2**(bitwidth(x)-1)-1.
39 * This means that for a uint8_t with the maximum value 255, it would think:
40 * - when adding nothing - it is neither a predecessor nor a successor
41 * - before adding more than 127 to the starting value - it is a predecessor,
42 * - when adding 128 - it is neither a predecessor nor a successor,
43 * - after adding more than 127 to the starting value - it is a successor */
44#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \
45 _dummy > smallest_signed_int(_dummy); })
46#define seq_after(x, y) seq_before(y, x)
47
48static void start_vis_timer(struct bat_priv *bat_priv);
49
50/* free the info */
51static void free_info(struct kref *ref)
52{
53 struct vis_info *info = container_of(ref, struct vis_info, refcount);
54 struct bat_priv *bat_priv = info->bat_priv;
55 struct recvlist_node *entry, *tmp;
56 unsigned long flags;
57
58 list_del_init(&info->send_list);
59 spin_lock_irqsave(&bat_priv->vis_list_lock, flags);
60 list_for_each_entry_safe(entry, tmp, &info->recv_list, list) {
61 list_del(&entry->list);
62 kfree(entry);
63 }
64
65 spin_unlock_irqrestore(&bat_priv->vis_list_lock, flags);
66 kfree_skb(info->skb_packet);
67}
68
69/* Compare two vis packets, used by the hashing algorithm */
70static int vis_info_cmp(void *data1, void *data2)
71{
72 struct vis_info *d1, *d2;
73 struct vis_packet *p1, *p2;
74 d1 = data1;
75 d2 = data2;
76 p1 = (struct vis_packet *)d1->skb_packet->data;
77 p2 = (struct vis_packet *)d2->skb_packet->data;
78 return compare_orig(p1->vis_orig, p2->vis_orig);
79}
80
81/* hash function to choose an entry in a hash table of given size */
82/* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */
83static int vis_info_choose(void *data, int size)
84{
85 struct vis_info *vis_info = data;
86 struct vis_packet *packet;
87 unsigned char *key;
88 uint32_t hash = 0;
89 size_t i;
90
91 packet = (struct vis_packet *)vis_info->skb_packet->data;
92 key = packet->vis_orig;
93 for (i = 0; i < ETH_ALEN; i++) {
94 hash += key[i];
95 hash += (hash << 10);
96 hash ^= (hash >> 6);
97 }
98
99 hash += (hash << 3);
100 hash ^= (hash >> 11);
101 hash += (hash << 15);
102
103 return hash % size;
104}
105
106/* insert interface to the list of interfaces of one originator, if it
107 * does not already exist in the list */
108static void vis_data_insert_interface(const uint8_t *interface,
109 struct hlist_head *if_list,
110 bool primary)
111{
112 struct if_list_entry *entry;
113 struct hlist_node *pos;
114
115 hlist_for_each_entry(entry, pos, if_list, list) {
116 if (compare_orig(entry->addr, (void *)interface))
117 return;
118 }
119
120 /* its a new address, add it to the list */
121 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
122 if (!entry)
123 return;
124 memcpy(entry->addr, interface, ETH_ALEN);
125 entry->primary = primary;
126 hlist_add_head(&entry->list, if_list);
127}
128
129static ssize_t vis_data_read_prim_sec(char *buff, struct hlist_head *if_list)
130{
131 struct if_list_entry *entry;
132 struct hlist_node *pos;
133 size_t len = 0;
134
135 hlist_for_each_entry(entry, pos, if_list, list) {
136 if (entry->primary)
137 len += sprintf(buff + len, "PRIMARY, ");
138 else {
139 len += sprintf(buff + len, "SEC %pM, ", entry->addr);
140 }
141 }
142
143 return len;
144}
145
146static size_t vis_data_count_prim_sec(struct hlist_head *if_list)
147{
148 struct if_list_entry *entry;
149 struct hlist_node *pos;
150 size_t count = 0;
151
152 hlist_for_each_entry(entry, pos, if_list, list) {
153 if (entry->primary)
154 count += 9;
155 else
156 count += 23;
157 }
158
159 return count;
160}
161
162/* read an entry */
163static ssize_t vis_data_read_entry(char *buff, struct vis_info_entry *entry,
164 uint8_t *src, bool primary)
165{
166 /* maximal length: max(4+17+2, 3+17+1+3+2) == 26 */
167 if (primary && entry->quality == 0)
168 return sprintf(buff, "HNA %pM, ", entry->dest);
169 else if (compare_orig(entry->src, src))
170 return sprintf(buff, "TQ %pM %d, ", entry->dest,
171 entry->quality);
172
173 return 0;
174}
175
176int vis_seq_print_text(struct seq_file *seq, void *offset)
177{
178 HASHIT(hashit);
179 HASHIT(hashit_count);
180 struct vis_info *info;
181 struct vis_packet *packet;
182 struct vis_info_entry *entries;
183 struct net_device *net_dev = (struct net_device *)seq->private;
184 struct bat_priv *bat_priv = netdev_priv(net_dev);
185 HLIST_HEAD(vis_if_list);
186 struct if_list_entry *entry;
187 struct hlist_node *pos, *n;
188 int i;
189 unsigned long flags;
190 int vis_server = atomic_read(&bat_priv->vis_mode);
191 size_t buff_pos, buf_size;
192 char *buff;
193
194 if ((!bat_priv->primary_if) ||
195 (vis_server == VIS_TYPE_CLIENT_UPDATE))
196 return 0;
197
198 buf_size = 1;
199 /* Estimate length */
200 spin_lock_irqsave(&bat_priv->vis_hash_lock, flags);
201 while (hash_iterate(bat_priv->vis_hash, &hashit_count)) {
202 info = hashit_count.bucket->data;
203 packet = (struct vis_packet *)info->skb_packet->data;
204 entries = (struct vis_info_entry *)
205 ((char *)packet + sizeof(struct vis_packet));
206
207 for (i = 0; i < packet->entries; i++) {
208 if (entries[i].quality == 0)
209 continue;
210 vis_data_insert_interface(entries[i].src, &vis_if_list,
211 compare_orig(entries[i].src, packet->vis_orig));
212 }
213
214 hlist_for_each_entry(entry, pos, &vis_if_list, list) {
215 buf_size += 18 + 26 * packet->entries;
216
217 /* add primary/secondary records */
218 if (compare_orig(entry->addr, packet->vis_orig))
219 buf_size +=
220 vis_data_count_prim_sec(&vis_if_list);
221
222 buf_size += 1;
223 }
224
225 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list, list) {
226 hlist_del(&entry->list);
227 kfree(entry);
228 }
229 }
230
231 buff = kmalloc(buf_size, GFP_ATOMIC);
232 if (!buff) {
233 spin_unlock_irqrestore(&bat_priv->vis_hash_lock, flags);
234 return -ENOMEM;
235 }
236 buff[0] = '\0';
237 buff_pos = 0;
238
239 while (hash_iterate(bat_priv->vis_hash, &hashit)) {
240 info = hashit.bucket->data;
241 packet = (struct vis_packet *)info->skb_packet->data;
242 entries = (struct vis_info_entry *)
243 ((char *)packet + sizeof(struct vis_packet));
244
245 for (i = 0; i < packet->entries; i++) {
246 if (entries[i].quality == 0)
247 continue;
248 vis_data_insert_interface(entries[i].src, &vis_if_list,
249 compare_orig(entries[i].src, packet->vis_orig));
250 }
251
252 hlist_for_each_entry(entry, pos, &vis_if_list, list) {
253 buff_pos += sprintf(buff + buff_pos, "%pM,",
254 entry->addr);
255
256 for (i = 0; i < packet->entries; i++)
257 buff_pos += vis_data_read_entry(buff + buff_pos,
258 &entries[i],
259 entry->addr,
260 entry->primary);
261
262 /* add primary/secondary records */
263 if (compare_orig(entry->addr, packet->vis_orig))
264 buff_pos +=
265 vis_data_read_prim_sec(buff + buff_pos,
266 &vis_if_list);
267
268 buff_pos += sprintf(buff + buff_pos, "\n");
269 }
270
271 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list, list) {
272 hlist_del(&entry->list);
273 kfree(entry);
274 }
275 }
276
277 spin_unlock_irqrestore(&bat_priv->vis_hash_lock, flags);
278
279 seq_printf(seq, "%s", buff);
280 kfree(buff);
281
282 return 0;
283}
284
285/* add the info packet to the send list, if it was not
286 * already linked in. */
287static void send_list_add(struct bat_priv *bat_priv, struct vis_info *info)
288{
289 if (list_empty(&info->send_list)) {
290 kref_get(&info->refcount);
291 list_add_tail(&info->send_list, &bat_priv->vis_send_list);
292 }
293}
294
295/* delete the info packet from the send list, if it was
296 * linked in. */
297static void send_list_del(struct vis_info *info)
298{
299 if (!list_empty(&info->send_list)) {
300 list_del_init(&info->send_list);
301 kref_put(&info->refcount, free_info);
302 }
303}
304
305/* tries to add one entry to the receive list. */
306static void recv_list_add(struct bat_priv *bat_priv,
307 struct list_head *recv_list, char *mac)
308{
309 struct recvlist_node *entry;
310 unsigned long flags;
311
312 entry = kmalloc(sizeof(struct recvlist_node), GFP_ATOMIC);
313 if (!entry)
314 return;
315
316 memcpy(entry->mac, mac, ETH_ALEN);
317 spin_lock_irqsave(&bat_priv->vis_list_lock, flags);
318 list_add_tail(&entry->list, recv_list);
319 spin_unlock_irqrestore(&bat_priv->vis_list_lock, flags);
320}
321
322/* returns 1 if this mac is in the recv_list */
323static int recv_list_is_in(struct bat_priv *bat_priv,
324 struct list_head *recv_list, char *mac)
325{
326 struct recvlist_node *entry;
327 unsigned long flags;
328
329 spin_lock_irqsave(&bat_priv->vis_list_lock, flags);
330 list_for_each_entry(entry, recv_list, list) {
331 if (memcmp(entry->mac, mac, ETH_ALEN) == 0) {
332 spin_unlock_irqrestore(&bat_priv->vis_list_lock,
333 flags);
334 return 1;
335 }
336 }
337 spin_unlock_irqrestore(&bat_priv->vis_list_lock, flags);
338 return 0;
339}
340
341/* try to add the packet to the vis_hash. return NULL if invalid (e.g. too old,
342 * broken.. ). vis hash must be locked outside. is_new is set when the packet
343 * is newer than old entries in the hash. */
344static struct vis_info *add_packet(struct bat_priv *bat_priv,
345 struct vis_packet *vis_packet,
346 int vis_info_len, int *is_new,
347 int make_broadcast)
348{
349 struct vis_info *info, *old_info;
350 struct vis_packet *search_packet, *old_packet;
351 struct vis_info search_elem;
352 struct vis_packet *packet;
353
354 *is_new = 0;
355 /* sanity check */
356 if (!bat_priv->vis_hash)
357 return NULL;
358
359 /* see if the packet is already in vis_hash */
360 search_elem.skb_packet = dev_alloc_skb(sizeof(struct vis_packet));
361 if (!search_elem.skb_packet)
362 return NULL;
363 search_packet = (struct vis_packet *)skb_put(search_elem.skb_packet,
364 sizeof(struct vis_packet));
365
366 memcpy(search_packet->vis_orig, vis_packet->vis_orig, ETH_ALEN);
367 old_info = hash_find(bat_priv->vis_hash, &search_elem);
368 kfree_skb(search_elem.skb_packet);
369
370 if (old_info != NULL) {
371 old_packet = (struct vis_packet *)old_info->skb_packet->data;
372 if (!seq_after(ntohl(vis_packet->seqno),
373 ntohl(old_packet->seqno))) {
374 if (old_packet->seqno == vis_packet->seqno) {
375 recv_list_add(bat_priv, &old_info->recv_list,
376 vis_packet->sender_orig);
377 return old_info;
378 } else {
379 /* newer packet is already in hash. */
380 return NULL;
381 }
382 }
383 /* remove old entry */
384 hash_remove(bat_priv->vis_hash, old_info);
385 send_list_del(old_info);
386 kref_put(&old_info->refcount, free_info);
387 }
388
389 info = kmalloc(sizeof(struct vis_info), GFP_ATOMIC);
390 if (!info)
391 return NULL;
392
393 info->skb_packet = dev_alloc_skb(sizeof(struct vis_packet) +
394 vis_info_len + sizeof(struct ethhdr));
395 if (!info->skb_packet) {
396 kfree(info);
397 return NULL;
398 }
399 skb_reserve(info->skb_packet, sizeof(struct ethhdr));
400 packet = (struct vis_packet *)skb_put(info->skb_packet,
401 sizeof(struct vis_packet) +
402 vis_info_len);
403
404 kref_init(&info->refcount);
405 INIT_LIST_HEAD(&info->send_list);
406 INIT_LIST_HEAD(&info->recv_list);
407 info->first_seen = jiffies;
408 info->bat_priv = bat_priv;
409 memcpy(packet, vis_packet, sizeof(struct vis_packet) + vis_info_len);
410
411 /* initialize and add new packet. */
412 *is_new = 1;
413
414 /* Make it a broadcast packet, if required */
415 if (make_broadcast)
416 memcpy(packet->target_orig, broadcast_addr, ETH_ALEN);
417
418 /* repair if entries is longer than packet. */
419 if (packet->entries * sizeof(struct vis_info_entry) > vis_info_len)
420 packet->entries = vis_info_len / sizeof(struct vis_info_entry);
421
422 recv_list_add(bat_priv, &info->recv_list, packet->sender_orig);
423
424 /* try to add it */
425 if (hash_add(bat_priv->vis_hash, info) < 0) {
426 /* did not work (for some reason) */
427 kref_put(&old_info->refcount, free_info);
428 info = NULL;
429 }
430
431 return info;
432}
433
434/* handle the server sync packet, forward if needed. */
435void receive_server_sync_packet(struct bat_priv *bat_priv,
436 struct vis_packet *vis_packet,
437 int vis_info_len)
438{
439 struct vis_info *info;
440 int is_new, make_broadcast;
441 unsigned long flags;
442 int vis_server = atomic_read(&bat_priv->vis_mode);
443
444 make_broadcast = (vis_server == VIS_TYPE_SERVER_SYNC);
445
446 spin_lock_irqsave(&bat_priv->vis_hash_lock, flags);
447 info = add_packet(bat_priv, vis_packet, vis_info_len,
448 &is_new, make_broadcast);
449 if (!info)
450 goto end;
451
452 /* only if we are server ourselves and packet is newer than the one in
453 * hash.*/
454 if (vis_server == VIS_TYPE_SERVER_SYNC && is_new)
455 send_list_add(bat_priv, info);
456end:
457 spin_unlock_irqrestore(&bat_priv->vis_hash_lock, flags);
458}
459
460/* handle an incoming client update packet and schedule forward if needed. */
461void receive_client_update_packet(struct bat_priv *bat_priv,
462 struct vis_packet *vis_packet,
463 int vis_info_len)
464{
465 struct vis_info *info;
466 struct vis_packet *packet;
467 int is_new;
468 unsigned long flags;
469 int vis_server = atomic_read(&bat_priv->vis_mode);
470 int are_target = 0;
471
472 /* clients shall not broadcast. */
473 if (is_bcast(vis_packet->target_orig))
474 return;
475
476 /* Are we the target for this VIS packet? */
477 if (vis_server == VIS_TYPE_SERVER_SYNC &&
478 is_my_mac(vis_packet->target_orig))
479 are_target = 1;
480
481 spin_lock_irqsave(&bat_priv->vis_hash_lock, flags);
482 info = add_packet(bat_priv, vis_packet, vis_info_len,
483 &is_new, are_target);
484
485 if (!info)
486 goto end;
487 /* note that outdated packets will be dropped at this point. */
488
489 packet = (struct vis_packet *)info->skb_packet->data;
490
491 /* send only if we're the target server or ... */
492 if (are_target && is_new) {
493 packet->vis_type = VIS_TYPE_SERVER_SYNC; /* upgrade! */
494 send_list_add(bat_priv, info);
495
496 /* ... we're not the recipient (and thus need to forward). */
497 } else if (!is_my_mac(packet->target_orig)) {
498 send_list_add(bat_priv, info);
499 }
500
501end:
502 spin_unlock_irqrestore(&bat_priv->vis_hash_lock, flags);
503}
504
505/* Walk the originators and find the VIS server with the best tq. Set the packet
506 * address to its address and return the best_tq.
507 *
508 * Must be called with the originator hash locked */
509static int find_best_vis_server(struct bat_priv *bat_priv,
510 struct vis_info *info)
511{
512 HASHIT(hashit);
513 struct orig_node *orig_node;
514 struct vis_packet *packet;
515 int best_tq = -1;
516
517 packet = (struct vis_packet *)info->skb_packet->data;
518
519 while (hash_iterate(bat_priv->orig_hash, &hashit)) {
520 orig_node = hashit.bucket->data;
521 if ((orig_node) && (orig_node->router) &&
522 (orig_node->flags & VIS_SERVER) &&
523 (orig_node->router->tq_avg > best_tq)) {
524 best_tq = orig_node->router->tq_avg;
525 memcpy(packet->target_orig, orig_node->orig, ETH_ALEN);
526 }
527 }
528 return best_tq;
529}
530
531/* Return true if the vis packet is full. */
532static bool vis_packet_full(struct vis_info *info)
533{
534 struct vis_packet *packet;
535 packet = (struct vis_packet *)info->skb_packet->data;
536
537 if (MAX_VIS_PACKET_SIZE / sizeof(struct vis_info_entry)
538 < packet->entries + 1)
539 return true;
540 return false;
541}
542
543/* generates a packet of own vis data,
544 * returns 0 on success, -1 if no packet could be generated */
545static int generate_vis_packet(struct bat_priv *bat_priv)
546{
547 HASHIT(hashit_local);
548 HASHIT(hashit_global);
549 struct orig_node *orig_node;
550 struct vis_info *info = (struct vis_info *)bat_priv->my_vis_info;
551 struct vis_packet *packet = (struct vis_packet *)info->skb_packet->data;
552 struct vis_info_entry *entry;
553 struct hna_local_entry *hna_local_entry;
554 int best_tq = -1;
555 unsigned long flags;
556
557 info->first_seen = jiffies;
558 packet->vis_type = atomic_read(&bat_priv->vis_mode);
559
560 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
561 memcpy(packet->target_orig, broadcast_addr, ETH_ALEN);
562 packet->ttl = TTL;
563 packet->seqno = htonl(ntohl(packet->seqno) + 1);
564 packet->entries = 0;
565 skb_trim(info->skb_packet, sizeof(struct vis_packet));
566
567 if (packet->vis_type == VIS_TYPE_CLIENT_UPDATE) {
568 best_tq = find_best_vis_server(bat_priv, info);
569
570 if (best_tq < 0) {
571 spin_unlock_irqrestore(&bat_priv->orig_hash_lock,
572 flags);
573 return -1;
574 }
575 }
576
577 while (hash_iterate(bat_priv->orig_hash, &hashit_global)) {
578 orig_node = hashit_global.bucket->data;
579
580 if (!orig_node->router)
581 continue;
582
583 if (!compare_orig(orig_node->router->addr, orig_node->orig))
584 continue;
585
586 if (orig_node->router->if_incoming->if_status != IF_ACTIVE)
587 continue;
588
589 if (orig_node->router->tq_avg < 1)
590 continue;
591
592 /* fill one entry into buffer. */
593 entry = (struct vis_info_entry *)
594 skb_put(info->skb_packet, sizeof(*entry));
595 memcpy(entry->src,
596 orig_node->router->if_incoming->net_dev->dev_addr,
597 ETH_ALEN);
598 memcpy(entry->dest, orig_node->orig, ETH_ALEN);
599 entry->quality = orig_node->router->tq_avg;
600 packet->entries++;
601
602 if (vis_packet_full(info)) {
603 spin_unlock_irqrestore(
604 &bat_priv->orig_hash_lock, flags);
605 return 0;
606 }
607 }
608
609 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
610
611 spin_lock_irqsave(&bat_priv->hna_lhash_lock, flags);
612 while (hash_iterate(bat_priv->hna_local_hash, &hashit_local)) {
613 hna_local_entry = hashit_local.bucket->data;
614 entry = (struct vis_info_entry *)skb_put(info->skb_packet,
615 sizeof(*entry));
616 memset(entry->src, 0, ETH_ALEN);
617 memcpy(entry->dest, hna_local_entry->addr, ETH_ALEN);
618 entry->quality = 0; /* 0 means HNA */
619 packet->entries++;
620
621 if (vis_packet_full(info)) {
622 spin_unlock_irqrestore(&bat_priv->hna_lhash_lock,
623 flags);
624 return 0;
625 }
626 }
627
628 spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags);
629 return 0;
630}
631
632/* free old vis packets. Must be called with this vis_hash_lock
633 * held */
634static void purge_vis_packets(struct bat_priv *bat_priv)
635{
636 HASHIT(hashit);
637 struct vis_info *info;
638
639 while (hash_iterate(bat_priv->vis_hash, &hashit)) {
640 info = hashit.bucket->data;
641
642 /* never purge own data. */
643 if (info == bat_priv->my_vis_info)
644 continue;
645
646 if (time_after(jiffies,
647 info->first_seen + VIS_TIMEOUT * HZ)) {
648 hash_remove_bucket(bat_priv->vis_hash, &hashit);
649 send_list_del(info);
650 kref_put(&info->refcount, free_info);
651 }
652 }
653}
654
655static void broadcast_vis_packet(struct bat_priv *bat_priv,
656 struct vis_info *info)
657{
658 HASHIT(hashit);
659 struct orig_node *orig_node;
660 struct vis_packet *packet;
661 struct sk_buff *skb;
662 unsigned long flags;
663 struct batman_if *batman_if;
664 uint8_t dstaddr[ETH_ALEN];
665
666
667 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
668 packet = (struct vis_packet *)info->skb_packet->data;
669
670 /* send to all routers in range. */
671 while (hash_iterate(bat_priv->orig_hash, &hashit)) {
672 orig_node = hashit.bucket->data;
673
674 /* if it's a vis server and reachable, send it. */
675 if ((!orig_node) || (!orig_node->router))
676 continue;
677 if (!(orig_node->flags & VIS_SERVER))
678 continue;
679 /* don't send it if we already received the packet from
680 * this node. */
681 if (recv_list_is_in(bat_priv, &info->recv_list,
682 orig_node->orig))
683 continue;
684
685 memcpy(packet->target_orig, orig_node->orig, ETH_ALEN);
686 batman_if = orig_node->router->if_incoming;
687 memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
688 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
689
690 skb = skb_clone(info->skb_packet, GFP_ATOMIC);
691 if (skb)
692 send_skb_packet(skb, batman_if, dstaddr);
693
694 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
695
696 }
697
698 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
699}
700
701static void unicast_vis_packet(struct bat_priv *bat_priv,
702 struct vis_info *info)
703{
704 struct orig_node *orig_node;
705 struct sk_buff *skb;
706 struct vis_packet *packet;
707 unsigned long flags;
708 struct batman_if *batman_if;
709 uint8_t dstaddr[ETH_ALEN];
710
711 spin_lock_irqsave(&bat_priv->orig_hash_lock, flags);
712 packet = (struct vis_packet *)info->skb_packet->data;
713 orig_node = ((struct orig_node *)hash_find(bat_priv->orig_hash,
714 packet->target_orig));
715
716 if ((!orig_node) || (!orig_node->router))
717 goto out;
718
719 /* don't lock while sending the packets ... we therefore
720 * copy the required data before sending */
721 batman_if = orig_node->router->if_incoming;
722 memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
723 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
724
725 skb = skb_clone(info->skb_packet, GFP_ATOMIC);
726 if (skb)
727 send_skb_packet(skb, batman_if, dstaddr);
728
729 return;
730
731out:
732 spin_unlock_irqrestore(&bat_priv->orig_hash_lock, flags);
733}
734
735/* only send one vis packet. called from send_vis_packets() */
736static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info)
737{
738 struct vis_packet *packet;
739
740 packet = (struct vis_packet *)info->skb_packet->data;
741 if (packet->ttl < 2) {
742 pr_debug("Error - can't send vis packet: ttl exceeded\n");
743 return;
744 }
745
746 memcpy(packet->sender_orig, bat_priv->primary_if->net_dev->dev_addr,
747 ETH_ALEN);
748 packet->ttl--;
749
750 if (is_bcast(packet->target_orig))
751 broadcast_vis_packet(bat_priv, info);
752 else
753 unicast_vis_packet(bat_priv, info);
754 packet->ttl++; /* restore TTL */
755}
756
757/* called from timer; send (and maybe generate) vis packet. */
758static void send_vis_packets(struct work_struct *work)
759{
760 struct delayed_work *delayed_work =
761 container_of(work, struct delayed_work, work);
762 struct bat_priv *bat_priv =
763 container_of(delayed_work, struct bat_priv, vis_work);
764 struct vis_info *info, *temp;
765 unsigned long flags;
766
767 spin_lock_irqsave(&bat_priv->vis_hash_lock, flags);
768 purge_vis_packets(bat_priv);
769
770 if (generate_vis_packet(bat_priv) == 0) {
771 /* schedule if generation was successful */
772 send_list_add(bat_priv, bat_priv->my_vis_info);
773 }
774
775 list_for_each_entry_safe(info, temp, &bat_priv->vis_send_list,
776 send_list) {
777
778 kref_get(&info->refcount);
779 spin_unlock_irqrestore(&bat_priv->vis_hash_lock, flags);
780
781 if (bat_priv->primary_if)
782 send_vis_packet(bat_priv, info);
783
784 spin_lock_irqsave(&bat_priv->vis_hash_lock, flags);
785 send_list_del(info);
786 kref_put(&info->refcount, free_info);
787 }
788 spin_unlock_irqrestore(&bat_priv->vis_hash_lock, flags);
789 start_vis_timer(bat_priv);
790}
791
792/* init the vis server. this may only be called when if_list is already
793 * initialized (e.g. bat0 is initialized, interfaces have been added) */
794int vis_init(struct bat_priv *bat_priv)
795{
796 struct vis_packet *packet;
797 unsigned long flags;
798
799 if (bat_priv->vis_hash)
800 return 1;
801
802 spin_lock_irqsave(&bat_priv->vis_hash_lock, flags);
803
804 bat_priv->vis_hash = hash_new(256, vis_info_cmp, vis_info_choose);
805 if (!bat_priv->vis_hash) {
806 pr_err("Can't initialize vis_hash\n");
807 goto err;
808 }
809
810 bat_priv->my_vis_info = kmalloc(MAX_VIS_PACKET_SIZE, GFP_ATOMIC);
811 if (!bat_priv->my_vis_info) {
812 pr_err("Can't initialize vis packet\n");
813 goto err;
814 }
815
816 bat_priv->my_vis_info->skb_packet = dev_alloc_skb(
817 sizeof(struct vis_packet) +
818 MAX_VIS_PACKET_SIZE +
819 sizeof(struct ethhdr));
820 if (!bat_priv->my_vis_info->skb_packet)
821 goto free_info;
822
823 skb_reserve(bat_priv->my_vis_info->skb_packet, sizeof(struct ethhdr));
824 packet = (struct vis_packet *)skb_put(
825 bat_priv->my_vis_info->skb_packet,
826 sizeof(struct vis_packet));
827
828 /* prefill the vis info */
829 bat_priv->my_vis_info->first_seen = jiffies -
830 msecs_to_jiffies(VIS_INTERVAL);
831 INIT_LIST_HEAD(&bat_priv->my_vis_info->recv_list);
832 INIT_LIST_HEAD(&bat_priv->my_vis_info->send_list);
833 kref_init(&bat_priv->my_vis_info->refcount);
834 bat_priv->my_vis_info->bat_priv = bat_priv;
835 packet->version = COMPAT_VERSION;
836 packet->packet_type = BAT_VIS;
837 packet->ttl = TTL;
838 packet->seqno = 0;
839 packet->entries = 0;
840
841 INIT_LIST_HEAD(&bat_priv->vis_send_list);
842
843 if (hash_add(bat_priv->vis_hash, bat_priv->my_vis_info) < 0) {
844 pr_err("Can't add own vis packet into hash\n");
845 /* not in hash, need to remove it manually. */
846 kref_put(&bat_priv->my_vis_info->refcount, free_info);
847 goto err;
848 }
849
850 spin_unlock_irqrestore(&bat_priv->vis_hash_lock, flags);
851 start_vis_timer(bat_priv);
852 return 1;
853
854free_info:
855 kfree(bat_priv->my_vis_info);
856 bat_priv->my_vis_info = NULL;
857err:
858 spin_unlock_irqrestore(&bat_priv->vis_hash_lock, flags);
859 vis_quit(bat_priv);
860 return 0;
861}
862
863/* Decrease the reference count on a hash item info */
864static void free_info_ref(void *data, void *arg)
865{
866 struct vis_info *info = data;
867
868 send_list_del(info);
869 kref_put(&info->refcount, free_info);
870}
871
872/* shutdown vis-server */
873void vis_quit(struct bat_priv *bat_priv)
874{
875 unsigned long flags;
876 if (!bat_priv->vis_hash)
877 return;
878
879 cancel_delayed_work_sync(&bat_priv->vis_work);
880
881 spin_lock_irqsave(&bat_priv->vis_hash_lock, flags);
882 /* properly remove, kill timers ... */
883 hash_delete(bat_priv->vis_hash, free_info_ref, NULL);
884 bat_priv->vis_hash = NULL;
885 bat_priv->my_vis_info = NULL;
886 spin_unlock_irqrestore(&bat_priv->vis_hash_lock, flags);
887}
888
889/* schedule packets for (re)transmission */
890static void start_vis_timer(struct bat_priv *bat_priv)
891{
892 INIT_DELAYED_WORK(&bat_priv->vis_work, send_vis_packets);
893 queue_delayed_work(bat_event_workqueue, &bat_priv->vis_work,
894 msecs_to_jiffies(VIS_INTERVAL));
895}
diff --git a/drivers/staging/batman-adv/vis.h b/drivers/staging/batman-adv/vis.h
deleted file mode 100644
index 2c3b33089a9b..000000000000
--- a/drivers/staging/batman-adv/vis.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 * Copyright (C) 2008-2010 B.A.T.M.A.N. contributors:
3 *
4 * Simon Wunderlich, Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#ifndef _NET_BATMAN_ADV_VIS_H_
23#define _NET_BATMAN_ADV_VIS_H_
24
25#define VIS_TIMEOUT 200 /* timeout of vis packets in seconds */
26
27int vis_seq_print_text(struct seq_file *seq, void *offset);
28void receive_server_sync_packet(struct bat_priv *bat_priv,
29 struct vis_packet *vis_packet,
30 int vis_info_len);
31void receive_client_update_packet(struct bat_priv *bat_priv,
32 struct vis_packet *vis_packet,
33 int vis_info_len);
34int vis_init(struct bat_priv *bat_priv);
35void vis_quit(struct bat_priv *bat_priv);
36
37#endif /* _NET_BATMAN_ADV_VIS_H_ */
diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h
index 748460e898d8..32909e2938d5 100644
--- a/drivers/staging/bcm/Adapter.h
+++ b/drivers/staging/bcm/Adapter.h
@@ -7,53 +7,6 @@
7#define MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES 256 7#define MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES 256
8#include "Debug.h" 8#include "Debug.h"
9 9
10typedef struct _LIST_ENTRY{
11 struct _LIST_ENTRY *next;
12 struct _LIST_ENTRY *prev;
13} LIST_ENTRY, *PLIST_ENTRY;
14
15typedef struct _BCM_LIST_ENTRY {
16
17 LIST_ENTRY Link;
18
19} BCM_LIST_ENTRY, *PBCM_LIST_ENTRY;
20
21typedef enum _RCB_STATUS
22{
23 DRIVER_PROCESSED=1,
24 APPLICATION_PROCESSED
25} RCB_STATUS, *PRCB_STATUS;
26
27#define fFILLED 1
28#define fEMPTY 0
29
30struct _BCM_CB
31{
32 // The network packet that this RCB is receiving
33 PVOID pv_packet;
34 // Describes the length of the packet .
35 UINT ui_packet_length;
36 // Pointer to the first buffer in the packet (only one buffer for Rx)
37 PUCHAR buffer;
38 atomic_t status;
39 UINT filled;
40} __attribute__((packed));
41typedef struct _BCM_CB BCM_CB,*PBCM_CB;
42
43typedef BCM_CB BCM_RCB, *PBCM_RCB;
44typedef BCM_CB BCM_TCB, *PBCM_TCB;
45
46/* This is to be stored in the "pvOsDepData" of ADAPTER */
47typedef struct LINUX_DEP_DATA
48{
49 struct net_device *virtualdev; /* Our Interface (veth0) */
50 struct net_device *actualdev; /* True Interface (eth0) */
51 struct net_device_stats netstats; /* Net statistics */
52 struct fasync_struct *async_queue; /* For asynchronus notification */
53
54} LINUX_DEP_DATA, *PLINUX_DEP_DATA;
55
56
57struct _LEADER 10struct _LEADER
58{ 11{
59 USHORT Vcid; 12 USHORT Vcid;
@@ -429,26 +382,28 @@ Driver adapter data structure
429struct _MINI_ADAPTER 382struct _MINI_ADAPTER
430{ 383{
431 struct _MINI_ADAPTER *next; 384 struct _MINI_ADAPTER *next;
432 PVOID pvOsDepData; 385 struct net_device *dev;
386 u32 msg_enable;
387
433 CHAR *caDsxReqResp; 388 CHAR *caDsxReqResp;
434 atomic_t ApplicationRunning; 389 atomic_t ApplicationRunning;
435 volatile INT CtrlQueueLen; 390 volatile INT CtrlQueueLen;
436 atomic_t AppCtrlQueueLen; 391 atomic_t AppCtrlQueueLen;
437 BOOLEAN AppCtrlQueueOverFlow; 392 BOOLEAN AppCtrlQueueOverFlow;
438 atomic_t CurrentApplicationCount; 393 atomic_t CurrentApplicationCount;
439 atomic_t RegisteredApplicationCount; 394 atomic_t RegisteredApplicationCount;
440 BOOLEAN TimerActive; 395 BOOLEAN LinkUpStatus;
441 ULONG StatisticsPointer; 396 BOOLEAN TimerActive;
397 u32 StatisticsPointer;
442 struct sk_buff *RxControlHead; 398 struct sk_buff *RxControlHead;
443 struct sk_buff *RxControlTail; 399 struct sk_buff *RxControlTail;
444// spinlock_t RxControlQueuelock; 400
445 struct semaphore RxAppControlQueuelock; 401 struct semaphore RxAppControlQueuelock;
446 struct semaphore fw_download_sema; 402 struct semaphore fw_download_sema;
447 403
448 PPER_TARANG_DATA pTarangs; 404 PPER_TARANG_DATA pTarangs;
449 spinlock_t control_queue_lock; 405 spinlock_t control_queue_lock;
450 wait_queue_head_t process_read_wait_queue; 406 wait_queue_head_t process_read_wait_queue;
451 ULONG bcm_jiffies; /* Store Jiffies value */
452 407
453 // the pointer to the first packet we have queued in send 408 // the pointer to the first packet we have queued in send
454 // deserialized miniport support variables 409 // deserialized miniport support variables
@@ -458,24 +413,15 @@ struct _MINI_ADAPTER
458 // this to keep track of the Tx and Rx MailBox Registers. 413 // this to keep track of the Tx and Rx MailBox Registers.
459 atomic_t CurrNumFreeTxDesc; 414 atomic_t CurrNumFreeTxDesc;
460 // to keep track the no of byte recieved 415 // to keep track the no of byte recieved
461 atomic_t RxRollOverCount;
462 USHORT PrevNumRecvDescs; 416 USHORT PrevNumRecvDescs;
463 USHORT CurrNumRecvDescs; 417 USHORT CurrNumRecvDescs;
464 atomic_t GoodRxByteCount;
465 atomic_t GoodRxPktCount;
466 atomic_t BadRxByteCount;
467 atomic_t RxPacketDroppedCount;
468 atomic_t GoodTxByteCount;
469 atomic_t TxTotalPacketCount;
470 atomic_t TxDroppedPacketCount;
471 ULONG LinkUpStatus;
472 BOOLEAN TransferMode;
473 UINT u32TotalDSD; 418 UINT u32TotalDSD;
474 PacketInfo PackInfo[NO_OF_QUEUES]; 419 PacketInfo PackInfo[NO_OF_QUEUES];
475 S_CLASSIFIER_RULE astClassifierTable[MAX_CLASSIFIERS]; 420 S_CLASSIFIER_RULE astClassifierTable[MAX_CLASSIFIERS];
421 BOOLEAN TransferMode;
476 422
477 /*************** qos ******************/ 423 /*************** qos ******************/
478 UINT bETHCSEnabled; 424 BOOLEAN bETHCSEnabled;
479 425
480 ULONG BEBucketSize; 426 ULONG BEBucketSize;
481 ULONG rtPSBucketSize; 427 ULONG rtPSBucketSize;
@@ -483,7 +429,6 @@ struct _MINI_ADAPTER
483 BOOLEAN AutoLinkUp; 429 BOOLEAN AutoLinkUp;
484 BOOLEAN AutoSyncup; 430 BOOLEAN AutoSyncup;
485 431
486 struct net_device *dev;
487 int major; 432 int major;
488 int minor; 433 int minor;
489 wait_queue_head_t tx_packet_wait_queue; 434 wait_queue_head_t tx_packet_wait_queue;
@@ -491,8 +436,6 @@ struct _MINI_ADAPTER
491 atomic_t process_waiting; 436 atomic_t process_waiting;
492 BOOLEAN fw_download_done; 437 BOOLEAN fw_download_done;
493 438
494 unsigned int ctrlpkt_present;
495 BOOLEAN packets_given_to_all;
496 char *txctlpacket[MAX_CNTRL_PKTS]; 439 char *txctlpacket[MAX_CNTRL_PKTS];
497 atomic_t cntrlpktCnt ; 440 atomic_t cntrlpktCnt ;
498 atomic_t index_app_read_cntrlpkt; 441 atomic_t index_app_read_cntrlpkt;
@@ -502,34 +445,30 @@ struct _MINI_ADAPTER
502 struct semaphore rdmwrmsync; 445 struct semaphore rdmwrmsync;
503 446
504 STTARGETDSXBUFFER astTargetDsxBuffer[MAX_TARGET_DSX_BUFFERS]; 447 STTARGETDSXBUFFER astTargetDsxBuffer[MAX_TARGET_DSX_BUFFERS];
505 ULONG ulFreeTargetBufferCnt; 448 ULONG ulFreeTargetBufferCnt;
506 ULONG ulCurrentTargetBuffer; 449 ULONG ulCurrentTargetBuffer;
507 ULONG ulTotalTargetBuffersAvailable; 450 ULONG ulTotalTargetBuffersAvailable;
508 unsigned int timeout; 451
509 int irq;
510 unsigned long chip_id; 452 unsigned long chip_id;
511 unsigned int bFlashBoot; 453
512 unsigned int if_up;
513// spinlock_t sleeper_lock;
514 atomic_t rdm_wrm_access;
515 atomic_t tx_rx_access;
516 wait_queue_head_t lowpower_mode_wait_queue; 454 wait_queue_head_t lowpower_mode_wait_queue;
517 atomic_t bAbortedByHost; 455
518 BOOLEAN bBinDownloaded; 456 BOOLEAN bFlashBoot;
519 BOOLEAN bCfgDownloaded; 457 BOOLEAN bBinDownloaded;
520 USHORT usBestEffortQueueIndex; 458 BOOLEAN bCfgDownloaded;
521 BOOLEAN bSyncUpRequestSent; 459 BOOLEAN bSyncUpRequestSent;
522// struct semaphore data_packet_queue_lock; 460 USHORT usBestEffortQueueIndex;
461
523 wait_queue_head_t ioctl_fw_dnld_wait_queue; 462 wait_queue_head_t ioctl_fw_dnld_wait_queue;
524 BOOLEAN waiting_to_fw_download_done; 463 BOOLEAN waiting_to_fw_download_done;
525 pid_t fw_download_process_pid; 464 pid_t fw_download_process_pid;
526 PSTARGETPARAMS pstargetparams; 465 PSTARGETPARAMS pstargetparams;
527 BOOLEAN device_removed; 466 BOOLEAN device_removed;
528 BOOLEAN DeviceAccess; 467 BOOLEAN DeviceAccess;
529 INT DDRSetting; 468 BOOLEAN bIsAutoCorrectEnabled;
530 BOOLEAN bDDRInitDone; 469 BOOLEAN bDDRInitDone;
470 INT DDRSetting;
531 ULONG ulPowerSaveMode; 471 ULONG ulPowerSaveMode;
532 BOOLEAN bIsAutoCorrectEnabled;
533 spinlock_t txtransmitlock; 472 spinlock_t txtransmitlock;
534 B_UINT8 txtransmit_running; 473 B_UINT8 txtransmit_running;
535 /* Thread for control packet handling */ 474 /* Thread for control packet handling */
@@ -567,13 +506,13 @@ struct _MINI_ADAPTER
567 unsigned int usIdleModePattern; 506 unsigned int usIdleModePattern;
568 //BOOLEAN bTriedToWakeUpFromShutdown; 507 //BOOLEAN bTriedToWakeUpFromShutdown;
569 BOOLEAN bLinkDownRequested; 508 BOOLEAN bLinkDownRequested;
570 unsigned int check_for_hang; 509
571 int downloadDDR; 510 int downloadDDR;
572 PHS_DEVICE_EXTENSION stBCMPhsContext; 511 PHS_DEVICE_EXTENSION stBCMPhsContext;
573 S_HDR_SUPRESSION_CONTEXTINFO stPhsTxContextInfo; 512 S_HDR_SUPRESSION_CONTEXTINFO stPhsTxContextInfo;
574 uint8_t ucaPHSPktRestoreBuf[2048]; 513 uint8_t ucaPHSPktRestoreBuf[2048];
575 uint8_t bPHSEnabled; 514 uint8_t bPHSEnabled;
576 int AutoFirmDld; 515 BOOLEAN AutoFirmDld;
577 BOOLEAN bMipsConfig; 516 BOOLEAN bMipsConfig;
578 BOOLEAN bDPLLConfig; 517 BOOLEAN bDPLLConfig;
579 UINT32 aTxPktSizeHist[MIBS_MAX_HIST_ENTRIES]; 518 UINT32 aTxPktSizeHist[MIBS_MAX_HIST_ENTRIES];
@@ -599,10 +538,9 @@ struct _MINI_ADAPTER
599 538
600 539
601 struct semaphore NVMRdmWrmLock; 540 struct semaphore NVMRdmWrmLock;
602 BOOLEAN bNetworkInterfaceRegistered; 541
603 BOOLEAN bNetdeviceNotifierRegistered;
604 struct device *pstCreatedClassDevice; 542 struct device *pstCreatedClassDevice;
605 BOOLEAN bUsbClassDriverRegistered; 543
606// BOOLEAN InterfaceUpStatus; 544// BOOLEAN InterfaceUpStatus;
607 PFLASH2X_CS_INFO psFlash2xCSInfo; 545 PFLASH2X_CS_INFO psFlash2xCSInfo;
608 PFLASH_CS_INFO psFlashCSInfo ; 546 PFLASH_CS_INFO psFlashCSInfo ;
@@ -630,17 +568,13 @@ struct _MINI_ADAPTER
630 struct semaphore LowPowerModeSync; 568 struct semaphore LowPowerModeSync;
631 ULONG liDrainCalculated; 569 ULONG liDrainCalculated;
632 UINT gpioBitMap; 570 UINT gpioBitMap;
571
633 S_BCM_DEBUG_STATE stDebugState; 572 S_BCM_DEBUG_STATE stDebugState;
634 573
635}; 574};
636typedef struct _MINI_ADAPTER MINI_ADAPTER, *PMINI_ADAPTER; 575typedef struct _MINI_ADAPTER MINI_ADAPTER, *PMINI_ADAPTER;
637 576
638 577#define GET_BCM_ADAPTER(net_dev) netdev_priv(net_dev)
639typedef struct _DEVICE_EXTENSION
640{
641 PMINI_ADAPTER pAdapt;
642}DEVICE_EXTENSION,*PDEVICE_EXTENSION;
643
644 578
645struct _ETH_HEADER_STRUC { 579struct _ETH_HEADER_STRUC {
646 UCHAR au8DestinationAddress[6]; 580 UCHAR au8DestinationAddress[6];
@@ -667,8 +601,8 @@ typedef LINK_REQUEST CONTROL_MESSAGE;
667 601
668typedef struct _DDR_SETTING 602typedef struct _DDR_SETTING
669{ 603{
670 ULONG ulRegAddress; 604 UINT ulRegAddress;
671 ULONG ulRegValue; 605 UINT ulRegValue;
672}DDR_SETTING, *PDDR_SETTING; 606}DDR_SETTING, *PDDR_SETTING;
673typedef DDR_SETTING DDR_SET_NODE, *PDDR_SET_NODE; 607typedef DDR_SETTING DDR_SET_NODE, *PDDR_SET_NODE;
674INT 608INT
diff --git a/drivers/staging/bcm/Arp.c b/drivers/staging/bcm/Arp.c
deleted file mode 100644
index d60d8593d2ef..000000000000
--- a/drivers/staging/bcm/Arp.c
+++ /dev/null
@@ -1,94 +0,0 @@
1
2/*
3 * File Name: Arp.c
4 * Abstract: This file contains the routines for handling ARP PACKETS
5 */
6#include "headers.h"
7#define ARP_PKT_SIZE 60
8
9/* =========================================================================
10 * Function - reply_to_arp_request()
11 *
12 * Description - When this host tries to broadcast ARP request packet through
13 * the virtual interface (veth0), reply directly to upper layer.
14 * This function allocates a new skb for ARP reply packet,
15 * fills in the fields of the packet and then sends it to
16 * upper layer.
17 *
18 * Parameters - skb: Pointer to sk_buff structure of the ARP request pkt.
19 *
20 * Returns - None
21 * =========================================================================*/
22
23VOID
24reply_to_arp_request(struct sk_buff *skb)
25{
26 PMINI_ADAPTER Adapter;
27 struct ArpHeader *pArpHdr = NULL;
28 struct ethhdr *pethhdr = NULL;
29 UCHAR uiIPHdr[4];
30 /* Check for valid skb */
31 if(skb == NULL)
32 {
33 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid skb: Cannot reply to ARP request\n");
34 return;
35 }
36
37
38 Adapter = GET_BCM_ADAPTER(skb->dev);
39 /* Print the ARP Request Packet */
40 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, ARP_RESP, DBG_LVL_ALL, "ARP Packet Dump :");
41 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_TX, ARP_RESP, DBG_LVL_ALL, (PUCHAR)(skb->data), skb->len);
42
43 /*
44 * Extract the Ethernet Header and Arp Payload including Header
45 */
46 pethhdr = (struct ethhdr *)skb->data;
47 pArpHdr = (struct ArpHeader *)(skb->data+ETH_HLEN);
48
49 if(Adapter->bETHCSEnabled)
50 {
51 if(memcmp(pethhdr->h_source, Adapter->dev->dev_addr, ETH_ALEN))
52 {
53 bcm_kfree_skb(skb);
54 return;
55 }
56 }
57
58 // Set the Ethernet Header First.
59 memcpy(pethhdr->h_dest, pethhdr->h_source, ETH_ALEN);
60 if(!memcmp(pethhdr->h_source, Adapter->dev->dev_addr, ETH_ALEN))
61 {
62 pethhdr->h_source[5]++;
63 }
64
65 /* Set the reply to ARP Reply */
66 pArpHdr->arp.ar_op = ntohs(ARPOP_REPLY);
67
68 /* Set the HW Address properly */
69 memcpy(pArpHdr->ar_sha, pethhdr->h_source, ETH_ALEN);
70 memcpy(pArpHdr->ar_tha, pethhdr->h_dest, ETH_ALEN);
71
72 // Swapping the IP Adddress
73 memcpy(uiIPHdr,pArpHdr->ar_sip,4);
74 memcpy(pArpHdr->ar_sip,pArpHdr->ar_tip,4);
75 memcpy(pArpHdr->ar_tip,uiIPHdr,4);
76
77 /* Print the ARP Reply Packet */
78
79 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, ARP_RESP, DBG_LVL_ALL, "ARP REPLY PACKET: ");
80
81 /* Send the Packet to upper layer */
82 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_TX, ARP_RESP, DBG_LVL_ALL, (PUCHAR)(skb->data), skb->len);
83
84 skb->protocol = eth_type_trans(skb,skb->dev);
85 skb->pkt_type = PACKET_HOST;
86
87// skb->mac.raw=skb->data+LEADER_SIZE;
88 skb_set_mac_header (skb, LEADER_SIZE);
89 netif_rx(skb);
90 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, ARP_RESP, DBG_LVL_ALL, "<=============\n");
91 return;
92}
93
94
diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c
index fead9c56162e..31674ea1cd48 100644
--- a/drivers/staging/bcm/Bcmchar.c
+++ b/drivers/staging/bcm/Bcmchar.c
@@ -12,7 +12,7 @@
12* 12*
13* Returns - Zero(Success) 13* Returns - Zero(Success)
14****************************************************************/ 14****************************************************************/
15static struct class *bcm_class = NULL; 15
16static int bcm_char_open(struct inode *inode, struct file * filp) 16static int bcm_char_open(struct inode *inode, struct file * filp)
17{ 17{
18 PMINI_ADAPTER Adapter = NULL; 18 PMINI_ADAPTER Adapter = NULL;
@@ -93,7 +93,7 @@ static int bcm_char_release(struct inode *inode, struct file *filp)
93 /*Stop Queuing the control response Packets*/ 93 /*Stop Queuing the control response Packets*/
94 atomic_dec(&Adapter->ApplicationRunning); 94 atomic_dec(&Adapter->ApplicationRunning);
95 95
96 bcm_kfree(pTarang); 96 kfree(pTarang);
97 97
98 /* remove this filp from the asynchronously notified filp's */ 98 /* remove this filp from the asynchronously notified filp's */
99 filp->private_data = NULL; 99 filp->private_data = NULL;
@@ -102,11 +102,11 @@ static int bcm_char_release(struct inode *inode, struct file *filp)
102 102
103static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos) 103static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
104{ 104{
105 PPER_TARANG_DATA pTarang = (PPER_TARANG_DATA)filp->private_data; 105 PPER_TARANG_DATA pTarang = filp->private_data;
106 PMINI_ADAPTER Adapter = pTarang->Adapter; 106 PMINI_ADAPTER Adapter = pTarang->Adapter;
107 struct sk_buff* Packet = NULL; 107 struct sk_buff* Packet = NULL;
108 UINT PktLen = 0; 108 ssize_t PktLen = 0;
109 int wait_ret_val=0; 109 int wait_ret_val=0;
110 110
111 wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue, 111 wait_ret_val = wait_event_interruptible(Adapter->process_read_wait_queue,
112 (pTarang->RxAppControlHead || Adapter->device_removed)); 112 (pTarang->RxAppControlHead || Adapter->device_removed));
@@ -139,14 +139,16 @@ static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size, l
139 if(Packet) 139 if(Packet)
140 { 140 {
141 PktLen = Packet->len; 141 PktLen = Packet->len;
142 if(copy_to_user(buf, Packet->data, PktLen)) 142 if(copy_to_user(buf, Packet->data, min_t(size_t, PktLen, size)))
143 { 143 {
144 bcm_kfree_skb(Packet); 144 dev_kfree_skb(Packet);
145 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "\nReturning from copy to user failure \n"); 145 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "\nReturning from copy to user failure \n");
146 return -EFAULT; 146 return -EFAULT;
147 } 147 }
148 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Read %d Bytes From Adapter packet = 0x%p by process %d!\n", PktLen, Packet, current->pid); 148 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
149 bcm_kfree_skb(Packet); 149 "Read %zd Bytes From Adapter packet = %p by process %d!\n",
150 PktLen, Packet, current->pid);
151 dev_kfree_skb(Packet);
150 } 152 }
151 153
152 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<====\n"); 154 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<====\n");
@@ -155,15 +157,12 @@ static ssize_t bcm_char_read(struct file *filp, char __user *buf, size_t size, l
155 157
156static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg) 158static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
157{ 159{
158 PPER_TARANG_DATA pTarang = (PPER_TARANG_DATA)filp->private_data; 160 PPER_TARANG_DATA pTarang = filp->private_data;
159 void __user *argp = (void __user *)argp; 161 void __user *argp = (void __user *)arg;
160 PMINI_ADAPTER Adapter = pTarang->Adapter; 162 PMINI_ADAPTER Adapter = pTarang->Adapter;
161 INT Status = STATUS_FAILURE; 163 INT Status = STATUS_FAILURE;
162 IOCTL_BUFFER IoBuffer={}; 164 int timeout = 0;
163#ifndef BCM_SHM_INTERFACE 165 IOCTL_BUFFER IoBuffer;
164 int timeout = 0;
165#endif
166
167 166
168 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX", cmd, arg); 167 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX", cmd, arg);
169 168
@@ -204,50 +203,41 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
204 203
205 Status = vendorextnIoctl(Adapter, cmd, arg); 204 Status = vendorextnIoctl(Adapter, cmd, arg);
206 if(Status != CONTINUE_COMMON_PATH ) 205 if(Status != CONTINUE_COMMON_PATH )
207 {
208 return Status; 206 return Status;
209 }
210 207
211 switch(cmd){ 208 switch(cmd){
212 // Rdms for Swin Idle... 209 // Rdms for Swin Idle...
213 case IOCTL_BCM_REGISTER_READ_PRIVATE: 210 case IOCTL_BCM_REGISTER_READ_PRIVATE:
214 { 211 {
215 RDM_BUFFER sRdmBuffer = {0}; 212 RDM_BUFFER sRdmBuffer = {0};
216 PCHAR temp_buff = NULL; 213 PCHAR temp_buff;
217 UINT Bufflen = 0; 214 UINT Bufflen;
215
218 /* Copy Ioctl Buffer structure */ 216 /* Copy Ioctl Buffer structure */
219 if(copy_from_user((PCHAR)&IoBuffer, argp, 217 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
220 sizeof(IOCTL_BUFFER))) 218 return -EFAULT;
221 { 219
222 Status = -EFAULT; 220 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
223 break; 221 return -EINVAL;
224 }
225 222
223 if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
224 return -EFAULT;
225
226 /* FIXME: need to restrict BuffLen */
226 Bufflen = IoBuffer.OutputLength + (4 - IoBuffer.OutputLength%4)%4; 227 Bufflen = IoBuffer.OutputLength + (4 - IoBuffer.OutputLength%4)%4;
227 temp_buff = (PCHAR)kmalloc(Bufflen, GFP_KERNEL); 228 temp_buff = kmalloc(Bufflen, GFP_KERNEL);
228 if(!temp_buff) 229 if(!temp_buff)
229 { 230 return -ENOMEM;
230 return STATUS_FAILURE; 231
231 }
232 if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer,
233 IoBuffer.InputLength))
234 {
235 Status = -EFAULT;
236 break;
237 }
238 Status = rdmalt(Adapter, (UINT)sRdmBuffer.Register, 232 Status = rdmalt(Adapter, (UINT)sRdmBuffer.Register,
239 (PUINT)temp_buff, Bufflen); 233 (PUINT)temp_buff, Bufflen);
240 if(Status != STATUS_SUCCESS) 234 if(Status == STATUS_SUCCESS)
241 {
242 bcm_kfree(temp_buff);
243 return Status;
244 }
245 if(copy_to_user(IoBuffer.OutputBuffer,
246 (PCHAR)temp_buff, (UINT)IoBuffer.OutputLength))
247 { 235 {
248 Status = -EFAULT; 236 if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
237 Status = -EFAULT;
249 } 238 }
250 bcm_kfree(temp_buff); 239
240 kfree(temp_buff);
251 break; 241 break;
252 } 242 }
253 case IOCTL_BCM_REGISTER_WRITE_PRIVATE: 243 case IOCTL_BCM_REGISTER_WRITE_PRIVATE:
@@ -256,19 +246,16 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
256 UINT uiTempVar=0; 246 UINT uiTempVar=0;
257 /* Copy Ioctl Buffer structure */ 247 /* Copy Ioctl Buffer structure */
258 248
259 if(copy_from_user(&IoBuffer, argp, 249 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
260 sizeof(IOCTL_BUFFER))) 250 return -EFAULT;
261 { 251
262 Status = -EFAULT; 252 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
263 break; 253 return -EINVAL;
264 } 254
265 /* Get WrmBuffer structure */ 255 /* Get WrmBuffer structure */
266 if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, 256 if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
267 IoBuffer.InputLength)) 257 return -EFAULT;
268 { 258
269 Status = -EFAULT;
270 break;
271 }
272 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK; 259 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
273 if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) && 260 if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
274 ((uiTempVar == EEPROM_REJECT_REG_1)|| 261 ((uiTempVar == EEPROM_REJECT_REG_1)||
@@ -277,8 +264,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
277 (uiTempVar == EEPROM_REJECT_REG_4))) 264 (uiTempVar == EEPROM_REJECT_REG_4)))
278 { 265 {
279 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n"); 266 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
280 Status = -EFAULT; 267 return -EFAULT;
281 break;
282 } 268 }
283 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register, 269 Status = wrmalt(Adapter, (UINT)sWrmBuffer.Register,
284 (PUINT)sWrmBuffer.Data, sizeof(ULONG)); 270 (PUINT)sWrmBuffer.Data, sizeof(ULONG));
@@ -305,56 +291,39 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
305 (Adapter->bPreparingForLowPowerMode ==TRUE)) 291 (Adapter->bPreparingForLowPowerMode ==TRUE))
306 { 292 {
307 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n"); 293 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Rdms\n");
308 Status = -EACCES; 294 return -EACCES;
309 break;
310 } 295 }
311 /* Copy Ioctl Buffer structure */ 296 /* Copy Ioctl Buffer structure */
312 if(copy_from_user(&IoBuffer, argp, 297 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
313 sizeof(IOCTL_BUFFER))) 298 return -EFAULT;
314 { 299
315 Status = -EFAULT; 300 if (IoBuffer.InputLength > sizeof(sRdmBuffer))
316 break; 301 return -EINVAL;
317 }
318 302
319 temp_buff = (PCHAR)kmalloc(IoBuffer.OutputLength, GFP_KERNEL); 303 if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
304 return -EFAULT;
305
306 /* FIXME: don't trust user supplied length */
307 temp_buff = kmalloc(IoBuffer.OutputLength, GFP_KERNEL);
320 if(!temp_buff) 308 if(!temp_buff)
321 {
322 return STATUS_FAILURE; 309 return STATUS_FAILURE;
323 }
324 if(copy_from_user(&sRdmBuffer, IoBuffer.InputBuffer,
325 IoBuffer.InputLength))
326 {
327 Status = -EFAULT;
328 break;
329 }
330 310
331 if( 311 if((((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
332#if !defined(BCM_SHM_INTERFACE) 312 ((ULONG)sRdmBuffer.Register & 0x3))
333 (((ULONG)sRdmBuffer.Register & 0x0F000000) != 0x0F000000) ||
334#endif
335 ((ULONG)sRdmBuffer.Register & 0x3)
336 )
337 { 313 {
338 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n", 314 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "RDM Done On invalid Address : %x Access Denied.\n",
339 (int)sRdmBuffer.Register); 315 (int)sRdmBuffer.Register);
340 Status = -EINVAL; 316 return -EINVAL;
341 break;
342 } 317 }
343 318
344 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK; 319 uiTempVar = sRdmBuffer.Register & EEPROM_REJECT_MASK;
345 Status = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register, 320 Status = rdmaltWithLock(Adapter, (UINT)sRdmBuffer.Register,
346 (PUINT)temp_buff, IoBuffer.OutputLength); 321 (PUINT)temp_buff, IoBuffer.OutputLength);
347 if(Status != STATUS_SUCCESS) 322 if(Status == STATUS_SUCCESS)
348 { 323 if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, IoBuffer.OutputLength))
349 bcm_kfree(temp_buff); 324 Status = -EFAULT;
350 return Status; 325
351 } 326 kfree(temp_buff);
352 if(copy_to_user(IoBuffer.OutputBuffer,
353 (PCHAR)temp_buff, (UINT)IoBuffer.OutputLength))
354 {
355 Status = -EFAULT;
356 }
357 bcm_kfree(temp_buff);
358 break; 327 break;
359 } 328 }
360 case IOCTL_BCM_REGISTER_WRITE: 329 case IOCTL_BCM_REGISTER_WRITE:
@@ -367,36 +336,28 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
367 (Adapter->bPreparingForLowPowerMode ==TRUE)) 336 (Adapter->bPreparingForLowPowerMode ==TRUE))
368 { 337 {
369 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Wrms\n"); 338 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Device in Idle Mode, Blocking Wrms\n");
370 Status = -EACCES; 339 return -EACCES;
371 break;
372 } 340 }
341
373 /* Copy Ioctl Buffer structure */ 342 /* Copy Ioctl Buffer structure */
374 if(copy_from_user((PCHAR)&IoBuffer, argp, 343 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
375 sizeof(IOCTL_BUFFER))) 344 return -EFAULT;
376 { 345
377 Status = -EFAULT; 346 if (IoBuffer.InputLength > sizeof(sWrmBuffer))
378 break; 347 return -EINVAL;
379 } 348
380 /* Get WrmBuffer structure */ 349 /* Get WrmBuffer structure */
381 if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, 350 if(copy_from_user(&sWrmBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
382 IoBuffer.InputLength)) 351 return -EFAULT;
383 {
384 Status = -EFAULT;
385 break;
386 }
387 if(
388#if !defined(BCM_SHM_INTERFACE)
389 352
390 (((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) || 353 if( (((ULONG)sWrmBuffer.Register & 0x0F000000) != 0x0F000000) ||
391#endif 354 ((ULONG)sWrmBuffer.Register & 0x3) )
392 ((ULONG)sWrmBuffer.Register & 0x3)
393 )
394 { 355 {
395 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n", 356 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Done On invalid Address : %x Access Denied.\n",
396 (int)sWrmBuffer.Register); 357 (int)sWrmBuffer.Register);
397 Status = -EINVAL; 358 return -EINVAL;
398 break;
399 } 359 }
360
400 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK; 361 uiTempVar = sWrmBuffer.Register & EEPROM_REJECT_MASK;
401 if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) && 362 if(!((Adapter->pstargetparams->m_u32Customize) & VSG_MODE) &&
402 ((uiTempVar == EEPROM_REJECT_REG_1)|| 363 ((uiTempVar == EEPROM_REJECT_REG_1)||
@@ -406,8 +367,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
406 (cmd == IOCTL_BCM_REGISTER_WRITE)) 367 (cmd == IOCTL_BCM_REGISTER_WRITE))
407 { 368 {
408 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n"); 369 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "EEPROM Access Denied, not in VSG Mode\n");
409 Status = -EFAULT; 370 return -EFAULT;
410 break;
411 } 371 }
412 372
413 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register, 373 Status = wrmaltWithLock(Adapter, (UINT)sWrmBuffer.Register,
@@ -436,19 +396,14 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
436 (Adapter->bPreparingForLowPowerMode ==TRUE)) 396 (Adapter->bPreparingForLowPowerMode ==TRUE))
437 { 397 {
438 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode"); 398 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"GPIO Can't be set/clear in Low power Mode");
439 Status = -EACCES; 399 return -EACCES;
440 break;
441 } 400 }
442 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) 401 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
443 { 402 return -EFAULT;
444 Status = -EFAULT; 403 if (IoBuffer.InputLength > sizeof(gpio_info))
445 break; 404 return -EINVAL;
446 }
447 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength)) 405 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
448 { 406 return -EFAULT;
449 Status = -EFAULT;
450 break;
451 }
452 uiBit = gpio_info.uiGpioNumber; 407 uiBit = gpio_info.uiGpioNumber;
453 uiOperation = gpio_info.uiGpioValue; 408 uiOperation = gpio_info.uiGpioValue;
454 409
@@ -517,8 +472,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
517 break; 472 break;
518 case BCM_LED_THREAD_STATE_CHANGE_REQ: 473 case BCM_LED_THREAD_STATE_CHANGE_REQ:
519 { 474 {
520 475 USER_THREAD_REQ threadReq = { 0 };
521 USER_THREAD_REQ threadReq = {0};
522 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"User made LED thread InActive"); 476 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"User made LED thread InActive");
523 477
524 if((Adapter->IdleMode == TRUE) || 478 if((Adapter->IdleMode == TRUE) ||
@@ -529,21 +483,16 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
529 Status = -EACCES; 483 Status = -EACCES;
530 break; 484 break;
531 } 485 }
532 Status =copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER));
533 if(Status)
534 {
535 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status);
536 Status = -EFAULT;
537 break;
538 }
539 486
540 Status= copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength); 487 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
541 if(Status) 488 return -EFAULT;
542 { 489
543 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the InputBuffer from user space err:%d",Status); 490 if (IoBuffer.InputLength > sizeof(threadReq))
544 Status = -EFAULT; 491 return -EINVAL;
545 break; 492
546 } 493 if (copy_from_user(&threadReq, IoBuffer.InputBuffer, IoBuffer.InputLength))
494 return -EFAULT;
495
547 //if LED thread is running(Actively or Inactively) set it state to make inactive 496 //if LED thread is running(Actively or Inactively) set it state to make inactive
548 if(Adapter->LEDInfo.led_thread_running) 497 if(Adapter->LEDInfo.led_thread_running)
549 { 498 {
@@ -572,19 +521,13 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
572 if((Adapter->IdleMode == TRUE) || 521 if((Adapter->IdleMode == TRUE) ||
573 (Adapter->bShutStatus ==TRUE) || 522 (Adapter->bShutStatus ==TRUE) ||
574 (Adapter->bPreparingForLowPowerMode ==TRUE)) 523 (Adapter->bPreparingForLowPowerMode ==TRUE))
575 { 524 return -EACCES;
576 Status = -EACCES; 525 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
577 break; 526 return -EFAULT;
578 } 527 if (IoBuffer.InputLength > sizeof(gpio_info))
579 if(copy_from_user((PCHAR)&IoBuffer, argp, sizeof(IOCTL_BUFFER))) { 528 return -EINVAL;
580 Status = -EFAULT; 529 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
581 break; 530 return -EFAULT;
582 }
583 if(copy_from_user(&gpio_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
584 {
585 Status = -EFAULT;
586 break;
587 }
588 uiBit = gpio_info.uiGpioNumber; 531 uiBit = gpio_info.uiGpioNumber;
589 //Set the gpio output register 532 //Set the gpio output register
590 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER, 533 Status = rdmaltWithLock(Adapter, (UINT)GPIO_PIN_STATE_REGISTER,
@@ -608,25 +551,14 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
608 if((Adapter->IdleMode == TRUE) || 551 if((Adapter->IdleMode == TRUE) ||
609 (Adapter->bShutStatus ==TRUE) || 552 (Adapter->bShutStatus ==TRUE) ||
610 (Adapter->bPreparingForLowPowerMode ==TRUE)) 553 (Adapter->bPreparingForLowPowerMode ==TRUE))
611 { 554 return -EINVAL;
612 Status = -EINVAL; 555 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
613 break; 556 return -EFAULT;
614 } 557 if (IoBuffer.InputLength > sizeof(gpio_multi_info))
615 Status = copy_from_user( (PCHAR)&IoBuffer, argp, sizeof( IOCTL_BUFFER)); 558 return -EINVAL;
616 if(Status) 559 if (copy_from_user(&gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength))
617 { 560 return -EFAULT;
618 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status);
619 Status = -EFAULT;
620 break;
621 }
622 561
623 Status = copy_from_user( &gpio_multi_info, IoBuffer.InputBuffer, IoBuffer.InputLength);
624 if(Status)
625 {
626 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer Contents from user space err:%d",Status);
627 Status = -EFAULT;
628 break;
629 }
630 if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_info[WIMAX_IDX].uiGPIOMask)== FALSE) 562 if(IsReqGpioIsLedInNVM(Adapter,pgpio_multi_info[WIMAX_IDX].uiGPIOMask)== FALSE)
631 { 563 {
632 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",pgpio_multi_info[WIMAX_IDX].uiGPIOMask,Adapter->gpioBitMap); 564 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",pgpio_multi_info[WIMAX_IDX].uiGPIOMask,Adapter->gpioBitMap);
@@ -686,7 +618,6 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
686 if(Status) 618 if(Status)
687 { 619 {
688 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status); 620 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
689 Status = -EFAULT;
690 break; 621 break;
691 } 622 }
692 } 623 }
@@ -700,25 +631,14 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
700 if((Adapter->IdleMode == TRUE) || 631 if((Adapter->IdleMode == TRUE) ||
701 (Adapter->bShutStatus ==TRUE) || 632 (Adapter->bShutStatus ==TRUE) ||
702 (Adapter->bPreparingForLowPowerMode ==TRUE)) 633 (Adapter->bPreparingForLowPowerMode ==TRUE))
703 { 634 return -EINVAL;
704 Status = -EINVAL;
705 break;
706 }
707 Status = copy_from_user(&IoBuffer, argp, sizeof( IOCTL_BUFFER));
708 if(Status)
709 {
710 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer from user space err:%d",Status);
711 Status = -EFAULT;
712 break;
713 }
714 635
715 Status = copy_from_user( &gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength); 636 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
716 if(Status) 637 return -EFAULT;
717 { 638 if (IoBuffer.InputLength > sizeof(gpio_multi_mode))
718 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying the IOBufer Contents from user space err:%d",Status); 639 return -EINVAL;
719 Status = -EFAULT; 640 if (copy_from_user(&gpio_multi_mode, IoBuffer.InputBuffer, IoBuffer.InputLength))
720 break; 641 return -EFAULT;
721 }
722 642
723 Status = rdmaltWithLock( Adapter, ( UINT) GPIO_MODE_REGISTER, ( PUINT) ucResetValue, sizeof( UINT)); 643 Status = rdmaltWithLock( Adapter, ( UINT) GPIO_MODE_REGISTER, ( PUINT) ucResetValue, sizeof( UINT));
724 if( STATUS_SUCCESS != Status) 644 if( STATUS_SUCCESS != Status)
@@ -769,7 +689,6 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
769 if(Status) 689 if(Status)
770 { 690 {
771 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status); 691 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Failed while copying Content to IOBufer for user space err:%d",Status);
772 Status = -EFAULT;
773 break; 692 break;
774 } 693 }
775 } 694 }
@@ -783,24 +702,20 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
783 case IOCTL_IDLE_REQ: 702 case IOCTL_IDLE_REQ:
784 { 703 {
785 PVOID pvBuffer=NULL; 704 PVOID pvBuffer=NULL;
705
786 /* Copy Ioctl Buffer structure */ 706 /* Copy Ioctl Buffer structure */
787 if(copy_from_user(&IoBuffer, argp, 707 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
788 sizeof(IOCTL_BUFFER))) 708 return -EFAULT;
789 { 709
790 Status = -EFAULT; 710 /* FIXME: don't accept any length from user */
791 break; 711 pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
792 }
793 pvBuffer=kmalloc(IoBuffer.InputLength, GFP_KERNEL);
794 if(!pvBuffer) 712 if(!pvBuffer)
795 {
796 return -ENOMEM; 713 return -ENOMEM;
797 }
798 714
799 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, 715 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
800 IoBuffer.InputLength))
801 { 716 {
802 Status = -EFAULT; 717 Status = -EFAULT;
803 bcm_kfree(pvBuffer); 718 kfree(pvBuffer);
804 break; 719 break;
805 } 720 }
806 721
@@ -820,10 +735,9 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
820 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer); 735 Status = CopyBufferToControlPacket(Adapter, (PVOID)pvBuffer);
821 cntrlEnd: 736 cntrlEnd:
822 up(&Adapter->LowPowerModeSync); 737 up(&Adapter->LowPowerModeSync);
823 bcm_kfree(pvBuffer); 738 kfree(pvBuffer);
824 break; 739 break;
825 } 740 }
826#ifndef BCM_SHM_INTERFACE
827 case IOCTL_BCM_BUFFER_DOWNLOAD_START: 741 case IOCTL_BCM_BUFFER_DOWNLOAD_START:
828 { 742 {
829 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock) ; 743 INT NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock) ;
@@ -844,7 +758,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
844 Status = reset_card_proc(Adapter); 758 Status = reset_card_proc(Adapter);
845 if(Status) 759 if(Status)
846 { 760 {
847 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "reset_card_proc Failed!\n"); 761 pr_err(PFX "%s: reset_card_proc Failed!\n", Adapter->dev->name);
848 up(&Adapter->fw_download_sema); 762 up(&Adapter->fw_download_sema);
849 up(&Adapter->NVMRdmWrmLock); 763 up(&Adapter->NVMRdmWrmLock);
850 break; 764 break;
@@ -862,7 +776,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
862 } 776 }
863 case IOCTL_BCM_BUFFER_DOWNLOAD: 777 case IOCTL_BCM_BUFFER_DOWNLOAD:
864 { 778 {
865 FIRMWARE_INFO *psFwInfo=NULL; 779 FIRMWARE_INFO *psFwInfo = NULL;
866 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid); 780 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Starting the firmware download PID =0x%x!!!!\n", current->pid);
867 do{ 781 do{
868 if(!down_trylock(&Adapter->fw_download_sema)) 782 if(!down_trylock(&Adapter->fw_download_sema))
@@ -871,29 +785,23 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
871 Status=-EINVAL; 785 Status=-EINVAL;
872 break; 786 break;
873 } 787 }
788
874 /* Copy Ioctl Buffer structure */ 789 /* Copy Ioctl Buffer structure */
875 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) 790 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
876 { 791 return -EFAULT;
877 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copy_from_user 1 failed\n"); 792
878 Status = -EFAULT;
879 break;
880 }
881 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Length for FW DLD is : %lx\n", 793 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Length for FW DLD is : %lx\n",
882 IoBuffer.InputLength); 794 IoBuffer.InputLength);
883 psFwInfo=kmalloc(sizeof(*psFwInfo), GFP_KERNEL); 795
796 if (IoBuffer.InputLength > sizeof(FIRMWARE_INFO))
797 return -EINVAL;
798
799 psFwInfo = kmalloc(sizeof(*psFwInfo), GFP_KERNEL);
884 if(!psFwInfo) 800 if(!psFwInfo)
885 { 801 return -ENOMEM;
886 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Failed to allocate buffer!!!!\n"); 802
887 Status = -ENOMEM; 803 if(copy_from_user(psFwInfo, IoBuffer.InputBuffer, IoBuffer.InputLength))
888 break; 804 return -EFAULT;
889 }
890 if(copy_from_user(psFwInfo, IoBuffer.InputBuffer,
891 IoBuffer.InputLength))
892 {
893 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_from_user 2 failed\n");
894 Status = -EFAULT;
895 break;
896 }
897 805
898 if(!psFwInfo->pvMappedFirmwareAddress || 806 if(!psFwInfo->pvMappedFirmwareAddress ||
899 (psFwInfo->u32FirmwareLength == 0)) 807 (psFwInfo->u32FirmwareLength == 0))
@@ -929,7 +837,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
929 if(Status != STATUS_SUCCESS) 837 if(Status != STATUS_SUCCESS)
930 up(&Adapter->fw_download_sema); 838 up(&Adapter->fw_download_sema);
931 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n"); 839 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL, "IOCTL: Firmware File Uploaded\n");
932 bcm_kfree(psFwInfo); 840 kfree(psFwInfo);
933 break; 841 break;
934 } 842 }
935 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP: 843 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP:
@@ -946,7 +854,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
946 Adapter->bBinDownloaded=TRUE; 854 Adapter->bBinDownloaded=TRUE;
947 Adapter->bCfgDownloaded=TRUE; 855 Adapter->bCfgDownloaded=TRUE;
948 atomic_set(&Adapter->CurrNumFreeTxDesc, 0); 856 atomic_set(&Adapter->CurrNumFreeTxDesc, 0);
949 atomic_set(&Adapter->RxRollOverCount, 0); 857
950 Adapter->CurrNumRecvDescs=0; 858 Adapter->CurrNumRecvDescs=0;
951 Adapter->downloadDDR = 0; 859 Adapter->downloadDDR = 0;
952 860
@@ -999,7 +907,6 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
999 up(&Adapter->NVMRdmWrmLock); 907 up(&Adapter->NVMRdmWrmLock);
1000 break; 908 break;
1001 } 909 }
1002#endif
1003 case IOCTL_BE_BUCKET_SIZE: 910 case IOCTL_BE_BUCKET_SIZE:
1004 Status = 0; 911 Status = 0;
1005 if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg)) 912 if (get_user(Adapter->BEBucketSize, (unsigned long __user *)arg))
@@ -1050,22 +957,16 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1050 break; 957 break;
1051 958
1052 case IOCTL_GET_PACK_INFO: 959 case IOCTL_GET_PACK_INFO:
1053 if(copy_to_user(argp, &Adapter->PackInfo, 960 if(copy_to_user(argp, &Adapter->PackInfo, sizeof(PacketInfo)*NO_OF_QUEUES))
1054 sizeof(PacketInfo)*NO_OF_QUEUES)) 961 return -EFAULT;
1055 {
1056 Status = -EFAULT;
1057 break;
1058 }
1059 Status = STATUS_SUCCESS; 962 Status = STATUS_SUCCESS;
1060 break; 963 break;
1061 case IOCTL_BCM_SWITCH_TRANSFER_MODE: 964 case IOCTL_BCM_SWITCH_TRANSFER_MODE:
1062 { 965 {
1063 UINT uiData = 0; 966 UINT uiData = 0;
1064 if(copy_from_user(&uiData, argp, sizeof(UINT))) 967 if(copy_from_user(&uiData, argp, sizeof(UINT)))
1065 { 968 return -EFAULT;
1066 Status = -EFAULT; 969
1067 break;
1068 }
1069 if(uiData) /* Allow All Packets */ 970 if(uiData) /* Allow All Packets */
1070 { 971 {
1071 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n"); 972 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
@@ -1084,22 +985,16 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1084 { 985 {
1085 /* Copy Ioctl Buffer structure */ 986 /* Copy Ioctl Buffer structure */
1086 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) 987 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1087 { 988 return -EFAULT;
1088 Status = -EFAULT; 989
1089 break; 990 if(copy_to_user(IoBuffer.OutputBuffer, VER_FILEVERSION_STR, IoBuffer.OutputLength))
1090 } 991 return -EFAULT;
1091 if(copy_to_user(IoBuffer.OutputBuffer,
1092 VER_FILEVERSION_STR, (UINT)IoBuffer.OutputLength))
1093 {
1094 Status = -EFAULT;
1095 break;
1096 }
1097 Status = STATUS_SUCCESS; 992 Status = STATUS_SUCCESS;
1098 break; 993 break;
1099 } 994 }
1100 case IOCTL_BCM_GET_CURRENT_STATUS: 995 case IOCTL_BCM_GET_CURRENT_STATUS:
1101 { 996 {
1102 LINK_STATE plink_state; 997 LINK_STATE link_state;
1103 998
1104 /* Copy Ioctl Buffer structure */ 999 /* Copy Ioctl Buffer structure */
1105 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) 1000 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
@@ -1108,19 +1003,19 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1108 Status = -EFAULT; 1003 Status = -EFAULT;
1109 break; 1004 break;
1110 } 1005 }
1111 if (IoBuffer.OutputLength != sizeof(plink_state)) { 1006 if (IoBuffer.OutputLength != sizeof(link_state)) {
1112 Status = -EINVAL; 1007 Status = -EINVAL;
1113 break; 1008 break;
1114 } 1009 }
1115 1010
1116 if (copy_from_user(&plink_state, (void __user *)arg, sizeof(plink_state))) { 1011 memset(&link_state, 0, sizeof(link_state));
1117 Status = -EFAULT; 1012 link_state.bIdleMode = Adapter->IdleMode;
1118 break; 1013 link_state.bShutdownMode = Adapter->bShutStatus;
1119 } 1014 link_state.ucLinkStatus = Adapter->LinkStatus;
1120 plink_state.bIdleMode = (UCHAR)Adapter->IdleMode; 1015
1121 plink_state.bShutdownMode = Adapter->bShutStatus; 1016 if (copy_to_user(IoBuffer.OutputBuffer, &link_state,
1122 plink_state.ucLinkStatus = (UCHAR)Adapter->LinkStatus; 1017 min_t(size_t, sizeof(link_state), IoBuffer.OutputLength)))
1123 if (copy_to_user(IoBuffer.OutputBuffer, &plink_state, IoBuffer.OutputLength)) { 1018 {
1124 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n"); 1019 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_to_user Failed..\n");
1125 Status = -EFAULT; 1020 Status = -EFAULT;
1126 break; 1021 break;
@@ -1131,17 +1026,14 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1131 case IOCTL_BCM_SET_MAC_TRACING: 1026 case IOCTL_BCM_SET_MAC_TRACING:
1132 { 1027 {
1133 UINT tracing_flag; 1028 UINT tracing_flag;
1029
1134 /* copy ioctl Buffer structure */ 1030 /* copy ioctl Buffer structure */
1135 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) 1031 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1136 { 1032 return -EFAULT;
1137 Status = -EFAULT; 1033
1138 break; 1034 if(copy_from_user(&tracing_flag,IoBuffer.InputBuffer,sizeof(UINT)))
1139 } 1035 return -EFAULT;
1140 if(copy_from_user(&tracing_flag, IoBuffer.InputBuffer,sizeof(UINT))) 1036
1141 {
1142 Status = -EFAULT;
1143 break;
1144 }
1145 if (tracing_flag) 1037 if (tracing_flag)
1146 Adapter->pTarangs->MacTracingEnabled = TRUE; 1038 Adapter->pTarangs->MacTracingEnabled = TRUE;
1147 else 1039 else
@@ -1151,72 +1043,53 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1151 case IOCTL_BCM_GET_DSX_INDICATION: 1043 case IOCTL_BCM_GET_DSX_INDICATION:
1152 { 1044 {
1153 ULONG ulSFId=0; 1045 ULONG ulSFId=0;
1154 if(copy_from_user((PCHAR)&IoBuffer, argp, 1046 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1155 sizeof(IOCTL_BUFFER))) 1047 return -EFAULT;
1156 { 1048
1157 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Invalid IO buffer!!!" );
1158 Status = -EFAULT;
1159 break;
1160 }
1161 if(IoBuffer.OutputLength < sizeof(stLocalSFAddIndicationAlt)) 1049 if(IoBuffer.OutputLength < sizeof(stLocalSFAddIndicationAlt))
1162 { 1050 {
1163 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Mismatch req: %lx needed is =0x%zx!!!", 1051 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,
1164 IoBuffer.OutputLength, sizeof(stLocalSFAddIndicationAlt)); 1052 "Mismatch req: %lx needed is =0x%zx!!!",
1053 IoBuffer.OutputLength, sizeof(stLocalSFAddIndicationAlt));
1165 return -EINVAL; 1054 return -EINVAL;
1166 } 1055 }
1167 if(copy_from_user(&ulSFId, IoBuffer.InputBuffer, 1056
1168 sizeof(ulSFId))) 1057 if(copy_from_user(&ulSFId, IoBuffer.InputBuffer, sizeof(ulSFId)))
1169 { 1058 return -EFAULT;
1170 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Invalid SFID!!! %lu", ulSFId ); 1059
1171 Status = -EFAULT;
1172 break;
1173 }
1174 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId ); 1060 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Get DSX Data SF ID is =%lx\n", ulSFId );
1175 get_dsx_sf_data_to_application(Adapter, ulSFId, 1061 get_dsx_sf_data_to_application(Adapter, ulSFId, IoBuffer.OutputBuffer);
1176 IoBuffer.OutputBuffer);
1177 Status=STATUS_SUCCESS; 1062 Status=STATUS_SUCCESS;
1178 } 1063 }
1179 break; 1064 break;
1180 case IOCTL_BCM_GET_HOST_MIBS: 1065 case IOCTL_BCM_GET_HOST_MIBS:
1181 { 1066 {
1182 PCHAR temp_buff; 1067 PVOID temp_buff;
1183 1068
1184 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) 1069 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1185 { 1070 return -EFAULT;
1186 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy_from user for IoBuff failed\n");
1187 Status = -EFAULT;
1188 break;
1189 }
1190 1071
1191 if(IoBuffer.OutputLength != sizeof(S_MIBS_HOST_STATS_MIBS)) 1072 if(IoBuffer.OutputLength != sizeof(S_MIBS_HOST_STATS_MIBS))
1192 { 1073 {
1193 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Length Check failed %lu %zd\n", IoBuffer.OutputLength, 1074 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,
1194 sizeof(S_MIBS_HOST_STATS_MIBS)); 1075 "Length Check failed %lu %zd\n",
1195 return -EINVAL; 1076 IoBuffer.OutputLength, sizeof(S_MIBS_HOST_STATS_MIBS));
1077 return -EINVAL;
1196 } 1078 }
1197 1079
1198 temp_buff = (PCHAR)kmalloc(IoBuffer.OutputLength, GFP_KERNEL); 1080 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1199 1081 temp_buff = kzalloc(sizeof(S_MIBS_HOST_STATS_MIBS), GFP_KERNEL);
1200 if(!temp_buff) 1082 if(!temp_buff)
1201 {
1202 return STATUS_FAILURE; 1083 return STATUS_FAILURE;
1203 }
1204
1205 Status = ProcessGetHostMibs(Adapter,
1206 (PUCHAR)temp_buff, IoBuffer.OutputLength);
1207 1084
1208 Status = GetDroppedAppCntrlPktMibs((PVOID)temp_buff, 1085 Status = ProcessGetHostMibs(Adapter, temp_buff);
1209 (PPER_TARANG_DATA)filp->private_data); 1086 GetDroppedAppCntrlPktMibs(temp_buff, pTarang);
1210 1087
1211 if(copy_to_user(IoBuffer.OutputBuffer,(PCHAR)temp_buff, 1088 if (Status != STATUS_FAILURE)
1212 sizeof(S_MIBS_HOST_STATS_MIBS))) 1089 if(copy_to_user(IoBuffer.OutputBuffer, temp_buff, sizeof(S_MIBS_HOST_STATS_MIBS)))
1213 { 1090 Status = -EFAULT;
1214 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy to user failed\n");
1215 bcm_kfree(temp_buff);
1216 return -EFAULT;
1217 }
1218 1091
1219 bcm_kfree(temp_buff); 1092 kfree(temp_buff);
1220 break; 1093 break;
1221 } 1094 }
1222 1095
@@ -1226,10 +1099,6 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1226 Adapter->usIdleModePattern = ABORT_IDLE_MODE; 1099 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
1227 Adapter->bWakeUpDevice = TRUE; 1100 Adapter->bWakeUpDevice = TRUE;
1228 wake_up(&Adapter->process_rx_cntrlpkt); 1101 wake_up(&Adapter->process_rx_cntrlpkt);
1229 #if 0
1230 Adapter->bTriedToWakeUpFromlowPowerMode = TRUE;
1231 InterfaceAbortIdlemode (Adapter, Adapter->usIdleModePattern);
1232 #endif
1233 } 1102 }
1234 Status = STATUS_SUCCESS; 1103 Status = STATUS_SUCCESS;
1235 break; 1104 break;
@@ -1248,24 +1117,20 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1248 Status = -EACCES; 1117 Status = -EACCES;
1249 break; 1118 break;
1250 } 1119 }
1120
1251 /* Copy Ioctl Buffer structure */ 1121 /* Copy Ioctl Buffer structure */
1252 if(copy_from_user((PCHAR)&IoBuffer, argp, sizeof(IOCTL_BUFFER))) 1122 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1253 { 1123 return -EFAULT;
1254 Status = -EFAULT;
1255 break;
1256 }
1257 1124
1258 pvBuffer=kmalloc(IoBuffer.InputLength, GFP_KERNEL); 1125 /* FIXME: restrict length */
1126 pvBuffer = kmalloc(IoBuffer.InputLength, GFP_KERNEL);
1259 if(!pvBuffer) 1127 if(!pvBuffer)
1260 {
1261 return -ENOMEM; 1128 return -ENOMEM;
1262 break;
1263 }
1264 1129
1265 /* Get WrmBuffer structure */ 1130 /* Get WrmBuffer structure */
1266 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength)) 1131 if(copy_from_user(pvBuffer, IoBuffer.InputBuffer, IoBuffer.InputLength))
1267 { 1132 {
1268 bcm_kfree(pvBuffer); 1133 kfree(pvBuffer);
1269 Status = -EFAULT; 1134 Status = -EFAULT;
1270 break; 1135 break;
1271 } 1136 }
@@ -1275,7 +1140,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1275 if(((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 || 1140 if(((ULONG)pBulkBuffer->Register & 0x0F000000) != 0x0F000000 ||
1276 ((ULONG)pBulkBuffer->Register & 0x3)) 1141 ((ULONG)pBulkBuffer->Register & 0x3))
1277 { 1142 {
1278 bcm_kfree(pvBuffer); 1143 kfree(pvBuffer);
1279 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"WRM Done On invalid Address : %x Access Denied.\n",(int)pBulkBuffer->Register); 1144 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"WRM Done On invalid Address : %x Access Denied.\n",(int)pBulkBuffer->Register);
1280 Status = -EINVAL; 1145 Status = -EINVAL;
1281 break; 1146 break;
@@ -1290,7 +1155,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1290 (uiTempVar == EEPROM_REJECT_REG_4)) && 1155 (uiTempVar == EEPROM_REJECT_REG_4)) &&
1291 (cmd == IOCTL_BCM_REGISTER_WRITE)) 1156 (cmd == IOCTL_BCM_REGISTER_WRITE))
1292 { 1157 {
1293 bcm_kfree(pvBuffer); 1158 kfree(pvBuffer);
1294 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"EEPROM Access Denied, not in VSG Mode\n"); 1159 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0,"EEPROM Access Denied, not in VSG Mode\n");
1295 Status = -EFAULT; 1160 Status = -EFAULT;
1296 break; 1161 break;
@@ -1306,30 +1171,19 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1306 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n"); 1171 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1307 } 1172 }
1308 1173
1309 bcm_kfree(pvBuffer); 1174 kfree(pvBuffer);
1310 break; 1175 break;
1311 } 1176 }
1312 1177
1313 case IOCTL_BCM_GET_NVM_SIZE: 1178 case IOCTL_BCM_GET_NVM_SIZE:
1314 {
1315
1316 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) 1179 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1317 { 1180 return -EFAULT;
1318 //IOLog("failed NVM first"); 1181
1319 Status = -EFAULT;
1320 break;
1321 }
1322 if(Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH ) { 1182 if(Adapter->eNVMType == NVM_EEPROM || Adapter->eNVMType == NVM_FLASH ) {
1323 if(copy_to_user(IoBuffer.OutputBuffer, 1183 if(copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiNVMDSDSize, sizeof(UINT)))
1324 (unsigned char *)&Adapter->uiNVMDSDSize, (UINT)sizeof(UINT))) 1184 return -EFAULT;
1325 {
1326 Status = -EFAULT;
1327 return Status;
1328 }
1329 } 1185 }
1330
1331 Status = STATUS_SUCCESS ; 1186 Status = STATUS_SUCCESS ;
1332 }
1333 break; 1187 break;
1334 1188
1335 case IOCTL_BCM_CAL_INIT : 1189 case IOCTL_BCM_CAL_INIT :
@@ -1338,40 +1192,26 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1338 UINT uiSectorSize = 0 ; 1192 UINT uiSectorSize = 0 ;
1339 if(Adapter->eNVMType == NVM_FLASH) 1193 if(Adapter->eNVMType == NVM_FLASH)
1340 { 1194 {
1341 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); 1195 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1342 if(Status)
1343 {
1344 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy From User space failed. status :%d", Status);
1345 return -EFAULT; 1196 return -EFAULT;
1346 } 1197
1347 if (get_user(uiSectorSize, (unsigned int __user *)IoBuffer.InputBuffer)) 1198 if (copy_from_user(&uiSectorSize, IoBuffer.InputBuffer, sizeof(UINT)))
1348 return -EFAULT; 1199 return -EFAULT;
1349 1200
1350 if((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE)) 1201 if((uiSectorSize < MIN_SECTOR_SIZE) || (uiSectorSize > MAX_SECTOR_SIZE))
1351 { 1202 {
1352 1203 if (copy_to_user(IoBuffer.OutputBuffer, &Adapter->uiSectorSize,
1353 Status = copy_to_user(IoBuffer.OutputBuffer, 1204 sizeof(UINT)))
1354 (unsigned char *)&Adapter->uiSectorSize , 1205 return -EFAULT;
1355 (UINT)sizeof(UINT));
1356 if(Status)
1357 {
1358 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Coping the sector size to use space failed. status:%d",Status);
1359 return -EFAULT;
1360 }
1361 } 1206 }
1362 else 1207 else
1363 { 1208 {
1364 if(IsFlash2x(Adapter)) 1209 if(IsFlash2x(Adapter))
1365 { 1210 {
1366 Status = copy_to_user(IoBuffer.OutputBuffer, 1211 if (copy_to_user(IoBuffer.OutputBuffer,
1367 (unsigned char *)&Adapter->uiSectorSize , 1212 &Adapter->uiSectorSize ,
1368 (UINT)sizeof(UINT)); 1213 sizeof(UINT)))
1369 if(Status) 1214 return -EFAULT;
1370 {
1371 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Coping the sector size to use space failed. status:%d",Status);
1372 return -EFAULT;
1373 }
1374
1375 } 1215 }
1376 else 1216 else
1377 { 1217 {
@@ -1395,25 +1235,19 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1395 } 1235 }
1396 break; 1236 break;
1397 case IOCTL_BCM_SET_DEBUG : 1237 case IOCTL_BCM_SET_DEBUG :
1238#ifdef DEBUG
1398 { 1239 {
1399 USER_BCM_DBG_STATE sUserDebugState; 1240 USER_BCM_DBG_STATE sUserDebugState;
1400 1241
1401// BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Entered the ioctl %x \n", IOCTL_BCM_SET_DEBUG ); 1242// BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Entered the ioctl %x \n", IOCTL_BCM_SET_DEBUG );
1402 1243
1403 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n"); 1244 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1404 Status = copy_from_user((PCHAR)&IoBuffer, argp, sizeof(IOCTL_BUFFER)); 1245 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1405 if(Status)
1406 {
1407 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy from user failed\n");
1408 Status = -EFAULT;
1409 break;
1410 }
1411 Status = copy_from_user(&sUserDebugState,IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE));
1412 if(Status)
1413 {
1414 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "Copy of IoBuffer.InputBuffer failed");
1415 return -EFAULT; 1246 return -EFAULT;
1416 } 1247
1248 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE)))
1249 return -EFAULT;
1250
1417 1251
1418 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ", 1252 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1419 sUserDebugState.OnOff, sUserDebugState.Type); 1253 sUserDebugState.OnOff, sUserDebugState.Type);
@@ -1436,15 +1270,14 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1436 BCM_SHOW_DEBUG_BITMAP(Adapter); 1270 BCM_SHOW_DEBUG_BITMAP(Adapter);
1437 1271
1438 } 1272 }
1273#endif
1439 break; 1274 break;
1440 case IOCTL_BCM_NVM_READ: 1275 case IOCTL_BCM_NVM_READ:
1441 case IOCTL_BCM_NVM_WRITE: 1276 case IOCTL_BCM_NVM_WRITE:
1442 { 1277 {
1443 1278 NVM_READWRITE stNVMReadWrite;
1444 NVM_READWRITE stNVMReadWrite = {};
1445 PUCHAR pReadData = NULL; 1279 PUCHAR pReadData = NULL;
1446 void __user * pBuffertobeCopied = NULL; 1280 ULONG ulDSDMagicNumInUsrBuff = 0;
1447 ULONG ulDSDMagicNumInUsrBuff = 0 ;
1448 struct timeval tv0, tv1; 1281 struct timeval tv0, tv1;
1449 memset(&tv0,0,sizeof(struct timeval)); 1282 memset(&tv0,0,sizeof(struct timeval));
1450 memset(&tv1,0,sizeof(struct timeval)); 1283 memset(&tv1,0,sizeof(struct timeval));
@@ -1469,21 +1302,12 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1469 /* Copy Ioctl Buffer structure */ 1302 /* Copy Ioctl Buffer structure */
1470 1303
1471 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER))) 1304 if(copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1472 { 1305 return -EFAULT;
1473 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"copy_from_user failed\n");
1474 Status = -EFAULT;
1475 break;
1476 }
1477 if(IOCTL_BCM_NVM_READ == cmd)
1478 pBuffertobeCopied = IoBuffer.OutputBuffer;
1479 else
1480 pBuffertobeCopied = IoBuffer.InputBuffer;
1481 1306
1482 if(copy_from_user(&stNVMReadWrite, pBuffertobeCopied,sizeof(NVM_READWRITE))) 1307 if(copy_from_user(&stNVMReadWrite,
1483 { 1308 (IOCTL_BCM_NVM_READ == cmd) ? IoBuffer.OutputBuffer : IoBuffer.InputBuffer,
1484 Status = -EFAULT; 1309 sizeof(NVM_READWRITE)))
1485 break; 1310 return -EFAULT;
1486 }
1487 1311
1488 // 1312 //
1489 // Deny the access if the offset crosses the cal area limit. 1313 // Deny the access if the offset crosses the cal area limit.
@@ -1496,18 +1320,15 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1496 break; 1320 break;
1497 } 1321 }
1498 1322
1499 pReadData =(PCHAR)kmalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL); 1323 pReadData = kzalloc(stNVMReadWrite.uiNumBytes, GFP_KERNEL);
1500
1501 if(!pReadData) 1324 if(!pReadData)
1502 return -ENOMEM; 1325 return -ENOMEM;
1503 1326
1504 memset(pReadData,0,stNVMReadWrite.uiNumBytes);
1505
1506 if(copy_from_user(pReadData, stNVMReadWrite.pBuffer, 1327 if(copy_from_user(pReadData, stNVMReadWrite.pBuffer,
1507 stNVMReadWrite.uiNumBytes)) 1328 stNVMReadWrite.uiNumBytes))
1508 { 1329 {
1509 Status = -EFAULT; 1330 Status = -EFAULT;
1510 bcm_kfree(pReadData); 1331 kfree(pReadData);
1511 break; 1332 break;
1512 } 1333 }
1513 1334
@@ -1522,7 +1343,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1522 { 1343 {
1523 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n"); 1344 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1524 up(&Adapter->NVMRdmWrmLock); 1345 up(&Adapter->NVMRdmWrmLock);
1525 bcm_kfree(pReadData); 1346 kfree(pReadData);
1526 return -EACCES; 1347 return -EACCES;
1527 } 1348 }
1528 1349
@@ -1533,13 +1354,12 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1533 1354
1534 if(Status != STATUS_SUCCESS) 1355 if(Status != STATUS_SUCCESS)
1535 { 1356 {
1536 bcm_kfree(pReadData); 1357 kfree(pReadData);
1537 return Status; 1358 return Status;
1538 } 1359 }
1539 if(copy_to_user(stNVMReadWrite.pBuffer, 1360 if(copy_to_user(stNVMReadWrite.pBuffer,pReadData, stNVMReadWrite.uiNumBytes))
1540 pReadData, (UINT)stNVMReadWrite.uiNumBytes))
1541 { 1361 {
1542 bcm_kfree(pReadData); 1362 kfree(pReadData);
1543 Status = -EFAULT; 1363 Status = -EFAULT;
1544 } 1364 }
1545 } 1365 }
@@ -1554,7 +1374,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1554 { 1374 {
1555 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n"); 1375 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1556 up(&Adapter->NVMRdmWrmLock); 1376 up(&Adapter->NVMRdmWrmLock);
1557 bcm_kfree(pReadData); 1377 kfree(pReadData);
1558 return -EACCES; 1378 return -EACCES;
1559 } 1379 }
1560 1380
@@ -1582,7 +1402,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1582 { 1402 {
1583 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input.."); 1403 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
1584 up(&Adapter->NVMRdmWrmLock); 1404 up(&Adapter->NVMRdmWrmLock);
1585 bcm_kfree(pReadData); 1405 kfree(pReadData);
1586 return Status; 1406 return Status;
1587 } 1407 }
1588 1408
@@ -1591,7 +1411,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1591 { 1411 {
1592 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input.."); 1412 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"DSD Sig is present neither in Flash nor User provided Input..");
1593 up(&Adapter->NVMRdmWrmLock); 1413 up(&Adapter->NVMRdmWrmLock);
1594 bcm_kfree(pReadData); 1414 kfree(pReadData);
1595 return Status; 1415 return Status;
1596 } 1416 }
1597 } 1417 }
@@ -1608,7 +1428,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1608 1428
1609 if(Status != STATUS_SUCCESS) 1429 if(Status != STATUS_SUCCESS)
1610 { 1430 {
1611 bcm_kfree(pReadData); 1431 kfree(pReadData);
1612 return Status; 1432 return Status;
1613 } 1433 }
1614 } 1434 }
@@ -1616,7 +1436,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1616 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " timetaken by Write/read :%ld msec\n",(tv1.tv_sec - tv0.tv_sec)*1000 +(tv1.tv_usec - tv0.tv_usec)/1000); 1436 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " timetaken by Write/read :%ld msec\n",(tv1.tv_sec - tv0.tv_sec)*1000 +(tv1.tv_usec - tv0.tv_usec)/1000);
1617 1437
1618 1438
1619 bcm_kfree(pReadData); 1439 kfree(pReadData);
1620 Status = STATUS_SUCCESS; 1440 Status = STATUS_SUCCESS;
1621 } 1441 }
1622 break; 1442 break;
@@ -1629,7 +1449,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1629 UINT BuffSize = 0; 1449 UINT BuffSize = 0;
1630 UINT ReadBytes = 0; 1450 UINT ReadBytes = 0;
1631 UINT ReadOffset = 0; 1451 UINT ReadOffset = 0;
1632 char __user *OutPutBuff = NULL; 1452 void __user *OutPutBuff;
1633 1453
1634 if(IsFlash2x(Adapter) != TRUE) 1454 if(IsFlash2x(Adapter) != TRUE)
1635 { 1455 {
@@ -1638,20 +1458,12 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1638 } 1458 }
1639 1459
1640 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called"); 1460 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1641 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); 1461 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1642 if(Status)
1643 {
1644 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1645 return -EFAULT; 1462 return -EFAULT;
1646 }
1647 1463
1648 //Reading FLASH 2.x READ structure 1464 //Reading FLASH 2.x READ structure
1649 Status = copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer,sizeof(FLASH2X_READWRITE)); 1465 if (copy_from_user(&sFlash2xRead, IoBuffer.InputBuffer,sizeof(FLASH2X_READWRITE)))
1650 if(Status)
1651 {
1652 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of Input Buffer failed");
1653 return -EFAULT; 1466 return -EFAULT;
1654 }
1655 1467
1656 1468
1657 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xRead.Section); 1469 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xRead.Section);
@@ -1687,7 +1499,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1687 { 1499 {
1688 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n"); 1500 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1689 up(&Adapter->NVMRdmWrmLock); 1501 up(&Adapter->NVMRdmWrmLock);
1690 bcm_kfree(pReadBuff); 1502 kfree(pReadBuff);
1691 return -EACCES; 1503 return -EACCES;
1692 } 1504 }
1693 1505
@@ -1715,7 +1527,6 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1715 if(Status) 1527 if(Status)
1716 { 1528 {
1717 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Copy to use failed with status :%d", Status); 1529 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Copy to use failed with status :%d", Status);
1718 Status = -EFAULT;
1719 break; 1530 break;
1720 } 1531 }
1721 NOB = NOB - ReadBytes; 1532 NOB = NOB - ReadBytes;
@@ -1727,15 +1538,15 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1727 1538
1728 } 1539 }
1729 up(&Adapter->NVMRdmWrmLock); 1540 up(&Adapter->NVMRdmWrmLock);
1730 bcm_kfree(pReadBuff); 1541 kfree(pReadBuff);
1731 1542
1732 } 1543 }
1733 break ; 1544 break ;
1734 case IOCTL_BCM_FLASH2X_SECTION_WRITE : 1545 case IOCTL_BCM_FLASH2X_SECTION_WRITE :
1735 { 1546 {
1736 FLASH2X_READWRITE sFlash2xWrite = {0}; 1547 FLASH2X_READWRITE sFlash2xWrite = {0};
1737 PUCHAR pWriteBuff = NULL; 1548 PUCHAR pWriteBuff;
1738 void __user *InputAddr = NULL; 1549 void __user *InputAddr;
1739 UINT NOB = 0; 1550 UINT NOB = 0;
1740 UINT BuffSize = 0; 1551 UINT BuffSize = 0;
1741 UINT WriteOffset = 0; 1552 UINT WriteOffset = 0;
@@ -1752,33 +1563,17 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1752 1563
1753 1564
1754 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_FLASH2X_SECTION_WRITE Called"); 1565 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, " IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1755 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); 1566 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1756 if(Status)
1757 {
1758 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1759 return -EFAULT; 1567 return -EFAULT;
1760 }
1761 1568
1762 //Reading FLASH 2.x READ structure 1569 //Reading FLASH 2.x READ structure
1763 Status = copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE)); 1570 if (copy_from_user(&sFlash2xWrite, IoBuffer.InputBuffer, sizeof(FLASH2X_READWRITE)))
1764 if(Status)
1765 {
1766 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Reading of output Buffer from IOCTL buffer fails");
1767 return -EFAULT; 1571 return -EFAULT;
1768 }
1769 1572
1770 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xWrite.Section); 1573 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.Section :%x" ,sFlash2xWrite.Section);
1771 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%d" ,sFlash2xWrite.offset); 1574 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.offset :%d" ,sFlash2xWrite.offset);
1772 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xWrite.numOfBytes); 1575 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.numOfBytes :%x" ,sFlash2xWrite.numOfBytes);
1773 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xWrite.bVerify); 1576 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\nsFlash2xRead.bVerify :%x\n" ,sFlash2xWrite.bVerify);
1774 #if 0
1775 if((sFlash2xWrite.Section == ISO_IMAGE1) ||(sFlash2xWrite.Section == ISO_IMAGE2) ||
1776 (sFlash2xWrite.Section == DSD0) || (sFlash2xWrite.Section == DSD1) || (sFlash2xWrite.Section == DSD2))
1777 {
1778 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"ISO/DSD Image write is not allowed.... ");
1779 return STATUS_FAILURE ;
1780 }
1781 #endif
1782 if((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) && 1577 if((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1) &&
1783 (sFlash2xWrite.Section != VSA2) ) 1578 (sFlash2xWrite.Section != VSA2) )
1784 { 1579 {
@@ -1798,12 +1593,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1798 else 1593 else
1799 BuffSize = NOB ; 1594 BuffSize = NOB ;
1800 1595
1801 pWriteBuff = (PCHAR)kmalloc(BuffSize, GFP_KERNEL); 1596 pWriteBuff = kmalloc(BuffSize, GFP_KERNEL);
1802 if(pWriteBuff == NULL) 1597 if(pWriteBuff == NULL)
1803 {
1804 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
1805 return -ENOMEM; 1598 return -ENOMEM;
1806 } 1599
1807 1600
1808 //extracting the remainder of the given offset. 1601 //extracting the remainder of the given offset.
1809 WriteBytes = Adapter->uiSectorSize ; 1602 WriteBytes = Adapter->uiSectorSize ;
@@ -1820,7 +1613,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1820 { 1613 {
1821 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n"); 1614 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1822 up(&Adapter->NVMRdmWrmLock); 1615 up(&Adapter->NVMRdmWrmLock);
1823 bcm_kfree(pWriteBuff); 1616 kfree(pWriteBuff);
1824 return -EACCES; 1617 return -EACCES;
1825 } 1618 }
1826 1619
@@ -1831,7 +1624,6 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1831 if(Status) 1624 if(Status)
1832 { 1625 {
1833 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to user failed with status :%d", Status); 1626 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to user failed with status :%d", Status);
1834 Status = -EFAULT;
1835 break ; 1627 break ;
1836 } 1628 }
1837 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pWriteBuff,WriteBytes); 1629 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pWriteBuff,WriteBytes);
@@ -1859,28 +1651,22 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1859 } while(NOB > 0); 1651 } while(NOB > 0);
1860 BcmFlash2xWriteSig(Adapter,sFlash2xWrite.Section); 1652 BcmFlash2xWriteSig(Adapter,sFlash2xWrite.Section);
1861 up(&Adapter->NVMRdmWrmLock); 1653 up(&Adapter->NVMRdmWrmLock);
1862 bcm_kfree(pWriteBuff); 1654 kfree(pWriteBuff);
1863 } 1655 }
1864 break ; 1656 break ;
1865 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP : 1657 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP :
1866 { 1658 {
1867 1659
1868 PFLASH2X_BITMAP psFlash2xBitMap = NULL ; 1660 PFLASH2X_BITMAP psFlash2xBitMap;
1869 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called"); 1661 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1870 1662
1871 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); 1663 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
1872 if(Status)
1873 {
1874 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1875 return -EFAULT; 1664 return -EFAULT;
1876 } 1665
1877 if(IoBuffer.OutputLength != sizeof(FLASH2X_BITMAP)) 1666 if(IoBuffer.OutputLength != sizeof(FLASH2X_BITMAP))
1878 { 1667 return -EINVAL;
1879 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Structure size mismatch Lib :0x%lx Driver :0x%zx ",IoBuffer.OutputLength, sizeof(FLASH2X_BITMAP));
1880 break;
1881 }
1882 1668
1883 psFlash2xBitMap = (PFLASH2X_BITMAP)kzalloc(sizeof(FLASH2X_BITMAP), GFP_KERNEL); 1669 psFlash2xBitMap = kzalloc(sizeof(FLASH2X_BITMAP), GFP_KERNEL);
1884 if(psFlash2xBitMap == NULL) 1670 if(psFlash2xBitMap == NULL)
1885 { 1671 {
1886 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory is not available"); 1672 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory is not available");
@@ -1895,20 +1681,16 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1895 { 1681 {
1896 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n"); 1682 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
1897 up(&Adapter->NVMRdmWrmLock); 1683 up(&Adapter->NVMRdmWrmLock);
1898 bcm_kfree(psFlash2xBitMap); 1684 kfree(psFlash2xBitMap);
1899 return -EACCES; 1685 return -EACCES;
1900 } 1686 }
1901 1687
1902 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap); 1688 BcmGetFlash2xSectionalBitMap(Adapter, psFlash2xBitMap);
1903 up(&Adapter->NVMRdmWrmLock); 1689 up(&Adapter->NVMRdmWrmLock);
1904 Status = copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP)); 1690 if (copy_to_user(IoBuffer.OutputBuffer, psFlash2xBitMap, sizeof(FLASH2X_BITMAP)))
1905 if(Status) 1691 Status = -EFAULT;
1906 { 1692
1907 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copying Flash2x bitMap failed"); 1693 kfree(psFlash2xBitMap);
1908 bcm_kfree(psFlash2xBitMap);
1909 return -EFAULT;
1910 }
1911 bcm_kfree(psFlash2xBitMap);
1912 } 1694 }
1913 break ; 1695 break ;
1914 case IOCTL_BCM_SET_ACTIVE_SECTION : 1696 case IOCTL_BCM_SET_ACTIVE_SECTION :
@@ -1926,14 +1708,14 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1926 if(Status) 1708 if(Status)
1927 { 1709 {
1928 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed"); 1710 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
1929 return -EFAULT; 1711 return Status;
1930 } 1712 }
1931 1713
1932 Status = copy_from_user(&eFlash2xSectionVal,IoBuffer.InputBuffer, sizeof(INT)); 1714 Status = copy_from_user(&eFlash2xSectionVal,IoBuffer.InputBuffer, sizeof(INT));
1933 if(Status) 1715 if(Status)
1934 { 1716 {
1935 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed"); 1717 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
1936 return -EFAULT; 1718 return Status;
1937 } 1719 }
1938 1720
1939 down(&Adapter->NVMRdmWrmLock); 1721 down(&Adapter->NVMRdmWrmLock);
@@ -1961,29 +1743,6 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
1961 Adapter->bAllDSDWriteAllow = FALSE ; 1743 Adapter->bAllDSDWriteAllow = FALSE ;
1962 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called"); 1744 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
1963 1745
1964 #if 0
1965 SECTION_TYPE section = 0 ;
1966
1967
1968 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION Called");
1969 Status = copy_from_user((PCHAR)&IoBuffer, (PCHAR)arg, sizeof(IOCTL_BUFFER));
1970 if(Status)
1971 {
1972 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy of IOCTL BUFFER failed");
1973 return -EFAULT;
1974 }
1975 Status = copy_from_user((PCHAR)section,(PCHAR)&IoBuffer, sizeof(INT));
1976 if(Status)
1977 {
1978 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Copy of section type failed failed");
1979 return -EFAULT;
1980 }
1981 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Read Section :%d", section);
1982 if(section == DSD)
1983 Adapter->ulFlashCalStart = Adapter->uiActiveDSDOffsetAtFwDld ;
1984 else
1985 Status = STATUS_FAILURE ;
1986 #endif
1987 Status = STATUS_SUCCESS ; 1746 Status = STATUS_SUCCESS ;
1988 } 1747 }
1989 break ; 1748 break ;
@@ -2004,14 +1763,14 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2004 if(Status) 1763 if(Status)
2005 { 1764 {
2006 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status); 1765 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed Status :%d", Status);
2007 return -EFAULT; 1766 return Status;
2008 } 1767 }
2009 1768
2010 Status = copy_from_user(&sCopySectStrut,IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION)); 1769 Status = copy_from_user(&sCopySectStrut, IoBuffer.InputBuffer, sizeof(FLASH2X_COPY_SECTION));
2011 if(Status) 1770 if(Status)
2012 { 1771 {
2013 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status); 1772 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of Copy_Section_Struct failed with Status :%d", Status);
2014 return -EFAULT; 1773 return Status;
2015 } 1774 }
2016 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection); 1775 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Source SEction :%x", sCopySectStrut.SrcSection);
2017 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection); 1776 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "Destination SEction :%x", sCopySectStrut.DstSection);
@@ -2082,7 +1841,6 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2082 if(Status) 1841 if(Status)
2083 { 1842 {
2084 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed"); 1843 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2085 Status = -EFAULT;
2086 break; 1844 break;
2087 } 1845 }
2088 if(Adapter->eNVMType != NVM_FLASH) 1846 if(Adapter->eNVMType != NVM_FLASH)
@@ -2095,35 +1853,18 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2095 { 1853 {
2096 1854
2097 if(IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO)) 1855 if(IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO))
2098 { 1856 return -EINVAL;
2099 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0," Passed buffer size:0x%lX is insufficient for the CS structure.. \nRequired size :0x%zx ",IoBuffer.OutputLength, sizeof(FLASH2X_CS_INFO));
2100 Status = -EINVAL;
2101 break;
2102 }
2103 1857
2104 Status = copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO)); 1858 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO)))
2105 if(Status) 1859 return -EFAULT;
2106 {
2107 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copying Flash2x cs info failed");
2108 Status = -EFAULT;
2109 break;
2110 }
2111 } 1860 }
2112 else 1861 else
2113 { 1862 {
2114 if(IoBuffer.OutputLength < sizeof(FLASH_CS_INFO)) 1863 if(IoBuffer.OutputLength < sizeof(FLASH_CS_INFO))
2115 { 1864 return -EINVAL;
2116 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0," Passed buffer size:0x%lX is insufficient for the CS structure.. Required size :0x%zx ",IoBuffer.OutputLength, sizeof(FLASH_CS_INFO)); 1865
2117 Status = -EINVAL; 1866 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO)))
2118 break; 1867 return -EFAULT;
2119 }
2120 Status = copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO));
2121 if(Status)
2122 {
2123 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "copying Flash CS info failed");
2124 Status = -EFAULT;
2125 break;
2126 }
2127 1868
2128 } 1869 }
2129 } 1870 }
@@ -2145,13 +1886,13 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2145 if(Status) 1886 if(Status)
2146 { 1887 {
2147 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed"); 1888 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2148 return -EFAULT; 1889 return Status;
2149 } 1890 }
2150 Status = copy_from_user(&eFlash2xSectionVal,IoBuffer.InputBuffer, sizeof(INT)); 1891 Status = copy_from_user(&eFlash2xSectionVal, IoBuffer.InputBuffer, sizeof(INT));
2151 if(Status) 1892 if(Status)
2152 { 1893 {
2153 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed"); 1894 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of flash section val failed");
2154 return -EFAULT; 1895 return Status;
2155 } 1896 }
2156 1897
2157 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Read Section :%d", eFlash2xSectionVal); 1898 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Read Section :%d", eFlash2xSectionVal);
@@ -2181,13 +1922,13 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2181 case IOCTL_BCM_NVM_RAW_READ : 1922 case IOCTL_BCM_NVM_RAW_READ :
2182 { 1923 {
2183 1924
2184 NVM_READWRITE stNVMRead = {}; 1925 NVM_READWRITE stNVMRead;
2185 INT NOB ; 1926 INT NOB ;
2186 INT BuffSize ; 1927 INT BuffSize ;
2187 INT ReadOffset = 0; 1928 INT ReadOffset = 0;
2188 UINT ReadBytes = 0 ; 1929 UINT ReadBytes = 0 ;
2189 PUCHAR pReadBuff = NULL ; 1930 PUCHAR pReadBuff;
2190 char __user *OutPutBuff = NULL ; 1931 void __user *OutPutBuff;
2191 1932
2192 if(Adapter->eNVMType != NVM_FLASH) 1933 if(Adapter->eNVMType != NVM_FLASH)
2193 { 1934 {
@@ -2204,10 +1945,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2204 } 1945 }
2205 1946
2206 if(copy_from_user(&stNVMRead, IoBuffer.OutputBuffer,sizeof(NVM_READWRITE))) 1947 if(copy_from_user(&stNVMRead, IoBuffer.OutputBuffer,sizeof(NVM_READWRITE)))
2207 { 1948 return -EFAULT;
2208 Status = -EFAULT;
2209 break;
2210 }
2211 1949
2212 NOB = stNVMRead.uiNumBytes; 1950 NOB = stNVMRead.uiNumBytes;
2213 //In Raw-Read max Buff size : 64MB 1951 //In Raw-Read max Buff size : 64MB
@@ -2217,11 +1955,10 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2217 else 1955 else
2218 BuffSize = NOB ; 1956 BuffSize = NOB ;
2219 1957
2220 ReadOffset = stNVMRead.uiOffset ; 1958 ReadOffset = stNVMRead.uiOffset;
2221 OutPutBuff = stNVMRead.pBuffer; 1959 OutPutBuff = stNVMRead.pBuffer;
2222 1960
2223 1961 pReadBuff = kzalloc(BuffSize , GFP_KERNEL);
2224 pReadBuff = (PCHAR)kzalloc(BuffSize , GFP_KERNEL);
2225 if(pReadBuff == NULL) 1962 if(pReadBuff == NULL)
2226 { 1963 {
2227 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure"); 1964 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Memory allocation failed for Flash 2.x Read Structure");
@@ -2235,7 +1972,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2235 (Adapter->bPreparingForLowPowerMode ==TRUE)) 1972 (Adapter->bPreparingForLowPowerMode ==TRUE))
2236 { 1973 {
2237 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n"); 1974 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"Device is in Idle/Shutdown Mode\n");
2238 bcm_kfree(pReadBuff); 1975 kfree(pReadBuff);
2239 up(&Adapter->NVMRdmWrmLock); 1976 up(&Adapter->NVMRdmWrmLock);
2240 return -EACCES; 1977 return -EACCES;
2241 } 1978 }
@@ -2256,13 +1993,12 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2256 break; 1993 break;
2257 } 1994 }
2258 1995
2259 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff, ReadBytes); 1996 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,pReadBuff,ReadBytes);
2260 1997
2261 Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes); 1998 Status = copy_to_user(OutPutBuff, pReadBuff,ReadBytes);
2262 if(Status) 1999 if(Status)
2263 { 2000 {
2264 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to use failed with status :%d", Status); 2001 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Copy to use failed with status :%d", Status);
2265 Status = -EFAULT;
2266 break; 2002 break;
2267 } 2003 }
2268 NOB = NOB - ReadBytes; 2004 NOB = NOB - ReadBytes;
@@ -2275,7 +2011,7 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2275 } 2011 }
2276 Adapter->bFlashRawRead = FALSE ; 2012 Adapter->bFlashRawRead = FALSE ;
2277 up(&Adapter->NVMRdmWrmLock); 2013 up(&Adapter->NVMRdmWrmLock);
2278 bcm_kfree(pReadBuff); 2014 kfree(pReadBuff);
2279 break ; 2015 break ;
2280 } 2016 }
2281 2017
@@ -2288,7 +2024,6 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2288 if(Status) 2024 if(Status)
2289 { 2025 {
2290 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of Ioctl buffer is failed from user space"); 2026 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of Ioctl buffer is failed from user space");
2291 Status = -EFAULT;
2292 break; 2027 break;
2293 } 2028 }
2294 2029
@@ -2296,7 +2031,6 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2296 if(Status) 2031 if(Status)
2297 { 2032 {
2298 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of control bit mask failed from user space"); 2033 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"copy of control bit mask failed from user space");
2299 Status = -EFAULT;
2300 break; 2034 break;
2301 } 2035 }
2302 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask); 2036 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"\n Got user defined cntrl msg bit mask :%lx", RxCntrlMsgBitMask);
@@ -2315,71 +2049,44 @@ static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2315 DevInfo.u32NVMType = Adapter->eNVMType; 2049 DevInfo.u32NVMType = Adapter->eNVMType;
2316 DevInfo.u32InterfaceType = BCM_USB; 2050 DevInfo.u32InterfaceType = BCM_USB;
2317 2051
2318 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); 2052 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
2319 if(Status) 2053 return -EFAULT;
2320 { 2054
2321 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2322 Status = -EFAULT;
2323 break;
2324 }
2325 if(IoBuffer.OutputLength < sizeof(DevInfo)) 2055 if(IoBuffer.OutputLength < sizeof(DevInfo))
2326 { 2056 return -EINVAL;
2327 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"User Passed buffer length is less than actural buffer size"); 2057
2328 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"user passed buffer size :0x%lX, expected size :0x%zx",IoBuffer.OutputLength, sizeof(DevInfo)); 2058 if (copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo)))
2329 Status = -EINVAL; 2059 return -EFAULT;
2330 break;
2331 }
2332 Status = copy_to_user(IoBuffer.OutputBuffer, &DevInfo, sizeof(DevInfo));
2333 if(Status)
2334 {
2335 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"copying Dev info structure to user space buffer failed");
2336 Status = -EFAULT;
2337 break;
2338 }
2339 } 2060 }
2340 break ; 2061 break ;
2341 2062
2342 case IOCTL_BCM_TIME_SINCE_NET_ENTRY: 2063 case IOCTL_BCM_TIME_SINCE_NET_ENTRY:
2343 { 2064 {
2344 ST_TIME_ELAPSED stTimeElapsedSinceNetEntry = {0}; 2065 ST_TIME_ELAPSED stTimeElapsedSinceNetEntry = {0};
2345 struct timeval tv = {0} ;
2346 2066
2347 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_TIME_SINCE_NET_ENTRY called"); 2067 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
2348 2068
2349 Status = copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)); 2069 if (copy_from_user(&IoBuffer, argp, sizeof(IOCTL_BUFFER)))
2350 if(Status) 2070 return -EFAULT;
2351 { 2071
2352 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Copy of IOCTL BUFFER failed");
2353 Status = -EFAULT;
2354 break;
2355 }
2356 if(IoBuffer.OutputLength < sizeof(ST_TIME_ELAPSED)) 2072 if(IoBuffer.OutputLength < sizeof(ST_TIME_ELAPSED))
2357 { 2073 return -EINVAL;
2358 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"User Passed buffer length:0x%lx is less than expected buff size :0x%zX",IoBuffer.OutputLength,sizeof(ST_TIME_ELAPSED));
2359 Status = -EINVAL;
2360 break;
2361 }
2362 2074
2363 //stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = Adapter->liTimeSinceLastNetEntry; 2075 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = get_seconds() - Adapter->liTimeSinceLastNetEntry;
2364 do_gettimeofday(&tv);
2365 stTimeElapsedSinceNetEntry.ul64TimeElapsedSinceNetEntry = tv.tv_sec - Adapter->liTimeSinceLastNetEntry;
2366 2076
2367 Status = copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(ST_TIME_ELAPSED)); 2077 if (copy_to_user(IoBuffer.OutputBuffer, &stTimeElapsedSinceNetEntry, sizeof(ST_TIME_ELAPSED)))
2368 if(Status) 2078 return -EFAULT;
2369 {
2370 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"copying ST_TIME_ELAPSED structure to user space buffer failed");
2371 Status = -EFAULT;
2372 break;
2373 }
2374 2079
2375 } 2080 }
2376 break; 2081 break;
2377 2082
2378 default: 2083 case IOCTL_CLOSE_NOTIFICATION:
2379 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "wrong input %x",cmd); 2084 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,"IOCTL_CLOSE_NOTIFICATION");
2380 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In default ioctl %d\n", cmd); 2085 break;
2381 Status = STATUS_FAILURE;
2382 2086
2087 default:
2088 pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
2089 Status = STATUS_FAILURE;
2383 break; 2090 break;
2384 } 2091 }
2385 return Status; 2092 return Status;
@@ -2395,59 +2102,37 @@ static struct file_operations bcm_fops = {
2395 .llseek = no_llseek, 2102 .llseek = no_llseek,
2396}; 2103};
2397 2104
2105extern struct class *bcm_class;
2398 2106
2399int register_control_device_interface(PMINI_ADAPTER Adapter) 2107int register_control_device_interface(PMINI_ADAPTER Adapter)
2400{ 2108{
2109
2401 if(Adapter->major>0) 2110 if(Adapter->major>0)
2402 return Adapter->major; 2111 return Adapter->major;
2403 Adapter->major = register_chrdev(0, "tarang", &bcm_fops); 2112
2404 if(Adapter->major < 0) 2113 Adapter->major = register_chrdev(0, DEV_NAME, &bcm_fops);
2405 { 2114 if(Adapter->major < 0) {
2406 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "register_chrdev:Failed to registering WiMax control char device!"); 2115 pr_err(DRV_NAME ": could not created character device\n");
2407 return Adapter->major; 2116 return Adapter->major;
2408 }
2409
2410 bcm_class = NULL;
2411 bcm_class = class_create (THIS_MODULE, "tarang");
2412 if(IS_ERR (bcm_class))
2413 {
2414 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Unable to create class\n");
2415 unregister_chrdev(Adapter->major, "tarang");
2416 Adapter->major = 0;
2417 return -ENODEV;
2418 } 2117 }
2118
2419 Adapter->pstCreatedClassDevice = device_create (bcm_class, NULL, 2119 Adapter->pstCreatedClassDevice = device_create (bcm_class, NULL,
2420 MKDEV(Adapter->major, 0), 2120 MKDEV(Adapter->major, 0), Adapter,
2421#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26) 2121 DEV_NAME);
2422 NULL ,
2423#endif
2424 "tarang");
2425 2122
2426 if(IS_ERR(Adapter->pstCreatedClassDevice)) 2123 if(IS_ERR(Adapter->pstCreatedClassDevice)) {
2427 { 2124 pr_err(DRV_NAME ": class device create failed\n");
2428 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "class device did not get created : %ld", PTR_ERR(Adapter->pstCreatedClassDevice) ); 2125 unregister_chrdev(Adapter->major, DEV_NAME);
2126 return PTR_ERR(Adapter->pstCreatedClassDevice);
2429 } 2127 }
2430 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Got Major No: %d", Adapter->major); 2128
2431 return 0; 2129 return 0;
2432} 2130}
2433 2131
2434void unregister_control_device_interface(PMINI_ADAPTER Adapter) 2132void unregister_control_device_interface(PMINI_ADAPTER Adapter)
2435{ 2133{
2436 if(Adapter->major > 0) 2134 if(Adapter->major > 0) {
2437 {
2438 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "destroying class device");
2439 device_destroy (bcm_class, MKDEV(Adapter->major, 0)); 2135 device_destroy (bcm_class, MKDEV(Adapter->major, 0));
2136 unregister_chrdev(Adapter->major, DEV_NAME);
2440 } 2137 }
2441 if(!IS_ERR(bcm_class))
2442 {
2443 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "destroying created class ");
2444 class_destroy (bcm_class);
2445 bcm_class = NULL;
2446 }
2447 if(Adapter->major > 0)
2448 {
2449 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"unregistering character interface");
2450 unregister_chrdev(Adapter->major, "tarang");
2451 }
2452
2453} 2138}
diff --git a/drivers/staging/bcm/Bcmnet.c b/drivers/staging/bcm/Bcmnet.c
index bc2969821421..a6ce2396c791 100644
--- a/drivers/staging/bcm/Bcmnet.c
+++ b/drivers/staging/bcm/Bcmnet.c
@@ -1,264 +1,238 @@
1#include "headers.h" 1#include "headers.h"
2 2
3static INT bcm_notify_event(struct notifier_block *nb, ULONG event, PVOID dev) 3struct net_device *gblpnetdev;
4
5static INT bcm_open(struct net_device *dev)
4{ 6{
5 struct net_device *ndev = (struct net_device*)dev; 7 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
6 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 8
7 //PMINI_ADAPTER Adapter = (PMINI_ADAPTER)ndev->priv; 9 if (Adapter->fw_download_done == FALSE) {
8 if(strncmp(ndev->name,gblpnetdev->name,5)==0) 10 pr_notice(PFX "%s: link up failed (download in progress)\n",
9 { 11 dev->name);
10 switch(event) 12 return -EBUSY;
11 {
12 case NETDEV_CHANGEADDR:
13 case NETDEV_GOING_DOWN:
14 /*ignore this */
15 break;
16 case NETDEV_DOWN:
17 break;
18
19 case NETDEV_UP:
20 break;
21
22 case NETDEV_REGISTER:
23 /* Increment the Reference Count for "veth0" */
24 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Register RefCount: %x\n",
25 netdev_refcnt_read(ndev));
26 dev_hold(ndev);
27 break;
28
29 case NETDEV_UNREGISTER:
30 /* Decrement the Reference Count for "veth0" */
31 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Unregister RefCnt: %x\n",
32 netdev_refcnt_read(ndev));
33 dev_put(ndev);
34 break;
35 };
36 } 13 }
37 return NOTIFY_DONE;
38}
39 14
40/* Notifier block to receive netdevice events */ 15 if (netif_msg_ifup(Adapter))
41static struct notifier_block bcm_notifier_block = 16 pr_info(PFX "%s: enabling interface\n", dev->name);
42{
43 .notifier_call = bcm_notify_event,
44};
45 17
46struct net_device *gblpnetdev; 18 if (Adapter->LinkUpStatus) {
47/***************************************************************************************/ 19 if (netif_msg_link(Adapter))
48/* proto-type of lower function */ 20 pr_info(PFX "%s: link up\n", dev->name);
49#ifdef BCM_SHM_INTERFACE
50const char *bcmVirtDeviceName="bcmeth";
51#endif
52 21
53static INT bcm_open(struct net_device *dev) 22 netif_carrier_on(Adapter->dev);
54{ 23 netif_start_queue(Adapter->dev);
55 PMINI_ADAPTER Adapter = NULL ; //(PMINI_ADAPTER)dev->priv;
56 Adapter = GET_BCM_ADAPTER(dev);
57 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "======>");
58 if(Adapter->fw_download_done==FALSE)
59 return -EINVAL;
60 Adapter->if_up=1;
61 if(Adapter->LinkUpStatus == 1){
62 if(netif_queue_stopped(Adapter->dev)){
63 netif_carrier_on(Adapter->dev);
64 netif_start_queue(Adapter->dev);
65 }
66 } 24 }
67 25
68 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "<======"); 26 return 0;
69 return 0;
70} 27}
71 28
72static INT bcm_close(struct net_device *dev) 29static INT bcm_close(struct net_device *dev)
73{ 30{
74 PMINI_ADAPTER Adapter = NULL ;//gpadapter ; 31 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
75 Adapter = GET_BCM_ADAPTER(dev); 32
76 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "=====>"); 33 if (netif_msg_ifdown(Adapter))
77 Adapter->if_up=0; 34 pr_info(PFX "%s: disabling interface\n", dev->name);
78 if(!netif_queue_stopped(dev)) { 35
79 netif_carrier_off(dev); 36 netif_carrier_off(dev);
80 netif_stop_queue(dev); 37 netif_stop_queue(dev);
81 } 38
82 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"<====="); 39 return 0;
83 return 0; 40}
41
42static u16 bcm_select_queue(struct net_device *dev, struct sk_buff *skb)
43{
44 return ClassifyPacket(netdev_priv(dev), skb);
84} 45}
85 46
86static struct net_device_stats *bcm_get_stats(struct net_device *dev) 47/*******************************************************************
48* Function - bcm_transmit()
49*
50* Description - This is the main transmit function for our virtual
51* interface(eth0). It handles the ARP packets. It
52* clones this packet and then Queue it to a suitable
53* Queue. Then calls the transmit_packet().
54*
55* Parameter - skb - Pointer to the socket buffer structure
56* dev - Pointer to the virtual net device structure
57*
58*********************************************************************/
59
60static netdev_tx_t bcm_transmit(struct sk_buff *skb, struct net_device *dev)
87{ 61{
88 PLINUX_DEP_DATA pLinuxData=NULL; 62 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
89 PMINI_ADAPTER Adapter = NULL ;// gpadapter ; 63 u16 qindex = skb_get_queue_mapping(skb);
90 Adapter = GET_BCM_ADAPTER(dev); 64
91 pLinuxData = (PLINUX_DEP_DATA)(Adapter->pvOsDepData); 65
92 66 if (Adapter->device_removed || !Adapter->LinkUpStatus)
93 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Dev = %p, pLinuxData = %p", dev, pLinuxData); 67 goto drop;
94 pLinuxData->netstats.rx_packets=atomic_read(&Adapter->RxRollOverCount)*64*1024+Adapter->PrevNumRecvDescs; 68
95 pLinuxData->netstats.rx_bytes=atomic_read(&Adapter->GoodRxByteCount)+atomic_read(&Adapter->BadRxByteCount); 69 if (Adapter->TransferMode != IP_PACKET_ONLY_MODE)
96 pLinuxData->netstats.rx_dropped=atomic_read(&Adapter->RxPacketDroppedCount); 70 goto drop;
97 pLinuxData->netstats.rx_errors=atomic_read(&Adapter->RxPacketDroppedCount); 71
98 pLinuxData->netstats.rx_length_errors=0; 72 if (INVALID_QUEUE_INDEX == qindex)
99 pLinuxData->netstats.rx_frame_errors=0; 73 goto drop;
100 pLinuxData->netstats.rx_crc_errors=0; 74
101 pLinuxData->netstats.tx_bytes=atomic_read(&Adapter->GoodTxByteCount); 75 if (Adapter->PackInfo[qindex].uiCurrentPacketsOnHost >=
102 pLinuxData->netstats.tx_packets=atomic_read(&Adapter->TxTotalPacketCount); 76 SF_MAX_ALLOWED_PACKETS_TO_BACKUP)
103 pLinuxData->netstats.tx_dropped=atomic_read(&Adapter->TxDroppedPacketCount); 77 return NETDEV_TX_BUSY;
104 78
105 return &(pLinuxData->netstats); 79 /* Now Enqueue the packet */
80 if (netif_msg_tx_queued(Adapter))
81 pr_info(PFX "%s: enqueueing packet to queue %d\n",
82 dev->name, qindex);
83
84 spin_lock(&Adapter->PackInfo[qindex].SFQueueLock);
85 Adapter->PackInfo[qindex].uiCurrentBytesOnHost += skb->len;
86 Adapter->PackInfo[qindex].uiCurrentPacketsOnHost++;
87
88 *((B_UINT32 *) skb->cb + SKB_CB_LATENCY_OFFSET) = jiffies;
89 ENQUEUEPACKET(Adapter->PackInfo[qindex].FirstTxQueue,
90 Adapter->PackInfo[qindex].LastTxQueue, skb);
91 atomic_inc(&Adapter->TotalPacketCount);
92 spin_unlock(&Adapter->PackInfo[qindex].SFQueueLock);
93
94 /* FIXME - this is racy and incorrect, replace with work queue */
95 if (!atomic_read(&Adapter->TxPktAvail)) {
96 atomic_set(&Adapter->TxPktAvail, 1);
97 wake_up(&Adapter->tx_packet_wait_queue);
98 }
99 return NETDEV_TX_OK;
100
101 drop:
102 dev_kfree_skb(skb);
103 return NETDEV_TX_OK;
106} 104}
105
106
107
107/** 108/**
108@ingroup init_functions 109@ingroup init_functions
109Register other driver entry points with the kernel 110Register other driver entry points with the kernel
110*/ 111*/
111#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29) 112static const struct net_device_ops bcmNetDevOps = {
112static struct net_device_ops bcmNetDevOps = {
113 .ndo_open = bcm_open, 113 .ndo_open = bcm_open,
114 .ndo_stop = bcm_close, 114 .ndo_stop = bcm_close,
115 .ndo_get_stats = bcm_get_stats,
116 .ndo_start_xmit = bcm_transmit, 115 .ndo_start_xmit = bcm_transmit,
117 .ndo_change_mtu = eth_change_mtu, 116 .ndo_change_mtu = eth_change_mtu,
118 .ndo_set_mac_address = eth_mac_addr, 117 .ndo_set_mac_address = eth_mac_addr,
119 .ndo_validate_addr = eth_validate_addr, 118 .ndo_validate_addr = eth_validate_addr,
119 .ndo_select_queue = bcm_select_queue,
120}; 120};
121#endif
122 121
123int register_networkdev(PMINI_ADAPTER Adapter) 122static struct device_type wimax_type = {
123 .name = "wimax",
124};
125
126static int bcm_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
124{ 127{
125 int result=0; 128 cmd->supported = 0;
126#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) 129 cmd->advertising = 0;
127 void **temp = NULL; /* actually we're *allocating* the device in alloc_etherdev */ 130 cmd->speed = SPEED_10000;
128#endif 131 cmd->duplex = DUPLEX_FULL;
129 Adapter->dev = alloc_etherdev(sizeof(PMINI_ADAPTER)); 132 cmd->port = PORT_TP;
130 if(!Adapter->dev) 133 cmd->phy_address = 0;
131 { 134 cmd->transceiver = XCVR_INTERNAL;
132 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "ERR: No Dev"); 135 cmd->autoneg = AUTONEG_DISABLE;
133 return -ENOMEM; 136 cmd->maxtxpkt = 0;
134 } 137 cmd->maxrxpkt = 0;
135 gblpnetdev = Adapter->dev; 138 return 0;
136#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) 139}
137 Adapter->dev->priv = Adapter;
138#else
139 temp = netdev_priv(Adapter->dev);
140 *temp = (void *)Adapter;
141#endif
142 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "init adapterptr: %x %x\n", (UINT)Adapter, temp);
143
144#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
145 Adapter->dev->netdev_ops = &bcmNetDevOps;
146#else
147 Adapter->dev->open = bcm_open;
148 Adapter->dev->stop = bcm_close;
149 Adapter->dev->get_stats = bcm_get_stats;
150 Adapter->dev->hard_start_xmit = bcm_transmit;
151 Adapter->dev->hard_header_len = ETH_HLEN + LEADER_SIZE;
152#endif
153
154#ifndef BCM_SHM_INTERFACE
155 Adapter->dev->mtu = MTU_SIZE; /* 1400 Bytes */
156 /* Read the MAC Address from EEPROM */
157 ReadMacAddressFromNVM(Adapter);
158 140
141static void bcm_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
142{
143 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
144 PS_INTERFACE_ADAPTER psIntfAdapter = Adapter->pvInterfaceAdapter;
145 struct usb_device *udev = interface_to_usbdev(psIntfAdapter->interface);
159 146
160 /* Register the notifier block for getting netdevice events */ 147 strcpy(info->driver, DRV_NAME);
161 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Registering netdevice notifier\n"); 148 strcpy(info->version, DRV_VERSION);
162 result = register_netdevice_notifier(&bcm_notifier_block); 149 snprintf(info->fw_version, sizeof(info->fw_version), "%u.%u",
163 if(result) 150 Adapter->uiFlashLayoutMajorVersion,
164 { 151 Adapter->uiFlashLayoutMinorVersion);
165 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "BCM Notifier Block did not get registered");
166 Adapter->bNetdeviceNotifierRegistered = FALSE;
167 return result;
168 }
169 else
170 {
171 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "BCM Notifier got Registered");
172 Adapter->bNetdeviceNotifierRegistered = TRUE;
173 }
174 152
175#else 153 usb_make_path(udev, info->bus_info, sizeof(info->bus_info));
176 154}
177 Adapter->dev->mtu = CPE_MTU_SIZE;
178
179#if 0
180 //for CPE - harcode the virtual mac address
181 Adapter->dev->dev_addr[0] = MII_WIMAX_MACADDRESS[0];
182 Adapter->dev->dev_addr[1] = MII_WIMAX_MACADDRESS[1];
183 Adapter->dev->dev_addr[2] = MII_WIMAX_MACADDRESS[2];
184 Adapter->dev->dev_addr[3] = MII_WIMAX_MACADDRESS[3];
185 Adapter->dev->dev_addr[4] = MII_WIMAX_MACADDRESS[4];
186 Adapter->dev->dev_addr[5] = MII_WIMAX_MACADDRESS[5];
187#else
188 ReadMacAddressFromNVM(Adapter);
189#endif
190 strcpy(Adapter->dev->name, bcmVirtDeviceName); //Copy the device name
191
192#endif
193
194 result = register_netdev(Adapter->dev);
195 if (!result)
196 {
197 Adapter->bNetworkInterfaceRegistered = TRUE ;
198 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Beceem Network device name is %s!", Adapter->dev->name);
199 }
200 else
201 {
202 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Network device can not be registered!");
203 Adapter->bNetworkInterfaceRegistered = FALSE ;
204 return result;
205 }
206 155
207#if 0 156static u32 bcm_get_link(struct net_device *dev)
208 Adapter->stDebugState.debug_level = DBG_LVL_CURR; 157{
209 Adapter->stDebugState.type =(UINT)0xffffffff; 158 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
210 Adapter->stDebugState.subtype[DBG_TYPE_OTHERS] = 0xffffffff;
211 Adapter->stDebugState.subtype[DBG_TYPE_RX] = 0xffffffff;
212 Adapter->stDebugState.subtype[DBG_TYPE_TX] = 0xffffffff;
213 Adapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xffffffff;
214 159
215 printk("-------ps_adapter->stDebugState.type=%x\n",Adapter->stDebugState.type); 160 return Adapter->LinkUpStatus;
216 printk("-------ps_adapter->stDebugState.subtype[DBG_TYPE_OTHERS]=%x\n",Adapter->stDebugState.subtype[DBG_TYPE_OTHERS]); 161}
217 printk("-------ps_adapter->stDebugState.subtype[DBG_TYPE_RX]=%x\n",Adapter->stDebugState.subtype[DBG_TYPE_RX]);
218 printk("-------ps_adapter->stDebugState.subtype[DBG_TYPE_TX]=%x\n",Adapter->stDebugState.subtype[DBG_TYPE_TX]);
219#endif
220 162
221 return 0; 163static u32 bcm_get_msglevel (struct net_device *dev)
164{
165 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
166
167 return Adapter->msg_enable;
222} 168}
223 169
224void bcm_unregister_networkdev(PMINI_ADAPTER Adapter) 170static void bcm_set_msglevel (struct net_device *dev, u32 level)
225{ 171{
226 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Unregistering the Net Dev...\n"); 172 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(dev);
227 if(Adapter->dev && !IS_ERR(Adapter->dev) && Adapter->bNetworkInterfaceRegistered) 173
228 unregister_netdev(Adapter->dev); 174 Adapter->msg_enable = level;
229 /* Unregister the notifier block */
230 if(Adapter->bNetdeviceNotifierRegistered == TRUE)
231 {
232 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Unregistering netdevice notifier\n");
233 unregister_netdevice_notifier(&bcm_notifier_block);
234 }
235} 175}
236 176
237static int bcm_init(void) 177static const struct ethtool_ops bcm_ethtool_ops = {
178 .get_settings = bcm_get_settings,
179 .get_drvinfo = bcm_get_drvinfo,
180 .get_link = bcm_get_link,
181 .get_msglevel = bcm_get_msglevel,
182 .set_msglevel = bcm_set_msglevel,
183};
184
185int register_networkdev(PMINI_ADAPTER Adapter)
238{ 186{
187 struct net_device *net = Adapter->dev;
188 PS_INTERFACE_ADAPTER IntfAdapter = Adapter->pvInterfaceAdapter;
189 struct usb_interface *udev = IntfAdapter->interface;
190 struct usb_device *xdev = IntfAdapter->udev;
191
239 int result; 192 int result;
240 result = InterfaceInitialize(); 193
241 if(result) 194 net->netdev_ops = &bcmNetDevOps;
242 { 195 net->ethtool_ops = &bcm_ethtool_ops;
243 printk("Initialisation failed for usbbcm"); 196 net->mtu = MTU_SIZE; /* 1400 Bytes */
244 } 197 net->tx_queue_len = TX_QLEN;
245 else 198 net->flags |= IFF_NOARP;
246 { 199
247 printk("Initialised usbbcm"); 200 netif_carrier_off(net);
201
202 SET_NETDEV_DEVTYPE(net, &wimax_type);
203
204 /* Read the MAC Address from EEPROM */
205 result = ReadMacAddressFromNVM(Adapter);
206 if (result != STATUS_SUCCESS) {
207 dev_err(&udev->dev,
208 PFX "Error in Reading the mac Address: %d", result);
209 return -EIO;
248 } 210 }
249 return result;
250}
251 211
212 result = register_netdev(net);
213 if (result)
214 return result;
252 215
253static void bcm_exit(void) 216 gblpnetdev = Adapter->dev;
254{
255 printk("%s %s Calling InterfaceExit\n",__FILE__, __FUNCTION__);
256 InterfaceExit();
257 printk("%s %s InterfaceExit returned\n",__FILE__, __FUNCTION__);
258}
259 217
260module_init(bcm_init); 218 if (netif_msg_probe(Adapter))
261module_exit(bcm_exit); 219 dev_info(&udev->dev, PFX "%s: register usb-%s-%s %pM\n",
262MODULE_LICENSE ("GPL"); 220 net->name, xdev->bus->bus_name, xdev->devpath,
221 net->dev_addr);
263 222
223 return 0;
224}
264 225
226void unregister_networkdev(PMINI_ADAPTER Adapter)
227{
228 struct net_device *net = Adapter->dev;
229 PS_INTERFACE_ADAPTER IntfAdapter = Adapter->pvInterfaceAdapter;
230 struct usb_interface *udev = IntfAdapter->interface;
231 struct usb_device *xdev = IntfAdapter->udev;
232
233 if (netif_msg_probe(Adapter))
234 dev_info(&udev->dev, PFX "%s: unregister usb-%s%s\n",
235 net->name, xdev->bus->bus_name, xdev->devpath);
236
237 unregister_netdev(Adapter->dev);
238}
diff --git a/drivers/staging/bcm/CmHost.c b/drivers/staging/bcm/CmHost.c
index 6f388a374ddc..5ac45820d564 100644
--- a/drivers/staging/bcm/CmHost.c
+++ b/drivers/staging/bcm/CmHost.c
@@ -15,6 +15,7 @@ typedef enum _E_CLASSIFIER_ACTION
15 eDeleteClassifier 15 eDeleteClassifier
16}E_CLASSIFIER_ACTION; 16}E_CLASSIFIER_ACTION;
17 17
18static ULONG GetNextTargetBufferLocation(PMINI_ADAPTER Adapter,B_UINT16 tid);
18 19
19/************************************************************ 20/************************************************************
20* Function - SearchSfid 21* Function - SearchSfid
@@ -28,7 +29,7 @@ typedef enum _E_CLASSIFIER_ACTION
28* Returns - Queue index for this SFID(If matched) 29* Returns - Queue index for this SFID(If matched)
29 Else Invalid Queue Index(If Not matched) 30 Else Invalid Queue Index(If Not matched)
30************************************************************/ 31************************************************************/
31__inline INT SearchSfid(PMINI_ADAPTER Adapter,UINT uiSfid) 32INT SearchSfid(PMINI_ADAPTER Adapter,UINT uiSfid)
32{ 33{
33 INT iIndex=0; 34 INT iIndex=0;
34 for(iIndex=(NO_OF_QUEUES-1); iIndex>=0; iIndex--) 35 for(iIndex=(NO_OF_QUEUES-1); iIndex>=0; iIndex--)
@@ -47,26 +48,16 @@ __inline INT SearchSfid(PMINI_ADAPTER Adapter,UINT uiSfid)
47* Returns - Queue index for the free SFID 48* Returns - Queue index for the free SFID
48* Else returns Invalid Index. 49* Else returns Invalid Index.
49****************************************************************/ 50****************************************************************/
50__inline INT SearchFreeSfid(PMINI_ADAPTER Adapter) 51static INT SearchFreeSfid(PMINI_ADAPTER Adapter)
51{ 52{
52 UINT uiIndex=0; 53 UINT uiIndex=0;
54
53 for(uiIndex=0; uiIndex < (NO_OF_QUEUES-1); uiIndex++) 55 for(uiIndex=0; uiIndex < (NO_OF_QUEUES-1); uiIndex++)
54 if(Adapter->PackInfo[uiIndex].ulSFID==0) 56 if(Adapter->PackInfo[uiIndex].ulSFID==0)
55 return uiIndex; 57 return uiIndex;
56 return NO_OF_QUEUES+1; 58 return NO_OF_QUEUES+1;
57} 59}
58 60
59__inline int SearchVcid(PMINI_ADAPTER Adapter,unsigned short usVcid)
60{
61 int iIndex=0;
62 for(iIndex=(NO_OF_QUEUES-1);iIndex>=0;iIndex--)
63 if(Adapter->PackInfo[iIndex].usVCID_Value == usVcid)
64 return iIndex;
65 return NO_OF_QUEUES+1;
66
67}
68
69
70/* 61/*
71Function: SearchClsid 62Function: SearchClsid
72Description: This routinue would search Classifier having specified ClassifierID as input parameter 63Description: This routinue would search Classifier having specified ClassifierID as input parameter
@@ -76,7 +67,7 @@ Input parameters: PMINI_ADAPTER Adapter - Adapter Context
76Return: int :Classifier table index of matching entry 67Return: int :Classifier table index of matching entry
77*/ 68*/
78 69
79__inline int SearchClsid(PMINI_ADAPTER Adapter,ULONG ulSFID,B_UINT16 uiClassifierID) 70static int SearchClsid(PMINI_ADAPTER Adapter,ULONG ulSFID,B_UINT16 uiClassifierID)
80{ 71{
81 unsigned int uiClassifierIndex = 0; 72 unsigned int uiClassifierIndex = 0;
82 for(uiClassifierIndex=0;uiClassifierIndex<MAX_CLASSIFIERS;uiClassifierIndex++) 73 for(uiClassifierIndex=0;uiClassifierIndex<MAX_CLASSIFIERS;uiClassifierIndex++)
@@ -94,7 +85,7 @@ __inline int SearchClsid(PMINI_ADAPTER Adapter,ULONG ulSFID,B_UINT16 uiClassifi
94This routinue would search Free available Classifier entry in classifier table. 85This routinue would search Free available Classifier entry in classifier table.
95@return free Classifier Entry index in classifier table for specified SF 86@return free Classifier Entry index in classifier table for specified SF
96*/ 87*/
97static __inline int SearchFreeClsid(PMINI_ADAPTER Adapter /**Adapter Context*/ 88static int SearchFreeClsid(PMINI_ADAPTER Adapter /**Adapter Context*/
98 ) 89 )
99{ 90{
100 unsigned int uiClassifierIndex = 0; 91 unsigned int uiClassifierIndex = 0;
@@ -106,7 +97,7 @@ static __inline int SearchFreeClsid(PMINI_ADAPTER Adapter /**Adapter Context*/
106 return MAX_CLASSIFIERS+1; 97 return MAX_CLASSIFIERS+1;
107} 98}
108 99
109VOID deleteSFBySfid(PMINI_ADAPTER Adapter, UINT uiSearchRuleIndex) 100static VOID deleteSFBySfid(PMINI_ADAPTER Adapter, UINT uiSearchRuleIndex)
110{ 101{
111 //deleting all the packet held in the SF 102 //deleting all the packet held in the SF
112 flush_queue(Adapter,uiSearchRuleIndex); 103 flush_queue(Adapter,uiSearchRuleIndex);
@@ -985,7 +976,7 @@ static VOID CopyToAdapter( register PMINI_ADAPTER Adapter, /**<Pointer to the A
985 976
986 if(Adapter->PackInfo[uiSearchRuleIndex].pstSFIndication) 977 if(Adapter->PackInfo[uiSearchRuleIndex].pstSFIndication)
987 { 978 {
988 bcm_kfree(Adapter->PackInfo[uiSearchRuleIndex].pstSFIndication); 979 kfree(Adapter->PackInfo[uiSearchRuleIndex].pstSFIndication);
989 Adapter->PackInfo[uiSearchRuleIndex].pstSFIndication = NULL; 980 Adapter->PackInfo[uiSearchRuleIndex].pstSFIndication = NULL;
990 } 981 }
991 Adapter->PackInfo[uiSearchRuleIndex].pstSFIndication = pstAddIndication; 982 Adapter->PackInfo[uiSearchRuleIndex].pstSFIndication = pstAddIndication;
@@ -1061,12 +1052,6 @@ static VOID DumpCmControlPacket(PVOID pvBuffer)
1061 pstAddIndication->sfAuthorizedSet.u32MaxTrafficBurst); 1052 pstAddIndication->sfAuthorizedSet.u32MaxTrafficBurst);
1062 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MinReservedTrafficRate : 0x%X", 1053 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MinReservedTrafficRate : 0x%X",
1063 pstAddIndication->sfAuthorizedSet.u32MinReservedTrafficRate); 1054 pstAddIndication->sfAuthorizedSet.u32MinReservedTrafficRate);
1064#if 0
1065 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MinimumTolerableTrafficRate : 0x%X",
1066 pstAddIndication->sfAuthorizedSet.u32MinimumTolerableTrafficRate);
1067 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32RequesttransmissionPolicy : 0x%X",
1068 pstAddIndication->sfAuthorizedSet.u32RequesttransmissionPolicy);
1069#endif
1070 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParamLength : 0x%X", 1055 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParamLength : 0x%X",
1071 pstAddIndication->sfAuthorizedSet.u8VendorSpecificQoSParamLength); 1056 pstAddIndication->sfAuthorizedSet.u8VendorSpecificQoSParamLength);
1072 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParam : 0x%X", 1057 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParam : 0x%X",
@@ -1114,13 +1099,6 @@ static VOID DumpCmControlPacket(PVOID pvBuffer)
1114 pstAddIndication->sfAuthorizedSet.u8PagingPreference); 1099 pstAddIndication->sfAuthorizedSet.u8PagingPreference);
1115 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16UnsolicitedPollingInterval : 0x%X", 1100 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16UnsolicitedPollingInterval : 0x%X",
1116 pstAddIndication->sfAuthorizedSet.u16UnsolicitedPollingInterval); 1101 pstAddIndication->sfAuthorizedSet.u16UnsolicitedPollingInterval);
1117#if 0
1118 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "MBSZoneIdentifierassignmentLength : 0x%X",
1119 pstAddIndication->sfAuthorizedSet.MBSZoneIdentifierassignmentLength);
1120 for(uiLoopIndex=0; uiLoopIndex < MAX_STRING_LEN; uiLoopIndex++)
1121 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "MBSZoneIdentifierassignment : 0x%X",
1122 pstAddIndication->sfAuthorizedSet.MBSZoneIdentifierassignment[uiLoopIndex]);
1123#endif
1124 1102
1125 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "sfAuthorizedSet.u8HARQChannelMapping %x %x %x ", 1103 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "sfAuthorizedSet.u8HARQChannelMapping %x %x %x ",
1126 *(unsigned int*)pstAddIndication->sfAuthorizedSet.u8HARQChannelMapping, 1104 *(unsigned int*)pstAddIndication->sfAuthorizedSet.u8HARQChannelMapping,
@@ -1158,11 +1136,6 @@ static VOID DumpCmControlPacket(PVOID pvBuffer)
1158 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[0], 1136 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[0],
1159 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[1], 1137 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[1],
1160 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[2]); 1138 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[2]);
1161#if 0
1162
1163 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "u8ProtocolLength :0x%X ",
1164 psfCSType->cCPacketClassificationRule.u8ProtocolLength);
1165#endif
1166 1139
1167 for(uiLoopIndex=0; uiLoopIndex < 1; uiLoopIndex++) 1140 for(uiLoopIndex=0; uiLoopIndex < 1; uiLoopIndex++)
1168 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8Protocol : 0x%02X ", 1141 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8Protocol : 0x%02X ",
@@ -1278,14 +1251,6 @@ static VOID DumpCmControlPacket(PVOID pvBuffer)
1278 pstAddIndication->sfAdmittedSet.u8QosParamSet); 1251 pstAddIndication->sfAdmittedSet.u8QosParamSet);
1279 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficPriority : 0x%02X", 1252 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficPriority : 0x%02X",
1280 pstAddIndication->sfAdmittedSet.u8TrafficPriority); 1253 pstAddIndication->sfAdmittedSet.u8TrafficPriority);
1281#if 0
1282 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "u32MaxSustainedTrafficRate : 0x%02X",
1283 ntohl(pstAddIndication->sfAdmittedSet.u32MaxSustainedTrafficRate));
1284 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "u32MinimumTolerableTrafficRate : 0x%X",
1285 pstAddIndication->sfAdmittedSet.u32MinimumTolerableTrafficRate);
1286 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "u32RequesttransmissionPolicy : 0x%X",
1287 pstAddIndication->sfAdmittedSet.u32RequesttransmissionPolicy);
1288#endif
1289 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaxTrafficBurst : 0x%X", 1254 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaxTrafficBurst : 0x%X",
1290 pstAddIndication->sfAdmittedSet.u32MaxTrafficBurst); 1255 pstAddIndication->sfAdmittedSet.u32MaxTrafficBurst);
1291 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MinReservedTrafficRate : 0x%X", 1256 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MinReservedTrafficRate : 0x%X",
@@ -1339,13 +1304,6 @@ static VOID DumpCmControlPacket(PVOID pvBuffer)
1339 pstAddIndication->sfAdmittedSet.u16TimeBase); 1304 pstAddIndication->sfAdmittedSet.u16TimeBase);
1340 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8PagingPreference : 0x%X", 1305 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8PagingPreference : 0x%X",
1341 pstAddIndication->sfAdmittedSet.u8PagingPreference); 1306 pstAddIndication->sfAdmittedSet.u8PagingPreference);
1342#if 0
1343 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "MBSZoneIdentifierassignmentLength : 0x%X",
1344 pstAddIndication->sfAdmittedSet.MBSZoneIdentifierassignmentLength);
1345 for(uiLoopIndex=0; uiLoopIndex < MAX_STRING_LEN; uiLoopIndex++)
1346 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "MBSZoneIdentifierassignment : 0x%X",
1347 pstAddIndication->sfAdmittedSet.MBSZoneIdentifierassignment[uiLoopIndex]);
1348#endif
1349 1307
1350 1308
1351 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficIndicationPreference : 0x%02X", 1309 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficIndicationPreference : 0x%02X",
@@ -1378,11 +1336,6 @@ static VOID DumpCmControlPacket(PVOID pvBuffer)
1378 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[0], 1336 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[0],
1379 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[1], 1337 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[1],
1380 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[2]); 1338 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[2]);
1381#if 0
1382
1383 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ProtocolLength :0x%02X ",
1384 psfCSType->cCPacketClassificationRule.u8ProtocolLength);
1385#endif
1386 for(uiLoopIndex=0; uiLoopIndex < 1; uiLoopIndex++) 1339 for(uiLoopIndex=0; uiLoopIndex < 1; uiLoopIndex++)
1387 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8Protocol: 0x%02X ", 1340 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8Protocol: 0x%02X ",
1388 psfCSType->cCPacketClassificationRule.u8Protocol); 1341 psfCSType->cCPacketClassificationRule.u8Protocol);
@@ -1497,20 +1450,10 @@ static VOID DumpCmControlPacket(PVOID pvBuffer)
1497 pstAddIndication->sfActiveSet.u8QosParamSet); 1450 pstAddIndication->sfActiveSet.u8QosParamSet);
1498 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficPriority : 0x%02X", 1451 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficPriority : 0x%02X",
1499 pstAddIndication->sfActiveSet.u8TrafficPriority); 1452 pstAddIndication->sfActiveSet.u8TrafficPriority);
1500#if 0
1501 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "u32MaxSustainedTrafficRate : 0x%02X",
1502 ntohl(pstAddIndication->sfActiveSet.u32MaxSustainedTrafficRate));
1503#endif
1504 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaxTrafficBurst : 0x%X", 1453 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaxTrafficBurst : 0x%X",
1505 pstAddIndication->sfActiveSet.u32MaxTrafficBurst); 1454 pstAddIndication->sfActiveSet.u32MaxTrafficBurst);
1506 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MinReservedTrafficRate : 0x%X", 1455 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MinReservedTrafficRate : 0x%X",
1507 pstAddIndication->sfActiveSet.u32MinReservedTrafficRate); 1456 pstAddIndication->sfActiveSet.u32MinReservedTrafficRate);
1508#if 0
1509 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "u32MinimumTolerableTrafficRate : 0x%X",
1510 pstAddIndication->sfActiveSet.u32MinimumTolerableTrafficRate);
1511 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "u32RequesttransmissionPolicy : 0x%X",
1512 pstAddIndication->sfActiveSet.u32RequesttransmissionPolicy);
1513#endif
1514 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParamLength : 0x%02X", 1457 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParamLength : 0x%02X",
1515 pstAddIndication->sfActiveSet.u8VendorSpecificQoSParamLength); 1458 pstAddIndication->sfActiveSet.u8VendorSpecificQoSParamLength);
1516 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParam : 0x%02X", 1459 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParam : 0x%02X",
@@ -1558,13 +1501,6 @@ static VOID DumpCmControlPacket(PVOID pvBuffer)
1558 pstAddIndication->sfActiveSet.u16TimeBase); 1501 pstAddIndication->sfActiveSet.u16TimeBase);
1559 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8PagingPreference : 0x%X", 1502 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8PagingPreference : 0x%X",
1560 pstAddIndication->sfActiveSet.u8PagingPreference); 1503 pstAddIndication->sfActiveSet.u8PagingPreference);
1561#if 0
1562 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " MBSZoneIdentifierassignmentLength : 0x%X",
1563 pstAddIndication->sfActiveSet.MBSZoneIdentifierassignmentLength);
1564 for(uiLoopIndex=0; uiLoopIndex < MAX_STRING_LEN; uiLoopIndex++)
1565 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " MBSZoneIdentifierassignment : 0x%X",
1566 pstAddIndication->sfActiveSet.MBSZoneIdentifierassignment[uiLoopIndex]);
1567#endif
1568 1504
1569 1505
1570 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8TrafficIndicationPreference : 0x%X", 1506 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8TrafficIndicationPreference : 0x%X",
@@ -1597,11 +1533,6 @@ static VOID DumpCmControlPacket(PVOID pvBuffer)
1597 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[0], 1533 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[0],
1598 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[1], 1534 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[1],
1599 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[2]); 1535 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[2]);
1600#if 0
1601
1602 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, " u8ProtocolLength :0x%X ",
1603 psfCSType->cCPacketClassificationRule.u8ProtocolLength);
1604#endif
1605 for(uiLoopIndex=0; uiLoopIndex < 1; uiLoopIndex++) 1536 for(uiLoopIndex=0; uiLoopIndex < 1; uiLoopIndex++)
1606 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8Protocol : 0x%X ", 1537 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8Protocol : 0x%X ",
1607 psfCSType->cCPacketClassificationRule.u8Protocol); 1538 psfCSType->cCPacketClassificationRule.u8Protocol);
@@ -1706,12 +1637,8 @@ static inline ULONG RestoreSFParam(PMINI_ADAPTER Adapter, ULONG ulAddrSFParamSet
1706 return 0; 1637 return 0;
1707 } 1638 }
1708 ulAddrSFParamSet = ntohl(ulAddrSFParamSet); 1639 ulAddrSFParamSet = ntohl(ulAddrSFParamSet);
1709 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, " RestoreSFParam: Total Words of DSX Message To Read: 0x%zx From Target At : 0x%lx ",
1710 nBytesToRead/sizeof(ULONG),ulAddrSFParamSet);
1711 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "sizeof(stServiceFlowParamSI) = %zx", sizeof(stServiceFlowParamSI));
1712 1640
1713 //Read out the SF Param Set At the indicated Location 1641 //Read out the SF Param Set At the indicated Location
1714 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "nBytesToRead = %x", nBytesToRead);
1715 if(rdm(Adapter, ulAddrSFParamSet, (PUCHAR)pucDestBuffer, nBytesToRead) < 0) 1642 if(rdm(Adapter, ulAddrSFParamSet, (PUCHAR)pucDestBuffer, nBytesToRead) < 0)
1716 return STATUS_FAILURE; 1643 return STATUS_FAILURE;
1717 1644
@@ -1719,23 +1646,20 @@ static inline ULONG RestoreSFParam(PMINI_ADAPTER Adapter, ULONG ulAddrSFParamSet
1719} 1646}
1720 1647
1721 1648
1722static __inline ULONG StoreSFParam(PMINI_ADAPTER Adapter,PUCHAR pucSrcBuffer,ULONG ulAddrSFParamSet) 1649static ULONG StoreSFParam(PMINI_ADAPTER Adapter,PUCHAR pucSrcBuffer,ULONG ulAddrSFParamSet)
1723{ 1650{
1724 UINT nBytesToWrite = sizeof(stServiceFlowParamSI); 1651 UINT nBytesToWrite = sizeof(stServiceFlowParamSI);
1725 UINT uiRetVal =0; 1652 int ret = 0;
1726 1653
1727 if(ulAddrSFParamSet == 0 || NULL == pucSrcBuffer) 1654 if(ulAddrSFParamSet == 0 || NULL == pucSrcBuffer)
1728 { 1655 {
1729 return 0; 1656 return 0;
1730 } 1657 }
1731 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, " StoreSFParam: Total Words of DSX Message To Write: 0x%zX To Target At : 0x%lX ",(nBytesToWrite/sizeof(ULONG)),ulAddrSFParamSet);
1732 1658
1733 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "WRM with %x bytes",nBytesToWrite); 1659 ret = wrm(Adapter, ulAddrSFParamSet, (u8 *)pucSrcBuffer, nBytesToWrite);
1734 1660 if (ret < 0) {
1735 uiRetVal = wrm(Adapter,ulAddrSFParamSet,(PUCHAR)pucSrcBuffer, nBytesToWrite);
1736 if(uiRetVal < 0) {
1737 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "%s:%d WRM failed",__FUNCTION__, __LINE__); 1661 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "%s:%d WRM failed",__FUNCTION__, __LINE__);
1738 return uiRetVal; 1662 return ret;
1739 } 1663 }
1740 return 1; 1664 return 1;
1741} 1665}
@@ -1778,7 +1702,7 @@ ULONG StoreCmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT *p
1778 } 1702 }
1779 // For DSA_REQ, only upto "psfAuthorizedSet" parameter should be accessed by driver! 1703 // For DSA_REQ, only upto "psfAuthorizedSet" parameter should be accessed by driver!
1780 1704
1781 pstAddIndication=(stLocalSFAddIndication *)kmalloc(sizeof(*pstAddIndication), GFP_KERNEL); 1705 pstAddIndication=kmalloc(sizeof(*pstAddIndication), GFP_KERNEL);
1782 if(NULL==pstAddIndication) 1706 if(NULL==pstAddIndication)
1783 return 0; 1707 return 0;
1784 1708
@@ -1844,7 +1768,7 @@ ULONG StoreCmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT *p
1844 1768
1845 (*puBufferLength) = sizeof(stLocalSFAddIndication); 1769 (*puBufferLength) = sizeof(stLocalSFAddIndication);
1846 *(stLocalSFAddIndication *)pvBuffer = *pstAddIndication; 1770 *(stLocalSFAddIndication *)pvBuffer = *pstAddIndication;
1847 bcm_kfree(pstAddIndication); 1771 kfree(pstAddIndication);
1848 return 1; 1772 return 1;
1849} 1773}
1850 1774
@@ -1931,7 +1855,7 @@ static inline stLocalSFAddIndicationAlt
1931 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "============================================================"); 1855 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "============================================================");
1932 return pstAddIndicationDest; 1856 return pstAddIndicationDest;
1933failed_restore_sf_param: 1857failed_restore_sf_param:
1934 bcm_kfree(pstAddIndicationDest); 1858 kfree(pstAddIndicationDest);
1935 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "<=====" ); 1859 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "<=====" );
1936 return NULL; 1860 return NULL;
1937} 1861}
@@ -1988,7 +1912,7 @@ ULONG SetUpTargetDsxBuffers(PMINI_ADAPTER Adapter)
1988 return 1; 1912 return 1;
1989} 1913}
1990 1914
1991ULONG GetNextTargetBufferLocation(PMINI_ADAPTER Adapter,B_UINT16 tid) 1915static ULONG GetNextTargetBufferLocation(PMINI_ADAPTER Adapter,B_UINT16 tid)
1992{ 1916{
1993 ULONG ulTargetDSXBufferAddress; 1917 ULONG ulTargetDSXBufferAddress;
1994 ULONG ulTargetDsxBufferIndexToUse,ulMaxTry; 1918 ULONG ulTargetDsxBufferIndexToUse,ulMaxTry;
@@ -2049,7 +1973,7 @@ INT FreeAdapterDsxBuffer(PMINI_ADAPTER Adapter)
2049{ 1973{
2050 if(Adapter->caDsxReqResp) 1974 if(Adapter->caDsxReqResp)
2051 { 1975 {
2052 bcm_kfree(Adapter->caDsxReqResp); 1976 kfree(Adapter->caDsxReqResp);
2053 } 1977 }
2054 return 0; 1978 return 0;
2055 1979
@@ -2102,7 +2026,7 @@ BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter, /**<Pointer to the Adap
2102 2026
2103 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, " VCID = %x", ntohs(pstAddIndication->u16VCID)); 2027 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, " VCID = %x", ntohs(pstAddIndication->u16VCID));
2104 CopyBufferToControlPacket(Adapter,(PVOID)Adapter->caDsxReqResp); 2028 CopyBufferToControlPacket(Adapter,(PVOID)Adapter->caDsxReqResp);
2105 bcm_kfree(pstAddIndication); 2029 kfree(pstAddIndication);
2106 } 2030 }
2107 break; 2031 break;
2108 case DSA_RSP: 2032 case DSA_RSP:
@@ -2118,7 +2042,7 @@ BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter, /**<Pointer to the Adap
2118 case DSA_ACK: 2042 case DSA_ACK:
2119 { 2043 {
2120 UINT uiSearchRuleIndex=0; 2044 UINT uiSearchRuleIndex=0;
2121 struct timeval tv = {0}; 2045
2122 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "VCID:0x%X", 2046 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "VCID:0x%X",
2123 ntohs(pstAddIndication->u16VCID)); 2047 ntohs(pstAddIndication->u16VCID));
2124 uiSearchRuleIndex=SearchFreeSfid(Adapter); 2048 uiSearchRuleIndex=SearchFreeSfid(Adapter);
@@ -2169,7 +2093,7 @@ BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter, /**<Pointer to the Adap
2169 Adapter->PackInfo[uiSearchRuleIndex].bActive=FALSE; 2093 Adapter->PackInfo[uiSearchRuleIndex].bActive=FALSE;
2170 Adapter->PackInfo[uiSearchRuleIndex].bValid=FALSE; 2094 Adapter->PackInfo[uiSearchRuleIndex].bValid=FALSE;
2171 Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value=0; 2095 Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value=0;
2172 bcm_kfree(pstAddIndication); 2096 kfree(pstAddIndication);
2173 } 2097 }
2174 2098
2175 else if(psfLocalSet->bValid && (pstAddIndication->u8CC == 0)) 2099 else if(psfLocalSet->bValid && (pstAddIndication->u8CC == 0))
@@ -2200,14 +2124,13 @@ BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter, /**<Pointer to the Adap
2200 if(!Adapter->LinkUpStatus) 2124 if(!Adapter->LinkUpStatus)
2201 { 2125 {
2202 netif_carrier_on(Adapter->dev); 2126 netif_carrier_on(Adapter->dev);
2203 netif_start_queue(Adapter->dev); 2127 netif_start_queue(Adapter->dev);
2204 Adapter->LinkUpStatus = 1; 2128 Adapter->LinkUpStatus = 1;
2205 do_gettimeofday(&tv); 2129 if (netif_msg_link(Adapter))
2206 2130 pr_info(PFX "%s: link up\n", Adapter->dev->name);
2207 atomic_set(&Adapter->TxPktAvail, 1); 2131 atomic_set(&Adapter->TxPktAvail, 1);
2208 wake_up(&Adapter->tx_packet_wait_queue); 2132 wake_up(&Adapter->tx_packet_wait_queue);
2209 Adapter->liTimeSinceLastNetEntry = tv.tv_sec; 2133 Adapter->liTimeSinceLastNetEntry = get_seconds();
2210 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "============Tx Service Flow Created!");
2211 } 2134 }
2212 } 2135 }
2213 } 2136 }
@@ -2218,13 +2141,13 @@ BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter, /**<Pointer to the Adap
2218 Adapter->PackInfo[uiSearchRuleIndex].bActive=FALSE; 2141 Adapter->PackInfo[uiSearchRuleIndex].bActive=FALSE;
2219 Adapter->PackInfo[uiSearchRuleIndex].bValid=FALSE; 2142 Adapter->PackInfo[uiSearchRuleIndex].bValid=FALSE;
2220 Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value=0; 2143 Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value=0;
2221 bcm_kfree(pstAddIndication); 2144 kfree(pstAddIndication);
2222 } 2145 }
2223 } 2146 }
2224 else 2147 else
2225 { 2148 {
2226 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0, "DSA ACK did not get valid SFID"); 2149 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0, "DSA ACK did not get valid SFID");
2227 bcm_kfree(pstAddIndication); 2150 kfree(pstAddIndication);
2228 return FALSE; 2151 return FALSE;
2229 } 2152 }
2230 } 2153 }
@@ -2239,7 +2162,7 @@ BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter, /**<Pointer to the Adap
2239 ((stLocalSFChangeIndicationAlt*)&(Adapter->caDsxReqResp[LEADER_SIZE]))->u8Type = DSC_RSP; 2162 ((stLocalSFChangeIndicationAlt*)&(Adapter->caDsxReqResp[LEADER_SIZE]))->u8Type = DSC_RSP;
2240 2163
2241 CopyBufferToControlPacket(Adapter,(PVOID)Adapter->caDsxReqResp); 2164 CopyBufferToControlPacket(Adapter,(PVOID)Adapter->caDsxReqResp);
2242 bcm_kfree(pstAddIndication); 2165 kfree(pstAddIndication);
2243 } 2166 }
2244 break; 2167 break;
2245 case DSC_RSP: 2168 case DSC_RSP:
@@ -2312,13 +2235,13 @@ BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter, /**<Pointer to the Adap
2312 else if(pstChangeIndication->u8CC == 6) 2235 else if(pstChangeIndication->u8CC == 6)
2313 { 2236 {
2314 deleteSFBySfid(Adapter,uiSearchRuleIndex); 2237 deleteSFBySfid(Adapter,uiSearchRuleIndex);
2315 bcm_kfree(pstAddIndication); 2238 kfree(pstAddIndication);
2316 } 2239 }
2317 } 2240 }
2318 else 2241 else
2319 { 2242 {
2320 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0, "DSC ACK did not get valid SFID"); 2243 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_PRINTK, 0, 0, "DSC ACK did not get valid SFID");
2321 bcm_kfree(pstAddIndication); 2244 kfree(pstAddIndication);
2322 return FALSE; 2245 return FALSE;
2323 } 2246 }
2324 } 2247 }
@@ -2355,7 +2278,7 @@ BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter, /**<Pointer to the Adap
2355 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "DSD ACK Rcd, let App handle it\n"); 2278 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "DSD ACK Rcd, let App handle it\n");
2356 break; 2279 break;
2357 default: 2280 default:
2358 bcm_kfree(pstAddIndication); 2281 kfree(pstAddIndication);
2359 return FALSE ; 2282 return FALSE ;
2360 } 2283 }
2361 return TRUE; 2284 return TRUE;
diff --git a/drivers/staging/bcm/CmHost.h b/drivers/staging/bcm/CmHost.h
index 847782c3765b..8f689769b4ba 100644
--- a/drivers/staging/bcm/CmHost.h
+++ b/drivers/staging/bcm/CmHost.h
@@ -150,8 +150,6 @@ typedef struct stLocalSFChangeIndicationAlt{
150 150
151ULONG StoreCmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT *puBufferLength); 151ULONG StoreCmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT *puBufferLength);
152 152
153ULONG GetNextTargetBufferLocation(PMINI_ADAPTER Adapter,B_UINT16 tid);
154
155INT AllocAdapterDsxBuffer(PMINI_ADAPTER Adapter); 153INT AllocAdapterDsxBuffer(PMINI_ADAPTER Adapter);
156 154
157INT FreeAdapterDsxBuffer(PMINI_ADAPTER Adapter); 155INT FreeAdapterDsxBuffer(PMINI_ADAPTER Adapter);
@@ -159,7 +157,6 @@ ULONG SetUpTargetDsxBuffers(PMINI_ADAPTER Adapter);
159 157
160BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer); 158BOOLEAN CmControlResponseMessage(PMINI_ADAPTER Adapter,PVOID pvBuffer);
161 159
162VOID deleteSFBySfid(PMINI_ADAPTER Adapter, UINT uiSearchRuleIndex);
163 160
164#pragma pack (pop) 161#pragma pack (pop)
165 162
diff --git a/drivers/staging/bcm/DDRInit.c b/drivers/staging/bcm/DDRInit.c
index 8907e211d483..1c7db81a1ee8 100644
--- a/drivers/staging/bcm/DDRInit.c
+++ b/drivers/staging/bcm/DDRInit.c
@@ -1,6 +1,5 @@
1#include "headers.h" 1#include "headers.h"
2 2
3#ifndef BCM_SHM_INTERFACE
4 3
5 4
6#define DDR_DUMP_INTERNAL_DEVICE_MEMORY 0xBFC02B00 5#define DDR_DUMP_INTERNAL_DEVICE_MEMORY 0xBFC02B00
@@ -188,17 +187,6 @@ static DDR_SET_NODE asDPLL_266MHZ[] = {
188 {0x0f000840,0x0FFF1B00}, 187 {0x0f000840,0x0FFF1B00},
189 {0x0f000870,0x00000002} 188 {0x0f000870,0x00000002}
190 }; 189 };
191#if 0
192static DDR_SET_NODE asDPLL_800MHZ[] = {
193 {0x0f000810,0x00000F95},
194 {0x0f000810,0x00000F95},
195 {0x0f000810,0x00000F95},
196 {0x0f000820,0x03F1365B},
197 {0x0f000840,0x0FFF0000},
198 {0x0f000880,0x000003DD},
199 {0x0f000860,0x00000000}
200 };
201#endif
202 190
203#define T3B_SKIP_CLOCK_PROGRAM_DUMP_133MHZ 11 //index for 0x0F007000 191#define T3B_SKIP_CLOCK_PROGRAM_DUMP_133MHZ 11 //index for 0x0F007000
204static DDR_SET_NODE asT3B_DDRSetting133MHz[] = {// # DPLL Clock Setting 192static DDR_SET_NODE asT3B_DDRSetting133MHz[] = {// # DPLL Clock Setting
@@ -788,7 +776,7 @@ int ddr_init(MINI_ADAPTER *Adapter)
788{ 776{
789 PDDR_SETTING psDDRSetting=NULL; 777 PDDR_SETTING psDDRSetting=NULL;
790 ULONG RegCount=0; 778 ULONG RegCount=0;
791 ULONG value = 0; 779 UINT value = 0;
792 UINT uiResetValue = 0; 780 UINT uiResetValue = 0;
793 UINT uiClockSetting = 0; 781 UINT uiClockSetting = 0;
794 int retval = STATUS_SUCCESS; 782 int retval = STATUS_SUCCESS;
@@ -982,7 +970,7 @@ int ddr_init(MINI_ADAPTER *Adapter)
982 { 970 {
983 value = psDDRSetting->ulRegValue; 971 value = psDDRSetting->ulRegValue;
984 } 972 }
985 retval = wrmalt(Adapter, psDDRSetting->ulRegAddress, (PUINT)&value, sizeof(value)); 973 retval = wrmalt(Adapter, psDDRSetting->ulRegAddress, &value, sizeof(value));
986 if(STATUS_SUCCESS != retval) { 974 if(STATUS_SUCCESS != retval) {
987 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"%s:%d\n", __FUNCTION__, __LINE__); 975 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"%s:%d\n", __FUNCTION__, __LINE__);
988 break; 976 break;
@@ -1298,5 +1286,4 @@ int download_ddr_settings(PMINI_ADAPTER Adapter)
1298 return retval; 1286 return retval;
1299} 1287}
1300 1288
1301#endif
1302 1289
diff --git a/drivers/staging/bcm/Debug.c b/drivers/staging/bcm/Debug.c
deleted file mode 100644
index 2703f304756d..000000000000
--- a/drivers/staging/bcm/Debug.c
+++ /dev/null
@@ -1,41 +0,0 @@
1#include "headers.h"
2
3static UINT current_debug_level=BCM_SCREAM;
4
5int bcm_print_buffer( UINT debug_level, const char *function_name,
6 char *file_name, int line_number, unsigned char *buffer, int bufferlen, enum _BASE_TYPE base)
7{
8 static const char * const buff_dump_base[] = {
9 "DEC", "HEX", "OCT", "BIN"
10 };
11 if(debug_level>=current_debug_level)
12 {
13 int i=0;
14 printk("\n%s:%s:%d:Buffer dump of size 0x%x in the %s:\n", file_name, function_name, line_number, bufferlen, buff_dump_base[1]);
15 for(;i<bufferlen;i++)
16 {
17 if(i && !(i%16) )
18 printk("\n");
19 switch(base)
20 {
21 case BCM_BASE_TYPE_DEC:
22 printk("%03d ", buffer[i]);
23 break;
24 case BCM_BASE_TYPE_OCT:
25 printk("%0x03o ", buffer[i]);
26 break;
27 case BCM_BASE_TYPE_BIN:
28 printk("%02x ", buffer[i]);
29 break;
30 case BCM_BASE_TYPE_HEX:
31 default:
32 printk("%02X ", buffer[i]);
33 break;
34 }
35 }
36 printk("\n");
37 }
38 return 0;
39}
40
41
diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h
index 3d788b59ab57..3138729cf34f 100644
--- a/drivers/staging/bcm/Debug.h
+++ b/drivers/staging/bcm/Debug.h
@@ -9,34 +9,6 @@
9#include <linux/string.h> 9#include <linux/string.h>
10#define NONE 0xFFFF 10#define NONE 0xFFFF
11 11
12typedef enum _BASE_TYPE
13{
14 BCM_BASE_TYPE_DEC,
15 BCM_BASE_TYPE_OCT,
16 BCM_BASE_TYPE_BIN,
17 BCM_BASE_TYPE_HEX,
18 BCM_BASE_TYPE_NONE,
19} BASE_TYPE, *PBASE_TYPE;
20
21int bcm_print_buffer( UINT debug_level, const char *function_name,
22 char *file_name, int line_number, unsigned char *buffer, int bufferlen, BASE_TYPE base);
23
24#ifdef BCM_SHM_INTERFACE
25#define CPE_VIRTUAL_ERROR_CODE_BASE_ADDR (0xBFC02E00 + 0x4C)
26// ERROR codes for debugging
27extern unsigned char u32ErrorCounter ;
28#define ERROR_DEVICE_REMOVED 0x1
29#define ERROR_LEADER_LENGTH_ZERO 0x2
30#define ERROR_LEADER_LENGTH_CORRUPTED 0x3
31#define ERROR_NO_SKBUFF 0x4
32
33#define ERROR_DL_MODULE 0xaa000000
34extern void CPE_ERROR_LOG(unsigned int module,unsigned int code);
35
36#endif
37
38
39
40 12
41//-------------------------------------------------------------------------------- 13//--------------------------------------------------------------------------------
42 14
@@ -242,44 +214,34 @@ typedef struct _S_BCM_DEBUG_STATE {
242 214
243//--- Only for direct printk's; "hidden" to API. 215//--- Only for direct printk's; "hidden" to API.
244#define DBG_TYPE_PRINTK 3 216#define DBG_TYPE_PRINTK 3
245#define PRINTKS_ON 1 // "hidden" from API, set to 0 to turn off all printk's
246
247#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) do { \
248 if ((DBG_TYPE_PRINTK == Type) && (PRINTKS_ON)) { \
249 printk ("%s:" string, __FUNCTION__, ##args); \
250 printk("\n"); \
251 } else if (!Adapter) \
252 ; \
253 else { \
254 if (((dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level) && \
255 ((Type & Adapter->stDebugState.type) && (SubType & Adapter->stDebugState.subtype[Type]))) { \
256 if (dbg_level & DBG_NO_FUNC_PRINT) \
257 printk (string, ##args); \
258 else \
259 { \
260 printk ("%s:" string, __FUNCTION__, ##args); \
261 printk("\n"); \
262 } \
263 } \
264 } \
265} while (0)
266 217
267#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level, buffer, bufferlen) do { \ 218#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) \
268 if ((DBG_TYPE_PRINTK == Type) && (PRINTKS_ON)) { \ 219 do { \
269 bcm_print_buffer( dbg_level, __FUNCTION__, __FILE__, __LINE__, buffer, bufferlen, BCM_BASE_TYPE_HEX); \ 220 if (DBG_TYPE_PRINTK == Type) \
270 } else if (!Adapter) \ 221 pr_info("%s:" string, __func__, ##args); \
271 ; \ 222 else if (Adapter && \
272 else { \ 223 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \
273 if (((dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level) && \ 224 (Type & Adapter->stDebugState.type) && \
274 ((Type & Adapter->stDebugState.type) && (SubType & Adapter->stDebugState.subtype[Type]))) { \ 225 (SubType & Adapter->stDebugState.subtype[Type])) { \
275 if (dbg_level & DBG_NO_FUNC_PRINT) \ 226 if (dbg_level & DBG_NO_FUNC_PRINT) \
276 bcm_print_buffer( dbg_level, NULL, NULL, __LINE__, buffer, bufferlen, BCM_BASE_TYPE_HEX); \ 227 printk(KERN_DEBUG string, ##args); \
277 else \ 228 else \
278 bcm_print_buffer( dbg_level, __FUNCTION__, __FILE__, __LINE__, buffer, bufferlen, BCM_BASE_TYPE_HEX); \ 229 printk(KERN_DEBUG "%s:" string, __func__, ##args); \
279 } \ 230 } \
280 } \
281 } while (0) 231 } while (0)
282 232
233#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level, buffer, bufferlen) do { \
234 if (DBG_TYPE_PRINTK == Type || \
235 (Adapter && \
236 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \
237 (Type & Adapter->stDebugState.type) && \
238 (SubType & Adapter->stDebugState.subtype[Type]))) { \
239 printk(KERN_DEBUG "%s:\n", __func__); \
240 print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET, \
241 16, 1, buffer, bufferlen, false); \
242 } \
243} while(0)
244
283 245
284#define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \ 246#define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \
285 int i; \ 247 int i; \
diff --git a/drivers/staging/bcm/HandleControlPacket.c b/drivers/staging/bcm/HandleControlPacket.c
index 7b2ec28a4bc1..2b1e9e17e11c 100644
--- a/drivers/staging/bcm/HandleControlPacket.c
+++ b/drivers/staging/bcm/HandleControlPacket.c
@@ -11,8 +11,7 @@ When a control packet is received, analyze the
11Enqueue the control packet for Application. 11Enqueue the control packet for Application.
12@return None 12@return None
13*/ 13*/
14VOID handle_rx_control_packet(PMINI_ADAPTER Adapter, /**<Pointer to the Adapter structure*/ 14static VOID handle_rx_control_packet(PMINI_ADAPTER Adapter, struct sk_buff *skb)
15 struct sk_buff *skb) /**<Pointer to the socket buffer*/
16{ 15{
17 PPER_TARANG_DATA pTarang = NULL; 16 PPER_TARANG_DATA pTarang = NULL;
18 BOOLEAN HighPriorityMessage = FALSE; 17 BOOLEAN HighPriorityMessage = FALSE;
@@ -20,8 +19,10 @@ VOID handle_rx_control_packet(PMINI_ADAPTER Adapter, /**<Pointer to the Adapter
20 CHAR cntrl_msg_mask_bit = 0; 19 CHAR cntrl_msg_mask_bit = 0;
21 BOOLEAN drop_pkt_flag = TRUE ; 20 BOOLEAN drop_pkt_flag = TRUE ;
22 USHORT usStatus = *(PUSHORT)(skb->data); 21 USHORT usStatus = *(PUSHORT)(skb->data);
23 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "=====>"); 22
24 /* Get the Leader field */ 23 if (netif_msg_pktdata(Adapter))
24 print_hex_dump(KERN_DEBUG, PFX "rx control: ", DUMP_PREFIX_NONE,
25 16, 1, skb->data, skb->len, 0);
25 26
26 switch(usStatus) 27 switch(usStatus)
27 { 28 {
@@ -134,7 +135,7 @@ VOID handle_rx_control_packet(PMINI_ADAPTER Adapter, /**<Pointer to the Adapter
134 } 135 }
135 up(&Adapter->RxAppControlQueuelock); 136 up(&Adapter->RxAppControlQueuelock);
136 wake_up(&Adapter->process_read_wait_queue); 137 wake_up(&Adapter->process_read_wait_queue);
137 bcm_kfree_skb(skb); 138 dev_kfree_skb(skb);
138 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "After wake_up_interruptible"); 139 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "After wake_up_interruptible");
139} 140}
140 141
@@ -185,33 +186,7 @@ int control_packet_handler (PMINI_ADAPTER Adapter /**< pointer to adapter obje
185 { 186 {
186 DEQUEUEPACKET(Adapter->RxControlHead,Adapter->RxControlTail); 187 DEQUEUEPACKET(Adapter->RxControlHead,Adapter->RxControlTail);
187// Adapter->RxControlHead=ctrl_packet->next; 188// Adapter->RxControlHead=ctrl_packet->next;
188 ((PLINUX_DEP_DATA)Adapter->pvOsDepData)->netstats.rx_packets++;
189 ((PLINUX_DEP_DATA)Adapter->pvOsDepData)->netstats.rx_bytes+=
190 ((PLEADER)ctrl_packet->data)->PLength;
191 }
192 #if 0 //Idle mode debug profiling...
193 if(*(PUSHORT)ctrl_packet->data == IDLE_MODE_STATUS)
194 {
195 puiBuffer = (PUINT)(ctrl_packet->data +sizeof(USHORT));
196 if((ntohl(*puiBuffer) == GO_TO_IDLE_MODE_PAYLOAD))
197 {
198 memset(&tv, 0, sizeof(tv));
199 do_gettimeofday(&tv);
200 if((ntohl(*(puiBuffer+1)) == 0))
201 {
202 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "IdleMode Wake-up Msg from f/w at time :%ld ms", tv.tv_sec *1000 + tv.tv_usec /1000);
203 }
204 else
205 {
206 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "IdleMode req Msg from f/w at time :%ld ms", tv.tv_sec *1000 + tv.tv_usec /1000);
207 }
208 }
209 else if((ntohl(*puiBuffer) == IDLE_MODE_SF_UPDATE_MSG))
210 {
211 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL, "GOT IDLE_MODE_SF_UPDATE MSG at time :%ld ms", tv.tv_sec *1000 + tv.tv_usec /1000);
212 }
213 } 189 }
214 #endif
215 190
216 spin_unlock_irqrestore (&Adapter->control_queue_lock, flags); 191 spin_unlock_irqrestore (&Adapter->control_queue_lock, flags);
217 handle_rx_control_packet(Adapter, ctrl_packet); 192 handle_rx_control_packet(Adapter, ctrl_packet);
@@ -234,7 +209,7 @@ INT flushAllAppQ(void)
234 { 209 {
235 PacketToDrop=pTarang->RxAppControlHead; 210 PacketToDrop=pTarang->RxAppControlHead;
236 DEQUEUEPACKET(pTarang->RxAppControlHead,pTarang->RxAppControlTail); 211 DEQUEUEPACKET(pTarang->RxAppControlHead,pTarang->RxAppControlTail);
237 bcm_kfree_skb(PacketToDrop); 212 dev_kfree_skb(PacketToDrop);
238 } 213 }
239 pTarang->AppCtrlQueueLen = 0; 214 pTarang->AppCtrlQueueLen = 0;
240 //dropped contrl packet statistics also should be reset. 215 //dropped contrl packet statistics also should be reset.
diff --git a/drivers/staging/bcm/HostMibs.h b/drivers/staging/bcm/HostMibs.h
deleted file mode 100644
index 28a578311378..000000000000
--- a/drivers/staging/bcm/HostMibs.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef _HOST_MIBS_H
2#define _HOST_MIBS_H
3
4INT ProcessGetHostMibs(PMINI_ADAPTER Adapter,
5 PVOID ioBuffer,
6 ULONG inputBufferLength);
7#endif
diff --git a/drivers/staging/bcm/IPv6Protocol.c b/drivers/staging/bcm/IPv6Protocol.c
index 5ec3b896c6a7..91b6fbe33c91 100644
--- a/drivers/staging/bcm/IPv6Protocol.c
+++ b/drivers/staging/bcm/IPv6Protocol.c
@@ -1,5 +1,9 @@
1#include "headers.h" 1#include "headers.h"
2 2
3static BOOLEAN MatchSrcIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header);
4static BOOLEAN MatchDestIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header);
5static VOID DumpIpv6Header(IPV6Header *pstIpv6Header);
6
3static UCHAR * GetNextIPV6ChainedHeader(UCHAR **ppucPayload,UCHAR *pucNextHeader,BOOLEAN *bParseDone,USHORT *pusPayloadLength) 7static UCHAR * GetNextIPV6ChainedHeader(UCHAR **ppucPayload,UCHAR *pucNextHeader,BOOLEAN *bParseDone,USHORT *pusPayloadLength)
4{ 8{
5 UCHAR *pucRetHeaderPtr = NULL; 9 UCHAR *pucRetHeaderPtr = NULL;
@@ -257,7 +261,7 @@ USHORT IpVersion6(PMINI_ADAPTER Adapter, /**< Pointer to the driver control stru
257} 261}
258 262
259 263
260BOOLEAN MatchSrcIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header) 264static BOOLEAN MatchSrcIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header)
261{ 265{
262 UINT uiLoopIndex=0; 266 UINT uiLoopIndex=0;
263 UINT uiIpv6AddIndex=0; 267 UINT uiIpv6AddIndex=0;
@@ -310,7 +314,7 @@ BOOLEAN MatchSrcIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pst
310 return FALSE; 314 return FALSE;
311} 315}
312 316
313BOOLEAN MatchDestIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header) 317static BOOLEAN MatchDestIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header)
314{ 318{
315 UINT uiLoopIndex=0; 319 UINT uiLoopIndex=0;
316 UINT uiIpv6AddIndex=0; 320 UINT uiIpv6AddIndex=0;
@@ -376,7 +380,7 @@ VOID DumpIpv6Address(ULONG *puIpv6Address)
376 380
377} 381}
378 382
379VOID DumpIpv6Header(IPV6Header *pstIpv6Header) 383static VOID DumpIpv6Header(IPV6Header *pstIpv6Header)
380{ 384{
381 UCHAR ucVersion; 385 UCHAR ucVersion;
382 UCHAR ucPrio ; 386 UCHAR ucPrio ;
diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h
index b93f7902e283..a0db5a1de763 100644
--- a/drivers/staging/bcm/IPv6ProtocolHdr.h
+++ b/drivers/staging/bcm/IPv6ProtocolHdr.h
@@ -101,15 +101,12 @@ typedef enum _E_IPADDR_CONTEXT
101 101
102 102
103//Function Prototypes 103//Function Prototypes
104BOOLEAN MatchSrcIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header);
105BOOLEAN MatchDestIpv6Address(S_CLASSIFIER_RULE *pstClassifierRule,IPV6Header *pstIpv6Header);
106 104
107USHORT IpVersion6(PMINI_ADAPTER Adapter, /**< Pointer to the driver control structure */ 105USHORT IpVersion6(PMINI_ADAPTER Adapter, /**< Pointer to the driver control structure */
108 PVOID pcIpHeader, /**<Pointer to the IP Hdr of the packet*/ 106 PVOID pcIpHeader, /**<Pointer to the IP Hdr of the packet*/
109 S_CLASSIFIER_RULE *pstClassifierRule ); 107 S_CLASSIFIER_RULE *pstClassifierRule );
110 108
111VOID DumpIpv6Address(ULONG *puIpv6Address); 109VOID DumpIpv6Address(ULONG *puIpv6Address);
112VOID DumpIpv6Header(IPV6Header *pstIpv6Header);
113 110
114extern BOOLEAN MatchSrcPort(S_CLASSIFIER_RULE *pstClassifierRule,USHORT ushSrcPort); 111extern BOOLEAN MatchSrcPort(S_CLASSIFIER_RULE *pstClassifierRule,USHORT ushSrcPort);
115extern BOOLEAN MatchDestPort(S_CLASSIFIER_RULE *pstClassifierRule,USHORT ushSrcPort); 112extern BOOLEAN MatchDestPort(S_CLASSIFIER_RULE *pstClassifierRule,USHORT ushSrcPort);
diff --git a/drivers/staging/bcm/InterfaceDld.c b/drivers/staging/bcm/InterfaceDld.c
index 60c0f29f3eef..df64acb06126 100644
--- a/drivers/staging/bcm/InterfaceDld.c
+++ b/drivers/staging/bcm/InterfaceDld.c
@@ -1,20 +1,18 @@
1#include "headers.h" 1#include "headers.h"
2 2
3#ifndef BCM_SHM_INTERFACE
4 3
5int InterfaceFileDownload( PVOID arg, 4int InterfaceFileDownload( PVOID arg,
6 struct file *flp, 5 struct file *flp,
7 unsigned int on_chip_loc) 6 unsigned int on_chip_loc)
8{ 7{
9 char *buff=NULL;
10 // unsigned int reg=0; 8 // unsigned int reg=0;
11 mm_segment_t oldfs={0}; 9 mm_segment_t oldfs={0};
12 int errno=0, len=0 /*,is_config_file = 0*/; 10 int errno=0, len=0 /*,is_config_file = 0*/;
13 loff_t pos=0; 11 loff_t pos=0;
14 PS_INTERFACE_ADAPTER psIntfAdapter = (PS_INTERFACE_ADAPTER)arg; 12 PS_INTERFACE_ADAPTER psIntfAdapter = (PS_INTERFACE_ADAPTER)arg;
15 //PMINI_ADAPTER Adapter = psIntfAdapter->psAdapter; 13 //PMINI_ADAPTER Adapter = psIntfAdapter->psAdapter;
14 char *buff=kmalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_KERNEL);
16 15
17 buff=(PCHAR)kmalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_KERNEL);
18 if(!buff) 16 if(!buff)
19 { 17 {
20 return -ENOMEM; 18 return -ENOMEM;
@@ -49,7 +47,7 @@ int InterfaceFileDownload( PVOID arg,
49 on_chip_loc+=MAX_TRANSFER_CTRL_BYTE_USB; 47 on_chip_loc+=MAX_TRANSFER_CTRL_BYTE_USB;
50 }/* End of for(;;)*/ 48 }/* End of for(;;)*/
51 49
52 bcm_kfree(buff); 50 kfree(buff);
53 return errno; 51 return errno;
54} 52}
55 53
@@ -57,7 +55,7 @@ int InterfaceFileReadbackFromChip( PVOID arg,
57 struct file *flp, 55 struct file *flp,
58 unsigned int on_chip_loc) 56 unsigned int on_chip_loc)
59{ 57{
60 char *buff=NULL, *buff_readback=NULL; 58 char *buff, *buff_readback;
61 unsigned int reg=0; 59 unsigned int reg=0;
62 mm_segment_t oldfs={0}; 60 mm_segment_t oldfs={0};
63 int errno=0, len=0, is_config_file = 0; 61 int errno=0, len=0, is_config_file = 0;
@@ -66,12 +64,12 @@ int InterfaceFileReadbackFromChip( PVOID arg,
66 INT Status = STATUS_SUCCESS; 64 INT Status = STATUS_SUCCESS;
67 PS_INTERFACE_ADAPTER psIntfAdapter = (PS_INTERFACE_ADAPTER)arg; 65 PS_INTERFACE_ADAPTER psIntfAdapter = (PS_INTERFACE_ADAPTER)arg;
68 66
69 buff=(PCHAR)kmalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_DMA); 67 buff=kmalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_DMA);
70 buff_readback=(PCHAR)kmalloc(MAX_TRANSFER_CTRL_BYTE_USB , GFP_DMA); 68 buff_readback=kmalloc(MAX_TRANSFER_CTRL_BYTE_USB , GFP_DMA);
71 if(!buff || !buff_readback) 69 if(!buff || !buff_readback)
72 { 70 {
73 bcm_kfree(buff); 71 kfree(buff);
74 bcm_kfree(buff_readback); 72 kfree(buff_readback);
75 73
76 return -ENOMEM; 74 return -ENOMEM;
77 } 75 }
@@ -138,8 +136,8 @@ int InterfaceFileReadbackFromChip( PVOID arg,
138 on_chip_loc+=MAX_TRANSFER_CTRL_BYTE_USB; 136 on_chip_loc+=MAX_TRANSFER_CTRL_BYTE_USB;
139 }/* End of while(1)*/ 137 }/* End of while(1)*/
140exit: 138exit:
141 bcm_kfree(buff); 139 kfree(buff);
142 bcm_kfree(buff_readback); 140 kfree(buff_readback);
143 return Status; 141 return Status;
144} 142}
145 143
@@ -165,7 +163,7 @@ static int bcm_download_config_file(PMINI_ADAPTER Adapter,
165 psFwInfo->pvMappedFirmwareAddress, psFwInfo->u32FirmwareLength); 163 psFwInfo->pvMappedFirmwareAddress, psFwInfo->u32FirmwareLength);
166 if(retval) 164 if(retval)
167 { 165 {
168 bcm_kfree (Adapter->pstargetparams); 166 kfree(Adapter->pstargetparams);
169 Adapter->pstargetparams = NULL; 167 Adapter->pstargetparams = NULL;
170 return -EFAULT; 168 return -EFAULT;
171 } 169 }
@@ -231,41 +229,6 @@ static int bcm_download_config_file(PMINI_ADAPTER Adapter,
231 229
232 return retval; 230 return retval;
233} 231}
234#if 0
235static int bcm_download_buffer(PMINI_ADAPTER Adapter,
236 unsigned char *mappedbuffer, unsigned int u32FirmwareLength,
237 unsigned long u32StartingAddress)
238{
239 char *buff=NULL;
240 unsigned int len = 0;
241 int retval = STATUS_SUCCESS;
242 buff = kzalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_KERNEL);
243
244 len = u32FirmwareLength;
245
246 while(u32FirmwareLength)
247 {
248 len = MIN_VAL (u32FirmwareLength, MAX_TRANSFER_CTRL_BYTE_USB);
249 if(STATUS_SUCCESS != (retval = copy_from_user(buff,
250 (unsigned char *)mappedbuffer, len)))
251 {
252 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "copy_from_user failed\n");
253 break;
254 }
255 retval = wrm (Adapter, u32StartingAddress, buff, len);
256 if(retval)
257 {
258 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "wrm failed\n");
259 break;
260 }
261 u32StartingAddress += len;
262 u32FirmwareLength -= len;
263 mappedbuffer +=len;
264 }
265 bcm_kfree(buff);
266 return retval;
267}
268#endif
269static int bcm_compare_buff_contents(unsigned char *readbackbuff, 232static int bcm_compare_buff_contents(unsigned char *readbackbuff,
270 unsigned char *buff,unsigned int len) 233 unsigned char *buff,unsigned int len)
271{ 234{
@@ -297,58 +260,6 @@ static int bcm_compare_buff_contents(unsigned char *readbackbuff,
297 } 260 }
298 return retval; 261 return retval;
299} 262}
300#if 0
301static int bcm_buffer_readback(PMINI_ADAPTER Adapter,
302 unsigned char *mappedbuffer, unsigned int u32FirmwareLength,
303 unsigned long u32StartingAddress)
304{
305 unsigned char *buff = NULL;
306 unsigned char *readbackbuff = NULL;
307 unsigned int len = u32FirmwareLength;
308 int retval = STATUS_SUCCESS;
309
310 buff=(unsigned char *)kzalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_KERNEL);
311 if(NULL == buff)
312 return -ENOMEM;
313 readbackbuff = (unsigned char *)kzalloc(MAX_TRANSFER_CTRL_BYTE_USB,
314 GFP_KERNEL);
315 if(NULL == readbackbuff)
316 {
317 bcm_kfree(buff);
318 return -ENOMEM;
319 }
320 while (u32FirmwareLength && !retval)
321 {
322 len = MIN_VAL (u32FirmwareLength, MAX_TRANSFER_CTRL_BYTE_USB);
323
324 /* read from the appl buff and then read from the target, compare */
325 if(STATUS_SUCCESS != (retval = copy_from_user(buff,
326 (unsigned char *)mappedbuffer, len)))
327 {
328 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "copy_from_user failed\n");
329 break;
330 }
331 retval = rdm (Adapter, u32StartingAddress, readbackbuff, len);
332 if(retval)
333 {
334 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "rdm failed\n");
335 break;
336 }
337
338 if (STATUS_SUCCESS !=
339 (retval = bcm_compare_buff_contents (readbackbuff, buff, len)))
340 {
341 break;
342 }
343 u32StartingAddress += len;
344 u32FirmwareLength -= len;
345 mappedbuffer +=len;
346 }/* end of while (u32FirmwareLength && !retval) */
347 bcm_kfree(buff);
348 bcm_kfree(readbackbuff);
349 return retval;
350}
351#endif
352int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter, FIRMWARE_INFO *psFwInfo) 263int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter, FIRMWARE_INFO *psFwInfo)
353{ 264{
354 int retval = STATUS_SUCCESS; 265 int retval = STATUS_SUCCESS;
@@ -375,7 +286,7 @@ int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter, FIRMWARE_INFO *psFwInfo)
375 else 286 else
376 { 287 {
377 288
378 buff = (PUCHAR)kzalloc(psFwInfo->u32FirmwareLength,GFP_KERNEL); 289 buff = kzalloc(psFwInfo->u32FirmwareLength,GFP_KERNEL);
379 if(buff==NULL) 290 if(buff==NULL)
380 { 291 {
381 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Failed in allocation memory"); 292 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Failed in allocation memory");
@@ -389,23 +300,6 @@ int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter, FIRMWARE_INFO *psFwInfo)
389 goto error ; 300 goto error ;
390 } 301 }
391 302
392 #if 0
393 retval = bcm_download_buffer(Adapter,
394 (unsigned char *)psFwInfo->pvMappedFirmwareAddress,
395 psFwInfo->u32FirmwareLength, psFwInfo->u32StartingAddress);
396 if(retval != STATUS_SUCCESS)
397 {
398 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "User space buffer download fails....");
399 }
400 retval = bcm_buffer_readback (Adapter,
401 (unsigned char *)psFwInfo->pvMappedFirmwareAddress,
402 psFwInfo->u32FirmwareLength, psFwInfo->u32StartingAddress);
403
404 if(retval != STATUS_SUCCESS)
405 {
406 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "read back verifier failed ....");
407 }
408 #endif
409 retval = buffDnldVerify(Adapter, 303 retval = buffDnldVerify(Adapter,
410 buff, 304 buff,
411 psFwInfo->u32FirmwareLength, 305 psFwInfo->u32FirmwareLength,
@@ -417,7 +311,7 @@ int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter, FIRMWARE_INFO *psFwInfo)
417 } 311 }
418 } 312 }
419error: 313error:
420 bcm_kfree(buff); 314 kfree(buff);
421 return retval; 315 return retval;
422} 316}
423 317
@@ -450,11 +344,10 @@ static INT buffRdbkVerify(PMINI_ADAPTER Adapter,
450 PUCHAR mappedbuffer, UINT u32FirmwareLength, 344 PUCHAR mappedbuffer, UINT u32FirmwareLength,
451 ULONG u32StartingAddress) 345 ULONG u32StartingAddress)
452{ 346{
453 PUCHAR readbackbuff = NULL;
454 UINT len = u32FirmwareLength; 347 UINT len = u32FirmwareLength;
455 INT retval = STATUS_SUCCESS; 348 INT retval = STATUS_SUCCESS;
349 PUCHAR readbackbuff = kzalloc(MAX_TRANSFER_CTRL_BYTE_USB,GFP_KERNEL);
456 350
457 readbackbuff = (PUCHAR)kzalloc(MAX_TRANSFER_CTRL_BYTE_USB,GFP_KERNEL);
458 if(NULL == readbackbuff) 351 if(NULL == readbackbuff)
459 { 352 {
460 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "MEMORY ALLOCATION FAILED"); 353 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "MEMORY ALLOCATION FAILED");
@@ -480,7 +373,7 @@ static INT buffRdbkVerify(PMINI_ADAPTER Adapter,
480 u32FirmwareLength -= len; 373 u32FirmwareLength -= len;
481 mappedbuffer +=len; 374 mappedbuffer +=len;
482 }/* end of while (u32FirmwareLength && !retval) */ 375 }/* end of while (u32FirmwareLength && !retval) */
483 bcm_kfree(readbackbuff); 376 kfree(readbackbuff);
484 return retval; 377 return retval;
485} 378}
486 379
@@ -506,5 +399,4 @@ error:
506 return status; 399 return status;
507} 400}
508 401
509#endif
510 402
diff --git a/drivers/staging/bcm/InterfaceIdleMode.c b/drivers/staging/bcm/InterfaceIdleMode.c
index 0750382733ff..bf5c0ad86610 100644
--- a/drivers/staging/bcm/InterfaceIdleMode.c
+++ b/drivers/staging/bcm/InterfaceIdleMode.c
@@ -98,14 +98,6 @@ int InterfaceIdleModeRespond(PMINI_ADAPTER Adapter, unsigned int* puiBuffer)
98 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE; 98 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
99 99
100 wake_up(&Adapter->lowpower_mode_wait_queue); 100 wake_up(&Adapter->lowpower_mode_wait_queue);
101 #if 0
102 if(Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY)
103 {
104 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, IDLE_MODE, DBG_LVL_ALL,"LED Thread is Running. Hence Setting the LED Event as IDLEMODE_EXIT");
105 Adapter->DriverState = IDLEMODE_EXIT;
106 wake_up(&Adapter->LEDInfo.notify_led_event);
107 }
108 #endif
109 101
110 } 102 }
111 else 103 else
@@ -154,17 +146,7 @@ int InterfaceIdleModeRespond(PMINI_ADAPTER Adapter, unsigned int* puiBuffer)
154 return status; 146 return status;
155} 147}
156 148
157 149static int InterfaceAbortIdlemode(PMINI_ADAPTER Adapter, unsigned int Pattern)
158VOID InterfaceWriteIdleModeWakePattern(PMINI_ADAPTER Adapter)
159{
160/* BeceemWriteMemoryUshort(Adapter, Host2CPU_Mailbox_Low, 0x1d1e);
161 BeceemWriteMemoryUshort(Adapter, Host2CPU_Mailbox_Low, 0x1d1e);
162 BeceemWriteMemoryUshort(Adapter, Host2CPU_Mailbox_Upp, 0xd0ea);
163 BeceemWriteMemoryUshort(Adapter, Host2CPU_Mailbox_Upp, 0xd0ea);*/
164 return;
165}
166
167int InterfaceAbortIdlemode(PMINI_ADAPTER Adapter, unsigned int Pattern)
168{ 150{
169 int status = STATUS_SUCCESS; 151 int status = STATUS_SUCCESS;
170 unsigned int value; 152 unsigned int value;
diff --git a/drivers/staging/bcm/InterfaceIdleMode.h b/drivers/staging/bcm/InterfaceIdleMode.h
index 1bc723d2d72c..859a2ffba6b7 100644
--- a/drivers/staging/bcm/InterfaceIdleMode.h
+++ b/drivers/staging/bcm/InterfaceIdleMode.h
@@ -7,8 +7,6 @@ INT InterfaceIdleModeRespond(PMINI_ADAPTER Adapter, unsigned int *puiBuffer);
7 7
8VOID InterfaceWriteIdleModeWakePattern(PMINI_ADAPTER Adapter); 8VOID InterfaceWriteIdleModeWakePattern(PMINI_ADAPTER Adapter);
9 9
10INT InterfaceAbortIdlemode(PMINI_ADAPTER Adapter, unsigned int Pattern);
11
12INT InterfaceWakeUp(PMINI_ADAPTER Adapter); 10INT InterfaceWakeUp(PMINI_ADAPTER Adapter);
13 11
14VOID InterfaceHandleShutdownModeWakeup(PMINI_ADAPTER Adapter); 12VOID InterfaceHandleShutdownModeWakeup(PMINI_ADAPTER Adapter);
diff --git a/drivers/staging/bcm/InterfaceInit.c b/drivers/staging/bcm/InterfaceInit.c
index e97ad99b1bb4..d78d5ef1f298 100644
--- a/drivers/staging/bcm/InterfaceInit.c
+++ b/drivers/staging/bcm/InterfaceInit.c
@@ -1,54 +1,63 @@
1#include "headers.h" 1#include "headers.h"
2 2
3static struct usb_device_id InterfaceUsbtable[] = { 3static struct usb_device_id InterfaceUsbtable[] = {
4 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3) }, 4 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3) },
5 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3B) }, 5 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3B) },
6 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3L) }, 6 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3L) },
7 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_226) }, 7 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_SM250) },
8 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_226) },
8 { USB_DEVICE(BCM_USB_VENDOR_ID_FOXCONN, BCM_USB_PRODUCT_ID_1901) }, 9 { USB_DEVICE(BCM_USB_VENDOR_ID_FOXCONN, BCM_USB_PRODUCT_ID_1901) },
9 {} 10 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_ZTE_TU25) },
11 { }
10}; 12};
13MODULE_DEVICE_TABLE(usb, InterfaceUsbtable);
11 14
12VOID InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter) 15static int debug = -1;
16module_param(debug, uint, 0600);
17MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
18
19static const u32 default_msg =
20 NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
21 | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR
22 | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
23
24static int InterfaceAdapterInit(PS_INTERFACE_ADAPTER Adapter);
25
26static void InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter)
13{ 27{
14 INT i = 0; 28 int i = 0;
15 // Wake up the wait_queue... 29
16 if(psIntfAdapter->psAdapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) 30 /* Wake up the wait_queue... */
17 { 31 if (psIntfAdapter->psAdapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
18 psIntfAdapter->psAdapter->DriverState = DRIVER_HALT; 32 psIntfAdapter->psAdapter->DriverState = DRIVER_HALT;
19 wake_up(&psIntfAdapter->psAdapter->LEDInfo.notify_led_event); 33 wake_up(&psIntfAdapter->psAdapter->LEDInfo.notify_led_event);
20 } 34 }
21 reset_card_proc(psIntfAdapter->psAdapter); 35 reset_card_proc(psIntfAdapter->psAdapter);
22 36
23 //worst case time taken by the RDM/WRM will be 5 sec. will check after every 100 ms 37 /*
24 //to accertain the device is not being accessed. After this No RDM/WRM should be made. 38 * worst case time taken by the RDM/WRM will be 5 sec. will check after every 100 ms
25 while(psIntfAdapter->psAdapter->DeviceAccess) 39 * to accertain the device is not being accessed. After this No RDM/WRM should be made.
26 { 40 */
27 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Device is being Accessed \n"); 41 while (psIntfAdapter->psAdapter->DeviceAccess) {
42 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
43 "Device is being accessed.\n");
28 msleep(100); 44 msleep(100);
29 } 45 }
30 /* Free interrupt URB */ 46 /* Free interrupt URB */
31 //psIntfAdapter->psAdapter->device_removed = TRUE; 47 /* psIntfAdapter->psAdapter->device_removed = TRUE; */
32 if(psIntfAdapter->psInterruptUrb) 48 usb_free_urb(psIntfAdapter->psInterruptUrb);
33 {
34 usb_free_urb(psIntfAdapter->psInterruptUrb);
35 }
36 49
37 /* Free transmit URBs */ 50 /* Free transmit URBs */
38 for(i = 0; i < MAXIMUM_USB_TCB; i++) 51 for (i = 0; i < MAXIMUM_USB_TCB; i++) {
39 { 52 if (psIntfAdapter->asUsbTcb[i].urb != NULL) {
40 if(psIntfAdapter->asUsbTcb[i].urb != NULL)
41 {
42 usb_free_urb(psIntfAdapter->asUsbTcb[i].urb); 53 usb_free_urb(psIntfAdapter->asUsbTcb[i].urb);
43 psIntfAdapter->asUsbTcb[i].urb = NULL; 54 psIntfAdapter->asUsbTcb[i].urb = NULL;
44 } 55 }
45 } 56 }
46 /* Free receive URB and buffers */ 57 /* Free receive URB and buffers */
47 for(i = 0; i < MAXIMUM_USB_RCB; i++) 58 for (i = 0; i < MAXIMUM_USB_RCB; i++) {
48 { 59 if (psIntfAdapter->asUsbRcb[i].urb != NULL) {
49 if (psIntfAdapter->asUsbRcb[i].urb != NULL) 60 kfree(psIntfAdapter->asUsbRcb[i].urb->transfer_buffer);
50 {
51 bcm_kfree(psIntfAdapter->asUsbRcb[i].urb->transfer_buffer);
52 usb_free_urb(psIntfAdapter->asUsbRcb[i].urb); 61 usb_free_urb(psIntfAdapter->asUsbRcb[i].urb);
53 psIntfAdapter->asUsbRcb[i].urb = NULL; 62 psIntfAdapter->asUsbRcb[i].urb = NULL;
54 } 63 }
@@ -56,151 +65,109 @@ VOID InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter)
56 AdapterFree(psIntfAdapter->psAdapter); 65 AdapterFree(psIntfAdapter->psAdapter);
57} 66}
58 67
59 68static void ConfigureEndPointTypesThroughEEPROM(PMINI_ADAPTER Adapter)
60
61static int usbbcm_open(struct inode *inode, struct file *file)
62{
63 return 0;
64}
65
66static int usbbcm_release(struct inode *inode, struct file *file)
67{
68 return 0;
69}
70
71static ssize_t usbbcm_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
72{
73 return 0;
74}
75
76static ssize_t usbbcm_write(struct file *file, const char __user *user_buffer, size_t count, loff_t *ppos)
77{ 69{
78 return 0; 70 unsigned long ulReg = 0;
79} 71 int ret;
80 72
81 73 /* Program EP2 MAX_PKT_SIZE */
82VOID ConfigureEndPointTypesThroughEEPROM(PMINI_ADAPTER Adapter)
83{
84 ULONG ulReg = 0;
85
86// Program EP2 MAX_PKT_SIZE
87 ulReg = ntohl(EP2_MPS_REG); 74 ulReg = ntohl(EP2_MPS_REG);
88 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x128,4,TRUE); 75 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x128, 4, TRUE);
89 ulReg = ntohl(EP2_MPS); 76 ulReg = ntohl(EP2_MPS);
90 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x12C,4,TRUE); 77 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x12C, 4, TRUE);
91 78
92 ulReg = ntohl(EP2_CFG_REG); 79 ulReg = ntohl(EP2_CFG_REG);
93 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x132,4,TRUE); 80 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x132, 4, TRUE);
94 if(((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter))->bHighSpeedDevice == TRUE) 81 if (((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter))->bHighSpeedDevice == TRUE) {
95 {
96 ulReg = ntohl(EP2_CFG_INT); 82 ulReg = ntohl(EP2_CFG_INT);
97 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x136,4,TRUE); 83 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE);
98 } 84 } else {
99 else 85 /* USE BULK EP as TX in FS mode. */
100 {
101// USE BULK EP as TX in FS mode.
102 ulReg = ntohl(EP2_CFG_BULK); 86 ulReg = ntohl(EP2_CFG_BULK);
103 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x136,4,TRUE); 87 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE);
104 } 88 }
105 89
106 90 /* Program EP4 MAX_PKT_SIZE. */
107// Program EP4 MAX_PKT_SIZE.
108 ulReg = ntohl(EP4_MPS_REG); 91 ulReg = ntohl(EP4_MPS_REG);
109 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x13C,4,TRUE); 92 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x13C, 4, TRUE);
110 ulReg = ntohl(EP4_MPS); 93 ulReg = ntohl(EP4_MPS);
111 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x140,4,TRUE); 94 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x140, 4, TRUE);
112 95
113// Program TX EP as interrupt (Alternate Setting) 96 /* Program TX EP as interrupt(Alternate Setting) */
114 if( rdmalt(Adapter,0x0F0110F8, (PUINT)&ulReg,4)) 97 ret = rdmalt(Adapter, 0x0F0110F8, (u32 *)&ulReg, sizeof(u32));
115 { 98 if (ret) {
116 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reading of Tx EP is failing"); 99 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
117 return ; 100 "reading of Tx EP failed\n");
101 return;
118 } 102 }
119 ulReg |= 0x6; 103 ulReg |= 0x6;
120 104
121 ulReg = ntohl(ulReg); 105 ulReg = ntohl(ulReg);
122 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1CC,4,TRUE); 106 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1CC, 4, TRUE);
123 107
124 ulReg = ntohl(EP4_CFG_REG); 108 ulReg = ntohl(EP4_CFG_REG);
125 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1C8,4,TRUE); 109 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C8, 4, TRUE);
126// Program ISOCHRONOUS EP size to zero. 110 /* Program ISOCHRONOUS EP size to zero. */
127 ulReg = ntohl(ISO_MPS_REG); 111 ulReg = ntohl(ISO_MPS_REG);
128 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1D2,4,TRUE); 112 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D2, 4, TRUE);
129 ulReg = ntohl(ISO_MPS); 113 ulReg = ntohl(ISO_MPS);
130 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1D6,4,TRUE); 114 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D6, 4, TRUE);
131 115
132// Update EEPROM Version. 116 /*
133// Read 4 bytes from 508 and modify 511 and 510. 117 * Update EEPROM Version.
134// 118 * Read 4 bytes from 508 and modify 511 and 510.
135 ReadBeceemEEPROM(Adapter,0x1FC,(PUINT)&ulReg); 119 */
120 ReadBeceemEEPROM(Adapter, 0x1FC, (PUINT)&ulReg);
136 ulReg &= 0x0101FFFF; 121 ulReg &= 0x0101FFFF;
137 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1FC,4,TRUE); 122 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1FC, 4, TRUE);
138// 123
139//Update length field if required. Also make the string NULL terminated. 124 /* Update length field if required. Also make the string NULL terminated. */
140// 125
141 ReadBeceemEEPROM(Adapter,0xA8,(PUINT)&ulReg); 126 ReadBeceemEEPROM(Adapter, 0xA8, (PUINT)&ulReg);
142 if((ulReg&0x00FF0000)>>16 > 0x30) 127 if ((ulReg&0x00FF0000)>>16 > 0x30) {
143 {
144 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16); 128 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
145 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0xA8,4,TRUE); 129 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0xA8, 4, TRUE);
146 } 130 }
147 ReadBeceemEEPROM(Adapter,0x148,(PUINT)&ulReg); 131 ReadBeceemEEPROM(Adapter, 0x148, (PUINT)&ulReg);
148 if((ulReg&0x00FF0000)>>16 > 0x30) 132 if ((ulReg&0x00FF0000)>>16 > 0x30) {
149 {
150 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16); 133 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
151 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x148,4,TRUE); 134 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x148, 4, TRUE);
152 } 135 }
153 ulReg = 0; 136 ulReg = 0;
154 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x122,4,TRUE); 137 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x122, 4, TRUE);
155 ulReg = 0; 138 ulReg = 0;
156 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)&ulReg,0x1C2,4,TRUE); 139 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C2, 4, TRUE);
157
158} 140}
159 141
160static struct file_operations usbbcm_fops = {
161 .open = usbbcm_open,
162 .release = usbbcm_release,
163 .read = usbbcm_read,
164 .write = usbbcm_write,
165 .owner = THIS_MODULE,
166 .llseek = no_llseek,
167};
168
169static struct usb_class_driver usbbcm_class = {
170 .name = "usbbcm",
171 .fops = &usbbcm_fops,
172 .minor_base = BCM_USB_MINOR_BASE,
173};
174
175static int 142static int
176usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id) 143usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id)
177{ 144{
178 int retval =0 ; 145 struct usb_device *udev = interface_to_usbdev(intf);
179 PMINI_ADAPTER psAdapter = NULL; 146 int retval;
180 PS_INTERFACE_ADAPTER psIntfAdapter = NULL; 147 PMINI_ADAPTER psAdapter;
181 struct usb_device *udev = NULL; 148 PS_INTERFACE_ADAPTER psIntfAdapter;
182 149 struct net_device *ndev;
183// BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Usbbcm probe!!");
184 if((intf == NULL) || (id == NULL))
185 {
186 // BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "intf or id is NULL");
187 return -EINVAL;
188 }
189 150
190 /* Allocate Adapter structure */ 151 /* Reserve one extra queue for the bit-bucket */
191 if((psAdapter = kzalloc(sizeof(MINI_ADAPTER), GFP_KERNEL)) == NULL) 152 ndev = alloc_etherdev_mq(sizeof(MINI_ADAPTER), NO_OF_QUEUES+1);
192 { 153 if (ndev == NULL) {
193 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0, "Out of memory"); 154 dev_err(&udev->dev, DRV_NAME ": no memory for device\n");
194 return -ENOMEM; 155 return -ENOMEM;
195 } 156 }
196 157
197 /* Init default driver debug state */ 158 SET_NETDEV_DEV(ndev, &intf->dev);
198 159
199 psAdapter->stDebugState.debug_level = DBG_LVL_CURR; 160 psAdapter = netdev_priv(ndev);
161 psAdapter->dev = ndev;
162 psAdapter->msg_enable = netif_msg_init(debug, default_msg);
163
164 /* Init default driver debug state */
165
166 psAdapter->stDebugState.debug_level = DBG_LVL_CURR;
200 psAdapter->stDebugState.type = DBG_TYPE_INITEXIT; 167 psAdapter->stDebugState.type = DBG_TYPE_INITEXIT;
201 memset (psAdapter->stDebugState.subtype, 0, sizeof (psAdapter->stDebugState.subtype));
202 168
203 /* Technically, one can start using BCM_DEBUG_PRINT after this point. 169 /*
170 * Technically, one can start using BCM_DEBUG_PRINT after this point.
204 * However, realize that by default the Type/Subtype bitmaps are all zero now; 171 * However, realize that by default the Type/Subtype bitmaps are all zero now;
205 * so no prints will actually appear until the TestApp turns on debug paths via 172 * so no prints will actually appear until the TestApp turns on debug paths via
206 * the ioctl(); so practically speaking, in early init, no logging happens. 173 * the ioctl(); so practically speaking, in early init, no logging happens.
@@ -211,160 +178,128 @@ usbbcm_device_probe(struct usb_interface *intf, const struct usb_device_id *id)
211 * Further, we turn this OFF once init_module() completes. 178 * Further, we turn this OFF once init_module() completes.
212 */ 179 */
213 180
214 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff; 181 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff;
215 BCM_SHOW_DEBUG_BITMAP(psAdapter); 182 BCM_SHOW_DEBUG_BITMAP(psAdapter);
216 183
217 retval = InitAdapter(psAdapter); 184 retval = InitAdapter(psAdapter);
218 if(retval) 185 if (retval) {
219 { 186 dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n");
220 BCM_DEBUG_PRINT (psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "InitAdapter Failed\n");
221 AdapterFree(psAdapter); 187 AdapterFree(psAdapter);
222 return retval; 188 return retval;
223 } 189 }
224 190
225 /* Allocate interface adapter structure */ 191 /* Allocate interface adapter structure */
226 if((psAdapter->pvInterfaceAdapter = 192 psIntfAdapter = kzalloc(sizeof(S_INTERFACE_ADAPTER), GFP_KERNEL);
227 kmalloc(sizeof(S_INTERFACE_ADAPTER), GFP_KERNEL)) == NULL) 193 if (psIntfAdapter == NULL) {
228 { 194 dev_err(&udev->dev, DRV_NAME ": no memory for Interface adapter\n");
229 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0, "Out of memory"); 195 AdapterFree(psAdapter);
230 AdapterFree (psAdapter);
231 return -ENOMEM; 196 return -ENOMEM;
232 } 197 }
233 memset(psAdapter->pvInterfaceAdapter, 0, sizeof(S_INTERFACE_ADAPTER));
234 198
235 psIntfAdapter = InterfaceAdapterGet(psAdapter); 199 psAdapter->pvInterfaceAdapter = psIntfAdapter;
236 psIntfAdapter->psAdapter = psAdapter; 200 psIntfAdapter->psAdapter = psAdapter;
237 201
238 /* Store usb interface in Interface Adapter */ 202 /* Store usb interface in Interface Adapter */
239 psIntfAdapter->interface = intf; 203 psIntfAdapter->interface = intf;
240 usb_set_intfdata(intf, psIntfAdapter); 204 usb_set_intfdata(intf, psIntfAdapter);
241 205
242 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%p",psIntfAdapter); 206 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
207 "psIntfAdapter 0x%p\n", psIntfAdapter);
243 retval = InterfaceAdapterInit(psIntfAdapter); 208 retval = InterfaceAdapterInit(psIntfAdapter);
244 if(retval) 209 if (retval) {
245 {
246 /* If the Firmware/Cfg File is not present 210 /* If the Firmware/Cfg File is not present
247 * then return success, let the application 211 * then return success, let the application
248 * download the files. 212 * download the files.
249 */ 213 */
250 if(-ENOENT == retval){ 214 if (-ENOENT == retval) {
251 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "File Not Found, Use App to Download\n"); 215 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
216 "File Not Found. Use app to download.\n");
252 return STATUS_SUCCESS; 217 return STATUS_SUCCESS;
253 } 218 }
254 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "InterfaceAdapterInit Failed \n"); 219 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
220 "InterfaceAdapterInit failed.\n");
255 usb_set_intfdata(intf, NULL); 221 usb_set_intfdata(intf, NULL);
256 udev = interface_to_usbdev (intf); 222 udev = interface_to_usbdev(intf);
257 usb_put_dev(udev); 223 usb_put_dev(udev);
258 if(psAdapter->bUsbClassDriverRegistered == TRUE)
259 usb_deregister_dev (intf, &usbbcm_class);
260 InterfaceAdapterFree(psIntfAdapter); 224 InterfaceAdapterFree(psIntfAdapter);
261 return retval ; 225 return retval;
262 } 226 }
263 if(psAdapter->chip_id > T3) 227 if (psAdapter->chip_id > T3) {
264 { 228 uint32_t uiNackZeroLengthInt = 4;
265 uint32_t uiNackZeroLengthInt=4; 229
266 if(wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT, &uiNackZeroLengthInt, sizeof(uiNackZeroLengthInt))) 230 retval = wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT, &uiNackZeroLengthInt, sizeof(uiNackZeroLengthInt));
267 { 231 if (retval)
268 return -EIO;; 232 return retval;
269 }
270 } 233 }
271 234
272 udev = interface_to_usbdev (intf);
273 /* Check whether the USB-Device Supports remote Wake-Up */ 235 /* Check whether the USB-Device Supports remote Wake-Up */
274 if(USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes) 236 if (USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes) {
275 {
276 /* If Suspend then only support dynamic suspend */ 237 /* If Suspend then only support dynamic suspend */
277 if(psAdapter->bDoSuspend) 238 if (psAdapter->bDoSuspend) {
278 {
279#ifdef CONFIG_PM 239#ifdef CONFIG_PM
280 pm_runtime_set_autosuspend_delay(&udev->dev, 0); 240 pm_runtime_set_autosuspend_delay(&udev->dev, 0);
281 intf->needs_remote_wakeup = 1; 241 intf->needs_remote_wakeup = 1;
282#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
283 udev->autosuspend_disabled = 0;
284#else
285 usb_enable_autosuspend(udev); 242 usb_enable_autosuspend(udev);
286#endif 243 device_init_wakeup(&intf->dev, 1);
287 device_init_wakeup(&intf->dev,1);
288#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32)
289 usb_autopm_disable(intf);
290#endif
291 INIT_WORK(&psIntfAdapter->usbSuspendWork, putUsbSuspend); 244 INIT_WORK(&psIntfAdapter->usbSuspendWork, putUsbSuspend);
292 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Enabling USB Auto-Suspend\n"); 245 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
246 "Enabling USB Auto-Suspend\n");
293#endif 247#endif
294 } 248 } else {
295 else
296 {
297 intf->needs_remote_wakeup = 0; 249 intf->needs_remote_wakeup = 0;
298#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
299 udev->autosuspend_disabled = 1;
300#else
301 usb_disable_autosuspend(udev); 250 usb_disable_autosuspend(udev);
302#endif
303 } 251 }
304 } 252 }
305 253
306 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0; 254 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0;
307 return retval; 255 return retval;
308} 256}
309 257
310static void usbbcm_disconnect (struct usb_interface *intf) 258static void usbbcm_disconnect(struct usb_interface *intf)
311{ 259{
312 PS_INTERFACE_ADAPTER psIntfAdapter = NULL; 260 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
313 PMINI_ADAPTER psAdapter = NULL; 261 PMINI_ADAPTER psAdapter;
314 struct usb_device *udev = NULL; 262 struct usb_device *udev = interface_to_usbdev(intf);
315 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 263
316 264 if (psIntfAdapter == NULL)
317 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Usb disconnected");
318 if(intf == NULL)
319 {
320 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "intf pointer is NULL");
321 return;
322 }
323 psIntfAdapter = usb_get_intfdata(intf);
324 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "psIntfAdapter 0x%p",psIntfAdapter);
325 if(psIntfAdapter == NULL)
326 {
327 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "InterfaceAdapter pointer is NULL");
328 return; 265 return;
329 } 266
330 psAdapter = psIntfAdapter->psAdapter; 267 psAdapter = psIntfAdapter->psAdapter;
331 if(psAdapter->bDoSuspend) 268 netif_device_detach(psAdapter->dev);
269
270 if (psAdapter->bDoSuspend)
332 intf->needs_remote_wakeup = 0; 271 intf->needs_remote_wakeup = 0;
333 272
334 psAdapter->device_removed = TRUE ; 273 psAdapter->device_removed = TRUE ;
335 usb_set_intfdata(intf, NULL); 274 usb_set_intfdata(intf, NULL);
336 InterfaceAdapterFree(psIntfAdapter); 275 InterfaceAdapterFree(psIntfAdapter);
337 udev = interface_to_usbdev (intf);
338 usb_put_dev(udev); 276 usb_put_dev(udev);
339 usb_deregister_dev (intf, &usbbcm_class);
340} 277}
341 278
342 279static int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter)
343static __inline int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter)
344{ 280{
345 int i = 0; 281 int i = 0;
346 for(i = 0; i < MAXIMUM_USB_TCB; i++) 282
347 { 283 for (i = 0; i < MAXIMUM_USB_TCB; i++) {
348 if((psIntfAdapter->asUsbTcb[i].urb = 284 if ((psIntfAdapter->asUsbTcb[i].urb =
349 usb_alloc_urb(0, GFP_KERNEL)) == NULL) 285 usb_alloc_urb(0, GFP_KERNEL)) == NULL) {
350 { 286 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
351 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Tx urb for index %d", i); 287 "Can't allocate Tx urb for index %d\n", i);
352 return -ENOMEM; 288 return -ENOMEM;
353 } 289 }
354 } 290 }
355 291
356 for(i = 0; i < MAXIMUM_USB_RCB; i++) 292 for (i = 0; i < MAXIMUM_USB_RCB; i++) {
357 {
358 if ((psIntfAdapter->asUsbRcb[i].urb = 293 if ((psIntfAdapter->asUsbRcb[i].urb =
359 usb_alloc_urb(0, GFP_KERNEL)) == NULL) 294 usb_alloc_urb(0, GFP_KERNEL)) == NULL) {
360 { 295 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
361 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Rx urb for index %d", i); 296 "Can't allocate Rx urb for index %d\n", i);
362 return -ENOMEM; 297 return -ENOMEM;
363 } 298 }
364 if((psIntfAdapter->asUsbRcb[i].urb->transfer_buffer = 299 if ((psIntfAdapter->asUsbRcb[i].urb->transfer_buffer =
365 kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL)) == NULL) 300 kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL)) == NULL) {
366 { 301 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
367 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cant allocate Rx buffer for index %d", i); 302 "Can't allocate Rx buffer for index %d\n", i);
368 return -ENOMEM; 303 return -ENOMEM;
369 } 304 }
370 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length = MAX_DATA_BUFFER_SIZE; 305 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length = MAX_DATA_BUFFER_SIZE;
@@ -372,77 +307,41 @@ static __inline int AllocUsbCb(PS_INTERFACE_ADAPTER psIntfAdapter)
372 return 0; 307 return 0;
373} 308}
374 309
375
376
377static int device_run(PS_INTERFACE_ADAPTER psIntfAdapter) 310static int device_run(PS_INTERFACE_ADAPTER psIntfAdapter)
378{ 311{
379 INT value = 0; 312 int value = 0;
380 UINT status = STATUS_SUCCESS; 313 UINT status = STATUS_SUCCESS;
381 314
382 status = InitCardAndDownloadFirmware(psIntfAdapter->psAdapter); 315 status = InitCardAndDownloadFirmware(psIntfAdapter->psAdapter);
383 if(status != STATUS_SUCCESS) 316 if (status != STATUS_SUCCESS) {
384 { 317 pr_err(DRV_NAME "InitCardAndDownloadFirmware failed.\n");
385 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "InitCardAndDownloadFirmware failed.\n");
386 return status; 318 return status;
387 } 319 }
388 if(TRUE == psIntfAdapter->psAdapter->fw_download_done) 320 if (TRUE == psIntfAdapter->psAdapter->fw_download_done) {
389 { 321 if (StartInterruptUrb(psIntfAdapter)) {
390 322 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
391 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Sending first interrupt URB down......"); 323 "Cannot send interrupt in URB\n");
392 if(StartInterruptUrb(psIntfAdapter))
393 {
394 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Cannot send interrupt in URB");
395 } 324 }
396 //now register the cntrl interface.
397 //after downloading the f/w waiting for 5 sec to get the mailbox interrupt.
398 325
326 /*
327 * now register the cntrl interface.
328 * after downloading the f/w waiting for 5 sec to get the mailbox interrupt.
329 */
399 psIntfAdapter->psAdapter->waiting_to_fw_download_done = FALSE; 330 psIntfAdapter->psAdapter->waiting_to_fw_download_done = FALSE;
400 value = wait_event_timeout(psIntfAdapter->psAdapter->ioctl_fw_dnld_wait_queue, 331 value = wait_event_timeout(psIntfAdapter->psAdapter->ioctl_fw_dnld_wait_queue,
401 psIntfAdapter->psAdapter->waiting_to_fw_download_done, 5*HZ); 332 psIntfAdapter->psAdapter->waiting_to_fw_download_done, 5*HZ);
402 333
403 if(value == 0) 334 if (value == 0)
404 { 335 pr_err(DRV_NAME ": Timeout waiting for mailbox interrupt.\n");
405 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Mailbox Interrupt has not reached to Driver.."); 336
406 } 337 if (register_control_device_interface(psIntfAdapter->psAdapter) < 0) {
407 else 338 pr_err(DRV_NAME ": Register Control Device failed.\n");
408 {
409 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Got the mailbox interrupt ...Registering control interface...\n ");
410 }
411 if(register_control_device_interface(psIntfAdapter->psAdapter) < 0)
412 {
413 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Register Control Device failed...");
414 return -EIO; 339 return -EIO;
415 } 340 }
416 } 341 }
417 return 0; 342 return 0;
418} 343}
419 344
420#if 0
421static void print_usb_interface_desc(struct usb_interface_descriptor *usb_intf_desc)
422{
423 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "**************** INTERFACE DESCRIPTOR *********************");
424 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bLength: %x", usb_intf_desc->bLength);
425 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bDescriptorType: %x", usb_intf_desc->bDescriptorType);
426 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bInterfaceNumber: %x", usb_intf_desc->bInterfaceNumber);
427 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bAlternateSetting: %x", usb_intf_desc->bAlternateSetting);
428 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bNumEndpoints: %x", usb_intf_desc->bNumEndpoints);
429 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bInterfaceClass: %x", usb_intf_desc->bInterfaceClass);
430 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bInterfaceSubClass: %x", usb_intf_desc->bInterfaceSubClass);
431 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bInterfaceProtocol: %x", usb_intf_desc->bInterfaceProtocol);
432 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "iInterface :%x\n",usb_intf_desc->iInterface);
433}
434static void print_usb_endpoint_descriptor(struct usb_endpoint_descriptor *usb_ep_desc)
435{
436 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "**************** ENDPOINT DESCRIPTOR *********************");
437 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bLength :%x ", usb_ep_desc->bLength);
438 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bDescriptorType :%x ", usb_ep_desc->bDescriptorType);
439 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bEndpointAddress :%x ", usb_ep_desc->bEndpointAddress);
440 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bmAttributes :%x ", usb_ep_desc->bmAttributes);
441 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "wMaxPacketSize :%x ",usb_ep_desc->wMaxPacketSize);
442 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "bInterval :%x ",usb_ep_desc->bInterval);
443}
444
445#endif
446 345
447static inline int bcm_usb_endpoint_num(const struct usb_endpoint_descriptor *epd) 346static inline int bcm_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
448{ 347{
@@ -518,124 +417,111 @@ static inline int bcm_usb_endpoint_is_isoc_out(const struct usb_endpoint_descrip
518 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_out(epd)); 417 return (bcm_usb_endpoint_xfer_isoc(epd) && bcm_usb_endpoint_dir_out(epd));
519} 418}
520 419
521INT InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter) 420static int InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter)
522{ 421{
523 struct usb_host_interface *iface_desc; 422 struct usb_host_interface *iface_desc;
524 struct usb_endpoint_descriptor *endpoint; 423 struct usb_endpoint_descriptor *endpoint;
525 size_t buffer_size; 424 size_t buffer_size;
526 ULONG value; 425 unsigned long value;
527 INT retval = 0; 426 int retval = 0;
528 INT usedIntOutForBulkTransfer = 0 ; 427 int usedIntOutForBulkTransfer = 0 ;
529 BOOLEAN bBcm16 = FALSE; 428 BOOLEAN bBcm16 = FALSE;
530 UINT uiData = 0; 429 UINT uiData = 0;
531 430
532 /* Store the usb dev into interface adapter */ 431 /* Store the usb dev into interface adapter */
533 psIntfAdapter->udev = usb_get_dev(interface_to_usbdev( 432 psIntfAdapter->udev = usb_get_dev(interface_to_usbdev(psIntfAdapter->interface));
534 psIntfAdapter->interface));
535
536 if((psIntfAdapter->udev->speed == USB_SPEED_HIGH))
537 {
538 psIntfAdapter->bHighSpeedDevice = TRUE ;
539 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "MODEM IS CONFIGURED TO HIGH_SPEED ");
540 }
541 else
542 {
543 psIntfAdapter->bHighSpeedDevice = FALSE ;
544 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "MODEM IS CONFIGURED TO FULL_SPEED ");
545 }
546 433
434 psIntfAdapter->bHighSpeedDevice = (psIntfAdapter->udev->speed == USB_SPEED_HIGH);
547 psIntfAdapter->psAdapter->interface_rdm = BcmRDM; 435 psIntfAdapter->psAdapter->interface_rdm = BcmRDM;
548 psIntfAdapter->psAdapter->interface_wrm = BcmWRM; 436 psIntfAdapter->psAdapter->interface_wrm = BcmWRM;
549 437
550 if(rdmalt(psIntfAdapter->psAdapter, CHIP_ID_REG, (PUINT)&(psIntfAdapter->psAdapter->chip_id), sizeof(UINT)) < 0) 438 retval = rdmalt(psIntfAdapter->psAdapter, CHIP_ID_REG,
551 { 439 (u32 *)&(psIntfAdapter->psAdapter->chip_id), sizeof(u32));
552 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "CHIP ID Read Failed\n"); 440 if (retval) {
553 return STATUS_FAILURE; 441 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0, "CHIP ID Read Failed\n");
554 } 442 return retval;
555 if(0xbece3200==(psIntfAdapter->psAdapter->chip_id&~(0xF0)))
556 {
557 psIntfAdapter->psAdapter->chip_id=(psIntfAdapter->psAdapter->chip_id&~(0xF0));
558 } 443 }
559 444
560 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "First RDM Chip ID 0x%lx\n", psIntfAdapter->psAdapter->chip_id); 445 if (0xbece3200 == (psIntfAdapter->psAdapter->chip_id & ~(0xF0)))
446 psIntfAdapter->psAdapter->chip_id &= ~0xF0;
561 447
562 iface_desc = psIntfAdapter->interface->cur_altsetting; 448 dev_info(&psIntfAdapter->udev->dev, "RDM Chip ID 0x%lx\n",
563 //print_usb_interface_desc(&(iface_desc->desc)); 449 psIntfAdapter->psAdapter->chip_id);
564 450
565 if(psIntfAdapter->psAdapter->chip_id == T3B) 451 iface_desc = psIntfAdapter->interface->cur_altsetting;
566 {
567 452
568 // 453 if (psIntfAdapter->psAdapter->chip_id == T3B) {
569 //T3B device will have EEPROM,check if EEPROM is proper and BCM16 can be done or not. 454 /* T3B device will have EEPROM, check if EEPROM is proper and BCM16 can be done or not. */
570 // 455 BeceemEEPROMBulkRead(psIntfAdapter->psAdapter, &uiData, 0x0, 4);
571 BeceemEEPROMBulkRead(psIntfAdapter->psAdapter,&uiData,0x0,4); 456 if (uiData == BECM)
572 if(uiData == BECM)
573 {
574 bBcm16 = TRUE; 457 bBcm16 = TRUE;
575 } 458
576 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Number of Altsetting aviailable for This Modem 0x%x\n", psIntfAdapter->interface->num_altsetting); 459 dev_info(&psIntfAdapter->udev->dev, "number of alternate setting %d\n",
577 if(bBcm16 == TRUE) 460 psIntfAdapter->interface->num_altsetting);
578 { 461
579 //selecting alternate setting one as a default setting for High Speed modem. 462 if (bBcm16 == TRUE) {
580 if(psIntfAdapter->bHighSpeedDevice) 463 /* selecting alternate setting one as a default setting for High Speed modem. */
581 retval= usb_set_interface(psIntfAdapter->udev,DEFAULT_SETTING_0,ALTERNATE_SETTING_1); 464 if (psIntfAdapter->bHighSpeedDevice)
582 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "BCM16 is Applicable on this dongle"); 465 retval= usb_set_interface(psIntfAdapter->udev, DEFAULT_SETTING_0, ALTERNATE_SETTING_1);
583 if(retval || (psIntfAdapter->bHighSpeedDevice == FALSE)) 466 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
584 { 467 "BCM16 is applicable on this dongle\n");
468 if (retval || (psIntfAdapter->bHighSpeedDevice == FALSE)) {
585 usedIntOutForBulkTransfer = EP2 ; 469 usedIntOutForBulkTransfer = EP2 ;
586 endpoint = &iface_desc->endpoint[EP2].desc; 470 endpoint = &iface_desc->endpoint[EP2].desc;
587 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Interface altsetting got failed or Moemd is configured to FS.hence will work on default setting 0 \n"); 471 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
472 "Interface altsetting failed or modem is configured to Full Speed, hence will work on default setting 0\n");
588 /* 473 /*
589 If Modem is high speed device EP2 should be INT OUT End point 474 * If Modem is high speed device EP2 should be INT OUT End point
590 If Mode is FS then EP2 should be bulk end point 475 * If Mode is FS then EP2 should be bulk end point
591 */ 476 */
592 if(((psIntfAdapter->bHighSpeedDevice ==TRUE ) && (bcm_usb_endpoint_is_int_out(endpoint)== FALSE)) 477 if (((psIntfAdapter->bHighSpeedDevice == TRUE) && (bcm_usb_endpoint_is_int_out(endpoint) == FALSE))
593 ||((psIntfAdapter->bHighSpeedDevice == FALSE)&& (bcm_usb_endpoint_is_bulk_out(endpoint)== FALSE))) 478 || ((psIntfAdapter->bHighSpeedDevice == FALSE) && (bcm_usb_endpoint_is_bulk_out(endpoint) == FALSE))) {
594 { 479 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
595 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Configuring the EEPROM "); 480 "Configuring the EEPROM\n");
596 //change the EP2, EP4 to INT OUT end point 481 /* change the EP2, EP4 to INT OUT end point */
597 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter); 482 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
598 483
599 /* 484 /*
600 It resets the device and if any thing gets changed in USB descriptor it will show fail and 485 * It resets the device and if any thing gets changed
601 re-enumerate the device 486 * in USB descriptor it will show fail and re-enumerate
602 */ 487 * the device
488 */
603 retval = usb_reset_device(psIntfAdapter->udev); 489 retval = usb_reset_device(psIntfAdapter->udev);
604 if(retval) 490 if (retval) {
605 { 491 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
606 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reset got failed. hence Re-enumerating the device \n"); 492 "reset failed. Re-enumerating the device.\n");
607 return retval ; 493 return retval ;
608 } 494 }
609 495
610 } 496 }
611 if((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint)) 497 if ((psIntfAdapter->bHighSpeedDevice == FALSE) && bcm_usb_endpoint_is_bulk_out(endpoint)) {
612 { 498 /* Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail. */
613 // Once BULK is selected in FS mode. Revert it back to INT. Else USB_IF will fail.
614 UINT _uiData = ntohl(EP2_CFG_INT); 499 UINT _uiData = ntohl(EP2_CFG_INT);
615 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,"Reverting Bulk to INT as it is FS MODE"); 500 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
616 BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter,(PUCHAR)&_uiData,0x136,4,TRUE); 501 "Reverting Bulk to INT as it is in Full Speed mode.\n");
502 BeceemEEPROMBulkWrite(psIntfAdapter->psAdapter, (PUCHAR)&_uiData, 0x136, 4, TRUE);
617 } 503 }
618 } 504 } else {
619 else
620 {
621 usedIntOutForBulkTransfer = EP4 ; 505 usedIntOutForBulkTransfer = EP4 ;
622 endpoint = &iface_desc->endpoint[EP4].desc; 506 endpoint = &iface_desc->endpoint[EP4].desc;
623 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Choosing AltSetting as a default setting"); 507 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
624 if( bcm_usb_endpoint_is_int_out(endpoint) == FALSE) 508 "Choosing AltSetting as a default setting.\n");
625 { 509 if (bcm_usb_endpoint_is_int_out(endpoint) == FALSE) {
626 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, " Dongle does not have BCM16 Fix"); 510 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
627 //change the EP2, EP4 to INT OUT end point and use EP4 in altsetting 511 "Dongle does not have BCM16 Fix.\n");
512 /* change the EP2, EP4 to INT OUT end point and use EP4 in altsetting */
628 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter); 513 ConfigureEndPointTypesThroughEEPROM(psIntfAdapter->psAdapter);
629 514
630 /* 515 /*
631 It resets the device and if any thing gets changed in USB descriptor it will show fail and 516 * It resets the device and if any thing gets changed in
632 re-enumerate the device 517 * USB descriptor it will show fail and re-enumerate the
633 */ 518 * device
519 */
634 retval = usb_reset_device(psIntfAdapter->udev); 520 retval = usb_reset_device(psIntfAdapter->udev);
635 if(retval) 521 if (retval) {
636 { 522 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
637 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "reset got failed. hence Re-enumerating the device \n"); 523 "reset failed. Re-enumerating the device.\n");
638 return retval ; 524 return retval;
639 } 525 }
640 526
641 } 527 }
@@ -644,99 +530,67 @@ INT InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter)
644 } 530 }
645 531
646 iface_desc = psIntfAdapter->interface->cur_altsetting; 532 iface_desc = psIntfAdapter->interface->cur_altsetting;
647 //print_usb_interface_desc(&(iface_desc->desc)); 533
648 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Current number of endpoints :%x \n", iface_desc->desc.bNumEndpoints); 534 for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value) {
649 for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value) 535 endpoint = &iface_desc->endpoint[value].desc;
650 { 536
651 endpoint = &iface_desc->endpoint[value].desc; 537 if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr && bcm_usb_endpoint_is_bulk_in(endpoint)) {
652 //print_usb_endpoint_descriptor(endpoint); 538 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
653 539 psIntfAdapter->sBulkIn.bulk_in_size = buffer_size;
654 if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr && bcm_usb_endpoint_is_bulk_in(endpoint)) 540 psIntfAdapter->sBulkIn.bulk_in_endpointAddr = endpoint->bEndpointAddress;
655 { 541 psIntfAdapter->sBulkIn.bulk_in_pipe =
656 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
657 psIntfAdapter->sBulkIn.bulk_in_size = buffer_size;
658 psIntfAdapter->sBulkIn.bulk_in_endpointAddr =
659 endpoint->bEndpointAddress;
660 psIntfAdapter->sBulkIn.bulk_in_pipe =
661 usb_rcvbulkpipe(psIntfAdapter->udev, 542 usb_rcvbulkpipe(psIntfAdapter->udev,
662 psIntfAdapter->sBulkIn.bulk_in_endpointAddr); 543 psIntfAdapter->sBulkIn.bulk_in_endpointAddr);
663 } 544 }
664
665 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && bcm_usb_endpoint_is_bulk_out(endpoint))
666 {
667 545
668 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = 546 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr && bcm_usb_endpoint_is_bulk_out(endpoint)) {
669 endpoint->bEndpointAddress; 547 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress;
670 psIntfAdapter->sBulkOut.bulk_out_pipe = 548 psIntfAdapter->sBulkOut.bulk_out_pipe =
671 usb_sndbulkpipe(psIntfAdapter->udev, 549 usb_sndbulkpipe(psIntfAdapter->udev,
672 psIntfAdapter->sBulkOut.bulk_out_endpointAddr); 550 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
673 } 551 }
674 552
675 if (!psIntfAdapter->sIntrIn.int_in_endpointAddr && bcm_usb_endpoint_is_int_in(endpoint)) 553 if (!psIntfAdapter->sIntrIn.int_in_endpointAddr && bcm_usb_endpoint_is_int_in(endpoint)) {
676 { 554 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
677 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 555 psIntfAdapter->sIntrIn.int_in_size = buffer_size;
678 psIntfAdapter->sIntrIn.int_in_size = buffer_size; 556 psIntfAdapter->sIntrIn.int_in_endpointAddr = endpoint->bEndpointAddress;
679 psIntfAdapter->sIntrIn.int_in_endpointAddr = 557 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval;
680 endpoint->bEndpointAddress; 558 psIntfAdapter->sIntrIn.int_in_buffer =
681 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval;
682 psIntfAdapter->sIntrIn.int_in_buffer =
683 kmalloc(buffer_size, GFP_KERNEL); 559 kmalloc(buffer_size, GFP_KERNEL);
684 if (!psIntfAdapter->sIntrIn.int_in_buffer) { 560 if (!psIntfAdapter->sIntrIn.int_in_buffer) {
685 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Could not allocate interrupt_in_buffer"); 561 dev_err(&psIntfAdapter->udev->dev,
686 return -EINVAL; 562 "could not allocate interrupt_in_buffer\n");
687 } 563 return -EINVAL;
688 //psIntfAdapter->sIntrIn.int_in_pipe = 564 }
689 } 565 }
690
691 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint))
692 {
693
694 if( !psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
695 (psIntfAdapter->psAdapter->chip_id == T3B) && (value == usedIntOutForBulkTransfer))
696 {
697 //use first intout end point as a bulk out end point
698 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
699 psIntfAdapter->sBulkOut.bulk_out_size = buffer_size;
700 //printk("\nINT OUT Endpoing buffer size :%x endpoint :%x\n", buffer_size, value +1);
701 psIntfAdapter->sBulkOut.bulk_out_endpointAddr =
702 endpoint->bEndpointAddress;
703 psIntfAdapter->sBulkOut.bulk_out_pipe =
704 usb_sndintpipe(psIntfAdapter->udev,
705 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
706 psIntfAdapter->sBulkOut.int_out_interval = endpoint->bInterval;
707 566
567 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint)) {
568 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
569 (psIntfAdapter->psAdapter->chip_id == T3B) && (value == usedIntOutForBulkTransfer)) {
570 /* use first intout end point as a bulk out end point */
571 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
572 psIntfAdapter->sBulkOut.bulk_out_size = buffer_size;
573 psIntfAdapter->sBulkOut.bulk_out_endpointAddr = endpoint->bEndpointAddress;
574 psIntfAdapter->sBulkOut.bulk_out_pipe = usb_sndintpipe(psIntfAdapter->udev,
575 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
576 psIntfAdapter->sBulkOut.int_out_interval = endpoint->bInterval;
577 } else if (value == EP6) {
578 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
579 psIntfAdapter->sIntrOut.int_out_size = buffer_size;
580 psIntfAdapter->sIntrOut.int_out_endpointAddr = endpoint->bEndpointAddress;
581 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval;
582 psIntfAdapter->sIntrOut.int_out_buffer= kmalloc(buffer_size, GFP_KERNEL);
583 if (!psIntfAdapter->sIntrOut.int_out_buffer) {
584 dev_err(&psIntfAdapter->udev->dev,
585 "could not allocate interrupt_out_buffer\n");
586 return -EINVAL;
587 }
708 } 588 }
709 else if(value == EP6) 589 }
710 {
711 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
712 psIntfAdapter->sIntrOut.int_out_size = buffer_size;
713 psIntfAdapter->sIntrOut.int_out_endpointAddr =
714 endpoint->bEndpointAddress;
715 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval;
716 psIntfAdapter->sIntrOut.int_out_buffer= kmalloc(buffer_size,
717 GFP_KERNEL);
718 if (!psIntfAdapter->sIntrOut.int_out_buffer)
719 {
720 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Could not allocate interrupt_out_buffer");
721 return -EINVAL;
722 }
723 }
724 }
725 }
726 usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter);
727 retval = usb_register_dev(psIntfAdapter->interface, &usbbcm_class);
728 if(retval)
729 {
730 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "usb register dev failed = %d", retval);
731 psIntfAdapter->psAdapter->bUsbClassDriverRegistered = FALSE;
732 return retval;
733 }
734 else
735 {
736 psIntfAdapter->psAdapter->bUsbClassDriverRegistered = TRUE;
737 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "usb dev registered");
738 } 590 }
739 591
592 usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter);
593
740 psIntfAdapter->psAdapter->bcm_file_download = InterfaceFileDownload; 594 psIntfAdapter->psAdapter->bcm_file_download = InterfaceFileDownload;
741 psIntfAdapter->psAdapter->bcm_file_readback_from_chip = 595 psIntfAdapter->psAdapter->bcm_file_readback_from_chip =
742 InterfaceFileReadbackFromChip; 596 InterfaceFileReadbackFromChip;
@@ -744,67 +598,51 @@ INT InterfaceAdapterInit(PS_INTERFACE_ADAPTER psIntfAdapter)
744 598
745 retval = CreateInterruptUrb(psIntfAdapter); 599 retval = CreateInterruptUrb(psIntfAdapter);
746 600
747 if(retval) 601 if (retval) {
748 { 602 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
749 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cannot create interrupt urb"); 603 "Cannot create interrupt urb\n");
750 return retval; 604 return retval;
751 } 605 }
752 606
753 retval = AllocUsbCb(psIntfAdapter); 607 retval = AllocUsbCb(psIntfAdapter);
754 if(retval) 608 if (retval)
755 {
756 return retval; 609 return retval;
757 }
758
759 610
760 retval = device_run(psIntfAdapter); 611 return device_run(psIntfAdapter);
761 if(retval)
762 {
763 return retval;
764 }
765
766
767 return 0;
768} 612}
769 613
770static int InterfaceSuspend (struct usb_interface *intf, pm_message_t message) 614static int InterfaceSuspend(struct usb_interface *intf, pm_message_t message)
771{ 615{
772 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf); 616 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
773 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "=================================\n"); 617
774 //Bcm_kill_all_URBs(psIntfAdapter);
775 psIntfAdapter->bSuspended = TRUE; 618 psIntfAdapter->bSuspended = TRUE;
776 619
777 if(TRUE == psIntfAdapter->bPreparingForBusSuspend) 620 if (TRUE == psIntfAdapter->bPreparingForBusSuspend) {
778 {
779 psIntfAdapter->bPreparingForBusSuspend = FALSE; 621 psIntfAdapter->bPreparingForBusSuspend = FALSE;
780 622
781 if(psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE) 623 if (psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE) {
782 {
783 psIntfAdapter->psAdapter->IdleMode = TRUE ; 624 psIntfAdapter->psAdapter->IdleMode = TRUE ;
784 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Host Entered in PMU Idle Mode.."); 625 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
785 } 626 "Host Entered in PMU Idle Mode.\n");
786 else 627 } else {
787 {
788 psIntfAdapter->psAdapter->bShutStatus = TRUE; 628 psIntfAdapter->psAdapter->bShutStatus = TRUE;
789 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Host Entered in PMU Shutdown Mode.."); 629 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
630 "Host Entered in PMU Shutdown Mode.\n");
790 } 631 }
791 } 632 }
792 psIntfAdapter->psAdapter->bPreparingForLowPowerMode = FALSE; 633 psIntfAdapter->psAdapter->bPreparingForLowPowerMode = FALSE;
793 634
794 //Signaling the control pkt path 635 /* Signaling the control pkt path */
795 wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue); 636 wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue);
796 637
797 return 0; 638 return 0;
798} 639}
799 640
800static int InterfaceResume (struct usb_interface *intf) 641static int InterfaceResume(struct usb_interface *intf)
801{ 642{
802 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf); 643 PS_INTERFACE_ADAPTER psIntfAdapter = usb_get_intfdata(intf);
803 printk("=================================\n");
804 mdelay(100); 644 mdelay(100);
805#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32) 645
806 intf->pm_usage_cnt =1 ;
807#endif
808 psIntfAdapter->bSuspended = FALSE; 646 psIntfAdapter->bSuspended = FALSE;
809 647
810 StartInterruptUrb(psIntfAdapter); 648 StartInterruptUrb(psIntfAdapter);
@@ -812,57 +650,41 @@ static int InterfaceResume (struct usb_interface *intf)
812 return 0; 650 return 0;
813} 651}
814 652
815static int InterfacePreReset(struct usb_interface *intf)
816{
817 printk("====================>");
818 return STATUS_SUCCESS;
819}
820
821static int InterfacePostReset(struct usb_interface *intf)
822{
823 printk("Do Post chip reset setting here if it is required");
824 return STATUS_SUCCESS;
825}
826static struct usb_driver usbbcm_driver = { 653static struct usb_driver usbbcm_driver = {
827 .name = "usbbcm", 654 .name = "usbbcm",
828 .probe = usbbcm_device_probe, 655 .probe = usbbcm_device_probe,
829 .disconnect = usbbcm_disconnect, 656 .disconnect = usbbcm_disconnect,
830 .suspend = InterfaceSuspend, 657 .suspend = InterfaceSuspend,
831 .resume = InterfaceResume, 658 .resume = InterfaceResume,
832 .pre_reset=InterfacePreReset, 659 .id_table = InterfaceUsbtable,
833 .post_reset=InterfacePostReset, 660 .supports_autosuspend = 1,
834 .id_table = InterfaceUsbtable,
835 .supports_autosuspend = 1,
836}; 661};
837 662
663struct class *bcm_class;
838 664
839/* 665static __init int bcm_init(void)
840Function: InterfaceInitialize 666{
841 667 printk(KERN_INFO "%s: %s, %s\n", DRV_NAME, DRV_DESCRIPTION, DRV_VERSION);
842Description: This is the hardware specific initialization Function. 668 printk(KERN_INFO "%s\n", DRV_COPYRIGHT);
843 Registering the driver with NDIS , other device specific NDIS
844 and hardware initializations are done here.
845
846Input parameters: IN PMINI_ADAPTER Adapter - Miniport Adapter Context
847 669
670 bcm_class = class_create(THIS_MODULE, DRV_NAME);
671 if (IS_ERR(bcm_class)) {
672 printk(KERN_ERR DRV_NAME ": could not create class\n");
673 return PTR_ERR(bcm_class);
674 }
848 675
849Return: BCM_STATUS_SUCCESS - If Initialization of the
850 HW Interface was successful.
851 Other - If an error occured.
852*/
853INT InterfaceInitialize(void)
854{
855// BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Registering Usb driver!!");
856 return usb_register(&usbbcm_driver); 676 return usb_register(&usbbcm_driver);
857} 677}
858 678
859INT InterfaceExit(void) 679static __exit void bcm_exit(void)
860{ 680{
861 //PMINI_ADAPTER psAdapter = NULL;
862 int status = 0;
863
864 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL, "Deregistering Usb driver!!");
865 usb_deregister(&usbbcm_driver); 681 usb_deregister(&usbbcm_driver);
866 return status; 682 class_destroy(bcm_class);
867} 683}
868MODULE_LICENSE ("GPL"); 684
685module_init(bcm_init);
686module_exit(bcm_exit);
687
688MODULE_DESCRIPTION(DRV_DESCRIPTION);
689MODULE_VERSION(DRV_VERSION);
690MODULE_LICENSE("GPL");
diff --git a/drivers/staging/bcm/InterfaceInit.h b/drivers/staging/bcm/InterfaceInit.h
index e7a96e5c5c50..058315a64c05 100644
--- a/drivers/staging/bcm/InterfaceInit.h
+++ b/drivers/staging/bcm/InterfaceInit.h
@@ -8,9 +8,11 @@
8#define BCM_USB_PRODUCT_ID_T3 0x0300 8#define BCM_USB_PRODUCT_ID_T3 0x0300
9#define BCM_USB_PRODUCT_ID_T3B 0x0210 9#define BCM_USB_PRODUCT_ID_T3B 0x0210
10#define BCM_USB_PRODUCT_ID_T3L 0x0220 10#define BCM_USB_PRODUCT_ID_T3L 0x0220
11#define BCM_USB_PRODUCT_ID_SM250 0xbccd
11#define BCM_USB_PRODUCT_ID_SYM 0x15E 12#define BCM_USB_PRODUCT_ID_SYM 0x15E
12#define BCM_USB_PRODUCT_ID_1901 0xe017 13#define BCM_USB_PRODUCT_ID_1901 0xe017
13#define BCM_USB_PRODUCT_ID_226 0x0132 14#define BCM_USB_PRODUCT_ID_226 0x0132
15#define BCM_USB_PRODUCT_ID_ZTE_TU25 0x0007
14 16
15#define BCM_USB_MINOR_BASE 192 17#define BCM_USB_MINOR_BASE 192
16 18
@@ -19,33 +21,7 @@ INT InterfaceInitialize(void);
19 21
20INT InterfaceExit(void); 22INT InterfaceExit(void);
21 23
22#ifndef BCM_SHM_INTERFACE
23INT InterfaceAdapterInit(PS_INTERFACE_ADAPTER Adapter);
24
25INT usbbcm_worker_thread(PS_INTERFACE_ADAPTER psIntfAdapter); 24INT usbbcm_worker_thread(PS_INTERFACE_ADAPTER psIntfAdapter);
26 25
27VOID InterfaceAdapterFree(PS_INTERFACE_ADAPTER psIntfAdapter);
28
29#else
30INT InterfaceAdapterInit(PMINI_ADAPTER Adapter);
31#endif
32
33
34#if 0
35
36ULONG InterfaceClaimAdapter(PMINI_ADAPTER Adapter);
37
38VOID InterfaceDDRControllerInit(PMINI_ADAPTER Adapter);
39
40ULONG InterfaceReset(PMINI_ADAPTER Adapter);
41
42ULONG InterfaceRegisterResources(PMINI_ADAPTER Adapter);
43
44VOID InterfaceUnRegisterResources(PMINI_ADAPTER Adapter);
45
46ULONG InterfaceFirmwareDownload(PMINI_ADAPTER Adapter);
47
48#endif
49
50#endif 26#endif
51 27
diff --git a/drivers/staging/bcm/InterfaceIsr.c b/drivers/staging/bcm/InterfaceIsr.c
index f928fe4d564d..220ff922bdcf 100644
--- a/drivers/staging/bcm/InterfaceIsr.c
+++ b/drivers/staging/bcm/InterfaceIsr.c
@@ -1,6 +1,5 @@
1#include "headers.h" 1#include "headers.h"
2 2
3#ifndef BCM_SHM_INTERFACE
4 3
5static void read_int_callback(struct urb *urb/*, struct pt_regs *regs*/) 4static void read_int_callback(struct urb *urb/*, struct pt_regs *regs*/)
6{ 5{
@@ -8,6 +7,10 @@ static void read_int_callback(struct urb *urb/*, struct pt_regs *regs*/)
8 PS_INTERFACE_ADAPTER psIntfAdapter = (PS_INTERFACE_ADAPTER)urb->context; 7 PS_INTERFACE_ADAPTER psIntfAdapter = (PS_INTERFACE_ADAPTER)urb->context;
9 PMINI_ADAPTER Adapter = psIntfAdapter->psAdapter ; 8 PMINI_ADAPTER Adapter = psIntfAdapter->psAdapter ;
10 9
10 if (netif_msg_intr(Adapter))
11 pr_info(PFX "%s: interrupt status %d\n",
12 Adapter->dev->name, status);
13
11 if(Adapter->device_removed == TRUE) 14 if(Adapter->device_removed == TRUE)
12 { 15 {
13 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, INTF_INIT, DBG_LVL_ALL,"Device has Got Removed."); 16 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, INTF_INIT, DBG_LVL_ALL,"Device has Got Removed.");
@@ -87,7 +90,7 @@ static void read_int_callback(struct urb *urb/*, struct pt_regs *regs*/)
87 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, INTF_INIT, DBG_LVL_ALL,"Interrupt IN endPoint has got halted/stalled...need to clear this"); 90 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, INTF_INIT, DBG_LVL_ALL,"Interrupt IN endPoint has got halted/stalled...need to clear this");
88 Adapter->bEndPointHalted = TRUE ; 91 Adapter->bEndPointHalted = TRUE ;
89 wake_up(&Adapter->tx_packet_wait_queue); 92 wake_up(&Adapter->tx_packet_wait_queue);
90 urb->status = STATUS_SUCCESS ;; 93 urb->status = STATUS_SUCCESS ;
91 return; 94 return;
92 } 95 }
93 /* software-driven interface shutdown */ 96 /* software-driven interface shutdown */
@@ -164,40 +167,3 @@ INT StartInterruptUrb(PS_INTERFACE_ADAPTER psIntfAdapter)
164 return status; 167 return status;
165} 168}
166 169
167/*
168Function: InterfaceEnableInterrupt
169
170Description: This is the hardware specific Function for configuring
171 and enabling the interrupts on the device.
172
173Input parameters: IN PMINI_ADAPTER Adapter - Miniport Adapter Context
174
175
176Return: BCM_STATUS_SUCCESS - If configuring the interrupts was successful.
177 Other - If an error occured.
178*/
179
180void InterfaceEnableInterrupt(PMINI_ADAPTER Adapter)
181{
182
183}
184
185/*
186Function: InterfaceDisableInterrupt
187
188Description: This is the hardware specific Function for disabling the interrupts on the device.
189
190Input parameters: IN PMINI_ADAPTER Adapter - Miniport Adapter Context
191
192
193Return: BCM_STATUS_SUCCESS - If disabling the interrupts was successful.
194 Other - If an error occured.
195*/
196
197void InterfaceDisableInterrupt(PMINI_ADAPTER Adapter)
198{
199
200}
201
202#endif
203
diff --git a/drivers/staging/bcm/InterfaceMisc.c b/drivers/staging/bcm/InterfaceMisc.c
index 8fc893b37fe4..a51185b522cf 100644
--- a/drivers/staging/bcm/InterfaceMisc.c
+++ b/drivers/staging/bcm/InterfaceMisc.c
@@ -1,17 +1,5 @@
1#include "headers.h" 1#include "headers.h"
2 2
3#ifndef BCM_SHM_INTERFACE
4
5PS_INTERFACE_ADAPTER
6InterfaceAdapterGet(PMINI_ADAPTER psAdapter)
7{
8 if(psAdapter == NULL)
9 {
10 return NULL;
11 }
12 return (PS_INTERFACE_ADAPTER)(psAdapter->pvInterfaceAdapter);
13}
14
15INT 3INT
16InterfaceRDM(PS_INTERFACE_ADAPTER psIntfAdapter, 4InterfaceRDM(PS_INTERFACE_ADAPTER psIntfAdapter,
17 UINT addr, 5 UINT addr,
@@ -102,7 +90,7 @@ InterfaceWRM(PS_INTERFACE_ADAPTER psIntfAdapter,
102 if((psIntfAdapter->psAdapter->StopAllXaction == TRUE) && (psIntfAdapter->psAdapter->chip_id >= T3LPB)) 90 if((psIntfAdapter->psAdapter->StopAllXaction == TRUE) && (psIntfAdapter->psAdapter->chip_id >= T3LPB))
103 { 91 {
104 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_OTHERS, WRM, DBG_LVL_ALL,"Currently Xaction is not allowed on the bus..."); 92 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_OTHERS, WRM, DBG_LVL_ALL,"Currently Xaction is not allowed on the bus...");
105 return EACCES; 93 return -EACCES;
106 } 94 }
107 95
108 if(psIntfAdapter->bSuspended ==TRUE || psIntfAdapter->bPreparingForBusSuspend == TRUE) 96 if(psIntfAdapter->bSuspended ==TRUE || psIntfAdapter->bPreparingForBusSuspend == TRUE)
@@ -236,9 +224,7 @@ VOID Bcm_kill_all_URBs(PS_INTERFACE_ADAPTER psIntfAdapter)
236 } 224 }
237 225
238 /* Cancel All submitted TX URB's */ 226 /* Cancel All submitted TX URB's */
239 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cancelling All Submitted TX Urbs \n"); 227 for(i = 0; i < MAXIMUM_USB_TCB; i++)
240
241 for(i = 0; i < MAXIMUM_USB_TCB; i++)
242 { 228 {
243 tempUrb = psIntfAdapter->asUsbTcb[i].urb; 229 tempUrb = psIntfAdapter->asUsbTcb[i].urb;
244 if(tempUrb) 230 if(tempUrb)
@@ -248,9 +234,6 @@ VOID Bcm_kill_all_URBs(PS_INTERFACE_ADAPTER psIntfAdapter)
248 } 234 }
249 } 235 }
250 236
251
252 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Cancelling All submitted Rx Urbs \n");
253
254 for(i = 0; i < MAXIMUM_USB_RCB; i++) 237 for(i = 0; i < MAXIMUM_USB_RCB; i++)
255 { 238 {
256 tempUrb = psIntfAdapter->asUsbRcb[i].urb; 239 tempUrb = psIntfAdapter->asUsbRcb[i].urb;
@@ -261,16 +244,11 @@ VOID Bcm_kill_all_URBs(PS_INTERFACE_ADAPTER psIntfAdapter)
261 } 244 }
262 } 245 }
263 246
264
265 atomic_set(&psIntfAdapter->uNumTcbUsed, 0); 247 atomic_set(&psIntfAdapter->uNumTcbUsed, 0);
266 atomic_set(&psIntfAdapter->uCurrTcb, 0); 248 atomic_set(&psIntfAdapter->uCurrTcb, 0);
267 249
268 atomic_set(&psIntfAdapter->uNumRcbUsed, 0); 250 atomic_set(&psIntfAdapter->uNumRcbUsed, 0);
269 atomic_set(&psIntfAdapter->uCurrRcb, 0); 251 atomic_set(&psIntfAdapter->uCurrRcb, 0);
270
271 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "TCB: used- %d cur-%d\n", atomic_read(&psIntfAdapter->uNumTcbUsed), atomic_read(&psIntfAdapter->uCurrTcb));
272 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "RCB: used- %d cur-%d\n", atomic_read(&psIntfAdapter->uNumRcbUsed), atomic_read(&psIntfAdapter->uCurrRcb));
273
274} 252}
275 253
276VOID putUsbSuspend(struct work_struct *work) 254VOID putUsbSuspend(struct work_struct *work)
@@ -282,9 +260,6 @@ VOID putUsbSuspend(struct work_struct *work)
282 260
283 if(psIntfAdapter->bSuspended == FALSE) 261 if(psIntfAdapter->bSuspended == FALSE)
284 usb_autopm_put_interface(intf); 262 usb_autopm_put_interface(intf);
285 else
286 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Interface Resumed Completely\n");
287 263
288} 264}
289 265
290#endif
diff --git a/drivers/staging/bcm/InterfaceMisc.h b/drivers/staging/bcm/InterfaceMisc.h
index 74c81d45cff4..6c9e39bf9889 100644
--- a/drivers/staging/bcm/InterfaceMisc.h
+++ b/drivers/staging/bcm/InterfaceMisc.h
@@ -1,9 +1,6 @@
1#ifndef __INTERFACE_MISC_H 1#ifndef __INTERFACE_MISC_H
2#define __INTERFACE_MISC_H 2#define __INTERFACE_MISC_H
3 3
4PS_INTERFACE_ADAPTER
5InterfaceAdapterGet(PMINI_ADAPTER psAdapter);
6
7INT 4INT
8InterfaceRDM(PS_INTERFACE_ADAPTER psIntfAdapter, 5InterfaceRDM(PS_INTERFACE_ADAPTER psIntfAdapter,
9 UINT addr, 6 UINT addr,
diff --git a/drivers/staging/bcm/InterfaceRx.c b/drivers/staging/bcm/InterfaceRx.c
index 6fee9684f2ef..533f8ebe0f84 100644
--- a/drivers/staging/bcm/InterfaceRx.c
+++ b/drivers/staging/bcm/InterfaceRx.c
@@ -1,5 +1,15 @@
1#include "headers.h" 1#include "headers.h"
2extern int SearchVcid(PMINI_ADAPTER , unsigned short); 2
3static int SearchVcid(PMINI_ADAPTER Adapter,unsigned short usVcid)
4{
5 int iIndex=0;
6
7 for(iIndex=(NO_OF_QUEUES-1);iIndex>=0;iIndex--)
8 if(Adapter->PackInfo[iIndex].usVCID_Value == usVcid)
9 return iIndex;
10 return NO_OF_QUEUES+1;
11
12}
3 13
4 14
5static PUSB_RCB 15static PUSB_RCB
@@ -38,13 +48,9 @@ static void read_bulk_callback(struct urb *urb)
38 PMINI_ADAPTER Adapter = psIntfAdapter->psAdapter; 48 PMINI_ADAPTER Adapter = psIntfAdapter->psAdapter;
39 PLEADER pLeader = urb->transfer_buffer; 49 PLEADER pLeader = urb->transfer_buffer;
40 50
41 51 if (unlikely(netif_msg_rx_status(Adapter)))
42 #if 0 52 pr_info(PFX "%s: rx urb status %d length %d\n",
43 int *puiBuffer = NULL; 53 Adapter->dev->name, urb->status, urb->actual_length);
44 struct timeval tv;
45 memset(&tv, 0, sizeof(tv));
46 do_gettimeofday(&tv);
47 #endif
48 54
49 if((Adapter->device_removed == TRUE) || 55 if((Adapter->device_removed == TRUE) ||
50 (TRUE == Adapter->bEndPointHalted) || 56 (TRUE == Adapter->bEndPointHalted) ||
@@ -89,10 +95,10 @@ static void read_bulk_callback(struct urb *urb)
89 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "Leader Status:0x%hX, Length:0x%hX, VCID:0x%hX", pLeader->Status,pLeader->PLength,pLeader->Vcid); 95 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "Leader Status:0x%hX, Length:0x%hX, VCID:0x%hX", pLeader->Status,pLeader->PLength,pLeader->Vcid);
90 if(MAX_CNTL_PKT_SIZE < pLeader->PLength) 96 if(MAX_CNTL_PKT_SIZE < pLeader->PLength)
91 { 97 {
92 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Corrupted leader length...%d\n", 98 if (netif_msg_rx_err(Adapter))
93 pLeader->PLength); 99 pr_info(PFX "%s: corrupted leader length...%d\n",
94 atomic_inc(&Adapter->RxPacketDroppedCount); 100 Adapter->dev->name, pLeader->PLength);
95 atomic_add(pLeader->PLength, &Adapter->BadRxByteCount); 101 ++Adapter->dev->stats.rx_dropped;
96 atomic_dec(&psIntfAdapter->uNumRcbUsed); 102 atomic_dec(&psIntfAdapter->uNumRcbUsed);
97 return; 103 return;
98 } 104 }
@@ -145,10 +151,9 @@ static void read_bulk_callback(struct urb *urb)
145 skb_put (skb, pLeader->PLength + ETH_HLEN); 151 skb_put (skb, pLeader->PLength + ETH_HLEN);
146 Adapter->PackInfo[QueueIndex].uiTotalRxBytes+=pLeader->PLength; 152 Adapter->PackInfo[QueueIndex].uiTotalRxBytes+=pLeader->PLength;
147 Adapter->PackInfo[QueueIndex].uiThisPeriodRxBytes+= pLeader->PLength; 153 Adapter->PackInfo[QueueIndex].uiThisPeriodRxBytes+= pLeader->PLength;
148 atomic_add(pLeader->PLength, &Adapter->GoodRxByteCount);
149 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_RX, RX_DATA, DBG_LVL_ALL, "Recived Data pkt of len :0x%X", pLeader->PLength); 154 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_RX, RX_DATA, DBG_LVL_ALL, "Recived Data pkt of len :0x%X", pLeader->PLength);
150 155
151 if(Adapter->if_up) 156 if(netif_running(Adapter->dev))
152 { 157 {
153 /* Moving ahead by ETH_HLEN to the data ptr as received from FW */ 158 /* Moving ahead by ETH_HLEN to the data ptr as received from FW */
154 skb_pull(skb, ETH_HLEN); 159 skb_pull(skb, ETH_HLEN);
@@ -173,9 +178,12 @@ static void read_bulk_callback(struct urb *urb)
173 else 178 else
174 { 179 {
175 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_RX, RX_DATA, DBG_LVL_ALL, "i/f not up hance freeing SKB..."); 180 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_RX, RX_DATA, DBG_LVL_ALL, "i/f not up hance freeing SKB...");
176 bcm_kfree_skb(skb); 181 dev_kfree_skb(skb);
177 } 182 }
178 atomic_inc(&Adapter->GoodRxPktCount); 183
184 ++Adapter->dev->stats.rx_packets;
185 Adapter->dev->stats.rx_bytes += pLeader->PLength;
186
179 for(uiIndex = 0 ; uiIndex < MIBS_MAX_HIST_ENTRIES ; uiIndex++) 187 for(uiIndex = 0 ; uiIndex < MIBS_MAX_HIST_ENTRIES ; uiIndex++)
180 { 188 {
181 if((pLeader->PLength <= MIBS_PKTSIZEHIST_RANGE*(uiIndex+1)) 189 if((pLeader->PLength <= MIBS_PKTSIZEHIST_RANGE*(uiIndex+1))
diff --git a/drivers/staging/bcm/InterfaceTx.c b/drivers/staging/bcm/InterfaceTx.c
index 771f7b34d2ec..a842de9de6b5 100644
--- a/drivers/staging/bcm/InterfaceTx.c
+++ b/drivers/staging/bcm/InterfaceTx.c
@@ -1,50 +1,5 @@
1#include "headers.h" 1#include "headers.h"
2 2
3#ifndef BCM_SHM_INTERFACE
4
5/*
6Function: InterfaceTxDataPacket
7
8Description: This is the hardware specific Function for Transmitting
9 data packet to the device.
10
11Input parameters: IN PMINI_ADAPTER Adapter - Miniport Adapter Context
12 PVOID Packet - Packet Containing the data to be transmitted
13 USHORT usVcid - VCID on which data packet is to be sent
14
15
16Return: BCM_STATUS_SUCCESS - If Tx was successful.
17 Other - If an error occured.
18*/
19
20ULONG InterfaceTxDataPacket(PMINI_ADAPTER Adapter,PVOID Packet,USHORT usVcid)
21{
22 ULONG Status = 0;
23 return Status;
24}
25
26/*
27Function: InterfaceTxControlPacket
28
29Description: This is the hardware specific Function for Transmitting
30 control packet to the device.
31
32Input parameters: IN PMINI_ADAPTER Adapter - Miniport Adapter Context
33 PVOID pvBuffer - Buffer containg control packet
34 UINT uiBufferLength - Buffer Length
35
36Return: BCM_STATUS_SUCCESS - If control packet transmit was successful.
37 Other - If an error occured.
38*/
39
40ULONG InterfaceTxControlPacket(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT uiBufferLength)
41{
42 ULONG Status = 0;
43
44
45
46 return Status;
47}
48/*this is transmit call-back(BULK OUT)*/ 3/*this is transmit call-back(BULK OUT)*/
49static void write_bulk_callback(struct urb *urb/*, struct pt_regs *regs*/) 4static void write_bulk_callback(struct urb *urb/*, struct pt_regs *regs*/)
50{ 5{
@@ -54,10 +9,10 @@ static void write_bulk_callback(struct urb *urb/*, struct pt_regs *regs*/)
54 PMINI_ADAPTER psAdapter = psIntfAdapter->psAdapter ; 9 PMINI_ADAPTER psAdapter = psIntfAdapter->psAdapter ;
55 BOOLEAN bpowerDownMsg = FALSE ; 10 BOOLEAN bpowerDownMsg = FALSE ;
56 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 11 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
57#if 0 12
58 struct timeval tv; 13 if (unlikely(netif_msg_tx_done(Adapter)))
59 UINT time_ms = 0; 14 pr_info(PFX "%s: transmit status %d\n", Adapter->dev->name, urb->status);
60#endif 15
61 if(urb->status != STATUS_SUCCESS) 16 if(urb->status != STATUS_SUCCESS)
62 { 17 {
63 if(urb->status == -EPIPE) 18 if(urb->status == -EPIPE)
@@ -78,11 +33,6 @@ static void write_bulk_callback(struct urb *urb/*, struct pt_regs *regs*/)
78 33
79 if(TRUE == psAdapter->bPreparingForLowPowerMode) 34 if(TRUE == psAdapter->bPreparingForLowPowerMode)
80 { 35 {
81 #if 0
82 do_gettimeofday(&tv);
83 time_ms = tv.tv_sec *1000 + tv.tv_usec/1000;
84 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, " %s Idle Mode ACK_Sent got from device at time :0x%x", __FUNCTION__, time_ms);
85 #endif
86 36
87 if(((pControlMsg->szData[0] == GO_TO_IDLE_MODE_PAYLOAD) && 37 if(((pControlMsg->szData[0] == GO_TO_IDLE_MODE_PAYLOAD) &&
88 (pControlMsg->szData[1] == TARGET_CAN_GO_TO_IDLE_MODE))) 38 (pControlMsg->szData[1] == TARGET_CAN_GO_TO_IDLE_MODE)))
@@ -152,17 +102,12 @@ static void write_bulk_callback(struct urb *urb/*, struct pt_regs *regs*/)
152 } 102 }
153 103
154err_exit : 104err_exit :
155#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
156 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
157 urb->transfer_buffer, urb->transfer_dma);
158#else
159 usb_free_coherent(urb->dev, urb->transfer_buffer_length, 105 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
160 urb->transfer_buffer, urb->transfer_dma); 106 urb->transfer_buffer, urb->transfer_dma);
161#endif
162} 107}
163 108
164 109
165static __inline PUSB_TCB GetBulkOutTcb(PS_INTERFACE_ADAPTER psIntfAdapter) 110static PUSB_TCB GetBulkOutTcb(PS_INTERFACE_ADAPTER psIntfAdapter)
166{ 111{
167 PUSB_TCB pTcb = NULL; 112 PUSB_TCB pTcb = NULL;
168 UINT index = 0; 113 UINT index = 0;
@@ -183,20 +128,14 @@ static __inline PUSB_TCB GetBulkOutTcb(PS_INTERFACE_ADAPTER psIntfAdapter)
183 return pTcb; 128 return pTcb;
184} 129}
185 130
186static __inline int TransmitTcb(PS_INTERFACE_ADAPTER psIntfAdapter, PUSB_TCB pTcb, PVOID data, int len) 131static int TransmitTcb(PS_INTERFACE_ADAPTER psIntfAdapter, PUSB_TCB pTcb, PVOID data, int len)
187{ 132{
188 133
189 struct urb *urb = pTcb->urb; 134 struct urb *urb = pTcb->urb;
190 int retval = 0; 135 int retval = 0;
191 136
192#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
193 urb->transfer_buffer = usb_buffer_alloc(psIntfAdapter->udev, len,
194 GFP_ATOMIC, &urb->transfer_dma);
195#else
196 urb->transfer_buffer = usb_alloc_coherent(psIntfAdapter->udev, len, 137 urb->transfer_buffer = usb_alloc_coherent(psIntfAdapter->udev, len,
197 GFP_ATOMIC, &urb->transfer_dma); 138 GFP_ATOMIC, &urb->transfer_dma);
198#endif
199
200 if (!urb->transfer_buffer) 139 if (!urb->transfer_buffer)
201 { 140 {
202 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Error allocating memory\n"); 141 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Error allocating memory\n");
@@ -255,5 +194,4 @@ int InterfaceTransmitPacket(PVOID arg, PVOID data, UINT len)
255 return TransmitTcb(psIntfAdapter, pTcb, data, len); 194 return TransmitTcb(psIntfAdapter, pTcb, data, len);
256} 195}
257 196
258#endif
259 197
diff --git a/drivers/staging/bcm/InterfaceTx.h b/drivers/staging/bcm/InterfaceTx.h
index 053f631e2042..273147577c17 100644
--- a/drivers/staging/bcm/InterfaceTx.h
+++ b/drivers/staging/bcm/InterfaceTx.h
@@ -3,11 +3,5 @@
3 3
4INT InterfaceTransmitPacket(PVOID arg, PVOID data, UINT len); 4INT InterfaceTransmitPacket(PVOID arg, PVOID data, UINT len);
5 5
6
7ULONG InterfaceTxDataPacket(PMINI_ADAPTER Adapter,PVOID Packet,USHORT usVcid);
8
9ULONG InterfaceTxControlPacket(PMINI_ADAPTER Adapter,PVOID pvBuffer,UINT uiBufferLength);
10
11
12#endif 6#endif
13 7
diff --git a/drivers/staging/bcm/Interfacemain.h b/drivers/staging/bcm/Interfacemain.h
deleted file mode 100644
index e0db563c5e0f..000000000000
--- a/drivers/staging/bcm/Interfacemain.h
+++ /dev/null
@@ -1,10 +0,0 @@
1#ifndef _MAIN_
2#define _MAIN_
3#if 0
4typedef struct _MINI_ADAPTER
5{
6 S_INTERFACE_ADAPTER stInterfaceAdapter;
7}MINI_ADAPTER,*PMINI_ADAPTER;
8
9#endif
10#endif
diff --git a/drivers/staging/bcm/LeakyBucket.c b/drivers/staging/bcm/LeakyBucket.c
index cae382313ce9..f4cf41c0e46b 100644
--- a/drivers/staging/bcm/LeakyBucket.c
+++ b/drivers/staging/bcm/LeakyBucket.c
@@ -75,14 +75,14 @@ static VOID UpdateTokenCount(register PMINI_ADAPTER Adapter)
75* Returns - The number of bytes allowed for transmission. 75* Returns - The number of bytes allowed for transmission.
76* 76*
77***********************************************************************/ 77***********************************************************************/
78static __inline ULONG GetSFTokenCount(PMINI_ADAPTER Adapter, PacketInfo *psSF) 78static ULONG GetSFTokenCount(PMINI_ADAPTER Adapter, PacketInfo *psSF)
79{ 79{
80 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IsPacketAllowedForFlow ===>"); 80 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IsPacketAllowedForFlow ===>");
81 /* Validate the parameters */ 81 /* Validate the parameters */
82 if(NULL == Adapter || (psSF < Adapter->PackInfo && 82 if(NULL == Adapter || (psSF < Adapter->PackInfo &&
83 (uintptr_t)psSF > (uintptr_t) &Adapter->PackInfo[HiPriority])) 83 (uintptr_t)psSF > (uintptr_t) &Adapter->PackInfo[HiPriority]))
84 { 84 {
85 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IPAFF: Got wrong Parameters:Adapter: %p, QIndex: %ld\n", Adapter, (psSF-Adapter->PackInfo)); 85 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IPAFF: Got wrong Parameters:Adapter: %p, QIndex: %zd\n", Adapter, (psSF-Adapter->PackInfo));
86 return 0; 86 return 0;
87 } 87 }
88 88
@@ -94,51 +94,27 @@ static __inline ULONG GetSFTokenCount(PMINI_ADAPTER Adapter, PacketInfo *psSF)
94 } 94 }
95 else 95 else
96 { 96 {
97 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "Not enough tokens in queue %ld Available %u\n", 97 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "Not enough tokens in queue %zd Available %u\n",
98 psSF-Adapter->PackInfo, psSF->uiCurrentTokenCount); 98 psSF-Adapter->PackInfo, psSF->uiCurrentTokenCount);
99 psSF->uiPendedLast = 1; 99 psSF->uiPendedLast = 1;
100 } 100 }
101 } 101 }
102 else 102 else
103 { 103 {
104 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IPAFF: Queue %ld not valid\n", psSF-Adapter->PackInfo); 104 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IPAFF: Queue %zd not valid\n", psSF-Adapter->PackInfo);
105 } 105 }
106 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IsPacketAllowedForFlow <==="); 106 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL, "IsPacketAllowedForFlow <===");
107 return 0; 107 return 0;
108} 108}
109 109
110static __inline void RemovePacketFromQueue(PacketInfo *pPackInfo , struct sk_buff *Packet)
111{
112 struct sk_buff *psQueueCurrent=NULL, *psLastQueueNode=NULL;
113 psQueueCurrent = pPackInfo->FirstTxQueue;
114 while(psQueueCurrent)
115 {
116 if(Packet == psQueueCurrent)
117 {
118 if(psQueueCurrent == pPackInfo->FirstTxQueue)
119 {
120 pPackInfo->FirstTxQueue=psQueueCurrent->next;
121 if(psQueueCurrent==pPackInfo->LastTxQueue)
122 pPackInfo->LastTxQueue=NULL;
123 }
124 else
125 {
126 psLastQueueNode->next=psQueueCurrent->next;
127 }
128 break;
129 }
130 psLastQueueNode = psQueueCurrent;
131 psQueueCurrent=psQueueCurrent->next;
132 }
133}
134/** 110/**
135@ingroup tx_functions 111@ingroup tx_functions
136This function despatches packet from the specified queue. 112This function despatches packet from the specified queue.
137@return Zero(success) or Negative value(failure) 113@return Zero(success) or Negative value(failure)
138*/ 114*/
139static __inline INT SendPacketFromQueue(PMINI_ADAPTER Adapter,/**<Logical Adapter*/ 115static INT SendPacketFromQueue(PMINI_ADAPTER Adapter,/**<Logical Adapter*/
140 PacketInfo *psSF, /**<Queue identifier*/ 116 PacketInfo *psSF, /**<Queue identifier*/
141 struct sk_buff* Packet) /**<Pointer to the packet to be sent*/ 117 struct sk_buff* Packet) /**<Pointer to the packet to be sent*/
142{ 118{
143 INT Status=STATUS_FAILURE; 119 INT Status=STATUS_FAILURE;
144 UINT uiIndex =0,PktLen = 0; 120 UINT uiIndex =0,PktLen = 0;
@@ -180,8 +156,7 @@ static __inline INT SendPacketFromQueue(PMINI_ADAPTER Adapter,/**<Logical Adapte
180* Returns - None. 156* Returns - None.
181* 157*
182****************************************************************************/ 158****************************************************************************/
183static __inline VOID CheckAndSendPacketFromIndex 159static VOID CheckAndSendPacketFromIndex(PMINI_ADAPTER Adapter, PacketInfo *psSF)
184(PMINI_ADAPTER Adapter, PacketInfo *psSF)
185{ 160{
186 struct sk_buff *QueuePacket=NULL; 161 struct sk_buff *QueuePacket=NULL;
187 char *pControlPacket = NULL; 162 char *pControlPacket = NULL;
@@ -189,7 +164,7 @@ static __inline VOID CheckAndSendPacketFromIndex
189 int iPacketLen=0; 164 int iPacketLen=0;
190 165
191 166
192 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "%ld ====>", (psSF-Adapter->PackInfo)); 167 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "%zd ====>", (psSF-Adapter->PackInfo));
193 if((psSF != &Adapter->PackInfo[HiPriority]) && Adapter->LinkUpStatus && atomic_read(&psSF->uiPerSFTxResourceCount))//Get data packet 168 if((psSF != &Adapter->PackInfo[HiPriority]) && Adapter->LinkUpStatus && atomic_read(&psSF->uiPerSFTxResourceCount))//Get data packet
194 { 169 {
195 if(!psSF->ucDirection ) 170 if(!psSF->ucDirection )
@@ -197,10 +172,8 @@ static __inline VOID CheckAndSendPacketFromIndex
197 172
198 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "UpdateTokenCount "); 173 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "UpdateTokenCount ");
199 if(Adapter->IdleMode || Adapter->bPreparingForLowPowerMode) 174 if(Adapter->IdleMode || Adapter->bPreparingForLowPowerMode)
200 { 175 return; /* in idle mode */
201 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle Mode..Hence blocking Data Packets..\n"); 176
202 return;
203 }
204 // Check for Free Descriptors 177 // Check for Free Descriptors
205 if(atomic_read(&Adapter->CurrNumFreeTxDesc) <= MINIMUM_PENDING_DESCRIPTORS) 178 if(atomic_read(&Adapter->CurrNumFreeTxDesc) <= MINIMUM_PENDING_DESCRIPTORS)
206 { 179 {
@@ -208,9 +181,6 @@ static __inline VOID CheckAndSendPacketFromIndex
208 return ; 181 return ;
209 } 182 }
210 183
211#if 0
212 PruneQueue(Adapter,(psSF-Adapter->PackInfo));
213#endif
214 spin_lock_bh(&psSF->SFQueueLock); 184 spin_lock_bh(&psSF->SFQueueLock);
215 QueuePacket=psSF->FirstTxQueue; 185 QueuePacket=psSF->FirstTxQueue;
216 186
@@ -240,7 +210,7 @@ static __inline VOID CheckAndSendPacketFromIndex
240 } 210 }
241 else 211 else
242 { 212 {
243 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "For Queue: %ld\n", psSF-Adapter->PackInfo); 213 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "For Queue: %zd\n", psSF-Adapter->PackInfo);
244 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "\nAvailable Tokens = %d required = %d\n", 214 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "\nAvailable Tokens = %d required = %d\n",
245 psSF->uiCurrentTokenCount, iPacketLen); 215 psSF->uiCurrentTokenCount, iPacketLen);
246 //this part indicates that becuase of non-availability of the tokens 216 //this part indicates that becuase of non-availability of the tokens
@@ -290,17 +260,6 @@ static __inline VOID CheckAndSendPacketFromIndex
290 } 260 }
291 } 261 }
292 } 262 }
293
294 if(Status != STATUS_SUCCESS) //Tx of data packet to device Failed
295 {
296 if(Adapter->bcm_jiffies == 0)
297 Adapter->bcm_jiffies = jiffies;
298 }
299 else
300 {
301 Adapter->bcm_jiffies = 0;
302 }
303 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "<=====");
304} 263}
305 264
306 265
@@ -387,12 +346,7 @@ VOID transmit_packets(PMINI_ADAPTER Adapter)
387 if(exit_flag == TRUE ) 346 if(exit_flag == TRUE )
388 break ; 347 break ;
389 }/* end of inner while loop */ 348 }/* end of inner while loop */
390 if(Adapter->bcm_jiffies == 0 && 349
391 atomic_read(&Adapter->TotalPacketCount) != 0 &&
392 uiPrevTotalCount == atomic_read(&Adapter->TotalPacketCount))
393 {
394 Adapter->bcm_jiffies = jiffies;
395 }
396 update_per_cid_rx (Adapter); 350 update_per_cid_rx (Adapter);
397 Adapter->txtransmit_running = 0; 351 Adapter->txtransmit_running = 0;
398 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "<======"); 352 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "<======");
diff --git a/drivers/staging/bcm/Macros.h b/drivers/staging/bcm/Macros.h
index 0241234605f1..feb351578c8b 100644
--- a/drivers/staging/bcm/Macros.h
+++ b/drivers/staging/bcm/Macros.h
@@ -4,10 +4,6 @@
4#ifndef __MACROS_H__ 4#ifndef __MACROS_H__
5#define __MACROS_H__ 5#define __MACROS_H__
6 6
7#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
8#define kthread_run(threadfn,data,datafmt)(struct task_struct *)kernel_thread(threadfn,data,0)
9#endif
10
11#define TX_TIMER_PERIOD 10 //10 msec 7#define TX_TIMER_PERIOD 10 //10 msec
12#define MAX_CLASSIFIERS 100 8#define MAX_CLASSIFIERS 100
13//#define MAX_CLASSIFIERS_PER_SF 20 9//#define MAX_CLASSIFIERS_PER_SF 20
@@ -17,10 +13,9 @@
17#define MAX_DATA_PKTS 200 13#define MAX_DATA_PKTS 200
18#define MAX_ETH_SIZE 1536 14#define MAX_ETH_SIZE 1536
19#define MAX_CNTL_PKT_SIZE 2048 15#define MAX_CNTL_PKT_SIZE 2048
20/* TIMER RELATED */
21#define JIFFIES_2_QUADPART() (ULONG)(jiffies * 10000) // jiffies(1msec) to Quadpart(100nsec)
22 16
23#define MTU_SIZE 1400 17#define MTU_SIZE 1400
18#define TX_QLEN 5
24 19
25#define MAC_ADDR_REGISTER 0xbf60d000 20#define MAC_ADDR_REGISTER 0xbf60d000
26 21
@@ -266,7 +261,7 @@ typedef enum _E_PHS_DSC_ACTION
266 261
267#define FIRMWARE_BEGIN_ADDR 0xBFC00000 262#define FIRMWARE_BEGIN_ADDR 0xBFC00000
268 263
269#define INVALID_QUEUE_INDEX (USHORT)-1 264#define INVALID_QUEUE_INDEX NO_OF_QUEUES
270 265
271#define INVALID_PID (pid_t)-1 266#define INVALID_PID (pid_t)-1
272#define DDR_80_MHZ 0 267#define DDR_80_MHZ 0
@@ -300,12 +295,7 @@ typedef enum _E_PHS_DSC_ACTION
300 295
301/* Idle Mode Related Registers */ 296/* Idle Mode Related Registers */
302#define DEBUG_INTERRUPT_GENERATOR_REGISTOR 0x0F00007C 297#define DEBUG_INTERRUPT_GENERATOR_REGISTOR 0x0F00007C
303#ifdef BCM_SHM_INTERFACE
304#define SW_ABORT_IDLEMODE_LOC 0xbfc02f9c
305#define CPE_VIRTUAL_MAILBOX_REG 0xBFC02E58
306#else
307#define SW_ABORT_IDLEMODE_LOC 0x0FF01FFC 298#define SW_ABORT_IDLEMODE_LOC 0x0FF01FFC
308#endif
309 299
310#define SW_ABORT_IDLEMODE_PATTERN 0xd0ea1d1e 300#define SW_ABORT_IDLEMODE_PATTERN 0xd0ea1d1e
311#define DEVICE_INT_OUT_EP_REG0 0x0F011870 301#define DEVICE_INT_OUT_EP_REG0 0x0F011870
@@ -355,12 +345,7 @@ typedef enum ePMU_MODES
355 HYBRID_MODE_6 = 2 345 HYBRID_MODE_6 = 2
356}PMU_MODE; 346}PMU_MODE;
357 347
358#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
359#define MAX_RDM_WRM_RETIRES 16
360#else
361#define MAX_RDM_WRM_RETIRES 1 348#define MAX_RDM_WRM_RETIRES 1
362#endif
363
364 349
365enum eAbortPattern { 350enum eAbortPattern {
366 ABORT_SHUTDOWN_MODE = 1, 351 ABORT_SHUTDOWN_MODE = 1,
@@ -369,27 +354,6 @@ enum eAbortPattern {
369 ABORT_IDLE_SYNCDOWN = 3 354 ABORT_IDLE_SYNCDOWN = 3
370}; 355};
371 356
372#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
373 #define GET_BCM_ADAPTER(net_dev) ({\
374 PMINI_ADAPTER __Adapter = NULL; \
375 if (net_dev) { \
376 __Adapter = (PMINI_ADAPTER)(net_dev->priv); \
377 } \
378 else { \
379 __Adapter = NULL; \
380 }__Adapter;} )
381#else
382 #define GET_BCM_ADAPTER(net_dev) ({\
383 PMINI_ADAPTER __Adapter = NULL; \
384 if (net_dev) { \
385 __Adapter = (PMINI_ADAPTER)(*((unsigned long *)netdev_priv(net_dev))); \
386 } \
387 else { \
388 __Adapter = NULL; \
389 }__Adapter;})
390
391
392#endif
393 357
394/* Offsets used by driver in skb cb variable */ 358/* Offsets used by driver in skb cb variable */
395#define SKB_CB_CLASSIFICATION_OFFSET 0 359#define SKB_CB_CLASSIFICATION_OFFSET 0
diff --git a/drivers/staging/bcm/Makefile b/drivers/staging/bcm/Makefile
index c3ae25af670a..652b7f87737c 100644
--- a/drivers/staging/bcm/Makefile
+++ b/drivers/staging/bcm/Makefile
@@ -6,7 +6,7 @@ obj-$(CONFIG_BCM_WIMAX) += bcm_wimax.o
6 6
7bcm_wimax-y := InterfaceDld.o InterfaceIdleMode.o InterfaceInit.o InterfaceRx.o \ 7bcm_wimax-y := InterfaceDld.o InterfaceIdleMode.o InterfaceInit.o InterfaceRx.o \
8 InterfaceIsr.o InterfaceMisc.o InterfaceTx.o \ 8 InterfaceIsr.o InterfaceMisc.o InterfaceTx.o \
9 Arp.o CmHost.o Debug.o IPv6Protocol.o Qos.o Transmit.o\ 9 CmHost.o IPv6Protocol.o Qos.o Transmit.o\
10 Bcmnet.o DDRInit.o HandleControlPacket.o\ 10 Bcmnet.o DDRInit.o HandleControlPacket.o\
11 LeakyBucket.o Misc.o sort.o Bcmchar.o hostmibs.o PHSModule.o\ 11 LeakyBucket.o Misc.o sort.o Bcmchar.o hostmibs.o PHSModule.o\
12 Osal_Misc.o led_control.o nvm.o vendorspecificextn.o 12 led_control.o nvm.o vendorspecificextn.o
diff --git a/drivers/staging/bcm/Misc.c b/drivers/staging/bcm/Misc.c
index 22550f745917..f585aae9cf8b 100644
--- a/drivers/staging/bcm/Misc.c
+++ b/drivers/staging/bcm/Misc.c
@@ -1,5 +1,12 @@
1#include "headers.h" 1#include "headers.h"
2 2
3static int BcmFileDownload(PMINI_ADAPTER Adapter, const char *path,
4 unsigned int loc);
5static VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter);
6static void HandleShutDownModeRequest(PMINI_ADAPTER Adapter,PUCHAR pucBuffer);
7static int bcm_parse_target_params(PMINI_ADAPTER Adapter);
8static void beceem_protocol_reset (PMINI_ADAPTER Adapter);
9
3static VOID default_wimax_protocol_initialize(PMINI_ADAPTER Adapter) 10static VOID default_wimax_protocol_initialize(PMINI_ADAPTER Adapter)
4{ 11{
5 12
@@ -60,21 +67,11 @@ InitAdapter(PMINI_ADAPTER psAdapter)
60 //init_waitqueue_head(&psAdapter->device_wake_queue); 67 //init_waitqueue_head(&psAdapter->device_wake_queue);
61 psAdapter->fw_download_done=FALSE; 68 psAdapter->fw_download_done=FALSE;
62 69
63 psAdapter->pvOsDepData = (PLINUX_DEP_DATA) kmalloc(sizeof(LINUX_DEP_DATA),
64 GFP_KERNEL);
65
66 if(psAdapter->pvOsDepData == NULL)
67 {
68 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Linux Specific Data allocation failed");
69 return -ENOMEM;
70 }
71 memset(psAdapter->pvOsDepData, 0, sizeof(LINUX_DEP_DATA));
72 70
73 default_wimax_protocol_initialize(psAdapter); 71 default_wimax_protocol_initialize(psAdapter);
74 for (i=0;i<MAX_CNTRL_PKTS;i++) 72 for (i=0;i<MAX_CNTRL_PKTS;i++)
75 { 73 {
76 psAdapter->txctlpacket[i] = (char *)kmalloc(MAX_CNTL_PKT_SIZE, 74 psAdapter->txctlpacket[i] = kmalloc(MAX_CNTL_PKT_SIZE, GFP_KERNEL);
77 GFP_KERNEL);
78 if(!psAdapter->txctlpacket[i]) 75 if(!psAdapter->txctlpacket[i])
79 { 76 {
80 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No More Cntl pkts got, max got is %d", i); 77 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No More Cntl pkts got, max got is %d", i);
@@ -117,7 +114,7 @@ InitAdapter(PMINI_ADAPTER psAdapter)
117 114
118VOID AdapterFree(PMINI_ADAPTER Adapter) 115VOID AdapterFree(PMINI_ADAPTER Adapter)
119{ 116{
120 INT count = 0; 117 int count;
121 118
122 beceem_protocol_reset(Adapter); 119 beceem_protocol_reset(Adapter);
123 120
@@ -125,72 +122,66 @@ VOID AdapterFree(PMINI_ADAPTER Adapter)
125 122
126 if(Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler)) 123 if(Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler))
127 kthread_stop (Adapter->control_packet_handler); 124 kthread_stop (Adapter->control_packet_handler);
125
128 if(Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread)) 126 if(Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread))
129 kthread_stop (Adapter->transmit_packet_thread); 127 kthread_stop (Adapter->transmit_packet_thread);
130 wake_up(&Adapter->process_read_wait_queue); 128
129 wake_up(&Adapter->process_read_wait_queue);
130
131 if(Adapter->LEDInfo.led_thread_running & (BCM_LED_THREAD_RUNNING_ACTIVELY | BCM_LED_THREAD_RUNNING_INACTIVELY)) 131 if(Adapter->LEDInfo.led_thread_running & (BCM_LED_THREAD_RUNNING_ACTIVELY | BCM_LED_THREAD_RUNNING_INACTIVELY))
132 kthread_stop (Adapter->LEDInfo.led_cntrl_threadid); 132 kthread_stop (Adapter->LEDInfo.led_cntrl_threadid);
133 bcm_unregister_networkdev(Adapter); 133
134 unregister_networkdev(Adapter);
135
136 /* FIXME: use proper wait_event and refcounting */
134 while(atomic_read(&Adapter->ApplicationRunning)) 137 while(atomic_read(&Adapter->ApplicationRunning))
135 { 138 {
136 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Waiting for Application to close.. %d\n",atomic_read(&Adapter->ApplicationRunning)); 139 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Waiting for Application to close.. %d\n",atomic_read(&Adapter->ApplicationRunning));
137 msleep(100); 140 msleep(100);
138 } 141 }
139 unregister_control_device_interface(Adapter); 142 unregister_control_device_interface(Adapter);
140 if(Adapter->dev && !IS_ERR(Adapter->dev)) 143
141 free_netdev(Adapter->dev); 144 kfree(Adapter->pstargetparams);
142 if(Adapter->pstargetparams != NULL) 145
143 {
144 bcm_kfree(Adapter->pstargetparams);
145 }
146 for (count =0;count < MAX_CNTRL_PKTS;count++) 146 for (count =0;count < MAX_CNTRL_PKTS;count++)
147 { 147 kfree(Adapter->txctlpacket[count]);
148 if(Adapter->txctlpacket[count]) 148
149 bcm_kfree(Adapter->txctlpacket[count]);
150 }
151 FreeAdapterDsxBuffer(Adapter); 149 FreeAdapterDsxBuffer(Adapter);
152 if(Adapter->pvOsDepData) 150
153 bcm_kfree (Adapter->pvOsDepData); 151 kfree(Adapter->pvInterfaceAdapter);
154 if(Adapter->pvInterfaceAdapter)
155 bcm_kfree(Adapter->pvInterfaceAdapter);
156 152
157 //Free the PHS Interface 153 //Free the PHS Interface
158 PhsCleanup(&Adapter->stBCMPhsContext); 154 PhsCleanup(&Adapter->stBCMPhsContext);
159 155
160#ifndef BCM_SHM_INTERFACE
161 BcmDeAllocFlashCSStructure(Adapter); 156 BcmDeAllocFlashCSStructure(Adapter);
162#endif
163 157
164 bcm_kfree (Adapter); 158 free_netdev(Adapter->dev);
165 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "<========\n");
166} 159}
167 160
168 161static int create_worker_threads(PMINI_ADAPTER psAdapter)
169int create_worker_threads(PMINI_ADAPTER psAdapter)
170{ 162{
171 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Init Threads...");
172 // Rx Control Packets Processing 163 // Rx Control Packets Processing
173 psAdapter->control_packet_handler = kthread_run((int (*)(void *)) 164 psAdapter->control_packet_handler = kthread_run((int (*)(void *))
174 control_packet_handler, psAdapter, "CtrlPktHdlr"); 165 control_packet_handler, psAdapter, "%s-rx", DRV_NAME);
175 if(IS_ERR(psAdapter->control_packet_handler)) 166 if(IS_ERR(psAdapter->control_packet_handler))
176 { 167 {
177 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Kernel Thread, but still returning success\n"); 168 pr_notice(DRV_NAME ": could not create control thread\n");
178 return PTR_ERR(psAdapter->control_packet_handler); 169 return PTR_ERR(psAdapter->control_packet_handler);
179 } 170 }
171
180 // Tx Thread 172 // Tx Thread
181 psAdapter->transmit_packet_thread = kthread_run((int (*)(void *)) 173 psAdapter->transmit_packet_thread = kthread_run((int (*)(void *))
182 tx_pkt_handler, psAdapter, "TxPktThread"); 174 tx_pkt_handler, psAdapter, "%s-tx", DRV_NAME);
183 if(IS_ERR (psAdapter->transmit_packet_thread)) 175 if(IS_ERR (psAdapter->transmit_packet_thread))
184 { 176 {
185 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Kernel Thread, but still returning success"); 177 pr_notice(DRV_NAME ": could not creat transmit thread\n");
186 kthread_stop(psAdapter->control_packet_handler); 178 kthread_stop(psAdapter->control_packet_handler);
187 return PTR_ERR(psAdapter->transmit_packet_thread); 179 return PTR_ERR(psAdapter->transmit_packet_thread);
188 } 180 }
189 return 0; 181 return 0;
190} 182}
191 183
192 184static struct file *open_firmware_file(PMINI_ADAPTER Adapter, const char *path)
193static inline struct file *open_firmware_file(PMINI_ADAPTER Adapter, char *path)
194{ 185{
195 struct file *flp=NULL; 186 struct file *flp=NULL;
196 mm_segment_t oldfs; 187 mm_segment_t oldfs;
@@ -200,26 +191,20 @@ static inline struct file *open_firmware_file(PMINI_ADAPTER Adapter, char *path)
200 set_fs(oldfs); 191 set_fs(oldfs);
201 if(IS_ERR(flp)) 192 if(IS_ERR(flp))
202 { 193 {
203 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable To Open File %s, err %lx", 194 pr_err(DRV_NAME "Unable To Open File %s, err %ld",
204 path, PTR_ERR(flp)); 195 path, PTR_ERR(flp));
205 flp = NULL; 196 flp = NULL;
206 }
207 else
208 {
209 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Got file descriptor pointer of %s!",
210 path);
211 } 197 }
212 if(Adapter->device_removed) 198
213 { 199 if(Adapter->device_removed)
214 flp = NULL; 200 flp = NULL;
215 }
216 201
217 return flp; 202 return flp;
218} 203}
219 204
220 205
221int BcmFileDownload(PMINI_ADAPTER Adapter,/**< Logical Adapter */ 206static int BcmFileDownload(PMINI_ADAPTER Adapter,/**< Logical Adapter */
222 char *path, /**< path to image file */ 207 const char *path, /**< path to image file */
223 unsigned int loc /**< Download Address on the chip*/ 208 unsigned int loc /**< Download Address on the chip*/
224 ) 209 )
225{ 210{
@@ -248,9 +233,7 @@ int BcmFileDownload(PMINI_ADAPTER Adapter,/**< Logical Adapter */
248 goto exit_download; 233 goto exit_download;
249 } 234 }
250 oldfs=get_fs();set_fs(get_ds()); 235 oldfs=get_fs();set_fs(get_ds());
251#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
252 vfs_llseek(flp, 0, 0); 236 vfs_llseek(flp, 0, 0);
253#endif
254 set_fs(oldfs); 237 set_fs(oldfs);
255 if(Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter, 238 if(Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter,
256 flp, loc)) 239 flp, loc))
@@ -265,29 +248,8 @@ exit_download:
265 if(flp && !(IS_ERR(flp))) 248 if(flp && !(IS_ERR(flp)))
266 filp_close(flp, current->files); 249 filp_close(flp, current->files);
267 set_fs(oldfs); 250 set_fs(oldfs);
268 do_gettimeofday(&tv);
269 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "file download done at %lx", ((tv.tv_sec * 1000) +
270 (tv.tv_usec/1000)));
271 return errorno;
272}
273
274 251
275void bcm_kfree_skb(struct sk_buff *skb) 252 return errorno;
276{
277 if(skb)
278 {
279 kfree_skb(skb);
280 }
281 skb = NULL ;
282}
283
284VOID bcm_kfree(VOID *ptr)
285{
286 if(ptr)
287 {
288 kfree(ptr);
289 }
290 ptr = NULL ;
291} 253}
292 254
293/** 255/**
@@ -395,13 +357,6 @@ INT CopyBufferToControlPacket(PMINI_ADAPTER Adapter,/**<Logical Adapter*/
395 /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent 357 /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent
396 the wake up from idlemode is from host*/ 358 the wake up from idlemode is from host*/
397 //Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE; 359 //Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE;
398#if 0
399 if(STATUS_SUCCESS != InterfaceIdleModeWakeup(Adapter))
400 {
401 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Idle Mode Wake up Failed\n");
402 return STATUS_FAILURE;
403 }
404#endif
405 Adapter->bWakeUpDevice = TRUE; 360 Adapter->bWakeUpDevice = TRUE;
406 wake_up(&Adapter->process_rx_cntrlpkt); 361 wake_up(&Adapter->process_rx_cntrlpkt);
407 362
@@ -489,9 +444,6 @@ INT CopyBufferToControlPacket(PMINI_ADAPTER Adapter,/**<Logical Adapter*/
489 atomic_inc(&Adapter->index_wr_txcntrlpkt); 444 atomic_inc(&Adapter->index_wr_txcntrlpkt);
490 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Calling transmit_packets"); 445 BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, TX_CONTROL,DBG_LVL_ALL, "Calling transmit_packets");
491 atomic_set(&Adapter->TxPktAvail, 1); 446 atomic_set(&Adapter->TxPktAvail, 1);
492#ifdef BCM_SHM_INTERFACE
493 virtual_mail_box_interrupt();
494#endif
495 wake_up(&Adapter->tx_packet_wait_queue); 447 wake_up(&Adapter->tx_packet_wait_queue);
496 } 448 }
497 else 449 else
@@ -530,18 +482,6 @@ static VOID SendStatisticsPointerRequest(PMINI_ADAPTER Adapter,
530#endif 482#endif
531 483
532 484
533void SendLinkDown(PMINI_ADAPTER Adapter)
534{
535 LINK_REQUEST stLinkDownRequest;
536 memset(&stLinkDownRequest, 0, sizeof(LINK_REQUEST));
537 stLinkDownRequest.Leader.Status=LINK_UP_CONTROL_REQ;
538 stLinkDownRequest.Leader.PLength=sizeof(ULONG);//minimum 4 bytes
539 stLinkDownRequest.szData[0]=LINK_DOWN_REQ_PAYLOAD;
540 Adapter->bLinkDownRequested = TRUE;
541
542 CopyBufferToControlPacket(Adapter,&stLinkDownRequest);
543}
544
545/****************************************************************** 485/******************************************************************
546* Function - LinkMessage() 486* Function - LinkMessage()
547* 487*
@@ -552,7 +492,7 @@ void SendLinkDown(PMINI_ADAPTER Adapter)
552* 492*
553* Returns - None. 493* Returns - None.
554*******************************************************************/ 494*******************************************************************/
555__inline VOID LinkMessage(PMINI_ADAPTER Adapter) 495VOID LinkMessage(PMINI_ADAPTER Adapter)
556{ 496{
557 PLINK_REQUEST pstLinkRequest=NULL; 497 PLINK_REQUEST pstLinkRequest=NULL;
558 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>"); 498 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
@@ -594,7 +534,7 @@ __inline VOID LinkMessage(PMINI_ADAPTER Adapter)
594 { 534 {
595 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket"); 535 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
596 CopyBufferToControlPacket(Adapter, pstLinkRequest); 536 CopyBufferToControlPacket(Adapter, pstLinkRequest);
597 bcm_kfree(pstLinkRequest); 537 kfree(pstLinkRequest);
598 } 538 }
599 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <====="); 539 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
600 return; 540 return;
@@ -614,8 +554,8 @@ __inline VOID LinkMessage(PMINI_ADAPTER Adapter)
614VOID StatisticsResponse(PMINI_ADAPTER Adapter,PVOID pvBuffer) 554VOID StatisticsResponse(PMINI_ADAPTER Adapter,PVOID pvBuffer)
615{ 555{
616 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>",__FUNCTION__); 556 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>",__FUNCTION__);
617 Adapter->StatisticsPointer = ntohl(*(PULONG)pvBuffer); 557 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
618 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %lx", Adapter->StatisticsPointer); 558 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (UINT)Adapter->StatisticsPointer);
619 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====",__FUNCTION__); 559 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====",__FUNCTION__);
620 return; 560 return;
621} 561}
@@ -764,7 +704,7 @@ void SendIdleModeResponse(PMINI_ADAPTER Adapter)
764 704
765 /* Wake the LED Thread with IDLEMODE_ENTER State */ 705 /* Wake the LED Thread with IDLEMODE_ENTER State */
766 Adapter->DriverState = LOWPOWER_MODE_ENTER; 706 Adapter->DriverState = LOWPOWER_MODE_ENTER;
767 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,"LED Thread is Running..Hence Setting LED Event as IDLEMODE_ENTER jiffies:%ld",jiffies);; 707 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,"LED Thread is Running..Hence Setting LED Event as IDLEMODE_ENTER jiffies:%ld",jiffies);
768 wake_up(&Adapter->LEDInfo.notify_led_event); 708 wake_up(&Adapter->LEDInfo.notify_led_event);
769 709
770 /* Wait for 1 SEC for LED to OFF */ 710 /* Wait for 1 SEC for LED to OFF */
@@ -787,12 +727,10 @@ void SendIdleModeResponse(PMINI_ADAPTER Adapter)
787 down(&Adapter->rdmwrmsync); 727 down(&Adapter->rdmwrmsync);
788 Adapter->bPreparingForLowPowerMode = TRUE; 728 Adapter->bPreparingForLowPowerMode = TRUE;
789 up(&Adapter->rdmwrmsync); 729 up(&Adapter->rdmwrmsync);
790#ifndef BCM_SHM_INTERFACE
791 //Killing all URBS. 730 //Killing all URBS.
792 if(Adapter->bDoSuspend == TRUE) 731 if(Adapter->bDoSuspend == TRUE)
793 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter)); 732 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
794 733
795#endif
796 } 734 }
797 else 735 else
798 { 736 {
@@ -811,9 +749,7 @@ void SendIdleModeResponse(PMINI_ADAPTER Adapter)
811 { 749 {
812 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"fail to send the Idle mode Request \n"); 750 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"fail to send the Idle mode Request \n");
813 Adapter->bPreparingForLowPowerMode = FALSE; 751 Adapter->bPreparingForLowPowerMode = FALSE;
814#ifndef BCM_SHM_INTERFACE
815 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter)); 752 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
816#endif
817 } 753 }
818 do_gettimeofday(&tv); 754 do_gettimeofday(&tv);
819 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "IdleMode Msg submitter to Q :%ld ms", tv.tv_sec *1000 + tv.tv_usec /1000); 755 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "IdleMode Msg submitter to Q :%ld ms", tv.tv_sec *1000 + tv.tv_usec /1000);
@@ -980,12 +916,10 @@ VOID DumpPackInfo(PMINI_ADAPTER Adapter)
980 916
981} 917}
982 918
983 919int reset_card_proc(PMINI_ADAPTER ps_adapter)
984__inline int reset_card_proc(PMINI_ADAPTER ps_adapter)
985{ 920{
986 int retval = STATUS_SUCCESS; 921 int retval = STATUS_SUCCESS;
987 922
988#ifndef BCM_SHM_INTERFACE
989 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 923 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
990 PS_INTERFACE_ADAPTER psIntfAdapter = NULL; 924 PS_INTERFACE_ADAPTER psIntfAdapter = NULL;
991 unsigned int value = 0, uiResetValue = 0; 925 unsigned int value = 0, uiResetValue = 0;
@@ -1006,11 +940,9 @@ __inline int reset_card_proc(PMINI_ADAPTER ps_adapter)
1006 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value)); 940 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
1007 } 941 }
1008 942
1009#ifndef BCM_SHM_INTERFACE
1010 //killing all submitted URBs. 943 //killing all submitted URBs.
1011 psIntfAdapter->psAdapter->StopAllXaction = TRUE ; 944 psIntfAdapter->psAdapter->StopAllXaction = TRUE ;
1012 Bcm_kill_all_URBs(psIntfAdapter); 945 Bcm_kill_all_URBs(psIntfAdapter);
1013#endif
1014 /* Reset the UMA-B Device */ 946 /* Reset the UMA-B Device */
1015 if(ps_adapter->chip_id >= T3LPB) 947 if(ps_adapter->chip_id >= T3LPB)
1016 { 948 {
@@ -1111,11 +1043,10 @@ __inline int reset_card_proc(PMINI_ADAPTER ps_adapter)
1111 1043
1112err_exit : 1044err_exit :
1113 psIntfAdapter->psAdapter->StopAllXaction = FALSE ; 1045 psIntfAdapter->psAdapter->StopAllXaction = FALSE ;
1114#endif
1115 return retval; 1046 return retval;
1116} 1047}
1117 1048
1118__inline int run_card_proc(PMINI_ADAPTER ps_adapter ) 1049int run_card_proc(PMINI_ADAPTER ps_adapter )
1119{ 1050{
1120 unsigned int value=0; 1051 unsigned int value=0;
1121 { 1052 {
@@ -1146,21 +1077,17 @@ __inline int run_card_proc(PMINI_ADAPTER ps_adapter )
1146int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter) 1077int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
1147{ 1078{
1148 1079
1149 UINT status = STATUS_SUCCESS; 1080 int status;
1150 UINT value = 0; 1081 UINT value = 0;
1151#ifdef BCM_SHM_INTERFACE
1152 unsigned char *pConfigFileAddr = (unsigned char *)CPE_MACXVI_CFG_ADDR;
1153#endif
1154 /* 1082 /*
1155 * Create the threads first and then download the 1083 * Create the threads first and then download the
1156 * Firm/DDR Settings.. 1084 * Firm/DDR Settings..
1157 */ 1085 */
1158 1086
1159 if((status = create_worker_threads(ps_adapter))<0) 1087 status = create_worker_threads(ps_adapter);
1160 { 1088 if (status<0)
1161 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Cannot create thread");
1162 return status; 1089 return status;
1163 } 1090
1164 /* 1091 /*
1165 * For Downloading the Firm, parse the cfg file first. 1092 * For Downloading the Firm, parse the cfg file first.
1166 */ 1093 */
@@ -1169,7 +1096,6 @@ int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
1169 return status; 1096 return status;
1170 } 1097 }
1171 1098
1172#ifndef BCM_SHM_INTERFACE
1173 if(ps_adapter->chip_id >= T3LPB) 1099 if(ps_adapter->chip_id >= T3LPB)
1174 { 1100 {
1175 rdmalt(ps_adapter, SYS_CFG, &value, sizeof (value)); 1101 rdmalt(ps_adapter, SYS_CFG, &value, sizeof (value));
@@ -1187,7 +1113,7 @@ int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
1187 status = ddr_init(ps_adapter); 1113 status = ddr_init(ps_adapter);
1188 if(status) 1114 if(status)
1189 { 1115 {
1190 BCM_DEBUG_PRINT (ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "ddr_init Failed\n"); 1116 pr_err(DRV_NAME "ddr_init Failed\n");
1191 return status; 1117 return status;
1192 } 1118 }
1193 1119
@@ -1201,7 +1127,6 @@ int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
1201 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file"); 1127 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
1202 goto OUT; 1128 goto OUT;
1203 } 1129 }
1204 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "CFG file downloaded");
1205 1130
1206 if(register_networkdev(ps_adapter)) 1131 if(register_networkdev(ps_adapter))
1207 { 1132 {
@@ -1266,12 +1191,6 @@ int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
1266 goto OUT; 1191 goto OUT;
1267 } 1192 }
1268 } 1193 }
1269#if 0
1270 else if(psAdapter->eNVMType == NVM_EEPROM)
1271 {
1272 PropagateCalParamsFromEEPROMToMemory();
1273 }
1274#endif
1275 1194
1276 /* Download Firmare */ 1195 /* Download Firmare */
1277 if ((status = BcmFileDownload( ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR))) 1196 if ((status = BcmFileDownload( ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR)))
@@ -1280,7 +1199,6 @@ int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter)
1280 goto OUT; 1199 goto OUT;
1281 } 1200 }
1282 1201
1283 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "BIN file downloaded");
1284 status = run_card_proc(ps_adapter); 1202 status = run_card_proc(ps_adapter);
1285 if(status) 1203 if(status)
1286 { 1204 {
@@ -1299,68 +1217,19 @@ OUT:
1299 wake_up(&ps_adapter->LEDInfo.notify_led_event); 1217 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1300 } 1218 }
1301 1219
1302#else
1303
1304 ps_adapter->bDDRInitDone = TRUE;
1305 //Initializing the NVM.
1306 BcmInitNVM(ps_adapter);
1307
1308 //Propagating the cal param from Flash to DDR
1309 value = 0;
1310 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1311 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1312
1313 if(ps_adapter->eNVMType == NVM_FLASH)
1314 {
1315 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1316 if(status)
1317 {
1318 printk("\nPropogation of Cal param from flash to DDR failed ..\n" );
1319 }
1320 }
1321
1322 //Copy config file param to DDR.
1323 memcpy(pConfigFileAddr,ps_adapter->pstargetparams, sizeof(STARGETPARAMS));
1324
1325 if(register_networkdev(ps_adapter))
1326 {
1327 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
1328 return -EIO;
1329 }
1330
1331
1332 status = InitLedSettings (ps_adapter);
1333 if(status)
1334 {
1335 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_PRINTK, 0, 0,"INIT LED FAILED\n");
1336 return status;
1337 }
1338
1339
1340 if(register_control_device_interface(ps_adapter) < 0)
1341 {
1342 BCM_DEBUG_PRINT(ps_adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
1343 return -EIO;
1344 }
1345
1346 ps_adapter->fw_download_done = TRUE;
1347#endif
1348 return status; 1220 return status;
1349} 1221}
1350 1222
1351 1223
1352int bcm_parse_target_params(PMINI_ADAPTER Adapter) 1224static int bcm_parse_target_params(PMINI_ADAPTER Adapter)
1353{ 1225{
1354#ifdef BCM_SHM_INTERFACE
1355 extern void read_cfg_file(PMINI_ADAPTER Adapter);
1356#endif
1357 struct file *flp=NULL; 1226 struct file *flp=NULL;
1358 mm_segment_t oldfs={0}; 1227 mm_segment_t oldfs={0};
1359 char *buff = NULL; 1228 char *buff;
1360 int len = 0; 1229 int len = 0;
1361 loff_t pos = 0; 1230 loff_t pos = 0;
1362 1231
1363 buff=(PCHAR)kmalloc(BUFFER_1K, GFP_KERNEL); 1232 buff=kmalloc(BUFFER_1K, GFP_KERNEL);
1364 if(!buff) 1233 if(!buff)
1365 { 1234 {
1366 return -ENOMEM; 1235 return -ENOMEM;
@@ -1368,14 +1237,14 @@ int bcm_parse_target_params(PMINI_ADAPTER Adapter)
1368 if((Adapter->pstargetparams = 1237 if((Adapter->pstargetparams =
1369 kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL)) == NULL) 1238 kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL)) == NULL)
1370 { 1239 {
1371 bcm_kfree(buff); 1240 kfree(buff);
1372 return -ENOMEM; 1241 return -ENOMEM;
1373 } 1242 }
1374 flp=open_firmware_file(Adapter, CFG_FILE); 1243 flp=open_firmware_file(Adapter, CFG_FILE);
1375 if(!flp) { 1244 if(!flp) {
1376 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE \n", CFG_FILE); 1245 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE \n", CFG_FILE);
1377 bcm_kfree(buff); 1246 kfree(buff);
1378 bcm_kfree(Adapter->pstargetparams); 1247 kfree(Adapter->pstargetparams);
1379 Adapter->pstargetparams = NULL; 1248 Adapter->pstargetparams = NULL;
1380 return -ENOENT; 1249 return -ENOENT;
1381 } 1250 }
@@ -1386,8 +1255,8 @@ int bcm_parse_target_params(PMINI_ADAPTER Adapter)
1386 if(len != sizeof(STARGETPARAMS)) 1255 if(len != sizeof(STARGETPARAMS))
1387 { 1256 {
1388 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Mismatch in Target Param Structure!\n"); 1257 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"Mismatch in Target Param Structure!\n");
1389 bcm_kfree(buff); 1258 kfree(buff);
1390 bcm_kfree(Adapter->pstargetparams); 1259 kfree(Adapter->pstargetparams);
1391 Adapter->pstargetparams = NULL; 1260 Adapter->pstargetparams = NULL;
1392 filp_close(flp, current->files); 1261 filp_close(flp, current->files);
1393 return -ENOENT; 1262 return -ENOENT;
@@ -1399,37 +1268,34 @@ int bcm_parse_target_params(PMINI_ADAPTER Adapter)
1399 * Values in Adapter->pstargetparams are in network byte order 1268 * Values in Adapter->pstargetparams are in network byte order
1400 */ 1269 */
1401 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS)); 1270 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS));
1402 bcm_kfree (buff); 1271 kfree (buff);
1403 beceem_parse_target_struct(Adapter); 1272 beceem_parse_target_struct(Adapter);
1404#ifdef BCM_SHM_INTERFACE
1405 read_cfg_file(Adapter);
1406
1407#endif
1408 return STATUS_SUCCESS; 1273 return STATUS_SUCCESS;
1409} 1274}
1410 1275
1411void beceem_parse_target_struct(PMINI_ADAPTER Adapter) 1276void beceem_parse_target_struct(PMINI_ADAPTER Adapter)
1412{ 1277{
1413 UINT uiHostDrvrCfg6 =0, uiEEPROMFlag = 0;; 1278 UINT uiHostDrvrCfg6 =0, uiEEPROMFlag = 0;
1414 1279
1415 if(ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) 1280 if(ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE)
1416 { 1281 {
1417 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoSyncup is Disabled\n"); 1282 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1418 Adapter->AutoSyncup = FALSE; 1283 Adapter->AutoSyncup = FALSE;
1419 } 1284 }
1420 else 1285 else
1421 { 1286 {
1422 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoSyncup is Enabled\n"); 1287 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1423 Adapter->AutoSyncup = TRUE; 1288 Adapter->AutoSyncup = TRUE;
1424 } 1289 }
1290
1425 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) 1291 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE)
1426 { 1292 {
1427 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Enabling autolink up"); 1293 pr_info(DRV_NAME ": Enabling autolink up");
1428 Adapter->AutoLinkUp = TRUE; 1294 Adapter->AutoLinkUp = TRUE;
1429 } 1295 }
1430 else 1296 else
1431 { 1297 {
1432 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Disabling autolink up"); 1298 pr_info(DRV_NAME ": Disabling autolink up");
1433 Adapter->AutoLinkUp = FALSE; 1299 Adapter->AutoLinkUp = FALSE;
1434 } 1300 }
1435 // Setting the DDR Setting.. 1301 // Setting the DDR Setting..
@@ -1438,59 +1304,54 @@ void beceem_parse_target_struct(PMINI_ADAPTER Adapter)
1438 Adapter->ulPowerSaveMode = 1304 Adapter->ulPowerSaveMode =
1439 (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F; 1305 (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
1440 1306
1441 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "DDR Setting: %x\n", Adapter->DDRSetting); 1307 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1442 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT,DBG_LVL_ALL, "Power Save Mode: %lx\n", 1308 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
1443 Adapter->ulPowerSaveMode);
1444 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) 1309 if(ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD)
1445 { 1310 {
1446 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Enabling Auto Firmware Download\n"); 1311 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1447 Adapter->AutoFirmDld = TRUE; 1312 Adapter->AutoFirmDld = TRUE;
1448 } 1313 }
1449 else 1314 else
1450 { 1315 {
1451 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Disabling Auto Firmware Download\n"); 1316 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1452 Adapter->AutoFirmDld = FALSE; 1317 Adapter->AutoFirmDld = FALSE;
1453 } 1318 }
1454 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6); 1319 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1455 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01; 1320 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
1456 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"MIPSConfig : 0x%X\n",Adapter->bMipsConfig); 1321 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n",Adapter->bMipsConfig);
1457 //used for backward compatibility. 1322 //used for backward compatibility.
1458 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01; 1323 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
1459 1324
1460 Adapter->PmuMode= (uiHostDrvrCfg6 >> 24 ) & 0x03; 1325 Adapter->PmuMode= (uiHostDrvrCfg6 >> 24 ) & 0x03;
1461 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "PMU MODE: %x", Adapter->PmuMode); 1326 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1462 1327
1463 if((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT ) & (0x01)) 1328 if((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT ) & (0x01))
1464 { 1329 {
1465 Adapter->bDoSuspend = TRUE; 1330 Adapter->bDoSuspend = TRUE;
1466 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Making DoSuspend TRUE as per configFile"); 1331 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1467 } 1332 }
1468 1333
1469 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag); 1334 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1470 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "uiEEPROMFlag : 0x%X\n",uiEEPROMFlag); 1335 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n",uiEEPROMFlag);
1471 Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3); 1336 Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3);
1472 1337
1473
1474 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1; 1338 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1475 //printk(("bStatusWrite : 0x%X\n", Adapter->bStatusWrite));
1476 1339
1477 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4)); 1340 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1478 //printk(("uiSectorSize : 0x%X\n", Adapter->uiSectorSizeInCFG));
1479 1341
1480 Adapter->bSectorSizeOverride =(bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1; 1342 Adapter->bSectorSizeOverride =(bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1481 //printk(MP_INIT,("bSectorSizeOverride : 0x%X\n",Adapter->bSectorSizeOverride));
1482 1343
1483 if(ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) &0x01) 1344 if(ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) &0x01)
1484 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE; 1345 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1485 //autocorrection part 1346
1486 if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) 1347 if(Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1487 doPowerAutoCorrection(Adapter); 1348 doPowerAutoCorrection(Adapter);
1488 1349
1489} 1350}
1490 1351
1491VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter) 1352static VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter)
1492{ 1353{
1493 UINT reporting_mode = 0; 1354 UINT reporting_mode;
1494 1355
1495 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) &0x02 ; 1356 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) &0x02 ;
1496 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1); 1357 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
@@ -1504,20 +1365,9 @@ VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter)
1504 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) 1365 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB))
1505 { 1366 {
1506 //If reporting mode is enable, switch PMU to PMC 1367 //If reporting mode is enable, switch PMU to PMC
1507 #if 0
1508 if(reporting_mode == FALSE)
1509 {
1510 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_SHUTDOWN;
1511 psAdapter->bDoSuspend = TRUE;
1512 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"PMU selected ....");
1513
1514 }
1515 else
1516 #endif
1517 { 1368 {
1518 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING; 1369 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1519 psAdapter->bDoSuspend =FALSE; 1370 psAdapter->bDoSuspend =FALSE;
1520 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL,"PMC selected..");
1521 1371
1522 } 1372 }
1523 1373
@@ -1540,12 +1390,10 @@ VOID doPowerAutoCorrection(PMINI_ADAPTER psAdapter)
1540#if 0 1390#if 0
1541static unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress) 1391static unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
1542{ 1392{
1543 unsigned char *pucmacaddr = NULL; 1393 int status = 0, i = 0;
1544 int status = 0, i=0; 1394 unsigned int temp = 0;
1545 unsigned int temp =0; 1395 unsigned char *pucmacaddr = kmalloc(MAC_ADDRESS_SIZE, GFP_KERNEL);
1546 1396
1547
1548 pucmacaddr = (unsigned char *)kmalloc(MAC_ADDRESS_SIZE, GFP_KERNEL);
1549 if(!pucmacaddr) 1397 if(!pucmacaddr)
1550 { 1398 {
1551 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "No Buffers to Read the EEPROM Address\n"); 1399 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "No Buffers to Read the EEPROM Address\n");
@@ -1558,7 +1406,7 @@ static unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
1558 if(status != STATUS_SUCCESS) 1406 if(status != STATUS_SUCCESS)
1559 { 1407 {
1560 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "wrm Failed..\n"); 1408 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "wrm Failed..\n");
1561 bcm_kfree(pucmacaddr); 1409 kfree(pucmacaddr);
1562 pucmacaddr = NULL; 1410 pucmacaddr = NULL;
1563 goto OUT; 1411 goto OUT;
1564 } 1412 }
@@ -1568,7 +1416,7 @@ static unsigned char *ReadMacAddrEEPROM(PMINI_ADAPTER Adapter, ulong dwAddress)
1568 if(status != STATUS_SUCCESS) 1416 if(status != STATUS_SUCCESS)
1569 { 1417 {
1570 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm Failed..\n"); 1418 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm Failed..\n");
1571 bcm_kfree(pucmacaddr); 1419 kfree(pucmacaddr);
1572 pucmacaddr = NULL; 1420 pucmacaddr = NULL;
1573 goto OUT; 1421 goto OUT;
1574 } 1422 }
@@ -1580,43 +1428,6 @@ OUT:
1580} 1428}
1581#endif 1429#endif
1582 1430
1583#if 0
1584INT ReadMacAddressFromEEPROM(PMINI_ADAPTER Adapter)
1585{
1586 unsigned char *puMacAddr = NULL;
1587 int i =0;
1588
1589 puMacAddr = ReadMacAddrEEPROM(Adapter,0x200);
1590 if(!puMacAddr)
1591 {
1592 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Couldn't retrieve the Mac Address\n");
1593 return STATUS_FAILURE;
1594 }
1595 else
1596 {
1597 if((puMacAddr[0] == 0x0 && puMacAddr[1] == 0x0 &&
1598 puMacAddr[2] == 0x0 && puMacAddr[3] == 0x0 &&
1599 puMacAddr[4] == 0x0 && puMacAddr[5] == 0x0) ||
1600 (puMacAddr[0] == 0xFF && puMacAddr[1] == 0xFF &&
1601 puMacAddr[2] == 0xFF && puMacAddr[3] == 0xFF &&
1602 puMacAddr[4] == 0xFF && puMacAddr[5] == 0xFF))
1603 {
1604 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Invalid Mac Address\n");
1605 bcm_kfree(puMacAddr);
1606 return STATUS_FAILURE;
1607 }
1608 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "The Mac Address received is: \n");
1609 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
1610 for(i=0;i<MAC_ADDRESS_SIZE;i++)
1611 {
1612 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"%02x ", Adapter->dev->dev_addr[i]);
1613 }
1614 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"\n");
1615 bcm_kfree(puMacAddr);
1616 }
1617 return STATUS_SUCCESS;
1618}
1619#endif
1620 1431
1621static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount) 1432static void convertEndian(B_UINT8 rwFlag, PUINT puiBuffer, UINT uiByteCount)
1622{ 1433{
@@ -1640,81 +1451,21 @@ int rdm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1640{ 1451{
1641 INT uiRetVal =0; 1452 INT uiRetVal =0;
1642 1453
1643#ifndef BCM_SHM_INTERFACE
1644 uiRetVal = Adapter->interface_rdm(Adapter->pvInterfaceAdapter, 1454 uiRetVal = Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1645 uiAddress, pucBuff, sSize); 1455 uiAddress, pucBuff, sSize);
1646 1456
1647 if(uiRetVal < 0) 1457 if(uiRetVal < 0)
1648 return uiRetVal; 1458 return uiRetVal;
1649 1459
1650#else
1651 int indx;
1652 uiRetVal = STATUS_SUCCESS;
1653 if(uiAddress & 0x10000000) {
1654 // DDR Memory Access
1655 uiAddress |= CACHE_ADDRESS_MASK;
1656 memcpy(pucBuff,(unsigned char *)uiAddress ,sSize);
1657 }
1658 else {
1659 // Register, SPRAM, Flash
1660 uiAddress |= UNCACHE_ADDRESS_MASK;
1661 if ((uiAddress & FLASH_ADDR_MASK) == (FLASH_CONTIGIOUS_START_ADDR_BCS350 & FLASH_ADDR_MASK))
1662 {
1663 #if defined(FLASH_DIRECT_ACCESS)
1664 memcpy(pucBuff,(unsigned char *)uiAddress ,sSize);
1665 #else
1666 printk("\nInvalid GSPI ACCESS :Addr :%#X", uiAddress);
1667 uiRetVal = STATUS_FAILURE;
1668 #endif
1669 }
1670 else if(((unsigned int )uiAddress & 0x3) ||
1671 ((unsigned int )pucBuff & 0x3) ||
1672 ((unsigned int )sSize & 0x3)) {
1673 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"rdmalt :unalligned register access uiAddress = %x,pucBuff = %x size = %x\n",(unsigned int )uiAddress,(unsigned int )pucBuff,(unsigned int )sSize);
1674 uiRetVal = STATUS_FAILURE;
1675 }
1676 else {
1677 for (indx=0;indx<sSize;indx+=4){
1678 *(PUINT)(pucBuff + indx) = *(PUINT)(uiAddress + indx);
1679 }
1680 }
1681 }
1682#endif
1683 return uiRetVal; 1460 return uiRetVal;
1684} 1461}
1685int wrm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize) 1462int wrm(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1686{ 1463{
1687 int iRetVal; 1464 int iRetVal;
1688 1465
1689#ifndef BCM_SHM_INTERFACE
1690 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter, 1466 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1691 uiAddress, pucBuff, sSize); 1467 uiAddress, pucBuff, sSize);
1692 1468
1693#else
1694 int indx;
1695 if(uiAddress & 0x10000000) {
1696 // DDR Memory Access
1697 uiAddress |= CACHE_ADDRESS_MASK;
1698 memcpy((unsigned char *)(uiAddress),pucBuff,sSize);
1699 }
1700 else {
1701 // Register, SPRAM, Flash
1702 uiAddress |= UNCACHE_ADDRESS_MASK;
1703
1704 if(((unsigned int )uiAddress & 0x3) ||
1705 ((unsigned int )pucBuff & 0x3) ||
1706 ((unsigned int )sSize & 0x3)) {
1707 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"wrmalt: unalligned register access uiAddress = %x,pucBuff = %x size = %x\n",(unsigned int )uiAddress,(unsigned int )pucBuff,(unsigned int )sSize);
1708 iRetVal = STATUS_FAILURE;
1709 }
1710 else {
1711 for (indx=0;indx<sSize;indx+=4) {
1712 *(PUINT)(uiAddress + indx) = *(PUINT)(pucBuff + indx);
1713 }
1714 }
1715 }
1716 iRetVal = STATUS_SUCCESS;
1717#endif
1718 1469
1719 return iRetVal; 1470 return iRetVal;
1720} 1471}
@@ -1735,26 +1486,7 @@ int rdmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t size)
1735 return uiRetVal; 1486 return uiRetVal;
1736} 1487}
1737 1488
1738int rdmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1739{
1740
1741 INT status = STATUS_SUCCESS ;
1742 down(&Adapter->rdmwrmsync);
1743
1744 if((Adapter->IdleMode == TRUE) ||
1745 (Adapter->bShutStatus ==TRUE) ||
1746 (Adapter->bPreparingForLowPowerMode ==TRUE))
1747 {
1748 status = -EACCES;
1749 goto exit;
1750 }
1751 1489
1752 status = rdm(Adapter, uiAddress, pucBuff, sSize);
1753
1754exit:
1755 up(&Adapter->rdmwrmsync);
1756 return status ;
1757}
1758int wrmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize) 1490int wrmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t sSize)
1759{ 1491{
1760 INT status = STATUS_SUCCESS ; 1492 INT status = STATUS_SUCCESS ;
@@ -1921,10 +1653,8 @@ static VOID SendShutModeResponse(PMINI_ADAPTER Adapter)
1921 Adapter->bPreparingForLowPowerMode = TRUE; 1653 Adapter->bPreparingForLowPowerMode = TRUE;
1922 up(&Adapter->rdmwrmsync); 1654 up(&Adapter->rdmwrmsync);
1923 //Killing all URBS. 1655 //Killing all URBS.
1924#ifndef BCM_SHM_INTERFACE
1925 if(Adapter->bDoSuspend == TRUE) 1656 if(Adapter->bDoSuspend == TRUE)
1926 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter)); 1657 Bcm_kill_all_URBs((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1927#endif
1928 } 1658 }
1929 else 1659 else
1930 { 1660 {
@@ -1943,14 +1673,12 @@ static VOID SendShutModeResponse(PMINI_ADAPTER Adapter)
1943 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"fail to send the Idle mode Request \n"); 1673 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL,"fail to send the Idle mode Request \n");
1944 Adapter->bPreparingForLowPowerMode = FALSE; 1674 Adapter->bPreparingForLowPowerMode = FALSE;
1945 1675
1946#ifndef BCM_SHM_INTERFACE
1947 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter)); 1676 StartInterruptUrb((PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter));
1948#endif
1949 } 1677 }
1950} 1678}
1951 1679
1952 1680
1953void HandleShutDownModeRequest(PMINI_ADAPTER Adapter,PUCHAR pucBuffer) 1681static void HandleShutDownModeRequest(PMINI_ADAPTER Adapter,PUCHAR pucBuffer)
1954{ 1682{
1955 B_UINT32 uiResetValue = 0; 1683 B_UINT32 uiResetValue = 0;
1956 1684
@@ -2077,11 +1805,7 @@ void update_per_sf_desc_cnts( PMINI_ADAPTER Adapter)
2077 if(!atomic_read (&Adapter->uiMBupdate)) 1805 if(!atomic_read (&Adapter->uiMBupdate))
2078 return; 1806 return;
2079 1807
2080#ifdef BCM_SHM_INTERFACE
2081 if(rdmalt(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS)<0)
2082#else
2083 if(rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS)<0) 1808 if(rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (PUINT)uibuff, sizeof(UINT) * MAX_TARGET_DSX_BUFFERS)<0)
2084#endif
2085 { 1809 {
2086 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm failed\n"); 1810 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
2087 return; 1811 return;
@@ -2107,9 +1831,7 @@ void update_per_sf_desc_cnts( PMINI_ADAPTER Adapter)
2107void flush_queue(PMINI_ADAPTER Adapter, UINT iQIndex) 1831void flush_queue(PMINI_ADAPTER Adapter, UINT iQIndex)
2108{ 1832{
2109 struct sk_buff* PacketToDrop=NULL; 1833 struct sk_buff* PacketToDrop=NULL;
2110 struct net_device_stats* netstats=NULL; 1834 struct net_device_stats* netstats = &Adapter->dev->stats;
2111
2112 netstats = &((PLINUX_DEP_DATA)Adapter->pvOsDepData)->netstats;
2113 1835
2114 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock); 1836 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
2115 1837
@@ -2130,25 +1852,23 @@ void flush_queue(PMINI_ADAPTER Adapter, UINT iQIndex)
2130 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len; 1852 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
2131 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++; 1853 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
2132 1854
2133 bcm_kfree_skb(PacketToDrop); 1855 dev_kfree_skb(PacketToDrop);
2134 atomic_dec(&Adapter->TotalPacketCount); 1856 atomic_dec(&Adapter->TotalPacketCount);
2135 atomic_inc(&Adapter->TxDroppedPacketCount);
2136
2137 } 1857 }
2138 } 1858 }
2139 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock); 1859 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
2140 1860
2141} 1861}
2142 1862
2143void beceem_protocol_reset (PMINI_ADAPTER Adapter) 1863static void beceem_protocol_reset (PMINI_ADAPTER Adapter)
2144{ 1864{
2145 int i =0; 1865 int i;
2146 1866
2147 if(NULL != Adapter->dev) 1867 if (netif_msg_link(Adapter))
2148 { 1868 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
2149 netif_carrier_off(Adapter->dev); 1869
2150 netif_stop_queue(Adapter->dev); 1870 netif_carrier_off(Adapter->dev);
2151 } 1871 netif_stop_queue(Adapter->dev);
2152 1872
2153 Adapter->IdleMode = FALSE; 1873 Adapter->IdleMode = FALSE;
2154 Adapter->LinkUpStatus = FALSE; 1874 Adapter->LinkUpStatus = FALSE;
@@ -2166,78 +1886,18 @@ void beceem_protocol_reset (PMINI_ADAPTER Adapter)
2166 Adapter->TimerActive = FALSE; 1886 Adapter->TimerActive = FALSE;
2167 1887
2168 memset(Adapter->astFragmentedPktClassifierTable, 0, 1888 memset(Adapter->astFragmentedPktClassifierTable, 0,
2169 sizeof(S_FRAGMENTED_PACKET_INFO) * 1889 sizeof(S_FRAGMENTED_PACKET_INFO) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
2170 MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
2171 1890
2172 for(i = 0;i<HiPriority;i++) 1891 for(i = 0;i<HiPriority;i++)
2173 { 1892 {
2174 //resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. 1893 //resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF.
2175 // It is same between MIBs and SF. 1894 // It is same between MIBs and SF.
2176 memset((PVOID)&Adapter->PackInfo[i],0,sizeof(S_MIBS_SERVICEFLOW_TABLE)); 1895 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable,
1896 0, sizeof(S_MIBS_EXTSERVICEFLOW_PARAMETERS));
2177 } 1897 }
2178} 1898}
2179 1899
2180 1900
2181 1901
2182#ifdef BCM_SHM_INTERFACE
2183
2184
2185#define GET_GTB_DIFF(start, end) \
2186( (start) < (end) )? ( (end) - (start) ) : ( ~0x0 - ( (start) - (end)) +1 )
2187
2188void usdelay ( unsigned int a) {
2189 unsigned int start= *(unsigned int *)0xaf8051b4;
2190 unsigned int end = start+1;
2191 unsigned int diff = 0;
2192
2193 while(1) {
2194 end = *(unsigned int *)0xaf8051b4;
2195 diff = (GET_GTB_DIFF(start,end))/80;
2196 if (diff >= a)
2197 break;
2198 }
2199}
2200void read_cfg_file(PMINI_ADAPTER Adapter) {
2201
2202
2203 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Config File Version = 0x%x \n",Adapter->pstargetparams->m_u32CfgVersion );
2204 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Center Frequency = 0x%x \n",Adapter->pstargetparams->m_u32CenterFrequency );
2205 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Band A Scan = 0x%x \n",Adapter->pstargetparams->m_u32BandAScan );
2206 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Band B Scan = 0x%x \n",Adapter->pstargetparams->m_u32BandBScan );
2207 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Band C Scan = 0x%x \n",Adapter->pstargetparams->m_u32BandCScan );
2208 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"ERTPS Options = 0x%x \n",Adapter->pstargetparams->m_u32ErtpsOptions );
2209 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"PHS Enable = 0x%x \n",Adapter->pstargetparams->m_u32PHSEnable );
2210 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Handoff Enable = 0x%x \n",Adapter->pstargetparams->m_u32HoEnable );
2211 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"HO Reserved1 = 0x%x \n",Adapter->pstargetparams->m_u32HoReserved1 );
2212 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"HO Reserved2 = 0x%x \n",Adapter->pstargetparams->m_u32HoReserved2 );
2213 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"MIMO Enable = 0x%x \n",Adapter->pstargetparams->m_u32MimoEnable );
2214 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"PKMv2 Enable = 0x%x \n",Adapter->pstargetparams->m_u32SecurityEnable );
2215 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Powersaving Modes Enable = 0x%x \n",Adapter->pstargetparams->m_u32PowerSavingModesEnable );
2216 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Power Saving Mode Options = 0x%x \n",Adapter->pstargetparams->m_u32PowerSavingModeOptions );
2217 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"ARQ Enable = 0x%x \n",Adapter->pstargetparams->m_u32ArqEnable );
2218 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Harq Enable = 0x%x \n",Adapter->pstargetparams->m_u32HarqEnable );
2219 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"EEPROM Flag = 0x%x \n",Adapter->pstargetparams->m_u32EEPROMFlag );
2220 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Customize = 0x%x \n",Adapter->pstargetparams->m_u32Customize );
2221 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Bandwidth = 0x%x \n",Adapter->pstargetparams->m_u32ConfigBW );
2222 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"ShutDown Timer Value = 0x%x \n",Adapter->pstargetparams->m_u32ShutDownInitThresholdTimer );
2223 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"RadioParameter = 0x%x \n",Adapter->pstargetparams->m_u32RadioParameter );
2224 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"PhyParameter1 = 0x%x \n",Adapter->pstargetparams->m_u32PhyParameter1 );
2225 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"PhyParameter2 = 0x%x \n",Adapter->pstargetparams->m_u32PhyParameter2 );
2226 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"PhyParameter3 = 0x%x \n",Adapter->pstargetparams->m_u32PhyParameter3 );
2227 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"m_u32TestOptions = 0x%x \n",Adapter->pstargetparams->m_u32TestOptions );
2228 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"MaxMACDataperDLFrame = 0x%x \n",Adapter->pstargetparams->m_u32MaxMACDataperDLFrame );
2229 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"MaxMACDataperULFrame = 0x%x \n",Adapter->pstargetparams->m_u32MaxMACDataperULFrame );
2230 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Corr2MacFlags = 0x%x \n",Adapter->pstargetparams->m_u32Corr2MacFlags );
2231 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"HostDrvrConfig1 = 0x%x \n",Adapter->pstargetparams->HostDrvrConfig1 );
2232 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"HostDrvrConfig2 = 0x%x \n",Adapter->pstargetparams->HostDrvrConfig2 );
2233 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"HostDrvrConfig3 = 0x%x \n",Adapter->pstargetparams->HostDrvrConfig3 );
2234 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"HostDrvrConfig4 = 0x%x \n",Adapter->pstargetparams->HostDrvrConfig4 );
2235 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"HostDrvrConfig5 = 0x%x \n",Adapter->pstargetparams->HostDrvrConfig5 );
2236 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"HostDrvrConfig6 = 0x%x \n",Adapter->pstargetparams->HostDrvrConfig6 );
2237 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Segmented PUSC Enable = 0x%x \n",Adapter->pstargetparams->m_u32SegmentedPUSCenable );
2238 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"BamcEnable = 0x%x \n",Adapter->pstargetparams->m_u32BandAMCEnable );
2239}
2240
2241#endif
2242 1902
2243 1903
diff --git a/drivers/staging/bcm/Osal_Misc.c b/drivers/staging/bcm/Osal_Misc.c
deleted file mode 100644
index feefd20a5291..000000000000
--- a/drivers/staging/bcm/Osal_Misc.c
+++ /dev/null
@@ -1,27 +0,0 @@
1 /*++
2
3 Copyright (c) Beceem Communications Inc.
4
5 Module Name:
6 WIN_Misc.c
7
8 Abstract:
9 Implements the Miscelanneous OS Construts
10 Linked Lists
11 Dispatcher Objects(Events,Semaphores,Spin Locks and the like)
12 Files
13
14 Revision History:
15 Who When What
16 -------- -------- ----------------------------------------------
17 Name Date Created/reviewed/modified
18 Rajeev 24/1/08 Created
19 Notes:
20
21 --*/
22#include "headers.h"
23
24bool OsalMemCompare(void *dest, void *src, UINT len)
25{
26 return (memcmp(src, dest, len));
27}
diff --git a/drivers/staging/bcm/PHSModule.c b/drivers/staging/bcm/PHSModule.c
index 8a38cf43e795..d1ca1912a74b 100644
--- a/drivers/staging/bcm/PHSModule.c
+++ b/drivers/staging/bcm/PHSModule.c
@@ -1,10 +1,54 @@
1#include "headers.h" 1#include "headers.h"
2 2
3static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId,S_SERVICEFLOW_TABLE *psServiceFlowTable,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI);
4
5static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId,S_SERVICEFLOW_ENTRY *pstServiceFlowEntry,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI);
6
7static UINT CreateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI);
8
9static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_ENTRY *pstClassifierEntry,S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI);
10
11static BOOLEAN ValidatePHSRuleComplete(S_PHS_RULE *psPhsRule);
12
13static BOOLEAN DerefPhsRule(B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable,S_PHS_RULE *pstPhsRule);
14
15static UINT GetClassifierEntry(S_CLASSIFIER_TABLE *pstClassifierTable,B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, S_CLASSIFIER_ENTRY **ppstClassifierEntry);
16
17static UINT GetPhsRuleEntry(S_CLASSIFIER_TABLE *pstClassifierTable,B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,S_PHS_RULE **ppstPhsRule);
18
19static void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTable);
20
21static int phs_compress(S_PHS_RULE *phs_members,unsigned char *in_buf,
22 unsigned char *out_buf,unsigned int *header_size,UINT *new_header_size );
23
24
25static int verify_suppress_phsf(unsigned char *in_buffer,unsigned char *out_buffer,
26 unsigned char *phsf,unsigned char *phsm,unsigned int phss,unsigned int phsv,UINT *new_header_size );
27
28static int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,\
29 S_PHS_RULE *phs_rules,UINT *header_size);
30
31
32static ULONG PhsCompress(void* pvContext,
33 B_UINT16 uiVcid,
34 B_UINT16 uiClsId,
35 void *pvInputBuffer,
36 void *pvOutputBuffer,
37 UINT *pOldHeaderSize,
38 UINT *pNewHeaderSize );
39
40static ULONG PhsDeCompress(void* pvContext,
41 B_UINT16 uiVcid,
42 void *pvInputBuffer,
43 void *pvOutputBuffer,
44 UINT *pInHeaderSize,
45 UINT *pOutHeaderSize);
46
47
48
3#define IN 49#define IN
4#define OUT 50#define OUT
5 51
6void DumpDataPacketHeader(PUCHAR pPkt);
7
8/* 52/*
9Function: PHSTransmit 53Function: PHSTransmit
10 54
@@ -81,8 +125,6 @@ int PHSTransmit(PMINI_ADAPTER Adapter,
81 { 125 {
82 126
83 127
84 //DumpDataPacketHeader(pucPHSPktHdrInBuf);
85
86 // Step 2 Supress Header using PHS and fill into intermediate ucaPHSPktHdrOutBuf. 128 // Step 2 Supress Header using PHS and fill into intermediate ucaPHSPktHdrOutBuf.
87 // Suppress only if IP Header and PHS Enabled For the Service Flow 129 // Suppress only if IP Header and PHS Enabled For the Service Flow
88 if(((usPacketType == ETHERNET_FRAMETYPE_IPV4) || 130 if(((usPacketType == ETHERNET_FRAMETYPE_IPV4) ||
@@ -120,15 +162,15 @@ int PHSTransmit(PMINI_ADAPTER Adapter,
120 if(newPacket == NULL) 162 if(newPacket == NULL)
121 return STATUS_FAILURE; 163 return STATUS_FAILURE;
122 164
123 bcm_kfree_skb(Packet); 165 dev_kfree_skb(Packet);
124 *pPacket = Packet = newPacket; 166 *pPacket = Packet = newPacket;
125 pucPHSPktHdrInBuf = Packet->data + BytesToRemove; 167 pucPHSPktHdrInBuf = Packet->data + BytesToRemove;
126 } 168 }
127 169
128 numBytesCompressed = unPhsOldHdrSize - (unPHSNewPktHeaderLen+PHSI_LEN); 170 numBytesCompressed = unPhsOldHdrSize - (unPHSNewPktHeaderLen+PHSI_LEN);
129 171
130 OsalMemMove(pucPHSPktHdrInBuf + numBytesCompressed, pucPHSPktHdrOutBuf, unPHSNewPktHeaderLen + PHSI_LEN); 172 memcpy(pucPHSPktHdrInBuf + numBytesCompressed, pucPHSPktHdrOutBuf, unPHSNewPktHeaderLen + PHSI_LEN);
131 OsalMemMove(Packet->data + numBytesCompressed, Packet->data, BytesToRemove); 173 memcpy(Packet->data + numBytesCompressed, Packet->data, BytesToRemove);
132 skb_pull(Packet, numBytesCompressed); 174 skb_pull(Packet, numBytesCompressed);
133 175
134 return STATUS_SUCCESS; 176 return STATUS_SUCCESS;
@@ -223,23 +265,12 @@ int PHSRecieve(PMINI_ADAPTER Adapter,
223 } 265 }
224 } 266 }
225 267
226 OsalMemMove(packet->data, Adapter->ucaPHSPktRestoreBuf, nStandardPktHdrLen); 268 memcpy(packet->data, Adapter->ucaPHSPktRestoreBuf, nStandardPktHdrLen);
227 } 269 }
228 270
229 return STATUS_SUCCESS; 271 return STATUS_SUCCESS;
230} 272}
231 273
232void DumpDataPacketHeader(PUCHAR pPkt)
233{
234 struct iphdr *iphd = (struct iphdr*)pPkt;
235 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
236 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"Phs Send/Recieve : IP Packet Hdr \n");
237 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"TOS : %x \n",iphd->tos);
238 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"Src IP : %x \n",iphd->saddr);
239 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,"Dest IP : %x \n \n",iphd->daddr);
240
241}
242
243void DumpFullPacket(UCHAR *pBuf,UINT nPktLen) 274void DumpFullPacket(UCHAR *pBuf,UINT nPktLen)
244{ 275{
245 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 276 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
@@ -270,15 +301,9 @@ int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension,PMINI_ADAPTER Adapter)
270 return -EINVAL; 301 return -EINVAL;
271 302
272 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = 303 pPhsdeviceExtension->pstServiceFlowPhsRulesTable =
273 (S_SERVICEFLOW_TABLE*)OsalMemAlloc(sizeof(S_SERVICEFLOW_TABLE), 304 kzalloc(sizeof(S_SERVICEFLOW_TABLE), GFP_KERNEL);
274 PHS_MEM_TAG);
275 305
276 if(pPhsdeviceExtension->pstServiceFlowPhsRulesTable) 306 if(!pPhsdeviceExtension->pstServiceFlowPhsRulesTable)
277 {
278 OsalZeroMemory(pPhsdeviceExtension->pstServiceFlowPhsRulesTable,
279 sizeof(S_SERVICEFLOW_TABLE));
280 }
281 else
282 { 307 {
283 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation ServiceFlowPhsRulesTable failed"); 308 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation ServiceFlowPhsRulesTable failed");
284 return -ENOMEM; 309 return -ENOMEM;
@@ -288,14 +313,8 @@ int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension,PMINI_ADAPTER Adapter)
288 for(i=0;i<MAX_SERVICEFLOWS;i++) 313 for(i=0;i<MAX_SERVICEFLOWS;i++)
289 { 314 {
290 S_SERVICEFLOW_ENTRY sServiceFlow = pstServiceFlowTable->stSFList[i]; 315 S_SERVICEFLOW_ENTRY sServiceFlow = pstServiceFlowTable->stSFList[i];
291 sServiceFlow.pstClassifierTable = (S_CLASSIFIER_TABLE*)OsalMemAlloc( 316 sServiceFlow.pstClassifierTable = kzalloc(sizeof(S_CLASSIFIER_TABLE), GFP_KERNEL);
292 sizeof(S_CLASSIFIER_TABLE), PHS_MEM_TAG); 317 if(!sServiceFlow.pstClassifierTable)
293 if(sServiceFlow.pstClassifierTable)
294 {
295 OsalZeroMemory(sServiceFlow.pstClassifierTable,sizeof(S_CLASSIFIER_TABLE));
296 pstServiceFlowTable->stSFList[i].pstClassifierTable = sServiceFlow.pstClassifierTable;
297 }
298 else
299 { 318 {
300 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed"); 319 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
301 free_phs_serviceflow_rules(pPhsdeviceExtension-> 320 free_phs_serviceflow_rules(pPhsdeviceExtension->
@@ -305,9 +324,7 @@ int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension,PMINI_ADAPTER Adapter)
305 } 324 }
306 } 325 }
307 326
308 327 pPhsdeviceExtension->CompressedTxBuffer = kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL);
309 pPhsdeviceExtension->CompressedTxBuffer =
310 OsalMemAlloc(PHS_BUFFER_SIZE,PHS_MEM_TAG);
311 328
312 if(pPhsdeviceExtension->CompressedTxBuffer == NULL) 329 if(pPhsdeviceExtension->CompressedTxBuffer == NULL)
313 { 330 {
@@ -317,12 +334,11 @@ int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension,PMINI_ADAPTER Adapter)
317 return -ENOMEM; 334 return -ENOMEM;
318 } 335 }
319 336
320 pPhsdeviceExtension->UnCompressedRxBuffer = 337 pPhsdeviceExtension->UnCompressedRxBuffer = kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL);
321 OsalMemAlloc(PHS_BUFFER_SIZE,PHS_MEM_TAG);
322 if(pPhsdeviceExtension->UnCompressedRxBuffer == NULL) 338 if(pPhsdeviceExtension->UnCompressedRxBuffer == NULL)
323 { 339 {
324 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed"); 340 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
325 OsalMemFree(pPhsdeviceExtension->CompressedTxBuffer,PHS_BUFFER_SIZE); 341 kfree(pPhsdeviceExtension->CompressedTxBuffer);
326 free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable); 342 free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable);
327 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL; 343 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL;
328 return -ENOMEM; 344 return -ENOMEM;
@@ -343,16 +359,11 @@ int PhsCleanup(IN PPHS_DEVICE_EXTENSION pPHSDeviceExt)
343 pPHSDeviceExt->pstServiceFlowPhsRulesTable = NULL; 359 pPHSDeviceExt->pstServiceFlowPhsRulesTable = NULL;
344 } 360 }
345 361
346 if(pPHSDeviceExt->CompressedTxBuffer) 362 kfree(pPHSDeviceExt->CompressedTxBuffer);
347 { 363 pPHSDeviceExt->CompressedTxBuffer = NULL;
348 OsalMemFree(pPHSDeviceExt->CompressedTxBuffer,PHS_BUFFER_SIZE); 364
349 pPHSDeviceExt->CompressedTxBuffer = NULL; 365 kfree(pPHSDeviceExt->UnCompressedRxBuffer);
350 } 366 pPHSDeviceExt->UnCompressedRxBuffer = NULL;
351 if(pPHSDeviceExt->UnCompressedRxBuffer)
352 {
353 OsalMemFree(pPHSDeviceExt->UnCompressedRxBuffer,PHS_BUFFER_SIZE);
354 pPHSDeviceExt->UnCompressedRxBuffer = NULL;
355 }
356 367
357 return 0; 368 return 0;
358} 369}
@@ -478,20 +489,12 @@ ULONG PhsDeletePHSRule(IN void* pvContext,IN B_UINT16 uiVcid,IN B_UINT8 u8PHSI)
478 { 489 {
479 if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].bUsed && pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule) 490 if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].bUsed && pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule)
480 { 491 {
481 if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex] 492 if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8PHSI == u8PHSI) {
482 .pstPhsRule->u8PHSI == u8PHSI) 493 if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
483 { 494 pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt--;
484 if(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule 495 if(0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
485 ->u8RefCnt) 496 kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule);
486 pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule 497 memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0,
487 ->u8RefCnt--;
488 if(0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex]
489 .pstPhsRule->u8RefCnt)
490 OsalMemFree(pstClassifierRulesTable
491 ->stActivePhsRulesList[nClsidIndex].pstPhsRule,
492 sizeof(S_PHS_RULE));
493 OsalZeroMemory(&pstClassifierRulesTable
494 ->stActivePhsRulesList[nClsidIndex],
495 sizeof(S_CLASSIFIER_ENTRY)); 498 sizeof(S_CLASSIFIER_ENTRY));
496 } 499 }
497 } 500 }
@@ -548,10 +551,10 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16
548 if(pstClassifierEntry->pstPhsRule->u8RefCnt) 551 if(pstClassifierEntry->pstPhsRule->u8RefCnt)
549 pstClassifierEntry->pstPhsRule->u8RefCnt--; 552 pstClassifierEntry->pstPhsRule->u8RefCnt--;
550 if(0==pstClassifierEntry->pstPhsRule->u8RefCnt) 553 if(0==pstClassifierEntry->pstPhsRule->u8RefCnt)
551 OsalMemFree(pstClassifierEntry->pstPhsRule,sizeof(S_PHS_RULE)); 554 kfree(pstClassifierEntry->pstPhsRule);
552 555
553 } 556 }
554 OsalZeroMemory(pstClassifierEntry,sizeof(S_CLASSIFIER_ENTRY)); 557 memset(pstClassifierEntry, 0, sizeof(S_CLASSIFIER_ENTRY));
555 } 558 }
556 559
557 nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable, 560 nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
@@ -559,10 +562,8 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16
559 562
560 if((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule)) 563 if((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule))
561 { 564 {
562 if(pstClassifierEntry->pstPhsRule) 565 kfree(pstClassifierEntry->pstPhsRule);
563 //Delete the classifier entry 566 memset(pstClassifierEntry, 0, sizeof(S_CLASSIFIER_ENTRY));
564 OsalMemFree(pstClassifierEntry->pstPhsRule,sizeof(S_PHS_RULE));
565 OsalZeroMemory(pstClassifierEntry,sizeof(S_CLASSIFIER_ENTRY));
566 } 567 }
567 } 568 }
568 return lStatus; 569 return lStatus;
@@ -619,14 +620,11 @@ ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid)
619 .pstPhsRule->u8RefCnt--; 620 .pstPhsRule->u8RefCnt--;
620 if(0==pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex] 621 if(0==pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex]
621 .pstPhsRule->u8RefCnt) 622 .pstPhsRule->u8RefCnt)
622 OsalMemFree(pstClassifierRulesTable 623 kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule);
623 ->stActivePhsRulesList[nClsidIndex].pstPhsRule,
624 sizeof(S_PHS_RULE));
625 pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex] 624 pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex]
626 .pstPhsRule = NULL; 625 .pstPhsRule = NULL;
627 } 626 }
628 OsalZeroMemory(&pstClassifierRulesTable 627 memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, sizeof(S_CLASSIFIER_ENTRY));
629 ->stActivePhsRulesList[nClsidIndex],sizeof(S_CLASSIFIER_ENTRY));
630 if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule) 628 if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule)
631 { 629 {
632 if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex] 630 if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex]
@@ -635,15 +633,12 @@ ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid)
635 .pstPhsRule->u8RefCnt--; 633 .pstPhsRule->u8RefCnt--;
636 if(0 == pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex] 634 if(0 == pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex]
637 .pstPhsRule->u8RefCnt) 635 .pstPhsRule->u8RefCnt)
638 OsalMemFree(pstClassifierRulesTable 636 kfree(pstClassifierRulesTable
639 ->stOldPhsRulesList[nClsidIndex].pstPhsRule, 637 ->stOldPhsRulesList[nClsidIndex].pstPhsRule);
640 sizeof(S_PHS_RULE));
641 pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex] 638 pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex]
642 .pstPhsRule = NULL; 639 .pstPhsRule = NULL;
643 } 640 }
644 OsalZeroMemory(&pstClassifierRulesTable 641 memset(&pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex], 0, sizeof(S_CLASSIFIER_ENTRY));
645 ->stOldPhsRulesList[nClsidIndex],
646 sizeof(S_CLASSIFIER_ENTRY));
647 } 642 }
648 } 643 }
649 pstServiceFlowEntry->bUsed = FALSE; 644 pstServiceFlowEntry->bUsed = FALSE;
@@ -849,7 +844,7 @@ ULONG PhsDeCompress(IN void* pvContext,
849// Does not return any value. 844// Does not return any value.
850//----------------------------------------------------------------------------- 845//-----------------------------------------------------------------------------
851 846
852void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTable) 847static void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTable)
853{ 848{
854 int i,j; 849 int i,j;
855 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev); 850 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
@@ -876,8 +871,7 @@ void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTable)
876 ->u8RefCnt--; 871 ->u8RefCnt--;
877 if(0==pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule 872 if(0==pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule
878 ->u8RefCnt) 873 ->u8RefCnt)
879 OsalMemFree(pstClassifierRulesTable->stActivePhsRulesList[j]. 874 kfree(pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule);
880 pstPhsRule, sizeof(S_PHS_RULE));
881 pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule = NULL; 875 pstClassifierRulesTable->stActivePhsRulesList[j].pstPhsRule = NULL;
882 } 876 }
883 if(pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule) 877 if(pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule)
@@ -888,24 +882,23 @@ void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTable)
888 ->u8RefCnt--; 882 ->u8RefCnt--;
889 if(0==pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule 883 if(0==pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule
890 ->u8RefCnt) 884 ->u8RefCnt)
891 OsalMemFree(pstClassifierRulesTable->stOldPhsRulesList[j] 885 kfree(pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule);
892 .pstPhsRule,sizeof(S_PHS_RULE));
893 pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule = NULL; 886 pstClassifierRulesTable->stOldPhsRulesList[j].pstPhsRule = NULL;
894 } 887 }
895 } 888 }
896 OsalMemFree(pstClassifierRulesTable,sizeof(S_CLASSIFIER_TABLE)); 889 kfree(pstClassifierRulesTable);
897 stServiceFlowEntry.pstClassifierTable = pstClassifierRulesTable = NULL; 890 stServiceFlowEntry.pstClassifierTable = pstClassifierRulesTable = NULL;
898 } 891 }
899 } 892 }
900 } 893 }
901 894
902 OsalMemFree(psServiceFlowRulesTable,sizeof(S_SERVICEFLOW_TABLE)); 895 kfree(psServiceFlowRulesTable);
903 psServiceFlowRulesTable = NULL; 896 psServiceFlowRulesTable = NULL;
904} 897}
905 898
906 899
907 900
908BOOLEAN ValidatePHSRuleComplete(IN S_PHS_RULE *psPhsRule) 901static BOOLEAN ValidatePHSRuleComplete(IN S_PHS_RULE *psPhsRule)
909{ 902{
910 if(psPhsRule) 903 if(psPhsRule)
911 { 904 {
@@ -988,9 +981,9 @@ UINT GetClassifierEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable,
988 return PHS_INVALID_TABLE_INDEX; 981 return PHS_INVALID_TABLE_INDEX;
989} 982}
990 983
991UINT GetPhsRuleEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable, 984static UINT GetPhsRuleEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable,
992 IN B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, 985 IN B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,
993 OUT S_PHS_RULE **ppstPhsRule) 986 OUT S_PHS_RULE **ppstPhsRule)
994{ 987{
995 int i; 988 int i;
996 S_CLASSIFIER_ENTRY *pstClassifierRule = NULL; 989 S_CLASSIFIER_ENTRY *pstClassifierRule = NULL;
@@ -1102,7 +1095,7 @@ UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid,
1102 if(psPhsRule->u8PHSFLength) 1095 if(psPhsRule->u8PHSFLength)
1103 { 1096 {
1104 //update PHSF 1097 //update PHSF
1105 OsalMemMove(pstClassifierEntry->pstPhsRule->u8PHSF, 1098 memcpy(pstClassifierEntry->pstPhsRule->u8PHSF,
1106 psPhsRule->u8PHSF , MAX_PHS_LENGTHS); 1099 psPhsRule->u8PHSF , MAX_PHS_LENGTHS);
1107 } 1100 }
1108 if(psPhsRule->u8PHSFLength) 1101 if(psPhsRule->u8PHSFLength)
@@ -1114,7 +1107,7 @@ UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid,
1114 if(psPhsRule->u8PHSMLength) 1107 if(psPhsRule->u8PHSMLength)
1115 { 1108 {
1116 //update PHSM 1109 //update PHSM
1117 OsalMemMove(pstClassifierEntry->pstPhsRule->u8PHSM, 1110 memcpy(pstClassifierEntry->pstPhsRule->u8PHSM,
1118 psPhsRule->u8PHSM, MAX_PHS_LENGTHS); 1111 psPhsRule->u8PHSM, MAX_PHS_LENGTHS);
1119 } 1112 }
1120 if(psPhsRule->u8PHSMLength) 1113 if(psPhsRule->u8PHSMLength)
@@ -1147,7 +1140,7 @@ UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid,
1147 return uiStatus; 1140 return uiStatus;
1148} 1141}
1149 1142
1150UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId, 1143static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId,
1151 S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule, 1144 S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,
1152 E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI) 1145 E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI)
1153{ 1146{
@@ -1234,8 +1227,7 @@ UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId,
1234 { 1227 {
1235 if(psClassifierRules->pstPhsRule == NULL) 1228 if(psClassifierRules->pstPhsRule == NULL)
1236 { 1229 {
1237 psClassifierRules->pstPhsRule = (S_PHS_RULE*)OsalMemAlloc 1230 psClassifierRules->pstPhsRule = kmalloc(sizeof(S_PHS_RULE),GFP_KERNEL);
1238 (sizeof(S_PHS_RULE),PHS_MEM_TAG);
1239 1231
1240 if(NULL == psClassifierRules->pstPhsRule) 1232 if(NULL == psClassifierRules->pstPhsRule)
1241 return ERR_PHSRULE_MEMALLOC_FAIL; 1233 return ERR_PHSRULE_MEMALLOC_FAIL;
@@ -1247,7 +1239,7 @@ UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId,
1247 psClassifierRules->bUnclassifiedPHSRule = psPhsRule->bUnclassifiedPHSRule; 1239 psClassifierRules->bUnclassifiedPHSRule = psPhsRule->bUnclassifiedPHSRule;
1248 1240
1249 /* Update The PHS rule */ 1241 /* Update The PHS rule */
1250 OsalMemMove(psClassifierRules->pstPhsRule, 1242 memcpy(psClassifierRules->pstPhsRule,
1251 psPhsRule, sizeof(S_PHS_RULE)); 1243 psPhsRule, sizeof(S_PHS_RULE));
1252 } 1244 }
1253 else 1245 else
@@ -1259,7 +1251,7 @@ UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId,
1259} 1251}
1260 1252
1261 1253
1262UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId, 1254static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId,
1263 IN S_CLASSIFIER_ENTRY *pstClassifierEntry, 1255 IN S_CLASSIFIER_ENTRY *pstClassifierEntry,
1264 S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule, 1256 S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,
1265 B_UINT8 u8AssociatedPHSI) 1257 B_UINT8 u8AssociatedPHSI)
@@ -1289,13 +1281,13 @@ UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId,
1289 //Step 2.a PHS Rule Does Not Exist .Create New PHS Rule for uiClsId 1281 //Step 2.a PHS Rule Does Not Exist .Create New PHS Rule for uiClsId
1290 if(FALSE == bPHSRuleOrphaned) 1282 if(FALSE == bPHSRuleOrphaned)
1291 { 1283 {
1292 pstClassifierEntry->pstPhsRule = (S_PHS_RULE*)OsalMemAlloc(sizeof(S_PHS_RULE),PHS_MEM_TAG); 1284 pstClassifierEntry->pstPhsRule = kmalloc(sizeof(S_PHS_RULE), GFP_KERNEL);
1293 if(NULL == pstClassifierEntry->pstPhsRule) 1285 if(NULL == pstClassifierEntry->pstPhsRule)
1294 { 1286 {
1295 return ERR_PHSRULE_MEMALLOC_FAIL; 1287 return ERR_PHSRULE_MEMALLOC_FAIL;
1296 } 1288 }
1297 } 1289 }
1298 OsalMemMove(pstClassifierEntry->pstPhsRule, psPhsRule, sizeof(S_PHS_RULE)); 1290 memcpy(pstClassifierEntry->pstPhsRule, psPhsRule, sizeof(S_PHS_RULE));
1299 1291
1300 } 1292 }
1301 else 1293 else
@@ -1304,14 +1296,8 @@ UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId,
1304 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nTying Classifier to Existing PHS Rule"); 1296 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nTying Classifier to Existing PHS Rule");
1305 if(bPHSRuleOrphaned) 1297 if(bPHSRuleOrphaned)
1306 { 1298 {
1307 if(pstClassifierEntry->pstPhsRule) 1299 kfree(pstClassifierEntry->pstPhsRule);
1308 {
1309 //Just Free the PHS Rule as Ref Count is Zero
1310 OsalMemFree(pstClassifierEntry->pstPhsRule,sizeof(S_PHS_RULE));
1311 pstClassifierEntry->pstPhsRule = NULL; 1300 pstClassifierEntry->pstPhsRule = NULL;
1312
1313 }
1314
1315 } 1301 }
1316 pstClassifierEntry->pstPhsRule = pstAddPhsRule; 1302 pstClassifierEntry->pstPhsRule = pstAddPhsRule;
1317 1303
@@ -1326,7 +1312,7 @@ UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId,
1326 1312
1327} 1313}
1328 1314
1329BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable,S_PHS_RULE *pstPhsRule) 1315static BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable,S_PHS_RULE *pstPhsRule)
1330{ 1316{
1331 if(pstPhsRule==NULL) 1317 if(pstPhsRule==NULL)
1332 return FALSE; 1318 return FALSE;
@@ -1345,22 +1331,6 @@ BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable
1345 } 1331 }
1346} 1332}
1347 1333
1348static void DumpBuffer(PVOID BuffVAddress, int xferSize)
1349{
1350 int i;
1351 int iPrintLength;
1352 PUCHAR temp=(PUCHAR)BuffVAddress;
1353 PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
1354 iPrintLength=(xferSize<32?xferSize:32);
1355 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\n");
1356
1357 for (i=0;i < iPrintLength;i++) {
1358 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "%x|",temp[i]);
1359 }
1360 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\n");
1361}
1362
1363
1364void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension) 1334void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension)
1365{ 1335{
1366 int i,j,k,l; 1336 int i,j,k,l;
@@ -1520,8 +1490,8 @@ int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,
1520// size-The number of bytes copied into the output buffer i.e dynamic fields 1490// size-The number of bytes copied into the output buffer i.e dynamic fields
1521// 0 -If PHS rule is NULL.If PHSV field is not set.If the verification fails. 1491// 0 -If PHS rule is NULL.If PHSV field is not set.If the verification fails.
1522//----------------------------------------------------------------------------- 1492//-----------------------------------------------------------------------------
1523int phs_compress(S_PHS_RULE *phs_rule,unsigned char *in_buf 1493static int phs_compress(S_PHS_RULE *phs_rule,unsigned char *in_buf
1524 ,unsigned char *out_buf,UINT *header_size,UINT *new_header_size) 1494 ,unsigned char *out_buf,UINT *header_size,UINT *new_header_size)
1525{ 1495{
1526 unsigned char *old_addr = out_buf; 1496 unsigned char *old_addr = out_buf;
1527 int supress = 0; 1497 int supress = 0;
@@ -1581,9 +1551,9 @@ int phs_compress(S_PHS_RULE *phs_rule,unsigned char *in_buf
1581// 0 -Packet has failed the verification. 1551// 0 -Packet has failed the verification.
1582//----------------------------------------------------------------------------- 1552//-----------------------------------------------------------------------------
1583 1553
1584 int verify_suppress_phsf(unsigned char *in_buffer,unsigned char *out_buffer, 1554static int verify_suppress_phsf(unsigned char *in_buffer,unsigned char *out_buffer,
1585 unsigned char *phsf,unsigned char *phsm,unsigned int phss, 1555 unsigned char *phsf,unsigned char *phsm,unsigned int phss,
1586 unsigned int phsv,UINT* new_header_size) 1556 unsigned int phsv,UINT* new_header_size)
1587{ 1557{
1588 unsigned int size=0; 1558 unsigned int size=0;
1589 int bit,i=0; 1559 int bit,i=0;
diff --git a/drivers/staging/bcm/PHSModule.h b/drivers/staging/bcm/PHSModule.h
index bf2b5763252c..0dd05a7c55d9 100644
--- a/drivers/staging/bcm/PHSModule.h
+++ b/drivers/staging/bcm/PHSModule.h
@@ -27,19 +27,6 @@ void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension);
27 27
28int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension,PMINI_ADAPTER Adapter); 28int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension,PMINI_ADAPTER Adapter);
29 29
30void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTable);
31
32int phs_compress(S_PHS_RULE *phs_members,unsigned char *in_buf,
33 unsigned char *out_buf,unsigned int *header_size,UINT *new_header_size );
34
35
36int verify_suppress_phsf(unsigned char *in_buffer,unsigned char *out_buffer,
37 unsigned char *phsf,unsigned char *phsm,unsigned int phss,unsigned int phsv,UINT *new_header_size );
38
39int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,\
40 S_PHS_RULE *phs_rules,UINT *header_size);
41
42
43int PhsCleanup(PPHS_DEVICE_EXTENSION pPHSDeviceExt); 30int PhsCleanup(PPHS_DEVICE_EXTENSION pPHSDeviceExt);
44 31
45//Utility Functions 32//Utility Functions
@@ -52,42 +39,10 @@ ULONG PhsDeleteClassifierRule(void* pvContext, B_UINT16 uiVcid ,B_UINT16 uiClsI
52ULONG PhsDeleteSFRules(void* pvContext,B_UINT16 uiVcid) ; 39ULONG PhsDeleteSFRules(void* pvContext,B_UINT16 uiVcid) ;
53 40
54 41
55ULONG PhsCompress(void* pvContext,
56 B_UINT16 uiVcid,
57 B_UINT16 uiClsId,
58 void *pvInputBuffer,
59 void *pvOutputBuffer,
60 UINT *pOldHeaderSize,
61 UINT *pNewHeaderSize );
62
63ULONG PhsDeCompress(void* pvContext,
64 B_UINT16 uiVcid,
65 void *pvInputBuffer,
66 void *pvOutputBuffer,
67 UINT *pInHeaderSize,
68 UINT *pOutHeaderSize);
69
70
71BOOLEAN ValidatePHSRule(S_PHS_RULE *psPhsRule); 42BOOLEAN ValidatePHSRule(S_PHS_RULE *psPhsRule);
72 43
73BOOLEAN ValidatePHSRuleComplete(S_PHS_RULE *psPhsRule);
74
75UINT GetServiceFlowEntry(S_SERVICEFLOW_TABLE *psServiceFlowTable,B_UINT16 uiVcid,S_SERVICEFLOW_ENTRY **ppstServiceFlowEntry); 44UINT GetServiceFlowEntry(S_SERVICEFLOW_TABLE *psServiceFlowTable,B_UINT16 uiVcid,S_SERVICEFLOW_ENTRY **ppstServiceFlowEntry);
76 45
77UINT GetClassifierEntry(S_CLASSIFIER_TABLE *pstClassifierTable,B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, S_CLASSIFIER_ENTRY **ppstClassifierEntry);
78
79UINT GetPhsRuleEntry(S_CLASSIFIER_TABLE *pstClassifierTable,B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,S_PHS_RULE **ppstPhsRule);
80
81
82UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId,S_SERVICEFLOW_TABLE *psServiceFlowTable,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI);
83
84UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId,S_SERVICEFLOW_ENTRY *pstServiceFlowEntry,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI);
85
86UINT CreateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI);
87
88UINT UpdateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_ENTRY *pstClassifierEntry,S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI);
89
90BOOLEAN DerefPhsRule(B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable,S_PHS_RULE *pstPhsRule);
91 46
92void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension); 47void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension);
93 48
diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h
index 00f1cc12356a..b8a4009bdf0c 100644
--- a/drivers/staging/bcm/Protocol.h
+++ b/drivers/staging/bcm/Protocol.h
@@ -85,10 +85,10 @@ typedef struct _ETH_CS_ETH2_FRAME
85 ETH_HEADER_STRUC EThHdr; 85 ETH_HEADER_STRUC EThHdr;
86} __attribute__((packed)) ETH_CS_ETH2_FRAME; 86} __attribute__((packed)) ETH_CS_ETH2_FRAME;
87 87
88#define ETHERNET_FRAMETYPE_IPV4 ntohs(0x0800)
89#define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd)
90#define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100)
88 91
89#define ETHERNET_FRAMETYPE_IPV4 ntohs(0x0800)
90#define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd)
91#define ETHERNET_FRAMETYPE_802QVLAN 0x8100
92//Per SF CS Specification Encodings 92//Per SF CS Specification Encodings
93typedef enum _E_SERVICEFLOW_CS_SPEC_ 93typedef enum _E_SERVICEFLOW_CS_SPEC_
94{ 94{
diff --git a/drivers/staging/bcm/Prototypes.h b/drivers/staging/bcm/Prototypes.h
index 70ec8bcafd1e..b80b806c90a3 100644
--- a/drivers/staging/bcm/Prototypes.h
+++ b/drivers/staging/bcm/Prototypes.h
@@ -1,23 +1,12 @@
1#ifndef _PROTOTYPES_H_ 1#ifndef _PROTOTYPES_H_
2#define _PROTOTYPES_H_ 2#define _PROTOTYPES_H_
3 3
4int BcmFileDownload(PMINI_ADAPTER Adapter,/**< Logical Adapter */
5 char *path, /**< path to image file */
6 unsigned int loc /**< Download Address on the chip*/
7 );
8VOID LinkControlResponseMessage(PMINI_ADAPTER Adapter, PUCHAR pucBuffer); 4VOID LinkControlResponseMessage(PMINI_ADAPTER Adapter, PUCHAR pucBuffer);
9 5
10VOID StatisticsResponse(PMINI_ADAPTER Adapter,PVOID pvBuffer); 6VOID StatisticsResponse(PMINI_ADAPTER Adapter,PVOID pvBuffer);
11 7
12VOID IdleModeResponse(PMINI_ADAPTER Adapter,PUINT puiBuffer); 8VOID IdleModeResponse(PMINI_ADAPTER Adapter,PUINT puiBuffer);
13 9
14void bcm_kfree_skb(struct sk_buff *skb);
15VOID bcm_kfree(VOID *ptr);
16
17
18VOID handle_rx_control_packet(PMINI_ADAPTER Adapter, /**<Pointer to the Adapter structure*/
19 struct sk_buff *skb); /**<Pointer to the socket buffer*/
20
21int control_packet_handler (PMINI_ADAPTER Adapter); 10int control_packet_handler (PMINI_ADAPTER Adapter);
22 11
23VOID DeleteAllClassifiersForSF(PMINI_ADAPTER Adapter,UINT uiSearchRuleIndex); 12VOID DeleteAllClassifiersForSF(PMINI_ADAPTER Adapter,UINT uiSearchRuleIndex);
@@ -38,25 +27,16 @@ VOID SortClassifiers(PMINI_ADAPTER Adapter);
38 27
39VOID flush_all_queues(PMINI_ADAPTER Adapter); 28VOID flush_all_queues(PMINI_ADAPTER Adapter);
40 29
41USHORT IpVersion4(PMINI_ADAPTER Adapter, /**< Pointer to the driver control structure */
42 struct iphdr *iphd, /**<Pointer to the IP Hdr of the packet*/
43 S_CLASSIFIER_RULE *pstClassifierRule );
44
45VOID PruneQueue(PMINI_ADAPTER Adapter,/**<Pointer to the driver control structure*/
46 INT iIndex/**<Queue Index*/
47 );
48
49VOID PruneQueueAllSF(PMINI_ADAPTER Adapter); 30VOID PruneQueueAllSF(PMINI_ADAPTER Adapter);
50 31
51INT SearchSfid(PMINI_ADAPTER Adapter,UINT uiSfid); 32INT SearchSfid(PMINI_ADAPTER Adapter,UINT uiSfid);
52 33
53USHORT GetPacketQueueIndex(PMINI_ADAPTER Adapter, /**<Pointer to the driver control structure */ 34USHORT ClassifyPacket(PMINI_ADAPTER Adapter,struct sk_buff* skb);
54 struct sk_buff* Packet /**< Pointer to the Packet to be sent*/ 35
55 ); 36BOOLEAN MatchSrcPort(S_CLASSIFIER_RULE *pstClassifierRule,USHORT ushSrcPort);
37BOOLEAN MatchDestPort(S_CLASSIFIER_RULE *pstClassifierRule,USHORT ushSrcPort);
38BOOLEAN MatchProtocol(S_CLASSIFIER_RULE *pstClassifierRule,UCHAR ucProtocol);
56 39
57VOID
58reply_to_arp_request(struct sk_buff *skb /**<sk_buff of ARP request*/
59 );
60 40
61INT SetupNextSend(PMINI_ADAPTER Adapter, /**<Logical Adapter*/ 41INT SetupNextSend(PMINI_ADAPTER Adapter, /**<Logical Adapter*/
62 struct sk_buff *Packet, /**<data buffer*/ 42 struct sk_buff *Packet, /**<data buffer*/
@@ -70,11 +50,9 @@ INT SendControlPacket(PMINI_ADAPTER Adapter, /**<Logical Adapter*/
70 char *pControlPacket/**<Control Packet*/ 50 char *pControlPacket/**<Control Packet*/
71 ); 51 );
72 52
73INT bcm_transmit(struct sk_buff *skb, /**< skb */
74 struct net_device *dev /**< net device pointer */
75 );
76 53
77int register_networkdev(PMINI_ADAPTER Adapter); 54int register_networkdev(PMINI_ADAPTER Adapter);
55void unregister_networkdev(PMINI_ADAPTER Adapter);
78 56
79INT AllocAdapterDsxBuffer(PMINI_ADAPTER Adapter); 57INT AllocAdapterDsxBuffer(PMINI_ADAPTER Adapter);
80 58
@@ -82,8 +60,6 @@ VOID AdapterFree(PMINI_ADAPTER Adapter);
82 60
83INT FreeAdapterDsxBuffer(PMINI_ADAPTER Adapter); 61INT FreeAdapterDsxBuffer(PMINI_ADAPTER Adapter);
84 62
85int create_worker_threads(PMINI_ADAPTER psAdapter);
86
87int tx_pkt_handler(PMINI_ADAPTER Adapter); 63int tx_pkt_handler(PMINI_ADAPTER Adapter);
88 64
89int reset_card_proc(PMINI_ADAPTER Adapter ); 65int reset_card_proc(PMINI_ADAPTER Adapter );
@@ -92,7 +68,6 @@ int run_card_proc(PMINI_ADAPTER Adapter );
92 68
93int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter); 69int InitCardAndDownloadFirmware(PMINI_ADAPTER ps_adapter);
94 70
95int bcm_parse_target_params(PMINI_ADAPTER Adapter);
96 71
97INT ReadMacAddressFromNVM(PMINI_ADAPTER Adapter); 72INT ReadMacAddressFromNVM(PMINI_ADAPTER Adapter);
98 73
@@ -110,26 +85,15 @@ int rdmalt (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t sSize);
110 85
111int get_dsx_sf_data_to_application(PMINI_ADAPTER Adapter, UINT uiSFId, void __user * user_buffer); 86int get_dsx_sf_data_to_application(PMINI_ADAPTER Adapter, UINT uiSFId, void __user * user_buffer);
112 87
113void SendLinkDown(PMINI_ADAPTER Adapter);
114
115void SendIdleModeResponse(PMINI_ADAPTER Adapter); 88void SendIdleModeResponse(PMINI_ADAPTER Adapter);
116 89
117void HandleShutDownModeRequest(PMINI_ADAPTER Adapter,PUCHAR pucBuffer);
118
119int ProcessGetHostMibs(PMINI_ADAPTER Adapter, PVOID ioBuffer,
120 ULONG inputBufferLength);
121 90
122int GetDroppedAppCntrlPktMibs(PVOID ioBuffer, PPER_TARANG_DATA pTarang); 91int ProcessGetHostMibs(PMINI_ADAPTER Adapter, S_MIBS_HOST_STATS_MIBS *buf);
92void GetDroppedAppCntrlPktMibs(S_MIBS_HOST_STATS_MIBS *ioBuffer, PPER_TARANG_DATA pTarang);
123void beceem_parse_target_struct(PMINI_ADAPTER Adapter); 93void beceem_parse_target_struct(PMINI_ADAPTER Adapter);
124 94
125void doPowerAutoCorrection(PMINI_ADAPTER psAdapter);
126
127int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter, FIRMWARE_INFO *psFwInfo); 95int bcm_ioctl_fw_download(PMINI_ADAPTER Adapter, FIRMWARE_INFO *psFwInfo);
128 96
129void bcm_unregister_networkdev(PMINI_ADAPTER Adapter);
130
131int SearchVcid(PMINI_ADAPTER Adapter,unsigned short usVcid);
132
133void CopyMIBSExtendedSFParameters(PMINI_ADAPTER Adapter, 97void CopyMIBSExtendedSFParameters(PMINI_ADAPTER Adapter,
134 CServiceFlowParamSI *psfLocalSet, UINT uiSearchRuleIndex); 98 CServiceFlowParamSI *psfLocalSet, UINT uiSearchRuleIndex);
135 99
@@ -149,7 +113,6 @@ void update_per_sf_desc_cnts( PMINI_ADAPTER Adapter);
149 113
150void ClearTargetDSXBuffer(PMINI_ADAPTER Adapter,B_UINT16 TID,BOOLEAN bFreeAll); 114void ClearTargetDSXBuffer(PMINI_ADAPTER Adapter,B_UINT16 TID,BOOLEAN bFreeAll);
151 115
152void beceem_protocol_reset (PMINI_ADAPTER Adapter);
153 116
154void flush_queue(PMINI_ADAPTER Adapter, UINT iQIndex); 117void flush_queue(PMINI_ADAPTER Adapter, UINT iQIndex);
155 118
@@ -164,31 +127,11 @@ INT BeceemEEPROMBulkRead(
164 UINT uiNumBytes); 127 UINT uiNumBytes);
165 128
166 129
167INT BeceemFlashBulkRead(
168 PMINI_ADAPTER Adapter,
169 PUINT pBuffer,
170 UINT uiOffset,
171 UINT uiNumBytes);
172
173UINT BcmGetEEPROMSize(PMINI_ADAPTER Adapter);
174 130
175INT WriteBeceemEEPROM(PMINI_ADAPTER Adapter,UINT uiEEPROMOffset, UINT uiData); 131INT WriteBeceemEEPROM(PMINI_ADAPTER Adapter,UINT uiEEPROMOffset, UINT uiData);
176 132
177UINT BcmGetFlashSize(PMINI_ADAPTER Adapter);
178
179UINT BcmGetFlashSectorSize(PMINI_ADAPTER Adapter, UINT FlashSectorSizeSig, UINT FlashSectorSize);
180
181INT BeceemFlashBulkWrite(
182 PMINI_ADAPTER Adapter,
183 PUINT pBuffer,
184 UINT uiOffset,
185 UINT uiNumBytes,
186 BOOLEAN bVerify);
187
188INT PropagateCalParamsFromFlashToMemory(PMINI_ADAPTER Adapter); 133INT PropagateCalParamsFromFlashToMemory(PMINI_ADAPTER Adapter);
189 134
190INT PropagateCalParamsFromEEPROMToMemory(PMINI_ADAPTER Adapter);
191
192 135
193INT BeceemEEPROMBulkWrite( 136INT BeceemEEPROMBulkWrite(
194 PMINI_ADAPTER Adapter, 137 PMINI_ADAPTER Adapter,
@@ -198,11 +141,8 @@ INT BeceemEEPROMBulkWrite(
198 BOOLEAN bVerify); 141 BOOLEAN bVerify);
199 142
200 143
201INT ReadBeceemEEPROMBulk(PMINI_ADAPTER Adapter,UINT dwAddress, UINT *pdwData, UINT dwNumData);
202
203INT ReadBeceemEEPROM(PMINI_ADAPTER Adapter,UINT dwAddress, UINT *pdwData); 144INT ReadBeceemEEPROM(PMINI_ADAPTER Adapter,UINT dwAddress, UINT *pdwData);
204 145
205NVM_TYPE BcmGetNvmType(PMINI_ADAPTER Adapter);
206 146
207INT BeceemNVMRead( 147INT BeceemNVMRead(
208 PMINI_ADAPTER Adapter, 148 PMINI_ADAPTER Adapter,
@@ -217,24 +157,12 @@ INT BeceemNVMWrite(
217 UINT uiNumBytes, 157 UINT uiNumBytes,
218 BOOLEAN bVerify); 158 BOOLEAN bVerify);
219 159
220INT BcmUpdateSectorSize(PMINI_ADAPTER Adapter,UINT uiSectorSize);
221 160
222INT BcmInitNVM(PMINI_ADAPTER Adapter); 161INT BcmInitNVM(PMINI_ADAPTER Adapter);
223 162
224INT BcmGetNvmSize(PMINI_ADAPTER Adapter); 163INT BcmUpdateSectorSize(PMINI_ADAPTER Adapter,UINT uiSectorSize);
225 164BOOLEAN IsSectionExistInFlash(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section);
226INT IsSectionExistInVendorInfo(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section);
227
228VOID BcmValidateNvmType(PMINI_ADAPTER Adapter);
229
230VOID ConfigureEndPointTypesThroughEEPROM(PMINI_ADAPTER Adapter);
231 165
232INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter);
233INT ReadDSDHeader(PMINI_ADAPTER Adapter, PDSD_HEADER psDSDHeader, FLASH2X_SECTION_VAL dsd);
234INT BcmGetActiveDSD(PMINI_ADAPTER Adapter);
235INT ReadISOHeader(PMINI_ADAPTER Adapter, PISO_HEADER psISOHeader, FLASH2X_SECTION_VAL IsoImage);
236INT BcmGetActiveISO(PMINI_ADAPTER Adapter);
237B_UINT8 IsOffsetWritable(PMINI_ADAPTER Adapter, UINT uiOffset);
238INT BcmGetFlash2xSectionalBitMap(PMINI_ADAPTER Adapter, PFLASH2X_BITMAP psFlash2xBitMap); 166INT BcmGetFlash2xSectionalBitMap(PMINI_ADAPTER Adapter, PFLASH2X_BITMAP psFlash2xBitMap);
239 167
240INT BcmFlash2xBulkWrite( 168INT BcmFlash2xBulkWrite(
@@ -251,7 +179,6 @@ INT BcmFlash2xBulkRead(
251 FLASH2X_SECTION_VAL eFlashSectionVal, 179 FLASH2X_SECTION_VAL eFlashSectionVal,
252 UINT uiOffsetWithinSectionVal, 180 UINT uiOffsetWithinSectionVal,
253 UINT uiNumBytes); 181 UINT uiNumBytes);
254INT BcmGetSectionValEndOffset(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlashSectionVal);
255 182
256INT BcmGetSectionValStartOffset(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlashSectionVal); 183INT BcmGetSectionValStartOffset(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlashSectionVal);
257 184
@@ -264,34 +191,13 @@ INT BcmFlash2xCorruptSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSect
264INT BcmFlash2xWriteSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlashSectionVal); 191INT BcmFlash2xWriteSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlashSectionVal);
265INT validateFlash2xReadWrite(PMINI_ADAPTER Adapter, PFLASH2X_READWRITE psFlash2xReadWrite); 192INT validateFlash2xReadWrite(PMINI_ADAPTER Adapter, PFLASH2X_READWRITE psFlash2xReadWrite);
266INT IsFlash2x(PMINI_ADAPTER Adapter); 193INT IsFlash2x(PMINI_ADAPTER Adapter);
267INT GetFlashBaseAddr(PMINI_ADAPTER Adapter);
268INT SaveHeaderIfPresent(PMINI_ADAPTER Adapter, PUCHAR pBuff, UINT uiSectAlignAddr);
269INT BcmCopySection(PMINI_ADAPTER Adapter, 194INT BcmCopySection(PMINI_ADAPTER Adapter,
270 FLASH2X_SECTION_VAL SrcSection, 195 FLASH2X_SECTION_VAL SrcSection,
271 FLASH2X_SECTION_VAL DstSection, 196 FLASH2X_SECTION_VAL DstSection,
272 UINT offset, 197 UINT offset,
273 UINT numOfBytes); 198 UINT numOfBytes);
274 199
275INT BcmDoChipSelect(PMINI_ADAPTER Adapter, UINT offset); 200
276INT BcmMakeFlashCSActive(PMINI_ADAPTER Adapter, UINT offset);
277INT ReadDSDSignature(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL dsd);
278INT ReadDSDPriority(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL dsd);
279FLASH2X_SECTION_VAL getHighestPriDSD(PMINI_ADAPTER Adapter);
280INT ReadISOSignature(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL iso);
281INT ReadISOPriority(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL iso);
282FLASH2X_SECTION_VAL getHighestPriISO(PMINI_ADAPTER Adapter);
283INT WriteToFlashWithoutSectorErase(PMINI_ADAPTER Adapter,
284 PUINT pBuff,
285 FLASH2X_SECTION_VAL eFlash2xSectionVal,
286 UINT uiOffset,
287 UINT uiNumBytes
288 );
289
290//UINT getNumOfSubSectionWithWRPermisson(PMINI_ADAPTER Adapter, SECTION_TYPE secType);
291BOOLEAN IsSectionExistInFlash(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section);
292INT IsSectionWritable(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL Section);
293INT CorruptDSDSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal);
294INT CorruptISOSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal);
295BOOLEAN IsNonCDLessDevice(PMINI_ADAPTER Adapter); 201BOOLEAN IsNonCDLessDevice(PMINI_ADAPTER Adapter);
296 202
297 203
@@ -300,7 +206,6 @@ VOID OverrideServiceFlowParams(PMINI_ADAPTER Adapter,PUINT puiBuffer);
300int wrmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t sSize); 206int wrmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t sSize);
301int rdmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t sSize); 207int rdmaltWithLock (PMINI_ADAPTER Adapter, UINT uiAddress, PUINT pucBuff, size_t sSize);
302 208
303int rdmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t size);
304int wrmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t size); 209int wrmWithLock(PMINI_ADAPTER Adapter, UINT uiAddress, PCHAR pucBuff, size_t size);
305INT buffDnldVerify(PMINI_ADAPTER Adapter, unsigned char *mappedbuffer, unsigned int u32FirmwareLength, 210INT buffDnldVerify(PMINI_ADAPTER Adapter, unsigned char *mappedbuffer, unsigned int u32FirmwareLength,
306 unsigned long u32StartingAddress); 211 unsigned long u32StartingAddress);
@@ -309,11 +214,6 @@ INT buffDnldVerify(PMINI_ADAPTER Adapter, unsigned char *mappedbuffer, unsigned
309VOID putUsbSuspend(struct work_struct *work); 214VOID putUsbSuspend(struct work_struct *work);
310BOOLEAN IsReqGpioIsLedInNVM(PMINI_ADAPTER Adapter, UINT gpios); 215BOOLEAN IsReqGpioIsLedInNVM(PMINI_ADAPTER Adapter, UINT gpios);
311 216
312#ifdef BCM_SHM_INTERFACE
313INT beceem_virtual_device_init(void);
314VOID virtual_mail_box_interrupt(void);
315INT beceem_virtual_device_exit(void);
316#endif
317 217
318#endif 218#endif
319 219
diff --git a/drivers/staging/bcm/Qos.c b/drivers/staging/bcm/Qos.c
index 75b2b879633f..8ce4536e6e28 100644
--- a/drivers/staging/bcm/Qos.c
+++ b/drivers/staging/bcm/Qos.c
@@ -4,15 +4,14 @@ This file contains the routines related to Quality of Service.
4*/ 4*/
5#include "headers.h" 5#include "headers.h"
6 6
7BOOLEAN MatchSrcIpAddress(S_CLASSIFIER_RULE *pstClassifierRule,ULONG ulSrcIP); 7static void EThCSGetPktInfo(PMINI_ADAPTER Adapter,PVOID pvEthPayload,PS_ETHCS_PKT_INFO pstEthCsPktInfo);
8BOOLEAN MatchTos(S_CLASSIFIER_RULE *pstClassifierRule,UCHAR ucTypeOfService); 8static BOOLEAN EThCSClassifyPkt(PMINI_ADAPTER Adapter,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo,S_CLASSIFIER_RULE *pstClassifierRule, B_UINT8 EthCSCupport);
9BOOLEAN MatchSrcPort(S_CLASSIFIER_RULE *pstClassifierRule,USHORT ushSrcPort); 9
10BOOLEAN MatchDestPort(S_CLASSIFIER_RULE *pstClassifierRule,USHORT ushDestPort); 10static USHORT IpVersion4(PMINI_ADAPTER Adapter, struct iphdr *iphd,
11BOOLEAN MatchProtocol(S_CLASSIFIER_RULE *pstClassifierRule,UCHAR ucProtocol); 11 S_CLASSIFIER_RULE *pstClassifierRule );
12BOOLEAN MatchDestIpAddress(S_CLASSIFIER_RULE *pstClassifierRule,ULONG ulDestIP); 12
13USHORT ClassifyPacket(PMINI_ADAPTER Adapter,struct sk_buff* skb); 13static VOID PruneQueue(PMINI_ADAPTER Adapter, INT iIndex);
14void EThCSGetPktInfo(PMINI_ADAPTER Adapter,PVOID pvEthPayload,PS_ETHCS_PKT_INFO pstEthCsPktInfo); 14
15BOOLEAN EThCSClassifyPkt(PMINI_ADAPTER Adapter,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo,S_CLASSIFIER_RULE *pstClassifierRule, B_UINT8 EthCSCupport);
16 15
17/******************************************************************* 16/*******************************************************************
18* Function - MatchSrcIpAddress() 17* Function - MatchSrcIpAddress()
@@ -205,11 +204,10 @@ BOOLEAN MatchDestPort(S_CLASSIFIER_RULE *pstClassifierRule,USHORT ushDestPort)
205Compares IPV4 Ip address and port number 204Compares IPV4 Ip address and port number
206@return Queue Index. 205@return Queue Index.
207*/ 206*/
208USHORT IpVersion4(PMINI_ADAPTER Adapter, /**< Pointer to the driver control structure */ 207static USHORT IpVersion4(PMINI_ADAPTER Adapter,
209 struct iphdr *iphd, /**<Pointer to the IP Hdr of the packet*/ 208 struct iphdr *iphd,
210 S_CLASSIFIER_RULE *pstClassifierRule ) 209 S_CLASSIFIER_RULE *pstClassifierRule )
211{ 210{
212 //IPHeaderFormat *pIpHeader=NULL;
213 xporthdr *xprt_hdr=NULL; 211 xporthdr *xprt_hdr=NULL;
214 BOOLEAN bClassificationSucceed=FALSE; 212 BOOLEAN bClassificationSucceed=FALSE;
215 213
@@ -261,15 +259,6 @@ USHORT IpVersion4(PMINI_ADAPTER Adapter, /**< Pointer to the driver control stru
261 //if protocol is not TCP or UDP then no need of comparing source port and destination port 259 //if protocol is not TCP or UDP then no need of comparing source port and destination port
262 if(iphd->protocol!=TCP && iphd->protocol!=UDP) 260 if(iphd->protocol!=TCP && iphd->protocol!=UDP)
263 break; 261 break;
264#if 0
265 //check if memory is available of src and Dest port
266 if(ETH_AND_IP_HEADER_LEN + L4_SRC_PORT_LEN + L4_DEST_PORT_LEN > Packet->len)
267 {
268 //This is not an erroneous condition and pkt will be checked for next classification.
269 bClassificationSucceed = FALSE;
270 break;
271 }
272#endif
273 //******************Checking Transport Layer Header field if present *****************// 262 //******************Checking Transport Layer Header field if present *****************//
274 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Source Port %04x", 263 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Source Port %04x",
275 (iphd->protocol==UDP)?xprt_hdr->uhdr.source:xprt_hdr->thdr.source); 264 (iphd->protocol==UDP)?xprt_hdr->uhdr.source:xprt_hdr->thdr.source);
@@ -312,29 +301,6 @@ USHORT IpVersion4(PMINI_ADAPTER Adapter, /**< Pointer to the driver control stru
312 301
313 return bClassificationSucceed; 302 return bClassificationSucceed;
314} 303}
315/**
316@ingroup tx_functions
317@return Queue Index based on priority.
318*/
319USHORT GetPacketQueueIndex(PMINI_ADAPTER Adapter, /**<Pointer to the driver control structure */
320 struct sk_buff* Packet /**< Pointer to the Packet to be sent*/
321 )
322{
323 USHORT usIndex=-1;
324 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, QUEUE_INDEX, DBG_LVL_ALL, "=====>");
325
326 if(NULL==Adapter || NULL==Packet)
327 {
328 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, QUEUE_INDEX, DBG_LVL_ALL, "Got NULL Values<======");
329 return -1;
330 }
331
332 usIndex = ClassifyPacket(Adapter,Packet);
333
334 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, QUEUE_INDEX, DBG_LVL_ALL, "Got Queue Index %x",usIndex);
335 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, QUEUE_INDEX, DBG_LVL_ALL, "GetPacketQueueIndex <==============");
336 return usIndex;
337}
338 304
339VOID PruneQueueAllSF(PMINI_ADAPTER Adapter) 305VOID PruneQueueAllSF(PMINI_ADAPTER Adapter)
340{ 306{
@@ -357,23 +323,21 @@ is less than number of bytes in the queue. If so -
357drops packets from the Head till the number of bytes is 323drops packets from the Head till the number of bytes is
358less than or equal to max queue size for the queue. 324less than or equal to max queue size for the queue.
359*/ 325*/
360VOID PruneQueue(PMINI_ADAPTER Adapter,/**<Pointer to the driver control structure*/ 326static VOID PruneQueue(PMINI_ADAPTER Adapter, INT iIndex)
361 INT iIndex/**<Queue Index*/
362 )
363{ 327{
364 struct sk_buff* PacketToDrop=NULL; 328 struct sk_buff* PacketToDrop=NULL;
365 struct net_device_stats* netstats=NULL; 329 struct net_device_stats *netstats;
366 330
367 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, PRUNE_QUEUE, DBG_LVL_ALL, "=====> Index %d",iIndex); 331 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, PRUNE_QUEUE, DBG_LVL_ALL, "=====> Index %d",iIndex);
368 332
369 if(iIndex == HiPriority) 333 if(iIndex == HiPriority)
370 return; 334 return;
371 335
372 if(!Adapter || (iIndex < 0) || (iIndex > HiPriority)) 336 if(!Adapter || (iIndex < 0) || (iIndex > HiPriority))
373 return; 337 return;
374 338
375 /* To Store the netdevice statistic */ 339 /* To Store the netdevice statistic */
376 netstats = &((PLINUX_DEP_DATA)Adapter->pvOsDepData)->netstats; 340 netstats = &Adapter->dev->stats;
377 341
378 spin_lock_bh(&Adapter->PackInfo[iIndex].SFQueueLock); 342 spin_lock_bh(&Adapter->PackInfo[iIndex].SFQueueLock);
379 343
@@ -395,9 +359,13 @@ VOID PruneQueue(PMINI_ADAPTER Adapter,/**<Pointer to the driver control structur
395 359
396 if(PacketToDrop) 360 if(PacketToDrop)
397 { 361 {
398 if(netstats) 362 struct netdev_queue *txq = netdev_get_tx_queue(Adapter->dev, iIndex);
399 netstats->tx_dropped++; 363 if (netif_msg_tx_err(Adapter))
400 atomic_inc(&Adapter->TxDroppedPacketCount); 364 pr_info(PFX "%s: tx queue %d overlimit\n",
365 Adapter->dev->name, iIndex);
366
367 txq->tx_dropped++;
368
401 DEQUEUEPACKET(Adapter->PackInfo[iIndex].FirstTxQueue, 369 DEQUEUEPACKET(Adapter->PackInfo[iIndex].FirstTxQueue,
402 Adapter->PackInfo[iIndex].LastTxQueue); 370 Adapter->PackInfo[iIndex].LastTxQueue);
403 /// update current bytes and packets count 371 /// update current bytes and packets count
@@ -407,7 +375,7 @@ VOID PruneQueue(PMINI_ADAPTER Adapter,/**<Pointer to the driver control structur
407 /// update dropped bytes and packets counts 375 /// update dropped bytes and packets counts
408 Adapter->PackInfo[iIndex].uiDroppedCountBytes += PacketToDrop->len; 376 Adapter->PackInfo[iIndex].uiDroppedCountBytes += PacketToDrop->len;
409 Adapter->PackInfo[iIndex].uiDroppedCountPackets++; 377 Adapter->PackInfo[iIndex].uiDroppedCountPackets++;
410 bcm_kfree_skb(PacketToDrop); 378 dev_kfree_skb(PacketToDrop);
411 379
412 } 380 }
413 381
@@ -416,7 +384,6 @@ VOID PruneQueue(PMINI_ADAPTER Adapter,/**<Pointer to the driver control structur
416 Adapter->PackInfo[iIndex].uiDroppedCountPackets); 384 Adapter->PackInfo[iIndex].uiDroppedCountPackets);
417 385
418 atomic_dec(&Adapter->TotalPacketCount); 386 atomic_dec(&Adapter->TotalPacketCount);
419 Adapter->bcm_jiffies = jiffies;
420 } 387 }
421 388
422 spin_unlock_bh(&Adapter->PackInfo[iIndex].SFQueueLock); 389 spin_unlock_bh(&Adapter->PackInfo[iIndex].SFQueueLock);
@@ -430,16 +397,15 @@ VOID flush_all_queues(PMINI_ADAPTER Adapter)
430{ 397{
431 INT iQIndex; 398 INT iQIndex;
432 UINT uiTotalPacketLength; 399 UINT uiTotalPacketLength;
433 struct sk_buff* PacketToDrop=NULL; 400 struct sk_buff* PacketToDrop=NULL;
434 struct net_device_stats* netstats=NULL;
435 401
436 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "=====>"); 402 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "=====>");
437 /* To Store the netdevice statistic */
438 netstats = &((PLINUX_DEP_DATA)Adapter->pvOsDepData)->netstats;
439 403
440// down(&Adapter->data_packet_queue_lock); 404// down(&Adapter->data_packet_queue_lock);
441 for(iQIndex=LowPriority; iQIndex<HiPriority; iQIndex++) 405 for(iQIndex=LowPriority; iQIndex<HiPriority; iQIndex++)
442 { 406 {
407 struct netdev_queue *txq = netdev_get_tx_queue(Adapter->dev, iQIndex);
408
443 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock); 409 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
444 while(Adapter->PackInfo[iQIndex].FirstTxQueue) 410 while(Adapter->PackInfo[iQIndex].FirstTxQueue)
445 { 411 {
@@ -447,8 +413,7 @@ VOID flush_all_queues(PMINI_ADAPTER Adapter)
447 if(PacketToDrop) 413 if(PacketToDrop)
448 { 414 {
449 uiTotalPacketLength = PacketToDrop->len; 415 uiTotalPacketLength = PacketToDrop->len;
450 netstats->tx_dropped++; 416 txq->tx_dropped++;
451 atomic_inc(&Adapter->TxDroppedPacketCount);
452 } 417 }
453 else 418 else
454 uiTotalPacketLength = 0; 419 uiTotalPacketLength = 0;
@@ -457,7 +422,7 @@ VOID flush_all_queues(PMINI_ADAPTER Adapter)
457 Adapter->PackInfo[iQIndex].LastTxQueue); 422 Adapter->PackInfo[iQIndex].LastTxQueue);
458 423
459 /* Free the skb */ 424 /* Free the skb */
460 bcm_kfree_skb(PacketToDrop); 425 dev_kfree_skb(PacketToDrop);
461 426
462 /// update current bytes and packets count 427 /// update current bytes and packets count
463 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= uiTotalPacketLength; 428 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= uiTotalPacketLength;
@@ -559,12 +524,6 @@ USHORT ClassifyPacket(PMINI_ADAPTER Adapter,struct sk_buff* skb)
559 524
560 for(uiLoopIndex = MAX_CLASSIFIERS - 1; uiLoopIndex >= 0; uiLoopIndex--) 525 for(uiLoopIndex = MAX_CLASSIFIERS - 1; uiLoopIndex >= 0; uiLoopIndex--)
561 { 526 {
562 if (Adapter->device_removed)
563 {
564 bClassificationSucceed = FALSE;
565 break;
566 }
567
568 if(bClassificationSucceed) 527 if(bClassificationSucceed)
569 break; 528 break;
570 //Iterate through all classifiers which are already in order of priority 529 //Iterate through all classifiers which are already in order of priority
@@ -810,7 +769,10 @@ static BOOLEAN EthCSMatchVLANRules(S_CLASSIFIER_RULE *pstClassifierRule,struct s
810} 769}
811 770
812 771
813BOOLEAN EThCSClassifyPkt(PMINI_ADAPTER Adapter,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo,S_CLASSIFIER_RULE *pstClassifierRule, B_UINT8 EthCSCupport) 772static BOOLEAN EThCSClassifyPkt(PMINI_ADAPTER Adapter,struct sk_buff* skb,
773 PS_ETHCS_PKT_INFO pstEthCsPktInfo,
774 S_CLASSIFIER_RULE *pstClassifierRule,
775 B_UINT8 EthCSCupport)
814{ 776{
815 BOOLEAN bClassificationSucceed = FALSE; 777 BOOLEAN bClassificationSucceed = FALSE;
816 bClassificationSucceed = EthCSMatchSrcMACAddress(pstClassifierRule,((ETH_HEADER_STRUC *)(skb->data))->au8SourceAddress); 778 bClassificationSucceed = EthCSMatchSrcMACAddress(pstClassifierRule,((ETH_HEADER_STRUC *)(skb->data))->au8SourceAddress);
@@ -840,9 +802,11 @@ BOOLEAN EThCSClassifyPkt(PMINI_ADAPTER Adapter,struct sk_buff* skb,PS_ETHCS_PKT_
840 return bClassificationSucceed; 802 return bClassificationSucceed;
841} 803}
842 804
843void EThCSGetPktInfo(PMINI_ADAPTER Adapter,PVOID pvEthPayload,PS_ETHCS_PKT_INFO pstEthCsPktInfo) 805static void EThCSGetPktInfo(PMINI_ADAPTER Adapter,PVOID pvEthPayload,
806 PS_ETHCS_PKT_INFO pstEthCsPktInfo)
844{ 807{
845 USHORT u16Etype = ntohs(((ETH_HEADER_STRUC*)pvEthPayload)->u16Etype); 808 USHORT u16Etype = ntohs(((ETH_HEADER_STRUC*)pvEthPayload)->u16Etype);
809
846 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "EthCSGetPktInfo : Eth Hdr Type : %X\n",u16Etype); 810 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "EthCSGetPktInfo : Eth Hdr Type : %X\n",u16Etype);
847 if(u16Etype > 0x5dc) 811 if(u16Etype > 0x5dc)
848 { 812 {
diff --git a/drivers/staging/bcm/TODO b/drivers/staging/bcm/TODO
index 366634be5fe1..cd3e9f2ed87a 100644
--- a/drivers/staging/bcm/TODO
+++ b/drivers/staging/bcm/TODO
@@ -1,15 +1,22 @@
1This driver is barely functional in its current state.
2
3BIG:
4 - existing API is (/dev/tarang) should be replaced
5 Is it possible to use same API as Intel Wimax stack and
6 have same user level components.
7 - Qos and queue model is non-standard and inflexible.
8 Use existing TC Qos?
9
1TODO: 10TODO:
11 - support more than one board - eliminate global variables
12 - remove developer debug BCM_DEBUG() macros
13 add a limited number of messages through netif_msg()
2 - fix non-standard kernel style 14 - fix non-standard kernel style
3 - sparse warnings
4 - checkpatch warnings 15 - checkpatch warnings
5 - remove compatiablity code for older kernels 16 - use request firmware
6 - remove #ifdef's 17 - fix use of file I/O to load config with better API
7 - fix bogus device nameing and reference counting (see bcm_notify_event) 18 - merge some files together?
8 - fix use of file I/O to load config
9 - request firmware
10 - update to current network device API
11 - merge some files together
12 - cleanup/eliminate debug messages 19 - cleanup/eliminate debug messages
13 20
14 - integrate with existing Wimax stack? 21
15 22
diff --git a/drivers/staging/bcm/Transmit.c b/drivers/staging/bcm/Transmit.c
index 12f9e13457db..0f7000960d50 100644
--- a/drivers/staging/bcm/Transmit.c
+++ b/drivers/staging/bcm/Transmit.c
@@ -6,7 +6,7 @@
6digraph transmit1 { 6digraph transmit1 {
7node[shape=box] 7node[shape=box]
8edge[weight=5;color=red] 8edge[weight=5;color=red]
9bcm_transmit->reply_to_arp_request[label="ARP"] 9
10bcm_transmit->GetPacketQueueIndex[label="IP Packet"] 10bcm_transmit->GetPacketQueueIndex[label="IP Packet"]
11GetPacketQueueIndex->IpVersion4[label="IPV4"] 11GetPacketQueueIndex->IpVersion4[label="IPV4"]
12GetPacketQueueIndex->IpVersion6[label="IPV6"] 12GetPacketQueueIndex->IpVersion6[label="IPV6"]
@@ -35,169 +35,16 @@ SendPacketFromQueue->SetupNextSend->bcm_cmd53
35 35
36#include "headers.h" 36#include "headers.h"
37 37
38/*******************************************************************
39* Function - bcm_transmit()
40*
41* Description - This is the main transmit function for our virtual
42* interface(veth0). It handles the ARP packets. It
43* clones this packet and then Queue it to a suitable
44* Queue. Then calls the transmit_packet().
45*
46* Parameter - skb - Pointer to the socket buffer structure
47* dev - Pointer to the virtual net device structure
48*
49* Returns - zero (success) or -ve value (failure)
50*
51*********************************************************************/
52
53INT bcm_transmit(struct sk_buff *skb, /**< skb */
54 struct net_device *dev /**< net device pointer */
55 )
56{
57 PMINI_ADAPTER Adapter = NULL;
58 USHORT qindex=0;
59 struct timeval tv;
60 UINT pkt_type = 0;
61 UINT calltransmit = 0;
62
63 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_TX, TX_OSAL_DBG, DBG_LVL_ALL, "\n%s====>\n",__FUNCTION__);
64
65 memset(&tv, 0, sizeof(tv));
66 /* Check for valid parameters */
67 if(skb == NULL || dev==NULL)
68 {
69 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_TX,TX_OSAL_DBG, DBG_LVL_ALL, "Got NULL skb or dev\n");
70 return -EINVAL;
71 }
72
73 Adapter = GET_BCM_ADAPTER(dev);
74 if(!Adapter)
75 {
76 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_TX, TX_OSAL_DBG, DBG_LVL_ALL, "Got Invalid Adapter\n");
77 return -EINVAL;
78 }
79 if(Adapter->device_removed == TRUE || !Adapter->LinkUpStatus)
80 {
81 if(!netif_queue_stopped(dev)) {
82 netif_carrier_off(dev);
83 netif_stop_queue(dev);
84 }
85 return STATUS_FAILURE;
86 }
87 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_TX, TX_OSAL_DBG, DBG_LVL_ALL, "Packet size : %d\n", skb->len);
88
89 /*Add Ethernet CS check here*/
90 if(Adapter->TransferMode == IP_PACKET_ONLY_MODE )
91 {
92 pkt_type = ntohs(*(PUSHORT)(skb->data + 12));
93 /* Get the queue index where the packet is to be queued */
94 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_TX, TX_OSAL_DBG, DBG_LVL_ALL, "Getting the Queue Index.....");
95
96 qindex = GetPacketQueueIndex(Adapter,skb);
97
98 if((SHORT)INVALID_QUEUE_INDEX==(SHORT)qindex)
99 {
100 if(pkt_type == ETH_ARP_FRAME)
101 {
102 /*
103 Reply directly to ARP request packet
104 ARP Spoofing only if NO ETH CS rule matches for it
105 */
106 BCM_DEBUG_PRINT (Adapter,DBG_TYPE_TX, TX_OSAL_DBG, DBG_LVL_ALL,"ARP OPCODE = %02x",
107
108 (*(PUCHAR)(skb->data + 21)));
109
110 reply_to_arp_request(skb);
111
112 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_TX,TX_OSAL_DBG, DBG_LVL_ALL,"After reply_to_arp_request \n");
113
114 }
115 else
116 {
117 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_TX, TX_OSAL_DBG, DBG_LVL_ALL,
118 "Invalid queue index, dropping pkt\n");
119
120 bcm_kfree_skb(skb);
121 }
122 return STATUS_SUCCESS;
123 }
124
125 if(Adapter->PackInfo[qindex].uiCurrentPacketsOnHost >= SF_MAX_ALLOWED_PACKETS_TO_BACKUP)
126 {
127 atomic_inc(&Adapter->TxDroppedPacketCount);
128 bcm_kfree_skb(skb);
129 return STATUS_SUCCESS;
130 }
131
132 /* Now Enqueue the packet */
133 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "bcm_transmit Enqueueing the Packet To Queue %d",qindex);
134 spin_lock(&Adapter->PackInfo[qindex].SFQueueLock);
135 Adapter->PackInfo[qindex].uiCurrentBytesOnHost += skb->len;
136 Adapter->PackInfo[qindex].uiCurrentPacketsOnHost++;
137
138 *((B_UINT32 *)skb->cb + SKB_CB_LATENCY_OFFSET ) = jiffies;
139 ENQUEUEPACKET(Adapter->PackInfo[qindex].FirstTxQueue,
140 Adapter->PackInfo[qindex].LastTxQueue, skb);
141 atomic_inc(&Adapter->TotalPacketCount);
142 spin_unlock(&Adapter->PackInfo[qindex].SFQueueLock);
143 do_gettimeofday(&tv);
144
145 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_OSAL_DBG, DBG_LVL_ALL,"ENQ: \n");
146 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_OSAL_DBG, DBG_LVL_ALL, "Pkt Len = %d, sec: %ld, usec: %ld\n",
147 (skb->len-ETH_HLEN), tv.tv_sec, tv.tv_usec);
148
149#ifdef BCM_SHM_INTERFACE
150 spin_lock(&Adapter->txtransmitlock);
151 if(Adapter->txtransmit_running == 0)
152 {
153 Adapter->txtransmit_running = 1;
154 calltransmit = 1;
155 }
156 else
157 calltransmit = 0;
158
159 spin_unlock(&Adapter->txtransmitlock);
160#endif
161 if(calltransmit == 1)
162 transmit_packets(Adapter);
163 else
164 {
165 if(!atomic_read(&Adapter->TxPktAvail))
166 {
167 atomic_set(&Adapter->TxPktAvail, 1);
168#ifdef BCM_SHM_INTERFACE
169 virtual_mail_box_interrupt();
170#endif
171 wake_up(&Adapter->tx_packet_wait_queue);
172 }
173 }
174 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_OSAL_DBG, DBG_LVL_ALL, "<====");
175 }
176 else
177 bcm_kfree_skb(skb);
178
179 return STATUS_SUCCESS;
180}
181
182 38
183/** 39/**
184@ingroup ctrl_pkt_functions 40@ingroup ctrl_pkt_functions
185This function dispatches control packet to the h/w interface 41This function dispatches control packet to the h/w interface
186@return zero(success) or -ve value(failure) 42@return zero(success) or -ve value(failure)
187*/ 43*/
188INT SendControlPacket(PMINI_ADAPTER Adapter, /**<Logical Adapter*/ 44INT SendControlPacket(PMINI_ADAPTER Adapter, char *pControlPacket)
189 char *pControlPacket/**<Control Packet*/
190 )
191{ 45{
192 PLEADER PLeader = NULL; 46 PLEADER PLeader = (PLEADER)pControlPacket;
193 struct timeval tv;
194 memset(&tv, 0, sizeof(tv));
195
196
197
198 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "========>");
199 47
200 PLeader=(PLEADER)pControlPacket;
201 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Tx"); 48 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Tx");
202 if(!pControlPacket || !Adapter) 49 if(!pControlPacket || !Adapter)
203 { 50 {
@@ -208,12 +55,6 @@ INT SendControlPacket(PMINI_ADAPTER Adapter, /**<Logical Adapter*/
208 ((PLeader->PLength-1)/MAX_DEVICE_DESC_SIZE)+1)) 55 ((PLeader->PLength-1)/MAX_DEVICE_DESC_SIZE)+1))
209 { 56 {
210 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "NO FREE DESCRIPTORS TO SEND CONTROL PACKET"); 57 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "NO FREE DESCRIPTORS TO SEND CONTROL PACKET");
211 if(Adapter->bcm_jiffies == 0)
212 {
213 Adapter->bcm_jiffies = jiffies;
214 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "UPDATED TIME(hex): %lu",
215 Adapter->bcm_jiffies);
216 }
217 return STATUS_FAILURE; 58 return STATUS_FAILURE;
218 } 59 }
219 60
@@ -224,76 +65,33 @@ INT SendControlPacket(PMINI_ADAPTER Adapter, /**<Logical Adapter*/
224 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Leader Length: %x",PLeader->PLength); 65 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Leader Length: %x",PLeader->PLength);
225 if(Adapter->device_removed) 66 if(Adapter->device_removed)
226 return 0; 67 return 0;
227#ifndef BCM_SHM_INTERFACE
228 Adapter->interface_transmit(Adapter->pvInterfaceAdapter,
229 pControlPacket, (PLeader->PLength + LEADER_SIZE));
230#else
231 tx_pkts_to_firmware(pControlPacket,(PLeader->PLength + LEADER_SIZE),1);
232 68
233 if(PLeader->Status==IDLE_MESSAGE) 69 if (netif_msg_pktdata(Adapter))
234 { 70 print_hex_dump(KERN_DEBUG, PFX "tx control: ", DUMP_PREFIX_NONE,
235 if(((CONTROL_MESSAGE*)PLeader)->szData[0] == GO_TO_IDLE_MODE_PAYLOAD && 71 16, 1, pControlPacket, PLeader->PLength + LEADER_SIZE, 0);
236 ((CONTROL_MESSAGE*)PLeader)->szData[1] == TARGET_CAN_GO_TO_IDLE_MODE)
237 {
238 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Idle Mode Ack Sent to the Device\n");
239 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Host Entering into Idle Mode\n");
240 do_gettimeofday(&tv);
241 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "IdleMode Msg sent to f/w at time :%ld ms", tv.tv_sec *1000 + tv.tv_usec /1000);
242 if(Adapter->bDoSuspend != TRUE)
243 {
244 Adapter->IdleMode = TRUE;
245 Adapter->bPreparingForLowPowerMode = FALSE ;
246 }
247 }
248 }
249 if((PLeader->Status == LINK_UP_CONTROL_REQ) &&
250 ((PUCHAR)pControlPacket)[sizeof(LEADER)] == LINK_UP_ACK &&
251 ((PUCHAR)pControlPacket)[sizeof(LEADER)+1] ==
252 LINK_SHUTDOWN_REQ_FROM_FIRMWARE &&
253 ((PUCHAR)pControlPacket)[sizeof(LEADER)+2] == SHUTDOWN_ACK_FROM_DRIVER)
254 {
255 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Shut Down ACK Sent and Host entering Shut State \n");
256 if(Adapter->bDoSuspend != TRUE)
257 {
258 Adapter->bShutStatus = TRUE;
259 Adapter->bPreparingForLowPowerMode = FALSE;
260 Adapter->bTriedToWakeUpFromlowPowerMode = FALSE;
261 }
262 72
263 } 73 Adapter->interface_transmit(Adapter->pvInterfaceAdapter,
264#endif 74 pControlPacket, (PLeader->PLength + LEADER_SIZE));
265 75
266 ((PLINUX_DEP_DATA)Adapter->pvOsDepData)->netstats.tx_packets++;
267 ((PLINUX_DEP_DATA)Adapter->pvOsDepData)->netstats.tx_bytes+=
268 PLeader->PLength;
269 atomic_dec(&Adapter->CurrNumFreeTxDesc); 76 atomic_dec(&Adapter->CurrNumFreeTxDesc);
270 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<========="); 77 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<=========");
271 return STATUS_SUCCESS; 78 return STATUS_SUCCESS;
272} 79}
273static LEADER Leader={0}; 80
274/** 81/**
275@ingroup tx_functions 82@ingroup tx_functions
276This function despatches the IP packets with the given vcid 83This function despatches the IP packets with the given vcid
277to the target via the host h/w interface. 84to the target via the host h/w interface.
278@return zero(success) or -ve value(failure) 85@return zero(success) or -ve value(failure)
279*/ 86*/
280INT SetupNextSend(PMINI_ADAPTER Adapter, /**<Logical Adapter*/ 87INT SetupNextSend(PMINI_ADAPTER Adapter, struct sk_buff *Packet, USHORT Vcid)
281 struct sk_buff *Packet, /**<data buffer*/
282 USHORT Vcid) /**<VCID for this packet*/
283{ 88{
284 int status=0; 89 int status=0;
285#ifdef GDMA_INTERFACE
286 int dontfree = 0;
287#endif
288 BOOLEAN bHeaderSupressionEnabled = FALSE; 90 BOOLEAN bHeaderSupressionEnabled = FALSE;
289 B_UINT16 uiClassifierRuleID; 91 B_UINT16 uiClassifierRuleID;
290 int QueueIndex = NO_OF_QUEUES + 1; 92 u16 QueueIndex = skb_get_queue_mapping(Packet);
93 LEADER Leader={0};
291 94
292 if(!Adapter || !Packet)
293 {
294 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Got NULL Adapter or Packet");
295 return -EINVAL;
296 }
297 if(Packet->len > MAX_DEVICE_DESC_SIZE) 95 if(Packet->len > MAX_DEVICE_DESC_SIZE)
298 { 96 {
299 status = STATUS_FAILURE; 97 status = STATUS_FAILURE;
@@ -302,14 +100,10 @@ INT SetupNextSend(PMINI_ADAPTER Adapter, /**<Logical Adapter*/
302 100
303 /* Get the Classifier Rule ID */ 101 /* Get the Classifier Rule ID */
304 uiClassifierRuleID = *((UINT32*) (Packet->cb)+SKB_CB_CLASSIFICATION_OFFSET); 102 uiClassifierRuleID = *((UINT32*) (Packet->cb)+SKB_CB_CLASSIFICATION_OFFSET);
305 QueueIndex = SearchVcid( Adapter,Vcid); 103
306 if(QueueIndex < NO_OF_QUEUES) 104 bHeaderSupressionEnabled = Adapter->PackInfo[QueueIndex].bHeaderSuppressionEnabled
307 { 105 & Adapter->bPHSEnabled;
308 bHeaderSupressionEnabled = 106
309 Adapter->PackInfo[QueueIndex].bHeaderSuppressionEnabled;
310 bHeaderSupressionEnabled =
311 bHeaderSupressionEnabled & Adapter->bPHSEnabled;
312 }
313 if(Adapter->device_removed) 107 if(Adapter->device_removed)
314 { 108 {
315 status = STATUS_FAILURE; 109 status = STATUS_FAILURE;
@@ -327,15 +121,10 @@ INT SetupNextSend(PMINI_ADAPTER Adapter, /**<Logical Adapter*/
327 121
328 Leader.Vcid = Vcid; 122 Leader.Vcid = Vcid;
329 123
330 if(TCP_ACK == *((UINT32*) (Packet->cb) + SKB_CB_TCPACK_OFFSET )) 124 if(TCP_ACK == *((UINT32*) (Packet->cb) + SKB_CB_TCPACK_OFFSET ))
331 {
332 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Sending TCP ACK\n");
333 Leader.Status = LEADER_STATUS_TCP_ACK; 125 Leader.Status = LEADER_STATUS_TCP_ACK;
334 }
335 else 126 else
336 {
337 Leader.Status = LEADER_STATUS; 127 Leader.Status = LEADER_STATUS;
338 }
339 128
340 if(Adapter->PackInfo[QueueIndex].bEthCSSupport) 129 if(Adapter->PackInfo[QueueIndex].bEthCSSupport)
341 { 130 {
@@ -351,68 +140,53 @@ INT SetupNextSend(PMINI_ADAPTER Adapter, /**<Logical Adapter*/
351 skb_push(Packet, LEADER_SIZE); 140 skb_push(Packet, LEADER_SIZE);
352 memcpy(Packet->data, &Leader, LEADER_SIZE); 141 memcpy(Packet->data, &Leader, LEADER_SIZE);
353 } 142 }
354
355 else 143 else
356 { 144 {
357 Leader.PLength = Packet->len - ETH_HLEN; 145 Leader.PLength = Packet->len - ETH_HLEN;
358 memcpy((LEADER*)skb_pull(Packet, (ETH_HLEN - LEADER_SIZE)), &Leader, LEADER_SIZE); 146 memcpy((LEADER*)skb_pull(Packet, (ETH_HLEN - LEADER_SIZE)), &Leader, LEADER_SIZE);
359 } 147 }
360 148
361 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Packet->len = %d", Packet->len);
362 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Vcid = %d", Vcid);
363
364#ifndef BCM_SHM_INTERFACE
365 status = Adapter->interface_transmit(Adapter->pvInterfaceAdapter, 149 status = Adapter->interface_transmit(Adapter->pvInterfaceAdapter,
366 Packet->data, (Leader.PLength + LEADER_SIZE)); 150 Packet->data, (Leader.PLength + LEADER_SIZE));
367#else
368 status = tx_pkts_to_firmware(Packet,Packet->len,0);
369#endif
370 if(status) 151 if(status)
371 { 152 {
372 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Tx Failed..\n"); 153 ++Adapter->dev->stats.tx_errors;
154 if (netif_msg_tx_err(Adapter))
155 pr_info(PFX "%s: transmit error %d\n", Adapter->dev->name,
156 status);
373 } 157 }
374 else 158 else
375 { 159 {
160 struct netdev_queue *txq = netdev_get_tx_queue(Adapter->dev, QueueIndex);
376 Adapter->PackInfo[QueueIndex].uiTotalTxBytes += Leader.PLength; 161 Adapter->PackInfo[QueueIndex].uiTotalTxBytes += Leader.PLength;
377 atomic_add(Leader.PLength, &Adapter->GoodTxByteCount);
378 atomic_inc(&Adapter->TxTotalPacketCount);
379#ifdef GDMA_INTERFACE
380 dontfree = 1;
381#endif
382 }
383 162
384 atomic_dec(&Adapter->CurrNumFreeTxDesc); 163 txq->tx_bytes += Leader.PLength;
385 164 ++txq->tx_packets;
386errExit:
387 165
388 if(STATUS_SUCCESS == status)
389 {
390 Adapter->PackInfo[QueueIndex].uiCurrentTokenCount -= Leader.PLength << 3; 166 Adapter->PackInfo[QueueIndex].uiCurrentTokenCount -= Leader.PLength << 3;
391 Adapter->PackInfo[QueueIndex].uiSentBytes += (Packet->len); 167 Adapter->PackInfo[QueueIndex].uiSentBytes += (Packet->len);
392 Adapter->PackInfo[QueueIndex].uiSentPackets++; 168 Adapter->PackInfo[QueueIndex].uiSentPackets++;
393 Adapter->PackInfo[QueueIndex].NumOfPacketsSent++; 169 Adapter->PackInfo[QueueIndex].NumOfPacketsSent++;
394 170
395 atomic_dec(&Adapter->PackInfo[QueueIndex].uiPerSFTxResourceCount); 171 atomic_dec(&Adapter->PackInfo[QueueIndex].uiPerSFTxResourceCount);
396#ifdef BCM_SHM_INTERFACE
397 if(atomic_read(&Adapter->PackInfo[QueueIndex].uiPerSFTxResourceCount) < 0)
398 {
399 atomic_set(&Adapter->PackInfo[QueueIndex].uiPerSFTxResourceCount, 0);
400 }
401#endif
402 Adapter->PackInfo[QueueIndex].uiThisPeriodSentBytes += Leader.PLength; 172 Adapter->PackInfo[QueueIndex].uiThisPeriodSentBytes += Leader.PLength;
403 } 173 }
404 174
175 atomic_dec(&Adapter->CurrNumFreeTxDesc);
405 176
406#ifdef GDMA_INTERFACE 177errExit:
407 if(!dontfree){ 178
408 bcm_kfree_skb(Packet); 179 dev_kfree_skb(Packet);
409 }
410#else
411 bcm_kfree_skb(Packet);
412#endif
413 return status; 180 return status;
414} 181}
415 182
183static int tx_pending(PMINI_ADAPTER Adapter)
184{
185 return (atomic_read(&Adapter->TxPktAvail)
186 && MINIMUM_PENDING_DESCRIPTORS < atomic_read(&Adapter->CurrNumFreeTxDesc))
187 || Adapter->device_removed || (1 == Adapter->downloadDDR);
188}
189
416/** 190/**
417@ingroup tx_functions 191@ingroup tx_functions
418Transmit thread 192Transmit thread
@@ -420,57 +194,26 @@ Transmit thread
420int tx_pkt_handler(PMINI_ADAPTER Adapter /**< pointer to adapter object*/ 194int tx_pkt_handler(PMINI_ADAPTER Adapter /**< pointer to adapter object*/
421 ) 195 )
422{ 196{
423#ifndef BCM_SHM_INTERFACE
424 int status = 0; 197 int status = 0;
425#endif
426
427 UINT calltransmit = 1;
428 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "Entring to wait for signal from the interrupt service thread!Adapter = %p",Adapter);
429
430 198
431 while(1) 199 while(! kthread_should_stop()) {
432 { 200 /* FIXME - the timeout looks like workaround for racey usage of TxPktAvail */
433 if(Adapter->LinkUpStatus){ 201 if(Adapter->LinkUpStatus)
434 wait_event_timeout(Adapter->tx_packet_wait_queue, 202 wait_event_timeout(Adapter->tx_packet_wait_queue,
435 ((atomic_read(&Adapter->TxPktAvail) && 203 tx_pending(Adapter), msecs_to_jiffies(10));
436 (MINIMUM_PENDING_DESCRIPTORS < 204 else
437 atomic_read(&Adapter->CurrNumFreeTxDesc)) && 205 wait_event_interruptible(Adapter->tx_packet_wait_queue,
438 (Adapter->device_removed == FALSE))) || 206 tx_pending(Adapter));
439 (1 == Adapter->downloadDDR) || kthread_should_stop()
440#ifndef BCM_SHM_INTERFACE
441 || (TRUE == Adapter->bEndPointHalted)
442#endif
443 , msecs_to_jiffies(10));
444 }
445 else{
446 wait_event(Adapter->tx_packet_wait_queue,
447 ((atomic_read(&Adapter->TxPktAvail) &&
448 (MINIMUM_PENDING_DESCRIPTORS <
449 atomic_read(&Adapter->CurrNumFreeTxDesc)) &&
450 (Adapter->device_removed == FALSE))) ||
451 (1 == Adapter->downloadDDR) || kthread_should_stop()
452#ifndef BCM_SHM_INTERFACE
453 || (TRUE == Adapter->bEndPointHalted)
454#endif
455 );
456 }
457
458 if(kthread_should_stop() || Adapter->device_removed)
459 {
460 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "Exiting the tx thread..\n");
461 Adapter->transmit_packet_thread = NULL;
462 return 0;
463 }
464 207
465#ifndef BCM_SHM_INTERFACE 208 if (Adapter->device_removed)
209 break;
466 210
467 if(Adapter->downloadDDR == 1) 211 if(Adapter->downloadDDR == 1)
468 { 212 {
469 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "Downloading DDR Settings\n");
470 Adapter->downloadDDR +=1; 213 Adapter->downloadDDR +=1;
471 status = download_ddr_settings(Adapter); 214 status = download_ddr_settings(Adapter);
472 if(status) 215 if(status)
473 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "DDR DOWNLOAD FAILED!\n"); 216 pr_err(PFX "DDR DOWNLOAD FAILED! %d\n", status);
474 continue; 217 continue;
475 } 218 }
476 219
@@ -489,7 +232,6 @@ int tx_pkt_handler(PMINI_ADAPTER Adapter /**< pointer to adapter object*/
489 update_per_sf_desc_cnts(Adapter); 232 update_per_sf_desc_cnts(Adapter);
490 } 233 }
491 } 234 }
492#endif
493 235
494 if( atomic_read(&Adapter->CurrNumFreeTxDesc) && 236 if( atomic_read(&Adapter->CurrNumFreeTxDesc) &&
495 Adapter->LinkStatus == SYNC_UP_REQUEST && 237 Adapter->LinkStatus == SYNC_UP_REQUEST &&
@@ -507,49 +249,12 @@ int tx_pkt_handler(PMINI_ADAPTER Adapter /**< pointer to adapter object*/
507 wake_up(&Adapter->process_rx_cntrlpkt); 249 wake_up(&Adapter->process_rx_cntrlpkt);
508 } 250 }
509 251
510#ifdef BCM_SHM_INTERFACE 252 transmit_packets(Adapter);
511 spin_lock_bh(&Adapter->txtransmitlock);
512 if(Adapter->txtransmit_running == 0)
513 {
514 Adapter->txtransmit_running = 1;
515 calltransmit = 1;
516 }
517 else
518 calltransmit = 0;
519 spin_unlock_bh(&Adapter->txtransmitlock);
520#endif
521
522 if(calltransmit)
523 transmit_packets(Adapter);
524 253
525 atomic_set(&Adapter->TxPktAvail, 0); 254 atomic_set(&Adapter->TxPktAvail, 0);
526 } 255 }
527 return 0;
528}
529
530#ifdef BCM_SHM_INTERFACE
531extern PMINI_ADAPTER psAdaptertest;
532void virtual_mail_box_interrupt(void)
533{
534
535#ifndef GDMA_INTERFACE
536 PUINT ptr = (PUINT)CPE_VIRTUAL_MAILBOX_REG;
537 UINT intval = (UINT)((*ptr & 0xFF00) >> 8);
538 if (intval != 0)
539 {
540 atomic_set(&psAdaptertest->CurrNumFreeTxDesc, intval);
541 atomic_set (&psAdaptertest->uiMBupdate, TRUE);
542 256
543 //make it to 0 257 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL, "Exiting the tx thread..\n");
544 *ptr = *ptr & 0xffff00ff; 258 Adapter->transmit_packet_thread = NULL;
545 } 259 return 0;
546#endif
547}
548unsigned int total_tx_pkts_pending(void)
549{
550 return atomic_read(&psAdaptertest->TotalPacketCount);
551} 260}
552
553#endif
554
555
diff --git a/drivers/staging/bcm/cntrl_SignalingInterface.h b/drivers/staging/bcm/cntrl_SignalingInterface.h
index 4cbe30022248..890778450a86 100644
--- a/drivers/staging/bcm/cntrl_SignalingInterface.h
+++ b/drivers/staging/bcm/cntrl_SignalingInterface.h
@@ -2,19 +2,6 @@
2#define CNTRL_SIGNALING_INTERFACE_ 2#define CNTRL_SIGNALING_INTERFACE_
3 3
4 4
5#ifdef BECEEM_TARGET
6
7#include <mac_common.h>
8#include <msg_Dsa.h>
9#include <msg_Dsc.h>
10#include <msg_Dsd.h>
11#include <sch_definitions.h>
12using namespace Beceem;
13#ifdef ENABLE_CORRIGENDUM2_UPDATE
14extern B_UINT32 g_u32Corr2MacFlags;
15#endif
16
17#else
18 5
19 6
20#define DSA_REQ 11 7#define DSA_REQ 11
@@ -28,7 +15,6 @@ extern B_UINT32 g_u32Corr2MacFlags;
28#define DSD_ACK 19 15#define DSD_ACK 19
29#define MAX_CLASSIFIERS_IN_SF 4 16#define MAX_CLASSIFIERS_IN_SF 4
30 17
31#endif
32 18
33#define MAX_STRING_LEN 20 19#define MAX_STRING_LEN 20
34#define MAX_PHS_LENGTHS 255 20#define MAX_PHS_LENGTHS 255
@@ -57,37 +43,7 @@ extern B_UINT32 g_u32Corr2MacFlags;
57////////////////////////structure Definitions/////////////////////////////////// 43////////////////////////structure Definitions///////////////////////////////////
58//////////////////////////////////////////////////////////////////////////////// 44////////////////////////////////////////////////////////////////////////////////
59/// \brief class cCPacketClassificationRule 45/// \brief class cCPacketClassificationRule
60#ifdef BECEEM_TARGET
61class CCPacketClassificationRuleSI{
62 public:
63 /// \brief Constructor for the class
64 CCPacketClassificationRuleSI():
65 u8ClassifierRulePriority(mClassifierRulePriority),
66 u8IPTypeOfServiceLength(mIPTypeOfService),
67 u8Protocol(mProtocol),
68 u8IPMaskedSourceAddressLength(0),
69 u8IPDestinationAddressLength(0),
70 u8ProtocolSourcePortRangeLength(0),
71 u8ProtocolDestPortRangeLength(0),
72 u8EthernetDestMacAddressLength(0),
73 u8EthernetSourceMACAddressLength(0),
74 u8EthertypeLength(0),
75 u16UserPriority(mUserPriority),
76 u16VLANID(mVLANID),
77 u8AssociatedPHSI(mAssociatedPHSI),
78 u16PacketClassificationRuleIndex(mPacketClassifierRuleIndex),
79 u8VendorSpecificClassifierParamLength(mVendorSpecificClassifierParamLength),
80 u8IPv6FlowLableLength(mIPv6FlowLableLength),
81 u8ClassifierActionRule(mClassifierActionRule)
82
83 {}
84 void Reset()
85 {
86 CCPacketClassificationRuleSI();
87 }
88#else
89struct _stCPacketClassificationRuleSI{ 46struct _stCPacketClassificationRuleSI{
90#endif
91 47
92 /** 16bit UserPriority Of The Service Flow*/ 48 /** 16bit UserPriority Of The Service Flow*/
93 B_UINT16 u16UserPriority; 49 B_UINT16 u16UserPriority;
@@ -145,29 +101,10 @@ struct _stCPacketClassificationRuleSI{
145 B_UINT8 u8ClassifierActionRule; 101 B_UINT8 u8ClassifierActionRule;
146 B_UINT16 u16ValidityBitMap; 102 B_UINT16 u16ValidityBitMap;
147}; 103};
148#ifndef BECEEM_TARGET
149typedef struct _stCPacketClassificationRuleSI CCPacketClassificationRuleSI,stCPacketClassificationRuleSI, *pstCPacketClassificationRuleSI; 104typedef struct _stCPacketClassificationRuleSI CCPacketClassificationRuleSI,stCPacketClassificationRuleSI, *pstCPacketClassificationRuleSI;
150#endif
151 105
152/// \brief class CPhsRuleSI 106/// \brief class CPhsRuleSI
153#ifdef BECEEM_TARGET
154class CPhsRuleSI{
155 public:
156 /// \brief Constructor for the class
157 CPhsRuleSI():
158 u8PHSI(mPHSI),
159 u8PHSFLength(0),
160 u8PHSMLength(0),
161 u8PHSS(mPHSS),
162 u8PHSV(mPHSV),
163 u8VendorSpecificPHSParamsLength(mVendorSpecificPHSParamLength){}
164 void Reset()
165 {
166 CPhsRuleSI();
167 }
168#else
169typedef struct _stPhsRuleSI { 107typedef struct _stPhsRuleSI {
170#endif
171 /** 8bit PHS Index Of The Service Flow*/ 108 /** 8bit PHS Index Of The Service Flow*/
172 B_UINT8 u8PHSI; 109 B_UINT8 u8PHSI;
173 /** PHSF Length Of The Service Flow*/ 110 /** PHSF Length Of The Service Flow*/
@@ -188,31 +125,11 @@ typedef struct _stPhsRuleSI {
188 B_UINT8 u8VendorSpecificPHSParams[VENDOR_PHS_PARAM_LENGTH]; 125 B_UINT8 u8VendorSpecificPHSParams[VENDOR_PHS_PARAM_LENGTH];
189 126
190 B_UINT8 u8Padding[2]; 127 B_UINT8 u8Padding[2];
191#ifdef BECEEM_TARGET
192};
193#else
194}stPhsRuleSI,*pstPhsRuleSI; 128}stPhsRuleSI,*pstPhsRuleSI;
195typedef stPhsRuleSI CPhsRuleSI; 129typedef stPhsRuleSI CPhsRuleSI;
196#endif
197 130
198/// \brief structure cConvergenceSLTypes 131/// \brief structure cConvergenceSLTypes
199#ifdef BECEEM_TARGET
200class CConvergenceSLTypes{
201 public:
202 /// \brief Constructor for the class
203 CConvergenceSLTypes():
204 u8ClassfierDSCAction(mClassifierDSCAction),
205 u8PhsDSCAction (mPhsDSCAction)
206 {}
207 void Reset()
208 {
209 CConvergenceSLTypes();
210 cCPacketClassificationRule.Reset();
211 cPhsRule.Reset();
212 }
213#else
214struct _stConvergenceSLTypes{ 132struct _stConvergenceSLTypes{
215#endif
216 /** 8bit Phs Classfier Action Of The Service Flow*/ 133 /** 8bit Phs Classfier Action Of The Service Flow*/
217 B_UINT8 u8ClassfierDSCAction; 134 B_UINT8 u8ClassfierDSCAction;
218 /** 8bit Phs DSC Action Of The Service Flow*/ 135 /** 8bit Phs DSC Action Of The Service Flow*/
@@ -220,111 +137,15 @@ struct _stConvergenceSLTypes{
220 /** 16bit Padding */ 137 /** 16bit Padding */
221 B_UINT8 u8Padding[2]; 138 B_UINT8 u8Padding[2];
222 /// \brief class cCPacketClassificationRule 139 /// \brief class cCPacketClassificationRule
223#ifdef BECEEM_TARGET
224 CCPacketClassificationRuleSI cCPacketClassificationRule;
225#else
226 stCPacketClassificationRuleSI cCPacketClassificationRule; 140 stCPacketClassificationRuleSI cCPacketClassificationRule;
227#endif
228 /// \brief class CPhsRuleSI 141 /// \brief class CPhsRuleSI
229#ifdef BECEEM_TARGET
230 CPhsRuleSI cPhsRule;
231#else
232 struct _stPhsRuleSI cPhsRule; 142 struct _stPhsRuleSI cPhsRule;
233#endif
234}; 143};
235#ifndef BECEEM_TARGET
236typedef struct _stConvergenceSLTypes stConvergenceSLTypes,CConvergenceSLTypes, *pstConvergenceSLTypes; 144typedef struct _stConvergenceSLTypes stConvergenceSLTypes,CConvergenceSLTypes, *pstConvergenceSLTypes;
237#endif
238 145
239 146
240/// \brief structure CServiceFlowParamSI 147/// \brief structure CServiceFlowParamSI
241#ifdef BECEEM_TARGET
242class CServiceFlowParamSI{
243 public:
244 /// \brief Constructor for the class
245 CServiceFlowParamSI():
246 u32SFID(mSFid),
247 u16CID(mCid),
248 u8ServiceClassNameLength(mServiceClassNameLength),
249 u8MBSService(mMBSService),
250 u8QosParamSet(mQosParamSetType),
251 u8TrafficPriority(mTrafficPriority),
252 u32MaxSustainedTrafficRate(mMaximumSustainedTrafficRate),
253 u32MaxTrafficBurst(mMaximumTrafficBurst),
254 u32MinReservedTrafficRate(mMinimumReservedTrafficRate),
255 u8ServiceFlowSchedulingType(mServiceFlowSchedulingType),
256 u8RequesttransmissionPolicy(mRequestTransmissionPolicy),
257 u32ToleratedJitter(mToleratedJitter),
258 u32MaximumLatency(mMaximumLatency),
259 u8FixedLengthVSVariableLengthSDUIndicator
260 (mFixedLengthVSVariableLength),
261 u8SDUSize(mSDUSize),
262 u16TargetSAID(mTargetSAID),
263 u8ARQEnable(mARQEnable),
264 u16ARQWindowSize(mARQWindowSize),
265 u16ARQBlockLifeTime(mARQBlockLifeTime),
266 u16ARQSyncLossTimeOut(mARQSyncLossTimeOut),
267 u8ARQDeliverInOrder(mARQDeliverInOrder),
268 u16ARQRxPurgeTimeOut(mARQRXPurgeTimeOut),
269 //Add ARQ BLOCK SIZE, ARQ TX and RX delay initializations here
270 //after we move to only CORR2
271 u8RxARQAckProcessingTime(mRxARQAckProcessingTime),
272 u8CSSpecification(mCSSpecification),
273 u8TypeOfDataDeliveryService(mTypeOfDataDeliveryService),
274 u16SDUInterArrivalTime(mSDUInterArrivalTime),
275 u16TimeBase(mTimeBase),
276 u8PagingPreference(mPagingPreference),
277 u8MBSZoneIdentifierassignment(mMBSZoneIdentifierassignmentLength),
278 u8TrafficIndicationPreference(mTrafficIndicationPreference),
279 u8GlobalServicesClassNameLength(mGlobalServicesClassNameLength),
280 u8SNFeedbackEnabled(mSNFeedbackEnabled),
281 u8FSNSize(mFSNSize),
282 u8CIDAllocation4activeBSsLength(mCIDAllocation4activeBSsLength),
283 u16UnsolicitedGrantInterval(mUnsolicitedGrantInterval),
284 u16UnsolicitedPollingInterval(mUnsolicitedPollingInterval),
285 u8PDUSNExtendedSubheader4HarqReordering(mPDUSNExtendedSubheader4HarqReordering),
286 u8MBSContentsIDLength(mMBSContentsIDLength),
287 u8HARQServiceFlows(mHARQServiceFlows),
288 u8AuthTokenLength(mAuthTokenLength),
289 u8HarqChannelMappingLength(mHarqChannelMappingLength),
290 u8VendorSpecificQoSParamLength(mVendorSpecificQoSParamLength),
291 bValid(FALSE),
292 u8TotalClassifiers()
293{
294//Remove the bolck after we move to Corr2 only code
295#ifdef ENABLE_CORRIGENDUM2_UPDATE
296 if((g_u32Corr2MacFlags & CORR_2_DSX) || (g_u32Corr2MacFlags & CORR_2_ARQ))
297 {
298 /* IEEE Comment #627 / MTG Comment #426 */
299 u16ARQBlockSize = mARQBlockSize;
300 if(g_u32Corr2MacFlags & CORR_2_ARQ) {
301 u16ARQRetryTxTimeOut = mARQRetryTimeOutTxDelay;
302 if(g_u32VENDOR_TYPE == VENDOR_ALCATEL) {
303 u16ARQRetryRxTimeOut = mARQRetryTimeOutRxDelay_ALU;
304 } else {
305 u16ARQRetryRxTimeOut = mARQRetryTimeOutRxDelay;
306 }
307 }
308 else
309 {
310 u16ARQRetryTxTimeOut = mARQRetryTimeOutTxDelayCorr1;
311 u16ARQRetryRxTimeOut = mARQRetryTimeOutRxDelayCorr1;
312 }
313 }
314 else
315#endif
316 {
317 u16ARQBlockSize = mARQBlockSizeCorr1;
318 u16ARQRetryTxTimeOut = mARQRetryTimeOutTxDelayCorr1;
319 u16ARQRetryRxTimeOut = mARQRetryTimeOutRxDelayCorr1;
320 }
321}
322
323 void ComputeMacOverhead(B_UINT8 u8SecOvrhead);
324 B_UINT16 GetMacOverhead() { return u16MacOverhead; }
325#else
326typedef struct _stServiceFlowParamSI{ 148typedef struct _stServiceFlowParamSI{
327#endif //end of ifdef BECEEM_TARGET
328 149
329 /** 32bitSFID Of The Service Flow*/ 150 /** 32bitSFID Of The Service Flow*/
330 B_UINT32 u32SFID; 151 B_UINT32 u32SFID;
@@ -367,11 +188,6 @@ typedef struct _stServiceFlowParamSI{
367 188
368 /** 16bit ARQ Purge timeout */ 189 /** 16bit ARQ Purge timeout */
369 B_UINT16 u16ARQRxPurgeTimeOut; 190 B_UINT16 u16ARQRxPurgeTimeOut;
370#if 0 //def ENABLE_CORRIGENDUM2_UPDATE
371/* IEEE Comment #627 / MTG Comment #426 */
372 /// \brief Size of an ARQ block, changed from 2 bytes to 1
373 B_UINT8 u8ARQBlockSize;
374#endif
375//TODO::Remove this once we move to a new CORR2 driver 191//TODO::Remove this once we move to a new CORR2 driver
376 /// \brief Size of an ARQ block 192 /// \brief Size of an ARQ block
377 B_UINT16 u16ARQBlockSize; 193 B_UINT16 u16ARQBlockSize;
@@ -496,35 +312,18 @@ typedef struct _stServiceFlowParamSI{
496 B_UINT8 bValid; /**< Validity flag */ 312 B_UINT8 bValid; /**< Validity flag */
497 B_UINT8 u8Padding; /**< Padding byte*/ 313 B_UINT8 u8Padding; /**< Padding byte*/
498 314
499#ifdef BECEEM_TARGET
500/**
501Structure for Convergence SubLayer Types with a maximum of 4 classifiers
502*/
503 CConvergenceSLTypes cConvergenceSLTypes[MAX_CLASSIFIERS_IN_SF];
504#else
505/** 315/**
506Structure for Convergence SubLayer Types with a maximum of 4 classifiers 316Structure for Convergence SubLayer Types with a maximum of 4 classifiers
507*/ 317*/
508 stConvergenceSLTypes cConvergenceSLTypes[MAX_CLASSIFIERS_IN_SF]; 318 stConvergenceSLTypes cConvergenceSLTypes[MAX_CLASSIFIERS_IN_SF];
509#endif
510 319
511#ifdef BECEEM_TARGET
512};
513#else
514} stServiceFlowParamSI, *pstServiceFlowParamSI; 320} stServiceFlowParamSI, *pstServiceFlowParamSI;
515typedef stServiceFlowParamSI CServiceFlowParamSI; 321typedef stServiceFlowParamSI CServiceFlowParamSI;
516#endif
517 322
518/** 323/**
519structure stLocalSFAddRequest 324structure stLocalSFAddRequest
520*/ 325*/
521typedef struct _stLocalSFAddRequest{ 326typedef struct _stLocalSFAddRequest{
522#ifdef BECEEM_TARGET
523 _stLocalSFAddRequest( ) :
524 u8Type(0x00), eConnectionDir(0x00),
525 u16TID(0x0000), u16CID(0x0000), u16VCID(0x0000)
526 {}
527#endif
528 327
529 B_UINT8 u8Type; /**< Type*/ 328 B_UINT8 u8Type; /**< Type*/
530 B_UINT8 eConnectionDir; /**< Connection direction*/ 329 B_UINT8 eConnectionDir; /**< Connection direction*/
@@ -535,19 +334,9 @@ typedef struct _stLocalSFAddRequest{
535 /// \brief 16bitVCID 334 /// \brief 16bitVCID
536 B_UINT16 u16VCID; /**< 16bit VCID*/ 335 B_UINT16 u16VCID; /**< 16bit VCID*/
537 /// \brief structure ParameterSet 336 /// \brief structure ParameterSet
538#ifdef BECEEM_SIGNALLING_INTERFACE_API
539 CServiceFlowParamSI sfParameterSet;
540#endif
541 337
542#ifdef BECEEM_TARGET
543 CServiceFlowParamSI *psfParameterSet;
544#else
545 stServiceFlowParamSI *psfParameterSet; /**< structure ParameterSet*/ 338 stServiceFlowParamSI *psfParameterSet; /**< structure ParameterSet*/
546#endif
547 339
548#ifdef USING_VXWORKS
549 USE_DATA_MEMORY_MANAGER();
550#endif
551}stLocalSFAddRequest, *pstLocalSFAddRequest; 340}stLocalSFAddRequest, *pstLocalSFAddRequest;
552 341
553 342
@@ -555,12 +344,6 @@ typedef struct _stLocalSFAddRequest{
555structure stLocalSFAddIndication 344structure stLocalSFAddIndication
556*/ 345*/
557typedef struct _stLocalSFAddIndication{ 346typedef struct _stLocalSFAddIndication{
558#ifdef BECEEM_TARGET
559 _stLocalSFAddIndication( ) :
560 u8Type(0x00), eConnectionDir(0x00),
561 u16TID(0x0000), u16CID(0x0000), u16VCID(0x0000)
562 {}
563#endif
564 347
565 B_UINT8 u8Type; /**< Type*/ 348 B_UINT8 u8Type; /**< Type*/
566 B_UINT8 eConnectionDir; /**< Connection Direction*/ 349 B_UINT8 eConnectionDir; /**< Connection Direction*/
@@ -571,37 +354,19 @@ typedef struct _stLocalSFAddIndication{
571 /// \brief 16bitVCID 354 /// \brief 16bitVCID
572 B_UINT16 u16VCID; /**< 16bitVCID*/ 355 B_UINT16 u16VCID; /**< 16bitVCID*/
573 356
574#ifdef BECEEM_SIGNALLING_INTERFACE_API
575 CServiceFlowParamSI sfAuthorizedSet;
576 /// \brief structure AdmittedSet
577 CServiceFlowParamSI sfAdmittedSet;
578 /// \brief structure ActiveSet
579 CServiceFlowParamSI sfActiveSet;
580#endif
581 357
582 /// \brief structure AuthorizedSet 358 /// \brief structure AuthorizedSet
583#ifdef BECEEM_TARGET
584 CServiceFlowParamSI *psfAuthorizedSet;
585 /// \brief structure AdmittedSet
586 CServiceFlowParamSI *psfAdmittedSet;
587 /// \brief structure ActiveSet
588 CServiceFlowParamSI *psfActiveSet;
589#else
590 /// \brief structure AuthorizedSet 359 /// \brief structure AuthorizedSet
591 stServiceFlowParamSI *psfAuthorizedSet; /**< AuthorizedSet of type stServiceFlowParamSI*/ 360 stServiceFlowParamSI *psfAuthorizedSet; /**< AuthorizedSet of type stServiceFlowParamSI*/
592 /// \brief structure AdmittedSet 361 /// \brief structure AdmittedSet
593 stServiceFlowParamSI *psfAdmittedSet; /**< AdmittedSet of type stServiceFlowParamSI*/ 362 stServiceFlowParamSI *psfAdmittedSet; /**< AdmittedSet of type stServiceFlowParamSI*/
594 /// \brief structure ActiveSet 363 /// \brief structure ActiveSet
595 stServiceFlowParamSI *psfActiveSet; /**< sfActiveSet of type stServiceFlowParamSI*/ 364 stServiceFlowParamSI *psfActiveSet; /**< sfActiveSet of type stServiceFlowParamSI*/
596#endif
597 B_UINT8 u8CC; /**< Confirmation Code*/ 365 B_UINT8 u8CC; /**< Confirmation Code*/
598 B_UINT8 u8Padd; /**< 8-bit Padding */ 366 B_UINT8 u8Padd; /**< 8-bit Padding */
599 367
600 B_UINT16 u16Padd; /**< 16 bit Padding */ 368 B_UINT16 u16Padd; /**< 16 bit Padding */
601 369
602#ifdef USING_VXWORKS
603 USE_DATA_MEMORY_MANAGER();
604#endif
605}stLocalSFAddIndication; 370}stLocalSFAddIndication;
606 371
607 372
@@ -619,33 +384,17 @@ typedef struct _stLocalSFAddIndication stLocalSFChangeIndication, *pstLocalSFCha
619structure stLocalSFDeleteRequest 384structure stLocalSFDeleteRequest
620*/ 385*/
621typedef struct _stLocalSFDeleteRequest{ 386typedef struct _stLocalSFDeleteRequest{
622#ifdef BECEEM_TARGET
623 _stLocalSFDeleteRequest( ) :
624 u8Type(0x00), u8Padding(0x00),
625 u16TID(0x0000), u32SFID (0x00000000)
626 {}
627#endif
628 B_UINT8 u8Type; /**< Type*/ 387 B_UINT8 u8Type; /**< Type*/
629 B_UINT8 u8Padding; /**< Padding byte*/ 388 B_UINT8 u8Padding; /**< Padding byte*/
630 B_UINT16 u16TID; /**< TID*/ 389 B_UINT16 u16TID; /**< TID*/
631 /// \brief 32bitSFID 390 /// \brief 32bitSFID
632 B_UINT32 u32SFID; /**< SFID*/ 391 B_UINT32 u32SFID; /**< SFID*/
633#ifdef USING_VXWORKS
634 USE_DATA_MEMORY_MANAGER();
635#endif
636}stLocalSFDeleteRequest, *pstLocalSFDeleteRequest; 392}stLocalSFDeleteRequest, *pstLocalSFDeleteRequest;
637 393
638/** 394/**
639structure stLocalSFDeleteIndication 395structure stLocalSFDeleteIndication
640*/ 396*/
641typedef struct stLocalSFDeleteIndication{ 397typedef struct stLocalSFDeleteIndication{
642#ifdef BECEEM_TARGET
643 stLocalSFDeleteIndication( ) :
644 u8Type(0x00), u8Padding(0x00),
645 u16TID(0x0000), u16CID(0x0000),
646 u16VCID(0x0000),u32SFID (0x00000000)
647 {}
648#endif
649 B_UINT8 u8Type; /**< Type */ 398 B_UINT8 u8Type; /**< Type */
650 B_UINT8 u8Padding; /**< Padding */ 399 B_UINT8 u8Padding; /**< Padding */
651 B_UINT16 u16TID; /**< TID */ 400 B_UINT16 u16TID; /**< TID */
@@ -658,9 +407,6 @@ typedef struct stLocalSFDeleteIndication{
658 /// \brief 8bit Confirmation code 407 /// \brief 8bit Confirmation code
659 B_UINT8 u8ConfirmationCode; /**< Confirmation code */ 408 B_UINT8 u8ConfirmationCode; /**< Confirmation code */
660 B_UINT8 u8Padding1[3]; /**< 3 byte Padding */ 409 B_UINT8 u8Padding1[3]; /**< 3 byte Padding */
661#ifdef USING_VXWORKS
662 USE_DATA_MEMORY_MANAGER();
663#endif
664}stLocalSFDeleteIndication; 410}stLocalSFDeleteIndication;
665 411
666typedef struct _stIM_SFHostNotify 412typedef struct _stIM_SFHostNotify
diff --git a/drivers/staging/bcm/headers.h b/drivers/staging/bcm/headers.h
index 9d4e3aca1b34..1148e5e22eb9 100644
--- a/drivers/staging/bcm/headers.h
+++ b/drivers/staging/bcm/headers.h
@@ -22,7 +22,6 @@
22#include <linux/etherdevice.h> 22#include <linux/etherdevice.h>
23#include <net/ip.h> 23#include <net/ip.h>
24#include <linux/wait.h> 24#include <linux/wait.h>
25#include <linux/notifier.h>
26#include <linux/proc_fs.h> 25#include <linux/proc_fs.h>
27#include <linux/interrupt.h> 26#include <linux/interrupt.h>
28 27
@@ -36,26 +35,10 @@
36#include <linux/mm.h> 35#include <linux/mm.h>
37#include <linux/pagemap.h> 36#include <linux/pagemap.h>
38#include <asm/uaccess.h> 37#include <asm/uaccess.h>
39#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
40#include <linux/kthread.h> 38#include <linux/kthread.h>
41#endif
42#include <linux/tcp.h> 39#include <linux/tcp.h>
43#include <linux/udp.h> 40#include <linux/udp.h>
44#ifndef BCM_SHM_INTERFACE
45#include <linux/usb.h> 41#include <linux/usb.h>
46#endif
47#ifdef BECEEM_TARGET
48
49#include <mac_common.h>
50#include <msg_Dsa.h>
51#include <msg_Dsc.h>
52#include <msg_Dsd.h>
53#include <sch_definitions.h>
54using namespace Beceem;
55#ifdef ENABLE_CORRIGENDUM2_UPDATE
56extern B_UINT32 g_u32Corr2MacFlags;
57#endif
58#endif
59 42
60#include "Typedefs.h" 43#include "Typedefs.h"
61#include "Version.h" 44#include "Version.h"
@@ -71,39 +54,28 @@ extern B_UINT32 g_u32Corr2MacFlags;
71#include "CmHost.h" 54#include "CmHost.h"
72#include "DDRInit.h" 55#include "DDRInit.h"
73#include "Debug.h" 56#include "Debug.h"
74#include "HostMibs.h"
75#include "IPv6ProtocolHdr.h" 57#include "IPv6ProtocolHdr.h"
76#include "osal_misc.h"
77#include "PHSModule.h" 58#include "PHSModule.h"
78#include "Protocol.h" 59#include "Protocol.h"
79#include "Prototypes.h" 60#include "Prototypes.h"
80#include "Queue.h" 61#include "Queue.h"
81#include "vendorspecificextn.h" 62#include "vendorspecificextn.h"
82 63
83#ifndef BCM_SHM_INTERFACE
84 64
85#include "InterfaceMacros.h" 65#include "InterfaceMacros.h"
86#include "InterfaceAdapter.h" 66#include "InterfaceAdapter.h"
87#include "InterfaceIsr.h" 67#include "InterfaceIsr.h"
88#include "Interfacemain.h"
89#include "InterfaceMisc.h" 68#include "InterfaceMisc.h"
90#include "InterfaceRx.h" 69#include "InterfaceRx.h"
91#include "InterfaceTx.h" 70#include "InterfaceTx.h"
92#endif
93#include "InterfaceIdleMode.h" 71#include "InterfaceIdleMode.h"
94#include "InterfaceInit.h" 72#include "InterfaceInit.h"
95 73
96#ifdef BCM_SHM_INTERFACE 74#define DRV_NAME "beceem"
97#include <linux/cpe_config.h> 75#define DEV_NAME "tarang"
98 76#define DRV_DESCRIPTION "Beceem Communications Inc. WiMAX driver"
99#ifdef GDMA_INTERFACE 77#define DRV_COPYRIGHT "Copyright 2010. Beceem Communications Inc"
100#include "GdmaInterface.h" 78#define DRV_VERSION VER_FILEVERSION_STR
101#include "symphony.h" 79#define PFX DRV_NAME " "
102#else
103#include "virtual_interface.h"
104
105#endif
106
107#endif
108 80
109#endif 81#endif
diff --git a/drivers/staging/bcm/hostmibs.c b/drivers/staging/bcm/hostmibs.c
index e9da513b3c24..c13ea5c9a2aa 100644
--- a/drivers/staging/bcm/hostmibs.c
+++ b/drivers/staging/bcm/hostmibs.c
@@ -10,12 +10,8 @@
10 */ 10 */
11#include "headers.h" 11#include "headers.h"
12 12
13INT ProcessGetHostMibs(PMINI_ADAPTER Adapter, 13INT ProcessGetHostMibs(PMINI_ADAPTER Adapter, S_MIBS_HOST_STATS_MIBS *pstHostMibs)
14 PVOID ioBuffer,
15 ULONG inputBufferLength)
16{ 14{
17
18 S_MIBS_HOST_STATS_MIBS *pstHostMibs = NULL;
19 S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; 15 S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL;
20 S_PHS_RULE *pstPhsRule = NULL; 16 S_PHS_RULE *pstPhsRule = NULL;
21 S_CLASSIFIER_TABLE *pstClassifierTable = NULL; 17 S_CLASSIFIER_TABLE *pstClassifierTable = NULL;
@@ -30,15 +26,6 @@ INT ProcessGetHostMibs(PMINI_ADAPTER Adapter,
30 return STATUS_FAILURE; 26 return STATUS_FAILURE;
31 } 27 }
32 28
33 if(ioBuffer == NULL)
34 {
35 return -EINVAL;
36 }
37 memset(ioBuffer,0,sizeof(S_MIBS_HOST_STATS_MIBS));
38
39 pstHostMibs = (S_MIBS_HOST_STATS_MIBS *)ioBuffer;
40
41
42 //Copy the classifier Table 29 //Copy the classifier Table
43 for(nClassifierIndex=0; nClassifierIndex < MAX_CLASSIFIERS; 30 for(nClassifierIndex=0; nClassifierIndex < MAX_CLASSIFIERS;
44 nClassifierIndex++) 31 nClassifierIndex++)
@@ -54,7 +41,7 @@ INT ProcessGetHostMibs(PMINI_ADAPTER Adapter,
54 { 41 {
55 if(Adapter->PackInfo[nSfIndex].bValid) 42 if(Adapter->PackInfo[nSfIndex].bValid)
56 { 43 {
57 OsalMemMove((PVOID)&pstHostMibs->astSFtable[nSfIndex],(PVOID)&Adapter->PackInfo[nSfIndex],sizeof(S_MIBS_SERVICEFLOW_TABLE)); 44 memcpy((PVOID)&pstHostMibs->astSFtable[nSfIndex],(PVOID)&Adapter->PackInfo[nSfIndex],sizeof(S_MIBS_SERVICEFLOW_TABLE));
58 } 45 }
59 else 46 else
60 { 47 {
@@ -83,7 +70,7 @@ INT ProcessGetHostMibs(PMINI_ADAPTER Adapter,
83 70
84 pstHostMibs->astPhsRulesTable[nPhsTableIndex].ulSFID = Adapter->PackInfo[nSfIndex].ulSFID; 71 pstHostMibs->astPhsRulesTable[nPhsTableIndex].ulSFID = Adapter->PackInfo[nSfIndex].ulSFID;
85 72
86 OsalMemMove(&pstHostMibs->astPhsRulesTable[nPhsTableIndex].u8PHSI, 73 memcpy(&pstHostMibs->astPhsRulesTable[nPhsTableIndex].u8PHSI,
87 &pstPhsRule->u8PHSI, 74 &pstPhsRule->u8PHSI,
88 sizeof(S_PHS_RULE)); 75 sizeof(S_PHS_RULE));
89 nPhsTableIndex++; 76 nPhsTableIndex++;
@@ -95,12 +82,9 @@ INT ProcessGetHostMibs(PMINI_ADAPTER Adapter,
95 } 82 }
96 83
97 84
98
99 //copy other Host Statistics parameters 85 //copy other Host Statistics parameters
100 pstHostMibs->stHostInfo.GoodTransmits = 86 pstHostMibs->stHostInfo.GoodTransmits = Adapter->dev->stats.tx_packets;
101 atomic_read(&Adapter->TxTotalPacketCount); 87 pstHostMibs->stHostInfo.GoodReceives = Adapter->dev->stats.rx_packets;
102 pstHostMibs->stHostInfo.GoodReceives =
103 atomic_read(&Adapter->GoodRxPktCount);
104 pstHostMibs->stHostInfo.CurrNumFreeDesc = 88 pstHostMibs->stHostInfo.CurrNumFreeDesc =
105 atomic_read(&Adapter->CurrNumFreeTxDesc); 89 atomic_read(&Adapter->CurrNumFreeTxDesc);
106 pstHostMibs->stHostInfo.BEBucketSize = Adapter->BEBucketSize; 90 pstHostMibs->stHostInfo.BEBucketSize = Adapter->BEBucketSize;
@@ -115,13 +99,10 @@ INT ProcessGetHostMibs(PMINI_ADAPTER Adapter,
115} 99}
116 100
117 101
118INT GetDroppedAppCntrlPktMibs(PVOID ioBuffer, PPER_TARANG_DATA pTarang) 102VOID GetDroppedAppCntrlPktMibs(S_MIBS_HOST_STATS_MIBS *pstHostMibs, const PPER_TARANG_DATA pTarang)
119{ 103{
120 S_MIBS_HOST_STATS_MIBS *pstHostMibs = (S_MIBS_HOST_STATS_MIBS *)ioBuffer; 104 memcpy(&(pstHostMibs->stDroppedAppCntrlMsgs),
121 105 &(pTarang->stDroppedAppCntrlMsgs),sizeof(S_MIBS_DROPPED_APP_CNTRL_MESSAGES));
122 memcpy((PVOID)&(pstHostMibs->stDroppedAppCntrlMsgs),(PVOID)&(pTarang->stDroppedAppCntrlMsgs),sizeof(S_MIBS_DROPPED_APP_CNTRL_MESSAGES));
123
124 return STATUS_SUCCESS ;
125} 106}
126 107
127 108
diff --git a/drivers/staging/bcm/led_control.c b/drivers/staging/bcm/led_control.c
index 97adaae7dfc0..16e939fa15d6 100644
--- a/drivers/staging/bcm/led_control.c
+++ b/drivers/staging/bcm/led_control.c
@@ -108,52 +108,16 @@ static INT LED_Proportional_Blink(PMINI_ADAPTER Adapter, UCHAR GPIO_Num_tx,
108 ulong timeout = 0; 108 ulong timeout = 0;
109 109
110 /*Read initial value of packets sent/received */ 110 /*Read initial value of packets sent/received */
111 Initial_num_of_packts_tx = atomic_read(&Adapter->TxTotalPacketCount); 111 Initial_num_of_packts_tx = Adapter->dev->stats.tx_packets;
112 Initial_num_of_packts_rx = atomic_read(&Adapter->GoodRxPktCount); 112 Initial_num_of_packts_rx = Adapter->dev->stats.rx_packets;
113
113 /*Scale the rate of transfer to no of blinks.*/ 114 /*Scale the rate of transfer to no of blinks.*/
114 num_of_time_tx= ScaleRateofTransfer((ULONG)rate_of_transfer_tx); 115 num_of_time_tx= ScaleRateofTransfer((ULONG)rate_of_transfer_tx);
115 num_of_time_rx= ScaleRateofTransfer((ULONG)rate_of_transfer_rx); 116 num_of_time_rx= ScaleRateofTransfer((ULONG)rate_of_transfer_rx);
116 117
117 while((Adapter->device_removed == FALSE)) 118 while((Adapter->device_removed == FALSE))
118 { 119 {
119 #if 0
120 if(0 == num_of_time_tx && 0 == num_of_time_rx)
121 {
122 timeout = 1000;
123 Status = wait_event_interruptible_timeout(Adapter->LEDInfo.notify_led_event,
124 currdriverstate!= Adapter->DriverState || kthread_should_stop(),
125 msecs_to_jiffies (timeout));
126 if(kthread_should_stop())
127 {
128 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "Led thread got signal to exit..hence exiting");
129 Adapter->LEDInfo.led_thread_running= BCM_LED_THREAD_DISABLED;
130 return EVENT_SIGNALED;
131 }
132 if(Status)
133 return EVENT_SIGNALED;
134
135 }
136 #endif
137
138 timeout = 50; 120 timeout = 50;
139 #if 0
140 /*Turn on LED if Tx is high bandwidth*/
141 if(num_of_time_tx > MAX_NUM_OF_BLINKS)
142 {
143 TURN_ON_LED(1<<GPIO_Num_tx, uiTxLedIndex);
144 num_of_time_tx = 0;
145 bBlinkBothLED = FALSE;
146 num_of_time = num_of_time_rx;
147 }
148 /*Turn on LED if Rx is high bandwidth*/
149 if(num_of_time_rx > MAX_NUM_OF_BLINKS)
150 {
151 TURN_ON_LED(1<<GPIO_Num_rx, uiRxLedIndex);
152 num_of_time_rx = 0;
153 bBlinkBothLED = FALSE;
154 num_of_time = num_of_time_tx;
155 }
156 #endif
157 /*Blink Tx and Rx LED when both Tx and Rx is in normal bandwidth*/ 121 /*Blink Tx and Rx LED when both Tx and Rx is in normal bandwidth*/
158 if(bBlinkBothLED) 122 if(bBlinkBothLED)
159 { 123 {
@@ -249,9 +213,10 @@ static INT LED_Proportional_Blink(PMINI_ADAPTER Adapter, UCHAR GPIO_Num_tx,
249 * Read the Tx & Rx packets transmission after 1 second and 213 * Read the Tx & Rx packets transmission after 1 second and
250 * calculate rate of transfer 214 * calculate rate of transfer
251 */ 215 */
252 Final_num_of_packts_tx = atomic_read(&Adapter->TxTotalPacketCount); 216 Final_num_of_packts_tx = Adapter->dev->stats.tx_packets;
217 Final_num_of_packts_rx = Adapter->dev->stats.rx_packets;
218
253 rate_of_transfer_tx = Final_num_of_packts_tx - Initial_num_of_packts_tx; 219 rate_of_transfer_tx = Final_num_of_packts_tx - Initial_num_of_packts_tx;
254 Final_num_of_packts_rx = atomic_read(&Adapter->GoodRxPktCount);
255 rate_of_transfer_rx = Final_num_of_packts_rx - Initial_num_of_packts_rx; 220 rate_of_transfer_rx = Final_num_of_packts_rx - Initial_num_of_packts_rx;
256 221
257 /*Read initial value of packets sent/received */ 222 /*Read initial value of packets sent/received */
@@ -293,7 +258,7 @@ static INT ValidateDSDParamsChecksum(
293 258
294 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread:ValidateDSDParamsChecksum: 0x%lx 0x%X",ulParamOffset, usParamLen); 259 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread:ValidateDSDParamsChecksum: 0x%lx 0x%X",ulParamOffset, usParamLen);
295 260
296 puBuffer = OsalMemAlloc(usParamLen,"!MEM"); 261 puBuffer = kmalloc(usParamLen, GFP_KERNEL);
297 if(!puBuffer) 262 if(!puBuffer)
298 { 263 {
299 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: ValidateDSDParamsChecksum Allocation failed"); 264 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: ValidateDSDParamsChecksum Allocation failed");
@@ -341,10 +306,7 @@ static INT ValidateDSDParamsChecksum(
341 } 306 }
342 307
343exit: 308exit:
344 if(puBuffer) 309 kfree(puBuffer);
345 {
346 OsalMemFree(puBuffer, usParamLen);
347 }
348 return Status; 310 return Status;
349} 311}
350 312
@@ -497,12 +459,10 @@ static int ReadConfigFileStructure(PMINI_ADAPTER Adapter, BOOLEAN *bEnableThread
497{ 459{
498 int Status = STATUS_SUCCESS; 460 int Status = STATUS_SUCCESS;
499 UCHAR GPIO_Array[NUM_OF_LEDS+1]; /*Array to store GPIO numbers from EEPROM*/ 461 UCHAR GPIO_Array[NUM_OF_LEDS+1]; /*Array to store GPIO numbers from EEPROM*/
500#ifndef BCM_SHM_INTERFACE
501 UINT uiIndex = 0; 462 UINT uiIndex = 0;
502 UINT uiNum_of_LED_Type = 0; 463 UINT uiNum_of_LED_Type = 0;
503 PUCHAR puCFGData = NULL; 464 PUCHAR puCFGData = NULL;
504 UCHAR bData = 0; 465 UCHAR bData = 0;
505#endif
506 memset(GPIO_Array, DISABLE_GPIO_NUM, NUM_OF_LEDS+1); 466 memset(GPIO_Array, DISABLE_GPIO_NUM, NUM_OF_LEDS+1);
507 467
508 if(!Adapter->pstargetparams || IS_ERR(Adapter->pstargetparams)) 468 if(!Adapter->pstargetparams || IS_ERR(Adapter->pstargetparams))
@@ -524,10 +484,6 @@ static int ReadConfigFileStructure(PMINI_ADAPTER Adapter, BOOLEAN *bEnableThread
524 *bEnableThread = FALSE; 484 *bEnableThread = FALSE;
525 return Status; 485 return Status;
526 } 486 }
527#ifdef BCM_SHM_INTERFACE
528 *bEnableThread = FALSE;
529 return Status ;
530#else
531 /* 487 /*
532 * CONFIG file read successfully. Deallocate the memory of 488 * CONFIG file read successfully. Deallocate the memory of
533 * uiFileNameBufferSize 489 * uiFileNameBufferSize
@@ -578,23 +534,7 @@ static int ReadConfigFileStructure(PMINI_ADAPTER Adapter, BOOLEAN *bEnableThread
578 } 534 }
579 if(uiNum_of_LED_Type >= NUM_OF_LEDS) 535 if(uiNum_of_LED_Type >= NUM_OF_LEDS)
580 *bEnableThread = FALSE; 536 *bEnableThread = FALSE;
581#endif
582 537
583#if 0
584 for(uiIndex=0; uiIndex<NUM_OF_LEDS; uiIndex++)
585 {
586 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LEDState[%d].LED_Type = %x\n", uiIndex,
587 Adapter->LEDInfo.LEDState[uiIndex].LED_Type);
588 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LEDState[%d].LED_On_State = %x\n", uiIndex,
589 Adapter->LEDInfo.LEDState[uiIndex].LED_On_State);
590 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LEDState[%d].LED_Blink_State = %x\n", uiIndex,
591 Adapter->LEDInfo.LEDState[uiIndex].LED_Blink_State);
592 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LEDState[%d].GPIO_Num = %x\n", uiIndex,
593 Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num);
594 }
595 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: Polarity = %d\n",
596 Adapter->LEDInfo.BitPolarty);
597#endif
598 return Status; 538 return Status;
599} 539}
600//-------------------------------------------------------------------------- 540//--------------------------------------------------------------------------
@@ -721,20 +661,6 @@ static VOID LEDControlThread(PMINI_ADAPTER Adapter)
721 TURN_OFF_LED(1<<GPIO_num, uiLedIndex); 661 TURN_OFF_LED(1<<GPIO_num, uiLedIndex);
722 return ;//STATUS_FAILURE; 662 return ;//STATUS_FAILURE;
723 } 663 }
724 #if 0
725 if(Adapter->device_removed)
726 {
727 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"Device removed hence exiting from Led Thread..");
728 return ; //-ENODEV;
729 }
730 #endif
731 #if 0
732 if((GPIO_num != DISABLE_GPIO_NUM) &&
733 ((currdriverstate != FW_DOWNLOAD) &&
734 (currdriverstate != NORMAL_OPERATION) &&
735 (currdriverstate != IDLEMODE_EXIT)))
736 TURN_OFF_LED(1<<GPIO_num, uiLedIndex);
737 #endif
738 664
739 if(GPIO_num != DISABLE_GPIO_NUM) 665 if(GPIO_num != DISABLE_GPIO_NUM)
740 { 666 {
@@ -752,10 +678,6 @@ static VOID LEDControlThread(PMINI_ADAPTER Adapter)
752 case DRIVER_INIT: 678 case DRIVER_INIT:
753 { 679 {
754 currdriverstate = DRIVER_INIT;//Adapter->DriverState; 680 currdriverstate = DRIVER_INIT;//Adapter->DriverState;
755 #if 0
756 LedGpioInit(Adapter);
757 Adapter->LEDInfo.bLedInitDone = TRUE;
758 #endif
759 BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum, &uiLedIndex, &dummyIndex, currdriverstate); 681 BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum, &uiLedIndex, &dummyIndex, currdriverstate);
760 682
761 if(GPIO_num != DISABLE_GPIO_NUM) 683 if(GPIO_num != DISABLE_GPIO_NUM)
@@ -768,13 +690,6 @@ static VOID LEDControlThread(PMINI_ADAPTER Adapter)
768 { 690 {
769 //BCM_DEBUG_PRINT (Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: FW_DN_DONE called\n"); 691 //BCM_DEBUG_PRINT (Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: FW_DN_DONE called\n");
770 currdriverstate = FW_DOWNLOAD; 692 currdriverstate = FW_DOWNLOAD;
771 #if 0
772 if(Adapter->LEDInfo.bLedInitDone == FALSE)
773 {
774 LedGpioInit(Adapter);
775 Adapter->LEDInfo.bLedInitDone = TRUE;
776 }
777 #endif
778 BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum, &uiLedIndex, &dummyIndex, currdriverstate); 693 BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum, &uiLedIndex, &dummyIndex, currdriverstate);
779 694
780 if(GPIO_num != DISABLE_GPIO_NUM) 695 if(GPIO_num != DISABLE_GPIO_NUM)
@@ -796,12 +711,6 @@ static VOID LEDControlThread(PMINI_ADAPTER Adapter)
796 break; 711 break;
797 712
798 case SHUTDOWN_EXIT: 713 case SHUTDOWN_EXIT:
799 #if 0
800 if(Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_PMU_SHUTDOWN)
801 {
802 LedGpioInit(Adapter);
803 }
804 #endif
805 //no break, continue to NO_NETWORK_ENTRY state as well. 714 //no break, continue to NO_NETWORK_ENTRY state as well.
806 715
807 case NO_NETWORK_ENTRY: 716 case NO_NETWORK_ENTRY:
@@ -875,34 +784,6 @@ static VOID LEDControlThread(PMINI_ADAPTER Adapter)
875 break; 784 break;
876 case IDLEMODE_EXIT: 785 case IDLEMODE_EXIT:
877 { 786 {
878#if 0
879 UCHAR GPIO_num_tx = DISABLE_GPIO_NUM;
880 UCHAR GPIO_num_rx = DISABLE_GPIO_NUM;
881 UCHAR uiTxLedIndex = 0;
882 UCHAR uiRxLedIndex = 0;
883
884 currdriverstate = IDLEMODE_EXIT;
885 if(DEVICE_POWERSAVE_MODE_AS_PMU_SHUTDOWN == Adapter->ulPowerSaveMode)
886 {
887 LedGpioInit(Adapter);
888 }
889 BcmGetGPIOPinInfo(Adapter, &GPIO_num_tx, &GPIO_num_rx, &uiTxLedIndex,&uiRxLedIndex,currdriverstate);
890
891 Adapter->LEDInfo.bIdle_led_off = FALSE;
892
893 if((GPIO_num_tx == DISABLE_GPIO_NUM) && (GPIO_num_rx == DISABLE_GPIO_NUM))
894 {
895 GPIO_num = DISABLE_GPIO_NUM ;
896 }
897 else
898 {
899 timeout = 50;
900 if(Adapter->LEDInfo.bIdleMode_tx_from_host)
901 LED_Blink(Adapter, 1<<GPIO_num_tx, uiTxLedIndex, timeout, -1,currdriverstate);
902 else
903 LED_Blink(Adapter, 1<<GPIO_num_rx, uiRxLedIndex, timeout, -1,currdriverstate);
904 }
905#endif
906 } 787 }
907 break; 788 break;
908 case DRIVER_HALT: 789 case DRIVER_HALT:
diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c
index 41c9ab8a2385..c7292373a65f 100644
--- a/drivers/staging/bcm/nvm.c
+++ b/drivers/staging/bcm/nvm.c
@@ -1,6 +1,56 @@
1#include "headers.h" 1#include "headers.h"
2 2
3#define DWORD unsigned int 3#define DWORD unsigned int
4
5static INT BcmDoChipSelect(PMINI_ADAPTER Adapter, UINT offset);
6static INT BcmGetActiveDSD(PMINI_ADAPTER Adapter);
7static INT BcmGetActiveISO(PMINI_ADAPTER Adapter);
8static UINT BcmGetEEPROMSize(PMINI_ADAPTER Adapter);
9static INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter);
10static UINT BcmGetFlashSectorSize(PMINI_ADAPTER Adapter, UINT FlashSectorSizeSig, UINT FlashSectorSize);
11
12static VOID BcmValidateNvmType(PMINI_ADAPTER Adapter);
13static INT BcmGetNvmSize(PMINI_ADAPTER Adapter);
14static UINT BcmGetFlashSize(PMINI_ADAPTER Adapter);
15static NVM_TYPE BcmGetNvmType(PMINI_ADAPTER Adapter);
16
17static INT BcmGetSectionValEndOffset(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal);
18
19static B_UINT8 IsOffsetWritable(PMINI_ADAPTER Adapter, UINT uiOffset);
20static INT IsSectionWritable(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL Section);
21static INT IsSectionExistInVendorInfo(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section);
22
23static INT ReadDSDPriority(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL dsd);
24static INT ReadDSDSignature(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL dsd);
25static INT ReadISOPriority(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL iso);
26static INT ReadISOSignature(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL iso);
27
28static INT CorruptDSDSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal);
29static INT CorruptISOSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal);
30static INT SaveHeaderIfPresent(PMINI_ADAPTER Adapter, PUCHAR pBuff, UINT uiSectAlignAddr);
31static INT WriteToFlashWithoutSectorErase(PMINI_ADAPTER Adapter, PUINT pBuff,
32 FLASH2X_SECTION_VAL eFlash2xSectionVal,
33 UINT uiOffset, UINT uiNumBytes);
34static FLASH2X_SECTION_VAL getHighestPriDSD(PMINI_ADAPTER Adapter);
35static FLASH2X_SECTION_VAL getHighestPriISO(PMINI_ADAPTER Adapter);
36
37static INT BeceemFlashBulkRead(
38 PMINI_ADAPTER Adapter,
39 PUINT pBuffer,
40 UINT uiOffset,
41 UINT uiNumBytes);
42
43static INT BeceemFlashBulkWrite(
44 PMINI_ADAPTER Adapter,
45 PUINT pBuffer,
46 UINT uiOffset,
47 UINT uiNumBytes,
48 BOOLEAN bVerify);
49
50static INT GetFlashBaseAddr(PMINI_ADAPTER Adapter);
51
52static INT ReadBeceemEEPROMBulk(PMINI_ADAPTER Adapter,UINT dwAddress, UINT *pdwData, UINT dwNumData);
53
4// Procedure: ReadEEPROMStatusRegister 54// Procedure: ReadEEPROMStatusRegister
5// 55//
6// Description: Reads the standard EEPROM Status Register. 56// Description: Reads the standard EEPROM Status Register.
@@ -228,213 +278,27 @@ INT ReadBeceemEEPROM( PMINI_ADAPTER Adapter,
228 ReadBeceemEEPROMBulk(Adapter, uiTempOffset + MAX_RW_SIZE, (PUINT)&uiData[4], 4); 278 ReadBeceemEEPROMBulk(Adapter, uiTempOffset + MAX_RW_SIZE, (PUINT)&uiData[4], 4);
229 } 279 }
230 280
231 OsalMemMove( (PUCHAR) pBuffer, ( ((PUCHAR)&uiData[0]) + uiByteOffset ), 4); 281 memcpy( (PUCHAR) pBuffer, ( ((PUCHAR)&uiData[0]) + uiByteOffset ), 4);
232 282
233 return STATUS_SUCCESS; 283 return STATUS_SUCCESS;
234} /* ReadBeceemEEPROM() */ 284} /* ReadBeceemEEPROM() */
235 285
236 286
237#if 0
238//-----------------------------------------------------------------------------
239// Procedure: IsEEPROMWriteDone
240//
241// Description: Reads the SPI status to see the status of previous write.
242//
243// Arguments:
244// Adapter - ptr to Adapter object instance
245//
246// Returns:
247// BOOLEAN - TRUE - write went through
248// - FALSE - Write Failed.
249//-----------------------------------------------------------------------------
250
251BOOLEAN IsEEPROMWriteDone(PMINI_ADAPTER Adapter)
252{
253 UINT uiRetries = 16;
254 //UINT uiStatus = 0;
255 UINT value;
256
257 //sleep for 1.2ms ..worst case EEPROM write can take up to 1.2ms.
258 mdelay(2);
259
260 value = 0;
261 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
262
263 while(((value >> 14) & 1) == 1)
264 {
265 // EEPROM_SPI_Q_STATUS1_REG will be cleared only if write back to that.
266 value = (0x1 << 14);
267 wrmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG,&value, sizeof(value));
268 udelay(1000);
269 uiRetries--;
270 if(uiRetries == 0)
271 {
272 return FALSE;
273 }
274 value = 0;
275 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
276 }
277 return TRUE;
278
279
280}
281
282
283//-----------------------------------------------------------------------------
284// Procedure: ReadBeceemEEPROMBulk
285//
286// Description: This routine reads 16Byte data from EEPROM
287//
288// Arguments:
289// Adapter - ptr to Adapter object instance
290// dwAddress - EEPROM Offset to read the data from.
291// pdwData - Pointer to double word where data needs to be stored in.
292//
293// Returns:
294// OSAL_STATUS_CODE:
295//-----------------------------------------------------------------------------
296
297INT ReadBeceemEEPROMBulk(PMINI_ADAPTER Adapter,DWORD dwAddress, DWORD *pdwData)
298{
299 DWORD dwRetries = 16;
300 DWORD dwIndex = 0;
301 UINT value, tmpVal;
302
303
304 value = 0;
305 rdmalt (Adapter, 0x0f003008, &value, sizeof(value));
306
307 //read 0x0f003020 untill bit 1 of 0x0f003008 is set.
308 while(((value >> 1) & 1) == 0)
309 {
310
311 rdmalt (Adapter, 0x0f003020, &tmpVal, sizeof(tmpVal));
312 dwRetries--;
313 if(dwRetries == 0)
314 {
315 return -1;
316 }
317 value = 0;
318 rdmalt (Adapter, 0x0f003008, &value, sizeof(value));
319 }
320
321 value = dwAddress | 0xfb000000;
322 wrmalt (Adapter, 0x0f003018, &value, sizeof(value));
323
324 udelay(1000);
325 value = 0;
326 for(dwIndex = 0;dwIndex < 4 ; dwIndex++)
327 {
328 value = 0;
329 rdmalt (Adapter, 0x0f003020, &value, sizeof(value));
330 pdwData[dwIndex] = value;
331
332 value = 0;
333 rdmalt (Adapter, 0x0f003020, &value, sizeof(value));
334 pdwData[dwIndex] |= (value << 8);
335
336 value = 0;
337 rdmalt (Adapter, 0x0f003020, &value, sizeof(value));
338 pdwData[dwIndex] |= (value << 16);
339
340 value = 0;
341 rdmalt (Adapter, 0x0f003020, &value, sizeof(value));
342 pdwData[dwIndex] |= (value << 24);
343
344 }
345 return 0;
346}
347
348//-----------------------------------------------------------------------------
349// Procedure: ReadBeceemEEPROM
350//
351// Description: This routine reads 4Byte data from EEPROM
352//
353// Arguments:
354// Adapter - ptr to Adapter object instance
355// dwAddress - EEPROM Offset to read the data from.
356// pdwData - Pointer to double word where data needs to be stored in.
357//
358// Returns:
359// OSAL_STATUS_CODE:
360//-----------------------------------------------------------------------------
361
362INT ReadBeceemEEPROM(PMINI_ADAPTER Adapter,DWORD dwAddress, DWORD *pdwData)
363{
364
365 DWORD dwReadValue = 0;
366 DWORD dwRetries = 16, dwCompleteWord = 0;
367 UINT value, tmpVal;
368
369 rdmalt(Adapter, 0x0f003008, &value, sizeof(value));
370 while (((value >> 1) & 1) == 0) {
371 rdmalt(Adapter, 0x0f003020, &tmpVal, sizeof(tmpVal));
372
373 if (dwRetries == 0) {
374 return -1;
375 }
376 rdmalt(Adapter, 0x0f003008, &value, sizeof(value));
377 }
378
379
380 //wrm (0x0f003018, 0xNbXXXXXX) // N is the number of bytes u want to read (0 means 1, f means 16, b is the opcode for page read)
381 // Follow it up by N executions of rdm(0x0f003020) to read the rxed bytes from rx queue.
382 dwAddress |= 0x3b000000;
383 wrmalt(Adapter, 0x0f003018,&dwAddress,4);
384 mdelay(10);
385 rdmalt(Adapter, 0x0f003020,&dwReadValue,4);
386 dwCompleteWord=dwReadValue;
387 rdmalt(Adapter, 0x0f003020,&dwReadValue,4);
388 dwCompleteWord|=(dwReadValue<<8);
389 rdmalt(Adapter, 0x0f003020,&dwReadValue,4);
390 dwCompleteWord|=(dwReadValue<<16);
391 rdmalt(Adapter, 0x0f003020,&dwReadValue,4);
392 dwCompleteWord|=(dwReadValue<<24);
393
394 *pdwData = dwCompleteWord;
395
396 return 0;
397}
398#endif
399 287
400INT ReadMacAddressFromNVM(PMINI_ADAPTER Adapter) 288INT ReadMacAddressFromNVM(PMINI_ADAPTER Adapter)
401{ 289{
402 INT Status=0, i; 290 INT Status;
403 unsigned char puMacAddr[6] = {0}; 291 unsigned char puMacAddr[6];
404 INT AllZeroMac = 0;
405 INT AllFFMac = 0;
406 292
407 Status = BeceemNVMRead(Adapter, 293 Status = BeceemNVMRead(Adapter,
408 (PUINT)&puMacAddr[0], 294 (PUINT)&puMacAddr[0],
409 INIT_PARAMS_1_MACADDRESS_ADDRESS, 295 INIT_PARAMS_1_MACADDRESS_ADDRESS,
410 MAC_ADDRESS_SIZE); 296 MAC_ADDRESS_SIZE);
411 297
412 if(Status != STATUS_SUCCESS) 298 if(Status == STATUS_SUCCESS)
413 { 299 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
414 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Error in Reading the mac Addres with status :%d", Status);
415 return Status;
416 }
417
418 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
419 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Modem MAC Addr :");
420 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_PRINTK, 0, DBG_LVL_ALL,&Adapter->dev->dev_addr[0],MAC_ADDRESS_SIZE);
421 for(i=0;i<MAC_ADDRESS_SIZE;i++)
422 {
423
424 if(Adapter->dev->dev_addr[i] == 0x00)
425 AllZeroMac++;
426 if(Adapter->dev->dev_addr[i] == 0xFF)
427 AllFFMac++;
428
429 }
430 //BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "\n");
431 if(AllZeroMac == MAC_ADDRESS_SIZE)
432 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Warning :: MAC Address has all 00's");
433 if(AllFFMac == MAC_ADDRESS_SIZE)
434 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Warning :: MAC Address has all FF's");
435 300
436 return Status; 301 return Status;
437
438} 302}
439 303
440//----------------------------------------------------------------------------- 304//-----------------------------------------------------------------------------
@@ -476,7 +340,7 @@ INT BeceemEEPROMBulkRead(
476 ReadBeceemEEPROMBulk(Adapter,uiTempOffset,(PUINT)&uiData[0],4); 340 ReadBeceemEEPROMBulk(Adapter,uiTempOffset,(PUINT)&uiData[0],4);
477 if(uiBytesRemaining >= (MAX_RW_SIZE - uiExtraBytes)) 341 if(uiBytesRemaining >= (MAX_RW_SIZE - uiExtraBytes))
478 { 342 {
479 OsalMemMove(pBuffer,(((PUCHAR)&uiData[0])+uiExtraBytes),MAX_RW_SIZE - uiExtraBytes); 343 memcpy(pBuffer,(((PUCHAR)&uiData[0])+uiExtraBytes),MAX_RW_SIZE - uiExtraBytes);
480 344
481 uiBytesRemaining -= (MAX_RW_SIZE - uiExtraBytes); 345 uiBytesRemaining -= (MAX_RW_SIZE - uiExtraBytes);
482 uiIndex += (MAX_RW_SIZE - uiExtraBytes); 346 uiIndex += (MAX_RW_SIZE - uiExtraBytes);
@@ -484,7 +348,7 @@ INT BeceemEEPROMBulkRead(
484 } 348 }
485 else 349 else
486 { 350 {
487 OsalMemMove(pBuffer,(((PUCHAR)&uiData[0])+uiExtraBytes),uiBytesRemaining); 351 memcpy(pBuffer,(((PUCHAR)&uiData[0])+uiExtraBytes),uiBytesRemaining);
488 uiIndex += uiBytesRemaining; 352 uiIndex += uiBytesRemaining;
489 uiOffset += uiBytesRemaining; 353 uiOffset += uiBytesRemaining;
490 uiBytesRemaining = 0; 354 uiBytesRemaining = 0;
@@ -508,7 +372,7 @@ INT BeceemEEPROMBulkRead(
508 * We read 4 Dwords of data */ 372 * We read 4 Dwords of data */
509 if(0 == ReadBeceemEEPROMBulk(Adapter,uiOffset,&uiData[0],4)) 373 if(0 == ReadBeceemEEPROMBulk(Adapter,uiOffset,&uiData[0],4))
510 { 374 {
511 OsalMemMove(pcBuff+uiIndex,&uiData[0],MAX_RW_SIZE); 375 memcpy(pcBuff+uiIndex,&uiData[0],MAX_RW_SIZE);
512 uiOffset += MAX_RW_SIZE; 376 uiOffset += MAX_RW_SIZE;
513 uiBytesRemaining -= MAX_RW_SIZE; 377 uiBytesRemaining -= MAX_RW_SIZE;
514 uiIndex += MAX_RW_SIZE; 378 uiIndex += MAX_RW_SIZE;
@@ -523,7 +387,7 @@ INT BeceemEEPROMBulkRead(
523 { 387 {
524 if(0 == ReadBeceemEEPROM(Adapter,uiOffset,&uiData[0])) 388 if(0 == ReadBeceemEEPROM(Adapter,uiOffset,&uiData[0]))
525 { 389 {
526 OsalMemMove(pcBuff+uiIndex,&uiData[0],4); 390 memcpy(pcBuff+uiIndex,&uiData[0],4);
527 uiOffset += 4; 391 uiOffset += 4;
528 uiBytesRemaining -= 4; 392 uiBytesRemaining -= 4;
529 uiIndex +=4; 393 uiIndex +=4;
@@ -540,7 +404,7 @@ INT BeceemEEPROMBulkRead(
540 pCharBuff += uiIndex; 404 pCharBuff += uiIndex;
541 if(0 == ReadBeceemEEPROM(Adapter,uiOffset,&uiData[0])) 405 if(0 == ReadBeceemEEPROM(Adapter,uiOffset,&uiData[0]))
542 { 406 {
543 OsalMemMove(pCharBuff,&uiData[0],uiBytesRemaining);//copy only bytes requested. 407 memcpy(pCharBuff,&uiData[0],uiBytesRemaining);//copy only bytes requested.
544 uiBytesRemaining = 0; 408 uiBytesRemaining = 0;
545 } 409 }
546 else 410 else
@@ -571,7 +435,7 @@ INT BeceemEEPROMBulkRead(
571// <FAILURE> - if failed. 435// <FAILURE> - if failed.
572//----------------------------------------------------------------------------- 436//-----------------------------------------------------------------------------
573 437
574INT BeceemFlashBulkRead( 438static INT BeceemFlashBulkRead(
575 PMINI_ADAPTER Adapter, 439 PMINI_ADAPTER Adapter,
576 PUINT pBuffer, 440 PUINT pBuffer,
577 UINT uiOffset, 441 UINT uiOffset,
@@ -653,16 +517,8 @@ INT BeceemFlashBulkRead(
653// 517//
654//----------------------------------------------------------------------------- 518//-----------------------------------------------------------------------------
655 519
656UINT BcmGetFlashSize(PMINI_ADAPTER Adapter) 520static UINT BcmGetFlashSize(PMINI_ADAPTER Adapter)
657{ 521{
658#if 0
659 if(Adapter->bDDRInitDone)
660 {
661 return rdm(Adapter,FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT|FLASH_SIZE_ADDR);
662 }
663
664 return rdm(Adapter,FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT|FLASH_SIZE_ADDR);
665#endif
666 if(IsFlash2x(Adapter)) 522 if(IsFlash2x(Adapter))
667 return (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER)); 523 return (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER));
668 else 524 else
@@ -684,7 +540,7 @@ UINT BcmGetFlashSize(PMINI_ADAPTER Adapter)
684// 540//
685//----------------------------------------------------------------------------- 541//-----------------------------------------------------------------------------
686 542
687UINT BcmGetEEPROMSize(PMINI_ADAPTER Adapter) 543static UINT BcmGetEEPROMSize(PMINI_ADAPTER Adapter)
688{ 544{
689 UINT uiData = 0; 545 UINT uiData = 0;
690 UINT uiIndex = 0; 546 UINT uiIndex = 0;
@@ -733,60 +589,6 @@ UINT BcmGetEEPROMSize(PMINI_ADAPTER Adapter)
733 return 0; 589 return 0;
734} 590}
735 591
736#if 0
737/***********************************************************************************/
738//
739// WriteBeceemEEPROM: Writes 4 byte data to EEPROM offset.
740//
741// uiEEPROMOffset - Offset to be written to.
742// uiData - Data to be written.
743//
744/***********************************************************************************/
745
746INT WriteBeceemEEPROM(PMINI_ADAPTER Adapter,UINT uiEEPROMOffset, UINT uiData)
747{
748 INT Status = 0;
749 ULONG ulRdBk = 0;
750 ULONG ulRetryCount = 3;
751 UINT value;
752
753 if(uiEEPROMOffset > EEPROM_END)
754 {
755
756 return -1;
757 }
758
759 uiData = htonl(uiData);
760 while(ulRetryCount--)
761 {
762 value = 0x06000000;
763 wrmalt(Adapter, 0x0F003018,&value, sizeof(value));//flush the EEPROM FIFO.
764 wrmalt(Adapter, 0x0F00301C,&uiData, sizeof(uiData));
765 value = 0x3A000000 | uiEEPROMOffset;
766 wrmalt(Adapter, 0x0F003018,&value, sizeof(value));
767 __udelay(100000);
768 //read back and verify.
769 Status = ReadBeceemEEPROM(Adapter,uiEEPROMOffset,(UINT *)&ulRdBk);
770 if(Status == 0)
771 {
772 if(ulRdBk == uiData)
773 {
774 return Status;
775 }
776 else
777 {
778 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WriteBeceemEEPROM: Readback does not match\n");
779 }
780 }
781 else
782 {
783 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "WriteBeceemEEPROM: Readback failed\n");
784 }
785 }
786
787 return 0;
788}
789#endif
790 592
791//----------------------------------------------------------------------------- 593//-----------------------------------------------------------------------------
792// Procedure: FlashSectorErase 594// Procedure: FlashSectorErase
@@ -973,7 +775,7 @@ static INT flashWrite(
973// need not write 0xFFFFFFFF because write requires an erase and erase will 775// need not write 0xFFFFFFFF because write requires an erase and erase will
974// make whole sector 0xFFFFFFFF. 776// make whole sector 0xFFFFFFFF.
975// 777//
976 if (!OsalMemCompare(pData, uiErasePattern, MAX_RW_SIZE)) 778 if (!memcmp(pData, uiErasePattern, MAX_RW_SIZE))
977 { 779 {
978 return 0; 780 return 0;
979 } 781 }
@@ -1138,7 +940,7 @@ static INT flashWriteStatus(
1138// need not write 0xFFFFFFFF because write requires an erase and erase will 940// need not write 0xFFFFFFFF because write requires an erase and erase will
1139// make whole sector 0xFFFFFFFF. 941// make whole sector 0xFFFFFFFF.
1140// 942//
1141 if (!OsalMemCompare(pData,uiErasePattern,MAX_RW_SIZE)) 943 if (!memcmp(pData,uiErasePattern,MAX_RW_SIZE))
1142 { 944 {
1143 return 0; 945 return 0;
1144 } 946 }
@@ -1332,7 +1134,7 @@ static ULONG BcmFlashUnProtectBlock(PMINI_ADAPTER Adapter,UINT uiOffset, UINT ui
1332// 1134//
1333//----------------------------------------------------------------------------- 1135//-----------------------------------------------------------------------------
1334 1136
1335INT BeceemFlashBulkWrite( 1137static INT BeceemFlashBulkWrite(
1336 PMINI_ADAPTER Adapter, 1138 PMINI_ADAPTER Adapter,
1337 PUINT pBuffer, 1139 PUINT pBuffer,
1338 UINT uiOffset, 1140 UINT uiOffset,
@@ -1353,15 +1155,6 @@ INT BeceemFlashBulkWrite(
1353 UINT uiTemp = 0; 1155 UINT uiTemp = 0;
1354 UINT index = 0; 1156 UINT index = 0;
1355 UINT uiPartOffset = 0; 1157 UINT uiPartOffset = 0;
1356 #if 0
1357 struct timeval tv1 = {0};
1358 struct timeval tv2 = {0};
1359
1360 struct timeval tr = {0};
1361 struct timeval te = {0};
1362 struct timeval tw = {0};
1363 struct timeval twv = {0};
1364 #endif
1365 1158
1366#if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS) 1159#if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
1367 Status = bcmflash_raw_write((uiOffset/FLASH_PART_SIZE),(uiOffset % FLASH_PART_SIZE),( unsigned char *)pBuffer,uiNumBytes); 1160 Status = bcmflash_raw_write((uiOffset/FLASH_PART_SIZE),(uiOffset % FLASH_PART_SIZE),( unsigned char *)pBuffer,uiNumBytes);
@@ -1377,12 +1170,9 @@ INT BeceemFlashBulkWrite(
1377 uiCurrSectOffsetAddr = uiOffset & (Adapter->uiSectorSize - 1); 1170 uiCurrSectOffsetAddr = uiOffset & (Adapter->uiSectorSize - 1);
1378 uiSectBoundary = uiSectAlignAddr + Adapter->uiSectorSize; 1171 uiSectBoundary = uiSectAlignAddr + Adapter->uiSectorSize;
1379 1172
1380 //pTempBuff = OsalMemAlloc(MAX_SECTOR_SIZE,'!MVN'); 1173 pTempBuff = kmalloc(Adapter->uiSectorSize, GFP_KERNEL);
1381 pTempBuff = OsalMemAlloc(Adapter->uiSectorSize ,"!MVN");
1382 if(NULL == pTempBuff) 1174 if(NULL == pTempBuff)
1383 {
1384 goto BeceemFlashBulkWrite_EXIT; 1175 goto BeceemFlashBulkWrite_EXIT;
1385 }
1386// 1176//
1387// check if the data to be written is overlapped accross sectors 1177// check if the data to be written is overlapped accross sectors
1388// 1178//
@@ -1399,7 +1189,6 @@ INT BeceemFlashBulkWrite(
1399 uiNumSectTobeRead++; 1189 uiNumSectTobeRead++;
1400 } 1190 }
1401 } 1191 }
1402 #if 1
1403 //Check whether Requested sector is writable or not in case of flash2x write. But if write call is 1192 //Check whether Requested sector is writable or not in case of flash2x write. But if write call is
1404 // for DSD calibration, allow it without checking of sector permission 1193 // for DSD calibration, allow it without checking of sector permission
1405 1194
@@ -1420,7 +1209,6 @@ INT BeceemFlashBulkWrite(
1420 index = index + 1 ; 1209 index = index + 1 ;
1421 } 1210 }
1422 } 1211 }
1423 #endif
1424 Adapter->SelectedChip = RESET_CHIP_SELECT; 1212 Adapter->SelectedChip = RESET_CHIP_SELECT;
1425 while(uiNumSectTobeRead) 1213 while(uiNumSectTobeRead)
1426 { 1214 {
@@ -1448,13 +1236,13 @@ INT BeceemFlashBulkWrite(
1448 if(uiNumSectTobeRead > 1) 1236 if(uiNumSectTobeRead > 1)
1449 { 1237 {
1450 1238
1451 OsalMemMove(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr)); 1239 memcpy(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1452 pcBuffer += ((uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr))); 1240 pcBuffer += ((uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr)));
1453 uiNumBytes -= (uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr)); 1241 uiNumBytes -= (uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1454 } 1242 }
1455 else 1243 else
1456 { 1244 {
1457 OsalMemMove(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiNumBytes); 1245 memcpy(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiNumBytes);
1458 } 1246 }
1459 1247
1460 if(IsFlash2x(Adapter)) 1248 if(IsFlash2x(Adapter))
@@ -1503,7 +1291,7 @@ INT BeceemFlashBulkWrite(
1503 } 1291 }
1504 else 1292 else
1505 { 1293 {
1506 if(OsalMemCompare(ucReadBk,&pTempBuff[uiIndex],MAX_RW_SIZE)) 1294 if(memcmp(ucReadBk,&pTempBuff[uiIndex],MAX_RW_SIZE))
1507 { 1295 {
1508 if(STATUS_SUCCESS != (*Adapter->fpFlashWriteWithStatusCheck)(Adapter,uiPartOffset+uiIndex,&pTempBuff[uiIndex])) 1296 if(STATUS_SUCCESS != (*Adapter->fpFlashWriteWithStatusCheck)(Adapter,uiPartOffset+uiIndex,&pTempBuff[uiIndex]))
1509 { 1297 {
@@ -1541,10 +1329,8 @@ BeceemFlashBulkWrite_EXIT:
1541 { 1329 {
1542 BcmRestoreBlockProtectStatus(Adapter,ulStatus); 1330 BcmRestoreBlockProtectStatus(Adapter,ulStatus);
1543 } 1331 }
1544 if(pTempBuff) 1332
1545 { 1333 kfree(pTempBuff);
1546 OsalMemFree(pTempBuff,Adapter->uiSectorSize);
1547 }
1548 1334
1549 Adapter->SelectedChip = RESET_CHIP_SELECT; 1335 Adapter->SelectedChip = RESET_CHIP_SELECT;
1550 return Status; 1336 return Status;
@@ -1599,14 +1385,10 @@ static INT BeceemFlashBulkWriteStatus(
1599 uiCurrSectOffsetAddr = uiOffset & (Adapter->uiSectorSize - 1); 1385 uiCurrSectOffsetAddr = uiOffset & (Adapter->uiSectorSize - 1);
1600 uiSectBoundary = uiSectAlignAddr + Adapter->uiSectorSize; 1386 uiSectBoundary = uiSectAlignAddr + Adapter->uiSectorSize;
1601 1387
1602 1388 pTempBuff = kmalloc(Adapter->uiSectorSize, GFP_KERNEL);
1603
1604// pTempBuff = OsalMemAlloc(MAX_SECTOR_SIZE,'!MVN');
1605 pTempBuff = OsalMemAlloc(Adapter->uiSectorSize,"!MVN");
1606 if(NULL == pTempBuff) 1389 if(NULL == pTempBuff)
1607 {
1608 goto BeceemFlashBulkWriteStatus_EXIT; 1390 goto BeceemFlashBulkWriteStatus_EXIT;
1609 } 1391
1610// 1392//
1611// check if the data to be written is overlapped accross sectors 1393// check if the data to be written is overlapped accross sectors
1612// 1394//
@@ -1662,13 +1444,13 @@ static INT BeceemFlashBulkWriteStatus(
1662 if(uiNumSectTobeRead > 1) 1444 if(uiNumSectTobeRead > 1)
1663 { 1445 {
1664 1446
1665 OsalMemMove(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr)); 1447 memcpy(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1666 pcBuffer += ((uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr))); 1448 pcBuffer += ((uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr)));
1667 uiNumBytes -= (uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr)); 1449 uiNumBytes -= (uiSectBoundary-(uiSectAlignAddr+uiCurrSectOffsetAddr));
1668 } 1450 }
1669 else 1451 else
1670 { 1452 {
1671 OsalMemMove(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiNumBytes); 1453 memcpy(&pTempBuff[uiCurrSectOffsetAddr],pcBuffer,uiNumBytes);
1672 } 1454 }
1673 1455
1674 if(IsFlash2x(Adapter)) 1456 if(IsFlash2x(Adapter))
@@ -1698,25 +1480,10 @@ static INT BeceemFlashBulkWriteStatus(
1698 { 1480 {
1699 for(uiIndex = 0;uiIndex < Adapter->uiSectorSize;uiIndex += MAX_RW_SIZE) 1481 for(uiIndex = 0;uiIndex < Adapter->uiSectorSize;uiIndex += MAX_RW_SIZE)
1700 { 1482 {
1701#if 0
1702 if(0 == BeceemFlashBulkRead(Adapter,uiReadBk,uiOffsetFromSectStart+uiIndex + Adapter->ulFlashCalStart ,MAX_RW_SIZE))
1703 {
1704 for(uiReadIndex = 0;uiReadIndex < 4; uiReadIndex++)
1705 {
1706 if(*((PUINT)&pTempBuff[uiIndex+uiReadIndex*4]) != uiReadBk[uiReadIndex])
1707 {
1708 Status = -1;
1709 goto BeceemFlashBulkWriteStatus_EXIT;
1710
1711 }
1712 }
1713
1714 }
1715#endif
1716 1483
1717 if(STATUS_SUCCESS == BeceemFlashBulkRead(Adapter,(PUINT)ucReadBk,uiOffsetFromSectStart+uiIndex,MAX_RW_SIZE)) 1484 if(STATUS_SUCCESS == BeceemFlashBulkRead(Adapter,(PUINT)ucReadBk,uiOffsetFromSectStart+uiIndex,MAX_RW_SIZE))
1718 { 1485 {
1719 if(OsalMemCompare(ucReadBk,&pTempBuff[uiIndex],MAX_RW_SIZE)) 1486 if(memcmp(ucReadBk,&pTempBuff[uiIndex],MAX_RW_SIZE))
1720 { 1487 {
1721 Status = STATUS_FAILURE; 1488 Status = STATUS_FAILURE;
1722 goto BeceemFlashBulkWriteStatus_EXIT; 1489 goto BeceemFlashBulkWriteStatus_EXIT;
@@ -1747,10 +1514,8 @@ BeceemFlashBulkWriteStatus_EXIT:
1747 { 1514 {
1748 BcmRestoreBlockProtectStatus(Adapter,ulStatus); 1515 BcmRestoreBlockProtectStatus(Adapter,ulStatus);
1749 } 1516 }
1750 if(pTempBuff) 1517
1751 { 1518 kfree(pTempBuff);
1752 OsalMemFree(pTempBuff,Adapter->uiSectorSize);
1753 }
1754 Adapter->SelectedChip = RESET_CHIP_SELECT; 1519 Adapter->SelectedChip = RESET_CHIP_SELECT;
1755 return Status; 1520 return Status;
1756 1521
@@ -1771,7 +1536,7 @@ BeceemFlashBulkWriteStatus_EXIT:
1771 1536
1772INT PropagateCalParamsFromEEPROMToMemory(PMINI_ADAPTER Adapter) 1537INT PropagateCalParamsFromEEPROMToMemory(PMINI_ADAPTER Adapter)
1773{ 1538{
1774 PCHAR pBuff = OsalMemAlloc(BUFFER_4K,"3MVN"); 1539 PCHAR pBuff = kmalloc(BUFFER_4K, GFP_KERNEL);
1775 UINT uiEepromSize = 0; 1540 UINT uiEepromSize = 0;
1776 UINT uiIndex = 0; 1541 UINT uiIndex = 0;
1777 UINT uiBytesToCopy = 0; 1542 UINT uiBytesToCopy = 0;
@@ -1787,14 +1552,14 @@ INT PropagateCalParamsFromEEPROMToMemory(PMINI_ADAPTER Adapter)
1787 if(0 != BeceemEEPROMBulkRead(Adapter,&uiEepromSize,EEPROM_SIZE_OFFSET,4)) 1552 if(0 != BeceemEEPROMBulkRead(Adapter,&uiEepromSize,EEPROM_SIZE_OFFSET,4))
1788 { 1553 {
1789 1554
1790 OsalMemFree(pBuff,BUFFER_4K); 1555 kfree(pBuff);
1791 return -1; 1556 return -1;
1792 } 1557 }
1793 1558
1794 uiEepromSize >>= 16; 1559 uiEepromSize >>= 16;
1795 if(uiEepromSize > 1024*1024) 1560 if(uiEepromSize > 1024*1024)
1796 { 1561 {
1797 OsalMemFree(pBuff,BUFFER_4K); 1562 kfree(pBuff);
1798 return -1; 1563 return -1;
1799 } 1564 }
1800 1565
@@ -1820,7 +1585,7 @@ INT PropagateCalParamsFromEEPROMToMemory(PMINI_ADAPTER Adapter)
1820 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC-4,&value, sizeof(value)); 1585 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC-4,&value, sizeof(value));
1821 value = 0xbeadbead; 1586 value = 0xbeadbead;
1822 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC-8,&value, sizeof(value)); 1587 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC-8,&value, sizeof(value));
1823 OsalMemFree(pBuff,MAX_RW_SIZE); 1588 kfree(pBuff);
1824 1589
1825 return Status; 1590 return Status;
1826 1591
@@ -1873,16 +1638,13 @@ INT PropagateCalParamsFromFlashToMemory(PMINI_ADAPTER Adapter)
1873 return -1; 1638 return -1;
1874 } 1639 }
1875 1640
1876 pBuff = OsalMemAlloc(uiEepromSize, 0); 1641 pBuff = kmalloc(uiEepromSize, GFP_KERNEL);
1877
1878 if ( pBuff == NULL ) 1642 if ( pBuff == NULL )
1879 {
1880 return -1; 1643 return -1;
1881 }
1882 1644
1883 if(0 != BeceemNVMRead(Adapter,(PUINT)pBuff,uiCalStartAddr, uiEepromSize)) 1645 if(0 != BeceemNVMRead(Adapter,(PUINT)pBuff,uiCalStartAddr, uiEepromSize))
1884 { 1646 {
1885 OsalMemFree(pBuff, 0); 1647 kfree(pBuff);
1886 return -1; 1648 return -1;
1887 } 1649 }
1888 1650
@@ -1905,7 +1667,7 @@ INT PropagateCalParamsFromFlashToMemory(PMINI_ADAPTER Adapter)
1905 uiBytesToCopy = MIN(BUFFER_4K,uiEepromSize); 1667 uiBytesToCopy = MIN(BUFFER_4K,uiEepromSize);
1906 } 1668 }
1907 1669
1908 OsalMemFree(pBuff, 0); 1670 kfree(pBuff);
1909 return Status; 1671 return Status;
1910 1672
1911} 1673}
@@ -1947,14 +1709,14 @@ static INT BeceemEEPROMReadBackandVerify(
1947 {// for the requests more than or equal to MAX_RW_SIZE bytes, use bulk read function to make the access faster. 1709 {// for the requests more than or equal to MAX_RW_SIZE bytes, use bulk read function to make the access faster.
1948 BeceemEEPROMBulkRead(Adapter,&auiData[0],uiOffset,MAX_RW_SIZE); 1710 BeceemEEPROMBulkRead(Adapter,&auiData[0],uiOffset,MAX_RW_SIZE);
1949 1711
1950 if(OsalMemCompare(&pBuffer[uiIndex],&auiData[0],MAX_RW_SIZE)) 1712 if(memcmp(&pBuffer[uiIndex],&auiData[0],MAX_RW_SIZE))
1951 { 1713 {
1952 // re-write 1714 // re-write
1953 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)(pBuffer+uiIndex),uiOffset,MAX_RW_SIZE,FALSE); 1715 BeceemEEPROMBulkWrite(Adapter,(PUCHAR)(pBuffer+uiIndex),uiOffset,MAX_RW_SIZE,FALSE);
1954 mdelay(3); 1716 mdelay(3);
1955 BeceemEEPROMBulkRead(Adapter,&auiData[0],uiOffset,MAX_RW_SIZE); 1717 BeceemEEPROMBulkRead(Adapter,&auiData[0],uiOffset,MAX_RW_SIZE);
1956 1718
1957 if(OsalMemCompare(&pBuffer[uiIndex],&auiData[0],MAX_RW_SIZE)) 1719 if(memcmp(&pBuffer[uiIndex],&auiData[0],MAX_RW_SIZE))
1958 { 1720 {
1959 return -1; 1721 return -1;
1960 } 1722 }
@@ -1986,7 +1748,7 @@ static INT BeceemEEPROMReadBackandVerify(
1986 else 1748 else
1987 { // Handle the reads less than 4 bytes... 1749 { // Handle the reads less than 4 bytes...
1988 uiData = 0; 1750 uiData = 0;
1989 OsalMemMove(&uiData,((PUCHAR)pBuffer)+(uiIndex*sizeof(UINT)),uiNumBytes); 1751 memcpy(&uiData,((PUCHAR)pBuffer)+(uiIndex*sizeof(UINT)),uiNumBytes);
1990 BeceemEEPROMBulkRead(Adapter,&uiRdbk,uiOffset,4); 1752 BeceemEEPROMBulkRead(Adapter,&uiRdbk,uiOffset,4);
1991 1753
1992 if(memcmp(&uiData, &uiRdbk, uiNumBytes)) 1754 if(memcmp(&uiData, &uiRdbk, uiNumBytes))
@@ -2186,7 +1948,7 @@ INT BeceemEEPROMBulkWrite(
2186 1948
2187 if(uiBytesToCopy >= (16 -uiExtraBytes)) 1949 if(uiBytesToCopy >= (16 -uiExtraBytes))
2188 { 1950 {
2189 OsalMemMove((((PUCHAR)&uiData[0])+uiExtraBytes),pBuffer,MAX_RW_SIZE- uiExtraBytes); 1951 memcpy((((PUCHAR)&uiData[0])+uiExtraBytes),pBuffer,MAX_RW_SIZE- uiExtraBytes);
2190 1952
2191 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiTempOffset ) ) 1953 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiTempOffset ) )
2192 return STATUS_FAILURE; 1954 return STATUS_FAILURE;
@@ -2197,7 +1959,7 @@ INT BeceemEEPROMBulkWrite(
2197 } 1959 }
2198 else 1960 else
2199 { 1961 {
2200 OsalMemMove((((PUCHAR)&uiData[0])+uiExtraBytes),pBuffer,uiBytesToCopy); 1962 memcpy((((PUCHAR)&uiData[0])+uiExtraBytes),pBuffer,uiBytesToCopy);
2201 1963
2202 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiTempOffset ) ) 1964 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiTempOffset ) )
2203 return STATUS_FAILURE; 1965 return STATUS_FAILURE;
@@ -2233,7 +1995,7 @@ INT BeceemEEPROMBulkWrite(
2233 // To program non 16byte aligned data, read 16byte and then update. 1995 // To program non 16byte aligned data, read 16byte and then update.
2234 // 1996 //
2235 BeceemEEPROMBulkRead(Adapter,&uiData[0],uiOffset,16); 1997 BeceemEEPROMBulkRead(Adapter,&uiData[0],uiOffset,16);
2236 OsalMemMove(&uiData[0],pBuffer+uiIndex,uiBytesToCopy); 1998 memcpy(&uiData[0],pBuffer+uiIndex,uiBytesToCopy);
2237 1999
2238 2000
2239 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiOffset ) ) 2001 if ( STATUS_FAILURE == BeceemEEPROMWritePage( Adapter, uiData, uiOffset ) )
@@ -2535,7 +2297,7 @@ INT BcmUpdateSectorSize(PMINI_ADAPTER Adapter,UINT uiSectorSize)
2535// 2297//
2536//----------------------------------------------------------------------------- 2298//-----------------------------------------------------------------------------
2537 2299
2538UINT BcmGetFlashSectorSize(PMINI_ADAPTER Adapter, UINT FlashSectorSizeSig, UINT FlashSectorSize) 2300static UINT BcmGetFlashSectorSize(PMINI_ADAPTER Adapter, UINT FlashSectorSizeSig, UINT FlashSectorSize)
2539{ 2301{
2540 UINT uiSectorSize = 0; 2302 UINT uiSectorSize = 0;
2541 UINT uiSectorSig = 0; 2303 UINT uiSectorSig = 0;
@@ -2642,20 +2404,8 @@ static INT BcmInitEEPROMQueues(PMINI_ADAPTER Adapter)
2642 2404
2643INT BcmInitNVM(PMINI_ADAPTER ps_adapter) 2405INT BcmInitNVM(PMINI_ADAPTER ps_adapter)
2644{ 2406{
2645#ifdef BCM_SHM_INTERFACE
2646#ifdef FLASH_DIRECT_ACCESS
2647 unsigned int data,data1,data2 = 1;
2648 wrm(ps_adapter, PAD_SELECT_REGISTER, &data2, 4);
2649 data1 = rdm(ps_adapter,SYS_CFG,&data,4);
2650 data1 = rdm(ps_adapter,SYS_CFG,&data,4);
2651 data2 = (data | 0x80 | 0x8000);
2652 wrm(ps_adapter,SYS_CFG, &data2,4); // over-write as Flash boot mode
2653#endif
2654 ps_adapter->eNVMType = NVM_FLASH;
2655#else
2656 BcmValidateNvmType(ps_adapter); 2407 BcmValidateNvmType(ps_adapter);
2657 BcmInitEEPROMQueues(ps_adapter); 2408 BcmInitEEPROMQueues(ps_adapter);
2658#endif
2659 2409
2660 if(ps_adapter->eNVMType == NVM_AUTODETECT) 2410 if(ps_adapter->eNVMType == NVM_AUTODETECT)
2661 { 2411 {
@@ -2684,7 +2434,7 @@ INT BcmInitNVM(PMINI_ADAPTER ps_adapter)
2684*/ 2434*/
2685/***************************************************************************/ 2435/***************************************************************************/
2686 2436
2687INT BcmGetNvmSize(PMINI_ADAPTER Adapter) 2437static INT BcmGetNvmSize(PMINI_ADAPTER Adapter)
2688{ 2438{
2689 if(Adapter->eNVMType == NVM_EEPROM) 2439 if(Adapter->eNVMType == NVM_EEPROM)
2690 { 2440 {
@@ -2708,7 +2458,7 @@ INT BcmGetNvmSize(PMINI_ADAPTER Adapter)
2708// Returns: 2458// Returns:
2709// <VOID> 2459// <VOID>
2710//----------------------------------------------------------------------------- 2460//-----------------------------------------------------------------------------
2711VOID BcmValidateNvmType(PMINI_ADAPTER Adapter) 2461static VOID BcmValidateNvmType(PMINI_ADAPTER Adapter)
2712{ 2462{
2713 2463
2714 // 2464 //
@@ -2775,7 +2525,7 @@ INT BcmAllocFlashCSStructure(PMINI_ADAPTER psAdapter)
2775 if(psAdapter->psFlash2xCSInfo == NULL) 2525 if(psAdapter->psFlash2xCSInfo == NULL)
2776 { 2526 {
2777 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0,"Can't Allocate memory for Flash 2.x"); 2527 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0,"Can't Allocate memory for Flash 2.x");
2778 bcm_kfree(psAdapter->psFlashCSInfo); 2528 kfree(psAdapter->psFlashCSInfo);
2779 return -ENOMEM; 2529 return -ENOMEM;
2780 } 2530 }
2781 2531
@@ -2783,8 +2533,8 @@ INT BcmAllocFlashCSStructure(PMINI_ADAPTER psAdapter)
2783 if(psAdapter->psFlash2xVendorInfo == NULL) 2533 if(psAdapter->psFlash2xVendorInfo == NULL)
2784 { 2534 {
2785 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0,"Can't Allocate Vendor Info Memory for Flash 2.x"); 2535 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0,"Can't Allocate Vendor Info Memory for Flash 2.x");
2786 bcm_kfree(psAdapter->psFlashCSInfo); 2536 kfree(psAdapter->psFlashCSInfo);
2787 bcm_kfree(psAdapter->psFlash2xCSInfo); 2537 kfree(psAdapter->psFlash2xCSInfo);
2788 return -ENOMEM; 2538 return -ENOMEM;
2789 } 2539 }
2790 2540
@@ -2798,9 +2548,9 @@ INT BcmDeAllocFlashCSStructure(PMINI_ADAPTER psAdapter)
2798 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0," Adapter structure point is NULL"); 2548 BCM_DEBUG_PRINT(psAdapter,DBG_TYPE_PRINTK, 0, 0," Adapter structure point is NULL");
2799 return -EINVAL; 2549 return -EINVAL;
2800 } 2550 }
2801 bcm_kfree(psAdapter->psFlashCSInfo); 2551 kfree(psAdapter->psFlashCSInfo);
2802 bcm_kfree(psAdapter->psFlash2xCSInfo); 2552 kfree(psAdapter->psFlash2xCSInfo);
2803 bcm_kfree(psAdapter->psFlash2xVendorInfo); 2553 kfree(psAdapter->psFlash2xVendorInfo);
2804 return STATUS_SUCCESS ; 2554 return STATUS_SUCCESS ;
2805} 2555}
2806 2556
@@ -2954,7 +2704,7 @@ static INT ConvertEndianOfCSStructure(PFLASH_CS_INFO psFlashCSInfo)
2954 return STATUS_SUCCESS; 2704 return STATUS_SUCCESS;
2955} 2705}
2956 2706
2957INT IsSectionExistInVendorInfo(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section) 2707static INT IsSectionExistInVendorInfo(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section)
2958{ 2708{
2959 return ( Adapter->uiVendorExtnFlag && 2709 return ( Adapter->uiVendorExtnFlag &&
2960 (Adapter->psFlash2xVendorInfo->VendorSection[section].AccessFlags & FLASH2X_SECTION_PRESENT) && 2710 (Adapter->psFlash2xVendorInfo->VendorSection[section].AccessFlags & FLASH2X_SECTION_PRESENT) &&
@@ -3052,7 +2802,7 @@ static VOID UpdateVendorInfo(PMINI_ADAPTER Adapter)
3052// <VOID> 2802// <VOID>
3053//----------------------------------------------------------------------------- 2803//-----------------------------------------------------------------------------
3054 2804
3055INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter) 2805static INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter)
3056{ 2806{
3057 //FLASH_CS_INFO sFlashCsInfo = {0}; 2807 //FLASH_CS_INFO sFlashCsInfo = {0};
3058 2808
@@ -3070,7 +2820,6 @@ INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter)
3070 memset(Adapter->psFlashCSInfo, 0 ,sizeof(FLASH_CS_INFO)); 2820 memset(Adapter->psFlashCSInfo, 0 ,sizeof(FLASH_CS_INFO));
3071 memset(Adapter->psFlash2xCSInfo, 0 ,sizeof(FLASH2X_CS_INFO)); 2821 memset(Adapter->psFlash2xCSInfo, 0 ,sizeof(FLASH2X_CS_INFO));
3072 2822
3073#ifndef BCM_SHM_INTERFACE
3074 if(!Adapter->bDDRInitDone) 2823 if(!Adapter->bDDRInitDone)
3075 { 2824 {
3076 { 2825 {
@@ -3079,7 +2828,6 @@ INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter)
3079 } 2828 }
3080 } 2829 }
3081 2830
3082#endif
3083 2831
3084 // Reading first 8 Bytes to get the Flash Layout 2832 // Reading first 8 Bytes to get the Flash Layout
3085 // MagicNumber(4 bytes) +FlashLayoutMinorVersion(2 Bytes) +FlashLayoutMajorVersion(2 Bytes) 2833 // MagicNumber(4 bytes) +FlashLayoutMinorVersion(2 Bytes) +FlashLayoutMajorVersion(2 Bytes)
@@ -3147,9 +2895,7 @@ INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter)
3147 return STATUS_FAILURE; 2895 return STATUS_FAILURE;
3148 } 2896 }
3149 ConvertEndianOf2XCSStructure(Adapter->psFlash2xCSInfo); 2897 ConvertEndianOf2XCSStructure(Adapter->psFlash2xCSInfo);
3150#ifndef BCM_SHM_INTERFACE
3151 BcmDumpFlash2XCSStructure(Adapter->psFlash2xCSInfo,Adapter); 2898 BcmDumpFlash2XCSStructure(Adapter->psFlash2xCSInfo,Adapter);
3152#endif
3153 if((FLASH_CONTROL_STRUCT_SIGNATURE == Adapter->psFlash2xCSInfo->MagicNumber) && 2899 if((FLASH_CONTROL_STRUCT_SIGNATURE == Adapter->psFlash2xCSInfo->MagicNumber) &&
3154 (SCSI_FIRMWARE_MINOR_VERSION <= MINOR_VERSION(Adapter->psFlash2xCSInfo->SCSIFirmwareVersion)) && 2900 (SCSI_FIRMWARE_MINOR_VERSION <= MINOR_VERSION(Adapter->psFlash2xCSInfo->SCSIFirmwareVersion)) &&
3155 (FLASH_SECTOR_SIZE_SIG == Adapter->psFlash2xCSInfo->FlashSectorSizeSig) && 2901 (FLASH_SECTOR_SIZE_SIG == Adapter->psFlash2xCSInfo->FlashSectorSizeSig) &&
@@ -3181,21 +2927,10 @@ INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter)
3181 Concerns: what if CS sector size does not match with this sector size ??? 2927 Concerns: what if CS sector size does not match with this sector size ???
3182 what is the indication of AccessBitMap in CS in flash 2.x ???? 2928 what is the indication of AccessBitMap in CS in flash 2.x ????
3183 */ 2929 */
3184#ifndef BCM_SHM_INTERFACE
3185 Adapter->ulFlashID = BcmReadFlashRDID(Adapter); 2930 Adapter->ulFlashID = BcmReadFlashRDID(Adapter);
3186#endif
3187 2931
3188 Adapter->uiFlashLayoutMajorVersion = uiFlashLayoutMajorVersion; 2932 Adapter->uiFlashLayoutMajorVersion = uiFlashLayoutMajorVersion;
3189 2933
3190 #if 0
3191 if(FLASH_PART_SST25VF080B == Adapter->ulFlashID)
3192 {
3193 //
3194 // 1MB flash has been selected. we have to use 64K as sector size no matter what is kept in FLASH_CS.
3195 //
3196 Adapter->uiSectorSize = 0x10000;
3197 }
3198 #endif
3199 2934
3200 return STATUS_SUCCESS ; 2935 return STATUS_SUCCESS ;
3201} 2936}
@@ -3214,7 +2949,7 @@ INT BcmGetFlashCSInfo(PMINI_ADAPTER Adapter)
3214// 2949//
3215//----------------------------------------------------------------------------- 2950//-----------------------------------------------------------------------------
3216 2951
3217NVM_TYPE BcmGetNvmType(PMINI_ADAPTER Adapter) 2952static NVM_TYPE BcmGetNvmType(PMINI_ADAPTER Adapter)
3218{ 2953{
3219 UINT uiData = 0; 2954 UINT uiData = 0;
3220 2955
@@ -3569,39 +3304,6 @@ INT BcmFlash2xBulkWrite(
3569} 3304}
3570 3305
3571/** 3306/**
3572* ReadDSDHeader : Read the DSD map for the DSD Section val provided in Argument.
3573* @Adapter : Beceem Private Data Structure
3574* @psDSDHeader :Pointer of the buffer where header has to be read
3575* @dsd :value of the Dyanmic DSD like DSD0 of DSD1 or DSD2
3576*
3577* Return Value:-
3578* if suceeds return STATUS_SUCCESS or negative error code.
3579**/
3580INT ReadDSDHeader(PMINI_ADAPTER Adapter, PDSD_HEADER psDSDHeader, FLASH2X_SECTION_VAL dsd)
3581{
3582 INT Status = STATUS_SUCCESS;
3583
3584 Status =BcmFlash2xBulkRead(Adapter,
3585 (PUINT)psDSDHeader,
3586 dsd,
3587 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader,
3588 sizeof(DSD_HEADER));
3589 if(Status == STATUS_SUCCESS)
3590 {
3591 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImageMagicNumber :0X%x", ntohl(psDSDHeader->DSDImageMagicNumber));
3592 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImageSize :0X%x ",ntohl(psDSDHeader->DSDImageSize));
3593 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImageCRC :0X%x",ntohl(psDSDHeader->DSDImageCRC));
3594 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSDImagePriority :0X%x",ntohl(psDSDHeader->DSDImagePriority));
3595 }
3596 else
3597 {
3598 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"DSD Header read is failed with status :%d", Status);
3599 }
3600
3601 return Status;
3602}
3603
3604/**
3605* BcmGetActiveDSD : Set the Active DSD in Adapter Structure which has to be dumped in DDR 3307* BcmGetActiveDSD : Set the Active DSD in Adapter Structure which has to be dumped in DDR
3606* @Adapter :-Drivers private Data Structure 3308* @Adapter :-Drivers private Data Structure
3607* 3309*
@@ -3609,7 +3311,7 @@ INT ReadDSDHeader(PMINI_ADAPTER Adapter, PDSD_HEADER psDSDHeader, FLASH2X_SECTIO
3609* Return STATUS_SUCESS if get sucess in setting the right DSD else negaive error code 3311* Return STATUS_SUCESS if get sucess in setting the right DSD else negaive error code
3610* 3312*
3611**/ 3313**/
3612INT BcmGetActiveDSD(PMINI_ADAPTER Adapter) 3314static INT BcmGetActiveDSD(PMINI_ADAPTER Adapter)
3613{ 3315{
3614 FLASH2X_SECTION_VAL uiHighestPriDSD = 0 ; 3316 FLASH2X_SECTION_VAL uiHighestPriDSD = 0 ;
3615 3317
@@ -3647,39 +3349,6 @@ INT BcmGetActiveDSD(PMINI_ADAPTER Adapter)
3647 return STATUS_SUCCESS; 3349 return STATUS_SUCCESS;
3648} 3350}
3649 3351
3650/**
3651* ReadISOUnReservedBytes : Read the ISO map for the ISO Section val provided in Argument.
3652* @Adapter : Driver Private Data Structure
3653* @psISOHeader :Pointer of the location where header has to be read
3654* @IsoImage :value of the Dyanmic ISO like ISO_IMAGE1 of ISO_IMAGE2
3655*
3656* Return Value:-
3657* if suceeds return STATUS_SUCCESS or negative error code.
3658**/
3659
3660INT ReadISOHeader(PMINI_ADAPTER Adapter, PISO_HEADER psISOHeader, FLASH2X_SECTION_VAL IsoImage)
3661{
3662 INT Status = STATUS_SUCCESS;
3663
3664 Status = BcmFlash2xBulkRead(Adapter,
3665 (PUINT)psISOHeader,
3666 IsoImage,
3667 0,
3668 sizeof(ISO_HEADER));
3669
3670 if(Status == STATUS_SUCCESS)
3671 {
3672 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImageMagicNumber :0X%x", ntohl(psISOHeader->ISOImageMagicNumber));
3673 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImageSize :0X%x ",ntohl(psISOHeader->ISOImageSize));
3674 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImageCRC :0X%x",ntohl(psISOHeader->ISOImageCRC));
3675 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISOImagePriority :0X%x",ntohl(psISOHeader->ISOImagePriority));
3676 }
3677 else
3678 {
3679 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "ISO Header Read failed");
3680 }
3681 return Status;
3682}
3683 3352
3684/** 3353/**
3685* BcmGetActiveISO :- Set the Active ISO in Adapter Data Structue 3354* BcmGetActiveISO :- Set the Active ISO in Adapter Data Structue
@@ -3691,7 +3360,7 @@ INT ReadISOHeader(PMINI_ADAPTER Adapter, PISO_HEADER psISOHeader, FLASH2X_SECTIO
3691* 3360*
3692**/ 3361**/
3693 3362
3694INT BcmGetActiveISO(PMINI_ADAPTER Adapter) 3363static INT BcmGetActiveISO(PMINI_ADAPTER Adapter)
3695{ 3364{
3696 3365
3697 INT HighestPriISO = 0 ; 3366 INT HighestPriISO = 0 ;
@@ -4588,7 +4257,7 @@ INT BcmCopyISO(PMINI_ADAPTER Adapter, FLASH2X_COPY_SECTION sCopySectStrut)
4588 4257
4589 } 4258 }
4590 4259
4591 bcm_kfree(Buff); 4260 kfree(Buff);
4592 4261
4593 return Status; 4262 return Status;
4594} 4263}
@@ -4789,7 +4458,7 @@ Return Value:-
4789 Success :- Base Address of the Flash 4458 Success :- Base Address of the Flash
4790**/ 4459**/
4791 4460
4792INT GetFlashBaseAddr(PMINI_ADAPTER Adapter) 4461static INT GetFlashBaseAddr(PMINI_ADAPTER Adapter)
4793{ 4462{
4794 4463
4795 UINT uiBaseAddr = 0; 4464 UINT uiBaseAddr = 0;
@@ -4866,20 +4535,6 @@ INT BcmCopySection(PMINI_ADAPTER Adapter,
4866 return -EINVAL; 4535 return -EINVAL;
4867 } 4536 }
4868 4537
4869 #if 0
4870 else
4871 {
4872 if((SrcSection == VSA0) || (SrcSection == VSA1) || (SrcSection == VSA2))
4873 {
4874 if((DstSection != VSA0) && (DstSection != VSA1) && (DstSection != VSA2))
4875 {
4876 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Source and Destion secton is not of same type");
4877 return -EINVAL;
4878 }
4879 }
4880
4881 }
4882 #endif
4883 //if offset zero means have to copy complete secton 4538 //if offset zero means have to copy complete secton
4884 4539
4885 if(numOfBytes == 0) 4540 if(numOfBytes == 0)
@@ -4954,7 +4609,7 @@ INT BcmCopySection(PMINI_ADAPTER Adapter,
4954 BytesToBeCopied = numOfBytes; 4609 BytesToBeCopied = numOfBytes;
4955 } 4610 }
4956 }while(numOfBytes > 0) ; 4611 }while(numOfBytes > 0) ;
4957 bcm_kfree(pBuff); 4612 kfree(pBuff);
4958 Adapter->bHeaderChangeAllowed = FALSE ; 4613 Adapter->bHeaderChangeAllowed = FALSE ;
4959 return Status; 4614 return Status;
4960} 4615}
@@ -4979,14 +4634,6 @@ INT SaveHeaderIfPresent(PMINI_ADAPTER Adapter, PUCHAR pBuff, UINT uiOffset)
4979 UINT uiSectAlignAddr = 0; 4634 UINT uiSectAlignAddr = 0;
4980 UINT sig = 0; 4635 UINT sig = 0;
4981 4636
4982 #if 0
4983 //if Chenges in Header is allowed, Return back
4984 if(Adapter->bHeaderChangeAllowed == TRUE)
4985 {
4986 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Header Change is allowed");
4987 return STATUS_SUCCESS ;
4988 }
4989 #endif
4990 //making the offset sector alligned 4637 //making the offset sector alligned
4991 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1); 4638 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
4992 4639
@@ -5024,7 +4671,7 @@ INT SaveHeaderIfPresent(PMINI_ADAPTER Adapter, PUCHAR pBuff, UINT uiOffset)
5024 //Replace Buffer content with Header 4671 //Replace Buffer content with Header
5025 memcpy(pBuff +offsetToProtect,pTempBuff,HeaderSizeToProtect); 4672 memcpy(pBuff +offsetToProtect,pTempBuff,HeaderSizeToProtect);
5026 4673
5027 bcm_kfree(pTempBuff); 4674 kfree(pTempBuff);
5028 } 4675 }
5029 if(bHasHeader && Adapter->bSigCorrupted) 4676 if(bHasHeader && Adapter->bSigCorrupted)
5030 { 4677 {
@@ -5044,29 +4691,7 @@ INT SaveHeaderIfPresent(PMINI_ADAPTER Adapter, PUCHAR pBuff, UINT uiOffset)
5044 4691
5045 return STATUS_SUCCESS ; 4692 return STATUS_SUCCESS ;
5046} 4693}
5047INT BcmMakeFlashCSActive(PMINI_ADAPTER Adapter, UINT offset)
5048{
5049 UINT GPIOConfig = 0 ;
5050
5051
5052 if(Adapter->bFlashRawRead == FALSE)
5053 {
5054 //Applicable for Flash2.x
5055 if(IsFlash2x(Adapter) == FALSE)
5056 return STATUS_SUCCESS;
5057 }
5058 4694
5059 if(offset/FLASH_PART_SIZE)
5060 {
5061 //bit[14..12] -> will select make Active CS1, CS2 or CS3
5062 // Select CS1, CS2 and CS3 (CS0 is dedicated pin)
5063 rdmalt(Adapter,FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
5064 GPIOConfig |= (7 << 12);
5065 wrmalt(Adapter,FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
5066 }
5067
5068 return STATUS_SUCCESS ;
5069}
5070/** 4695/**
5071BcmDoChipSelect : This will selcet the appropriate chip for writing. 4696BcmDoChipSelect : This will selcet the appropriate chip for writing.
5072@Adapater :- Bcm Driver Private Data Structure 4697@Adapater :- Bcm Driver Private Data Structure
@@ -5074,7 +4699,7 @@ BcmDoChipSelect : This will selcet the appropriate chip for writing.
5074OutPut:- 4699OutPut:-
5075 Select the Appropriate chip and retrn status Sucess 4700 Select the Appropriate chip and retrn status Sucess
5076**/ 4701**/
5077INT BcmDoChipSelect(PMINI_ADAPTER Adapter, UINT offset) 4702static INT BcmDoChipSelect(PMINI_ADAPTER Adapter, UINT offset)
5078{ 4703{
5079 UINT FlashConfig = 0; 4704 UINT FlashConfig = 0;
5080 INT ChipNum = 0; 4705 INT ChipNum = 0;
@@ -5365,39 +4990,6 @@ INT WriteToFlashWithoutSectorErase(PMINI_ADAPTER Adapter,
5365 return Status; 4990 return Status;
5366} 4991}
5367 4992
5368#if 0
5369UINT getNumOfSubSectionWithWRPermisson(PMINI_ADAPTER Adapter, SECTION_TYPE secType)
5370{
5371
5372 UINT numOfWRSubSec = 0;
5373 switch(secType)
5374 {
5375 case ISO :
5376 if(IsSectionWritable(Adapter,ISO_IMAGE1))
5377 numOfWRSubSec = numOfWRSubSec + 1;
5378 if(IsSectionWritable(Adapter,ISO_IMAGE2))
5379 numOfWRSubSec = numOfWRSubSec + 1;
5380 break;
5381
5382 case DSD :
5383 if(IsSectionWritable(Adapter,DSD2))
5384 numOfWRSubSec = numOfWRSubSec + 1;
5385 if(IsSectionWritable(Adapter,DSD1))
5386 numOfWRSubSec = numOfWRSubSec + 1;
5387 if(IsSectionWritable(Adapter,DSD0))
5388 numOfWRSubSec = numOfWRSubSec + 1;
5389 break ;
5390
5391 case VSA :
5392 //for VSA Add code Here
5393 default :
5394 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Invalid secton<%d> is passed", secType);\
5395 numOfWRSubSec = 0;
5396
5397 }
5398 return numOfWRSubSec;
5399}
5400#endif
5401BOOLEAN IsSectionExistInFlash(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section) 4993BOOLEAN IsSectionExistInFlash(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL section)
5402{ 4994{
5403 4995
@@ -5479,7 +5071,7 @@ INT IsSectionWritable(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL Section)
5479 return Status ; 5071 return Status ;
5480} 5072}
5481 5073
5482INT CorruptDSDSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal) 5074static INT CorruptDSDSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
5483{ 5075{
5484 5076
5485 PUCHAR pBuff = NULL; 5077 PUCHAR pBuff = NULL;
@@ -5543,16 +5135,16 @@ INT CorruptDSDSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
5543 else 5135 else
5544 { 5136 {
5545 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"BCM Signature is not present in header"); 5137 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"BCM Signature is not present in header");
5546 bcm_kfree(pBuff); 5138 kfree(pBuff);
5547 return STATUS_FAILURE; 5139 return STATUS_FAILURE;
5548 } 5140 }
5549 5141
5550 bcm_kfree(pBuff); 5142 kfree(pBuff);
5551 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Corrupted the signature"); 5143 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Corrupted the signature");
5552 return STATUS_SUCCESS ; 5144 return STATUS_SUCCESS ;
5553} 5145}
5554 5146
5555INT CorruptISOSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal) 5147static INT CorruptISOSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
5556{ 5148{
5557 5149
5558 PUCHAR pBuff = NULL; 5150 PUCHAR pBuff = NULL;
@@ -5593,14 +5185,14 @@ INT CorruptISOSig(PMINI_ADAPTER Adapter, FLASH2X_SECTION_VAL eFlash2xSectionVal)
5593 else 5185 else
5594 { 5186 {
5595 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"BCM Signature is not present in header"); 5187 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"BCM Signature is not present in header");
5596 bcm_kfree(pBuff); 5188 kfree(pBuff);
5597 return STATUS_FAILURE; 5189 return STATUS_FAILURE;
5598 } 5190 }
5599 5191
5600 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Corrupted the signature"); 5192 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,"Corrupted the signature");
5601 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,pBuff,MAX_RW_SIZE); 5193 BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL,pBuff,MAX_RW_SIZE);
5602 5194
5603 bcm_kfree(pBuff); 5195 kfree(pBuff);
5604 return STATUS_SUCCESS ; 5196 return STATUS_SUCCESS ;
5605} 5197}
5606 5198
diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h
index 6ec6ca85b501..651b5a455b32 100644
--- a/drivers/staging/bcm/nvm.h
+++ b/drivers/staging/bcm/nvm.h
@@ -323,15 +323,6 @@ typedef struct _ISO_HEADER
323 323
324 324
325 325
326#ifdef BCM_SHM_INTERFACE
327
328#define FLASH_ADDR_MASK 0x1F000000
329extern int bcmflash_raw_read(unsigned int flash_id, unsigned int offset, unsigned char *inbuf, unsigned int len);
330extern int bcmflash_raw_write(unsigned int flash_id, unsigned int offset, unsigned char *outbuf, unsigned int len);
331extern int bcmflash_raw_writenoerase(unsigned int flash_id, unsigned int offset, unsigned char *outbuf, unsigned int len);
332
333
334#endif
335 326
336#define FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT 0x1C000000 327#define FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT 0x1C000000
337#define FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT 0x1F000000 328#define FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT 0x1F000000
@@ -414,76 +405,5 @@ extern int bcmflash_raw_writenoerase(unsigned int flash_id, unsigned int offset,
414 405
415#define FIELD_OFFSET_IN_HEADER(HeaderPointer,Field) ((PUCHAR)&((HeaderPointer)(NULL))->Field - (PUCHAR)(NULL)) 406#define FIELD_OFFSET_IN_HEADER(HeaderPointer,Field) ((PUCHAR)&((HeaderPointer)(NULL))->Field - (PUCHAR)(NULL))
416 407
417#if 0
418INT BeceemEEPROMBulkRead(
419 PMINI_ADAPTER Adapter,
420 PUINT pBuffer,
421 UINT uiOffset,
422 UINT uiNumBytes);
423
424
425INT BeceemFlashBulkRead(
426 PMINI_ADAPTER Adapter,
427 PUINT pBuffer,
428 UINT uiOffset,
429 UINT uiNumBytes);
430
431UINT BcmGetEEPROMSize(PMINI_ADAPTER Adapter);
432
433UINT BcmGetFlashSize(PMINI_ADAPTER Adapter);
434
435UINT BcmGetFlashSectorSize(PMINI_ADAPTER Adapter);
436
437
438
439INT BeceemFlashBulkWrite(
440 PMINI_ADAPTER Adapter,
441 PUINT pBuffer,
442 UINT uiOffset,
443 UINT uiNumBytes,
444 BOOLEAN bVerify);
445
446INT PropagateCalParamsFromFlashToMemory(PMINI_ADAPTER Adapter);
447
448INT PropagateCalParamsFromEEPROMToMemory(PMINI_ADAPTER Adapter);
449
450
451INT BeceemEEPROMBulkWrite(
452 PMINI_ADAPTER Adapter,
453 PUCHAR pBuffer,
454 UINT uiOffset,
455 UINT uiNumBytes,
456 BOOLEAN bVerify);
457
458
459INT ReadBeceemEEPROM(PMINI_ADAPTER Adapter,UINT dwAddress, UINT *pdwData);
460
461NVM_TYPE BcmGetNvmType(PMINI_ADAPTER Adapter);
462
463INT BeceemNVMRead(
464 PMINI_ADAPTER Adapter,
465 PUINT pBuffer,
466 UINT uiOffset,
467 UINT uiNumBytes);
468
469INT BeceemNVMWrite(
470 PMINI_ADAPTER Adapter,
471 PUINT pBuffer,
472 UINT uiOffset,
473 UINT uiNumBytes,
474 BOOLEAN bVerify);
475
476INT ReadMacAddressFromEEPROM(PMINI_ADAPTER Adapter);
477
478INT BcmUpdateSectorSize(PMINI_ADAPTER Adapter,UINT uiSectorSize);
479
480INT BcmInitNVM(PMINI_ADAPTER Adapter);
481
482VOID BcmValidateNvmType(PMINI_ADAPTER Adapter);
483
484VOID BcmGetFlashCSInfo(PMINI_ADAPTER Adapter);
485
486#endif
487
488#endif 408#endif
489 409
diff --git a/drivers/staging/bcm/osal_misc.h b/drivers/staging/bcm/osal_misc.h
deleted file mode 100644
index ff4adde17cd8..000000000000
--- a/drivers/staging/bcm/osal_misc.h
+++ /dev/null
@@ -1,49 +0,0 @@
1 /*++
2
3 Copyright (c) Beceem Communications Inc.
4
5 Module Name:
6 OSAL_Misc.h
7
8 Abstract:
9 Provides the OS Abstracted macros to access:
10 Linked Lists
11 Dispatcher Objects(Events,Semaphores,Spin Locks and the like)
12 Files
13
14
15 Revision History:
16 Who When What
17 -------- -------- ----------------------------------------------
18 Name Date Created/reviewed/modified
19 Rajeev 24/1/08 Created
20 Notes:
21
22 --*/
23#ifndef _OSAL_MISC_H_
24#define _OSAL_MISC_H_
25//OSAL Macros
26//OSAL Primitives
27typedef PUCHAR POSAL_NW_PACKET ; //Nw packets
28
29
30#define OsalMemAlloc(n,t) kmalloc(n,GFP_KERNEL)
31
32#define OsalMemFree(x,n) bcm_kfree(x)
33
34#define OsalMemMove(dest, src, len) \
35{ \
36 memcpy(dest,src, len); \
37}
38
39#define OsalZeroMemory(pDest, Len) \
40{ \
41 memset(pDest,0,Len); \
42}
43
44//#define OsalMemSet(pSrc,Char,Len) memset(pSrc,Char,Len)
45
46bool OsalMemCompare(void *dest, void *src, UINT len);
47
48#endif
49
diff --git a/drivers/staging/brcm80211/README b/drivers/staging/brcm80211/README
index a27bb0b4f581..99e67669f26b 100644
--- a/drivers/staging/brcm80211/README
+++ b/drivers/staging/brcm80211/README
@@ -43,14 +43,8 @@ Firmware is available from the Linux firmware repository at:
43 http://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git 43 http://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git
44 https://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git 44 https://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git
45 45
46For all chips, copy brcm/bcm43xx-0-610-809-0.fw and 46For all chips, copy brcm/bcm43xx-0.fw and brcm/bcm43xx_hdr-0.fw to
47brcm/bcm43xx_hdr-0-610-809-0.fw to /lib/firmware/brcm (or wherever firmware is 47/lib/firmware/brcm (or wherever firmware is normally installed on your system).
48normally installed on the system). In the /lib/firmware/brcm directory, then
49create the following symlinks:
50
51 ln -s bcm43xx-0-610-809-0.fw bcm43xx-0.fw
52 ln -s bcm43xx_hdr-0-610-809-0.fw bcm43xx_hdr-0.fw
53
54 48
55Currently supported chips 49Currently supported chips
56============== 50==============
diff --git a/drivers/staging/brcm80211/brcmfmac/README b/drivers/staging/brcm80211/brcmfmac/README
index 43601fa8b17e..be29e4236920 100644
--- a/drivers/staging/brcm80211/brcmfmac/README
+++ b/drivers/staging/brcm80211/brcmfmac/README
@@ -25,8 +25,9 @@ Firmware is available from the Linux firmware repository at:
25 http://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git 25 http://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git
26 https://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git 26 https://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git
27 27
28For 4329 chip, copy brcm/bcm4329-fullmac-4-218-248-5.bin and 28For 4329 chip, copy brcm/bcm4329-fullmac-4.bin and brcm/bcm4329-fullmac-4.txt
29bcm4329-fullmac-4-218-248-5.txt to /lib/firmware/brcm 29to /lib/firmware/brcm (or wherever firmware is normally installed on your
30system).
30 31
31Contact Info: 32Contact Info:
32============= 33=============
diff --git a/drivers/staging/brcm80211/brcmfmac/bcmsdh.c b/drivers/staging/brcm80211/brcmfmac/bcmsdh.c
index 4c613da3553a..acf43a365081 100644
--- a/drivers/staging/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/staging/brcm80211/brcmfmac/bcmsdh.c
@@ -16,13 +16,14 @@
16/* ****************** BCMSDH Interface Functions *************************** */ 16/* ****************** BCMSDH Interface Functions *************************** */
17 17
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/netdevice.h>
19#include <bcmdefs.h> 20#include <bcmdefs.h>
20#include <bcmdevs.h> 21#include <bcmdevs.h>
21#include <bcmendian.h> 22#include <bcmendian.h>
23#include <osl.h>
22#include <bcmutils.h> 24#include <bcmutils.h>
23#include <hndsoc.h> 25#include <hndsoc.h>
24#include <siutils.h> 26#include <siutils.h>
25#include <osl.h>
26 27
27#include <bcmsdh.h> /* BRCM API for SDIO 28#include <bcmsdh.h> /* BRCM API for SDIO
28 clients (such as wl, dhd) */ 29 clients (such as wl, dhd) */
@@ -38,7 +39,7 @@ struct bcmsdh_info {
38 bool init_success; /* underlying driver successfully attached */ 39 bool init_success; /* underlying driver successfully attached */
39 void *sdioh; /* handler for sdioh */ 40 void *sdioh; /* handler for sdioh */
40 u32 vendevid; /* Target Vendor and Device ID on SD bus */ 41 u32 vendevid; /* Target Vendor and Device ID on SD bus */
41 osl_t *osh; 42 struct osl_info *osh;
42 bool regfail; /* Save status of last 43 bool regfail; /* Save status of last
43 reg_read/reg_write call */ 44 reg_read/reg_write call */
44 u32 sbwad; /* Save backplane window address */ 45 u32 sbwad; /* Save backplane window address */
@@ -55,7 +56,8 @@ void bcmsdh_enable_hw_oob_intr(bcmsdh_info_t *sdh, bool enable)
55} 56}
56#endif 57#endif
57 58
58bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva, uint irq) 59bcmsdh_info_t *bcmsdh_attach(struct osl_info *osh, void *cfghdl,
60 void **regsva, uint irq)
59{ 61{
60 bcmsdh_info_t *bcmsdh; 62 bcmsdh_info_t *bcmsdh;
61 63
@@ -84,7 +86,7 @@ bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva, uint irq)
84 return bcmsdh; 86 return bcmsdh;
85} 87}
86 88
87int bcmsdh_detach(osl_t *osh, void *sdh) 89int bcmsdh_detach(struct osl_info *osh, void *sdh)
88{ 90{
89 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; 91 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
90 92
@@ -451,7 +453,7 @@ bool bcmsdh_regfail(void *sdh)
451 453
452int 454int
453bcmsdh_recv_buf(void *sdh, u32 addr, uint fn, uint flags, 455bcmsdh_recv_buf(void *sdh, u32 addr, uint fn, uint flags,
454 u8 *buf, uint nbytes, void *pkt, 456 u8 *buf, uint nbytes, struct sk_buff *pkt,
455 bcmsdh_cmplt_fn_t complete, void *handle) 457 bcmsdh_cmplt_fn_t complete, void *handle)
456{ 458{
457 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; 459 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh;
diff --git a/drivers/staging/brcm80211/brcmfmac/bcmsdh_linux.c b/drivers/staging/brcm80211/brcmfmac/bcmsdh_linux.c
index 9028cd01d9d0..d24b5e7d753c 100644
--- a/drivers/staging/brcm80211/brcmfmac/bcmsdh_linux.c
+++ b/drivers/staging/brcm80211/brcmfmac/bcmsdh_linux.c
@@ -20,8 +20,7 @@
20 20
21#define __UNDEF_NO_VERSION__ 21#define __UNDEF_NO_VERSION__
22 22
23#include <linuxver.h> 23#include <linux/netdevice.h>
24
25#include <linux/pci.h> 24#include <linux/pci.h>
26#include <linux/completion.h> 25#include <linux/completion.h>
27 26
@@ -57,7 +56,7 @@ struct bcmsdh_hc {
57#else 56#else
58 struct pci_dev *dev; /* pci device handle */ 57 struct pci_dev *dev; /* pci device handle */
59#endif /* BCMPLATFORM_BUS */ 58#endif /* BCMPLATFORM_BUS */
60 osl_t *osh; 59 struct osl_info *osh;
61 void *regs; /* SDIO Host Controller address */ 60 void *regs; /* SDIO Host Controller address */
62 bcmsdh_info_t *sdh; /* SDIO Host Controller handle */ 61 bcmsdh_info_t *sdh; /* SDIO Host Controller handle */
63 void *ch; 62 void *ch;
@@ -139,22 +138,11 @@ static int __devexit bcmsdh_remove(struct device *dev);
139#endif /* BCMLXSDMMC */ 138#endif /* BCMLXSDMMC */
140 139
141#ifndef BCMLXSDMMC 140#ifndef BCMLXSDMMC
142static struct device_driver bcmsdh_driver = {
143 .name = "pxa2xx-mci",
144 .bus = &platform_bus_type,
145 .probe = bcmsdh_probe,
146 .remove = bcmsdh_remove,
147 .suspend = NULL,
148 .resume = NULL,
149};
150#endif /* BCMLXSDMMC */
151
152#ifndef BCMLXSDMMC
153static 141static
154#endif /* BCMLXSDMMC */ 142#endif /* BCMLXSDMMC */
155int bcmsdh_probe(struct device *dev) 143int bcmsdh_probe(struct device *dev)
156{ 144{
157 osl_t *osh = NULL; 145 struct osl_info *osh = NULL;
158 bcmsdh_hc_t *sdhc = NULL; 146 bcmsdh_hc_t *sdhc = NULL;
159 unsigned long regs = 0; 147 unsigned long regs = 0;
160 bcmsdh_info_t *sdh = NULL; 148 bcmsdh_info_t *sdh = NULL;
@@ -189,7 +177,7 @@ int bcmsdh_probe(struct device *dev)
189 } 177 }
190#endif /* defined(OOB_INTR_ONLY) */ 178#endif /* defined(OOB_INTR_ONLY) */
191 /* allocate SDIO Host Controller state info */ 179 /* allocate SDIO Host Controller state info */
192 osh = osl_attach(dev, PCI_BUS, false); 180 osh = osl_attach(dev, PCI_BUS);
193 if (!osh) { 181 if (!osh) {
194 SDLX_MSG(("%s: osl_attach failed\n", __func__)); 182 SDLX_MSG(("%s: osl_attach failed\n", __func__));
195 goto err; 183 goto err;
@@ -258,7 +246,7 @@ static
258int bcmsdh_remove(struct device *dev) 246int bcmsdh_remove(struct device *dev)
259{ 247{
260 bcmsdh_hc_t *sdhc, *prev; 248 bcmsdh_hc_t *sdhc, *prev;
261 osl_t *osh; 249 struct osl_info *osh;
262 250
263 sdhc = sdhcinfo; 251 sdhc = sdhcinfo;
264 drvinfo.detach(sdhc->ch); 252 drvinfo.detach(sdhc->ch);
@@ -291,269 +279,23 @@ int bcmsdh_remove(struct device *dev)
291 279
292 return 0; 280 return 0;
293} 281}
294
295#else /* BCMPLATFORM_BUS */
296
297#if !defined(BCMLXSDMMC)
298/* forward declarations for PCI probe and remove functions. */
299static int __devinit bcmsdh_pci_probe(struct pci_dev *pdev,
300 const struct pci_device_id *ent);
301static void __devexit bcmsdh_pci_remove(struct pci_dev *pdev);
302
303/**
304 * pci id table
305 */
306static struct pci_device_id bcmsdh_pci_devid[] __devinitdata = {
307{
308 .vendor = PCI_ANY_ID,
309 .device = PCI_ANY_ID,
310 .subvendor = PCI_ANY_ID,
311 .subdevice = PCI_ANY_ID,
312 .class = 0,
313 .class_mask = 0,
314 .driver_data = 0,
315},
316{0,}
317};
318
319MODULE_DEVICE_TABLE(pci, bcmsdh_pci_devid);
320
321/**
322 * SDIO Host Controller pci driver info
323 */
324static struct pci_driver bcmsdh_pci_driver = {
325 .node = {},
326 .name = "bcmsdh",
327 .id_table = bcmsdh_pci_devid,
328 .probe = bcmsdh_pci_probe,
329 .remove = bcmsdh_pci_remove,
330 .suspend = NULL,
331 .resume = NULL,
332};
333
334extern uint sd_pci_slot; /* Force detection to a particular PCI */
335 /* slot only . Allows for having multiple */
336 /* WL devices at once in a PC */
337 /* Only one instance of dhd will be */
338 /* usable at a time */
339 /* Upper word is bus number, */
340 /* lower word is slot number */
341 /* Default value of 0xFFFFffff turns this */
342 /* off */
343module_param(sd_pci_slot, uint, 0);
344
345/**
346 * Detect supported SDIO Host Controller and attach if found.
347 *
348 * Determine if the device described by pdev is a supported SDIO Host
349 * Controller. If so, attach to it and attach to the target device.
350 */
351static int __devinit
352bcmsdh_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
353{
354 osl_t *osh = NULL;
355 bcmsdh_hc_t *sdhc = NULL;
356 unsigned long regs;
357 bcmsdh_info_t *sdh = NULL;
358 int rc;
359
360 if (sd_pci_slot != 0xFFFFffff) {
361 if (pdev->bus->number != (sd_pci_slot >> 16) ||
362 PCI_SLOT(pdev->devfn) != (sd_pci_slot & 0xffff)) {
363 SDLX_MSG(("%s: %s: bus %X, slot %X, vend %X, dev %X\n",
364 __func__,
365 bcmsdh_chipmatch(pdev->vendor, pdev->device) ?
366 "Found compatible SDIOHC" :
367 "Probing unknown device",
368 pdev->bus->number, PCI_SLOT(pdev->devfn),
369 pdev->vendor, pdev->device));
370 return -ENODEV;
371 }
372 SDLX_MSG(("%s: %s: bus %X, slot %X, vendor %X, device %X "
373 "(good PCI location)\n", __func__,
374 bcmsdh_chipmatch(pdev->vendor, pdev->device) ?
375 "Using compatible SDIOHC" : "WARNING, forced use "
376 "of unkown device",
377 pdev->bus->number, PCI_SLOT(pdev->devfn), pdev->vendor,
378 pdev->device));
379 }
380
381 if ((pdev->vendor == VENDOR_TI)
382 && ((pdev->device == PCIXX21_FLASHMEDIA_ID)
383 || (pdev->device == PCIXX21_FLASHMEDIA0_ID))) {
384 u32 config_reg;
385
386 SDLX_MSG(("%s: Disabling TI FlashMedia Controller.\n",
387 __func__));
388 osh = osl_attach(pdev, PCI_BUS, false);
389 if (!osh) {
390 SDLX_MSG(("%s: osl_attach failed\n", __func__));
391 goto err;
392 }
393
394 config_reg = OSL_PCI_READ_CONFIG(osh, 0x4c, 4);
395
396 /*
397 * Set MMC_SD_DIS bit in FlashMedia Controller.
398 * Disbling the SD/MMC Controller in the FlashMedia Controller
399 * allows the Standard SD Host Controller to take over control
400 * of the SD Slot.
401 */
402 config_reg |= 0x02;
403 OSL_PCI_WRITE_CONFIG(osh, 0x4c, 4, config_reg);
404 osl_detach(osh);
405 }
406 /* match this pci device with what we support */
407 /* we can't solely rely on this to believe it is
408 our SDIO Host Controller! */
409 if (!bcmsdh_chipmatch(pdev->vendor, pdev->device))
410 return -ENODEV;
411
412 /* this is a pci device we might support */
413 SDLX_MSG(("%s: Found possible SDIO Host Controller: "
414 "bus %d slot %d func %d irq %d\n", __func__,
415 pdev->bus->number, PCI_SLOT(pdev->devfn),
416 PCI_FUNC(pdev->devfn), pdev->irq));
417
418 /* use bcmsdh_query_device() to get the vendor ID of the target device
419 * so it will eventually appear in the Broadcom string on the console
420 */
421
422 /* allocate SDIO Host Controller state info */
423 osh = osl_attach(pdev, PCI_BUS, false);
424 if (!osh) {
425 SDLX_MSG(("%s: osl_attach failed\n", __func__));
426 goto err;
427 }
428 sdhc = kzalloc(sizeof(bcmsdh_hc_t), GFP_ATOMIC);
429 if (!sdhc) {
430 SDLX_MSG(("%s: out of memory\n", __func__));
431 goto err;
432 }
433 sdhc->osh = osh;
434
435 sdhc->dev = pdev;
436
437 /* map to address where host can access */
438 pci_set_master(pdev);
439 rc = pci_enable_device(pdev);
440 if (rc) {
441 SDLX_MSG(("%s: Cannot enable PCI device\n", __func__));
442 goto err;
443 }
444 sdh = bcmsdh_attach(osh, (void *)(unsigned long)pci_resource_start(pdev, 0),
445 (void **)&regs, pdev->irq);
446 if (!sdh) {
447 SDLX_MSG(("%s: bcmsdh_attach failed\n", __func__));
448 goto err;
449 }
450
451 sdhc->sdh = sdh;
452
453 /* try to attach to the target device */
454 sdhc->ch = drvinfo.attach(VENDOR_BROADCOM, /* pdev->vendor, */
455 bcmsdh_query_device(sdh) & 0xFFFF, 0, 0, 0, 0,
456 (void *)regs, NULL, sdh);
457 if (!sdhc->ch) {
458 SDLX_MSG(("%s: device attach failed\n", __func__));
459 goto err;
460 }
461
462 /* chain SDIO Host Controller info together */
463 sdhc->next = sdhcinfo;
464 sdhcinfo = sdhc;
465
466 return 0;
467
468 /* error handling */
469err:
470 if (sdhc->sdh)
471 bcmsdh_detach(sdhc->osh, sdhc->sdh);
472 if (sdhc)
473 kfree(sdhc);
474 if (osh)
475 osl_detach(osh);
476 return -ENODEV;
477}
478
479/**
480 * Detach from target devices and SDIO Host Controller
481 */
482static void __devexit bcmsdh_pci_remove(struct pci_dev *pdev)
483{
484 bcmsdh_hc_t *sdhc, *prev;
485 osl_t *osh;
486
487 /* find the SDIO Host Controller state for this
488 pdev and take it out from the list */
489 for (sdhc = sdhcinfo, prev = NULL; sdhc; sdhc = sdhc->next) {
490 if (sdhc->dev == pdev) {
491 if (prev)
492 prev->next = sdhc->next;
493 else
494 sdhcinfo = NULL;
495 break;
496 }
497 prev = sdhc;
498 }
499 if (!sdhc)
500 return;
501
502 drvinfo.detach(sdhc->ch);
503
504 bcmsdh_detach(sdhc->osh, sdhc->sdh);
505
506 /* release SDIO Host Controller info */
507 osh = sdhc->osh;
508 kfree(sdhc);
509 osl_detach(osh);
510}
511#endif /* BCMLXSDMMC */
512#endif /* BCMPLATFORM_BUS */ 282#endif /* BCMPLATFORM_BUS */
513 283
514extern int sdio_function_init(void); 284extern int sdio_function_init(void);
515 285
516int bcmsdh_register(bcmsdh_driver_t *driver) 286int bcmsdh_register(bcmsdh_driver_t *driver)
517{ 287{
518 int error = 0;
519
520 drvinfo = *driver; 288 drvinfo = *driver;
521 289
522#if defined(BCMPLATFORM_BUS)
523#if defined(BCMLXSDMMC)
524 SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n")); 290 SDLX_MSG(("Linux Kernel SDIO/MMC Driver\n"));
525 error = sdio_function_init(); 291 return sdio_function_init();
526#else
527 SDLX_MSG(("Intel PXA270 SDIO Driver\n"));
528 error = driver_register(&bcmsdh_driver);
529#endif /* defined(BCMLXSDMMC) */
530 return error;
531#endif /* defined(BCMPLATFORM_BUS) */
532
533#if !defined(BCMPLATFORM_BUS) && !defined(BCMLXSDMMC)
534 error = pci_register_driver(&bcmsdh_pci_driver);
535 if (!error)
536 return 0;
537
538 SDLX_MSG(("%s: pci_register_driver failed 0x%x\n", __func__, error));
539#endif /* BCMPLATFORM_BUS */
540
541 return error;
542} 292}
543 293
544extern void sdio_function_cleanup(void); 294extern void sdio_function_cleanup(void);
545 295
546void bcmsdh_unregister(void) 296void bcmsdh_unregister(void)
547{ 297{
548#if defined(BCMPLATFORM_BUS) && !defined(BCMLXSDMMC)
549 driver_unregister(&bcmsdh_driver);
550#endif
551#if defined(BCMLXSDMMC)
552 sdio_function_cleanup(); 298 sdio_function_cleanup();
553#endif /* BCMLXSDMMC */
554#if !defined(BCMPLATFORM_BUS) && !defined(BCMLXSDMMC)
555 pci_unregister_driver(&bcmsdh_pci_driver);
556#endif /* BCMPLATFORM_BUS */
557} 299}
558 300
559#if defined(OOB_INTR_ONLY) 301#if defined(OOB_INTR_ONLY)
diff --git a/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc.c b/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc.c
index f6c9c4541813..d399b5c76f94 100644
--- a/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc.c
+++ b/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc.c
@@ -14,11 +14,12 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/netdevice.h>
17#include <bcmdefs.h> 18#include <bcmdefs.h>
18#include <bcmdevs.h> 19#include <bcmdevs.h>
19#include <bcmendian.h> 20#include <bcmendian.h>
20#include <bcmutils.h>
21#include <osl.h> 21#include <osl.h>
22#include <bcmutils.h>
22#include <sdio.h> /* SDIO Device and Protocol Specs */ 23#include <sdio.h> /* SDIO Device and Protocol Specs */
23#include <sdioh.h> /* SDIO Host Controller Specification */ 24#include <sdioh.h> /* SDIO Host Controller Specification */
24#include <bcmsdbus.h> /* bcmsdh to/from specific controller APIs */ 25#include <bcmsdbus.h> /* bcmsdh to/from specific controller APIs */
@@ -111,7 +112,7 @@ static int sdioh_sdmmc_card_enablefuncs(sdioh_info_t *sd)
111/* 112/*
112 * Public entry points & extern's 113 * Public entry points & extern's
113 */ 114 */
114extern sdioh_info_t *sdioh_attach(osl_t *osh, void *bar0, uint irq) 115extern sdioh_info_t *sdioh_attach(struct osl_info *osh, void *bar0, uint irq)
115{ 116{
116 sdioh_info_t *sd; 117 sdioh_info_t *sd;
117 int err_ret; 118 int err_ret;
@@ -174,7 +175,7 @@ extern sdioh_info_t *sdioh_attach(osl_t *osh, void *bar0, uint irq)
174 return sd; 175 return sd;
175} 176}
176 177
177extern SDIOH_API_RC sdioh_detach(osl_t *osh, sdioh_info_t *sd) 178extern SDIOH_API_RC sdioh_detach(struct osl_info *osh, sdioh_info_t *sd)
178{ 179{
179 sd_trace(("%s\n", __func__)); 180 sd_trace(("%s\n", __func__));
180 181
@@ -750,7 +751,7 @@ sdioh_cis_read(sdioh_info_t *sd, uint func, u8 *cisd, u32 length)
750 sd_trace(("%s: Func = %d\n", __func__, func)); 751 sd_trace(("%s: Func = %d\n", __func__, func));
751 752
752 if (!sd->func_cis_ptr[func]) { 753 if (!sd->func_cis_ptr[func]) {
753 bzero(cis, length); 754 memset(cis, 0, length);
754 sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func)); 755 sd_err(("%s: no func_cis_ptr[%d]\n", __func__, func));
755 return SDIOH_API_RC_FAIL; 756 return SDIOH_API_RC_FAIL;
756 } 757 }
@@ -927,13 +928,13 @@ sdioh_request_word(sdioh_info_t *sd, uint cmd_type, uint rw, uint func,
927 928
928static SDIOH_API_RC 929static SDIOH_API_RC
929sdioh_request_packet(sdioh_info_t *sd, uint fix_inc, uint write, uint func, 930sdioh_request_packet(sdioh_info_t *sd, uint fix_inc, uint write, uint func,
930 uint addr, void *pkt) 931 uint addr, struct sk_buff *pkt)
931{ 932{
932 bool fifo = (fix_inc == SDIOH_DATA_FIX); 933 bool fifo = (fix_inc == SDIOH_DATA_FIX);
933 u32 SGCount = 0; 934 u32 SGCount = 0;
934 int err_ret = 0; 935 int err_ret = 0;
935 936
936 void *pnext; 937 struct sk_buff *pnext;
937 938
938 sd_trace(("%s: Enter\n", __func__)); 939 sd_trace(("%s: Enter\n", __func__));
939 940
@@ -943,8 +944,8 @@ sdioh_request_packet(sdioh_info_t *sd, uint fix_inc, uint write, uint func,
943 944
944 /* Claim host controller */ 945 /* Claim host controller */
945 sdio_claim_host(gInstance->func[func]); 946 sdio_claim_host(gInstance->func[func]);
946 for (pnext = pkt; pnext; pnext = PKTNEXT(pnext)) { 947 for (pnext = pkt; pnext; pnext = pnext->next) {
947 uint pkt_len = PKTLEN(pnext); 948 uint pkt_len = pnext->len;
948 pkt_len += 3; 949 pkt_len += 3;
949 pkt_len &= 0xFFFFFFFC; 950 pkt_len &= 0xFFFFFFFC;
950 951
@@ -961,23 +962,23 @@ sdioh_request_packet(sdioh_info_t *sd, uint fix_inc, uint write, uint func,
961 * is supposed to give 962 * is supposed to give
962 * us something we can work with. 963 * us something we can work with.
963 */ 964 */
964 ASSERT(((u32) (PKTDATA(pkt)) & DMA_ALIGN_MASK) == 0); 965 ASSERT(((u32) (pkt->data) & DMA_ALIGN_MASK) == 0);
965 966
966 if ((write) && (!fifo)) { 967 if ((write) && (!fifo)) {
967 err_ret = sdio_memcpy_toio(gInstance->func[func], addr, 968 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
968 ((u8 *) PKTDATA(pnext)), 969 ((u8 *) (pnext->data)),
969 pkt_len); 970 pkt_len);
970 } else if (write) { 971 } else if (write) {
971 err_ret = sdio_memcpy_toio(gInstance->func[func], addr, 972 err_ret = sdio_memcpy_toio(gInstance->func[func], addr,
972 ((u8 *) PKTDATA(pnext)), 973 ((u8 *) (pnext->data)),
973 pkt_len); 974 pkt_len);
974 } else if (fifo) { 975 } else if (fifo) {
975 err_ret = sdio_readsb(gInstance->func[func], 976 err_ret = sdio_readsb(gInstance->func[func],
976 ((u8 *) PKTDATA(pnext)), 977 ((u8 *) (pnext->data)),
977 addr, pkt_len); 978 addr, pkt_len);
978 } else { 979 } else {
979 err_ret = sdio_memcpy_fromio(gInstance->func[func], 980 err_ret = sdio_memcpy_fromio(gInstance->func[func],
980 ((u8 *) PKTDATA(pnext)), 981 ((u8 *) (pnext->data)),
981 addr, pkt_len); 982 addr, pkt_len);
982 } 983 }
983 984
@@ -1025,10 +1026,10 @@ sdioh_request_packet(sdioh_info_t *sd, uint fix_inc, uint write, uint func,
1025extern SDIOH_API_RC 1026extern SDIOH_API_RC
1026sdioh_request_buffer(sdioh_info_t *sd, uint pio_dma, uint fix_inc, uint write, 1027sdioh_request_buffer(sdioh_info_t *sd, uint pio_dma, uint fix_inc, uint write,
1027 uint func, uint addr, uint reg_width, uint buflen_u, 1028 uint func, uint addr, uint reg_width, uint buflen_u,
1028 u8 *buffer, void *pkt) 1029 u8 *buffer, struct sk_buff *pkt)
1029{ 1030{
1030 SDIOH_API_RC Status; 1031 SDIOH_API_RC Status;
1031 void *mypkt = NULL; 1032 struct sk_buff *mypkt = NULL;
1032 1033
1033 sd_trace(("%s: Enter\n", __func__)); 1034 sd_trace(("%s: Enter\n", __func__));
1034 1035
@@ -1038,52 +1039,52 @@ sdioh_request_buffer(sdioh_info_t *sd, uint pio_dma, uint fix_inc, uint write,
1038 if (pkt == NULL) { 1039 if (pkt == NULL) {
1039 sd_data(("%s: Creating new %s Packet, len=%d\n", 1040 sd_data(("%s: Creating new %s Packet, len=%d\n",
1040 __func__, write ? "TX" : "RX", buflen_u)); 1041 __func__, write ? "TX" : "RX", buflen_u));
1041 mypkt = PKTGET(sd->osh, buflen_u, write ? true : false); 1042 mypkt = pkt_buf_get_skb(sd->osh, buflen_u);
1042 if (!mypkt) { 1043 if (!mypkt) {
1043 sd_err(("%s: PKTGET failed: len %d\n", 1044 sd_err(("%s: pkt_buf_get_skb failed: len %d\n",
1044 __func__, buflen_u)); 1045 __func__, buflen_u));
1045 return SDIOH_API_RC_FAIL; 1046 return SDIOH_API_RC_FAIL;
1046 } 1047 }
1047 1048
1048 /* For a write, copy the buffer data into the packet. */ 1049 /* For a write, copy the buffer data into the packet. */
1049 if (write) 1050 if (write)
1050 bcopy(buffer, PKTDATA(mypkt), buflen_u); 1051 bcopy(buffer, mypkt->data, buflen_u);
1051 1052
1052 Status = 1053 Status =
1053 sdioh_request_packet(sd, fix_inc, write, func, addr, mypkt); 1054 sdioh_request_packet(sd, fix_inc, write, func, addr, mypkt);
1054 1055
1055 /* For a read, copy the packet data back to the buffer. */ 1056 /* For a read, copy the packet data back to the buffer. */
1056 if (!write) 1057 if (!write)
1057 bcopy(PKTDATA(mypkt), buffer, buflen_u); 1058 bcopy(mypkt->data, buffer, buflen_u);
1058 1059
1059 PKTFREE(sd->osh, mypkt, write ? true : false); 1060 pkt_buf_free_skb(sd->osh, mypkt, write ? true : false);
1060 } else if (((u32) (PKTDATA(pkt)) & DMA_ALIGN_MASK) != 0) { 1061 } else if (((u32) (pkt->data) & DMA_ALIGN_MASK) != 0) {
1061 /* Case 2: We have a packet, but it is unaligned. */ 1062 /* Case 2: We have a packet, but it is unaligned. */
1062 1063
1063 /* In this case, we cannot have a chain. */ 1064 /* In this case, we cannot have a chain. */
1064 ASSERT(PKTNEXT(pkt) == NULL); 1065 ASSERT(pkt->next == NULL);
1065 1066
1066 sd_data(("%s: Creating aligned %s Packet, len=%d\n", 1067 sd_data(("%s: Creating aligned %s Packet, len=%d\n",
1067 __func__, write ? "TX" : "RX", PKTLEN(pkt))); 1068 __func__, write ? "TX" : "RX", pkt->len));
1068 mypkt = PKTGET(sd->osh, PKTLEN(pkt), write ? true : false); 1069 mypkt = pkt_buf_get_skb(sd->osh, pkt->len);
1069 if (!mypkt) { 1070 if (!mypkt) {
1070 sd_err(("%s: PKTGET failed: len %d\n", 1071 sd_err(("%s: pkt_buf_get_skb failed: len %d\n",
1071 __func__, PKTLEN(pkt))); 1072 __func__, pkt->len));
1072 return SDIOH_API_RC_FAIL; 1073 return SDIOH_API_RC_FAIL;
1073 } 1074 }
1074 1075
1075 /* For a write, copy the buffer data into the packet. */ 1076 /* For a write, copy the buffer data into the packet. */
1076 if (write) 1077 if (write)
1077 bcopy(PKTDATA(pkt), PKTDATA(mypkt), PKTLEN(pkt)); 1078 bcopy(pkt->data, mypkt->data, pkt->len);
1078 1079
1079 Status = 1080 Status =
1080 sdioh_request_packet(sd, fix_inc, write, func, addr, mypkt); 1081 sdioh_request_packet(sd, fix_inc, write, func, addr, mypkt);
1081 1082
1082 /* For a read, copy the packet data back to the buffer. */ 1083 /* For a read, copy the packet data back to the buffer. */
1083 if (!write) 1084 if (!write)
1084 bcopy(PKTDATA(mypkt), PKTDATA(pkt), PKTLEN(mypkt)); 1085 bcopy(mypkt->data, pkt->data, mypkt->len);
1085 1086
1086 PKTFREE(sd->osh, mypkt, write ? true : false); 1087 pkt_buf_free_skb(sd->osh, mypkt, write ? true : false);
1087 } else { /* case 3: We have a packet and 1088 } else { /* case 3: We have a packet and
1088 it is aligned. */ 1089 it is aligned. */
1089 sd_data(("%s: Aligned %s Packet, direct DMA\n", 1090 sd_data(("%s: Aligned %s Packet, direct DMA\n",
diff --git a/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc_linux.c b/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc_linux.c
index ae7b566b11d7..ceaa47490680 100644
--- a/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc_linux.c
+++ b/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc_linux.c
@@ -15,7 +15,9 @@
15 */ 15 */
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/sched.h> /* request_irq() */ 17#include <linux/sched.h> /* request_irq() */
18#include <linux/netdevice.h>
18#include <bcmdefs.h> 19#include <bcmdefs.h>
20#include <osl.h>
19#include <bcmutils.h> 21#include <bcmutils.h>
20#include <sdio.h> /* SDIO Specs */ 22#include <sdio.h> /* SDIO Specs */
21#include <bcmsdbus.h> /* bcmsdh to/from specific controller APIs */ 23#include <bcmsdbus.h> /* bcmsdh to/from specific controller APIs */
@@ -211,7 +213,7 @@ int sdio_function_init(void)
211 if (!gInstance) 213 if (!gInstance)
212 return -ENOMEM; 214 return -ENOMEM;
213 215
214 bzero(&sdmmc_dev, sizeof(sdmmc_dev)); 216 memset(&sdmmc_dev, 0, sizeof(sdmmc_dev));
215 error = sdio_register_driver(&bcmsdh_sdmmc_driver); 217 error = sdio_register_driver(&bcmsdh_sdmmc_driver);
216 218
217 return error; 219 return error;
diff --git a/drivers/staging/brcm80211/brcmfmac/dhd.h b/drivers/staging/brcm80211/brcmfmac/dhd.h
index 57d06b2da46f..69c6a0272812 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd.h
+++ b/drivers/staging/brcm80211/brcmfmac/dhd.h
@@ -77,7 +77,7 @@ enum dhd_prealloc_index {
77/* Common structure for module and instance linkage */ 77/* Common structure for module and instance linkage */
78typedef struct dhd_pub { 78typedef struct dhd_pub {
79 /* Linkage ponters */ 79 /* Linkage ponters */
80 osl_t *osh; /* OSL handle */ 80 struct osl_info *osh; /* OSL handle */
81 struct dhd_bus *bus; /* Bus module handle */ 81 struct dhd_bus *bus; /* Bus module handle */
82 struct dhd_prot *prot; /* Protocol module handle */ 82 struct dhd_prot *prot; /* Protocol module handle */
83 struct dhd_info *info; /* Info module handle */ 83 struct dhd_info *info; /* Info module handle */
@@ -277,15 +277,16 @@ typedef struct dhd_if_event {
277 */ 277 */
278 278
279/* To allow osl_attach/detach calls from os-independent modules */ 279/* To allow osl_attach/detach calls from os-independent modules */
280osl_t *dhd_osl_attach(void *pdev, uint bustype); 280struct osl_info *dhd_osl_attach(void *pdev, uint bustype);
281void dhd_osl_detach(osl_t *osh); 281void dhd_osl_detach(struct osl_info *osh);
282 282
283/* Indication from bus module regarding presence/insertion of dongle. 283/* Indication from bus module regarding presence/insertion of dongle.
284 * Return dhd_pub_t pointer, used as handle to OS module in later calls. 284 * Return dhd_pub_t pointer, used as handle to OS module in later calls.
285 * Returned structure should have bus and prot pointers filled in. 285 * Returned structure should have bus and prot pointers filled in.
286 * bus_hdrlen specifies required headroom for bus module header. 286 * bus_hdrlen specifies required headroom for bus module header.
287 */ 287 */
288extern dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen); 288extern dhd_pub_t *dhd_attach(struct osl_info *osh, struct dhd_bus *bus,
289 uint bus_hdrlen);
289extern int dhd_net_attach(dhd_pub_t *dhdp, int idx); 290extern int dhd_net_attach(dhd_pub_t *dhdp, int idx);
290 291
291/* Indication from bus module regarding removal/absence of dongle */ 292/* Indication from bus module regarding removal/absence of dongle */
@@ -294,10 +295,12 @@ extern void dhd_detach(dhd_pub_t *dhdp);
294/* Indication from bus module to change flow-control state */ 295/* Indication from bus module to change flow-control state */
295extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on); 296extern void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool on);
296 297
297extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec); 298extern bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q,
299 struct sk_buff *pkt, int prec);
298 300
299/* Receive frame for delivery to OS. Callee disposes of rxp. */ 301/* Receive frame for delivery to OS. Callee disposes of rxp. */
300extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *rxp, int numpkt); 302extern void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx,
303 struct sk_buff *rxp, int numpkt);
301 304
302/* Return pointer to interface name */ 305/* Return pointer to interface name */
303extern char *dhd_ifname(dhd_pub_t *dhdp, int idx); 306extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
@@ -306,7 +309,7 @@ extern char *dhd_ifname(dhd_pub_t *dhdp, int idx);
306extern void dhd_sched_dpc(dhd_pub_t *dhdp); 309extern void dhd_sched_dpc(dhd_pub_t *dhdp);
307 310
308/* Notify tx completion */ 311/* Notify tx completion */
309extern void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success); 312extern void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success);
310 313
311/* Query ioctl */ 314/* Query ioctl */
312extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, 315extern int dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
@@ -377,7 +380,7 @@ extern void dhd_vif_sendup(struct dhd_info *dhd, int ifidx, unsigned char * cp,
377 int len); 380 int len);
378 381
379/* Send packet to dongle via data channel */ 382/* Send packet to dongle via data channel */
380extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pkt); 383extern int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pkt);
381 384
382/* Send event to host */ 385/* Send event to host */
383extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event, 386extern void dhd_sendup_event(dhd_pub_t *dhdp, wl_event_msg_t *event,
diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_bus.h b/drivers/staging/brcm80211/brcmfmac/dhd_bus.h
index 3b39c9966f81..cd0d5400bf07 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd_bus.h
+++ b/drivers/staging/brcm80211/brcmfmac/dhd_bus.h
@@ -26,8 +26,8 @@ extern int dhd_bus_register(void);
26extern void dhd_bus_unregister(void); 26extern void dhd_bus_unregister(void);
27 27
28/* Download firmware image and nvram image */ 28/* Download firmware image and nvram image */
29extern bool dhd_bus_download_firmware(struct dhd_bus *bus, osl_t * osh, 29extern bool dhd_bus_download_firmware(struct dhd_bus *bus,
30 char *fw_path, char *nv_path); 30 struct osl_info *osh, char *fw_path, char *nv_path);
31 31
32/* Stop bus module: clear pending frames, disable data flow */ 32/* Stop bus module: clear pending frames, disable data flow */
33extern void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex); 33extern void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex);
@@ -36,7 +36,7 @@ extern void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex);
36extern int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex); 36extern int dhd_bus_init(dhd_pub_t *dhdp, bool enforce_mutex);
37 37
38/* Send a data frame to the dongle. Callee disposes of txp. */ 38/* Send a data frame to the dongle. Callee disposes of txp. */
39extern int dhd_bus_txdata(struct dhd_bus *bus, void *txp); 39extern int dhd_bus_txdata(struct dhd_bus *bus, struct sk_buff *txp);
40 40
41/* Send/receive a control message to/from the dongle. 41/* Send/receive a control message to/from the dongle.
42 * Expects caller to enforce a single outstanding transaction. 42 * Expects caller to enforce a single outstanding transaction.
diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_cdc.c b/drivers/staging/brcm80211/brcmfmac/dhd_cdc.c
index bcbaac9bcdcc..b7b527f5024c 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd_cdc.c
+++ b/drivers/staging/brcm80211/brcmfmac/dhd_cdc.c
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include <linux/types.h> 17#include <linux/types.h>
18#include <linux/netdevice.h>
18#include <bcmdefs.h> 19#include <bcmdefs.h>
19#include <osl.h> 20#include <osl.h>
20 21
@@ -297,6 +298,15 @@ done:
297 return ret; 298 return ret;
298} 299}
299 300
301#define PKTSUMNEEDED(skb) \
302 (((struct sk_buff *)(skb))->ip_summed == CHECKSUM_PARTIAL)
303#define PKTSETSUMGOOD(skb, x) \
304 (((struct sk_buff *)(skb))->ip_summed = \
305 ((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE))
306
307/* PKTSETSUMNEEDED and PKTSUMGOOD are not possible because
308 skb->ip_summed is overloaded */
309
300int 310int
301dhd_prot_iovar_op(dhd_pub_t *dhdp, const char *name, 311dhd_prot_iovar_op(dhd_pub_t *dhdp, const char *name,
302 void *params, int plen, void *arg, int len, bool set) 312 void *params, int plen, void *arg, int len, bool set)
@@ -309,7 +319,7 @@ void dhd_prot_dump(dhd_pub_t *dhdp, struct bcmstrbuf *strbuf)
309 bcm_bprintf(strbuf, "Protocol CDC: reqid %d\n", dhdp->prot->reqid); 319 bcm_bprintf(strbuf, "Protocol CDC: reqid %d\n", dhdp->prot->reqid);
310} 320}
311 321
312void dhd_prot_hdrpush(dhd_pub_t *dhd, int ifidx, void *pktbuf) 322void dhd_prot_hdrpush(dhd_pub_t *dhd, int ifidx, struct sk_buff *pktbuf)
313{ 323{
314#ifdef BDC 324#ifdef BDC
315 struct bdc_header *h; 325 struct bdc_header *h;
@@ -320,33 +330,33 @@ void dhd_prot_hdrpush(dhd_pub_t *dhd, int ifidx, void *pktbuf)
320#ifdef BDC 330#ifdef BDC
321 /* Push BDC header used to convey priority for buses that don't */ 331 /* Push BDC header used to convey priority for buses that don't */
322 332
323 PKTPUSH(pktbuf, BDC_HEADER_LEN); 333 skb_push(pktbuf, BDC_HEADER_LEN);
324 334
325 h = (struct bdc_header *)PKTDATA(pktbuf); 335 h = (struct bdc_header *)(pktbuf->data);
326 336
327 h->flags = (BDC_PROTO_VER << BDC_FLAG_VER_SHIFT); 337 h->flags = (BDC_PROTO_VER << BDC_FLAG_VER_SHIFT);
328 if (PKTSUMNEEDED(pktbuf)) 338 if (PKTSUMNEEDED(pktbuf))
329 h->flags |= BDC_FLAG_SUM_NEEDED; 339 h->flags |= BDC_FLAG_SUM_NEEDED;
330 340
331 h->priority = (PKTPRIO(pktbuf) & BDC_PRIORITY_MASK); 341 h->priority = (pktbuf->priority & BDC_PRIORITY_MASK);
332 h->flags2 = 0; 342 h->flags2 = 0;
333 h->rssi = 0; 343 h->rssi = 0;
334#endif /* BDC */ 344#endif /* BDC */
335 BDC_SET_IF_IDX(h, ifidx); 345 BDC_SET_IF_IDX(h, ifidx);
336} 346}
337 347
338bool dhd_proto_fcinfo(dhd_pub_t *dhd, void *pktbuf, u8 * fcbits) 348bool dhd_proto_fcinfo(dhd_pub_t *dhd, struct sk_buff *pktbuf, u8 * fcbits)
339{ 349{
340#ifdef BDC 350#ifdef BDC
341 struct bdc_header *h; 351 struct bdc_header *h;
342 352
343 if (PKTLEN(pktbuf) < BDC_HEADER_LEN) { 353 if (pktbuf->len < BDC_HEADER_LEN) {
344 DHD_ERROR(("%s: rx data too short (%d < %d)\n", 354 DHD_ERROR(("%s: rx data too short (%d < %d)\n",
345 __func__, PKTLEN(pktbuf), BDC_HEADER_LEN)); 355 __func__, pktbuf->len, BDC_HEADER_LEN));
346 return BCME_ERROR; 356 return BCME_ERROR;
347 } 357 }
348 358
349 h = (struct bdc_header *)PKTDATA(pktbuf); 359 h = (struct bdc_header *)(pktbuf->data);
350 360
351 *fcbits = h->priority >> BDC_PRIORITY_FC_SHIFT; 361 *fcbits = h->priority >> BDC_PRIORITY_FC_SHIFT;
352 if ((h->flags2 & BDC_FLAG2_FC_FLAG) == BDC_FLAG2_FC_FLAG) 362 if ((h->flags2 & BDC_FLAG2_FC_FLAG) == BDC_FLAG2_FC_FLAG)
@@ -355,7 +365,7 @@ bool dhd_proto_fcinfo(dhd_pub_t *dhd, void *pktbuf, u8 * fcbits)
355 return false; 365 return false;
356} 366}
357 367
358int dhd_prot_hdrpull(dhd_pub_t *dhd, int *ifidx, void *pktbuf) 368int dhd_prot_hdrpull(dhd_pub_t *dhd, int *ifidx, struct sk_buff *pktbuf)
359{ 369{
360#ifdef BDC 370#ifdef BDC
361 struct bdc_header *h; 371 struct bdc_header *h;
@@ -366,13 +376,13 @@ int dhd_prot_hdrpull(dhd_pub_t *dhd, int *ifidx, void *pktbuf)
366#ifdef BDC 376#ifdef BDC
367 /* Pop BDC header used to convey priority for buses that don't */ 377 /* Pop BDC header used to convey priority for buses that don't */
368 378
369 if (PKTLEN(pktbuf) < BDC_HEADER_LEN) { 379 if (pktbuf->len < BDC_HEADER_LEN) {
370 DHD_ERROR(("%s: rx data too short (%d < %d)\n", __func__, 380 DHD_ERROR(("%s: rx data too short (%d < %d)\n", __func__,
371 PKTLEN(pktbuf), BDC_HEADER_LEN)); 381 pktbuf->len, BDC_HEADER_LEN));
372 return BCME_ERROR; 382 return BCME_ERROR;
373 } 383 }
374 384
375 h = (struct bdc_header *)PKTDATA(pktbuf); 385 h = (struct bdc_header *)(pktbuf->data);
376 386
377 *ifidx = BDC_GET_IF_IDX(h); 387 *ifidx = BDC_GET_IF_IDX(h);
378 if (*ifidx >= DHD_MAX_IFS) { 388 if (*ifidx >= DHD_MAX_IFS) {
@@ -395,9 +405,9 @@ int dhd_prot_hdrpull(dhd_pub_t *dhd, int *ifidx, void *pktbuf)
395 PKTSETSUMGOOD(pktbuf, true); 405 PKTSETSUMGOOD(pktbuf, true);
396 } 406 }
397 407
398 PKTSETPRIO(pktbuf, (h->priority & BDC_PRIORITY_MASK)); 408 pktbuf->priority = h->priority & BDC_PRIORITY_MASK;
399 409
400 PKTPULL(pktbuf, BDC_HEADER_LEN); 410 skb_pull(pktbuf, BDC_HEADER_LEN);
401#endif /* BDC */ 411#endif /* BDC */
402 412
403 return 0; 413 return 0;
@@ -467,7 +477,7 @@ int dhd_prot_init(dhd_pub_t *dhd)
467 dhd_os_proto_unblock(dhd); 477 dhd_os_proto_unblock(dhd);
468 return ret; 478 return ret;
469 } 479 }
470 memcpy(dhd->mac.octet, buf, ETHER_ADDR_LEN); 480 memcpy(dhd->mac.octet, buf, ETH_ALEN);
471 481
472 dhd_os_proto_unblock(dhd); 482 dhd_os_proto_unblock(dhd);
473 483
diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_common.c b/drivers/staging/brcm80211/brcmfmac/dhd_common.c
index 703188fc28ec..3dbf72eebd4a 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd_common.c
+++ b/drivers/staging/brcm80211/brcmfmac/dhd_common.c
@@ -16,6 +16,7 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/string.h> 17#include <linux/string.h>
18#include <bcmdefs.h> 18#include <bcmdefs.h>
19#include <linux/netdevice.h>
19#include <osl.h> 20#include <osl.h>
20#include <bcmutils.h> 21#include <bcmutils.h>
21#include <bcmendian.h> 22#include <bcmendian.h>
@@ -326,9 +327,10 @@ void dhd_store_conn_status(u32 event, u32 status, u32 reason)
326 } 327 }
327} 328}
328 329
329bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec) 330bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, struct sk_buff *pkt,
331 int prec)
330{ 332{
331 void *p; 333 struct sk_buff *p;
332 int eprec = -1; /* precedence to evict from */ 334 int eprec = -1; /* precedence to evict from */
333 bool discard_oldest; 335 bool discard_oldest;
334 336
@@ -366,7 +368,7 @@ bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec)
366 ASSERT(p); 368 ASSERT(p);
367 } 369 }
368 370
369 PKTFREE(dhdp->osh, p, true); 371 pkt_buf_free_skb(dhdp->osh, p, true);
370 } 372 }
371 373
372 /* Enqueue */ 374 /* Enqueue */
@@ -832,7 +834,7 @@ wl_host_event(struct dhd_info *dhd, int *ifidx, void *pktdata,
832 u16 flags; 834 u16 flags;
833 int evlen; 835 int evlen;
834 836
835 if (bcmp(BRCM_OUI, &pvt_data->bcm_hdr.oui[0], DOT11_OUI_LEN)) { 837 if (memcmp(BRCM_OUI, &pvt_data->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
836 DHD_ERROR(("%s: mismatched OUI, bailing\n", __func__)); 838 DHD_ERROR(("%s: mismatched OUI, bailing\n", __func__));
837 return BCME_ERROR; 839 return BCME_ERROR;
838 } 840 }
@@ -1254,7 +1256,7 @@ int dhd_preinit_ioctls(dhd_pub_t *dhd)
1254 */ 1256 */
1255 ret = dhd_custom_get_mac_address(ea_addr.octet); 1257 ret = dhd_custom_get_mac_address(ea_addr.octet);
1256 if (!ret) { 1258 if (!ret) {
1257 bcm_mkiovar("cur_etheraddr", (void *)&ea_addr, ETHER_ADDR_LEN, 1259 bcm_mkiovar("cur_etheraddr", (void *)&ea_addr, ETH_ALEN,
1258 buf, sizeof(buf)); 1260 buf, sizeof(buf));
1259 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf)); 1261 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf));
1260 if (ret < 0) { 1262 if (ret < 0) {
@@ -1262,7 +1264,7 @@ int dhd_preinit_ioctls(dhd_pub_t *dhd)
1262 __func__, ret)); 1264 __func__, ret));
1263 } else 1265 } else
1264 memcpy(dhd->mac.octet, (void *)&ea_addr, 1266 memcpy(dhd->mac.octet, (void *)&ea_addr,
1265 ETHER_ADDR_LEN); 1267 ETH_ALEN);
1266 } 1268 }
1267#endif /* GET_CUSTOM_MAC_ENABLE */ 1269#endif /* GET_CUSTOM_MAC_ENABLE */
1268 1270
@@ -1532,7 +1534,7 @@ int dhd_iscan_delete_bss(void *dhdp, void *addr, iscan_buf_t *iscan_skip)
1532 break; 1534 break;
1533 1535
1534 if (!memcmp 1536 if (!memcmp
1535 (bi->BSSID.octet, addr, ETHER_ADDR_LEN)) { 1537 (bi->BSSID.octet, addr, ETH_ALEN)) {
1536 DHD_ISCAN(("%s: Del BSS[%2.2d:%2.2d] " 1538 DHD_ISCAN(("%s: Del BSS[%2.2d:%2.2d] "
1537 "%X:%X:%X:%X:%X:%X\n", 1539 "%X:%X:%X:%X:%X:%X\n",
1538 __func__, l, i, bi->BSSID.octet[0], 1540 __func__, l, i, bi->BSSID.octet[0],
@@ -1670,7 +1672,7 @@ int dhd_iscan_request(void *dhdp, u16 action)
1670 char buf[WLC_IOCTL_SMLEN]; 1672 char buf[WLC_IOCTL_SMLEN];
1671 1673
1672 memset(&params, 0, sizeof(wl_iscan_params_t)); 1674 memset(&params, 0, sizeof(wl_iscan_params_t));
1673 memcpy(&params.params.bssid, &ether_bcast, ETHER_ADDR_LEN); 1675 memcpy(&params.params.bssid, &ether_bcast, ETH_ALEN);
1674 1676
1675 params.params.bss_type = DOT11_BSSTYPE_ANY; 1677 params.params.bss_type = DOT11_BSSTYPE_ANY;
1676 params.params.scan_type = DOT11_SCANTYPE_ACTIVE; 1678 params.params.scan_type = DOT11_SCANTYPE_ACTIVE;
diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_custom_gpio.c b/drivers/staging/brcm80211/brcmfmac/dhd_custom_gpio.c
index f647034f36d6..c3f18bb3b27c 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd_custom_gpio.c
+++ b/drivers/staging/brcm80211/brcmfmac/dhd_custom_gpio.c
@@ -14,7 +14,7 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linuxver.h> 17#include <linux/netdevice.h>
18#include <osl.h> 18#include <osl.h>
19#include <bcmutils.h> 19#include <bcmutils.h>
20 20
@@ -24,8 +24,8 @@
24#include <wlioctl.h> 24#include <wlioctl.h>
25#include <wl_iw.h> 25#include <wl_iw.h>
26 26
27#define WL_ERROR(x) printf x 27#define WL_ERROR(fmt, args...) printk(fmt, ##args)
28#define WL_TRACE(x) 28#define WL_TRACE(fmt, args...) no_printk(fmt, ##args)
29 29
30#ifdef CUSTOMER_HW 30#ifdef CUSTOMER_HW
31extern void bcm_wlan_power_off(int); 31extern void bcm_wlan_power_off(int);
@@ -67,13 +67,13 @@ int dhd_customer_oob_irq_map(unsigned long *irq_flags_ptr)
67#endif 67#endif
68 68
69 if (dhd_oob_gpio_num < 0) { 69 if (dhd_oob_gpio_num < 0) {
70 WL_ERROR(("%s: ERROR customer specific Host GPIO is NOT defined\n", 70 WL_ERROR("%s: ERROR customer specific Host GPIO is NOT defined\n",
71 __func__)); 71 __func__);
72 return dhd_oob_gpio_num; 72 return dhd_oob_gpio_num;
73 } 73 }
74 74
75 WL_ERROR(("%s: customer specific Host GPIO number is (%d)\n", 75 WL_ERROR("%s: customer specific Host GPIO number is (%d)\n",
76 __func__, dhd_oob_gpio_num)); 76 __func__, dhd_oob_gpio_num);
77 77
78#if defined CUSTOMER_HW 78#if defined CUSTOMER_HW
79 host_oob_irq = MSM_GPIO_TO_INT(dhd_oob_gpio_num); 79 host_oob_irq = MSM_GPIO_TO_INT(dhd_oob_gpio_num);
@@ -93,40 +93,40 @@ void dhd_customer_gpio_wlan_ctrl(int onoff)
93{ 93{
94 switch (onoff) { 94 switch (onoff) {
95 case WLAN_RESET_OFF: 95 case WLAN_RESET_OFF:
96 WL_TRACE(("%s: call customer specific GPIO to insert WLAN RESET\n", 96 WL_TRACE("%s: call customer specific GPIO to insert WLAN RESET\n",
97 __func__)); 97 __func__);
98#ifdef CUSTOMER_HW 98#ifdef CUSTOMER_HW
99 bcm_wlan_power_off(2); 99 bcm_wlan_power_off(2);
100#endif /* CUSTOMER_HW */ 100#endif /* CUSTOMER_HW */
101#ifdef CUSTOMER_HW2 101#ifdef CUSTOMER_HW2
102 wifi_set_power(0, 0); 102 wifi_set_power(0, 0);
103#endif 103#endif
104 WL_ERROR(("=========== WLAN placed in RESET ========\n")); 104 WL_ERROR("=========== WLAN placed in RESET ========\n");
105 break; 105 break;
106 106
107 case WLAN_RESET_ON: 107 case WLAN_RESET_ON:
108 WL_TRACE(("%s: callc customer specific GPIO to remove WLAN RESET\n", 108 WL_TRACE("%s: callc customer specific GPIO to remove WLAN RESET\n",
109 __func__)); 109 __func__);
110#ifdef CUSTOMER_HW 110#ifdef CUSTOMER_HW
111 bcm_wlan_power_on(2); 111 bcm_wlan_power_on(2);
112#endif /* CUSTOMER_HW */ 112#endif /* CUSTOMER_HW */
113#ifdef CUSTOMER_HW2 113#ifdef CUSTOMER_HW2
114 wifi_set_power(1, 0); 114 wifi_set_power(1, 0);
115#endif 115#endif
116 WL_ERROR(("=========== WLAN going back to live ========\n")); 116 WL_ERROR("=========== WLAN going back to live ========\n");
117 break; 117 break;
118 118
119 case WLAN_POWER_OFF: 119 case WLAN_POWER_OFF:
120 WL_TRACE(("%s: call customer specific GPIO to turn off WL_REG_ON\n", 120 WL_TRACE("%s: call customer specific GPIO to turn off WL_REG_ON\n",
121 __func__)); 121 __func__);
122#ifdef CUSTOMER_HW 122#ifdef CUSTOMER_HW
123 bcm_wlan_power_off(1); 123 bcm_wlan_power_off(1);
124#endif /* CUSTOMER_HW */ 124#endif /* CUSTOMER_HW */
125 break; 125 break;
126 126
127 case WLAN_POWER_ON: 127 case WLAN_POWER_ON:
128 WL_TRACE(("%s: call customer specific GPIO to turn on WL_REG_ON\n", 128 WL_TRACE("%s: call customer specific GPIO to turn on WL_REG_ON\n",
129 __func__)); 129 __func__);
130#ifdef CUSTOMER_HW 130#ifdef CUSTOMER_HW
131 bcm_wlan_power_on(1); 131 bcm_wlan_power_on(1);
132#endif /* CUSTOMER_HW */ 132#endif /* CUSTOMER_HW */
@@ -140,7 +140,7 @@ void dhd_customer_gpio_wlan_ctrl(int onoff)
140/* Function to get custom MAC address */ 140/* Function to get custom MAC address */
141int dhd_custom_get_mac_address(unsigned char *buf) 141int dhd_custom_get_mac_address(unsigned char *buf)
142{ 142{
143 WL_TRACE(("%s Enter\n", __func__)); 143 WL_TRACE("%s Enter\n", __func__);
144 if (!buf) 144 if (!buf)
145 return -EINVAL; 145 return -EINVAL;
146 146
diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_linux.c b/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
index 9335f02029aa..db4508378775 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
+++ b/drivers/staging/brcm80211/brcmfmac/dhd_linux.c
@@ -32,7 +32,6 @@
32#include <linux/fs.h> 32#include <linux/fs.h>
33#include <linux/uaccess.h> 33#include <linux/uaccess.h>
34#include <bcmdefs.h> 34#include <bcmdefs.h>
35#include <linuxver.h>
36#include <osl.h> 35#include <osl.h>
37#include <bcmutils.h> 36#include <bcmutils.h>
38#include <bcmendian.h> 37#include <bcmendian.h>
@@ -211,7 +210,7 @@ typedef struct dhd_if {
211 int idx; /* iface idx in dongle */ 210 int idx; /* iface idx in dongle */
212 int state; /* interface state */ 211 int state; /* interface state */
213 uint subunit; /* subunit */ 212 uint subunit; /* subunit */
214 u8 mac_addr[ETHER_ADDR_LEN]; /* assigned MAC address */ 213 u8 mac_addr[ETH_ALEN]; /* assigned MAC address */
215 bool attached; /* Delayed attachment when unset */ 214 bool attached; /* Delayed attachment when unset */
216 bool txflowcontrol; /* Per interface flow control indicator */ 215 bool txflowcontrol; /* Per interface flow control indicator */
217 char name[IFNAMSIZ]; /* linux interface name */ 216 char name[IFNAMSIZ]; /* linux interface name */
@@ -709,7 +708,7 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
709 708
710 /* Send down the multicast list first. */ 709 /* Send down the multicast list first. */
711 710
712 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETHER_ADDR_LEN); 711 buflen = sizeof("mcast_list") + sizeof(cnt) + (cnt * ETH_ALEN);
713 bufp = buf = kmalloc(buflen, GFP_ATOMIC); 712 bufp = buf = kmalloc(buflen, GFP_ATOMIC);
714 if (!bufp) { 713 if (!bufp) {
715 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n", 714 DHD_ERROR(("%s: out of memory for mcast_list, cnt %d\n",
@@ -727,8 +726,8 @@ static void _dhd_set_multicast_list(dhd_info_t *dhd, int ifidx)
727 netdev_for_each_mc_addr(ha, dev) { 726 netdev_for_each_mc_addr(ha, dev) {
728 if (!cnt) 727 if (!cnt)
729 break; 728 break;
730 memcpy(bufp, ha->addr, ETHER_ADDR_LEN); 729 memcpy(bufp, ha->addr, ETH_ALEN);
731 bufp += ETHER_ADDR_LEN; 730 bufp += ETH_ALEN;
732 cnt--; 731 cnt--;
733 } 732 }
734 733
@@ -812,7 +811,7 @@ _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
812 811
813 DHD_TRACE(("%s enter\n", __func__)); 812 DHD_TRACE(("%s enter\n", __func__));
814 if (!bcm_mkiovar 813 if (!bcm_mkiovar
815 ("cur_etheraddr", (char *)addr, ETHER_ADDR_LEN, buf, 32)) { 814 ("cur_etheraddr", (char *)addr, ETH_ALEN, buf, 32)) {
816 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n", 815 DHD_ERROR(("%s: mkiovar failed for cur_etheraddr\n",
817 dhd_ifname(&dhd->pub, ifidx))); 816 dhd_ifname(&dhd->pub, ifidx)));
818 return -1; 817 return -1;
@@ -828,7 +827,7 @@ _dhd_set_mac_address(dhd_info_t *dhd, int ifidx, struct ether_addr *addr)
828 DHD_ERROR(("%s: set cur_etheraddr failed\n", 827 DHD_ERROR(("%s: set cur_etheraddr failed\n",
829 dhd_ifname(&dhd->pub, ifidx))); 828 dhd_ifname(&dhd->pub, ifidx)));
830 } else { 829 } else {
831 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETHER_ADDR_LEN); 830 memcpy(dhd->iflist[ifidx]->net->dev_addr, addr, ETH_ALEN);
832 } 831 }
833 832
834 return ret; 833 return ret;
@@ -998,7 +997,7 @@ static int dhd_set_mac_address(struct net_device *dev, void *addr)
998 return -1; 997 return -1;
999 998
1000 ASSERT(dhd->sysioc_tsk); 999 ASSERT(dhd->sysioc_tsk);
1001 memcpy(&dhd->macvalue, sa->sa_data, ETHER_ADDR_LEN); 1000 memcpy(&dhd->macvalue, sa->sa_data, ETH_ALEN);
1002 dhd->set_macaddress = true; 1001 dhd->set_macaddress = true;
1003 up(&dhd->sysioc_sem); 1002 up(&dhd->sysioc_sem);
1004 1003
@@ -1019,7 +1018,7 @@ static void dhd_set_multicast_list(struct net_device *dev)
1019 up(&dhd->sysioc_sem); 1018 up(&dhd->sysioc_sem);
1020} 1019}
1021 1020
1022int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf) 1021int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf)
1023{ 1022{
1024 int ret; 1023 int ret;
1025 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info); 1024 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
@@ -1029,13 +1028,13 @@ int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1029 return -ENODEV; 1028 return -ENODEV;
1030 1029
1031 /* Update multicast statistic */ 1030 /* Update multicast statistic */
1032 if (PKTLEN(pktbuf) >= ETHER_ADDR_LEN) { 1031 if (pktbuf->len >= ETH_ALEN) {
1033 u8 *pktdata = (u8 *) PKTDATA(pktbuf); 1032 u8 *pktdata = (u8 *) (pktbuf->data);
1034 struct ether_header *eh = (struct ether_header *)pktdata; 1033 struct ether_header *eh = (struct ether_header *)pktdata;
1035 1034
1036 if (ETHER_ISMULTI(eh->ether_dhost)) 1035 if (is_multicast_ether_addr(eh->ether_dhost))
1037 dhdp->tx_multicast++; 1036 dhdp->tx_multicast++;
1038 if (ntoh16(eh->ether_type) == ETHER_TYPE_802_1X) 1037 if (ntoh16(eh->ether_type) == ETH_P_PAE)
1039 atomic_inc(&dhd->pend_8021x_cnt); 1038 atomic_inc(&dhd->pend_8021x_cnt);
1040 } 1039 }
1041 1040
@@ -1053,6 +1052,32 @@ int dhd_sendpkt(dhd_pub_t *dhdp, int ifidx, void *pktbuf)
1053 return ret; 1052 return ret;
1054} 1053}
1055 1054
1055static inline void *
1056osl_pkt_frmnative(struct osl_info *osh, struct sk_buff *skb)
1057{
1058 struct sk_buff *nskb;
1059
1060 for (nskb = skb; nskb; nskb = nskb->next)
1061 osh->pktalloced++;
1062
1063 return (void *)skb;
1064}
1065#define PKTFRMNATIVE(osh, skb) \
1066 osl_pkt_frmnative((osh), (struct sk_buff *)(skb))
1067
1068static inline struct sk_buff *
1069osl_pkt_tonative(struct osl_info *osh, void *pkt)
1070{
1071 struct sk_buff *nskb;
1072
1073 for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next)
1074 osh->pktalloced--;
1075
1076 return (struct sk_buff *)pkt;
1077}
1078#define PKTTONATIVE(osh, pkt) \
1079 osl_pkt_tonative((osh), (pkt))
1080
1056static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net) 1081static int dhd_start_xmit(struct sk_buff *skb, struct net_device *net)
1057{ 1082{
1058 int ret; 1083 int ret;
@@ -1133,13 +1158,15 @@ void dhd_txflowcontrol(dhd_pub_t *dhdp, int ifidx, bool state)
1133 netif_wake_queue(net); 1158 netif_wake_queue(net);
1134} 1159}
1135 1160
1136void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt) 1161void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, struct sk_buff *pktbuf,
1162 int numpkt)
1137{ 1163{
1138 dhd_info_t *dhd = (dhd_info_t *) dhdp->info; 1164 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
1139 struct sk_buff *skb; 1165 struct sk_buff *skb;
1140 unsigned char *eth; 1166 unsigned char *eth;
1141 uint len; 1167 uint len;
1142 void *data, *pnext, *save_pktbuf; 1168 void *data;
1169 struct sk_buff *pnext, *save_pktbuf;
1143 int i; 1170 int i;
1144 dhd_if_t *ifp; 1171 dhd_if_t *ifp;
1145 wl_event_msg_t event; 1172 wl_event_msg_t event;
@@ -1150,8 +1177,8 @@ void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1150 1177
1151 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) { 1178 for (i = 0; pktbuf && i < numpkt; i++, pktbuf = pnext) {
1152 1179
1153 pnext = PKTNEXT(pktbuf); 1180 pnext = pktbuf->next;
1154 PKTSETNEXT(pktbuf, NULL); 1181 pktbuf->next = NULL;
1155 1182
1156 skb = PKTTONATIVE(dhdp->osh, pktbuf); 1183 skb = PKTTONATIVE(dhdp->osh, pktbuf);
1157 1184
@@ -1190,7 +1217,7 @@ void dhd_rx_frame(dhd_pub_t *dhdp, int ifidx, void *pktbuf, int numpkt)
1190 /* Process special event packets and then discard them */ 1217 /* Process special event packets and then discard them */
1191 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM) 1218 if (ntoh16(skb->protocol) == ETHER_TYPE_BRCM)
1192 dhd_wl_host_event(dhd, &ifidx, 1219 dhd_wl_host_event(dhd, &ifidx,
1193 skb->mac_header, 1220 skb_mac_header(skb),
1194 &event, &data); 1221 &event, &data);
1195 1222
1196 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]); 1223 ASSERT(ifidx < DHD_MAX_IFS && dhd->iflist[ifidx]);
@@ -1223,7 +1250,7 @@ void dhd_event(struct dhd_info *dhd, char *evpkt, int evlen, int ifidx)
1223 return; 1250 return;
1224} 1251}
1225 1252
1226void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success) 1253void dhd_txcomplete(dhd_pub_t *dhdp, struct sk_buff *txp, bool success)
1227{ 1254{
1228 uint ifidx; 1255 uint ifidx;
1229 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info); 1256 dhd_info_t *dhd = (dhd_info_t *) (dhdp->info);
@@ -1232,10 +1259,10 @@ void dhd_txcomplete(dhd_pub_t *dhdp, void *txp, bool success)
1232 1259
1233 dhd_prot_hdrpull(dhdp, &ifidx, txp); 1260 dhd_prot_hdrpull(dhdp, &ifidx, txp);
1234 1261
1235 eh = (struct ether_header *)PKTDATA(txp); 1262 eh = (struct ether_header *)(txp->data);
1236 type = ntoh16(eh->ether_type); 1263 type = ntoh16(eh->ether_type);
1237 1264
1238 if (type == ETHER_TYPE_802_1X) 1265 if (type == ETH_P_PAE)
1239 atomic_dec(&dhd->pend_8021x_cnt); 1266 atomic_dec(&dhd->pend_8021x_cnt);
1240 1267
1241} 1268}
@@ -1621,6 +1648,51 @@ static int dhd_ethtool(dhd_info_t *dhd, void *uaddr)
1621 return 0; 1648 return 0;
1622} 1649}
1623 1650
1651static s16 linuxbcmerrormap[] = { 0, /* 0 */
1652 -EINVAL, /* BCME_ERROR */
1653 -EINVAL, /* BCME_BADARG */
1654 -EINVAL, /* BCME_BADOPTION */
1655 -EINVAL, /* BCME_NOTUP */
1656 -EINVAL, /* BCME_NOTDOWN */
1657 -EINVAL, /* BCME_NOTAP */
1658 -EINVAL, /* BCME_NOTSTA */
1659 -EINVAL, /* BCME_BADKEYIDX */
1660 -EINVAL, /* BCME_RADIOOFF */
1661 -EINVAL, /* BCME_NOTBANDLOCKED */
1662 -EINVAL, /* BCME_NOCLK */
1663 -EINVAL, /* BCME_BADRATESET */
1664 -EINVAL, /* BCME_BADBAND */
1665 -E2BIG, /* BCME_BUFTOOSHORT */
1666 -E2BIG, /* BCME_BUFTOOLONG */
1667 -EBUSY, /* BCME_BUSY */
1668 -EINVAL, /* BCME_NOTASSOCIATED */
1669 -EINVAL, /* BCME_BADSSIDLEN */
1670 -EINVAL, /* BCME_OUTOFRANGECHAN */
1671 -EINVAL, /* BCME_BADCHAN */
1672 -EFAULT, /* BCME_BADADDR */
1673 -ENOMEM, /* BCME_NORESOURCE */
1674 -EOPNOTSUPP, /* BCME_UNSUPPORTED */
1675 -EMSGSIZE, /* BCME_BADLENGTH */
1676 -EINVAL, /* BCME_NOTREADY */
1677 -EPERM, /* BCME_NOTPERMITTED */
1678 -ENOMEM, /* BCME_NOMEM */
1679 -EINVAL, /* BCME_ASSOCIATED */
1680 -ERANGE, /* BCME_RANGE */
1681 -EINVAL, /* BCME_NOTFOUND */
1682 -EINVAL, /* BCME_WME_NOT_ENABLED */
1683 -EINVAL, /* BCME_TSPEC_NOTFOUND */
1684 -EINVAL, /* BCME_ACM_NOTSUPPORTED */
1685 -EINVAL, /* BCME_NOT_WME_ASSOCIATION */
1686 -EIO, /* BCME_SDIO_ERROR */
1687 -ENODEV, /* BCME_DONGLE_DOWN */
1688 -EINVAL, /* BCME_VERSION */
1689 -EIO, /* BCME_TXFAIL */
1690 -EIO, /* BCME_RXFAIL */
1691 -EINVAL, /* BCME_NODEVICE */
1692 -EINVAL, /* BCME_NMODE_DISABLED */
1693 -ENODATA, /* BCME_NONRESIDENT */
1694};
1695
1624static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd) 1696static int dhd_ioctl_entry(struct net_device *net, struct ifreq *ifr, int cmd)
1625{ 1697{
1626 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net); 1698 dhd_info_t *dhd = *(dhd_info_t **) netdev_priv(net);
@@ -1742,7 +1814,12 @@ done:
1742 if (buf) 1814 if (buf)
1743 kfree(buf); 1815 kfree(buf);
1744 1816
1745 return OSL_ERROR(bcmerror); 1817 if (bcmerror > 0)
1818 bcmerror = 0;
1819 else if (bcmerror < BCME_LAST)
1820 bcmerror = BCME_ERROR;
1821
1822 return linuxbcmerrormap[-bcmerror];
1746} 1823}
1747 1824
1748static int dhd_stop(struct net_device *net) 1825static int dhd_stop(struct net_device *net)
@@ -1789,7 +1866,7 @@ static int dhd_open(struct net_device *net)
1789 } 1866 }
1790 atomic_set(&dhd->pend_8021x_cnt, 0); 1867 atomic_set(&dhd->pend_8021x_cnt, 0);
1791 1868
1792 memcpy(net->dev_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN); 1869 memcpy(net->dev_addr, dhd->pub.mac.octet, ETH_ALEN);
1793 1870
1794#ifdef TOE 1871#ifdef TOE
1795 /* Get current TOE mode from dongle */ 1872 /* Get current TOE mode from dongle */
@@ -1814,12 +1891,12 @@ static int dhd_open(struct net_device *net)
1814 return ret; 1891 return ret;
1815} 1892}
1816 1893
1817osl_t *dhd_osl_attach(void *pdev, uint bustype) 1894struct osl_info *dhd_osl_attach(void *pdev, uint bustype)
1818{ 1895{
1819 return osl_attach(pdev, bustype, true); 1896 return osl_attach(pdev, bustype);
1820} 1897}
1821 1898
1822void dhd_osl_detach(osl_t *osh) 1899void dhd_osl_detach(struct osl_info *osh)
1823{ 1900{
1824 osl_detach(osh); 1901 osl_detach(osh);
1825} 1902}
@@ -1845,7 +1922,7 @@ dhd_add_if(dhd_info_t *dhd, int ifidx, void *handle, char *name,
1845 dhd->iflist[ifidx] = ifp; 1922 dhd->iflist[ifidx] = ifp;
1846 strlcpy(ifp->name, name, IFNAMSIZ); 1923 strlcpy(ifp->name, name, IFNAMSIZ);
1847 if (mac_addr != NULL) 1924 if (mac_addr != NULL)
1848 memcpy(&ifp->mac_addr, mac_addr, ETHER_ADDR_LEN); 1925 memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
1849 1926
1850 if (handle == NULL) { 1927 if (handle == NULL) {
1851 ifp->state = WLC_E_IF_ADD; 1928 ifp->state = WLC_E_IF_ADD;
@@ -1877,7 +1954,8 @@ void dhd_del_if(dhd_info_t *dhd, int ifidx)
1877 up(&dhd->sysioc_sem); 1954 up(&dhd->sysioc_sem);
1878} 1955}
1879 1956
1880dhd_pub_t *dhd_attach(osl_t *osh, struct dhd_bus *bus, uint bus_hdrlen) 1957dhd_pub_t *dhd_attach(struct osl_info *osh, struct dhd_bus *bus,
1958 uint bus_hdrlen)
1881{ 1959{
1882 dhd_info_t *dhd = NULL; 1960 dhd_info_t *dhd = NULL;
1883 struct net_device *net; 1961 struct net_device *net;
@@ -2199,19 +2277,11 @@ static struct net_device_ops dhd_ops_pri = {
2199 .ndo_set_multicast_list = dhd_set_multicast_list 2277 .ndo_set_multicast_list = dhd_set_multicast_list
2200}; 2278};
2201 2279
2202static struct net_device_ops dhd_ops_virt = {
2203 .ndo_get_stats = dhd_get_stats,
2204 .ndo_do_ioctl = dhd_ioctl_entry,
2205 .ndo_start_xmit = dhd_start_xmit,
2206 .ndo_set_mac_address = dhd_set_mac_address,
2207 .ndo_set_multicast_list = dhd_set_multicast_list
2208};
2209
2210int dhd_net_attach(dhd_pub_t *dhdp, int ifidx) 2280int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2211{ 2281{
2212 dhd_info_t *dhd = (dhd_info_t *) dhdp->info; 2282 dhd_info_t *dhd = (dhd_info_t *) dhdp->info;
2213 struct net_device *net; 2283 struct net_device *net;
2214 u8 temp_addr[ETHER_ADDR_LEN] = { 2284 u8 temp_addr[ETH_ALEN] = {
2215 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33}; 2285 0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
2216 2286
2217 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx)); 2287 DHD_TRACE(("%s: ifidx %d\n", __func__, ifidx));
@@ -2229,7 +2299,7 @@ int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2229 */ 2299 */
2230 if (ifidx != 0) { 2300 if (ifidx != 0) {
2231 /* for virtual interfaces use the primary MAC */ 2301 /* for virtual interfaces use the primary MAC */
2232 memcpy(temp_addr, dhd->pub.mac.octet, ETHER_ADDR_LEN); 2302 memcpy(temp_addr, dhd->pub.mac.octet, ETH_ALEN);
2233 2303
2234 } 2304 }
2235 2305
@@ -2257,7 +2327,7 @@ int dhd_net_attach(dhd_pub_t *dhdp, int ifidx)
2257 2327
2258 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen; 2328 dhd->pub.rxsz = net->mtu + net->hard_header_len + dhd->pub.hdrlen;
2259 2329
2260 memcpy(net->dev_addr, temp_addr, ETHER_ADDR_LEN); 2330 memcpy(net->dev_addr, temp_addr, ETH_ALEN);
2261 2331
2262 if (register_netdev(net) != 0) { 2332 if (register_netdev(net) != 0) {
2263 DHD_ERROR(("%s: couldn't register the net device\n", 2333 DHD_ERROR(("%s: couldn't register the net device\n",
diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_linux_sched.c b/drivers/staging/brcm80211/brcmfmac/dhd_linux_sched.c
index bf8df9801030..c66f1c2941e2 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd_linux_sched.c
+++ b/drivers/staging/brcm80211/brcmfmac/dhd_linux_sched.c
@@ -16,7 +16,6 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linuxver.h>
20 19
21int setScheduler(struct task_struct *p, int policy, struct sched_param *param) 20int setScheduler(struct task_struct *p, int policy, struct sched_param *param)
22{ 21{
diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_proto.h b/drivers/staging/brcm80211/brcmfmac/dhd_proto.h
index cc42fa4a9140..a5309e27b65b 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd_proto.h
+++ b/drivers/staging/brcm80211/brcmfmac/dhd_proto.h
@@ -46,15 +46,16 @@ extern int dhd_prot_init(dhd_pub_t *dhdp);
46/* Stop protocol: sync w/dongle state. */ 46/* Stop protocol: sync w/dongle state. */
47extern void dhd_prot_stop(dhd_pub_t *dhdp); 47extern void dhd_prot_stop(dhd_pub_t *dhdp);
48 48
49extern bool dhd_proto_fcinfo(dhd_pub_t *dhd, void *pktbuf, u8 *fcbits); 49extern bool dhd_proto_fcinfo(dhd_pub_t *dhd, struct sk_buff *pktbuf,
50 u8 *fcbits);
50 51
51/* Add any protocol-specific data header. 52/* Add any protocol-specific data header.
52 * Caller must reserve prot_hdrlen prepend space. 53 * Caller must reserve prot_hdrlen prepend space.
53 */ 54 */
54extern void dhd_prot_hdrpush(dhd_pub_t *, int ifidx, void *txp); 55extern void dhd_prot_hdrpush(dhd_pub_t *, int ifidx, struct sk_buff *txp);
55 56
56/* Remove any protocol-specific data header. */ 57/* Remove any protocol-specific data header. */
57extern int dhd_prot_hdrpull(dhd_pub_t *, int *ifidx, void *rxp); 58extern int dhd_prot_hdrpull(dhd_pub_t *, int *ifidx, struct sk_buff *rxp);
58 59
59/* Use protocol to issue ioctl to dongle */ 60/* Use protocol to issue ioctl to dongle */
60extern int dhd_prot_ioctl(dhd_pub_t *dhd, int ifidx, wl_ioctl_t *ioc, 61extern int dhd_prot_ioctl(dhd_pub_t *dhd, int ifidx, wl_ioctl_t *ioc,
diff --git a/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c b/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c
index b2281d9dfdcf..3edce44978a1 100644
--- a/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/types.h> 17#include <linux/types.h>
18#include <bcmdefs.h> 18#include <bcmdefs.h>
19#include <linux/netdevice.h>
19#include <osl.h> 20#include <osl.h>
20#include <bcmsdh.h> 21#include <bcmsdh.h>
21 22
@@ -143,7 +144,7 @@
143 * bufpool was present for gspi bus. 144 * bufpool was present for gspi bus.
144 */ 145 */
145#define PKTFREE2() if ((bus->bus != SPI_BUS) || bus->usebufpool) \ 146#define PKTFREE2() if ((bus->bus != SPI_BUS) || bus->usebufpool) \
146 PKTFREE(bus->dhd->osh, pkt, false); 147 pkt_buf_free_skb(bus->dhd->osh, pkt, false);
147DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep); 148DHD_SPINWAIT_SLEEP_INIT(sdioh_spinwait_sleep);
148extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, 149extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
149 uint len); 150 uint len);
@@ -202,8 +203,8 @@ typedef struct dhd_bus {
202 u8 rx_seq; /* Receive sequence number (expected) */ 203 u8 rx_seq; /* Receive sequence number (expected) */
203 bool rxskip; /* Skip receive (awaiting NAK ACK) */ 204 bool rxskip; /* Skip receive (awaiting NAK ACK) */
204 205
205 void *glomd; /* Packet containing glomming descriptor */ 206 struct sk_buff *glomd; /* Packet containing glomming descriptor */
206 void *glom; /* Packet chain for glommed superframe */ 207 struct sk_buff *glom; /* Packet chain for glommed superframe */
207 uint glomerr; /* Glom packet read errors */ 208 uint glomerr; /* Glom packet read errors */
208 209
209 u8 *rxbuf; /* Buffer for receiving control packets */ 210 u8 *rxbuf; /* Buffer for receiving control packets */
@@ -356,16 +357,16 @@ extern void bcmsdh_enable_hw_oob_intr(void *sdh, bool enable);
356#if defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) 357#if defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD)
357#error OOB_INTR_ONLY is NOT working with SDIO_ISR_THREAD 358#error OOB_INTR_ONLY is NOT working with SDIO_ISR_THREAD
358#endif /* defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) */ 359#endif /* defined(OOB_INTR_ONLY) && defined(SDIO_ISR_THREAD) */
359#define PKTALIGN(osh, p, len, align) \ 360#define PKTALIGN(_osh, _p, _len, _align) \
360 do { \ 361 do { \
361 uint datalign; \ 362 uint datalign; \
362 datalign = (unsigned long)PKTDATA((p)); \ 363 datalign = (unsigned long)((_p)->data); \
363 datalign = roundup(datalign, (align)) - datalign; \ 364 datalign = roundup(datalign, (_align)) - datalign; \
364 ASSERT(datalign < (align)); \ 365 ASSERT(datalign < (_align)); \
365 ASSERT(PKTLEN((p)) >= ((len) + datalign)); \ 366 ASSERT((_p)->len >= ((_len) + datalign)); \
366 if (datalign) \ 367 if (datalign) \
367 PKTPULL((p), datalign); \ 368 skb_pull((_p), datalign); \
368 PKTSETLEN((p), (len)); \ 369 __skb_trim((_p), (_len)); \
369 } while (0) 370 } while (0)
370 371
371/* Limit on rounding up frames */ 372/* Limit on rounding up frames */
@@ -430,27 +431,30 @@ static int dhdsdio_mem_dump(dhd_bus_t *bus);
430#endif /* DHD_DEBUG */ 431#endif /* DHD_DEBUG */
431static int dhdsdio_download_state(dhd_bus_t *bus, bool enter); 432static int dhdsdio_download_state(dhd_bus_t *bus, bool enter);
432 433
433static void dhdsdio_release(dhd_bus_t *bus, osl_t *osh); 434static void dhdsdio_release(dhd_bus_t *bus, struct osl_info *osh);
434static void dhdsdio_release_malloc(dhd_bus_t *bus, osl_t *osh); 435static void dhdsdio_release_malloc(dhd_bus_t *bus, struct osl_info *osh);
435static void dhdsdio_disconnect(void *ptr); 436static void dhdsdio_disconnect(void *ptr);
436static bool dhdsdio_chipmatch(u16 chipid); 437static bool dhdsdio_chipmatch(u16 chipid);
437static bool dhdsdio_probe_attach(dhd_bus_t *bus, osl_t *osh, void *sdh, 438static bool dhdsdio_probe_attach(dhd_bus_t *bus, struct osl_info *osh,
438 void *regsva, u16 devid); 439 void *sdh, void *regsva, u16 devid);
439static bool dhdsdio_probe_malloc(dhd_bus_t *bus, osl_t *osh, void *sdh); 440static bool dhdsdio_probe_malloc(dhd_bus_t *bus, struct osl_info *osh,
440static bool dhdsdio_probe_init(dhd_bus_t *bus, osl_t *osh, void *sdh); 441 void *sdh);
441static void dhdsdio_release_dongle(dhd_bus_t *bus, osl_t * osh); 442static bool dhdsdio_probe_init(dhd_bus_t *bus, struct osl_info *osh, void *sdh);
443static void dhdsdio_release_dongle(dhd_bus_t *bus, struct osl_info * osh);
442 444
443static uint process_nvram_vars(char *varbuf, uint len); 445static uint process_nvram_vars(char *varbuf, uint len);
444 446
445static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size); 447static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size);
446static int dhd_bcmsdh_recv_buf(dhd_bus_t *bus, u32 addr, uint fn, 448static int dhd_bcmsdh_recv_buf(dhd_bus_t *bus, u32 addr, uint fn,
447 uint flags, u8 *buf, uint nbytes, void *pkt, 449 uint flags, u8 *buf, uint nbytes,
448 bcmsdh_cmplt_fn_t complete, void *handle); 450 struct sk_buff *pkt, bcmsdh_cmplt_fn_t complete,
451 void *handle);
449static int dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn, 452static int dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn,
450 uint flags, u8 *buf, uint nbytes, void *pkt, 453 uint flags, u8 *buf, uint nbytes,
451 bcmsdh_cmplt_fn_t complete, void *handle); 454 struct sk_buff *pkt, bcmsdh_cmplt_fn_t complete,
455 void *handle);
452 456
453static bool dhdsdio_download_firmware(struct dhd_bus *bus, osl_t *osh, 457static bool dhdsdio_download_firmware(struct dhd_bus *bus, struct osl_info *osh,
454 void *sdh); 458 void *sdh);
455static int _dhdsdio_download_firmware(struct dhd_bus *bus); 459static int _dhdsdio_download_firmware(struct dhd_bus *bus);
456 460
@@ -900,16 +904,17 @@ void dhd_enable_oob_intr(struct dhd_bus *bus, bool enable)
900 904
901/* Writes a HW/SW header into the packet and sends it. */ 905/* Writes a HW/SW header into the packet and sends it. */
902/* Assumes: (a) header space already there, (b) caller holds lock */ 906/* Assumes: (a) header space already there, (b) caller holds lock */
903static int dhdsdio_txpkt(dhd_bus_t *bus, void *pkt, uint chan, bool free_pkt) 907static int dhdsdio_txpkt(dhd_bus_t *bus, struct sk_buff *pkt, uint chan,
908 bool free_pkt)
904{ 909{
905 int ret; 910 int ret;
906 osl_t *osh; 911 struct osl_info *osh;
907 u8 *frame; 912 u8 *frame;
908 u16 len, pad = 0; 913 u16 len, pad = 0;
909 u32 swheader; 914 u32 swheader;
910 uint retries = 0; 915 uint retries = 0;
911 bcmsdh_info_t *sdh; 916 bcmsdh_info_t *sdh;
912 void *new; 917 struct sk_buff *new;
913 int i; 918 int i;
914 919
915 DHD_TRACE(("%s: Enter\n", __func__)); 920 DHD_TRACE(("%s: Enter\n", __func__));
@@ -922,46 +927,46 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, void *pkt, uint chan, bool free_pkt)
922 goto done; 927 goto done;
923 } 928 }
924 929
925 frame = (u8 *) PKTDATA(pkt); 930 frame = (u8 *) (pkt->data);
926 931
927 /* Add alignment padding, allocate new packet if needed */ 932 /* Add alignment padding, allocate new packet if needed */
928 pad = ((unsigned long)frame % DHD_SDALIGN); 933 pad = ((unsigned long)frame % DHD_SDALIGN);
929 if (pad) { 934 if (pad) {
930 if (PKTHEADROOM(pkt) < pad) { 935 if (skb_headroom(pkt) < pad) {
931 DHD_INFO(("%s: insufficient headroom %d for %d pad\n", 936 DHD_INFO(("%s: insufficient headroom %d for %d pad\n",
932 __func__, (int)PKTHEADROOM(pkt), pad)); 937 __func__, skb_headroom(pkt), pad));
933 bus->dhd->tx_realloc++; 938 bus->dhd->tx_realloc++;
934 new = PKTGET(osh, (PKTLEN(pkt) + DHD_SDALIGN), true); 939 new = pkt_buf_get_skb(osh, (pkt->len + DHD_SDALIGN));
935 if (!new) { 940 if (!new) {
936 DHD_ERROR(("%s: couldn't allocate new %d-byte " 941 DHD_ERROR(("%s: couldn't allocate new %d-byte "
937 "packet\n", 942 "packet\n",
938 __func__, PKTLEN(pkt) + DHD_SDALIGN)); 943 __func__, pkt->len + DHD_SDALIGN));
939 ret = BCME_NOMEM; 944 ret = BCME_NOMEM;
940 goto done; 945 goto done;
941 } 946 }
942 947
943 PKTALIGN(osh, new, PKTLEN(pkt), DHD_SDALIGN); 948 PKTALIGN(osh, new, pkt->len, DHD_SDALIGN);
944 bcopy(PKTDATA(pkt), PKTDATA(new), PKTLEN(pkt)); 949 bcopy(pkt->data, new->data, pkt->len);
945 if (free_pkt) 950 if (free_pkt)
946 PKTFREE(osh, pkt, true); 951 pkt_buf_free_skb(osh, pkt, true);
947 /* free the pkt if canned one is not used */ 952 /* free the pkt if canned one is not used */
948 free_pkt = true; 953 free_pkt = true;
949 pkt = new; 954 pkt = new;
950 frame = (u8 *) PKTDATA(pkt); 955 frame = (u8 *) (pkt->data);
951 ASSERT(((unsigned long)frame % DHD_SDALIGN) == 0); 956 ASSERT(((unsigned long)frame % DHD_SDALIGN) == 0);
952 pad = 0; 957 pad = 0;
953 } else { 958 } else {
954 PKTPUSH(pkt, pad); 959 skb_push(pkt, pad);
955 frame = (u8 *) PKTDATA(pkt); 960 frame = (u8 *) (pkt->data);
956 961
957 ASSERT((pad + SDPCM_HDRLEN) <= (int)PKTLEN(pkt)); 962 ASSERT((pad + SDPCM_HDRLEN) <= (int)(pkt->len));
958 bzero(frame, pad + SDPCM_HDRLEN); 963 memset(frame, 0, pad + SDPCM_HDRLEN);
959 } 964 }
960 } 965 }
961 ASSERT(pad < DHD_SDALIGN); 966 ASSERT(pad < DHD_SDALIGN);
962 967
963 /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */ 968 /* Hardware tag: 2 byte len followed by 2 byte ~len check (all LE) */
964 len = (u16) PKTLEN(pkt); 969 len = (u16) (pkt->len);
965 *(u16 *) frame = htol16(len); 970 *(u16 *) frame = htol16(len);
966 *(((u16 *) frame) + 1) = htol16(~len); 971 *(((u16 *) frame) + 1) = htol16(~len);
967 972
@@ -974,7 +979,7 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, void *pkt, uint chan, bool free_pkt)
974 htol32_ua_store(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader)); 979 htol32_ua_store(0, frame + SDPCM_FRAMETAG_LEN + sizeof(swheader));
975 980
976#ifdef DHD_DEBUG 981#ifdef DHD_DEBUG
977 tx_packets[PKTPRIO(pkt)]++; 982 tx_packets[pkt->priority]++;
978 if (DHD_BYTES_ON() && 983 if (DHD_BYTES_ON() &&
979 (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) || 984 (((DHD_CTL_ON() && (chan == SDPCM_CONTROL_CHANNEL)) ||
980 (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) { 985 (DHD_DATA_ON() && (chan != SDPCM_CONTROL_CHANNEL))))) {
@@ -989,7 +994,7 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, void *pkt, uint chan, bool free_pkt)
989 u16 pad = bus->blocksize - (len % bus->blocksize); 994 u16 pad = bus->blocksize - (len % bus->blocksize);
990 if ((pad <= bus->roundup) && (pad < bus->blocksize)) 995 if ((pad <= bus->roundup) && (pad < bus->blocksize))
991#ifdef NOTUSED 996#ifdef NOTUSED
992 if (pad <= PKTTAILROOM(pkt)) 997 if (pad <= skb_tailroom(pkt))
993#endif /* NOTUSED */ 998#endif /* NOTUSED */
994 len += pad; 999 len += pad;
995 } else if (len % DHD_SDALIGN) { 1000 } else if (len % DHD_SDALIGN) {
@@ -999,7 +1004,7 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, void *pkt, uint chan, bool free_pkt)
999 /* Some controllers have trouble with odd bytes -- round to even */ 1004 /* Some controllers have trouble with odd bytes -- round to even */
1000 if (forcealign && (len & (ALIGNMENT - 1))) { 1005 if (forcealign && (len & (ALIGNMENT - 1))) {
1001#ifdef NOTUSED 1006#ifdef NOTUSED
1002 if (PKTTAILROOM(pkt)) 1007 if (skb_tailroom(pkt))
1003#endif 1008#endif
1004 len = roundup(len, ALIGNMENT); 1009 len = roundup(len, ALIGNMENT);
1005#ifdef NOTUSED 1010#ifdef NOTUSED
@@ -1050,34 +1055,34 @@ static int dhdsdio_txpkt(dhd_bus_t *bus, void *pkt, uint chan, bool free_pkt)
1050 1055
1051done: 1056done:
1052 /* restore pkt buffer pointer before calling tx complete routine */ 1057 /* restore pkt buffer pointer before calling tx complete routine */
1053 PKTPULL(pkt, SDPCM_HDRLEN + pad); 1058 skb_pull(pkt, SDPCM_HDRLEN + pad);
1054 dhd_os_sdunlock(bus->dhd); 1059 dhd_os_sdunlock(bus->dhd);
1055 dhd_txcomplete(bus->dhd, pkt, ret != 0); 1060 dhd_txcomplete(bus->dhd, pkt, ret != 0);
1056 dhd_os_sdlock(bus->dhd); 1061 dhd_os_sdlock(bus->dhd);
1057 1062
1058 if (free_pkt) 1063 if (free_pkt)
1059 PKTFREE(osh, pkt, true); 1064 pkt_buf_free_skb(osh, pkt, true);
1060 1065
1061 return ret; 1066 return ret;
1062} 1067}
1063 1068
1064int dhd_bus_txdata(struct dhd_bus *bus, void *pkt) 1069int dhd_bus_txdata(struct dhd_bus *bus, struct sk_buff *pkt)
1065{ 1070{
1066 int ret = BCME_ERROR; 1071 int ret = BCME_ERROR;
1067 osl_t *osh; 1072 struct osl_info *osh;
1068 uint datalen, prec; 1073 uint datalen, prec;
1069 1074
1070 DHD_TRACE(("%s: Enter\n", __func__)); 1075 DHD_TRACE(("%s: Enter\n", __func__));
1071 1076
1072 osh = bus->dhd->osh; 1077 osh = bus->dhd->osh;
1073 datalen = PKTLEN(pkt); 1078 datalen = pkt->len;
1074 1079
1075#ifdef SDTEST 1080#ifdef SDTEST
1076 /* Push the test header if doing loopback */ 1081 /* Push the test header if doing loopback */
1077 if (bus->ext_loop) { 1082 if (bus->ext_loop) {
1078 u8 *data; 1083 u8 *data;
1079 PKTPUSH(pkt, SDPCM_TEST_HDRLEN); 1084 skb_push(pkt, SDPCM_TEST_HDRLEN);
1080 data = PKTDATA(pkt); 1085 data = pkt->data;
1081 *data++ = SDPCM_TEST_ECHOREQ; 1086 *data++ = SDPCM_TEST_ECHOREQ;
1082 *data++ = (u8) bus->loopid++; 1087 *data++ = (u8) bus->loopid++;
1083 *data++ = (datalen >> 0); 1088 *data++ = (datalen >> 0);
@@ -1087,10 +1092,10 @@ int dhd_bus_txdata(struct dhd_bus *bus, void *pkt)
1087#endif /* SDTEST */ 1092#endif /* SDTEST */
1088 1093
1089 /* Add space for the header */ 1094 /* Add space for the header */
1090 PKTPUSH(pkt, SDPCM_HDRLEN); 1095 skb_push(pkt, SDPCM_HDRLEN);
1091 ASSERT(IS_ALIGNED((unsigned long)PKTDATA(pkt), 2)); 1096 ASSERT(IS_ALIGNED((unsigned long)(pkt->data), 2));
1092 1097
1093 prec = PRIO2PREC((PKTPRIO(pkt) & PRIOMASK)); 1098 prec = PRIO2PREC((pkt->priority & PRIOMASK));
1094 1099
1095 /* Check for existing queue, current flow-control, 1100 /* Check for existing queue, current flow-control,
1096 pending event, or pending clock */ 1101 pending event, or pending clock */
@@ -1105,9 +1110,9 @@ int dhd_bus_txdata(struct dhd_bus *bus, void *pkt)
1105 /* Priority based enq */ 1110 /* Priority based enq */
1106 dhd_os_sdlock_txq(bus->dhd); 1111 dhd_os_sdlock_txq(bus->dhd);
1107 if (dhd_prec_enq(bus->dhd, &bus->txq, pkt, prec) == false) { 1112 if (dhd_prec_enq(bus->dhd, &bus->txq, pkt, prec) == false) {
1108 PKTPULL(pkt, SDPCM_HDRLEN); 1113 skb_pull(pkt, SDPCM_HDRLEN);
1109 dhd_txcomplete(bus->dhd, pkt, false); 1114 dhd_txcomplete(bus->dhd, pkt, false);
1110 PKTFREE(osh, pkt, true); 1115 pkt_buf_free_skb(osh, pkt, true);
1111 DHD_ERROR(("%s: out of bus->txq !!!\n", __func__)); 1116 DHD_ERROR(("%s: out of bus->txq !!!\n", __func__));
1112 ret = BCME_NORESOURCE; 1117 ret = BCME_NORESOURCE;
1113 } else { 1118 } else {
@@ -1162,7 +1167,7 @@ int dhd_bus_txdata(struct dhd_bus *bus, void *pkt)
1162 1167
1163static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes) 1168static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes)
1164{ 1169{
1165 void *pkt; 1170 struct sk_buff *pkt;
1166 u32 intstatus = 0; 1171 u32 intstatus = 0;
1167 uint retries = 0; 1172 uint retries = 0;
1168 int ret = 0, prec_out; 1173 int ret = 0, prec_out;
@@ -1186,7 +1191,7 @@ static uint dhdsdio_sendfromq(dhd_bus_t *bus, uint maxframes)
1186 break; 1191 break;
1187 } 1192 }
1188 dhd_os_sdunlock_txq(bus->dhd); 1193 dhd_os_sdunlock_txq(bus->dhd);
1189 datalen = PKTLEN(pkt) - SDPCM_HDRLEN; 1194 datalen = pkt->len - SDPCM_HDRLEN;
1190 1195
1191#ifndef SDTEST 1196#ifndef SDTEST
1192 ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true); 1197 ret = dhdsdio_txpkt(bus, pkt, SDPCM_DATA_CHANNEL, true);
@@ -1247,7 +1252,7 @@ int dhd_bus_txctl(struct dhd_bus *bus, unsigned char *msg, uint msglen)
1247 frame -= doff; 1252 frame -= doff;
1248 len += doff; 1253 len += doff;
1249 msglen += doff; 1254 msglen += doff;
1250 bzero(frame, doff + SDPCM_HDRLEN); 1255 memset(frame, 0, doff + SDPCM_HDRLEN);
1251 } 1256 }
1252 ASSERT(doff < DHD_SDALIGN); 1257 ASSERT(doff < DHD_SDALIGN);
1253 } 1258 }
@@ -2531,7 +2536,7 @@ static int dhdsdio_write_vars(dhd_bus_t *bus)
2531 if (!vbuffer) 2536 if (!vbuffer)
2532 return BCME_NOMEM; 2537 return BCME_NOMEM;
2533 2538
2534 bzero(vbuffer, varsize); 2539 memset(vbuffer, 0, varsize);
2535 bcopy(bus->vars, vbuffer, bus->varsz); 2540 bcopy(bus->vars, vbuffer, bus->varsz);
2536 2541
2537 /* Write the vars list */ 2542 /* Write the vars list */
@@ -2823,7 +2828,7 @@ exit:
2823 2828
2824void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex) 2829void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex)
2825{ 2830{
2826 osl_t *osh = bus->dhd->osh; 2831 struct osl_info *osh = bus->dhd->osh;
2827 u32 local_hostintmask; 2832 u32 local_hostintmask;
2828 u8 saveclk; 2833 u8 saveclk;
2829 uint retries; 2834 uint retries;
@@ -2877,10 +2882,10 @@ void dhd_bus_stop(struct dhd_bus *bus, bool enforce_mutex)
2877 2882
2878 /* Clear any held glomming stuff */ 2883 /* Clear any held glomming stuff */
2879 if (bus->glomd) 2884 if (bus->glomd)
2880 PKTFREE(osh, bus->glomd, false); 2885 pkt_buf_free_skb(osh, bus->glomd, false);
2881 2886
2882 if (bus->glom) 2887 if (bus->glom)
2883 PKTFREE(osh, bus->glom, false); 2888 pkt_buf_free_skb(osh, bus->glom, false);
2884 2889
2885 bus->glom = bus->glomd = NULL; 2890 bus->glom = bus->glomd = NULL;
2886 2891
@@ -3178,8 +3183,8 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3178 u8 *dptr, num = 0; 3183 u8 *dptr, num = 0;
3179 3184
3180 u16 sublen, check; 3185 u16 sublen, check;
3181 void *pfirst, *plast, *pnext, *save_pfirst; 3186 struct sk_buff *pfirst, *plast, *pnext, *save_pfirst;
3182 osl_t *osh = bus->dhd->osh; 3187 struct osl_info *osh = bus->dhd->osh;
3183 3188
3184 int errcode; 3189 int errcode;
3185 u8 chan, seq, doff, sfdoff; 3190 u8 chan, seq, doff, sfdoff;
@@ -3199,8 +3204,8 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3199 dhd_os_sdlock_rxq(bus->dhd); 3204 dhd_os_sdlock_rxq(bus->dhd);
3200 3205
3201 pfirst = plast = pnext = NULL; 3206 pfirst = plast = pnext = NULL;
3202 dlen = (u16) PKTLEN(bus->glomd); 3207 dlen = (u16) (bus->glomd->len);
3203 dptr = PKTDATA(bus->glomd); 3208 dptr = bus->glomd->data;
3204 if (!dlen || (dlen & 1)) { 3209 if (!dlen || (dlen & 1)) {
3205 DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n", 3210 DHD_ERROR(("%s: bad glomd len(%d), ignore descriptor\n",
3206 __func__, dlen)); 3211 __func__, dlen));
@@ -3235,19 +3240,19 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3235 } 3240 }
3236 3241
3237 /* Allocate/chain packet for next subframe */ 3242 /* Allocate/chain packet for next subframe */
3238 pnext = PKTGET(osh, sublen + DHD_SDALIGN, false); 3243 pnext = pkt_buf_get_skb(osh, sublen + DHD_SDALIGN);
3239 if (pnext == NULL) { 3244 if (pnext == NULL) {
3240 DHD_ERROR(("%s: PKTGET failed, num %d len %d\n", 3245 DHD_ERROR(("%s: pkt_buf_get_skb failed, num %d len %d\n",
3241 __func__, num, sublen)); 3246 __func__, num, sublen));
3242 break; 3247 break;
3243 } 3248 }
3244 ASSERT(!PKTLINK(pnext)); 3249 ASSERT(!(pnext->prev));
3245 if (!pfirst) { 3250 if (!pfirst) {
3246 ASSERT(!plast); 3251 ASSERT(!plast);
3247 pfirst = plast = pnext; 3252 pfirst = plast = pnext;
3248 } else { 3253 } else {
3249 ASSERT(plast); 3254 ASSERT(plast);
3250 PKTSETNEXT(plast, pnext); 3255 plast->next = pnext;
3251 plast = pnext; 3256 plast = pnext;
3252 } 3257 }
3253 3258
@@ -3271,13 +3276,13 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3271 pfirst = pnext = NULL; 3276 pfirst = pnext = NULL;
3272 } else { 3277 } else {
3273 if (pfirst) 3278 if (pfirst)
3274 PKTFREE(osh, pfirst, false); 3279 pkt_buf_free_skb(osh, pfirst, false);
3275 bus->glom = NULL; 3280 bus->glom = NULL;
3276 num = 0; 3281 num = 0;
3277 } 3282 }
3278 3283
3279 /* Done with descriptor packet */ 3284 /* Done with descriptor packet */
3280 PKTFREE(osh, bus->glomd, false); 3285 pkt_buf_free_skb(osh, bus->glomd, false);
3281 bus->glomd = NULL; 3286 bus->glomd = NULL;
3282 bus->nextlen = 0; 3287 bus->nextlen = 0;
3283 3288
@@ -3290,10 +3295,10 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3290 if (DHD_GLOM_ON()) { 3295 if (DHD_GLOM_ON()) {
3291 DHD_GLOM(("%s: try superframe read, packet chain:\n", 3296 DHD_GLOM(("%s: try superframe read, packet chain:\n",
3292 __func__)); 3297 __func__));
3293 for (pnext = bus->glom; pnext; pnext = PKTNEXT(pnext)) { 3298 for (pnext = bus->glom; pnext; pnext = pnext->next) {
3294 DHD_GLOM((" %p: %p len 0x%04x (%d)\n", 3299 DHD_GLOM((" %p: %p len 0x%04x (%d)\n",
3295 pnext, (u8 *) PKTDATA(pnext), 3300 pnext, (u8 *) (pnext->data),
3296 PKTLEN(pnext), PKTLEN(pnext))); 3301 pnext->len, pnext->len));
3297 } 3302 }
3298 } 3303 }
3299 3304
@@ -3309,7 +3314,7 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3309 bcmsdh_cur_sbwad 3314 bcmsdh_cur_sbwad
3310 (bus->sdh), SDIO_FUNC_2, 3315 (bus->sdh), SDIO_FUNC_2,
3311 F2SYNC, 3316 F2SYNC,
3312 (u8 *) PKTDATA(pfirst), 3317 (u8 *) pfirst->data,
3313 dlen, pfirst, NULL, NULL); 3318 dlen, pfirst, NULL, NULL);
3314 } else if (bus->dataptr) { 3319 } else if (bus->dataptr) {
3315 errcode = dhd_bcmsdh_recv_buf(bus, 3320 errcode = dhd_bcmsdh_recv_buf(bus,
@@ -3346,7 +3351,7 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3346 bus->glomerr = 0; 3351 bus->glomerr = 0;
3347 dhdsdio_rxfail(bus, true, false); 3352 dhdsdio_rxfail(bus, true, false);
3348 dhd_os_sdlock_rxq(bus->dhd); 3353 dhd_os_sdlock_rxq(bus->dhd);
3349 PKTFREE(osh, bus->glom, false); 3354 pkt_buf_free_skb(osh, bus->glom, false);
3350 dhd_os_sdunlock_rxq(bus->dhd); 3355 dhd_os_sdunlock_rxq(bus->dhd);
3351 bus->rxglomfail++; 3356 bus->rxglomfail++;
3352 bus->glom = NULL; 3357 bus->glom = NULL;
@@ -3355,13 +3360,13 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3355 } 3360 }
3356#ifdef DHD_DEBUG 3361#ifdef DHD_DEBUG
3357 if (DHD_GLOM_ON()) { 3362 if (DHD_GLOM_ON()) {
3358 prhex("SUPERFRAME", PKTDATA(pfirst), 3363 prhex("SUPERFRAME", pfirst->data,
3359 min_t(int, PKTLEN(pfirst), 48)); 3364 min_t(int, pfirst->len, 48));
3360 } 3365 }
3361#endif 3366#endif
3362 3367
3363 /* Validate the superframe header */ 3368 /* Validate the superframe header */
3364 dptr = (u8 *) PKTDATA(pfirst); 3369 dptr = (u8 *) (pfirst->data);
3365 sublen = ltoh16_ua(dptr); 3370 sublen = ltoh16_ua(dptr);
3366 check = ltoh16_ua(dptr + sizeof(u16)); 3371 check = ltoh16_ua(dptr + sizeof(u16));
3367 3372
@@ -3399,11 +3404,11 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3399 __func__)); 3404 __func__));
3400 errcode = -1; 3405 errcode = -1;
3401 } else if ((doff < SDPCM_HDRLEN) || 3406 } else if ((doff < SDPCM_HDRLEN) ||
3402 (doff > (PKTLEN(pfirst) - SDPCM_HDRLEN))) { 3407 (doff > (pfirst->len - SDPCM_HDRLEN))) {
3403 DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d " 3408 DHD_ERROR(("%s (superframe): Bad data offset %d: HW %d "
3404 "pkt %d min %d\n", 3409 "pkt %d min %d\n",
3405 __func__, doff, sublen, 3410 __func__, doff, sublen,
3406 PKTLEN(pfirst), SDPCM_HDRLEN)); 3411 pfirst->len, SDPCM_HDRLEN));
3407 errcode = -1; 3412 errcode = -1;
3408 } 3413 }
3409 3414
@@ -3424,14 +3429,14 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3424 bus->tx_max = txmax; 3429 bus->tx_max = txmax;
3425 3430
3426 /* Remove superframe header, remember offset */ 3431 /* Remove superframe header, remember offset */
3427 PKTPULL(pfirst, doff); 3432 skb_pull(pfirst, doff);
3428 sfdoff = doff; 3433 sfdoff = doff;
3429 3434
3430 /* Validate all the subframe headers */ 3435 /* Validate all the subframe headers */
3431 for (num = 0, pnext = pfirst; pnext && !errcode; 3436 for (num = 0, pnext = pfirst; pnext && !errcode;
3432 num++, pnext = PKTNEXT(pnext)) { 3437 num++, pnext = pnext->next) {
3433 dptr = (u8 *) PKTDATA(pnext); 3438 dptr = (u8 *) (pnext->data);
3434 dlen = (u16) PKTLEN(pnext); 3439 dlen = (u16) (pnext->len);
3435 sublen = ltoh16_ua(dptr); 3440 sublen = ltoh16_ua(dptr);
3436 check = ltoh16_ua(dptr + sizeof(u16)); 3441 check = ltoh16_ua(dptr + sizeof(u16));
3437 chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); 3442 chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]);
@@ -3469,13 +3474,13 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3469 a couple retries */ 3474 a couple retries */
3470 if (bus->glomerr++ < 3) { 3475 if (bus->glomerr++ < 3) {
3471 /* Restore superframe header space */ 3476 /* Restore superframe header space */
3472 PKTPUSH(pfirst, sfdoff); 3477 skb_push(pfirst, sfdoff);
3473 dhdsdio_rxfail(bus, true, true); 3478 dhdsdio_rxfail(bus, true, true);
3474 } else { 3479 } else {
3475 bus->glomerr = 0; 3480 bus->glomerr = 0;
3476 dhdsdio_rxfail(bus, true, false); 3481 dhdsdio_rxfail(bus, true, false);
3477 dhd_os_sdlock_rxq(bus->dhd); 3482 dhd_os_sdlock_rxq(bus->dhd);
3478 PKTFREE(osh, bus->glom, false); 3483 pkt_buf_free_skb(osh, bus->glom, false);
3479 dhd_os_sdunlock_rxq(bus->dhd); 3484 dhd_os_sdunlock_rxq(bus->dhd);
3480 bus->rxglomfail++; 3485 bus->rxglomfail++;
3481 bus->glom = NULL; 3486 bus->glom = NULL;
@@ -3491,10 +3496,10 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3491 3496
3492 dhd_os_sdlock_rxq(bus->dhd); 3497 dhd_os_sdlock_rxq(bus->dhd);
3493 for (num = 0; pfirst; rxseq++, pfirst = pnext) { 3498 for (num = 0; pfirst; rxseq++, pfirst = pnext) {
3494 pnext = PKTNEXT(pfirst); 3499 pnext = pfirst->next;
3495 PKTSETNEXT(pfirst, NULL); 3500 pfirst->next = NULL;
3496 3501
3497 dptr = (u8 *) PKTDATA(pfirst); 3502 dptr = (u8 *) (pfirst->data);
3498 sublen = ltoh16_ua(dptr); 3503 sublen = ltoh16_ua(dptr);
3499 chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]); 3504 chan = SDPCM_PACKET_CHANNEL(&dptr[SDPCM_FRAMETAG_LEN]);
3500 seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]); 3505 seq = SDPCM_PACKET_SEQUENCE(&dptr[SDPCM_FRAMETAG_LEN]);
@@ -3502,8 +3507,8 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3502 3507
3503 DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d " 3508 DHD_GLOM(("%s: Get subframe %d, %p(%p/%d), sublen %d "
3504 "chan %d seq %d\n", 3509 "chan %d seq %d\n",
3505 __func__, num, pfirst, PKTDATA(pfirst), 3510 __func__, num, pfirst, pfirst->data,
3506 PKTLEN(pfirst), sublen, chan, seq)); 3511 pfirst->len, sublen, chan, seq));
3507 3512
3508 ASSERT((chan == SDPCM_DATA_CHANNEL) 3513 ASSERT((chan == SDPCM_DATA_CHANNEL)
3509 || (chan == SDPCM_EVENT_CHANNEL)); 3514 || (chan == SDPCM_EVENT_CHANNEL));
@@ -3519,13 +3524,13 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3519 prhex("Rx Subframe Data", dptr, dlen); 3524 prhex("Rx Subframe Data", dptr, dlen);
3520#endif 3525#endif
3521 3526
3522 PKTSETLEN(pfirst, sublen); 3527 __skb_trim(pfirst, sublen);
3523 PKTPULL(pfirst, doff); 3528 skb_pull(pfirst, doff);
3524 3529
3525 if (PKTLEN(pfirst) == 0) { 3530 if (pfirst->len == 0) {
3526 PKTFREE(bus->dhd->osh, pfirst, false); 3531 pkt_buf_free_skb(bus->dhd->osh, pfirst, false);
3527 if (plast) { 3532 if (plast) {
3528 PKTSETNEXT(plast, pnext); 3533 plast->next = pnext;
3529 } else { 3534 } else {
3530 ASSERT(save_pfirst == pfirst); 3535 ASSERT(save_pfirst == pfirst);
3531 save_pfirst = pnext; 3536 save_pfirst = pnext;
@@ -3536,9 +3541,9 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3536 DHD_ERROR(("%s: rx protocol error\n", 3541 DHD_ERROR(("%s: rx protocol error\n",
3537 __func__)); 3542 __func__));
3538 bus->dhd->rx_errors++; 3543 bus->dhd->rx_errors++;
3539 PKTFREE(osh, pfirst, false); 3544 pkt_buf_free_skb(osh, pfirst, false);
3540 if (plast) { 3545 if (plast) {
3541 PKTSETNEXT(plast, pnext); 3546 plast->next = pnext;
3542 } else { 3547 } else {
3543 ASSERT(save_pfirst == pfirst); 3548 ASSERT(save_pfirst == pfirst);
3544 save_pfirst = pnext; 3549 save_pfirst = pnext;
@@ -3548,7 +3553,7 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3548 3553
3549 /* this packet will go up, link back into 3554 /* this packet will go up, link back into
3550 chain and count it */ 3555 chain and count it */
3551 PKTSETNEXT(pfirst, pnext); 3556 pfirst->next = pnext;
3552 plast = pfirst; 3557 plast = pfirst;
3553 num++; 3558 num++;
3554 3559
@@ -3556,11 +3561,11 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3556 if (DHD_GLOM_ON()) { 3561 if (DHD_GLOM_ON()) {
3557 DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) " 3562 DHD_GLOM(("%s subframe %d to stack, %p(%p/%d) "
3558 "nxt/lnk %p/%p\n", 3563 "nxt/lnk %p/%p\n",
3559 __func__, num, pfirst, PKTDATA(pfirst), 3564 __func__, num, pfirst, pfirst->data,
3560 PKTLEN(pfirst), PKTNEXT(pfirst), 3565 pfirst->len, pfirst->next,
3561 PKTLINK(pfirst))); 3566 pfirst->prev));
3562 prhex("", (u8 *) PKTDATA(pfirst), 3567 prhex("", (u8 *) pfirst->data,
3563 min_t(int, PKTLEN(pfirst), 32)); 3568 min_t(int, pfirst->len, 32));
3564 } 3569 }
3565#endif /* DHD_DEBUG */ 3570#endif /* DHD_DEBUG */
3566 } 3571 }
@@ -3580,7 +3585,7 @@ static u8 dhdsdio_rxglom(dhd_bus_t *bus, u8 rxseq)
3580/* Return true if there may be more frames to read */ 3585/* Return true if there may be more frames to read */
3581static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished) 3586static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
3582{ 3587{
3583 osl_t *osh = bus->dhd->osh; 3588 struct osl_info *osh = bus->dhd->osh;
3584 bcmsdh_info_t *sdh = bus->sdh; 3589 bcmsdh_info_t *sdh = bus->sdh;
3585 3590
3586 u16 len, check; /* Extracted hardware header fields */ 3591 u16 len, check; /* Extracted hardware header fields */
@@ -3588,7 +3593,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
3588 u8 fcbits; /* Extracted fcbits from software header */ 3593 u8 fcbits; /* Extracted fcbits from software header */
3589 u8 delta; 3594 u8 delta;
3590 3595
3591 void *pkt; /* Packet for event or data frames */ 3596 struct sk_buff *pkt; /* Packet for event or data frames */
3592 u16 pad; /* Number of pad bytes to read */ 3597 u16 pad; /* Number of pad bytes to read */
3593 u16 rdlen; /* Total number of bytes to read */ 3598 u16 rdlen; /* Total number of bytes to read */
3594 u8 rxseq; /* Next sequence number to expect */ 3599 u8 rxseq; /* Next sequence number to expect */
@@ -3675,7 +3680,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
3675 */ 3680 */
3676 /* Allocate a packet buffer */ 3681 /* Allocate a packet buffer */
3677 dhd_os_sdlock_rxq(bus->dhd); 3682 dhd_os_sdlock_rxq(bus->dhd);
3678 pkt = PKTGET(osh, rdlen + DHD_SDALIGN, false); 3683 pkt = pkt_buf_get_skb(osh, rdlen + DHD_SDALIGN);
3679 if (!pkt) { 3684 if (!pkt) {
3680 if (bus->bus == SPI_BUS) { 3685 if (bus->bus == SPI_BUS) {
3681 bus->usebufpool = false; 3686 bus->usebufpool = false;
@@ -3721,7 +3726,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
3721 } else { 3726 } else {
3722 /* Give up on data, 3727 /* Give up on data,
3723 request rtx of events */ 3728 request rtx of events */
3724 DHD_ERROR(("%s (nextlen): PKTGET failed: len %d rdlen %d " "expected rxseq %d\n", 3729 DHD_ERROR(("%s (nextlen): pkt_buf_get_skb failed: len %d rdlen %d " "expected rxseq %d\n",
3725 __func__, len, rdlen, rxseq)); 3730 __func__, len, rdlen, rxseq));
3726 /* Just go try again w/normal 3731 /* Just go try again w/normal
3727 header read */ 3732 header read */
@@ -3732,9 +3737,9 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
3732 if (bus->bus == SPI_BUS) 3737 if (bus->bus == SPI_BUS)
3733 bus->usebufpool = true; 3738 bus->usebufpool = true;
3734 3739
3735 ASSERT(!PKTLINK(pkt)); 3740 ASSERT(!(pkt->prev));
3736 PKTALIGN(osh, pkt, rdlen, DHD_SDALIGN); 3741 PKTALIGN(osh, pkt, rdlen, DHD_SDALIGN);
3737 rxbuf = (u8 *) PKTDATA(pkt); 3742 rxbuf = (u8 *) (pkt->data);
3738 /* Read the entire frame */ 3743 /* Read the entire frame */
3739 sdret = 3744 sdret =
3740 dhd_bcmsdh_recv_buf(bus, 3745 dhd_bcmsdh_recv_buf(bus,
@@ -3748,7 +3753,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
3748 if (sdret < 0) { 3753 if (sdret < 0) {
3749 DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n", 3754 DHD_ERROR(("%s (nextlen): read %d bytes failed: %d\n",
3750 __func__, rdlen, sdret)); 3755 __func__, rdlen, sdret));
3751 PKTFREE(bus->dhd->osh, pkt, false); 3756 pkt_buf_free_skb(bus->dhd->osh, pkt, false);
3752 bus->dhd->rx_errors++; 3757 bus->dhd->rx_errors++;
3753 dhd_os_sdunlock_rxq(bus->dhd); 3758 dhd_os_sdunlock_rxq(bus->dhd);
3754 /* Force retry w/normal header read. 3759 /* Force retry w/normal header read.
@@ -3896,7 +3901,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
3896 doff); 3901 doff);
3897 if (bus->usebufpool) { 3902 if (bus->usebufpool) {
3898 dhd_os_sdlock_rxq(bus->dhd); 3903 dhd_os_sdlock_rxq(bus->dhd);
3899 PKTFREE(bus->dhd->osh, pkt, 3904 pkt_buf_free_skb(bus->dhd->osh, pkt,
3900 false); 3905 false);
3901 dhd_os_sdunlock_rxq(bus->dhd); 3906 dhd_os_sdunlock_rxq(bus->dhd);
3902 } 3907 }
@@ -4086,10 +4091,10 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
4086 } 4091 }
4087 4092
4088 dhd_os_sdlock_rxq(bus->dhd); 4093 dhd_os_sdlock_rxq(bus->dhd);
4089 pkt = PKTGET(osh, (rdlen + firstread + DHD_SDALIGN), false); 4094 pkt = pkt_buf_get_skb(osh, (rdlen + firstread + DHD_SDALIGN));
4090 if (!pkt) { 4095 if (!pkt) {
4091 /* Give up on data, request rtx of events */ 4096 /* Give up on data, request rtx of events */
4092 DHD_ERROR(("%s: PKTGET failed: rdlen %d chan %d\n", 4097 DHD_ERROR(("%s: pkt_buf_get_skb failed: rdlen %d chan %d\n",
4093 __func__, rdlen, chan)); 4098 __func__, rdlen, chan));
4094 bus->dhd->rx_dropped++; 4099 bus->dhd->rx_dropped++;
4095 dhd_os_sdunlock_rxq(bus->dhd); 4100 dhd_os_sdunlock_rxq(bus->dhd);
@@ -4098,17 +4103,17 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
4098 } 4103 }
4099 dhd_os_sdunlock_rxq(bus->dhd); 4104 dhd_os_sdunlock_rxq(bus->dhd);
4100 4105
4101 ASSERT(!PKTLINK(pkt)); 4106 ASSERT(!(pkt->prev));
4102 4107
4103 /* Leave room for what we already read, and align remainder */ 4108 /* Leave room for what we already read, and align remainder */
4104 ASSERT(firstread < (PKTLEN(pkt))); 4109 ASSERT(firstread < pkt->len);
4105 PKTPULL(pkt, firstread); 4110 skb_pull(pkt, firstread);
4106 PKTALIGN(osh, pkt, rdlen, DHD_SDALIGN); 4111 PKTALIGN(osh, pkt, rdlen, DHD_SDALIGN);
4107 4112
4108 /* Read the remaining frame data */ 4113 /* Read the remaining frame data */
4109 sdret = 4114 sdret =
4110 dhd_bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2, 4115 dhd_bcmsdh_recv_buf(bus, bcmsdh_cur_sbwad(sdh), SDIO_FUNC_2,
4111 F2SYNC, ((u8 *) PKTDATA(pkt)), rdlen, 4116 F2SYNC, ((u8 *) (pkt->data)), rdlen,
4112 pkt, NULL, NULL); 4117 pkt, NULL, NULL);
4113 bus->f2rxdata++; 4118 bus->f2rxdata++;
4114 ASSERT(sdret != BCME_PENDING); 4119 ASSERT(sdret != BCME_PENDING);
@@ -4122,7 +4127,7 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
4122 ? "data" : "test")), 4127 ? "data" : "test")),
4123 sdret)); 4128 sdret));
4124 dhd_os_sdlock_rxq(bus->dhd); 4129 dhd_os_sdlock_rxq(bus->dhd);
4125 PKTFREE(bus->dhd->osh, pkt, false); 4130 pkt_buf_free_skb(bus->dhd->osh, pkt, false);
4126 dhd_os_sdunlock_rxq(bus->dhd); 4131 dhd_os_sdunlock_rxq(bus->dhd);
4127 bus->dhd->rx_errors++; 4132 bus->dhd->rx_errors++;
4128 dhdsdio_rxfail(bus, true, RETRYCHAN(chan)); 4133 dhdsdio_rxfail(bus, true, RETRYCHAN(chan));
@@ -4130,12 +4135,12 @@ static uint dhdsdio_readframes(dhd_bus_t *bus, uint maxframes, bool *finished)
4130 } 4135 }
4131 4136
4132 /* Copy the already-read portion */ 4137 /* Copy the already-read portion */
4133 PKTPUSH(pkt, firstread); 4138 skb_push(pkt, firstread);
4134 bcopy(bus->rxhdr, PKTDATA(pkt), firstread); 4139 bcopy(bus->rxhdr, pkt->data, firstread);
4135 4140
4136#ifdef DHD_DEBUG 4141#ifdef DHD_DEBUG
4137 if (DHD_BYTES_ON() && DHD_DATA_ON()) 4142 if (DHD_BYTES_ON() && DHD_DATA_ON())
4138 prhex("Rx Data", PKTDATA(pkt), len); 4143 prhex("Rx Data", pkt->data, len);
4139#endif 4144#endif
4140 4145
4141deliver: 4146deliver:
@@ -4146,12 +4151,12 @@ deliver:
4146 __func__, len)); 4151 __func__, len));
4147#ifdef DHD_DEBUG 4152#ifdef DHD_DEBUG
4148 if (DHD_GLOM_ON()) { 4153 if (DHD_GLOM_ON()) {
4149 prhex("Glom Data", PKTDATA(pkt), len); 4154 prhex("Glom Data", pkt->data, len);
4150 } 4155 }
4151#endif 4156#endif
4152 PKTSETLEN(pkt, len); 4157 __skb_trim(pkt, len);
4153 ASSERT(doff == SDPCM_HDRLEN); 4158 ASSERT(doff == SDPCM_HDRLEN);
4154 PKTPULL(pkt, SDPCM_HDRLEN); 4159 skb_pull(pkt, SDPCM_HDRLEN);
4155 bus->glomd = pkt; 4160 bus->glomd = pkt;
4156 } else { 4161 } else {
4157 DHD_ERROR(("%s: glom superframe w/o " 4162 DHD_ERROR(("%s: glom superframe w/o "
@@ -4162,8 +4167,8 @@ deliver:
4162 } 4167 }
4163 4168
4164 /* Fill in packet len and prio, deliver upward */ 4169 /* Fill in packet len and prio, deliver upward */
4165 PKTSETLEN(pkt, len); 4170 __skb_trim(pkt, len);
4166 PKTPULL(pkt, doff); 4171 skb_pull(pkt, doff);
4167 4172
4168#ifdef SDTEST 4173#ifdef SDTEST
4169 /* Test channel packets are processed separately */ 4174 /* Test channel packets are processed separately */
@@ -4173,15 +4178,15 @@ deliver:
4173 } 4178 }
4174#endif /* SDTEST */ 4179#endif /* SDTEST */
4175 4180
4176 if (PKTLEN(pkt) == 0) { 4181 if (pkt->len == 0) {
4177 dhd_os_sdlock_rxq(bus->dhd); 4182 dhd_os_sdlock_rxq(bus->dhd);
4178 PKTFREE(bus->dhd->osh, pkt, false); 4183 pkt_buf_free_skb(bus->dhd->osh, pkt, false);
4179 dhd_os_sdunlock_rxq(bus->dhd); 4184 dhd_os_sdunlock_rxq(bus->dhd);
4180 continue; 4185 continue;
4181 } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pkt) != 0) { 4186 } else if (dhd_prot_hdrpull(bus->dhd, &ifidx, pkt) != 0) {
4182 DHD_ERROR(("%s: rx protocol error\n", __func__)); 4187 DHD_ERROR(("%s: rx protocol error\n", __func__));
4183 dhd_os_sdlock_rxq(bus->dhd); 4188 dhd_os_sdlock_rxq(bus->dhd);
4184 PKTFREE(bus->dhd->osh, pkt, false); 4189 pkt_buf_free_skb(bus->dhd->osh, pkt, false);
4185 dhd_os_sdunlock_rxq(bus->dhd); 4190 dhd_os_sdunlock_rxq(bus->dhd);
4186 bus->dhd->rx_errors++; 4191 bus->dhd->rx_errors++;
4187 continue; 4192 continue;
@@ -4626,11 +4631,11 @@ static void dhdsdio_pktgen_init(dhd_bus_t *bus)
4626 4631
4627static void dhdsdio_pktgen(dhd_bus_t *bus) 4632static void dhdsdio_pktgen(dhd_bus_t *bus)
4628{ 4633{
4629 void *pkt; 4634 struct sk_buff *pkt;
4630 u8 *data; 4635 u8 *data;
4631 uint pktcount; 4636 uint pktcount;
4632 uint fillbyte; 4637 uint fillbyte;
4633 osl_t *osh = bus->dhd->osh; 4638 struct osl_info *osh = bus->dhd->osh;
4634 u16 len; 4639 u16 len;
4635 4640
4636 /* Display current count if appropriate */ 4641 /* Display current count if appropriate */
@@ -4658,16 +4663,16 @@ static void dhdsdio_pktgen(dhd_bus_t *bus)
4658 4663
4659 /* Allocate an appropriate-sized packet */ 4664 /* Allocate an appropriate-sized packet */
4660 len = bus->pktgen_len; 4665 len = bus->pktgen_len;
4661 pkt = PKTGET(osh, 4666 pkt = pkt_buf_get_skb(osh,
4662 (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN), 4667 (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN),
4663 true); 4668 true);
4664 if (!pkt) { 4669 if (!pkt) {
4665 DHD_ERROR(("%s: PKTGET failed!\n", __func__)); 4670 DHD_ERROR(("%s: pkt_buf_get_skb failed!\n", __func__));
4666 break; 4671 break;
4667 } 4672 }
4668 PKTALIGN(osh, pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), 4673 PKTALIGN(osh, pkt, (len + SDPCM_HDRLEN + SDPCM_TEST_HDRLEN),
4669 DHD_SDALIGN); 4674 DHD_SDALIGN);
4670 data = (u8 *) PKTDATA(pkt) + SDPCM_HDRLEN; 4675 data = (u8 *) (pkt->data) + SDPCM_HDRLEN;
4671 4676
4672 /* Write test header cmd and extra based on mode */ 4677 /* Write test header cmd and extra based on mode */
4673 switch (bus->pktgen_mode) { 4678 switch (bus->pktgen_mode) {
@@ -4689,7 +4694,7 @@ static void dhdsdio_pktgen(dhd_bus_t *bus)
4689 default: 4694 default:
4690 DHD_ERROR(("Unrecognized pktgen mode %d\n", 4695 DHD_ERROR(("Unrecognized pktgen mode %d\n",
4691 bus->pktgen_mode)); 4696 bus->pktgen_mode));
4692 PKTFREE(osh, pkt, true); 4697 pkt_buf_free_skb(osh, pkt, true);
4693 bus->pktgen_count = 0; 4698 bus->pktgen_count = 0;
4694 return; 4699 return;
4695 } 4700 }
@@ -4706,9 +4711,9 @@ static void dhdsdio_pktgen(dhd_bus_t *bus)
4706 4711
4707#ifdef DHD_DEBUG 4712#ifdef DHD_DEBUG
4708 if (DHD_BYTES_ON() && DHD_DATA_ON()) { 4713 if (DHD_BYTES_ON() && DHD_DATA_ON()) {
4709 data = (u8 *) PKTDATA(pkt) + SDPCM_HDRLEN; 4714 data = (u8 *) (pkt->data) + SDPCM_HDRLEN;
4710 prhex("dhdsdio_pktgen: Tx Data", data, 4715 prhex("dhdsdio_pktgen: Tx Data", data,
4711 PKTLEN(pkt) - SDPCM_HDRLEN); 4716 pkt->len - SDPCM_HDRLEN);
4712 } 4717 }
4713#endif 4718#endif
4714 4719
@@ -4733,19 +4738,19 @@ static void dhdsdio_pktgen(dhd_bus_t *bus)
4733 4738
4734static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start) 4739static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start)
4735{ 4740{
4736 void *pkt; 4741 struct sk_buff *pkt;
4737 u8 *data; 4742 u8 *data;
4738 osl_t *osh = bus->dhd->osh; 4743 struct osl_info *osh = bus->dhd->osh;
4739 4744
4740 /* Allocate the packet */ 4745 /* Allocate the packet */
4741 pkt = PKTGET(osh, SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN, 4746 pkt = pkt_buf_get_skb(osh, SDPCM_HDRLEN + SDPCM_TEST_HDRLEN + DHD_SDALIGN,
4742 true); 4747 true);
4743 if (!pkt) { 4748 if (!pkt) {
4744 DHD_ERROR(("%s: PKTGET failed!\n", __func__)); 4749 DHD_ERROR(("%s: pkt_buf_get_skb failed!\n", __func__));
4745 return; 4750 return;
4746 } 4751 }
4747 PKTALIGN(osh, pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), DHD_SDALIGN); 4752 PKTALIGN(osh, pkt, (SDPCM_HDRLEN + SDPCM_TEST_HDRLEN), DHD_SDALIGN);
4748 data = (u8 *) PKTDATA(pkt) + SDPCM_HDRLEN; 4753 data = (u8 *) (pkt->data) + SDPCM_HDRLEN;
4749 4754
4750 /* Fill in the test header */ 4755 /* Fill in the test header */
4751 *data++ = SDPCM_TEST_SEND; 4756 *data++ = SDPCM_TEST_SEND;
@@ -4758,9 +4763,9 @@ static void dhdsdio_sdtest_set(dhd_bus_t *bus, bool start)
4758 bus->pktgen_fail++; 4763 bus->pktgen_fail++;
4759} 4764}
4760 4765
4761static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq) 4766static void dhdsdio_testrcv(dhd_bus_t *bus, struct sk_buff *pkt, uint seq)
4762{ 4767{
4763 osl_t *osh = bus->dhd->osh; 4768 struct osl_info *osh = bus->dhd->osh;
4764 u8 *data; 4769 u8 *data;
4765 uint pktlen; 4770 uint pktlen;
4766 4771
@@ -4770,16 +4775,16 @@ static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq)
4770 u16 offset; 4775 u16 offset;
4771 4776
4772 /* Check for min length */ 4777 /* Check for min length */
4773 pktlen = PKTLEN(pkt); 4778 pktlen = pkt->len;
4774 if (pktlen < SDPCM_TEST_HDRLEN) { 4779 if (pktlen < SDPCM_TEST_HDRLEN) {
4775 DHD_ERROR(("dhdsdio_restrcv: toss runt frame, pktlen %d\n", 4780 DHD_ERROR(("dhdsdio_restrcv: toss runt frame, pktlen %d\n",
4776 pktlen)); 4781 pktlen));
4777 PKTFREE(osh, pkt, false); 4782 pkt_buf_free_skb(osh, pkt, false);
4778 return; 4783 return;
4779 } 4784 }
4780 4785
4781 /* Extract header fields */ 4786 /* Extract header fields */
4782 data = PKTDATA(pkt); 4787 data = pkt->data;
4783 cmd = *data++; 4788 cmd = *data++;
4784 extra = *data++; 4789 extra = *data++;
4785 len = *data++; 4790 len = *data++;
@@ -4792,7 +4797,7 @@ static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq)
4792 DHD_ERROR(("dhdsdio_testrcv: frame length mismatch, " 4797 DHD_ERROR(("dhdsdio_testrcv: frame length mismatch, "
4793 "pktlen %d seq %d" " cmd %d extra %d len %d\n", 4798 "pktlen %d seq %d" " cmd %d extra %d len %d\n",
4794 pktlen, seq, cmd, extra, len)); 4799 pktlen, seq, cmd, extra, len));
4795 PKTFREE(osh, pkt, false); 4800 pkt_buf_free_skb(osh, pkt, false);
4796 return; 4801 return;
4797 } 4802 }
4798 } 4803 }
@@ -4802,19 +4807,19 @@ static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq)
4802 case SDPCM_TEST_ECHOREQ: 4807 case SDPCM_TEST_ECHOREQ:
4803 /* Rx->Tx turnaround ok (even on NDIS w/current 4808 /* Rx->Tx turnaround ok (even on NDIS w/current
4804 implementation) */ 4809 implementation) */
4805 *(u8 *) (PKTDATA(pkt)) = SDPCM_TEST_ECHORSP; 4810 *(u8 *) (pkt->data) = SDPCM_TEST_ECHORSP;
4806 if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) { 4811 if (dhdsdio_txpkt(bus, pkt, SDPCM_TEST_CHANNEL, true) == 0) {
4807 bus->pktgen_sent++; 4812 bus->pktgen_sent++;
4808 } else { 4813 } else {
4809 bus->pktgen_fail++; 4814 bus->pktgen_fail++;
4810 PKTFREE(osh, pkt, false); 4815 pkt_buf_free_skb(osh, pkt, false);
4811 } 4816 }
4812 bus->pktgen_rcvd++; 4817 bus->pktgen_rcvd++;
4813 break; 4818 break;
4814 4819
4815 case SDPCM_TEST_ECHORSP: 4820 case SDPCM_TEST_ECHORSP:
4816 if (bus->ext_loop) { 4821 if (bus->ext_loop) {
4817 PKTFREE(osh, pkt, false); 4822 pkt_buf_free_skb(osh, pkt, false);
4818 bus->pktgen_rcvd++; 4823 bus->pktgen_rcvd++;
4819 break; 4824 break;
4820 } 4825 }
@@ -4827,12 +4832,12 @@ static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq)
4827 break; 4832 break;
4828 } 4833 }
4829 } 4834 }
4830 PKTFREE(osh, pkt, false); 4835 pkt_buf_free_skb(osh, pkt, false);
4831 bus->pktgen_rcvd++; 4836 bus->pktgen_rcvd++;
4832 break; 4837 break;
4833 4838
4834 case SDPCM_TEST_DISCARD: 4839 case SDPCM_TEST_DISCARD:
4835 PKTFREE(osh, pkt, false); 4840 pkt_buf_free_skb(osh, pkt, false);
4836 bus->pktgen_rcvd++; 4841 bus->pktgen_rcvd++;
4837 break; 4842 break;
4838 4843
@@ -4842,7 +4847,7 @@ static void dhdsdio_testrcv(dhd_bus_t *bus, void *pkt, uint seq)
4842 DHD_INFO(("dhdsdio_testrcv: unsupported or unknown command, " 4847 DHD_INFO(("dhdsdio_testrcv: unsupported or unknown command, "
4843 "pktlen %d seq %d" " cmd %d extra %d len %d\n", 4848 "pktlen %d seq %d" " cmd %d extra %d len %d\n",
4844 pktlen, seq, cmd, extra, len)); 4849 pktlen, seq, cmd, extra, len));
4845 PKTFREE(osh, pkt, false); 4850 pkt_buf_free_skb(osh, pkt, false);
4846 break; 4851 break;
4847 } 4852 }
4848 4853
@@ -4960,7 +4965,7 @@ extern int dhd_bus_console_in(dhd_pub_t *dhdp, unsigned char *msg, uint msglen)
4960 dhd_bus_t *bus = dhdp->bus; 4965 dhd_bus_t *bus = dhdp->bus;
4961 u32 addr, val; 4966 u32 addr, val;
4962 int rv; 4967 int rv;
4963 void *pkt; 4968 struct sk_buff *pkt;
4964 4969
4965 /* Address could be zero if CONSOLE := 0 in dongle Makefile */ 4970 /* Address could be zero if CONSOLE := 0 in dongle Makefile */
4966 if (bus->console_addr == 0) 4971 if (bus->console_addr == 0)
@@ -5003,7 +5008,7 @@ extern int dhd_bus_console_in(dhd_pub_t *dhdp, unsigned char *msg, uint msglen)
5003 /* Bump dongle by sending an empty event pkt. 5008 /* Bump dongle by sending an empty event pkt.
5004 * sdpcm_sendup (RX) checks for virtual console input. 5009 * sdpcm_sendup (RX) checks for virtual console input.
5005 */ 5010 */
5006 pkt = PKTGET(bus->dhd->osh, 4 + SDPCM_RESERVE, true); 5011 pkt = pkt_buf_get_skb(bus->dhd->osh, 4 + SDPCM_RESERVE);
5007 if ((pkt != NULL) && bus->clkstate == CLK_AVAIL) 5012 if ((pkt != NULL) && bus->clkstate == CLK_AVAIL)
5008 dhdsdio_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true); 5013 dhdsdio_txpkt(bus, pkt, SDPCM_EVENT_CHANNEL, true);
5009 5014
@@ -5061,7 +5066,7 @@ static bool dhdsdio_chipmatch(u16 chipid)
5061 5066
5062static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no, 5067static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no,
5063 u16 slot, u16 func, uint bustype, void *regsva, 5068 u16 slot, u16 func, uint bustype, void *regsva,
5064 osl_t *osh, void *sdh) 5069 struct osl_info *osh, void *sdh)
5065{ 5070{
5066 int ret; 5071 int ret;
5067 dhd_bus_t *bus; 5072 dhd_bus_t *bus;
@@ -5220,8 +5225,8 @@ fail:
5220} 5225}
5221 5226
5222static bool 5227static bool
5223dhdsdio_probe_attach(struct dhd_bus *bus, osl_t *osh, void *sdh, void *regsva, 5228dhdsdio_probe_attach(struct dhd_bus *bus, struct osl_info *osh, void *sdh,
5224 u16 devid) 5229 void *regsva, u16 devid)
5225{ 5230{
5226 u8 clkctl = 0; 5231 u8 clkctl = 0;
5227 int err = 0; 5232 int err = 0;
@@ -5280,7 +5285,7 @@ dhdsdio_probe_attach(struct dhd_bus *bus, osl_t *osh, void *sdh, void *regsva,
5280 "failed\n", fn)); 5285 "failed\n", fn));
5281 break; 5286 break;
5282 } 5287 }
5283 bzero(cis[fn], SBSDIO_CIS_SIZE_LIMIT); 5288 memset(cis[fn], 0, SBSDIO_CIS_SIZE_LIMIT);
5284 5289
5285 err = bcmsdh_cis_read(sdh, fn, cis[fn], 5290 err = bcmsdh_cis_read(sdh, fn, cis[fn],
5286 SBSDIO_CIS_SIZE_LIMIT); 5291 SBSDIO_CIS_SIZE_LIMIT);
@@ -5378,7 +5383,8 @@ fail:
5378 return false; 5383 return false;
5379} 5384}
5380 5385
5381static bool dhdsdio_probe_malloc(dhd_bus_t *bus, osl_t *osh, void *sdh) 5386static bool dhdsdio_probe_malloc(dhd_bus_t *bus, struct osl_info *osh,
5387 void *sdh)
5382{ 5388{
5383 DHD_TRACE(("%s: Enter\n", __func__)); 5389 DHD_TRACE(("%s: Enter\n", __func__));
5384 5390
@@ -5419,7 +5425,7 @@ fail:
5419 return false; 5425 return false;
5420} 5426}
5421 5427
5422static bool dhdsdio_probe_init(dhd_bus_t *bus, osl_t *osh, void *sdh) 5428static bool dhdsdio_probe_init(dhd_bus_t *bus, struct osl_info *osh, void *sdh)
5423{ 5429{
5424 s32 fnum; 5430 s32 fnum;
5425 5431
@@ -5496,7 +5502,7 @@ static bool dhdsdio_probe_init(dhd_bus_t *bus, osl_t *osh, void *sdh)
5496} 5502}
5497 5503
5498bool 5504bool
5499dhd_bus_download_firmware(struct dhd_bus *bus, osl_t *osh, 5505dhd_bus_download_firmware(struct dhd_bus *bus, struct osl_info *osh,
5500 char *fw_path, char *nv_path) 5506 char *fw_path, char *nv_path)
5501{ 5507{
5502 bool ret; 5508 bool ret;
@@ -5509,7 +5515,7 @@ dhd_bus_download_firmware(struct dhd_bus *bus, osl_t *osh,
5509} 5515}
5510 5516
5511static bool 5517static bool
5512dhdsdio_download_firmware(struct dhd_bus *bus, osl_t *osh, void *sdh) 5518dhdsdio_download_firmware(struct dhd_bus *bus, struct osl_info *osh, void *sdh)
5513{ 5519{
5514 bool ret; 5520 bool ret;
5515 5521
@@ -5524,7 +5530,7 @@ dhdsdio_download_firmware(struct dhd_bus *bus, osl_t *osh, void *sdh)
5524} 5530}
5525 5531
5526/* Detach and free everything */ 5532/* Detach and free everything */
5527static void dhdsdio_release(dhd_bus_t *bus, osl_t *osh) 5533static void dhdsdio_release(dhd_bus_t *bus, struct osl_info *osh)
5528{ 5534{
5529 DHD_TRACE(("%s: Enter\n", __func__)); 5535 DHD_TRACE(("%s: Enter\n", __func__));
5530 5536
@@ -5554,7 +5560,7 @@ static void dhdsdio_release(dhd_bus_t *bus, osl_t *osh)
5554 DHD_TRACE(("%s: Disconnected\n", __func__)); 5560 DHD_TRACE(("%s: Disconnected\n", __func__));
5555} 5561}
5556 5562
5557static void dhdsdio_release_malloc(dhd_bus_t *bus, osl_t *osh) 5563static void dhdsdio_release_malloc(dhd_bus_t *bus, struct osl_info *osh)
5558{ 5564{
5559 DHD_TRACE(("%s: Enter\n", __func__)); 5565 DHD_TRACE(("%s: Enter\n", __func__));
5560 5566
@@ -5573,7 +5579,7 @@ static void dhdsdio_release_malloc(dhd_bus_t *bus, osl_t *osh)
5573 } 5579 }
5574} 5580}
5575 5581
5576static void dhdsdio_release_dongle(dhd_bus_t *bus, osl_t *osh) 5582static void dhdsdio_release_dongle(dhd_bus_t *bus, struct osl_info *osh)
5577{ 5583{
5578 DHD_TRACE(("%s: Enter\n", __func__)); 5584 DHD_TRACE(("%s: Enter\n", __func__));
5579 5585
@@ -5986,7 +5992,7 @@ err:
5986 5992
5987static int 5993static int
5988dhd_bcmsdh_recv_buf(dhd_bus_t *bus, u32 addr, uint fn, uint flags, 5994dhd_bcmsdh_recv_buf(dhd_bus_t *bus, u32 addr, uint fn, uint flags,
5989 u8 *buf, uint nbytes, void *pkt, 5995 u8 *buf, uint nbytes, struct sk_buff *pkt,
5990 bcmsdh_cmplt_fn_t complete, void *handle) 5996 bcmsdh_cmplt_fn_t complete, void *handle)
5991{ 5997{
5992 int status; 5998 int status;
@@ -6000,7 +6006,7 @@ dhd_bcmsdh_recv_buf(dhd_bus_t *bus, u32 addr, uint fn, uint flags,
6000 6006
6001static int 6007static int
6002dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn, uint flags, 6008dhd_bcmsdh_send_buf(dhd_bus_t *bus, u32 addr, uint fn, uint flags,
6003 u8 *buf, uint nbytes, void *pkt, 6009 u8 *buf, uint nbytes, struct sk_buff *pkt,
6004 bcmsdh_cmplt_fn_t complete, void *handle) 6010 bcmsdh_cmplt_fn_t complete, void *handle)
6005{ 6011{
6006 return bcmsdh_send_buf 6012 return bcmsdh_send_buf
diff --git a/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
index ea0825238d53..991463f4a7f4 100644
--- a/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
+++ b/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c
@@ -16,7 +16,6 @@
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/if_arp.h> 18#include <linux/if_arp.h>
19#include <linuxver.h>
20#include <osl.h> 19#include <osl.h>
21 20
22#include <bcmutils.h> 21#include <bcmutils.h>
@@ -30,10 +29,6 @@
30#include <dhdioctl.h> 29#include <dhdioctl.h>
31#include <wlioctl.h> 30#include <wlioctl.h>
32 31
33#include <proto/ethernet.h>
34#include <dngl_stats.h>
35#include <dhd.h>
36
37#include <linux/kthread.h> 32#include <linux/kthread.h>
38#include <linux/netdevice.h> 33#include <linux/netdevice.h>
39#include <linux/sched.h> 34#include <linux/sched.h>
@@ -342,7 +337,7 @@ static void wl_debugfs_remove_netdev(struct wl_priv *wl);
342 struct wl_iface *ci; \ 337 struct wl_iface *ci; \
343 if (unlikely(!(wl_cfg80211_dev && \ 338 if (unlikely(!(wl_cfg80211_dev && \
344 (ci = wl_get_drvdata(wl_cfg80211_dev))))) { \ 339 (ci = wl_get_drvdata(wl_cfg80211_dev))))) { \
345 WL_ERR(("wl_cfg80211_dev is unavailable\n")); \ 340 WL_ERR("wl_cfg80211_dev is unavailable\n"); \
346 BUG(); \ 341 BUG(); \
347 } \ 342 } \
348 ci_to_wl(ci); \ 343 ci_to_wl(ci); \
@@ -352,8 +347,8 @@ static void wl_debugfs_remove_netdev(struct wl_priv *wl);
352do { \ 347do { \
353 struct wl_priv *wl = wiphy_to_wl(wiphy); \ 348 struct wl_priv *wl = wiphy_to_wl(wiphy); \
354 if (unlikely(!test_bit(WL_STATUS_READY, &wl->status))) { \ 349 if (unlikely(!test_bit(WL_STATUS_READY, &wl->status))) { \
355 WL_INFO(("device is not ready : status (%d)\n", \ 350 WL_INFO("device is not ready : status (%d)\n", \
356 (int)wl->status)); \ 351 (int)wl->status); \
357 return -EIO; \ 352 return -EIO; \
358 } \ 353 } \
359} while (0) 354} while (0)
@@ -618,8 +613,8 @@ wl_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
618 switch (type) { 613 switch (type) {
619 case NL80211_IFTYPE_MONITOR: 614 case NL80211_IFTYPE_MONITOR:
620 case NL80211_IFTYPE_WDS: 615 case NL80211_IFTYPE_WDS:
621 WL_ERR(("type (%d) : currently we do not support this type\n", 616 WL_ERR("type (%d) : currently we do not support this type\n",
622 type)); 617 type);
623 return -EOPNOTSUPP; 618 return -EOPNOTSUPP;
624 case NL80211_IFTYPE_ADHOC: 619 case NL80211_IFTYPE_ADHOC:
625 wl->conf->mode = WL_MODE_IBSS; 620 wl->conf->mode = WL_MODE_IBSS;
@@ -635,15 +630,15 @@ wl_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
635 ap = htod32(ap); 630 ap = htod32(ap);
636 wdev = ndev->ieee80211_ptr; 631 wdev = ndev->ieee80211_ptr;
637 wdev->iftype = type; 632 wdev->iftype = type;
638 WL_DBG(("%s : ap (%d), infra (%d)\n", ndev->name, ap, infra)); 633 WL_DBG("%s : ap (%d), infra (%d)\n", ndev->name, ap, infra);
639 err = wl_dev_ioctl(ndev, WLC_SET_INFRA, &infra, sizeof(infra)); 634 err = wl_dev_ioctl(ndev, WLC_SET_INFRA, &infra, sizeof(infra));
640 if (unlikely(err)) { 635 if (unlikely(err)) {
641 WL_ERR(("WLC_SET_INFRA error (%d)\n", err)); 636 WL_ERR("WLC_SET_INFRA error (%d)\n", err);
642 return err; 637 return err;
643 } 638 }
644 err = wl_dev_ioctl(ndev, WLC_SET_AP, &ap, sizeof(ap)); 639 err = wl_dev_ioctl(ndev, WLC_SET_AP, &ap, sizeof(ap));
645 if (unlikely(err)) { 640 if (unlikely(err)) {
646 WL_ERR(("WLC_SET_AP error (%d)\n", err)); 641 WL_ERR("WLC_SET_AP error (%d)\n", err);
647 return err; 642 return err;
648 } 643 }
649 644
@@ -653,7 +648,7 @@ wl_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
653 648
654static void wl_iscan_prep(struct wl_scan_params *params, struct wlc_ssid *ssid) 649static void wl_iscan_prep(struct wl_scan_params *params, struct wlc_ssid *ssid)
655{ 650{
656 memcpy(&params->bssid, &ether_bcast, ETHER_ADDR_LEN); 651 memcpy(&params->bssid, &ether_bcast, ETH_ALEN);
657 params->bss_type = DOT11_BSSTYPE_ANY; 652 params->bss_type = DOT11_BSSTYPE_ANY;
658 params->scan_type = 0; 653 params->scan_type = 0;
659 params->nprobes = -1; 654 params->nprobes = -1;
@@ -705,7 +700,7 @@ wl_run_iscan(struct wl_iscan_ctrl *iscan, struct wlc_ssid *ssid, u16 action)
705 700
706 if (ssid && ssid->SSID_len) 701 if (ssid && ssid->SSID_len)
707 params_size += sizeof(struct wlc_ssid); 702 params_size += sizeof(struct wlc_ssid);
708 params = (struct wl_iscan_params *)kzalloc(params_size, GFP_KERNEL); 703 params = kzalloc(params_size, GFP_KERNEL);
709 if (unlikely(!params)) 704 if (unlikely(!params))
710 return -ENOMEM; 705 return -ENOMEM;
711 memset(params, 0, params_size); 706 memset(params, 0, params_size);
@@ -722,9 +717,9 @@ wl_run_iscan(struct wl_iscan_ctrl *iscan, struct wlc_ssid *ssid, u16 action)
722 iscan->ioctl_buf, WLC_IOCTL_SMLEN); 717 iscan->ioctl_buf, WLC_IOCTL_SMLEN);
723 if (unlikely(err)) { 718 if (unlikely(err)) {
724 if (err == -EBUSY) { 719 if (err == -EBUSY) {
725 WL_INFO(("system busy : iscan canceled\n")); 720 WL_INFO("system busy : iscan canceled\n");
726 } else { 721 } else {
727 WL_ERR(("error (%d)\n", err)); 722 WL_ERR("error (%d)\n", err);
728 } 723 }
729 } 724 }
730 kfree(params); 725 kfree(params);
@@ -748,7 +743,7 @@ static s32 wl_do_iscan(struct wl_priv *wl)
748 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_SET_PASSIVE_SCAN, 743 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_SET_PASSIVE_SCAN,
749 &passive_scan, sizeof(passive_scan)); 744 &passive_scan, sizeof(passive_scan));
750 if (unlikely(err)) { 745 if (unlikely(err)) {
751 WL_DBG(("error (%d)\n", err)); 746 WL_DBG("error (%d)\n", err);
752 return err; 747 return err;
753 } 748 }
754 wl_set_mpc(ndev, 0); 749 wl_set_mpc(ndev, 0);
@@ -774,12 +769,12 @@ __wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
774 s32 err = 0; 769 s32 err = 0;
775 770
776 if (unlikely(test_bit(WL_STATUS_SCANNING, &wl->status))) { 771 if (unlikely(test_bit(WL_STATUS_SCANNING, &wl->status))) {
777 WL_ERR(("Scanning already : status (%d)\n", (int)wl->status)); 772 WL_ERR("Scanning already : status (%d)\n", (int)wl->status);
778 return -EAGAIN; 773 return -EAGAIN;
779 } 774 }
780 if (unlikely(test_bit(WL_STATUS_SCAN_ABORTING, &wl->status))) { 775 if (unlikely(test_bit(WL_STATUS_SCAN_ABORTING, &wl->status))) {
781 WL_ERR(("Scanning being aborted : status (%d)\n", 776 WL_ERR("Scanning being aborted : status (%d)\n",
782 (int)wl->status)); 777 (int)wl->status);
783 return -EAGAIN; 778 return -EAGAIN;
784 } 779 }
785 780
@@ -811,26 +806,26 @@ __wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
811 else 806 else
812 goto scan_out; 807 goto scan_out;
813 } else { 808 } else {
814 WL_DBG(("ssid \"%s\", ssid_len (%d)\n", 809 WL_DBG("ssid \"%s\", ssid_len (%d)\n",
815 ssids->ssid, ssids->ssid_len)); 810 ssids->ssid, ssids->ssid_len);
816 memset(&sr->ssid, 0, sizeof(sr->ssid)); 811 memset(&sr->ssid, 0, sizeof(sr->ssid));
817 sr->ssid.SSID_len = 812 sr->ssid.SSID_len =
818 min_t(u8, sizeof(sr->ssid.SSID), ssids->ssid_len); 813 min_t(u8, sizeof(sr->ssid.SSID), ssids->ssid_len);
819 if (sr->ssid.SSID_len) { 814 if (sr->ssid.SSID_len) {
820 memcpy(sr->ssid.SSID, ssids->ssid, sr->ssid.SSID_len); 815 memcpy(sr->ssid.SSID, ssids->ssid, sr->ssid.SSID_len);
821 sr->ssid.SSID_len = htod32(sr->ssid.SSID_len); 816 sr->ssid.SSID_len = htod32(sr->ssid.SSID_len);
822 WL_DBG(("Specific scan ssid=\"%s\" len=%d\n", 817 WL_DBG("Specific scan ssid=\"%s\" len=%d\n",
823 sr->ssid.SSID, sr->ssid.SSID_len)); 818 sr->ssid.SSID, sr->ssid.SSID_len);
824 spec_scan = true; 819 spec_scan = true;
825 } else { 820 } else {
826 WL_DBG(("Broadcast scan\n")); 821 WL_DBG("Broadcast scan\n");
827 } 822 }
828 WL_DBG(("sr->ssid.SSID_len (%d)\n", sr->ssid.SSID_len)); 823 WL_DBG("sr->ssid.SSID_len (%d)\n", sr->ssid.SSID_len);
829 passive_scan = wl->active_scan ? 0 : 1; 824 passive_scan = wl->active_scan ? 0 : 1;
830 err = wl_dev_ioctl(ndev, WLC_SET_PASSIVE_SCAN, 825 err = wl_dev_ioctl(ndev, WLC_SET_PASSIVE_SCAN,
831 &passive_scan, sizeof(passive_scan)); 826 &passive_scan, sizeof(passive_scan));
832 if (unlikely(err)) { 827 if (unlikely(err)) {
833 WL_ERR(("WLC_SET_PASSIVE_SCAN error (%d)\n", err)); 828 WL_ERR("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
834 goto scan_out; 829 goto scan_out;
835 } 830 }
836 wl_set_mpc(ndev, 0); 831 wl_set_mpc(ndev, 0);
@@ -838,10 +833,10 @@ __wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
838 sizeof(sr->ssid)); 833 sizeof(sr->ssid));
839 if (err) { 834 if (err) {
840 if (err == -EBUSY) { 835 if (err == -EBUSY) {
841 WL_INFO(("system busy : scan for \"%s\" " 836 WL_INFO("system busy : scan for \"%s\" canceled\n",
842 "canceled\n", sr->ssid.SSID)); 837 sr->ssid.SSID);
843 } else { 838 } else {
844 WL_ERR(("WLC_SCAN error (%d)\n", err)); 839 WL_ERR("WLC_SCAN error (%d)\n", err);
845 } 840 }
846 wl_set_mpc(ndev, 1); 841 wl_set_mpc(ndev, 1);
847 goto scan_out; 842 goto scan_out;
@@ -865,7 +860,7 @@ wl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
865 CHECK_SYS_UP(); 860 CHECK_SYS_UP();
866 err = __wl_cfg80211_scan(wiphy, ndev, request, NULL); 861 err = __wl_cfg80211_scan(wiphy, ndev, request, NULL);
867 if (unlikely(err)) { 862 if (unlikely(err)) {
868 WL_DBG(("scan error (%d)\n", err)); 863 WL_DBG("scan error (%d)\n", err);
869 return err; 864 return err;
870 } 865 }
871 866
@@ -884,7 +879,7 @@ static s32 wl_dev_intvar_set(struct net_device *dev, s8 *name, s32 val)
884 879
885 err = wl_dev_ioctl(dev, WLC_SET_VAR, buf, len); 880 err = wl_dev_ioctl(dev, WLC_SET_VAR, buf, len);
886 if (unlikely(err)) { 881 if (unlikely(err)) {
887 WL_ERR(("error (%d)\n", err)); 882 WL_ERR("error (%d)\n", err);
888 } 883 }
889 884
890 return err; 885 return err;
@@ -907,7 +902,7 @@ wl_dev_intvar_get(struct net_device *dev, s8 *name, s32 *retval)
907 BUG_ON(unlikely(!len)); 902 BUG_ON(unlikely(!len));
908 err = wl_dev_ioctl(dev, WLC_GET_VAR, &var, len); 903 err = wl_dev_ioctl(dev, WLC_GET_VAR, &var, len);
909 if (unlikely(err)) { 904 if (unlikely(err)) {
910 WL_ERR(("error (%d)\n", err)); 905 WL_ERR("error (%d)\n", err);
911 } 906 }
912 *retval = dtoh32(var.val); 907 *retval = dtoh32(var.val);
913 908
@@ -920,7 +915,7 @@ static s32 wl_set_rts(struct net_device *dev, u32 rts_threshold)
920 915
921 err = wl_dev_intvar_set(dev, "rtsthresh", rts_threshold); 916 err = wl_dev_intvar_set(dev, "rtsthresh", rts_threshold);
922 if (unlikely(err)) { 917 if (unlikely(err)) {
923 WL_ERR(("Error (%d)\n", err)); 918 WL_ERR("Error (%d)\n", err);
924 return err; 919 return err;
925 } 920 }
926 return err; 921 return err;
@@ -932,7 +927,7 @@ static s32 wl_set_frag(struct net_device *dev, u32 frag_threshold)
932 927
933 err = wl_dev_intvar_set(dev, "fragthresh", frag_threshold); 928 err = wl_dev_intvar_set(dev, "fragthresh", frag_threshold);
934 if (unlikely(err)) { 929 if (unlikely(err)) {
935 WL_ERR(("Error (%d)\n", err)); 930 WL_ERR("Error (%d)\n", err);
936 return err; 931 return err;
937 } 932 }
938 return err; 933 return err;
@@ -946,7 +941,7 @@ static s32 wl_set_retry(struct net_device *dev, u32 retry, bool l)
946 retry = htod32(retry); 941 retry = htod32(retry);
947 err = wl_dev_ioctl(dev, cmd, &retry, sizeof(retry)); 942 err = wl_dev_ioctl(dev, cmd, &retry, sizeof(retry));
948 if (unlikely(err)) { 943 if (unlikely(err)) {
949 WL_ERR(("cmd (%d) , error (%d)\n", cmd, err)); 944 WL_ERR("cmd (%d) , error (%d)\n", cmd, err);
950 return err; 945 return err;
951 } 946 }
952 return err; 947 return err;
@@ -1006,7 +1001,7 @@ wl_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1006 1001
1007 CHECK_SYS_UP(); 1002 CHECK_SYS_UP();
1008 if (params->bssid) { 1003 if (params->bssid) {
1009 WL_ERR(("Invalid bssid\n")); 1004 WL_ERR("Invalid bssid\n");
1010 return -EOPNOTSUPP; 1005 return -EOPNOTSUPP;
1011 } 1006 }
1012 bss = cfg80211_get_ibss(wiphy, NULL, params->ssid, params->ssid_len); 1007 bss = cfg80211_get_ibss(wiphy, NULL, params->ssid, params->ssid_len);
@@ -1032,7 +1027,7 @@ wl_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1032 } 1027 }
1033 if (bss) { 1028 if (bss) {
1034 wl->ibss_starter = false; 1029 wl->ibss_starter = false;
1035 WL_DBG(("Found IBSS\n")); 1030 WL_DBG("Found IBSS\n");
1036 } else { 1031 } else {
1037 wl->ibss_starter = true; 1032 wl->ibss_starter = true;
1038 } 1033 }
@@ -1049,14 +1044,14 @@ wl_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1049 join_params.ssid.SSID_len = htod32(params->ssid_len); 1044 join_params.ssid.SSID_len = htod32(params->ssid_len);
1050 if (params->bssid) 1045 if (params->bssid)
1051 memcpy(&join_params.params.bssid, params->bssid, 1046 memcpy(&join_params.params.bssid, params->bssid,
1052 ETHER_ADDR_LEN); 1047 ETH_ALEN);
1053 else 1048 else
1054 memset(&join_params.params.bssid, 0, ETHER_ADDR_LEN); 1049 memset(&join_params.params.bssid, 0, ETH_ALEN);
1055 1050
1056 err = wl_dev_ioctl(dev, WLC_SET_SSID, &join_params, 1051 err = wl_dev_ioctl(dev, WLC_SET_SSID, &join_params,
1057 sizeof(join_params)); 1052 sizeof(join_params));
1058 if (unlikely(err)) { 1053 if (unlikely(err)) {
1059 WL_ERR(("Error (%d)\n", err)); 1054 WL_ERR("Error (%d)\n", err);
1060 return err; 1055 return err;
1061 } 1056 }
1062 return err; 1057 return err;
@@ -1087,10 +1082,10 @@ wl_set_wpa_version(struct net_device *dev, struct cfg80211_connect_params *sme)
1087 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED; 1082 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
1088 else 1083 else
1089 val = WPA_AUTH_DISABLED; 1084 val = WPA_AUTH_DISABLED;
1090 WL_DBG(("setting wpa_auth to 0x%0x\n", val)); 1085 WL_DBG("setting wpa_auth to 0x%0x\n", val);
1091 err = wl_dev_intvar_set(dev, "wpa_auth", val); 1086 err = wl_dev_intvar_set(dev, "wpa_auth", val);
1092 if (unlikely(err)) { 1087 if (unlikely(err)) {
1093 WL_ERR(("set wpa_auth failed (%d)\n", err)); 1088 WL_ERR("set wpa_auth failed (%d)\n", err);
1094 return err; 1089 return err;
1095 } 1090 }
1096 sec = wl_read_prof(wl, WL_PROF_SEC); 1091 sec = wl_read_prof(wl, WL_PROF_SEC);
@@ -1109,27 +1104,27 @@ wl_set_auth_type(struct net_device *dev, struct cfg80211_connect_params *sme)
1109 switch (sme->auth_type) { 1104 switch (sme->auth_type) {
1110 case NL80211_AUTHTYPE_OPEN_SYSTEM: 1105 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1111 val = 0; 1106 val = 0;
1112 WL_DBG(("open system\n")); 1107 WL_DBG("open system\n");
1113 break; 1108 break;
1114 case NL80211_AUTHTYPE_SHARED_KEY: 1109 case NL80211_AUTHTYPE_SHARED_KEY:
1115 val = 1; 1110 val = 1;
1116 WL_DBG(("shared key\n")); 1111 WL_DBG("shared key\n");
1117 break; 1112 break;
1118 case NL80211_AUTHTYPE_AUTOMATIC: 1113 case NL80211_AUTHTYPE_AUTOMATIC:
1119 val = 2; 1114 val = 2;
1120 WL_DBG(("automatic\n")); 1115 WL_DBG("automatic\n");
1121 break; 1116 break;
1122 case NL80211_AUTHTYPE_NETWORK_EAP: 1117 case NL80211_AUTHTYPE_NETWORK_EAP:
1123 WL_DBG(("network eap\n")); 1118 WL_DBG("network eap\n");
1124 default: 1119 default:
1125 val = 2; 1120 val = 2;
1126 WL_ERR(("invalid auth type (%d)\n", sme->auth_type)); 1121 WL_ERR("invalid auth type (%d)\n", sme->auth_type);
1127 break; 1122 break;
1128 } 1123 }
1129 1124
1130 err = wl_dev_intvar_set(dev, "auth", val); 1125 err = wl_dev_intvar_set(dev, "auth", val);
1131 if (unlikely(err)) { 1126 if (unlikely(err)) {
1132 WL_ERR(("set auth failed (%d)\n", err)); 1127 WL_ERR("set auth failed (%d)\n", err);
1133 return err; 1128 return err;
1134 } 1129 }
1135 sec = wl_read_prof(wl, WL_PROF_SEC); 1130 sec = wl_read_prof(wl, WL_PROF_SEC);
@@ -1162,8 +1157,8 @@ wl_set_set_cipher(struct net_device *dev, struct cfg80211_connect_params *sme)
1162 pval = AES_ENABLED; 1157 pval = AES_ENABLED;
1163 break; 1158 break;
1164 default: 1159 default:
1165 WL_ERR(("invalid cipher pairwise (%d)\n", 1160 WL_ERR("invalid cipher pairwise (%d)\n",
1166 sme->crypto.ciphers_pairwise[0])); 1161 sme->crypto.ciphers_pairwise[0]);
1167 return -EINVAL; 1162 return -EINVAL;
1168 } 1163 }
1169 } 1164 }
@@ -1183,16 +1178,16 @@ wl_set_set_cipher(struct net_device *dev, struct cfg80211_connect_params *sme)
1183 gval = AES_ENABLED; 1178 gval = AES_ENABLED;
1184 break; 1179 break;
1185 default: 1180 default:
1186 WL_ERR(("invalid cipher group (%d)\n", 1181 WL_ERR("invalid cipher group (%d)\n",
1187 sme->crypto.cipher_group)); 1182 sme->crypto.cipher_group);
1188 return -EINVAL; 1183 return -EINVAL;
1189 } 1184 }
1190 } 1185 }
1191 1186
1192 WL_DBG(("pval (%d) gval (%d)\n", pval, gval)); 1187 WL_DBG("pval (%d) gval (%d)\n", pval, gval);
1193 err = wl_dev_intvar_set(dev, "wsec", pval | gval); 1188 err = wl_dev_intvar_set(dev, "wsec", pval | gval);
1194 if (unlikely(err)) { 1189 if (unlikely(err)) {
1195 WL_ERR(("error (%d)\n", err)); 1190 WL_ERR("error (%d)\n", err);
1196 return err; 1191 return err;
1197 } 1192 }
1198 1193
@@ -1214,7 +1209,7 @@ wl_set_key_mgmt(struct net_device *dev, struct cfg80211_connect_params *sme)
1214 if (sme->crypto.n_akm_suites) { 1209 if (sme->crypto.n_akm_suites) {
1215 err = wl_dev_intvar_get(dev, "wpa_auth", &val); 1210 err = wl_dev_intvar_get(dev, "wpa_auth", &val);
1216 if (unlikely(err)) { 1211 if (unlikely(err)) {
1217 WL_ERR(("could not get wpa_auth (%d)\n", err)); 1212 WL_ERR("could not get wpa_auth (%d)\n", err);
1218 return err; 1213 return err;
1219 } 1214 }
1220 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) { 1215 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
@@ -1226,8 +1221,8 @@ wl_set_key_mgmt(struct net_device *dev, struct cfg80211_connect_params *sme)
1226 val = WPA_AUTH_PSK; 1221 val = WPA_AUTH_PSK;
1227 break; 1222 break;
1228 default: 1223 default:
1229 WL_ERR(("invalid cipher group (%d)\n", 1224 WL_ERR("invalid cipher group (%d)\n",
1230 sme->crypto.cipher_group)); 1225 sme->crypto.cipher_group);
1231 return -EINVAL; 1226 return -EINVAL;
1232 } 1227 }
1233 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) { 1228 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
@@ -1239,16 +1234,16 @@ wl_set_key_mgmt(struct net_device *dev, struct cfg80211_connect_params *sme)
1239 val = WPA2_AUTH_PSK; 1234 val = WPA2_AUTH_PSK;
1240 break; 1235 break;
1241 default: 1236 default:
1242 WL_ERR(("invalid cipher group (%d)\n", 1237 WL_ERR("invalid cipher group (%d)\n",
1243 sme->crypto.cipher_group)); 1238 sme->crypto.cipher_group);
1244 return -EINVAL; 1239 return -EINVAL;
1245 } 1240 }
1246 } 1241 }
1247 1242
1248 WL_DBG(("setting wpa_auth to %d\n", val)); 1243 WL_DBG("setting wpa_auth to %d\n", val);
1249 err = wl_dev_intvar_set(dev, "wpa_auth", val); 1244 err = wl_dev_intvar_set(dev, "wpa_auth", val);
1250 if (unlikely(err)) { 1245 if (unlikely(err)) {
1251 WL_ERR(("could not set wpa_auth (%d)\n", err)); 1246 WL_ERR("could not set wpa_auth (%d)\n", err);
1252 return err; 1247 return err;
1253 } 1248 }
1254 } 1249 }
@@ -1268,11 +1263,11 @@ wl_set_set_sharedkey(struct net_device *dev,
1268 s32 val; 1263 s32 val;
1269 s32 err = 0; 1264 s32 err = 0;
1270 1265
1271 WL_DBG(("key len (%d)\n", sme->key_len)); 1266 WL_DBG("key len (%d)\n", sme->key_len);
1272 if (sme->key_len) { 1267 if (sme->key_len) {
1273 sec = wl_read_prof(wl, WL_PROF_SEC); 1268 sec = wl_read_prof(wl, WL_PROF_SEC);
1274 WL_DBG(("wpa_versions 0x%x cipher_pairwise 0x%x\n", 1269 WL_DBG("wpa_versions 0x%x cipher_pairwise 0x%x\n",
1275 sec->wpa_versions, sec->cipher_pairwise)); 1270 sec->wpa_versions, sec->cipher_pairwise);
1276 if (! 1271 if (!
1277 (sec->wpa_versions & (NL80211_WPA_VERSION_1 | 1272 (sec->wpa_versions & (NL80211_WPA_VERSION_1 |
1278 NL80211_WPA_VERSION_2)) 1273 NL80211_WPA_VERSION_2))
@@ -1282,7 +1277,7 @@ wl_set_set_sharedkey(struct net_device *dev,
1282 key.len = (u32) sme->key_len; 1277 key.len = (u32) sme->key_len;
1283 key.index = (u32) sme->key_idx; 1278 key.index = (u32) sme->key_idx;
1284 if (unlikely(key.len > sizeof(key.data))) { 1279 if (unlikely(key.len > sizeof(key.data))) {
1285 WL_ERR(("Too long key length (%u)\n", key.len)); 1280 WL_ERR("Too long key length (%u)\n", key.len);
1286 return -EINVAL; 1281 return -EINVAL;
1287 } 1282 }
1288 memcpy(key.data, sme->key, key.len); 1283 memcpy(key.data, sme->key, key.len);
@@ -1295,27 +1290,27 @@ wl_set_set_sharedkey(struct net_device *dev,
1295 key.algo = CRYPTO_ALGO_WEP128; 1290 key.algo = CRYPTO_ALGO_WEP128;
1296 break; 1291 break;
1297 default: 1292 default:
1298 WL_ERR(("Invalid algorithm (%d)\n", 1293 WL_ERR("Invalid algorithm (%d)\n",
1299 sme->crypto.ciphers_pairwise[0])); 1294 sme->crypto.ciphers_pairwise[0]);
1300 return -EINVAL; 1295 return -EINVAL;
1301 } 1296 }
1302 /* Set the new key/index */ 1297 /* Set the new key/index */
1303 WL_DBG(("key length (%d) key index (%d) algo (%d)\n", 1298 WL_DBG("key length (%d) key index (%d) algo (%d)\n",
1304 key.len, key.index, key.algo)); 1299 key.len, key.index, key.algo);
1305 WL_DBG(("key \"%s\"\n", key.data)); 1300 WL_DBG("key \"%s\"\n", key.data);
1306 swap_key_from_BE(&key); 1301 swap_key_from_BE(&key);
1307 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, 1302 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key,
1308 sizeof(key)); 1303 sizeof(key));
1309 if (unlikely(err)) { 1304 if (unlikely(err)) {
1310 WL_ERR(("WLC_SET_KEY error (%d)\n", err)); 1305 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1311 return err; 1306 return err;
1312 } 1307 }
1313 if (sec->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) { 1308 if (sec->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) {
1314 WL_DBG(("set auth_type to shared key\n")); 1309 WL_DBG("set auth_type to shared key\n");
1315 val = 1; /* shared key */ 1310 val = 1; /* shared key */
1316 err = wl_dev_intvar_set(dev, "auth", val); 1311 err = wl_dev_intvar_set(dev, "auth", val);
1317 if (unlikely(err)) { 1312 if (unlikely(err)) {
1318 WL_ERR(("set auth failed (%d)\n", err)); 1313 WL_ERR("set auth failed (%d)\n", err);
1319 return err; 1314 return err;
1320 } 1315 }
1321 } 1316 }
@@ -1337,15 +1332,15 @@ wl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1337 1332
1338 CHECK_SYS_UP(); 1333 CHECK_SYS_UP();
1339 if (unlikely(!sme->ssid)) { 1334 if (unlikely(!sme->ssid)) {
1340 WL_ERR(("Invalid ssid\n")); 1335 WL_ERR("Invalid ssid\n");
1341 return -EOPNOTSUPP; 1336 return -EOPNOTSUPP;
1342 } 1337 }
1343 if (chan) { 1338 if (chan) {
1344 wl->channel = ieee80211_frequency_to_channel(chan->center_freq); 1339 wl->channel = ieee80211_frequency_to_channel(chan->center_freq);
1345 WL_DBG(("channel (%d), center_req (%d)\n", wl->channel, 1340 WL_DBG("channel (%d), center_req (%d)\n",
1346 chan->center_freq)); 1341 wl->channel, chan->center_freq);
1347 } 1342 }
1348 WL_DBG(("ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len)); 1343 WL_DBG("ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
1349 err = wl_set_wpa_version(dev, sme); 1344 err = wl_set_wpa_version(dev, sme);
1350 if (unlikely(err)) 1345 if (unlikely(err))
1351 return err; 1346 return err;
@@ -1378,18 +1373,18 @@ wl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
1378 memcpy(&join_params.ssid.SSID, sme->ssid, join_params.ssid.SSID_len); 1373 memcpy(&join_params.ssid.SSID, sme->ssid, join_params.ssid.SSID_len);
1379 join_params.ssid.SSID_len = htod32(join_params.ssid.SSID_len); 1374 join_params.ssid.SSID_len = htod32(join_params.ssid.SSID_len);
1380 wl_update_prof(wl, NULL, &join_params.ssid, WL_PROF_SSID); 1375 wl_update_prof(wl, NULL, &join_params.ssid, WL_PROF_SSID);
1381 memcpy(&join_params.params.bssid, &ether_bcast, ETHER_ADDR_LEN); 1376 memcpy(&join_params.params.bssid, &ether_bcast, ETH_ALEN);
1382 1377
1383 wl_ch_to_chanspec(wl->channel, &join_params, &join_params_size); 1378 wl_ch_to_chanspec(wl->channel, &join_params, &join_params_size);
1384 WL_DBG(("join_param_size %d\n", join_params_size)); 1379 WL_DBG("join_param_size %d\n", join_params_size);
1385 1380
1386 if (join_params.ssid.SSID_len < IEEE80211_MAX_SSID_LEN) { 1381 if (join_params.ssid.SSID_len < IEEE80211_MAX_SSID_LEN) {
1387 WL_DBG(("ssid \"%s\", len (%d)\n", join_params.ssid.SSID, 1382 WL_DBG("ssid \"%s\", len (%d)\n",
1388 join_params.ssid.SSID_len)); 1383 join_params.ssid.SSID, join_params.ssid.SSID_len);
1389 } 1384 }
1390 err = wl_dev_ioctl(dev, WLC_SET_SSID, &join_params, join_params_size); 1385 err = wl_dev_ioctl(dev, WLC_SET_SSID, &join_params, join_params_size);
1391 if (unlikely(err)) { 1386 if (unlikely(err)) {
1392 WL_ERR(("error (%d)\n", err)); 1387 WL_ERR("error (%d)\n", err);
1393 return err; 1388 return err;
1394 } 1389 }
1395 set_bit(WL_STATUS_CONNECTING, &wl->status); 1390 set_bit(WL_STATUS_CONNECTING, &wl->status);
@@ -1406,17 +1401,17 @@ wl_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *dev,
1406 bool act = false; 1401 bool act = false;
1407 s32 err = 0; 1402 s32 err = 0;
1408 1403
1409 WL_DBG(("Reason %d\n", reason_code)); 1404 WL_DBG("Reason %d\n", reason_code);
1410 CHECK_SYS_UP(); 1405 CHECK_SYS_UP();
1411 act = *(bool *) wl_read_prof(wl, WL_PROF_ACT); 1406 act = *(bool *) wl_read_prof(wl, WL_PROF_ACT);
1412 if (likely(act)) { 1407 if (likely(act)) {
1413 scbval.val = reason_code; 1408 scbval.val = reason_code;
1414 memcpy(&scbval.ea, &wl->bssid, ETHER_ADDR_LEN); 1409 memcpy(&scbval.ea, &wl->bssid, ETH_ALEN);
1415 scbval.val = htod32(scbval.val); 1410 scbval.val = htod32(scbval.val);
1416 err = wl_dev_ioctl(dev, WLC_DISASSOC, &scbval, 1411 err = wl_dev_ioctl(dev, WLC_DISASSOC, &scbval,
1417 sizeof(scb_val_t)); 1412 sizeof(scb_val_t));
1418 if (unlikely(err)) { 1413 if (unlikely(err)) {
1419 WL_ERR(("error (%d)\n", err)); 1414 WL_ERR("error (%d)\n", err);
1420 return err; 1415 return err;
1421 } 1416 }
1422 } 1417 }
@@ -1441,13 +1436,13 @@ wl_cfg80211_set_tx_power(struct wiphy *wiphy,
1441 break; 1436 break;
1442 case NL80211_TX_POWER_LIMITED: 1437 case NL80211_TX_POWER_LIMITED:
1443 if (dbm < 0) { 1438 if (dbm < 0) {
1444 WL_ERR(("TX_POWER_LIMITTED - dbm is negative\n")); 1439 WL_ERR("TX_POWER_LIMITED - dbm is negative\n");
1445 return -EINVAL; 1440 return -EINVAL;
1446 } 1441 }
1447 break; 1442 break;
1448 case NL80211_TX_POWER_FIXED: 1443 case NL80211_TX_POWER_FIXED:
1449 if (dbm < 0) { 1444 if (dbm < 0) {
1450 WL_ERR(("TX_POWER_FIXED - dbm is negative..\n")); 1445 WL_ERR("TX_POWER_FIXED - dbm is negative\n");
1451 return -EINVAL; 1446 return -EINVAL;
1452 } 1447 }
1453 break; 1448 break;
@@ -1457,7 +1452,7 @@ wl_cfg80211_set_tx_power(struct wiphy *wiphy,
1457 disable = htod32(disable); 1452 disable = htod32(disable);
1458 err = wl_dev_ioctl(ndev, WLC_SET_RADIO, &disable, sizeof(disable)); 1453 err = wl_dev_ioctl(ndev, WLC_SET_RADIO, &disable, sizeof(disable));
1459 if (unlikely(err)) { 1454 if (unlikely(err)) {
1460 WL_ERR(("WLC_SET_RADIO error (%d)\n", err)); 1455 WL_ERR("WLC_SET_RADIO error (%d)\n", err);
1461 return err; 1456 return err;
1462 } 1457 }
1463 1458
@@ -1468,7 +1463,7 @@ wl_cfg80211_set_tx_power(struct wiphy *wiphy,
1468 err = wl_dev_intvar_set(ndev, "qtxpower", 1463 err = wl_dev_intvar_set(ndev, "qtxpower",
1469 (s32) (bcm_mw_to_qdbm(txpwrmw))); 1464 (s32) (bcm_mw_to_qdbm(txpwrmw)));
1470 if (unlikely(err)) { 1465 if (unlikely(err)) {
1471 WL_ERR(("qtxpower error (%d)\n", err)); 1466 WL_ERR("qtxpower error (%d)\n", err);
1472 return err; 1467 return err;
1473 } 1468 }
1474 wl->conf->tx_power = dbm; 1469 wl->conf->tx_power = dbm;
@@ -1487,7 +1482,7 @@ static s32 wl_cfg80211_get_tx_power(struct wiphy *wiphy, s32 *dbm)
1487 CHECK_SYS_UP(); 1482 CHECK_SYS_UP();
1488 err = wl_dev_intvar_get(ndev, "qtxpower", &txpwrdbm); 1483 err = wl_dev_intvar_get(ndev, "qtxpower", &txpwrdbm);
1489 if (unlikely(err)) { 1484 if (unlikely(err)) {
1490 WL_ERR(("error (%d)\n", err)); 1485 WL_ERR("error (%d)\n", err);
1491 return err; 1486 return err;
1492 } 1487 }
1493 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE); 1488 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE);
@@ -1504,12 +1499,12 @@ wl_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *dev,
1504 s32 wsec; 1499 s32 wsec;
1505 s32 err = 0; 1500 s32 err = 0;
1506 1501
1507 WL_DBG(("key index (%d)\n", key_idx)); 1502 WL_DBG("key index (%d)\n", key_idx);
1508 CHECK_SYS_UP(); 1503 CHECK_SYS_UP();
1509 1504
1510 err = wl_dev_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec)); 1505 err = wl_dev_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec));
1511 if (unlikely(err)) { 1506 if (unlikely(err)) {
1512 WL_ERR(("WLC_GET_WSEC error (%d)\n", err)); 1507 WL_ERR("WLC_GET_WSEC error (%d)\n", err);
1513 return err; 1508 return err;
1514 } 1509 }
1515 wsec = dtoh32(wsec); 1510 wsec = dtoh32(wsec);
@@ -1520,7 +1515,7 @@ wl_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *dev,
1520 err = wl_dev_ioctl(dev, WLC_SET_KEY_PRIMARY, &index, 1515 err = wl_dev_ioctl(dev, WLC_SET_KEY_PRIMARY, &index,
1521 sizeof(index)); 1516 sizeof(index));
1522 if (unlikely(err)) { 1517 if (unlikely(err)) {
1523 WL_ERR(("error (%d)\n", err)); 1518 WL_ERR("error (%d)\n", err);
1524 } 1519 }
1525 } 1520 }
1526 return err; 1521 return err;
@@ -1537,8 +1532,8 @@ wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
1537 key.index = (u32) key_idx; 1532 key.index = (u32) key_idx;
1538 /* Instead of bcast for ea address for default wep keys, 1533 /* Instead of bcast for ea address for default wep keys,
1539 driver needs it to be Null */ 1534 driver needs it to be Null */
1540 if (!ETHER_ISMULTI(mac_addr)) 1535 if (!is_multicast_ether_addr(mac_addr))
1541 memcpy((char *)&key.ea, (void *)mac_addr, ETHER_ADDR_LEN); 1536 memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
1542 key.len = (u32) params->key_len; 1537 key.len = (u32) params->key_len;
1543 /* check for key index change */ 1538 /* check for key index change */
1544 if (key.len == 0) { 1539 if (key.len == 0) {
@@ -1546,16 +1541,16 @@ wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
1546 swap_key_from_BE(&key); 1541 swap_key_from_BE(&key);
1547 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key)); 1542 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1548 if (unlikely(err)) { 1543 if (unlikely(err)) {
1549 WL_ERR(("key delete error (%d)\n", err)); 1544 WL_ERR("key delete error (%d)\n", err);
1550 return err; 1545 return err;
1551 } 1546 }
1552 } else { 1547 } else {
1553 if (key.len > sizeof(key.data)) { 1548 if (key.len > sizeof(key.data)) {
1554 WL_ERR(("Invalid key length (%d)\n", key.len)); 1549 WL_ERR("Invalid key length (%d)\n", key.len);
1555 return -EINVAL; 1550 return -EINVAL;
1556 } 1551 }
1557 1552
1558 WL_DBG(("Setting the key index %d\n", key.index)); 1553 WL_DBG("Setting the key index %d\n", key.index);
1559 memcpy(key.data, params->key, key.len); 1554 memcpy(key.data, params->key, key.len);
1560 1555
1561 if (params->cipher == WLAN_CIPHER_SUITE_TKIP) { 1556 if (params->cipher == WLAN_CIPHER_SUITE_TKIP) {
@@ -1579,26 +1574,26 @@ wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
1579 switch (params->cipher) { 1574 switch (params->cipher) {
1580 case WLAN_CIPHER_SUITE_WEP40: 1575 case WLAN_CIPHER_SUITE_WEP40:
1581 key.algo = CRYPTO_ALGO_WEP1; 1576 key.algo = CRYPTO_ALGO_WEP1;
1582 WL_DBG(("WLAN_CIPHER_SUITE_WEP40\n")); 1577 WL_DBG("WLAN_CIPHER_SUITE_WEP40\n");
1583 break; 1578 break;
1584 case WLAN_CIPHER_SUITE_WEP104: 1579 case WLAN_CIPHER_SUITE_WEP104:
1585 key.algo = CRYPTO_ALGO_WEP128; 1580 key.algo = CRYPTO_ALGO_WEP128;
1586 WL_DBG(("WLAN_CIPHER_SUITE_WEP104\n")); 1581 WL_DBG("WLAN_CIPHER_SUITE_WEP104\n");
1587 break; 1582 break;
1588 case WLAN_CIPHER_SUITE_TKIP: 1583 case WLAN_CIPHER_SUITE_TKIP:
1589 key.algo = CRYPTO_ALGO_TKIP; 1584 key.algo = CRYPTO_ALGO_TKIP;
1590 WL_DBG(("WLAN_CIPHER_SUITE_TKIP\n")); 1585 WL_DBG("WLAN_CIPHER_SUITE_TKIP\n");
1591 break; 1586 break;
1592 case WLAN_CIPHER_SUITE_AES_CMAC: 1587 case WLAN_CIPHER_SUITE_AES_CMAC:
1593 key.algo = CRYPTO_ALGO_AES_CCM; 1588 key.algo = CRYPTO_ALGO_AES_CCM;
1594 WL_DBG(("WLAN_CIPHER_SUITE_AES_CMAC\n")); 1589 WL_DBG("WLAN_CIPHER_SUITE_AES_CMAC\n");
1595 break; 1590 break;
1596 case WLAN_CIPHER_SUITE_CCMP: 1591 case WLAN_CIPHER_SUITE_CCMP:
1597 key.algo = CRYPTO_ALGO_AES_CCM; 1592 key.algo = CRYPTO_ALGO_AES_CCM;
1598 WL_DBG(("WLAN_CIPHER_SUITE_CCMP\n")); 1593 WL_DBG("WLAN_CIPHER_SUITE_CCMP\n");
1599 break; 1594 break;
1600 default: 1595 default:
1601 WL_ERR(("Invalid cipher (0x%x)\n", params->cipher)); 1596 WL_ERR("Invalid cipher (0x%x)\n", params->cipher);
1602 return -EINVAL; 1597 return -EINVAL;
1603 } 1598 }
1604 swap_key_from_BE(&key); 1599 swap_key_from_BE(&key);
@@ -1606,7 +1601,7 @@ wl_add_keyext(struct wiphy *wiphy, struct net_device *dev,
1606 dhd_wait_pend8021x(dev); 1601 dhd_wait_pend8021x(dev);
1607 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key)); 1602 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1608 if (unlikely(err)) { 1603 if (unlikely(err)) {
1609 WL_ERR(("WLC_SET_KEY error (%d)\n", err)); 1604 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1610 return err; 1605 return err;
1611 } 1606 }
1612 } 1607 }
@@ -1623,7 +1618,7 @@ wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
1623 s32 wsec; 1618 s32 wsec;
1624 s32 err = 0; 1619 s32 err = 0;
1625 1620
1626 WL_DBG(("key index (%d)\n", key_idx)); 1621 WL_DBG("key index (%d)\n", key_idx);
1627 CHECK_SYS_UP(); 1622 CHECK_SYS_UP();
1628 1623
1629 if (mac_addr) 1624 if (mac_addr)
@@ -1634,7 +1629,7 @@ wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
1634 key.index = (u32) key_idx; 1629 key.index = (u32) key_idx;
1635 1630
1636 if (unlikely(key.len > sizeof(key.data))) { 1631 if (unlikely(key.len > sizeof(key.data))) {
1637 WL_ERR(("Too long key length (%u)\n", key.len)); 1632 WL_ERR("Too long key length (%u)\n", key.len);
1638 return -EINVAL; 1633 return -EINVAL;
1639 } 1634 }
1640 memcpy(key.data, params->key, key.len); 1635 memcpy(key.data, params->key, key.len);
@@ -1643,26 +1638,26 @@ wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
1643 switch (params->cipher) { 1638 switch (params->cipher) {
1644 case WLAN_CIPHER_SUITE_WEP40: 1639 case WLAN_CIPHER_SUITE_WEP40:
1645 key.algo = CRYPTO_ALGO_WEP1; 1640 key.algo = CRYPTO_ALGO_WEP1;
1646 WL_DBG(("WLAN_CIPHER_SUITE_WEP40\n")); 1641 WL_DBG("WLAN_CIPHER_SUITE_WEP40\n");
1647 break; 1642 break;
1648 case WLAN_CIPHER_SUITE_WEP104: 1643 case WLAN_CIPHER_SUITE_WEP104:
1649 key.algo = CRYPTO_ALGO_WEP128; 1644 key.algo = CRYPTO_ALGO_WEP128;
1650 WL_DBG(("WLAN_CIPHER_SUITE_WEP104\n")); 1645 WL_DBG("WLAN_CIPHER_SUITE_WEP104\n");
1651 break; 1646 break;
1652 case WLAN_CIPHER_SUITE_TKIP: 1647 case WLAN_CIPHER_SUITE_TKIP:
1653 key.algo = CRYPTO_ALGO_TKIP; 1648 key.algo = CRYPTO_ALGO_TKIP;
1654 WL_DBG(("WLAN_CIPHER_SUITE_TKIP\n")); 1649 WL_DBG("WLAN_CIPHER_SUITE_TKIP\n");
1655 break; 1650 break;
1656 case WLAN_CIPHER_SUITE_AES_CMAC: 1651 case WLAN_CIPHER_SUITE_AES_CMAC:
1657 key.algo = CRYPTO_ALGO_AES_CCM; 1652 key.algo = CRYPTO_ALGO_AES_CCM;
1658 WL_DBG(("WLAN_CIPHER_SUITE_AES_CMAC\n")); 1653 WL_DBG("WLAN_CIPHER_SUITE_AES_CMAC\n");
1659 break; 1654 break;
1660 case WLAN_CIPHER_SUITE_CCMP: 1655 case WLAN_CIPHER_SUITE_CCMP:
1661 key.algo = CRYPTO_ALGO_AES_CCM; 1656 key.algo = CRYPTO_ALGO_AES_CCM;
1662 WL_DBG(("WLAN_CIPHER_SUITE_CCMP\n")); 1657 WL_DBG("WLAN_CIPHER_SUITE_CCMP\n");
1663 break; 1658 break;
1664 default: 1659 default:
1665 WL_ERR(("Invalid cipher (0x%x)\n", params->cipher)); 1660 WL_ERR("Invalid cipher (0x%x)\n", params->cipher);
1666 return -EINVAL; 1661 return -EINVAL;
1667 } 1662 }
1668 1663
@@ -1670,21 +1665,21 @@ wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
1670 swap_key_from_BE(&key); 1665 swap_key_from_BE(&key);
1671 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key)); 1666 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
1672 if (unlikely(err)) { 1667 if (unlikely(err)) {
1673 WL_ERR(("WLC_SET_KEY error (%d)\n", err)); 1668 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1674 return err; 1669 return err;
1675 } 1670 }
1676 1671
1677 val = WEP_ENABLED; 1672 val = WEP_ENABLED;
1678 err = wl_dev_intvar_get(dev, "wsec", &wsec); 1673 err = wl_dev_intvar_get(dev, "wsec", &wsec);
1679 if (unlikely(err)) { 1674 if (unlikely(err)) {
1680 WL_ERR(("get wsec error (%d)\n", err)); 1675 WL_ERR("get wsec error (%d)\n", err);
1681 return err; 1676 return err;
1682 } 1677 }
1683 wsec &= ~(WEP_ENABLED); 1678 wsec &= ~(WEP_ENABLED);
1684 wsec |= val; 1679 wsec |= val;
1685 err = wl_dev_intvar_set(dev, "wsec", wsec); 1680 err = wl_dev_intvar_set(dev, "wsec", wsec);
1686 if (unlikely(err)) { 1681 if (unlikely(err)) {
1687 WL_ERR(("set wsec error (%d)\n", err)); 1682 WL_ERR("set wsec error (%d)\n", err);
1688 return err; 1683 return err;
1689 } 1684 }
1690 1685
@@ -1692,7 +1687,7 @@ wl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *dev,
1692 val = htod32(val); 1687 val = htod32(val);
1693 err = wl_dev_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val)); 1688 err = wl_dev_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val));
1694 if (unlikely(err)) { 1689 if (unlikely(err)) {
1695 WL_ERR(("WLC_SET_AUTH error (%d)\n", err)); 1690 WL_ERR("WLC_SET_AUTH error (%d)\n", err);
1696 return err; 1691 return err;
1697 } 1692 }
1698 return err; 1693 return err;
@@ -1714,7 +1709,7 @@ wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
1714 key.flags = WL_PRIMARY_KEY; 1709 key.flags = WL_PRIMARY_KEY;
1715 key.algo = CRYPTO_ALGO_OFF; 1710 key.algo = CRYPTO_ALGO_OFF;
1716 1711
1717 WL_DBG(("key index (%d)\n", key_idx)); 1712 WL_DBG("key index (%d)\n", key_idx);
1718 /* Set the new key/index */ 1713 /* Set the new key/index */
1719 swap_key_from_BE(&key); 1714 swap_key_from_BE(&key);
1720 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key)); 1715 err = wl_dev_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
@@ -1722,10 +1717,10 @@ wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
1722 if (err == -EINVAL) { 1717 if (err == -EINVAL) {
1723 if (key.index >= DOT11_MAX_DEFAULT_KEYS) { 1718 if (key.index >= DOT11_MAX_DEFAULT_KEYS) {
1724 /* we ignore this key index in this case */ 1719 /* we ignore this key index in this case */
1725 WL_DBG(("invalid key index (%d)\n", key_idx)); 1720 WL_DBG("invalid key index (%d)\n", key_idx);
1726 } 1721 }
1727 } else { 1722 } else {
1728 WL_ERR(("WLC_SET_KEY error (%d)\n", err)); 1723 WL_ERR("WLC_SET_KEY error (%d)\n", err);
1729 } 1724 }
1730 return err; 1725 return err;
1731 } 1726 }
@@ -1733,14 +1728,14 @@ wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
1733 val = 0; 1728 val = 0;
1734 err = wl_dev_intvar_get(dev, "wsec", &wsec); 1729 err = wl_dev_intvar_get(dev, "wsec", &wsec);
1735 if (unlikely(err)) { 1730 if (unlikely(err)) {
1736 WL_ERR(("get wsec error (%d)\n", err)); 1731 WL_ERR("get wsec error (%d)\n", err);
1737 return err; 1732 return err;
1738 } 1733 }
1739 wsec &= ~(WEP_ENABLED); 1734 wsec &= ~(WEP_ENABLED);
1740 wsec |= val; 1735 wsec |= val;
1741 err = wl_dev_intvar_set(dev, "wsec", wsec); 1736 err = wl_dev_intvar_set(dev, "wsec", wsec);
1742 if (unlikely(err)) { 1737 if (unlikely(err)) {
1743 WL_ERR(("set wsec error (%d)\n", err)); 1738 WL_ERR("set wsec error (%d)\n", err);
1744 return err; 1739 return err;
1745 } 1740 }
1746 1741
@@ -1748,7 +1743,7 @@ wl_cfg80211_del_key(struct wiphy *wiphy, struct net_device *dev,
1748 val = htod32(val); 1743 val = htod32(val);
1749 err = wl_dev_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val)); 1744 err = wl_dev_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val));
1750 if (unlikely(err)) { 1745 if (unlikely(err)) {
1751 WL_ERR(("WLC_SET_AUTH error (%d)\n", err)); 1746 WL_ERR("WLC_SET_AUTH error (%d)\n", err);
1752 return err; 1747 return err;
1753 } 1748 }
1754 return err; 1749 return err;
@@ -1766,7 +1761,7 @@ wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev,
1766 s32 wsec; 1761 s32 wsec;
1767 s32 err = 0; 1762 s32 err = 0;
1768 1763
1769 WL_DBG(("key index (%d)\n", key_idx)); 1764 WL_DBG("key index (%d)\n", key_idx);
1770 CHECK_SYS_UP(); 1765 CHECK_SYS_UP();
1771 1766
1772 memset(&key, 0, sizeof(key)); 1767 memset(&key, 0, sizeof(key));
@@ -1778,7 +1773,7 @@ wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev,
1778 1773
1779 err = wl_dev_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec)); 1774 err = wl_dev_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec));
1780 if (unlikely(err)) { 1775 if (unlikely(err)) {
1781 WL_ERR(("WLC_GET_WSEC error (%d)\n", err)); 1776 WL_ERR("WLC_GET_WSEC error (%d)\n", err);
1782 return err; 1777 return err;
1783 } 1778 }
1784 wsec = dtoh32(wsec); 1779 wsec = dtoh32(wsec);
@@ -1787,22 +1782,22 @@ wl_cfg80211_get_key(struct wiphy *wiphy, struct net_device *dev,
1787 sec = wl_read_prof(wl, WL_PROF_SEC); 1782 sec = wl_read_prof(wl, WL_PROF_SEC);
1788 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) { 1783 if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
1789 params.cipher = WLAN_CIPHER_SUITE_WEP40; 1784 params.cipher = WLAN_CIPHER_SUITE_WEP40;
1790 WL_DBG(("WLAN_CIPHER_SUITE_WEP40\n")); 1785 WL_DBG("WLAN_CIPHER_SUITE_WEP40\n");
1791 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) { 1786 } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
1792 params.cipher = WLAN_CIPHER_SUITE_WEP104; 1787 params.cipher = WLAN_CIPHER_SUITE_WEP104;
1793 WL_DBG(("WLAN_CIPHER_SUITE_WEP104\n")); 1788 WL_DBG("WLAN_CIPHER_SUITE_WEP104\n");
1794 } 1789 }
1795 break; 1790 break;
1796 case TKIP_ENABLED: 1791 case TKIP_ENABLED:
1797 params.cipher = WLAN_CIPHER_SUITE_TKIP; 1792 params.cipher = WLAN_CIPHER_SUITE_TKIP;
1798 WL_DBG(("WLAN_CIPHER_SUITE_TKIP\n")); 1793 WL_DBG("WLAN_CIPHER_SUITE_TKIP\n");
1799 break; 1794 break;
1800 case AES_ENABLED: 1795 case AES_ENABLED:
1801 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC; 1796 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
1802 WL_DBG(("WLAN_CIPHER_SUITE_AES_CMAC\n")); 1797 WL_DBG("WLAN_CIPHER_SUITE_AES_CMAC\n");
1803 break; 1798 break;
1804 default: 1799 default:
1805 WL_ERR(("Invalid algo (0x%x)\n", wsec)); 1800 WL_ERR("Invalid algo (0x%x)\n", wsec);
1806 return -EINVAL; 1801 return -EINVAL;
1807 } 1802 }
1808 1803
@@ -1814,7 +1809,7 @@ static s32
1814wl_cfg80211_config_default_mgmt_key(struct wiphy *wiphy, 1809wl_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
1815 struct net_device *dev, u8 key_idx) 1810 struct net_device *dev, u8 key_idx)
1816{ 1811{
1817 WL_INFO(("Not supported\n")); 1812 WL_INFO("Not supported\n");
1818 CHECK_SYS_UP(); 1813 CHECK_SYS_UP();
1819 return -EOPNOTSUPP; 1814 return -EOPNOTSUPP;
1820} 1815}
@@ -1831,20 +1826,20 @@ wl_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1831 1826
1832 CHECK_SYS_UP(); 1827 CHECK_SYS_UP();
1833 if (unlikely 1828 if (unlikely
1834 (memcmp(mac, wl_read_prof(wl, WL_PROF_BSSID), ETHER_ADDR_LEN))) { 1829 (memcmp(mac, wl_read_prof(wl, WL_PROF_BSSID), ETH_ALEN))) {
1835 WL_ERR(("Wrong Mac address\n")); 1830 WL_ERR("Wrong Mac address\n");
1836 return -ENOENT; 1831 return -ENOENT;
1837 } 1832 }
1838 1833
1839 /* Report the current tx rate */ 1834 /* Report the current tx rate */
1840 err = wl_dev_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate)); 1835 err = wl_dev_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate));
1841 if (err) { 1836 if (err) {
1842 WL_ERR(("Could not get rate (%d)\n", err)); 1837 WL_ERR("Could not get rate (%d)\n", err);
1843 } else { 1838 } else {
1844 rate = dtoh32(rate); 1839 rate = dtoh32(rate);
1845 sinfo->filled |= STATION_INFO_TX_BITRATE; 1840 sinfo->filled |= STATION_INFO_TX_BITRATE;
1846 sinfo->txrate.legacy = rate * 5; 1841 sinfo->txrate.legacy = rate * 5;
1847 WL_DBG(("Rate %d Mbps\n", (rate / 2))); 1842 WL_DBG("Rate %d Mbps\n", rate / 2);
1848 } 1843 }
1849 1844
1850 if (test_bit(WL_STATUS_CONNECTED, &wl->status)) { 1845 if (test_bit(WL_STATUS_CONNECTED, &wl->status)) {
@@ -1852,13 +1847,13 @@ wl_cfg80211_get_station(struct wiphy *wiphy, struct net_device *dev,
1852 err = wl_dev_ioctl(dev, WLC_GET_RSSI, &scb_val, 1847 err = wl_dev_ioctl(dev, WLC_GET_RSSI, &scb_val,
1853 sizeof(scb_val_t)); 1848 sizeof(scb_val_t));
1854 if (unlikely(err)) { 1849 if (unlikely(err)) {
1855 WL_ERR(("Could not get rssi (%d)\n", err)); 1850 WL_ERR("Could not get rssi (%d)\n", err);
1856 return err; 1851 return err;
1857 } 1852 }
1858 rssi = dtoh32(scb_val.val); 1853 rssi = dtoh32(scb_val.val);
1859 sinfo->filled |= STATION_INFO_SIGNAL; 1854 sinfo->filled |= STATION_INFO_SIGNAL;
1860 sinfo->signal = rssi; 1855 sinfo->signal = rssi;
1861 WL_DBG(("RSSI %d dBm\n", rssi)); 1856 WL_DBG("RSSI %d dBm\n", rssi);
1862 } 1857 }
1863 1858
1864 return err; 1859 return err;
@@ -1874,13 +1869,13 @@ wl_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1874 CHECK_SYS_UP(); 1869 CHECK_SYS_UP();
1875 pm = enabled ? PM_FAST : PM_OFF; 1870 pm = enabled ? PM_FAST : PM_OFF;
1876 pm = htod32(pm); 1871 pm = htod32(pm);
1877 WL_DBG(("power save %s\n", (pm ? "enabled" : "disabled"))); 1872 WL_DBG("power save %s\n", (pm ? "enabled" : "disabled"));
1878 err = wl_dev_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm)); 1873 err = wl_dev_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm));
1879 if (unlikely(err)) { 1874 if (unlikely(err)) {
1880 if (err == -ENODEV) 1875 if (err == -ENODEV)
1881 WL_DBG(("net_device is not ready yet\n")); 1876 WL_DBG("net_device is not ready yet\n");
1882 else 1877 else
1883 WL_ERR(("error (%d)\n", err)); 1878 WL_ERR("error (%d)\n", err);
1884 return err; 1879 return err;
1885 } 1880 }
1886 return err; 1881 return err;
@@ -1932,7 +1927,7 @@ wl_cfg80211_set_bitrate_mask(struct wiphy *wiphy, struct net_device *dev,
1932 err = wl_dev_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, 1927 err = wl_dev_ioctl(dev, WLC_GET_CURR_RATESET, &rateset,
1933 sizeof(rateset)); 1928 sizeof(rateset));
1934 if (unlikely(err)) { 1929 if (unlikely(err)) {
1935 WL_ERR(("could not get current rateset (%d)\n", err)); 1930 WL_ERR("could not get current rateset (%d)\n", err);
1936 return err; 1931 return err;
1937 } 1932 }
1938 1933
@@ -1952,7 +1947,7 @@ wl_cfg80211_set_bitrate_mask(struct wiphy *wiphy, struct net_device *dev,
1952 rate = val / 500000; 1947 rate = val / 500000;
1953 } 1948 }
1954 1949
1955 WL_DBG(("rate %d mbps\n", (rate / 2))); 1950 WL_DBG("rate %d mbps\n", rate / 2);
1956 1951
1957 /* 1952 /*
1958 * 1953 *
@@ -1962,7 +1957,7 @@ wl_cfg80211_set_bitrate_mask(struct wiphy *wiphy, struct net_device *dev,
1962 err_bg = wl_dev_intvar_set(dev, "bg_rate", rate); 1957 err_bg = wl_dev_intvar_set(dev, "bg_rate", rate);
1963 err_a = wl_dev_intvar_set(dev, "a_rate", rate); 1958 err_a = wl_dev_intvar_set(dev, "a_rate", rate);
1964 if (unlikely(err_bg && err_a)) { 1959 if (unlikely(err_bg && err_a)) {
1965 WL_ERR(("could not set fixed rate (%d) (%d)\n", err_bg, err_a)); 1960 WL_ERR("could not set fixed rate (%d) (%d)\n", err_bg, err_a);
1966 return err_bg | err_a; 1961 return err_bg | err_a;
1967 } 1962 }
1968 1963
@@ -2007,12 +2002,12 @@ wl_update_pmklist(struct net_device *dev, struct wl_pmk_list *pmk_list,
2007{ 2002{
2008 int i, j; 2003 int i, j;
2009 2004
2010 WL_DBG(("No of elements %d\n", pmk_list->pmkids.npmkid)); 2005 WL_DBG("No of elements %d\n", pmk_list->pmkids.npmkid);
2011 for (i = 0; i < pmk_list->pmkids.npmkid; i++) { 2006 for (i = 0; i < pmk_list->pmkids.npmkid; i++) {
2012 WL_DBG(("PMKID[%d]: %pM =\n", i, 2007 WL_DBG("PMKID[%d]: %pM =\n", i,
2013 &pmk_list->pmkids.pmkid[i].BSSID)); 2008 &pmk_list->pmkids.pmkid[i].BSSID);
2014 for (j = 0; j < WPA2_PMKID_LEN; j++) { 2009 for (j = 0; j < WPA2_PMKID_LEN; j++) {
2015 WL_DBG(("%02x\n", pmk_list->pmkids.pmkid[i].PMKID[j])); 2010 WL_DBG("%02x\n", pmk_list->pmkids.pmkid[i].PMKID[j]);
2016 } 2011 }
2017 } 2012 }
2018 if (likely(!err)) { 2013 if (likely(!err)) {
@@ -2034,11 +2029,11 @@ wl_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
2034 CHECK_SYS_UP(); 2029 CHECK_SYS_UP();
2035 for (i = 0; i < wl->pmk_list->pmkids.npmkid; i++) 2030 for (i = 0; i < wl->pmk_list->pmkids.npmkid; i++)
2036 if (!memcmp(pmksa->bssid, &wl->pmk_list->pmkids.pmkid[i].BSSID, 2031 if (!memcmp(pmksa->bssid, &wl->pmk_list->pmkids.pmkid[i].BSSID,
2037 ETHER_ADDR_LEN)) 2032 ETH_ALEN))
2038 break; 2033 break;
2039 if (i < WL_NUM_PMKIDS_MAX) { 2034 if (i < WL_NUM_PMKIDS_MAX) {
2040 memcpy(&wl->pmk_list->pmkids.pmkid[i].BSSID, pmksa->bssid, 2035 memcpy(&wl->pmk_list->pmkids.pmkid[i].BSSID, pmksa->bssid,
2041 ETHER_ADDR_LEN); 2036 ETH_ALEN);
2042 memcpy(&wl->pmk_list->pmkids.pmkid[i].PMKID, pmksa->pmkid, 2037 memcpy(&wl->pmk_list->pmkids.pmkid[i].PMKID, pmksa->pmkid,
2043 WPA2_PMKID_LEN); 2038 WPA2_PMKID_LEN);
2044 if (i == wl->pmk_list->pmkids.npmkid) 2039 if (i == wl->pmk_list->pmkids.npmkid)
@@ -2046,12 +2041,12 @@ wl_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *dev,
2046 } else { 2041 } else {
2047 err = -EINVAL; 2042 err = -EINVAL;
2048 } 2043 }
2049 WL_DBG(("set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n", 2044 WL_DBG("set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
2050 &wl->pmk_list->pmkids.pmkid[wl->pmk_list->pmkids.npmkid].BSSID)); 2045 &wl->pmk_list->pmkids.pmkid[wl->pmk_list->pmkids.npmkid].BSSID);
2051 for (i = 0; i < WPA2_PMKID_LEN; i++) { 2046 for (i = 0; i < WPA2_PMKID_LEN; i++) {
2052 WL_DBG(("%02x\n", 2047 WL_DBG("%02x\n",
2053 wl->pmk_list->pmkids.pmkid[wl->pmk_list->pmkids.npmkid]. 2048 wl->pmk_list->pmkids.pmkid[wl->pmk_list->pmkids.npmkid].
2054 PMKID[i])); 2049 PMKID[i]);
2055 } 2050 }
2056 2051
2057 err = wl_update_pmklist(dev, wl->pmk_list, err); 2052 err = wl_update_pmklist(dev, wl->pmk_list, err);
@@ -2069,19 +2064,19 @@ wl_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
2069 int i; 2064 int i;
2070 2065
2071 CHECK_SYS_UP(); 2066 CHECK_SYS_UP();
2072 memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETHER_ADDR_LEN); 2067 memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN);
2073 memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WPA2_PMKID_LEN); 2068 memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WPA2_PMKID_LEN);
2074 2069
2075 WL_DBG(("del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n", 2070 WL_DBG("del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
2076 &pmkid.pmkid[0].BSSID)); 2071 &pmkid.pmkid[0].BSSID);
2077 for (i = 0; i < WPA2_PMKID_LEN; i++) { 2072 for (i = 0; i < WPA2_PMKID_LEN; i++) {
2078 WL_DBG(("%02x\n", pmkid.pmkid[0].PMKID[i])); 2073 WL_DBG("%02x\n", pmkid.pmkid[0].PMKID[i]);
2079 } 2074 }
2080 2075
2081 for (i = 0; i < wl->pmk_list->pmkids.npmkid; i++) 2076 for (i = 0; i < wl->pmk_list->pmkids.npmkid; i++)
2082 if (!memcmp 2077 if (!memcmp
2083 (pmksa->bssid, &wl->pmk_list->pmkids.pmkid[i].BSSID, 2078 (pmksa->bssid, &wl->pmk_list->pmkids.pmkid[i].BSSID,
2084 ETHER_ADDR_LEN)) 2079 ETH_ALEN))
2085 break; 2080 break;
2086 2081
2087 if ((wl->pmk_list->pmkids.npmkid > 0) 2082 if ((wl->pmk_list->pmkids.npmkid > 0)
@@ -2090,7 +2085,7 @@ wl_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *dev,
2090 for (; i < (wl->pmk_list->pmkids.npmkid - 1); i++) { 2085 for (; i < (wl->pmk_list->pmkids.npmkid - 1); i++) {
2091 memcpy(&wl->pmk_list->pmkids.pmkid[i].BSSID, 2086 memcpy(&wl->pmk_list->pmkids.pmkid[i].BSSID,
2092 &wl->pmk_list->pmkids.pmkid[i + 1].BSSID, 2087 &wl->pmk_list->pmkids.pmkid[i + 1].BSSID,
2093 ETHER_ADDR_LEN); 2088 ETH_ALEN);
2094 memcpy(&wl->pmk_list->pmkids.pmkid[i].PMKID, 2089 memcpy(&wl->pmk_list->pmkids.pmkid[i].PMKID,
2095 &wl->pmk_list->pmkids.pmkid[i + 1].PMKID, 2090 &wl->pmk_list->pmkids.pmkid[i + 1].PMKID,
2096 WPA2_PMKID_LEN); 2091 WPA2_PMKID_LEN);
@@ -2168,13 +2163,13 @@ static struct wireless_dev *wl_alloc_wdev(s32 sizeof_iface,
2168 2163
2169 wdev = kzalloc(sizeof(*wdev), GFP_KERNEL); 2164 wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
2170 if (unlikely(!wdev)) { 2165 if (unlikely(!wdev)) {
2171 WL_ERR(("Could not allocate wireless device\n")); 2166 WL_ERR("Could not allocate wireless device\n");
2172 return ERR_PTR(-ENOMEM); 2167 return ERR_PTR(-ENOMEM);
2173 } 2168 }
2174 wdev->wiphy = 2169 wdev->wiphy =
2175 wiphy_new(&wl_cfg80211_ops, sizeof(struct wl_priv) + sizeof_iface); 2170 wiphy_new(&wl_cfg80211_ops, sizeof(struct wl_priv) + sizeof_iface);
2176 if (unlikely(!wdev->wiphy)) { 2171 if (unlikely(!wdev->wiphy)) {
2177 WL_ERR(("Couldn not allocate wiphy device\n")); 2172 WL_ERR("Couldn not allocate wiphy device\n");
2178 err = -ENOMEM; 2173 err = -ENOMEM;
2179 goto wiphy_new_out; 2174 goto wiphy_new_out;
2180 } 2175 }
@@ -2204,7 +2199,7 @@ static struct wireless_dev *wl_alloc_wdev(s32 sizeof_iface,
2204#endif /* !WL_POWERSAVE_DISABLED */ 2199#endif /* !WL_POWERSAVE_DISABLED */
2205 err = wiphy_register(wdev->wiphy); 2200 err = wiphy_register(wdev->wiphy);
2206 if (unlikely(err < 0)) { 2201 if (unlikely(err < 0)) {
2207 WL_ERR(("Couldn not register wiphy device (%d)\n", err)); 2202 WL_ERR("Couldn not register wiphy device (%d)\n", err);
2208 goto wiphy_register_out; 2203 goto wiphy_register_out;
2209 } 2204 }
2210 return wdev; 2205 return wdev;
@@ -2223,7 +2218,7 @@ static void wl_free_wdev(struct wl_priv *wl)
2223 struct wireless_dev *wdev = wl_to_wdev(wl); 2218 struct wireless_dev *wdev = wl_to_wdev(wl);
2224 2219
2225 if (unlikely(!wdev)) { 2220 if (unlikely(!wdev)) {
2226 WL_ERR(("wdev is invalid\n")); 2221 WL_ERR("wdev is invalid\n");
2227 return; 2222 return;
2228 } 2223 }
2229 wiphy_unregister(wdev->wiphy); 2224 wiphy_unregister(wdev->wiphy);
@@ -2241,11 +2236,11 @@ static s32 wl_inform_bss(struct wl_priv *wl)
2241 2236
2242 bss_list = wl->bss_list; 2237 bss_list = wl->bss_list;
2243 if (unlikely(bss_list->version != WL_BSS_INFO_VERSION)) { 2238 if (unlikely(bss_list->version != WL_BSS_INFO_VERSION)) {
2244 WL_ERR(("Version %d != WL_BSS_INFO_VERSION\n", 2239 WL_ERR("Version %d != WL_BSS_INFO_VERSION\n",
2245 bss_list->version)); 2240 bss_list->version);
2246 return -EOPNOTSUPP; 2241 return -EOPNOTSUPP;
2247 } 2242 }
2248 WL_DBG(("scanned AP count (%d)\n", bss_list->count)); 2243 WL_DBG("scanned AP count (%d)\n", bss_list->count);
2249 bi = next_bss(bss_list, bi); 2244 bi = next_bss(bss_list, bi);
2250 for_each_bss(bss_list, bi, i) { 2245 for_each_bss(bss_list, bi, i) {
2251 err = wl_inform_single_bss(wl, bi); 2246 err = wl_inform_single_bss(wl, bi);
@@ -2270,14 +2265,14 @@ static s32 wl_inform_single_bss(struct wl_priv *wl, struct wl_bss_info *bi)
2270 s32 err = 0; 2265 s32 err = 0;
2271 2266
2272 if (unlikely(dtoh32(bi->length) > WL_BSS_INFO_MAX)) { 2267 if (unlikely(dtoh32(bi->length) > WL_BSS_INFO_MAX)) {
2273 WL_DBG(("Beacon is larger than buffer. Discarding\n")); 2268 WL_DBG("Beacon is larger than buffer. Discarding\n");
2274 return err; 2269 return err;
2275 } 2270 }
2276 notif_bss_info = 2271 notif_bss_info =
2277 kzalloc(sizeof(*notif_bss_info) + sizeof(*mgmt) - sizeof(u8) + 2272 kzalloc(sizeof(*notif_bss_info) + sizeof(*mgmt) - sizeof(u8) +
2278 WL_BSS_INFO_MAX, GFP_KERNEL); 2273 WL_BSS_INFO_MAX, GFP_KERNEL);
2279 if (unlikely(!notif_bss_info)) { 2274 if (unlikely(!notif_bss_info)) {
2280 WL_ERR(("notif_bss_info alloc failed\n")); 2275 WL_ERR("notif_bss_info alloc failed\n");
2281 return -ENOMEM; 2276 return -ENOMEM;
2282 } 2277 }
2283 mgmt = (struct ieee80211_mgmt *)notif_bss_info->frame_buf; 2278 mgmt = (struct ieee80211_mgmt *)notif_bss_info->frame_buf;
@@ -2289,7 +2284,7 @@ static s32 wl_inform_single_bss(struct wl_priv *wl, struct wl_bss_info *bi)
2289 else 2284 else
2290 band = wiphy->bands[IEEE80211_BAND_5GHZ]; 2285 band = wiphy->bands[IEEE80211_BAND_5GHZ];
2291 notif_bss_info->rssi = bi->RSSI; 2286 notif_bss_info->rssi = bi->RSSI;
2292 memcpy(mgmt->bssid, &bi->BSSID, ETHER_ADDR_LEN); 2287 memcpy(mgmt->bssid, &bi->BSSID, ETH_ALEN);
2293 mgmt_type = wl->active_scan ? 2288 mgmt_type = wl->active_scan ?
2294 IEEE80211_STYPE_PROBE_RESP : IEEE80211_STYPE_BEACON; 2289 IEEE80211_STYPE_PROBE_RESP : IEEE80211_STYPE_BEACON;
2295 if (!memcmp(bi->SSID, sr->ssid.SSID, bi->SSID_len)) { 2290 if (!memcmp(bi->SSID, sr->ssid.SSID, bi->SSID_len)) {
@@ -2321,17 +2316,17 @@ static s32 wl_inform_single_bss(struct wl_priv *wl, struct wl_bss_info *bi)
2321 freq = ieee80211_channel_to_frequency(notif_bss_info->channel); 2316 freq = ieee80211_channel_to_frequency(notif_bss_info->channel);
2322 channel = ieee80211_get_channel(wiphy, freq); 2317 channel = ieee80211_get_channel(wiphy, freq);
2323 2318
2324 WL_DBG(("SSID : \"%s\", rssi %d, channel %d, capability : 0x04%x, bssid %pM\n", 2319 WL_DBG("SSID : \"%s\", rssi %d, channel %d, capability : 0x04%x, bssid %pM\n",
2325 bi->SSID, 2320 bi->SSID,
2326 notif_bss_info->rssi, notif_bss_info->channel, 2321 notif_bss_info->rssi, notif_bss_info->channel,
2327 mgmt->u.beacon.capab_info, &bi->BSSID)); 2322 mgmt->u.beacon.capab_info, &bi->BSSID);
2328 2323
2329 signal = notif_bss_info->rssi * 100; 2324 signal = notif_bss_info->rssi * 100;
2330 if (unlikely(!cfg80211_inform_bss_frame(wiphy, channel, mgmt, 2325 if (unlikely(!cfg80211_inform_bss_frame(wiphy, channel, mgmt,
2331 le16_to_cpu 2326 le16_to_cpu
2332 (notif_bss_info->frame_len), 2327 (notif_bss_info->frame_len),
2333 signal, GFP_KERNEL))) { 2328 signal, GFP_KERNEL))) {
2334 WL_ERR(("cfg80211_inform_bss_frame error\n")); 2329 WL_ERR("cfg80211_inform_bss_frame error\n");
2335 kfree(notif_bss_info); 2330 kfree(notif_bss_info);
2336 return -EINVAL; 2331 return -EINVAL;
2337 } 2332 }
@@ -2399,12 +2394,12 @@ wl_notify_connect_status(struct wl_priv *wl, struct net_device *ndev,
2399 if (wl_is_ibssmode(wl)) { 2394 if (wl_is_ibssmode(wl)) {
2400 cfg80211_ibss_joined(ndev, (s8 *)&e->addr, 2395 cfg80211_ibss_joined(ndev, (s8 *)&e->addr,
2401 GFP_KERNEL); 2396 GFP_KERNEL);
2402 WL_DBG(("joined in IBSS network\n")); 2397 WL_DBG("joined in IBSS network\n");
2403 } else { 2398 } else {
2404 wl_bss_connect_done(wl, ndev, e, data, true); 2399 wl_bss_connect_done(wl, ndev, e, data, true);
2405 WL_DBG(("joined in BSS network \"%s\"\n", 2400 WL_DBG("joined in BSS network \"%s\"\n",
2406 ((struct wlc_ssid *) 2401 ((struct wlc_ssid *)
2407 wl_read_prof(wl, WL_PROF_SSID))->SSID)); 2402 wl_read_prof(wl, WL_PROF_SSID))->SSID);
2408 } 2403 }
2409 act = true; 2404 act = true;
2410 wl_update_prof(wl, e, &act, WL_PROF_ACT); 2405 wl_update_prof(wl, e, &act, WL_PROF_ACT);
@@ -2459,7 +2454,7 @@ wl_dev_bufvar_get(struct net_device *dev, s8 *name, s8 *buf,
2459 err = wl_dev_ioctl(dev, WLC_GET_VAR, (void *)wl->ioctl_buf, 2454 err = wl_dev_ioctl(dev, WLC_GET_VAR, (void *)wl->ioctl_buf,
2460 WL_IOCTL_LEN_MAX); 2455 WL_IOCTL_LEN_MAX);
2461 if (unlikely(err)) { 2456 if (unlikely(err)) {
2462 WL_ERR(("error (%d)\n", err)); 2457 WL_ERR("error (%d)\n", err);
2463 return err; 2458 return err;
2464 } 2459 }
2465 memcpy(buf, wl->ioctl_buf, buf_len); 2460 memcpy(buf, wl->ioctl_buf, buf_len);
@@ -2479,7 +2474,7 @@ static s32 wl_get_assoc_ies(struct wl_priv *wl)
2479 err = wl_dev_bufvar_get(ndev, "assoc_info", wl->extra_buf, 2474 err = wl_dev_bufvar_get(ndev, "assoc_info", wl->extra_buf,
2480 WL_ASSOC_INFO_MAX); 2475 WL_ASSOC_INFO_MAX);
2481 if (unlikely(err)) { 2476 if (unlikely(err)) {
2482 WL_ERR(("could not get assoc info (%d)\n", err)); 2477 WL_ERR("could not get assoc info (%d)\n", err);
2483 return err; 2478 return err;
2484 } 2479 }
2485 assoc_info = (struct wl_assoc_ielen *)wl->extra_buf; 2480 assoc_info = (struct wl_assoc_ielen *)wl->extra_buf;
@@ -2489,7 +2484,7 @@ static s32 wl_get_assoc_ies(struct wl_priv *wl)
2489 err = wl_dev_bufvar_get(ndev, "assoc_req_ies", wl->extra_buf, 2484 err = wl_dev_bufvar_get(ndev, "assoc_req_ies", wl->extra_buf,
2490 WL_ASSOC_INFO_MAX); 2485 WL_ASSOC_INFO_MAX);
2491 if (unlikely(err)) { 2486 if (unlikely(err)) {
2492 WL_ERR(("could not get assoc req (%d)\n", err)); 2487 WL_ERR("could not get assoc req (%d)\n", err);
2493 return err; 2488 return err;
2494 } 2489 }
2495 conn_info->req_ie_len = req_len; 2490 conn_info->req_ie_len = req_len;
@@ -2503,7 +2498,7 @@ static s32 wl_get_assoc_ies(struct wl_priv *wl)
2503 err = wl_dev_bufvar_get(ndev, "assoc_resp_ies", wl->extra_buf, 2498 err = wl_dev_bufvar_get(ndev, "assoc_resp_ies", wl->extra_buf,
2504 WL_ASSOC_INFO_MAX); 2499 WL_ASSOC_INFO_MAX);
2505 if (unlikely(err)) { 2500 if (unlikely(err)) {
2506 WL_ERR(("could not get assoc resp (%d)\n", err)); 2501 WL_ERR("could not get assoc resp (%d)\n", err);
2507 return err; 2502 return err;
2508 } 2503 }
2509 conn_info->resp_ie_len = resp_len; 2504 conn_info->resp_ie_len = resp_len;
@@ -2513,8 +2508,8 @@ static s32 wl_get_assoc_ies(struct wl_priv *wl)
2513 conn_info->resp_ie_len = 0; 2508 conn_info->resp_ie_len = 0;
2514 conn_info->resp_ie = NULL; 2509 conn_info->resp_ie = NULL;
2515 } 2510 }
2516 WL_DBG(("req len (%d) resp len (%d)\n", conn_info->req_ie_len, 2511 WL_DBG("req len (%d) resp len (%d)\n",
2517 conn_info->resp_ie_len)); 2512 conn_info->req_ie_len, conn_info->resp_ie_len);
2518 2513
2519 return err; 2514 return err;
2520} 2515}
@@ -2547,8 +2542,8 @@ static void wl_ch_to_chanspec(int ch, struct wl_join_params *join_params,
2547 join_params->params.chanspec_num = 2542 join_params->params.chanspec_num =
2548 htod32(join_params->params.chanspec_num); 2543 htod32(join_params->params.chanspec_num);
2549 2544
2550 WL_DBG(("join_params->params.chanspec_list[0]= %#X, channel %d, chanspec %#X\n", 2545 WL_DBG("join_params->params.chanspec_list[0]= %#X, channel %d, chanspec %#X\n",
2551 join_params->params.chanspec_list[0], ch, chanspec)); 2546 join_params->params.chanspec_list[0], ch, chanspec);
2552 } 2547 }
2553} 2548}
2554 2549
@@ -2575,16 +2570,16 @@ static s32 wl_update_bss_info(struct wl_priv *wl)
2575 2570
2576 rtnl_lock(); 2571 rtnl_lock();
2577 if (unlikely(!bss)) { 2572 if (unlikely(!bss)) {
2578 WL_DBG(("Could not find the AP\n")); 2573 WL_DBG("Could not find the AP\n");
2579 *(u32 *) wl->extra_buf = htod32(WL_EXTRA_BUF_MAX); 2574 *(u32 *) wl->extra_buf = htod32(WL_EXTRA_BUF_MAX);
2580 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_GET_BSS_INFO, 2575 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_GET_BSS_INFO,
2581 wl->extra_buf, WL_EXTRA_BUF_MAX); 2576 wl->extra_buf, WL_EXTRA_BUF_MAX);
2582 if (unlikely(err)) { 2577 if (unlikely(err)) {
2583 WL_ERR(("Could not get bss info %d\n", err)); 2578 WL_ERR("Could not get bss info %d\n", err);
2584 goto update_bss_info_out; 2579 goto update_bss_info_out;
2585 } 2580 }
2586 bi = (struct wl_bss_info *)(wl->extra_buf + 4); 2581 bi = (struct wl_bss_info *)(wl->extra_buf + 4);
2587 if (unlikely(memcmp(&bi->BSSID, &wl->bssid, ETHER_ADDR_LEN))) { 2582 if (unlikely(memcmp(&bi->BSSID, &wl->bssid, ETH_ALEN))) {
2588 err = -EIO; 2583 err = -EIO;
2589 goto update_bss_info_out; 2584 goto update_bss_info_out;
2590 } 2585 }
@@ -2596,7 +2591,7 @@ static s32 wl_update_bss_info(struct wl_priv *wl)
2596 ie_len = bi->ie_length; 2591 ie_len = bi->ie_length;
2597 beacon_interval = cpu_to_le16(bi->beacon_period); 2592 beacon_interval = cpu_to_le16(bi->beacon_period);
2598 } else { 2593 } else {
2599 WL_DBG(("Found the AP in the list - BSSID %pM\n", bss->bssid)); 2594 WL_DBG("Found the AP in the list - BSSID %pM\n", bss->bssid);
2600 ie = bss->information_elements; 2595 ie = bss->information_elements;
2601 ie_len = bss->len_information_elements; 2596 ie_len = bss->len_information_elements;
2602 beacon_interval = bss->beacon_interval; 2597 beacon_interval = bss->beacon_interval;
@@ -2615,7 +2610,7 @@ static s32 wl_update_bss_info(struct wl_priv *wl)
2615 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_GET_DTIMPRD, 2610 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_GET_DTIMPRD,
2616 &dtim_period, sizeof(dtim_period)); 2611 &dtim_period, sizeof(dtim_period));
2617 if (unlikely(err)) { 2612 if (unlikely(err)) {
2618 WL_ERR(("WLC_GET_DTIMPRD error (%d)\n", err)); 2613 WL_ERR("WLC_GET_DTIMPRD error (%d)\n", err);
2619 goto update_bss_info_out; 2614 goto update_bss_info_out;
2620 } 2615 }
2621 } 2616 }
@@ -2636,13 +2631,13 @@ wl_bss_roaming_done(struct wl_priv *wl, struct net_device *ndev,
2636 s32 err = 0; 2631 s32 err = 0;
2637 2632
2638 wl_get_assoc_ies(wl); 2633 wl_get_assoc_ies(wl);
2639 memcpy(&wl->bssid, &e->addr, ETHER_ADDR_LEN); 2634 memcpy(&wl->bssid, &e->addr, ETH_ALEN);
2640 wl_update_bss_info(wl); 2635 wl_update_bss_info(wl);
2641 cfg80211_roamed(ndev, 2636 cfg80211_roamed(ndev,
2642 (u8 *)&wl->bssid, 2637 (u8 *)&wl->bssid,
2643 conn_info->req_ie, conn_info->req_ie_len, 2638 conn_info->req_ie, conn_info->req_ie_len,
2644 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL); 2639 conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
2645 WL_DBG(("Report roaming result\n")); 2640 WL_DBG("Report roaming result\n");
2646 2641
2647 set_bit(WL_STATUS_CONNECTED, &wl->status); 2642 set_bit(WL_STATUS_CONNECTED, &wl->status);
2648 2643
@@ -2657,7 +2652,7 @@ wl_bss_connect_done(struct wl_priv *wl, struct net_device *ndev,
2657 s32 err = 0; 2652 s32 err = 0;
2658 2653
2659 wl_get_assoc_ies(wl); 2654 wl_get_assoc_ies(wl);
2660 memcpy(&wl->bssid, &e->addr, ETHER_ADDR_LEN); 2655 memcpy(&wl->bssid, &e->addr, ETH_ALEN);
2661 wl_update_bss_info(wl); 2656 wl_update_bss_info(wl);
2662 if (test_and_clear_bit(WL_STATUS_CONNECTING, &wl->status)) { 2657 if (test_and_clear_bit(WL_STATUS_CONNECTING, &wl->status)) {
2663 cfg80211_connect_result(ndev, 2658 cfg80211_connect_result(ndev,
@@ -2668,15 +2663,15 @@ wl_bss_connect_done(struct wl_priv *wl, struct net_device *ndev,
2668 conn_info->resp_ie_len, 2663 conn_info->resp_ie_len,
2669 completed ? WLAN_STATUS_SUCCESS : WLAN_STATUS_AUTH_TIMEOUT, 2664 completed ? WLAN_STATUS_SUCCESS : WLAN_STATUS_AUTH_TIMEOUT,
2670 GFP_KERNEL); 2665 GFP_KERNEL);
2671 WL_DBG(("Report connect result - connection %s\n", 2666 WL_DBG("Report connect result - connection %s\n",
2672 completed ? "succeeded" : "failed")); 2667 completed ? "succeeded" : "failed");
2673 } else { 2668 } else {
2674 cfg80211_roamed(ndev, 2669 cfg80211_roamed(ndev,
2675 (u8 *)&wl->bssid, 2670 (u8 *)&wl->bssid,
2676 conn_info->req_ie, conn_info->req_ie_len, 2671 conn_info->req_ie, conn_info->req_ie_len,
2677 conn_info->resp_ie, conn_info->resp_ie_len, 2672 conn_info->resp_ie, conn_info->resp_ie_len,
2678 GFP_KERNEL); 2673 GFP_KERNEL);
2679 WL_DBG(("Report roaming result\n")); 2674 WL_DBG("Report roaming result\n");
2680 } 2675 }
2681 set_bit(WL_STATUS_CONNECTED, &wl->status); 2676 set_bit(WL_STATUS_CONNECTED, &wl->status);
2682 2677
@@ -2716,7 +2711,7 @@ wl_notify_scan_status(struct wl_priv *wl, struct net_device *ndev,
2716 return wl_wakeup_iscan(wl_to_iscan(wl)); 2711 return wl_wakeup_iscan(wl_to_iscan(wl));
2717 2712
2718 if (unlikely(!test_and_clear_bit(WL_STATUS_SCANNING, &wl->status))) { 2713 if (unlikely(!test_and_clear_bit(WL_STATUS_SCANNING, &wl->status))) {
2719 WL_ERR(("Scan complete while device not scanning\n")); 2714 WL_ERR("Scan complete while device not scanning\n");
2720 return -EINVAL; 2715 return -EINVAL;
2721 } 2716 }
2722 if (unlikely(!wl->scan_request)) { 2717 if (unlikely(!wl->scan_request)) {
@@ -2725,14 +2720,14 @@ wl_notify_scan_status(struct wl_priv *wl, struct net_device *ndev,
2725 err = wl_dev_ioctl(ndev, WLC_GET_CHANNEL, &channel_inform, 2720 err = wl_dev_ioctl(ndev, WLC_GET_CHANNEL, &channel_inform,
2726 sizeof(channel_inform)); 2721 sizeof(channel_inform));
2727 if (unlikely(err)) { 2722 if (unlikely(err)) {
2728 WL_ERR(("scan busy (%d)\n", err)); 2723 WL_ERR("scan busy (%d)\n", err);
2729 goto scan_done_out; 2724 goto scan_done_out;
2730 } 2725 }
2731 channel_inform.scan_channel = dtoh32(channel_inform.scan_channel); 2726 channel_inform.scan_channel = dtoh32(channel_inform.scan_channel);
2732 if (unlikely(channel_inform.scan_channel)) { 2727 if (unlikely(channel_inform.scan_channel)) {
2733 2728
2734 WL_DBG(("channel_inform.scan_channel (%d)\n", 2729 WL_DBG("channel_inform.scan_channel (%d)\n",
2735 channel_inform.scan_channel)); 2730 channel_inform.scan_channel);
2736 } 2731 }
2737 wl->bss_list = wl->scan_results; 2732 wl->bss_list = wl->scan_results;
2738 bss_list = wl->bss_list; 2733 bss_list = wl->bss_list;
@@ -2740,7 +2735,7 @@ wl_notify_scan_status(struct wl_priv *wl, struct net_device *ndev,
2740 bss_list->buflen = htod32(len); 2735 bss_list->buflen = htod32(len);
2741 err = wl_dev_ioctl(ndev, WLC_SCAN_RESULTS, bss_list, len); 2736 err = wl_dev_ioctl(ndev, WLC_SCAN_RESULTS, bss_list, len);
2742 if (unlikely(err)) { 2737 if (unlikely(err)) {
2743 WL_ERR(("%s Scan_results error (%d)\n", ndev->name, err)); 2738 WL_ERR("%s Scan_results error (%d)\n", ndev->name, err);
2744 err = -EINVAL; 2739 err = -EINVAL;
2745 goto scan_done_out; 2740 goto scan_done_out;
2746 } 2741 }
@@ -2794,55 +2789,54 @@ static void wl_init_eloop_handler(struct wl_event_loop *el)
2794 2789
2795static s32 wl_init_priv_mem(struct wl_priv *wl) 2790static s32 wl_init_priv_mem(struct wl_priv *wl)
2796{ 2791{
2797 wl->scan_results = (void *)kzalloc(WL_SCAN_BUF_MAX, GFP_KERNEL); 2792 wl->scan_results = kzalloc(WL_SCAN_BUF_MAX, GFP_KERNEL);
2798 if (unlikely(!wl->scan_results)) { 2793 if (unlikely(!wl->scan_results)) {
2799 WL_ERR(("Scan results alloc failed\n")); 2794 WL_ERR("Scan results alloc failed\n");
2800 goto init_priv_mem_out; 2795 goto init_priv_mem_out;
2801 } 2796 }
2802 wl->conf = (void *)kzalloc(sizeof(*wl->conf), GFP_KERNEL); 2797 wl->conf = kzalloc(sizeof(*wl->conf), GFP_KERNEL);
2803 if (unlikely(!wl->conf)) { 2798 if (unlikely(!wl->conf)) {
2804 WL_ERR(("wl_conf alloc failed\n")); 2799 WL_ERR("wl_conf alloc failed\n");
2805 goto init_priv_mem_out; 2800 goto init_priv_mem_out;
2806 } 2801 }
2807 wl->profile = (void *)kzalloc(sizeof(*wl->profile), GFP_KERNEL); 2802 wl->profile = kzalloc(sizeof(*wl->profile), GFP_KERNEL);
2808 if (unlikely(!wl->profile)) { 2803 if (unlikely(!wl->profile)) {
2809 WL_ERR(("wl_profile alloc failed\n")); 2804 WL_ERR("wl_profile alloc failed\n");
2810 goto init_priv_mem_out; 2805 goto init_priv_mem_out;
2811 } 2806 }
2812 wl->bss_info = (void *)kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); 2807 wl->bss_info = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2813 if (unlikely(!wl->bss_info)) { 2808 if (unlikely(!wl->bss_info)) {
2814 WL_ERR(("Bss information alloc failed\n")); 2809 WL_ERR("Bss information alloc failed\n");
2815 goto init_priv_mem_out; 2810 goto init_priv_mem_out;
2816 } 2811 }
2817 wl->scan_req_int = 2812 wl->scan_req_int = kzalloc(sizeof(*wl->scan_req_int), GFP_KERNEL);
2818 (void *)kzalloc(sizeof(*wl->scan_req_int), GFP_KERNEL);
2819 if (unlikely(!wl->scan_req_int)) { 2813 if (unlikely(!wl->scan_req_int)) {
2820 WL_ERR(("Scan req alloc failed\n")); 2814 WL_ERR("Scan req alloc failed\n");
2821 goto init_priv_mem_out; 2815 goto init_priv_mem_out;
2822 } 2816 }
2823 wl->ioctl_buf = (void *)kzalloc(WL_IOCTL_LEN_MAX, GFP_KERNEL); 2817 wl->ioctl_buf = kzalloc(WL_IOCTL_LEN_MAX, GFP_KERNEL);
2824 if (unlikely(!wl->ioctl_buf)) { 2818 if (unlikely(!wl->ioctl_buf)) {
2825 WL_ERR(("Ioctl buf alloc failed\n")); 2819 WL_ERR("Ioctl buf alloc failed\n");
2826 goto init_priv_mem_out; 2820 goto init_priv_mem_out;
2827 } 2821 }
2828 wl->extra_buf = (void *)kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL); 2822 wl->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
2829 if (unlikely(!wl->extra_buf)) { 2823 if (unlikely(!wl->extra_buf)) {
2830 WL_ERR(("Extra buf alloc failed\n")); 2824 WL_ERR("Extra buf alloc failed\n");
2831 goto init_priv_mem_out; 2825 goto init_priv_mem_out;
2832 } 2826 }
2833 wl->iscan = (void *)kzalloc(sizeof(*wl->iscan), GFP_KERNEL); 2827 wl->iscan = kzalloc(sizeof(*wl->iscan), GFP_KERNEL);
2834 if (unlikely(!wl->iscan)) { 2828 if (unlikely(!wl->iscan)) {
2835 WL_ERR(("Iscan buf alloc failed\n")); 2829 WL_ERR("Iscan buf alloc failed\n");
2836 goto init_priv_mem_out; 2830 goto init_priv_mem_out;
2837 } 2831 }
2838 wl->fw = (void *)kzalloc(sizeof(*wl->fw), GFP_KERNEL); 2832 wl->fw = kzalloc(sizeof(*wl->fw), GFP_KERNEL);
2839 if (unlikely(!wl->fw)) { 2833 if (unlikely(!wl->fw)) {
2840 WL_ERR(("fw object alloc failed\n")); 2834 WL_ERR("fw object alloc failed\n");
2841 goto init_priv_mem_out; 2835 goto init_priv_mem_out;
2842 } 2836 }
2843 wl->pmk_list = (void *)kzalloc(sizeof(*wl->pmk_list), GFP_KERNEL); 2837 wl->pmk_list = kzalloc(sizeof(*wl->pmk_list), GFP_KERNEL);
2844 if (unlikely(!wl->pmk_list)) { 2838 if (unlikely(!wl->pmk_list)) {
2845 WL_ERR(("pmk list alloc failed\n")); 2839 WL_ERR("pmk list alloc failed\n");
2846 goto init_priv_mem_out; 2840 goto init_priv_mem_out;
2847 } 2841 }
2848 2842
@@ -2884,7 +2878,7 @@ static s32 wl_create_event_handler(struct wl_priv *wl)
2884 wl->event_tsk = kthread_run(wl_event_handler, wl, "wl_event_handler"); 2878 wl->event_tsk = kthread_run(wl_event_handler, wl, "wl_event_handler");
2885 if (IS_ERR(wl->event_tsk)) { 2879 if (IS_ERR(wl->event_tsk)) {
2886 wl->event_tsk = NULL; 2880 wl->event_tsk = NULL;
2887 WL_ERR(("failed to create event thread\n")); 2881 WL_ERR("failed to create event thread\n");
2888 return -ENOMEM; 2882 return -ENOMEM;
2889 } 2883 }
2890 return 0; 2884 return 0;
@@ -2917,7 +2911,7 @@ static void wl_notify_iscan_complete(struct wl_iscan_ctrl *iscan, bool aborted)
2917 struct net_device *ndev = wl_to_ndev(wl); 2911 struct net_device *ndev = wl_to_ndev(wl);
2918 2912
2919 if (unlikely(!test_and_clear_bit(WL_STATUS_SCANNING, &wl->status))) { 2913 if (unlikely(!test_and_clear_bit(WL_STATUS_SCANNING, &wl->status))) {
2920 WL_ERR(("Scan complete while device not scanning\n")); 2914 WL_ERR("Scan complete while device not scanning\n");
2921 return; 2915 return;
2922 } 2916 }
2923 if (likely(wl->scan_request)) { 2917 if (likely(wl->scan_request)) {
@@ -2931,7 +2925,7 @@ static void wl_notify_iscan_complete(struct wl_iscan_ctrl *iscan, bool aborted)
2931static s32 wl_wakeup_iscan(struct wl_iscan_ctrl *iscan) 2925static s32 wl_wakeup_iscan(struct wl_iscan_ctrl *iscan)
2932{ 2926{
2933 if (likely(iscan->state != WL_ISCAN_STATE_IDLE)) { 2927 if (likely(iscan->state != WL_ISCAN_STATE_IDLE)) {
2934 WL_DBG(("wake up iscan\n")); 2928 WL_DBG("wake up iscan\n");
2935 up(&iscan->sync); 2929 up(&iscan->sync);
2936 return 0; 2930 return 0;
2937 } 2931 }
@@ -2961,14 +2955,14 @@ wl_get_iscan_results(struct wl_iscan_ctrl *iscan, u32 *status,
2961 WL_ISCAN_RESULTS_FIXED_SIZE, iscan->scan_buf, 2955 WL_ISCAN_RESULTS_FIXED_SIZE, iscan->scan_buf,
2962 WL_ISCAN_BUF_MAX); 2956 WL_ISCAN_BUF_MAX);
2963 if (unlikely(err)) { 2957 if (unlikely(err)) {
2964 WL_ERR(("error (%d)\n", err)); 2958 WL_ERR("error (%d)\n", err);
2965 return err; 2959 return err;
2966 } 2960 }
2967 results->buflen = dtoh32(results->buflen); 2961 results->buflen = dtoh32(results->buflen);
2968 results->version = dtoh32(results->version); 2962 results->version = dtoh32(results->version);
2969 results->count = dtoh32(results->count); 2963 results->count = dtoh32(results->count);
2970 WL_DBG(("results->count = %d\n", results->count)); 2964 WL_DBG("results->count = %d\n", results->count);
2971 WL_DBG(("results->buflen = %d\n", results->buflen)); 2965 WL_DBG("results->buflen = %d\n", results->buflen);
2972 *status = dtoh32(list_buf->status); 2966 *status = dtoh32(list_buf->status);
2973 *bss_list = results; 2967 *bss_list = results;
2974 2968
@@ -3053,7 +3047,7 @@ static s32 wl_iscan_thread(void *data)
3053 err = wl_get_iscan_results(iscan, &status, &wl->bss_list); 3047 err = wl_get_iscan_results(iscan, &status, &wl->bss_list);
3054 if (unlikely(err)) { 3048 if (unlikely(err)) {
3055 status = WL_SCAN_RESULTS_ABORTED; 3049 status = WL_SCAN_RESULTS_ABORTED;
3056 WL_ERR(("Abort iscan\n")); 3050 WL_ERR("Abort iscan\n");
3057 } 3051 }
3058 rtnl_unlock(); 3052 rtnl_unlock();
3059 el->handler[status] (wl); 3053 el->handler[status] (wl);
@@ -3062,7 +3056,7 @@ static s32 wl_iscan_thread(void *data)
3062 del_timer_sync(&iscan->timer); 3056 del_timer_sync(&iscan->timer);
3063 iscan->timer_on = 0; 3057 iscan->timer_on = 0;
3064 } 3058 }
3065 WL_DBG(("%s was terminated\n", __func__)); 3059 WL_DBG("%s was terminated\n", __func__);
3066 3060
3067 return 0; 3061 return 0;
3068} 3062}
@@ -3073,7 +3067,7 @@ static void wl_iscan_timer(unsigned long data)
3073 3067
3074 if (iscan) { 3068 if (iscan) {
3075 iscan->timer_on = 0; 3069 iscan->timer_on = 0;
3076 WL_DBG(("timer expired\n")); 3070 WL_DBG("timer expired\n");
3077 wl_wakeup_iscan(iscan); 3071 wl_wakeup_iscan(iscan);
3078 } 3072 }
3079} 3073}
@@ -3088,7 +3082,7 @@ static s32 wl_invoke_iscan(struct wl_priv *wl)
3088 sema_init(&iscan->sync, 0); 3082 sema_init(&iscan->sync, 0);
3089 iscan->tsk = kthread_run(wl_iscan_thread, iscan, "wl_iscan"); 3083 iscan->tsk = kthread_run(wl_iscan_thread, iscan, "wl_iscan");
3090 if (IS_ERR(iscan->tsk)) { 3084 if (IS_ERR(iscan->tsk)) {
3091 WL_ERR(("Could not create iscan thread\n")); 3085 WL_ERR("Could not create iscan thread\n");
3092 iscan->tsk = NULL; 3086 iscan->tsk = NULL;
3093 return -ENOMEM; 3087 return -ENOMEM;
3094 } 3088 }
@@ -3123,7 +3117,7 @@ static s32 wl_init_iscan(struct wl_priv *wl)
3123 sema_init(&iscan->sync, 0); 3117 sema_init(&iscan->sync, 0);
3124 iscan->tsk = kthread_run(wl_iscan_thread, iscan, "wl_iscan"); 3118 iscan->tsk = kthread_run(wl_iscan_thread, iscan, "wl_iscan");
3125 if (IS_ERR(iscan->tsk)) { 3119 if (IS_ERR(iscan->tsk)) {
3126 WL_ERR(("Could not create iscan thread\n")); 3120 WL_ERR("Could not create iscan thread\n");
3127 iscan->tsk = NULL; 3121 iscan->tsk = NULL;
3128 return -ENOMEM; 3122 return -ENOMEM;
3129 } 3123 }
@@ -3192,17 +3186,17 @@ s32 wl_cfg80211_attach(struct net_device *ndev, void *data)
3192 s32 err = 0; 3186 s32 err = 0;
3193 3187
3194 if (unlikely(!ndev)) { 3188 if (unlikely(!ndev)) {
3195 WL_ERR(("ndev is invaild\n")); 3189 WL_ERR("ndev is invalid\n");
3196 return -ENODEV; 3190 return -ENODEV;
3197 } 3191 }
3198 wl_cfg80211_dev = kzalloc(sizeof(struct wl_dev), GFP_KERNEL); 3192 wl_cfg80211_dev = kzalloc(sizeof(struct wl_dev), GFP_KERNEL);
3199 if (unlikely(!wl_cfg80211_dev)) { 3193 if (unlikely(!wl_cfg80211_dev)) {
3200 WL_ERR(("wl_cfg80211_dev is invalid\n")); 3194 WL_ERR("wl_cfg80211_dev is invalid\n");
3201 return -ENOMEM; 3195 return -ENOMEM;
3202 } 3196 }
3203 WL_DBG(("func %p\n", wl_cfg80211_get_sdio_func())); 3197 WL_DBG("func %p\n", wl_cfg80211_get_sdio_func());
3204 wdev = wl_alloc_wdev(sizeof(struct wl_iface), &wl_cfg80211_get_sdio_func()->dev); 3198 wdev = wl_alloc_wdev(sizeof(struct wl_iface), &wl_cfg80211_get_sdio_func()->dev);
3205 if (unlikely(IS_ERR(wdev))) 3199 if (IS_ERR(wdev))
3206 return -ENOMEM; 3200 return -ENOMEM;
3207 3201
3208 wdev->iftype = wl_mode_to_nl80211_iftype(WL_MODE_BSS); 3202 wdev->iftype = wl_mode_to_nl80211_iftype(WL_MODE_BSS);
@@ -3216,7 +3210,7 @@ s32 wl_cfg80211_attach(struct net_device *ndev, void *data)
3216 wdev->netdev = ndev; 3210 wdev->netdev = ndev;
3217 err = wl_init_priv(wl); 3211 err = wl_init_priv(wl);
3218 if (unlikely(err)) { 3212 if (unlikely(err)) {
3219 WL_ERR(("Failed to init iwm_priv (%d)\n", err)); 3213 WL_ERR("Failed to init iwm_priv (%d)\n", err);
3220 goto cfg80211_attach_out; 3214 goto cfg80211_attach_out;
3221 } 3215 }
3222 wl_set_drvdata(wl_cfg80211_dev, ci); 3216 wl_set_drvdata(wl_cfg80211_dev, ci);
@@ -3261,19 +3255,19 @@ static s32 wl_event_handler(void *data)
3261 break; 3255 break;
3262 e = wl_deq_event(wl); 3256 e = wl_deq_event(wl);
3263 if (unlikely(!e)) { 3257 if (unlikely(!e)) {
3264 WL_ERR(("eqeue empty..\n")); 3258 WL_ERR("event queue empty...\n");
3265 BUG(); 3259 BUG();
3266 } 3260 }
3267 WL_DBG(("event type (%d)\n", e->etype)); 3261 WL_DBG("event type (%d)\n", e->etype);
3268 if (wl->el.handler[e->etype]) { 3262 if (wl->el.handler[e->etype]) {
3269 wl->el.handler[e->etype] (wl, wl_to_ndev(wl), &e->emsg, 3263 wl->el.handler[e->etype] (wl, wl_to_ndev(wl), &e->emsg,
3270 e->edata); 3264 e->edata);
3271 } else { 3265 } else {
3272 WL_DBG(("Unknown Event (%d): ignoring\n", e->etype)); 3266 WL_DBG("Unknown Event (%d): ignoring\n", e->etype);
3273 } 3267 }
3274 wl_put_event(e); 3268 wl_put_event(e);
3275 } 3269 }
3276 WL_DBG(("%s was terminated\n", __func__)); 3270 WL_DBG("%s was terminated\n", __func__);
3277 return 0; 3271 return 0;
3278} 3272}
3279 3273
@@ -3286,7 +3280,7 @@ wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t * e, void *data)
3286 s8 *estr = (event_type <= sizeof(wl_dbg_estr) / WL_DBG_ESTR_MAX - 1) ? 3280 s8 *estr = (event_type <= sizeof(wl_dbg_estr) / WL_DBG_ESTR_MAX - 1) ?
3287 wl_dbg_estr[event_type] : (s8 *) "Unknown"; 3281 wl_dbg_estr[event_type] : (s8 *) "Unknown";
3288#endif /* (WL_DBG_LEVEL > 0) */ 3282#endif /* (WL_DBG_LEVEL > 0) */
3289 WL_DBG(("event_type (%d):" "WLC_E_" "%s\n", event_type, estr)); 3283 WL_DBG("event_type (%d):" "WLC_E_" "%s\n", event_type, estr);
3290 if (likely(!wl_enq_event(wl, event_type, e, data))) 3284 if (likely(!wl_enq_event(wl, event_type, e, data)))
3291 wl_wakeup_event(wl); 3285 wl_wakeup_event(wl);
3292} 3286}
@@ -3341,7 +3335,7 @@ wl_enq_event(struct wl_priv *wl, u32 event, const wl_event_msg_t *msg,
3341 3335
3342 e = kzalloc(sizeof(struct wl_event_q), GFP_KERNEL); 3336 e = kzalloc(sizeof(struct wl_event_q), GFP_KERNEL);
3343 if (unlikely(!e)) { 3337 if (unlikely(!e)) {
3344 WL_ERR(("event alloc failed\n")); 3338 WL_ERR("event alloc failed\n");
3345 return -ENOMEM; 3339 return -ENOMEM;
3346 } 3340 }
3347 3341
@@ -3385,8 +3379,8 @@ static s32 wl_dongle_mode(struct net_device *ndev, s32 iftype)
3385 switch (iftype) { 3379 switch (iftype) {
3386 case NL80211_IFTYPE_MONITOR: 3380 case NL80211_IFTYPE_MONITOR:
3387 case NL80211_IFTYPE_WDS: 3381 case NL80211_IFTYPE_WDS:
3388 WL_ERR(("type (%d) : currently we do not support this mode\n", 3382 WL_ERR("type (%d) : currently we do not support this mode\n",
3389 iftype)); 3383 iftype);
3390 err = -EINVAL; 3384 err = -EINVAL;
3391 return err; 3385 return err;
3392 case NL80211_IFTYPE_ADHOC: 3386 case NL80211_IFTYPE_ADHOC:
@@ -3396,20 +3390,20 @@ static s32 wl_dongle_mode(struct net_device *ndev, s32 iftype)
3396 break; 3390 break;
3397 default: 3391 default:
3398 err = -EINVAL; 3392 err = -EINVAL;
3399 WL_ERR(("invalid type (%d)\n", iftype)); 3393 WL_ERR("invalid type (%d)\n", iftype);
3400 return err; 3394 return err;
3401 } 3395 }
3402 infra = htod32(infra); 3396 infra = htod32(infra);
3403 ap = htod32(ap); 3397 ap = htod32(ap);
3404 WL_DBG(("%s ap (%d), infra (%d)\n", ndev->name, ap, infra)); 3398 WL_DBG("%s ap (%d), infra (%d)\n", ndev->name, ap, infra);
3405 err = wl_dev_ioctl(ndev, WLC_SET_INFRA, &infra, sizeof(infra)); 3399 err = wl_dev_ioctl(ndev, WLC_SET_INFRA, &infra, sizeof(infra));
3406 if (unlikely(err)) { 3400 if (unlikely(err)) {
3407 WL_ERR(("WLC_SET_INFRA error (%d)\n", err)); 3401 WL_ERR("WLC_SET_INFRA error (%d)\n", err);
3408 return err; 3402 return err;
3409 } 3403 }
3410 err = wl_dev_ioctl(ndev, WLC_SET_AP, &ap, sizeof(ap)); 3404 err = wl_dev_ioctl(ndev, WLC_SET_AP, &ap, sizeof(ap));
3411 if (unlikely(err)) { 3405 if (unlikely(err)) {
3412 WL_ERR(("WLC_SET_AP error (%d)\n", err)); 3406 WL_ERR("WLC_SET_AP error (%d)\n", err);
3413 return err; 3407 return err;
3414 } 3408 }
3415 3409
@@ -3431,7 +3425,7 @@ static s32 wl_dongle_up(struct net_device *ndev, u32 up)
3431 3425
3432 err = wl_dev_ioctl(ndev, WLC_UP, &up, sizeof(up)); 3426 err = wl_dev_ioctl(ndev, WLC_UP, &up, sizeof(up));
3433 if (unlikely(err)) { 3427 if (unlikely(err)) {
3434 WL_ERR(("WLC_UP error (%d)\n", err)); 3428 WL_ERR("WLC_UP error (%d)\n", err);
3435 } 3429 }
3436 return err; 3430 return err;
3437} 3431}
@@ -3442,7 +3436,7 @@ static s32 wl_dongle_power(struct net_device *ndev, u32 power_mode)
3442 3436
3443 err = wl_dev_ioctl(ndev, WLC_SET_PM, &power_mode, sizeof(power_mode)); 3437 err = wl_dev_ioctl(ndev, WLC_SET_PM, &power_mode, sizeof(power_mode));
3444 if (unlikely(err)) { 3438 if (unlikely(err)) {
3445 WL_ERR(("WLC_SET_PM error (%d)\n", err)); 3439 WL_ERR("WLC_SET_PM error (%d)\n", err);
3446 } 3440 }
3447 return err; 3441 return err;
3448} 3442}
@@ -3459,14 +3453,14 @@ wl_dongle_glom(struct net_device *ndev, u32 glom, u32 dongle_align)
3459 sizeof(iovbuf)); 3453 sizeof(iovbuf));
3460 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); 3454 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3461 if (unlikely(err)) { 3455 if (unlikely(err)) {
3462 WL_ERR(("txglomalign error (%d)\n", err)); 3456 WL_ERR("txglomalign error (%d)\n", err);
3463 goto dongle_glom_out; 3457 goto dongle_glom_out;
3464 } 3458 }
3465 /* disable glom option per default */ 3459 /* disable glom option per default */
3466 bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf)); 3460 bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
3467 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); 3461 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3468 if (unlikely(err)) { 3462 if (unlikely(err)) {
3469 WL_ERR(("txglom error (%d)\n", err)); 3463 WL_ERR("txglom error (%d)\n", err);
3470 goto dongle_glom_out; 3464 goto dongle_glom_out;
3471 } 3465 }
3472dongle_glom_out: 3466dongle_glom_out:
@@ -3487,7 +3481,7 @@ wl_dongle_roam(struct net_device *ndev, u32 roamvar, u32 bcn_timeout)
3487 sizeof(iovbuf)); 3481 sizeof(iovbuf));
3488 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); 3482 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3489 if (unlikely(err)) { 3483 if (unlikely(err)) {
3490 WL_ERR(("bcn_timeout error (%d)\n", err)); 3484 WL_ERR("bcn_timeout error (%d)\n", err);
3491 goto dongle_rom_out; 3485 goto dongle_rom_out;
3492 } 3486 }
3493 } 3487 }
@@ -3496,7 +3490,7 @@ wl_dongle_roam(struct net_device *ndev, u32 roamvar, u32 bcn_timeout)
3496 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf)); 3490 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
3497 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); 3491 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3498 if (unlikely(err)) { 3492 if (unlikely(err)) {
3499 WL_ERR(("roam_off error (%d)\n", err)); 3493 WL_ERR("roam_off error (%d)\n", err);
3500 goto dongle_rom_out; 3494 goto dongle_rom_out;
3501 } 3495 }
3502dongle_rom_out: 3496dongle_rom_out:
@@ -3516,7 +3510,7 @@ static s32 wl_dongle_eventmsg(struct net_device *ndev)
3516 sizeof(iovbuf)); 3510 sizeof(iovbuf));
3517 err = wl_dev_ioctl(ndev, WLC_GET_VAR, iovbuf, sizeof(iovbuf)); 3511 err = wl_dev_ioctl(ndev, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
3518 if (unlikely(err)) { 3512 if (unlikely(err)) {
3519 WL_ERR(("Get event_msgs error (%d)\n", err)); 3513 WL_ERR("Get event_msgs error (%d)\n", err);
3520 goto dongle_eventmsg_out; 3514 goto dongle_eventmsg_out;
3521 } 3515 }
3522 memcpy(eventmask, iovbuf, WL_EVENTING_MASK_LEN); 3516 memcpy(eventmask, iovbuf, WL_EVENTING_MASK_LEN);
@@ -3544,7 +3538,7 @@ static s32 wl_dongle_eventmsg(struct net_device *ndev)
3544 sizeof(iovbuf)); 3538 sizeof(iovbuf));
3545 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); 3539 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3546 if (unlikely(err)) { 3540 if (unlikely(err)) {
3547 WL_ERR(("Set event_msgs error (%d)\n", err)); 3541 WL_ERR("Set event_msgs error (%d)\n", err);
3548 goto dongle_eventmsg_out; 3542 goto dongle_eventmsg_out;
3549 } 3543 }
3550 3544
@@ -3562,9 +3556,9 @@ wl_dongle_scantime(struct net_device *ndev, s32 scan_assoc_time,
3562 sizeof(scan_assoc_time)); 3556 sizeof(scan_assoc_time));
3563 if (err) { 3557 if (err) {
3564 if (err == -EOPNOTSUPP) { 3558 if (err == -EOPNOTSUPP) {
3565 WL_INFO(("Scan assoc time is not supported\n")); 3559 WL_INFO("Scan assoc time is not supported\n");
3566 } else { 3560 } else {
3567 WL_ERR(("Scan assoc time error (%d)\n", err)); 3561 WL_ERR("Scan assoc time error (%d)\n", err);
3568 } 3562 }
3569 goto dongle_scantime_out; 3563 goto dongle_scantime_out;
3570 } 3564 }
@@ -3572,9 +3566,9 @@ wl_dongle_scantime(struct net_device *ndev, s32 scan_assoc_time,
3572 sizeof(scan_unassoc_time)); 3566 sizeof(scan_unassoc_time));
3573 if (err) { 3567 if (err) {
3574 if (err == -EOPNOTSUPP) { 3568 if (err == -EOPNOTSUPP) {
3575 WL_INFO(("Scan unassoc time is not supported\n")); 3569 WL_INFO("Scan unassoc time is not supported\n");
3576 } else { 3570 } else {
3577 WL_ERR(("Scan unassoc time error (%d)\n", err)); 3571 WL_ERR("Scan unassoc time error (%d)\n", err);
3578 } 3572 }
3579 goto dongle_scantime_out; 3573 goto dongle_scantime_out;
3580 } 3574 }
@@ -3595,9 +3589,9 @@ wl_dongle_offload(struct net_device *ndev, s32 arpoe, s32 arp_ol)
3595 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); 3589 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3596 if (err) { 3590 if (err) {
3597 if (err == -EOPNOTSUPP) 3591 if (err == -EOPNOTSUPP)
3598 WL_INFO(("arpoe is not supported\n")); 3592 WL_INFO("arpoe is not supported\n");
3599 else 3593 else
3600 WL_ERR(("arpoe error (%d)\n", err)); 3594 WL_ERR("arpoe error (%d)\n", err);
3601 3595
3602 goto dongle_offload_out; 3596 goto dongle_offload_out;
3603 } 3597 }
@@ -3605,9 +3599,9 @@ wl_dongle_offload(struct net_device *ndev, s32 arpoe, s32 arp_ol)
3605 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); 3599 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3606 if (err) { 3600 if (err) {
3607 if (err == -EOPNOTSUPP) 3601 if (err == -EOPNOTSUPP)
3608 WL_INFO(("arp_ol is not supported\n")); 3602 WL_INFO("arp_ol is not supported\n");
3609 else 3603 else
3610 WL_ERR(("arp_ol error (%d)\n", err)); 3604 WL_ERR("arp_ol error (%d)\n", err);
3611 3605
3612 goto dongle_offload_out; 3606 goto dongle_offload_out;
3613 } 3607 }
@@ -3620,12 +3614,12 @@ static s32 wl_pattern_atoh(s8 *src, s8 *dst)
3620{ 3614{
3621 int i; 3615 int i;
3622 if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) { 3616 if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
3623 WL_ERR(("Mask invalid format. Needs to start with 0x\n")); 3617 WL_ERR("Mask invalid format. Needs to start with 0x\n");
3624 return -1; 3618 return -1;
3625 } 3619 }
3626 src = src + 2; /* Skip past 0x */ 3620 src = src + 2; /* Skip past 0x */
3627 if (strlen(src) % 2 != 0) { 3621 if (strlen(src) % 2 != 0) {
3628 WL_ERR(("Mask invalid format. Needs to be of even length\n")); 3622 WL_ERR("Mask invalid format. Needs to be of even length\n");
3629 return -1; 3623 return -1;
3630 } 3624 }
3631 for (i = 0; *src != '\0'; i++) { 3625 for (i = 0; *src != '\0'; i++) {
@@ -3684,7 +3678,7 @@ static s32 wl_dongle_filter(struct net_device *ndev, u32 filter_mode)
3684 mask_and_pattern[mask_size])); 3678 mask_and_pattern[mask_size]));
3685 3679
3686 if (mask_size != pattern_size) { 3680 if (mask_size != pattern_size) {
3687 WL_ERR(("Mask and pattern not the same size\n")); 3681 WL_ERR("Mask and pattern not the same size\n");
3688 err = -EINVAL; 3682 err = -EINVAL;
3689 goto dongle_filter_out; 3683 goto dongle_filter_out;
3690 } 3684 }
@@ -3704,9 +3698,9 @@ static s32 wl_dongle_filter(struct net_device *ndev, u32 filter_mode)
3704 err = wl_dev_ioctl(ndev, WLC_SET_VAR, buf, buf_len); 3698 err = wl_dev_ioctl(ndev, WLC_SET_VAR, buf, buf_len);
3705 if (err) { 3699 if (err) {
3706 if (err == -EOPNOTSUPP) { 3700 if (err == -EOPNOTSUPP) {
3707 WL_INFO(("filter not supported\n")); 3701 WL_INFO("filter not supported\n");
3708 } else { 3702 } else {
3709 WL_ERR(("filter (%d)\n", err)); 3703 WL_ERR("filter (%d)\n", err);
3710 } 3704 }
3711 goto dongle_filter_out; 3705 goto dongle_filter_out;
3712 } 3706 }
@@ -3717,9 +3711,9 @@ static s32 wl_dongle_filter(struct net_device *ndev, u32 filter_mode)
3717 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); 3711 err = wl_dev_ioctl(ndev, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
3718 if (err) { 3712 if (err) {
3719 if (err == -EOPNOTSUPP) { 3713 if (err == -EOPNOTSUPP) {
3720 WL_INFO(("filter_mode not supported\n")); 3714 WL_INFO("filter_mode not supported\n");
3721 } else { 3715 } else {
3722 WL_ERR(("filter_mode (%d)\n", err)); 3716 WL_ERR("filter_mode (%d)\n", err);
3723 } 3717 }
3724 goto dongle_filter_out; 3718 goto dongle_filter_out;
3725 } 3719 }
@@ -3800,12 +3794,12 @@ static s32 wl_update_wiphybands(struct wl_priv *wl)
3800 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_GET_PHYLIST, &phy_list, 3794 err = wl_dev_ioctl(wl_to_ndev(wl), WLC_GET_PHYLIST, &phy_list,
3801 sizeof(phy_list)); 3795 sizeof(phy_list));
3802 if (unlikely(err)) { 3796 if (unlikely(err)) {
3803 WL_ERR(("error (%d)\n", err)); 3797 WL_ERR("error (%d)\n", err);
3804 return err; 3798 return err;
3805 } 3799 }
3806 3800
3807 phy = ((char *)&phy_list)[1]; 3801 phy = ((char *)&phy_list)[1];
3808 WL_DBG(("%c phy\n", phy)); 3802 WL_DBG("%c phy\n", phy);
3809 if (phy == 'n' || phy == 'a') { 3803 if (phy == 'n' || phy == 'a') {
3810 wiphy = wl_to_wiphy(wl); 3804 wiphy = wl_to_wiphy(wl);
3811 wiphy->bands[IEEE80211_BAND_5GHZ] = &__wl_band_5ghz_n; 3805 wiphy->bands[IEEE80211_BAND_5GHZ] = &__wl_band_5ghz_n;
@@ -3911,7 +3905,7 @@ static void *wl_read_prof(struct wl_priv *wl, s32 item)
3911 case WL_PROF_SSID: 3905 case WL_PROF_SSID:
3912 return &wl->profile->ssid; 3906 return &wl->profile->ssid;
3913 } 3907 }
3914 WL_ERR(("invalid item (%d)\n", item)); 3908 WL_ERR("invalid item (%d)\n", item);
3915 return NULL; 3909 return NULL;
3916} 3910}
3917 3911
@@ -3932,9 +3926,9 @@ wl_update_prof(struct wl_priv *wl, const wl_event_msg_t *e, void *data,
3932 break; 3926 break;
3933 case WL_PROF_BSSID: 3927 case WL_PROF_BSSID:
3934 if (data) 3928 if (data)
3935 memcpy(wl->profile->bssid, data, ETHER_ADDR_LEN); 3929 memcpy(wl->profile->bssid, data, ETH_ALEN);
3936 else 3930 else
3937 memset(wl->profile->bssid, 0, ETHER_ADDR_LEN); 3931 memset(wl->profile->bssid, 0, ETH_ALEN);
3938 break; 3932 break;
3939 case WL_PROF_SEC: 3933 case WL_PROF_SEC:
3940 memcpy(&wl->profile->sec, data, sizeof(wl->profile->sec)); 3934 memcpy(&wl->profile->sec, data, sizeof(wl->profile->sec));
@@ -3949,7 +3943,7 @@ wl_update_prof(struct wl_priv *wl, const wl_event_msg_t *e, void *data,
3949 wl->profile->dtim_period = *(u8 *)data; 3943 wl->profile->dtim_period = *(u8 *)data;
3950 break; 3944 break;
3951 default: 3945 default:
3952 WL_ERR(("unsupported item (%d)\n", item)); 3946 WL_ERR("unsupported item (%d)\n", item);
3953 err = -EOPNOTSUPP; 3947 err = -EOPNOTSUPP;
3954 break; 3948 break;
3955 } 3949 }
@@ -3991,7 +3985,7 @@ static __used s32 wl_add_ie(struct wl_priv *wl, u8 t, u8 l, u8 *v)
3991 s32 err = 0; 3985 s32 err = 0;
3992 3986
3993 if (unlikely(ie->offset + l + 2 > WL_TLV_INFO_MAX)) { 3987 if (unlikely(ie->offset + l + 2 > WL_TLV_INFO_MAX)) {
3994 WL_ERR(("ei crosses buffer boundary\n")); 3988 WL_ERR("ei crosses buffer boundary\n");
3995 return -ENOSPC; 3989 return -ENOSPC;
3996 } 3990 }
3997 ie->buf[ie->offset] = t; 3991 ie->buf[ie->offset] = t;
@@ -4008,7 +4002,7 @@ static s32 wl_mrg_ie(struct wl_priv *wl, u8 *ie_stream, u16 ie_size)
4008 s32 err = 0; 4002 s32 err = 0;
4009 4003
4010 if (unlikely(ie->offset + ie_size > WL_TLV_INFO_MAX)) { 4004 if (unlikely(ie->offset + ie_size > WL_TLV_INFO_MAX)) {
4011 WL_ERR(("ei_stream crosses buffer boundary\n")); 4005 WL_ERR("ei_stream crosses buffer boundary\n");
4012 return -ENOSPC; 4006 return -ENOSPC;
4013 } 4007 }
4014 memcpy(&ie->buf[ie->offset], ie_stream, ie_size); 4008 memcpy(&ie->buf[ie->offset], ie_stream, ie_size);
@@ -4023,7 +4017,7 @@ static s32 wl_cp_ie(struct wl_priv *wl, u8 *dst, u16 dst_size)
4023 s32 err = 0; 4017 s32 err = 0;
4024 4018
4025 if (unlikely(ie->offset > dst_size)) { 4019 if (unlikely(ie->offset > dst_size)) {
4026 WL_ERR(("dst_size is not enough\n")); 4020 WL_ERR("dst_size is not enough\n");
4027 return -ENOSPC; 4021 return -ENOSPC;
4028 } 4022 }
4029 memcpy(dst, &ie->buf[0], ie->offset); 4023 memcpy(dst, &ie->buf[0], ie->offset);
@@ -4123,37 +4117,37 @@ void *wl_cfg80211_request_fw(s8 *file_name)
4123 const struct firmware *fw_entry = NULL; 4117 const struct firmware *fw_entry = NULL;
4124 s32 err = 0; 4118 s32 err = 0;
4125 4119
4126 WL_DBG(("file name : \"%s\"\n", file_name)); 4120 WL_DBG("file name : \"%s\"\n", file_name);
4127 wl = WL_PRIV_GET(); 4121 wl = WL_PRIV_GET();
4128 4122
4129 if (!test_bit(WL_FW_LOADING_DONE, &wl->fw->status)) { 4123 if (!test_bit(WL_FW_LOADING_DONE, &wl->fw->status)) {
4130 err = request_firmware(&wl->fw->fw_entry, file_name, 4124 err = request_firmware(&wl->fw->fw_entry, file_name,
4131 &wl_cfg80211_get_sdio_func()->dev); 4125 &wl_cfg80211_get_sdio_func()->dev);
4132 if (unlikely(err)) { 4126 if (unlikely(err)) {
4133 WL_ERR(("Could not download fw (%d)\n", err)); 4127 WL_ERR("Could not download fw (%d)\n", err);
4134 goto req_fw_out; 4128 goto req_fw_out;
4135 } 4129 }
4136 set_bit(WL_FW_LOADING_DONE, &wl->fw->status); 4130 set_bit(WL_FW_LOADING_DONE, &wl->fw->status);
4137 fw_entry = wl->fw->fw_entry; 4131 fw_entry = wl->fw->fw_entry;
4138 if (fw_entry) { 4132 if (fw_entry) {
4139 WL_DBG(("fw size (%zd), data (%p)\n", fw_entry->size, 4133 WL_DBG("fw size (%zd), data (%p)\n",
4140 fw_entry->data)); 4134 fw_entry->size, fw_entry->data);
4141 } 4135 }
4142 } else if (!test_bit(WL_NVRAM_LOADING_DONE, &wl->fw->status)) { 4136 } else if (!test_bit(WL_NVRAM_LOADING_DONE, &wl->fw->status)) {
4143 err = request_firmware(&wl->fw->fw_entry, file_name, 4137 err = request_firmware(&wl->fw->fw_entry, file_name,
4144 &wl_cfg80211_get_sdio_func()->dev); 4138 &wl_cfg80211_get_sdio_func()->dev);
4145 if (unlikely(err)) { 4139 if (unlikely(err)) {
4146 WL_ERR(("Could not download nvram (%d)\n", err)); 4140 WL_ERR("Could not download nvram (%d)\n", err);
4147 goto req_fw_out; 4141 goto req_fw_out;
4148 } 4142 }
4149 set_bit(WL_NVRAM_LOADING_DONE, &wl->fw->status); 4143 set_bit(WL_NVRAM_LOADING_DONE, &wl->fw->status);
4150 fw_entry = wl->fw->fw_entry; 4144 fw_entry = wl->fw->fw_entry;
4151 if (fw_entry) { 4145 if (fw_entry) {
4152 WL_DBG(("nvram size (%zd), data (%p)\n", fw_entry->size, 4146 WL_DBG("nvram size (%zd), data (%p)\n",
4153 fw_entry->data)); 4147 fw_entry->size, fw_entry->data);
4154 } 4148 }
4155 } else { 4149 } else {
4156 WL_DBG(("Downloading already done. Nothing to do more\n")); 4150 WL_DBG("Downloading already done. Nothing to do more\n");
4157 err = -EPERM; 4151 err = -EPERM;
4158 } 4152 }
4159 4153
@@ -4189,10 +4183,10 @@ static void wl_set_mpc(struct net_device *ndev, int mpc)
4189 4183
4190 err = wl_dev_intvar_set(ndev, "mpc", mpc); 4184 err = wl_dev_intvar_set(ndev, "mpc", mpc);
4191 if (unlikely(err)) { 4185 if (unlikely(err)) {
4192 WL_ERR(("fail to set mpc\n")); 4186 WL_ERR("fail to set mpc\n");
4193 return; 4187 return;
4194 } 4188 }
4195 WL_DBG(("MPC : %d\n", mpc)); 4189 WL_DBG("MPC : %d\n", mpc);
4196} 4190}
4197 4191
4198static int wl_debugfs_add_netdev_params(struct wl_priv *wl) 4192static int wl_debugfs_add_netdev_params(struct wl_priv *wl)
diff --git a/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
index 770e63f0c8ef..482691be210a 100644
--- a/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
+++ b/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
@@ -54,34 +54,36 @@ struct wl_ibss;
54 54
55#define WL_DBG_LEVEL 1 /* 0 invalidates all debug messages. 55#define WL_DBG_LEVEL 1 /* 0 invalidates all debug messages.
56 default is 1 */ 56 default is 1 */
57#define WL_ERR(args) \ 57#define WL_ERR(fmt, args...) \
58do { \ 58do { \
59 if (wl_dbg_level & WL_DBG_ERR) { \ 59 if (wl_dbg_level & WL_DBG_ERR) { \
60 if (net_ratelimit()) { \ 60 if (net_ratelimit()) { \
61 printk(KERN_ERR "ERROR @%s : ", __func__); \ 61 printk(KERN_ERR "ERROR @%s : " fmt, \
62 printk args; \ 62 __func__, ##args); \
63 } \ 63 } \
64 } \ 64 } \
65} while (0) 65} while (0)
66#define WL_INFO(args) \ 66
67do { \ 67#define WL_INFO(fmt, args...) \
68 if (wl_dbg_level & WL_DBG_INFO) { \ 68do { \
69 if (net_ratelimit()) { \ 69 if (wl_dbg_level & WL_DBG_INFO) { \
70 printk(KERN_ERR "INFO @%s : ", __func__); \ 70 if (net_ratelimit()) { \
71 printk args; \ 71 printk(KERN_ERR "INFO @%s : " fmt, \
72 } \ 72 __func__, ##args); \
73 } \ 73 } \
74 } \
74} while (0) 75} while (0)
76
75#if (WL_DBG_LEVEL > 0) 77#if (WL_DBG_LEVEL > 0)
76#define WL_DBG(args) \ 78#define WL_DBG(fmt, args...) \
77do { \ 79do { \
78 if (wl_dbg_level & WL_DBG_DBG) { \ 80 if (wl_dbg_level & WL_DBG_DBG) { \
79 printk(KERN_ERR "DEBUG @%s :", __func__); \ 81 printk(KERN_ERR "DEBUG @%s :" fmt, \
80 printk args; \ 82 __func__, ##args); \
81 } \ 83 } \
82} while (0) 84} while (0)
83#else /* !(WL_DBG_LEVEL > 0) */ 85#else /* !(WL_DBG_LEVEL > 0) */
84#define WL_DBG(args) 86#define WL_DBG(fmt, args...) noprintk(fmt, ##args)
85#endif /* (WL_DBG_LEVEL > 0) */ 87#endif /* (WL_DBG_LEVEL > 0) */
86 88
87#define WL_SCAN_RETRY_MAX 3 /* used for ibss scan */ 89#define WL_SCAN_RETRY_MAX 3 /* used for ibss scan */
@@ -237,7 +239,7 @@ struct wl_ibss {
237struct wl_profile { 239struct wl_profile {
238 u32 mode; 240 u32 mode;
239 struct wlc_ssid ssid; 241 struct wlc_ssid ssid;
240 u8 bssid[ETHER_ADDR_LEN]; 242 u8 bssid[ETH_ALEN];
241 u16 beacon_interval; 243 u16 beacon_interval;
242 u8 dtim_period; 244 u8 dtim_period;
243 struct wl_security sec; 245 struct wl_security sec;
diff --git a/drivers/staging/brcm80211/brcmfmac/wl_iw.c b/drivers/staging/brcm80211/brcmfmac/wl_iw.c
index 979a494fda59..db6e68eab290 100644
--- a/drivers/staging/brcm80211/brcmfmac/wl_iw.c
+++ b/drivers/staging/brcm80211/brcmfmac/wl_iw.c
@@ -15,8 +15,9 @@
15 */ 15 */
16 16
17#include <linux/kthread.h> 17#include <linux/kthread.h>
18#include <linux/semaphore.h>
18#include <bcmdefs.h> 19#include <bcmdefs.h>
19#include <linuxver.h> 20#include <linux/netdevice.h>
20#include <osl.h> 21#include <osl.h>
21#include <wlioctl.h> 22#include <wlioctl.h>
22 23
@@ -31,20 +32,18 @@
31#include <dhd.h> 32#include <dhd.h>
32#include <dhdioctl.h> 33#include <dhdioctl.h>
33 34
34typedef void wlc_info_t;
35typedef void wl_info_t;
36typedef const struct si_pub si_t; 35typedef const struct si_pub si_t;
37#include <wlioctl.h> 36#include <wlioctl.h>
38 37
39#include <proto/ethernet.h> 38#include <proto/ethernet.h>
40#include <dngl_stats.h> 39#include <dngl_stats.h>
41#include <dhd.h> 40#include <dhd.h>
42#define WL_ERROR(x) printf x 41
43#define WL_TRACE(x) 42#define WL_ERROR(fmt, args...) printk(fmt, ##args)
44#define WL_ASSOC(x) 43#define WL_TRACE(fmt, args...) no_printk(fmt, ##args)
45#define WL_INFORM(x) 44#define WL_INFORM(fmt, args...) no_printk(fmt, ##args)
46#define WL_WSEC(x) 45#define WL_WSEC(fmt, args...) no_printk(fmt, ##args)
47#define WL_SCAN(x) 46#define WL_SCAN(fmt, args...) no_printk(fmt, ##args)
48 47
49#include <wl_iw.h> 48#include <wl_iw.h>
50 49
@@ -187,12 +186,12 @@ static int dev_wlc_ioctl(struct net_device *dev, int cmd, void *arg, int len)
187 int ret = -EINVAL; 186 int ret = -EINVAL;
188 187
189 if (!dev) { 188 if (!dev) {
190 WL_ERROR(("%s: dev is null\n", __func__)); 189 WL_ERROR("%s: dev is null\n", __func__);
191 return ret; 190 return ret;
192 } 191 }
193 192
194 WL_INFORM(("\n%s, PID:%x: send Local IOCTL -> dhd: cmd:0x%x, buf:%p, " 193 WL_INFORM("\n%s, PID:%x: send Local IOCTL -> dhd: cmd:0x%x, buf:%p, len:%d\n",
195 "len:%d ,\n", __func__, current->pid, cmd, arg, len)); 194 __func__, current->pid, cmd, arg, len);
196 195
197 if (g_onoff == G_WLAN_SET_ON) { 196 if (g_onoff == G_WLAN_SET_ON) {
198 memset(&ioc, 0, sizeof(ioc)); 197 memset(&ioc, 0, sizeof(ioc));
@@ -205,7 +204,7 @@ static int dev_wlc_ioctl(struct net_device *dev, int cmd, void *arg, int len)
205 204
206 ret = dev_open(dev); 205 ret = dev_open(dev);
207 if (ret) { 206 if (ret) {
208 WL_ERROR(("%s: Error dev_open: %d\n", __func__, ret)); 207 WL_ERROR("%s: Error dev_open: %d\n", __func__, ret);
209 return ret; 208 return ret;
210 } 209 }
211 210
@@ -214,7 +213,7 @@ static int dev_wlc_ioctl(struct net_device *dev, int cmd, void *arg, int len)
214 ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE); 213 ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
215 set_fs(fs); 214 set_fs(fs);
216 } else { 215 } else {
217 WL_TRACE(("%s: call after driver stop : ignored\n", __func__)); 216 WL_TRACE("%s: call after driver stop : ignored\n", __func__);
218 } 217 }
219 return ret; 218 return ret;
220} 219}
@@ -335,7 +334,7 @@ wl_iw_config_commit(struct net_device *dev,
335 int error; 334 int error;
336 struct sockaddr bssid; 335 struct sockaddr bssid;
337 336
338 WL_TRACE(("%s: SIOCSIWCOMMIT\n", dev->name)); 337 WL_TRACE("%s: SIOCSIWCOMMIT\n", dev->name);
339 338
340 error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid)); 339 error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid));
341 if (error) 340 if (error)
@@ -346,11 +345,11 @@ wl_iw_config_commit(struct net_device *dev,
346 if (!ssid.SSID_len) 345 if (!ssid.SSID_len)
347 return 0; 346 return 0;
348 347
349 bzero(&bssid, sizeof(struct sockaddr)); 348 memset(&bssid, 0, sizeof(struct sockaddr));
350 error = dev_wlc_ioctl(dev, WLC_REASSOC, &bssid, ETHER_ADDR_LEN); 349 error = dev_wlc_ioctl(dev, WLC_REASSOC, &bssid, ETH_ALEN);
351 if (error) { 350 if (error) {
352 WL_ERROR(("%s: WLC_REASSOC to %s failed \n", __func__, 351 WL_ERROR("%s: WLC_REASSOC to %s failed\n",
353 ssid.SSID)); 352 __func__, ssid.SSID);
354 return error; 353 return error;
355 } 354 }
356 355
@@ -361,7 +360,7 @@ static int
361wl_iw_get_name(struct net_device *dev, 360wl_iw_get_name(struct net_device *dev,
362 struct iw_request_info *info, char *cwrq, char *extra) 361 struct iw_request_info *info, char *cwrq, char *extra)
363{ 362{
364 WL_TRACE(("%s: SIOCGIWNAME\n", dev->name)); 363 WL_TRACE("%s: SIOCGIWNAME\n", dev->name);
365 364
366 strcpy(cwrq, "IEEE 802.11-DS"); 365 strcpy(cwrq, "IEEE 802.11-DS");
367 366
@@ -375,7 +374,7 @@ wl_iw_set_freq(struct net_device *dev,
375 int error, chan; 374 int error, chan;
376 uint sf = 0; 375 uint sf = 0;
377 376
378 WL_TRACE(("\n %s %s: SIOCSIWFREQ\n", __func__, dev->name)); 377 WL_TRACE("\n %s %s: SIOCSIWFREQ\n", __func__, dev->name);
379 378
380 if (fwrq->e == 0 && fwrq->m < MAXCHANNEL) { 379 if (fwrq->e == 0 && fwrq->m < MAXCHANNEL) {
381 chan = fwrq->m; 380 chan = fwrq->m;
@@ -410,7 +409,7 @@ wl_iw_get_freq(struct net_device *dev,
410 channel_info_t ci; 409 channel_info_t ci;
411 int error; 410 int error;
412 411
413 WL_TRACE(("%s: SIOCGIWFREQ\n", dev->name)); 412 WL_TRACE("%s: SIOCGIWFREQ\n", dev->name);
414 413
415 error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci)); 414 error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci));
416 if (error) 415 if (error)
@@ -427,7 +426,7 @@ wl_iw_set_mode(struct net_device *dev,
427{ 426{
428 int infra = 0, ap = 0, error = 0; 427 int infra = 0, ap = 0, error = 0;
429 428
430 WL_TRACE(("%s: SIOCSIWMODE\n", dev->name)); 429 WL_TRACE("%s: SIOCSIWMODE\n", dev->name);
431 430
432 switch (*uwrq) { 431 switch (*uwrq) {
433 case IW_MODE_MASTER: 432 case IW_MODE_MASTER:
@@ -462,7 +461,7 @@ wl_iw_get_mode(struct net_device *dev,
462{ 461{
463 int error, infra = 0, ap = 0; 462 int error, infra = 0, ap = 0;
464 463
465 WL_TRACE(("%s: SIOCGIWMODE\n", dev->name)); 464 WL_TRACE("%s: SIOCGIWMODE\n", dev->name);
466 465
467 error = dev_wlc_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra)); 466 error = dev_wlc_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra));
468 if (error) 467 if (error)
@@ -501,14 +500,14 @@ wl_iw_get_range(struct net_device *dev,
501 {30, 60, 90, 120, 180, 240, 270, 300} 500 {30, 60, 90, 120, 180, 240, 270, 300}
502 }; 501 };
503 502
504 WL_TRACE(("%s: SIOCGIWRANGE\n", dev->name)); 503 WL_TRACE("%s: SIOCGIWRANGE\n", dev->name);
505 504
506 if (!extra) 505 if (!extra)
507 return -EINVAL; 506 return -EINVAL;
508 507
509 channels = kmalloc((MAXCHANNEL + 1) * 4, GFP_KERNEL); 508 channels = kmalloc((MAXCHANNEL + 1) * 4, GFP_KERNEL);
510 if (!channels) { 509 if (!channels) {
511 WL_ERROR(("Could not alloc channels\n")); 510 WL_ERROR("Could not alloc channels\n");
512 return -ENOMEM; 511 return -ENOMEM;
513 } 512 }
514 list = (wl_u32_list_t *) channels; 513 list = (wl_u32_list_t *) channels;
@@ -684,14 +683,14 @@ wl_iw_set_spy(struct net_device *dev,
684 struct sockaddr *addr = (struct sockaddr *)extra; 683 struct sockaddr *addr = (struct sockaddr *)extra;
685 int i; 684 int i;
686 685
687 WL_TRACE(("%s: SIOCSIWSPY\n", dev->name)); 686 WL_TRACE("%s: SIOCSIWSPY\n", dev->name);
688 687
689 if (!extra) 688 if (!extra)
690 return -EINVAL; 689 return -EINVAL;
691 690
692 iw->spy_num = min_t(int, ARRAY_SIZE(iw->spy_addr), dwrq->length); 691 iw->spy_num = min_t(int, ARRAY_SIZE(iw->spy_addr), dwrq->length);
693 for (i = 0; i < iw->spy_num; i++) 692 for (i = 0; i < iw->spy_num; i++)
694 memcpy(&iw->spy_addr[i], addr[i].sa_data, ETHER_ADDR_LEN); 693 memcpy(&iw->spy_addr[i], addr[i].sa_data, ETH_ALEN);
695 memset(iw->spy_qual, 0, sizeof(iw->spy_qual)); 694 memset(iw->spy_qual, 0, sizeof(iw->spy_qual));
696 695
697 return 0; 696 return 0;
@@ -706,14 +705,14 @@ wl_iw_get_spy(struct net_device *dev,
706 struct iw_quality *qual = (struct iw_quality *)&addr[iw->spy_num]; 705 struct iw_quality *qual = (struct iw_quality *)&addr[iw->spy_num];
707 int i; 706 int i;
708 707
709 WL_TRACE(("%s: SIOCGIWSPY\n", dev->name)); 708 WL_TRACE("%s: SIOCGIWSPY\n", dev->name);
710 709
711 if (!extra) 710 if (!extra)
712 return -EINVAL; 711 return -EINVAL;
713 712
714 dwrq->length = iw->spy_num; 713 dwrq->length = iw->spy_num;
715 for (i = 0; i < iw->spy_num; i++) { 714 for (i = 0; i < iw->spy_num; i++) {
716 memcpy(addr[i].sa_data, &iw->spy_addr[i], ETHER_ADDR_LEN); 715 memcpy(addr[i].sa_data, &iw->spy_addr[i], ETH_ALEN);
717 addr[i].sa_family = AF_UNIX; 716 addr[i].sa_family = AF_UNIX;
718 memcpy(&qual[i], &iw->spy_qual[i], sizeof(struct iw_quality)); 717 memcpy(&qual[i], &iw->spy_qual[i], sizeof(struct iw_quality));
719 iw->spy_qual[i].updated = 0; 718 iw->spy_qual[i].updated = 0;
@@ -751,8 +750,8 @@ wl_iw_ch_to_chanspec(int ch, wl_join_params_t *join_params,
751 join_params->params.chanspec_num = 750 join_params->params.chanspec_num =
752 htod32(join_params->params.chanspec_num); 751 htod32(join_params->params.chanspec_num);
753 752
754 WL_TRACE(("%s join_params->params.chanspec_list[0]= %X\n", 753 WL_TRACE("%s join_params->params.chanspec_list[0]= %X\n",
755 __func__, join_params->params.chanspec_list[0])); 754 __func__, join_params->params.chanspec_list[0]);
756 } 755 }
757 return 1; 756 return 1;
758} 757}
@@ -765,16 +764,17 @@ wl_iw_set_wap(struct net_device *dev,
765 wl_join_params_t join_params; 764 wl_join_params_t join_params;
766 int join_params_size; 765 int join_params_size;
767 766
768 WL_TRACE(("%s: SIOCSIWAP\n", dev->name)); 767 WL_TRACE("%s: SIOCSIWAP\n", dev->name);
769 768
770 if (awrq->sa_family != ARPHRD_ETHER) { 769 if (awrq->sa_family != ARPHRD_ETHER) {
771 WL_ERROR(("Invalid Header...sa_family\n")); 770 WL_ERROR("Invalid Header...sa_family\n");
772 return -EINVAL; 771 return -EINVAL;
773 } 772 }
774 773
775 if (ETHER_ISBCAST(awrq->sa_data) || ETHER_ISNULLADDR(awrq->sa_data)) { 774 if (is_broadcast_ether_addr(awrq->sa_data) ||
775 is_zero_ether_addr(awrq->sa_data)) {
776 scb_val_t scbval; 776 scb_val_t scbval;
777 bzero(&scbval, sizeof(scb_val_t)); 777 memset(&scbval, 0, sizeof(scb_val_t));
778 (void)dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, 778 (void)dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval,
779 sizeof(scb_val_t)); 779 sizeof(scb_val_t));
780 return 0; 780 return 0;
@@ -785,23 +785,23 @@ wl_iw_set_wap(struct net_device *dev,
785 785
786 memcpy(join_params.ssid.SSID, g_ssid.SSID, g_ssid.SSID_len); 786 memcpy(join_params.ssid.SSID, g_ssid.SSID, g_ssid.SSID_len);
787 join_params.ssid.SSID_len = htod32(g_ssid.SSID_len); 787 join_params.ssid.SSID_len = htod32(g_ssid.SSID_len);
788 memcpy(&join_params.params.bssid, awrq->sa_data, ETHER_ADDR_LEN); 788 memcpy(&join_params.params.bssid, awrq->sa_data, ETH_ALEN);
789 789
790 WL_TRACE(("%s target_channel=%d\n", __func__, 790 WL_TRACE("%s target_channel=%d\n",
791 g_wl_iw_params.target_channel)); 791 __func__, g_wl_iw_params.target_channel);
792 wl_iw_ch_to_chanspec(g_wl_iw_params.target_channel, &join_params, 792 wl_iw_ch_to_chanspec(g_wl_iw_params.target_channel, &join_params,
793 &join_params_size); 793 &join_params_size);
794 794
795 error = dev_wlc_ioctl(dev, WLC_SET_SSID, &join_params, 795 error = dev_wlc_ioctl(dev, WLC_SET_SSID, &join_params,
796 join_params_size); 796 join_params_size);
797 if (error) { 797 if (error) {
798 WL_ERROR(("%s Invalid ioctl data=%d\n", __func__, error)); 798 WL_ERROR("%s Invalid ioctl data=%d\n", __func__, error);
799 } 799 }
800 800
801 if (g_ssid.SSID_len) { 801 if (g_ssid.SSID_len) {
802 WL_TRACE(("%s: join SSID=%s BSSID=%pM ch=%d\n", 802 WL_TRACE("%s: join SSID=%s BSSID=%pM ch=%d\n",
803 __func__, g_ssid.SSID, awrq->sa_data, 803 __func__, g_ssid.SSID, awrq->sa_data,
804 g_wl_iw_params.target_channel)); 804 g_wl_iw_params.target_channel);
805 } 805 }
806 806
807 memset(&g_ssid, 0, sizeof(g_ssid)); 807 memset(&g_ssid, 0, sizeof(g_ssid));
@@ -812,12 +812,12 @@ static int
812wl_iw_get_wap(struct net_device *dev, 812wl_iw_get_wap(struct net_device *dev,
813 struct iw_request_info *info, struct sockaddr *awrq, char *extra) 813 struct iw_request_info *info, struct sockaddr *awrq, char *extra)
814{ 814{
815 WL_TRACE(("%s: SIOCGIWAP\n", dev->name)); 815 WL_TRACE("%s: SIOCGIWAP\n", dev->name);
816 816
817 awrq->sa_family = ARPHRD_ETHER; 817 awrq->sa_family = ARPHRD_ETHER;
818 memset(awrq->sa_data, 0, ETHER_ADDR_LEN); 818 memset(awrq->sa_data, 0, ETH_ALEN);
819 819
820 (void)dev_wlc_ioctl(dev, WLC_GET_BSSID, awrq->sa_data, ETHER_ADDR_LEN); 820 (void)dev_wlc_ioctl(dev, WLC_GET_BSSID, awrq->sa_data, ETH_ALEN);
821 821
822 return 0; 822 return 0;
823} 823}
@@ -831,16 +831,16 @@ wl_iw_mlme(struct net_device *dev,
831 scb_val_t scbval; 831 scb_val_t scbval;
832 int error = -EINVAL; 832 int error = -EINVAL;
833 833
834 WL_TRACE(("%s: SIOCSIWMLME DISASSOC/DEAUTH\n", dev->name)); 834 WL_TRACE("%s: SIOCSIWMLME DISASSOC/DEAUTH\n", dev->name);
835 835
836 mlme = (struct iw_mlme *)extra; 836 mlme = (struct iw_mlme *)extra;
837 if (mlme == NULL) { 837 if (mlme == NULL) {
838 WL_ERROR(("Invalid ioctl data.\n")); 838 WL_ERROR("Invalid ioctl data\n");
839 return error; 839 return error;
840 } 840 }
841 841
842 scbval.val = mlme->reason_code; 842 scbval.val = mlme->reason_code;
843 bcopy(&mlme->addr.sa_data, &scbval.ea, ETHER_ADDR_LEN); 843 bcopy(&mlme->addr.sa_data, &scbval.ea, ETH_ALEN);
844 844
845 if (mlme->cmd == IW_MLME_DISASSOC) { 845 if (mlme->cmd == IW_MLME_DISASSOC) {
846 scbval.val = htod32(scbval.val); 846 scbval.val = htod32(scbval.val);
@@ -853,7 +853,7 @@ wl_iw_mlme(struct net_device *dev,
853 dev_wlc_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, 853 dev_wlc_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON,
854 &scbval, sizeof(scb_val_t)); 854 &scbval, sizeof(scb_val_t));
855 } else { 855 } else {
856 WL_ERROR(("Invalid ioctl data.\n")); 856 WL_ERROR("Invalid ioctl data\n");
857 return error; 857 return error;
858 } 858 }
859 859
@@ -874,7 +874,7 @@ wl_iw_get_aplist(struct net_device *dev,
874 int error, i; 874 int error, i;
875 uint buflen = dwrq->length; 875 uint buflen = dwrq->length;
876 876
877 WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name)); 877 WL_TRACE("%s: SIOCGIWAPLIST\n", dev->name);
878 878
879 if (!extra) 879 if (!extra)
880 return -EINVAL; 880 return -EINVAL;
@@ -886,7 +886,7 @@ wl_iw_get_aplist(struct net_device *dev,
886 list->buflen = htod32(buflen); 886 list->buflen = htod32(buflen);
887 error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen); 887 error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen);
888 if (error) { 888 if (error) {
889 WL_ERROR(("%d: Scan results error %d\n", __LINE__, error)); 889 WL_ERROR("%d: Scan results error %d\n", __LINE__, error);
890 kfree(list); 890 kfree(list);
891 return error; 891 return error;
892 } 892 }
@@ -894,8 +894,8 @@ wl_iw_get_aplist(struct net_device *dev,
894 list->version = dtoh32(list->version); 894 list->version = dtoh32(list->version);
895 list->count = dtoh32(list->count); 895 list->count = dtoh32(list->count);
896 if (list->version != WL_BSS_INFO_VERSION) { 896 if (list->version != WL_BSS_INFO_VERSION) {
897 WL_ERROR(("%s : list->version %d != WL_BSS_INFO_VERSION\n", 897 WL_ERROR("%s : list->version %d != WL_BSS_INFO_VERSION\n",
898 __func__, list->version)); 898 __func__, list->version);
899 kfree(list); 899 kfree(list);
900 return -EINVAL; 900 return -EINVAL;
901 } 901 }
@@ -911,7 +911,7 @@ wl_iw_get_aplist(struct net_device *dev,
911 if (!(dtoh16(bi->capability) & DOT11_CAP_ESS)) 911 if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
912 continue; 912 continue;
913 913
914 memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN); 914 memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETH_ALEN);
915 addr[dwrq->length].sa_family = ARPHRD_ETHER; 915 addr[dwrq->length].sa_family = ARPHRD_ETHER;
916 qual[dwrq->length].qual = rssi_to_qual(dtoh16(bi->RSSI)); 916 qual[dwrq->length].qual = rssi_to_qual(dtoh16(bi->RSSI));
917 qual[dwrq->length].level = 0x100 + dtoh16(bi->RSSI); 917 qual[dwrq->length].level = 0x100 + dtoh16(bi->RSSI);
@@ -952,13 +952,13 @@ wl_iw_iscan_get_aplist(struct net_device *dev,
952 wl_bss_info_t *bi = NULL; 952 wl_bss_info_t *bi = NULL;
953 int i; 953 int i;
954 954
955 WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name)); 955 WL_TRACE("%s: SIOCGIWAPLIST\n", dev->name);
956 956
957 if (!extra) 957 if (!extra)
958 return -EINVAL; 958 return -EINVAL;
959 959
960 if ((!iscan) || (!iscan->sysioc_tsk)) { 960 if ((!iscan) || (!iscan->sysioc_tsk)) {
961 WL_ERROR(("%s error\n", __func__)); 961 WL_ERROR("%s error\n", __func__);
962 return 0; 962 return 0;
963 } 963 }
964 964
@@ -966,9 +966,8 @@ wl_iw_iscan_get_aplist(struct net_device *dev,
966 while (buf) { 966 while (buf) {
967 list = &((wl_iscan_results_t *) buf->iscan_buf)->results; 967 list = &((wl_iscan_results_t *) buf->iscan_buf)->results;
968 if (list->version != WL_BSS_INFO_VERSION) { 968 if (list->version != WL_BSS_INFO_VERSION) {
969 WL_ERROR(("%s : list->version %d != " 969 WL_ERROR("%s : list->version %d != WL_BSS_INFO_VERSION\n",
970 "WL_BSS_INFO_VERSION\n", 970 __func__, list->version);
971 __func__, list->version));
972 return -EINVAL; 971 return -EINVAL;
973 } 972 }
974 973
@@ -985,7 +984,7 @@ wl_iw_iscan_get_aplist(struct net_device *dev,
985 continue; 984 continue;
986 985
987 memcpy(addr[dwrq->length].sa_data, &bi->BSSID, 986 memcpy(addr[dwrq->length].sa_data, &bi->BSSID,
988 ETHER_ADDR_LEN); 987 ETH_ALEN);
989 addr[dwrq->length].sa_family = ARPHRD_ETHER; 988 addr[dwrq->length].sa_family = ARPHRD_ETHER;
990 qual[dwrq->length].qual = 989 qual[dwrq->length].qual =
991 rssi_to_qual(dtoh16(bi->RSSI)); 990 rssi_to_qual(dtoh16(bi->RSSI));
@@ -1016,7 +1015,7 @@ static int wl_iw_iscan_prep(wl_scan_params_t *params, wlc_ssid_t *ssid)
1016{ 1015{
1017 int err = 0; 1016 int err = 0;
1018 1017
1019 memcpy(&params->bssid, &ether_bcast, ETHER_ADDR_LEN); 1018 memcpy(&params->bssid, &ether_bcast, ETH_ALEN);
1020 params->bss_type = DOT11_BSSTYPE_ANY; 1019 params->bss_type = DOT11_BSSTYPE_ANY;
1021 params->scan_type = 0; 1020 params->scan_type = 0;
1022 params->nprobes = -1; 1021 params->nprobes = -1;
@@ -1043,15 +1042,15 @@ static int wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, u16 action)
1043 iscan->iscan_ex_params_p->action = htod16(action); 1042 iscan->iscan_ex_params_p->action = htod16(action);
1044 iscan->iscan_ex_params_p->scan_duration = htod16(0); 1043 iscan->iscan_ex_params_p->scan_duration = htod16(0);
1045 1044
1046 WL_SCAN(("%s : nprobes=%d\n", __func__, 1045 WL_SCAN("%s : nprobes=%d\n",
1047 iscan->iscan_ex_params_p->params.nprobes)); 1046 __func__, iscan->iscan_ex_params_p->params.nprobes);
1048 WL_SCAN(("active_time=%d\n", 1047 WL_SCAN("active_time=%d\n",
1049 iscan->iscan_ex_params_p->params.active_time)); 1048 iscan->iscan_ex_params_p->params.active_time);
1050 WL_SCAN(("passive_time=%d\n", 1049 WL_SCAN("passive_time=%d\n",
1051 iscan->iscan_ex_params_p->params.passive_time)); 1050 iscan->iscan_ex_params_p->params.passive_time);
1052 WL_SCAN(("home_time=%d\n", iscan->iscan_ex_params_p->params.home_time)); 1051 WL_SCAN("home_time=%d\n", iscan->iscan_ex_params_p->params.home_time);
1053 WL_SCAN(("scan_type=%d\n", iscan->iscan_ex_params_p->params.scan_type)); 1052 WL_SCAN("scan_type=%d\n", iscan->iscan_ex_params_p->params.scan_type);
1054 WL_SCAN(("bss_type=%d\n", iscan->iscan_ex_params_p->params.bss_type)); 1053 WL_SCAN("bss_type=%d\n", iscan->iscan_ex_params_p->params.bss_type);
1055 1054
1056 (void)dev_iw_iovar_setbuf(iscan->dev, "iscan", iscan->iscan_ex_params_p, 1055 (void)dev_iw_iovar_setbuf(iscan->dev, "iscan", iscan->iscan_ex_params_p,
1057 iscan->iscan_ex_param_size, iscan->ioctlbuf, 1056 iscan->iscan_ex_param_size, iscan->ioctlbuf,
@@ -1066,7 +1065,7 @@ static void wl_iw_timerfunc(unsigned long data)
1066 if (iscan) { 1065 if (iscan) {
1067 iscan->timer_on = 0; 1066 iscan->timer_on = 0;
1068 if (iscan->iscan_state != ISCAN_STATE_IDLE) { 1067 if (iscan->iscan_state != ISCAN_STATE_IDLE) {
1069 WL_TRACE(("timer trigger\n")); 1068 WL_TRACE("timer trigger\n");
1070 up(&iscan->sysioc_sem); 1069 up(&iscan->sysioc_sem);
1071 } 1070 }
1072 } 1071 }
@@ -1101,8 +1100,8 @@ static u32 wl_iw_iscan_get(iscan_info_t *iscan)
1101 } else { 1100 } else {
1102 buf = kmalloc(sizeof(iscan_buf_t), GFP_KERNEL); 1101 buf = kmalloc(sizeof(iscan_buf_t), GFP_KERNEL);
1103 if (!buf) { 1102 if (!buf) {
1104 WL_ERROR(("%s can't alloc iscan_buf_t : going to abort " 1103 WL_ERROR("%s can't alloc iscan_buf_t : going to abort current iscan\n",
1105 "currect iscan\n", __func__)); 1104 __func__);
1106 MUTEX_UNLOCK_WL_SCAN_SET(); 1105 MUTEX_UNLOCK_WL_SCAN_SET();
1107 return WL_SCAN_RESULTS_NO_MEM; 1106 return WL_SCAN_RESULTS_NO_MEM;
1108 } 1107 }
@@ -1135,11 +1134,11 @@ static u32 wl_iw_iscan_get(iscan_info_t *iscan)
1135 results->buflen = dtoh32(results->buflen); 1134 results->buflen = dtoh32(results->buflen);
1136 results->version = dtoh32(results->version); 1135 results->version = dtoh32(results->version);
1137 results->count = dtoh32(results->count); 1136 results->count = dtoh32(results->count);
1138 WL_TRACE(("results->count = %d\n", results->count)); 1137 WL_TRACE("results->count = %d\n", results->count);
1139 WL_TRACE(("results->buflen = %d\n", results->buflen)); 1138 WL_TRACE("results->buflen = %d\n", results->buflen);
1140 status = dtoh32(list_buf->status); 1139 status = dtoh32(list_buf->status);
1141 } else { 1140 } else {
1142 WL_ERROR(("%s returns error %d\n", __func__, res)); 1141 WL_ERROR("%s returns error %d\n", __func__, res);
1143 status = WL_SCAN_RESULTS_NO_MEM; 1142 status = WL_SCAN_RESULTS_NO_MEM;
1144 } 1143 }
1145 MUTEX_UNLOCK_WL_SCAN_SET(); 1144 MUTEX_UNLOCK_WL_SCAN_SET();
@@ -1148,8 +1147,8 @@ static u32 wl_iw_iscan_get(iscan_info_t *iscan)
1148 1147
1149static void wl_iw_force_specific_scan(iscan_info_t *iscan) 1148static void wl_iw_force_specific_scan(iscan_info_t *iscan)
1150{ 1149{
1151 WL_TRACE(("%s force Specific SCAN for %s\n", __func__, 1150 WL_TRACE("%s force Specific SCAN for %s\n",
1152 g_specific_ssid.SSID)); 1151 __func__, g_specific_ssid.SSID);
1153 rtnl_lock(); 1152 rtnl_lock();
1154 1153
1155 (void)dev_wlc_ioctl(iscan->dev, WLC_SCAN, &g_specific_ssid, 1154 (void)dev_wlc_ioctl(iscan->dev, WLC_SCAN, &g_specific_ssid,
@@ -1166,7 +1165,7 @@ static void wl_iw_send_scan_complete(iscan_info_t *iscan)
1166 memset(&wrqu, 0, sizeof(wrqu)); 1165 memset(&wrqu, 0, sizeof(wrqu));
1167 1166
1168 wireless_send_event(iscan->dev, SIOCGIWSCAN, &wrqu, NULL); 1167 wireless_send_event(iscan->dev, SIOCGIWSCAN, &wrqu, NULL);
1169 WL_TRACE(("Send Event ISCAN complete\n")); 1168 WL_TRACE("Send Event ISCAN complete\n");
1170#endif 1169#endif
1171} 1170}
1172 1171
@@ -1190,8 +1189,8 @@ static int _iscan_sysioc_thread(void *data)
1190 status = wl_iw_iscan_get(iscan); 1189 status = wl_iw_iscan_get(iscan);
1191 rtnl_unlock(); 1190 rtnl_unlock();
1192 if (g_scan_specified_ssid && (iscan_pass_abort == true)) { 1191 if (g_scan_specified_ssid && (iscan_pass_abort == true)) {
1193 WL_TRACE(("%s Get results from specific scan " 1192 WL_TRACE("%s Get results from specific scan status = %d\n",
1194 "status = %d\n", __func__, status)); 1193 __func__, status);
1195 wl_iw_send_scan_complete(iscan); 1194 wl_iw_send_scan_complete(iscan);
1196 iscan_pass_abort = false; 1195 iscan_pass_abort = false;
1197 status = -1; 1196 status = -1;
@@ -1199,7 +1198,7 @@ static int _iscan_sysioc_thread(void *data)
1199 1198
1200 switch (status) { 1199 switch (status) {
1201 case WL_SCAN_RESULTS_PARTIAL: 1200 case WL_SCAN_RESULTS_PARTIAL:
1202 WL_TRACE(("iscanresults incomplete\n")); 1201 WL_TRACE("iscanresults incomplete\n");
1203 rtnl_lock(); 1202 rtnl_lock();
1204 wl_iw_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE); 1203 wl_iw_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE);
1205 rtnl_unlock(); 1204 rtnl_unlock();
@@ -1208,18 +1207,18 @@ static int _iscan_sysioc_thread(void *data)
1208 iscan->timer_on = 1; 1207 iscan->timer_on = 1;
1209 break; 1208 break;
1210 case WL_SCAN_RESULTS_SUCCESS: 1209 case WL_SCAN_RESULTS_SUCCESS:
1211 WL_TRACE(("iscanresults complete\n")); 1210 WL_TRACE("iscanresults complete\n");
1212 iscan->iscan_state = ISCAN_STATE_IDLE; 1211 iscan->iscan_state = ISCAN_STATE_IDLE;
1213 wl_iw_send_scan_complete(iscan); 1212 wl_iw_send_scan_complete(iscan);
1214 break; 1213 break;
1215 case WL_SCAN_RESULTS_PENDING: 1214 case WL_SCAN_RESULTS_PENDING:
1216 WL_TRACE(("iscanresults pending\n")); 1215 WL_TRACE("iscanresults pending\n");
1217 mod_timer(&iscan->timer, 1216 mod_timer(&iscan->timer,
1218 jiffies + iscan->timer_ms * HZ / 1000); 1217 jiffies + iscan->timer_ms * HZ / 1000);
1219 iscan->timer_on = 1; 1218 iscan->timer_on = 1;
1220 break; 1219 break;
1221 case WL_SCAN_RESULTS_ABORTED: 1220 case WL_SCAN_RESULTS_ABORTED:
1222 WL_TRACE(("iscanresults aborted\n")); 1221 WL_TRACE("iscanresults aborted\n");
1223 iscan->iscan_state = ISCAN_STATE_IDLE; 1222 iscan->iscan_state = ISCAN_STATE_IDLE;
1224 if (g_scan_specified_ssid == 0) 1223 if (g_scan_specified_ssid == 0)
1225 wl_iw_send_scan_complete(iscan); 1224 wl_iw_send_scan_complete(iscan);
@@ -1229,12 +1228,12 @@ static int _iscan_sysioc_thread(void *data)
1229 } 1228 }
1230 break; 1229 break;
1231 case WL_SCAN_RESULTS_NO_MEM: 1230 case WL_SCAN_RESULTS_NO_MEM:
1232 WL_TRACE(("iscanresults can't alloc memory: skip\n")); 1231 WL_TRACE("iscanresults can't alloc memory: skip\n");
1233 iscan->iscan_state = ISCAN_STATE_IDLE; 1232 iscan->iscan_state = ISCAN_STATE_IDLE;
1234 break; 1233 break;
1235 default: 1234 default:
1236 WL_TRACE(("iscanresults returned unknown status %d\n", 1235 WL_TRACE("iscanresults returned unknown status %d\n",
1237 status)); 1236 status);
1238 break; 1237 break;
1239 } 1238 }
1240 } 1239 }
@@ -1253,11 +1252,11 @@ wl_iw_set_scan(struct net_device *dev,
1253 union iwreq_data *wrqu, char *extra) 1252 union iwreq_data *wrqu, char *extra)
1254{ 1253{
1255 int error; 1254 int error;
1256 WL_TRACE(("\n:%s dev:%s: SIOCSIWSCAN : SCAN\n", __func__, dev->name)); 1255 WL_TRACE("\n:%s dev:%s: SIOCSIWSCAN : SCAN\n", __func__, dev->name);
1257 1256
1258 g_set_essid_before_scan = false; 1257 g_set_essid_before_scan = false;
1259#if defined(CSCAN) 1258#if defined(CSCAN)
1260 WL_ERROR(("%s: Scan from SIOCGIWSCAN not supported\n", __func__)); 1259 WL_ERROR("%s: Scan from SIOCGIWSCAN not supported\n", __func__);
1261 return -EINVAL; 1260 return -EINVAL;
1262#endif 1261#endif
1263 1262
@@ -1274,9 +1273,8 @@ wl_iw_set_scan(struct net_device *dev,
1274 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { 1273 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1275 struct iw_scan_req *req = (struct iw_scan_req *)extra; 1274 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1276 if (g_scan_specified_ssid) { 1275 if (g_scan_specified_ssid) {
1277 WL_TRACE(("%s Specific SCAN is not done ignore " 1276 WL_TRACE("%s Specific SCAN is not done ignore scan for = %s\n",
1278 "scan for = %s\n", 1277 __func__, req->essid);
1279 __func__, req->essid));
1280 return -EBUSY; 1278 return -EBUSY;
1281 } else { 1279 } else {
1282 g_specific_ssid.SSID_len = min_t(size_t, 1280 g_specific_ssid.SSID_len = min_t(size_t,
@@ -1287,9 +1285,9 @@ wl_iw_set_scan(struct net_device *dev,
1287 g_specific_ssid.SSID_len = 1285 g_specific_ssid.SSID_len =
1288 htod32(g_specific_ssid.SSID_len); 1286 htod32(g_specific_ssid.SSID_len);
1289 g_scan_specified_ssid = 1; 1287 g_scan_specified_ssid = 1;
1290 WL_TRACE(("### Specific scan ssid=%s len=%d\n", 1288 WL_TRACE("### Specific scan ssid=%s len=%d\n",
1291 g_specific_ssid.SSID, 1289 g_specific_ssid.SSID,
1292 g_specific_ssid.SSID_len)); 1290 g_specific_ssid.SSID_len);
1293 } 1291 }
1294 } 1292 }
1295 } 1293 }
@@ -1297,8 +1295,8 @@ wl_iw_set_scan(struct net_device *dev,
1297 error = dev_wlc_ioctl(dev, WLC_SCAN, &g_specific_ssid, 1295 error = dev_wlc_ioctl(dev, WLC_SCAN, &g_specific_ssid,
1298 sizeof(g_specific_ssid)); 1296 sizeof(g_specific_ssid));
1299 if (error) { 1297 if (error) {
1300 WL_TRACE(("#### Set SCAN for %s failed with %d\n", 1298 WL_TRACE("#### Set SCAN for %s failed with %d\n",
1301 g_specific_ssid.SSID, error)); 1299 g_specific_ssid.SSID, error);
1302 g_scan_specified_ssid = 0; 1300 g_scan_specified_ssid = 0;
1303 return -EBUSY; 1301 return -EBUSY;
1304 } 1302 }
@@ -1317,7 +1315,7 @@ int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag)
1317 1315
1318 wl_iw_set_event_mask(dev); 1316 wl_iw_set_event_mask(dev);
1319 1317
1320 WL_TRACE(("+++: Set Broadcast ISCAN\n")); 1318 WL_TRACE("+++: Set Broadcast ISCAN\n");
1321 memset(&ssid, 0, sizeof(ssid)); 1319 memset(&ssid, 0, sizeof(ssid));
1322 1320
1323 iscan->list_cur = iscan->list_hdr; 1321 iscan->list_cur = iscan->list_hdr;
@@ -1346,20 +1344,20 @@ wl_iw_iscan_set_scan(struct net_device *dev,
1346 wlc_ssid_t ssid; 1344 wlc_ssid_t ssid;
1347 iscan_info_t *iscan = g_iscan; 1345 iscan_info_t *iscan = g_iscan;
1348 1346
1349 WL_TRACE(("%s: SIOCSIWSCAN : ISCAN\n", dev->name)); 1347 WL_TRACE("%s: SIOCSIWSCAN : ISCAN\n", dev->name);
1350 1348
1351#if defined(CSCAN) 1349#if defined(CSCAN)
1352 WL_ERROR(("%s: Scan from SIOCGIWSCAN not supported\n", __func__)); 1350 WL_ERROR("%s: Scan from SIOCGIWSCAN not supported\n", __func__);
1353 return -EINVAL; 1351 return -EINVAL;
1354#endif 1352#endif
1355 1353
1356 if (g_onoff == G_WLAN_SET_OFF) { 1354 if (g_onoff == G_WLAN_SET_OFF) {
1357 WL_TRACE(("%s: driver is not up yet after START\n", __func__)); 1355 WL_TRACE("%s: driver is not up yet after START\n", __func__);
1358 return 0; 1356 return 0;
1359 } 1357 }
1360#ifdef PNO_SUPPORT 1358#ifdef PNO_SUPPORT
1361 if (dhd_dev_get_pno_status(dev)) { 1359 if (dhd_dev_get_pno_status(dev)) {
1362 WL_ERROR(("%s: Scan called when PNO is active\n", __func__)); 1360 WL_ERROR("%s: Scan called when PNO is active\n", __func__);
1363 } 1361 }
1364#endif 1362#endif
1365 1363
@@ -1367,8 +1365,8 @@ wl_iw_iscan_set_scan(struct net_device *dev,
1367 return wl_iw_set_scan(dev, info, wrqu, extra); 1365 return wl_iw_set_scan(dev, info, wrqu, extra);
1368 1366
1369 if (g_scan_specified_ssid) { 1367 if (g_scan_specified_ssid) {
1370 WL_TRACE(("%s Specific SCAN already running ignoring BC scan\n", 1368 WL_TRACE("%s Specific SCAN already running ignoring BC scan\n",
1371 __func__)); 1369 __func__);
1372 return EBUSY; 1370 return EBUSY;
1373 } 1371 }
1374 1372
@@ -1386,8 +1384,8 @@ wl_iw_iscan_set_scan(struct net_device *dev,
1386 g_scan_specified_ssid = 0; 1384 g_scan_specified_ssid = 0;
1387 1385
1388 if (iscan->iscan_state == ISCAN_STATE_SCANING) { 1386 if (iscan->iscan_state == ISCAN_STATE_SCANING) {
1389 WL_TRACE(("%s ISCAN already in progress \n", 1387 WL_TRACE("%s ISCAN already in progress\n",
1390 __func__)); 1388 __func__);
1391 return 0; 1389 return 0;
1392 } 1390 }
1393 } 1391 }
@@ -1406,7 +1404,7 @@ static bool ie_is_wpa_ie(u8 **wpaie, u8 **tlvs, int *tlvs_len)
1406 u8 *ie = *wpaie; 1404 u8 *ie = *wpaie;
1407 1405
1408 if ((ie[1] >= 6) && 1406 if ((ie[1] >= 6) &&
1409 !bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x01"), 4)) { 1407 !memcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x01"), 4)) {
1410 return true; 1408 return true;
1411 } 1409 }
1412 1410
@@ -1422,7 +1420,7 @@ static bool ie_is_wps_ie(u8 **wpsie, u8 **tlvs, int *tlvs_len)
1422 u8 *ie = *wpsie; 1420 u8 *ie = *wpsie;
1423 1421
1424 if ((ie[1] >= 4) && 1422 if ((ie[1] >= 4) &&
1425 !bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x04"), 4)) { 1423 !memcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x04"), 4)) {
1426 return true; 1424 return true;
1427 } 1425 }
1428 1426
@@ -1501,9 +1499,8 @@ wl_iw_get_scan_prep(wl_scan_results_t *list,
1501 1499
1502 for (i = 0; i < list->count && i < IW_MAX_AP; i++) { 1500 for (i = 0; i < list->count && i < IW_MAX_AP; i++) {
1503 if (list->version != WL_BSS_INFO_VERSION) { 1501 if (list->version != WL_BSS_INFO_VERSION) {
1504 WL_ERROR(("%s : list->version %d != " 1502 WL_ERROR("%s : list->version %d != WL_BSS_INFO_VERSION\n",
1505 "WL_BSS_INFO_VERSION\n", 1503 __func__, list->version);
1506 __func__, list->version));
1507 return ret; 1504 return ret;
1508 } 1505 }
1509 1506
@@ -1511,11 +1508,11 @@ wl_iw_get_scan_prep(wl_scan_results_t *list,
1511 dtoh32(bi->length)) : list-> 1508 dtoh32(bi->length)) : list->
1512 bss_info; 1509 bss_info;
1513 1510
1514 WL_TRACE(("%s : %s\n", __func__, bi->SSID)); 1511 WL_TRACE("%s : %s\n", __func__, bi->SSID);
1515 1512
1516 iwe.cmd = SIOCGIWAP; 1513 iwe.cmd = SIOCGIWAP;
1517 iwe.u.ap_addr.sa_family = ARPHRD_ETHER; 1514 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1518 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN); 1515 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETH_ALEN);
1519 event = 1516 event =
1520 IWE_STREAM_ADD_EVENT(info, event, end, &iwe, 1517 IWE_STREAM_ADD_EVENT(info, event, end, &iwe,
1521 IW_EV_ADDR_LEN); 1518 IW_EV_ADDR_LEN);
@@ -1590,11 +1587,11 @@ wl_iw_get_scan_prep(wl_scan_results_t *list,
1590 1587
1591 ret = event - extra; 1588 ret = event - extra;
1592 if (ret < 0) { 1589 if (ret < 0) {
1593 WL_ERROR(("==> Wrong size\n")); 1590 WL_ERROR("==> Wrong size\n");
1594 ret = 0; 1591 ret = 0;
1595 } 1592 }
1596 WL_TRACE(("%s: size=%d bytes prepared\n", __func__, 1593 WL_TRACE("%s: size=%d bytes prepared\n",
1597 (unsigned int)(event - extra))); 1594 __func__, (unsigned int)(event - extra));
1598 return (uint)ret; 1595 return (uint)ret;
1599} 1596}
1600 1597
@@ -1614,10 +1611,10 @@ wl_iw_get_scan(struct net_device *dev,
1614 iscan_buf_t *p_buf; 1611 iscan_buf_t *p_buf;
1615#endif 1612#endif
1616 1613
1617 WL_TRACE(("%s: buflen_from_user %d: \n", dev->name, buflen_from_user)); 1614 WL_TRACE("%s: buflen_from_user %d:\n", dev->name, buflen_from_user);
1618 1615
1619 if (!extra) { 1616 if (!extra) {
1620 WL_TRACE(("%s: wl_iw_get_scan return -EINVAL\n", dev->name)); 1617 WL_TRACE("%s: wl_iw_get_scan return -EINVAL\n", dev->name);
1621 return -EINVAL; 1618 return -EINVAL;
1622 } 1619 }
1623 1620
@@ -1631,8 +1628,8 @@ wl_iw_get_scan(struct net_device *dev,
1631 if (g_scan_specified_ssid) { 1628 if (g_scan_specified_ssid) {
1632 list = kmalloc(len, GFP_KERNEL); 1629 list = kmalloc(len, GFP_KERNEL);
1633 if (!list) { 1630 if (!list) {
1634 WL_TRACE(("%s: wl_iw_get_scan return -ENOMEM\n", 1631 WL_TRACE("%s: wl_iw_get_scan return -ENOMEM\n",
1635 dev->name)); 1632 dev->name);
1636 g_scan_specified_ssid = 0; 1633 g_scan_specified_ssid = 0;
1637 return -ENOMEM; 1634 return -ENOMEM;
1638 } 1635 }
@@ -1642,8 +1639,8 @@ wl_iw_get_scan(struct net_device *dev,
1642 list->buflen = htod32(len); 1639 list->buflen = htod32(len);
1643 error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, len); 1640 error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, len);
1644 if (error) { 1641 if (error) {
1645 WL_ERROR(("%s: %s : Scan_results ERROR %d\n", dev->name, 1642 WL_ERROR("%s: %s : Scan_results ERROR %d\n",
1646 __func__, error)); 1643 dev->name, __func__, error);
1647 dwrq->length = len; 1644 dwrq->length = len;
1648 if (g_scan_specified_ssid) { 1645 if (g_scan_specified_ssid) {
1649 g_scan_specified_ssid = 0; 1646 g_scan_specified_ssid = 0;
@@ -1656,8 +1653,8 @@ wl_iw_get_scan(struct net_device *dev,
1656 list->count = dtoh32(list->count); 1653 list->count = dtoh32(list->count);
1657 1654
1658 if (list->version != WL_BSS_INFO_VERSION) { 1655 if (list->version != WL_BSS_INFO_VERSION) {
1659 WL_ERROR(("%s : list->version %d != WL_BSS_INFO_VERSION\n", 1656 WL_ERROR("%s : list->version %d != WL_BSS_INFO_VERSION\n",
1660 __func__, list->version)); 1657 __func__, list->version);
1661 if (g_scan_specified_ssid) { 1658 if (g_scan_specified_ssid) {
1662 g_scan_specified_ssid = 0; 1659 g_scan_specified_ssid = 0;
1663 kfree(list); 1660 kfree(list);
@@ -1666,8 +1663,8 @@ wl_iw_get_scan(struct net_device *dev,
1666 } 1663 }
1667 1664
1668 if (g_scan_specified_ssid) { 1665 if (g_scan_specified_ssid) {
1669 WL_TRACE(("%s: Specified scan APs in the list =%d\n", 1666 WL_TRACE("%s: Specified scan APs in the list =%d\n",
1670 __func__, list->count)); 1667 __func__, list->count);
1671 len_ret = 1668 len_ret =
1672 (__u16) wl_iw_get_scan_prep(list, info, extra, 1669 (__u16) wl_iw_get_scan_prep(list, info, extra,
1673 buflen_from_user); 1670 buflen_from_user);
@@ -1678,8 +1675,8 @@ wl_iw_get_scan(struct net_device *dev,
1678 while (p_buf != iscan->list_cur) { 1675 while (p_buf != iscan->list_cur) {
1679 list_merge = 1676 list_merge =
1680 &((wl_iscan_results_t *) p_buf->iscan_buf)->results; 1677 &((wl_iscan_results_t *) p_buf->iscan_buf)->results;
1681 WL_TRACE(("%s: Bcast APs list=%d\n", __func__, 1678 WL_TRACE("%s: Bcast APs list=%d\n",
1682 list_merge->count)); 1679 __func__, list_merge->count);
1683 if (list_merge->count > 0) 1680 if (list_merge->count > 0)
1684 len_ret += 1681 len_ret +=
1685 (__u16) wl_iw_get_scan_prep(list_merge, 1682 (__u16) wl_iw_get_scan_prep(list_merge,
@@ -1689,8 +1686,8 @@ wl_iw_get_scan(struct net_device *dev,
1689 } 1686 }
1690#else 1687#else
1691 list_merge = (wl_scan_results_t *) g_scan; 1688 list_merge = (wl_scan_results_t *) g_scan;
1692 WL_TRACE(("%s: Bcast APs list=%d\n", __func__, 1689 WL_TRACE("%s: Bcast APs list=%d\n",
1693 list_merge->count)); 1690 __func__, list_merge->count);
1694 if (list_merge->count > 0) 1691 if (list_merge->count > 0)
1695 len_ret += 1692 len_ret +=
1696 (__u16) wl_iw_get_scan_prep(list_merge, info, 1693 (__u16) wl_iw_get_scan_prep(list_merge, info,
@@ -1714,8 +1711,8 @@ wl_iw_get_scan(struct net_device *dev,
1714 dwrq->length = len; 1711 dwrq->length = len;
1715 dwrq->flags = 0; 1712 dwrq->flags = 0;
1716 1713
1717 WL_TRACE(("%s return to WE %d bytes APs=%d\n", __func__, 1714 WL_TRACE("%s return to WE %d bytes APs=%d\n",
1718 dwrq->length, list->count)); 1715 __func__, dwrq->length, list->count);
1719 return 0; 1716 return 0;
1720} 1717}
1721 1718
@@ -1736,26 +1733,26 @@ wl_iw_iscan_get_scan(struct net_device *dev,
1736 u32 counter = 0; 1733 u32 counter = 0;
1737 u8 channel; 1734 u8 channel;
1738 1735
1739 WL_TRACE(("%s %s buflen_from_user %d:\n", dev->name, __func__, 1736 WL_TRACE("%s %s buflen_from_user %d:\n",
1740 dwrq->length)); 1737 dev->name, __func__, dwrq->length);
1741 1738
1742 if (!extra) { 1739 if (!extra) {
1743 WL_TRACE(("%s: INVALID SIOCGIWSCAN GET bad parameter\n", 1740 WL_TRACE("%s: INVALID SIOCGIWSCAN GET bad parameter\n",
1744 dev->name)); 1741 dev->name);
1745 return -EINVAL; 1742 return -EINVAL;
1746 } 1743 }
1747 1744
1748 if ((!iscan) || (!iscan->sysioc_tsk)) { 1745 if ((!iscan) || (!iscan->sysioc_tsk)) {
1749 WL_ERROR(("%ssysioc_tsk\n", __func__)); 1746 WL_ERROR("%ssysioc_tsk\n", __func__);
1750 return wl_iw_get_scan(dev, info, dwrq, extra); 1747 return wl_iw_get_scan(dev, info, dwrq, extra);
1751 } 1748 }
1752 1749
1753 if (iscan->iscan_state == ISCAN_STATE_SCANING) { 1750 if (iscan->iscan_state == ISCAN_STATE_SCANING) {
1754 WL_TRACE(("%s: SIOCGIWSCAN GET still scanning\n", dev->name)); 1751 WL_TRACE("%s: SIOCGIWSCAN GET still scanning\n", dev->name);
1755 return -EAGAIN; 1752 return -EAGAIN;
1756 } 1753 }
1757 1754
1758 WL_TRACE(("%s: SIOCGIWSCAN GET broadcast results\n", dev->name)); 1755 WL_TRACE("%s: SIOCGIWSCAN GET broadcast results\n", dev->name);
1759 apcnt = 0; 1756 apcnt = 0;
1760 p_buf = iscan->list_hdr; 1757 p_buf = iscan->list_hdr;
1761 while (p_buf != iscan->list_cur) { 1758 while (p_buf != iscan->list_cur) {
@@ -1764,9 +1761,8 @@ wl_iw_iscan_get_scan(struct net_device *dev,
1764 counter += list->count; 1761 counter += list->count;
1765 1762
1766 if (list->version != WL_BSS_INFO_VERSION) { 1763 if (list->version != WL_BSS_INFO_VERSION) {
1767 WL_ERROR(("%s : list->version %d != " 1764 WL_ERROR("%s : list->version %d != WL_BSS_INFO_VERSION\n",
1768 "WL_BSS_INFO_VERSION\n", 1765 __func__, list->version);
1769 __func__, list->version));
1770 return -EINVAL; 1766 return -EINVAL;
1771 } 1767 }
1772 1768
@@ -1779,14 +1775,14 @@ wl_iw_iscan_get_scan(struct net_device *dev,
1779 ASSERT(((unsigned long)bi + dtoh32(bi->length)) <= 1775 ASSERT(((unsigned long)bi + dtoh32(bi->length)) <=
1780 ((unsigned long)list + WLC_IW_ISCAN_MAXLEN)); 1776 ((unsigned long)list + WLC_IW_ISCAN_MAXLEN));
1781 1777
1782 if (event + ETHER_ADDR_LEN + bi->SSID_len + 1778 if (event + ETH_ALEN + bi->SSID_len +
1783 IW_EV_UINT_LEN + IW_EV_FREQ_LEN + IW_EV_QUAL_LEN >= 1779 IW_EV_UINT_LEN + IW_EV_FREQ_LEN + IW_EV_QUAL_LEN >=
1784 end) 1780 end)
1785 return -E2BIG; 1781 return -E2BIG;
1786 iwe.cmd = SIOCGIWAP; 1782 iwe.cmd = SIOCGIWAP;
1787 iwe.u.ap_addr.sa_family = ARPHRD_ETHER; 1783 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1788 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, 1784 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID,
1789 ETHER_ADDR_LEN); 1785 ETH_ALEN);
1790 event = 1786 event =
1791 IWE_STREAM_ADD_EVENT(info, event, end, &iwe, 1787 IWE_STREAM_ADD_EVENT(info, event, end, &iwe,
1792 IW_EV_ADDR_LEN); 1788 IW_EV_ADDR_LEN);
@@ -1876,8 +1872,8 @@ wl_iw_iscan_get_scan(struct net_device *dev,
1876 dwrq->length = event - extra; 1872 dwrq->length = event - extra;
1877 dwrq->flags = 0; 1873 dwrq->flags = 0;
1878 1874
1879 WL_TRACE(("%s return to WE %d bytes APs=%d\n", __func__, 1875 WL_TRACE("%s return to WE %d bytes APs=%d\n",
1880 dwrq->length, counter)); 1876 __func__, dwrq->length, counter);
1881 1877
1882 if (!dwrq->length) 1878 if (!dwrq->length)
1883 return -EAGAIN; 1879 return -EAGAIN;
@@ -1895,7 +1891,7 @@ wl_iw_set_essid(struct net_device *dev,
1895 wl_join_params_t join_params; 1891 wl_join_params_t join_params;
1896 int join_params_size; 1892 int join_params_size;
1897 1893
1898 WL_TRACE(("%s: SIOCSIWESSID\n", dev->name)); 1894 WL_TRACE("%s: SIOCSIWESSID\n", dev->name);
1899 1895
1900 if (g_set_essid_before_scan) 1896 if (g_set_essid_before_scan)
1901 return -EAGAIN; 1897 return -EAGAIN;
@@ -1923,7 +1919,7 @@ wl_iw_set_essid(struct net_device *dev,
1923 1919
1924 memcpy(&join_params.ssid.SSID, g_ssid.SSID, g_ssid.SSID_len); 1920 memcpy(&join_params.ssid.SSID, g_ssid.SSID, g_ssid.SSID_len);
1925 join_params.ssid.SSID_len = htod32(g_ssid.SSID_len); 1921 join_params.ssid.SSID_len = htod32(g_ssid.SSID_len);
1926 memcpy(&join_params.params.bssid, &ether_bcast, ETHER_ADDR_LEN); 1922 memcpy(&join_params.params.bssid, &ether_bcast, ETH_ALEN);
1927 1923
1928 wl_iw_ch_to_chanspec(g_wl_iw_params.target_channel, &join_params, 1924 wl_iw_ch_to_chanspec(g_wl_iw_params.target_channel, &join_params,
1929 &join_params_size); 1925 &join_params_size);
@@ -1931,11 +1927,11 @@ wl_iw_set_essid(struct net_device *dev,
1931 error = dev_wlc_ioctl(dev, WLC_SET_SSID, &join_params, 1927 error = dev_wlc_ioctl(dev, WLC_SET_SSID, &join_params,
1932 join_params_size); 1928 join_params_size);
1933 if (error) 1929 if (error)
1934 WL_ERROR(("Invalid ioctl data=%d\n", error)); 1930 WL_ERROR("Invalid ioctl data=%d\n", error);
1935 1931
1936 if (g_ssid.SSID_len) { 1932 if (g_ssid.SSID_len) {
1937 WL_TRACE(("%s: join SSID=%s ch=%d\n", __func__, 1933 WL_TRACE("%s: join SSID=%s ch=%d\n",
1938 g_ssid.SSID, g_wl_iw_params.target_channel)); 1934 __func__, g_ssid.SSID, g_wl_iw_params.target_channel);
1939 } 1935 }
1940 return 0; 1936 return 0;
1941} 1937}
@@ -1948,14 +1944,14 @@ wl_iw_get_essid(struct net_device *dev,
1948 wlc_ssid_t ssid; 1944 wlc_ssid_t ssid;
1949 int error; 1945 int error;
1950 1946
1951 WL_TRACE(("%s: SIOCGIWESSID\n", dev->name)); 1947 WL_TRACE("%s: SIOCGIWESSID\n", dev->name);
1952 1948
1953 if (!extra) 1949 if (!extra)
1954 return -EINVAL; 1950 return -EINVAL;
1955 1951
1956 error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid)); 1952 error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid));
1957 if (error) { 1953 if (error) {
1958 WL_ERROR(("Error getting the SSID\n")); 1954 WL_ERROR("Error getting the SSID\n");
1959 return error; 1955 return error;
1960 } 1956 }
1961 1957
@@ -1976,7 +1972,7 @@ wl_iw_set_nick(struct net_device *dev,
1976{ 1972{
1977 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev); 1973 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev);
1978 1974
1979 WL_TRACE(("%s: SIOCSIWNICKN\n", dev->name)); 1975 WL_TRACE("%s: SIOCSIWNICKN\n", dev->name);
1980 1976
1981 if (!extra) 1977 if (!extra)
1982 return -EINVAL; 1978 return -EINVAL;
@@ -1996,7 +1992,7 @@ wl_iw_get_nick(struct net_device *dev,
1996{ 1992{
1997 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev); 1993 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev);
1998 1994
1999 WL_TRACE(("%s: SIOCGIWNICKN\n", dev->name)); 1995 WL_TRACE("%s: SIOCGIWNICKN\n", dev->name);
2000 1996
2001 if (!extra) 1997 if (!extra)
2002 return -EINVAL; 1998 return -EINVAL;
@@ -2014,7 +2010,7 @@ wl_iw_set_rate(struct net_device *dev,
2014 wl_rateset_t rateset; 2010 wl_rateset_t rateset;
2015 int error, rate, i, error_bg, error_a; 2011 int error, rate, i, error_bg, error_a;
2016 2012
2017 WL_TRACE(("%s: SIOCSIWRATE\n", dev->name)); 2013 WL_TRACE("%s: SIOCSIWRATE\n", dev->name);
2018 2014
2019 error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, 2015 error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset,
2020 sizeof(rateset)); 2016 sizeof(rateset));
@@ -2063,7 +2059,7 @@ wl_iw_get_rate(struct net_device *dev,
2063{ 2059{
2064 int error, rate; 2060 int error, rate;
2065 2061
2066 WL_TRACE(("%s: SIOCGIWRATE\n", dev->name)); 2062 WL_TRACE("%s: SIOCGIWRATE\n", dev->name);
2067 2063
2068 error = dev_wlc_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate)); 2064 error = dev_wlc_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate));
2069 if (error) 2065 if (error)
@@ -2080,7 +2076,7 @@ wl_iw_set_rts(struct net_device *dev,
2080{ 2076{
2081 int error, rts; 2077 int error, rts;
2082 2078
2083 WL_TRACE(("%s: SIOCSIWRTS\n", dev->name)); 2079 WL_TRACE("%s: SIOCSIWRTS\n", dev->name);
2084 2080
2085 if (vwrq->disabled) 2081 if (vwrq->disabled)
2086 rts = DOT11_DEFAULT_RTS_LEN; 2082 rts = DOT11_DEFAULT_RTS_LEN;
@@ -2102,7 +2098,7 @@ wl_iw_get_rts(struct net_device *dev,
2102{ 2098{
2103 int error, rts; 2099 int error, rts;
2104 2100
2105 WL_TRACE(("%s: SIOCGIWRTS\n", dev->name)); 2101 WL_TRACE("%s: SIOCGIWRTS\n", dev->name);
2106 2102
2107 error = dev_wlc_intvar_get(dev, "rtsthresh", &rts); 2103 error = dev_wlc_intvar_get(dev, "rtsthresh", &rts);
2108 if (error) 2104 if (error)
@@ -2121,7 +2117,7 @@ wl_iw_set_frag(struct net_device *dev,
2121{ 2117{
2122 int error, frag; 2118 int error, frag;
2123 2119
2124 WL_TRACE(("%s: SIOCSIWFRAG\n", dev->name)); 2120 WL_TRACE("%s: SIOCSIWFRAG\n", dev->name);
2125 2121
2126 if (vwrq->disabled) 2122 if (vwrq->disabled)
2127 frag = DOT11_DEFAULT_FRAG_LEN; 2123 frag = DOT11_DEFAULT_FRAG_LEN;
@@ -2143,7 +2139,7 @@ wl_iw_get_frag(struct net_device *dev,
2143{ 2139{
2144 int error, fragthreshold; 2140 int error, fragthreshold;
2145 2141
2146 WL_TRACE(("%s: SIOCGIWFRAG\n", dev->name)); 2142 WL_TRACE("%s: SIOCGIWFRAG\n", dev->name);
2147 2143
2148 error = dev_wlc_intvar_get(dev, "fragthresh", &fragthreshold); 2144 error = dev_wlc_intvar_get(dev, "fragthresh", &fragthreshold);
2149 if (error) 2145 if (error)
@@ -2163,7 +2159,7 @@ wl_iw_set_txpow(struct net_device *dev,
2163{ 2159{
2164 int error, disable; 2160 int error, disable;
2165 u16 txpwrmw; 2161 u16 txpwrmw;
2166 WL_TRACE(("%s: SIOCSIWTXPOW\n", dev->name)); 2162 WL_TRACE("%s: SIOCSIWTXPOW\n", dev->name);
2167 2163
2168 disable = vwrq->disabled ? WL_RADIO_SW_DISABLE : 0; 2164 disable = vwrq->disabled ? WL_RADIO_SW_DISABLE : 0;
2169 disable += WL_RADIO_SW_DISABLE << 16; 2165 disable += WL_RADIO_SW_DISABLE << 16;
@@ -2200,7 +2196,7 @@ wl_iw_get_txpow(struct net_device *dev,
2200 int error, disable, txpwrdbm; 2196 int error, disable, txpwrdbm;
2201 u8 result; 2197 u8 result;
2202 2198
2203 WL_TRACE(("%s: SIOCGIWTXPOW\n", dev->name)); 2199 WL_TRACE("%s: SIOCGIWTXPOW\n", dev->name);
2204 2200
2205 error = dev_wlc_ioctl(dev, WLC_GET_RADIO, &disable, sizeof(disable)); 2201 error = dev_wlc_ioctl(dev, WLC_GET_RADIO, &disable, sizeof(disable));
2206 if (error) 2202 if (error)
@@ -2229,7 +2225,7 @@ wl_iw_set_retry(struct net_device *dev,
2229{ 2225{
2230 int error, lrl, srl; 2226 int error, lrl, srl;
2231 2227
2232 WL_TRACE(("%s: SIOCSIWRETRY\n", dev->name)); 2228 WL_TRACE("%s: SIOCSIWRETRY\n", dev->name);
2233 2229
2234 if (vwrq->disabled || (vwrq->flags & IW_RETRY_LIFETIME)) 2230 if (vwrq->disabled || (vwrq->flags & IW_RETRY_LIFETIME))
2235 return -EINVAL; 2231 return -EINVAL;
@@ -2277,7 +2273,7 @@ wl_iw_get_retry(struct net_device *dev,
2277{ 2273{
2278 int error, lrl, srl; 2274 int error, lrl, srl;
2279 2275
2280 WL_TRACE(("%s: SIOCGIWRETRY\n", dev->name)); 2276 WL_TRACE("%s: SIOCGIWRETRY\n", dev->name);
2281 2277
2282 vwrq->disabled = 0; 2278 vwrq->disabled = 0;
2283 2279
@@ -2317,7 +2313,7 @@ wl_iw_set_encode(struct net_device *dev,
2317 wl_wsec_key_t key; 2313 wl_wsec_key_t key;
2318 int error, val, wsec; 2314 int error, val, wsec;
2319 2315
2320 WL_TRACE(("%s: SIOCSIWENCODE\n", dev->name)); 2316 WL_TRACE("%s: SIOCSIWENCODE\n", dev->name);
2321 2317
2322 memset(&key, 0, sizeof(key)); 2318 memset(&key, 0, sizeof(key));
2323 2319
@@ -2409,9 +2405,9 @@ wl_iw_get_encode(struct net_device *dev,
2409 wl_wsec_key_t key; 2405 wl_wsec_key_t key;
2410 int error, val, wsec, auth; 2406 int error, val, wsec, auth;
2411 2407
2412 WL_TRACE(("%s: SIOCGIWENCODE\n", dev->name)); 2408 WL_TRACE("%s: SIOCGIWENCODE\n", dev->name);
2413 2409
2414 bzero(&key, sizeof(wl_wsec_key_t)); 2410 memset(&key, 0, sizeof(wl_wsec_key_t));
2415 2411
2416 if ((dwrq->flags & IW_ENCODE_INDEX) == 0) { 2412 if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
2417 for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; 2413 for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS;
@@ -2465,7 +2461,7 @@ wl_iw_set_power(struct net_device *dev,
2465{ 2461{
2466 int error, pm; 2462 int error, pm;
2467 2463
2468 WL_TRACE(("%s: SIOCSIWPOWER\n", dev->name)); 2464 WL_TRACE("%s: SIOCSIWPOWER\n", dev->name);
2469 2465
2470 pm = vwrq->disabled ? PM_OFF : PM_MAX; 2466 pm = vwrq->disabled ? PM_OFF : PM_MAX;
2471 2467
@@ -2484,7 +2480,7 @@ wl_iw_get_power(struct net_device *dev,
2484{ 2480{
2485 int error, pm; 2481 int error, pm;
2486 2482
2487 WL_TRACE(("%s: SIOCGIWPOWER\n", dev->name)); 2483 WL_TRACE("%s: SIOCGIWPOWER\n", dev->name);
2488 2484
2489 error = dev_wlc_ioctl(dev, WLC_GET_PM, &pm, sizeof(pm)); 2485 error = dev_wlc_ioctl(dev, WLC_GET_PM, &pm, sizeof(pm));
2490 if (error) 2486 if (error)
@@ -2503,7 +2499,7 @@ wl_iw_set_wpaie(struct net_device *dev,
2503 struct iw_request_info *info, struct iw_point *iwp, char *extra) 2499 struct iw_request_info *info, struct iw_point *iwp, char *extra)
2504{ 2500{
2505 2501
2506 WL_TRACE(("%s: SIOCSIWGENIE\n", dev->name)); 2502 WL_TRACE("%s: SIOCSIWGENIE\n", dev->name);
2507 2503
2508 CHECK_EXTRA_FOR_NULL(extra); 2504 CHECK_EXTRA_FOR_NULL(extra);
2509 2505
@@ -2516,7 +2512,7 @@ static int
2516wl_iw_get_wpaie(struct net_device *dev, 2512wl_iw_get_wpaie(struct net_device *dev,
2517 struct iw_request_info *info, struct iw_point *iwp, char *extra) 2513 struct iw_request_info *info, struct iw_point *iwp, char *extra)
2518{ 2514{
2519 WL_TRACE(("%s: SIOCGIWGENIE\n", dev->name)); 2515 WL_TRACE("%s: SIOCGIWGENIE\n", dev->name);
2520 iwp->length = 64; 2516 iwp->length = 64;
2521 dev_wlc_bufvar_get(dev, "wpaie", extra, iwp->length); 2517 dev_wlc_bufvar_get(dev, "wpaie", extra, iwp->length);
2522 return 0; 2518 return 0;
@@ -2531,7 +2527,7 @@ wl_iw_set_encodeext(struct net_device *dev,
2531 int error; 2527 int error;
2532 struct iw_encode_ext *iwe; 2528 struct iw_encode_ext *iwe;
2533 2529
2534 WL_TRACE(("%s: SIOCSIWENCODEEXT\n", dev->name)); 2530 WL_TRACE("%s: SIOCSIWENCODEEXT\n", dev->name);
2535 2531
2536 CHECK_EXTRA_FOR_NULL(extra); 2532 CHECK_EXTRA_FOR_NULL(extra);
2537 2533
@@ -2548,14 +2544,14 @@ wl_iw_set_encodeext(struct net_device *dev,
2548 2544
2549 key.len = iwe->key_len; 2545 key.len = iwe->key_len;
2550 2546
2551 if (!ETHER_ISMULTI(iwe->addr.sa_data)) 2547 if (!is_multicast_ether_addr(iwe->addr.sa_data))
2552 bcopy((void *)&iwe->addr.sa_data, (char *)&key.ea, 2548 bcopy((void *)&iwe->addr.sa_data, (char *)&key.ea,
2553 ETHER_ADDR_LEN); 2549 ETH_ALEN);
2554 2550
2555 if (key.len == 0) { 2551 if (key.len == 0) {
2556 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { 2552 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2557 WL_WSEC(("Changing the the primary Key to %d\n", 2553 WL_WSEC("Changing the the primary Key to %d\n",
2558 key.index)); 2554 key.index);
2559 key.index = htod32(key.index); 2555 key.index = htod32(key.index);
2560 error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY, 2556 error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY,
2561 &key.index, sizeof(key.index)); 2557 &key.index, sizeof(key.index));
@@ -2569,9 +2565,9 @@ wl_iw_set_encodeext(struct net_device *dev,
2569 if (iwe->key_len > sizeof(key.data)) 2565 if (iwe->key_len > sizeof(key.data))
2570 return -EINVAL; 2566 return -EINVAL;
2571 2567
2572 WL_WSEC(("Setting the key index %d\n", key.index)); 2568 WL_WSEC("Setting the key index %d\n", key.index);
2573 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { 2569 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2574 WL_WSEC(("key is a Primary Key\n")); 2570 WL_WSEC("key is a Primary Key\n");
2575 key.flags = WL_PRIMARY_KEY; 2571 key.flags = WL_PRIMARY_KEY;
2576 } 2572 }
2577 2573
@@ -2638,15 +2634,15 @@ wl_iw_set_pmksa(struct net_device *dev,
2638 uint i; 2634 uint i;
2639 int ret = 0; 2635 int ret = 0;
2640 2636
2641 WL_WSEC(("%s: SIOCSIWPMKSA\n", dev->name)); 2637 WL_WSEC("%s: SIOCSIWPMKSA\n", dev->name);
2642 2638
2643 CHECK_EXTRA_FOR_NULL(extra); 2639 CHECK_EXTRA_FOR_NULL(extra);
2644 2640
2645 iwpmksa = (struct iw_pmksa *)extra; 2641 iwpmksa = (struct iw_pmksa *)extra;
2646 2642
2647 if (iwpmksa->cmd == IW_PMKSA_FLUSH) { 2643 if (iwpmksa->cmd == IW_PMKSA_FLUSH) {
2648 WL_WSEC(("wl_iw_set_pmksa - IW_PMKSA_FLUSH\n")); 2644 WL_WSEC("wl_iw_set_pmksa - IW_PMKSA_FLUSH\n");
2649 bzero((char *)&pmkid_list, sizeof(pmkid_list)); 2645 memset((char *)&pmkid_list, 0, sizeof(pmkid_list));
2650 } 2646 }
2651 2647
2652 else if (iwpmksa->cmd == IW_PMKSA_REMOVE) { 2648 else if (iwpmksa->cmd == IW_PMKSA_REMOVE) {
@@ -2656,30 +2652,30 @@ wl_iw_set_pmksa(struct net_device *dev,
2656 pmkidptr = &pmkid; 2652 pmkidptr = &pmkid;
2657 2653
2658 bcopy(&iwpmksa->bssid.sa_data[0], 2654 bcopy(&iwpmksa->bssid.sa_data[0],
2659 &pmkidptr->pmkid[0].BSSID, ETHER_ADDR_LEN); 2655 &pmkidptr->pmkid[0].BSSID, ETH_ALEN);
2660 bcopy(&iwpmksa->pmkid[0], &pmkidptr->pmkid[0].PMKID, 2656 bcopy(&iwpmksa->pmkid[0], &pmkidptr->pmkid[0].PMKID,
2661 WPA2_PMKID_LEN); 2657 WPA2_PMKID_LEN);
2662 2658
2663 WL_WSEC(("wl_iw_set_pmksa:IW_PMKSA_REMOVE:PMKID: " 2659 WL_WSEC("wl_iw_set_pmksa:IW_PMKSA_REMOVE:PMKID: %pM = ",
2664 "%pM = ", &pmkidptr->pmkid[0].BSSID)); 2660 &pmkidptr->pmkid[0].BSSID);
2665 for (j = 0; j < WPA2_PMKID_LEN; j++) 2661 for (j = 0; j < WPA2_PMKID_LEN; j++)
2666 WL_WSEC(("%02x ", pmkidptr->pmkid[0].PMKID[j])); 2662 WL_WSEC("%02x ", pmkidptr->pmkid[0].PMKID[j]);
2667 WL_WSEC(("\n")); 2663 WL_WSEC("\n");
2668 } 2664 }
2669 2665
2670 for (i = 0; i < pmkid_list.pmkids.npmkid; i++) 2666 for (i = 0; i < pmkid_list.pmkids.npmkid; i++)
2671 if (!bcmp 2667 if (!memcmp
2672 (&iwpmksa->bssid.sa_data[0], 2668 (&iwpmksa->bssid.sa_data[0],
2673 &pmkid_list.pmkids.pmkid[i].BSSID, ETHER_ADDR_LEN)) 2669 &pmkid_list.pmkids.pmkid[i].BSSID, ETH_ALEN))
2674 break; 2670 break;
2675 2671
2676 if ((pmkid_list.pmkids.npmkid > 0) 2672 if ((pmkid_list.pmkids.npmkid > 0)
2677 && (i < pmkid_list.pmkids.npmkid)) { 2673 && (i < pmkid_list.pmkids.npmkid)) {
2678 bzero(&pmkid_list.pmkids.pmkid[i], sizeof(pmkid_t)); 2674 memset(&pmkid_list.pmkids.pmkid[i], 0, sizeof(pmkid_t));
2679 for (; i < (pmkid_list.pmkids.npmkid - 1); i++) { 2675 for (; i < (pmkid_list.pmkids.npmkid - 1); i++) {
2680 bcopy(&pmkid_list.pmkids.pmkid[i + 1].BSSID, 2676 bcopy(&pmkid_list.pmkids.pmkid[i + 1].BSSID,
2681 &pmkid_list.pmkids.pmkid[i].BSSID, 2677 &pmkid_list.pmkids.pmkid[i].BSSID,
2682 ETHER_ADDR_LEN); 2678 ETH_ALEN);
2683 bcopy(&pmkid_list.pmkids.pmkid[i + 1].PMKID, 2679 bcopy(&pmkid_list.pmkids.pmkid[i + 1].PMKID,
2684 &pmkid_list.pmkids.pmkid[i].PMKID, 2680 &pmkid_list.pmkids.pmkid[i].PMKID,
2685 WPA2_PMKID_LEN); 2681 WPA2_PMKID_LEN);
@@ -2691,14 +2687,14 @@ wl_iw_set_pmksa(struct net_device *dev,
2691 2687
2692 else if (iwpmksa->cmd == IW_PMKSA_ADD) { 2688 else if (iwpmksa->cmd == IW_PMKSA_ADD) {
2693 for (i = 0; i < pmkid_list.pmkids.npmkid; i++) 2689 for (i = 0; i < pmkid_list.pmkids.npmkid; i++)
2694 if (!bcmp 2690 if (!memcmp
2695 (&iwpmksa->bssid.sa_data[0], 2691 (&iwpmksa->bssid.sa_data[0],
2696 &pmkid_list.pmkids.pmkid[i].BSSID, ETHER_ADDR_LEN)) 2692 &pmkid_list.pmkids.pmkid[i].BSSID, ETH_ALEN))
2697 break; 2693 break;
2698 if (i < MAXPMKID) { 2694 if (i < MAXPMKID) {
2699 bcopy(&iwpmksa->bssid.sa_data[0], 2695 bcopy(&iwpmksa->bssid.sa_data[0],
2700 &pmkid_list.pmkids.pmkid[i].BSSID, 2696 &pmkid_list.pmkids.pmkid[i].BSSID,
2701 ETHER_ADDR_LEN); 2697 ETH_ALEN);
2702 bcopy(&iwpmksa->pmkid[0], 2698 bcopy(&iwpmksa->pmkid[0],
2703 &pmkid_list.pmkids.pmkid[i].PMKID, 2699 &pmkid_list.pmkids.pmkid[i].PMKID,
2704 WPA2_PMKID_LEN); 2700 WPA2_PMKID_LEN);
@@ -2710,25 +2706,25 @@ wl_iw_set_pmksa(struct net_device *dev,
2710 uint j; 2706 uint j;
2711 uint k; 2707 uint k;
2712 k = pmkid_list.pmkids.npmkid; 2708 k = pmkid_list.pmkids.npmkid;
2713 WL_WSEC(("wl_iw_set_pmksa,IW_PMKSA_ADD - PMKID: %pM = ", 2709 WL_WSEC("wl_iw_set_pmksa,IW_PMKSA_ADD - PMKID: %pM = ",
2714 &pmkid_list.pmkids.pmkid[k].BSSID)); 2710 &pmkid_list.pmkids.pmkid[k].BSSID);
2715 for (j = 0; j < WPA2_PMKID_LEN; j++) 2711 for (j = 0; j < WPA2_PMKID_LEN; j++)
2716 WL_WSEC(("%02x ", 2712 WL_WSEC("%02x ",
2717 pmkid_list.pmkids.pmkid[k].PMKID[j])); 2713 pmkid_list.pmkids.pmkid[k].PMKID[j]);
2718 WL_WSEC(("\n")); 2714 WL_WSEC("\n");
2719 } 2715 }
2720 } 2716 }
2721 WL_WSEC(("PRINTING pmkid LIST - No of elements %d\n", 2717 WL_WSEC("PRINTING pmkid LIST - No of elements %d\n",
2722 pmkid_list.pmkids.npmkid)); 2718 pmkid_list.pmkids.npmkid);
2723 for (i = 0; i < pmkid_list.pmkids.npmkid; i++) { 2719 for (i = 0; i < pmkid_list.pmkids.npmkid; i++) {
2724 uint j; 2720 uint j;
2725 WL_WSEC(("PMKID[%d]: %pM = ", i, 2721 WL_WSEC("PMKID[%d]: %pM = ",
2726 &pmkid_list.pmkids.pmkid[i].BSSID)); 2722 i, &pmkid_list.pmkids.pmkid[i].BSSID);
2727 for (j = 0; j < WPA2_PMKID_LEN; j++) 2723 for (j = 0; j < WPA2_PMKID_LEN; j++)
2728 WL_WSEC(("%02x ", pmkid_list.pmkids.pmkid[i].PMKID[j])); 2724 WL_WSEC("%02x ", pmkid_list.pmkids.pmkid[i].PMKID[j]);
2729 WL_WSEC(("\n")); 2725 WL_WSEC("\n");
2730 } 2726 }
2731 WL_WSEC(("\n")); 2727 WL_WSEC("\n");
2732 2728
2733 if (!ret) 2729 if (!ret)
2734 ret = dev_wlc_bufvar_set(dev, "pmkid_info", (char *)&pmkid_list, 2730 ret = dev_wlc_bufvar_set(dev, "pmkid_info", (char *)&pmkid_list,
@@ -2742,7 +2738,7 @@ wl_iw_get_encodeext(struct net_device *dev,
2742 struct iw_request_info *info, 2738 struct iw_request_info *info,
2743 struct iw_param *vwrq, char *extra) 2739 struct iw_param *vwrq, char *extra)
2744{ 2740{
2745 WL_TRACE(("%s: SIOCGIWENCODEEXT\n", dev->name)); 2741 WL_TRACE("%s: SIOCGIWENCODEEXT\n", dev->name);
2746 return 0; 2742 return 0;
2747} 2743}
2748 2744
@@ -2757,13 +2753,13 @@ wl_iw_set_wpaauth(struct net_device *dev,
2757 int val = 0; 2753 int val = 0;
2758 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev); 2754 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev);
2759 2755
2760 WL_TRACE(("%s: SIOCSIWAUTH\n", dev->name)); 2756 WL_TRACE("%s: SIOCSIWAUTH\n", dev->name);
2761 2757
2762 paramid = vwrq->flags & IW_AUTH_INDEX; 2758 paramid = vwrq->flags & IW_AUTH_INDEX;
2763 paramval = vwrq->value; 2759 paramval = vwrq->value;
2764 2760
2765 WL_TRACE(("%s: SIOCSIWAUTH, paramid = 0x%0x, paramval = 0x%0x\n", 2761 WL_TRACE("%s: SIOCSIWAUTH, paramid = 0x%0x, paramval = 0x%0x\n",
2766 dev->name, paramid, paramval)); 2762 dev->name, paramid, paramval);
2767 2763
2768 switch (paramid) { 2764 switch (paramid) {
2769 case IW_AUTH_WPA_VERSION: 2765 case IW_AUTH_WPA_VERSION:
@@ -2773,8 +2769,8 @@ wl_iw_set_wpaauth(struct net_device *dev,
2773 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED; 2769 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
2774 else if (paramval & IW_AUTH_WPA_VERSION_WPA2) 2770 else if (paramval & IW_AUTH_WPA_VERSION_WPA2)
2775 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED; 2771 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
2776 WL_INFORM(("%s: %d: setting wpa_auth to 0x%0x\n", __func__, 2772 WL_INFORM("%s: %d: setting wpa_auth to 0x%0x\n",
2777 __LINE__, val)); 2773 __func__, __LINE__, val);
2778 error = dev_wlc_intvar_set(dev, "wpa_auth", val); 2774 error = dev_wlc_intvar_set(dev, "wpa_auth", val);
2779 if (error) 2775 if (error)
2780 return error; 2776 return error;
@@ -2797,20 +2793,19 @@ wl_iw_set_wpaauth(struct net_device *dev,
2797 } 2793 }
2798 2794
2799 if (iw->privacy_invoked && !val) { 2795 if (iw->privacy_invoked && !val) {
2800 WL_WSEC(("%s: %s: 'Privacy invoked' true but clearing " 2796 WL_WSEC("%s: %s: 'Privacy invoked' true but clearing wsec, assuming we're a WPS enrollee\n",
2801 "wsec, assuming " "we're a WPS enrollee\n", 2797 dev->name, __func__);
2802 dev->name, __func__));
2803 error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", 2798 error = dev_wlc_intvar_set(dev, "is_WPS_enrollee",
2804 true); 2799 true);
2805 if (error) { 2800 if (error) {
2806 WL_WSEC(("Failed to set is_WPS_enrollee\n")); 2801 WL_WSEC("Failed to set is_WPS_enrollee\n");
2807 return error; 2802 return error;
2808 } 2803 }
2809 } else if (val) { 2804 } else if (val) {
2810 error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", 2805 error = dev_wlc_intvar_set(dev, "is_WPS_enrollee",
2811 false); 2806 false);
2812 if (error) { 2807 if (error) {
2813 WL_WSEC(("Failed to clear is_WPS_enrollee\n")); 2808 WL_WSEC("Failed to clear is_WPS_enrollee\n");
2814 return error; 2809 return error;
2815 } 2810 }
2816 } 2811 }
@@ -2837,8 +2832,8 @@ wl_iw_set_wpaauth(struct net_device *dev,
2837 else 2832 else
2838 val = WPA2_AUTH_UNSPECIFIED; 2833 val = WPA2_AUTH_UNSPECIFIED;
2839 } 2834 }
2840 WL_INFORM(("%s: %d: setting wpa_auth to %d\n", __func__, 2835 WL_INFORM("%s: %d: setting wpa_auth to %d\n",
2841 __LINE__, val)); 2836 __func__, __LINE__, val);
2842 error = dev_wlc_intvar_set(dev, "wpa_auth", val); 2837 error = dev_wlc_intvar_set(dev, "wpa_auth", val);
2843 if (error) 2838 if (error)
2844 return error; 2839 return error;
@@ -2850,7 +2845,7 @@ wl_iw_set_wpaauth(struct net_device *dev,
2850 break; 2845 break;
2851 2846
2852 case IW_AUTH_80211_AUTH_ALG: 2847 case IW_AUTH_80211_AUTH_ALG:
2853 WL_INFORM(("Setting the D11auth %d\n", paramval)); 2848 WL_INFORM("Setting the D11auth %d\n", paramval);
2854 if (paramval == IW_AUTH_ALG_OPEN_SYSTEM) 2849 if (paramval == IW_AUTH_ALG_OPEN_SYSTEM)
2855 val = 0; 2850 val = 0;
2856 else if (paramval == IW_AUTH_ALG_SHARED_KEY) 2851 else if (paramval == IW_AUTH_ALG_SHARED_KEY)
@@ -2879,8 +2874,8 @@ wl_iw_set_wpaauth(struct net_device *dev,
2879 dev_wlc_intvar_set(dev, "wsec", val); 2874 dev_wlc_intvar_set(dev, "wsec", val);
2880 } 2875 }
2881 val = 0; 2876 val = 0;
2882 WL_INFORM(("%s: %d: setting wpa_auth to %d\n", 2877 WL_INFORM("%s: %d: setting wpa_auth to %d\n",
2883 __func__, __LINE__, val)); 2878 __func__, __LINE__, val);
2884 dev_wlc_intvar_set(dev, "wpa_auth", 0); 2879 dev_wlc_intvar_set(dev, "wpa_auth", 0);
2885 return error; 2880 return error;
2886 } 2881 }
@@ -2897,7 +2892,7 @@ wl_iw_set_wpaauth(struct net_device *dev,
2897 2892
2898#if WIRELESS_EXT > 17 2893#if WIRELESS_EXT > 17
2899 case IW_AUTH_ROAMING_CONTROL: 2894 case IW_AUTH_ROAMING_CONTROL:
2900 WL_INFORM(("%s: IW_AUTH_ROAMING_CONTROL\n", __func__)); 2895 WL_INFORM("%s: IW_AUTH_ROAMING_CONTROL\n", __func__);
2901 break; 2896 break;
2902 case IW_AUTH_PRIVACY_INVOKED: 2897 case IW_AUTH_PRIVACY_INVOKED:
2903 { 2898 {
@@ -2908,8 +2903,7 @@ wl_iw_set_wpaauth(struct net_device *dev,
2908 error = dev_wlc_intvar_set(dev, 2903 error = dev_wlc_intvar_set(dev,
2909 "is_WPS_enrollee", false); 2904 "is_WPS_enrollee", false);
2910 if (error) { 2905 if (error) {
2911 WL_WSEC(("Failed to clear iovar " 2906 WL_WSEC("Failed to clear iovar is_WPS_enrollee\n");
2912 "is_WPS_enrollee\n"));
2913 return error; 2907 return error;
2914 } 2908 }
2915 } else { 2909 } else {
@@ -2923,8 +2917,7 @@ wl_iw_set_wpaauth(struct net_device *dev,
2923 "is_WPS_enrollee", 2917 "is_WPS_enrollee",
2924 true); 2918 true);
2925 if (error) { 2919 if (error) {
2926 WL_WSEC(("Failed to set iovar " 2920 WL_WSEC("Failed to set iovar is_WPS_enrollee\n");
2927 "is_WPS_enrollee\n"));
2928 return error; 2921 return error;
2929 } 2922 }
2930 } else { 2923 } else {
@@ -2932,8 +2925,7 @@ wl_iw_set_wpaauth(struct net_device *dev,
2932 "is_WPS_enrollee", 2925 "is_WPS_enrollee",
2933 false); 2926 false);
2934 if (error) { 2927 if (error) {
2935 WL_WSEC(("Failed to clear " 2928 WL_WSEC("Failed to clear is_WPS_enrollee\n");
2936 "is_WPS_enrollee\n"));
2937 return error; 2929 return error;
2938 } 2930 }
2939 } 2931 }
@@ -2960,7 +2952,7 @@ wl_iw_get_wpaauth(struct net_device *dev,
2960 int val; 2952 int val;
2961 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev); 2953 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev);
2962 2954
2963 WL_TRACE(("%s: SIOCGIWAUTH\n", dev->name)); 2955 WL_TRACE("%s: SIOCGIWAUTH\n", dev->name);
2964 2956
2965 paramid = vwrq->flags & IW_AUTH_INDEX; 2957 paramid = vwrq->flags & IW_AUTH_INDEX;
2966 2958
@@ -3040,7 +3032,7 @@ wl_iw_get_wpaauth(struct net_device *dev,
3040 break; 3032 break;
3041#if WIRELESS_EXT > 17 3033#if WIRELESS_EXT > 17
3042 case IW_AUTH_ROAMING_CONTROL: 3034 case IW_AUTH_ROAMING_CONTROL:
3043 WL_ERROR(("%s: IW_AUTH_ROAMING_CONTROL\n", __func__)); 3035 WL_ERROR("%s: IW_AUTH_ROAMING_CONTROL\n", __func__);
3044 break; 3036 break;
3045 case IW_AUTH_PRIVACY_INVOKED: 3037 case IW_AUTH_PRIVACY_INVOKED:
3046 paramval = iw->privacy_invoked; 3038 paramval = iw->privacy_invoked;
@@ -3157,19 +3149,19 @@ int wl_iw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3157 char *extra = NULL; 3149 char *extra = NULL;
3158 int token_size = 1, max_tokens = 0, ret = 0; 3150 int token_size = 1, max_tokens = 0, ret = 0;
3159 3151
3160 WL_TRACE(("\n%s, cmd:%x alled via dhd->do_ioctl()entry point\n", 3152 WL_TRACE("\n%s, cmd:%x alled via dhd->do_ioctl()entry point\n",
3161 __func__, cmd)); 3153 __func__, cmd);
3162 if (cmd < SIOCIWFIRST || 3154 if (cmd < SIOCIWFIRST ||
3163 IW_IOCTL_IDX(cmd) >= ARRAY_SIZE(wl_iw_handler)) { 3155 IW_IOCTL_IDX(cmd) >= ARRAY_SIZE(wl_iw_handler)) {
3164 WL_ERROR(("%s: error in cmd=%x : out of range\n", __func__, 3156 WL_ERROR("%s: error in cmd=%x : out of range\n",
3165 cmd)); 3157 __func__, cmd);
3166 return -EOPNOTSUPP; 3158 return -EOPNOTSUPP;
3167 } 3159 }
3168 3160
3169 handler = wl_iw_handler[IW_IOCTL_IDX(cmd)]; 3161 handler = wl_iw_handler[IW_IOCTL_IDX(cmd)];
3170 if (!handler) { 3162 if (!handler) {
3171 WL_ERROR(("%s: error in cmd=%x : not supported\n", 3163 WL_ERROR("%s: error in cmd=%x : not supported\n",
3172 __func__, cmd)); 3164 __func__, cmd);
3173 return -EOPNOTSUPP; 3165 return -EOPNOTSUPP;
3174 } 3166 }
3175 3167
@@ -3234,9 +3226,8 @@ int wl_iw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3234 3226
3235 if (max_tokens && wrq->u.data.pointer) { 3227 if (max_tokens && wrq->u.data.pointer) {
3236 if (wrq->u.data.length > max_tokens) { 3228 if (wrq->u.data.length > max_tokens) {
3237 WL_ERROR(("%s: error in cmd=%x wrq->u.data.length=%d " 3229 WL_ERROR("%s: error in cmd=%x wrq->u.data.length=%d > max_tokens=%d\n",
3238 "> max_tokens=%d\n", 3230 __func__, cmd, wrq->u.data.length, max_tokens);
3239 __func__, cmd, wrq->u.data.length, max_tokens));
3240 return -E2BIG; 3231 return -E2BIG;
3241 } 3232 }
3242 extra = kmalloc(max_tokens * token_size, GFP_KERNEL); 3233 extra = kmalloc(max_tokens * token_size, GFP_KERNEL);
@@ -3339,7 +3330,7 @@ wl_iw_conn_status_str(u32 event_type, u32 status, u32 reason,
3339 memset(stringBuf, 0, buflen); 3330 memset(stringBuf, 0, buflen);
3340 snprintf(stringBuf, buflen, "%s %s %02d %02d", 3331 snprintf(stringBuf, buflen, "%s %s %02d %02d",
3341 name, cause, status, reason); 3332 name, cause, status, reason);
3342 WL_INFORM(("Connection status: %s\n", stringBuf)); 3333 WL_INFORM("Connection status: %s\n", stringBuf);
3343 return true; 3334 return true;
3344 } else { 3335 } else {
3345 return false; 3336 return false;
@@ -3383,46 +3374,46 @@ void wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void *data)
3383 iw = 0; 3374 iw = 0;
3384 3375
3385 if (!dev) { 3376 if (!dev) {
3386 WL_ERROR(("%s: dev is null\n", __func__)); 3377 WL_ERROR("%s: dev is null\n", __func__);
3387 return; 3378 return;
3388 } 3379 }
3389 3380
3390 iw = *(wl_iw_t **) netdev_priv(dev); 3381 iw = *(wl_iw_t **) netdev_priv(dev);
3391 3382
3392 WL_TRACE(("%s: dev=%s event=%d\n", __func__, dev->name, event_type)); 3383 WL_TRACE("%s: dev=%s event=%d\n", __func__, dev->name, event_type);
3393 3384
3394 switch (event_type) { 3385 switch (event_type) {
3395 case WLC_E_TXFAIL: 3386 case WLC_E_TXFAIL:
3396 cmd = IWEVTXDROP; 3387 cmd = IWEVTXDROP;
3397 memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN); 3388 memcpy(wrqu.addr.sa_data, &e->addr, ETH_ALEN);
3398 wrqu.addr.sa_family = ARPHRD_ETHER; 3389 wrqu.addr.sa_family = ARPHRD_ETHER;
3399 break; 3390 break;
3400#if WIRELESS_EXT > 14 3391#if WIRELESS_EXT > 14
3401 case WLC_E_JOIN: 3392 case WLC_E_JOIN:
3402 case WLC_E_ASSOC_IND: 3393 case WLC_E_ASSOC_IND:
3403 case WLC_E_REASSOC_IND: 3394 case WLC_E_REASSOC_IND:
3404 memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN); 3395 memcpy(wrqu.addr.sa_data, &e->addr, ETH_ALEN);
3405 wrqu.addr.sa_family = ARPHRD_ETHER; 3396 wrqu.addr.sa_family = ARPHRD_ETHER;
3406 cmd = IWEVREGISTERED; 3397 cmd = IWEVREGISTERED;
3407 break; 3398 break;
3408 case WLC_E_DEAUTH_IND: 3399 case WLC_E_DEAUTH_IND:
3409 case WLC_E_DISASSOC_IND: 3400 case WLC_E_DISASSOC_IND:
3410 cmd = SIOCGIWAP; 3401 cmd = SIOCGIWAP;
3411 bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN); 3402 memset(wrqu.addr.sa_data, 0, ETH_ALEN);
3412 wrqu.addr.sa_family = ARPHRD_ETHER; 3403 wrqu.addr.sa_family = ARPHRD_ETHER;
3413 bzero(&extra, ETHER_ADDR_LEN); 3404 memset(&extra, 0, ETH_ALEN);
3414 break; 3405 break;
3415 case WLC_E_LINK: 3406 case WLC_E_LINK:
3416 case WLC_E_NDIS_LINK: 3407 case WLC_E_NDIS_LINK:
3417 cmd = SIOCGIWAP; 3408 cmd = SIOCGIWAP;
3418 if (!(flags & WLC_EVENT_MSG_LINK)) { 3409 if (!(flags & WLC_EVENT_MSG_LINK)) {
3419 bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN); 3410 memset(wrqu.addr.sa_data, 0, ETH_ALEN);
3420 bzero(&extra, ETHER_ADDR_LEN); 3411 memset(&extra, 0, ETH_ALEN);
3421 WAKE_LOCK_TIMEOUT(iw->pub, WAKE_LOCK_LINK_DOWN_TMOUT, 3412 WAKE_LOCK_TIMEOUT(iw->pub, WAKE_LOCK_LINK_DOWN_TMOUT,
3422 20 * HZ); 3413 20 * HZ);
3423 } else { 3414 } else {
3424 memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN); 3415 memcpy(wrqu.addr.sa_data, &e->addr, ETH_ALEN);
3425 WL_TRACE(("Link UP\n")); 3416 WL_TRACE("Link UP\n");
3426 3417
3427 } 3418 }
3428 wrqu.addr.sa_family = ARPHRD_ETHER; 3419 wrqu.addr.sa_family = ARPHRD_ETHER;
@@ -3433,8 +3424,8 @@ void wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void *data)
3433 wrqu.data.length = datalen + 1; 3424 wrqu.data.length = datalen + 1;
3434 extra[0] = WLC_E_ACTION_FRAME; 3425 extra[0] = WLC_E_ACTION_FRAME;
3435 memcpy(&extra[1], data, datalen); 3426 memcpy(&extra[1], data, datalen);
3436 WL_TRACE(("WLC_E_ACTION_FRAME len %d \n", 3427 WL_TRACE("WLC_E_ACTION_FRAME len %d\n",
3437 wrqu.data.length)); 3428 wrqu.data.length);
3438 } 3429 }
3439 break; 3430 break;
3440 3431
@@ -3464,7 +3455,7 @@ void wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void *data)
3464 else 3455 else
3465 micerrevt->flags |= IW_MICFAILURE_PAIRWISE; 3456 micerrevt->flags |= IW_MICFAILURE_PAIRWISE;
3466 memcpy(micerrevt->src_addr.sa_data, &e->addr, 3457 memcpy(micerrevt->src_addr.sa_data, &e->addr,
3467 ETHER_ADDR_LEN); 3458 ETH_ALEN);
3468 micerrevt->src_addr.sa_family = ARPHRD_ETHER; 3459 micerrevt->src_addr.sa_family = ARPHRD_ETHER;
3469 3460
3470 break; 3461 break;
@@ -3487,14 +3478,14 @@ void wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void *data)
3487 wrqu.data.length = sizeof(struct iw_pmkid_cand); 3478 wrqu.data.length = sizeof(struct iw_pmkid_cand);
3488 pmkidcand = pmkcandlist->pmkid_cand; 3479 pmkidcand = pmkcandlist->pmkid_cand;
3489 while (count) { 3480 while (count) {
3490 bzero(iwpmkidcand, 3481 memset(iwpmkidcand, 0,
3491 sizeof(struct iw_pmkid_cand)); 3482 sizeof(struct iw_pmkid_cand));
3492 if (pmkidcand->preauth) 3483 if (pmkidcand->preauth)
3493 iwpmkidcand->flags |= 3484 iwpmkidcand->flags |=
3494 IW_PMKID_CAND_PREAUTH; 3485 IW_PMKID_CAND_PREAUTH;
3495 bcopy(&pmkidcand->BSSID, 3486 bcopy(&pmkidcand->BSSID,
3496 &iwpmkidcand->bssid.sa_data, 3487 &iwpmkidcand->bssid.sa_data,
3497 ETHER_ADDR_LEN); 3488 ETH_ALEN);
3498#ifndef SANDGATE2G 3489#ifndef SANDGATE2G
3499 wireless_send_event(dev, cmd, &wrqu, 3490 wireless_send_event(dev, cmd, &wrqu,
3500 extra); 3491 extra);
@@ -3515,13 +3506,13 @@ void wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void *data)
3515 } else { 3506 } else {
3516 cmd = SIOCGIWSCAN; 3507 cmd = SIOCGIWSCAN;
3517 wrqu.data.length = strlen(extra); 3508 wrqu.data.length = strlen(extra);
3518 WL_TRACE(("Event WLC_E_SCAN_COMPLETE from specific " 3509 WL_TRACE("Event WLC_E_SCAN_COMPLETE from specific scan %d\n",
3519 "scan %d\n", g_iscan->iscan_state)); 3510 g_iscan->iscan_state);
3520 } 3511 }
3521#else 3512#else
3522 cmd = SIOCGIWSCAN; 3513 cmd = SIOCGIWSCAN;
3523 wrqu.data.length = strlen(extra); 3514 wrqu.data.length = strlen(extra);
3524 WL_TRACE(("Event WLC_E_SCAN_COMPLETE\n")); 3515 WL_TRACE("Event WLC_E_SCAN_COMPLETE\n");
3525#endif 3516#endif
3526 break; 3517 break;
3527 3518
@@ -3529,9 +3520,9 @@ void wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void *data)
3529 { 3520 {
3530 wlc_ssid_t *ssid; 3521 wlc_ssid_t *ssid;
3531 ssid = (wlc_ssid_t *) data; 3522 ssid = (wlc_ssid_t *) data;
3532 WL_ERROR(("%s Event WLC_E_PFN_NET_FOUND, send %s up : " 3523 WL_ERROR("%s Event WLC_E_PFN_NET_FOUND, send %s up : find %s len=%d\n",
3533 "find %s len=%d\n", __func__, PNO_EVENT_UP, 3524 __func__, PNO_EVENT_UP,
3534 ssid->SSID, ssid->SSID_len)); 3525 ssid->SSID, ssid->SSID_len);
3535 WAKE_LOCK_TIMEOUT(iw->pub, WAKE_LOCK_PNO_FIND_TMOUT, 3526 WAKE_LOCK_TIMEOUT(iw->pub, WAKE_LOCK_PNO_FIND_TMOUT,
3536 20 * HZ); 3527 20 * HZ);
3537 cmd = IWEVCUSTOM; 3528 cmd = IWEVCUSTOM;
@@ -3542,7 +3533,7 @@ void wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void *data)
3542 break; 3533 break;
3543 3534
3544 default: 3535 default:
3545 WL_TRACE(("Unknown Event %d: ignoring\n", event_type)); 3536 WL_TRACE("Unknown Event %d: ignoring\n", event_type);
3546 break; 3537 break;
3547 } 3538 }
3548#ifndef SANDGATE2G 3539#ifndef SANDGATE2G
@@ -3583,15 +3574,15 @@ wl_iw_get_wireless_stats(struct net_device *dev, struct iw_statistics *wstats)
3583 goto done; 3574 goto done;
3584 3575
3585 phy_noise = dtoh32(phy_noise); 3576 phy_noise = dtoh32(phy_noise);
3586 WL_TRACE(("wl_iw_get_wireless_stats phy noise=%d\n", phy_noise)); 3577 WL_TRACE("wl_iw_get_wireless_stats phy noise=%d\n", phy_noise);
3587 3578
3588 bzero(&scb_val, sizeof(scb_val_t)); 3579 memset(&scb_val, 0, sizeof(scb_val_t));
3589 res = dev_wlc_ioctl(dev, WLC_GET_RSSI, &scb_val, sizeof(scb_val_t)); 3580 res = dev_wlc_ioctl(dev, WLC_GET_RSSI, &scb_val, sizeof(scb_val_t));
3590 if (res) 3581 if (res)
3591 goto done; 3582 goto done;
3592 3583
3593 rssi = dtoh32(scb_val.val); 3584 rssi = dtoh32(scb_val.val);
3594 WL_TRACE(("wl_iw_get_wireless_stats rssi=%d\n", rssi)); 3585 WL_TRACE("wl_iw_get_wireless_stats rssi=%d\n", rssi);
3595 if (rssi <= WL_IW_RSSI_NO_SIGNAL) 3586 if (rssi <= WL_IW_RSSI_NO_SIGNAL)
3596 wstats->qual.qual = 0; 3587 wstats->qual.qual = 0;
3597 else if (rssi <= WL_IW_RSSI_VERY_LOW) 3588 else if (rssi <= WL_IW_RSSI_VERY_LOW)
@@ -3614,23 +3605,21 @@ wl_iw_get_wireless_stats(struct net_device *dev, struct iw_statistics *wstats)
3614#endif 3605#endif
3615 3606
3616#if WIRELESS_EXT > 11 3607#if WIRELESS_EXT > 11
3617 WL_TRACE(("wl_iw_get_wireless_stats counters=%d\n", 3608 WL_TRACE("wl_iw_get_wireless_stats counters=%zu\n", sizeof(wl_cnt_t));
3618 (int)sizeof(wl_cnt_t)));
3619 3609
3620 memset(&cnt, 0, sizeof(wl_cnt_t)); 3610 memset(&cnt, 0, sizeof(wl_cnt_t));
3621 res = 3611 res =
3622 dev_wlc_bufvar_get(dev, "counters", (char *)&cnt, sizeof(wl_cnt_t)); 3612 dev_wlc_bufvar_get(dev, "counters", (char *)&cnt, sizeof(wl_cnt_t));
3623 if (res) { 3613 if (res) {
3624 WL_ERROR(("wl_iw_get_wireless_stats counters failed error=%d\n", 3614 WL_ERROR("wl_iw_get_wireless_stats counters failed error=%d\n",
3625 res)); 3615 res);
3626 goto done; 3616 goto done;
3627 } 3617 }
3628 3618
3629 cnt.version = dtoh16(cnt.version); 3619 cnt.version = dtoh16(cnt.version);
3630 if (cnt.version != WL_CNT_T_VERSION) { 3620 if (cnt.version != WL_CNT_T_VERSION) {
3631 WL_TRACE(("\tIncorrect version of counters struct: expected " 3621 WL_TRACE("\tIncorrect version of counters struct: expected %d; got %d\n",
3632 "%d; got %d\n", 3622 WL_CNT_T_VERSION, cnt.version);
3633 WL_CNT_T_VERSION, cnt.version));
3634 goto done; 3623 goto done;
3635 } 3624 }
3636 3625
@@ -3641,22 +3630,22 @@ wl_iw_get_wireless_stats(struct net_device *dev, struct iw_statistics *wstats)
3641 wstats->discard.misc = dtoh32(cnt.rxrunt) + dtoh32(cnt.rxgiant); 3630 wstats->discard.misc = dtoh32(cnt.rxrunt) + dtoh32(cnt.rxgiant);
3642 wstats->miss.beacon = 0; 3631 wstats->miss.beacon = 0;
3643 3632
3644 WL_TRACE(("wl_iw_get_wireless_stats counters txframe=%d txbyte=%d\n", 3633 WL_TRACE("wl_iw_get_wireless_stats counters txframe=%d txbyte=%d\n",
3645 dtoh32(cnt.txframe), dtoh32(cnt.txbyte))); 3634 dtoh32(cnt.txframe), dtoh32(cnt.txbyte));
3646 WL_TRACE(("wl_iw_get_wireless_stats counters rxfrmtoolong=%d\n", 3635 WL_TRACE("wl_iw_get_wireless_stats counters rxfrmtoolong=%d\n",
3647 dtoh32(cnt.rxfrmtoolong))); 3636 dtoh32(cnt.rxfrmtoolong));
3648 WL_TRACE(("wl_iw_get_wireless_stats counters rxbadplcp=%d\n", 3637 WL_TRACE("wl_iw_get_wireless_stats counters rxbadplcp=%d\n",
3649 dtoh32(cnt.rxbadplcp))); 3638 dtoh32(cnt.rxbadplcp));
3650 WL_TRACE(("wl_iw_get_wireless_stats counters rxundec=%d\n", 3639 WL_TRACE("wl_iw_get_wireless_stats counters rxundec=%d\n",
3651 dtoh32(cnt.rxundec))); 3640 dtoh32(cnt.rxundec));
3652 WL_TRACE(("wl_iw_get_wireless_stats counters rxfragerr=%d\n", 3641 WL_TRACE("wl_iw_get_wireless_stats counters rxfragerr=%d\n",
3653 dtoh32(cnt.rxfragerr))); 3642 dtoh32(cnt.rxfragerr));
3654 WL_TRACE(("wl_iw_get_wireless_stats counters txfail=%d\n", 3643 WL_TRACE("wl_iw_get_wireless_stats counters txfail=%d\n",
3655 dtoh32(cnt.txfail))); 3644 dtoh32(cnt.txfail));
3656 WL_TRACE(("wl_iw_get_wireless_stats counters rxrunt=%d\n", 3645 WL_TRACE("wl_iw_get_wireless_stats counters rxrunt=%d\n",
3657 dtoh32(cnt.rxrunt))); 3646 dtoh32(cnt.rxrunt));
3658 WL_TRACE(("wl_iw_get_wireless_stats counters rxgiant=%d\n", 3647 WL_TRACE("wl_iw_get_wireless_stats counters rxgiant=%d\n",
3659 dtoh32(cnt.rxgiant))); 3648 dtoh32(cnt.rxgiant));
3660#endif /* WIRELESS_EXT > 11 */ 3649#endif /* WIRELESS_EXT > 11 */
3661 3650
3662done: 3651done:
@@ -3690,8 +3679,7 @@ int wl_iw_attach(struct net_device *dev, void *dhdp)
3690 return -ENOMEM; 3679 return -ENOMEM;
3691 memset(iscan, 0, sizeof(iscan_info_t)); 3680 memset(iscan, 0, sizeof(iscan_info_t));
3692 3681
3693 iscan->iscan_ex_params_p = 3682 iscan->iscan_ex_params_p = kmalloc(params_size, GFP_KERNEL);
3694 (wl_iscan_params_t *) kmalloc(params_size, GFP_KERNEL);
3695 if (!iscan->iscan_ex_params_p) 3683 if (!iscan->iscan_ex_params_p)
3696 return -ENOMEM; 3684 return -ENOMEM;
3697 iscan->iscan_ex_param_size = params_size; 3685 iscan->iscan_ex_param_size = params_size;
@@ -3723,9 +3711,7 @@ int wl_iw_attach(struct net_device *dev, void *dhdp)
3723 priv_dev = dev; 3711 priv_dev = dev;
3724 MUTEX_LOCK_SOFTAP_SET_INIT(iw->pub); 3712 MUTEX_LOCK_SOFTAP_SET_INIT(iw->pub);
3725#endif 3713#endif
3726 g_scan = NULL; 3714 g_scan = kmalloc(G_SCAN_RESULTS, GFP_KERNEL);
3727
3728 g_scan = (void *)kmalloc(G_SCAN_RESULTS, GFP_KERNEL);
3729 if (!g_scan) 3715 if (!g_scan)
3730 return -ENOMEM; 3716 return -ENOMEM;
3731 3717
diff --git a/drivers/staging/brcm80211/brcmfmac/wl_iw.h b/drivers/staging/brcm80211/brcmfmac/wl_iw.h
index edbf61f30b47..c8637c50dc17 100644
--- a/drivers/staging/brcm80211/brcmfmac/wl_iw.h
+++ b/drivers/staging/brcm80211/brcmfmac/wl_iw.h
@@ -78,7 +78,7 @@ typedef struct wl_iw_extra_params {
78 78
79#define CHECK_EXTRA_FOR_NULL(extra) \ 79#define CHECK_EXTRA_FOR_NULL(extra) \
80if (!extra) { \ 80if (!extra) { \
81 WL_ERROR(("%s: error : extra is null pointer\n", __func__)); \ 81 WL_ERROR("%s: error : extra is null pointer\n", __func__); \
82 return -EINVAL; \ 82 return -EINVAL; \
83} 83}
84 84
diff --git a/drivers/staging/brcm80211/include/bcm_rpc.h b/drivers/staging/brcm80211/include/bcm_rpc.h
deleted file mode 100644
index 77e5d8f71966..000000000000
--- a/drivers/staging/brcm80211/include/bcm_rpc.h
+++ /dev/null
@@ -1,79 +0,0 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _BCM_RPC_H_
18#define _BCM_RPC_H_
19
20#include <rpc_osl.h>
21
22typedef struct rpc_info rpc_info_t;
23typedef struct rpc_buf rpc_buf_t;
24struct rpc_transport_info;
25typedef void (*rpc_dispatch_cb_t) (void *ctx, struct rpc_buf *buf);
26typedef void (*rpc_resync_cb_t) (void *ctx);
27typedef void (*rpc_down_cb_t) (void *ctx);
28typedef void (*rpc_txdone_cb_t) (void *ctx, struct rpc_buf *buf);
29extern struct rpc_info *bcm_rpc_attach(void *pdev, osl_t *osh,
30 struct rpc_transport_info *rpc_th);
31
32extern void bcm_rpc_detach(struct rpc_info *rpc);
33extern void bcm_rpc_down(struct rpc_info *rpc);
34extern void bcm_rpc_watchdog(struct rpc_info *rpc);
35
36extern struct rpc_buf *bcm_rpc_buf_alloc(struct rpc_info *rpc, int len);
37extern void bcm_rpc_buf_free(struct rpc_info *rpc, struct rpc_buf *b);
38/* get rpc transport handle */
39extern struct rpc_transport_info *bcm_rpc_tp_get(struct rpc_info *rpc);
40
41/* callback for: data_rx, down, resync */
42extern void bcm_rpc_rxcb_init(struct rpc_info *rpc, void *ctx,
43 rpc_dispatch_cb_t cb, void *dnctx,
44 rpc_down_cb_t dncb, rpc_resync_cb_t resync_cb,
45 rpc_txdone_cb_t);
46extern void bcm_rpc_rxcb_deinit(struct rpc_info *rpci);
47
48/* HOST or CLIENT rpc call, requiring no return value */
49extern int bcm_rpc_call(struct rpc_info *rpc, struct rpc_buf *b);
50
51/* HOST rpc call, demanding return.
52 * The thread may be suspended and control returns back to OS
53 * The thread will resume(waked up) on either the return signal received or timeout
54 * The implementation details depend on OS
55 */
56extern struct rpc_buf *bcm_rpc_call_with_return(struct rpc_info *rpc,
57 struct rpc_buf *b);
58
59/* CLIENT rpc call to respond to bcm_rpc_call_with_return, requiring no return value */
60extern int bcm_rpc_call_return(struct rpc_info *rpc, struct rpc_buf *retb);
61
62extern uint bcm_rpc_buf_header_len(struct rpc_info *rpci);
63
64#define RPC_PKTLOG_SIZE 50 /* Depth of the history */
65#define RPC_PKTLOG_RD_LEN 3
66#define RPC_PKTLOG_DUMP_SIZE 150 /* dump size should be more than the product of above two */
67extern int bcm_rpc_pktlog_get(struct rpc_info *rpci, u32 *buf,
68 uint buf_size, bool send);
69extern int bcm_rpc_dump(rpc_info_t *rpci, struct bcmstrbuf *b);
70
71/* HIGH/BMAC: bit 15-8: RPC module, bit 7-0: TP module */
72#define RPC_ERROR_VAL 0x0001
73#define RPC_TRACE_VAL 0x0002
74#define RPC_PKTTRACE_VAL 0x0004
75#define RPC_PKTLOG_VAL 0x0008
76extern void bcm_rpc_msglevel_set(struct rpc_info *rpci, u16 msglevel,
77 bool high_low);
78
79#endif /* _BCM_RPC_H_ */
diff --git a/drivers/staging/brcm80211/include/bcm_rpc_tp.h b/drivers/staging/brcm80211/include/bcm_rpc_tp.h
deleted file mode 100644
index bb8dc6dd6f44..000000000000
--- a/drivers/staging/brcm80211/include/bcm_rpc_tp.h
+++ /dev/null
@@ -1,137 +0,0 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _bcm_rpc_tp_h_
18#define _bcm_rpc_tp_h_
19#include <bcm_rpc.h>
20
21#define DBUS_RX_BUFFER_SIZE_RPC (2100) /* rxbufsize for dbus_attach, linux only for now */
22
23#define BCM_RPC_TP_ENCAP_LEN 4 /* TP header is 4 bytes */
24
25#define BCM_RPC_TP_HOST_AGG_MASK 0xffff0000
26#define BCM_RPC_TP_HOST_AGG_SHIFT 16
27#define BCM_RPC_TP_HOST_AGG_AMPDU 0x00010000 /* HOST->DNGL ampdu aggregation */
28#define BCM_RPC_TP_HOST_AGG_TEST 0x00100000 /* HOST->DNGL test aggregation */
29#define BCM_RPC_TP_DNGL_AGG_MASK 0x0000ffff
30#define BCM_RPC_TP_DNGL_AGG_DPC 0x00000001 /* DNGL->HOST data aggregation */
31#define BCM_RPC_TP_DNGL_AGG_FLOWCTL 0x00000002 /* DNGL->HOST tx flowcontrol agg */
32#define BCM_RPC_TP_DNGL_AGG_TEST 0x00000010 /* DNGL->HOST test agg */
33
34#define BCM_RPC_TP_DNGL_AGG_MAX_SFRAME 3 /* max agg subframes, must be <= USB_NTXD */
35#define BCM_RPC_TP_DNGL_AGG_MAX_BYTE 4000 /* max agg bytes */
36
37#define BCM_RPC_TP_HOST_AGG_MAX_SFRAME 3 /* max agg subframes, AMPDU only, 3 is enough */
38#define BCM_RPC_TP_HOST_AGG_MAX_BYTE 3400 /* max agg bytes; to fit 2+ tcp/udp pkts. Each one:
39 * 802.3pkt + 802.11 hdr + rpc hdr + tp hdr < 1700B
40 * Need to be in sync with dongle usb rx dma
41 * rxbufsize(USBBULK_RXBUF_GIANT in usbdev_sb.c)
42 */
43/* TP-DBUS pkts flowcontrol */
44#define BCM_RPC_TP_DBUS_NTXQ 50 /* queue size for TX on bulk OUT, aggregation possible */
45#define BCM_RPC_TP_DBUS_NRXQ 50 /* queue size for RX on bulk IN, aggregation possible */
46#define BCM_RPC_TP_DBUS_NRXQ_CTRL 1 /* queue size for RX on ctl EP0 */
47
48#define BCM_RPC_TP_DBUS_NRXQ_PKT (BCM_RPC_TP_DBUS_NRXQ * BCM_RPC_TP_DNGL_AGG_MAX_SFRAME)
49#define BCM_RPC_TP_DBUS_NTXQ_PKT (BCM_RPC_TP_DBUS_NTXQ * BCM_RPC_TP_HOST_AGG_MAX_SFRAME)
50
51typedef struct rpc_transport_info rpc_tp_info_t;
52
53typedef void (*rpc_tx_complete_fn_t) (void *, rpc_buf_t *, int status);
54typedef void (*rpc_rx_fn_t) (void *, rpc_buf_t *);
55
56#ifdef WLC_LOW
57typedef void (*rpc_txflowctl_cb_t) (void *ctx, bool on);
58#endif
59
60extern rpc_tp_info_t *bcm_rpc_tp_attach(osl_t *osh, void *bus);
61extern void bcm_rpc_tp_detach(rpc_tp_info_t *rpcb);
62extern void bcm_rpc_tp_down(rpc_tp_info_t *rpcb);
63extern void bcm_rpc_tp_watchdog(rpc_tp_info_t *rpcb);
64
65extern int bcm_rpc_tp_buf_send(rpc_tp_info_t *rpcb, rpc_buf_t *buf);
66
67/* callback for tx_complete, rx_pkt */
68extern void bcm_rpc_tp_register_cb(rpc_tp_info_t *rpcb,
69 rpc_tx_complete_fn_t txcmplt,
70 void *tx_context, rpc_rx_fn_t rxpkt,
71 void *rx_context, rpc_osl_t *rpc_osh);
72extern void bcm_rpc_tp_deregister_cb(rpc_tp_info_t *rpcb);
73
74/* Buffer manipulation */
75extern uint bcm_rpc_buf_tp_header_len(rpc_tp_info_t *rpcb);
76extern rpc_buf_t *bcm_rpc_tp_buf_alloc(rpc_tp_info_t *rpcb, int len);
77extern void bcm_rpc_tp_buf_free(rpc_tp_info_t *rpcb, rpc_buf_t *buf);
78extern int bcm_rpc_buf_len_get(rpc_tp_info_t *rpcb, rpc_buf_t *b);
79extern int bcm_rpc_buf_len_set(rpc_tp_info_t *rpcb, rpc_buf_t *b, uint len);
80extern rpc_buf_t *bcm_rpc_buf_next_get(rpc_tp_info_t *rpcb, rpc_buf_t *b);
81extern void bcm_rpc_buf_next_set(rpc_tp_info_t *rpcb, rpc_buf_t *b,
82 rpc_buf_t *nextb);
83extern unsigned char *bcm_rpc_buf_data(rpc_tp_info_t *rpcb, rpc_buf_t *b);
84extern unsigned char *bcm_rpc_buf_push(rpc_tp_info_t *rpcb, rpc_buf_t *b,
85 uint delta);
86extern unsigned char *bcm_rpc_buf_pull(rpc_tp_info_t *rpcb, rpc_buf_t *b,
87 uint delta);
88extern void bcm_rpc_tp_buf_release(rpc_tp_info_t *rpcb, rpc_buf_t *buf);
89extern void bcm_rpc_tp_buf_cnt_adjust(rpc_tp_info_t *rpcb, int adjust);
90/* RPC call_with_return */
91extern int bcm_rpc_tp_recv_rtn(rpc_tp_info_t *rpcb);
92extern int bcm_rpc_tp_get_device_speed(rpc_tp_info_t *rpc_th);
93#ifdef BCMDBG
94extern int bcm_rpc_tp_dump(rpc_tp_info_t *rpcb, struct bcmstrbuf *b);
95#endif
96
97#ifdef WLC_LOW
98/* intercept USB pkt to parse RPC header: USB driver rx-> wl_send -> this -> wl driver */
99extern void bcm_rpc_tp_rx_from_dnglbus(rpc_tp_info_t *rpc_th, struct lbuf *lb);
100
101/* RPC callreturn pkt, go to USB driver tx */
102extern int bcm_rpc_tp_send_callreturn(rpc_tp_info_t *rpc_th, rpc_buf_t *b);
103
104extern void bcm_rpc_tp_dump(rpc_tp_info_t *rpcb);
105extern void bcm_rpc_tp_txflowctl(rpc_tp_info_t *rpcb, bool state, int prio);
106extern void bcm_rpc_tp_txflowctlcb_init(rpc_tp_info_t *rpc_th, void *ctx,
107 rpc_txflowctl_cb_t cb);
108extern void bcm_rpc_tp_txflowctlcb_deinit(rpc_tp_info_t *rpc_th);
109extern void bcm_rpc_tp_txq_wm_set(rpc_tp_info_t *rpc_th, u8 hiwm,
110 u8 lowm);
111extern void bcm_rpc_tp_txq_wm_get(rpc_tp_info_t *rpc_th, u8 *hiwm,
112 u8 *lowm);
113#endif /* WLC_LOW */
114
115extern void bcm_rpc_tp_agg_set(rpc_tp_info_t *rpcb, u32 reason, bool set);
116extern void bcm_rpc_tp_agg_limit_set(rpc_tp_info_t *rpc_th, u8 sf,
117 u16 bytes);
118extern void bcm_rpc_tp_agg_limit_get(rpc_tp_info_t *rpc_th, u8 *sf,
119 u16 *bytes);
120
121#define BCM_RPC_TP_MSG_LEVEL_MASK 0x00ff
122/* dongle msg level */
123#define RPC_TP_MSG_DNGL_ERR_VAL 0x0001 /* DNGL TP error msg */
124#define RPC_TP_MSG_DNGL_DBG_VAL 0x0002 /* DNGL TP dbg msg */
125#define RPC_TP_MSG_DNGL_AGG_VAL 0x0004 /* DNGL TP agg msg */
126#define RPC_TP_MSG_DNGL_DEA_VAL 0x0008 /* DNGL TP deag msg */
127
128/* host msg level */
129#define RPC_TP_MSG_HOST_ERR_VAL 0x0001 /* DNGL TP error msg */
130#define RPC_TP_MSG_HOST_DBG_VAL 0x0002 /* DNGL TP dbg msg */
131#define RPC_TP_MSG_HOST_AGG_VAL 0x0004 /* DNGL TP agg msg */
132#define RPC_TP_MSG_HOST_DEA_VAL 0x0008 /* DNGL TP deag msg */
133
134extern void bcm_rpc_tp_msglevel_set(rpc_tp_info_t *rpc_th, u8 msglevel,
135 bool high_low);
136
137#endif /* _bcm_rpc_tp_h_ */
diff --git a/drivers/staging/brcm80211/include/bcm_xdr.h b/drivers/staging/brcm80211/include/bcm_xdr.h
deleted file mode 100644
index 50fbd78a8804..000000000000
--- a/drivers/staging/brcm80211/include/bcm_xdr.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _BCM_XDR_H
18#define _BCM_XDR_H
19
20/*
21 * bcm_xdr_buf_t
22 * Structure used for bookkeeping of a buffer being packed or unpacked.
23 * Keeps a current read/write pointer and size as well as
24 * the original buffer pointer and size.
25 *
26 */
27typedef struct {
28 u8 *buf; /* pointer to current position in origbuf */
29 uint size; /* current (residual) size in bytes */
30 u8 *origbuf; /* unmodified pointer to orignal buffer */
31 uint origsize; /* unmodified orignal buffer size in bytes */
32} bcm_xdr_buf_t;
33
34void bcm_xdr_buf_init(bcm_xdr_buf_t *b, void *buf, size_t len);
35
36int bcm_xdr_pack_u32(bcm_xdr_buf_t *b, u32 val);
37int bcm_xdr_unpack_u32(bcm_xdr_buf_t *b, u32 *pval);
38int bcm_xdr_pack_s32(bcm_xdr_buf_t *b, s32 val);
39int bcm_xdr_unpack_s32(bcm_xdr_buf_t *b, s32 *pval);
40int bcm_xdr_pack_s8(bcm_xdr_buf_t *b, s8 val);
41int bcm_xdr_unpack_s8(bcm_xdr_buf_t *b, s8 *pval);
42int bcm_xdr_pack_opaque(bcm_xdr_buf_t *b, uint len, void *data);
43int bcm_xdr_unpack_opaque(bcm_xdr_buf_t *b, uint len, void **pdata);
44int bcm_xdr_unpack_opaque_cpy(bcm_xdr_buf_t *b, uint len, void *data);
45int bcm_xdr_pack_opaque_varlen(bcm_xdr_buf_t *b, uint len, void *data);
46int bcm_xdr_unpack_opaque_varlen(bcm_xdr_buf_t *b, uint *plen, void **pdata);
47int bcm_xdr_pack_string(bcm_xdr_buf_t *b, char *str);
48int bcm_xdr_unpack_string(bcm_xdr_buf_t *b, uint *plen, char **pstr);
49
50int bcm_xdr_pack_u8_vec(bcm_xdr_buf_t *, u8 *vec, u32 elems);
51int bcm_xdr_unpack_u8_vec(bcm_xdr_buf_t *, u8 *vec, u32 elems);
52int bcm_xdr_pack_u16_vec(bcm_xdr_buf_t *b, uint len, void *vec);
53int bcm_xdr_unpack_u16_vec(bcm_xdr_buf_t *b, uint len, void *vec);
54int bcm_xdr_pack_u32_vec(bcm_xdr_buf_t *b, uint len, void *vec);
55int bcm_xdr_unpack_u32_vec(bcm_xdr_buf_t *b, uint len, void *vec);
56
57int bcm_xdr_pack_opaque_raw(bcm_xdr_buf_t *b, uint len, void *data);
58int bcm_xdr_pack_opaque_pad(bcm_xdr_buf_t *b);
59
60#endif /* _BCM_XDR_H */
diff --git a/drivers/staging/brcm80211/include/bcmdefs.h b/drivers/staging/brcm80211/include/bcmdefs.h
index dc52e9dbb8b5..74601fc971c9 100644
--- a/drivers/staging/brcm80211/include/bcmdefs.h
+++ b/drivers/staging/brcm80211/include/bcmdefs.h
@@ -42,9 +42,6 @@
42#define BCMFASTPATH 42#define BCMFASTPATH
43#endif 43#endif
44 44
45/* Put some library data/code into ROM to reduce RAM requirements */
46#define BCMROMFN(_fn) _fn
47
48/* Bus types */ 45/* Bus types */
49#define SI_BUS 0 /* SOC Interconnect */ 46#define SI_BUS 0 /* SOC Interconnect */
50#define PCI_BUS 1 /* PCI target */ 47#define PCI_BUS 1 /* PCI target */
@@ -54,35 +51,6 @@
54#define SPI_BUS 6 /* gSPI target */ 51#define SPI_BUS 6 /* gSPI target */
55#define RPC_BUS 7 /* RPC target */ 52#define RPC_BUS 7 /* RPC target */
56 53
57/* Allows size optimization for single-bus image */
58#ifdef BCMBUSTYPE
59#define BUSTYPE(bus) (BCMBUSTYPE)
60#else
61#define BUSTYPE(bus) (bus)
62#endif
63
64/* Allows size optimization for single-backplane image */
65#ifdef BCMCHIPTYPE
66#define CHIPTYPE(bus) (BCMCHIPTYPE)
67#else
68#define CHIPTYPE(bus) (bus)
69#endif
70
71/* Allows size optimization for SPROM support */
72#define SPROMBUS (PCI_BUS)
73
74/* Allows size optimization for single-chip image */
75#ifdef BCMCHIPID
76#define CHIPID(chip) (BCMCHIPID)
77#else
78#define CHIPID(chip) (chip)
79#endif
80
81#ifdef BCMCHIPREV
82#define CHIPREV(rev) (BCMCHIPREV)
83#else
84#define CHIPREV(rev) (rev)
85#endif
86 54
87/* Defines for DMA Address Width - Shared between OSL and HNDDMA */ 55/* Defines for DMA Address Width - Shared between OSL and HNDDMA */
88#define DMADDR_MASK_32 0x0 /* Address mask for 32-bits */ 56#define DMADDR_MASK_32 0x0 /* Address mask for 32-bits */
@@ -146,31 +114,11 @@ typedef struct {
146 114
147#define BCMEXTRAHDROOM 172 115#define BCMEXTRAHDROOM 172
148 116
149/* Headroom required for dongle-to-host communication. Packets allocated
150 * locally in the dongle (e.g. for CDC ioctls or RNDIS messages) should
151 * leave this much room in front for low-level message headers which may
152 * be needed to get across the dongle bus to the host. (These messages
153 * don't go over the network, so room for the full WL header above would
154 * be a waste.).
155*/
156#define BCMDONGLEHDRSZ 12
157#define BCMDONGLEPADSZ 16
158
159#define BCMDONGLEOVERHEAD (BCMDONGLEHDRSZ + BCMDONGLEPADSZ)
160
161#ifdef BCMDBG 117#ifdef BCMDBG
162
163#define BCMDBG_ERR
164
165#ifndef BCMDBG_ASSERT 118#ifndef BCMDBG_ASSERT
166#define BCMDBG_ASSERT 119#define BCMDBG_ASSERT
167#endif /* BCMDBG_ASSERT */ 120#endif /* BCMDBG_ASSERT */
168 121#endif /* BCMDBG */
169#endif /* BCMDBG */
170
171#if defined(BCMDBG_ASSERT)
172#define BCMASSERT_SUPPORT
173#endif
174 122
175/* Macros for doing definition and get/set of bitfields 123/* Macros for doing definition and get/set of bitfields
176 * Usage example, e.g. a three-bit field (bits 4-6): 124 * Usage example, e.g. a three-bit field (bits 4-6):
@@ -190,11 +138,10 @@ typedef struct {
190 (((val) & (~(field ## _M << field ## _S))) | \ 138 (((val) & (~(field ## _M << field ## _S))) | \
191 ((unsigned)(bits) << field ## _S)) 139 ((unsigned)(bits) << field ## _S))
192 140
193/* define BCMSMALL to remove misc features for memory-constrained environments */
194#define BCMSPACE
195#define bcmspace true /* if (bcmspace) code is retained */
196
197/* Max. nvram variable table size */ 141/* Max. nvram variable table size */
198#define MAXSZ_NVRAM_VARS 4096 142#define MAXSZ_NVRAM_VARS 4096
199 143
144/* handle forward declaration */
145struct wl_info;
146
200#endif /* _bcmdefs_h_ */ 147#endif /* _bcmdefs_h_ */
diff --git a/drivers/staging/brcm80211/include/bcmsdbus.h b/drivers/staging/brcm80211/include/bcmsdbus.h
index ca99495eaa89..89059dd8088b 100644
--- a/drivers/staging/brcm80211/include/bcmsdbus.h
+++ b/drivers/staging/brcm80211/include/bcmsdbus.h
@@ -46,8 +46,8 @@ typedef void (*sdioh_cb_fn_t) (void *);
46 * The handler shall be provided by all subsequent calls. No local cache 46 * The handler shall be provided by all subsequent calls. No local cache
47 * cfghdl points to the starting address of pci device mapped memory 47 * cfghdl points to the starting address of pci device mapped memory
48 */ 48 */
49extern sdioh_info_t *sdioh_attach(osl_t *osh, void *cfghdl, uint irq); 49extern sdioh_info_t *sdioh_attach(struct osl_info *osh, void *cfghdl, uint irq);
50extern SDIOH_API_RC sdioh_detach(osl_t *osh, sdioh_info_t *si); 50extern SDIOH_API_RC sdioh_detach(struct osl_info *osh, sdioh_info_t *si);
51extern SDIOH_API_RC sdioh_interrupt_register(sdioh_info_t *si, 51extern SDIOH_API_RC sdioh_interrupt_register(sdioh_info_t *si,
52 sdioh_cb_fn_t fn, void *argh); 52 sdioh_cb_fn_t fn, void *argh);
53extern SDIOH_API_RC sdioh_interrupt_deregister(sdioh_info_t *si); 53extern SDIOH_API_RC sdioh_interrupt_deregister(sdioh_info_t *si);
@@ -79,7 +79,7 @@ extern SDIOH_API_RC sdioh_request_buffer(sdioh_info_t *si, uint pio_dma,
79 uint fix_inc, uint rw, uint fnc_num, 79 uint fix_inc, uint rw, uint fnc_num,
80 u32 addr, uint regwidth, 80 u32 addr, uint regwidth,
81 u32 buflen, u8 *buffer, 81 u32 buflen, u8 *buffer,
82 void *pkt); 82 struct sk_buff *pkt);
83 83
84/* get cis data */ 84/* get cis data */
85extern SDIOH_API_RC sdioh_cis_read(sdioh_info_t *si, uint fuc, u8 *cis, 85extern SDIOH_API_RC sdioh_cis_read(sdioh_info_t *si, uint fuc, u8 *cis,
diff --git a/drivers/staging/brcm80211/include/bcmsdh.h b/drivers/staging/brcm80211/include/bcmsdh.h
index 6b80983d43c9..0e1f79919c9c 100644
--- a/drivers/staging/brcm80211/include/bcmsdh.h
+++ b/drivers/staging/brcm80211/include/bcmsdh.h
@@ -40,11 +40,11 @@ typedef void (*bcmsdh_cb_fn_t) (void *);
40 * implementation may maintain a single "default" handle (e.g. the first or 40 * implementation may maintain a single "default" handle (e.g. the first or
41 * most recent one) to enable single-instance implementations to pass NULL. 41 * most recent one) to enable single-instance implementations to pass NULL.
42 */ 42 */
43extern bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva, 43extern bcmsdh_info_t *bcmsdh_attach(struct osl_info *osh, void *cfghdl,
44 uint irq); 44 void **regsva, uint irq);
45 45
46/* Detach - freeup resources allocated in attach */ 46/* Detach - freeup resources allocated in attach */
47extern int bcmsdh_detach(osl_t *osh, void *sdh); 47extern int bcmsdh_detach(struct osl_info *osh, void *sdh);
48 48
49/* Query if SD device interrupts are enabled */ 49/* Query if SD device interrupts are enabled */
50extern bool bcmsdh_intr_query(void *sdh); 50extern bool bcmsdh_intr_query(void *sdh);
@@ -122,7 +122,7 @@ extern int bcmsdh_send_buf(void *sdh, u32 addr, uint fn, uint flags,
122 u8 *buf, uint nbytes, void *pkt, 122 u8 *buf, uint nbytes, void *pkt,
123 bcmsdh_cmplt_fn_t complete, void *handle); 123 bcmsdh_cmplt_fn_t complete, void *handle);
124extern int bcmsdh_recv_buf(void *sdh, u32 addr, uint fn, uint flags, 124extern int bcmsdh_recv_buf(void *sdh, u32 addr, uint fn, uint flags,
125 u8 *buf, uint nbytes, void *pkt, 125 u8 *buf, uint nbytes, struct sk_buff *pkt,
126 bcmsdh_cmplt_fn_t complete, void *handle); 126 bcmsdh_cmplt_fn_t complete, void *handle);
127 127
128/* Flags bits */ 128/* Flags bits */
@@ -174,8 +174,8 @@ extern void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh);
174typedef struct { 174typedef struct {
175 /* attach to device */ 175 /* attach to device */
176 void *(*attach) (u16 vend_id, u16 dev_id, u16 bus, u16 slot, 176 void *(*attach) (u16 vend_id, u16 dev_id, u16 bus, u16 slot,
177 u16 func, uint bustype, void *regsva, osl_t *osh, 177 u16 func, uint bustype, void *regsva,
178 void *param); 178 struct osl_info *osh, void *param);
179 /* detach from device */ 179 /* detach from device */
180 void (*detach) (void *ch); 180 void (*detach) (void *ch);
181} bcmsdh_driver_t; 181} bcmsdh_driver_t;
diff --git a/drivers/staging/brcm80211/include/bcmsdh_sdmmc.h b/drivers/staging/brcm80211/include/bcmsdh_sdmmc.h
index 7d5aa71a7dc7..4d671ddb3af1 100644
--- a/drivers/staging/brcm80211/include/bcmsdh_sdmmc.h
+++ b/drivers/staging/brcm80211/include/bcmsdh_sdmmc.h
@@ -51,7 +51,7 @@ extern void sdioh_sdmmc_osfree(sdioh_info_t *sd);
51#define CLIENT_INTR 0x100 /* Get rid of this! */ 51#define CLIENT_INTR 0x100 /* Get rid of this! */
52 52
53struct sdioh_info { 53struct sdioh_info {
54 osl_t *osh; /* osh handler */ 54 struct osl_info *osh; /* osh handler */
55 bool client_intr_enabled; /* interrupt connnected flag */ 55 bool client_intr_enabled; /* interrupt connnected flag */
56 bool intr_handler_valid; /* client driver interrupt handler valid */ 56 bool intr_handler_valid; /* client driver interrupt handler valid */
57 sdioh_cb_fn_t intr_handler; /* registered interrupt handler */ 57 sdioh_cb_fn_t intr_handler; /* registered interrupt handler */
@@ -94,8 +94,8 @@ extern void sdioh_sdmmc_devintr_off(sdioh_info_t *sd);
94 */ 94 */
95 95
96/* Register mapping routines */ 96/* Register mapping routines */
97extern u32 *sdioh_sdmmc_reg_map(osl_t *osh, s32 addr, int size); 97extern u32 *sdioh_sdmmc_reg_map(struct osl_info *osh, s32 addr, int size);
98extern void sdioh_sdmmc_reg_unmap(osl_t *osh, s32 addr, int size); 98extern void sdioh_sdmmc_reg_unmap(struct osl_info *osh, s32 addr, int size);
99 99
100/* Interrupt (de)registration routines */ 100/* Interrupt (de)registration routines */
101extern int sdioh_sdmmc_register_irq(sdioh_info_t *sd, uint irq); 101extern int sdioh_sdmmc_register_irq(sdioh_info_t *sd, uint irq);
diff --git a/drivers/staging/brcm80211/include/bcmsrom.h b/drivers/staging/brcm80211/include/bcmsrom.h
index 9d53657fdaa1..cdcef746284f 100644
--- a/drivers/staging/brcm80211/include/bcmsrom.h
+++ b/drivers/staging/brcm80211/include/bcmsrom.h
@@ -20,15 +20,15 @@
20#include <bcmsrom_fmt.h> 20#include <bcmsrom_fmt.h>
21 21
22/* Prototypes */ 22/* Prototypes */
23extern int srom_var_init(si_t *sih, uint bus, void *curmap, osl_t *osh, 23extern int srom_var_init(si_t *sih, uint bus, void *curmap,
24 char **vars, uint *count); 24 struct osl_info *osh, char **vars, uint *count);
25 25
26extern int srom_read(si_t *sih, uint bus, void *curmap, osl_t *osh, 26extern int srom_read(si_t *sih, uint bus, void *curmap, struct osl_info *osh,
27 uint byteoff, uint nbytes, u16 *buf, bool check_crc); 27 uint byteoff, uint nbytes, u16 *buf, bool check_crc);
28 28
29/* parse standard PCMCIA cis, normally used by SB/PCMCIA/SDIO/SPI/OTP 29/* parse standard PCMCIA cis, normally used by SB/PCMCIA/SDIO/SPI/OTP
30 * and extract from it into name=value pairs 30 * and extract from it into name=value pairs
31 */ 31 */
32extern int srom_parsecis(osl_t *osh, u8 **pcis, uint ciscnt, 32extern int srom_parsecis(struct osl_info *osh, u8 **pcis, uint ciscnt,
33 char **vars, uint *count); 33 char **vars, uint *count);
34#endif /* _bcmsrom_h_ */ 34#endif /* _bcmsrom_h_ */
diff --git a/drivers/staging/brcm80211/include/bcmutils.h b/drivers/staging/brcm80211/include/bcmutils.h
index b53315981be0..a8f76d8199ff 100644
--- a/drivers/staging/brcm80211/include/bcmutils.h
+++ b/drivers/staging/brcm80211/include/bcmutils.h
@@ -30,7 +30,6 @@
30 }; 30 };
31 31
32/* ** driver-only section ** */ 32/* ** driver-only section ** */
33#include <osl.h>
34 33
35#define GPIO_PIN_NOTDEFINED 0x20 /* Pin not defined */ 34#define GPIO_PIN_NOTDEFINED 0x20 /* Pin not defined */
36 35
@@ -56,10 +55,10 @@
56#endif 55#endif
57 56
58 typedef struct pktq_prec { 57 typedef struct pktq_prec {
59 void *head; /* first packet to dequeue */ 58 struct sk_buff *head; /* first packet to dequeue */
60 void *tail; /* last packet to dequeue */ 59 struct sk_buff *tail; /* last packet to dequeue */
61 u16 len; /* number of queued packets */ 60 u16 len; /* number of queued packets */
62 u16 max; /* maximum number of queued packets */ 61 u16 max; /* maximum number of queued packets */
63 } pktq_prec_t; 62 } pktq_prec_t;
64 63
65/* multi-priority pkt queue */ 64/* multi-priority pkt queue */
@@ -105,23 +104,26 @@
105#define pktq_ppeek(pq, prec) ((pq)->q[prec].head) 104#define pktq_ppeek(pq, prec) ((pq)->q[prec].head)
106#define pktq_ppeek_tail(pq, prec) ((pq)->q[prec].tail) 105#define pktq_ppeek_tail(pq, prec) ((pq)->q[prec].tail)
107 106
108 extern void *pktq_penq(struct pktq *pq, int prec, void *p); 107extern struct sk_buff *pktq_penq(struct pktq *pq, int prec,
109 extern void *pktq_penq_head(struct pktq *pq, int prec, void *p); 108 struct sk_buff *p);
110 extern void *pktq_pdeq(struct pktq *pq, int prec); 109extern struct sk_buff *pktq_penq_head(struct pktq *pq, int prec,
111 extern void *pktq_pdeq_tail(struct pktq *pq, int prec); 110 struct sk_buff *p);
111extern struct sk_buff *pktq_pdeq(struct pktq *pq, int prec);
112extern struct sk_buff *pktq_pdeq_tail(struct pktq *pq, int prec);
113
112/* Empty the queue at particular precedence level */ 114/* Empty the queue at particular precedence level */
113#ifdef BRCM_FULLMAC 115#ifdef BRCM_FULLMAC
114 extern void pktq_pflush(osl_t *osh, struct pktq *pq, int prec, 116 extern void pktq_pflush(struct osl_info *osh, struct pktq *pq, int prec,
115 bool dir); 117 bool dir);
116#else 118#else
117 extern void pktq_pflush(osl_t *osh, struct pktq *pq, int prec, 119 extern void pktq_pflush(struct osl_info *osh, struct pktq *pq, int prec,
118 bool dir, ifpkt_cb_t fn, int arg); 120 bool dir, ifpkt_cb_t fn, int arg);
119#endif /* BRCM_FULLMAC */ 121#endif /* BRCM_FULLMAC */
120 122
121/* operations on a set of precedences in packet queue */ 123/* operations on a set of precedences in packet queue */
122 124
123 extern int pktq_mlen(struct pktq *pq, uint prec_bmp); 125extern int pktq_mlen(struct pktq *pq, uint prec_bmp);
124 extern void *pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out); 126extern struct sk_buff *pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out);
125 127
126/* operations on packet queue as a whole */ 128/* operations on packet queue as a whole */
127 129
@@ -140,20 +142,19 @@
140 142
141 extern void pktq_init(struct pktq *pq, int num_prec, int max_len); 143 extern void pktq_init(struct pktq *pq, int num_prec, int max_len);
142/* prec_out may be NULL if caller is not interested in return value */ 144/* prec_out may be NULL if caller is not interested in return value */
143 extern void *pktq_peek_tail(struct pktq *pq, int *prec_out); 145 extern struct sk_buff *pktq_peek_tail(struct pktq *pq, int *prec_out);
144#ifdef BRCM_FULLMAC 146#ifdef BRCM_FULLMAC
145 extern void pktq_flush(osl_t *osh, struct pktq *pq, bool dir); 147 extern void pktq_flush(struct osl_info *osh, struct pktq *pq, bool dir);
146#else 148#else
147 extern void pktq_flush(osl_t *osh, struct pktq *pq, bool dir, 149 extern void pktq_flush(struct osl_info *osh, struct pktq *pq, bool dir,
148 ifpkt_cb_t fn, int arg); 150 ifpkt_cb_t fn, int arg);
149#endif 151#endif
150 152
151/* externs */ 153/* externs */
152/* packet */ 154/* packet */
153 extern uint pktfrombuf(osl_t *osh, void *p, uint offset, int len, 155 extern uint pktfrombuf(struct osl_info *osh, struct sk_buff *p,
154 unsigned char *buf); 156 uint offset, int len, unsigned char *buf);
155 extern uint pktsegcnt(osl_t *osh, void *p); 157 extern uint pkttotlen(struct osl_info *osh, struct sk_buff *p);
156 extern uint pkttotlen(osl_t *osh, void *p);
157 158
158/* ethernet address */ 159/* ethernet address */
159 extern int bcm_ether_atoe(char *p, struct ether_addr *ea); 160 extern int bcm_ether_atoe(char *p, struct ether_addr *ea);
@@ -166,7 +167,8 @@
166 extern char *getvar(char *vars, const char *name); 167 extern char *getvar(char *vars, const char *name);
167 extern int getintvar(char *vars, const char *name); 168 extern int getintvar(char *vars, const char *name);
168#ifdef BCMDBG 169#ifdef BCMDBG
169 extern void prpkt(const char *msg, osl_t *osh, void *p0); 170 extern void prpkt(const char *msg, struct osl_info *osh,
171 struct sk_buff *p0);
170#endif /* BCMDBG */ 172#endif /* BCMDBG */
171#define bcm_perf_enable() 173#define bcm_perf_enable()
172#define bcmstats(fmt) 174#define bcmstats(fmt)
@@ -359,7 +361,21 @@
359#define CEIL(x, y) (((x) + ((y)-1)) / (y)) 361#define CEIL(x, y) (((x) + ((y)-1)) / (y))
360#define ISPOWEROF2(x) ((((x)-1)&(x)) == 0) 362#define ISPOWEROF2(x) ((((x)-1)&(x)) == 0)
361 363
362/* bit map related macros */ 364/* map physical to virtual I/O */
365#if !defined(CONFIG_MMC_MSM7X00A)
366#define REG_MAP(pa, size) ioremap_nocache((unsigned long)(pa), \
367 (unsigned long)(size))
368#else
369#define REG_MAP(pa, size) (void *)(0)
370#endif
371
372/* Register operations */
373#define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v))
374#define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v))
375
376#define SET_REG(osh, r, mask, val) \
377 W_REG((osh), (r), ((R_REG((osh), r) & ~(mask)) | (val)))
378
363#ifndef setbit 379#ifndef setbit
364#ifndef NBBY /* the BSD family defines NBBY */ 380#ifndef NBBY /* the BSD family defines NBBY */
365#define NBBY 8 /* 8 bits per byte */ 381#define NBBY 8 /* 8 bits per byte */
diff --git a/drivers/staging/brcm80211/include/d11.h b/drivers/staging/brcm80211/include/d11.h
index c07548c70e30..be2d4970407c 100644
--- a/drivers/staging/brcm80211/include/d11.h
+++ b/drivers/staging/brcm80211/include/d11.h
@@ -17,13 +17,6 @@
17#ifndef _D11_H 17#ifndef _D11_H
18#define _D11_H 18#define _D11_H
19 19
20#include <bcmdefs.h>
21#include <bcmdevs.h>
22#include <hndsoc.h>
23#include <sbhndpio.h>
24#include <sbhnddma.h>
25#include <proto/802.11.h>
26
27/* This marks the start of a packed structure section. */ 20/* This marks the start of a packed structure section. */
28#include <packed_section_start.h> 21#include <packed_section_start.h>
29 22
diff --git a/drivers/staging/brcm80211/include/dbus.h b/drivers/staging/brcm80211/include/dbus.h
deleted file mode 100644
index 81ffea79d008..000000000000
--- a/drivers/staging/brcm80211/include/dbus.h
+++ /dev/null
@@ -1,353 +0,0 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef __DBUS_H__
18#define __DBUS_H__
19
20#ifdef BCMDBG
21#define DBUSERR(args) do { if (net_ratelimit()) printf args; } while (0)
22#define DBUSTRACE(args)
23#define DBUSDBGLOCK(args)
24
25#else
26#define DBUSTRACE(args)
27#define DBUSERR(args)
28#define DBUSDBGLOCK(args)
29#endif
30
31enum {
32 DBUS_OK = 0,
33 DBUS_ERR = -200,
34 DBUS_ERR_TIMEOUT,
35 DBUS_ERR_DISCONNECT,
36 DBUS_ERR_NODEVICE,
37 DBUS_ERR_UNSUPPORTED,
38 DBUS_ERR_PENDING,
39 DBUS_ERR_NOMEM,
40 DBUS_ERR_TXFAIL,
41 DBUS_ERR_TXTIMEOUT,
42 DBUS_ERR_TXDROP,
43 DBUS_ERR_RXFAIL,
44 DBUS_ERR_RXDROP,
45 DBUS_ERR_TXCTLFAIL,
46 DBUS_ERR_RXCTLFAIL,
47 DBUS_ERR_REG_PARAM,
48 DBUS_STATUS_CANCELLED
49};
50
51#define ERR_CBMASK_TXFAIL 0x00000001
52#define ERR_CBMASK_RXFAIL 0x00000002
53#define ERR_CBMASK_ALL 0xFFFFFFFF
54
55#define DBUS_CBCTL_WRITE 0
56#define DBUS_CBCTL_READ 1
57
58#define DBUS_TX_RETRY_LIMIT 3 /* retries for failed txirb */
59#define DBUS_TX_TIMEOUT_INTERVAL 250 /* timeout for txirb complete, in ms */
60
61#define DBUS_BUFFER_SIZE_TX 5000
62#define DBUS_BUFFER_SIZE_RX 5000
63
64#define DBUS_BUFFER_SIZE_TX_NOAGG 2048
65#define DBUS_BUFFER_SIZE_RX_NOAGG 2048
66
67/* DBUS types */
68enum {
69 DBUS_USB,
70 DBUS_SDIO,
71 DBUS_SPI,
72 DBUS_UNKNOWN
73};
74
75enum dbus_state {
76 DBUS_STATE_DL_PENDING,
77 DBUS_STATE_DL_DONE,
78 DBUS_STATE_UP,
79 DBUS_STATE_DOWN,
80 DBUS_STATE_PNP_FWDL,
81 DBUS_STATE_DISCONNECT
82};
83
84enum dbus_pnp_state {
85 DBUS_PNP_DISCONNECT,
86 DBUS_PNP_SLEEP,
87 DBUS_PNP_RESUME
88};
89
90typedef enum _DEVICE_SPEED {
91 INVALID_SPEED = -1,
92 LOW_SPEED = 1, /* USB 1.1: 1.5 Mbps */
93 FULL_SPEED, /* USB 1.1: 12 Mbps */
94 HIGH_SPEED, /* USB 2.0: 480 Mbps */
95 SUPER_SPEED, /* USB 3.0: 4.8 Gbps */
96} DEVICE_SPEED;
97
98typedef struct {
99 int bustype;
100 int vid;
101 int pid;
102 int devid;
103 int chiprev; /* chip revsion number */
104 int mtu;
105 int nchan; /* Data Channels */
106} dbus_attrib_t;
107
108/* FIX: Account for errors related to DBUS;
109 * Let upper layer account for packets/bytes
110 */
111typedef struct {
112 u32 rx_errors;
113 u32 tx_errors;
114 u32 rx_dropped;
115 u32 tx_dropped;
116} dbus_stats_t;
117
118/*
119 * Configurable BUS parameters
120 */
121typedef struct {
122 bool rxctl_deferrespok;
123} dbus_config_t;
124
125struct dbus_callbacks;
126struct exec_parms;
127
128typedef void *(*probe_cb_t) (void *arg, const char *desc, u32 bustype,
129 u32 hdrlen);
130typedef void (*disconnect_cb_t) (void *arg);
131typedef void *(*exec_cb_t) (struct exec_parms *args);
132
133/* Client callbacks registered during dbus_attach() */
134typedef struct dbus_callbacks {
135 void (*send_complete) (void *cbarg, void *info, int status);
136 void (*recv_buf) (void *cbarg, u8 *buf, int len);
137 void (*recv_pkt) (void *cbarg, void *pkt);
138 void (*txflowcontrol) (void *cbarg, bool onoff);
139 void (*errhandler) (void *cbarg, int err);
140 void (*ctl_complete) (void *cbarg, int type, int status);
141 void (*state_change) (void *cbarg, int state);
142 void *(*pktget) (void *cbarg, uint len, bool send);
143 void (*pktfree) (void *cbarg, void *p, bool send);
144} dbus_callbacks_t;
145
146struct dbus_pub;
147struct bcmstrbuf;
148struct dbus_irb;
149struct dbus_irb_rx;
150struct dbus_irb_tx;
151struct dbus_intf_callbacks;
152
153typedef struct {
154 void *(*attach) (struct dbus_pub *pub, void *cbarg,
155 struct dbus_intf_callbacks *cbs);
156 void (*detach) (struct dbus_pub *pub, void *bus);
157
158 int (*up) (void *bus);
159 int (*down) (void *bus);
160 int (*send_irb) (void *bus, struct dbus_irb_tx *txirb);
161 int (*recv_irb) (void *bus, struct dbus_irb_rx *rxirb);
162 int (*cancel_irb) (void *bus, struct dbus_irb_tx *txirb);
163 int (*send_ctl) (void *bus, u8 *buf, int len);
164 int (*recv_ctl) (void *bus, u8 *buf, int len);
165 int (*get_stats) (void *bus, dbus_stats_t *stats);
166 int (*get_attrib) (void *bus, dbus_attrib_t *attrib);
167
168 int (*pnp) (void *bus, int event);
169 int (*remove) (void *bus);
170 int (*resume) (void *bus);
171 int (*suspend) (void *bus);
172 int (*stop) (void *bus);
173 int (*reset) (void *bus);
174
175 /* Access to bus buffers directly */
176 void *(*pktget) (void *bus, int len);
177 void (*pktfree) (void *bus, void *pkt);
178
179 int (*iovar_op) (void *bus, const char *name, void *params, int plen,
180 void *arg, int len, bool set);
181 void (*dump) (void *bus, struct bcmstrbuf *strbuf);
182 int (*set_config) (void *bus, dbus_config_t *config);
183 int (*get_config) (void *bus, dbus_config_t *config);
184
185 bool(*device_exists) (void *bus);
186 bool(*dlneeded) (void *bus);
187 int (*dlstart) (void *bus, u8 *fw, int len);
188 int (*dlrun) (void *bus);
189 bool(*recv_needed) (void *bus);
190
191 void *(*exec_rxlock) (void *bus, exec_cb_t func,
192 struct exec_parms *args);
193 void *(*exec_txlock) (void *bus, exec_cb_t func,
194 struct exec_parms *args);
195
196 int (*tx_timer_init) (void *bus);
197 int (*tx_timer_start) (void *bus, uint timeout);
198 int (*tx_timer_stop) (void *bus);
199
200 int (*sched_dpc) (void *bus);
201 int (*lock) (void *bus);
202 int (*unlock) (void *bus);
203 int (*sched_probe_cb) (void *bus);
204
205 int (*shutdown) (void *bus);
206
207 int (*recv_stop) (void *bus);
208 int (*recv_resume) (void *bus);
209
210 /* Add from the bottom */
211} dbus_intf_t;
212
213typedef struct dbus_pub {
214 struct osl_info *osh;
215 dbus_stats_t stats;
216 dbus_attrib_t attrib;
217 enum dbus_state busstate;
218 DEVICE_SPEED device_speed;
219 int ntxq, nrxq, rxsize;
220 void *bus;
221 struct shared_info *sh;
222} dbus_pub_t;
223
224#define BUS_INFO(bus, type) (((type *) bus)->pub->bus)
225
226/*
227 * Public Bus Function Interface
228 */
229extern int dbus_register(int vid, int pid, probe_cb_t prcb,
230 disconnect_cb_t discb, void *prarg, void *param1,
231 void *param2);
232extern int dbus_deregister(void);
233
234extern const dbus_pub_t *dbus_attach(struct osl_info *osh, int rxsize, int nrxq,
235 int ntxq, void *cbarg,
236 dbus_callbacks_t *cbs,
237 struct shared_info *sh);
238extern void dbus_detach(const dbus_pub_t *pub);
239
240extern int dbus_up(const dbus_pub_t *pub);
241extern int dbus_down(const dbus_pub_t *pub);
242extern int dbus_stop(const dbus_pub_t *pub);
243extern int dbus_shutdown(const dbus_pub_t *pub);
244extern void dbus_flowctrl_rx(const dbus_pub_t *pub, bool on);
245
246extern int dbus_send_buf(const dbus_pub_t *pub, u8 *buf, int len,
247 void *info);
248extern int dbus_send_pkt(const dbus_pub_t *pub, void *pkt, void *info);
249extern int dbus_send_ctl(const dbus_pub_t *pub, u8 *buf, int len);
250extern int dbus_recv_ctl(const dbus_pub_t *pub, u8 *buf, int len);
251
252extern int dbus_get_stats(const dbus_pub_t *pub, dbus_stats_t *stats);
253extern int dbus_get_attrib(const dbus_pub_t *pub, dbus_attrib_t *attrib);
254extern int dbus_get_device_speed(const dbus_pub_t *pub);
255extern int dbus_set_config(const dbus_pub_t *pub, dbus_config_t *config);
256extern int dbus_get_config(const dbus_pub_t *pub, dbus_config_t *config);
257
258extern void *dbus_pktget(const dbus_pub_t *pub, int len);
259extern void dbus_pktfree(const dbus_pub_t *pub, void *pkt);
260
261extern int dbus_set_errmask(const dbus_pub_t *pub, u32 mask);
262extern int dbus_pnp_sleep(const dbus_pub_t *pub);
263extern int dbus_pnp_resume(const dbus_pub_t *pub, int *fw_reload);
264extern int dbus_pnp_disconnect(const dbus_pub_t *pub);
265
266extern int dbus_iovar_op(const dbus_pub_t *pub, const char *name,
267 void *params, int plen, void *arg, int len, bool set);
268#ifdef BCMDBG
269extern void dbus_hist_dump(const dbus_pub_t *pub, struct bcmstrbuf *b);
270#endif /* BCMDBG */
271/*
272 * Private Common Bus Interface
273 */
274
275/* IO Request Block (IRB) */
276typedef struct dbus_irb {
277 struct dbus_irb *next; /* it's casted from dbus_irb_tx or dbus_irb_rx struct */
278} dbus_irb_t;
279
280typedef struct dbus_irb_rx {
281 struct dbus_irb irb; /* Must be first */
282 u8 *buf;
283 int buf_len;
284 int actual_len;
285 void *pkt;
286 void *info;
287 void *arg;
288} dbus_irb_rx_t;
289
290typedef struct dbus_irb_tx {
291 struct dbus_irb irb; /* Must be first */
292 u8 *buf;
293 int len;
294 void *pkt;
295 int retry_count;
296 void *info;
297 void *arg;
298} dbus_irb_tx_t;
299
300/* DBUS interface callbacks are different from user callbacks
301 * so, internally, different info can be passed to upper layer
302 */
303typedef struct dbus_intf_callbacks {
304 void (*send_irb_timeout) (void *cbarg, dbus_irb_tx_t *txirb);
305 void (*send_irb_complete) (void *cbarg, dbus_irb_tx_t *txirb,
306 int status);
307 void (*recv_irb_complete) (void *cbarg, dbus_irb_rx_t *rxirb,
308 int status);
309 void (*errhandler) (void *cbarg, int err);
310 void (*ctl_complete) (void *cbarg, int type, int status);
311 void (*state_change) (void *cbarg, int state);
312 bool(*isr) (void *cbarg, bool *wantdpc);
313 bool(*dpc) (void *cbarg, bool bounded);
314 void (*watchdog) (void *cbarg);
315 void *(*pktget) (void *cbarg, uint len, bool send);
316 void (*pktfree) (void *cbarg, void *p, bool send);
317 struct dbus_irb *(*getirb) (void *cbarg, bool send);
318 void (*rxerr_indicate) (void *cbarg, bool on);
319} dbus_intf_callbacks_t;
320
321/*
322 * Porting: To support new bus, port these functions below
323 */
324
325/*
326 * Bus specific Interface
327 * Implemented by dbus_usb.c/dbus_sdio.c
328 */
329extern int dbus_bus_register(int vid, int pid, probe_cb_t prcb,
330 disconnect_cb_t discb, void *prarg,
331 dbus_intf_t **intf, void *param1, void *param2);
332extern int dbus_bus_deregister(void);
333
334/*
335 * Bus-specific and OS-specific Interface
336 * Implemented by dbus_usb_[linux/ndis].c/dbus_sdio_[linux/ndis].c
337 */
338extern int dbus_bus_osl_register(int vid, int pid, probe_cb_t prcb,
339 disconnect_cb_t discb, void *prarg,
340 dbus_intf_t **intf, void *param1,
341 void *param2);
342extern int dbus_bus_osl_deregister(void);
343
344/*
345 * Bus-specific, OS-specific, HW-specific Interface
346 * Mainly for SDIO Host HW controller
347 */
348extern int dbus_bus_osl_hw_register(int vid, int pid, probe_cb_t prcb,
349 disconnect_cb_t discb, void *prarg,
350 dbus_intf_t **intf);
351extern int dbus_bus_osl_hw_deregister(void);
352
353#endif /* __DBUS_H__ */
diff --git a/drivers/staging/brcm80211/include/epivers.h b/drivers/staging/brcm80211/include/epivers.h
deleted file mode 100644
index 2e6b5190ad6c..000000000000
--- a/drivers/staging/brcm80211/include/epivers.h
+++ /dev/null
@@ -1,44 +0,0 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _epivers_h_
18#define _epivers_h_
19
20#define EPI_MAJOR_VERSION 5
21
22#define EPI_MINOR_VERSION 75
23
24#define EPI_RC_NUMBER 11
25
26#define EPI_INCREMENTAL_NUMBER 0
27
28#define EPI_BUILD_NUMBER 1
29
30#define EPI_VERSION { 5, 75, 11, 0 }
31
32#ifdef BCMSDIO
33/* EPI_VERSION_NUM must match FW version */
34#define EPI_VERSION_NUM 0x054b0c00
35#else
36#define EPI_VERSION_NUM 0x054b0b00
37#endif
38
39#define EPI_VERSION_DEV 5.75.11
40
41/* Driver Version String, ASCII, 32 chars max */
42#define EPI_VERSION_STR "5.75.11"
43
44#endif /* _epivers_h_ */
diff --git a/drivers/staging/brcm80211/include/hnddma.h b/drivers/staging/brcm80211/include/hnddma.h
index bee4c89be23d..4c5462baf11e 100644
--- a/drivers/staging/brcm80211/include/hnddma.h
+++ b/drivers/staging/brcm80211/include/hnddma.h
@@ -19,7 +19,7 @@
19 19
20#ifndef _hnddma_pub_ 20#ifndef _hnddma_pub_
21#define _hnddma_pub_ 21#define _hnddma_pub_
22typedef const struct hnddma_pub hnddma_t; 22struct hnddma_pub;
23#endif /* _hnddma_pub_ */ 23#endif /* _hnddma_pub_ */
24 24
25/* range param for dma_getnexttxp() and dma_txreclaim */ 25/* range param for dma_getnexttxp() and dma_txreclaim */
@@ -30,52 +30,54 @@ typedef enum txd_range {
30} txd_range_t; 30} txd_range_t;
31 31
32/* dma function type */ 32/* dma function type */
33typedef void (*di_detach_t) (hnddma_t *dmah); 33typedef void (*di_detach_t) (struct hnddma_pub *dmah);
34typedef bool(*di_txreset_t) (hnddma_t *dmah); 34typedef bool(*di_txreset_t) (struct hnddma_pub *dmah);
35typedef bool(*di_rxreset_t) (hnddma_t *dmah); 35typedef bool(*di_rxreset_t) (struct hnddma_pub *dmah);
36typedef bool(*di_rxidle_t) (hnddma_t *dmah); 36typedef bool(*di_rxidle_t) (struct hnddma_pub *dmah);
37typedef void (*di_txinit_t) (hnddma_t *dmah); 37typedef void (*di_txinit_t) (struct hnddma_pub *dmah);
38typedef bool(*di_txenabled_t) (hnddma_t *dmah); 38typedef bool(*di_txenabled_t) (struct hnddma_pub *dmah);
39typedef void (*di_rxinit_t) (hnddma_t *dmah); 39typedef void (*di_rxinit_t) (struct hnddma_pub *dmah);
40typedef void (*di_txsuspend_t) (hnddma_t *dmah); 40typedef void (*di_txsuspend_t) (struct hnddma_pub *dmah);
41typedef void (*di_txresume_t) (hnddma_t *dmah); 41typedef void (*di_txresume_t) (struct hnddma_pub *dmah);
42typedef bool(*di_txsuspended_t) (hnddma_t *dmah); 42typedef bool(*di_txsuspended_t) (struct hnddma_pub *dmah);
43typedef bool(*di_txsuspendedidle_t) (hnddma_t *dmah); 43typedef bool(*di_txsuspendedidle_t) (struct hnddma_pub *dmah);
44typedef int (*di_txfast_t) (hnddma_t *dmah, void *p, bool commit); 44typedef int (*di_txfast_t) (struct hnddma_pub *dmah, struct sk_buff *p,
45typedef int (*di_txunframed_t) (hnddma_t *dmah, void *p, uint len, 45 bool commit);
46typedef int (*di_txunframed_t) (struct hnddma_pub *dmah, void *p, uint len,
46 bool commit); 47 bool commit);
47typedef void *(*di_getpos_t) (hnddma_t *di, bool direction); 48typedef void *(*di_getpos_t) (struct hnddma_pub *di, bool direction);
48typedef void (*di_fifoloopbackenable_t) (hnddma_t *dmah); 49typedef void (*di_fifoloopbackenable_t) (struct hnddma_pub *dmah);
49typedef bool(*di_txstopped_t) (hnddma_t *dmah); 50typedef bool(*di_txstopped_t) (struct hnddma_pub *dmah);
50typedef bool(*di_rxstopped_t) (hnddma_t *dmah); 51typedef bool(*di_rxstopped_t) (struct hnddma_pub *dmah);
51typedef bool(*di_rxenable_t) (hnddma_t *dmah); 52typedef bool(*di_rxenable_t) (struct hnddma_pub *dmah);
52typedef bool(*di_rxenabled_t) (hnddma_t *dmah); 53typedef bool(*di_rxenabled_t) (struct hnddma_pub *dmah);
53typedef void *(*di_rx_t) (hnddma_t *dmah); 54typedef void *(*di_rx_t) (struct hnddma_pub *dmah);
54typedef bool(*di_rxfill_t) (hnddma_t *dmah); 55typedef bool(*di_rxfill_t) (struct hnddma_pub *dmah);
55typedef void (*di_txreclaim_t) (hnddma_t *dmah, txd_range_t range); 56typedef void (*di_txreclaim_t) (struct hnddma_pub *dmah, txd_range_t range);
56typedef void (*di_rxreclaim_t) (hnddma_t *dmah); 57typedef void (*di_rxreclaim_t) (struct hnddma_pub *dmah);
57typedef unsigned long (*di_getvar_t) (hnddma_t *dmah, const char *name); 58typedef unsigned long (*di_getvar_t) (struct hnddma_pub *dmah,
58typedef void *(*di_getnexttxp_t) (hnddma_t *dmah, txd_range_t range); 59 const char *name);
59typedef void *(*di_getnextrxp_t) (hnddma_t *dmah, bool forceall); 60typedef void *(*di_getnexttxp_t) (struct hnddma_pub *dmah, txd_range_t range);
60typedef void *(*di_peeknexttxp_t) (hnddma_t *dmah); 61typedef void *(*di_getnextrxp_t) (struct hnddma_pub *dmah, bool forceall);
61typedef void *(*di_peeknextrxp_t) (hnddma_t *dmah); 62typedef void *(*di_peeknexttxp_t) (struct hnddma_pub *dmah);
62typedef void (*di_rxparam_get_t) (hnddma_t *dmah, u16 *rxoffset, 63typedef void *(*di_peeknextrxp_t) (struct hnddma_pub *dmah);
64typedef void (*di_rxparam_get_t) (struct hnddma_pub *dmah, u16 *rxoffset,
63 u16 *rxbufsize); 65 u16 *rxbufsize);
64typedef void (*di_txblock_t) (hnddma_t *dmah); 66typedef void (*di_txblock_t) (struct hnddma_pub *dmah);
65typedef void (*di_txunblock_t) (hnddma_t *dmah); 67typedef void (*di_txunblock_t) (struct hnddma_pub *dmah);
66typedef uint(*di_txactive_t) (hnddma_t *dmah); 68typedef uint(*di_txactive_t) (struct hnddma_pub *dmah);
67typedef void (*di_txrotate_t) (hnddma_t *dmah); 69typedef void (*di_txrotate_t) (struct hnddma_pub *dmah);
68typedef void (*di_counterreset_t) (hnddma_t *dmah); 70typedef void (*di_counterreset_t) (struct hnddma_pub *dmah);
69typedef uint(*di_ctrlflags_t) (hnddma_t *dmah, uint mask, uint flags); 71typedef uint(*di_ctrlflags_t) (struct hnddma_pub *dmah, uint mask, uint flags);
70typedef char *(*di_dump_t) (hnddma_t *dmah, struct bcmstrbuf *b, 72typedef char *(*di_dump_t) (struct hnddma_pub *dmah, struct bcmstrbuf *b,
71 bool dumpring); 73 bool dumpring);
72typedef char *(*di_dumptx_t) (hnddma_t *dmah, struct bcmstrbuf *b, 74typedef char *(*di_dumptx_t) (struct hnddma_pub *dmah, struct bcmstrbuf *b,
73 bool dumpring); 75 bool dumpring);
74typedef char *(*di_dumprx_t) (hnddma_t *dmah, struct bcmstrbuf *b, 76typedef char *(*di_dumprx_t) (struct hnddma_pub *dmah, struct bcmstrbuf *b,
75 bool dumpring); 77 bool dumpring);
76typedef uint(*di_rxactive_t) (hnddma_t *dmah); 78typedef uint(*di_rxactive_t) (struct hnddma_pub *dmah);
77typedef uint(*di_txpending_t) (hnddma_t *dmah); 79typedef uint(*di_txpending_t) (struct hnddma_pub *dmah);
78typedef uint(*di_txcommitted_t) (hnddma_t *dmah); 80typedef uint(*di_txcommitted_t) (struct hnddma_pub *dmah);
79 81
80/* dma opsvec */ 82/* dma opsvec */
81typedef struct di_fcn_s { 83typedef struct di_fcn_s {
@@ -141,7 +143,8 @@ struct hnddma_pub {
141 uint txnobuf; /* tx out of dma descriptors */ 143 uint txnobuf; /* tx out of dma descriptors */
142}; 144};
143 145
144extern hnddma_t *dma_attach(osl_t *osh, char *name, si_t *sih, 146extern struct hnddma_pub *dma_attach(struct osl_info *osh, char *name,
147 si_t *sih,
145 void *dmaregstx, void *dmaregsrx, uint ntxd, 148 void *dmaregstx, void *dmaregsrx, uint ntxd,
146 uint nrxd, uint rxbufsize, int rxextheadroom, 149 uint nrxd, uint rxbufsize, int rxextheadroom,
147 uint nrxpost, uint rxoffset, uint *msg_level); 150 uint nrxpost, uint rxoffset, uint *msg_level);
@@ -238,6 +241,6 @@ extern const di_fcn_t dma64proc;
238extern uint dma_addrwidth(si_t *sih, void *dmaregs); 241extern uint dma_addrwidth(si_t *sih, void *dmaregs);
239 242
240/* pio helpers */ 243/* pio helpers */
241extern void dma_txpioloopback(osl_t *osh, dma32regs_t *); 244extern void dma_txpioloopback(struct osl_info *osh, dma32regs_t *);
242 245
243#endif /* _hnddma_h_ */ 246#endif /* _hnddma_h_ */
diff --git a/drivers/staging/brcm80211/include/hndpmu.h b/drivers/staging/brcm80211/include/hndpmu.h
index bbcf0eecd212..a0110e4c9ac4 100644
--- a/drivers/staging/brcm80211/include/hndpmu.h
+++ b/drivers/staging/brcm80211/include/hndpmu.h
@@ -28,44 +28,44 @@
28#define SET_LDO_VOLTAGE_LNLDO1 9 28#define SET_LDO_VOLTAGE_LNLDO1 9
29#define SET_LDO_VOLTAGE_LNLDO2_SEL 10 29#define SET_LDO_VOLTAGE_LNLDO2_SEL 10
30 30
31extern void si_pmu_init(si_t *sih, osl_t *osh); 31extern void si_pmu_init(si_t *sih, struct osl_info *osh);
32extern void si_pmu_chip_init(si_t *sih, osl_t *osh); 32extern void si_pmu_chip_init(si_t *sih, struct osl_info *osh);
33extern void si_pmu_pll_init(si_t *sih, osl_t *osh, u32 xtalfreq); 33extern void si_pmu_pll_init(si_t *sih, struct osl_info *osh, u32 xtalfreq);
34extern void si_pmu_res_init(si_t *sih, osl_t *osh); 34extern void si_pmu_res_init(si_t *sih, struct osl_info *osh);
35extern void si_pmu_swreg_init(si_t *sih, osl_t *osh); 35extern void si_pmu_swreg_init(si_t *sih, struct osl_info *osh);
36 36
37extern u32 si_pmu_force_ilp(si_t *sih, osl_t *osh, bool force); 37extern u32 si_pmu_force_ilp(si_t *sih, struct osl_info *osh, bool force);
38 38
39extern u32 si_pmu_si_clock(si_t *sih, osl_t *osh); 39extern u32 si_pmu_si_clock(si_t *sih, struct osl_info *osh);
40extern u32 si_pmu_cpu_clock(si_t *sih, osl_t *osh); 40extern u32 si_pmu_cpu_clock(si_t *sih, struct osl_info *osh);
41extern u32 si_pmu_mem_clock(si_t *sih, osl_t *osh); 41extern u32 si_pmu_mem_clock(si_t *sih, struct osl_info *osh);
42extern u32 si_pmu_alp_clock(si_t *sih, osl_t *osh); 42extern u32 si_pmu_alp_clock(si_t *sih, struct osl_info *osh);
43extern u32 si_pmu_ilp_clock(si_t *sih, osl_t *osh); 43extern u32 si_pmu_ilp_clock(si_t *sih, struct osl_info *osh);
44 44
45extern void si_pmu_set_switcher_voltage(si_t *sih, osl_t *osh, 45extern void si_pmu_set_switcher_voltage(si_t *sih, struct osl_info *osh,
46 u8 bb_voltage, u8 rf_voltage); 46 u8 bb_voltage, u8 rf_voltage);
47extern void si_pmu_set_ldo_voltage(si_t *sih, osl_t *osh, u8 ldo, 47extern void si_pmu_set_ldo_voltage(si_t *sih, struct osl_info *osh, u8 ldo,
48 u8 voltage); 48 u8 voltage);
49extern u16 si_pmu_fast_pwrup_delay(si_t *sih, osl_t *osh); 49extern u16 si_pmu_fast_pwrup_delay(si_t *sih, struct osl_info *osh);
50extern void si_pmu_rcal(si_t *sih, osl_t *osh); 50extern void si_pmu_rcal(si_t *sih, struct osl_info *osh);
51extern void si_pmu_pllupd(si_t *sih); 51extern void si_pmu_pllupd(si_t *sih);
52extern void si_pmu_spuravoid(si_t *sih, osl_t *osh, u8 spuravoid); 52extern void si_pmu_spuravoid(si_t *sih, struct osl_info *osh, u8 spuravoid);
53 53
54extern bool si_pmu_is_otp_powered(si_t *sih, osl_t *osh); 54extern bool si_pmu_is_otp_powered(si_t *sih, struct osl_info *osh);
55extern u32 si_pmu_measure_alpclk(si_t *sih, osl_t *osh); 55extern u32 si_pmu_measure_alpclk(si_t *sih, struct osl_info *osh);
56 56
57extern u32 si_pmu_chipcontrol(si_t *sih, uint reg, u32 mask, u32 val); 57extern u32 si_pmu_chipcontrol(si_t *sih, uint reg, u32 mask, u32 val);
58extern u32 si_pmu_regcontrol(si_t *sih, uint reg, u32 mask, u32 val); 58extern u32 si_pmu_regcontrol(si_t *sih, uint reg, u32 mask, u32 val);
59extern u32 si_pmu_pllcontrol(si_t *sih, uint reg, u32 mask, u32 val); 59extern u32 si_pmu_pllcontrol(si_t *sih, uint reg, u32 mask, u32 val);
60extern void si_pmu_pllupd(si_t *sih); 60extern void si_pmu_pllupd(si_t *sih);
61extern void si_pmu_sprom_enable(si_t *sih, osl_t *osh, bool enable); 61extern void si_pmu_sprom_enable(si_t *sih, struct osl_info *osh, bool enable);
62 62
63extern void si_pmu_radio_enable(si_t *sih, bool enable); 63extern void si_pmu_radio_enable(si_t *sih, bool enable);
64extern u32 si_pmu_waitforclk_on_backplane(si_t *sih, osl_t *osh, 64extern u32 si_pmu_waitforclk_on_backplane(si_t *sih, struct osl_info *osh,
65 u32 clk, u32 delay); 65 u32 clk, u32 delay);
66 66
67extern void si_pmu_otp_power(si_t *sih, osl_t *osh, bool on); 67extern void si_pmu_otp_power(si_t *sih, struct osl_info *osh, bool on);
68extern void si_sdiod_drive_strength_init(si_t *sih, osl_t *osh, 68extern void si_sdiod_drive_strength_init(si_t *sih, struct osl_info *osh,
69 u32 drivestrength); 69 u32 drivestrength);
70 70
71#endif /* _hndpmu_h_ */ 71#endif /* _hndpmu_h_ */
diff --git a/drivers/staging/brcm80211/include/linux_osl.h b/drivers/staging/brcm80211/include/linux_osl.h
deleted file mode 100644
index c9c860b6e474..000000000000
--- a/drivers/staging/brcm80211/include/linux_osl.h
+++ /dev/null
@@ -1,407 +0,0 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _linux_osl_h_
18#define _linux_osl_h_
19
20
21/* Linux Kernel: File Operations: start */
22extern void *osl_os_open_image(char *filename);
23extern int osl_os_get_image_block(char *buf, int len, void *image);
24extern void osl_os_close_image(void *image);
25/* Linux Kernel: File Operations: end */
26
27extern osl_t *osl_attach(void *pdev, uint bustype, bool pkttag);
28extern void osl_detach(osl_t *osh);
29
30extern u32 g_assert_type;
31
32#if defined(BCMDBG_ASSERT)
33#define ASSERT(exp) \
34 do { if (!(exp)) osl_assert(#exp, __FILE__, __LINE__); } while (0)
35extern void osl_assert(char *exp, char *file, int line);
36#else
37#ifdef __GNUC__
38#define GCC_VERSION \
39 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
40#if GCC_VERSION > 30100
41#define ASSERT(exp) do {} while (0)
42#else
43 /* ASSERT could cause segmentation fault on GCC3.1, use empty instead */
44#define ASSERT(exp)
45#endif /* GCC_VERSION > 30100 */
46#endif /* __GNUC__ */
47#endif /* defined(BCMDBG_ASSERT) */
48
49/* PCI configuration space access macros */
50#define OSL_PCI_READ_CONFIG(osh, offset, size) \
51 osl_pci_read_config((osh), (offset), (size))
52#define OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
53 osl_pci_write_config((osh), (offset), (size), (val))
54extern u32 osl_pci_read_config(osl_t *osh, uint offset, uint size);
55extern void osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val);
56
57/* PCI device bus # and slot # */
58#define OSL_PCI_BUS(osh) osl_pci_bus(osh)
59#define OSL_PCI_SLOT(osh) osl_pci_slot(osh)
60extern uint osl_pci_bus(osl_t *osh);
61extern uint osl_pci_slot(osl_t *osh);
62
63/* Pkttag flag should be part of public information */
64typedef struct {
65 bool pkttag;
66 uint pktalloced; /* Number of allocated packet buffers */
67 bool mmbus; /* Bus supports memory-mapped register accesses */
68 pktfree_cb_fn_t tx_fn; /* Callback function for PKTFREE */
69 void *tx_ctx; /* Context to the callback function */
70#if defined(BCMSDIO) && !defined(BRCM_FULLMAC)
71 osl_rreg_fn_t rreg_fn; /* Read Register function */
72 osl_wreg_fn_t wreg_fn; /* Write Register function */
73 void *reg_ctx; /* Context to the reg callback functions */
74#endif
75} osl_pubinfo_t;
76
77#define PKTFREESETCB(osh, _tx_fn, _tx_ctx) \
78 do { \
79 ((osl_pubinfo_t *)osh)->tx_fn = _tx_fn; \
80 ((osl_pubinfo_t *)osh)->tx_ctx = _tx_ctx; \
81 } while (0)
82
83#if defined(BCMSDIO) && !defined(BRCM_FULLMAC)
84#define REGOPSSET(osh, rreg, wreg, ctx) \
85 do { \
86 ((osl_pubinfo_t *)osh)->rreg_fn = rreg; \
87 ((osl_pubinfo_t *)osh)->wreg_fn = wreg; \
88 ((osl_pubinfo_t *)osh)->reg_ctx = ctx; \
89 } while (0)
90#endif
91
92#define BUS_SWAP32(v) (v)
93
94#define DMA_CONSISTENT_ALIGN osl_dma_consistent_align()
95extern uint osl_dma_consistent_align(void);
96extern void *osl_dma_alloc_consistent(osl_t *osh, uint size, u16 align,
97 uint *tot, unsigned long *pap);
98
99#ifdef BRCM_FULLMAC
100#define DMA_ALLOC_CONSISTENT(osh, size, pap, dmah, alignbits) \
101 osl_dma_alloc_consistent((osh), (size), (0), (tot), (pap))
102#else
103#define DMA_ALLOC_CONSISTENT(osh, size, align, tot, pap, dmah) \
104 osl_dma_alloc_consistent((osh), (size), (align), (tot), (pap))
105#endif /* BRCM_FULLMAC */
106
107#define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
108 osl_dma_free_consistent((osh), (void *)(va), (size), (pa))
109extern void osl_dma_free_consistent(osl_t *osh, void *va, uint size, unsigned long pa);
110
111/* map/unmap direction */
112#define DMA_TX 1 /* TX direction for DMA */
113#define DMA_RX 2 /* RX direction for DMA */
114
115/* map/unmap shared (dma-able) memory */
116#define DMA_MAP(osh, va, size, direction, p, dmah) \
117 osl_dma_map((osh), (va), (size), (direction))
118#define DMA_UNMAP(osh, pa, size, direction, p, dmah) \
119 osl_dma_unmap((osh), (pa), (size), (direction))
120extern uint osl_dma_map(osl_t *osh, void *va, uint size, int direction);
121extern void osl_dma_unmap(osl_t *osh, uint pa, uint size, int direction);
122
123/* API for DMA addressing capability */
124#define OSL_DMADDRWIDTH(osh, addrwidth) do {} while (0)
125
126/* register access macros */
127#if defined(BCMSDIO)
128#ifdef BRCM_FULLMAC
129#include <bcmsdh.h>
130#endif
131#define OSL_WRITE_REG(osh, r, v) (bcmsdh_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), (v)))
132#define OSL_READ_REG(osh, r) (bcmsdh_reg_read(NULL, (unsigned long)(r), sizeof(*(r))))
133#endif
134
135#if defined(BCMSDIO)
136#define SELECT_BUS_WRITE(osh, mmap_op, bus_op) if (((osl_pubinfo_t *)(osh))->mmbus) \
137 mmap_op else bus_op
138#define SELECT_BUS_READ(osh, mmap_op, bus_op) (((osl_pubinfo_t *)(osh))->mmbus) ? \
139 mmap_op : bus_op
140#else
141#define SELECT_BUS_WRITE(osh, mmap_op, bus_op) mmap_op
142#define SELECT_BUS_READ(osh, mmap_op, bus_op) mmap_op
143#endif
144
145#define OSL_ERROR(bcmerror) osl_error(bcmerror)
146extern int osl_error(int bcmerror);
147
148/* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
149#define PKTBUFSZ 2048 /* largest reasonable packet buffer, driver uses for ethernet MTU */
150
151#define OSL_SYSUPTIME() ((u32)jiffies * (1000 / HZ))
152#define printf(fmt, args...) printk(fmt , ## args)
153#ifdef BRCM_FULLMAC
154#include <linux/kernel.h> /* for vsn/printf's */
155#include <linux/string.h> /* for mem*, str* */
156#endif
157/* bcopy's: Linux kernel doesn't provide these (anymore) */
158#define bcopy(src, dst, len) memcpy((dst), (src), (len))
159#define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
160#define bzero(b, len) memset((b), '\0', (len))
161
162/* register access macros */
163#if defined(OSLREGOPS)
164#else
165#ifndef IL_BIGENDIAN
166#ifndef __mips__
167#define R_REG(osh, r) (\
168 SELECT_BUS_READ(osh, sizeof(*(r)) == sizeof(u8) ? readb((volatile u8*)(r)) : \
169 sizeof(*(r)) == sizeof(u16) ? readw((volatile u16*)(r)) : \
170 readl((volatile u32*)(r)), OSL_READ_REG(osh, r)) \
171)
172#else /* __mips__ */
173#define R_REG(osh, r) (\
174 SELECT_BUS_READ(osh, \
175 ({ \
176 __typeof(*(r)) __osl_v; \
177 __asm__ __volatile__("sync"); \
178 switch (sizeof(*(r))) { \
179 case sizeof(u8): \
180 __osl_v = readb((volatile u8*)(r)); \
181 break; \
182 case sizeof(u16): \
183 __osl_v = readw((volatile u16*)(r)); \
184 break; \
185 case sizeof(u32): \
186 __osl_v = \
187 readl((volatile u32*)(r)); \
188 break; \
189 } \
190 __asm__ __volatile__("sync"); \
191 __osl_v; \
192 }), \
193 ({ \
194 __typeof(*(r)) __osl_v; \
195 __asm__ __volatile__("sync"); \
196 __osl_v = OSL_READ_REG(osh, r); \
197 __asm__ __volatile__("sync"); \
198 __osl_v; \
199 })) \
200)
201#endif /* __mips__ */
202
203#define W_REG(osh, r, v) do { \
204 SELECT_BUS_WRITE(osh, \
205 switch (sizeof(*(r))) { \
206 case sizeof(u8): \
207 writeb((u8)(v), (volatile u8*)(r)); break; \
208 case sizeof(u16): \
209 writew((u16)(v), (volatile u16*)(r)); break; \
210 case sizeof(u32): \
211 writel((u32)(v), (volatile u32*)(r)); break; \
212 }, \
213 (OSL_WRITE_REG(osh, r, v))); \
214 } while (0)
215#else /* IL_BIGENDIAN */
216#define R_REG(osh, r) (\
217 SELECT_BUS_READ(osh, \
218 ({ \
219 __typeof(*(r)) __osl_v; \
220 switch (sizeof(*(r))) { \
221 case sizeof(u8): \
222 __osl_v = \
223 readb((volatile u8*)((r)^3)); \
224 break; \
225 case sizeof(u16): \
226 __osl_v = \
227 readw((volatile u16*)((r)^2)); \
228 break; \
229 case sizeof(u32): \
230 __osl_v = readl((volatile u32*)(r)); \
231 break; \
232 } \
233 __osl_v; \
234 }), \
235 OSL_READ_REG(osh, r)) \
236)
237#define W_REG(osh, r, v) do { \
238 SELECT_BUS_WRITE(osh, \
239 switch (sizeof(*(r))) { \
240 case sizeof(u8): \
241 writeb((u8)(v), \
242 (volatile u8*)((r)^3)); break; \
243 case sizeof(u16): \
244 writew((u16)(v), \
245 (volatile u16*)((r)^2)); break; \
246 case sizeof(u32): \
247 writel((u32)(v), \
248 (volatile u32*)(r)); break; \
249 }, \
250 (OSL_WRITE_REG(osh, r, v))); \
251 } while (0)
252#endif /* IL_BIGENDIAN */
253
254#endif /* OSLREGOPS */
255
256#define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v))
257#define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v))
258
259/* bcopy, bcmp, and bzero functions */
260#define bcopy(src, dst, len) memcpy((dst), (src), (len))
261#define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
262#define bzero(b, len) memset((b), '\0', (len))
263
264/* uncached/cached virtual address */
265#ifdef __mips__
266#include <asm/addrspace.h>
267#define OSL_UNCACHED(va) ((void *)KSEG1ADDR((va)))
268#define OSL_CACHED(va) ((void *)KSEG0ADDR((va)))
269#else
270#define OSL_UNCACHED(va) ((void *)va)
271#define OSL_CACHED(va) ((void *)va)
272#endif /* mips */
273
274#if defined(mips)
275#define OSL_GETCYCLES(x) ((x) = read_c0_count() * 2)
276#elif defined(__i386__)
277#define OSL_GETCYCLES(x) rdtscl((x))
278#else
279#define OSL_GETCYCLES(x) ((x) = 0)
280#endif /* defined(mips) */
281
282/* dereference an address that may cause a bus exception */
283#ifdef mips
284#define BUSPROBE(val, addr) get_dbe((val), (addr))
285#include <asm/paccess.h>
286#else
287#define BUSPROBE(val, addr) ({ (val) = R_REG(NULL, (addr)); 0; })
288#endif /* mips */
289
290/* map/unmap physical to virtual I/O */
291#if !defined(CONFIG_MMC_MSM7X00A)
292#define REG_MAP(pa, size) ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
293#else
294#define REG_MAP(pa, size) (void *)(0)
295#endif /* !defined(CONFIG_MMC_MSM7X00A */
296#define REG_UNMAP(va) iounmap((va))
297
298#define R_SM(r) (*(r))
299#define W_SM(r, v) (*(r) = (v))
300#define BZERO_SM(r, len) memset((r), '\0', (len))
301
302#ifdef BRCM_FULLMAC
303#include <linuxver.h> /* use current 2.4.x calling conventions */
304#endif
305
306/* packet primitives */
307#define PKTGET(osh, len, send) osl_pktget((osh), (len))
308#define PKTFREE(osh, skb, send) osl_pktfree((osh), (skb), (send))
309#define PKTDATA(skb) (((struct sk_buff *)(skb))->data)
310#define PKTLEN(skb) (((struct sk_buff *)(skb))->len)
311#define PKTHEADROOM(skb) (PKTDATA(skb)-(((struct sk_buff *)(skb))->head))
312#define PKTTAILROOM(skb) ((((struct sk_buff *)(skb))->end)-(((struct sk_buff *)(skb))->tail))
313#define PKTNEXT(skb) (((struct sk_buff *)(skb))->next)
314#define PKTSETNEXT(skb, x) \
315 (((struct sk_buff *)(skb))->next = (struct sk_buff *)(x))
316#define PKTSETLEN(skb, len) __skb_trim((struct sk_buff *)(skb), (len))
317#define PKTPUSH(skb, bytes) skb_push((struct sk_buff *)(skb), (bytes))
318#define PKTPULL(skb, bytes) skb_pull((struct sk_buff *)(skb), (bytes))
319#define PKTTAG(skb) ((void *)(((struct sk_buff *)(skb))->cb))
320#define PKTALLOCED(osh) (((osl_pubinfo_t *)(osh))->pktalloced)
321#define PKTSETPOOL(osh, skb, x, y) do {} while (0)
322#define PKTPOOL(osh, skb) false
323extern void *osl_pktget(osl_t *osh, uint len);
324extern void osl_pktfree(osl_t *osh, void *skb, bool send);
325
326#ifdef BRCM_FULLMAC
327extern void *osl_pktget_static(osl_t *osh, uint len);
328extern void osl_pktfree_static(osl_t *osh, void *skb, bool send);
329
330static inline void *
331osl_pkt_frmnative(osl_pubinfo_t *osh, struct sk_buff *skb)
332{
333 struct sk_buff *nskb;
334
335 if (osh->pkttag)
336 bzero((void *)skb->cb, OSL_PKTTAG_SZ);
337
338 for (nskb = skb; nskb; nskb = nskb->next)
339 osh->pktalloced++;
340
341 return (void *)skb;
342}
343#define PKTFRMNATIVE(osh, skb) \
344 osl_pkt_frmnative(((osl_pubinfo_t *)osh), (struct sk_buff*)(skb))
345
346static inline struct sk_buff *
347osl_pkt_tonative(osl_pubinfo_t *osh, void *pkt)
348{
349 struct sk_buff *nskb;
350
351 if (osh->pkttag)
352 bzero(((struct sk_buff *)pkt)->cb, OSL_PKTTAG_SZ);
353
354 for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next)
355 osh->pktalloced--;
356
357 return (struct sk_buff *)pkt;
358}
359#define PKTTONATIVE(osh, pkt) \
360 osl_pkt_tonative((osl_pubinfo_t *)(osh), (pkt))
361#else /* !BRCM_FULLMAC */
362#define PKTUNALLOC(osh) (((osl_pubinfo_t *)(osh))->pktalloced--)
363
364#define PKTSETSKIPCT(osh, skb)
365#define PKTCLRSKIPCT(osh, skb)
366#define PKTSKIPCT(osh, skb)
367#endif /* BRCM_FULLMAC */
368
369#define PKTLINK(skb) (((struct sk_buff *)(skb))->prev)
370#define PKTSETLINK(skb, x) (((struct sk_buff *)(skb))->prev = (struct sk_buff*)(x))
371#define PKTPRIO(skb) (((struct sk_buff *)(skb))->priority)
372#define PKTSETPRIO(skb, x) (((struct sk_buff *)(skb))->priority = (x))
373#define PKTSUMNEEDED(skb) (((struct sk_buff *)(skb))->ip_summed == CHECKSUM_PARTIAL)
374#define PKTSETSUMGOOD(skb, x) (((struct sk_buff *)(skb))->ip_summed = \
375 ((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE))
376/* PKTSETSUMNEEDED and PKTSUMGOOD are not possible because skb->ip_summed is overloaded */
377#define PKTSHARED(skb) (((struct sk_buff *)(skb))->cloned)
378
379#if defined(BCMSDIO) && !defined(BRCM_FULLMAC)
380#define RPC_READ_REG(osh, r) (\
381 sizeof(*(r)) == sizeof(u8) ? osl_readb((osh), (volatile u8*)(r)) : \
382 sizeof(*(r)) == sizeof(u16) ? osl_readw((osh), (volatile u16*)(r)) : \
383 osl_readl((osh), (volatile u32*)(r)) \
384)
385#define RPC_WRITE_REG(osh, r, v) do { \
386 switch (sizeof(*(r))) { \
387 case sizeof(u8): \
388 osl_writeb((osh), (volatile u8*)(r), (u8)(v)); \
389 break; \
390 case sizeof(u16): \
391 osl_writew((osh), (volatile u16*)(r), (u16)(v)); \
392 break; \
393 case sizeof(u32): \
394 osl_writel((osh), (volatile u32*)(r), (u32)(v)); \
395 break; \
396 } \
397} while (0)
398
399extern u8 osl_readb(osl_t *osh, volatile u8 *r);
400extern u16 osl_readw(osl_t *osh, volatile u16 *r);
401extern u32 osl_readl(osl_t *osh, volatile u32 *r);
402extern void osl_writeb(osl_t *osh, volatile u8 *r, u8 v);
403extern void osl_writew(osl_t *osh, volatile u16 *r, u16 v);
404extern void osl_writel(osl_t *osh, volatile u32 *r, u32 v);
405#endif /* BCMSDIO */
406
407#endif /* _linux_osl_h_ */
diff --git a/drivers/staging/brcm80211/include/linuxver.h b/drivers/staging/brcm80211/include/linuxver.h
deleted file mode 100644
index dc721413ee29..000000000000
--- a/drivers/staging/brcm80211/include/linuxver.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _linuxver_h_
18#define _linuxver_h_
19
20#include <linux/module.h>
21#include <linux/slab.h>
22#include <linux/types.h>
23#include <linux/init.h>
24#include <linux/mm.h>
25#include <linux/string.h>
26#include <linux/pci.h>
27#include <linux/interrupt.h>
28#include <linux/netdevice.h>
29#include <linux/workqueue.h>
30#include <linux/sched.h>
31#include <linux/ieee80211.h>
32#include <linux/time.h>
33#include <linux/wait.h>
34
35#undef IP_TOS
36#include <asm/io.h>
37
38#endif /* _linuxver_h_ */
diff --git a/drivers/staging/brcm80211/include/nicpci.h b/drivers/staging/brcm80211/include/nicpci.h
index ce146e88ffdf..928818daedd7 100644
--- a/drivers/staging/brcm80211/include/nicpci.h
+++ b/drivers/staging/brcm80211/include/nicpci.h
@@ -45,17 +45,17 @@
45#else 45#else
46struct sbpcieregs; 46struct sbpcieregs;
47 47
48extern u8 pcicore_find_pci_capability(osl_t *osh, u8 req_cap_id, 48extern u8 pcicore_find_pci_capability(struct osl_info *osh, u8 req_cap_id,
49 unsigned char *buf, u32 *buflen); 49 unsigned char *buf, u32 *buflen);
50extern uint pcie_readreg(osl_t *osh, struct sbpcieregs *pcieregs, 50extern uint pcie_readreg(struct osl_info *osh, struct sbpcieregs *pcieregs,
51 uint addrtype, uint offset); 51 uint addrtype, uint offset);
52extern uint pcie_writereg(osl_t *osh, struct sbpcieregs *pcieregs, 52extern uint pcie_writereg(struct osl_info *osh, struct sbpcieregs *pcieregs,
53 uint addrtype, uint offset, uint val); 53 uint addrtype, uint offset, uint val);
54 54
55extern u8 pcie_clkreq(void *pch, u32 mask, u32 val); 55extern u8 pcie_clkreq(void *pch, u32 mask, u32 val);
56extern u32 pcie_lcreg(void *pch, u32 mask, u32 val); 56extern u32 pcie_lcreg(void *pch, u32 mask, u32 val);
57 57
58extern void *pcicore_init(si_t *sih, osl_t *osh, void *regs); 58extern void *pcicore_init(si_t *sih, struct osl_info *osh, void *regs);
59extern void pcicore_deinit(void *pch); 59extern void pcicore_deinit(void *pch);
60extern void pcicore_attach(void *pch, char *pvars, int state); 60extern void pcicore_attach(void *pch, char *pvars, int state);
61extern void pcicore_hwup(void *pch); 61extern void pcicore_hwup(void *pch);
@@ -70,10 +70,10 @@ extern u32 pcicore_pcieserdesreg(void *pch, u32 mdioslave, u32 offset,
70extern u32 pcicore_pciereg(void *pch, u32 offset, u32 mask, 70extern u32 pcicore_pciereg(void *pch, u32 offset, u32 mask,
71 u32 val, uint type); 71 u32 val, uint type);
72 72
73extern bool pcicore_pmecap_fast(osl_t *osh); 73extern bool pcicore_pmecap_fast(struct osl_info *osh);
74extern void pcicore_pmeen(void *pch); 74extern void pcicore_pmeen(void *pch);
75extern void pcicore_pmeclr(void *pch); 75extern void pcicore_pmeclr(void *pch);
76extern bool pcicore_pmestat(void *pch); 76extern bool pcicore_pmestat(void *pch);
77#endif /* defined(BCMSDIO) || (defined(BCMBUSTYPE) && (BCMBUSTYPE == SI_BUS)) */ 77#endif /* defined(BCMSDIO)||(defined(BCMBUSTYPE) && (BCMBUSTYPE==SI_BUS)) */
78 78
79#endif /* _NICPCI_H */ 79#endif /* _NICPCI_H */
diff --git a/drivers/staging/brcm80211/include/osl.h b/drivers/staging/brcm80211/include/osl.h
index c0ebb3d97220..b28235618d8b 100644
--- a/drivers/staging/brcm80211/include/osl.h
+++ b/drivers/staging/brcm80211/include/osl.h
@@ -18,42 +18,197 @@
18#define _osl_h_ 18#define _osl_h_
19 19
20/* osl handle type forward declaration */ 20/* osl handle type forward declaration */
21typedef struct osl_info osl_t; 21struct osl_info {
22 uint pktalloced; /* Number of allocated packet buffers */
23 bool mmbus; /* Bus supports memory-mapped registers */
24 uint magic;
25 void *pdev;
26 uint bustype;
27};
28
22typedef struct osl_dmainfo osldma_t; 29typedef struct osl_dmainfo osldma_t;
23 30
24#define OSL_PKTTAG_SZ 32 /* Size of PktTag */
25 31
26/* Drivers use PKTFREESETCB to register a callback function when a packet is freed by OSL */ 32extern struct osl_info *osl_attach(void *pdev, uint bustype);
27typedef void (*pktfree_cb_fn_t) (void *ctx, void *pkt, unsigned int status); 33extern void osl_detach(struct osl_info *osh);
28 34
29#ifdef BCMSDIO 35extern u32 g_assert_type;
30/* Drivers use REGOPSSET() to register register read/write funcitons */
31typedef unsigned int (*osl_rreg_fn_t) (void *ctx, void *reg, unsigned int size);
32typedef void (*osl_wreg_fn_t) (void *ctx, void *reg, unsigned int val,
33 unsigned int size);
34#endif
35 36
36#include <linux_osl.h> 37#if defined(BCMDBG_ASSERT)
38#define ASSERT(exp) \
39 do { if (!(exp)) osl_assert(#exp, __FILE__, __LINE__); } while (0)
40extern void osl_assert(char *exp, char *file, int line);
41#else
42#define ASSERT(exp) do {} while (0)
43#endif /* defined(BCMDBG_ASSERT) */
37 44
38/* -------------------------------------------------------------------------- 45/* PCI device bus # and slot # */
39** Register manipulation macros. 46#define OSL_PCI_BUS(osh) osl_pci_bus(osh)
40*/ 47#define OSL_PCI_SLOT(osh) osl_pci_slot(osh)
48extern uint osl_pci_bus(struct osl_info *osh);
49extern uint osl_pci_slot(struct osl_info *osh);
41 50
42#define SET_REG(osh, r, mask, val) W_REG((osh), (r), ((R_REG((osh), r) & ~(mask)) | (val))) 51#define BUS_SWAP32(v) (v)
43 52
44#ifndef AND_REG 53extern void *osl_dma_alloc_consistent(struct osl_info *osh, uint size,
45#define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v)) 54 u16 align, uint *tot, unsigned long *pap);
46#endif /* !AND_REG */ 55
56#ifdef BRCM_FULLMAC
57#define DMA_ALLOC_CONSISTENT(osh, size, pap, dmah, alignbits) \
58 osl_dma_alloc_consistent((osh), (size), (0), (tot), (pap))
59#else
60#define DMA_ALLOC_CONSISTENT(osh, size, align, tot, pap, dmah) \
61 osl_dma_alloc_consistent((osh), (size), (align), (tot), (pap))
62#endif /* BRCM_FULLMAC */
47 63
48#ifndef OR_REG 64#define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
49#define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v)) 65 osl_dma_free_consistent((osh), (void *)(va), (size), (pa))
50#endif /* !OR_REG */ 66extern void osl_dma_free_consistent(struct osl_info *osh, void *va,
67 uint size, unsigned long pa);
68
69/* map/unmap direction */
70#define DMA_TX 1 /* TX direction for DMA */
71#define DMA_RX 2 /* RX direction for DMA */
72
73/* map/unmap shared (dma-able) memory */
74#define DMA_MAP(osh, va, size, direction, p, dmah) \
75 osl_dma_map((osh), (va), (size), (direction))
76#define DMA_UNMAP(osh, pa, size, direction, p, dmah) \
77 osl_dma_unmap((osh), (pa), (size), (direction))
78extern uint osl_dma_map(struct osl_info *osh, void *va, uint size,
79 int direction);
80extern void osl_dma_unmap(struct osl_info *osh, uint pa, uint size,
81 int direction);
82
83/* register access macros */
84#if defined(BCMSDIO)
85#ifdef BRCM_FULLMAC
86#include <bcmsdh.h>
87#endif
88#define OSL_WRITE_REG(osh, r, v) \
89 (bcmsdh_reg_write(NULL, (unsigned long)(r), sizeof(*(r)), (v)))
90#define OSL_READ_REG(osh, r) \
91 (bcmsdh_reg_read(NULL, (unsigned long)(r), sizeof(*(r))))
92#endif
51 93
52#if !defined(OSL_SYSUPTIME) 94#if defined(BCMSDIO)
53#define OSL_SYSUPTIME() (0) 95#define SELECT_BUS_WRITE(osh, mmap_op, bus_op) \
54#define OSL_SYSUPTIME_SUPPORT false 96 if ((osh)->mmbus) \
97 mmap_op else bus_op
98#define SELECT_BUS_READ(osh, mmap_op, bus_op) \
99 ((osh)->mmbus) ? mmap_op : bus_op
55#else 100#else
56#define OSL_SYSUPTIME_SUPPORT true 101#define SELECT_BUS_WRITE(osh, mmap_op, bus_op) mmap_op
57#endif /* OSL_SYSUPTIME */ 102#define SELECT_BUS_READ(osh, mmap_op, bus_op) mmap_op
103#endif
104
105/* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
106#define PKTBUFSZ 2048
107
108#define OSL_SYSUPTIME() ((u32)jiffies * (1000 / HZ))
109#define printf(fmt, args...) printk(fmt , ## args)
110#ifdef BRCM_FULLMAC
111#include <linux/kernel.h> /* for vsn/printf's */
112#include <linux/string.h> /* for mem*, str* */
113#endif
114/* bcopy's: Linux kernel doesn't provide these (anymore) */
115#define bcopy(src, dst, len) memcpy((dst), (src), (len))
116
117/* register access macros */
118#ifndef IL_BIGENDIAN
119#ifndef __mips__
120#define R_REG(osh, r) (\
121 SELECT_BUS_READ(osh, sizeof(*(r)) == sizeof(u8) ? \
122 readb((volatile u8*)(r)) : \
123 sizeof(*(r)) == sizeof(u16) ? readw((volatile u16*)(r)) : \
124 readl((volatile u32*)(r)), OSL_READ_REG(osh, r)) \
125)
126#else /* __mips__ */
127#define R_REG(osh, r) (\
128 SELECT_BUS_READ(osh, \
129 ({ \
130 __typeof(*(r)) __osl_v; \
131 __asm__ __volatile__("sync"); \
132 switch (sizeof(*(r))) { \
133 case sizeof(u8): \
134 __osl_v = readb((volatile u8*)(r)); \
135 break; \
136 case sizeof(u16): \
137 __osl_v = readw((volatile u16*)(r)); \
138 break; \
139 case sizeof(u32): \
140 __osl_v = \
141 readl((volatile u32*)(r)); \
142 break; \
143 } \
144 __asm__ __volatile__("sync"); \
145 __osl_v; \
146 }), \
147 ({ \
148 __typeof(*(r)) __osl_v; \
149 __asm__ __volatile__("sync"); \
150 __osl_v = OSL_READ_REG(osh, r); \
151 __asm__ __volatile__("sync"); \
152 __osl_v; \
153 })) \
154)
155#endif /* __mips__ */
156
157#define W_REG(osh, r, v) do { \
158 SELECT_BUS_WRITE(osh, \
159 switch (sizeof(*(r))) { \
160 case sizeof(u8): \
161 writeb((u8)(v), (volatile u8*)(r)); break; \
162 case sizeof(u16): \
163 writew((u16)(v), (volatile u16*)(r)); break; \
164 case sizeof(u32): \
165 writel((u32)(v), (volatile u32*)(r)); break; \
166 }, \
167 (OSL_WRITE_REG(osh, r, v))); \
168 } while (0)
169#else /* IL_BIGENDIAN */
170#define R_REG(osh, r) (\
171 SELECT_BUS_READ(osh, \
172 ({ \
173 __typeof(*(r)) __osl_v; \
174 switch (sizeof(*(r))) { \
175 case sizeof(u8): \
176 __osl_v = \
177 readb((volatile u8*)((r)^3)); \
178 break; \
179 case sizeof(u16): \
180 __osl_v = \
181 readw((volatile u16*)((r)^2)); \
182 break; \
183 case sizeof(u32): \
184 __osl_v = readl((volatile u32*)(r)); \
185 break; \
186 } \
187 __osl_v; \
188 }), \
189 OSL_READ_REG(osh, r)) \
190)
191#define W_REG(osh, r, v) do { \
192 SELECT_BUS_WRITE(osh, \
193 switch (sizeof(*(r))) { \
194 case sizeof(u8): \
195 writeb((u8)(v), \
196 (volatile u8*)((r)^3)); break; \
197 case sizeof(u16): \
198 writew((u16)(v), \
199 (volatile u16*)((r)^2)); break; \
200 case sizeof(u32): \
201 writel((u32)(v), \
202 (volatile u32*)(r)); break; \
203 }, \
204 (OSL_WRITE_REG(osh, r, v))); \
205 } while (0)
206#endif /* IL_BIGENDIAN */
207
208#define bcopy(src, dst, len) memcpy((dst), (src), (len))
209
210/* packet primitives */
211extern struct sk_buff *pkt_buf_get_skb(struct osl_info *osh, uint len);
212extern void pkt_buf_free_skb(struct osl_info *osh, struct sk_buff *skb, bool send);
58 213
59#endif /* _osl_h_ */ 214#endif /* _osl_h_ */
diff --git a/drivers/staging/brcm80211/include/proto/ethernet.h b/drivers/staging/brcm80211/include/proto/ethernet.h
index cc17b428dd3f..567407de020e 100644
--- a/drivers/staging/brcm80211/include/proto/ethernet.h
+++ b/drivers/staging/brcm80211/include/proto/ethernet.h
@@ -17,28 +17,22 @@
17#ifndef _NET_ETHERNET_H_ 17#ifndef _NET_ETHERNET_H_
18#define _NET_ETHERNET_H_ 18#define _NET_ETHERNET_H_
19 19
20#include <linux/if_ether.h>
21
20#include <packed_section_start.h> 22#include <packed_section_start.h>
21 23
22#define ETHER_ADDR_LEN 6
23#define ETHER_TYPE_LEN 2 24#define ETHER_TYPE_LEN 2
24#define ETHER_CRC_LEN 4 25#define ETHER_CRC_LEN 4
25#define ETHER_HDR_LEN (ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN)
26#define ETHER_MIN_LEN 64 26#define ETHER_MIN_LEN 64
27#define ETHER_MIN_DATA 46 27#define ETHER_MIN_DATA 46
28#define ETHER_MAX_LEN 1518 28#define ETHER_MAX_LEN 1518
29#define ETHER_MAX_DATA 1500 29#define ETHER_MAX_DATA 1500
30 30
31#define ETHER_TYPE_MIN 0x0600
32#define ETHER_TYPE_IP 0x0800
33#define ETHER_TYPE_ARP 0x0806
34#define ETHER_TYPE_8021Q 0x8100
35#define ETHER_TYPE_BRCM 0x886c 31#define ETHER_TYPE_BRCM 0x886c
36#define ETHER_TYPE_802_1X 0x888e
37#define ETHER_TYPE_802_1X_PREAUTH 0x88c7
38 32
39#define ETHER_DEST_OFFSET (0 * ETHER_ADDR_LEN) 33#define ETHER_DEST_OFFSET (0 * ETH_ALEN)
40#define ETHER_SRC_OFFSET (1 * ETHER_ADDR_LEN) 34#define ETHER_SRC_OFFSET (1 * ETH_ALEN)
41#define ETHER_TYPE_OFFSET (2 * ETHER_ADDR_LEN) 35#define ETHER_TYPE_OFFSET (2 * ETH_ALEN)
42 36
43#define ETHER_IS_VALID_LEN(foo) \ 37#define ETHER_IS_VALID_LEN(foo) \
44 ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) 38 ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
@@ -53,50 +47,18 @@
53} 47}
54 48
55BWL_PRE_PACKED_STRUCT struct ether_header { 49BWL_PRE_PACKED_STRUCT struct ether_header {
56 u8 ether_dhost[ETHER_ADDR_LEN]; 50 u8 ether_dhost[ETH_ALEN];
57 u8 ether_shost[ETHER_ADDR_LEN]; 51 u8 ether_shost[ETH_ALEN];
58 u16 ether_type; 52 u16 ether_type;
59} BWL_POST_PACKED_STRUCT; 53} BWL_POST_PACKED_STRUCT;
60 54
61BWL_PRE_PACKED_STRUCT struct ether_addr { 55BWL_PRE_PACKED_STRUCT struct ether_addr {
62 u8 octet[ETHER_ADDR_LEN]; 56 u8 octet[ETH_ALEN];
63} BWL_POST_PACKED_STRUCT; 57} BWL_POST_PACKED_STRUCT;
64 58
65#define ETHER_SET_LOCALADDR(ea) (((u8 *)(ea))[0] = (((u8 *)(ea))[0] | 2))
66#define ETHER_IS_LOCALADDR(ea) (((u8 *)(ea))[0] & 2)
67#define ETHER_CLR_LOCALADDR(ea) (((u8 *)(ea))[0] = \
68 (((u8 *)(ea))[0] & 0xd))
69#define ETHER_TOGGLE_LOCALADDR(ea) (((u8 *)(ea))[0] = \
70 (((u8 *)(ea))[0] ^ 2))
71
72#define ETHER_SET_UNICAST(ea) (((u8 *)(ea))[0] = (((u8 *)(ea))[0] & ~1)) 59#define ETHER_SET_UNICAST(ea) (((u8 *)(ea))[0] = (((u8 *)(ea))[0] & ~1))
73 60
74#define ETHER_ISMULTI(ea) (((const u8 *)(ea))[0] & 1)
75
76#define ether_cmp(a, b) (!(((short *)a)[0] == ((short *)b)[0]) | \
77 !(((short *)a)[1] == ((short *)b)[1]) | \
78 !(((short *)a)[2] == ((short *)b)[2]))
79
80#define ether_copy(s, d) { \
81 ((short *)d)[0] = ((short *)s)[0]; \
82 ((short *)d)[1] = ((short *)s)[1]; \
83 ((short *)d)[2] = ((short *)s)[2]; }
84
85static const struct ether_addr ether_bcast = { {255, 255, 255, 255, 255, 255} }; 61static const struct ether_addr ether_bcast = { {255, 255, 255, 255, 255, 255} };
86static const struct ether_addr ether_null = { {0, 0, 0, 0, 0, 0} };
87
88#define ETHER_ISBCAST(ea) ((((u8 *)(ea))[0] & \
89 ((u8 *)(ea))[1] & \
90 ((u8 *)(ea))[2] & \
91 ((u8 *)(ea))[3] & \
92 ((u8 *)(ea))[4] & \
93 ((u8 *)(ea))[5]) == 0xff)
94#define ETHER_ISNULLADDR(ea) ((((u8 *)(ea))[0] | \
95 ((u8 *)(ea))[1] | \
96 ((u8 *)(ea))[2] | \
97 ((u8 *)(ea))[3] | \
98 ((u8 *)(ea))[4] | \
99 ((u8 *)(ea))[5]) == 0)
100 62
101#define ETHER_MOVE_HDR(d, s) \ 63#define ETHER_MOVE_HDR(d, s) \
102do { \ 64do { \
diff --git a/drivers/staging/brcm80211/include/proto/wpa.h b/drivers/staging/brcm80211/include/proto/wpa.h
index ec84c9f2b5ee..10c2fb62df09 100644
--- a/drivers/staging/brcm80211/include/proto/wpa.h
+++ b/drivers/staging/brcm80211/include/proto/wpa.h
@@ -19,95 +19,7 @@
19 19
20#include <proto/ethernet.h> 20#include <proto/ethernet.h>
21 21
22#include <packed_section_start.h>
23
24#define DOT11_RC_INVALID_WPA_IE 13
25#define DOT11_RC_MIC_FAILURE 14
26#define DOT11_RC_4WH_TIMEOUT 15
27#define DOT11_RC_GTK_UPDATE_TIMEOUT 16
28#define DOT11_RC_WPA_IE_MISMATCH 17
29#define DOT11_RC_INVALID_MC_CIPHER 18
30#define DOT11_RC_INVALID_UC_CIPHER 19
31#define DOT11_RC_INVALID_AKMP 20
32#define DOT11_RC_BAD_WPA_VERSION 21
33#define DOT11_RC_INVALID_WPA_CAP 22
34#define DOT11_RC_8021X_AUTH_FAIL 23
35
36#define WPA2_PMKID_LEN 16 22#define WPA2_PMKID_LEN 16
37
38typedef BWL_PRE_PACKED_STRUCT struct {
39 u8 tag;
40 u8 length;
41 u8 oui[3];
42 u8 oui_type;
43 BWL_PRE_PACKED_STRUCT struct {
44 u8 low;
45 u8 high;
46 } BWL_POST_PACKED_STRUCT version;
47} BWL_POST_PACKED_STRUCT wpa_ie_fixed_t;
48#define WPA_IE_OUITYPE_LEN 4
49#define WPA_IE_FIXED_LEN 8
50#define WPA_IE_TAG_FIXED_LEN 6
51
52typedef BWL_PRE_PACKED_STRUCT struct {
53 u8 tag;
54 u8 length;
55 BWL_PRE_PACKED_STRUCT struct {
56 u8 low;
57 u8 high;
58 } BWL_POST_PACKED_STRUCT version;
59} BWL_POST_PACKED_STRUCT wpa_rsn_ie_fixed_t;
60#define WPA_RSN_IE_FIXED_LEN 4
61#define WPA_RSN_IE_TAG_FIXED_LEN 2
62typedef u8 wpa_pmkid_t[WPA2_PMKID_LEN];
63
64typedef BWL_PRE_PACKED_STRUCT struct {
65 u8 oui[3];
66 u8 type;
67} BWL_POST_PACKED_STRUCT wpa_suite_t, wpa_suite_mcast_t;
68#define WPA_SUITE_LEN 4
69
70typedef BWL_PRE_PACKED_STRUCT struct {
71 BWL_PRE_PACKED_STRUCT struct {
72 u8 low;
73 u8 high;
74 } BWL_POST_PACKED_STRUCT count;
75 wpa_suite_t list[1];
76} BWL_POST_PACKED_STRUCT wpa_suite_ucast_t, wpa_suite_auth_key_mgmt_t;
77#define WPA_IE_SUITE_COUNT_LEN 2
78typedef BWL_PRE_PACKED_STRUCT struct {
79 BWL_PRE_PACKED_STRUCT struct {
80 u8 low;
81 u8 high;
82 } BWL_POST_PACKED_STRUCT count;
83 wpa_pmkid_t list[1];
84} BWL_POST_PACKED_STRUCT wpa_pmkid_list_t;
85
86#define WPA_CIPHER_NONE 0
87#define WPA_CIPHER_WEP_40 1
88#define WPA_CIPHER_TKIP 2
89#define WPA_CIPHER_AES_OCB 3
90#define WPA_CIPHER_AES_CCM 4
91#define WPA_CIPHER_WEP_104 5
92
93#define IS_WPA_CIPHER(cipher) ((cipher) == WPA_CIPHER_NONE || \
94 (cipher) == WPA_CIPHER_WEP_40 || \
95 (cipher) == WPA_CIPHER_WEP_104 || \
96 (cipher) == WPA_CIPHER_TKIP || \
97 (cipher) == WPA_CIPHER_AES_OCB || \
98 (cipher) == WPA_CIPHER_AES_CCM)
99
100#define WPA_TKIP_CM_DETECT 60
101#define WPA_TKIP_CM_BLOCK 60
102
103#define RSN_CAP_LEN 2
104
105#define RSN_CAP_PREAUTH 0x0001
106#define RSN_CAP_NOPAIRWISE 0x0002
107#define RSN_CAP_PTK_REPLAY_CNTR_MASK 0x000C
108#define RSN_CAP_PTK_REPLAY_CNTR_SHIFT 2
109#define RSN_CAP_GTK_REPLAY_CNTR_MASK 0x0030
110#define RSN_CAP_GTK_REPLAY_CNTR_SHIFT 4
111#define RSN_CAP_1_REPLAY_CNTR 0 23#define RSN_CAP_1_REPLAY_CNTR 0
112#define RSN_CAP_2_REPLAY_CNTRS 1 24#define RSN_CAP_2_REPLAY_CNTRS 1
113#define RSN_CAP_4_REPLAY_CNTRS 2 25#define RSN_CAP_4_REPLAY_CNTRS 2
@@ -118,10 +30,4 @@ typedef BWL_PRE_PACKED_STRUCT struct {
118#define WPA_CAP_REPLAY_CNTR_SHIFT RSN_CAP_PTK_REPLAY_CNTR_SHIFT 30#define WPA_CAP_REPLAY_CNTR_SHIFT RSN_CAP_PTK_REPLAY_CNTR_SHIFT
119#define WPA_CAP_REPLAY_CNTR_MASK RSN_CAP_PTK_REPLAY_CNTR_MASK 31#define WPA_CAP_REPLAY_CNTR_MASK RSN_CAP_PTK_REPLAY_CNTR_MASK
120 32
121#define WPA_CAP_LEN RSN_CAP_LEN
122
123#define WPA_CAP_WPA2_PREAUTH RSN_CAP_PREAUTH
124
125#include <packed_section_end.h>
126
127#endif /* _proto_wpa_h_ */ 33#endif /* _proto_wpa_h_ */
diff --git a/drivers/staging/brcm80211/include/rpc_osl.h b/drivers/staging/brcm80211/include/rpc_osl.h
index 4a2648001bf0..c59d9ed1397a 100644
--- a/drivers/staging/brcm80211/include/rpc_osl.h
+++ b/drivers/staging/brcm80211/include/rpc_osl.h
@@ -18,7 +18,7 @@
18#define _rpcosl_h_ 18#define _rpcosl_h_
19 19
20typedef struct rpc_osl rpc_osl_t; 20typedef struct rpc_osl rpc_osl_t;
21extern rpc_osl_t *rpc_osl_attach(osl_t *osh); 21extern rpc_osl_t *rpc_osl_attach(struct osl_info *osh);
22extern void rpc_osl_detach(rpc_osl_t *rpc_osh); 22extern void rpc_osl_detach(rpc_osl_t *rpc_osh);
23 23
24#define RPC_OSL_LOCK(rpc_osh) rpc_osl_lock((rpc_osh)) 24#define RPC_OSL_LOCK(rpc_osh) rpc_osl_lock((rpc_osh))
diff --git a/drivers/staging/brcm80211/include/siutils.h b/drivers/staging/brcm80211/include/siutils.h
index 57c36507a040..a935092d02df 100644
--- a/drivers/staging/brcm80211/include/siutils.h
+++ b/drivers/staging/brcm80211/include/siutils.h
@@ -19,9 +19,6 @@
19 19
20#include <hndsoc.h> 20#include <hndsoc.h>
21 21
22#if !defined(WLC_LOW)
23#include "bcm_rpc.h"
24#endif
25/* 22/*
26 * Data structure to export all chip specific common variables 23 * Data structure to export all chip specific common variables
27 * public (read-only) portion of siutils handle returned by si_attach() 24 * public (read-only) portion of siutils handle returned by si_attach()
@@ -50,19 +47,12 @@ struct si_pub {
50 uint socirev; /* SOC interconnect rev */ 47 uint socirev; /* SOC interconnect rev */
51 bool pci_pr32414; 48 bool pci_pr32414;
52 49
53#if !defined(WLC_LOW)
54 rpc_info_t *rpc;
55#endif
56}; 50};
57 51
58/* for HIGH_ONLY driver, the si_t must be writable to allow states sync from BMAC to HIGH driver 52/* for HIGH_ONLY driver, the si_t must be writable to allow states sync from BMAC to HIGH driver
59 * for monolithic driver, it is readonly to prevent accident change 53 * for monolithic driver, it is readonly to prevent accident change
60 */ 54 */
61#if !defined(WLC_LOW)
62typedef struct si_pub si_t;
63#else
64typedef const struct si_pub si_t; 55typedef const struct si_pub si_t;
65#endif
66 56
67/* 57/*
68 * Many of the routines below take an 'sih' handle as their first arg. 58 * Many of the routines below take an 'sih' handle as their first arg.
@@ -128,8 +118,8 @@ typedef void (*gpio_handler_t) (u32 stat, void *arg);
128#define GPIO_CTRL_EPA_EN_MASK 0x40 118#define GPIO_CTRL_EPA_EN_MASK 0x40
129 119
130/* === exported functions === */ 120/* === exported functions === */
131extern si_t *si_attach(uint pcidev, osl_t *osh, void *regs, uint bustype, 121extern si_t *si_attach(uint pcidev, struct osl_info *osh, void *regs,
132 void *sdh, char **vars, uint *varsz); 122 uint bustype, void *sdh, char **vars, uint *varsz);
133 123
134extern void si_detach(si_t *sih); 124extern void si_detach(si_t *sih);
135extern bool si_pci_war16165(si_t *sih); 125extern bool si_pci_war16165(si_t *sih);
@@ -138,7 +128,7 @@ extern uint si_coreid(si_t *sih);
138extern uint si_flag(si_t *sih); 128extern uint si_flag(si_t *sih);
139extern uint si_coreidx(si_t *sih); 129extern uint si_coreidx(si_t *sih);
140extern uint si_corerev(si_t *sih); 130extern uint si_corerev(si_t *sih);
141extern void *si_osh(si_t *sih); 131struct osl_info *si_osh(si_t *sih);
142extern uint si_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, 132extern uint si_corereg(si_t *sih, uint coreidx, uint regoff, uint mask,
143 uint val); 133 uint val);
144extern void si_write_wrapperreg(si_t *sih, u32 offset, u32 val); 134extern void si_write_wrapperreg(si_t *sih, u32 offset, u32 val);
@@ -227,7 +217,7 @@ typedef struct gpioh_item {
227/* misc si info needed by some of the routines */ 217/* misc si info needed by some of the routines */
228typedef struct si_info { 218typedef struct si_info {
229 struct si_pub pub; /* back plane public state (must be first field) */ 219 struct si_pub pub; /* back plane public state (must be first field) */
230 void *osh; /* osl os handle */ 220 struct osl_info *osh; /* osl os handle */
231 void *sdh; /* bcmsdh handle */ 221 void *sdh; /* bcmsdh handle */
232 uint dev_coreid; /* the core provides driver functions */ 222 uint dev_coreid; /* the core provides driver functions */
233 void *intr_arg; /* interrupt callback function arg */ 223 void *intr_arg; /* interrupt callback function arg */
@@ -305,9 +295,9 @@ typedef struct si_info {
305#define ILP_DIV_5MHZ 0 /* ILP = 5 MHz */ 295#define ILP_DIV_5MHZ 0 /* ILP = 5 MHz */
306#define ILP_DIV_1MHZ 4 /* ILP = 1 MHz */ 296#define ILP_DIV_1MHZ 4 /* ILP = 1 MHz */
307 297
308#define PCI(si) ((BUSTYPE((si)->pub.bustype) == PCI_BUS) && \ 298#define PCI(si) (((si)->pub.bustype == PCI_BUS) && \
309 ((si)->pub.buscoretype == PCI_CORE_ID)) 299 ((si)->pub.buscoretype == PCI_CORE_ID))
310#define PCIE(si) ((BUSTYPE((si)->pub.bustype) == PCI_BUS) && \ 300#define PCIE(si) (((si)->pub.bustype == PCI_BUS) && \
311 ((si)->pub.buscoretype == PCIE_CORE_ID)) 301 ((si)->pub.buscoretype == PCIE_CORE_ID))
312#define PCI_FORCEHT(si) \ 302#define PCI_FORCEHT(si) \
313 (PCIE(si) && (si->pub.chip == BCM4716_CHIP_ID)) 303 (PCIE(si) && (si->pub.chip == BCM4716_CHIP_ID))
@@ -344,9 +334,9 @@ extern void si_epa_4313war(si_t *sih);
344char *si_getnvramflvar(si_t *sih, const char *name); 334char *si_getnvramflvar(si_t *sih, const char *name);
345 335
346/* AMBA Interconnect exported externs */ 336/* AMBA Interconnect exported externs */
347extern si_t *ai_attach(uint pcidev, osl_t *osh, void *regs, uint bustype, 337extern si_t *ai_attach(uint pcidev, struct osl_info *osh, void *regs,
348 void *sdh, char **vars, uint *varsz); 338 uint bustype, void *sdh, char **vars, uint *varsz);
349extern si_t *ai_kattach(osl_t *osh); 339extern si_t *ai_kattach(struct osl_info *osh);
350extern void ai_scan(si_t *sih, void *regs, uint devid); 340extern void ai_scan(si_t *sih, void *regs, uint devid);
351 341
352extern uint ai_flag(si_t *sih); 342extern uint ai_flag(si_t *sih);
diff --git a/drivers/staging/brcm80211/include/wlioctl.h b/drivers/staging/brcm80211/include/wlioctl.h
index 96866fb8898c..9be793c5f10c 100644
--- a/drivers/staging/brcm80211/include/wlioctl.h
+++ b/drivers/staging/brcm80211/include/wlioctl.h
@@ -33,82 +33,9 @@
33#define BWL_DEFAULT_PACKING 33#define BWL_DEFAULT_PACKING
34#include <packed_section_start.h> 34#include <packed_section_start.h>
35 35
36/* Legacy structure to help keep backward compatible wl tool and tray app */
37
38#define LEGACY_WL_BSS_INFO_VERSION 107 /* older version of wl_bss_info struct */
39
40typedef struct wl_bss_info_107 {
41 u32 version; /* version field */
42 u32 length; /* byte length of data in this record,
43 * starting at version and including IEs
44 */
45 struct ether_addr BSSID;
46 u16 beacon_period; /* units are Kusec */
47 u16 capability; /* Capability information */
48 u8 SSID_len;
49 u8 SSID[32];
50 struct {
51 uint count; /* # rates in this set */
52 u8 rates[16]; /* rates in 500kbps units w/hi bit set if basic */
53 } rateset; /* supported rates */
54 u8 channel; /* Channel no. */
55 u16 atim_window; /* units are Kusec */
56 u8 dtim_period; /* DTIM period */
57 s16 RSSI; /* receive signal strength (in dBm) */
58 s8 phy_noise; /* noise (in dBm) */
59 u32 ie_length; /* byte length of Information Elements */
60 /* variable length Information Elements */
61} wl_bss_info_107_t;
62
63/*
64 * Per-BSS information structure.
65 */
66
67#define LEGACY2_WL_BSS_INFO_VERSION 108 /* old version of wl_bss_info struct */
68
69/* BSS info structure
70 * Applications MUST CHECK ie_offset field and length field to access IEs and
71 * next bss_info structure in a vector (in wl_scan_results_t)
72 */
73typedef struct wl_bss_info_108 {
74 u32 version; /* version field */
75 u32 length; /* byte length of data in this record,
76 * starting at version and including IEs
77 */
78 struct ether_addr BSSID;
79 u16 beacon_period; /* units are Kusec */
80 u16 capability; /* Capability information */
81 u8 SSID_len;
82 u8 SSID[32];
83 struct {
84 uint count; /* # rates in this set */
85 u8 rates[16]; /* rates in 500kbps units w/hi bit set if basic */
86 } rateset; /* supported rates */
87 chanspec_t chanspec; /* chanspec for bss */
88 u16 atim_window; /* units are Kusec */
89 u8 dtim_period; /* DTIM period */
90 s16 RSSI; /* receive signal strength (in dBm) */
91 s8 phy_noise; /* noise (in dBm) */
92
93 u8 n_cap; /* BSS is 802.11N Capable */
94 u32 nbss_cap; /* 802.11N BSS Capabilities (based on HT_CAP_*) */
95 u8 ctl_ch; /* 802.11N BSS control channel number */
96 u32 reserved32[1]; /* Reserved for expansion of BSS properties */
97 u8 flags; /* flags */
98 u8 reserved[3]; /* Reserved for expansion of BSS properties */
99 u8 basic_mcs[MCSSET_LEN]; /* 802.11N BSS required MCS set */
100
101 u16 ie_offset; /* offset at which IEs start, from beginning */
102 u32 ie_length; /* byte length of Information Elements */
103 /* Add new fields here */
104 /* variable length Information Elements */
105} wl_bss_info_108_t;
106
107#ifdef BRCM_FULLMAC 36#ifdef BRCM_FULLMAC
37
108#define WL_BSS_INFO_VERSION 108 /* current ver of wl_bss_info struct */ 38#define WL_BSS_INFO_VERSION 108 /* current ver of wl_bss_info struct */
109#else
110#define WL_BSS_INFO_VERSION 109 /* current ver of wl_bss_info struct */
111#endif
112 39
113/* BSS info structure 40/* BSS info structure
114 * Applications MUST CHECK ie_offset field and length field to access IEs and 41 * Applications MUST CHECK ie_offset field and length field to access IEs and
@@ -148,12 +75,14 @@ typedef struct wl_bss_info {
148 /* Add new fields here */ 75 /* Add new fields here */
149 /* variable length Information Elements */ 76 /* variable length Information Elements */
150} wl_bss_info_t; 77} wl_bss_info_t;
78#endif /* BRCM_FULLMAC */
151 79
152typedef struct wlc_ssid { 80typedef struct wlc_ssid {
153 u32 SSID_len; 81 u32 SSID_len;
154 unsigned char SSID[32]; 82 unsigned char SSID[32];
155} wlc_ssid_t; 83} wlc_ssid_t;
156 84
85#ifdef BRCM_FULLMAC
157typedef struct chan_scandata { 86typedef struct chan_scandata {
158 u8 txpower; 87 u8 txpower;
159 u8 pad; 88 u8 pad;
@@ -308,6 +237,7 @@ typedef struct wl_probe_params {
308 struct ether_addr bssid; 237 struct ether_addr bssid;
309 struct ether_addr mac; 238 struct ether_addr mac;
310} wl_probe_params_t; 239} wl_probe_params_t;
240#endif /* BRCM_FULLMAC */
311 241
312#define WL_NUMRATES 16 /* max # of rates in a rateset */ 242#define WL_NUMRATES 16 /* max # of rates in a rateset */
313typedef struct wl_rateset { 243typedef struct wl_rateset {
@@ -315,6 +245,7 @@ typedef struct wl_rateset {
315 u8 rates[WL_NUMRATES]; /* rates in 500kbps units w/hi bit set if basic */ 245 u8 rates[WL_NUMRATES]; /* rates in 500kbps units w/hi bit set if basic */
316} wl_rateset_t; 246} wl_rateset_t;
317 247
248#ifdef BRCM_FULLMAC
318typedef struct wl_rateset_args { 249typedef struct wl_rateset_args {
319 u32 count; /* # rates in this set */ 250 u32 count; /* # rates in this set */
320 u8 rates[WL_NUMRATES]; /* rates in 500kbps units w/hi bit set if basic */ 251 u8 rates[WL_NUMRATES]; /* rates in 500kbps units w/hi bit set if basic */
@@ -352,6 +283,8 @@ typedef struct wl_join_params {
352} wl_join_params_t; 283} wl_join_params_t;
353#define WL_JOIN_PARAMS_FIXED_SIZE (sizeof(wl_join_params_t) - sizeof(chanspec_t)) 284#define WL_JOIN_PARAMS_FIXED_SIZE (sizeof(wl_join_params_t) - sizeof(chanspec_t))
354 285
286#endif /* BRCM_FULLMAC */
287
355/* defines used by the nrate iovar */ 288/* defines used by the nrate iovar */
356#define NRATE_MCS_INUSE 0x00000080 /* MSC in use,indicates b0-6 holds an mcs */ 289#define NRATE_MCS_INUSE 0x00000080 /* MSC in use,indicates b0-6 holds an mcs */
357#define NRATE_RATE_MASK 0x0000007f /* rate/mcs value */ 290#define NRATE_RATE_MASK 0x0000007f /* rate/mcs value */
@@ -391,6 +324,7 @@ typedef struct {
391 324
392#define HIGHEST_SINGLE_STREAM_MCS 7 /* MCS values greater than this enable multiple streams */ 325#define HIGHEST_SINGLE_STREAM_MCS 7 /* MCS values greater than this enable multiple streams */
393 326
327#ifdef BRCM_FULLMAC
394#define MAX_CCA_CHANNELS 38 /* Max number of 20 Mhz wide channels */ 328#define MAX_CCA_CHANNELS 38 /* Max number of 20 Mhz wide channels */
395#define MAX_CCA_SECS 60 /* CCA keeps this many seconds history */ 329#define MAX_CCA_SECS 60 /* CCA keeps this many seconds history */
396 330
@@ -428,8 +362,11 @@ typedef struct {
428 cca_congest_t secs[1]; /* Data */ 362 cca_congest_t secs[1]; /* Data */
429} cca_congest_channel_req_t; 363} cca_congest_channel_req_t;
430 364
365#endif /* BRCM_FULLMAC */
366
431#define WLC_CNTRY_BUF_SZ 4 /* Country string is 3 bytes + NUL */ 367#define WLC_CNTRY_BUF_SZ 4 /* Country string is 3 bytes + NUL */
432 368
369#ifdef BRCM_FULLMAC
433typedef struct wl_country { 370typedef struct wl_country {
434 char country_abbrev[WLC_CNTRY_BUF_SZ]; /* nul-terminated country code used in 371 char country_abbrev[WLC_CNTRY_BUF_SZ]; /* nul-terminated country code used in
435 * the Country IE 372 * the Country IE
@@ -516,6 +453,7 @@ typedef struct wl_rm_rep {
516 wl_rm_rep_elt_t rep[1]; /* variable length block of reports */ 453 wl_rm_rep_elt_t rep[1]; /* variable length block of reports */
517} wl_rm_rep_t; 454} wl_rm_rep_t;
518#define WL_RM_REP_FIXED_LEN 8 455#define WL_RM_REP_FIXED_LEN 8
456#endif /* BRCM_FULLMAC */
519 457
520/* Enumerate crypto algorithms */ 458/* Enumerate crypto algorithms */
521#define CRYPTO_ALGO_OFF 0 459#define CRYPTO_ALGO_OFF 0
@@ -621,28 +559,6 @@ typedef struct wl_led_info {
621 u8 activehi; 559 u8 activehi;
622} wl_led_info_t; 560} wl_led_info_t;
623 561
624/* flags */
625#define WLC_ASSOC_REQ_IS_REASSOC 0x01 /* assoc req was actually a reassoc */
626
627/* srom read/write struct passed through ioctl */
628typedef struct {
629 uint byteoff; /* byte offset */
630 uint nbytes; /* number of bytes */
631 u16 buf[1];
632} srom_rw_t;
633
634/* similar cis (srom or otp) struct [iovar: may not be aligned] */
635typedef struct {
636 u32 source; /* cis source */
637 u32 byteoff; /* byte offset */
638 u32 nbytes; /* number of bytes */
639 /* data follows here */
640} cis_rw_t;
641
642#define WLC_CIS_DEFAULT 0 /* built-in default */
643#define WLC_CIS_SROM 1 /* source is sprom */
644#define WLC_CIS_OTP 2 /* source is otp */
645
646/* R_REG and W_REG struct passed through ioctl */ 562/* R_REG and W_REG struct passed through ioctl */
647typedef struct { 563typedef struct {
648 u32 byteoff; /* byte offset of the field in d11regs_t */ 564 u32 byteoff; /* byte offset of the field in d11regs_t */
@@ -651,102 +567,14 @@ typedef struct {
651 uint band; /* band (optional) */ 567 uint band; /* band (optional) */
652} rw_reg_t; 568} rw_reg_t;
653 569
654/* Structure used by GET/SET_ATTEN ioctls - it controls power in b/g-band */
655/* PCL - Power Control Loop */
656/* current gain setting is replaced by user input */
657#define WL_ATTEN_APP_INPUT_PCL_OFF 0 /* turn off PCL, apply supplied input */
658#define WL_ATTEN_PCL_ON 1 /* turn on PCL */
659/* current gain setting is maintained */
660#define WL_ATTEN_PCL_OFF 2 /* turn off PCL. */
661
662typedef struct {
663 u16 auto_ctrl; /* WL_ATTEN_XX */
664 u16 bb; /* Baseband attenuation */
665 u16 radio; /* Radio attenuation */
666 u16 txctl1; /* Radio TX_CTL1 value */
667} atten_t;
668
669/* Per-AC retry parameters */
670struct wme_tx_params_s {
671 u8 short_retry;
672 u8 short_fallback;
673 u8 long_retry;
674 u8 long_fallback;
675 u16 max_rate; /* In units of 512 Kbps */
676};
677
678typedef struct wme_tx_params_s wme_tx_params_t;
679
680#define WL_WME_TX_PARAMS_IO_BYTES (sizeof(wme_tx_params_t) * AC_COUNT)
681
682/* defines used by poweridx iovar - it controls power in a-band */
683/* current gain setting is maintained */
684#define WL_PWRIDX_PCL_OFF -2 /* turn off PCL. */
685#define WL_PWRIDX_PCL_ON -1 /* turn on PCL */
686#define WL_PWRIDX_LOWER_LIMIT -2 /* lower limit */
687#define WL_PWRIDX_UPPER_LIMIT 63 /* upper limit */
688/* value >= 0 causes
689 * - input to be set to that value
690 * - PCL to be off
691 */
692
693/* Used to get specific link/ac parameters */
694typedef struct {
695 int ac;
696 u8 val;
697 struct ether_addr ea;
698} link_val_t;
699
700#define BCM_MAC_STATUS_INDICATION (0x40010200L)
701
702typedef struct {
703 u16 ver; /* version of this struct */
704 u16 len; /* length in bytes of this structure */
705 u16 cap; /* sta's advertised capabilities */
706 u32 flags; /* flags defined below */
707 u32 idle; /* time since data pkt rx'd from sta */
708 struct ether_addr ea; /* Station address */
709 wl_rateset_t rateset; /* rateset in use */
710 u32 in; /* seconds elapsed since associated */
711 u32 listen_interval_inms; /* Min Listen interval in ms for this STA */
712 u32 tx_pkts; /* # of packets transmitted */
713 u32 tx_failures; /* # of packets failed */
714 u32 rx_ucast_pkts; /* # of unicast packets received */
715 u32 rx_mcast_pkts; /* # of multicast packets received */
716 u32 tx_rate; /* Rate of last successful tx frame */
717 u32 rx_rate; /* Rate of last successful rx frame */
718 u32 rx_decrypt_succeeds; /* # of packet decrypted successfully */
719 u32 rx_decrypt_failures; /* # of packet decrypted unsuccessfully */
720} sta_info_t;
721
722#define WL_OLD_STAINFO_SIZE offsetof(sta_info_t, tx_pkts)
723
724#define WL_STA_VER 3
725
726/* Flags for sta_info_t indicating properties of STA */
727#define WL_STA_BRCM 0x1 /* Running a Broadcom driver */
728#define WL_STA_WME 0x2 /* WMM association */
729#define WL_STA_ABCAP 0x4
730#define WL_STA_AUTHE 0x8 /* Authenticated */
731#define WL_STA_ASSOC 0x10 /* Associated */
732#define WL_STA_AUTHO 0x20 /* Authorized */
733#define WL_STA_WDS 0x40 /* Wireless Distribution System */
734#define WL_STA_WDS_LINKUP 0x80 /* WDS traffic/probes flowing properly */
735#define WL_STA_PS 0x100 /* STA is in power save mode from AP's viewpoint */
736#define WL_STA_APSD_BE 0x200 /* APSD delv/trigger for AC_BE is default enabled */
737#define WL_STA_APSD_BK 0x400 /* APSD delv/trigger for AC_BK is default enabled */
738#define WL_STA_APSD_VI 0x800 /* APSD delv/trigger for AC_VI is default enabled */
739#define WL_STA_APSD_VO 0x1000 /* APSD delv/trigger for AC_VO is default enabled */
740#define WL_STA_N_CAP 0x2000 /* STA 802.11n capable */
741#define WL_STA_SCBSTATS 0x4000 /* Per STA debug stats */
742
743#define WL_WDS_LINKUP WL_STA_WDS_LINKUP /* deprecated */
744 570
571#ifdef BRCM_FULLMAC
745/* Used to get specific STA parameters */ 572/* Used to get specific STA parameters */
746typedef struct { 573typedef struct {
747 u32 val; 574 u32 val;
748 struct ether_addr ea; 575 struct ether_addr ea;
749} scb_val_t; 576} scb_val_t;
577#endif /* BRCM_FULLMAC */
750 578
751/* channel encoding */ 579/* channel encoding */
752typedef struct channel_info { 580typedef struct channel_info {
@@ -770,6 +598,7 @@ typedef struct get_pktcnt {
770 uint rx_ocast_good_pkt; /* unicast packets destined for others */ 598 uint rx_ocast_good_pkt; /* unicast packets destined for others */
771} get_pktcnt_t; 599} get_pktcnt_t;
772 600
601#ifdef BRCM_FULLMAC
773/* Linux network driver ioctl encoding */ 602/* Linux network driver ioctl encoding */
774typedef struct wl_ioctl { 603typedef struct wl_ioctl {
775 uint cmd; /* common ioctl definition */ 604 uint cmd; /* common ioctl definition */
@@ -779,11 +608,8 @@ typedef struct wl_ioctl {
779 uint used; /* bytes read or written (optional) */ 608 uint used; /* bytes read or written (optional) */
780 uint needed; /* bytes needed (optional) */ 609 uint needed; /* bytes needed (optional) */
781} wl_ioctl_t; 610} wl_ioctl_t;
611#endif /* BRCM_FULLMAC */
782 612
783/* reference to wl_ioctl_t struct used by usermode driver */
784#define ioctl_subtype set /* subtype param */
785#define ioctl_pid used /* pid param */
786#define ioctl_status needed /* status param */
787 613
788/* 614/*
789 * Structure for passing hardware and software 615 * Structure for passing hardware and software
@@ -810,45 +636,11 @@ typedef struct wlc_rev_info {
810 636
811#define WL_REV_INFO_LEGACY_LENGTH 48 637#define WL_REV_INFO_LEGACY_LENGTH 48
812 638
813#define WL_BRAND_MAX 10
814typedef struct wl_instance_info {
815 uint instance;
816 char brand[WL_BRAND_MAX];
817} wl_instance_info_t;
818
819/* structure to change size of tx fifo */
820typedef struct wl_txfifo_sz {
821 u16 magic;
822 u16 fifo;
823 u16 size;
824} wl_txfifo_sz_t;
825/* magic pattern used for mismatch driver and wl */
826#define WL_TXFIFO_SZ_MAGIC 0xa5a5
827
828/* Transfer info about an IOVar from the driver */
829/* Max supported IOV name size in bytes, + 1 for nul termination */
830#define WLC_IOV_NAME_LEN 30
831typedef struct wlc_iov_trx_s {
832 u8 module;
833 u8 type;
834 char name[WLC_IOV_NAME_LEN];
835} wlc_iov_trx_t;
836
837/* check this magic number */
838#define WLC_IOCTL_MAGIC 0x14e46c77
839
840#define PROC_ENTRY_NAME "brcm_debug"
841/* bump this number if you change the ioctl interface */
842#define WLC_IOCTL_VERSION 1
843
844#ifdef BRCM_FULLMAC 639#ifdef BRCM_FULLMAC
845#define WLC_IOCTL_MAXLEN 8192
846#else
847#define WLC_IOCTL_MAXLEN 3072 /* max length ioctl buffer required */
848#endif
849#define WLC_IOCTL_SMLEN 256 /* "small" length ioctl buffer required */ 640#define WLC_IOCTL_SMLEN 256 /* "small" length ioctl buffer required */
850#define WLC_IOCTL_MEDLEN 1536 /* "med" length ioctl buffer required */ 641#define WLC_IOCTL_MEDLEN 1536 /* "med" length ioctl buffer required */
851#define WLC_SAMPLECOLLECT_MAXLEN 10240 /* Max Sample Collect buffer for two cores */ 642#define WLC_IOCTL_MAXLEN 8192
643#endif
852 644
853/* common ioctl definitions */ 645/* common ioctl definitions */
854#define WLC_GET_MAGIC 0 646#define WLC_GET_MAGIC 0
@@ -1399,23 +1191,6 @@ typedef struct {
1399#define WL_TX_POWER_MCS40_FIRST 28 1191#define WL_TX_POWER_MCS40_FIRST 28
1400#define WL_TX_POWER_MCS40_NUM 17 1192#define WL_TX_POWER_MCS40_NUM 17
1401 1193
1402typedef struct {
1403 u32 flags;
1404 chanspec_t chanspec; /* txpwr report for this channel */
1405 chanspec_t local_chanspec; /* channel on which we are associated */
1406 u8 local_max; /* local max according to the AP */
1407 u8 local_constraint; /* local constraint according to the AP */
1408 s8 antgain[2]; /* Ant gain for each band - from SROM */
1409 u8 rf_cores; /* count of RF Cores being reported */
1410 u8 est_Pout[4]; /* Latest tx power out estimate per RF
1411 * chain without adjustment
1412 */
1413 u8 est_Pout_cck; /* Latest CCK tx power out estimate */
1414 u8 user_limit[WL_TX_POWER_RATES_LEGACY]; /* User limit */
1415 u8 reg_limit[WL_TX_POWER_RATES_LEGACY]; /* Regulatory power limit */
1416 u8 board_limit[WL_TX_POWER_RATES_LEGACY]; /* Max power board can support (SROM) */
1417 u8 target[WL_TX_POWER_RATES_LEGACY]; /* Latest target power */
1418} tx_power_legacy2_t;
1419 1194
1420#define WL_TX_POWER_RATES 101 1195#define WL_TX_POWER_RATES 101
1421#define WL_TX_POWER_CCK_FIRST 0 1196#define WL_TX_POWER_CCK_FIRST 0
@@ -1848,63 +1623,6 @@ struct ampdu_retry_tid {
1848 u8 retry; /* retry value */ 1623 u8 retry; /* retry value */
1849}; 1624};
1850 1625
1851/* structure for addts arguments */
1852/* For ioctls that take a list of TSPEC */
1853struct tslist {
1854 int count; /* number of tspecs */
1855 struct tsinfo_arg tsinfo[1]; /* variable length array of tsinfo */
1856};
1857
1858/* structure for addts/delts arguments */
1859typedef struct tspec_arg {
1860 u16 version; /* see definition of TSPEC_ARG_VERSION */
1861 u16 length; /* length of entire structure */
1862 uint flag; /* bit field */
1863 /* TSPEC Arguments */
1864 struct tsinfo_arg tsinfo; /* TS Info bit field */
1865 u16 nom_msdu_size; /* (Nominal or fixed) MSDU Size (bytes) */
1866 u16 max_msdu_size; /* Maximum MSDU Size (bytes) */
1867 uint min_srv_interval; /* Minimum Service Interval (us) */
1868 uint max_srv_interval; /* Maximum Service Interval (us) */
1869 uint inactivity_interval; /* Inactivity Interval (us) */
1870 uint suspension_interval; /* Suspension Interval (us) */
1871 uint srv_start_time; /* Service Start Time (us) */
1872 uint min_data_rate; /* Minimum Data Rate (bps) */
1873 uint mean_data_rate; /* Mean Data Rate (bps) */
1874 uint peak_data_rate; /* Peak Data Rate (bps) */
1875 uint max_burst_size; /* Maximum Burst Size (bytes) */
1876 uint delay_bound; /* Delay Bound (us) */
1877 uint min_phy_rate; /* Minimum PHY Rate (bps) */
1878 u16 surplus_bw; /* Surplus Bandwidth Allowance (range 1.0 to 8.0) */
1879 u16 medium_time; /* Medium Time (32 us/s periods) */
1880 u8 dialog_token; /* dialog token */
1881} tspec_arg_t;
1882
1883/* tspec arg for desired station */
1884typedef struct tspec_per_sta_arg {
1885 struct ether_addr ea;
1886 struct tspec_arg ts;
1887} tspec_per_sta_arg_t;
1888
1889/* structure for max bandwidth for each access category */
1890typedef struct wme_max_bandwidth {
1891 u32 ac[AC_COUNT]; /* max bandwidth for each access category */
1892} wme_max_bandwidth_t;
1893
1894#define WL_WME_MBW_PARAMS_IO_BYTES (sizeof(wme_max_bandwidth_t))
1895
1896/* current version of wl_tspec_arg_t struct */
1897#define TSPEC_ARG_VERSION 2 /* current version of wl_tspec_arg_t struct */
1898#define TSPEC_ARG_LENGTH 55 /* argument length from tsinfo to medium_time */
1899#define TSPEC_DEFAULT_DIALOG_TOKEN 42 /* default dialog token */
1900#define TSPEC_DEFAULT_SBW_FACTOR 0x3000 /* default surplus bw */
1901
1902/* define for flag */
1903#define TSPEC_PENDING 0 /* TSPEC pending */
1904#define TSPEC_ACCEPTED 1 /* TSPEC accepted */
1905#define TSPEC_REJECTED 2 /* TSPEC rejected */
1906#define TSPEC_UNKNOWN 3 /* TSPEC unknown */
1907#define TSPEC_STATUS_MASK 7 /* TSPEC status mask */
1908 1626
1909/* Software feature flag defines used by wlfeatureflag */ 1627/* Software feature flag defines used by wlfeatureflag */
1910#define WL_SWFL_NOHWRADIO 0x0004 1628#define WL_SWFL_NOHWRADIO 0x0004
@@ -1913,16 +1631,6 @@ typedef struct wme_max_bandwidth {
1913 1631
1914#define WL_LIFETIME_MAX 0xFFFF /* Max value in ms */ 1632#define WL_LIFETIME_MAX 0xFFFF /* Max value in ms */
1915 1633
1916/*
1917 * Dongle pattern matching filter.
1918 */
1919
1920/* Packet filter types. Currently, only pattern matching is supported. */
1921typedef enum wl_pkt_filter_type {
1922 WL_PKT_FILTER_TYPE_PATTERN_MATCH /* Pattern matching filter */
1923} wl_pkt_filter_type_t;
1924
1925#define WL_PKT_FILTER_TYPE wl_pkt_filter_type_t
1926 1634
1927/* Pattern matching filter. Specifies an offset within received packets to 1635/* Pattern matching filter. Specifies an offset within received packets to
1928 * start matching, the pattern to match, the size of the pattern, and a bitmask 1636 * start matching, the pattern to match, the size of the pattern, and a bitmask
@@ -1957,20 +1665,6 @@ typedef struct wl_pkt_filter_enable {
1957 u32 enable; /* Enable/disable bool */ 1665 u32 enable; /* Enable/disable bool */
1958} wl_pkt_filter_enable_t; 1666} wl_pkt_filter_enable_t;
1959 1667
1960/* IOVAR "pkt_filter_list" parameter. Used to retrieve a list of installed filters. */
1961typedef struct wl_pkt_filter_list {
1962 u32 num; /* Number of installed packet filters */
1963 wl_pkt_filter_t filter[1]; /* Variable array of packet filters. */
1964} wl_pkt_filter_list_t;
1965
1966#define WL_PKT_FILTER_LIST_FIXED_LEN offsetof(wl_pkt_filter_list_t, filter)
1967
1968/* IOVAR "pkt_filter_stats" parameter. Used to retrieve debug statistics. */
1969typedef struct wl_pkt_filter_stats {
1970 u32 num_pkts_matched; /* # filter matches for specified filter id */
1971 u32 num_pkts_forwarded; /* # packets fwded from dongle to host for all filters */
1972 u32 num_pkts_discarded; /* # packets discarded by dongle for all filters */
1973} wl_pkt_filter_stats_t;
1974 1668
1975#define WLC_RSSI_INVALID 0 /* invalid RSSI value */ 1669#define WLC_RSSI_INVALID 0 /* invalid RSSI value */
1976 1670
diff --git a/drivers/staging/brcm80211/phy/wlc_phy_cmn.c b/drivers/staging/brcm80211/phy/wlc_phy_cmn.c
index 8287261120f4..3bed37cb59b8 100644
--- a/drivers/staging/brcm80211/phy/wlc_phy_cmn.c
+++ b/drivers/staging/brcm80211/phy/wlc_phy_cmn.c
@@ -20,10 +20,15 @@
20#include <linux/string.h> 20#include <linux/string.h>
21#include <bcmdefs.h> 21#include <bcmdefs.h>
22#include <osl.h> 22#include <osl.h>
23#include <linuxver.h> 23#include <linux/delay.h>
24#include <linux/module.h>
25#include <linux/pci.h>
24#include <bcmendian.h> 26#include <bcmendian.h>
25#include <bcmnvram.h> 27#include <bcmnvram.h>
26#include <sbchipc.h> 28#include <sbchipc.h>
29#include <bcmdevs.h>
30#include <sbhndpio.h>
31#include <sbhnddma.h>
27 32
28#include <wlc_phy_int.h> 33#include <wlc_phy_int.h>
29#include <wlc_phyreg_n.h> 34#include <wlc_phyreg_n.h>
@@ -163,7 +168,7 @@ char *phy_getvar(phy_info_t *pi, const char *name)
163 return NULL; 168 return NULL;
164 169
165 for (s = vars; s && *s;) { 170 for (s = vars; s && *s;) {
166 if ((bcmp(s, name, len) == 0) && (s[len] == '=')) 171 if ((memcmp(s, name, len) == 0) && (s[len] == '='))
167 return &s[len + 1]; 172 return &s[len + 1];
168 173
169 while (*s++) 174 while (*s++)
@@ -272,7 +277,7 @@ u16 read_radio_reg(phy_info_t *pi, u16 addr)
272 277
273void write_radio_reg(phy_info_t *pi, u16 addr, u16 val) 278void write_radio_reg(phy_info_t *pi, u16 addr, u16 val)
274{ 279{
275 osl_t *osh; 280 struct osl_info *osh;
276 281
277 if (NORADIO_ENAB(pi->pubpi)) 282 if (NORADIO_ENAB(pi->pubpi))
278 return; 283 return;
@@ -296,7 +301,7 @@ void write_radio_reg(phy_info_t *pi, u16 addr, u16 val)
296 W_REG(osh, &pi->regs->phy4wdatalo, val); 301 W_REG(osh, &pi->regs->phy4wdatalo, val);
297 } 302 }
298 303
299 if (BUSTYPE(pi->sh->bustype) == PCI_BUS) { 304 if (pi->sh->bustype == PCI_BUS) {
300 if (++pi->phy_wreg >= pi->phy_wreg_limit) { 305 if (++pi->phy_wreg >= pi->phy_wreg_limit) {
301 (void)R_REG(osh, &pi->regs->maccontrol); 306 (void)R_REG(osh, &pi->regs->maccontrol);
302 pi->phy_wreg = 0; 307 pi->phy_wreg = 0;
@@ -405,7 +410,7 @@ static bool wlc_phy_war41476(phy_info_t *pi)
405 410
406u16 read_phy_reg(phy_info_t *pi, u16 addr) 411u16 read_phy_reg(phy_info_t *pi, u16 addr)
407{ 412{
408 osl_t *osh; 413 struct osl_info *osh;
409 d11regs_t *regs; 414 d11regs_t *regs;
410 415
411 osh = pi->sh->osh; 416 osh = pi->sh->osh;
@@ -426,7 +431,7 @@ u16 read_phy_reg(phy_info_t *pi, u16 addr)
426 431
427void write_phy_reg(phy_info_t *pi, u16 addr, u16 val) 432void write_phy_reg(phy_info_t *pi, u16 addr, u16 val)
428{ 433{
429 osl_t *osh; 434 struct osl_info *osh;
430 d11regs_t *regs; 435 d11regs_t *regs;
431 436
432 osh = pi->sh->osh; 437 osh = pi->sh->osh;
@@ -441,7 +446,7 @@ void write_phy_reg(phy_info_t *pi, u16 addr, u16 val)
441#else 446#else
442 W_REG(osh, (volatile u32 *)(&regs->phyregaddr), 447 W_REG(osh, (volatile u32 *)(&regs->phyregaddr),
443 addr | (val << 16)); 448 addr | (val << 16));
444 if (BUSTYPE(pi->sh->bustype) == PCI_BUS) { 449 if (pi->sh->bustype == PCI_BUS) {
445 if (++pi->phy_wreg >= pi->phy_wreg_limit) { 450 if (++pi->phy_wreg >= pi->phy_wreg_limit) {
446 pi->phy_wreg = 0; 451 pi->phy_wreg = 0;
447 (void)R_REG(osh, &regs->phyversion); 452 (void)R_REG(osh, &regs->phyversion);
@@ -452,7 +457,7 @@ void write_phy_reg(phy_info_t *pi, u16 addr, u16 val)
452 457
453void and_phy_reg(phy_info_t *pi, u16 addr, u16 val) 458void and_phy_reg(phy_info_t *pi, u16 addr, u16 val)
454{ 459{
455 osl_t *osh; 460 struct osl_info *osh;
456 d11regs_t *regs; 461 d11regs_t *regs;
457 462
458 osh = pi->sh->osh; 463 osh = pi->sh->osh;
@@ -473,7 +478,7 @@ void and_phy_reg(phy_info_t *pi, u16 addr, u16 val)
473 478
474void or_phy_reg(phy_info_t *pi, u16 addr, u16 val) 479void or_phy_reg(phy_info_t *pi, u16 addr, u16 val)
475{ 480{
476 osl_t *osh; 481 struct osl_info *osh;
477 d11regs_t *regs; 482 d11regs_t *regs;
478 483
479 osh = pi->sh->osh; 484 osh = pi->sh->osh;
@@ -494,7 +499,7 @@ void or_phy_reg(phy_info_t *pi, u16 addr, u16 val)
494 499
495void mod_phy_reg(phy_info_t *pi, u16 addr, u16 mask, u16 val) 500void mod_phy_reg(phy_info_t *pi, u16 addr, u16 mask, u16 val)
496{ 501{
497 osl_t *osh; 502 struct osl_info *osh;
498 d11regs_t *regs; 503 d11regs_t *regs;
499 504
500 osh = pi->sh->osh; 505 osh = pi->sh->osh;
@@ -591,7 +596,7 @@ shared_phy_t *wlc_phy_shared_attach(shared_phy_params_t *shp)
591 596
592void wlc_phy_shared_detach(shared_phy_t *phy_sh) 597void wlc_phy_shared_detach(shared_phy_t *phy_sh)
593{ 598{
594 osl_t *osh; 599 struct osl_info *osh;
595 600
596 if (phy_sh) { 601 if (phy_sh) {
597 osh = phy_sh->osh; 602 osh = phy_sh->osh;
@@ -609,7 +614,7 @@ wlc_phy_t *wlc_phy_attach(shared_phy_t *sh, void *regs, int bandtype, char *vars
609 u32 sflags = 0; 614 u32 sflags = 0;
610 uint phyversion; 615 uint phyversion;
611 int i; 616 int i;
612 osl_t *osh; 617 struct osl_info *osh;
613 618
614 osh = sh->osh; 619 osh = sh->osh;
615 620
@@ -1080,8 +1085,8 @@ wlc_phy_table_addr(phy_info_t *pi, uint tbl_id, uint tbl_offset,
1080 pi->tbl_data_hi = tblDataHi; 1085 pi->tbl_data_hi = tblDataHi;
1081 pi->tbl_data_lo = tblDataLo; 1086 pi->tbl_data_lo = tblDataLo;
1082 1087
1083 if ((CHIPID(pi->sh->chip) == BCM43224_CHIP_ID || 1088 if ((pi->sh->chip == BCM43224_CHIP_ID ||
1084 CHIPID(pi->sh->chip) == BCM43421_CHIP_ID) && 1089 pi->sh->chip == BCM43421_CHIP_ID) &&
1085 (pi->sh->chiprev == 1)) { 1090 (pi->sh->chiprev == 1)) {
1086 pi->tbl_addr = tblAddr; 1091 pi->tbl_addr = tblAddr;
1087 pi->tbl_save_id = tbl_id; 1092 pi->tbl_save_id = tbl_id;
@@ -1093,8 +1098,8 @@ void wlc_phy_table_data_write(phy_info_t *pi, uint width, u32 val)
1093{ 1098{
1094 ASSERT((width == 8) || (width == 16) || (width == 32)); 1099 ASSERT((width == 8) || (width == 16) || (width == 32));
1095 1100
1096 if ((CHIPID(pi->sh->chip) == BCM43224_CHIP_ID || 1101 if ((pi->sh->chip == BCM43224_CHIP_ID ||
1097 CHIPID(pi->sh->chip) == BCM43421_CHIP_ID) && 1102 pi->sh->chip == BCM43421_CHIP_ID) &&
1098 (pi->sh->chiprev == 1) && 1103 (pi->sh->chiprev == 1) &&
1099 (pi->tbl_save_id == NPHY_TBL_ID_ANTSWCTRLLUT)) { 1104 (pi->tbl_save_id == NPHY_TBL_ID_ANTSWCTRLLUT)) {
1100 read_phy_reg(pi, pi->tbl_data_lo); 1105 read_phy_reg(pi, pi->tbl_data_lo);
@@ -1132,8 +1137,8 @@ wlc_phy_write_table(phy_info_t *pi, const phytbl_info_t *ptbl_info,
1132 1137
1133 for (idx = 0; idx < ptbl_info->tbl_len; idx++) { 1138 for (idx = 0; idx < ptbl_info->tbl_len; idx++) {
1134 1139
1135 if ((CHIPID(pi->sh->chip) == BCM43224_CHIP_ID || 1140 if ((pi->sh->chip == BCM43224_CHIP_ID ||
1136 CHIPID(pi->sh->chip) == BCM43421_CHIP_ID) && 1141 pi->sh->chip == BCM43421_CHIP_ID) &&
1137 (pi->sh->chiprev == 1) && 1142 (pi->sh->chiprev == 1) &&
1138 (tbl_id == NPHY_TBL_ID_ANTSWCTRLLUT)) { 1143 (tbl_id == NPHY_TBL_ID_ANTSWCTRLLUT)) {
1139 read_phy_reg(pi, tblDataLo); 1144 read_phy_reg(pi, tblDataLo);
@@ -1175,8 +1180,8 @@ wlc_phy_read_table(phy_info_t *pi, const phytbl_info_t *ptbl_info,
1175 1180
1176 for (idx = 0; idx < ptbl_info->tbl_len; idx++) { 1181 for (idx = 0; idx < ptbl_info->tbl_len; idx++) {
1177 1182
1178 if ((CHIPID(pi->sh->chip) == BCM43224_CHIP_ID || 1183 if ((pi->sh->chip == BCM43224_CHIP_ID ||
1179 CHIPID(pi->sh->chip) == BCM43421_CHIP_ID) && 1184 pi->sh->chip == BCM43421_CHIP_ID) &&
1180 (pi->sh->chiprev == 1)) { 1185 (pi->sh->chiprev == 1)) {
1181 (void)read_phy_reg(pi, tblDataLo); 1186 (void)read_phy_reg(pi, tblDataLo);
1182 1187
@@ -1534,7 +1539,7 @@ wlc_phy_chanspec_band_validch(wlc_phy_t *ppi, uint band, chanvec_t *channels)
1534 1539
1535 ASSERT((band == WLC_BAND_2G) || (band == WLC_BAND_5G)); 1540 ASSERT((band == WLC_BAND_2G) || (band == WLC_BAND_5G));
1536 1541
1537 bzero(channels, sizeof(chanvec_t)); 1542 memset(channels, 0, sizeof(chanvec_t));
1538 1543
1539 for (i = 0; i < ARRAY_SIZE(chan_info_all); i++) { 1544 for (i = 0; i < ARRAY_SIZE(chan_info_all); i++) {
1540 channel = chan_info_all[i].chan; 1545 channel = chan_info_all[i].chan;
@@ -1896,7 +1901,7 @@ void wlc_phy_txpower_recalc_target(phy_info_t *pi)
1896 tx_pwr_min = min(tx_pwr_min, tx_pwr_target[rate]); 1901 tx_pwr_min = min(tx_pwr_min, tx_pwr_target[rate]);
1897 } 1902 }
1898 1903
1899 bzero(pi->tx_power_offset, sizeof(pi->tx_power_offset)); 1904 memset(pi->tx_power_offset, 0, sizeof(pi->tx_power_offset));
1900 pi->tx_power_max = tx_pwr_max; 1905 pi->tx_power_max = tx_pwr_max;
1901 pi->tx_power_min = tx_pwr_min; 1906 pi->tx_power_min = tx_pwr_min;
1902 pi->tx_power_max_rate_ind = tx_pwr_max_rate_ind; 1907 pi->tx_power_max_rate_ind = tx_pwr_max_rate_ind;
@@ -2507,7 +2512,7 @@ wlc_phy_noise_calc_phy(phy_info_t *pi, u32 *cmplx_pwr, s8 *pwr_ant)
2507 s8 cmplx_pwr_dbm[PHY_CORE_MAX]; 2512 s8 cmplx_pwr_dbm[PHY_CORE_MAX];
2508 u8 i; 2513 u8 i;
2509 2514
2510 bzero((u8 *) cmplx_pwr_dbm, sizeof(cmplx_pwr_dbm)); 2515 memset((u8 *) cmplx_pwr_dbm, 0, sizeof(cmplx_pwr_dbm));
2511 ASSERT(pi->pubpi.phy_corenum <= PHY_CORE_MAX); 2516 ASSERT(pi->pubpi.phy_corenum <= PHY_CORE_MAX);
2512 wlc_phy_compute_dB(cmplx_pwr, cmplx_pwr_dbm, pi->pubpi.phy_corenum); 2517 wlc_phy_compute_dB(cmplx_pwr, cmplx_pwr_dbm, pi->pubpi.phy_corenum);
2513 2518
@@ -2621,9 +2626,9 @@ wlc_phy_noise_sample_request(wlc_phy_t *pih, u8 reason, u8 ch)
2621 u8 wait_crs = 0; 2626 u8 wait_crs = 0;
2622 u8 i; 2627 u8 i;
2623 2628
2624 bzero((u8 *) est, sizeof(est)); 2629 memset((u8 *) est, 0, sizeof(est));
2625 bzero((u8 *) cmplx_pwr, sizeof(cmplx_pwr)); 2630 memset((u8 *) cmplx_pwr, 0, sizeof(cmplx_pwr));
2626 bzero((u8 *) noise_dbm_ant, sizeof(noise_dbm_ant)); 2631 memset((u8 *) noise_dbm_ant, 0, sizeof(noise_dbm_ant));
2627 2632
2628 log_num_samps = PHY_NOISE_SAMPLE_LOG_NUM_NPHY; 2633 log_num_samps = PHY_NOISE_SAMPLE_LOG_NUM_NPHY;
2629 num_samps = 1 << log_num_samps; 2634 num_samps = 1 << log_num_samps;
@@ -2704,8 +2709,8 @@ static s8 wlc_phy_noise_read_shmem(phy_info_t *pi)
2704 u8 idx, core; 2709 u8 idx, core;
2705 2710
2706 ASSERT(pi->pubpi.phy_corenum <= PHY_CORE_MAX); 2711 ASSERT(pi->pubpi.phy_corenum <= PHY_CORE_MAX);
2707 bzero((u8 *) cmplx_pwr, sizeof(cmplx_pwr)); 2712 memset((u8 *) cmplx_pwr, 0, sizeof(cmplx_pwr));
2708 bzero((u8 *) noise_dbm_ant, sizeof(noise_dbm_ant)); 2713 memset((u8 *) noise_dbm_ant, 0, sizeof(noise_dbm_ant));
2709 2714
2710 for (idx = 0, core = 0; core < pi->pubpi.phy_corenum; idx += 2, core++) { 2715 for (idx = 0, core = 0; core < pi->pubpi.phy_corenum; idx += 2, core++) {
2711 lo = wlapi_bmac_read_shm(pi->sh->physhim, M_PWRIND_MAP(idx)); 2716 lo = wlapi_bmac_read_shm(pi->sh->physhim, M_PWRIND_MAP(idx));
@@ -3325,7 +3330,7 @@ const u8 *wlc_phy_get_ofdm_rate_lookup(void)
3325 3330
3326void wlc_lcnphy_epa_switch(phy_info_t *pi, bool mode) 3331void wlc_lcnphy_epa_switch(phy_info_t *pi, bool mode)
3327{ 3332{
3328 if ((CHIPID(pi->sh->chip) == BCM4313_CHIP_ID) && 3333 if ((pi->sh->chip == BCM4313_CHIP_ID) &&
3329 (pi->sh->boardflags & BFL_FEM)) { 3334 (pi->sh->boardflags & BFL_FEM)) {
3330 if (mode) { 3335 if (mode) {
3331 u16 txant = 0; 3336 u16 txant = 0;
diff --git a/drivers/staging/brcm80211/phy/wlc_phy_hal.h b/drivers/staging/brcm80211/phy/wlc_phy_hal.h
index 52260b2d0eba..514e15e00283 100644
--- a/drivers/staging/brcm80211/phy/wlc_phy_hal.h
+++ b/drivers/staging/brcm80211/phy/wlc_phy_hal.h
@@ -122,11 +122,7 @@ typedef struct shared_phy shared_phy_t;
122 122
123struct phy_pub; 123struct phy_pub;
124 124
125#ifdef WLC_HIGH_ONLY
126typedef struct wlc_rpc_phy wlc_phy_t;
127#else
128typedef struct phy_pub wlc_phy_t; 125typedef struct phy_pub wlc_phy_t;
129#endif
130 126
131typedef struct shared_phy_params { 127typedef struct shared_phy_params {
132 void *osh; 128 void *osh;
@@ -150,7 +146,6 @@ typedef struct shared_phy_params {
150 u32 boardflags2; 146 u32 boardflags2;
151} shared_phy_params_t; 147} shared_phy_params_t;
152 148
153#ifdef WLC_LOW
154 149
155extern shared_phy_t *wlc_phy_shared_attach(shared_phy_params_t *shp); 150extern shared_phy_t *wlc_phy_shared_attach(shared_phy_params_t *shp);
156extern void wlc_phy_shared_detach(shared_phy_t *phy_sh); 151extern void wlc_phy_shared_detach(shared_phy_t *phy_sh);
@@ -189,7 +184,6 @@ extern void wlc_phy_set_deaf(wlc_phy_t *ppi, bool user_flag);
189extern void wlc_phy_switch_radio(wlc_phy_t *ppi, bool on); 184extern void wlc_phy_switch_radio(wlc_phy_t *ppi, bool on);
190extern void wlc_phy_anacore(wlc_phy_t *ppi, bool on); 185extern void wlc_phy_anacore(wlc_phy_t *ppi, bool on);
191 186
192#endif /* WLC_LOW */
193 187
194extern void wlc_phy_BSSinit(wlc_phy_t *ppi, bool bonlyap, int rssi); 188extern void wlc_phy_BSSinit(wlc_phy_t *ppi, bool bonlyap, int rssi);
195 189
diff --git a/drivers/staging/brcm80211/phy/wlc_phy_int.h b/drivers/staging/brcm80211/phy/wlc_phy_int.h
index 9513b87fa163..72eee9120c2f 100644
--- a/drivers/staging/brcm80211/phy/wlc_phy_int.h
+++ b/drivers/staging/brcm80211/phy/wlc_phy_int.h
@@ -527,7 +527,7 @@ typedef struct {
527struct shared_phy { 527struct shared_phy {
528 struct phy_info *phy_head; 528 struct phy_info *phy_head;
529 uint unit; 529 uint unit;
530 osl_t *osh; 530 struct osl_info *osh;
531 si_t *sih; 531 si_t *sih;
532 void *physhim; 532 void *physhim;
533 uint corerev; 533 uint corerev;
@@ -1158,7 +1158,7 @@ extern void wlc_phy_table_write_nphy(phy_info_t *pi, u32, u32, u32,
1158 (pi->ipa5g_on && CHSPEC_IS5G(pi->radio_chanspec))) 1158 (pi->ipa5g_on && CHSPEC_IS5G(pi->radio_chanspec)))
1159 1159
1160#define WLC_PHY_WAR_PR51571(pi) \ 1160#define WLC_PHY_WAR_PR51571(pi) \
1161 if ((BUSTYPE((pi)->sh->bustype) == PCI_BUS) && NREV_LT((pi)->pubpi.phy_rev, 3)) \ 1161 if (((pi)->sh->bustype == PCI_BUS) && NREV_LT((pi)->pubpi.phy_rev, 3)) \
1162 (void)R_REG((pi)->sh->osh, &(pi)->regs->maccontrol) 1162 (void)R_REG((pi)->sh->osh, &(pi)->regs->maccontrol)
1163 1163
1164extern void wlc_phy_cal_perical_nphy_run(phy_info_t *pi, u8 caltype); 1164extern void wlc_phy_cal_perical_nphy_run(phy_info_t *pi, u8 caltype);
diff --git a/drivers/staging/brcm80211/phy/wlc_phy_lcn.c b/drivers/staging/brcm80211/phy/wlc_phy_lcn.c
index 3d3112ed4e20..3ac2b49d9a9d 100644
--- a/drivers/staging/brcm80211/phy/wlc_phy_lcn.c
+++ b/drivers/staging/brcm80211/phy/wlc_phy_lcn.c
@@ -17,13 +17,18 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/bitops.h> 19#include <linux/bitops.h>
20#include <linux/delay.h>
20#include <wlc_cfg.h> 21#include <wlc_cfg.h>
21#include <qmath.h> 22#include <qmath.h>
22#include <osl.h> 23#include <osl.h>
23#include <linuxver.h> 24#include <linux/pci.h>
24#include <siutils.h> 25#include <siutils.h>
25#include <hndpmu.h> 26#include <hndpmu.h>
26 27
28#include <bcmdevs.h>
29#include <sbhndpio.h>
30#include <sbhnddma.h>
31
27#include <wlc_phy_radio.h> 32#include <wlc_phy_radio.h>
28#include <wlc_phy_int.h> 33#include <wlc_phy_int.h>
29#include <wlc_phy_lcn.h> 34#include <wlc_phy_lcn.h>
@@ -1327,7 +1332,7 @@ static void wlc_lcnphy_clear_tx_power_offsets(phy_info_t *pi)
1327 u32 data_buf[64]; 1332 u32 data_buf[64];
1328 phytbl_info_t tab; 1333 phytbl_info_t tab;
1329 1334
1330 bzero(data_buf, sizeof(data_buf)); 1335 memset(data_buf, 0, sizeof(data_buf));
1331 1336
1332 tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL; 1337 tab.tbl_id = LCNPHY_TBL_ID_TXPWRCTL;
1333 tab.tbl_width = 32; 1338 tab.tbl_width = 32;
@@ -1951,7 +1956,7 @@ wlc_lcnphy_tx_iqlo_cal(phy_info_t *pi,
1951 band_idx = (CHSPEC_IS5G(pi->radio_chanspec) ? 1 : 0); 1956 band_idx = (CHSPEC_IS5G(pi->radio_chanspec) ? 1 : 0);
1952 1957
1953 cal_gains = *target_gains; 1958 cal_gains = *target_gains;
1954 bzero(ncorr_override, sizeof(ncorr_override)); 1959 memset(ncorr_override, 0, sizeof(ncorr_override));
1955 for (j = 0; j < iqcal_gainparams_numgains_lcnphy[band_idx]; j++) { 1960 for (j = 0; j < iqcal_gainparams_numgains_lcnphy[band_idx]; j++) {
1956 if (hash == tbl_iqcal_gainparams_lcnphy[band_idx][j][0]) { 1961 if (hash == tbl_iqcal_gainparams_lcnphy[band_idx][j][0]) {
1957 cal_gains.gm_gain = 1962 cal_gains.gm_gain =
@@ -2529,7 +2534,7 @@ static void wlc_lcnphy_clear_papd_comptable(phy_info_t *pi)
2529 tab.tbl_width = 32; 2534 tab.tbl_width = 32;
2530 tab.tbl_offset = 0; 2535 tab.tbl_offset = 0;
2531 2536
2532 bzero(temp_offset, sizeof(temp_offset)); 2537 memset(temp_offset, 0, sizeof(temp_offset));
2533 for (j = 1; j < 128; j += 2) 2538 for (j = 1; j < 128; j += 2)
2534 temp_offset[j] = 0x80000; 2539 temp_offset[j] = 0x80000;
2535 2540
diff --git a/drivers/staging/brcm80211/phy/wlc_phy_n.c b/drivers/staging/brcm80211/phy/wlc_phy_n.c
index 950008f122b1..c6cce8de1aee 100644
--- a/drivers/staging/brcm80211/phy/wlc_phy_n.c
+++ b/drivers/staging/brcm80211/phy/wlc_phy_n.c
@@ -18,13 +18,18 @@
18#include <linux/string.h> 18#include <linux/string.h>
19#include <bcmdefs.h> 19#include <bcmdefs.h>
20#include <wlc_cfg.h> 20#include <wlc_cfg.h>
21#include <linuxver.h> 21#include <linux/delay.h>
22#include <linux/pci.h>
22#include <osl.h> 23#include <osl.h>
23#include <siutils.h> 24#include <siutils.h>
24#include <sbchipc.h> 25#include <sbchipc.h>
25#include <hndpmu.h> 26#include <hndpmu.h>
26#include <bcmendian.h> 27#include <bcmendian.h>
27 28
29#include <bcmdevs.h>
30#include <sbhndpio.h>
31#include <sbhnddma.h>
32
28#include <wlc_phy_radio.h> 33#include <wlc_phy_radio.h>
29#include <wlc_phy_int.h> 34#include <wlc_phy_int.h>
30#include <wlc_phyreg_n.h> 35#include <wlc_phyreg_n.h>
@@ -14554,7 +14559,7 @@ void WLBANDINITFN(wlc_phy_init_nphy) (phy_info_t *pi)
14554 } 14559 }
14555 } 14560 }
14556 14561
14557 if ((!PHY_IPA(pi)) && (CHIPID(pi->sh->chip) == BCM5357_CHIP_ID)) { 14562 if ((!PHY_IPA(pi)) && (pi->sh->chip == BCM5357_CHIP_ID)) {
14558 si_pmu_chipcontrol(pi->sh->sih, 1, CCTRL5357_EXTPA, 14563 si_pmu_chipcontrol(pi->sh->sih, 1, CCTRL5357_EXTPA,
14559 CCTRL5357_EXTPA); 14564 CCTRL5357_EXTPA);
14560 } 14565 }
@@ -17599,7 +17604,7 @@ static void wlc_phy_radio_postinit_2057(phy_info_t *pi)
17599 17604
17600 mod_radio_reg(pi, RADIO_2057_XTALPUOVR_PINCTRL, 0x1, 0x1); 17605 mod_radio_reg(pi, RADIO_2057_XTALPUOVR_PINCTRL, 0x1, 0x1);
17601 17606
17602 if (CHIPID(pi->sh->chip) == !BCM6362_CHIP_ID) { 17607 if (pi->sh->chip == !BCM6362_CHIP_ID) {
17603 17608
17604 mod_radio_reg(pi, RADIO_2057_XTALPUOVR_PINCTRL, 0x2, 0x2); 17609 mod_radio_reg(pi, RADIO_2057_XTALPUOVR_PINCTRL, 0x2, 0x2);
17605 } 17610 }
@@ -18007,8 +18012,8 @@ wlc_phy_chanspec_radio2056_setup(phy_info_t *pi,
18007 write_radio_reg(pi, RADIO_2056_SYN_PLL_LOOPFILTER2 | 18012 write_radio_reg(pi, RADIO_2056_SYN_PLL_LOOPFILTER2 |
18008 RADIO_2056_SYN, 0x1f); 18013 RADIO_2056_SYN, 0x1f);
18009 18014
18010 if ((CHIPID(pi->sh->chip) == BCM4716_CHIP_ID) || 18015 if ((pi->sh->chip == BCM4716_CHIP_ID) ||
18011 (CHIPID(pi->sh->chip) == BCM47162_CHIP_ID)) { 18016 (pi->sh->chip == BCM47162_CHIP_ID)) {
18012 18017
18013 write_radio_reg(pi, 18018 write_radio_reg(pi,
18014 RADIO_2056_SYN_PLL_LOOPFILTER4 | 18019 RADIO_2056_SYN_PLL_LOOPFILTER4 |
@@ -18070,8 +18075,8 @@ wlc_phy_chanspec_radio2056_setup(phy_info_t *pi,
18070 WRITE_RADIO_REG2(pi, RADIO_2056, TX, core, 18075 WRITE_RADIO_REG2(pi, RADIO_2056, TX, core,
18071 PADG_IDAC, 0xcc); 18076 PADG_IDAC, 0xcc);
18072 18077
18073 if ((CHIPID(pi->sh->chip) == BCM4716_CHIP_ID) || 18078 if ((pi->sh->chip == BCM4716_CHIP_ID) ||
18074 (CHIPID(pi->sh->chip) == 18079 (pi->sh->chip ==
18075 BCM47162_CHIP_ID)) { 18080 BCM47162_CHIP_ID)) {
18076 bias = 0x40; 18081 bias = 0x40;
18077 cascbias = 0x45; 18082 cascbias = 0x45;
@@ -18083,11 +18088,11 @@ wlc_phy_chanspec_radio2056_setup(phy_info_t *pi,
18083 bias = 0x25; 18088 bias = 0x25;
18084 cascbias = 0x20; 18089 cascbias = 0x20;
18085 18090
18086 if ((CHIPID(pi->sh->chip) == 18091 if ((pi->sh->chip ==
18087 BCM43224_CHIP_ID) 18092 BCM43224_CHIP_ID)
18088 || (CHIPID(pi->sh->chip) == 18093 || (pi->sh->chip ==
18089 BCM43225_CHIP_ID) 18094 BCM43225_CHIP_ID)
18090 || (CHIPID(pi->sh->chip) == 18095 || (pi->sh->chip ==
18091 BCM43421_CHIP_ID)) { 18096 BCM43421_CHIP_ID)) {
18092 if (pi->sh->chippkg == 18097 if (pi->sh->chippkg ==
18093 BCM43224_FAB_SMIC) { 18098 BCM43224_FAB_SMIC) {
@@ -18198,9 +18203,9 @@ wlc_phy_chanspec_radio2056_setup(phy_info_t *pi,
18198 18203
18199 cascbias = 0x30; 18204 cascbias = 0x30;
18200 18205
18201 if ((CHIPID(pi->sh->chip) == BCM43224_CHIP_ID) || 18206 if ((pi->sh->chip == BCM43224_CHIP_ID) ||
18202 (CHIPID(pi->sh->chip) == BCM43225_CHIP_ID) || 18207 (pi->sh->chip == BCM43225_CHIP_ID) ||
18203 (CHIPID(pi->sh->chip) == BCM43421_CHIP_ID)) { 18208 (pi->sh->chip == BCM43421_CHIP_ID)) {
18204 if (pi->sh->chippkg == BCM43224_FAB_SMIC) { 18209 if (pi->sh->chippkg == BCM43224_FAB_SMIC) {
18205 cascbias = 0x35; 18210 cascbias = 0x35;
18206 } 18211 }
@@ -18927,7 +18932,7 @@ static void wlc_phy_spurwar_nphy(phy_info_t *pi)
18927 case 38: 18932 case 38:
18928 case 102: 18933 case 102:
18929 case 118: 18934 case 118:
18930 if ((CHIPID(pi->sh->chip) == BCM4716_CHIP_ID) && 18935 if ((pi->sh->chip == BCM4716_CHIP_ID) &&
18931 (pi->sh->chippkg == BCM4717_PKG_ID)) { 18936 (pi->sh->chippkg == BCM4717_PKG_ID)) {
18932 nphy_adj_tone_id_buf[0] = 32; 18937 nphy_adj_tone_id_buf[0] = 32;
18933 nphy_adj_noise_var_buf[0] = 0x21f; 18938 nphy_adj_noise_var_buf[0] = 0x21f;
@@ -19062,7 +19067,7 @@ wlc_phy_chanspec_nphy_setup(phy_info_t *pi, chanspec_t chanspec,
19062 if (pi->nphy_aband_spurwar_en && 19067 if (pi->nphy_aband_spurwar_en &&
19063 ((val == 38) || (val == 102) 19068 ((val == 38) || (val == 102)
19064 || (val == 118))) { 19069 || (val == 118))) {
19065 if ((CHIPID(pi->sh->chip) == 19070 if ((pi->sh->chip ==
19066 BCM4716_CHIP_ID) 19071 BCM4716_CHIP_ID)
19067 && (pi->sh->chippkg == 19072 && (pi->sh->chippkg ==
19068 BCM4717_PKG_ID)) { 19073 BCM4717_PKG_ID)) {
@@ -19077,8 +19082,8 @@ wlc_phy_chanspec_nphy_setup(phy_info_t *pi, chanspec_t chanspec,
19077 if (pi->phy_spuravoid == SPURAVOID_FORCEON) 19082 if (pi->phy_spuravoid == SPURAVOID_FORCEON)
19078 spuravoid = 1; 19083 spuravoid = 1;
19079 19084
19080 if ((CHIPID(pi->sh->chip) == BCM4716_CHIP_ID) || 19085 if ((pi->sh->chip == BCM4716_CHIP_ID) ||
19081 (CHIPID(pi->sh->chip) == BCM47162_CHIP_ID)) { 19086 (pi->sh->chip == BCM47162_CHIP_ID)) {
19082 si_pmu_spuravoid(pi->sh->sih, pi->sh->osh, spuravoid); 19087 si_pmu_spuravoid(pi->sh->sih, pi->sh->osh, spuravoid);
19083 } else { 19088 } else {
19084 wlapi_bmac_core_phypll_ctl(pi->sh->physhim, false); 19089 wlapi_bmac_core_phypll_ctl(pi->sh->physhim, false);
@@ -19086,9 +19091,9 @@ wlc_phy_chanspec_nphy_setup(phy_info_t *pi, chanspec_t chanspec,
19086 wlapi_bmac_core_phypll_ctl(pi->sh->physhim, true); 19091 wlapi_bmac_core_phypll_ctl(pi->sh->physhim, true);
19087 } 19092 }
19088 19093
19089 if ((CHIPID(pi->sh->chip) == BCM43224_CHIP_ID) || 19094 if ((pi->sh->chip == BCM43224_CHIP_ID) ||
19090 (CHIPID(pi->sh->chip) == BCM43225_CHIP_ID) || 19095 (pi->sh->chip == BCM43225_CHIP_ID) ||
19091 (CHIPID(pi->sh->chip) == BCM43421_CHIP_ID)) { 19096 (pi->sh->chip == BCM43421_CHIP_ID)) {
19092 19097
19093 if (spuravoid == 1) { 19098 if (spuravoid == 1) {
19094 19099
@@ -19105,8 +19110,8 @@ wlc_phy_chanspec_nphy_setup(phy_info_t *pi, chanspec_t chanspec,
19105 } 19110 }
19106 } 19111 }
19107 19112
19108 if (!((CHIPID(pi->sh->chip) == BCM4716_CHIP_ID) || 19113 if (!((pi->sh->chip == BCM4716_CHIP_ID) ||
19109 (CHIPID(pi->sh->chip) == BCM47162_CHIP_ID))) { 19114 (pi->sh->chip == BCM47162_CHIP_ID))) {
19110 wlapi_bmac_core_phypll_reset(pi->sh->physhim); 19115 wlapi_bmac_core_phypll_reset(pi->sh->physhim);
19111 } 19116 }
19112 19117
@@ -21062,11 +21067,11 @@ s16 wlc_phy_tempsense_nphy(phy_info_t *pi)
21062 wlc_phy_table_write_nphy(pi, NPHY_TBL_ID_AFECTRL, 1, 0x03, 16, 21067 wlc_phy_table_write_nphy(pi, NPHY_TBL_ID_AFECTRL, 1, 0x03, 16,
21063 &auxADC_rssi_ctrlH_save); 21068 &auxADC_rssi_ctrlH_save);
21064 21069
21065 if (CHIPID(pi->sh->chip) == BCM5357_CHIP_ID) { 21070 if (pi->sh->chip == BCM5357_CHIP_ID) {
21066 radio_temp[0] = (193 * (radio_temp[1] + radio_temp2[1]) 21071 radio_temp[0] = (193 * (radio_temp[1] + radio_temp2[1])
21067 + 88 * (auxADC_Vl) - 27111 + 21072 + 88 * (auxADC_Vl) - 27111 +
21068 128) / 256; 21073 128) / 256;
21069 } else if (CHIPID(pi->sh->chip) == BCM43236_CHIP_ID) { 21074 } else if (pi->sh->chip == BCM43236_CHIP_ID) {
21070 radio_temp[0] = (198 * (radio_temp[1] + radio_temp2[1]) 21075 radio_temp[0] = (198 * (radio_temp[1] + radio_temp2[1])
21071 + 91 * (auxADC_Vl) - 27243 + 21076 + 91 * (auxADC_Vl) - 27243 +
21072 128) / 256; 21077 128) / 256;
@@ -26277,7 +26282,7 @@ static u32 *wlc_phy_get_ipa_gaintbl_nphy(phy_info_t *pi)
26277 } else if (NREV_IS(pi->pubpi.phy_rev, 6)) { 26282 } else if (NREV_IS(pi->pubpi.phy_rev, 6)) {
26278 26283
26279 tx_pwrctrl_tbl = nphy_tpc_txgain_ipa_rev6; 26284 tx_pwrctrl_tbl = nphy_tpc_txgain_ipa_rev6;
26280 if (CHIPID(pi->sh->chip) == BCM47162_CHIP_ID) { 26285 if (pi->sh->chip == BCM47162_CHIP_ID) {
26281 26286
26282 tx_pwrctrl_tbl = nphy_tpc_txgain_ipa_rev5; 26287 tx_pwrctrl_tbl = nphy_tpc_txgain_ipa_rev5;
26283 } 26288 }
@@ -26833,7 +26838,7 @@ wlc_phy_a2_nphy(phy_info_t *pi, nphy_ipa_txcalgains_t *txgains,
26833 phy_a2 = 63; 26838 phy_a2 = 63;
26834 26839
26835 if (CHSPEC_IS2G(pi->radio_chanspec)) { 26840 if (CHSPEC_IS2G(pi->radio_chanspec)) {
26836 if (CHIPID(pi->sh->chip) == BCM6362_CHIP_ID) { 26841 if (pi->sh->chip == BCM6362_CHIP_ID) {
26837 phy_a1 = 35; 26842 phy_a1 = 35;
26838 phy_a3 = 35; 26843 phy_a3 = 35;
26839 } else if ((pi->pubpi.radiorev == 4) 26844 } else if ((pi->pubpi.radiorev == 4)
@@ -26946,7 +26951,7 @@ wlc_phy_a2_nphy(phy_info_t *pi, nphy_ipa_txcalgains_t *txgains,
26946 if (NREV_GE(pi->pubpi.phy_rev, 6)) { 26951 if (NREV_GE(pi->pubpi.phy_rev, 6)) {
26947 phy_a5 = 0x00f7 | (phy_a4 << 8); 26952 phy_a5 = 0x00f7 | (phy_a4 << 8);
26948 26953
26949 if (CHIPID(pi->sh->chip) == 26954 if (pi->sh->chip ==
26950 BCM47162_CHIP_ID) { 26955 BCM47162_CHIP_ID) {
26951 phy_a5 = 26956 phy_a5 =
26952 0x10f7 | (phy_a4 << 26957 0x10f7 | (phy_a4 <<
diff --git a/drivers/staging/brcm80211/phy/wlc_phytbl_lcn.c b/drivers/staging/brcm80211/phy/wlc_phytbl_lcn.c
index 6ce9e5d96830..330b88152b65 100644
--- a/drivers/staging/brcm80211/phy/wlc_phytbl_lcn.c
+++ b/drivers/staging/brcm80211/phy/wlc_phytbl_lcn.c
@@ -15,6 +15,9 @@
15 */ 15 */
16 16
17#include <linux/types.h> 17#include <linux/types.h>
18#include <sbhndpio.h>
19#include <sbhnddma.h>
20#include <osl.h>
18#include <wlc_phy_int.h> 21#include <wlc_phy_int.h>
19#include <wlc_phytbl_lcn.h> 22#include <wlc_phytbl_lcn.h>
20 23
diff --git a/drivers/staging/brcm80211/phy/wlc_phytbl_n.c b/drivers/staging/brcm80211/phy/wlc_phytbl_n.c
index 7cc2c563c727..a9fc193721ef 100644
--- a/drivers/staging/brcm80211/phy/wlc_phytbl_n.c
+++ b/drivers/staging/brcm80211/phy/wlc_phytbl_n.c
@@ -16,6 +16,9 @@
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18 18
19#include <sbhndpio.h>
20#include <sbhnddma.h>
21#include <osl.h>
19#include <wlc_phy_int.h> 22#include <wlc_phy_int.h>
20#include <wlc_phytbl_n.h> 23#include <wlc_phytbl_n.h>
21 24
diff --git a/drivers/staging/brcm80211/sys/wl_dbg.h b/drivers/staging/brcm80211/sys/wl_dbg.h
index e63b27ebad5e..54af257598c2 100644
--- a/drivers/staging/brcm80211/sys/wl_dbg.h
+++ b/drivers/staging/brcm80211/sys/wl_dbg.h
@@ -20,15 +20,20 @@
20/* wl_msg_level is a bit vector with defs in wlioctl.h */ 20/* wl_msg_level is a bit vector with defs in wlioctl.h */
21extern u32 wl_msg_level; 21extern u32 wl_msg_level;
22 22
23#define WL_PRINT(args) printf args 23#define WL_NONE(fmt, args...) no_printk(fmt, ##args)
24#define WL_NONE(args) 24
25#define WL_PRINT(level, fmt, args...) \
26do { \
27 if (wl_msg_level & level) \
28 printk(fmt, ##args); \
29} while (0)
25 30
26#ifdef BCMDBG 31#ifdef BCMDBG
27 32
28#define WL_ERROR(args) do {if ((wl_msg_level & WL_ERROR_VAL)) WL_PRINT(args); } while (0) 33#define WL_ERROR(fmt, args...) WL_PRINT(WL_ERROR_VAL, fmt, ##args)
29#define WL_TRACE(args) do {if (wl_msg_level & WL_TRACE_VAL) WL_PRINT(args); } while (0) 34#define WL_TRACE(fmt, args...) WL_PRINT(WL_TRACE_VAL, fmt, ##args)
30#define WL_AMPDU(args) do {if (wl_msg_level & WL_AMPDU_VAL) WL_PRINT(args); } while (0) 35#define WL_AMPDU(fmt, args...) WL_PRINT(WL_AMPDU_VAL, fmt, ##args)
31#define WL_FFPLD(args) do {if (wl_msg_level & WL_FFPLD_VAL) WL_PRINT(args); } while (0) 36#define WL_FFPLD(fmt, args...) WL_PRINT(WL_FFPLD_VAL, fmt, ##args)
32 37
33#define WL_ERROR_ON() (wl_msg_level & WL_ERROR_VAL) 38#define WL_ERROR_ON() (wl_msg_level & WL_ERROR_VAL)
34 39
@@ -44,35 +49,50 @@ extern u32 wl_msg_level;
44 49
45extern u32 wl_ampdu_dbg; 50extern u32 wl_ampdu_dbg;
46 51
47#define WL_AMPDU_UPDN(args) do {if (wl_ampdu_dbg & WL_AMPDU_UPDN_VAL) {WL_AMPDU(args); } } while (0) 52#define WL_AMPDU_PRINT(level, fmt, args...) \
48#define WL_AMPDU_RX(args) do {if (wl_ampdu_dbg & WL_AMPDU_RX_VAL) {WL_AMPDU(args); } } while (0) 53do { \
49#define WL_AMPDU_ERR(args) do {if (wl_ampdu_dbg & WL_AMPDU_ERR_VAL) {WL_AMPDU(args); } } while (0) 54 if (wl_ampdu_dbg & level) { \
50#define WL_AMPDU_TX(args) do {if (wl_ampdu_dbg & WL_AMPDU_TX_VAL) {WL_AMPDU(args); } } while (0) 55 WL_AMPDU(fmt, ##args); \
51#define WL_AMPDU_CTL(args) do {if (wl_ampdu_dbg & WL_AMPDU_CTL_VAL) {WL_AMPDU(args); } } while (0) 56 } \
52#define WL_AMPDU_HW(args) do {if (wl_ampdu_dbg & WL_AMPDU_HW_VAL) {WL_AMPDU(args); } } while (0) 57} while (0)
53#define WL_AMPDU_HWTXS(args) do {if (wl_ampdu_dbg & WL_AMPDU_HWTXS_VAL) {WL_AMPDU(args); } } while (0) 58
54#define WL_AMPDU_HWDBG(args) do {if (wl_ampdu_dbg & WL_AMPDU_HWDBG_VAL) {WL_AMPDU(args); } } while (0) 59#define WL_AMPDU_UPDN(fmt, args...) \
60 WL_AMPDU_PRINT(WL_AMPDU_UPDN_VAL, fmt, ##args)
61#define WL_AMPDU_RX(fmt, args...) \
62 WL_AMPDU_PRINT(WL_AMPDU_RX_VAL, fmt, ##args)
63#define WL_AMPDU_ERR(fmt, args...) \
64 WL_AMPDU_PRINT(WL_AMPDU_ERR_VAL, fmt, ##args)
65#define WL_AMPDU_TX(fmt, args...) \
66 WL_AMPDU_PRINT(WL_AMPDU_TX_VAL, fmt, ##args)
67#define WL_AMPDU_CTL(fmt, args...) \
68 WL_AMPDU_PRINT(WL_AMPDU_CTL_VAL, fmt, ##args)
69#define WL_AMPDU_HW(fmt, args...) \
70 WL_AMPDU_PRINT(WL_AMPDU_HW_VAL, fmt, ##args)
71#define WL_AMPDU_HWTXS(fmt, args...) \
72 WL_AMPDU_PRINT(WL_AMPDU_HWTXS_VAL, fmt, ##args)
73#define WL_AMPDU_HWDBG(fmt, args...) \
74 WL_AMPDU_PRINT(WL_AMPDU_HWDBG_VAL, fmt, ##args)
55#define WL_AMPDU_ERR_ON() (wl_ampdu_dbg & WL_AMPDU_ERR_VAL) 75#define WL_AMPDU_ERR_ON() (wl_ampdu_dbg & WL_AMPDU_ERR_VAL)
56#define WL_AMPDU_HW_ON() (wl_ampdu_dbg & WL_AMPDU_HW_VAL) 76#define WL_AMPDU_HW_ON() (wl_ampdu_dbg & WL_AMPDU_HW_VAL)
57#define WL_AMPDU_HWTXS_ON() (wl_ampdu_dbg & WL_AMPDU_HWTXS_VAL) 77#define WL_AMPDU_HWTXS_ON() (wl_ampdu_dbg & WL_AMPDU_HWTXS_VAL)
58 78
59#else /* BCMDBG */ 79#else /* BCMDBG */
60 80
61#define WL_ERROR(args) 81#define WL_ERROR(fmt, args...) no_printk(fmt, ##args)
62#define WL_TRACE(args) 82#define WL_TRACE(fmt, args...) no_printk(fmt, ##args)
63#define WL_AMPDU(args) 83#define WL_AMPDU(fmt, args...) no_printk(fmt, ##args)
64#define WL_FFPLD(args) 84#define WL_FFPLD(fmt, args...) no_printk(fmt, ##args)
65 85
66#define WL_ERROR_ON() 0 86#define WL_ERROR_ON() 0
67 87
68#define WL_AMPDU_UPDN(args) 88#define WL_AMPDU_UPDN(fmt, args...) no_printk(fmt, ##args)
69#define WL_AMPDU_RX(args) 89#define WL_AMPDU_RX(fmt, args...) no_printk(fmt, ##args)
70#define WL_AMPDU_ERR(args) 90#define WL_AMPDU_ERR(fmt, args...) no_printk(fmt, ##args)
71#define WL_AMPDU_TX(args) 91#define WL_AMPDU_TX(fmt, args...) no_printk(fmt, ##args)
72#define WL_AMPDU_CTL(args) 92#define WL_AMPDU_CTL(fmt, args...) no_printk(fmt, ##args)
73#define WL_AMPDU_HW(args) 93#define WL_AMPDU_HW(fmt, args...) no_printk(fmt, ##args)
74#define WL_AMPDU_HWTXS(args) 94#define WL_AMPDU_HWTXS(fmt, args...) no_printk(fmt, ##args)
75#define WL_AMPDU_HWDBG(args) 95#define WL_AMPDU_HWDBG(fmt, args...) no_printk(fmt, ##args)
76#define WL_AMPDU_ERR_ON() 0 96#define WL_AMPDU_ERR_ON() 0
77#define WL_AMPDU_HW_ON() 0 97#define WL_AMPDU_HW_ON() 0
78#define WL_AMPDU_HWTXS_ON() 0 98#define WL_AMPDU_HWTXS_ON() 0
diff --git a/drivers/staging/brcm80211/sys/wl_export.h b/drivers/staging/brcm80211/sys/wl_export.h
index 08442f8e84e0..aa8b5a3ed633 100644
--- a/drivers/staging/brcm80211/sys/wl_export.h
+++ b/drivers/staging/brcm80211/sys/wl_export.h
@@ -45,10 +45,10 @@ extern void wl_add_timer(struct wl_info *wl, struct wl_timer *timer, uint ms,
45 int periodic); 45 int periodic);
46extern bool wl_del_timer(struct wl_info *wl, struct wl_timer *timer); 46extern bool wl_del_timer(struct wl_info *wl, struct wl_timer *timer);
47 47
48extern uint wl_buf_to_pktcopy(osl_t *osh, void *p, unsigned char *buf, int len, 48extern uint wl_buf_to_pktcopy(struct osl_info *osh, void *p, unsigned char *buf,
49 uint offset); 49 int len, uint offset);
50extern void *wl_get_pktbuffer(osl_t *osh, int len); 50extern void *wl_get_pktbuffer(struct osl_info *osh, int len);
51extern int wl_set_pktlen(osl_t *osh, void *p, int len); 51extern int wl_set_pktlen(struct osl_info *osh, void *p, int len);
52 52
53#define wl_sort_bsslist(a, b) false 53#define wl_sort_bsslist(a, b) false
54 54
diff --git a/drivers/staging/brcm80211/sys/wl_mac80211.c b/drivers/staging/brcm80211/sys/wl_mac80211.c
index d060377629ac..bdd629d72a75 100644
--- a/drivers/staging/brcm80211/sys/wl_mac80211.c
+++ b/drivers/staging/brcm80211/sys/wl_mac80211.c
@@ -21,72 +21,36 @@
21#include <linux/string.h> 21#include <linux/string.h>
22#include <linux/pci_ids.h> 22#include <linux/pci_ids.h>
23#include <bcmdefs.h> 23#include <bcmdefs.h>
24#include <linuxver.h> 24#include <linux/module.h>
25#include <linux/pci.h>
26#include <linux/sched.h>
25#include <osl.h> 27#include <osl.h>
26#define WLC_MAXBSSCFG 1 /* single BSS configs */ 28#define WLC_MAXBSSCFG 1 /* single BSS configs */
27 29
28#include <wlc_cfg.h> 30#include <wlc_cfg.h>
29#include <net/mac80211.h> 31#include <net/mac80211.h>
30#include <epivers.h>
31#ifndef WLC_HIGH_ONLY
32#include <phy_version.h> 32#include <phy_version.h>
33#endif
34#include <bcmutils.h> 33#include <bcmutils.h>
35#include <pcicfg.h> 34#include <pcicfg.h>
36#include <wlioctl.h> 35#include <wlioctl.h>
37#include <wlc_key.h> 36#include <wlc_key.h>
37#include <sbhndpio.h>
38#include <sbhnddma.h>
38#include <wlc_channel.h> 39#include <wlc_channel.h>
39#include <wlc_pub.h> 40#include <wlc_pub.h>
40#include <wlc_scb.h> 41#include <wlc_scb.h>
41#include <wl_dbg.h> 42#include <wl_dbg.h>
42#ifdef BCMSDIO
43#include <bcmsdh.h>
44#endif
45#include <wl_export.h> 43#include <wl_export.h>
46#ifdef WLC_HIGH_ONLY
47#include "dbus.h"
48#include "bcm_rpc_tp.h"
49#include "bcm_rpc.h"
50#include "bcm_xdr.h"
51#include "wlc_rpc.h"
52#endif
53 44
54#include <wl_mac80211.h> 45#include <wl_mac80211.h>
55#include <linux/firmware.h> 46#include <linux/firmware.h>
56#ifndef WLC_HIGH_ONLY
57#include <wl_ucode.h> 47#include <wl_ucode.h>
58#include <d11ucode_ext.h> 48#include <d11ucode_ext.h>
59#endif
60 49
61#ifdef BCMSDIO
62extern struct device *sdiommc_dev;
63#endif
64
65extern void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg,
66 bool suspend);
67bool wlc_sendpkt_mac80211(wlc_info_t *wlc, void *sdu, struct ieee80211_hw *hw);
68void wlc_mac_bcn_promisc_change(wlc_info_t *wlc, bool promisc);
69void wlc_set_addrmatch(wlc_info_t *wlc, int match_reg_offset,
70 const struct ether_addr *addr);
71 50
72static void wl_timer(unsigned long data); 51static void wl_timer(unsigned long data);
73static void _wl_timer(wl_timer_t *t); 52static void _wl_timer(wl_timer_t *t);
74 53
75#ifdef WLC_HIGH_ONLY
76#define RPCQ_LOCK(_wl, _flags) spin_lock_irqsave(&(_wl)->rpcq_lock, (_flags))
77#define RPCQ_UNLOCK(_wl, _flags) spin_unlock_irqrestore(&(_wl)->rpcq_lock, (_flags))
78#define TXQ_LOCK(_wl, _flags) spin_lock_irqsave(&(_wl)->txq_lock, (_flags))
79#define TXQ_UNLOCK(_wl, _flags) spin_unlock_irqrestore(&(_wl)->txq_lock, (_flags))
80static void wl_rpc_down(void *wlh);
81static void wl_rpcq_free(wl_info_t *wl);
82static void wl_rpcq_dispatch(struct wl_task *task);
83static void wl_rpc_dispatch_schedule(void *ctx, struct rpc_buf *buf);
84static void wl_start_txqwork(struct wl_task *task);
85static void wl_txq_free(wl_info_t *wl);
86static void wl_timer_task(wl_task_t *task);
87static int wl_schedule_task(wl_info_t *wl, void (*fn) (struct wl_task *),
88 void *context);
89#endif /* WLC_HIGH_ONLY */
90 54
91static int ieee_hw_init(struct ieee80211_hw *hw); 55static int ieee_hw_init(struct ieee80211_hw *hw);
92static int ieee_hw_rate_init(struct ieee80211_hw *hw); 56static int ieee_hw_rate_init(struct ieee80211_hw *hw);
@@ -134,16 +98,14 @@ struct ieee80211_tkip_data {
134 u8 rx_hdr[16], tx_hdr[16]; 98 u8 rx_hdr[16], tx_hdr[16];
135}; 99};
136 100
137#ifndef WLC_HIGH_ONLY 101#define WL_DEV_IF(dev) ((struct wl_if *)netdev_priv(dev))
138#define WL_DEV_IF(dev) ((wl_if_t *)netdev_priv(dev)) 102#define WL_INFO(dev) ((struct wl_info *)(WL_DEV_IF(dev)->wl))
139#define WL_INFO(dev) ((wl_info_t *)(WL_DEV_IF(dev)->wl)) /* points to wl */ 103static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev);
140static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev); 104static void wl_release_fw(struct wl_info *wl);
141static void wl_release_fw(wl_info_t *wl);
142#endif
143 105
144/* local prototypes */ 106/* local prototypes */
145static int wl_start(struct sk_buff *skb, wl_info_t *wl); 107static int wl_start(struct sk_buff *skb, struct wl_info *wl);
146static int wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw, 108static int wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw,
147 struct sk_buff *skb); 109 struct sk_buff *skb);
148static void wl_dpc(unsigned long data); 110static void wl_dpc(unsigned long data);
149 111
@@ -152,7 +114,6 @@ MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
152MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards"); 114MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
153MODULE_LICENSE("Dual BSD/GPL"); 115MODULE_LICENSE("Dual BSD/GPL");
154 116
155#ifndef BCMSDIO
156/* recognized PCI IDs */ 117/* recognized PCI IDs */
157static struct pci_device_id wl_id_table[] = { 118static struct pci_device_id wl_id_table[] = {
158 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */ 119 {PCI_VENDOR_ID_BROADCOM, 0x4357, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 43225 2G */
@@ -163,55 +124,18 @@ static struct pci_device_id wl_id_table[] = {
163 124
164MODULE_DEVICE_TABLE(pci, wl_id_table); 125MODULE_DEVICE_TABLE(pci, wl_id_table);
165static void wl_remove(struct pci_dev *pdev); 126static void wl_remove(struct pci_dev *pdev);
166#endif /* !BCMSDIO */
167 127
168#ifdef BCMSDIO
169static uint sd_drivestrength = 6;
170module_param(sd_drivestrength, uint, 0);
171#endif
172 128
173#ifdef BCMDBG 129#ifdef BCMDBG
174static int msglevel = 0xdeadbeef; 130static int msglevel = 0xdeadbeef;
175module_param(msglevel, int, 0); 131module_param(msglevel, int, 0);
176#ifndef WLC_HIGH_ONLY
177static int phymsglevel = 0xdeadbeef; 132static int phymsglevel = 0xdeadbeef;
178module_param(phymsglevel, int, 0); 133module_param(phymsglevel, int, 0);
179#endif /* WLC_HIGH_ONLY */
180#endif /* BCMDBG */ 134#endif /* BCMDBG */
181 135
182static int oneonly;
183module_param(oneonly, int, 0);
184
185static int piomode;
186module_param(piomode, int, 0);
187
188static int instance_base; /* Starting instance number */
189module_param(instance_base, int, 0);
190
191#if defined(BCMDBG)
192static char *macaddr;
193module_param(macaddr, charp, S_IRUGO);
194#endif
195
196static int nompc = 1;
197module_param(nompc, int, 0);
198
199static char name[IFNAMSIZ] = "eth%d";
200module_param_string(name, name, IFNAMSIZ, 0);
201
202#ifndef SRCBASE
203#define SRCBASE "."
204#endif
205
206#define WL_MAGIC 0xdeadbeef
207
208#define HW_TO_WL(hw) (hw->priv) 136#define HW_TO_WL(hw) (hw->priv)
209#define WL_TO_HW(wl) (wl->pub->ieee_hw) 137#define WL_TO_HW(wl) (wl->pub->ieee_hw)
210#ifdef WLC_HIGH_ONLY
211static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb);
212#else
213static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb); 138static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
214#endif
215static int wl_ops_start(struct ieee80211_hw *hw); 139static int wl_ops_start(struct ieee80211_hw *hw);
216static void wl_ops_stop(struct ieee80211_hw *hw); 140static void wl_ops_stop(struct ieee80211_hw *hw);
217static int wl_ops_add_interface(struct ieee80211_hw *hw, 141static int wl_ops_add_interface(struct ieee80211_hw *hw,
@@ -249,28 +173,13 @@ static int wl_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
249 enum ieee80211_ampdu_mlme_action action, 173 enum ieee80211_ampdu_mlme_action action,
250 struct ieee80211_sta *sta, u16 tid, u16 *ssn); 174 struct ieee80211_sta *sta, u16 tid, u16 *ssn);
251 175
252#ifdef WLC_HIGH_ONLY
253static int wl_ops_tx_nl(struct ieee80211_hw *hw, struct sk_buff *skb)
254{
255 int status;
256 wl_info_t *wl = hw->priv;
257 if (!wl->pub->up) {
258 WL_ERROR(("ops->tx called while down\n"));
259 status = -ENETDOWN;
260 goto done;
261 }
262 status = wl_start(skb, wl);
263 done:
264 return status;
265}
266#else
267static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 176static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
268{ 177{
269 int status; 178 int status;
270 wl_info_t *wl = hw->priv; 179 struct wl_info *wl = hw->priv;
271 WL_LOCK(wl); 180 WL_LOCK(wl);
272 if (!wl->pub->up) { 181 if (!wl->pub->up) {
273 WL_ERROR(("ops->tx called while down\n")); 182 WL_ERROR("ops->tx called while down\n");
274 status = -ENETDOWN; 183 status = -ENETDOWN;
275 goto done; 184 goto done;
276 } 185 }
@@ -279,13 +188,14 @@ static int wl_ops_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
279 WL_UNLOCK(wl); 188 WL_UNLOCK(wl);
280 return status; 189 return status;
281} 190}
282#endif /* WLC_HIGH_ONLY */
283 191
284static int wl_ops_start(struct ieee80211_hw *hw) 192static int wl_ops_start(struct ieee80211_hw *hw)
285{ 193{
286 wl_info_t *wl = hw->priv; 194 struct wl_info *wl = hw->priv;
287 /* struct ieee80211_channel *curchan = hw->conf.channel; */ 195 /*
288 WL_NONE(("%s : Initial channel: %d\n", __func__, curchan->hw_value)); 196 struct ieee80211_channel *curchan = hw->conf.channel;
197 WL_NONE("%s : Initial channel: %d\n", __func__, curchan->hw_value);
198 */
289 199
290 WL_LOCK(wl); 200 WL_LOCK(wl);
291 ieee80211_wake_queues(hw); 201 ieee80211_wake_queues(hw);
@@ -296,7 +206,7 @@ static int wl_ops_start(struct ieee80211_hw *hw)
296 206
297static void wl_ops_stop(struct ieee80211_hw *hw) 207static void wl_ops_stop(struct ieee80211_hw *hw)
298{ 208{
299 wl_info_t *wl = hw->priv; 209 struct wl_info *wl = hw->priv;
300 ASSERT(wl); 210 ASSERT(wl);
301 WL_LOCK(wl); 211 WL_LOCK(wl);
302 wl_down(wl); 212 wl_down(wl);
@@ -309,7 +219,7 @@ static void wl_ops_stop(struct ieee80211_hw *hw)
309static int 219static int
310wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 220wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
311{ 221{
312 wl_info_t *wl; 222 struct wl_info *wl;
313 int err; 223 int err;
314 224
315 /* Just STA for now */ 225 /* Just STA for now */
@@ -318,8 +228,8 @@ wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
318 vif->type != NL80211_IFTYPE_STATION && 228 vif->type != NL80211_IFTYPE_STATION &&
319 vif->type != NL80211_IFTYPE_WDS && 229 vif->type != NL80211_IFTYPE_WDS &&
320 vif->type != NL80211_IFTYPE_ADHOC) { 230 vif->type != NL80211_IFTYPE_ADHOC) {
321 WL_ERROR(("%s: Attempt to add type %d, only STA for now\n", 231 WL_ERROR("%s: Attempt to add type %d, only STA for now\n",
322 __func__, vif->type)); 232 __func__, vif->type);
323 return -EOPNOTSUPP; 233 return -EOPNOTSUPP;
324 } 234 }
325 235
@@ -329,7 +239,7 @@ wl_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
329 WL_UNLOCK(wl); 239 WL_UNLOCK(wl);
330 240
331 if (err != 0) 241 if (err != 0)
332 WL_ERROR(("%s: wl_up() returned %d\n", __func__, err)); 242 WL_ERROR("%s: wl_up() returned %d\n", __func__, err);
333 return err; 243 return err;
334} 244}
335 245
@@ -343,7 +253,7 @@ static int
343ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan, 253ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
344 enum nl80211_channel_type type) 254 enum nl80211_channel_type type)
345{ 255{
346 wl_info_t *wl = HW_TO_WL(hw); 256 struct wl_info *wl = HW_TO_WL(hw);
347 int err = 0; 257 int err = 0;
348 258
349 switch (type) { 259 switch (type) {
@@ -355,8 +265,7 @@ ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
355 break; 265 break;
356 case NL80211_CHAN_HT40MINUS: 266 case NL80211_CHAN_HT40MINUS:
357 case NL80211_CHAN_HT40PLUS: 267 case NL80211_CHAN_HT40PLUS:
358 WL_ERROR(("%s: Need to implement 40 Mhz Channels!\n", 268 WL_ERROR("%s: Need to implement 40 Mhz Channels!\n", __func__);
359 __func__));
360 break; 269 break;
361 } 270 }
362 271
@@ -368,17 +277,17 @@ ieee_set_channel(struct ieee80211_hw *hw, struct ieee80211_channel *chan,
368static int wl_ops_config(struct ieee80211_hw *hw, u32 changed) 277static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
369{ 278{
370 struct ieee80211_conf *conf = &hw->conf; 279 struct ieee80211_conf *conf = &hw->conf;
371 wl_info_t *wl = HW_TO_WL(hw); 280 struct wl_info *wl = HW_TO_WL(hw);
372 int err = 0; 281 int err = 0;
373 int new_int; 282 int new_int;
374 283
375 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { 284 if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
376 WL_NONE(("%s: Setting listen interval to %d\n", 285 WL_NONE("%s: Setting listen interval to %d\n",
377 __func__, conf->listen_interval)); 286 __func__, conf->listen_interval);
378 if (wlc_iovar_setint 287 if (wlc_iovar_setint
379 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) { 288 (wl->wlc, "bcn_li_bcn", conf->listen_interval)) {
380 WL_ERROR(("%s: Error setting listen_interval\n", 289 WL_ERROR("%s: Error setting listen_interval\n",
381 __func__)); 290 __func__);
382 err = -EIO; 291 err = -EIO;
383 goto config_out; 292 goto config_out;
384 } 293 }
@@ -386,41 +295,42 @@ static int wl_ops_config(struct ieee80211_hw *hw, u32 changed)
386 ASSERT(new_int == conf->listen_interval); 295 ASSERT(new_int == conf->listen_interval);
387 } 296 }
388 if (changed & IEEE80211_CONF_CHANGE_MONITOR) 297 if (changed & IEEE80211_CONF_CHANGE_MONITOR)
389 WL_NONE(("Need to set monitor mode\n")); 298 WL_NONE("Need to set monitor mode\n");
390 if (changed & IEEE80211_CONF_CHANGE_PS) 299 if (changed & IEEE80211_CONF_CHANGE_PS)
391 WL_NONE(("Need to set Power-save mode\n")); 300 WL_NONE("Need to set Power-save mode\n");
392 301
393 if (changed & IEEE80211_CONF_CHANGE_POWER) { 302 if (changed & IEEE80211_CONF_CHANGE_POWER) {
394 WL_NONE(("%s: Setting tx power to %d dbm\n", __func__, 303 WL_NONE("%s: Setting tx power to %d dbm\n",
395 conf->power_level)); 304 __func__, conf->power_level);
396 if (wlc_iovar_setint 305 if (wlc_iovar_setint
397 (wl->wlc, "qtxpower", conf->power_level * 4)) { 306 (wl->wlc, "qtxpower", conf->power_level * 4)) {
398 WL_ERROR(("%s: Error setting power_level\n", __func__)); 307 WL_ERROR("%s: Error setting power_level\n", __func__);
399 err = -EIO; 308 err = -EIO;
400 goto config_out; 309 goto config_out;
401 } 310 }
402 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int); 311 wlc_iovar_getint(wl->wlc, "qtxpower", &new_int);
403 if (new_int != (conf->power_level * 4)) 312 if (new_int != (conf->power_level * 4))
404 WL_ERROR(("%s: Power level req != actual, %d %d\n", 313 WL_ERROR("%s: Power level req != actual, %d %d\n",
405 __func__, conf->power_level * 4, new_int)); 314 __func__, conf->power_level * 4, new_int);
406 } 315 }
407 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { 316 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
408 err = ieee_set_channel(hw, conf->channel, conf->channel_type); 317 err = ieee_set_channel(hw, conf->channel, conf->channel_type);
409 } 318 }
410 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { 319 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
411 WL_NONE(("%s: srl %d, lrl %d\n", __func__, 320 WL_NONE("%s: srl %d, lrl %d\n",
412 conf->short_frame_max_tx_count, 321 __func__,
413 conf->long_frame_max_tx_count)); 322 conf->short_frame_max_tx_count,
323 conf->long_frame_max_tx_count);
414 if (wlc_set 324 if (wlc_set
415 (wl->wlc, WLC_SET_SRL, 325 (wl->wlc, WLC_SET_SRL,
416 conf->short_frame_max_tx_count) < 0) { 326 conf->short_frame_max_tx_count) < 0) {
417 WL_ERROR(("%s: Error setting srl\n", __func__)); 327 WL_ERROR("%s: Error setting srl\n", __func__);
418 err = -EIO; 328 err = -EIO;
419 goto config_out; 329 goto config_out;
420 } 330 }
421 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count) 331 if (wlc_set(wl->wlc, WLC_SET_LRL, conf->long_frame_max_tx_count)
422 < 0) { 332 < 0) {
423 WL_ERROR(("%s: Error setting lrl\n", __func__)); 333 WL_ERROR("%s: Error setting lrl\n", __func__);
424 err = -EIO; 334 err = -EIO;
425 goto config_out; 335 goto config_out;
426 } 336 }
@@ -435,32 +345,29 @@ wl_ops_bss_info_changed(struct ieee80211_hw *hw,
435 struct ieee80211_vif *vif, 345 struct ieee80211_vif *vif,
436 struct ieee80211_bss_conf *info, u32 changed) 346 struct ieee80211_bss_conf *info, u32 changed)
437{ 347{
438 wl_info_t *wl = HW_TO_WL(hw); 348 struct wl_info *wl = HW_TO_WL(hw);
439 int val; 349 int val;
440 350
441#ifdef WLC_HIGH_ONLY
442 WL_LOCK(wl);
443#endif
444 351
445 if (changed & BSS_CHANGED_ASSOC) { 352 if (changed & BSS_CHANGED_ASSOC) {
446 WL_ERROR(("Associated:\t%s\n", info->assoc ? "True" : "False")); 353 WL_ERROR("Associated:\t%s\n", info->assoc ? "True" : "False");
447 /* association status changed (associated/disassociated) 354 /* association status changed (associated/disassociated)
448 * also implies a change in the AID. 355 * also implies a change in the AID.
449 */ 356 */
450 } 357 }
451 if (changed & BSS_CHANGED_ERP_CTS_PROT) { 358 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
452 WL_NONE(("Use_cts_prot:\t%s Implement me\n", 359 WL_NONE("Use_cts_prot:\t%s Implement me\n",
453 info->use_cts_prot ? "True" : "False")); 360 info->use_cts_prot ? "True" : "False");
454 /* CTS protection changed */ 361 /* CTS protection changed */
455 } 362 }
456 if (changed & BSS_CHANGED_ERP_PREAMBLE) { 363 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
457 WL_NONE(("Short preamble:\t%s Implement me\n", 364 WL_NONE("Short preamble:\t%s Implement me\n",
458 info->use_short_preamble ? "True" : "False")); 365 info->use_short_preamble ? "True" : "False");
459 /* preamble changed */ 366 /* preamble changed */
460 } 367 }
461 if (changed & BSS_CHANGED_ERP_SLOT) { 368 if (changed & BSS_CHANGED_ERP_SLOT) {
462 WL_NONE(("Changing short slot:\t%s\n", 369 WL_NONE("Changing short slot:\t%s\n",
463 info->use_short_slot ? "True" : "False")); 370 info->use_short_slot ? "True" : "False");
464 if (info->use_short_slot) 371 if (info->use_short_slot)
465 val = 1; 372 val = 1;
466 else 373 else
@@ -470,39 +377,36 @@ wl_ops_bss_info_changed(struct ieee80211_hw *hw,
470 } 377 }
471 378
472 if (changed & BSS_CHANGED_HT) { 379 if (changed & BSS_CHANGED_HT) {
473 WL_NONE(("%s: HT mode - Implement me\n", __func__)); 380 WL_NONE("%s: HT mode - Implement me\n", __func__);
474 /* 802.11n parameters changed */ 381 /* 802.11n parameters changed */
475 } 382 }
476 if (changed & BSS_CHANGED_BASIC_RATES) { 383 if (changed & BSS_CHANGED_BASIC_RATES) {
477 WL_NONE(("Need to change Basic Rates:\t0x%x! Implement me\n", 384 WL_NONE("Need to change Basic Rates:\t0x%x! Implement me\n",
478 (u32) info->basic_rates)); 385 (u32) info->basic_rates);
479 /* Basic rateset changed */ 386 /* Basic rateset changed */
480 } 387 }
481 if (changed & BSS_CHANGED_BEACON_INT) { 388 if (changed & BSS_CHANGED_BEACON_INT) {
482 WL_NONE(("Beacon Interval:\t%d Implement me\n", 389 WL_NONE("Beacon Interval:\t%d Implement me\n",
483 info->beacon_int)); 390 info->beacon_int);
484 /* Beacon interval changed */ 391 /* Beacon interval changed */
485 } 392 }
486 if (changed & BSS_CHANGED_BSSID) { 393 if (changed & BSS_CHANGED_BSSID) {
487 WL_NONE(("new BSSID:\taid %d bss:%pM\n", info->aid, 394 WL_NONE("new BSSID:\taid %d bss:%pM\n",
488 info->bssid)); 395 info->aid, info->bssid);
489 /* BSSID changed, for whatever reason (IBSS and managed mode) */ 396 /* BSSID changed, for whatever reason (IBSS and managed mode) */
490 /* FIXME: need to store bssid in bsscfg */ 397 /* FIXME: need to store bssid in bsscfg */
491 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, 398 wlc_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET,
492 (struct ether_addr *)info->bssid); 399 (struct ether_addr *)info->bssid);
493 } 400 }
494 if (changed & BSS_CHANGED_BEACON) { 401 if (changed & BSS_CHANGED_BEACON) {
495 WL_ERROR(("BSS_CHANGED_BEACON\n")); 402 WL_ERROR("BSS_CHANGED_BEACON\n");
496 /* Beacon data changed, retrieve new beacon (beaconing modes) */ 403 /* Beacon data changed, retrieve new beacon (beaconing modes) */
497 } 404 }
498 if (changed & BSS_CHANGED_BEACON_ENABLED) { 405 if (changed & BSS_CHANGED_BEACON_ENABLED) {
499 WL_ERROR(("Beacon enabled:\t%s\n", 406 WL_ERROR("Beacon enabled:\t%s\n",
500 info->enable_beacon ? "True" : "False")); 407 info->enable_beacon ? "True" : "False");
501 /* Beaconing should be enabled/disabled (beaconing modes) */ 408 /* Beaconing should be enabled/disabled (beaconing modes) */
502 } 409 }
503#ifdef WLC_HIGH_ONLY
504 WL_UNLOCK(wl);
505#endif
506 return; 410 return;
507} 411}
508 412
@@ -511,27 +415,24 @@ wl_ops_configure_filter(struct ieee80211_hw *hw,
511 unsigned int changed_flags, 415 unsigned int changed_flags,
512 unsigned int *total_flags, u64 multicast) 416 unsigned int *total_flags, u64 multicast)
513{ 417{
514#ifndef WLC_HIGH_ONLY 418 struct wl_info *wl = hw->priv;
515 wl_info_t *wl = hw->priv;
516#endif
517 419
518 changed_flags &= MAC_FILTERS; 420 changed_flags &= MAC_FILTERS;
519 *total_flags &= MAC_FILTERS; 421 *total_flags &= MAC_FILTERS;
520 if (changed_flags & FIF_PROMISC_IN_BSS) 422 if (changed_flags & FIF_PROMISC_IN_BSS)
521 WL_ERROR(("FIF_PROMISC_IN_BSS\n")); 423 WL_ERROR("FIF_PROMISC_IN_BSS\n");
522 if (changed_flags & FIF_ALLMULTI) 424 if (changed_flags & FIF_ALLMULTI)
523 WL_ERROR(("FIF_ALLMULTI\n")); 425 WL_ERROR("FIF_ALLMULTI\n");
524 if (changed_flags & FIF_FCSFAIL) 426 if (changed_flags & FIF_FCSFAIL)
525 WL_ERROR(("FIF_FCSFAIL\n")); 427 WL_ERROR("FIF_FCSFAIL\n");
526 if (changed_flags & FIF_PLCPFAIL) 428 if (changed_flags & FIF_PLCPFAIL)
527 WL_ERROR(("FIF_PLCPFAIL\n")); 429 WL_ERROR("FIF_PLCPFAIL\n");
528 if (changed_flags & FIF_CONTROL) 430 if (changed_flags & FIF_CONTROL)
529 WL_ERROR(("FIF_CONTROL\n")); 431 WL_ERROR("FIF_CONTROL\n");
530 if (changed_flags & FIF_OTHER_BSS) 432 if (changed_flags & FIF_OTHER_BSS)
531 WL_ERROR(("FIF_OTHER_BSS\n")); 433 WL_ERROR("FIF_OTHER_BSS\n");
532 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { 434 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
533 WL_NONE(("FIF_BCN_PRBRESP_PROMISC\n")); 435 WL_NONE("FIF_BCN_PRBRESP_PROMISC\n");
534#ifndef WLC_HIGH_ONLY
535 WL_LOCK(wl); 436 WL_LOCK(wl);
536 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) { 437 if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
537 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS; 438 wl->pub->mac80211_state |= MAC80211_PROMISC_BCNS;
@@ -541,7 +442,6 @@ wl_ops_configure_filter(struct ieee80211_hw *hw,
541 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS; 442 wl->pub->mac80211_state &= ~MAC80211_PROMISC_BCNS;
542 } 443 }
543 WL_UNLOCK(wl); 444 WL_UNLOCK(wl);
544#endif
545 } 445 }
546 return; 446 return;
547} 447}
@@ -549,25 +449,25 @@ wl_ops_configure_filter(struct ieee80211_hw *hw,
549static int 449static int
550wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set) 450wl_ops_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
551{ 451{
552 WL_ERROR(("%s: Enter\n", __func__)); 452 WL_ERROR("%s: Enter\n", __func__);
553 return 0; 453 return 0;
554} 454}
555 455
556static void wl_ops_sw_scan_start(struct ieee80211_hw *hw) 456static void wl_ops_sw_scan_start(struct ieee80211_hw *hw)
557{ 457{
558 WL_NONE(("Scan Start\n")); 458 WL_NONE("Scan Start\n");
559 return; 459 return;
560} 460}
561 461
562static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw) 462static void wl_ops_sw_scan_complete(struct ieee80211_hw *hw)
563{ 463{
564 WL_NONE(("Scan Complete\n")); 464 WL_NONE("Scan Complete\n");
565 return; 465 return;
566} 466}
567 467
568static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf) 468static void wl_ops_set_tsf(struct ieee80211_hw *hw, u64 tsf)
569{ 469{
570 WL_ERROR(("%s: Enter\n", __func__)); 470 WL_ERROR("%s: Enter\n", __func__);
571 return; 471 return;
572} 472}
573 473
@@ -575,13 +475,13 @@ static int
575wl_ops_get_stats(struct ieee80211_hw *hw, 475wl_ops_get_stats(struct ieee80211_hw *hw,
576 struct ieee80211_low_level_stats *stats) 476 struct ieee80211_low_level_stats *stats)
577{ 477{
578 WL_ERROR(("%s: Enter\n", __func__)); 478 WL_ERROR("%s: Enter\n", __func__);
579 return 0; 479 return 0;
580} 480}
581 481
582static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 482static int wl_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
583{ 483{
584 WL_ERROR(("%s: Enter\n", __func__)); 484 WL_ERROR("%s: Enter\n", __func__);
585 return 0; 485 return 0;
586} 486}
587 487
@@ -589,10 +489,10 @@ static void
589wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 489wl_ops_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
590 enum sta_notify_cmd cmd, struct ieee80211_sta *sta) 490 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
591{ 491{
592 WL_NONE(("%s: Enter\n", __func__)); 492 WL_NONE("%s: Enter\n", __func__);
593 switch (cmd) { 493 switch (cmd) {
594 default: 494 default:
595 WL_ERROR(("%s: Uknown cmd = %d\n", __func__, cmd)); 495 WL_ERROR("%s: Unknown cmd = %d\n", __func__, cmd);
596 break; 496 break;
597 } 497 }
598 return; 498 return;
@@ -602,11 +502,11 @@ static int
602wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue, 502wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
603 const struct ieee80211_tx_queue_params *params) 503 const struct ieee80211_tx_queue_params *params)
604{ 504{
605 wl_info_t *wl = hw->priv; 505 struct wl_info *wl = hw->priv;
606 506
607 WL_NONE(("%s: Enter (WME config)\n", __func__)); 507 WL_NONE("%s: Enter (WME config)\n", __func__);
608 WL_NONE(("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue, 508 WL_NONE("queue %d, txop %d, cwmin %d, cwmax %d, aifs %d\n", queue,
609 params->txop, params->cw_min, params->cw_max, params->aifs)); 509 params->txop, params->cw_min, params->cw_max, params->aifs);
610 510
611 WL_LOCK(wl); 511 WL_LOCK(wl);
612 wlc_wme_setparams(wl->wlc, queue, (void *)params, true); 512 wlc_wme_setparams(wl->wlc, queue, (void *)params, true);
@@ -617,7 +517,7 @@ wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue,
617 517
618static u64 wl_ops_get_tsf(struct ieee80211_hw *hw) 518static u64 wl_ops_get_tsf(struct ieee80211_hw *hw)
619{ 519{
620 WL_ERROR(("%s: Enter\n", __func__)); 520 WL_ERROR("%s: Enter\n", __func__);
621 return 0; 521 return 0;
622} 522}
623 523
@@ -628,11 +528,11 @@ wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
628 struct scb *scb; 528 struct scb *scb;
629 529
630 int i; 530 int i;
631 wl_info_t *wl = hw->priv; 531 struct wl_info *wl = hw->priv;
632 532
633 /* Init the scb */ 533 /* Init the scb */
634 scb = (struct scb *)sta->drv_priv; 534 scb = (struct scb *)sta->drv_priv;
635 bzero(scb, sizeof(struct scb)); 535 memset(scb, 0, sizeof(struct scb));
636 for (i = 0; i < NUMPRIO; i++) 536 for (i = 0; i < NUMPRIO; i++)
637 scb->seqctl[i] = 0xFFFF; 537 scb->seqctl[i] = 0xFFFF;
638 scb->seqctl_nonqos = 0xFFFF; 538 scb->seqctl_nonqos = 0xFFFF;
@@ -641,20 +541,12 @@ wl_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
641 wl->pub->global_scb = scb; 541 wl->pub->global_scb = scb;
642 wl->pub->global_ampdu = &(scb->scb_ampdu); 542 wl->pub->global_ampdu = &(scb->scb_ampdu);
643 wl->pub->global_ampdu->scb = scb; 543 wl->pub->global_ampdu->scb = scb;
644#ifdef WLC_HIGH_ONLY
645 wl->pub->global_ampdu->max_pdu = AMPDU_NUM_MPDU;
646#else
647 wl->pub->global_ampdu->max_pdu = 16; 544 wl->pub->global_ampdu->max_pdu = 16;
648#endif
649 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID, 545 pktq_init(&scb->scb_ampdu.txq, AMPDU_MAX_SCB_TID,
650 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT); 546 AMPDU_MAX_SCB_TID * PKTQ_LEN_DEFAULT);
651 547
652 sta->ht_cap.ht_supported = true; 548 sta->ht_cap.ht_supported = true;
653#ifdef WLC_HIGH_ONLY
654 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_16K;
655#else
656 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K; 549 sta->ht_cap.ampdu_factor = AMPDU_RX_FACTOR_64K;
657#endif
658 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY; 550 sta->ht_cap.ampdu_density = AMPDU_DEF_MPDU_DENSITY;
659 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD | 551 sta->ht_cap.cap = IEEE80211_HT_CAP_GRN_FLD |
660 IEEE80211_HT_CAP_SGI_20 | 552 IEEE80211_HT_CAP_SGI_20 |
@@ -668,7 +560,7 @@ static int
668wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 560wl_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
669 struct ieee80211_sta *sta) 561 struct ieee80211_sta *sta)
670{ 562{
671 WL_NONE(("%s: Enter\n", __func__)); 563 WL_NONE("%s: Enter\n", __func__);
672 return 0; 564 return 0;
673} 565}
674 566
@@ -681,19 +573,19 @@ wl_ampdu_action(struct ieee80211_hw *hw,
681#if defined(BCMDBG) 573#if defined(BCMDBG)
682 struct scb *scb = (struct scb *)sta->drv_priv; 574 struct scb *scb = (struct scb *)sta->drv_priv;
683#endif 575#endif
684 wl_info_t *wl = hw->priv; 576 struct wl_info *wl = hw->priv;
685 577
686 ASSERT(scb->magic == SCB_MAGIC); 578 ASSERT(scb->magic == SCB_MAGIC);
687 switch (action) { 579 switch (action) {
688 case IEEE80211_AMPDU_RX_START: 580 case IEEE80211_AMPDU_RX_START:
689 WL_NONE(("%s: action = IEEE80211_AMPDU_RX_START\n", __func__)); 581 WL_NONE("%s: action = IEEE80211_AMPDU_RX_START\n", __func__);
690 break; 582 break;
691 case IEEE80211_AMPDU_RX_STOP: 583 case IEEE80211_AMPDU_RX_STOP:
692 WL_NONE(("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__)); 584 WL_NONE("%s: action = IEEE80211_AMPDU_RX_STOP\n", __func__);
693 break; 585 break;
694 case IEEE80211_AMPDU_TX_START: 586 case IEEE80211_AMPDU_TX_START:
695 if (!wlc_aggregatable(wl->wlc, tid)) { 587 if (!wlc_aggregatable(wl->wlc, tid)) {
696 /* WL_ERROR(("START: tid %d is not agg' able, return FAILURE to stack\n", tid)); */ 588 /* WL_ERROR("START: tid %d is not agg' able, return FAILURE to stack\n", tid); */
697 return -1; 589 return -1;
698 } 590 }
699 /* XXX: Use the starting sequence number provided ... */ 591 /* XXX: Use the starting sequence number provided ... */
@@ -707,22 +599,18 @@ wl_ampdu_action(struct ieee80211_hw *hw,
707 case IEEE80211_AMPDU_TX_OPERATIONAL: 599 case IEEE80211_AMPDU_TX_OPERATIONAL:
708 /* Not sure what to do here */ 600 /* Not sure what to do here */
709 /* Power save wakeup */ 601 /* Power save wakeup */
710 WL_NONE(("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n", 602 WL_NONE("%s: action = IEEE80211_AMPDU_TX_OPERATIONAL\n",
711 __func__)); 603 __func__);
712 break; 604 break;
713 default: 605 default:
714 WL_ERROR(("%s: Invalid command, ignoring\n", __func__)); 606 WL_ERROR("%s: Invalid command, ignoring\n", __func__);
715 } 607 }
716 608
717 return 0; 609 return 0;
718} 610}
719 611
720static const struct ieee80211_ops wl_ops = { 612static const struct ieee80211_ops wl_ops = {
721#ifdef WLC_HIGH_ONLY
722 .tx = wl_ops_tx_nl,
723#else
724 .tx = wl_ops_tx, 613 .tx = wl_ops_tx,
725#endif
726 .start = wl_ops_start, 614 .start = wl_ops_start,
727 .stop = wl_ops_stop, 615 .stop = wl_ops_stop,
728 .add_interface = wl_ops_add_interface, 616 .add_interface = wl_ops_add_interface,
@@ -744,10 +632,10 @@ static const struct ieee80211_ops wl_ops = {
744 .ampdu_action = wl_ampdu_action, 632 .ampdu_action = wl_ampdu_action,
745}; 633};
746 634
747static int wl_set_hint(wl_info_t *wl, char *abbrev) 635static int wl_set_hint(struct wl_info *wl, char *abbrev)
748{ 636{
749 WL_ERROR(("%s: Sending country code %c%c to MAC80211\n", __func__, 637 WL_ERROR("%s: Sending country code %c%c to MAC80211\n",
750 abbrev[0], abbrev[1])); 638 __func__, abbrev[0], abbrev[1]);
751 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev); 639 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
752} 640}
753 641
@@ -762,117 +650,61 @@ static int wl_set_hint(wl_info_t *wl, char *abbrev)
762 * a warning that this function is defined but not used if we declare 650 * a warning that this function is defined but not used if we declare
763 * it as static. 651 * it as static.
764 */ 652 */
765static wl_info_t *wl_attach(u16 vendor, u16 device, unsigned long regs, 653static struct wl_info *wl_attach(u16 vendor, u16 device, unsigned long regs,
766 uint bustype, void *btparam, uint irq) 654 uint bustype, void *btparam, uint irq)
767{ 655{
768 wl_info_t *wl; 656 struct wl_info *wl;
769 osl_t *osh; 657 struct osl_info *osh;
770 int unit, err; 658 int unit, err;
771 659
772 unsigned long base_addr; 660 unsigned long base_addr;
773 struct ieee80211_hw *hw; 661 struct ieee80211_hw *hw;
774 u8 perm[ETH_ALEN]; 662 u8 perm[ETH_ALEN];
775 663
776 unit = wl_found + instance_base; 664 unit = wl_found;
777 err = 0; 665 err = 0;
778 666
779 if (unit < 0) { 667 if (unit < 0) {
780 WL_ERROR(("wl%d: unit number overflow, exiting\n", unit)); 668 WL_ERROR("wl%d: unit number overflow, exiting\n", unit);
781 return NULL; 669 return NULL;
782 } 670 }
783 671
784 if (oneonly && (unit != instance_base)) { 672 osh = osl_attach(btparam, bustype);
785 WL_ERROR(("wl%d: wl_attach: oneonly is set, exiting\n", unit));
786 return NULL;
787 }
788
789 /* Requires pkttag feature */
790 osh = osl_attach(btparam, bustype, true);
791 ASSERT(osh); 673 ASSERT(osh);
792 674
793#ifdef WLC_HIGH_ONLY
794 hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops);
795 if (!hw) {
796 WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__));
797 ASSERT(0);
798 }
799
800 bzero(hw->priv, sizeof(*wl));
801 wl = hw->priv;
802#else
803 /* allocate private info */ 675 /* allocate private info */
804 hw = pci_get_drvdata(btparam); /* btparam == pdev */ 676 hw = pci_get_drvdata(btparam); /* btparam == pdev */
805 wl = hw->priv; 677 wl = hw->priv;
806#endif
807 ASSERT(wl); 678 ASSERT(wl);
808 679
809 wl->magic = WL_MAGIC;
810 wl->osh = osh; 680 wl->osh = osh;
811 atomic_set(&wl->callbacks, 0); 681 atomic_set(&wl->callbacks, 0);
812 682
813 /* setup the bottom half handler */ 683 /* setup the bottom half handler */
814 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl); 684 tasklet_init(&wl->tasklet, wl_dpc, (unsigned long) wl);
815 685
816#ifdef WLC_HIGH_ONLY
817 wl->rpc_th = bcm_rpc_tp_attach(osh, NULL);
818 if (wl->rpc_th == NULL) {
819 WL_ERROR(("wl%d: %s: bcm_rpc_tp_attach failed!\n", unit,
820 __func__));
821 goto fail;
822 }
823
824 wl->rpc = bcm_rpc_attach(NULL, osh, wl->rpc_th);
825 if (wl->rpc == NULL) {
826 WL_ERROR(("wl%d: %s: bcm_rpc_attach failed!\n", unit,
827 __func__));
828 goto fail;
829 }
830
831 /* init tx work queue for wl_start/send pkt; no need to destroy workitem */
832 INIT_WORK(&wl->txq_task.work, (work_func_t) wl_start_txqwork);
833 wl->txq_task.context = wl;
834#endif /* WLC_HIGH_ONLY */
835 686
836#ifdef BCMSDIO
837 SET_IEEE80211_DEV(hw, sdiommc_dev);
838#endif
839 687
840 base_addr = regs; 688 base_addr = regs;
841 689
842 if (bustype == PCI_BUS) { 690 if (bustype == PCI_BUS) {
843 /* piomode can be overwritten by command argument */ 691 wl->piomode = false;
844 wl->piomode = piomode;
845 WL_TRACE(("PCI/%s\n", wl->piomode ? "PIO" : "DMA"));
846 } else if (bustype == RPC_BUS) { 692 } else if (bustype == RPC_BUS) {
847 /* Do nothing */ 693 /* Do nothing */
848 } else { 694 } else {
849 bustype = PCI_BUS; 695 bustype = PCI_BUS;
850 WL_TRACE(("force to PCI\n")); 696 WL_TRACE("force to PCI\n");
851 } 697 }
852 wl->bcm_bustype = bustype; 698 wl->bcm_bustype = bustype;
853 699
854#ifdef WLC_HIGH_ONLY
855 if (wl->bcm_bustype == RPC_BUS) {
856 wl->regsva = (void *)0;
857 btparam = wl->rpc;
858 } else
859#endif
860 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ); 700 wl->regsva = ioremap_nocache(base_addr, PCI_BAR0_WINSZ);
861 if (wl->regsva == NULL) { 701 if (wl->regsva == NULL) {
862 WL_ERROR(("wl%d: ioremap() failed\n", unit)); 702 WL_ERROR("wl%d: ioremap() failed\n", unit);
863 goto fail; 703 goto fail;
864 } 704 }
865#ifdef WLC_HIGH_ONLY
866 spin_lock_init(&wl->rpcq_lock);
867 spin_lock_init(&wl->txq_lock);
868
869 sema_init(&wl->sem, 1);
870#else
871 spin_lock_init(&wl->lock); 705 spin_lock_init(&wl->lock);
872 spin_lock_init(&wl->isr_lock); 706 spin_lock_init(&wl->isr_lock);
873#endif
874 707
875#ifndef WLC_HIGH_ONLY
876 /* prepare ucode */ 708 /* prepare ucode */
877 if (wl_request_fw(wl, (struct pci_dev *)btparam)) { 709 if (wl_request_fw(wl, (struct pci_dev *)btparam)) {
878 printf("%s: Failed to find firmware usually in %s\n", 710 printf("%s: Failed to find firmware usually in %s\n",
@@ -881,17 +713,14 @@ static wl_info_t *wl_attach(u16 vendor, u16 device, unsigned long regs,
881 wl_remove((struct pci_dev *)btparam); 713 wl_remove((struct pci_dev *)btparam);
882 goto fail1; 714 goto fail1;
883 } 715 }
884#endif
885 716
886 /* common load-time initialization */ 717 /* common load-time initialization */
887 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh, 718 wl->wlc = wlc_attach((void *)wl, vendor, device, unit, wl->piomode, osh,
888 wl->regsva, wl->bcm_bustype, btparam, &err); 719 wl->regsva, wl->bcm_bustype, btparam, &err);
889#ifndef WLC_HIGH_ONLY
890 wl_release_fw(wl); 720 wl_release_fw(wl);
891#endif
892 if (!wl->wlc) { 721 if (!wl->wlc) {
893 printf("%s: %s wlc_attach() failed with code %d\n", 722 printf("%s: wlc_attach() failed with code %d\n",
894 KBUILD_MODNAME, EPI_VERSION_STR, err); 723 KBUILD_MODNAME, err);
895 goto fail; 724 goto fail;
896 } 725 }
897 wl->pub = wlc_pub(wl->wlc); 726 wl->pub = wlc_pub(wl->wlc);
@@ -900,52 +729,35 @@ static wl_info_t *wl_attach(u16 vendor, u16 device, unsigned long regs,
900 ASSERT(wl->pub->ieee_hw); 729 ASSERT(wl->pub->ieee_hw);
901 ASSERT(wl->pub->ieee_hw->priv == wl); 730 ASSERT(wl->pub->ieee_hw->priv == wl);
902 731
903#ifdef WLC_HIGH_ONLY 732
904 REGOPSSET(osh, (osl_rreg_fn_t) wlc_reg_read, 733 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
905 (osl_wreg_fn_t) wlc_reg_write, wl->wlc); 734 WL_ERROR("wl%d: Error setting MPC variable to 0\n", unit);
906 wl->rpc_dispatch_ctx.rpc = wl->rpc;
907 wl->rpc_dispatch_ctx.wlc = wl->wlc;
908 bcm_rpc_rxcb_init(wl->rpc, wl, wl_rpc_dispatch_schedule, wl,
909 wl_rpc_down, NULL, NULL);
910#endif /* WLC_HIGH_ONLY */
911
912 if (nompc) {
913 if (wlc_iovar_setint(wl->wlc, "mpc", 0)) {
914 WL_ERROR(("wl%d: Error setting MPC variable to 0\n",
915 unit));
916 }
917 } 735 }
918#ifdef BCMSDIO
919 /* Set SDIO drive strength */
920 wlc_iovar_setint(wl->wlc, "sd_drivestrength", sd_drivestrength);
921#endif
922 736
923#ifdef WLC_LOW
924 /* register our interrupt handler */ 737 /* register our interrupt handler */
925 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) { 738 if (request_irq(irq, wl_isr, IRQF_SHARED, KBUILD_MODNAME, wl)) {
926 WL_ERROR(("wl%d: request_irq() failed\n", unit)); 739 WL_ERROR("wl%d: request_irq() failed\n", unit);
927 goto fail; 740 goto fail;
928 } 741 }
929 wl->irq = irq; 742 wl->irq = irq;
930#endif /* WLC_LOW */
931 743
932 /* register module */ 744 /* register module */
933 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog, 745 wlc_module_register(wl->pub, NULL, "linux", wl, NULL, wl_linux_watchdog,
934 NULL); 746 NULL);
935 747
936 if (ieee_hw_init(hw)) { 748 if (ieee_hw_init(hw)) {
937 WL_ERROR(("wl%d: %s: ieee_hw_init failed!\n", unit, __func__)); 749 WL_ERROR("wl%d: %s: ieee_hw_init failed!\n", unit, __func__);
938 goto fail; 750 goto fail;
939 } 751 }
940 752
941 bcopy(&wl->pub->cur_etheraddr, perm, ETHER_ADDR_LEN); 753 bcopy(&wl->pub->cur_etheraddr, perm, ETH_ALEN);
942 ASSERT(is_valid_ether_addr(perm)); 754 ASSERT(is_valid_ether_addr(perm));
943 SET_IEEE80211_PERM_ADDR(hw, perm); 755 SET_IEEE80211_PERM_ADDR(hw, perm);
944 756
945 err = ieee80211_register_hw(hw); 757 err = ieee80211_register_hw(hw);
946 if (err) { 758 if (err) {
947 WL_ERROR(("%s: ieee80211_register_hw failed, status %d\n", 759 WL_ERROR("%s: ieee80211_register_hw failed, status %d\n",
948 __func__, err)); 760 __func__, err);
949 } 761 }
950 762
951 if (wl->pub->srom_ccode[0]) 763 if (wl->pub->srom_ccode[0])
@@ -953,19 +765,14 @@ static wl_info_t *wl_attach(u16 vendor, u16 device, unsigned long regs,
953 else 765 else
954 err = wl_set_hint(wl, "US"); 766 err = wl_set_hint(wl, "US");
955 if (err) { 767 if (err) {
956 WL_ERROR(("%s: regulatory_hint failed, status %d\n", __func__, 768 WL_ERROR("%s: regulatory_hint failed, status %d\n",
957 err)); 769 __func__, err);
958 } 770 }
959#ifndef WLC_HIGH_ONLY 771 WL_ERROR("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver (" PHY_VERSION_STR ")",
960 WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver " 772 unit);
961 EPI_VERSION_STR " (" PHY_VERSION_STR ")", unit));
962#else
963 WL_ERROR(("wl%d: Broadcom BCM43xx 802.11 MAC80211 Driver "
964 EPI_VERSION_STR, unit));
965#endif
966 773
967#ifdef BCMDBG 774#ifdef BCMDBG
968 printf(" (Compiled in " SRCBASE " at " __TIME__ " on " __DATE__ ")"); 775 printf(" (Compiled at " __TIME__ " on " __DATE__ ")");
969#endif /* BCMDBG */ 776#endif /* BCMDBG */
970 printf("\n"); 777 printf("\n");
971 778
@@ -978,54 +785,6 @@ fail1:
978 return NULL; 785 return NULL;
979} 786}
980 787
981#ifdef WLC_HIGH_ONLY
982static void *wl_dbus_probe_cb(void *arg, const char *desc, u32 bustype,
983 u32 hdrlen)
984{
985 wl_info_t *wl;
986 WL_ERROR(("%s:\n", __func__));
987
988 wl = wl_attach(BCM_DNGL_VID, BCM_DNGL_BDC_PID, (unsigned long) NULL, RPC_BUS,
989 NULL, 0);
990 if (!wl) {
991 WL_ERROR(("%s: wl_attach failed\n", __func__));
992 }
993
994 /* This is later passed to wl_dbus_disconnect_cb */
995 return wl;
996}
997
998static void wl_dbus_disconnect_cb(void *arg)
999{
1000 wl_info_t *wl = arg;
1001
1002 WL_ERROR(("%s:\n", __func__));
1003
1004 if (wl) {
1005#ifdef WLC_HIGH_ONLY
1006 if (wl->pub->ieee_hw) {
1007 ieee80211_unregister_hw(wl->pub->ieee_hw);
1008 WL_ERROR(("%s: Back from down\n", __func__));
1009 }
1010 wlc_device_removed(wl->wlc);
1011 wlc_bmac_dngl_reboot(wl->rpc);
1012 bcm_rpc_down(wl->rpc);
1013#endif
1014 WL_LOCK(wl);
1015 wl_down(wl);
1016 WL_UNLOCK(wl);
1017#ifdef WLC_HIGH_ONLY
1018 if (wl->pub->ieee_hw) {
1019 ieee80211_free_hw(wl->pub->ieee_hw);
1020 WL_ERROR(("%s: Back from ieee80211_free_hw\n",
1021 __func__));
1022 wl->pub->ieee_hw = NULL;
1023 }
1024#endif
1025 wl_free(wl);
1026 }
1027}
1028#endif /* WLC_HIGH_ONLY */
1029 788
1030 789
1031#define CHAN2GHZ(channel, freqency, chflags) { \ 790#define CHAN2GHZ(channel, freqency, chflags) { \
@@ -1163,29 +922,13 @@ static struct ieee80211_supported_band wl_band_2GHz_nphy = {
1163 .cap = IEEE80211_HT_CAP_GRN_FLD | 922 .cap = IEEE80211_HT_CAP_GRN_FLD |
1164 IEEE80211_HT_CAP_SGI_20 | 923 IEEE80211_HT_CAP_SGI_20 |
1165 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT, 924 IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_40MHZ_INTOLERANT,
1166#ifdef WLC_HIGH_ONLY
1167 .ht_supported = true,
1168 .ampdu_factor = AMPDU_RX_FACTOR_16K,
1169#else
1170 .ht_supported = true, 925 .ht_supported = true,
1171 .ampdu_factor = AMPDU_RX_FACTOR_64K, 926 .ampdu_factor = AMPDU_RX_FACTOR_64K,
1172#endif
1173 .ampdu_density = AMPDU_DEF_MPDU_DENSITY, 927 .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
1174 .mcs = { 928 .mcs = {
1175 /* placeholders for now */ 929 /* placeholders for now */
1176#ifdef WLC_HIGH_ONLY
1177 /*
1178 * rx_mask[0] = 0xff by default
1179 * rx_mask[1] = 0xff if number of rx chain >=2
1180 * rx_mask[2] = 0xff if number of rx chain >=3
1181 * rx_mask[4] = 1 if 40Mhz is supported
1182 */
1183 .rx_mask = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0},
1184 .rx_highest = 72, /* max rate of single stream */
1185#else
1186 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0}, 930 .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
1187 .rx_highest = 500, 931 .rx_highest = 500,
1188#endif
1189 .tx_params = IEEE80211_HT_MCS_TX_DEFINED} 932 .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
1190 } 933 }
1191}; 934};
@@ -1212,7 +955,7 @@ static struct ieee80211_supported_band wl_band_5GHz_nphy = {
1212 955
1213static int ieee_hw_rate_init(struct ieee80211_hw *hw) 956static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1214{ 957{
1215 wl_info_t *wl = HW_TO_WL(hw); 958 struct wl_info *wl = HW_TO_WL(hw);
1216 int has_5g; 959 int has_5g;
1217 char phy_list[4]; 960 char phy_list[4];
1218 961
@@ -1222,20 +965,16 @@ static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1222 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL; 965 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
1223 966
1224 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) { 967 if (wlc_get(wl->wlc, WLC_GET_PHYLIST, (int *)&phy_list) < 0) {
1225 WL_ERROR(("Phy list failed\n")); 968 WL_ERROR("Phy list failed\n");
1226 } 969 }
1227 WL_NONE(("%s: phylist = %c\n", __func__, phy_list[0])); 970 WL_NONE("%s: phylist = %c\n", __func__, phy_list[0]);
1228 971
1229#ifndef WLC_HIGH_ONLY
1230 if (phy_list[0] == 'n' || phy_list[0] == 'c') { 972 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1231 if (phy_list[0] == 'c') { 973 if (phy_list[0] == 'c') {
1232 /* Single stream */ 974 /* Single stream */
1233 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0; 975 wl_band_2GHz_nphy.ht_cap.mcs.rx_mask[1] = 0;
1234 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72; 976 wl_band_2GHz_nphy.ht_cap.mcs.rx_highest = 72;
1235 } 977 }
1236#else
1237 if (phy_list[0] == 's') {
1238#endif
1239 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy; 978 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl_band_2GHz_nphy;
1240 } else { 979 } else {
1241 BUG(); 980 BUG();
@@ -1245,11 +984,7 @@ static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1245 /* Assume all bands use the same phy. True for 11n devices. */ 984 /* Assume all bands use the same phy. True for 11n devices. */
1246 if (NBANDS_PUB(wl->pub) > 1) { 985 if (NBANDS_PUB(wl->pub) > 1) {
1247 has_5g++; 986 has_5g++;
1248#ifndef WLC_HIGH_ONLY
1249 if (phy_list[0] == 'n' || phy_list[0] == 'c') { 987 if (phy_list[0] == 'n' || phy_list[0] == 'c') {
1250#else
1251 if (phy_list[0] == 's') {
1252#endif
1253 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = 988 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1254 &wl_band_5GHz_nphy; 989 &wl_band_5GHz_nphy;
1255 } else { 990 } else {
@@ -1257,7 +992,7 @@ static int ieee_hw_rate_init(struct ieee80211_hw *hw)
1257 } 992 }
1258 } 993 }
1259 994
1260 WL_NONE(("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g)); 995 WL_NONE("%s: 2ghz = %d, 5ghz = %d\n", __func__, 1, has_5g);
1261 996
1262 return 0; 997 return 0;
1263} 998}
@@ -1288,7 +1023,6 @@ static int ieee_hw_init(struct ieee80211_hw *hw)
1288 return ieee_hw_rate_init(hw); 1023 return ieee_hw_rate_init(hw);
1289} 1024}
1290 1025
1291#ifndef BCMSDIO
1292/** 1026/**
1293 * determines if a device is a WL device, and if so, attaches it. 1027 * determines if a device is a WL device, and if so, attaches it.
1294 * 1028 *
@@ -1300,15 +1034,15 @@ int __devinit
1300wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 1034wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1301{ 1035{
1302 int rc; 1036 int rc;
1303 wl_info_t *wl; 1037 struct wl_info *wl;
1304 struct ieee80211_hw *hw; 1038 struct ieee80211_hw *hw;
1305 u32 val; 1039 u32 val;
1306 1040
1307 ASSERT(pdev); 1041 ASSERT(pdev);
1308 1042
1309 WL_TRACE(("%s: bus %d slot %d func %d irq %d\n", __func__, 1043 WL_TRACE("%s: bus %d slot %d func %d irq %d\n",
1310 pdev->bus->number, PCI_SLOT(pdev->devfn), 1044 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1311 PCI_FUNC(pdev->devfn), pdev->irq)); 1045 PCI_FUNC(pdev->devfn), pdev->irq);
1312 1046
1313 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) || 1047 if ((pdev->vendor != PCI_VENDOR_ID_BROADCOM) ||
1314 (((pdev->device & 0xff00) != 0x4300) && 1048 (((pdev->device & 0xff00) != 0x4300) &&
@@ -1318,9 +1052,9 @@ wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1318 1052
1319 rc = pci_enable_device(pdev); 1053 rc = pci_enable_device(pdev);
1320 if (rc) { 1054 if (rc) {
1321 WL_ERROR(("%s: Cannot enable device %d-%d_%d\n", __func__, 1055 WL_ERROR("%s: Cannot enable device %d-%d_%d\n",
1322 pdev->bus->number, PCI_SLOT(pdev->devfn), 1056 __func__, pdev->bus->number, PCI_SLOT(pdev->devfn),
1323 PCI_FUNC(pdev->devfn))); 1057 PCI_FUNC(pdev->devfn));
1324 return -ENODEV; 1058 return -ENODEV;
1325 } 1059 }
1326 pci_set_master(pdev); 1060 pci_set_master(pdev);
@@ -1329,9 +1063,9 @@ wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1329 if ((val & 0x0000ff00) != 0) 1063 if ((val & 0x0000ff00) != 0)
1330 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); 1064 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1331 1065
1332 hw = ieee80211_alloc_hw(sizeof(wl_info_t), &wl_ops); 1066 hw = ieee80211_alloc_hw(sizeof(struct wl_info), &wl_ops);
1333 if (!hw) { 1067 if (!hw) {
1334 WL_ERROR(("%s: ieee80211_alloc_hw failed\n", __func__)); 1068 WL_ERROR("%s: ieee80211_alloc_hw failed\n", __func__);
1335 rc = -ENOMEM; 1069 rc = -ENOMEM;
1336 goto err_1; 1070 goto err_1;
1337 } 1071 }
@@ -1340,34 +1074,34 @@ wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1340 1074
1341 pci_set_drvdata(pdev, hw); 1075 pci_set_drvdata(pdev, hw);
1342 1076
1343 bzero(hw->priv, sizeof(*wl)); 1077 memset(hw->priv, 0, sizeof(*wl));
1344 1078
1345 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0), 1079 wl = wl_attach(pdev->vendor, pdev->device, pci_resource_start(pdev, 0),
1346 PCI_BUS, pdev, pdev->irq); 1080 PCI_BUS, pdev, pdev->irq);
1347 1081
1348 if (!wl) { 1082 if (!wl) {
1349 WL_ERROR(("%s: %s: wl_attach failed!\n", 1083 WL_ERROR("%s: %s: wl_attach failed!\n",
1350 KBUILD_MODNAME, __func__)); 1084 KBUILD_MODNAME, __func__);
1351 return -ENODEV; 1085 return -ENODEV;
1352 } 1086 }
1353 return 0; 1087 return 0;
1354 err_1: 1088 err_1:
1355 WL_ERROR(("%s: err_1: Major hoarkage\n", __func__)); 1089 WL_ERROR("%s: err_1: Major hoarkage\n", __func__);
1356 return 0; 1090 return 0;
1357} 1091}
1358 1092
1359#ifdef LINUXSTA_PS 1093#ifdef LINUXSTA_PS
1360static int wl_suspend(struct pci_dev *pdev, pm_message_t state) 1094static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1361{ 1095{
1362 wl_info_t *wl; 1096 struct wl_info *wl;
1363 struct ieee80211_hw *hw; 1097 struct ieee80211_hw *hw;
1364 1098
1365 WL_TRACE(("wl: wl_suspend\n")); 1099 WL_TRACE("wl: wl_suspend\n");
1366 1100
1367 hw = pci_get_drvdata(pdev); 1101 hw = pci_get_drvdata(pdev);
1368 wl = HW_TO_WL(hw); 1102 wl = HW_TO_WL(hw);
1369 if (!wl) { 1103 if (!wl) {
1370 WL_ERROR(("wl: wl_suspend: pci_get_drvdata failed\n")); 1104 WL_ERROR("wl: wl_suspend: pci_get_drvdata failed\n");
1371 return -ENODEV; 1105 return -ENODEV;
1372 } 1106 }
1373 1107
@@ -1382,16 +1116,16 @@ static int wl_suspend(struct pci_dev *pdev, pm_message_t state)
1382 1116
1383static int wl_resume(struct pci_dev *pdev) 1117static int wl_resume(struct pci_dev *pdev)
1384{ 1118{
1385 wl_info_t *wl; 1119 struct wl_info *wl;
1386 struct ieee80211_hw *hw; 1120 struct ieee80211_hw *hw;
1387 int err = 0; 1121 int err = 0;
1388 u32 val; 1122 u32 val;
1389 1123
1390 WL_TRACE(("wl: wl_resume\n")); 1124 WL_TRACE("wl: wl_resume\n");
1391 hw = pci_get_drvdata(pdev); 1125 hw = pci_get_drvdata(pdev);
1392 wl = HW_TO_WL(hw); 1126 wl = HW_TO_WL(hw);
1393 if (!wl) { 1127 if (!wl) {
1394 WL_ERROR(("wl: wl_resume: pci_get_drvdata failed\n")); 1128 WL_ERROR("wl: wl_resume: pci_get_drvdata failed\n");
1395 return -ENODEV; 1129 return -ENODEV;
1396 } 1130 }
1397 1131
@@ -1421,17 +1155,17 @@ static int wl_resume(struct pci_dev *pdev)
1421 1155
1422static void wl_remove(struct pci_dev *pdev) 1156static void wl_remove(struct pci_dev *pdev)
1423{ 1157{
1424 wl_info_t *wl; 1158 struct wl_info *wl;
1425 struct ieee80211_hw *hw; 1159 struct ieee80211_hw *hw;
1426 1160
1427 hw = pci_get_drvdata(pdev); 1161 hw = pci_get_drvdata(pdev);
1428 wl = HW_TO_WL(hw); 1162 wl = HW_TO_WL(hw);
1429 if (!wl) { 1163 if (!wl) {
1430 WL_ERROR(("wl: wl_remove: pci_get_drvdata failed\n")); 1164 WL_ERROR("wl: wl_remove: pci_get_drvdata failed\n");
1431 return; 1165 return;
1432 } 1166 }
1433 if (!wlc_chipmatch(pdev->vendor, pdev->device)) { 1167 if (!wlc_chipmatch(pdev->vendor, pdev->device)) {
1434 WL_ERROR(("wl: wl_remove: wlc_chipmatch failed\n")); 1168 WL_ERROR("wl: wl_remove: wlc_chipmatch failed\n");
1435 return; 1169 return;
1436 } 1170 }
1437 if (wl->wlc) { 1171 if (wl->wlc) {
@@ -1439,7 +1173,7 @@ static void wl_remove(struct pci_dev *pdev)
1439 WL_LOCK(wl); 1173 WL_LOCK(wl);
1440 wl_down(wl); 1174 wl_down(wl);
1441 WL_UNLOCK(wl); 1175 WL_UNLOCK(wl);
1442 WL_NONE(("%s: Down\n", __func__)); 1176 WL_NONE("%s: Down\n", __func__);
1443 } 1177 }
1444 pci_disable_device(pdev); 1178 pci_disable_device(pdev);
1445 1179
@@ -1459,7 +1193,6 @@ static struct pci_driver wl_pci_driver = {
1459 .remove = __devexit_p(wl_remove), 1193 .remove = __devexit_p(wl_remove),
1460 .id_table = wl_id_table, 1194 .id_table = wl_id_table,
1461}; 1195};
1462#endif /* !BCMSDIO */
1463 1196
1464/** 1197/**
1465 * This is the main entry point for the WL driver. 1198 * This is the main entry point for the WL driver.
@@ -1480,7 +1213,6 @@ static int __init wl_module_init(void)
1480 if (var) 1213 if (var)
1481 wl_msg_level = simple_strtoul(var, NULL, 0); 1214 wl_msg_level = simple_strtoul(var, NULL, 0);
1482 } 1215 }
1483#ifndef WLC_HIGH_ONLY
1484 { 1216 {
1485 extern u32 phyhal_msg_level; 1217 extern u32 phyhal_msg_level;
1486 1218
@@ -1492,25 +1224,13 @@ static int __init wl_module_init(void)
1492 phyhal_msg_level = simple_strtoul(var, NULL, 0); 1224 phyhal_msg_level = simple_strtoul(var, NULL, 0);
1493 } 1225 }
1494 } 1226 }
1495#endif /* WLC_HIGH_ONLY */
1496#endif /* BCMDBG */ 1227#endif /* BCMDBG */
1497 1228
1498#ifndef BCMSDIO
1499 error = pci_register_driver(&wl_pci_driver); 1229 error = pci_register_driver(&wl_pci_driver);
1500 if (!error) 1230 if (!error)
1501 return 0; 1231 return 0;
1502 1232
1503#endif /* !BCMSDIO */
1504 1233
1505#ifdef WLC_HIGH_ONLY
1506 /* BMAC_NOTE: define hardcode number, why NODEVICE is ok ? */
1507 error =
1508 dbus_register(BCM_DNGL_VID, 0, wl_dbus_probe_cb,
1509 wl_dbus_disconnect_cb, NULL, NULL, NULL);
1510 if (error == DBUS_ERR_NODEVICE) {
1511 error = DBUS_OK;
1512 }
1513#endif /* WLC_HIGH_ONLY */
1514 1234
1515 return error; 1235 return error;
1516} 1236}
@@ -1524,13 +1244,8 @@ static int __init wl_module_init(void)
1524 */ 1244 */
1525static void __exit wl_module_exit(void) 1245static void __exit wl_module_exit(void)
1526{ 1246{
1527#ifndef BCMSDIO
1528 pci_unregister_driver(&wl_pci_driver); 1247 pci_unregister_driver(&wl_pci_driver);
1529#endif /* !BCMSDIO */
1530 1248
1531#ifdef WLC_HIGH_ONLY
1532 dbus_deregister();
1533#endif /* WLC_HIGH_ONLY */
1534} 1249}
1535 1250
1536module_init(wl_module_init); 1251module_init(wl_module_init);
@@ -1543,19 +1258,17 @@ module_exit(wl_module_exit);
1543 * by the wl parameter. 1258 * by the wl parameter.
1544 * 1259 *
1545 */ 1260 */
1546void wl_free(wl_info_t *wl) 1261void wl_free(struct wl_info *wl)
1547{ 1262{
1548 wl_timer_t *t, *next; 1263 wl_timer_t *t, *next;
1549 osl_t *osh; 1264 struct osl_info *osh;
1550 1265
1551 ASSERT(wl); 1266 ASSERT(wl);
1552#ifndef WLC_HIGH_ONLY
1553 /* free ucode data */ 1267 /* free ucode data */
1554 if (wl->fw.fw_cnt) 1268 if (wl->fw.fw_cnt)
1555 wl_ucode_data_free(); 1269 wl_ucode_data_free();
1556 if (wl->irq) 1270 if (wl->irq)
1557 free_irq(wl->irq, wl); 1271 free_irq(wl->irq, wl);
1558#endif
1559 1272
1560 /* kill dpc */ 1273 /* kill dpc */
1561 tasklet_kill(&wl->tasklet); 1274 tasklet_kill(&wl->tasklet);
@@ -1593,103 +1306,50 @@ void wl_free(wl_info_t *wl)
1593 * unregister_netdev() calls get_stats() which may read chip registers 1306 * unregister_netdev() calls get_stats() which may read chip registers
1594 * so we cannot unmap the chip registers until after calling unregister_netdev() . 1307 * so we cannot unmap the chip registers until after calling unregister_netdev() .
1595 */ 1308 */
1596 if (wl->regsva && BUSTYPE(wl->bcm_bustype) != SDIO_BUS && 1309 if (wl->regsva && wl->bcm_bustype != SDIO_BUS &&
1597 BUSTYPE(wl->bcm_bustype) != JTAG_BUS) { 1310 wl->bcm_bustype != JTAG_BUS) {
1598 iounmap((void *)wl->regsva); 1311 iounmap((void *)wl->regsva);
1599 } 1312 }
1600 wl->regsva = NULL; 1313 wl->regsva = NULL;
1601 1314
1602#ifdef WLC_HIGH_ONLY
1603 wl_rpcq_free(wl);
1604
1605 wl_txq_free(wl);
1606
1607 if (wl->rpc) {
1608 bcm_rpc_detach(wl->rpc);
1609 wl->rpc = NULL;
1610 }
1611
1612 if (wl->rpc_th) {
1613 bcm_rpc_tp_detach(wl->rpc_th);
1614 wl->rpc_th = NULL;
1615 }
1616#endif /* WLC_HIGH_ONLY */
1617 1315
1618 osl_detach(osh); 1316 osl_detach(osh);
1619} 1317}
1620 1318
1621#ifdef WLC_LOW
1622/* transmit a packet */ 1319/* transmit a packet */
1623static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl) 1320static int BCMFASTPATH wl_start(struct sk_buff *skb, struct wl_info *wl)
1624{ 1321{
1625 if (!wl) 1322 if (!wl)
1626 return -ENETDOWN; 1323 return -ENETDOWN;
1627 1324
1628 return wl_start_int(wl, WL_TO_HW(wl), skb); 1325 return wl_start_int(wl, WL_TO_HW(wl), skb);
1629} 1326}
1630#endif /* WLC_LOW */
1631 1327
1632static int BCMFASTPATH 1328static int BCMFASTPATH
1633wl_start_int(wl_info_t *wl, struct ieee80211_hw *hw, struct sk_buff *skb) 1329wl_start_int(struct wl_info *wl, struct ieee80211_hw *hw, struct sk_buff *skb)
1634{ 1330{
1635#ifdef WLC_HIGH_ONLY
1636 WL_LOCK(wl);
1637#endif
1638 wlc_sendpkt_mac80211(wl->wlc, skb, hw); 1331 wlc_sendpkt_mac80211(wl->wlc, skb, hw);
1639#ifdef WLC_HIGH_ONLY
1640 WL_UNLOCK(wl);
1641#endif
1642 return NETDEV_TX_OK; 1332 return NETDEV_TX_OK;
1643} 1333}
1644 1334
1645void wl_txflowcontrol(wl_info_t *wl, struct wl_if *wlif, bool state, int prio) 1335void wl_txflowcontrol(struct wl_info *wl, struct wl_if *wlif, bool state,
1336 int prio)
1646{ 1337{
1647 WL_ERROR(("Shouldn't be here %s\n", __func__)); 1338 WL_ERROR("Shouldn't be here %s\n", __func__);
1648} 1339}
1649 1340
1650#if defined(WLC_HIGH_ONLY) 1341void wl_init(struct wl_info *wl)
1651/* Schedule a completion handler to run at safe time */
1652static int
1653wl_schedule_task(wl_info_t *wl, void (*fn) (struct wl_task *task),
1654 void *context)
1655{ 1342{
1656 wl_task_t *task; 1343 WL_TRACE("wl%d: wl_init\n", wl->pub->unit);
1657
1658 WL_TRACE(("wl%d: wl_schedule_task\n", wl->pub->unit));
1659
1660 task = kmalloc(sizeof(wl_task_t), GFP_ATOMIC);
1661 if (!task) {
1662 WL_ERROR(("wl%d: wl_schedule_task: out of memory\n", wl->pub->unit));
1663 return -ENOMEM;
1664 }
1665
1666 INIT_WORK(&task->work, (work_func_t) fn);
1667 task->context = context;
1668
1669 if (!schedule_work(&task->work)) {
1670 WL_ERROR(("wl%d: schedule_work() failed\n", wl->pub->unit));
1671 kfree(task);
1672 return -ENOMEM;
1673 }
1674
1675 atomic_inc(&wl->callbacks);
1676
1677 return 0;
1678}
1679#endif /* defined(WLC_HIGH_ONLY) */
1680
1681void wl_init(wl_info_t *wl)
1682{
1683 WL_TRACE(("wl%d: wl_init\n", wl->pub->unit));
1684 1344
1685 wl_reset(wl); 1345 wl_reset(wl);
1686 1346
1687 wlc_init(wl->wlc); 1347 wlc_init(wl->wlc);
1688} 1348}
1689 1349
1690uint wl_reset(wl_info_t *wl) 1350uint wl_reset(struct wl_info *wl)
1691{ 1351{
1692 WL_TRACE(("wl%d: wl_reset\n", wl->pub->unit)); 1352 WL_TRACE("wl%d: wl_reset\n", wl->pub->unit);
1693 1353
1694 wlc_reset(wl->wlc); 1354 wlc_reset(wl->wlc);
1695 1355
@@ -1703,25 +1363,22 @@ uint wl_reset(wl_info_t *wl)
1703 * These are interrupt on/off entry points. Disable interrupts 1363 * These are interrupt on/off entry points. Disable interrupts
1704 * during interrupt state transition. 1364 * during interrupt state transition.
1705 */ 1365 */
1706void BCMFASTPATH wl_intrson(wl_info_t *wl) 1366void BCMFASTPATH wl_intrson(struct wl_info *wl)
1707{ 1367{
1708#if defined(WLC_LOW)
1709 unsigned long flags; 1368 unsigned long flags;
1710 1369
1711 INT_LOCK(wl, flags); 1370 INT_LOCK(wl, flags);
1712 wlc_intrson(wl->wlc); 1371 wlc_intrson(wl->wlc);
1713 INT_UNLOCK(wl, flags); 1372 INT_UNLOCK(wl, flags);
1714#endif /* WLC_LOW */
1715} 1373}
1716 1374
1717bool wl_alloc_dma_resources(wl_info_t *wl, uint addrwidth) 1375bool wl_alloc_dma_resources(struct wl_info *wl, uint addrwidth)
1718{ 1376{
1719 return true; 1377 return true;
1720} 1378}
1721 1379
1722u32 BCMFASTPATH wl_intrsoff(wl_info_t *wl) 1380u32 BCMFASTPATH wl_intrsoff(struct wl_info *wl)
1723{ 1381{
1724#if defined(WLC_LOW)
1725 unsigned long flags; 1382 unsigned long flags;
1726 u32 status; 1383 u32 status;
1727 1384
@@ -1729,23 +1386,18 @@ u32 BCMFASTPATH wl_intrsoff(wl_info_t *wl)
1729 status = wlc_intrsoff(wl->wlc); 1386 status = wlc_intrsoff(wl->wlc);
1730 INT_UNLOCK(wl, flags); 1387 INT_UNLOCK(wl, flags);
1731 return status; 1388 return status;
1732#else
1733 return 0;
1734#endif /* WLC_LOW */
1735} 1389}
1736 1390
1737void wl_intrsrestore(wl_info_t *wl, u32 macintmask) 1391void wl_intrsrestore(struct wl_info *wl, u32 macintmask)
1738{ 1392{
1739#if defined(WLC_LOW)
1740 unsigned long flags; 1393 unsigned long flags;
1741 1394
1742 INT_LOCK(wl, flags); 1395 INT_LOCK(wl, flags);
1743 wlc_intrsrestore(wl->wlc, macintmask); 1396 wlc_intrsrestore(wl->wlc, macintmask);
1744 INT_UNLOCK(wl, flags); 1397 INT_UNLOCK(wl, flags);
1745#endif /* WLC_LOW */
1746} 1398}
1747 1399
1748int wl_up(wl_info_t *wl) 1400int wl_up(struct wl_info *wl)
1749{ 1401{
1750 int error = 0; 1402 int error = 0;
1751 1403
@@ -1757,7 +1409,7 @@ int wl_up(wl_info_t *wl)
1757 return error; 1409 return error;
1758} 1410}
1759 1411
1760void wl_down(wl_info_t *wl) 1412void wl_down(struct wl_info *wl)
1761{ 1413{
1762 uint callbacks, ret_val = 0; 1414 uint callbacks, ret_val = 0;
1763 1415
@@ -1768,24 +1420,21 @@ void wl_down(wl_info_t *wl)
1768 /* wait for down callbacks to complete */ 1420 /* wait for down callbacks to complete */
1769 WL_UNLOCK(wl); 1421 WL_UNLOCK(wl);
1770 1422
1771#ifndef WLC_HIGH_ONLY
1772 /* For HIGH_only driver, it's important to actually schedule other work, 1423 /* For HIGH_only driver, it's important to actually schedule other work,
1773 * not just spin wait since everything runs at schedule level 1424 * not just spin wait since everything runs at schedule level
1774 */ 1425 */
1775 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000); 1426 SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
1776#endif /* WLC_HIGH_ONLY */
1777 1427
1778 WL_LOCK(wl); 1428 WL_LOCK(wl);
1779} 1429}
1780 1430
1781irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id) 1431irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1782{ 1432{
1783#if defined(WLC_LOW) 1433 struct wl_info *wl;
1784 wl_info_t *wl;
1785 bool ours, wantdpc; 1434 bool ours, wantdpc;
1786 unsigned long flags; 1435 unsigned long flags;
1787 1436
1788 wl = (wl_info_t *) dev_id; 1437 wl = (struct wl_info *) dev_id;
1789 1438
1790 WL_ISRLOCK(wl, flags); 1439 WL_ISRLOCK(wl, flags);
1791 1440
@@ -1805,17 +1454,13 @@ irqreturn_t BCMFASTPATH wl_isr(int irq, void *dev_id)
1805 WL_ISRUNLOCK(wl, flags); 1454 WL_ISRUNLOCK(wl, flags);
1806 1455
1807 return IRQ_RETVAL(ours); 1456 return IRQ_RETVAL(ours);
1808#else
1809 return IRQ_RETVAL(0);
1810#endif /* WLC_LOW */
1811} 1457}
1812 1458
1813static void BCMFASTPATH wl_dpc(unsigned long data) 1459static void BCMFASTPATH wl_dpc(unsigned long data)
1814{ 1460{
1815#ifdef WLC_LOW 1461 struct wl_info *wl;
1816 wl_info_t *wl;
1817 1462
1818 wl = (wl_info_t *) data; 1463 wl = (struct wl_info *) data;
1819 1464
1820 WL_LOCK(wl); 1465 WL_LOCK(wl);
1821 1466
@@ -1846,20 +1491,19 @@ static void BCMFASTPATH wl_dpc(unsigned long data)
1846 1491
1847 done: 1492 done:
1848 WL_UNLOCK(wl); 1493 WL_UNLOCK(wl);
1849#endif /* WLC_LOW */
1850} 1494}
1851 1495
1852static void wl_link_up(wl_info_t *wl, char *ifname) 1496static void wl_link_up(struct wl_info *wl, char *ifname)
1853{ 1497{
1854 WL_ERROR(("wl%d: link up (%s)\n", wl->pub->unit, ifname)); 1498 WL_ERROR("wl%d: link up (%s)\n", wl->pub->unit, ifname);
1855} 1499}
1856 1500
1857static void wl_link_down(wl_info_t *wl, char *ifname) 1501static void wl_link_down(struct wl_info *wl, char *ifname)
1858{ 1502{
1859 WL_ERROR(("wl%d: link down (%s)\n", wl->pub->unit, ifname)); 1503 WL_ERROR("wl%d: link down (%s)\n", wl->pub->unit, ifname);
1860} 1504}
1861 1505
1862void wl_event(wl_info_t *wl, char *ifname, wlc_event_t *e) 1506void wl_event(struct wl_info *wl, char *ifname, wlc_event_t *e)
1863{ 1507{
1864 1508
1865 switch (e->event.event_type) { 1509 switch (e->event.event_type) {
@@ -1877,12 +1521,7 @@ void wl_event(wl_info_t *wl, char *ifname, wlc_event_t *e)
1877 1521
1878static void wl_timer(unsigned long data) 1522static void wl_timer(unsigned long data)
1879{ 1523{
1880#ifndef WLC_HIGH_ONLY
1881 _wl_timer((wl_timer_t *) data); 1524 _wl_timer((wl_timer_t *) data);
1882#else
1883 wl_timer_t *t = (wl_timer_t *) data;
1884 wl_schedule_task(t->wl, wl_timer_task, t);
1885#endif /* WLC_HIGH_ONLY */
1886} 1525}
1887 1526
1888static void _wl_timer(wl_timer_t *t) 1527static void _wl_timer(wl_timer_t *t)
@@ -1906,18 +1545,18 @@ static void _wl_timer(wl_timer_t *t)
1906 WL_UNLOCK(t->wl); 1545 WL_UNLOCK(t->wl);
1907} 1546}
1908 1547
1909wl_timer_t *wl_init_timer(wl_info_t *wl, void (*fn) (void *arg), void *arg, 1548wl_timer_t *wl_init_timer(struct wl_info *wl, void (*fn) (void *arg), void *arg,
1910 const char *name) 1549 const char *name)
1911{ 1550{
1912 wl_timer_t *t; 1551 wl_timer_t *t;
1913 1552
1914 t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC); 1553 t = kmalloc(sizeof(wl_timer_t), GFP_ATOMIC);
1915 if (!t) { 1554 if (!t) {
1916 WL_ERROR(("wl%d: wl_init_timer: out of memory\n", wl->pub->unit)); 1555 WL_ERROR("wl%d: wl_init_timer: out of memory\n", wl->pub->unit);
1917 return 0; 1556 return 0;
1918 } 1557 }
1919 1558
1920 bzero(t, sizeof(wl_timer_t)); 1559 memset(t, 0, sizeof(wl_timer_t));
1921 1560
1922 init_timer(&t->timer); 1561 init_timer(&t->timer);
1923 t->timer.data = (unsigned long) t; 1562 t->timer.data = (unsigned long) t;
@@ -1940,12 +1579,12 @@ wl_timer_t *wl_init_timer(wl_info_t *wl, void (*fn) (void *arg), void *arg,
1940/* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate 1579/* BMAC_NOTE: Add timer adds only the kernel timer since it's going to be more accurate
1941 * as well as it's easier to make it periodic 1580 * as well as it's easier to make it periodic
1942 */ 1581 */
1943void wl_add_timer(wl_info_t *wl, wl_timer_t *t, uint ms, int periodic) 1582void wl_add_timer(struct wl_info *wl, wl_timer_t *t, uint ms, int periodic)
1944{ 1583{
1945#ifdef BCMDBG 1584#ifdef BCMDBG
1946 if (t->set) { 1585 if (t->set) {
1947 WL_ERROR(("%s: Already set. Name: %s, per %d\n", 1586 WL_ERROR("%s: Already set. Name: %s, per %d\n",
1948 __func__, t->name, periodic)); 1587 __func__, t->name, periodic);
1949 } 1588 }
1950#endif 1589#endif
1951 ASSERT(!t->set); 1590 ASSERT(!t->set);
@@ -1960,7 +1599,7 @@ void wl_add_timer(wl_info_t *wl, wl_timer_t *t, uint ms, int periodic)
1960} 1599}
1961 1600
1962/* return true if timer successfully deleted, false if still pending */ 1601/* return true if timer successfully deleted, false if still pending */
1963bool wl_del_timer(wl_info_t *wl, wl_timer_t *t) 1602bool wl_del_timer(struct wl_info *wl, wl_timer_t *t)
1964{ 1603{
1965 if (t->set) { 1604 if (t->set) {
1966 t->set = false; 1605 t->set = false;
@@ -1973,7 +1612,7 @@ bool wl_del_timer(wl_info_t *wl, wl_timer_t *t)
1973 return true; 1612 return true;
1974} 1613}
1975 1614
1976void wl_free_timer(wl_info_t *wl, wl_timer_t *t) 1615void wl_free_timer(struct wl_info *wl, wl_timer_t *t)
1977{ 1616{
1978 wl_timer_t *tmp; 1617 wl_timer_t *tmp;
1979 1618
@@ -2009,7 +1648,7 @@ void wl_free_timer(wl_info_t *wl, wl_timer_t *t)
2009 1648
2010static int wl_linux_watchdog(void *ctx) 1649static int wl_linux_watchdog(void *ctx)
2011{ 1650{
2012 wl_info_t *wl = (wl_info_t *) ctx; 1651 struct wl_info *wl = (struct wl_info *) ctx;
2013 struct net_device_stats *stats = NULL; 1652 struct net_device_stats *stats = NULL;
2014 uint id; 1653 uint id;
2015 /* refresh stats */ 1654 /* refresh stats */
@@ -2049,233 +1688,12 @@ struct wl_fw_hdr {
2049 u32 idx; 1688 u32 idx;
2050}; 1689};
2051 1690
2052#ifdef WLC_HIGH_ONLY
2053static void wl_rpc_down(void *wlh)
2054{
2055 wl_info_t *wl = (wl_info_t *) (wlh);
2056
2057 wlc_device_removed(wl->wlc);
2058
2059 wl_rpcq_free(wl);
2060}
2061
2062static int BCMFASTPATH wl_start(struct sk_buff *skb, wl_info_t *wl)
2063{
2064
2065 unsigned long flags;
2066
2067 skb->prev = NULL;
2068
2069 /* Lock the queue as tasklet could be running at this time */
2070 TXQ_LOCK(wl, flags);
2071 if (wl->txq_head == NULL)
2072 wl->txq_head = skb;
2073 else {
2074 wl->txq_tail->prev = skb;
2075 }
2076 wl->txq_tail = skb;
2077
2078 if (wl->txq_dispatched == false) {
2079 wl->txq_dispatched = true;
2080
2081 if (schedule_work(&wl->txq_task.work)) {
2082 atomic_inc(&wl->callbacks);
2083 } else {
2084 WL_ERROR(("wl%d: wl_start/schedule_work failed\n",
2085 wl->pub->unit));
2086 }
2087 }
2088
2089 TXQ_UNLOCK(wl, flags);
2090
2091 return 0;
2092
2093}
2094
2095static void wl_start_txqwork(struct wl_task *task)
2096{
2097 wl_info_t *wl = (wl_info_t *) task->context;
2098 struct sk_buff *skb;
2099 unsigned long flags;
2100 uint count = 0;
2101
2102 WL_TRACE(("wl%d: wl_start_txqwork\n", wl->pub->unit));
2103
2104 /* First remove an entry then go for execution */
2105 TXQ_LOCK(wl, flags);
2106 while (wl->txq_head) {
2107 skb = wl->txq_head;
2108 wl->txq_head = skb->prev;
2109 skb->prev = NULL;
2110 if (wl->txq_head == NULL)
2111 wl->txq_tail = NULL;
2112 TXQ_UNLOCK(wl, flags);
2113
2114 /* it has WL_LOCK/WL_UNLOCK inside */
2115 wl_start_int(wl, WL_TO_HW(wl), skb);
2116
2117 /* bounded our execution, reshedule ourself next */
2118 if (++count >= 10)
2119 break;
2120
2121 TXQ_LOCK(wl, flags);
2122 }
2123
2124 if (count >= 10) {
2125 if (!schedule_work(&wl->txq_task.work)) {
2126 WL_ERROR(("wl%d: wl_start/schedule_work failed\n",
2127 wl->pub->unit));
2128 atomic_dec(&wl->callbacks);
2129 }
2130 } else {
2131 wl->txq_dispatched = false;
2132 TXQ_UNLOCK(wl, flags);
2133 atomic_dec(&wl->callbacks);
2134 }
2135
2136 return;
2137}
2138
2139static void wl_txq_free(wl_info_t *wl)
2140{
2141 struct sk_buff *skb;
2142
2143 if (wl->txq_head == NULL) {
2144 ASSERT(wl->txq_tail == NULL);
2145 return;
2146 }
2147
2148 while (wl->txq_head) {
2149 skb = wl->txq_head;
2150 wl->txq_head = skb->prev;
2151 PKTFREE(wl->osh, skb, true);
2152 }
2153
2154 wl->txq_tail = NULL;
2155}
2156
2157static void wl_rpcq_free(wl_info_t *wl)
2158{
2159 rpc_buf_t *buf;
2160
2161 if (wl->rpcq_head == NULL) {
2162 ASSERT(wl->rpcq_tail == NULL);
2163 return;
2164 }
2165
2166 while (wl->rpcq_head) {
2167 buf = wl->rpcq_head;
2168 wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf);
2169 bcm_rpc_buf_free(wl->rpc_dispatch_ctx.rpc, buf);
2170 }
2171
2172 wl->rpcq_tail = NULL;
2173}
2174
2175static void wl_rpcq_dispatch(struct wl_task *task)
2176{
2177 wl_info_t *wl = (wl_info_t *) task->context;
2178 rpc_buf_t *buf;
2179 unsigned long flags;
2180
2181 /* First remove an entry then go for execution */
2182 RPCQ_LOCK(wl, flags);
2183 while (wl->rpcq_head) {
2184 buf = wl->rpcq_head;
2185 wl->rpcq_head = bcm_rpc_buf_next_get(wl->rpc_th, buf);
2186
2187 if (wl->rpcq_head == NULL)
2188 wl->rpcq_tail = NULL;
2189 RPCQ_UNLOCK(wl, flags);
2190
2191 WL_LOCK(wl);
2192 wlc_rpc_high_dispatch(&wl->rpc_dispatch_ctx, buf);
2193 WL_UNLOCK(wl);
2194
2195 RPCQ_LOCK(wl, flags);
2196 }
2197
2198 wl->rpcq_dispatched = false;
2199
2200 RPCQ_UNLOCK(wl, flags);
2201
2202 kfree(task);
2203 atomic_dec(&wl->callbacks);
2204}
2205
2206static void wl_rpcq_add(wl_info_t *wl, rpc_buf_t *buf)
2207{
2208 unsigned long flags;
2209
2210 bcm_rpc_buf_next_set(wl->rpc_th, buf, NULL);
2211
2212 /* Lock the queue as tasklet could be running at this time */
2213 RPCQ_LOCK(wl, flags);
2214 if (wl->rpcq_head == NULL)
2215 wl->rpcq_head = buf;
2216 else
2217 bcm_rpc_buf_next_set(wl->rpc_th, wl->rpcq_tail, buf);
2218
2219 wl->rpcq_tail = buf;
2220
2221 if (wl->rpcq_dispatched == false) {
2222 wl->rpcq_dispatched = true;
2223 wl_schedule_task(wl, wl_rpcq_dispatch, wl);
2224 }
2225
2226 RPCQ_UNLOCK(wl, flags);
2227}
2228
2229#if defined(BCMDBG)
2230static const struct name_entry rpc_name_tbl[] = RPC_ID_TABLE;
2231#endif /* BCMDBG */
2232
2233/* dongle-side rpc dispatch routine */
2234static void wl_rpc_dispatch_schedule(void *ctx, struct rpc_buf *buf)
2235{
2236 bcm_xdr_buf_t b;
2237 wl_info_t *wl = (wl_info_t *) ctx;
2238 wlc_rpc_id_t rpc_id;
2239 int err;
2240
2241 bcm_xdr_buf_init(&b, bcm_rpc_buf_data(wl->rpc_th, buf),
2242 bcm_rpc_buf_len_get(wl->rpc_th, buf));
2243
2244 err = bcm_xdr_unpack_u32(&b, &rpc_id);
2245 ASSERT(!err);
2246 WL_TRACE(("%s: Dispatch id %s\n", __func__,
2247 WLC_RPC_ID_LOOKUP(rpc_name_tbl, rpc_id)));
2248
2249 /* Handle few emergency ones */
2250 switch (rpc_id) {
2251 default:
2252 wl_rpcq_add(wl, buf);
2253 break;
2254 }
2255}
2256
2257static void wl_timer_task(wl_task_t *task)
2258{
2259 wl_timer_t *t = (wl_timer_t *) task->context;
2260
2261 _wl_timer(t);
2262 kfree(task);
2263
2264 /* This dec is for the task_schedule. The timer related
2265 * callback is decremented in _wl_timer
2266 */
2267 atomic_dec(&t->wl->callbacks);
2268}
2269#endif /* WLC_HIGH_ONLY */
2270
2271#ifndef WLC_HIGH_ONLY
2272char *wl_firmwares[WL_MAX_FW] = { 1691char *wl_firmwares[WL_MAX_FW] = {
2273 "brcm/bcm43xx", 1692 "brcm/bcm43xx",
2274 NULL 1693 NULL
2275}; 1694};
2276 1695
2277#ifdef WLC_LOW 1696int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, u32 idx)
2278int wl_ucode_init_buf(wl_info_t *wl, void **pbuf, u32 idx)
2279{ 1697{
2280 int i, entry; 1698 int i, entry;
2281 const u8 *pdata; 1699 const u8 *pdata;
@@ -2301,7 +1719,7 @@ int wl_ucode_init_buf(wl_info_t *wl, void **pbuf, u32 idx)
2301 return -1; 1719 return -1;
2302} 1720}
2303 1721
2304int wl_ucode_init_uint(wl_info_t *wl, u32 *data, u32 idx) 1722int wl_ucode_init_uint(struct wl_info *wl, u32 *data, u32 idx)
2305{ 1723{
2306 int i, entry; 1724 int i, entry;
2307 const u8 *pdata; 1725 const u8 *pdata;
@@ -2321,22 +1739,21 @@ int wl_ucode_init_uint(wl_info_t *wl, u32 *data, u32 idx)
2321 printf("ERROR: ucode tag:%d can not be found!\n", idx); 1739 printf("ERROR: ucode tag:%d can not be found!\n", idx);
2322 return -1; 1740 return -1;
2323} 1741}
2324#endif /* WLC_LOW */
2325 1742
2326static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev) 1743static int wl_request_fw(struct wl_info *wl, struct pci_dev *pdev)
2327{ 1744{
2328 int status; 1745 int status;
2329 struct device *device = &pdev->dev; 1746 struct device *device = &pdev->dev;
2330 char fw_name[100]; 1747 char fw_name[100];
2331 int i; 1748 int i;
2332 1749
2333 bzero((void *)&wl->fw, sizeof(struct wl_firmware)); 1750 memset((void *)&wl->fw, 0, sizeof(struct wl_firmware));
2334 for (i = 0; i < WL_MAX_FW; i++) { 1751 for (i = 0; i < WL_MAX_FW; i++) {
2335 if (wl_firmwares[i] == NULL) 1752 if (wl_firmwares[i] == NULL)
2336 break; 1753 break;
2337 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i], 1754 sprintf(fw_name, "%s-%d.fw", wl_firmwares[i],
2338 UCODE_LOADER_API_VER); 1755 UCODE_LOADER_API_VER);
2339 WL_NONE(("request fw %s\n", fw_name)); 1756 WL_NONE("request fw %s\n", fw_name);
2340 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device); 1757 status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
2341 if (status) { 1758 if (status) {
2342 printf("%s: fail to load firmware %s\n", 1759 printf("%s: fail to load firmware %s\n",
@@ -2344,7 +1761,7 @@ static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev)
2344 wl_release_fw(wl); 1761 wl_release_fw(wl);
2345 return status; 1762 return status;
2346 } 1763 }
2347 WL_NONE(("request fw %s\n", fw_name)); 1764 WL_NONE("request fw %s\n", fw_name);
2348 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i], 1765 sprintf(fw_name, "%s_hdr-%d.fw", wl_firmwares[i],
2349 UCODE_LOADER_API_VER); 1766 UCODE_LOADER_API_VER);
2350 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device); 1767 status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
@@ -2356,22 +1773,19 @@ static int wl_request_fw(wl_info_t *wl, struct pci_dev *pdev)
2356 } 1773 }
2357 wl->fw.hdr_num_entries[i] = 1774 wl->fw.hdr_num_entries[i] =
2358 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr)); 1775 wl->fw.fw_hdr[i]->size / (sizeof(struct wl_fw_hdr));
2359 WL_NONE(("request fw %s find: %d entries\n", fw_name, 1776 WL_NONE("request fw %s find: %d entries\n",
2360 wl->fw.hdr_num_entries[i])); 1777 fw_name, wl->fw.hdr_num_entries[i]);
2361 } 1778 }
2362 wl->fw.fw_cnt = i; 1779 wl->fw.fw_cnt = i;
2363 wl_ucode_data_init(wl); 1780 return wl_ucode_data_init(wl);
2364 return 0;
2365} 1781}
2366 1782
2367#ifdef WLC_LOW
2368void wl_ucode_free_buf(void *p) 1783void wl_ucode_free_buf(void *p)
2369{ 1784{
2370 kfree(p); 1785 kfree(p);
2371} 1786}
2372#endif /* WLC_LOW */
2373 1787
2374static void wl_release_fw(wl_info_t *wl) 1788static void wl_release_fw(struct wl_info *wl)
2375{ 1789{
2376 int i; 1790 int i;
2377 for (i = 0; i < WL_MAX_FW; i++) { 1791 for (i = 0; i < WL_MAX_FW; i++) {
@@ -2379,4 +1793,54 @@ static void wl_release_fw(wl_info_t *wl)
2379 release_firmware(wl->fw.fw_hdr[i]); 1793 release_firmware(wl->fw.fw_hdr[i]);
2380 } 1794 }
2381} 1795}
2382#endif /* WLC_HIGH_ONLY */ 1796
1797
1798/*
1799 * checks validity of all firmware images loaded from user space
1800 */
1801int wl_check_firmwares(struct wl_info *wl)
1802{
1803 int i;
1804 int entry;
1805 int rc = 0;
1806 const struct firmware *fw;
1807 const struct firmware *fw_hdr;
1808 struct wl_fw_hdr *ucode_hdr;
1809 for (i = 0; i < WL_MAX_FW && rc == 0; i++) {
1810 fw = wl->fw.fw_bin[i];
1811 fw_hdr = wl->fw.fw_hdr[i];
1812 if (fw == NULL && fw_hdr == NULL) {
1813 break;
1814 } else if (fw == NULL || fw_hdr == NULL) {
1815 WL_ERROR("%s: invalid bin/hdr fw\n", __func__);
1816 rc = -EBADF;
1817 } else if (fw_hdr->size % sizeof(struct wl_fw_hdr)) {
1818 WL_ERROR("%s: non integral fw hdr file size %d/%zu\n",
1819 __func__, fw_hdr->size,
1820 sizeof(struct wl_fw_hdr));
1821 rc = -EBADF;
1822 } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
1823 WL_ERROR("%s: out of bounds fw file size %d\n",
1824 __func__, fw->size);
1825 rc = -EBADF;
1826 } else {
1827 /* check if ucode section overruns firmware image */
1828 ucode_hdr = (struct wl_fw_hdr *)fw_hdr->data;
1829 for (entry = 0; entry < wl->fw.hdr_num_entries[i] && rc;
1830 entry++, ucode_hdr++) {
1831 if (ucode_hdr->offset + ucode_hdr->len >
1832 fw->size) {
1833 WL_ERROR("%s: conflicting bin/hdr\n",
1834 __func__);
1835 rc = -EBADF;
1836 }
1837 }
1838 }
1839 }
1840 if (rc == 0 && wl->fw.fw_cnt != i) {
1841 WL_ERROR("%s: invalid fw_cnt=%d\n", __func__, wl->fw.fw_cnt);
1842 rc = -EBADF;
1843 }
1844 return rc;
1845}
1846
diff --git a/drivers/staging/brcm80211/sys/wl_mac80211.h b/drivers/staging/brcm80211/sys/wl_mac80211.h
index 78cee4454b0b..bb39b7705947 100644
--- a/drivers/staging/brcm80211/sys/wl_mac80211.h
+++ b/drivers/staging/brcm80211/sys/wl_mac80211.h
@@ -60,58 +60,32 @@ struct wl_firmware {
60}; 60};
61 61
62struct wl_info { 62struct wl_info {
63 wlc_pub_t *pub; /* pointer to public wlc state */ 63 struct wlc_pub *pub; /* pointer to public wlc state */
64 void *wlc; /* pointer to private common os-independent data */ 64 void *wlc; /* pointer to private common os-independent data */
65 osl_t *osh; /* pointer to os handler */ 65 struct osl_info *osh; /* pointer to os handler */
66 u32 magic; 66 u32 magic;
67 67
68 int irq; 68 int irq;
69 69
70#ifdef WLC_HIGH_ONLY
71 struct semaphore sem; /* use semaphore to allow sleep */
72#else
73 spinlock_t lock; /* per-device perimeter lock */ 70 spinlock_t lock; /* per-device perimeter lock */
74 spinlock_t isr_lock; /* per-device ISR synchronization lock */ 71 spinlock_t isr_lock; /* per-device ISR synchronization lock */
75#endif
76 uint bcm_bustype; /* bus type */ 72 uint bcm_bustype; /* bus type */
77 bool piomode; /* set from insmod argument */ 73 bool piomode; /* set from insmod argument */
78 void *regsva; /* opaque chip registers virtual address */ 74 void *regsva; /* opaque chip registers virtual address */
79 atomic_t callbacks; /* # outstanding callback functions */ 75 atomic_t callbacks; /* # outstanding callback functions */
80 struct wl_timer *timers; /* timer cleanup queue */ 76 struct wl_timer *timers; /* timer cleanup queue */
81 struct tasklet_struct tasklet; /* dpc tasklet */ 77 struct tasklet_struct tasklet; /* dpc tasklet */
82#ifdef BCMSDIO
83 bcmsdh_info_t *sdh; /* pointer to sdio bus handler */
84 unsigned long flags; /* current irq flags */
85#endif /* BCMSDIO */
86 bool resched; /* dpc needs to be and is rescheduled */ 78 bool resched; /* dpc needs to be and is rescheduled */
87#ifdef LINUXSTA_PS 79#ifdef LINUXSTA_PS
88 u32 pci_psstate[16]; /* pci ps-state save/restore */ 80 u32 pci_psstate[16]; /* pci ps-state save/restore */
89#endif 81#endif
90 /* RPC, handle, lock, txq, workitem */ 82 /* RPC, handle, lock, txq, workitem */
91#ifdef WLC_HIGH_ONLY
92 rpc_info_t *rpc; /* RPC handle */
93 rpc_tp_info_t *rpc_th; /* RPC transport handle */
94 wlc_rpc_ctx_t rpc_dispatch_ctx;
95
96 bool rpcq_dispatched; /* Avoid scheduling multiple tasks */
97 spinlock_t rpcq_lock; /* Lock for the queue */
98 rpc_buf_t *rpcq_head; /* RPC Q */
99 rpc_buf_t *rpcq_tail; /* Points to the last buf */
100
101 bool txq_dispatched; /* Avoid scheduling multiple tasks */
102 spinlock_t txq_lock; /* Lock for the queue */
103 struct sk_buff *txq_head; /* TX Q */
104 struct sk_buff *txq_tail; /* Points to the last buf */
105
106 wl_task_t txq_task; /* work queue for wl_start() */
107#endif /* WLC_HIGH_ONLY */
108 uint stats_id; /* the current set of stats */ 83 uint stats_id; /* the current set of stats */
109 /* ping-pong stats counters updated by Linux watchdog */ 84 /* ping-pong stats counters updated by Linux watchdog */
110 struct net_device_stats stats_watchdog[2]; 85 struct net_device_stats stats_watchdog[2];
111 struct wl_firmware fw; 86 struct wl_firmware fw;
112}; 87};
113 88
114#ifndef WLC_HIGH_ONLY
115#define WL_LOCK(wl) spin_lock_bh(&(wl)->lock) 89#define WL_LOCK(wl) spin_lock_bh(&(wl)->lock)
116#define WL_UNLOCK(wl) spin_unlock_bh(&(wl)->lock) 90#define WL_UNLOCK(wl) spin_unlock_bh(&(wl)->lock)
117 91
@@ -122,17 +96,6 @@ struct wl_info {
122/* locking under WL_LOCK() to synchronize with wl_isr */ 96/* locking under WL_LOCK() to synchronize with wl_isr */
123#define INT_LOCK(wl, flags) spin_lock_irqsave(&(wl)->isr_lock, flags) 97#define INT_LOCK(wl, flags) spin_lock_irqsave(&(wl)->isr_lock, flags)
124#define INT_UNLOCK(wl, flags) spin_unlock_irqrestore(&(wl)->isr_lock, flags) 98#define INT_UNLOCK(wl, flags) spin_unlock_irqrestore(&(wl)->isr_lock, flags)
125#else /* BCMSDIO */
126
127#define WL_LOCK(wl) down(&(wl)->sem)
128#define WL_UNLOCK(wl) up(&(wl)->sem)
129
130#define WL_ISRLOCK(wl)
131#define WL_ISRUNLOCK(wl)
132#endif /* WLC_HIGH_ONLY */
133
134/* handle forward declaration */
135typedef struct wl_info wl_info_t;
136 99
137#ifndef PCI_D0 100#ifndef PCI_D0
138#define PCI_D0 0 101#define PCI_D0 0
@@ -148,14 +111,7 @@ extern irqreturn_t wl_isr(int irq, void *dev_id);
148 111
149extern int __devinit wl_pci_probe(struct pci_dev *pdev, 112extern int __devinit wl_pci_probe(struct pci_dev *pdev,
150 const struct pci_device_id *ent); 113 const struct pci_device_id *ent);
151extern void wl_free(wl_info_t *wl); 114extern void wl_free(struct wl_info *wl);
152extern int wl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd); 115extern int wl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
153extern int wl_ucode_data_init(wl_info_t *wl);
154extern void wl_ucode_data_free(void);
155#ifdef WLC_LOW
156extern void wl_ucode_free_buf(void *);
157extern int wl_ucode_init_buf(wl_info_t *wl, void **pbuf, u32 idx);
158extern int wl_ucode_init_uint(wl_info_t *wl, u32 *data, u32 idx);
159#endif /* WLC_LOW */
160 116
161#endif /* _wl_mac80211_h_ */ 117#endif /* _wl_mac80211_h_ */
diff --git a/drivers/staging/brcm80211/sys/wl_ucode.h b/drivers/staging/brcm80211/sys/wl_ucode.h
index a1ba37209f96..2a0f4028f6f3 100644
--- a/drivers/staging/brcm80211/sys/wl_ucode.h
+++ b/drivers/staging/brcm80211/sys/wl_ucode.h
@@ -14,6 +14,9 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#define MIN_FW_SIZE 40000 /* minimum firmware file size in bytes */
18#define MAX_FW_SIZE 150000
19
17typedef struct d11init { 20typedef struct d11init {
18 u16 addr; 21 u16 addr;
19 u16 size; 22 u16 size;
@@ -35,3 +38,12 @@ extern u32 *bcm43xx_24_lcn;
35extern u32 bcm43xx_24_lcnsz; 38extern u32 bcm43xx_24_lcnsz;
36extern u32 *bcm43xx_bommajor; 39extern u32 *bcm43xx_bommajor;
37extern u32 *bcm43xx_bomminor; 40extern u32 *bcm43xx_bomminor;
41
42extern int wl_ucode_data_init(struct wl_info *wl);
43extern void wl_ucode_data_free(void);
44
45extern int wl_ucode_init_buf(struct wl_info *wl, void **pbuf, unsigned int idx);
46extern int wl_ucode_init_uint(struct wl_info *wl, unsigned *data,
47 unsigned int idx);
48extern void wl_ucode_free_buf(void *);
49extern int wl_check_firmwares(struct wl_info *wl);
diff --git a/drivers/staging/brcm80211/sys/wl_ucode_loader.c b/drivers/staging/brcm80211/sys/wl_ucode_loader.c
index 0b41a9cb1ec9..23e10f3dec0d 100644
--- a/drivers/staging/brcm80211/sys/wl_ucode_loader.c
+++ b/drivers/staging/brcm80211/sys/wl_ucode_loader.c
@@ -14,17 +14,12 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17typedef struct wl_info wl_info_t;
18#include <linux/types.h> 17#include <linux/types.h>
19#include <bcmdefs.h> 18#include <bcmdefs.h>
20#include <d11ucode_ext.h> 19#include <d11ucode_ext.h>
21#include <wl_ucode.h> 20#include <wl_ucode.h>
22 21
23extern int wl_ucode_init_buf(wl_info_t *wl, void **pbuf, unsigned int idx); 22
24extern int wl_ucode_init_uint(wl_info_t *wl, unsigned *data, unsigned int idx);
25extern int wl_ucode_data_init(wl_info_t *wl);
26extern void wl_ucode_data_free(void);
27extern void wl_ucode_free_buf(void *);
28 23
29d11init_t *d11lcn0bsinitvals24; 24d11init_t *d11lcn0bsinitvals24;
30d11init_t *d11lcn0initvals24; 25d11init_t *d11lcn0initvals24;
@@ -42,8 +37,12 @@ u32 bcm43xx_24_lcnsz;
42u32 *bcm43xx_bommajor; 37u32 *bcm43xx_bommajor;
43u32 *bcm43xx_bomminor; 38u32 *bcm43xx_bomminor;
44 39
45int wl_ucode_data_init(wl_info_t *wl) 40int wl_ucode_data_init(struct wl_info *wl)
46{ 41{
42 int rc;
43 rc = wl_check_firmwares(wl);
44 if (rc < 0)
45 return rc;
47 wl_ucode_init_buf(wl, (void **)&d11lcn0bsinitvals24, 46 wl_ucode_init_buf(wl, (void **)&d11lcn0bsinitvals24,
48 D11LCN0BSINITVALS24); 47 D11LCN0BSINITVALS24);
49 wl_ucode_init_buf(wl, (void **)&d11lcn0initvals24, D11LCN0INITVALS24); 48 wl_ucode_init_buf(wl, (void **)&d11lcn0initvals24, D11LCN0INITVALS24);
diff --git a/drivers/staging/brcm80211/sys/wlc_alloc.c b/drivers/staging/brcm80211/sys/wlc_alloc.c
index 2dc89f9c2635..746439e8fd57 100644
--- a/drivers/staging/brcm80211/sys/wlc_alloc.c
+++ b/drivers/staging/brcm80211/sys/wlc_alloc.c
@@ -17,28 +17,33 @@
17#include <linux/string.h> 17#include <linux/string.h>
18#include <bcmdefs.h> 18#include <bcmdefs.h>
19#include <wlc_cfg.h> 19#include <wlc_cfg.h>
20#include <linuxver.h> 20#include <linux/module.h>
21#include <linux/pci.h>
21#include <osl.h> 22#include <osl.h>
22#include <bcmutils.h> 23#include <bcmutils.h>
23#include <siutils.h> 24#include <siutils.h>
24#include <wlioctl.h> 25#include <wlioctl.h>
25#include <wlc_pub.h> 26#include <wlc_pub.h>
26#include <wlc_key.h> 27#include <wlc_key.h>
28#include <sbhndpio.h>
29#include <sbhnddma.h>
30#include <wlc_event.h>
27#include <wlc_mac80211.h> 31#include <wlc_mac80211.h>
28#include <wlc_alloc.h> 32#include <wlc_alloc.h>
33#include <wl_dbg.h>
29 34
30static wlc_pub_t *wlc_pub_malloc(osl_t *osh, uint unit, uint *err, 35static struct wlc_pub *wlc_pub_malloc(struct osl_info *osh, uint unit,
31 uint devid); 36 uint *err, uint devid);
32static void wlc_pub_mfree(osl_t *osh, wlc_pub_t *pub); 37static void wlc_pub_mfree(struct osl_info *osh, struct wlc_pub *pub);
33static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid); 38static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid);
34 39
35void *wlc_calloc(osl_t *osh, uint unit, uint size) 40void *wlc_calloc(struct osl_info *osh, uint unit, uint size)
36{ 41{
37 void *item; 42 void *item;
38 43
39 item = kzalloc(size, GFP_ATOMIC); 44 item = kzalloc(size, GFP_ATOMIC);
40 if (item == NULL) 45 if (item == NULL)
41 WL_ERROR(("wl%d: %s: out of memory\n", unit, __func__)); 46 WL_ERROR("wl%d: %s: out of memory\n", unit, __func__);
42 return item; 47 return item;
43} 48}
44 49
@@ -58,18 +63,14 @@ void wlc_tunables_init(wlc_tunables_t *tunables, uint devid)
58 tunables->ampdudatahiwat = WLC_AMPDUDATAHIWAT; 63 tunables->ampdudatahiwat = WLC_AMPDUDATAHIWAT;
59 tunables->rxbnd = RXBND; 64 tunables->rxbnd = RXBND;
60 tunables->txsbnd = TXSBND; 65 tunables->txsbnd = TXSBND;
61#if defined(WLC_HIGH_ONLY) && defined(NTXD_USB_4319)
62 if (devid == BCM4319_CHIP_ID) {
63 tunables->ntxd = NTXD_USB_4319;
64 }
65#endif /* WLC_HIGH_ONLY */
66} 66}
67 67
68static wlc_pub_t *wlc_pub_malloc(osl_t *osh, uint unit, uint *err, uint devid) 68static struct wlc_pub *wlc_pub_malloc(struct osl_info *osh, uint unit,
69 uint *err, uint devid)
69{ 70{
70 wlc_pub_t *pub; 71 struct wlc_pub *pub;
71 72
72 pub = (wlc_pub_t *) wlc_calloc(osh, unit, sizeof(wlc_pub_t)); 73 pub = (struct wlc_pub *) wlc_calloc(osh, unit, sizeof(struct wlc_pub));
73 if (pub == NULL) { 74 if (pub == NULL) {
74 *err = 1001; 75 *err = 1001;
75 goto fail; 76 goto fail;
@@ -99,7 +100,7 @@ static wlc_pub_t *wlc_pub_malloc(osl_t *osh, uint unit, uint *err, uint devid)
99 return NULL; 100 return NULL;
100} 101}
101 102
102static void wlc_pub_mfree(osl_t *osh, wlc_pub_t *pub) 103static void wlc_pub_mfree(struct osl_info *osh, struct wlc_pub *pub)
103{ 104{
104 if (pub == NULL) 105 if (pub == NULL)
105 return; 106 return;
@@ -114,7 +115,7 @@ static void wlc_pub_mfree(osl_t *osh, wlc_pub_t *pub)
114 kfree(pub); 115 kfree(pub);
115} 116}
116 117
117wlc_bsscfg_t *wlc_bsscfg_malloc(osl_t *osh, uint unit) 118wlc_bsscfg_t *wlc_bsscfg_malloc(struct osl_info *osh, uint unit)
118{ 119{
119 wlc_bsscfg_t *cfg; 120 wlc_bsscfg_t *cfg;
120 121
@@ -134,7 +135,7 @@ wlc_bsscfg_t *wlc_bsscfg_malloc(osl_t *osh, uint unit)
134 return NULL; 135 return NULL;
135} 136}
136 137
137void wlc_bsscfg_mfree(osl_t *osh, wlc_bsscfg_t *cfg) 138void wlc_bsscfg_mfree(struct osl_info *osh, wlc_bsscfg_t *cfg)
138{ 139{
139 if (cfg == NULL) 140 if (cfg == NULL)
140 return; 141 return;
@@ -155,7 +156,7 @@ void wlc_bsscfg_mfree(osl_t *osh, wlc_bsscfg_t *cfg)
155 kfree(cfg); 156 kfree(cfg);
156} 157}
157 158
158void wlc_bsscfg_ID_assign(wlc_info_t *wlc, wlc_bsscfg_t *bsscfg) 159void wlc_bsscfg_ID_assign(struct wlc_info *wlc, wlc_bsscfg_t *bsscfg)
159{ 160{
160 bsscfg->ID = wlc->next_bsscfg_ID; 161 bsscfg->ID = wlc->next_bsscfg_ID;
161 wlc->next_bsscfg_ID++; 162 wlc->next_bsscfg_ID++;
@@ -164,11 +165,13 @@ void wlc_bsscfg_ID_assign(wlc_info_t *wlc, wlc_bsscfg_t *bsscfg)
164/* 165/*
165 * The common driver entry routine. Error codes should be unique 166 * The common driver entry routine. Error codes should be unique
166 */ 167 */
167wlc_info_t *wlc_attach_malloc(osl_t *osh, uint unit, uint *err, uint devid) 168struct wlc_info *wlc_attach_malloc(struct osl_info *osh, uint unit, uint *err,
169 uint devid)
168{ 170{
169 wlc_info_t *wlc; 171 struct wlc_info *wlc;
170 172
171 wlc = (wlc_info_t *) wlc_calloc(osh, unit, sizeof(wlc_info_t)); 173 wlc = (struct wlc_info *) wlc_calloc(osh, unit,
174 sizeof(struct wlc_info));
172 if (wlc == NULL) { 175 if (wlc == NULL) {
173 *err = 1002; 176 *err = 1002;
174 goto fail; 177 goto fail;
@@ -176,7 +179,7 @@ wlc_info_t *wlc_attach_malloc(osl_t *osh, uint unit, uint *err, uint devid)
176 179
177 wlc->hwrxoff = WL_HWRXOFF; 180 wlc->hwrxoff = WL_HWRXOFF;
178 181
179 /* allocate wlc_pub_t state structure */ 182 /* allocate struct wlc_pub state structure */
180 wlc->pub = wlc_pub_malloc(osh, unit, err, devid); 183 wlc->pub = wlc_pub_malloc(osh, unit, err, devid);
181 if (wlc->pub == NULL) { 184 if (wlc->pub == NULL) {
182 *err = 1003; 185 *err = 1003;
@@ -184,17 +187,16 @@ wlc_info_t *wlc_attach_malloc(osl_t *osh, uint unit, uint *err, uint devid)
184 } 187 }
185 wlc->pub->wlc = wlc; 188 wlc->pub->wlc = wlc;
186 189
187 /* allocate wlc_hw_info_t state structure */ 190 /* allocate struct wlc_hw_info state structure */
188 191
189 wlc->hw = (wlc_hw_info_t *)wlc_calloc(osh, unit, 192 wlc->hw = (struct wlc_hw_info *)wlc_calloc(osh, unit,
190 sizeof(wlc_hw_info_t)); 193 sizeof(struct wlc_hw_info));
191 if (wlc->hw == NULL) { 194 if (wlc->hw == NULL) {
192 *err = 1005; 195 *err = 1005;
193 goto fail; 196 goto fail;
194 } 197 }
195 wlc->hw->wlc = wlc; 198 wlc->hw->wlc = wlc;
196 199
197#ifdef WLC_LOW
198 wlc->hw->bandstate[0] = (wlc_hwband_t *)wlc_calloc(osh, unit, 200 wlc->hw->bandstate[0] = (wlc_hwband_t *)wlc_calloc(osh, unit,
199 (sizeof(wlc_hwband_t) * MAXBANDS)); 201 (sizeof(wlc_hwband_t) * MAXBANDS));
200 if (wlc->hw->bandstate[0] == NULL) { 202 if (wlc->hw->bandstate[0] == NULL) {
@@ -209,7 +211,6 @@ wlc_info_t *wlc_attach_malloc(osl_t *osh, uint unit, uint *err, uint devid)
209 (sizeof(wlc_hwband_t) * i)); 211 (sizeof(wlc_hwband_t) * i));
210 } 212 }
211 } 213 }
212#endif /* WLC_LOW */
213 214
214 wlc->modulecb = (modulecb_t *)wlc_calloc(osh, unit, 215 wlc->modulecb = (modulecb_t *)wlc_calloc(osh, unit,
215 sizeof(modulecb_t) * WLC_MAXMODULES); 216 sizeof(modulecb_t) * WLC_MAXMODULES);
@@ -266,8 +267,8 @@ wlc_info_t *wlc_attach_malloc(osl_t *osh, uint unit, uint *err, uint devid)
266 goto fail; 267 goto fail;
267 } 268 }
268 269
269 wlc->bandstate[0] = (wlcband_t *)wlc_calloc(osh, unit, 270 wlc->bandstate[0] = (struct wlcband *)wlc_calloc(osh, unit,
270 (sizeof(wlcband_t) * MAXBANDS)); 271 (sizeof(struct wlcband)*MAXBANDS));
271 if (wlc->bandstate[0] == NULL) { 272 if (wlc->bandstate[0] == NULL) {
272 *err = 1025; 273 *err = 1025;
273 goto fail; 274 goto fail;
@@ -276,12 +277,13 @@ wlc_info_t *wlc_attach_malloc(osl_t *osh, uint unit, uint *err, uint devid)
276 277
277 for (i = 1; i < MAXBANDS; i++) { 278 for (i = 1; i < MAXBANDS; i++) {
278 wlc->bandstate[i] = 279 wlc->bandstate[i] =
279 (wlcband_t *) ((unsigned long)wlc->bandstate[0] + 280 (struct wlcband *) ((unsigned long)wlc->bandstate[0]
280 (sizeof(wlcband_t) * i)); 281 + (sizeof(struct wlcband)*i));
281 } 282 }
282 } 283 }
283 284
284 wlc->corestate = (wlccore_t *)wlc_calloc(osh, unit, sizeof(wlccore_t)); 285 wlc->corestate = (struct wlccore *)wlc_calloc(osh, unit,
286 sizeof(struct wlccore));
285 if (wlc->corestate == NULL) { 287 if (wlc->corestate == NULL) {
286 *err = 1026; 288 *err = 1026;
287 goto fail; 289 goto fail;
@@ -301,7 +303,7 @@ wlc_info_t *wlc_attach_malloc(osl_t *osh, uint unit, uint *err, uint devid)
301 return NULL; 303 return NULL;
302} 304}
303 305
304void wlc_detach_mfree(wlc_info_t *wlc, osl_t *osh) 306void wlc_detach_mfree(struct wlc_info *wlc, struct osl_info *osh)
305{ 307{
306 if (wlc == NULL) 308 if (wlc == NULL)
307 return; 309 return;
@@ -355,12 +357,10 @@ void wlc_detach_mfree(wlc_info_t *wlc, osl_t *osh)
355 } 357 }
356 358
357 if (wlc->hw) { 359 if (wlc->hw) {
358#ifdef WLC_LOW
359 if (wlc->hw->bandstate[0]) { 360 if (wlc->hw->bandstate[0]) {
360 kfree(wlc->hw->bandstate[0]); 361 kfree(wlc->hw->bandstate[0]);
361 wlc->hw->bandstate[0] = NULL; 362 wlc->hw->bandstate[0] = NULL;
362 } 363 }
363#endif
364 364
365 /* free hw struct */ 365 /* free hw struct */
366 kfree(wlc->hw); 366 kfree(wlc->hw);
diff --git a/drivers/staging/brcm80211/sys/wlc_alloc.h b/drivers/staging/brcm80211/sys/wlc_alloc.h
index 678a2b9784f8..ac34f782b400 100644
--- a/drivers/staging/brcm80211/sys/wlc_alloc.h
+++ b/drivers/staging/brcm80211/sys/wlc_alloc.h
@@ -14,12 +14,12 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17extern void *wlc_calloc(osl_t *osh, uint unit, uint size); 17extern void *wlc_calloc(struct osl_info *osh, uint unit, uint size);
18 18
19extern wlc_info_t *wlc_attach_malloc(osl_t *osh, uint unit, uint *err, 19extern struct wlc_info *wlc_attach_malloc(struct osl_info *osh, uint unit,
20 uint devid); 20 uint *err, uint devid);
21extern void wlc_detach_mfree(wlc_info_t *wlc, osl_t *osh); 21extern void wlc_detach_mfree(struct wlc_info *wlc, struct osl_info *osh);
22 22
23struct wlc_bsscfg; 23struct wlc_bsscfg;
24extern struct wlc_bsscfg *wlc_bsscfg_malloc(osl_t *osh, uint unit); 24extern struct wlc_bsscfg *wlc_bsscfg_malloc(struct osl_info *osh, uint unit);
25extern void wlc_bsscfg_mfree(osl_t *osh, struct wlc_bsscfg *cfg); 25extern void wlc_bsscfg_mfree(struct osl_info *osh, struct wlc_bsscfg *cfg);
diff --git a/drivers/staging/brcm80211/sys/wlc_ampdu.c b/drivers/staging/brcm80211/sys/wlc_ampdu.c
index a4e49f3c1363..d749917f5912 100644
--- a/drivers/staging/brcm80211/sys/wlc_ampdu.c
+++ b/drivers/staging/brcm80211/sys/wlc_ampdu.c
@@ -16,19 +16,19 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <wlc_cfg.h> 17#include <wlc_cfg.h>
18#include <bcmdefs.h> 18#include <bcmdefs.h>
19#include <linuxver.h>
20#include <bcmdefs.h>
21#include <osl.h> 19#include <osl.h>
22#include <bcmutils.h> 20#include <bcmutils.h>
23#include <siutils.h> 21#include <siutils.h>
24#include <bcmendian.h> 22#include <bcmendian.h>
25#include <wlioctl.h> 23#include <wlioctl.h>
24#include <sbhndpio.h>
26#include <sbhnddma.h> 25#include <sbhnddma.h>
27#include <hnddma.h> 26#include <hnddma.h>
28#include <d11.h> 27#include <d11.h>
29#include <wlc_rate.h> 28#include <wlc_rate.h>
30#include <wlc_pub.h> 29#include <wlc_pub.h>
31#include <wlc_key.h> 30#include <wlc_key.h>
31#include <wlc_event.h>
32#include <wlc_mac80211.h> 32#include <wlc_mac80211.h>
33#include <wlc_phy_hal.h> 33#include <wlc_phy_hal.h>
34#include <wlc_antsel.h> 34#include <wlc_antsel.h>
@@ -36,11 +36,8 @@
36#include <net/mac80211.h> 36#include <net/mac80211.h>
37#include <wlc_ampdu.h> 37#include <wlc_ampdu.h>
38#include <wl_export.h> 38#include <wl_export.h>
39#include <wl_dbg.h>
39 40
40#ifdef WLC_HIGH_ONLY
41#include <bcm_rpc_tp.h>
42#include <wlc_rpctx.h>
43#endif
44 41
45#define AMPDU_MAX_MPDU 32 /* max number of mpdus in an ampdu */ 42#define AMPDU_MAX_MPDU 32 /* max number of mpdus in an ampdu */
46#define AMPDU_NUM_MPDU_LEGACY 16 /* max number of mpdus in an ampdu to a legacy */ 43#define AMPDU_NUM_MPDU_LEGACY 16 /* max number of mpdus in an ampdu to a legacy */
@@ -101,7 +98,7 @@ typedef struct wlc_fifo_info {
101 98
102/* AMPDU module specific state */ 99/* AMPDU module specific state */
103struct ampdu_info { 100struct ampdu_info {
104 wlc_info_t *wlc; /* pointer to main wlc structure */ 101 struct wlc_info *wlc; /* pointer to main wlc structure */
105 int scb_handle; /* scb cubby handle to retrieve data from scb */ 102 int scb_handle; /* scb cubby handle to retrieve data from scb */
106 u8 ini_enable[AMPDU_MAX_SCB_TID]; /* per-tid initiator enable/disable of ampdu */ 103 u8 ini_enable[AMPDU_MAX_SCB_TID]; /* per-tid initiator enable/disable of ampdu */
107 u8 ba_tx_wsize; /* Tx ba window size (in pdu) */ 104 u8 ba_tx_wsize; /* Tx ba window size (in pdu) */
@@ -125,11 +122,6 @@ struct ampdu_info {
125 */ 122 */
126 wlc_fifo_info_t fifo_tb[NUM_FFPLD_FIFO]; /* table of fifo infos */ 123 wlc_fifo_info_t fifo_tb[NUM_FFPLD_FIFO]; /* table of fifo infos */
127 124
128#ifdef WLC_HIGH_ONLY
129 void *p;
130 tx_status_t txs;
131 bool waiting_status; /* To help sanity checks */
132#endif
133}; 125};
134 126
135#define AMPDU_CLEANUPFLAG_RX (0x1) 127#define AMPDU_CLEANUPFLAG_RX (0x1)
@@ -138,38 +130,39 @@ struct ampdu_info {
138#define SCB_AMPDU_CUBBY(ampdu, scb) (&(scb->scb_ampdu)) 130#define SCB_AMPDU_CUBBY(ampdu, scb) (&(scb->scb_ampdu))
139#define SCB_AMPDU_INI(scb_ampdu, tid) (&(scb_ampdu->ini[tid])) 131#define SCB_AMPDU_INI(scb_ampdu, tid) (&(scb_ampdu->ini[tid]))
140 132
141static void wlc_ffpld_init(ampdu_info_t *ampdu); 133static void wlc_ffpld_init(struct ampdu_info *ampdu);
142static int wlc_ffpld_check_txfunfl(wlc_info_t *wlc, int f); 134static int wlc_ffpld_check_txfunfl(struct wlc_info *wlc, int f);
143static void wlc_ffpld_calc_mcs2ampdu_table(ampdu_info_t *ampdu, int f); 135static void wlc_ffpld_calc_mcs2ampdu_table(struct ampdu_info *ampdu, int f);
144 136
145static scb_ampdu_tid_ini_t *wlc_ampdu_init_tid_ini(ampdu_info_t *ampdu, 137static scb_ampdu_tid_ini_t *wlc_ampdu_init_tid_ini(struct ampdu_info *ampdu,
146 scb_ampdu_t *scb_ampdu, 138 scb_ampdu_t *scb_ampdu,
147 u8 tid, bool override); 139 u8 tid, bool override);
148static void ampdu_cleanup_tid_ini(ampdu_info_t *ampdu, scb_ampdu_t *scb_ampdu, 140static void ampdu_cleanup_tid_ini(struct ampdu_info *ampdu,
141 scb_ampdu_t *scb_ampdu,
149 u8 tid, bool force); 142 u8 tid, bool force);
150static void ampdu_update_max_txlen(ampdu_info_t *ampdu, u8 dur); 143static void ampdu_update_max_txlen(struct ampdu_info *ampdu, u8 dur);
151static void scb_ampdu_update_config(ampdu_info_t *ampdu, struct scb *scb); 144static void scb_ampdu_update_config(struct ampdu_info *ampdu, struct scb *scb);
152static void scb_ampdu_update_config_all(ampdu_info_t *ampdu); 145static void scb_ampdu_update_config_all(struct ampdu_info *ampdu);
153 146
154#define wlc_ampdu_txflowcontrol(a, b, c) do {} while (0) 147#define wlc_ampdu_txflowcontrol(a, b, c) do {} while (0)
155 148
156static void wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, 149static void wlc_ampdu_dotxstatus_complete(struct ampdu_info *ampdu,
157 void *p, tx_status_t *txs, 150 struct scb *scb,
158 u32 frmtxstatus, 151 struct sk_buff *p, tx_status_t *txs,
159 u32 frmtxstatus2); 152 u32 frmtxstatus, u32 frmtxstatus2);
160 153
161static inline u16 pkt_txh_seqnum(wlc_info_t *wlc, void *p) 154static inline u16 pkt_txh_seqnum(struct wlc_info *wlc, struct sk_buff *p)
162{ 155{
163 d11txh_t *txh; 156 d11txh_t *txh;
164 struct dot11_header *h; 157 struct dot11_header *h;
165 txh = (d11txh_t *) PKTDATA(p); 158 txh = (d11txh_t *) p->data;
166 h = (struct dot11_header *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN); 159 h = (struct dot11_header *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
167 return ltoh16(h->seq) >> SEQNUM_SHIFT; 160 return ltoh16(h->seq) >> SEQNUM_SHIFT;
168} 161}
169 162
170ampdu_info_t *wlc_ampdu_attach(wlc_info_t *wlc) 163struct ampdu_info *wlc_ampdu_attach(struct wlc_info *wlc)
171{ 164{
172 ampdu_info_t *ampdu; 165 struct ampdu_info *ampdu;
173 int i; 166 int i;
174 167
175 /* some code depends on packed structures */ 168 /* some code depends on packed structures */
@@ -179,9 +172,10 @@ ampdu_info_t *wlc_ampdu_attach(wlc_info_t *wlc)
179 ASSERT(wlc->pub->tunables->ampdunummpdu <= AMPDU_MAX_MPDU); 172 ASSERT(wlc->pub->tunables->ampdunummpdu <= AMPDU_MAX_MPDU);
180 ASSERT(wlc->pub->tunables->ampdunummpdu > 0); 173 ASSERT(wlc->pub->tunables->ampdunummpdu > 0);
181 174
182 ampdu = kzalloc(sizeof(ampdu_info_t), GFP_ATOMIC); 175 ampdu = kzalloc(sizeof(struct ampdu_info), GFP_ATOMIC);
183 if (!ampdu) { 176 if (!ampdu) {
184 WL_ERROR(("wl%d: wlc_ampdu_attach: out of mem\n", wlc->pub->unit)); 177 WL_ERROR("wl%d: wlc_ampdu_attach: out of mem\n",
178 wlc->pub->unit);
185 return NULL; 179 return NULL;
186 } 180 }
187 ampdu->wlc = wlc; 181 ampdu->wlc = wlc;
@@ -209,10 +203,6 @@ ampdu_info_t *wlc_ampdu_attach(wlc_info_t *wlc)
209 ampdu->rx_factor = AMPDU_RX_FACTOR_32K; 203 ampdu->rx_factor = AMPDU_RX_FACTOR_32K;
210 else 204 else
211 ampdu->rx_factor = AMPDU_RX_FACTOR_64K; 205 ampdu->rx_factor = AMPDU_RX_FACTOR_64K;
212#ifdef WLC_HIGH_ONLY
213 /* Restrict to smaller rcv size for BMAC dongle */
214 ampdu->rx_factor = AMPDU_RX_FACTOR_32K;
215#endif
216 ampdu->retry_limit = AMPDU_DEF_RETRY_LIMIT; 206 ampdu->retry_limit = AMPDU_DEF_RETRY_LIMIT;
217 ampdu->rr_retry_limit = AMPDU_DEF_RR_RETRY_LIMIT; 207 ampdu->rr_retry_limit = AMPDU_DEF_RR_RETRY_LIMIT;
218 208
@@ -232,7 +222,7 @@ ampdu_info_t *wlc_ampdu_attach(wlc_info_t *wlc)
232 return ampdu; 222 return ampdu;
233} 223}
234 224
235void wlc_ampdu_detach(ampdu_info_t *ampdu) 225void wlc_ampdu_detach(struct ampdu_info *ampdu)
236{ 226{
237 int i; 227 int i;
238 228
@@ -250,12 +240,12 @@ void wlc_ampdu_detach(ampdu_info_t *ampdu)
250 kfree(ampdu); 240 kfree(ampdu);
251} 241}
252 242
253void scb_ampdu_cleanup(ampdu_info_t *ampdu, struct scb *scb) 243void scb_ampdu_cleanup(struct ampdu_info *ampdu, struct scb *scb)
254{ 244{
255 scb_ampdu_t *scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb); 245 scb_ampdu_t *scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb);
256 u8 tid; 246 u8 tid;
257 247
258 WL_AMPDU_UPDN(("scb_ampdu_cleanup: enter\n")); 248 WL_AMPDU_UPDN("scb_ampdu_cleanup: enter\n");
259 ASSERT(scb_ampdu); 249 ASSERT(scb_ampdu);
260 250
261 for (tid = 0; tid < AMPDU_MAX_SCB_TID; tid++) { 251 for (tid = 0; tid < AMPDU_MAX_SCB_TID; tid++) {
@@ -266,12 +256,12 @@ void scb_ampdu_cleanup(ampdu_info_t *ampdu, struct scb *scb)
266/* reset the ampdu state machine so that it can gracefully handle packets that were 256/* reset the ampdu state machine so that it can gracefully handle packets that were
267 * freed from the dma and tx queues during reinit 257 * freed from the dma and tx queues during reinit
268 */ 258 */
269void wlc_ampdu_reset(ampdu_info_t *ampdu) 259void wlc_ampdu_reset(struct ampdu_info *ampdu)
270{ 260{
271 WL_NONE(("%s: Entering\n", __func__)); 261 WL_NONE("%s: Entering\n", __func__);
272} 262}
273 263
274static void scb_ampdu_update_config(ampdu_info_t *ampdu, struct scb *scb) 264static void scb_ampdu_update_config(struct ampdu_info *ampdu, struct scb *scb)
275{ 265{
276 scb_ampdu_t *scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb); 266 scb_ampdu_t *scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb);
277 int i; 267 int i;
@@ -301,12 +291,12 @@ static void scb_ampdu_update_config(ampdu_info_t *ampdu, struct scb *scb)
301 ASSERT(scb_ampdu->release); 291 ASSERT(scb_ampdu->release);
302} 292}
303 293
304void scb_ampdu_update_config_all(ampdu_info_t *ampdu) 294void scb_ampdu_update_config_all(struct ampdu_info *ampdu)
305{ 295{
306 scb_ampdu_update_config(ampdu, ampdu->wlc->pub->global_scb); 296 scb_ampdu_update_config(ampdu, ampdu->wlc->pub->global_scb);
307} 297}
308 298
309static void wlc_ffpld_init(ampdu_info_t *ampdu) 299static void wlc_ffpld_init(struct ampdu_info *ampdu)
310{ 300{
311 int i, j; 301 int i, j;
312 wlc_fifo_info_t *fifo; 302 wlc_fifo_info_t *fifo;
@@ -330,9 +320,9 @@ static void wlc_ffpld_init(ampdu_info_t *ampdu)
330 * Return 1 if pre-loading not active, -1 if not an underflow event, 320 * Return 1 if pre-loading not active, -1 if not an underflow event,
331 * 0 if pre-loading module took care of the event. 321 * 0 if pre-loading module took care of the event.
332 */ 322 */
333static int wlc_ffpld_check_txfunfl(wlc_info_t *wlc, int fid) 323static int wlc_ffpld_check_txfunfl(struct wlc_info *wlc, int fid)
334{ 324{
335 ampdu_info_t *ampdu = wlc->ampdu; 325 struct ampdu_info *ampdu = wlc->ampdu;
336 u32 phy_rate = MCS_RATE(FFPLD_MAX_MCS, true, false); 326 u32 phy_rate = MCS_RATE(FFPLD_MAX_MCS, true, false);
337 u32 txunfl_ratio; 327 u32 txunfl_ratio;
338 u8 max_mpdu; 328 u8 max_mpdu;
@@ -349,7 +339,7 @@ static int wlc_ffpld_check_txfunfl(wlc_info_t *wlc, int fid)
349 M_UCODE_MACSTAT + offsetof(macstat_t, txfunfl[fid])); 339 M_UCODE_MACSTAT + offsetof(macstat_t, txfunfl[fid]));
350 new_txunfl = (u16) (cur_txunfl - fifo->prev_txfunfl); 340 new_txunfl = (u16) (cur_txunfl - fifo->prev_txfunfl);
351 if (new_txunfl == 0) { 341 if (new_txunfl == 0) {
352 WL_FFPLD(("check_txunfl : TX status FRAG set but no tx underflows\n")); 342 WL_FFPLD("check_txunfl : TX status FRAG set but no tx underflows\n");
353 return -1; 343 return -1;
354 } 344 }
355 fifo->prev_txfunfl = cur_txunfl; 345 fifo->prev_txfunfl = cur_txunfl;
@@ -359,7 +349,7 @@ static int wlc_ffpld_check_txfunfl(wlc_info_t *wlc, int fid)
359 349
360 /* check if fifo is big enough */ 350 /* check if fifo is big enough */
361 if (wlc_xmtfifo_sz_get(wlc, fid, &xmtfifo_sz)) { 351 if (wlc_xmtfifo_sz_get(wlc, fid, &xmtfifo_sz)) {
362 WL_FFPLD(("check_txunfl : get xmtfifo_sz failed.\n")); 352 WL_FFPLD("check_txunfl : get xmtfifo_sz failed\n");
363 return -1; 353 return -1;
364 } 354 }
365 355
@@ -373,8 +363,8 @@ static int wlc_ffpld_check_txfunfl(wlc_info_t *wlc, int fid)
373 if (fifo->accum_txfunfl < 10) 363 if (fifo->accum_txfunfl < 10)
374 return 0; 364 return 0;
375 365
376 WL_FFPLD(("ampdu_count %d tx_underflows %d\n", 366 WL_FFPLD("ampdu_count %d tx_underflows %d\n",
377 current_ampdu_cnt, fifo->accum_txfunfl)); 367 current_ampdu_cnt, fifo->accum_txfunfl);
378 368
379 /* 369 /*
380 compute the current ratio of tx unfl per ampdu. 370 compute the current ratio of tx unfl per ampdu.
@@ -427,8 +417,8 @@ static int wlc_ffpld_check_txfunfl(wlc_info_t *wlc, int fid)
427 (max_mpdu * FFPLD_MPDU_SIZE - fifo->ampdu_pld_size)) 417 (max_mpdu * FFPLD_MPDU_SIZE - fifo->ampdu_pld_size))
428 / (max_mpdu * FFPLD_MPDU_SIZE)) * 100; 418 / (max_mpdu * FFPLD_MPDU_SIZE)) * 100;
429 419
430 WL_FFPLD(("DMA estimated transfer rate %d; pre-load size %d\n", 420 WL_FFPLD("DMA estimated transfer rate %d; pre-load size %d\n",
431 fifo->dmaxferrate, fifo->ampdu_pld_size)); 421 fifo->dmaxferrate, fifo->ampdu_pld_size);
432 } else { 422 } else {
433 423
434 /* decrease ampdu size */ 424 /* decrease ampdu size */
@@ -450,7 +440,7 @@ static int wlc_ffpld_check_txfunfl(wlc_info_t *wlc, int fid)
450 return 0; 440 return 0;
451} 441}
452 442
453static void wlc_ffpld_calc_mcs2ampdu_table(ampdu_info_t *ampdu, int f) 443static void wlc_ffpld_calc_mcs2ampdu_table(struct ampdu_info *ampdu, int f)
454{ 444{
455 int i; 445 int i;
456 u32 phy_rate, dma_rate, tmp; 446 u32 phy_rate, dma_rate, tmp;
@@ -483,11 +473,12 @@ static void wlc_ffpld_calc_mcs2ampdu_table(ampdu_info_t *ampdu, int f)
483} 473}
484 474
485static void BCMFASTPATH 475static void BCMFASTPATH
486wlc_ampdu_agg(ampdu_info_t *ampdu, struct scb *scb, void *p, uint prec) 476wlc_ampdu_agg(struct ampdu_info *ampdu, struct scb *scb, struct sk_buff *p,
477 uint prec)
487{ 478{
488 scb_ampdu_t *scb_ampdu; 479 scb_ampdu_t *scb_ampdu;
489 scb_ampdu_tid_ini_t *ini; 480 scb_ampdu_tid_ini_t *ini;
490 u8 tid = (u8) PKTPRIO(p); 481 u8 tid = (u8) (p->priority);
491 482
492 scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb); 483 scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb);
493 484
@@ -500,11 +491,12 @@ wlc_ampdu_agg(ampdu_info_t *ampdu, struct scb *scb, void *p, uint prec)
500} 491}
501 492
502int BCMFASTPATH 493int BCMFASTPATH
503wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec) 494wlc_sendampdu(struct ampdu_info *ampdu, wlc_txq_info_t *qi,
495 struct sk_buff **pdu, int prec)
504{ 496{
505 wlc_info_t *wlc; 497 struct wlc_info *wlc;
506 osl_t *osh; 498 struct osl_info *osh;
507 void *p, *pkt[AMPDU_MAX_MPDU]; 499 struct sk_buff *p, *pkt[AMPDU_MAX_MPDU];
508 u8 tid, ndelim; 500 u8 tid, ndelim;
509 int err = 0; 501 int err = 0;
510 u8 preamble_type = WLC_GF_PREAMBLE; 502 u8 preamble_type = WLC_GF_PREAMBLE;
@@ -540,7 +532,7 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
540 532
541 ASSERT(p); 533 ASSERT(p);
542 534
543 tid = (u8) PKTPRIO(p); 535 tid = (u8) (p->priority);
544 ASSERT(tid < AMPDU_MAX_SCB_TID); 536 ASSERT(tid < AMPDU_MAX_SCB_TID);
545 537
546 f = ampdu->fifo_tb + prio2fifo[tid]; 538 f = ampdu->fifo_tb + prio2fifo[tid];
@@ -561,7 +553,7 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
561 wlc_ampdu_agg(ampdu, scb, p, tid); 553 wlc_ampdu_agg(ampdu, scb, p, tid);
562 554
563 if (wlc->block_datafifo) { 555 if (wlc->block_datafifo) {
564 WL_ERROR(("%s: Fifo blocked\n", __func__)); 556 WL_ERROR("%s: Fifo blocked\n", __func__);
565 return BCME_BUSY; 557 return BCME_BUSY;
566 } 558 }
567 rr_retry_limit = ampdu->rr_retry_limit_tid[tid]; 559 rr_retry_limit = ampdu->rr_retry_limit_tid[tid];
@@ -576,7 +568,7 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
576 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) { 568 if (tx_info->flags & IEEE80211_TX_CTL_AMPDU) {
577 err = wlc_prep_pdu(wlc, p, &fifo); 569 err = wlc_prep_pdu(wlc, p, &fifo);
578 } else { 570 } else {
579 WL_ERROR(("%s: AMPDU flag is off!\n", __func__)); 571 WL_ERROR("%s: AMPDU flag is off!\n", __func__);
580 *pdu = NULL; 572 *pdu = NULL;
581 err = 0; 573 err = 0;
582 break; 574 break;
@@ -584,14 +576,16 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
584 576
585 if (err) { 577 if (err) {
586 if (err == BCME_BUSY) { 578 if (err == BCME_BUSY) {
587 WL_ERROR(("wl%d: wlc_sendampdu: prep_xdu retry; seq 0x%x\n", wlc->pub->unit, seq)); 579 WL_ERROR("wl%d: wlc_sendampdu: prep_xdu retry; seq 0x%x\n",
580 wlc->pub->unit, seq);
588 WLCNTINCR(ampdu->cnt->sduretry); 581 WLCNTINCR(ampdu->cnt->sduretry);
589 *pdu = p; 582 *pdu = p;
590 break; 583 break;
591 } 584 }
592 585
593 /* error in the packet; reject it */ 586 /* error in the packet; reject it */
594 WL_AMPDU_ERR(("wl%d: wlc_sendampdu: prep_xdu rejected; seq 0x%x\n", wlc->pub->unit, seq)); 587 WL_AMPDU_ERR("wl%d: wlc_sendampdu: prep_xdu rejected; seq 0x%x\n",
588 wlc->pub->unit, seq);
595 WLCNTINCR(ampdu->cnt->sdurejected); 589 WLCNTINCR(ampdu->cnt->sdurejected);
596 590
597 *pdu = NULL; 591 *pdu = NULL;
@@ -600,7 +594,7 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
600 594
601 /* pkt is good to be aggregated */ 595 /* pkt is good to be aggregated */
602 ASSERT(tx_info->flags & IEEE80211_TX_CTL_AMPDU); 596 ASSERT(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
603 txh = (d11txh_t *) PKTDATA(p); 597 txh = (d11txh_t *) p->data;
604 plcp = (u8 *) (txh + 1); 598 plcp = (u8 *) (txh + 1);
605 h = (struct dot11_header *)(plcp + D11_PHY_HDR_LEN); 599 h = (struct dot11_header *)(plcp + D11_PHY_HDR_LEN);
606 seq = ltoh16(h->seq) >> SEQNUM_SHIFT; 600 seq = ltoh16(h->seq) >> SEQNUM_SHIFT;
@@ -633,8 +627,8 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
633 ndelim = txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM]; 627 ndelim = txh->RTSPLCPFallback[AMPDU_FBR_NULL_DELIM];
634 seg_cnt += 1; 628 seg_cnt += 1;
635 629
636 WL_AMPDU_TX(("wl%d: wlc_sendampdu: mpdu %d plcp_len %d\n", 630 WL_AMPDU_TX("wl%d: wlc_sendampdu: mpdu %d plcp_len %d\n",
637 wlc->pub->unit, count, len)); 631 wlc->pub->unit, count, len);
638 632
639 /* 633 /*
640 * aggregateable mpdu. For ucode/hw agg, 634 * aggregateable mpdu. For ucode/hw agg,
@@ -665,7 +659,8 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
665 659
666 dma_len += (u16) pkttotlen(osh, p); 660 dma_len += (u16) pkttotlen(osh, p);
667 661
668 WL_AMPDU_TX(("wl%d: wlc_sendampdu: ampdu_len %d seg_cnt %d null delim %d\n", wlc->pub->unit, ampdu_len, seg_cnt, ndelim)); 662 WL_AMPDU_TX("wl%d: wlc_sendampdu: ampdu_len %d seg_cnt %d null delim %d\n",
663 wlc->pub->unit, ampdu_len, seg_cnt, ndelim);
669 664
670 txh->MacTxControlLow = htol16(mcl); 665 txh->MacTxControlLow = htol16(mcl);
671 666
@@ -695,8 +690,8 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
695 min(scb_ampdu->max_rxlen, 690 min(scb_ampdu->max_rxlen,
696 ampdu->max_txlen[mcs][is40][sgi]); 691 ampdu->max_txlen[mcs][is40][sgi]);
697 692
698 WL_NONE(("sendampdu: sgi %d, is40 %d, mcs %d\n", sgi, 693 WL_NONE("sendampdu: sgi %d, is40 %d, mcs %d\n",
699 is40, mcs)); 694 sgi, is40, mcs);
700 695
701 maxlen = 64 * 1024; /* XXX Fix me to honor real max_rxlen */ 696 maxlen = 64 * 1024; /* XXX Fix me to honor real max_rxlen */
702 697
@@ -739,13 +734,14 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
739 /* test whether to add more */ 734 /* test whether to add more */
740 if ((MCS_RATE(mcs, true, false) >= f->dmaxferrate) && 735 if ((MCS_RATE(mcs, true, false) >= f->dmaxferrate) &&
741 (count == f->mcs2ampdu_table[mcs])) { 736 (count == f->mcs2ampdu_table[mcs])) {
742 WL_AMPDU_ERR(("wl%d: PR 37644: stopping ampdu at %d for mcs %d", wlc->pub->unit, count, mcs)); 737 WL_AMPDU_ERR("wl%d: PR 37644: stopping ampdu at %d for mcs %d\n",
738 wlc->pub->unit, count, mcs);
743 break; 739 break;
744 } 740 }
745 741
746 if (count == scb_ampdu->max_pdu) { 742 if (count == scb_ampdu->max_pdu) {
747 WL_NONE(("Stop taking from q, reached %d deep\n", 743 WL_NONE("Stop taking from q, reached %d deep\n",
748 scb_ampdu->max_pdu)); 744 scb_ampdu->max_pdu);
749 break; 745 break;
750 } 746 }
751 747
@@ -755,7 +751,7 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
755 751
756 if (p) { 752 if (p) {
757 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && 753 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) &&
758 ((u8) PKTPRIO(p) == tid)) { 754 ((u8) (p->priority) == tid)) {
759 755
760 plen = 756 plen =
761 pkttotlen(osh, p) + AMPDU_MAX_MPDU_OVERHEAD; 757 pkttotlen(osh, p) + AMPDU_MAX_MPDU_OVERHEAD;
@@ -763,15 +759,16 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
763 759
764 if ((plen + ampdu_len) > maxlen) { 760 if ((plen + ampdu_len) > maxlen) {
765 p = NULL; 761 p = NULL;
766 WL_ERROR(("%s: Bogus plen #1\n", 762 WL_ERROR("%s: Bogus plen #1\n",
767 __func__)); 763 __func__);
768 ASSERT(3 == 4); 764 ASSERT(3 == 4);
769 continue; 765 continue;
770 } 766 }
771 767
772 /* check if there are enough descriptors available */ 768 /* check if there are enough descriptors available */
773 if (TXAVAIL(wlc, fifo) <= (seg_cnt + 1)) { 769 if (TXAVAIL(wlc, fifo) <= (seg_cnt + 1)) {
774 WL_ERROR(("%s: No fifo space !!!!!!\n", __func__)); 770 WL_ERROR("%s: No fifo space !!!!!!\n",
771 __func__);
775 p = NULL; 772 p = NULL;
776 continue; 773 continue;
777 } 774 }
@@ -789,7 +786,7 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
789 WLCNTADD(ampdu->cnt->txmpdu, count); 786 WLCNTADD(ampdu->cnt->txmpdu, count);
790 787
791 /* patch up the last txh */ 788 /* patch up the last txh */
792 txh = (d11txh_t *) PKTDATA(pkt[count - 1]); 789 txh = (d11txh_t *) pkt[count - 1]->data;
793 mcl = ltoh16(txh->MacTxControlLow); 790 mcl = ltoh16(txh->MacTxControlLow);
794 mcl &= ~TXC_AMPDU_MASK; 791 mcl &= ~TXC_AMPDU_MASK;
795 mcl |= (TXC_AMPDU_LAST << TXC_AMPDU_SHIFT); 792 mcl |= (TXC_AMPDU_LAST << TXC_AMPDU_SHIFT);
@@ -807,7 +804,7 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
807 ampdu_len -= roundup(len, 4) - len; 804 ampdu_len -= roundup(len, 4) - len;
808 805
809 /* patch up the first txh & plcp */ 806 /* patch up the first txh & plcp */
810 txh = (d11txh_t *) PKTDATA(pkt[0]); 807 txh = (d11txh_t *) pkt[0]->data;
811 plcp = (u8 *) (txh + 1); 808 plcp = (u8 *) (txh + 1);
812 809
813 WLC_SET_MIMO_PLCP_LEN(plcp, ampdu_len); 810 WLC_SET_MIMO_PLCP_LEN(plcp, ampdu_len);
@@ -878,27 +875,18 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
878 WLC_SET_MIMO_PLCP_AMPDU(txh->FragPLCPFallback); 875 WLC_SET_MIMO_PLCP_AMPDU(txh->FragPLCPFallback);
879 } 876 }
880 877
881 WL_AMPDU_TX(("wl%d: wlc_sendampdu: count %d ampdu_len %d\n", 878 WL_AMPDU_TX("wl%d: wlc_sendampdu: count %d ampdu_len %d\n",
882 wlc->pub->unit, count, ampdu_len)); 879 wlc->pub->unit, count, ampdu_len);
883 880
884 /* inform rate_sel if it this is a rate probe pkt */ 881 /* inform rate_sel if it this is a rate probe pkt */
885 frameid = ltoh16(txh->TxFrameID); 882 frameid = ltoh16(txh->TxFrameID);
886 if (frameid & TXFID_RATE_PROBE_MASK) { 883 if (frameid & TXFID_RATE_PROBE_MASK) {
887 WL_ERROR(("%s: XXX what to do with TXFID_RATE_PROBE_MASK!?\n", __func__)); 884 WL_ERROR("%s: XXX what to do with TXFID_RATE_PROBE_MASK!?\n",
885 __func__);
888 } 886 }
889#ifdef WLC_HIGH_ONLY
890 if (wlc->rpc_agg & BCM_RPC_TP_HOST_AGG_AMPDU)
891 bcm_rpc_tp_agg_set(bcm_rpc_tp_get(wlc->rpc),
892 BCM_RPC_TP_HOST_AGG_AMPDU, true);
893#endif
894 for (i = 0; i < count; i++) 887 for (i = 0; i < count; i++)
895 wlc_txfifo(wlc, fifo, pkt[i], i == (count - 1), 888 wlc_txfifo(wlc, fifo, pkt[i], i == (count - 1),
896 ampdu->txpkt_weight); 889 ampdu->txpkt_weight);
897#ifdef WLC_HIGH_ONLY
898 if (wlc->rpc_agg & BCM_RPC_TP_HOST_AGG_AMPDU)
899 bcm_rpc_tp_agg_set(bcm_rpc_tp_get(wlc->rpc),
900 BCM_RPC_TP_HOST_AGG_AMPDU, false);
901#endif
902 890
903 } 891 }
904 /* endif (count) */ 892 /* endif (count) */
@@ -906,11 +894,11 @@ wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **pdu, int prec)
906} 894}
907 895
908void BCMFASTPATH 896void BCMFASTPATH
909wlc_ampdu_dotxstatus(ampdu_info_t *ampdu, struct scb *scb, void *p, 897wlc_ampdu_dotxstatus(struct ampdu_info *ampdu, struct scb *scb,
910 tx_status_t *txs) 898 struct sk_buff *p, tx_status_t *txs)
911{ 899{
912 scb_ampdu_t *scb_ampdu; 900 scb_ampdu_t *scb_ampdu;
913 wlc_info_t *wlc = ampdu->wlc; 901 struct wlc_info *wlc = ampdu->wlc;
914 scb_ampdu_tid_ini_t *ini; 902 scb_ampdu_tid_ini_t *ini;
915 u32 s1 = 0, s2 = 0; 903 u32 s1 = 0, s2 = 0;
916 struct ieee80211_tx_info *tx_info; 904 struct ieee80211_tx_info *tx_info;
@@ -922,7 +910,7 @@ wlc_ampdu_dotxstatus(ampdu_info_t *ampdu, struct scb *scb, void *p,
922 ASSERT(txs->status & TX_STATUS_AMPDU); 910 ASSERT(txs->status & TX_STATUS_AMPDU);
923 scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb); 911 scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb);
924 ASSERT(scb_ampdu); 912 ASSERT(scb_ampdu);
925 ini = SCB_AMPDU_INI(scb_ampdu, PKTPRIO(p)); 913 ini = SCB_AMPDU_INI(scb_ampdu, p->priority);
926 ASSERT(ini->scb == scb); 914 ASSERT(ini->scb == scb);
927 915
928 /* BMAC_NOTE: For the split driver, second level txstatus comes later 916 /* BMAC_NOTE: For the split driver, second level txstatus comes later
@@ -930,7 +918,6 @@ wlc_ampdu_dotxstatus(ampdu_info_t *ampdu, struct scb *scb, void *p,
930 * call the first one 918 * call the first one
931 */ 919 */
932 if (txs->status & TX_STATUS_ACK_RCV) { 920 if (txs->status & TX_STATUS_ACK_RCV) {
933#ifdef WLC_LOW
934 u8 status_delay = 0; 921 u8 status_delay = 0;
935 922
936 /* wait till the next 8 bytes of txstatus is available */ 923 /* wait till the next 8 bytes of txstatus is available */
@@ -948,54 +935,14 @@ wlc_ampdu_dotxstatus(ampdu_info_t *ampdu, struct scb *scb, void *p,
948 ASSERT(!(s1 & TX_STATUS_INTERMEDIATE)); 935 ASSERT(!(s1 & TX_STATUS_INTERMEDIATE));
949 ASSERT(s1 & TX_STATUS_AMPDU); 936 ASSERT(s1 & TX_STATUS_AMPDU);
950 s2 = R_REG(wlc->osh, &wlc->regs->frmtxstatus2); 937 s2 = R_REG(wlc->osh, &wlc->regs->frmtxstatus2);
951#else /* WLC_LOW */
952
953 /* Store the relevant information in ampdu structure */
954 WL_AMPDU_TX(("wl%d: wlc_ampdu_dotxstatus: High Recvd\n",
955 wlc->pub->unit));
956
957 ASSERT(!ampdu->p);
958 ampdu->p = p;
959 bcopy(txs, &ampdu->txs, sizeof(tx_status_t));
960 ampdu->waiting_status = true;
961 return;
962#endif /* WLC_LOW */
963 } 938 }
964 939
965 wlc_ampdu_dotxstatus_complete(ampdu, scb, p, txs, s1, s2); 940 wlc_ampdu_dotxstatus_complete(ampdu, scb, p, txs, s1, s2);
966 wlc_ampdu_txflowcontrol(wlc, scb_ampdu, ini); 941 wlc_ampdu_txflowcontrol(wlc, scb_ampdu, ini);
967} 942}
968 943
969#ifdef WLC_HIGH_ONLY
970void wlc_ampdu_txstatus_complete(ampdu_info_t *ampdu, u32 s1, u32 s2)
971{
972 WL_AMPDU_TX(("wl%d: wlc_ampdu_txstatus_complete: High Recvd 0x%x 0x%x p:%p\n", ampdu->wlc->pub->unit, s1, s2, ampdu->p));
973
974 ASSERT(ampdu->waiting_status);
975
976 /* The packet may have been freed if the SCB went away, if so, then still free the
977 * DMA chain
978 */
979 if (ampdu->p) {
980 struct ieee80211_tx_info *tx_info;
981 struct scb *scb;
982
983 tx_info = IEEE80211_SKB_CB(ampdu->p);
984 scb = (struct scb *)tx_info->control.sta->drv_priv;
985
986 wlc_ampdu_dotxstatus_complete(ampdu, scb, ampdu->p, &ampdu->txs,
987 s1, s2);
988 ampdu->p = NULL;
989 }
990
991 ampdu->waiting_status = false;
992}
993#endif /* WLC_HIGH_ONLY */
994void rate_status(wlc_info_t *wlc, struct ieee80211_tx_info *tx_info,
995 tx_status_t *txs, u8 mcs);
996
997void 944void
998rate_status(wlc_info_t *wlc, struct ieee80211_tx_info *tx_info, 945rate_status(struct wlc_info *wlc, struct ieee80211_tx_info *tx_info,
999 tx_status_t *txs, u8 mcs) 946 tx_status_t *txs, u8 mcs)
1000{ 947{
1001 struct ieee80211_tx_rate *txrate = tx_info->status.rates; 948 struct ieee80211_tx_rate *txrate = tx_info->status.rates;
@@ -1008,17 +955,15 @@ rate_status(wlc_info_t *wlc, struct ieee80211_tx_info *tx_info,
1008 } 955 }
1009} 956}
1010 957
1011extern void wlc_txq_enq(wlc_info_t *wlc, struct scb *scb, void *sdu,
1012 uint prec);
1013
1014#define SHORTNAME "AMPDU status" 958#define SHORTNAME "AMPDU status"
1015 959
1016static void BCMFASTPATH 960static void BCMFASTPATH
1017wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p, 961wlc_ampdu_dotxstatus_complete(struct ampdu_info *ampdu, struct scb *scb,
1018 tx_status_t *txs, u32 s1, u32 s2) 962 struct sk_buff *p, tx_status_t *txs,
963 u32 s1, u32 s2)
1019{ 964{
1020 scb_ampdu_t *scb_ampdu; 965 scb_ampdu_t *scb_ampdu;
1021 wlc_info_t *wlc = ampdu->wlc; 966 struct wlc_info *wlc = ampdu->wlc;
1022 scb_ampdu_tid_ini_t *ini; 967 scb_ampdu_tid_ini_t *ini;
1023 u8 bitmap[8], queue, tid; 968 u8 bitmap[8], queue, tid;
1024 d11txh_t *txh; 969 d11txh_t *txh;
@@ -1037,7 +982,7 @@ wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p,
1037 982
1038#ifdef BCMDBG 983#ifdef BCMDBG
1039 u8 hole[AMPDU_MAX_MPDU]; 984 u8 hole[AMPDU_MAX_MPDU];
1040 bzero(hole, sizeof(hole)); 985 memset(hole, 0, sizeof(hole));
1041#endif 986#endif
1042 987
1043 ASSERT(tx_info->flags & IEEE80211_TX_CTL_AMPDU); 988 ASSERT(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
@@ -1046,7 +991,7 @@ wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p,
1046 scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb); 991 scb_ampdu = SCB_AMPDU_CUBBY(ampdu, scb);
1047 ASSERT(scb_ampdu); 992 ASSERT(scb_ampdu);
1048 993
1049 tid = (u8) PKTPRIO(p); 994 tid = (u8) (p->priority);
1050 995
1051 ini = SCB_AMPDU_INI(scb_ampdu, tid); 996 ini = SCB_AMPDU_INI(scb_ampdu, tid);
1052 retry_limit = ampdu->retry_limit_tid[tid]; 997 retry_limit = ampdu->retry_limit_tid[tid];
@@ -1054,7 +999,7 @@ wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p,
1054 999
1055 ASSERT(ini->scb == scb); 1000 ASSERT(ini->scb == scb);
1056 1001
1057 bzero(bitmap, sizeof(bitmap)); 1002 memset(bitmap, 0, sizeof(bitmap));
1058 queue = txs->frameid & TXFID_QUEUE_MASK; 1003 queue = txs->frameid & TXFID_QUEUE_MASK;
1059 ASSERT(queue < AC_COUNT); 1004 ASSERT(queue < AC_COUNT);
1060 1005
@@ -1091,13 +1036,16 @@ wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p,
1091 if (supr_status) { 1036 if (supr_status) {
1092 update_rate = false; 1037 update_rate = false;
1093 if (supr_status == TX_STATUS_SUPR_BADCH) { 1038 if (supr_status == TX_STATUS_SUPR_BADCH) {
1094 WL_ERROR(("%s: Pkt tx suppressed, illegal channel possibly %d\n", __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec))); 1039 WL_ERROR("%s: Pkt tx suppressed, illegal channel possibly %d\n",
1040 __func__,
1041 CHSPEC_CHANNEL(wlc->default_bss->chanspec));
1095 } else { 1042 } else {
1096 if (supr_status == TX_STATUS_SUPR_FRAG) 1043 if (supr_status == TX_STATUS_SUPR_FRAG)
1097 WL_NONE(("%s: AMPDU frag err\n", 1044 WL_NONE("%s: AMPDU frag err\n",
1098 __func__)); 1045 __func__);
1099 else 1046 else
1100 WL_ERROR(("%s: wlc_ampdu_dotxstatus: supr_status 0x%x\n", __func__, supr_status)); 1047 WL_ERROR("%s: wlc_ampdu_dotxstatus: supr_status 0x%x\n",
1048 __func__, supr_status);
1101 } 1049 }
1102 /* no need to retry for badch; will fail again */ 1050 /* no need to retry for badch; will fail again */
1103 if (supr_status == TX_STATUS_SUPR_BADCH || 1051 if (supr_status == TX_STATUS_SUPR_BADCH ||
@@ -1116,22 +1064,18 @@ wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p,
1116 if (wlc_ffpld_check_txfunfl(wlc, prio2fifo[tid]) 1064 if (wlc_ffpld_check_txfunfl(wlc, prio2fifo[tid])
1117 > 0) { 1065 > 0) {
1118 tx_error = true; 1066 tx_error = true;
1119#ifdef WLC_HIGH_ONLY
1120 /* With BMAC, TX Underflows should not happen */
1121 WL_ERROR(("wl%d: BMAC TX Underflow?",
1122 wlc->pub->unit));
1123#endif
1124 } 1067 }
1125 } 1068 }
1126 } else if (txs->phyerr) { 1069 } else if (txs->phyerr) {
1127 update_rate = false; 1070 update_rate = false;
1128 WLCNTINCR(wlc->pub->_cnt->txphyerr); 1071 WLCNTINCR(wlc->pub->_cnt->txphyerr);
1129 WL_ERROR(("wl%d: wlc_ampdu_dotxstatus: tx phy error (0x%x)\n", wlc->pub->unit, txs->phyerr)); 1072 WL_ERROR("wl%d: wlc_ampdu_dotxstatus: tx phy error (0x%x)\n",
1073 wlc->pub->unit, txs->phyerr);
1130 1074
1131#ifdef BCMDBG 1075#ifdef BCMDBG
1132 if (WL_ERROR_ON()) { 1076 if (WL_ERROR_ON()) {
1133 prpkt("txpkt (AMPDU)", wlc->osh, p); 1077 prpkt("txpkt (AMPDU)", wlc->osh, p);
1134 wlc_print_txdesc((d11txh_t *) PKTDATA(p)); 1078 wlc_print_txdesc((d11txh_t *) p->data);
1135 wlc_print_txstatus(txs); 1079 wlc_print_txstatus(txs);
1136 } 1080 }
1137#endif /* BCMDBG */ 1081#endif /* BCMDBG */
@@ -1142,7 +1086,7 @@ wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p,
1142 while (p) { 1086 while (p) {
1143 tx_info = IEEE80211_SKB_CB(p); 1087 tx_info = IEEE80211_SKB_CB(p);
1144 ASSERT(tx_info->flags & IEEE80211_TX_CTL_AMPDU); 1088 ASSERT(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
1145 txh = (d11txh_t *) PKTDATA(p); 1089 txh = (d11txh_t *) p->data;
1146 mcl = ltoh16(txh->MacTxControlLow); 1090 mcl = ltoh16(txh->MacTxControlLow);
1147 plcp = (u8 *) (txh + 1); 1091 plcp = (u8 *) (txh + 1);
1148 h = (struct dot11_header *)(plcp + D11_PHY_HDR_LEN); 1092 h = (struct dot11_header *)(plcp + D11_PHY_HDR_LEN);
@@ -1158,10 +1102,9 @@ wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p,
1158 if (ba_recd) { 1102 if (ba_recd) {
1159 bindex = MODSUB_POW2(seq, start_seq, SEQNUM_MAX); 1103 bindex = MODSUB_POW2(seq, start_seq, SEQNUM_MAX);
1160 1104
1161 WL_AMPDU_TX(("%s: tid %d seq is %d, start_seq is %d, " 1105 WL_AMPDU_TX("%s: tid %d seq is %d, start_seq is %d, bindex is %d set %d, index %d\n",
1162 "bindex is %d set %d, index %d\n", 1106 __func__, tid, seq, start_seq, bindex,
1163 __func__, tid, seq, start_seq, bindex, 1107 isset(bitmap, bindex), index);
1164 isset(bitmap, bindex), index));
1165 1108
1166 /* if acked then clear bit and free packet */ 1109 /* if acked then clear bit and free packet */
1167 if ((bindex < AMPDU_TX_BA_MAX_WSIZE) 1110 if ((bindex < AMPDU_TX_BA_MAX_WSIZE)
@@ -1186,8 +1129,8 @@ wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p,
1186 status & TX_STATUS_FRM_RTX_MASK) >> 1129 status & TX_STATUS_FRM_RTX_MASK) >>
1187 TX_STATUS_FRM_RTX_SHIFT; 1130 TX_STATUS_FRM_RTX_SHIFT;
1188 1131
1189 PKTPULL(p, D11_PHY_HDR_LEN); 1132 skb_pull(p, D11_PHY_HDR_LEN);
1190 PKTPULL(p, D11_TXH_LEN); 1133 skb_pull(p, D11_TXH_LEN);
1191 1134
1192 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, 1135 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw,
1193 p); 1136 p);
@@ -1212,9 +1155,10 @@ wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p,
1212 ieee80211_tx_info_clear_status(tx_info); 1155 ieee80211_tx_info_clear_status(tx_info);
1213 tx_info->flags |= 1156 tx_info->flags |=
1214 IEEE80211_TX_STAT_AMPDU_NO_BACK; 1157 IEEE80211_TX_STAT_AMPDU_NO_BACK;
1215 PKTPULL(p, D11_PHY_HDR_LEN); 1158 skb_pull(p, D11_PHY_HDR_LEN);
1216 PKTPULL(p, D11_TXH_LEN); 1159 skb_pull(p, D11_TXH_LEN);
1217 WL_ERROR(("%s: BA Timeout, seq %d, in_transit %d\n", SHORTNAME, seq, ini->tx_in_transit)); 1160 WL_ERROR("%s: BA Timeout, seq %d, in_transit %d\n",
1161 SHORTNAME, seq, ini->tx_in_transit);
1218 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, 1162 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw,
1219 p); 1163 p);
1220 } 1164 }
@@ -1242,7 +1186,7 @@ wlc_ampdu_dotxstatus_complete(ampdu_info_t *ampdu, struct scb *scb, void *p,
1242} 1186}
1243 1187
1244static void 1188static void
1245ampdu_cleanup_tid_ini(ampdu_info_t *ampdu, scb_ampdu_t *scb_ampdu, u8 tid, 1189ampdu_cleanup_tid_ini(struct ampdu_info *ampdu, scb_ampdu_t *scb_ampdu, u8 tid,
1246 bool force) 1190 bool force)
1247{ 1191{
1248 scb_ampdu_tid_ini_t *ini; 1192 scb_ampdu_tid_ini_t *ini;
@@ -1250,8 +1194,8 @@ ampdu_cleanup_tid_ini(ampdu_info_t *ampdu, scb_ampdu_t *scb_ampdu, u8 tid,
1250 if (!ini) 1194 if (!ini)
1251 return; 1195 return;
1252 1196
1253 WL_AMPDU_CTL(("wl%d: ampdu_cleanup_tid_ini: tid %d\n", 1197 WL_AMPDU_CTL("wl%d: ampdu_cleanup_tid_ini: tid %d\n",
1254 ampdu->wlc->pub->unit, tid)); 1198 ampdu->wlc->pub->unit, tid);
1255 1199
1256 if (ini->tx_in_transit && !force) 1200 if (ini->tx_in_transit && !force)
1257 return; 1201 return;
@@ -1264,7 +1208,7 @@ ampdu_cleanup_tid_ini(ampdu_info_t *ampdu, scb_ampdu_t *scb_ampdu, u8 tid,
1264} 1208}
1265 1209
1266/* initialize the initiator code for tid */ 1210/* initialize the initiator code for tid */
1267static scb_ampdu_tid_ini_t *wlc_ampdu_init_tid_ini(ampdu_info_t *ampdu, 1211static scb_ampdu_tid_ini_t *wlc_ampdu_init_tid_ini(struct ampdu_info *ampdu,
1268 scb_ampdu_t *scb_ampdu, 1212 scb_ampdu_t *scb_ampdu,
1269 u8 tid, bool override) 1213 u8 tid, bool override)
1270{ 1214{
@@ -1277,7 +1221,7 @@ static scb_ampdu_tid_ini_t *wlc_ampdu_init_tid_ini(ampdu_info_t *ampdu,
1277 1221
1278 /* check for per-tid control of ampdu */ 1222 /* check for per-tid control of ampdu */
1279 if (!ampdu->ini_enable[tid]) { 1223 if (!ampdu->ini_enable[tid]) {
1280 WL_ERROR(("%s: Rejecting tid %d\n", __func__, tid)); 1224 WL_ERROR("%s: Rejecting tid %d\n", __func__, tid);
1281 return NULL; 1225 return NULL;
1282 } 1226 }
1283 1227
@@ -1290,21 +1234,21 @@ static scb_ampdu_tid_ini_t *wlc_ampdu_init_tid_ini(ampdu_info_t *ampdu,
1290 return ini; 1234 return ini;
1291} 1235}
1292 1236
1293int wlc_ampdu_set(ampdu_info_t *ampdu, bool on) 1237int wlc_ampdu_set(struct ampdu_info *ampdu, bool on)
1294{ 1238{
1295 wlc_info_t *wlc = ampdu->wlc; 1239 struct wlc_info *wlc = ampdu->wlc;
1296 1240
1297 wlc->pub->_ampdu = false; 1241 wlc->pub->_ampdu = false;
1298 1242
1299 if (on) { 1243 if (on) {
1300 if (!N_ENAB(wlc->pub)) { 1244 if (!N_ENAB(wlc->pub)) {
1301 WL_AMPDU_ERR(("wl%d: driver not nmode enabled\n", 1245 WL_AMPDU_ERR("wl%d: driver not nmode enabled\n",
1302 wlc->pub->unit)); 1246 wlc->pub->unit);
1303 return BCME_UNSUPPORTED; 1247 return BCME_UNSUPPORTED;
1304 } 1248 }
1305 if (!wlc_ampdu_cap(ampdu)) { 1249 if (!wlc_ampdu_cap(ampdu)) {
1306 WL_AMPDU_ERR(("wl%d: device not ampdu capable\n", 1250 WL_AMPDU_ERR("wl%d: device not ampdu capable\n",
1307 wlc->pub->unit)); 1251 wlc->pub->unit);
1308 return BCME_UNSUPPORTED; 1252 return BCME_UNSUPPORTED;
1309 } 1253 }
1310 wlc->pub->_ampdu = on; 1254 wlc->pub->_ampdu = on;
@@ -1313,7 +1257,7 @@ int wlc_ampdu_set(ampdu_info_t *ampdu, bool on)
1313 return 0; 1257 return 0;
1314} 1258}
1315 1259
1316bool wlc_ampdu_cap(ampdu_info_t *ampdu) 1260bool wlc_ampdu_cap(struct ampdu_info *ampdu)
1317{ 1261{
1318 if (WLC_PHY_11N_CAP(ampdu->wlc->band)) 1262 if (WLC_PHY_11N_CAP(ampdu->wlc->band))
1319 return true; 1263 return true;
@@ -1321,7 +1265,7 @@ bool wlc_ampdu_cap(ampdu_info_t *ampdu)
1321 return false; 1265 return false;
1322} 1266}
1323 1267
1324static void ampdu_update_max_txlen(ampdu_info_t *ampdu, u8 dur) 1268static void ampdu_update_max_txlen(struct ampdu_info *ampdu, u8 dur)
1325{ 1269{
1326 u32 rate, mcs; 1270 u32 rate, mcs;
1327 1271
@@ -1343,7 +1287,7 @@ static void ampdu_update_max_txlen(ampdu_info_t *ampdu, u8 dur)
1343} 1287}
1344 1288
1345u8 BCMFASTPATH 1289u8 BCMFASTPATH
1346wlc_ampdu_null_delim_cnt(ampdu_info_t *ampdu, struct scb *scb, 1290wlc_ampdu_null_delim_cnt(struct ampdu_info *ampdu, struct scb *scb,
1347 ratespec_t rspec, int phylen) 1291 ratespec_t rspec, int phylen)
1348{ 1292{
1349 scb_ampdu_t *scb_ampdu; 1293 scb_ampdu_t *scb_ampdu;
@@ -1379,25 +1323,25 @@ wlc_ampdu_null_delim_cnt(ampdu_info_t *ampdu, struct scb *scb,
1379 return 0; 1323 return 0;
1380} 1324}
1381 1325
1382void wlc_ampdu_macaddr_upd(wlc_info_t *wlc) 1326void wlc_ampdu_macaddr_upd(struct wlc_info *wlc)
1383{ 1327{
1384 char template[T_RAM_ACCESS_SZ * 2]; 1328 char template[T_RAM_ACCESS_SZ * 2];
1385 1329
1386 /* driver needs to write the ta in the template; ta is at offset 16 */ 1330 /* driver needs to write the ta in the template; ta is at offset 16 */
1387 bzero(template, sizeof(template)); 1331 memset(template, 0, sizeof(template));
1388 bcopy((char *)wlc->pub->cur_etheraddr.octet, template, ETHER_ADDR_LEN); 1332 bcopy((char *)wlc->pub->cur_etheraddr.octet, template, ETH_ALEN);
1389 wlc_write_template_ram(wlc, (T_BA_TPL_BASE + 16), (T_RAM_ACCESS_SZ * 2), 1333 wlc_write_template_ram(wlc, (T_BA_TPL_BASE + 16), (T_RAM_ACCESS_SZ * 2),
1390 template); 1334 template);
1391} 1335}
1392 1336
1393bool wlc_aggregatable(wlc_info_t *wlc, u8 tid) 1337bool wlc_aggregatable(struct wlc_info *wlc, u8 tid)
1394{ 1338{
1395 return wlc->ampdu->ini_enable[tid]; 1339 return wlc->ampdu->ini_enable[tid];
1396} 1340}
1397 1341
1398void wlc_ampdu_shm_upd(ampdu_info_t *ampdu) 1342void wlc_ampdu_shm_upd(struct ampdu_info *ampdu)
1399{ 1343{
1400 wlc_info_t *wlc = ampdu->wlc; 1344 struct wlc_info *wlc = ampdu->wlc;
1401 1345
1402 /* Extend ucode internal watchdog timer to match larger received frames */ 1346 /* Extend ucode internal watchdog timer to match larger received frames */
1403 if ((ampdu->rx_factor & HT_PARAMS_RX_FACTOR_MASK) == 1347 if ((ampdu->rx_factor & HT_PARAMS_RX_FACTOR_MASK) ==
diff --git a/drivers/staging/brcm80211/sys/wlc_ampdu.h b/drivers/staging/brcm80211/sys/wlc_ampdu.h
index c721b16cc706..03457f63f2ab 100644
--- a/drivers/staging/brcm80211/sys/wlc_ampdu.h
+++ b/drivers/staging/brcm80211/sys/wlc_ampdu.h
@@ -17,24 +17,20 @@
17#ifndef _wlc_ampdu_h_ 17#ifndef _wlc_ampdu_h_
18#define _wlc_ampdu_h_ 18#define _wlc_ampdu_h_
19 19
20extern ampdu_info_t *wlc_ampdu_attach(wlc_info_t *wlc); 20extern struct ampdu_info *wlc_ampdu_attach(struct wlc_info *wlc);
21extern void wlc_ampdu_detach(ampdu_info_t *ampdu); 21extern void wlc_ampdu_detach(struct ampdu_info *ampdu);
22extern bool wlc_ampdu_cap(ampdu_info_t *ampdu); 22extern bool wlc_ampdu_cap(struct ampdu_info *ampdu);
23extern int wlc_ampdu_set(ampdu_info_t *ampdu, bool on); 23extern int wlc_ampdu_set(struct ampdu_info *ampdu, bool on);
24extern int wlc_sendampdu(ampdu_info_t *ampdu, wlc_txq_info_t *qi, void **aggp, 24extern int wlc_sendampdu(struct ampdu_info *ampdu, wlc_txq_info_t *qi,
25 int prec); 25 struct sk_buff **aggp, int prec);
26extern void wlc_ampdu_dotxstatus(ampdu_info_t *ampdu, struct scb *scb, void *p, 26extern void wlc_ampdu_dotxstatus(struct ampdu_info *ampdu, struct scb *scb,
27 tx_status_t *txs); 27 struct sk_buff *p, tx_status_t *txs);
28extern void wlc_ampdu_reset(ampdu_info_t *ampdu); 28extern void wlc_ampdu_reset(struct ampdu_info *ampdu);
29extern void wlc_ampdu_macaddr_upd(wlc_info_t *wlc); 29extern void wlc_ampdu_macaddr_upd(struct wlc_info *wlc);
30extern void wlc_ampdu_shm_upd(ampdu_info_t *ampdu); 30extern void wlc_ampdu_shm_upd(struct ampdu_info *ampdu);
31 31
32extern u8 wlc_ampdu_null_delim_cnt(ampdu_info_t *ampdu, struct scb *scb, 32extern u8 wlc_ampdu_null_delim_cnt(struct ampdu_info *ampdu, struct scb *scb,
33 ratespec_t rspec, int phylen); 33 ratespec_t rspec, int phylen);
34extern void scb_ampdu_cleanup(ampdu_info_t *ampdu, struct scb *scb); 34extern void scb_ampdu_cleanup(struct ampdu_info *ampdu, struct scb *scb);
35#ifdef WLC_HIGH_ONLY
36extern void wlc_ampdu_txstatus_complete(ampdu_info_t *ampdu, u32 s1,
37 u32 s2);
38#endif
39 35
40#endif /* _wlc_ampdu_h_ */ 36#endif /* _wlc_ampdu_h_ */
diff --git a/drivers/staging/brcm80211/sys/wlc_antsel.c b/drivers/staging/brcm80211/sys/wlc_antsel.c
index 5ff8831d2fa8..402ddf8f3371 100644
--- a/drivers/staging/brcm80211/sys/wlc_antsel.c
+++ b/drivers/staging/brcm80211/sys/wlc_antsel.c
@@ -19,18 +19,23 @@
19#ifdef WLANTSEL 19#ifdef WLANTSEL
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linuxver.h> 22#include <linux/module.h>
23#include <linux/pci.h>
23#include <bcmdefs.h> 24#include <bcmdefs.h>
24#include <osl.h> 25#include <osl.h>
25#include <bcmutils.h> 26#include <bcmutils.h>
26#include <siutils.h> 27#include <siutils.h>
27#include <wlioctl.h> 28#include <wlioctl.h>
28 29
30#include <bcmdevs.h>
31#include <sbhndpio.h>
32#include <sbhnddma.h>
29#include <d11.h> 33#include <d11.h>
30#include <wlc_rate.h> 34#include <wlc_rate.h>
31#include <wlc_key.h> 35#include <wlc_key.h>
32#include <wlc_pub.h> 36#include <wlc_pub.h>
33#include <wl_dbg.h> 37#include <wl_dbg.h>
38#include <wlc_event.h>
34#include <wlc_mac80211.h> 39#include <wlc_mac80211.h>
35#include <wlc_bmac.h> 40#include <wlc_bmac.h>
36#include <wlc_phy_hal.h> 41#include <wlc_phy_hal.h>
@@ -58,10 +63,11 @@
58#define ANT_SELCFG_DEF_2x4 0x02 /* default antenna configuration */ 63#define ANT_SELCFG_DEF_2x4 0x02 /* default antenna configuration */
59 64
60/* static functions */ 65/* static functions */
61static int wlc_antsel_cfgupd(antsel_info_t *asi, wlc_antselcfg_t *antsel); 66static int wlc_antsel_cfgupd(struct antsel_info *asi, wlc_antselcfg_t *antsel);
62static u8 wlc_antsel_id2antcfg(antsel_info_t *asi, u8 id); 67static u8 wlc_antsel_id2antcfg(struct antsel_info *asi, u8 id);
63static u16 wlc_antsel_antcfg2antsel(antsel_info_t *asi, u8 ant_cfg); 68static u16 wlc_antsel_antcfg2antsel(struct antsel_info *asi, u8 ant_cfg);
64static void wlc_antsel_init_cfg(antsel_info_t *asi, wlc_antselcfg_t *antsel, 69static void wlc_antsel_init_cfg(struct antsel_info *asi,
70 wlc_antselcfg_t *antsel,
65 bool auto_sel); 71 bool auto_sel);
66 72
67const u16 mimo_2x4_div_antselpat_tbl[] = { 73const u16 mimo_2x4_div_antselpat_tbl[] = {
@@ -88,14 +94,15 @@ const u8 mimo_2x3_div_antselid_tbl[16] = {
88 0, 0, 0, 0, 0, 0, 0, 0 /* pat to antselid */ 94 0, 0, 0, 0, 0, 0, 0, 0 /* pat to antselid */
89}; 95};
90 96
91antsel_info_t *wlc_antsel_attach(wlc_info_t *wlc, osl_t *osh, 97struct antsel_info *wlc_antsel_attach(struct wlc_info *wlc,
92 wlc_pub_t *pub, 98 struct osl_info *osh,
93 wlc_hw_info_t *wlc_hw) { 99 struct wlc_pub *pub,
94 antsel_info_t *asi; 100 struct wlc_hw_info *wlc_hw) {
101 struct antsel_info *asi;
95 102
96 asi = kzalloc(sizeof(antsel_info_t), GFP_ATOMIC); 103 asi = kzalloc(sizeof(struct antsel_info), GFP_ATOMIC);
97 if (!asi) { 104 if (!asi) {
98 WL_ERROR(("wl%d: wlc_antsel_attach: out of mem\n", pub->unit)); 105 WL_ERROR("wl%d: wlc_antsel_attach: out of mem\n", pub->unit);
99 return NULL; 106 return NULL;
100 } 107 }
101 108
@@ -124,7 +131,7 @@ antsel_info_t *wlc_antsel_attach(wlc_info_t *wlc, osl_t *osh,
124 asi->antsel_avail = false; 131 asi->antsel_avail = false;
125 } else { 132 } else {
126 asi->antsel_avail = false; 133 asi->antsel_avail = false;
127 WL_ERROR(("wlc_antsel_attach: 2o3 board cfg invalid\n")); 134 WL_ERROR("wlc_antsel_attach: 2o3 board cfg invalid\n");
128 ASSERT(0); 135 ASSERT(0);
129 } 136 }
130 break; 137 break;
@@ -152,7 +159,7 @@ antsel_info_t *wlc_antsel_attach(wlc_info_t *wlc, osl_t *osh,
152 return asi; 159 return asi;
153} 160}
154 161
155void wlc_antsel_detach(antsel_info_t *asi) 162void wlc_antsel_detach(struct antsel_info *asi)
156{ 163{
157 if (!asi) 164 if (!asi)
158 return; 165 return;
@@ -160,7 +167,7 @@ void wlc_antsel_detach(antsel_info_t *asi)
160 kfree(asi); 167 kfree(asi);
161} 168}
162 169
163void wlc_antsel_init(antsel_info_t *asi) 170void wlc_antsel_init(struct antsel_info *asi)
164{ 171{
165 if ((asi->antsel_type == ANTSEL_2x3) || 172 if ((asi->antsel_type == ANTSEL_2x3) ||
166 (asi->antsel_type == ANTSEL_2x4)) 173 (asi->antsel_type == ANTSEL_2x4))
@@ -169,7 +176,7 @@ void wlc_antsel_init(antsel_info_t *asi)
169 176
170/* boardlevel antenna selection: init antenna selection structure */ 177/* boardlevel antenna selection: init antenna selection structure */
171static void 178static void
172wlc_antsel_init_cfg(antsel_info_t *asi, wlc_antselcfg_t *antsel, 179wlc_antsel_init_cfg(struct antsel_info *asi, wlc_antselcfg_t *antsel,
173 bool auto_sel) 180 bool auto_sel)
174{ 181{
175 if (asi->antsel_type == ANTSEL_2x3) { 182 if (asi->antsel_type == ANTSEL_2x3) {
@@ -200,7 +207,7 @@ wlc_antsel_init_cfg(antsel_info_t *asi, wlc_antselcfg_t *antsel,
200} 207}
201 208
202void BCMFASTPATH 209void BCMFASTPATH
203wlc_antsel_antcfg_get(antsel_info_t *asi, bool usedef, bool sel, 210wlc_antsel_antcfg_get(struct antsel_info *asi, bool usedef, bool sel,
204 u8 antselid, u8 fbantselid, u8 *antcfg, 211 u8 antselid, u8 fbantselid, u8 *antcfg,
205 u8 *fbantcfg) 212 u8 *fbantcfg)
206{ 213{
@@ -232,7 +239,7 @@ wlc_antsel_antcfg_get(antsel_info_t *asi, bool usedef, bool sel,
232} 239}
233 240
234/* boardlevel antenna selection: convert mimo_antsel (ucode interface) to id */ 241/* boardlevel antenna selection: convert mimo_antsel (ucode interface) to id */
235u8 wlc_antsel_antsel2id(antsel_info_t *asi, u16 antsel) 242u8 wlc_antsel_antsel2id(struct antsel_info *asi, u16 antsel)
236{ 243{
237 u8 antselid = 0; 244 u8 antselid = 0;
238 245
@@ -251,7 +258,7 @@ u8 wlc_antsel_antsel2id(antsel_info_t *asi, u16 antsel)
251} 258}
252 259
253/* boardlevel antenna selection: convert id to ant_cfg */ 260/* boardlevel antenna selection: convert id to ant_cfg */
254static u8 wlc_antsel_id2antcfg(antsel_info_t *asi, u8 id) 261static u8 wlc_antsel_id2antcfg(struct antsel_info *asi, u8 id)
255{ 262{
256 u8 antcfg = ANT_SELCFG_DEF_2x2; 263 u8 antcfg = ANT_SELCFG_DEF_2x2;
257 264
@@ -270,7 +277,7 @@ static u8 wlc_antsel_id2antcfg(antsel_info_t *asi, u8 id)
270} 277}
271 278
272/* boardlevel antenna selection: convert ant_cfg to mimo_antsel (ucode interface) */ 279/* boardlevel antenna selection: convert ant_cfg to mimo_antsel (ucode interface) */
273static u16 wlc_antsel_antcfg2antsel(antsel_info_t *asi, u8 ant_cfg) 280static u16 wlc_antsel_antcfg2antsel(struct antsel_info *asi, u8 ant_cfg)
274{ 281{
275 u8 idx = WLC_ANTIDX_11N(WLC_ANTSEL_11N(ant_cfg)); 282 u8 idx = WLC_ANTIDX_11N(WLC_ANTSEL_11N(ant_cfg));
276 u16 mimo_antsel = 0; 283 u16 mimo_antsel = 0;
@@ -290,9 +297,9 @@ static u16 wlc_antsel_antcfg2antsel(antsel_info_t *asi, u8 ant_cfg)
290} 297}
291 298
292/* boardlevel antenna selection: ucode interface control */ 299/* boardlevel antenna selection: ucode interface control */
293static int wlc_antsel_cfgupd(antsel_info_t *asi, wlc_antselcfg_t *antsel) 300static int wlc_antsel_cfgupd(struct antsel_info *asi, wlc_antselcfg_t *antsel)
294{ 301{
295 wlc_info_t *wlc = asi->wlc; 302 struct wlc_info *wlc = asi->wlc;
296 u8 ant_cfg; 303 u8 ant_cfg;
297 u16 mimo_antsel; 304 u16 mimo_antsel;
298 305
diff --git a/drivers/staging/brcm80211/sys/wlc_antsel.h b/drivers/staging/brcm80211/sys/wlc_antsel.h
index 1d048bbea946..8875b5848665 100644
--- a/drivers/staging/brcm80211/sys/wlc_antsel.h
+++ b/drivers/staging/brcm80211/sys/wlc_antsel.h
@@ -16,13 +16,15 @@
16 16
17#ifndef _wlc_antsel_h_ 17#ifndef _wlc_antsel_h_
18#define _wlc_antsel_h_ 18#define _wlc_antsel_h_
19extern antsel_info_t *wlc_antsel_attach(wlc_info_t *wlc, osl_t *osh, 19extern struct antsel_info *wlc_antsel_attach(struct wlc_info *wlc,
20 wlc_pub_t *pub, 20 struct osl_info *osh,
21 wlc_hw_info_t *wlc_hw); 21 struct wlc_pub *pub,
22extern void wlc_antsel_detach(antsel_info_t *asi); 22 struct wlc_hw_info *wlc_hw);
23extern void wlc_antsel_init(antsel_info_t *asi); 23extern void wlc_antsel_detach(struct antsel_info *asi);
24extern void wlc_antsel_antcfg_get(antsel_info_t *asi, bool usedef, bool sel, 24extern void wlc_antsel_init(struct antsel_info *asi);
25extern void wlc_antsel_antcfg_get(struct antsel_info *asi, bool usedef,
26 bool sel,
25 u8 id, u8 fbid, u8 *antcfg, 27 u8 id, u8 fbid, u8 *antcfg,
26 u8 *fbantcfg); 28 u8 *fbantcfg);
27extern u8 wlc_antsel_antsel2id(antsel_info_t *asi, u16 antsel); 29extern u8 wlc_antsel_antsel2id(struct antsel_info *asi, u16 antsel);
28#endif /* _wlc_antsel_h_ */ 30#endif /* _wlc_antsel_h_ */
diff --git a/drivers/staging/brcm80211/sys/wlc_bmac.c b/drivers/staging/brcm80211/sys/wlc_bmac.c
index b70f9d099233..69f600affa46 100644
--- a/drivers/staging/brcm80211/sys/wlc_bmac.c
+++ b/drivers/staging/brcm80211/sys/wlc_bmac.c
@@ -14,13 +14,13 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#ifndef WLC_LOW
18#error "This file needs WLC_LOW"
19#endif
20 17
21#include <linux/kernel.h> 18#include <linux/kernel.h>
22#include <wlc_cfg.h> 19#include <wlc_cfg.h>
23#include <linuxver.h> 20#include <linux/module.h>
21#include <linux/pci.h>
22#include <linux/netdevice.h>
23#include <linux/etherdevice.h>
24#include <bcmdefs.h> 24#include <bcmdefs.h>
25#include <osl.h> 25#include <osl.h>
26#include <proto/802.11.h> 26#include <proto/802.11.h>
@@ -42,12 +42,14 @@
42#include <wlc_channel.h> 42#include <wlc_channel.h>
43#include <bcmsrom.h> 43#include <bcmsrom.h>
44#include <wlc_key.h> 44#include <wlc_key.h>
45#include <bcmdevs.h>
45/* BMAC_NOTE: a WLC_HIGH compile include of wlc.h adds in more structures and type 46/* BMAC_NOTE: a WLC_HIGH compile include of wlc.h adds in more structures and type
46 * dependencies. Need to include these to files to allow a clean include of wlc.h 47 * dependencies. Need to include these to files to allow a clean include of wlc.h
47 * with WLC_HIGH defined. 48 * with WLC_HIGH defined.
48 * At some point we may be able to skip the include of wlc.h and instead just 49 * At some point we may be able to skip the include of wlc.h and instead just
49 * define a stub wlc_info and band struct to allow rpc calls to get the rpc handle. 50 * define a stub wlc_info and band struct to allow rpc calls to get the rpc handle.
50 */ 51 */
52#include <wlc_event.h>
51#include <wlc_mac80211.h> 53#include <wlc_mac80211.h>
52#include <wlc_bmac.h> 54#include <wlc_bmac.h>
53#include <wlc_phy_shim.h> 55#include <wlc_phy_shim.h>
@@ -55,9 +57,6 @@
55#include <wl_export.h> 57#include <wl_export.h>
56#include "wl_ucode.h" 58#include "wl_ucode.h"
57#include "d11ucode_ext.h" 59#include "d11ucode_ext.h"
58#ifdef BCMSDIO
59#include <bcmsdh.h>
60#endif
61#include <bcmotp.h> 60#include <bcmotp.h>
62 61
63/* BMAC_NOTE: With WLC_HIGH defined, some fns in this file make calls to high level 62/* BMAC_NOTE: With WLC_HIGH defined, some fns in this file make calls to high level
@@ -69,6 +68,7 @@
69#include <pcie_core.h> 68#include <pcie_core.h>
70 69
71#include <wlc_alloc.h> 70#include <wlc_alloc.h>
71#include <wl_dbg.h>
72 72
73#define TIMER_INTERVAL_WATCHDOG_BMAC 1000 /* watchdog timer, in unit of ms */ 73#define TIMER_INTERVAL_WATCHDOG_BMAC 1000 /* watchdog timer, in unit of ms */
74 74
@@ -113,64 +113,65 @@ static u16 xmtfifo_sz[][NFIFO] = {
113 {9, 58, 22, 14, 14, 5}, /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */ 113 {9, 58, 22, 14, 14, 5}, /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */
114}; 114};
115 115
116static void wlc_clkctl_clk(wlc_hw_info_t *wlc, uint mode); 116static void wlc_clkctl_clk(struct wlc_hw_info *wlc, uint mode);
117static void wlc_coreinit(wlc_info_t *wlc); 117static void wlc_coreinit(struct wlc_info *wlc);
118 118
119/* used by wlc_wakeucode_init() */ 119/* used by wlc_wakeucode_init() */
120static void wlc_write_inits(wlc_hw_info_t *wlc_hw, const d11init_t *inits); 120static void wlc_write_inits(struct wlc_hw_info *wlc_hw, const d11init_t *inits);
121static void wlc_ucode_write(wlc_hw_info_t *wlc_hw, const u32 ucode[], 121static void wlc_ucode_write(struct wlc_hw_info *wlc_hw, const u32 ucode[],
122 const uint nbytes); 122 const uint nbytes);
123static void wlc_ucode_download(wlc_hw_info_t *wlc); 123static void wlc_ucode_download(struct wlc_hw_info *wlc);
124static void wlc_ucode_txant_set(wlc_hw_info_t *wlc_hw); 124static void wlc_ucode_txant_set(struct wlc_hw_info *wlc_hw);
125 125
126/* used by wlc_dpc() */ 126/* used by wlc_dpc() */
127static bool wlc_bmac_dotxstatus(wlc_hw_info_t *wlc, tx_status_t *txs, 127static bool wlc_bmac_dotxstatus(struct wlc_hw_info *wlc, tx_status_t *txs,
128 u32 s2); 128 u32 s2);
129static bool wlc_bmac_txstatus_corerev4(wlc_hw_info_t *wlc); 129static bool wlc_bmac_txstatus_corerev4(struct wlc_hw_info *wlc);
130static bool wlc_bmac_txstatus(wlc_hw_info_t *wlc, bool bound, bool *fatal); 130static bool wlc_bmac_txstatus(struct wlc_hw_info *wlc, bool bound, bool *fatal);
131static bool wlc_bmac_recv(wlc_hw_info_t *wlc_hw, uint fifo, bool bound); 131static bool wlc_bmac_recv(struct wlc_hw_info *wlc_hw, uint fifo, bool bound);
132 132
133/* used by wlc_down() */ 133/* used by wlc_down() */
134static void wlc_flushqueues(wlc_info_t *wlc); 134static void wlc_flushqueues(struct wlc_info *wlc);
135 135
136static void wlc_write_mhf(wlc_hw_info_t *wlc_hw, u16 *mhfs); 136static void wlc_write_mhf(struct wlc_hw_info *wlc_hw, u16 *mhfs);
137static void wlc_mctrl_reset(wlc_hw_info_t *wlc_hw); 137static void wlc_mctrl_reset(struct wlc_hw_info *wlc_hw);
138static void wlc_corerev_fifofixup(wlc_hw_info_t *wlc_hw); 138static void wlc_corerev_fifofixup(struct wlc_hw_info *wlc_hw);
139 139
140/* Low Level Prototypes */ 140/* Low Level Prototypes */
141static u16 wlc_bmac_read_objmem(wlc_hw_info_t *wlc_hw, uint offset, 141static u16 wlc_bmac_read_objmem(struct wlc_hw_info *wlc_hw, uint offset,
142 u32 sel); 142 u32 sel);
143static void wlc_bmac_write_objmem(wlc_hw_info_t *wlc_hw, uint offset, u16 v, 143static void wlc_bmac_write_objmem(struct wlc_hw_info *wlc_hw, uint offset,
144 u32 sel); 144 u16 v, u32 sel);
145static bool wlc_bmac_attach_dmapio(wlc_info_t *wlc, uint j, bool wme); 145static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme);
146static void wlc_bmac_detach_dmapio(wlc_hw_info_t *wlc_hw); 146static void wlc_bmac_detach_dmapio(struct wlc_hw_info *wlc_hw);
147static void wlc_ucode_bsinit(wlc_hw_info_t *wlc_hw); 147static void wlc_ucode_bsinit(struct wlc_hw_info *wlc_hw);
148static bool wlc_validboardtype(wlc_hw_info_t *wlc); 148static bool wlc_validboardtype(struct wlc_hw_info *wlc);
149static bool wlc_isgoodchip(wlc_hw_info_t *wlc_hw); 149static bool wlc_isgoodchip(struct wlc_hw_info *wlc_hw);
150static char *wlc_get_macaddr(wlc_hw_info_t *wlc_hw); 150static char *wlc_get_macaddr(struct wlc_hw_info *wlc_hw);
151static void wlc_mhfdef(wlc_info_t *wlc, u16 *mhfs, u16 mhf2_init); 151static void wlc_mhfdef(struct wlc_info *wlc, u16 *mhfs, u16 mhf2_init);
152static void wlc_mctrl_write(wlc_hw_info_t *wlc_hw); 152static void wlc_mctrl_write(struct wlc_hw_info *wlc_hw);
153static void wlc_ucode_mute_override_set(wlc_hw_info_t *wlc_hw); 153static void wlc_ucode_mute_override_set(struct wlc_hw_info *wlc_hw);
154static void wlc_ucode_mute_override_clear(wlc_hw_info_t *wlc_hw); 154static void wlc_ucode_mute_override_clear(struct wlc_hw_info *wlc_hw);
155static u32 wlc_wlintrsoff(wlc_info_t *wlc); 155static u32 wlc_wlintrsoff(struct wlc_info *wlc);
156static void wlc_wlintrsrestore(wlc_info_t *wlc, u32 macintmask); 156static void wlc_wlintrsrestore(struct wlc_info *wlc, u32 macintmask);
157static void wlc_gpio_init(wlc_info_t *wlc); 157static void wlc_gpio_init(struct wlc_info *wlc);
158static void wlc_write_hw_bcntemplate0(wlc_hw_info_t *wlc_hw, void *bcn, 158static void wlc_write_hw_bcntemplate0(struct wlc_hw_info *wlc_hw, void *bcn,
159 int len); 159 int len);
160static void wlc_write_hw_bcntemplate1(wlc_hw_info_t *wlc_hw, void *bcn, 160static void wlc_write_hw_bcntemplate1(struct wlc_hw_info *wlc_hw, void *bcn,
161 int len); 161 int len);
162static void wlc_bmac_bsinit(wlc_info_t *wlc, chanspec_t chanspec); 162static void wlc_bmac_bsinit(struct wlc_info *wlc, chanspec_t chanspec);
163static u32 wlc_setband_inact(wlc_info_t *wlc, uint bandunit); 163static u32 wlc_setband_inact(struct wlc_info *wlc, uint bandunit);
164static void wlc_bmac_setband(wlc_hw_info_t *wlc_hw, uint bandunit, 164static void wlc_bmac_setband(struct wlc_hw_info *wlc_hw, uint bandunit,
165 chanspec_t chanspec); 165 chanspec_t chanspec);
166static void wlc_bmac_update_slot_timing(wlc_hw_info_t *wlc_hw, bool shortslot); 166static void wlc_bmac_update_slot_timing(struct wlc_hw_info *wlc_hw,
167static void wlc_upd_ofdm_pctl1_table(wlc_hw_info_t *wlc_hw); 167 bool shortslot);
168static u16 wlc_bmac_ofdm_ratetable_offset(wlc_hw_info_t *wlc_hw, 168static void wlc_upd_ofdm_pctl1_table(struct wlc_hw_info *wlc_hw);
169static u16 wlc_bmac_ofdm_ratetable_offset(struct wlc_hw_info *wlc_hw,
169 u8 rate); 170 u8 rate);
170 171
171/* === Low Level functions === */ 172/* === Low Level functions === */
172 173
173void wlc_bmac_set_shortslot(wlc_hw_info_t *wlc_hw, bool shortslot) 174void wlc_bmac_set_shortslot(struct wlc_hw_info *wlc_hw, bool shortslot)
174{ 175{
175 wlc_hw->shortslot = shortslot; 176 wlc_hw->shortslot = shortslot;
176 177
@@ -186,9 +187,10 @@ void wlc_bmac_set_shortslot(wlc_hw_info_t *wlc_hw, bool shortslot)
186 * or shortslot 11g (9us slots) 187 * or shortslot 11g (9us slots)
187 * The PSM needs to be suspended for this call. 188 * The PSM needs to be suspended for this call.
188 */ 189 */
189static void wlc_bmac_update_slot_timing(wlc_hw_info_t *wlc_hw, bool shortslot) 190static void wlc_bmac_update_slot_timing(struct wlc_hw_info *wlc_hw,
191 bool shortslot)
190{ 192{
191 osl_t *osh; 193 struct osl_info *osh;
192 d11regs_t *regs; 194 d11regs_t *regs;
193 195
194 osh = wlc_hw->osh; 196 osh = wlc_hw->osh;
@@ -205,7 +207,7 @@ static void wlc_bmac_update_slot_timing(wlc_hw_info_t *wlc_hw, bool shortslot)
205 } 207 }
206} 208}
207 209
208static void WLBANDINITFN(wlc_ucode_bsinit) (wlc_hw_info_t *wlc_hw) 210static void WLBANDINITFN(wlc_ucode_bsinit) (struct wlc_hw_info *wlc_hw)
209{ 211{
210 /* init microcode host flags */ 212 /* init microcode host flags */
211 wlc_write_mhf(wlc_hw, wlc_hw->band->mhfs); 213 wlc_write_mhf(wlc_hw, wlc_hw->band->mhfs);
@@ -215,30 +217,32 @@ static void WLBANDINITFN(wlc_ucode_bsinit) (wlc_hw_info_t *wlc_hw)
215 if (WLCISNPHY(wlc_hw->band)) { 217 if (WLCISNPHY(wlc_hw->band)) {
216 wlc_write_inits(wlc_hw, d11n0bsinitvals16); 218 wlc_write_inits(wlc_hw, d11n0bsinitvals16);
217 } else { 219 } else {
218 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n", 220 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
219 __func__, wlc_hw->unit, wlc_hw->corerev)); 221 __func__, wlc_hw->unit, wlc_hw->corerev);
220 } 222 }
221 } else { 223 } else {
222 if (D11REV_IS(wlc_hw->corerev, 24)) { 224 if (D11REV_IS(wlc_hw->corerev, 24)) {
223 if (WLCISLCNPHY(wlc_hw->band)) { 225 if (WLCISLCNPHY(wlc_hw->band)) {
224 wlc_write_inits(wlc_hw, d11lcn0bsinitvals24); 226 wlc_write_inits(wlc_hw, d11lcn0bsinitvals24);
225 } else 227 } else
226 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n", __func__, wlc_hw->unit, wlc_hw->corerev)); 228 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
229 __func__, wlc_hw->unit,
230 wlc_hw->corerev);
227 } else { 231 } else {
228 WL_ERROR(("%s: wl%d: unsupported corerev %d\n", 232 WL_ERROR("%s: wl%d: unsupported corerev %d\n",
229 __func__, wlc_hw->unit, wlc_hw->corerev)); 233 __func__, wlc_hw->unit, wlc_hw->corerev);
230 } 234 }
231 } 235 }
232} 236}
233 237
234/* switch to new band but leave it inactive */ 238/* switch to new band but leave it inactive */
235static u32 WLBANDINITFN(wlc_setband_inact) (wlc_info_t *wlc, uint bandunit) 239static u32 WLBANDINITFN(wlc_setband_inact) (struct wlc_info *wlc, uint bandunit)
236{ 240{
237 wlc_hw_info_t *wlc_hw = wlc->hw; 241 struct wlc_hw_info *wlc_hw = wlc->hw;
238 u32 macintmask; 242 u32 macintmask;
239 u32 tmp; 243 u32 tmp;
240 244
241 WL_TRACE(("wl%d: wlc_setband_inact\n", wlc_hw->unit)); 245 WL_TRACE("wl%d: wlc_setband_inact\n", wlc_hw->unit);
242 246
243 ASSERT(bandunit != wlc_hw->band->bandunit); 247 ASSERT(bandunit != wlc_hw->band->bandunit);
244 ASSERT(si_iscoreup(wlc_hw->sih)); 248 ASSERT(si_iscoreup(wlc_hw->sih));
@@ -269,24 +273,24 @@ static u32 WLBANDINITFN(wlc_setband_inact) (wlc_info_t *wlc, uint bandunit)
269 * Param 'bound' indicates max. # frames to process before break out. 273 * Param 'bound' indicates max. # frames to process before break out.
270 */ 274 */
271static bool BCMFASTPATH 275static bool BCMFASTPATH
272wlc_bmac_recv(wlc_hw_info_t *wlc_hw, uint fifo, bool bound) 276wlc_bmac_recv(struct wlc_hw_info *wlc_hw, uint fifo, bool bound)
273{ 277{
274 void *p; 278 struct sk_buff *p;
275 void *head = NULL; 279 struct sk_buff *head = NULL;
276 void *tail = NULL; 280 struct sk_buff *tail = NULL;
277 uint n = 0; 281 uint n = 0;
278 uint bound_limit = bound ? wlc_hw->wlc->pub->tunables->rxbnd : -1; 282 uint bound_limit = bound ? wlc_hw->wlc->pub->tunables->rxbnd : -1;
279 u32 tsf_h, tsf_l; 283 u32 tsf_h, tsf_l;
280 wlc_d11rxhdr_t *wlc_rxhdr = NULL; 284 wlc_d11rxhdr_t *wlc_rxhdr = NULL;
281 285
282 WL_TRACE(("wl%d: %s\n", wlc_hw->unit, __func__)); 286 WL_TRACE("wl%d: %s\n", wlc_hw->unit, __func__);
283 /* gather received frames */ 287 /* gather received frames */
284 while ((p = dma_rx(wlc_hw->di[fifo]))) { 288 while ((p = dma_rx(wlc_hw->di[fifo]))) {
285 289
286 if (!tail) 290 if (!tail)
287 head = tail = p; 291 head = tail = p;
288 else { 292 else {
289 PKTSETLINK(tail, p); 293 tail->prev = p;
290 tail = p; 294 tail = p;
291 } 295 }
292 296
@@ -303,11 +307,11 @@ wlc_bmac_recv(wlc_hw_info_t *wlc_hw, uint fifo, bool bound)
303 307
304 /* process each frame */ 308 /* process each frame */
305 while ((p = head) != NULL) { 309 while ((p = head) != NULL) {
306 head = PKTLINK(head); 310 head = head->prev;
307 PKTSETLINK(p, NULL); 311 p->prev = NULL;
308 312
309 /* record the tsf_l in wlc_rxd11hdr */ 313 /* record the tsf_l in wlc_rxd11hdr */
310 wlc_rxhdr = (wlc_d11rxhdr_t *) PKTDATA(p); 314 wlc_rxhdr = (wlc_d11rxhdr_t *) p->data;
311 wlc_rxhdr->tsf_l = htol32(tsf_l); 315 wlc_rxhdr->tsf_l = htol32(tsf_l);
312 316
313 /* compute the RSSI from d11rxhdr and record it in wlc_rxd11hr */ 317 /* compute the RSSI from d11rxhdr and record it in wlc_rxd11hr */
@@ -323,15 +327,15 @@ wlc_bmac_recv(wlc_hw_info_t *wlc_hw, uint fifo, bool bound)
323 * Return true if another dpc needs to be re-scheduled. false otherwise. 327 * Return true if another dpc needs to be re-scheduled. false otherwise.
324 * Param 'bounded' indicates if applicable loops should be bounded. 328 * Param 'bounded' indicates if applicable loops should be bounded.
325 */ 329 */
326bool BCMFASTPATH wlc_dpc(wlc_info_t *wlc, bool bounded) 330bool BCMFASTPATH wlc_dpc(struct wlc_info *wlc, bool bounded)
327{ 331{
328 u32 macintstatus; 332 u32 macintstatus;
329 wlc_hw_info_t *wlc_hw = wlc->hw; 333 struct wlc_hw_info *wlc_hw = wlc->hw;
330 d11regs_t *regs = wlc_hw->regs; 334 d11regs_t *regs = wlc_hw->regs;
331 bool fatal = false; 335 bool fatal = false;
332 336
333 if (DEVICEREMOVED(wlc)) { 337 if (DEVICEREMOVED(wlc)) {
334 WL_ERROR(("wl%d: %s: dead chip\n", wlc_hw->unit, __func__)); 338 WL_ERROR("wl%d: %s: dead chip\n", wlc_hw->unit, __func__);
335 wl_down(wlc->wl); 339 wl_down(wlc->wl);
336 return false; 340 return false;
337 } 341 }
@@ -340,8 +344,8 @@ bool BCMFASTPATH wlc_dpc(wlc_info_t *wlc, bool bounded)
340 macintstatus = wlc->macintstatus; 344 macintstatus = wlc->macintstatus;
341 wlc->macintstatus = 0; 345 wlc->macintstatus = 0;
342 346
343 WL_TRACE(("wl%d: wlc_dpc: macintstatus 0x%x\n", wlc_hw->unit, 347 WL_TRACE("wl%d: wlc_dpc: macintstatus 0x%x\n",
344 macintstatus)); 348 wlc_hw->unit, macintstatus);
345 349
346 if (macintstatus & MI_PRQ) { 350 if (macintstatus & MI_PRQ) {
347 /* Process probe request FIFO */ 351 /* Process probe request FIFO */
@@ -364,7 +368,7 @@ bool BCMFASTPATH wlc_dpc(wlc_info_t *wlc, bool bounded)
364 if (wlc_bmac_txstatus(wlc->hw, bounded, &fatal)) 368 if (wlc_bmac_txstatus(wlc->hw, bounded, &fatal))
365 wlc->macintstatus |= MI_TFS; 369 wlc->macintstatus |= MI_TFS;
366 if (fatal) { 370 if (fatal) {
367 WL_ERROR(("MI_TFS: fatal\n")); 371 WL_ERROR("MI_TFS: fatal\n");
368 goto fatal; 372 goto fatal;
369 } 373 }
370 } 374 }
@@ -374,7 +378,7 @@ bool BCMFASTPATH wlc_dpc(wlc_info_t *wlc, bool bounded)
374 378
375 /* ATIM window end */ 379 /* ATIM window end */
376 if (macintstatus & MI_ATIMWINEND) { 380 if (macintstatus & MI_ATIMWINEND) {
377 WL_TRACE(("wlc_isr: end of ATIM window\n")); 381 WL_TRACE("wlc_isr: end of ATIM window\n");
378 382
379 OR_REG(wlc_hw->osh, &regs->maccommand, wlc->qvalid); 383 OR_REG(wlc_hw->osh, &regs->maccommand, wlc->qvalid);
380 wlc->qvalid = 0; 384 wlc->qvalid = 0;
@@ -395,7 +399,7 @@ bool BCMFASTPATH wlc_dpc(wlc_info_t *wlc, bool bounded)
395 /* TX FIFO suspend/flush completion */ 399 /* TX FIFO suspend/flush completion */
396 if (macintstatus & MI_TXSTOP) { 400 if (macintstatus & MI_TXSTOP) {
397 if (wlc_bmac_tx_fifo_suspended(wlc_hw, TX_DATA_FIFO)) { 401 if (wlc_bmac_tx_fifo_suspended(wlc_hw, TX_DATA_FIFO)) {
398 /* WL_ERROR(("dpc: fifo_suspend_comlete\n")); */ 402 /* WL_ERROR("dpc: fifo_suspend_comlete\n"); */
399 } 403 }
400 } 404 }
401 405
@@ -405,11 +409,12 @@ bool BCMFASTPATH wlc_dpc(wlc_info_t *wlc, bool bounded)
405 } 409 }
406 410
407 if (macintstatus & MI_GP0) { 411 if (macintstatus & MI_GP0) {
408 WL_ERROR(("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n", wlc_hw->unit, wlc_hw->now)); 412 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
413 wlc_hw->unit, wlc_hw->now);
409 414
410 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n", 415 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
411 __func__, CHIPID(wlc_hw->sih->chip), 416 __func__, wlc_hw->sih->chip,
412 CHIPREV(wlc_hw->sih->chiprev)); 417 wlc_hw->sih->chiprev);
413 418
414 WLCNTINCR(wlc->pub->_cnt->psmwds); 419 WLCNTINCR(wlc->pub->_cnt->psmwds);
415 420
@@ -427,7 +432,8 @@ bool BCMFASTPATH wlc_dpc(wlc_info_t *wlc, bool bounded)
427 u32 rfd = R_REG(wlc_hw->osh, &regs->phydebug) & PDBG_RFD; 432 u32 rfd = R_REG(wlc_hw->osh, &regs->phydebug) & PDBG_RFD;
428#endif 433#endif
429 434
430 WL_ERROR(("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n", wlc_hw->unit, rfd)); 435 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
436 wlc_hw->unit, rfd);
431 437
432 WLCNTINCR(wlc->pub->_cnt->rfdisable); 438 WLCNTINCR(wlc->pub->_cnt->rfdisable);
433 } 439 }
@@ -452,10 +458,10 @@ bool BCMFASTPATH wlc_dpc(wlc_info_t *wlc, bool bounded)
452/* common low-level watchdog code */ 458/* common low-level watchdog code */
453void wlc_bmac_watchdog(void *arg) 459void wlc_bmac_watchdog(void *arg)
454{ 460{
455 wlc_info_t *wlc = (wlc_info_t *) arg; 461 struct wlc_info *wlc = (struct wlc_info *) arg;
456 wlc_hw_info_t *wlc_hw = wlc->hw; 462 struct wlc_hw_info *wlc_hw = wlc->hw;
457 463
458 WL_TRACE(("wl%d: wlc_bmac_watchdog\n", wlc_hw->unit)); 464 WL_TRACE("wl%d: wlc_bmac_watchdog\n", wlc_hw->unit);
459 465
460 if (!wlc_hw->up) 466 if (!wlc_hw->up)
461 return; 467 return;
@@ -476,13 +482,13 @@ void wlc_bmac_watchdog(void *arg)
476} 482}
477 483
478void 484void
479wlc_bmac_set_chanspec(wlc_hw_info_t *wlc_hw, chanspec_t chanspec, bool mute, 485wlc_bmac_set_chanspec(struct wlc_hw_info *wlc_hw, chanspec_t chanspec,
480 struct txpwr_limits *txpwr) 486 bool mute, struct txpwr_limits *txpwr)
481{ 487{
482 uint bandunit; 488 uint bandunit;
483 489
484 WL_TRACE(("wl%d: wlc_bmac_set_chanspec 0x%x\n", wlc_hw->unit, 490 WL_TRACE("wl%d: wlc_bmac_set_chanspec 0x%x\n",
485 chanspec)); 491 wlc_hw->unit, chanspec);
486 492
487 wlc_hw->chanspec = chanspec; 493 wlc_hw->chanspec = chanspec;
488 494
@@ -520,7 +526,8 @@ wlc_bmac_set_chanspec(wlc_hw_info_t *wlc_hw, chanspec_t chanspec, bool mute,
520 } 526 }
521} 527}
522 528
523int wlc_bmac_revinfo_get(wlc_hw_info_t *wlc_hw, wlc_bmac_revinfo_t *revinfo) 529int wlc_bmac_revinfo_get(struct wlc_hw_info *wlc_hw,
530 wlc_bmac_revinfo_t *revinfo)
524{ 531{
525 si_t *sih = wlc_hw->sih; 532 si_t *sih = wlc_hw->sih;
526 uint idx; 533 uint idx;
@@ -558,20 +565,20 @@ int wlc_bmac_revinfo_get(wlc_hw_info_t *wlc_hw, wlc_bmac_revinfo_t *revinfo)
558 return 0; 565 return 0;
559} 566}
560 567
561int wlc_bmac_state_get(wlc_hw_info_t *wlc_hw, wlc_bmac_state_t *state) 568int wlc_bmac_state_get(struct wlc_hw_info *wlc_hw, wlc_bmac_state_t *state)
562{ 569{
563 state->machwcap = wlc_hw->machwcap; 570 state->machwcap = wlc_hw->machwcap;
564 571
565 return 0; 572 return 0;
566} 573}
567 574
568static bool wlc_bmac_attach_dmapio(wlc_info_t *wlc, uint j, bool wme) 575static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme)
569{ 576{
570 uint i; 577 uint i;
571 char name[8]; 578 char name[8];
572 /* ucode host flag 2 needed for pio mode, independent of band and fifo */ 579 /* ucode host flag 2 needed for pio mode, independent of band and fifo */
573 u16 pio_mhf2 = 0; 580 u16 pio_mhf2 = 0;
574 wlc_hw_info_t *wlc_hw = wlc->hw; 581 struct wlc_hw_info *wlc_hw = wlc->hw;
575 uint unit = wlc_hw->unit; 582 uint unit = wlc_hw->unit;
576 wlc_tunables_t *tune = wlc->pub->tunables; 583 wlc_tunables_t *tune = wlc->pub->tunables;
577 584
@@ -581,7 +588,7 @@ static bool wlc_bmac_attach_dmapio(wlc_info_t *wlc, uint j, bool wme)
581 if (wlc_hw->di[0] == 0) { /* Init FIFOs */ 588 if (wlc_hw->di[0] == 0) { /* Init FIFOs */
582 uint addrwidth; 589 uint addrwidth;
583 int dma_attach_err = 0; 590 int dma_attach_err = 0;
584 osl_t *osh = wlc_hw->osh; 591 struct osl_info *osh = wlc_hw->osh;
585 592
586 /* Find out the DMA addressing capability and let OS know 593 /* Find out the DMA addressing capability and let OS know
587 * All the channels within one DMA core have 'common-minimum' same 594 * All the channels within one DMA core have 'common-minimum' same
@@ -589,10 +596,10 @@ static bool wlc_bmac_attach_dmapio(wlc_info_t *wlc, uint j, bool wme)
589 */ 596 */
590 addrwidth = 597 addrwidth =
591 dma_addrwidth(wlc_hw->sih, DMAREG(wlc_hw, DMA_TX, 0)); 598 dma_addrwidth(wlc_hw->sih, DMAREG(wlc_hw, DMA_TX, 0));
592 OSL_DMADDRWIDTH(osh, addrwidth);
593 599
594 if (!wl_alloc_dma_resources(wlc_hw->wlc->wl, addrwidth)) { 600 if (!wl_alloc_dma_resources(wlc_hw->wlc->wl, addrwidth)) {
595 WL_ERROR(("wl%d: wlc_attach: alloc_dma_resources failed\n", unit)); 601 WL_ERROR("wl%d: wlc_attach: alloc_dma_resources failed\n",
602 unit);
596 return false; 603 return false;
597 } 604 }
598 605
@@ -665,8 +672,7 @@ static bool wlc_bmac_attach_dmapio(wlc_info_t *wlc, uint j, bool wme)
665/* Cleaner to leave this as if with AP defined */ 672/* Cleaner to leave this as if with AP defined */
666 673
667 if (dma_attach_err) { 674 if (dma_attach_err) {
668 WL_ERROR(("wl%d: wlc_attach: dma_attach failed\n", 675 WL_ERROR("wl%d: wlc_attach: dma_attach failed\n", unit);
669 unit));
670 return false; 676 return false;
671 } 677 }
672 678
@@ -684,7 +690,7 @@ static bool wlc_bmac_attach_dmapio(wlc_info_t *wlc, uint j, bool wme)
684 return true; 690 return true;
685} 691}
686 692
687static void wlc_bmac_detach_dmapio(wlc_hw_info_t *wlc_hw) 693static void wlc_bmac_detach_dmapio(struct wlc_hw_info *wlc_hw)
688{ 694{
689 uint j; 695 uint j;
690 696
@@ -702,11 +708,11 @@ static void wlc_bmac_detach_dmapio(wlc_hw_info_t *wlc_hw)
702 * initialize software state for each core and band 708 * initialize software state for each core and band
703 * put the whole chip in reset(driver down state), no clock 709 * put the whole chip in reset(driver down state), no clock
704 */ 710 */
705int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit, 711int wlc_bmac_attach(struct wlc_info *wlc, u16 vendor, u16 device, uint unit,
706 bool piomode, osl_t *osh, void *regsva, uint bustype, 712 bool piomode, struct osl_info *osh, void *regsva,
707 void *btparam) 713 uint bustype, void *btparam)
708{ 714{
709 wlc_hw_info_t *wlc_hw; 715 struct wlc_hw_info *wlc_hw;
710 d11regs_t *regs; 716 d11regs_t *regs;
711 char *macaddr = NULL; 717 char *macaddr = NULL;
712 char *vars; 718 char *vars;
@@ -715,8 +721,8 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
715 bool wme = false; 721 bool wme = false;
716 shared_phy_params_t sha_params; 722 shared_phy_params_t sha_params;
717 723
718 WL_TRACE(("wl%d: wlc_bmac_attach: vendor 0x%x device 0x%x\n", unit, 724 WL_TRACE("wl%d: wlc_bmac_attach: vendor 0x%x device 0x%x\n",
719 vendor, device)); 725 unit, vendor, device);
720 726
721 ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF); 727 ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF);
722 728
@@ -729,7 +735,7 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
729 wlc_hw->band = wlc_hw->bandstate[0]; 735 wlc_hw->band = wlc_hw->bandstate[0];
730 wlc_hw->_piomode = piomode; 736 wlc_hw->_piomode = piomode;
731 737
732 /* populate wlc_hw_info_t with default values */ 738 /* populate struct wlc_hw_info with default values */
733 wlc_bmac_info_init(wlc_hw); 739 wlc_bmac_info_init(wlc_hw);
734 740
735 /* 741 /*
@@ -740,7 +746,7 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
740 wlc_hw->sih = si_attach((uint) device, osh, regsva, bustype, btparam, 746 wlc_hw->sih = si_attach((uint) device, osh, regsva, bustype, btparam,
741 &wlc_hw->vars, &wlc_hw->vars_size); 747 &wlc_hw->vars, &wlc_hw->vars_size);
742 if (wlc_hw->sih == NULL) { 748 if (wlc_hw->sih == NULL) {
743 WL_ERROR(("wl%d: wlc_bmac_attach: si_attach failed\n", unit)); 749 WL_ERROR("wl%d: wlc_bmac_attach: si_attach failed\n", unit);
744 err = 11; 750 err = 11;
745 goto fail; 751 goto fail;
746 } 752 }
@@ -760,21 +766,22 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
760 var = getvar(vars, "vendid"); 766 var = getvar(vars, "vendid");
761 if (var) { 767 if (var) {
762 vendor = (u16) simple_strtoul(var, NULL, 0); 768 vendor = (u16) simple_strtoul(var, NULL, 0);
763 WL_ERROR(("Overriding vendor id = 0x%x\n", vendor)); 769 WL_ERROR("Overriding vendor id = 0x%x\n", vendor);
764 } 770 }
765 var = getvar(vars, "devid"); 771 var = getvar(vars, "devid");
766 if (var) { 772 if (var) {
767 u16 devid = (u16) simple_strtoul(var, NULL, 0); 773 u16 devid = (u16) simple_strtoul(var, NULL, 0);
768 if (devid != 0xffff) { 774 if (devid != 0xffff) {
769 device = devid; 775 device = devid;
770 WL_ERROR(("Overriding device id = 0x%x\n", 776 WL_ERROR("Overriding device id = 0x%x\n",
771 device)); 777 device);
772 } 778 }
773 } 779 }
774 780
775 /* verify again the device is supported */ 781 /* verify again the device is supported */
776 if (!wlc_chipmatch(vendor, device)) { 782 if (!wlc_chipmatch(vendor, device)) {
777 WL_ERROR(("wl%d: wlc_bmac_attach: Unsupported vendor/device (0x%x/0x%x)\n", unit, vendor, device)); 783 WL_ERROR("wl%d: wlc_bmac_attach: Unsupported vendor/device (0x%x/0x%x)\n",
784 unit, vendor, device);
778 err = 12; 785 err = 12;
779 goto fail; 786 goto fail;
780 } 787 }
@@ -809,7 +816,8 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
809 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS); 816 wlc_bmac_corereset(wlc_hw, WLC_USE_COREFLAGS);
810 817
811 if (!wlc_bmac_validate_chip_access(wlc_hw)) { 818 if (!wlc_bmac_validate_chip_access(wlc_hw)) {
812 WL_ERROR(("wl%d: wlc_bmac_attach: validate_chip_access failed\n", unit)); 819 WL_ERROR("wl%d: wlc_bmac_attach: validate_chip_access failed\n",
820 unit);
813 err = 14; 821 err = 14;
814 goto fail; 822 goto fail;
815 } 823 }
@@ -821,7 +829,8 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
821 j = BOARDREV_PROMOTED; 829 j = BOARDREV_PROMOTED;
822 wlc_hw->boardrev = (u16) j; 830 wlc_hw->boardrev = (u16) j;
823 if (!wlc_validboardtype(wlc_hw)) { 831 if (!wlc_validboardtype(wlc_hw)) {
824 WL_ERROR(("wl%d: wlc_bmac_attach: Unsupported Broadcom board type (0x%x)" " or revision level (0x%x)\n", unit, wlc_hw->sih->boardtype, wlc_hw->boardrev)); 832 WL_ERROR("wl%d: wlc_bmac_attach: Unsupported Broadcom board type (0x%x)" " or revision level (0x%x)\n",
833 unit, wlc_hw->sih->boardtype, wlc_hw->boardrev);
825 err = 15; 834 err = 15;
826 goto fail; 835 goto fail;
827 } 836 }
@@ -833,7 +842,7 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
833 || (wlc_hw->boardflags & BFL_NOPLLDOWN)) 842 || (wlc_hw->boardflags & BFL_NOPLLDOWN))
834 wlc_bmac_pllreq(wlc_hw, true, WLC_PLLREQ_SHARED); 843 wlc_bmac_pllreq(wlc_hw, true, WLC_PLLREQ_SHARED);
835 844
836 if ((BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) 845 if ((wlc_hw->sih->bustype == PCI_BUS)
837 && (si_pci_war16165(wlc_hw->sih))) 846 && (si_pci_war16165(wlc_hw->sih)))
838 wlc->war16165 = true; 847 wlc->war16165 = true;
839 848
@@ -844,7 +853,7 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
844 } else 853 } else
845 wlc_hw->_nbands = 1; 854 wlc_hw->_nbands = 1;
846 855
847 if ((CHIPID(wlc_hw->sih->chip) == BCM43225_CHIP_ID)) 856 if ((wlc_hw->sih->chip == BCM43225_CHIP_ID))
848 wlc_hw->_nbands = 1; 857 wlc_hw->_nbands = 1;
849 858
850 /* BMAC_NOTE: remove init of pub values when wlc_attach() unconditionally does the 859 /* BMAC_NOTE: remove init of pub values when wlc_attach() unconditionally does the
@@ -863,8 +872,8 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
863 wlc_hw->physhim = wlc_phy_shim_attach(wlc_hw, wlc->wl, wlc); 872 wlc_hw->physhim = wlc_phy_shim_attach(wlc_hw, wlc->wl, wlc);
864 873
865 if (wlc_hw->physhim == NULL) { 874 if (wlc_hw->physhim == NULL) {
866 WL_ERROR(("wl%d: wlc_bmac_attach: wlc_phy_shim_attach failed\n", 875 WL_ERROR("wl%d: wlc_bmac_attach: wlc_phy_shim_attach failed\n",
867 unit)); 876 unit);
868 err = 25; 877 err = 25;
869 goto fail; 878 goto fail;
870 } 879 }
@@ -931,7 +940,8 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
931 wlc_hw->band->pi = wlc_phy_attach(wlc_hw->phy_sh, 940 wlc_hw->band->pi = wlc_phy_attach(wlc_hw->phy_sh,
932 (void *)regs, wlc_hw->band->bandtype, vars); 941 (void *)regs, wlc_hw->band->bandtype, vars);
933 if (wlc_hw->band->pi == NULL) { 942 if (wlc_hw->band->pi == NULL) {
934 WL_ERROR(("wl%d: wlc_bmac_attach: wlc_phy_attach failed\n", unit)); 943 WL_ERROR("wl%d: wlc_bmac_attach: wlc_phy_attach failed\n",
944 unit);
935 err = 17; 945 err = 17;
936 goto fail; 946 goto fail;
937 } 947 }
@@ -961,7 +971,9 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
961 goto bad_phy; 971 goto bad_phy;
962 } else { 972 } else {
963 bad_phy: 973 bad_phy:
964 WL_ERROR(("wl%d: wlc_bmac_attach: unsupported phy type/rev (%d/%d)\n", unit, wlc_hw->band->phytype, wlc_hw->band->phyrev)); 974 WL_ERROR("wl%d: wlc_bmac_attach: unsupported phy type/rev (%d/%d)\n",
975 unit,
976 wlc_hw->band->phytype, wlc_hw->band->phyrev);
965 err = 18; 977 err = 18;
966 goto fail; 978 goto fail;
967 } 979 }
@@ -993,7 +1005,7 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
993 wlc_coredisable(wlc_hw); 1005 wlc_coredisable(wlc_hw);
994 1006
995 /* Match driver "down" state */ 1007 /* Match driver "down" state */
996 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) 1008 if (wlc_hw->sih->bustype == PCI_BUS)
997 si_pci_down(wlc_hw->sih); 1009 si_pci_down(wlc_hw->sih);
998 1010
999 /* register sb interrupt callback functions */ 1011 /* register sb interrupt callback functions */
@@ -1016,27 +1028,27 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
1016 /* init etheraddr state variables */ 1028 /* init etheraddr state variables */
1017 macaddr = wlc_get_macaddr(wlc_hw); 1029 macaddr = wlc_get_macaddr(wlc_hw);
1018 if (macaddr == NULL) { 1030 if (macaddr == NULL) {
1019 WL_ERROR(("wl%d: wlc_bmac_attach: macaddr not found\n", unit)); 1031 WL_ERROR("wl%d: wlc_bmac_attach: macaddr not found\n", unit);
1020 err = 21; 1032 err = 21;
1021 goto fail; 1033 goto fail;
1022 } 1034 }
1023 bcm_ether_atoe(macaddr, &wlc_hw->etheraddr); 1035 bcm_ether_atoe(macaddr, &wlc_hw->etheraddr);
1024 if (ETHER_ISBCAST((char *)&wlc_hw->etheraddr) || 1036 if (is_broadcast_ether_addr(wlc_hw->etheraddr.octet) ||
1025 ETHER_ISNULLADDR((char *)&wlc_hw->etheraddr)) { 1037 is_zero_ether_addr(wlc_hw->etheraddr.octet)) {
1026 WL_ERROR(("wl%d: wlc_bmac_attach: bad macaddr %s\n", unit, 1038 WL_ERROR("wl%d: wlc_bmac_attach: bad macaddr %s\n",
1027 macaddr)); 1039 unit, macaddr);
1028 err = 22; 1040 err = 22;
1029 goto fail; 1041 goto fail;
1030 } 1042 }
1031 1043
1032 WL_ERROR(("%s:: deviceid 0x%x nbands %d board 0x%x macaddr: %s\n", 1044 WL_ERROR("%s:: deviceid 0x%x nbands %d board 0x%x macaddr: %s\n",
1033 __func__, wlc_hw->deviceid, wlc_hw->_nbands, 1045 __func__, wlc_hw->deviceid, wlc_hw->_nbands,
1034 wlc_hw->sih->boardtype, macaddr)); 1046 wlc_hw->sih->boardtype, macaddr);
1035 1047
1036 return err; 1048 return err;
1037 1049
1038 fail: 1050 fail:
1039 WL_ERROR(("wl%d: wlc_bmac_attach: failed with err %d\n", unit, err)); 1051 WL_ERROR("wl%d: wlc_bmac_attach: failed with err %d\n", unit, err);
1040 return err; 1052 return err;
1041} 1053}
1042 1054
@@ -1045,9 +1057,9 @@ int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
1045 * may get overrides later in this function 1057 * may get overrides later in this function
1046 * BMAC_NOTES, move low out and resolve the dangling ones 1058 * BMAC_NOTES, move low out and resolve the dangling ones
1047 */ 1059 */
1048void wlc_bmac_info_init(wlc_hw_info_t *wlc_hw) 1060void wlc_bmac_info_init(struct wlc_hw_info *wlc_hw)
1049{ 1061{
1050 wlc_info_t *wlc = wlc_hw->wlc; 1062 struct wlc_info *wlc = wlc_hw->wlc;
1051 1063
1052 /* set default sw macintmask value */ 1064 /* set default sw macintmask value */
1053 wlc->defmacintmask = DEF_MACINTMASK; 1065 wlc->defmacintmask = DEF_MACINTMASK;
@@ -1067,11 +1079,11 @@ void wlc_bmac_info_init(wlc_hw_info_t *wlc_hw)
1067/* 1079/*
1068 * low level detach 1080 * low level detach
1069 */ 1081 */
1070int wlc_bmac_detach(wlc_info_t *wlc) 1082int wlc_bmac_detach(struct wlc_info *wlc)
1071{ 1083{
1072 uint i; 1084 uint i;
1073 wlc_hwband_t *band; 1085 wlc_hwband_t *band;
1074 wlc_hw_info_t *wlc_hw = wlc->hw; 1086 struct wlc_hw_info *wlc_hw = wlc->hw;
1075 int callbacks; 1087 int callbacks;
1076 1088
1077 callbacks = 0; 1089 callbacks = 0;
@@ -1082,7 +1094,7 @@ int wlc_bmac_detach(wlc_info_t *wlc)
1082 */ 1094 */
1083 si_deregister_intr_callback(wlc_hw->sih); 1095 si_deregister_intr_callback(wlc_hw->sih);
1084 1096
1085 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) 1097 if (wlc_hw->sih->bustype == PCI_BUS)
1086 si_pci_sleep(wlc_hw->sih); 1098 si_pci_sleep(wlc_hw->sih);
1087 } 1099 }
1088 1100
@@ -1118,9 +1130,9 @@ int wlc_bmac_detach(wlc_info_t *wlc)
1118 1130
1119} 1131}
1120 1132
1121void wlc_bmac_reset(wlc_hw_info_t *wlc_hw) 1133void wlc_bmac_reset(struct wlc_hw_info *wlc_hw)
1122{ 1134{
1123 WL_TRACE(("wl%d: wlc_bmac_reset\n", wlc_hw->unit)); 1135 WL_TRACE("wl%d: wlc_bmac_reset\n", wlc_hw->unit);
1124 1136
1125 WLCNTINCR(wlc_hw->wlc->pub->_cnt->reset); 1137 WLCNTINCR(wlc_hw->wlc->pub->_cnt->reset);
1126 1138
@@ -1135,13 +1147,13 @@ void wlc_bmac_reset(wlc_hw_info_t *wlc_hw)
1135} 1147}
1136 1148
1137void 1149void
1138wlc_bmac_init(wlc_hw_info_t *wlc_hw, chanspec_t chanspec, 1150wlc_bmac_init(struct wlc_hw_info *wlc_hw, chanspec_t chanspec,
1139 bool mute) { 1151 bool mute) {
1140 u32 macintmask; 1152 u32 macintmask;
1141 bool fastclk; 1153 bool fastclk;
1142 wlc_info_t *wlc = wlc_hw->wlc; 1154 struct wlc_info *wlc = wlc_hw->wlc;
1143 1155
1144 WL_TRACE(("wl%d: wlc_bmac_init\n", wlc_hw->unit)); 1156 WL_TRACE("wl%d: wlc_bmac_init\n", wlc_hw->unit);
1145 1157
1146 /* request FAST clock if not on */ 1158 /* request FAST clock if not on */
1147 fastclk = wlc_hw->forcefastclk; 1159 fastclk = wlc_hw->forcefastclk;
@@ -1186,11 +1198,11 @@ wlc_bmac_init(wlc_hw_info_t *wlc_hw, chanspec_t chanspec,
1186 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC); 1198 wlc_clkctl_clk(wlc_hw, CLK_DYNAMIC);
1187} 1199}
1188 1200
1189int wlc_bmac_up_prep(wlc_hw_info_t *wlc_hw) 1201int wlc_bmac_up_prep(struct wlc_hw_info *wlc_hw)
1190{ 1202{
1191 uint coremask; 1203 uint coremask;
1192 1204
1193 WL_TRACE(("wl%d: %s:\n", wlc_hw->unit, __func__)); 1205 WL_TRACE("wl%d: %s:\n", wlc_hw->unit, __func__);
1194 1206
1195 ASSERT(wlc_hw->wlc->pub->hw_up && wlc_hw->wlc->macintmask == 0); 1207 ASSERT(wlc_hw->wlc->pub->hw_up && wlc_hw->wlc->macintmask == 0);
1196 1208
@@ -1208,7 +1220,7 @@ int wlc_bmac_up_prep(wlc_hw_info_t *wlc_hw)
1208 */ 1220 */
1209 coremask = (1 << wlc_hw->wlc->core->coreidx); 1221 coremask = (1 << wlc_hw->wlc->core->coreidx);
1210 1222
1211 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) 1223 if (wlc_hw->sih->bustype == PCI_BUS)
1212 si_pci_setup(wlc_hw->sih, coremask); 1224 si_pci_setup(wlc_hw->sih, coremask);
1213 1225
1214 ASSERT(si_coreid(wlc_hw->sih) == D11_CORE_ID); 1226 ASSERT(si_coreid(wlc_hw->sih) == D11_CORE_ID);
@@ -1219,13 +1231,13 @@ int wlc_bmac_up_prep(wlc_hw_info_t *wlc_hw)
1219 */ 1231 */
1220 if (wlc_bmac_radio_read_hwdisabled(wlc_hw)) { 1232 if (wlc_bmac_radio_read_hwdisabled(wlc_hw)) {
1221 /* put SB PCI in down state again */ 1233 /* put SB PCI in down state again */
1222 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) 1234 if (wlc_hw->sih->bustype == PCI_BUS)
1223 si_pci_down(wlc_hw->sih); 1235 si_pci_down(wlc_hw->sih);
1224 wlc_bmac_xtal(wlc_hw, OFF); 1236 wlc_bmac_xtal(wlc_hw, OFF);
1225 return BCME_RADIOOFF; 1237 return BCME_RADIOOFF;
1226 } 1238 }
1227 1239
1228 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) 1240 if (wlc_hw->sih->bustype == PCI_BUS)
1229 si_pci_up(wlc_hw->sih); 1241 si_pci_up(wlc_hw->sih);
1230 1242
1231 /* reset the d11 core */ 1243 /* reset the d11 core */
@@ -1234,9 +1246,9 @@ int wlc_bmac_up_prep(wlc_hw_info_t *wlc_hw)
1234 return 0; 1246 return 0;
1235} 1247}
1236 1248
1237int wlc_bmac_up_finish(wlc_hw_info_t *wlc_hw) 1249int wlc_bmac_up_finish(struct wlc_hw_info *wlc_hw)
1238{ 1250{
1239 WL_TRACE(("wl%d: %s:\n", wlc_hw->unit, __func__)); 1251 WL_TRACE("wl%d: %s:\n", wlc_hw->unit, __func__);
1240 1252
1241 wlc_hw->up = true; 1253 wlc_hw->up = true;
1242 wlc_phy_hw_state_upd(wlc_hw->band->pi, true); 1254 wlc_phy_hw_state_upd(wlc_hw->band->pi, true);
@@ -1248,12 +1260,12 @@ int wlc_bmac_up_finish(wlc_hw_info_t *wlc_hw)
1248 return 0; 1260 return 0;
1249} 1261}
1250 1262
1251int wlc_bmac_down_prep(wlc_hw_info_t *wlc_hw) 1263int wlc_bmac_down_prep(struct wlc_hw_info *wlc_hw)
1252{ 1264{
1253 bool dev_gone; 1265 bool dev_gone;
1254 uint callbacks = 0; 1266 uint callbacks = 0;
1255 1267
1256 WL_TRACE(("wl%d: %s:\n", wlc_hw->unit, __func__)); 1268 WL_TRACE("wl%d: %s:\n", wlc_hw->unit, __func__);
1257 1269
1258 if (!wlc_hw->up) 1270 if (!wlc_hw->up)
1259 return callbacks; 1271 return callbacks;
@@ -1276,12 +1288,12 @@ int wlc_bmac_down_prep(wlc_hw_info_t *wlc_hw)
1276 return callbacks; 1288 return callbacks;
1277} 1289}
1278 1290
1279int wlc_bmac_down_finish(wlc_hw_info_t *wlc_hw) 1291int wlc_bmac_down_finish(struct wlc_hw_info *wlc_hw)
1280{ 1292{
1281 uint callbacks = 0; 1293 uint callbacks = 0;
1282 bool dev_gone; 1294 bool dev_gone;
1283 1295
1284 WL_TRACE(("wl%d: %s:\n", wlc_hw->unit, __func__)); 1296 WL_TRACE("wl%d: %s:\n", wlc_hw->unit, __func__);
1285 1297
1286 if (!wlc_hw->up) 1298 if (!wlc_hw->up)
1287 return callbacks; 1299 return callbacks;
@@ -1311,7 +1323,7 @@ int wlc_bmac_down_finish(wlc_hw_info_t *wlc_hw)
1311 1323
1312 /* turn off primary xtal and pll */ 1324 /* turn off primary xtal and pll */
1313 if (!wlc_hw->noreset) { 1325 if (!wlc_hw->noreset) {
1314 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) 1326 if (wlc_hw->sih->bustype == PCI_BUS)
1315 si_pci_down(wlc_hw->sih); 1327 si_pci_down(wlc_hw->sih);
1316 wlc_bmac_xtal(wlc_hw, OFF); 1328 wlc_bmac_xtal(wlc_hw, OFF);
1317 } 1329 }
@@ -1320,7 +1332,7 @@ int wlc_bmac_down_finish(wlc_hw_info_t *wlc_hw)
1320 return callbacks; 1332 return callbacks;
1321} 1333}
1322 1334
1323void wlc_bmac_wait_for_wake(wlc_hw_info_t *wlc_hw) 1335void wlc_bmac_wait_for_wake(struct wlc_hw_info *wlc_hw)
1324{ 1336{
1325 if (D11REV_IS(wlc_hw->corerev, 4)) /* no slowclock */ 1337 if (D11REV_IS(wlc_hw->corerev, 4)) /* no slowclock */
1326 udelay(5); 1338 udelay(5);
@@ -1336,29 +1348,30 @@ void wlc_bmac_wait_for_wake(wlc_hw_info_t *wlc_hw)
1336 ASSERT(wlc_bmac_read_shm(wlc_hw, M_UCODE_DBGST) != DBGST_ASLEEP); 1348 ASSERT(wlc_bmac_read_shm(wlc_hw, M_UCODE_DBGST) != DBGST_ASLEEP);
1337} 1349}
1338 1350
1339void wlc_bmac_hw_etheraddr(wlc_hw_info_t *wlc_hw, struct ether_addr *ea) 1351void wlc_bmac_hw_etheraddr(struct wlc_hw_info *wlc_hw, struct ether_addr *ea)
1340{ 1352{
1341 bcopy(&wlc_hw->etheraddr, ea, ETHER_ADDR_LEN); 1353 bcopy(&wlc_hw->etheraddr, ea, ETH_ALEN);
1342} 1354}
1343 1355
1344void wlc_bmac_set_hw_etheraddr(wlc_hw_info_t *wlc_hw, struct ether_addr *ea) 1356void wlc_bmac_set_hw_etheraddr(struct wlc_hw_info *wlc_hw,
1357 struct ether_addr *ea)
1345{ 1358{
1346 bcopy(ea, &wlc_hw->etheraddr, ETHER_ADDR_LEN); 1359 bcopy(ea, &wlc_hw->etheraddr, ETH_ALEN);
1347} 1360}
1348 1361
1349int wlc_bmac_bandtype(wlc_hw_info_t *wlc_hw) 1362int wlc_bmac_bandtype(struct wlc_hw_info *wlc_hw)
1350{ 1363{
1351 return wlc_hw->band->bandtype; 1364 return wlc_hw->band->bandtype;
1352} 1365}
1353 1366
1354void *wlc_cur_phy(wlc_info_t *wlc) 1367void *wlc_cur_phy(struct wlc_info *wlc)
1355{ 1368{
1356 wlc_hw_info_t *wlc_hw = wlc->hw; 1369 struct wlc_hw_info *wlc_hw = wlc->hw;
1357 return (void *)wlc_hw->band->pi; 1370 return (void *)wlc_hw->band->pi;
1358} 1371}
1359 1372
1360/* control chip clock to save power, enable dynamic clock or force fast clock */ 1373/* control chip clock to save power, enable dynamic clock or force fast clock */
1361static void wlc_clkctl_clk(wlc_hw_info_t *wlc_hw, uint mode) 1374static void wlc_clkctl_clk(struct wlc_hw_info *wlc_hw, uint mode)
1362{ 1375{
1363 if (PMUCTL_ENAB(wlc_hw->sih)) { 1376 if (PMUCTL_ENAB(wlc_hw->sih)) {
1364 /* new chips with PMU, CCS_FORCEHT will distribute the HT clock on backplane, 1377 /* new chips with PMU, CCS_FORCEHT will distribute the HT clock on backplane,
@@ -1455,11 +1468,11 @@ static void wlc_clkctl_clk(wlc_hw_info_t *wlc_hw, uint mode)
1455 1468
1456/* set initial host flags value */ 1469/* set initial host flags value */
1457static void 1470static void
1458wlc_mhfdef(wlc_info_t *wlc, u16 *mhfs, u16 mhf2_init) 1471wlc_mhfdef(struct wlc_info *wlc, u16 *mhfs, u16 mhf2_init)
1459{ 1472{
1460 wlc_hw_info_t *wlc_hw = wlc->hw; 1473 struct wlc_hw_info *wlc_hw = wlc->hw;
1461 1474
1462 bzero(mhfs, sizeof(u16) * MHFMAX); 1475 memset(mhfs, 0, MHFMAX * sizeof(u16));
1463 1476
1464 mhfs[MHF2] |= mhf2_init; 1477 mhfs[MHF2] |= mhf2_init;
1465 1478
@@ -1485,7 +1498,7 @@ wlc_mhfdef(wlc_info_t *wlc, u16 *mhfs, u16 mhf2_init)
1485 * WLC_BAND_ALL <--- All bands 1498 * WLC_BAND_ALL <--- All bands
1486 */ 1499 */
1487void 1500void
1488wlc_bmac_mhf(wlc_hw_info_t *wlc_hw, u8 idx, u16 mask, u16 val, 1501wlc_bmac_mhf(struct wlc_hw_info *wlc_hw, u8 idx, u16 mask, u16 val,
1489 int bands) 1502 int bands)
1490{ 1503{
1491 u16 save; 1504 u16 save;
@@ -1539,7 +1552,7 @@ wlc_bmac_mhf(wlc_hw_info_t *wlc_hw, u8 idx, u16 mask, u16 val,
1539 } 1552 }
1540} 1553}
1541 1554
1542u16 wlc_bmac_mhf_get(wlc_hw_info_t *wlc_hw, u8 idx, int bands) 1555u16 wlc_bmac_mhf_get(struct wlc_hw_info *wlc_hw, u8 idx, int bands)
1543{ 1556{
1544 wlc_hwband_t *band; 1557 wlc_hwband_t *band;
1545 ASSERT(idx < MHFMAX); 1558 ASSERT(idx < MHFMAX);
@@ -1565,7 +1578,7 @@ u16 wlc_bmac_mhf_get(wlc_hw_info_t *wlc_hw, u8 idx, int bands)
1565 return band->mhfs[idx]; 1578 return band->mhfs[idx];
1566} 1579}
1567 1580
1568static void wlc_write_mhf(wlc_hw_info_t *wlc_hw, u16 *mhfs) 1581static void wlc_write_mhf(struct wlc_hw_info *wlc_hw, u16 *mhfs)
1569{ 1582{
1570 u8 idx; 1583 u8 idx;
1571 u16 addr[] = { 1584 u16 addr[] = {
@@ -1583,7 +1596,7 @@ static void wlc_write_mhf(wlc_hw_info_t *wlc_hw, u16 *mhfs)
1583/* set the maccontrol register to desired reset state and 1596/* set the maccontrol register to desired reset state and
1584 * initialize the sw cache of the register 1597 * initialize the sw cache of the register
1585 */ 1598 */
1586static void wlc_mctrl_reset(wlc_hw_info_t *wlc_hw) 1599static void wlc_mctrl_reset(struct wlc_hw_info *wlc_hw)
1587{ 1600{
1588 /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */ 1601 /* IHR accesses are always enabled, PSM disabled, HPS off and WAKE on */
1589 wlc_hw->maccontrol = 0; 1602 wlc_hw->maccontrol = 0;
@@ -1594,7 +1607,7 @@ static void wlc_mctrl_reset(wlc_hw_info_t *wlc_hw)
1594} 1607}
1595 1608
1596/* set or clear maccontrol bits */ 1609/* set or clear maccontrol bits */
1597void wlc_bmac_mctrl(wlc_hw_info_t *wlc_hw, u32 mask, u32 val) 1610void wlc_bmac_mctrl(struct wlc_hw_info *wlc_hw, u32 mask, u32 val)
1598{ 1611{
1599 u32 maccontrol; 1612 u32 maccontrol;
1600 u32 new_maccontrol; 1613 u32 new_maccontrol;
@@ -1616,7 +1629,7 @@ void wlc_bmac_mctrl(wlc_hw_info_t *wlc_hw, u32 mask, u32 val)
1616} 1629}
1617 1630
1618/* write the software state of maccontrol and overrides to the maccontrol register */ 1631/* write the software state of maccontrol and overrides to the maccontrol register */
1619static void wlc_mctrl_write(wlc_hw_info_t *wlc_hw) 1632static void wlc_mctrl_write(struct wlc_hw_info *wlc_hw)
1620{ 1633{
1621 u32 maccontrol = wlc_hw->maccontrol; 1634 u32 maccontrol = wlc_hw->maccontrol;
1622 1635
@@ -1633,7 +1646,7 @@ static void wlc_mctrl_write(wlc_hw_info_t *wlc_hw)
1633 W_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol, maccontrol); 1646 W_REG(wlc_hw->osh, &wlc_hw->regs->maccontrol, maccontrol);
1634} 1647}
1635 1648
1636void wlc_ucode_wake_override_set(wlc_hw_info_t *wlc_hw, u32 override_bit) 1649void wlc_ucode_wake_override_set(struct wlc_hw_info *wlc_hw, u32 override_bit)
1637{ 1650{
1638 ASSERT((wlc_hw->wake_override & override_bit) == 0); 1651 ASSERT((wlc_hw->wake_override & override_bit) == 0);
1639 1652
@@ -1650,7 +1663,7 @@ void wlc_ucode_wake_override_set(wlc_hw_info_t *wlc_hw, u32 override_bit)
1650 return; 1663 return;
1651} 1664}
1652 1665
1653void wlc_ucode_wake_override_clear(wlc_hw_info_t *wlc_hw, u32 override_bit) 1666void wlc_ucode_wake_override_clear(struct wlc_hw_info *wlc_hw, u32 override_bit)
1654{ 1667{
1655 ASSERT(wlc_hw->wake_override & override_bit); 1668 ASSERT(wlc_hw->wake_override & override_bit);
1656 1669
@@ -1671,7 +1684,7 @@ void wlc_ucode_wake_override_clear(wlc_hw_info_t *wlc_hw, u32 override_bit)
1671 * STA 0 1 <--- This will ensure no beacons 1684 * STA 0 1 <--- This will ensure no beacons
1672 * IBSS 0 0 1685 * IBSS 0 0
1673 */ 1686 */
1674static void wlc_ucode_mute_override_set(wlc_hw_info_t *wlc_hw) 1687static void wlc_ucode_mute_override_set(struct wlc_hw_info *wlc_hw)
1675{ 1688{
1676 wlc_hw->mute_override = 1; 1689 wlc_hw->mute_override = 1;
1677 1690
@@ -1687,7 +1700,7 @@ static void wlc_ucode_mute_override_set(wlc_hw_info_t *wlc_hw)
1687} 1700}
1688 1701
1689/* Clear the override on AP and INFRA bits */ 1702/* Clear the override on AP and INFRA bits */
1690static void wlc_ucode_mute_override_clear(wlc_hw_info_t *wlc_hw) 1703static void wlc_ucode_mute_override_clear(struct wlc_hw_info *wlc_hw)
1691{ 1704{
1692 if (wlc_hw->mute_override == 0) 1705 if (wlc_hw->mute_override == 0)
1693 return; 1706 return;
@@ -1707,16 +1720,16 @@ static void wlc_ucode_mute_override_clear(wlc_hw_info_t *wlc_hw)
1707 * Write a MAC address to the rcmta structure 1720 * Write a MAC address to the rcmta structure
1708 */ 1721 */
1709void 1722void
1710wlc_bmac_set_rcmta(wlc_hw_info_t *wlc_hw, int idx, 1723wlc_bmac_set_rcmta(struct wlc_hw_info *wlc_hw, int idx,
1711 const struct ether_addr *addr) 1724 const struct ether_addr *addr)
1712{ 1725{
1713 d11regs_t *regs = wlc_hw->regs; 1726 d11regs_t *regs = wlc_hw->regs;
1714 volatile u16 *objdata16 = (volatile u16 *)&regs->objdata; 1727 volatile u16 *objdata16 = (volatile u16 *)&regs->objdata;
1715 u32 mac_hm; 1728 u32 mac_hm;
1716 u16 mac_l; 1729 u16 mac_l;
1717 osl_t *osh; 1730 struct osl_info *osh;
1718 1731
1719 WL_TRACE(("wl%d: %s\n", wlc_hw->unit, __func__)); 1732 WL_TRACE("wl%d: %s\n", wlc_hw->unit, __func__);
1720 1733
1721 ASSERT(wlc_hw->corerev > 4); 1734 ASSERT(wlc_hw->corerev > 4);
1722 1735
@@ -1740,16 +1753,16 @@ wlc_bmac_set_rcmta(wlc_hw_info_t *wlc_hw, int idx,
1740 * Write a MAC address to the given match reg offset in the RXE match engine. 1753 * Write a MAC address to the given match reg offset in the RXE match engine.
1741 */ 1754 */
1742void 1755void
1743wlc_bmac_set_addrmatch(wlc_hw_info_t *wlc_hw, int match_reg_offset, 1756wlc_bmac_set_addrmatch(struct wlc_hw_info *wlc_hw, int match_reg_offset,
1744 const struct ether_addr *addr) 1757 const struct ether_addr *addr)
1745{ 1758{
1746 d11regs_t *regs; 1759 d11regs_t *regs;
1747 u16 mac_l; 1760 u16 mac_l;
1748 u16 mac_m; 1761 u16 mac_m;
1749 u16 mac_h; 1762 u16 mac_h;
1750 osl_t *osh; 1763 struct osl_info *osh;
1751 1764
1752 WL_TRACE(("wl%d: wlc_bmac_set_addrmatch\n", wlc_hw->unit)); 1765 WL_TRACE("wl%d: wlc_bmac_set_addrmatch\n", wlc_hw->unit);
1753 1766
1754 ASSERT((match_reg_offset < RCM_SIZE) || (wlc_hw->corerev == 4)); 1767 ASSERT((match_reg_offset < RCM_SIZE) || (wlc_hw->corerev == 4));
1755 1768
@@ -1769,7 +1782,7 @@ wlc_bmac_set_addrmatch(wlc_hw_info_t *wlc_hw, int match_reg_offset,
1769} 1782}
1770 1783
1771void 1784void
1772wlc_bmac_write_template_ram(wlc_hw_info_t *wlc_hw, int offset, int len, 1785wlc_bmac_write_template_ram(struct wlc_hw_info *wlc_hw, int offset, int len,
1773 void *buf) 1786 void *buf)
1774{ 1787{
1775 d11regs_t *regs; 1788 d11regs_t *regs;
@@ -1778,9 +1791,9 @@ wlc_bmac_write_template_ram(wlc_hw_info_t *wlc_hw, int offset, int len,
1778#ifdef IL_BIGENDIAN 1791#ifdef IL_BIGENDIAN
1779 volatile u16 *dptr = NULL; 1792 volatile u16 *dptr = NULL;
1780#endif /* IL_BIGENDIAN */ 1793#endif /* IL_BIGENDIAN */
1781 osl_t *osh; 1794 struct osl_info *osh;
1782 1795
1783 WL_TRACE(("wl%d: wlc_bmac_write_template_ram\n", wlc_hw->unit)); 1796 WL_TRACE("wl%d: wlc_bmac_write_template_ram\n", wlc_hw->unit);
1784 1797
1785 regs = wlc_hw->regs; 1798 regs = wlc_hw->regs;
1786 osh = wlc_hw->osh; 1799 osh = wlc_hw->osh;
@@ -1812,9 +1825,9 @@ wlc_bmac_write_template_ram(wlc_hw_info_t *wlc_hw, int offset, int len,
1812 } 1825 }
1813} 1826}
1814 1827
1815void wlc_bmac_set_cwmin(wlc_hw_info_t *wlc_hw, u16 newmin) 1828void wlc_bmac_set_cwmin(struct wlc_hw_info *wlc_hw, u16 newmin)
1816{ 1829{
1817 osl_t *osh; 1830 struct osl_info *osh;
1818 1831
1819 osh = wlc_hw->osh; 1832 osh = wlc_hw->osh;
1820 wlc_hw->band->CWmin = newmin; 1833 wlc_hw->band->CWmin = newmin;
@@ -1824,9 +1837,9 @@ void wlc_bmac_set_cwmin(wlc_hw_info_t *wlc_hw, u16 newmin)
1824 W_REG(osh, &wlc_hw->regs->objdata, newmin); 1837 W_REG(osh, &wlc_hw->regs->objdata, newmin);
1825} 1838}
1826 1839
1827void wlc_bmac_set_cwmax(wlc_hw_info_t *wlc_hw, u16 newmax) 1840void wlc_bmac_set_cwmax(struct wlc_hw_info *wlc_hw, u16 newmax)
1828{ 1841{
1829 osl_t *osh; 1842 struct osl_info *osh;
1830 1843
1831 osh = wlc_hw->osh; 1844 osh = wlc_hw->osh;
1832 wlc_hw->band->CWmax = newmax; 1845 wlc_hw->band->CWmax = newmax;
@@ -1836,7 +1849,7 @@ void wlc_bmac_set_cwmax(wlc_hw_info_t *wlc_hw, u16 newmax)
1836 W_REG(osh, &wlc_hw->regs->objdata, newmax); 1849 W_REG(osh, &wlc_hw->regs->objdata, newmax);
1837} 1850}
1838 1851
1839void wlc_bmac_bw_set(wlc_hw_info_t *wlc_hw, u16 bw) 1852void wlc_bmac_bw_set(struct wlc_hw_info *wlc_hw, u16 bw)
1840{ 1853{
1841 bool fastclk; 1854 bool fastclk;
1842 u32 tmp; 1855 u32 tmp;
@@ -1861,7 +1874,7 @@ void wlc_bmac_bw_set(wlc_hw_info_t *wlc_hw, u16 bw)
1861} 1874}
1862 1875
1863static void 1876static void
1864wlc_write_hw_bcntemplate0(wlc_hw_info_t *wlc_hw, void *bcn, int len) 1877wlc_write_hw_bcntemplate0(struct wlc_hw_info *wlc_hw, void *bcn, int len)
1865{ 1878{
1866 d11regs_t *regs = wlc_hw->regs; 1879 d11regs_t *regs = wlc_hw->regs;
1867 1880
@@ -1875,7 +1888,7 @@ wlc_write_hw_bcntemplate0(wlc_hw_info_t *wlc_hw, void *bcn, int len)
1875} 1888}
1876 1889
1877static void 1890static void
1878wlc_write_hw_bcntemplate1(wlc_hw_info_t *wlc_hw, void *bcn, int len) 1891wlc_write_hw_bcntemplate1(struct wlc_hw_info *wlc_hw, void *bcn, int len)
1879{ 1892{
1880 d11regs_t *regs = wlc_hw->regs; 1893 d11regs_t *regs = wlc_hw->regs;
1881 1894
@@ -1890,7 +1903,7 @@ wlc_write_hw_bcntemplate1(wlc_hw_info_t *wlc_hw, void *bcn, int len)
1890 1903
1891/* mac is assumed to be suspended at this point */ 1904/* mac is assumed to be suspended at this point */
1892void 1905void
1893wlc_bmac_write_hw_bcntemplates(wlc_hw_info_t *wlc_hw, void *bcn, int len, 1906wlc_bmac_write_hw_bcntemplates(struct wlc_hw_info *wlc_hw, void *bcn, int len,
1894 bool both) 1907 bool both)
1895{ 1908{
1896 d11regs_t *regs = wlc_hw->regs; 1909 d11regs_t *regs = wlc_hw->regs;
@@ -1911,10 +1924,10 @@ wlc_bmac_write_hw_bcntemplates(wlc_hw_info_t *wlc_hw, void *bcn, int len,
1911 } 1924 }
1912} 1925}
1913 1926
1914static void WLBANDINITFN(wlc_bmac_upd_synthpu) (wlc_hw_info_t *wlc_hw) 1927static void WLBANDINITFN(wlc_bmac_upd_synthpu) (struct wlc_hw_info *wlc_hw)
1915{ 1928{
1916 u16 v; 1929 u16 v;
1917 wlc_info_t *wlc = wlc_hw->wlc; 1930 struct wlc_info *wlc = wlc_hw->wlc;
1918 /* update SYNTHPU_DLY */ 1931 /* update SYNTHPU_DLY */
1919 1932
1920 if (WLCISLCNPHY(wlc->band)) { 1933 if (WLCISLCNPHY(wlc->band)) {
@@ -1930,12 +1943,12 @@ static void WLBANDINITFN(wlc_bmac_upd_synthpu) (wlc_hw_info_t *wlc_hw)
1930 1943
1931/* band-specific init */ 1944/* band-specific init */
1932static void 1945static void
1933WLBANDINITFN(wlc_bmac_bsinit) (wlc_info_t *wlc, chanspec_t chanspec) 1946WLBANDINITFN(wlc_bmac_bsinit) (struct wlc_info *wlc, chanspec_t chanspec)
1934{ 1947{
1935 wlc_hw_info_t *wlc_hw = wlc->hw; 1948 struct wlc_hw_info *wlc_hw = wlc->hw;
1936 1949
1937 WL_TRACE(("wl%d: wlc_bmac_bsinit: bandunit %d\n", wlc_hw->unit, 1950 WL_TRACE("wl%d: wlc_bmac_bsinit: bandunit %d\n",
1938 wlc_hw->band->bandunit)); 1951 wlc_hw->unit, wlc_hw->band->bandunit);
1939 1952
1940 /* sanity check */ 1953 /* sanity check */
1941 if (PHY_TYPE(R_REG(wlc_hw->osh, &wlc_hw->regs->phyversion)) != 1954 if (PHY_TYPE(R_REG(wlc_hw->osh, &wlc_hw->regs->phyversion)) !=
@@ -1969,9 +1982,9 @@ WLBANDINITFN(wlc_bmac_bsinit) (wlc_info_t *wlc, chanspec_t chanspec)
1969 wlc_bmac_upd_synthpu(wlc_hw); 1982 wlc_bmac_upd_synthpu(wlc_hw);
1970} 1983}
1971 1984
1972void wlc_bmac_core_phy_clk(wlc_hw_info_t *wlc_hw, bool clk) 1985void wlc_bmac_core_phy_clk(struct wlc_hw_info *wlc_hw, bool clk)
1973{ 1986{
1974 WL_TRACE(("wl%d: wlc_bmac_core_phy_clk: clk %d\n", wlc_hw->unit, clk)); 1987 WL_TRACE("wl%d: wlc_bmac_core_phy_clk: clk %d\n", wlc_hw->unit, clk);
1975 1988
1976 wlc_hw->phyclk = clk; 1989 wlc_hw->phyclk = clk;
1977 1990
@@ -1994,9 +2007,9 @@ void wlc_bmac_core_phy_clk(wlc_hw_info_t *wlc_hw, bool clk)
1994} 2007}
1995 2008
1996/* Perform a soft reset of the PHY PLL */ 2009/* Perform a soft reset of the PHY PLL */
1997void wlc_bmac_core_phypll_reset(wlc_hw_info_t *wlc_hw) 2010void wlc_bmac_core_phypll_reset(struct wlc_hw_info *wlc_hw)
1998{ 2011{
1999 WL_TRACE(("wl%d: wlc_bmac_core_phypll_reset\n", wlc_hw->unit)); 2012 WL_TRACE("wl%d: wlc_bmac_core_phypll_reset\n", wlc_hw->unit);
2000 2013
2001 si_corereg(wlc_hw->sih, SI_CC_IDX, 2014 si_corereg(wlc_hw->sih, SI_CC_IDX,
2002 offsetof(chipcregs_t, chipcontrol_addr), ~0, 0); 2015 offsetof(chipcregs_t, chipcontrol_addr), ~0, 0);
@@ -2015,7 +2028,7 @@ void wlc_bmac_core_phypll_reset(wlc_hw_info_t *wlc_hw)
2015/* light way to turn on phy clock without reset for NPHY only 2028/* light way to turn on phy clock without reset for NPHY only
2016 * refer to wlc_bmac_core_phy_clk for full version 2029 * refer to wlc_bmac_core_phy_clk for full version
2017 */ 2030 */
2018void wlc_bmac_phyclk_fgc(wlc_hw_info_t *wlc_hw, bool clk) 2031void wlc_bmac_phyclk_fgc(struct wlc_hw_info *wlc_hw, bool clk)
2019{ 2032{
2020 /* support(necessary for NPHY and HYPHY) only */ 2033 /* support(necessary for NPHY and HYPHY) only */
2021 if (!WLCISNPHY(wlc_hw->band)) 2034 if (!WLCISNPHY(wlc_hw->band))
@@ -2028,7 +2041,7 @@ void wlc_bmac_phyclk_fgc(wlc_hw_info_t *wlc_hw, bool clk)
2028 2041
2029} 2042}
2030 2043
2031void wlc_bmac_macphyclk_set(wlc_hw_info_t *wlc_hw, bool clk) 2044void wlc_bmac_macphyclk_set(struct wlc_hw_info *wlc_hw, bool clk)
2032{ 2045{
2033 if (ON == clk) 2046 if (ON == clk)
2034 si_core_cflags(wlc_hw->sih, SICF_MPCLKE, SICF_MPCLKE); 2047 si_core_cflags(wlc_hw->sih, SICF_MPCLKE, SICF_MPCLKE);
@@ -2036,13 +2049,13 @@ void wlc_bmac_macphyclk_set(wlc_hw_info_t *wlc_hw, bool clk)
2036 si_core_cflags(wlc_hw->sih, SICF_MPCLKE, 0); 2049 si_core_cflags(wlc_hw->sih, SICF_MPCLKE, 0);
2037} 2050}
2038 2051
2039void wlc_bmac_phy_reset(wlc_hw_info_t *wlc_hw) 2052void wlc_bmac_phy_reset(struct wlc_hw_info *wlc_hw)
2040{ 2053{
2041 wlc_phy_t *pih = wlc_hw->band->pi; 2054 wlc_phy_t *pih = wlc_hw->band->pi;
2042 u32 phy_bw_clkbits; 2055 u32 phy_bw_clkbits;
2043 bool phy_in_reset = false; 2056 bool phy_in_reset = false;
2044 2057
2045 WL_TRACE(("wl%d: wlc_bmac_phy_reset\n", wlc_hw->unit)); 2058 WL_TRACE("wl%d: wlc_bmac_phy_reset\n", wlc_hw->unit);
2046 2059
2047 if (pih == NULL) 2060 if (pih == NULL)
2048 return; 2061 return;
@@ -2080,9 +2093,9 @@ void wlc_bmac_phy_reset(wlc_hw_info_t *wlc_hw)
2080 2093
2081/* switch to and initialize new band */ 2094/* switch to and initialize new band */
2082static void 2095static void
2083WLBANDINITFN(wlc_bmac_setband) (wlc_hw_info_t *wlc_hw, uint bandunit, 2096WLBANDINITFN(wlc_bmac_setband) (struct wlc_hw_info *wlc_hw, uint bandunit,
2084 chanspec_t chanspec) { 2097 chanspec_t chanspec) {
2085 wlc_info_t *wlc = wlc_hw->wlc; 2098 struct wlc_info *wlc = wlc_hw->wlc;
2086 u32 macintmask; 2099 u32 macintmask;
2087 2100
2088 ASSERT(NBANDS_HW(wlc_hw) > 1); 2101 ASSERT(NBANDS_HW(wlc_hw) > 1);
@@ -2122,9 +2135,9 @@ WLBANDINITFN(wlc_bmac_setband) (wlc_hw_info_t *wlc_hw, uint bandunit,
2122} 2135}
2123 2136
2124/* low-level band switch utility routine */ 2137/* low-level band switch utility routine */
2125void WLBANDINITFN(wlc_setxband) (wlc_hw_info_t *wlc_hw, uint bandunit) 2138void WLBANDINITFN(wlc_setxband) (struct wlc_hw_info *wlc_hw, uint bandunit)
2126{ 2139{
2127 WL_TRACE(("wl%d: wlc_setxband: bandunit %d\n", wlc_hw->unit, bandunit)); 2140 WL_TRACE("wl%d: wlc_setxband: bandunit %d\n", wlc_hw->unit, bandunit);
2128 2141
2129 wlc_hw->band = wlc_hw->bandstate[bandunit]; 2142 wlc_hw->band = wlc_hw->bandstate[bandunit];
2130 2143
@@ -2138,19 +2151,19 @@ void WLBANDINITFN(wlc_setxband) (wlc_hw_info_t *wlc_hw, uint bandunit)
2138 } 2151 }
2139} 2152}
2140 2153
2141static bool wlc_isgoodchip(wlc_hw_info_t *wlc_hw) 2154static bool wlc_isgoodchip(struct wlc_hw_info *wlc_hw)
2142{ 2155{
2143 2156
2144 /* reject unsupported corerev */ 2157 /* reject unsupported corerev */
2145 if (!VALID_COREREV(wlc_hw->corerev)) { 2158 if (!VALID_COREREV(wlc_hw->corerev)) {
2146 WL_ERROR(("unsupported core rev %d\n", wlc_hw->corerev)); 2159 WL_ERROR("unsupported core rev %d\n", wlc_hw->corerev);
2147 return false; 2160 return false;
2148 } 2161 }
2149 2162
2150 return true; 2163 return true;
2151} 2164}
2152 2165
2153static bool wlc_validboardtype(wlc_hw_info_t *wlc_hw) 2166static bool wlc_validboardtype(struct wlc_hw_info *wlc_hw)
2154{ 2167{
2155 bool goodboard = true; 2168 bool goodboard = true;
2156 uint boardrev = wlc_hw->boardrev; 2169 uint boardrev = wlc_hw->boardrev;
@@ -2174,7 +2187,7 @@ static bool wlc_validboardtype(wlc_hw_info_t *wlc_hw)
2174 return goodboard; 2187 return goodboard;
2175} 2188}
2176 2189
2177static char *wlc_get_macaddr(wlc_hw_info_t *wlc_hw) 2190static char *wlc_get_macaddr(struct wlc_hw_info *wlc_hw)
2178{ 2191{
2179 const char *varname = "macaddr"; 2192 const char *varname = "macaddr";
2180 char *macaddr; 2193 char *macaddr;
@@ -2191,7 +2204,8 @@ static char *wlc_get_macaddr(wlc_hw_info_t *wlc_hw)
2191 2204
2192 macaddr = getvar(wlc_hw->vars, varname); 2205 macaddr = getvar(wlc_hw->vars, varname);
2193 if (macaddr == NULL) { 2206 if (macaddr == NULL) {
2194 WL_ERROR(("wl%d: wlc_get_macaddr: macaddr getvar(%s) not found\n", wlc_hw->unit, varname)); 2207 WL_ERROR("wl%d: wlc_get_macaddr: macaddr getvar(%s) not found\n",
2208 wlc_hw->unit, varname);
2195 } 2209 }
2196 2210
2197 return macaddr; 2211 return macaddr;
@@ -2203,7 +2217,7 @@ static char *wlc_get_macaddr(wlc_hw_info_t *wlc_hw)
2203 * this function could be called when driver is down and w/o clock 2217 * this function could be called when driver is down and w/o clock
2204 * it operates on different registers depending on corerev and boardflag. 2218 * it operates on different registers depending on corerev and boardflag.
2205 */ 2219 */
2206bool wlc_bmac_radio_read_hwdisabled(wlc_hw_info_t *wlc_hw) 2220bool wlc_bmac_radio_read_hwdisabled(struct wlc_hw_info *wlc_hw)
2207{ 2221{
2208 bool v, clk, xtal; 2222 bool v, clk, xtal;
2209 u32 resetbits = 0, flags = 0; 2223 u32 resetbits = 0, flags = 0;
@@ -2226,9 +2240,9 @@ bool wlc_bmac_radio_read_hwdisabled(wlc_hw_info_t *wlc_hw)
2226 flags |= SICF_PCLKE; 2240 flags |= SICF_PCLKE;
2227 2241
2228 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */ 2242 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
2229 if ((CHIPID(wlc_hw->sih->chip) == BCM43224_CHIP_ID) || 2243 if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
2230 (CHIPID(wlc_hw->sih->chip) == BCM43225_CHIP_ID) || 2244 (wlc_hw->sih->chip == BCM43225_CHIP_ID) ||
2231 (CHIPID(wlc_hw->sih->chip) == BCM43421_CHIP_ID)) 2245 (wlc_hw->sih->chip == BCM43421_CHIP_ID))
2232 wlc_hw->regs = 2246 wlc_hw->regs =
2233 (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID, 2247 (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID,
2234 0); 2248 0);
@@ -2249,12 +2263,12 @@ bool wlc_bmac_radio_read_hwdisabled(wlc_hw_info_t *wlc_hw)
2249} 2263}
2250 2264
2251/* Initialize just the hardware when coming out of POR or S3/S5 system states */ 2265/* Initialize just the hardware when coming out of POR or S3/S5 system states */
2252void wlc_bmac_hw_up(wlc_hw_info_t *wlc_hw) 2266void wlc_bmac_hw_up(struct wlc_hw_info *wlc_hw)
2253{ 2267{
2254 if (wlc_hw->wlc->pub->hw_up) 2268 if (wlc_hw->wlc->pub->hw_up)
2255 return; 2269 return;
2256 2270
2257 WL_TRACE(("wl%d: %s:\n", wlc_hw->unit, __func__)); 2271 WL_TRACE("wl%d: %s:\n", wlc_hw->unit, __func__);
2258 2272
2259 /* 2273 /*
2260 * Enable pll and xtal, initialize the power control registers, 2274 * Enable pll and xtal, initialize the power control registers,
@@ -2264,13 +2278,13 @@ void wlc_bmac_hw_up(wlc_hw_info_t *wlc_hw)
2264 si_clkctl_init(wlc_hw->sih); 2278 si_clkctl_init(wlc_hw->sih);
2265 wlc_clkctl_clk(wlc_hw, CLK_FAST); 2279 wlc_clkctl_clk(wlc_hw, CLK_FAST);
2266 2280
2267 if (BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) { 2281 if (wlc_hw->sih->bustype == PCI_BUS) {
2268 si_pci_fixcfg(wlc_hw->sih); 2282 si_pci_fixcfg(wlc_hw->sih);
2269 2283
2270 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */ 2284 /* AI chip doesn't restore bar0win2 on hibernation/resume, need sw fixup */
2271 if ((CHIPID(wlc_hw->sih->chip) == BCM43224_CHIP_ID) || 2285 if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
2272 (CHIPID(wlc_hw->sih->chip) == BCM43225_CHIP_ID) || 2286 (wlc_hw->sih->chip == BCM43225_CHIP_ID) ||
2273 (CHIPID(wlc_hw->sih->chip) == BCM43421_CHIP_ID)) 2287 (wlc_hw->sih->chip == BCM43421_CHIP_ID))
2274 wlc_hw->regs = 2288 wlc_hw->regs =
2275 (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID, 2289 (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID,
2276 0); 2290 0);
@@ -2283,7 +2297,7 @@ void wlc_bmac_hw_up(wlc_hw_info_t *wlc_hw)
2283 wlc_hw->wlc->pub->hw_up = true; 2297 wlc_hw->wlc->pub->hw_up = true;
2284 2298
2285 if ((wlc_hw->boardflags & BFL_FEM) 2299 if ((wlc_hw->boardflags & BFL_FEM)
2286 && (CHIPID(wlc_hw->sih->chip) == BCM4313_CHIP_ID)) { 2300 && (wlc_hw->sih->chip == BCM4313_CHIP_ID)) {
2287 if (! 2301 if (!
2288 (wlc_hw->boardrev >= 0x1250 2302 (wlc_hw->boardrev >= 0x1250
2289 && (wlc_hw->boardflags & BFL_FEM_BT))) 2303 && (wlc_hw->boardflags & BFL_FEM_BT)))
@@ -2291,10 +2305,10 @@ void wlc_bmac_hw_up(wlc_hw_info_t *wlc_hw)
2291 } 2305 }
2292} 2306}
2293 2307
2294static bool wlc_dma_rxreset(wlc_hw_info_t *wlc_hw, uint fifo) 2308static bool wlc_dma_rxreset(struct wlc_hw_info *wlc_hw, uint fifo)
2295{ 2309{
2296 hnddma_t *di = wlc_hw->di[fifo]; 2310 struct hnddma_pub *di = wlc_hw->di[fifo];
2297 osl_t *osh; 2311 struct osl_info *osh;
2298 2312
2299 if (D11REV_LT(wlc_hw->corerev, 12)) { 2313 if (D11REV_LT(wlc_hw->corerev, 12)) {
2300 bool rxidle = true; 2314 bool rxidle = true;
@@ -2309,7 +2323,8 @@ static bool wlc_dma_rxreset(wlc_hw_info_t *wlc_hw, uint fifo)
2309 50000); 2323 50000);
2310 2324
2311 if (!rxidle && (rcv_frm_cnt != 0)) 2325 if (!rxidle && (rcv_frm_cnt != 0))
2312 WL_ERROR(("wl%d: %s: rxdma[%d] not idle && rcv_frm_cnt(%d) not zero\n", wlc_hw->unit, __func__, fifo, rcv_frm_cnt)); 2326 WL_ERROR("wl%d: %s: rxdma[%d] not idle && rcv_frm_cnt(%d) not zero\n",
2327 wlc_hw->unit, __func__, fifo, rcv_frm_cnt);
2313 mdelay(2); 2328 mdelay(2);
2314 } 2329 }
2315 2330
@@ -2324,7 +2339,7 @@ static bool wlc_dma_rxreset(wlc_hw_info_t *wlc_hw, uint fifo)
2324 * clear software macintstatus for fresh new start 2339 * clear software macintstatus for fresh new start
2325 * one testing hack wlc_hw->noreset will bypass the d11/phy reset 2340 * one testing hack wlc_hw->noreset will bypass the d11/phy reset
2326 */ 2341 */
2327void wlc_bmac_corereset(wlc_hw_info_t *wlc_hw, u32 flags) 2342void wlc_bmac_corereset(struct wlc_hw_info *wlc_hw, u32 flags)
2328{ 2343{
2329 d11regs_t *regs; 2344 d11regs_t *regs;
2330 uint i; 2345 uint i;
@@ -2334,7 +2349,7 @@ void wlc_bmac_corereset(wlc_hw_info_t *wlc_hw, u32 flags)
2334 if (flags == WLC_USE_COREFLAGS) 2349 if (flags == WLC_USE_COREFLAGS)
2335 flags = (wlc_hw->band->pi ? wlc_hw->band->core_flags : 0); 2350 flags = (wlc_hw->band->pi ? wlc_hw->band->core_flags : 0);
2336 2351
2337 WL_TRACE(("wl%d: %s\n", wlc_hw->unit, __func__)); 2352 WL_TRACE("wl%d: %s\n", wlc_hw->unit, __func__);
2338 2353
2339 regs = wlc_hw->regs; 2354 regs = wlc_hw->regs;
2340 2355
@@ -2347,17 +2362,20 @@ void wlc_bmac_corereset(wlc_hw_info_t *wlc_hw, u32 flags)
2347 if (si_iscoreup(wlc_hw->sih)) { 2362 if (si_iscoreup(wlc_hw->sih)) {
2348 for (i = 0; i < NFIFO; i++) 2363 for (i = 0; i < NFIFO; i++)
2349 if ((wlc_hw->di[i]) && (!dma_txreset(wlc_hw->di[i]))) { 2364 if ((wlc_hw->di[i]) && (!dma_txreset(wlc_hw->di[i]))) {
2350 WL_ERROR(("wl%d: %s: dma_txreset[%d]: cannot stop dma\n", wlc_hw->unit, __func__, i)); 2365 WL_ERROR("wl%d: %s: dma_txreset[%d]: cannot stop dma\n",
2366 wlc_hw->unit, __func__, i);
2351 } 2367 }
2352 2368
2353 if ((wlc_hw->di[RX_FIFO]) 2369 if ((wlc_hw->di[RX_FIFO])
2354 && (!wlc_dma_rxreset(wlc_hw, RX_FIFO))) { 2370 && (!wlc_dma_rxreset(wlc_hw, RX_FIFO))) {
2355 WL_ERROR(("wl%d: %s: dma_rxreset[%d]: cannot stop dma\n", wlc_hw->unit, __func__, RX_FIFO)); 2371 WL_ERROR("wl%d: %s: dma_rxreset[%d]: cannot stop dma\n",
2372 wlc_hw->unit, __func__, RX_FIFO);
2356 } 2373 }
2357 if (D11REV_IS(wlc_hw->corerev, 4) 2374 if (D11REV_IS(wlc_hw->corerev, 4)
2358 && wlc_hw->di[RX_TXSTATUS_FIFO] 2375 && wlc_hw->di[RX_TXSTATUS_FIFO]
2359 && (!wlc_dma_rxreset(wlc_hw, RX_TXSTATUS_FIFO))) { 2376 && (!wlc_dma_rxreset(wlc_hw, RX_TXSTATUS_FIFO))) {
2360 WL_ERROR(("wl%d: %s: dma_rxreset[%d]: cannot stop dma\n", wlc_hw->unit, __func__, RX_TXSTATUS_FIFO)); 2377 WL_ERROR("wl%d: %s: dma_rxreset[%d]: cannot stop dma\n",
2378 wlc_hw->unit, __func__, RX_TXSTATUS_FIFO);
2361 } 2379 }
2362 } 2380 }
2363 /* if noreset, just stop the psm and return */ 2381 /* if noreset, just stop the psm and return */
@@ -2413,14 +2431,14 @@ void wlc_bmac_corereset(wlc_hw_info_t *wlc_hw, u32 flags)
2413 * txfifo sizes needs to be modified(increased) since the newer cores 2431 * txfifo sizes needs to be modified(increased) since the newer cores
2414 * have more memory. 2432 * have more memory.
2415 */ 2433 */
2416static void wlc_corerev_fifofixup(wlc_hw_info_t *wlc_hw) 2434static void wlc_corerev_fifofixup(struct wlc_hw_info *wlc_hw)
2417{ 2435{
2418 d11regs_t *regs = wlc_hw->regs; 2436 d11regs_t *regs = wlc_hw->regs;
2419 u16 fifo_nu; 2437 u16 fifo_nu;
2420 u16 txfifo_startblk = TXFIFO_START_BLK, txfifo_endblk; 2438 u16 txfifo_startblk = TXFIFO_START_BLK, txfifo_endblk;
2421 u16 txfifo_def, txfifo_def1; 2439 u16 txfifo_def, txfifo_def1;
2422 u16 txfifo_cmd; 2440 u16 txfifo_cmd;
2423 osl_t *osh; 2441 struct osl_info *osh;
2424 2442
2425 if (D11REV_LT(wlc_hw->corerev, 9)) 2443 if (D11REV_LT(wlc_hw->corerev, 9))
2426 goto exit; 2444 goto exit;
@@ -2473,22 +2491,22 @@ static void wlc_corerev_fifofixup(wlc_hw_info_t *wlc_hw)
2473 * config other core registers 2491 * config other core registers
2474 * init dma 2492 * init dma
2475 */ 2493 */
2476static void wlc_coreinit(wlc_info_t *wlc) 2494static void wlc_coreinit(struct wlc_info *wlc)
2477{ 2495{
2478 wlc_hw_info_t *wlc_hw = wlc->hw; 2496 struct wlc_hw_info *wlc_hw = wlc->hw;
2479 d11regs_t *regs; 2497 d11regs_t *regs;
2480 u32 sflags; 2498 u32 sflags;
2481 uint bcnint_us; 2499 uint bcnint_us;
2482 uint i = 0; 2500 uint i = 0;
2483 bool fifosz_fixup = false; 2501 bool fifosz_fixup = false;
2484 osl_t *osh; 2502 struct osl_info *osh;
2485 int err = 0; 2503 int err = 0;
2486 u16 buf[NFIFO]; 2504 u16 buf[NFIFO];
2487 2505
2488 regs = wlc_hw->regs; 2506 regs = wlc_hw->regs;
2489 osh = wlc_hw->osh; 2507 osh = wlc_hw->osh;
2490 2508
2491 WL_TRACE(("wl%d: wlc_coreinit\n", wlc_hw->unit)); 2509 WL_TRACE("wl%d: wlc_coreinit\n", wlc_hw->unit);
2492 2510
2493 /* reset PSM */ 2511 /* reset PSM */
2494 wlc_bmac_mctrl(wlc_hw, ~0, (MCTL_IHR_EN | MCTL_PSM_JMP_0 | MCTL_WAKE)); 2512 wlc_bmac_mctrl(wlc_hw, ~0, (MCTL_IHR_EN | MCTL_PSM_JMP_0 | MCTL_WAKE));
@@ -2511,8 +2529,8 @@ static void wlc_coreinit(wlc_info_t *wlc)
2511 SPINWAIT(((R_REG(osh, &regs->macintstatus) & MI_MACSSPNDD) == 0), 2529 SPINWAIT(((R_REG(osh, &regs->macintstatus) & MI_MACSSPNDD) == 0),
2512 1000 * 1000); 2530 1000 * 1000);
2513 if ((R_REG(osh, &regs->macintstatus) & MI_MACSSPNDD) == 0) 2531 if ((R_REG(osh, &regs->macintstatus) & MI_MACSSPNDD) == 0)
2514 WL_ERROR(("wl%d: wlc_coreinit: ucode did not self-suspend!\n", 2532 WL_ERROR("wl%d: wlc_coreinit: ucode did not self-suspend!\n",
2515 wlc_hw->unit)); 2533 wlc_hw->unit);
2516 2534
2517 wlc_gpio_init(wlc); 2535 wlc_gpio_init(wlc);
2518 2536
@@ -2522,18 +2540,18 @@ static void wlc_coreinit(wlc_info_t *wlc)
2522 if (WLCISNPHY(wlc_hw->band)) 2540 if (WLCISNPHY(wlc_hw->band))
2523 wlc_write_inits(wlc_hw, d11n0initvals16); 2541 wlc_write_inits(wlc_hw, d11n0initvals16);
2524 else 2542 else
2525 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n", 2543 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
2526 __func__, wlc_hw->unit, wlc_hw->corerev)); 2544 __func__, wlc_hw->unit, wlc_hw->corerev);
2527 } else if (D11REV_IS(wlc_hw->corerev, 24)) { 2545 } else if (D11REV_IS(wlc_hw->corerev, 24)) {
2528 if (WLCISLCNPHY(wlc_hw->band)) { 2546 if (WLCISLCNPHY(wlc_hw->band)) {
2529 wlc_write_inits(wlc_hw, d11lcn0initvals24); 2547 wlc_write_inits(wlc_hw, d11lcn0initvals24);
2530 } else { 2548 } else {
2531 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n", 2549 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
2532 __func__, wlc_hw->unit, wlc_hw->corerev)); 2550 __func__, wlc_hw->unit, wlc_hw->corerev);
2533 } 2551 }
2534 } else { 2552 } else {
2535 WL_ERROR(("%s: wl%d: unsupported corerev %d\n", 2553 WL_ERROR("%s: wl%d: unsupported corerev %d\n",
2536 __func__, wlc_hw->unit, wlc_hw->corerev)); 2554 __func__, wlc_hw->unit, wlc_hw->corerev);
2537 } 2555 }
2538 2556
2539 /* For old ucode, txfifo sizes needs to be modified(increased) for Corerev >= 9 */ 2557 /* For old ucode, txfifo sizes needs to be modified(increased) for Corerev >= 9 */
@@ -2575,7 +2593,8 @@ static void wlc_coreinit(wlc_info_t *wlc)
2575 err = -1; 2593 err = -1;
2576 } 2594 }
2577 if (err != 0) { 2595 if (err != 0) {
2578 WL_ERROR(("wlc_coreinit: txfifo mismatch: ucode size %d driver size %d index %d\n", buf[i], wlc_hw->xmtfifo_sz[i], i)); 2596 WL_ERROR("wlc_coreinit: txfifo mismatch: ucode size %d driver size %d index %d\n",
2597 buf[i], wlc_hw->xmtfifo_sz[i], i);
2579 /* DO NOT ASSERT corerev < 4 even there is a mismatch 2598 /* DO NOT ASSERT corerev < 4 even there is a mismatch
2580 * shmem, since driver don't overwrite those chip and 2599 * shmem, since driver don't overwrite those chip and
2581 * ucode initialize data will be used. 2600 * ucode initialize data will be used.
@@ -2684,15 +2703,15 @@ static void wlc_coreinit(wlc_info_t *wlc)
2684 * - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889 2703 * - 559241 = 0x88889 => tsf_clk_frac_h = 0x8, tsf_clk_frac_l = 0x8889
2685 */ 2704 */
2686 2705
2687void wlc_bmac_switch_macfreq(wlc_hw_info_t *wlc_hw, u8 spurmode) 2706void wlc_bmac_switch_macfreq(struct wlc_hw_info *wlc_hw, u8 spurmode)
2688{ 2707{
2689 d11regs_t *regs; 2708 d11regs_t *regs;
2690 osl_t *osh; 2709 struct osl_info *osh;
2691 regs = wlc_hw->regs; 2710 regs = wlc_hw->regs;
2692 osh = wlc_hw->osh; 2711 osh = wlc_hw->osh;
2693 2712
2694 if ((CHIPID(wlc_hw->sih->chip) == BCM43224_CHIP_ID) || 2713 if ((wlc_hw->sih->chip == BCM43224_CHIP_ID) ||
2695 (CHIPID(wlc_hw->sih->chip) == BCM43225_CHIP_ID)) { 2714 (wlc_hw->sih->chip == BCM43225_CHIP_ID)) {
2696 if (spurmode == WL_SPURAVOID_ON2) { /* 126Mhz */ 2715 if (spurmode == WL_SPURAVOID_ON2) { /* 126Mhz */
2697 W_REG(osh, &regs->tsf_clk_frac_l, 0x2082); 2716 W_REG(osh, &regs->tsf_clk_frac_l, 0x2082);
2698 W_REG(osh, &regs->tsf_clk_frac_h, 0x8); 2717 W_REG(osh, &regs->tsf_clk_frac_h, 0x8);
@@ -2715,12 +2734,12 @@ void wlc_bmac_switch_macfreq(wlc_hw_info_t *wlc_hw, u8 spurmode)
2715} 2734}
2716 2735
2717/* Initialize GPIOs that are controlled by D11 core */ 2736/* Initialize GPIOs that are controlled by D11 core */
2718static void wlc_gpio_init(wlc_info_t *wlc) 2737static void wlc_gpio_init(struct wlc_info *wlc)
2719{ 2738{
2720 wlc_hw_info_t *wlc_hw = wlc->hw; 2739 struct wlc_hw_info *wlc_hw = wlc->hw;
2721 d11regs_t *regs; 2740 d11regs_t *regs;
2722 u32 gc, gm; 2741 u32 gc, gm;
2723 osl_t *osh; 2742 struct osl_info *osh;
2724 2743
2725 regs = wlc_hw->regs; 2744 regs = wlc_hw->regs;
2726 osh = wlc_hw->osh; 2745 osh = wlc_hw->osh;
@@ -2780,9 +2799,9 @@ static void wlc_gpio_init(wlc_info_t *wlc)
2780 si_gpiocontrol(wlc_hw->sih, gm, gc, GPIO_DRV_PRIORITY); 2799 si_gpiocontrol(wlc_hw->sih, gm, gc, GPIO_DRV_PRIORITY);
2781} 2800}
2782 2801
2783static void wlc_ucode_download(wlc_hw_info_t *wlc_hw) 2802static void wlc_ucode_download(struct wlc_hw_info *wlc_hw)
2784{ 2803{
2785 wlc_info_t *wlc; 2804 struct wlc_info *wlc;
2786 wlc = wlc_hw->wlc; 2805 wlc = wlc_hw->wlc;
2787 2806
2788 if (wlc_hw->ucode_loaded) 2807 if (wlc_hw->ucode_loaded)
@@ -2794,30 +2813,30 @@ static void wlc_ucode_download(wlc_hw_info_t *wlc_hw)
2794 bcm43xx_16_mimosz); 2813 bcm43xx_16_mimosz);
2795 wlc_hw->ucode_loaded = true; 2814 wlc_hw->ucode_loaded = true;
2796 } else 2815 } else
2797 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n", 2816 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
2798 __func__, wlc_hw->unit, wlc_hw->corerev)); 2817 __func__, wlc_hw->unit, wlc_hw->corerev);
2799 } else if (D11REV_IS(wlc_hw->corerev, 24)) { 2818 } else if (D11REV_IS(wlc_hw->corerev, 24)) {
2800 if (WLCISLCNPHY(wlc_hw->band)) { 2819 if (WLCISLCNPHY(wlc_hw->band)) {
2801 wlc_ucode_write(wlc_hw, bcm43xx_24_lcn, 2820 wlc_ucode_write(wlc_hw, bcm43xx_24_lcn,
2802 bcm43xx_24_lcnsz); 2821 bcm43xx_24_lcnsz);
2803 wlc_hw->ucode_loaded = true; 2822 wlc_hw->ucode_loaded = true;
2804 } else { 2823 } else {
2805 WL_ERROR(("%s: wl%d: unsupported phy in corerev %d\n", 2824 WL_ERROR("%s: wl%d: unsupported phy in corerev %d\n",
2806 __func__, wlc_hw->unit, wlc_hw->corerev)); 2825 __func__, wlc_hw->unit, wlc_hw->corerev);
2807 } 2826 }
2808 } 2827 }
2809} 2828}
2810 2829
2811static void wlc_ucode_write(wlc_hw_info_t *wlc_hw, const u32 ucode[], 2830static void wlc_ucode_write(struct wlc_hw_info *wlc_hw, const u32 ucode[],
2812 const uint nbytes) { 2831 const uint nbytes) {
2813 osl_t *osh; 2832 struct osl_info *osh;
2814 d11regs_t *regs = wlc_hw->regs; 2833 d11regs_t *regs = wlc_hw->regs;
2815 uint i; 2834 uint i;
2816 uint count; 2835 uint count;
2817 2836
2818 osh = wlc_hw->osh; 2837 osh = wlc_hw->osh;
2819 2838
2820 WL_TRACE(("wl%d: wlc_ucode_write\n", wlc_hw->unit)); 2839 WL_TRACE("wl%d: wlc_ucode_write\n", wlc_hw->unit);
2821 2840
2822 ASSERT(IS_ALIGNED(nbytes, sizeof(u32))); 2841 ASSERT(IS_ALIGNED(nbytes, sizeof(u32)));
2823 2842
@@ -2829,13 +2848,13 @@ static void wlc_ucode_write(wlc_hw_info_t *wlc_hw, const u32 ucode[],
2829 W_REG(osh, &regs->objdata, ucode[i]); 2848 W_REG(osh, &regs->objdata, ucode[i]);
2830} 2849}
2831 2850
2832static void wlc_write_inits(wlc_hw_info_t *wlc_hw, const d11init_t *inits) 2851static void wlc_write_inits(struct wlc_hw_info *wlc_hw, const d11init_t *inits)
2833{ 2852{
2834 int i; 2853 int i;
2835 osl_t *osh; 2854 struct osl_info *osh;
2836 volatile u8 *base; 2855 volatile u8 *base;
2837 2856
2838 WL_TRACE(("wl%d: wlc_write_inits\n", wlc_hw->unit)); 2857 WL_TRACE("wl%d: wlc_write_inits\n", wlc_hw->unit);
2839 2858
2840 osh = wlc_hw->osh; 2859 osh = wlc_hw->osh;
2841 base = (volatile u8 *)wlc_hw->regs; 2860 base = (volatile u8 *)wlc_hw->regs;
@@ -2852,7 +2871,7 @@ static void wlc_write_inits(wlc_hw_info_t *wlc_hw, const d11init_t *inits)
2852 } 2871 }
2853} 2872}
2854 2873
2855static void wlc_ucode_txant_set(wlc_hw_info_t *wlc_hw) 2874static void wlc_ucode_txant_set(struct wlc_hw_info *wlc_hw)
2856{ 2875{
2857 u16 phyctl; 2876 u16 phyctl;
2858 u16 phytxant = wlc_hw->bmac_phytxant; 2877 u16 phytxant = wlc_hw->bmac_phytxant;
@@ -2869,7 +2888,7 @@ static void wlc_ucode_txant_set(wlc_hw_info_t *wlc_hw)
2869 wlc_bmac_write_shm(wlc_hw, M_RSP_PCTLWD, phyctl); 2888 wlc_bmac_write_shm(wlc_hw, M_RSP_PCTLWD, phyctl);
2870} 2889}
2871 2890
2872void wlc_bmac_txant_set(wlc_hw_info_t *wlc_hw, u16 phytxant) 2891void wlc_bmac_txant_set(struct wlc_hw_info *wlc_hw, u16 phytxant)
2873{ 2892{
2874 /* update sw state */ 2893 /* update sw state */
2875 wlc_hw->bmac_phytxant = phytxant; 2894 wlc_hw->bmac_phytxant = phytxant;
@@ -2881,12 +2900,12 @@ void wlc_bmac_txant_set(wlc_hw_info_t *wlc_hw, u16 phytxant)
2881 2900
2882} 2901}
2883 2902
2884u16 wlc_bmac_get_txant(wlc_hw_info_t *wlc_hw) 2903u16 wlc_bmac_get_txant(struct wlc_hw_info *wlc_hw)
2885{ 2904{
2886 return (u16) wlc_hw->wlc->stf->txant; 2905 return (u16) wlc_hw->wlc->stf->txant;
2887} 2906}
2888 2907
2889void wlc_bmac_antsel_type_set(wlc_hw_info_t *wlc_hw, u8 antsel_type) 2908void wlc_bmac_antsel_type_set(struct wlc_hw_info *wlc_hw, u8 antsel_type)
2890{ 2909{
2891 wlc_hw->antsel_type = antsel_type; 2910 wlc_hw->antsel_type = antsel_type;
2892 2911
@@ -2894,7 +2913,7 @@ void wlc_bmac_antsel_type_set(wlc_hw_info_t *wlc_hw, u8 antsel_type)
2894 wlc_phy_antsel_type_set(wlc_hw->band->pi, antsel_type); 2913 wlc_phy_antsel_type_set(wlc_hw->band->pi, antsel_type);
2895} 2914}
2896 2915
2897void wlc_bmac_fifoerrors(wlc_hw_info_t *wlc_hw) 2916void wlc_bmac_fifoerrors(struct wlc_hw_info *wlc_hw)
2898{ 2917{
2899 bool fatal = false; 2918 bool fatal = false;
2900 uint unit; 2919 uint unit;
@@ -2911,44 +2930,45 @@ void wlc_bmac_fifoerrors(wlc_hw_info_t *wlc_hw)
2911 if (!intstatus) 2930 if (!intstatus)
2912 continue; 2931 continue;
2913 2932
2914 WL_TRACE(("wl%d: wlc_bmac_fifoerrors: intstatus%d 0x%x\n", unit, 2933 WL_TRACE("wl%d: wlc_bmac_fifoerrors: intstatus%d 0x%x\n",
2915 idx, intstatus)); 2934 unit, idx, intstatus);
2916 2935
2917 if (intstatus & I_RO) { 2936 if (intstatus & I_RO) {
2918 WL_ERROR(("wl%d: fifo %d: receive fifo overflow\n", 2937 WL_ERROR("wl%d: fifo %d: receive fifo overflow\n",
2919 unit, idx)); 2938 unit, idx);
2920 WLCNTINCR(wlc_hw->wlc->pub->_cnt->rxoflo); 2939 WLCNTINCR(wlc_hw->wlc->pub->_cnt->rxoflo);
2921 fatal = true; 2940 fatal = true;
2922 } 2941 }
2923 2942
2924 if (intstatus & I_PC) { 2943 if (intstatus & I_PC) {
2925 WL_ERROR(("wl%d: fifo %d: descriptor error\n", unit, 2944 WL_ERROR("wl%d: fifo %d: descriptor error\n",
2926 idx)); 2945 unit, idx);
2927 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmade); 2946 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmade);
2928 fatal = true; 2947 fatal = true;
2929 } 2948 }
2930 2949
2931 if (intstatus & I_PD) { 2950 if (intstatus & I_PD) {
2932 WL_ERROR(("wl%d: fifo %d: data error\n", unit, idx)); 2951 WL_ERROR("wl%d: fifo %d: data error\n", unit, idx);
2933 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmada); 2952 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmada);
2934 fatal = true; 2953 fatal = true;
2935 } 2954 }
2936 2955
2937 if (intstatus & I_DE) { 2956 if (intstatus & I_DE) {
2938 WL_ERROR(("wl%d: fifo %d: descriptor protocol error\n", 2957 WL_ERROR("wl%d: fifo %d: descriptor protocol error\n",
2939 unit, idx)); 2958 unit, idx);
2940 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmape); 2959 WLCNTINCR(wlc_hw->wlc->pub->_cnt->dmape);
2941 fatal = true; 2960 fatal = true;
2942 } 2961 }
2943 2962
2944 if (intstatus & I_RU) { 2963 if (intstatus & I_RU) {
2945 WL_ERROR(("wl%d: fifo %d: receive descriptor underflow\n", unit, idx)); 2964 WL_ERROR("wl%d: fifo %d: receive descriptor underflow\n",
2965 idx, unit);
2946 WLCNTINCR(wlc_hw->wlc->pub->_cnt->rxuflo[idx]); 2966 WLCNTINCR(wlc_hw->wlc->pub->_cnt->rxuflo[idx]);
2947 } 2967 }
2948 2968
2949 if (intstatus & I_XU) { 2969 if (intstatus & I_XU) {
2950 WL_ERROR(("wl%d: fifo %d: transmit fifo underflow\n", 2970 WL_ERROR("wl%d: fifo %d: transmit fifo underflow\n",
2951 idx, unit)); 2971 idx, unit);
2952 WLCNTINCR(wlc_hw->wlc->pub->_cnt->txuflo); 2972 WLCNTINCR(wlc_hw->wlc->pub->_cnt->txuflo);
2953 fatal = true; 2973 fatal = true;
2954 } 2974 }
@@ -2962,9 +2982,9 @@ void wlc_bmac_fifoerrors(wlc_hw_info_t *wlc_hw)
2962 } 2982 }
2963} 2983}
2964 2984
2965void wlc_intrson(wlc_info_t *wlc) 2985void wlc_intrson(struct wlc_info *wlc)
2966{ 2986{
2967 wlc_hw_info_t *wlc_hw = wlc->hw; 2987 struct wlc_hw_info *wlc_hw = wlc->hw;
2968 ASSERT(wlc->defmacintmask); 2988 ASSERT(wlc->defmacintmask);
2969 wlc->macintmask = wlc->defmacintmask; 2989 wlc->macintmask = wlc->defmacintmask;
2970 W_REG(wlc_hw->osh, &wlc_hw->regs->macintmask, wlc->macintmask); 2990 W_REG(wlc_hw->osh, &wlc_hw->regs->macintmask, wlc->macintmask);
@@ -2975,7 +2995,7 @@ void wlc_intrson(wlc_info_t *wlc)
2975 * but also because per-port code may require sync with valid interrupt. 2995 * but also because per-port code may require sync with valid interrupt.
2976 */ 2996 */
2977 2997
2978static u32 wlc_wlintrsoff(wlc_info_t *wlc) 2998static u32 wlc_wlintrsoff(struct wlc_info *wlc)
2979{ 2999{
2980 if (!wlc->hw->up) 3000 if (!wlc->hw->up)
2981 return 0; 3001 return 0;
@@ -2983,7 +3003,7 @@ static u32 wlc_wlintrsoff(wlc_info_t *wlc)
2983 return wl_intrsoff(wlc->wl); 3003 return wl_intrsoff(wlc->wl);
2984} 3004}
2985 3005
2986static void wlc_wlintrsrestore(wlc_info_t *wlc, u32 macintmask) 3006static void wlc_wlintrsrestore(struct wlc_info *wlc, u32 macintmask)
2987{ 3007{
2988 if (!wlc->hw->up) 3008 if (!wlc->hw->up)
2989 return; 3009 return;
@@ -2991,9 +3011,9 @@ static void wlc_wlintrsrestore(wlc_info_t *wlc, u32 macintmask)
2991 wl_intrsrestore(wlc->wl, macintmask); 3011 wl_intrsrestore(wlc->wl, macintmask);
2992} 3012}
2993 3013
2994u32 wlc_intrsoff(wlc_info_t *wlc) 3014u32 wlc_intrsoff(struct wlc_info *wlc)
2995{ 3015{
2996 wlc_hw_info_t *wlc_hw = wlc->hw; 3016 struct wlc_hw_info *wlc_hw = wlc->hw;
2997 u32 macintmask; 3017 u32 macintmask;
2998 3018
2999 if (!wlc_hw->clk) 3019 if (!wlc_hw->clk)
@@ -3010,9 +3030,9 @@ u32 wlc_intrsoff(wlc_info_t *wlc)
3010 return wlc->macintstatus ? 0 : macintmask; 3030 return wlc->macintstatus ? 0 : macintmask;
3011} 3031}
3012 3032
3013void wlc_intrsrestore(wlc_info_t *wlc, u32 macintmask) 3033void wlc_intrsrestore(struct wlc_info *wlc, u32 macintmask)
3014{ 3034{
3015 wlc_hw_info_t *wlc_hw = wlc->hw; 3035 struct wlc_hw_info *wlc_hw = wlc->hw;
3016 if (!wlc_hw->clk) 3036 if (!wlc_hw->clk)
3017 return; 3037 return;
3018 3038
@@ -3020,7 +3040,7 @@ void wlc_intrsrestore(wlc_info_t *wlc, u32 macintmask)
3020 W_REG(wlc_hw->osh, &wlc_hw->regs->macintmask, wlc->macintmask); 3040 W_REG(wlc_hw->osh, &wlc_hw->regs->macintmask, wlc->macintmask);
3021} 3041}
3022 3042
3023void wlc_bmac_mute(wlc_hw_info_t *wlc_hw, bool on, mbool flags) 3043void wlc_bmac_mute(struct wlc_hw_info *wlc_hw, bool on, mbool flags)
3024{ 3044{
3025 struct ether_addr null_ether_addr = { {0, 0, 0, 0, 0, 0} }; 3045 struct ether_addr null_ether_addr = { {0, 0, 0, 0, 0, 0} };
3026 3046
@@ -3056,12 +3076,12 @@ void wlc_bmac_mute(wlc_hw_info_t *wlc_hw, bool on, mbool flags)
3056 wlc_ucode_mute_override_clear(wlc_hw); 3076 wlc_ucode_mute_override_clear(wlc_hw);
3057} 3077}
3058 3078
3059void wlc_bmac_set_deaf(wlc_hw_info_t *wlc_hw, bool user_flag) 3079void wlc_bmac_set_deaf(struct wlc_hw_info *wlc_hw, bool user_flag)
3060{ 3080{
3061 wlc_phy_set_deaf(wlc_hw->band->pi, user_flag); 3081 wlc_phy_set_deaf(wlc_hw->band->pi, user_flag);
3062} 3082}
3063 3083
3064int wlc_bmac_xmtfifo_sz_get(wlc_hw_info_t *wlc_hw, uint fifo, uint *blocks) 3084int wlc_bmac_xmtfifo_sz_get(struct wlc_hw_info *wlc_hw, uint fifo, uint *blocks)
3065{ 3085{
3066 if (fifo >= NFIFO) 3086 if (fifo >= NFIFO)
3067 return BCME_RANGE; 3087 return BCME_RANGE;
@@ -3071,7 +3091,7 @@ int wlc_bmac_xmtfifo_sz_get(wlc_hw_info_t *wlc_hw, uint fifo, uint *blocks)
3071 return 0; 3091 return 0;
3072} 3092}
3073 3093
3074int wlc_bmac_xmtfifo_sz_set(wlc_hw_info_t *wlc_hw, uint fifo, uint blocks) 3094int wlc_bmac_xmtfifo_sz_set(struct wlc_hw_info *wlc_hw, uint fifo, uint blocks)
3075{ 3095{
3076 if (fifo >= NFIFO || blocks > 299) 3096 if (fifo >= NFIFO || blocks > 299)
3077 return BCME_RANGE; 3097 return BCME_RANGE;
@@ -3091,7 +3111,7 @@ int wlc_bmac_xmtfifo_sz_set(wlc_hw_info_t *wlc_hw, uint fifo, uint blocks)
3091 * be pulling data into a tx fifo, by the time the MAC acks the suspend 3111 * be pulling data into a tx fifo, by the time the MAC acks the suspend
3092 * request. 3112 * request.
3093 */ 3113 */
3094bool wlc_bmac_tx_fifo_suspended(wlc_hw_info_t *wlc_hw, uint tx_fifo) 3114bool wlc_bmac_tx_fifo_suspended(struct wlc_hw_info *wlc_hw, uint tx_fifo)
3095{ 3115{
3096 /* check that a suspend has been requested and is no longer pending */ 3116 /* check that a suspend has been requested and is no longer pending */
3097 3117
@@ -3110,7 +3130,7 @@ bool wlc_bmac_tx_fifo_suspended(wlc_hw_info_t *wlc_hw, uint tx_fifo)
3110 return false; 3130 return false;
3111} 3131}
3112 3132
3113void wlc_bmac_tx_fifo_suspend(wlc_hw_info_t *wlc_hw, uint tx_fifo) 3133void wlc_bmac_tx_fifo_suspend(struct wlc_hw_info *wlc_hw, uint tx_fifo)
3114{ 3134{
3115 u8 fifo = 1 << tx_fifo; 3135 u8 fifo = 1 << tx_fifo;
3116 3136
@@ -3141,7 +3161,7 @@ void wlc_bmac_tx_fifo_suspend(wlc_hw_info_t *wlc_hw, uint tx_fifo)
3141 } 3161 }
3142} 3162}
3143 3163
3144void wlc_bmac_tx_fifo_resume(wlc_hw_info_t *wlc_hw, uint tx_fifo) 3164void wlc_bmac_tx_fifo_resume(struct wlc_hw_info *wlc_hw, uint tx_fifo)
3145{ 3165{
3146 /* BMAC_NOTE: WLC_TX_FIFO_ENAB is done in wlc_dpc() for DMA case but need to be done 3166 /* BMAC_NOTE: WLC_TX_FIFO_ENAB is done in wlc_dpc() for DMA case but need to be done
3147 * here for PIO otherwise the watchdog will catch the inconsistency and fire 3167 * here for PIO otherwise the watchdog will catch the inconsistency and fire
@@ -3169,20 +3189,20 @@ void wlc_bmac_tx_fifo_resume(wlc_hw_info_t *wlc_hw, uint tx_fifo)
3169 * 0 if the interrupt is not for us, or we are in some special cases; 3189 * 0 if the interrupt is not for us, or we are in some special cases;
3170 * device interrupt status bits otherwise. 3190 * device interrupt status bits otherwise.
3171 */ 3191 */
3172static inline u32 wlc_intstatus(wlc_info_t *wlc, bool in_isr) 3192static inline u32 wlc_intstatus(struct wlc_info *wlc, bool in_isr)
3173{ 3193{
3174 wlc_hw_info_t *wlc_hw = wlc->hw; 3194 struct wlc_hw_info *wlc_hw = wlc->hw;
3175 d11regs_t *regs = wlc_hw->regs; 3195 d11regs_t *regs = wlc_hw->regs;
3176 u32 macintstatus; 3196 u32 macintstatus;
3177 u32 intstatus_rxfifo, intstatus_txsfifo; 3197 u32 intstatus_rxfifo, intstatus_txsfifo;
3178 osl_t *osh; 3198 struct osl_info *osh;
3179 3199
3180 osh = wlc_hw->osh; 3200 osh = wlc_hw->osh;
3181 3201
3182 /* macintstatus includes a DMA interrupt summary bit */ 3202 /* macintstatus includes a DMA interrupt summary bit */
3183 macintstatus = R_REG(osh, &regs->macintstatus); 3203 macintstatus = R_REG(osh, &regs->macintstatus);
3184 3204
3185 WL_TRACE(("wl%d: macintstatus: 0x%x\n", wlc_hw->unit, macintstatus)); 3205 WL_TRACE("wl%d: macintstatus: 0x%x\n", wlc_hw->unit, macintstatus);
3186 3206
3187 /* detect cardbus removed, in power down(suspend) and in reset */ 3207 /* detect cardbus removed, in power down(suspend) and in reset */
3188 if (DEVICEREMOVED(wlc)) 3208 if (DEVICEREMOVED(wlc))
@@ -3207,9 +3227,7 @@ static inline u32 wlc_intstatus(wlc_info_t *wlc, bool in_isr)
3207 */ 3227 */
3208 /* turn off the interrupts */ 3228 /* turn off the interrupts */
3209 W_REG(osh, &regs->macintmask, 0); 3229 W_REG(osh, &regs->macintmask, 0);
3210#ifndef BCMSDIO
3211 (void)R_REG(osh, &regs->macintmask); /* sync readback */ 3230 (void)R_REG(osh, &regs->macintmask); /* sync readback */
3212#endif
3213 wlc->macintmask = 0; 3231 wlc->macintmask = 0;
3214 3232
3215 /* clear device interrupts */ 3233 /* clear device interrupts */
@@ -3224,7 +3242,9 @@ static inline u32 wlc_intstatus(wlc_info_t *wlc, bool in_isr)
3224 R_REG(osh, 3242 R_REG(osh,
3225 &regs->intctrlregs[RX_TXSTATUS_FIFO]. 3243 &regs->intctrlregs[RX_TXSTATUS_FIFO].
3226 intstatus); 3244 intstatus);
3227 WL_TRACE(("wl%d: intstatus_rxfifo 0x%x, intstatus_txsfifo 0x%x\n", wlc_hw->unit, intstatus_rxfifo, intstatus_txsfifo)); 3245 WL_TRACE("wl%d: intstatus_rxfifo 0x%x, intstatus_txsfifo 0x%x\n",
3246 wlc_hw->unit,
3247 intstatus_rxfifo, intstatus_txsfifo);
3228 3248
3229 /* defer unsolicited interrupt hints */ 3249 /* defer unsolicited interrupt hints */
3230 intstatus_rxfifo &= DEF_RXINTMASK; 3250 intstatus_rxfifo &= DEF_RXINTMASK;
@@ -3261,7 +3281,7 @@ static inline u32 wlc_intstatus(wlc_info_t *wlc, bool in_isr)
3261 3281
3262/* Update wlc->macintstatus and wlc->intstatus[]. */ 3282/* Update wlc->macintstatus and wlc->intstatus[]. */
3263/* Return true if they are updated successfully. false otherwise */ 3283/* Return true if they are updated successfully. false otherwise */
3264bool wlc_intrsupd(wlc_info_t *wlc) 3284bool wlc_intrsupd(struct wlc_info *wlc)
3265{ 3285{
3266 u32 macintstatus; 3286 u32 macintstatus;
3267 3287
@@ -3286,9 +3306,9 @@ bool wlc_intrsupd(wlc_info_t *wlc)
3286 * *wantdpc will be set to true if further wlc_dpc() processing is required, 3306 * *wantdpc will be set to true if further wlc_dpc() processing is required,
3287 * false otherwise. 3307 * false otherwise.
3288 */ 3308 */
3289bool BCMFASTPATH wlc_isr(wlc_info_t *wlc, bool *wantdpc) 3309bool BCMFASTPATH wlc_isr(struct wlc_info *wlc, bool *wantdpc)
3290{ 3310{
3291 wlc_hw_info_t *wlc_hw = wlc->hw; 3311 struct wlc_hw_info *wlc_hw = wlc->hw;
3292 u32 macintstatus; 3312 u32 macintstatus;
3293 3313
3294 *wantdpc = false; 3314 *wantdpc = false;
@@ -3300,7 +3320,7 @@ bool BCMFASTPATH wlc_isr(wlc_info_t *wlc, bool *wantdpc)
3300 macintstatus = wlc_intstatus(wlc, true); 3320 macintstatus = wlc_intstatus(wlc, true);
3301 3321
3302 if (macintstatus == 0xffffffff) 3322 if (macintstatus == 0xffffffff)
3303 WL_ERROR(("DEVICEREMOVED detected in the ISR code path.\n")); 3323 WL_ERROR("DEVICEREMOVED detected in the ISR code path\n");
3304 3324
3305 /* it is not for us */ 3325 /* it is not for us */
3306 if (macintstatus == 0) 3326 if (macintstatus == 0)
@@ -3317,20 +3337,20 @@ bool BCMFASTPATH wlc_isr(wlc_info_t *wlc, bool *wantdpc)
3317} 3337}
3318 3338
3319/* process tx completion events for corerev < 5 */ 3339/* process tx completion events for corerev < 5 */
3320static bool wlc_bmac_txstatus_corerev4(wlc_hw_info_t *wlc_hw) 3340static bool wlc_bmac_txstatus_corerev4(struct wlc_hw_info *wlc_hw)
3321{ 3341{
3322 void *status_p; 3342 struct sk_buff *status_p;
3323 tx_status_t *txs; 3343 tx_status_t *txs;
3324 osl_t *osh; 3344 struct osl_info *osh;
3325 bool fatal = false; 3345 bool fatal = false;
3326 3346
3327 WL_TRACE(("wl%d: wlc_txstatusrecv\n", wlc_hw->unit)); 3347 WL_TRACE("wl%d: wlc_txstatusrecv\n", wlc_hw->unit);
3328 3348
3329 osh = wlc_hw->osh; 3349 osh = wlc_hw->osh;
3330 3350
3331 while (!fatal && (status_p = dma_rx(wlc_hw->di[RX_TXSTATUS_FIFO]))) { 3351 while (!fatal && (status_p = dma_rx(wlc_hw->di[RX_TXSTATUS_FIFO]))) {
3332 3352
3333 txs = (tx_status_t *) PKTDATA(status_p); 3353 txs = (tx_status_t *) status_p->data;
3334 /* MAC uses little endian only */ 3354 /* MAC uses little endian only */
3335 ltoh16_buf((void *)txs, sizeof(tx_status_t)); 3355 ltoh16_buf((void *)txs, sizeof(tx_status_t));
3336 3356
@@ -3340,7 +3360,7 @@ static bool wlc_bmac_txstatus_corerev4(wlc_hw_info_t *wlc_hw)
3340 3360
3341 fatal = wlc_bmac_dotxstatus(wlc_hw, txs, 0); 3361 fatal = wlc_bmac_dotxstatus(wlc_hw, txs, 0);
3342 3362
3343 PKTFREE(osh, status_p, false); 3363 pkt_buf_free_skb(osh, status_p, false);
3344 } 3364 }
3345 3365
3346 if (fatal) 3366 if (fatal)
@@ -3353,7 +3373,7 @@ static bool wlc_bmac_txstatus_corerev4(wlc_hw_info_t *wlc_hw)
3353} 3373}
3354 3374
3355static bool BCMFASTPATH 3375static bool BCMFASTPATH
3356wlc_bmac_dotxstatus(wlc_hw_info_t *wlc_hw, tx_status_t *txs, u32 s2) 3376wlc_bmac_dotxstatus(struct wlc_hw_info *wlc_hw, tx_status_t *txs, u32 s2)
3357{ 3377{
3358 /* discard intermediate indications for ucode with one legitimate case: 3378 /* discard intermediate indications for ucode with one legitimate case:
3359 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent 3379 * e.g. if "useRTS" is set. ucode did a successful rts/cts exchange, but the subsequent
@@ -3372,12 +3392,12 @@ wlc_bmac_dotxstatus(wlc_hw_info_t *wlc_hw, tx_status_t *txs, u32 s2)
3372 * Return true if more tx status need to be processed. false otherwise. 3392 * Return true if more tx status need to be processed. false otherwise.
3373 */ 3393 */
3374static bool BCMFASTPATH 3394static bool BCMFASTPATH
3375wlc_bmac_txstatus(wlc_hw_info_t *wlc_hw, bool bound, bool *fatal) 3395wlc_bmac_txstatus(struct wlc_hw_info *wlc_hw, bool bound, bool *fatal)
3376{ 3396{
3377 bool morepending = false; 3397 bool morepending = false;
3378 wlc_info_t *wlc = wlc_hw->wlc; 3398 struct wlc_info *wlc = wlc_hw->wlc;
3379 3399
3380 WL_TRACE(("wl%d: wlc_bmac_txstatus\n", wlc_hw->unit)); 3400 WL_TRACE("wl%d: wlc_bmac_txstatus\n", wlc_hw->unit);
3381 3401
3382 if (D11REV_IS(wlc_hw->corerev, 4)) { 3402 if (D11REV_IS(wlc_hw->corerev, 4)) {
3383 /* to retire soon */ 3403 /* to retire soon */
@@ -3388,7 +3408,7 @@ wlc_bmac_txstatus(wlc_hw_info_t *wlc_hw, bool bound, bool *fatal)
3388 } else { 3408 } else {
3389 /* corerev >= 5 */ 3409 /* corerev >= 5 */
3390 d11regs_t *regs; 3410 d11regs_t *regs;
3391 osl_t *osh; 3411 struct osl_info *osh;
3392 tx_status_t txstatus, *txs; 3412 tx_status_t txstatus, *txs;
3393 u32 s1, s2; 3413 u32 s1, s2;
3394 uint n = 0; 3414 uint n = 0;
@@ -3402,8 +3422,8 @@ wlc_bmac_txstatus(wlc_hw_info_t *wlc_hw, bool bound, bool *fatal)
3402 && (s1 = R_REG(osh, &regs->frmtxstatus)) & TXS_V) { 3422 && (s1 = R_REG(osh, &regs->frmtxstatus)) & TXS_V) {
3403 3423
3404 if (s1 == 0xffffffff) { 3424 if (s1 == 0xffffffff) {
3405 WL_ERROR(("wl%d: %s: dead chip\n", 3425 WL_ERROR("wl%d: %s: dead chip\n",
3406 wlc_hw->unit, __func__)); 3426 wlc_hw->unit, __func__);
3407 ASSERT(s1 != 0xffffffff); 3427 ASSERT(s1 != 0xffffffff);
3408 return morepending; 3428 return morepending;
3409 } 3429 }
@@ -3436,15 +3456,15 @@ wlc_bmac_txstatus(wlc_hw_info_t *wlc_hw, bool bound, bool *fatal)
3436 return morepending; 3456 return morepending;
3437} 3457}
3438 3458
3439void wlc_suspend_mac_and_wait(wlc_info_t *wlc) 3459void wlc_suspend_mac_and_wait(struct wlc_info *wlc)
3440{ 3460{
3441 wlc_hw_info_t *wlc_hw = wlc->hw; 3461 struct wlc_hw_info *wlc_hw = wlc->hw;
3442 d11regs_t *regs = wlc_hw->regs; 3462 d11regs_t *regs = wlc_hw->regs;
3443 u32 mc, mi; 3463 u32 mc, mi;
3444 osl_t *osh; 3464 struct osl_info *osh;
3445 3465
3446 WL_TRACE(("wl%d: wlc_suspend_mac_and_wait: bandunit %d\n", wlc_hw->unit, 3466 WL_TRACE("wl%d: wlc_suspend_mac_and_wait: bandunit %d\n",
3447 wlc_hw->band->bandunit)); 3467 wlc_hw->unit, wlc_hw->band->bandunit);
3448 3468
3449 /* 3469 /*
3450 * Track overlapping suspend requests 3470 * Track overlapping suspend requests
@@ -3461,7 +3481,7 @@ void wlc_suspend_mac_and_wait(wlc_info_t *wlc)
3461 mc = R_REG(osh, &regs->maccontrol); 3481 mc = R_REG(osh, &regs->maccontrol);
3462 3482
3463 if (mc == 0xffffffff) { 3483 if (mc == 0xffffffff) {
3464 WL_ERROR(("wl%d: %s: dead chip\n", wlc_hw->unit, __func__)); 3484 WL_ERROR("wl%d: %s: dead chip\n", wlc_hw->unit, __func__);
3465 wl_down(wlc->wl); 3485 wl_down(wlc->wl);
3466 return; 3486 return;
3467 } 3487 }
@@ -3471,7 +3491,7 @@ void wlc_suspend_mac_and_wait(wlc_info_t *wlc)
3471 3491
3472 mi = R_REG(osh, &regs->macintstatus); 3492 mi = R_REG(osh, &regs->macintstatus);
3473 if (mi == 0xffffffff) { 3493 if (mi == 0xffffffff) {
3474 WL_ERROR(("wl%d: %s: dead chip\n", wlc_hw->unit, __func__)); 3494 WL_ERROR("wl%d: %s: dead chip\n", wlc_hw->unit, __func__);
3475 wl_down(wlc->wl); 3495 wl_down(wlc->wl);
3476 return; 3496 return;
3477 } 3497 }
@@ -3483,15 +3503,18 @@ void wlc_suspend_mac_and_wait(wlc_info_t *wlc)
3483 WLC_MAX_MAC_SUSPEND); 3503 WLC_MAX_MAC_SUSPEND);
3484 3504
3485 if (!(R_REG(osh, &regs->macintstatus) & MI_MACSSPNDD)) { 3505 if (!(R_REG(osh, &regs->macintstatus) & MI_MACSSPNDD)) {
3486 WL_ERROR(("wl%d: wlc_suspend_mac_and_wait: waited %d uS and " 3506 WL_ERROR("wl%d: wlc_suspend_mac_and_wait: waited %d uS and MI_MACSSPNDD is still not on.\n",
3487 "MI_MACSSPNDD is still not on.\n", 3507 wlc_hw->unit, WLC_MAX_MAC_SUSPEND);
3488 wlc_hw->unit, WLC_MAX_MAC_SUSPEND)); 3508 WL_ERROR("wl%d: psmdebug 0x%08x, phydebug 0x%08x, psm_brc 0x%04x\n",
3489 WL_ERROR(("wl%d: psmdebug 0x%08x, phydebug 0x%08x, psm_brc 0x%04x\n", wlc_hw->unit, R_REG(osh, &regs->psmdebug), R_REG(osh, &regs->phydebug), R_REG(osh, &regs->psm_brc))); 3509 wlc_hw->unit,
3510 R_REG(osh, &regs->psmdebug),
3511 R_REG(osh, &regs->phydebug),
3512 R_REG(osh, &regs->psm_brc));
3490 } 3513 }
3491 3514
3492 mc = R_REG(osh, &regs->maccontrol); 3515 mc = R_REG(osh, &regs->maccontrol);
3493 if (mc == 0xffffffff) { 3516 if (mc == 0xffffffff) {
3494 WL_ERROR(("wl%d: %s: dead chip\n", wlc_hw->unit, __func__)); 3517 WL_ERROR("wl%d: %s: dead chip\n", wlc_hw->unit, __func__);
3495 wl_down(wlc->wl); 3518 wl_down(wlc->wl);
3496 return; 3519 return;
3497 } 3520 }
@@ -3500,15 +3523,15 @@ void wlc_suspend_mac_and_wait(wlc_info_t *wlc)
3500 ASSERT(!(mc & MCTL_EN_MAC)); 3523 ASSERT(!(mc & MCTL_EN_MAC));
3501} 3524}
3502 3525
3503void wlc_enable_mac(wlc_info_t *wlc) 3526void wlc_enable_mac(struct wlc_info *wlc)
3504{ 3527{
3505 wlc_hw_info_t *wlc_hw = wlc->hw; 3528 struct wlc_hw_info *wlc_hw = wlc->hw;
3506 d11regs_t *regs = wlc_hw->regs; 3529 d11regs_t *regs = wlc_hw->regs;
3507 u32 mc, mi; 3530 u32 mc, mi;
3508 osl_t *osh; 3531 struct osl_info *osh;
3509 3532
3510 WL_TRACE(("wl%d: wlc_enable_mac: bandunit %d\n", wlc_hw->unit, 3533 WL_TRACE("wl%d: wlc_enable_mac: bandunit %d\n",
3511 wlc->band->bandunit)); 3534 wlc_hw->unit, wlc->band->bandunit);
3512 3535
3513 /* 3536 /*
3514 * Track overlapping suspend requests 3537 * Track overlapping suspend requests
@@ -3539,7 +3562,7 @@ void wlc_enable_mac(wlc_info_t *wlc)
3539 wlc_ucode_wake_override_clear(wlc_hw, WLC_WAKE_OVERRIDE_MACSUSPEND); 3562 wlc_ucode_wake_override_clear(wlc_hw, WLC_WAKE_OVERRIDE_MACSUSPEND);
3540} 3563}
3541 3564
3542void wlc_bmac_ifsctl_edcrs_set(wlc_hw_info_t *wlc_hw, bool abie, bool isht) 3565void wlc_bmac_ifsctl_edcrs_set(struct wlc_hw_info *wlc_hw, bool abie, bool isht)
3543{ 3566{
3544 if (!(WLCISNPHY(wlc_hw->band) && (D11REV_GE(wlc_hw->corerev, 16)))) 3567 if (!(WLCISNPHY(wlc_hw->band) && (D11REV_GE(wlc_hw->corerev, 16))))
3545 return; 3568 return;
@@ -3575,7 +3598,7 @@ void wlc_bmac_ifsctl_edcrs_set(wlc_hw_info_t *wlc_hw, bool abie, bool isht)
3575 } 3598 }
3576} 3599}
3577 3600
3578static void wlc_upd_ofdm_pctl1_table(wlc_hw_info_t *wlc_hw) 3601static void wlc_upd_ofdm_pctl1_table(struct wlc_hw_info *wlc_hw)
3579{ 3602{
3580 u8 rate; 3603 u8 rate;
3581 u8 rates[8] = { 3604 u8 rates[8] = {
@@ -3609,7 +3632,7 @@ static void wlc_upd_ofdm_pctl1_table(wlc_hw_info_t *wlc_hw)
3609 } 3632 }
3610} 3633}
3611 3634
3612static u16 wlc_bmac_ofdm_ratetable_offset(wlc_hw_info_t *wlc_hw, u8 rate) 3635static u16 wlc_bmac_ofdm_ratetable_offset(struct wlc_hw_info *wlc_hw, u8 rate)
3613{ 3636{
3614 uint i; 3637 uint i;
3615 u8 plcp_rate = 0; 3638 u8 plcp_rate = 0;
@@ -3642,7 +3665,7 @@ static u16 wlc_bmac_ofdm_ratetable_offset(wlc_hw_info_t *wlc_hw, u8 rate)
3642 return 2 * wlc_bmac_read_shm(wlc_hw, M_RT_DIRMAP_A + (plcp_rate * 2)); 3665 return 2 * wlc_bmac_read_shm(wlc_hw, M_RT_DIRMAP_A + (plcp_rate * 2));
3643} 3666}
3644 3667
3645void wlc_bmac_band_stf_ss_set(wlc_hw_info_t *wlc_hw, u8 stf_mode) 3668void wlc_bmac_band_stf_ss_set(struct wlc_hw_info *wlc_hw, u8 stf_mode)
3646{ 3669{
3647 wlc_hw->hw_stf_ss_opmode = stf_mode; 3670 wlc_hw->hw_stf_ss_opmode = stf_mode;
3648 3671
@@ -3651,7 +3674,7 @@ void wlc_bmac_band_stf_ss_set(wlc_hw_info_t *wlc_hw, u8 stf_mode)
3651} 3674}
3652 3675
3653void BCMFASTPATH 3676void BCMFASTPATH
3654wlc_bmac_read_tsf(wlc_hw_info_t *wlc_hw, u32 *tsf_l_ptr, 3677wlc_bmac_read_tsf(struct wlc_hw_info *wlc_hw, u32 *tsf_l_ptr,
3655 u32 *tsf_h_ptr) 3678 u32 *tsf_h_ptr)
3656{ 3679{
3657 d11regs_t *regs = wlc_hw->regs; 3680 d11regs_t *regs = wlc_hw->regs;
@@ -3663,14 +3686,14 @@ wlc_bmac_read_tsf(wlc_hw_info_t *wlc_hw, u32 *tsf_l_ptr,
3663 return; 3686 return;
3664} 3687}
3665 3688
3666bool wlc_bmac_validate_chip_access(wlc_hw_info_t *wlc_hw) 3689bool wlc_bmac_validate_chip_access(struct wlc_hw_info *wlc_hw)
3667{ 3690{
3668 d11regs_t *regs; 3691 d11regs_t *regs;
3669 u32 w, val; 3692 u32 w, val;
3670 volatile u16 *reg16; 3693 volatile u16 *reg16;
3671 osl_t *osh; 3694 struct osl_info *osh;
3672 3695
3673 WL_TRACE(("wl%d: validate_chip_access\n", wlc_hw->unit)); 3696 WL_TRACE("wl%d: validate_chip_access\n", wlc_hw->unit);
3674 3697
3675 regs = wlc_hw->regs; 3698 regs = wlc_hw->regs;
3676 osh = wlc_hw->osh; 3699 osh = wlc_hw->osh;
@@ -3690,7 +3713,8 @@ bool wlc_bmac_validate_chip_access(wlc_hw_info_t *wlc_hw)
3690 (void)R_REG(osh, &regs->objaddr); 3713 (void)R_REG(osh, &regs->objaddr);
3691 val = R_REG(osh, &regs->objdata); 3714 val = R_REG(osh, &regs->objdata);
3692 if (val != (u32) 0xaa5555aa) { 3715 if (val != (u32) 0xaa5555aa) {
3693 WL_ERROR(("wl%d: validate_chip_access: SHM = 0x%x, expected 0xaa5555aa\n", wlc_hw->unit, val)); 3716 WL_ERROR("wl%d: validate_chip_access: SHM = 0x%x, expected 0xaa5555aa\n",
3717 wlc_hw->unit, val);
3694 return false; 3718 return false;
3695 } 3719 }
3696 3720
@@ -3702,7 +3726,8 @@ bool wlc_bmac_validate_chip_access(wlc_hw_info_t *wlc_hw)
3702 (void)R_REG(osh, &regs->objaddr); 3726 (void)R_REG(osh, &regs->objaddr);
3703 val = R_REG(osh, &regs->objdata); 3727 val = R_REG(osh, &regs->objdata);
3704 if (val != (u32) 0x55aaaa55) { 3728 if (val != (u32) 0x55aaaa55) {
3705 WL_ERROR(("wl%d: validate_chip_access: SHM = 0x%x, expected 0x55aaaa55\n", wlc_hw->unit, val)); 3729 WL_ERROR("wl%d: validate_chip_access: SHM = 0x%x, expected 0x55aaaa55\n",
3730 wlc_hw->unit, val);
3706 return false; 3731 return false;
3707 } 3732 }
3708 3733
@@ -3732,12 +3757,14 @@ bool wlc_bmac_validate_chip_access(wlc_hw_info_t *wlc_hw)
3732 /* verify with the 16 bit registers that have no side effects */ 3757 /* verify with the 16 bit registers that have no side effects */
3733 val = R_REG(osh, &regs->tsf_cfpstrt_l); 3758 val = R_REG(osh, &regs->tsf_cfpstrt_l);
3734 if (val != (uint) 0xBBBB) { 3759 if (val != (uint) 0xBBBB) {
3735 WL_ERROR(("wl%d: validate_chip_access: tsf_cfpstrt_l = 0x%x, expected" " 0x%x\n", wlc_hw->unit, val, 0xBBBB)); 3760 WL_ERROR("wl%d: validate_chip_access: tsf_cfpstrt_l = 0x%x, expected 0x%x\n",
3761 wlc_hw->unit, val, 0xBBBB);
3736 return false; 3762 return false;
3737 } 3763 }
3738 val = R_REG(osh, &regs->tsf_cfpstrt_h); 3764 val = R_REG(osh, &regs->tsf_cfpstrt_h);
3739 if (val != (uint) 0xCCCC) { 3765 if (val != (uint) 0xCCCC) {
3740 WL_ERROR(("wl%d: validate_chip_access: tsf_cfpstrt_h = 0x%x, expected" " 0x%x\n", wlc_hw->unit, val, 0xCCCC)); 3766 WL_ERROR("wl%d: validate_chip_access: tsf_cfpstrt_h = 0x%x, expected 0x%x\n",
3767 wlc_hw->unit, val, 0xCCCC);
3741 return false; 3768 return false;
3742 } 3769 }
3743 3770
@@ -3749,7 +3776,10 @@ bool wlc_bmac_validate_chip_access(wlc_hw_info_t *wlc_hw)
3749 w = R_REG(osh, &regs->maccontrol); 3776 w = R_REG(osh, &regs->maccontrol);
3750 if ((w != (MCTL_IHR_EN | MCTL_WAKE)) && 3777 if ((w != (MCTL_IHR_EN | MCTL_WAKE)) &&
3751 (w != (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE))) { 3778 (w != (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE))) {
3752 WL_ERROR(("wl%d: validate_chip_access: maccontrol = 0x%x, expected 0x%x or 0x%x\n", wlc_hw->unit, w, (MCTL_IHR_EN | MCTL_WAKE), (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE))); 3779 WL_ERROR("wl%d: validate_chip_access: maccontrol = 0x%x, expected 0x%x or 0x%x\n",
3780 wlc_hw->unit, w,
3781 (MCTL_IHR_EN | MCTL_WAKE),
3782 (MCTL_IHR_EN | MCTL_GMODE | MCTL_WAKE));
3753 return false; 3783 return false;
3754 } 3784 }
3755 3785
@@ -3758,13 +3788,13 @@ bool wlc_bmac_validate_chip_access(wlc_hw_info_t *wlc_hw)
3758 3788
3759#define PHYPLL_WAIT_US 100000 3789#define PHYPLL_WAIT_US 100000
3760 3790
3761void wlc_bmac_core_phypll_ctl(wlc_hw_info_t *wlc_hw, bool on) 3791void wlc_bmac_core_phypll_ctl(struct wlc_hw_info *wlc_hw, bool on)
3762{ 3792{
3763 d11regs_t *regs; 3793 d11regs_t *regs;
3764 osl_t *osh; 3794 struct osl_info *osh;
3765 u32 tmp; 3795 u32 tmp;
3766 3796
3767 WL_TRACE(("wl%d: wlc_bmac_core_phypll_ctl\n", wlc_hw->unit)); 3797 WL_TRACE("wl%d: wlc_bmac_core_phypll_ctl\n", wlc_hw->unit);
3768 3798
3769 tmp = 0; 3799 tmp = 0;
3770 regs = wlc_hw->regs; 3800 regs = wlc_hw->regs;
@@ -3785,8 +3815,8 @@ void wlc_bmac_core_phypll_ctl(wlc_hw_info_t *wlc_hw, bool on)
3785 tmp = R_REG(osh, &regs->clk_ctl_st); 3815 tmp = R_REG(osh, &regs->clk_ctl_st);
3786 if ((tmp & (CCS_ERSRC_AVAIL_HT)) != 3816 if ((tmp & (CCS_ERSRC_AVAIL_HT)) !=
3787 (CCS_ERSRC_AVAIL_HT)) { 3817 (CCS_ERSRC_AVAIL_HT)) {
3788 WL_ERROR(("%s: turn on PHY PLL failed\n", 3818 WL_ERROR("%s: turn on PHY PLL failed\n",
3789 __func__)); 3819 __func__);
3790 ASSERT(0); 3820 ASSERT(0);
3791 } 3821 }
3792 } else { 3822 } else {
@@ -3803,8 +3833,8 @@ void wlc_bmac_core_phypll_ctl(wlc_hw_info_t *wlc_hw, bool on)
3803 (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) 3833 (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL))
3804 != 3834 !=
3805 (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) { 3835 (CCS_ERSRC_AVAIL_D11PLL | CCS_ERSRC_AVAIL_PHYPLL)) {
3806 WL_ERROR(("%s: turn on PHY PLL failed\n", 3836 WL_ERROR("%s: turn on PHY PLL failed\n",
3807 __func__)); 3837 __func__);
3808 ASSERT(0); 3838 ASSERT(0);
3809 } 3839 }
3810 } 3840 }
@@ -3817,11 +3847,11 @@ void wlc_bmac_core_phypll_ctl(wlc_hw_info_t *wlc_hw, bool on)
3817 } 3847 }
3818} 3848}
3819 3849
3820void wlc_coredisable(wlc_hw_info_t *wlc_hw) 3850void wlc_coredisable(struct wlc_hw_info *wlc_hw)
3821{ 3851{
3822 bool dev_gone; 3852 bool dev_gone;
3823 3853
3824 WL_TRACE(("wl%d: %s\n", wlc_hw->unit, __func__)); 3854 WL_TRACE("wl%d: %s\n", wlc_hw->unit, __func__);
3825 3855
3826 ASSERT(!wlc_hw->up); 3856 ASSERT(!wlc_hw->up);
3827 3857
@@ -3857,9 +3887,9 @@ void wlc_coredisable(wlc_hw_info_t *wlc_hw)
3857} 3887}
3858 3888
3859/* power both the pll and external oscillator on/off */ 3889/* power both the pll and external oscillator on/off */
3860void wlc_bmac_xtal(wlc_hw_info_t *wlc_hw, bool want) 3890void wlc_bmac_xtal(struct wlc_hw_info *wlc_hw, bool want)
3861{ 3891{
3862 WL_TRACE(("wl%d: wlc_bmac_xtal: want %d\n", wlc_hw->unit, want)); 3892 WL_TRACE("wl%d: wlc_bmac_xtal: want %d\n", wlc_hw->unit, want);
3863 3893
3864 /* dont power down if plldown is false or we must poll hw radio disable */ 3894 /* dont power down if plldown is false or we must poll hw radio disable */
3865 if (!want && wlc_hw->pllreq) 3895 if (!want && wlc_hw->pllreq)
@@ -3876,9 +3906,9 @@ void wlc_bmac_xtal(wlc_hw_info_t *wlc_hw, bool want)
3876 } 3906 }
3877} 3907}
3878 3908
3879static void wlc_flushqueues(wlc_info_t *wlc) 3909static void wlc_flushqueues(struct wlc_info *wlc)
3880{ 3910{
3881 wlc_hw_info_t *wlc_hw = wlc->hw; 3911 struct wlc_hw_info *wlc_hw = wlc->hw;
3882 uint i; 3912 uint i;
3883 3913
3884 wlc->txpend16165war = 0; 3914 wlc->txpend16165war = 0;
@@ -3888,8 +3918,8 @@ static void wlc_flushqueues(wlc_info_t *wlc)
3888 if (wlc_hw->di[i]) { 3918 if (wlc_hw->di[i]) {
3889 dma_txreclaim(wlc_hw->di[i], HNDDMA_RANGE_ALL); 3919 dma_txreclaim(wlc_hw->di[i], HNDDMA_RANGE_ALL);
3890 TXPKTPENDCLR(wlc, i); 3920 TXPKTPENDCLR(wlc, i);
3891 WL_TRACE(("wlc_flushqueues: pktpend fifo %d cleared\n", 3921 WL_TRACE("wlc_flushqueues: pktpend fifo %d cleared\n",
3892 i)); 3922 i);
3893 } 3923 }
3894 3924
3895 /* free any posted rx packets */ 3925 /* free any posted rx packets */
@@ -3898,12 +3928,12 @@ static void wlc_flushqueues(wlc_info_t *wlc)
3898 dma_rxreclaim(wlc_hw->di[RX_TXSTATUS_FIFO]); 3928 dma_rxreclaim(wlc_hw->di[RX_TXSTATUS_FIFO]);
3899} 3929}
3900 3930
3901u16 wlc_bmac_read_shm(wlc_hw_info_t *wlc_hw, uint offset) 3931u16 wlc_bmac_read_shm(struct wlc_hw_info *wlc_hw, uint offset)
3902{ 3932{
3903 return wlc_bmac_read_objmem(wlc_hw, offset, OBJADDR_SHM_SEL); 3933 return wlc_bmac_read_objmem(wlc_hw, offset, OBJADDR_SHM_SEL);
3904} 3934}
3905 3935
3906void wlc_bmac_write_shm(wlc_hw_info_t *wlc_hw, uint offset, u16 v) 3936void wlc_bmac_write_shm(struct wlc_hw_info *wlc_hw, uint offset, u16 v)
3907{ 3937{
3908 wlc_bmac_write_objmem(wlc_hw, offset, v, OBJADDR_SHM_SEL); 3938 wlc_bmac_write_objmem(wlc_hw, offset, v, OBJADDR_SHM_SEL);
3909} 3939}
@@ -3912,7 +3942,7 @@ void wlc_bmac_write_shm(wlc_hw_info_t *wlc_hw, uint offset, u16 v)
3912 * SHM 'offset' needs to be an even address and 3942 * SHM 'offset' needs to be an even address and
3913 * Buffer length 'len' must be an even number of bytes 3943 * Buffer length 'len' must be an even number of bytes
3914 */ 3944 */
3915void wlc_bmac_set_shm(wlc_hw_info_t *wlc_hw, uint offset, u16 v, int len) 3945void wlc_bmac_set_shm(struct wlc_hw_info *wlc_hw, uint offset, u16 v, int len)
3916{ 3946{
3917 int i; 3947 int i;
3918 3948
@@ -3929,7 +3959,7 @@ void wlc_bmac_set_shm(wlc_hw_info_t *wlc_hw, uint offset, u16 v, int len)
3929} 3959}
3930 3960
3931static u16 3961static u16
3932wlc_bmac_read_objmem(wlc_hw_info_t *wlc_hw, uint offset, u32 sel) 3962wlc_bmac_read_objmem(struct wlc_hw_info *wlc_hw, uint offset, u32 sel)
3933{ 3963{
3934 d11regs_t *regs = wlc_hw->regs; 3964 d11regs_t *regs = wlc_hw->regs;
3935 volatile u16 *objdata_lo = (volatile u16 *)&regs->objdata; 3965 volatile u16 *objdata_lo = (volatile u16 *)&regs->objdata;
@@ -3950,7 +3980,7 @@ wlc_bmac_read_objmem(wlc_hw_info_t *wlc_hw, uint offset, u32 sel)
3950} 3980}
3951 3981
3952static void 3982static void
3953wlc_bmac_write_objmem(wlc_hw_info_t *wlc_hw, uint offset, u16 v, u32 sel) 3983wlc_bmac_write_objmem(struct wlc_hw_info *wlc_hw, uint offset, u16 v, u32 sel)
3954{ 3984{
3955 d11regs_t *regs = wlc_hw->regs; 3985 d11regs_t *regs = wlc_hw->regs;
3956 volatile u16 *objdata_lo = (volatile u16 *)&regs->objdata; 3986 volatile u16 *objdata_lo = (volatile u16 *)&regs->objdata;
@@ -3973,7 +4003,7 @@ wlc_bmac_write_objmem(wlc_hw_info_t *wlc_hw, uint offset, u16 v, u32 sel)
3973 * 'sel' selects the type of memory 4003 * 'sel' selects the type of memory
3974 */ 4004 */
3975void 4005void
3976wlc_bmac_copyto_objmem(wlc_hw_info_t *wlc_hw, uint offset, const void *buf, 4006wlc_bmac_copyto_objmem(struct wlc_hw_info *wlc_hw, uint offset, const void *buf,
3977 int len, u32 sel) 4007 int len, u32 sel)
3978{ 4008{
3979 u16 v; 4009 u16 v;
@@ -3999,7 +4029,7 @@ wlc_bmac_copyto_objmem(wlc_hw_info_t *wlc_hw, uint offset, const void *buf,
3999 * 'sel' selects the type of memory 4029 * 'sel' selects the type of memory
4000 */ 4030 */
4001void 4031void
4002wlc_bmac_copyfrom_objmem(wlc_hw_info_t *wlc_hw, uint offset, void *buf, 4032wlc_bmac_copyfrom_objmem(struct wlc_hw_info *wlc_hw, uint offset, void *buf,
4003 int len, u32 sel) 4033 int len, u32 sel)
4004{ 4034{
4005 u16 v; 4035 u16 v;
@@ -4020,16 +4050,16 @@ wlc_bmac_copyfrom_objmem(wlc_hw_info_t *wlc_hw, uint offset, void *buf,
4020 } 4050 }
4021} 4051}
4022 4052
4023void wlc_bmac_copyfrom_vars(wlc_hw_info_t *wlc_hw, char **buf, uint *len) 4053void wlc_bmac_copyfrom_vars(struct wlc_hw_info *wlc_hw, char **buf, uint *len)
4024{ 4054{
4025 WL_TRACE(("wlc_bmac_copyfrom_vars, nvram vars totlen=%d\n", 4055 WL_TRACE("wlc_bmac_copyfrom_vars, nvram vars totlen=%d\n",
4026 wlc_hw->vars_size)); 4056 wlc_hw->vars_size);
4027 4057
4028 *buf = wlc_hw->vars; 4058 *buf = wlc_hw->vars;
4029 *len = wlc_hw->vars_size; 4059 *len = wlc_hw->vars_size;
4030} 4060}
4031 4061
4032void wlc_bmac_retrylimit_upd(wlc_hw_info_t *wlc_hw, u16 SRL, u16 LRL) 4062void wlc_bmac_retrylimit_upd(struct wlc_hw_info *wlc_hw, u16 SRL, u16 LRL)
4033{ 4063{
4034 wlc_hw->SRL = SRL; 4064 wlc_hw->SRL = SRL;
4035 wlc_hw->LRL = LRL; 4065 wlc_hw->LRL = LRL;
@@ -4047,17 +4077,17 @@ void wlc_bmac_retrylimit_upd(wlc_hw_info_t *wlc_hw, u16 SRL, u16 LRL)
4047 } 4077 }
4048} 4078}
4049 4079
4050void wlc_bmac_set_noreset(wlc_hw_info_t *wlc_hw, bool noreset_flag) 4080void wlc_bmac_set_noreset(struct wlc_hw_info *wlc_hw, bool noreset_flag)
4051{ 4081{
4052 wlc_hw->noreset = noreset_flag; 4082 wlc_hw->noreset = noreset_flag;
4053} 4083}
4054 4084
4055void wlc_bmac_set_ucode_loaded(wlc_hw_info_t *wlc_hw, bool ucode_loaded) 4085void wlc_bmac_set_ucode_loaded(struct wlc_hw_info *wlc_hw, bool ucode_loaded)
4056{ 4086{
4057 wlc_hw->ucode_loaded = ucode_loaded; 4087 wlc_hw->ucode_loaded = ucode_loaded;
4058} 4088}
4059 4089
4060void wlc_bmac_pllreq(wlc_hw_info_t *wlc_hw, bool set, mbool req_bit) 4090void wlc_bmac_pllreq(struct wlc_hw_info *wlc_hw, bool set, mbool req_bit)
4061{ 4091{
4062 ASSERT(req_bit); 4092 ASSERT(req_bit);
4063 4093
@@ -4088,7 +4118,7 @@ void wlc_bmac_pllreq(wlc_hw_info_t *wlc_hw, bool set, mbool req_bit)
4088 return; 4118 return;
4089} 4119}
4090 4120
4091void wlc_bmac_set_clk(wlc_hw_info_t *wlc_hw, bool on) 4121void wlc_bmac_set_clk(struct wlc_hw_info *wlc_hw, bool on)
4092{ 4122{
4093 if (on) { 4123 if (on) {
4094 /* power up pll and oscillator */ 4124 /* power up pll and oscillator */
@@ -4110,7 +4140,7 @@ void wlc_bmac_set_clk(wlc_hw_info_t *wlc_hw, bool on)
4110} 4140}
4111 4141
4112/* this will be true for all ai chips */ 4142/* this will be true for all ai chips */
4113bool wlc_bmac_taclear(wlc_hw_info_t *wlc_hw, bool ta_ok) 4143bool wlc_bmac_taclear(struct wlc_hw_info *wlc_hw, bool ta_ok)
4114{ 4144{
4115 return true; 4145 return true;
4116} 4146}
@@ -4118,7 +4148,7 @@ bool wlc_bmac_taclear(wlc_hw_info_t *wlc_hw, bool ta_ok)
4118/* Lower down relevant GPIOs like LED when going down w/o 4148/* Lower down relevant GPIOs like LED when going down w/o
4119 * doing PCI config cycles or touching interrupts 4149 * doing PCI config cycles or touching interrupts
4120 */ 4150 */
4121void wlc_gpio_fast_deinit(wlc_hw_info_t *wlc_hw) 4151void wlc_gpio_fast_deinit(struct wlc_hw_info *wlc_hw)
4122{ 4152{
4123 if ((wlc_hw == NULL) || (wlc_hw->sih == NULL)) 4153 if ((wlc_hw == NULL) || (wlc_hw->sih == NULL))
4124 return; 4154 return;
@@ -4126,17 +4156,17 @@ void wlc_gpio_fast_deinit(wlc_hw_info_t *wlc_hw)
4126 /* Only chips with internal bus or PCIE cores or certain PCI cores 4156 /* Only chips with internal bus or PCIE cores or certain PCI cores
4127 * are able to switch cores w/o disabling interrupts 4157 * are able to switch cores w/o disabling interrupts
4128 */ 4158 */
4129 if (!((BUSTYPE(wlc_hw->sih->bustype) == SI_BUS) || 4159 if (!((wlc_hw->sih->bustype == SI_BUS) ||
4130 ((BUSTYPE(wlc_hw->sih->bustype) == PCI_BUS) && 4160 ((wlc_hw->sih->bustype == PCI_BUS) &&
4131 ((wlc_hw->sih->buscoretype == PCIE_CORE_ID) || 4161 ((wlc_hw->sih->buscoretype == PCIE_CORE_ID) ||
4132 (wlc_hw->sih->buscorerev >= 13))))) 4162 (wlc_hw->sih->buscorerev >= 13)))))
4133 return; 4163 return;
4134 4164
4135 WL_TRACE(("wl%d: %s\n", wlc_hw->unit, __func__)); 4165 WL_TRACE("wl%d: %s\n", wlc_hw->unit, __func__);
4136 return; 4166 return;
4137} 4167}
4138 4168
4139bool wlc_bmac_radio_hw(wlc_hw_info_t *wlc_hw, bool enable) 4169bool wlc_bmac_radio_hw(struct wlc_hw_info *wlc_hw, bool enable)
4140{ 4170{
4141 /* Do not access Phy registers if core is not up */ 4171 /* Do not access Phy registers if core is not up */
4142 if (si_iscoreup(wlc_hw->sih) == false) 4172 if (si_iscoreup(wlc_hw->sih) == false)
@@ -4171,7 +4201,7 @@ bool wlc_bmac_radio_hw(wlc_hw_info_t *wlc_hw, bool enable)
4171 return true; 4201 return true;
4172} 4202}
4173 4203
4174u16 wlc_bmac_rate_shm_offset(wlc_hw_info_t *wlc_hw, u8 rate) 4204u16 wlc_bmac_rate_shm_offset(struct wlc_hw_info *wlc_hw, u8 rate)
4175{ 4205{
4176 u16 table_ptr; 4206 u16 table_ptr;
4177 u8 phy_rate, index; 4207 u8 phy_rate, index;
@@ -4195,12 +4225,12 @@ u16 wlc_bmac_rate_shm_offset(wlc_hw_info_t *wlc_hw, u8 rate)
4195 return 2 * wlc_bmac_read_shm(wlc_hw, table_ptr + (index * 2)); 4225 return 2 * wlc_bmac_read_shm(wlc_hw, table_ptr + (index * 2));
4196} 4226}
4197 4227
4198void wlc_bmac_set_txpwr_percent(wlc_hw_info_t *wlc_hw, u8 val) 4228void wlc_bmac_set_txpwr_percent(struct wlc_hw_info *wlc_hw, u8 val)
4199{ 4229{
4200 wlc_phy_txpwr_percent_set(wlc_hw->band->pi, val); 4230 wlc_phy_txpwr_percent_set(wlc_hw->band->pi, val);
4201} 4231}
4202 4232
4203void wlc_bmac_antsel_set(wlc_hw_info_t *wlc_hw, u32 antsel_avail) 4233void wlc_bmac_antsel_set(struct wlc_hw_info *wlc_hw, u32 antsel_avail)
4204{ 4234{
4205 wlc_hw->antsel_avail = antsel_avail; 4235 wlc_hw->antsel_avail = antsel_avail;
4206} 4236}
diff --git a/drivers/staging/brcm80211/sys/wlc_bmac.h b/drivers/staging/brcm80211/sys/wlc_bmac.h
index 872bc8d866d2..98150aaff3a3 100644
--- a/drivers/staging/brcm80211/sys/wlc_bmac.h
+++ b/drivers/staging/brcm80211/sys/wlc_bmac.h
@@ -57,7 +57,8 @@ typedef struct wlc_bmac_revinfo {
57 } band[MAXBANDS]; 57 } band[MAXBANDS];
58} wlc_bmac_revinfo_t; 58} wlc_bmac_revinfo_t;
59 59
60/* dup state between BMAC(wlc_hw_info_t) and HIGH(wlc_info_t) driver */ 60/* dup state between BMAC(struct wlc_hw_info) and HIGH(struct wlc_info)
61 driver */
61typedef struct wlc_bmac_state { 62typedef struct wlc_bmac_state {
62 u32 machwcap; /* mac hw capibility */ 63 u32 machwcap; /* mac hw capibility */
63 u32 preamble_ovr; /* preamble override */ 64 u32 preamble_ovr; /* preamble override */
@@ -130,148 +131,143 @@ typedef enum {
130 WLCHW_STATE_LAST 131 WLCHW_STATE_LAST
131} wlc_bmac_state_id_t; 132} wlc_bmac_state_id_t;
132 133
133extern int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, 134extern int wlc_bmac_attach(struct wlc_info *wlc, u16 vendor, u16 device,
134 uint unit, bool piomode, osl_t *osh, void *regsva, 135 uint unit, bool piomode, struct osl_info *osh,
135 uint bustype, void *btparam); 136 void *regsva, uint bustype, void *btparam);
136extern int wlc_bmac_detach(wlc_info_t *wlc); 137extern int wlc_bmac_detach(struct wlc_info *wlc);
137extern void wlc_bmac_watchdog(void *arg); 138extern void wlc_bmac_watchdog(void *arg);
138extern void wlc_bmac_info_init(wlc_hw_info_t *wlc_hw); 139extern void wlc_bmac_info_init(struct wlc_hw_info *wlc_hw);
139 140
140/* up/down, reset, clk */ 141/* up/down, reset, clk */
141#ifdef WLC_LOW 142extern void wlc_bmac_xtal(struct wlc_hw_info *wlc_hw, bool want);
142extern void wlc_bmac_xtal(wlc_hw_info_t *wlc_hw, bool want);
143#endif
144 143
145extern void wlc_bmac_copyto_objmem(wlc_hw_info_t *wlc_hw, 144extern void wlc_bmac_copyto_objmem(struct wlc_hw_info *wlc_hw,
146 uint offset, const void *buf, int len, 145 uint offset, const void *buf, int len,
147 u32 sel); 146 u32 sel);
148extern void wlc_bmac_copyfrom_objmem(wlc_hw_info_t *wlc_hw, uint offset, 147extern void wlc_bmac_copyfrom_objmem(struct wlc_hw_info *wlc_hw, uint offset,
149 void *buf, int len, u32 sel); 148 void *buf, int len, u32 sel);
150#define wlc_bmac_copyfrom_shm(wlc_hw, offset, buf, len) \ 149#define wlc_bmac_copyfrom_shm(wlc_hw, offset, buf, len) \
151 wlc_bmac_copyfrom_objmem(wlc_hw, offset, buf, len, OBJADDR_SHM_SEL) 150 wlc_bmac_copyfrom_objmem(wlc_hw, offset, buf, len, OBJADDR_SHM_SEL)
152#define wlc_bmac_copyto_shm(wlc_hw, offset, buf, len) \ 151#define wlc_bmac_copyto_shm(wlc_hw, offset, buf, len) \
153 wlc_bmac_copyto_objmem(wlc_hw, offset, buf, len, OBJADDR_SHM_SEL) 152 wlc_bmac_copyto_objmem(wlc_hw, offset, buf, len, OBJADDR_SHM_SEL)
154 153
155extern void wlc_bmac_core_phy_clk(wlc_hw_info_t *wlc_hw, bool clk); 154extern void wlc_bmac_core_phy_clk(struct wlc_hw_info *wlc_hw, bool clk);
156extern void wlc_bmac_core_phypll_reset(wlc_hw_info_t *wlc_hw); 155extern void wlc_bmac_core_phypll_reset(struct wlc_hw_info *wlc_hw);
157extern void wlc_bmac_core_phypll_ctl(wlc_hw_info_t *wlc_hw, bool on); 156extern void wlc_bmac_core_phypll_ctl(struct wlc_hw_info *wlc_hw, bool on);
158extern void wlc_bmac_phyclk_fgc(wlc_hw_info_t *wlc_hw, bool clk); 157extern void wlc_bmac_phyclk_fgc(struct wlc_hw_info *wlc_hw, bool clk);
159extern void wlc_bmac_macphyclk_set(wlc_hw_info_t *wlc_hw, bool clk); 158extern void wlc_bmac_macphyclk_set(struct wlc_hw_info *wlc_hw, bool clk);
160extern void wlc_bmac_phy_reset(wlc_hw_info_t *wlc_hw); 159extern void wlc_bmac_phy_reset(struct wlc_hw_info *wlc_hw);
161extern void wlc_bmac_corereset(wlc_hw_info_t *wlc_hw, u32 flags); 160extern void wlc_bmac_corereset(struct wlc_hw_info *wlc_hw, u32 flags);
162extern void wlc_bmac_reset(wlc_hw_info_t *wlc_hw); 161extern void wlc_bmac_reset(struct wlc_hw_info *wlc_hw);
163extern void wlc_bmac_init(wlc_hw_info_t *wlc_hw, chanspec_t chanspec, 162extern void wlc_bmac_init(struct wlc_hw_info *wlc_hw, chanspec_t chanspec,
164 bool mute); 163 bool mute);
165extern int wlc_bmac_up_prep(wlc_hw_info_t *wlc_hw); 164extern int wlc_bmac_up_prep(struct wlc_hw_info *wlc_hw);
166extern int wlc_bmac_up_finish(wlc_hw_info_t *wlc_hw); 165extern int wlc_bmac_up_finish(struct wlc_hw_info *wlc_hw);
167extern int wlc_bmac_down_prep(wlc_hw_info_t *wlc_hw); 166extern int wlc_bmac_down_prep(struct wlc_hw_info *wlc_hw);
168extern int wlc_bmac_down_finish(wlc_hw_info_t *wlc_hw); 167extern int wlc_bmac_down_finish(struct wlc_hw_info *wlc_hw);
169extern void wlc_bmac_corereset(wlc_hw_info_t *wlc_hw, u32 flags); 168extern void wlc_bmac_corereset(struct wlc_hw_info *wlc_hw, u32 flags);
170extern void wlc_bmac_switch_macfreq(wlc_hw_info_t *wlc_hw, u8 spurmode); 169extern void wlc_bmac_switch_macfreq(struct wlc_hw_info *wlc_hw, u8 spurmode);
171 170
172/* chanspec, ucode interface */ 171/* chanspec, ucode interface */
173extern int wlc_bmac_bandtype(wlc_hw_info_t *wlc_hw); 172extern int wlc_bmac_bandtype(struct wlc_hw_info *wlc_hw);
174extern void wlc_bmac_set_chanspec(wlc_hw_info_t *wlc_hw, chanspec_t chanspec, 173extern void wlc_bmac_set_chanspec(struct wlc_hw_info *wlc_hw,
174 chanspec_t chanspec,
175 bool mute, struct txpwr_limits *txpwr); 175 bool mute, struct txpwr_limits *txpwr);
176 176
177extern void wlc_bmac_txfifo(wlc_hw_info_t *wlc_hw, uint fifo, void *p, 177extern void wlc_bmac_txfifo(struct wlc_hw_info *wlc_hw, uint fifo, void *p,
178 bool commit, u16 frameid, u8 txpktpend); 178 bool commit, u16 frameid, u8 txpktpend);
179extern int wlc_bmac_xmtfifo_sz_get(wlc_hw_info_t *wlc_hw, uint fifo, 179extern int wlc_bmac_xmtfifo_sz_get(struct wlc_hw_info *wlc_hw, uint fifo,
180 uint *blocks); 180 uint *blocks);
181extern void wlc_bmac_mhf(wlc_hw_info_t *wlc_hw, u8 idx, u16 mask, 181extern void wlc_bmac_mhf(struct wlc_hw_info *wlc_hw, u8 idx, u16 mask,
182 u16 val, int bands); 182 u16 val, int bands);
183extern void wlc_bmac_mctrl(wlc_hw_info_t *wlc_hw, u32 mask, u32 val); 183extern void wlc_bmac_mctrl(struct wlc_hw_info *wlc_hw, u32 mask, u32 val);
184extern u16 wlc_bmac_mhf_get(wlc_hw_info_t *wlc_hw, u8 idx, int bands); 184extern u16 wlc_bmac_mhf_get(struct wlc_hw_info *wlc_hw, u8 idx, int bands);
185extern int wlc_bmac_xmtfifo_sz_set(wlc_hw_info_t *wlc_hw, uint fifo, 185extern int wlc_bmac_xmtfifo_sz_set(struct wlc_hw_info *wlc_hw, uint fifo,
186 uint blocks); 186 uint blocks);
187extern void wlc_bmac_txant_set(wlc_hw_info_t *wlc_hw, u16 phytxant); 187extern void wlc_bmac_txant_set(struct wlc_hw_info *wlc_hw, u16 phytxant);
188extern u16 wlc_bmac_get_txant(wlc_hw_info_t *wlc_hw); 188extern u16 wlc_bmac_get_txant(struct wlc_hw_info *wlc_hw);
189extern void wlc_bmac_antsel_type_set(wlc_hw_info_t *wlc_hw, u8 antsel_type); 189extern void wlc_bmac_antsel_type_set(struct wlc_hw_info *wlc_hw,
190extern int wlc_bmac_revinfo_get(wlc_hw_info_t *wlc_hw, 190 u8 antsel_type);
191extern int wlc_bmac_revinfo_get(struct wlc_hw_info *wlc_hw,
191 wlc_bmac_revinfo_t *revinfo); 192 wlc_bmac_revinfo_t *revinfo);
192extern int wlc_bmac_state_get(wlc_hw_info_t *wlc_hw, wlc_bmac_state_t *state); 193extern int wlc_bmac_state_get(struct wlc_hw_info *wlc_hw,
193extern void wlc_bmac_write_shm(wlc_hw_info_t *wlc_hw, uint offset, u16 v); 194 wlc_bmac_state_t *state);
194extern u16 wlc_bmac_read_shm(wlc_hw_info_t *wlc_hw, uint offset); 195extern void wlc_bmac_write_shm(struct wlc_hw_info *wlc_hw, uint offset, u16 v);
195extern void wlc_bmac_set_shm(wlc_hw_info_t *wlc_hw, uint offset, u16 v, 196extern u16 wlc_bmac_read_shm(struct wlc_hw_info *wlc_hw, uint offset);
197extern void wlc_bmac_set_shm(struct wlc_hw_info *wlc_hw, uint offset, u16 v,
196 int len); 198 int len);
197extern void wlc_bmac_write_template_ram(wlc_hw_info_t *wlc_hw, int offset, 199extern void wlc_bmac_write_template_ram(struct wlc_hw_info *wlc_hw, int offset,
198 int len, void *buf); 200 int len, void *buf);
199extern void wlc_bmac_copyfrom_vars(wlc_hw_info_t *wlc_hw, char **buf, 201extern void wlc_bmac_copyfrom_vars(struct wlc_hw_info *wlc_hw, char **buf,
200 uint *len); 202 uint *len);
201 203
202extern void wlc_bmac_process_ps_switch(wlc_hw_info_t *wlc, 204extern void wlc_bmac_process_ps_switch(struct wlc_hw_info *wlc,
203 struct ether_addr *ea, s8 ps_on); 205 struct ether_addr *ea, s8 ps_on);
204extern void wlc_bmac_hw_etheraddr(wlc_hw_info_t *wlc_hw, 206extern void wlc_bmac_hw_etheraddr(struct wlc_hw_info *wlc_hw,
205 struct ether_addr *ea); 207 struct ether_addr *ea);
206extern void wlc_bmac_set_hw_etheraddr(wlc_hw_info_t *wlc_hw, 208extern void wlc_bmac_set_hw_etheraddr(struct wlc_hw_info *wlc_hw,
207 struct ether_addr *ea); 209 struct ether_addr *ea);
208extern bool wlc_bmac_validate_chip_access(wlc_hw_info_t *wlc_hw); 210extern bool wlc_bmac_validate_chip_access(struct wlc_hw_info *wlc_hw);
209 211
210extern bool wlc_bmac_radio_read_hwdisabled(wlc_hw_info_t *wlc_hw); 212extern bool wlc_bmac_radio_read_hwdisabled(struct wlc_hw_info *wlc_hw);
211extern void wlc_bmac_set_shortslot(wlc_hw_info_t *wlc_hw, bool shortslot); 213extern void wlc_bmac_set_shortslot(struct wlc_hw_info *wlc_hw, bool shortslot);
212extern void wlc_bmac_mute(wlc_hw_info_t *wlc_hw, bool want, mbool flags); 214extern void wlc_bmac_mute(struct wlc_hw_info *wlc_hw, bool want, mbool flags);
213extern void wlc_bmac_set_deaf(wlc_hw_info_t *wlc_hw, bool user_flag); 215extern void wlc_bmac_set_deaf(struct wlc_hw_info *wlc_hw, bool user_flag);
214extern void wlc_bmac_band_stf_ss_set(wlc_hw_info_t *wlc_hw, u8 stf_mode); 216extern void wlc_bmac_band_stf_ss_set(struct wlc_hw_info *wlc_hw, u8 stf_mode);
215 217
216extern void wlc_bmac_wait_for_wake(wlc_hw_info_t *wlc_hw); 218extern void wlc_bmac_wait_for_wake(struct wlc_hw_info *wlc_hw);
217extern bool wlc_bmac_tx_fifo_suspended(wlc_hw_info_t *wlc_hw, uint tx_fifo); 219extern bool wlc_bmac_tx_fifo_suspended(struct wlc_hw_info *wlc_hw,
218extern void wlc_bmac_tx_fifo_suspend(wlc_hw_info_t *wlc_hw, uint tx_fifo); 220 uint tx_fifo);
219extern void wlc_bmac_tx_fifo_resume(wlc_hw_info_t *wlc_hw, uint tx_fifo); 221extern void wlc_bmac_tx_fifo_suspend(struct wlc_hw_info *wlc_hw, uint tx_fifo);
222extern void wlc_bmac_tx_fifo_resume(struct wlc_hw_info *wlc_hw, uint tx_fifo);
220 223
221extern void wlc_ucode_wake_override_set(wlc_hw_info_t *wlc_hw, 224extern void wlc_ucode_wake_override_set(struct wlc_hw_info *wlc_hw,
222 u32 override_bit); 225 u32 override_bit);
223extern void wlc_ucode_wake_override_clear(wlc_hw_info_t *wlc_hw, 226extern void wlc_ucode_wake_override_clear(struct wlc_hw_info *wlc_hw,
224 u32 override_bit); 227 u32 override_bit);
225 228
226extern void wlc_bmac_set_rcmta(wlc_hw_info_t *wlc_hw, int idx, 229extern void wlc_bmac_set_rcmta(struct wlc_hw_info *wlc_hw, int idx,
227 const struct ether_addr *addr); 230 const struct ether_addr *addr);
228extern void wlc_bmac_set_addrmatch(wlc_hw_info_t *wlc_hw, int match_reg_offset, 231extern void wlc_bmac_set_addrmatch(struct wlc_hw_info *wlc_hw,
232 int match_reg_offset,
229 const struct ether_addr *addr); 233 const struct ether_addr *addr);
230extern void wlc_bmac_write_hw_bcntemplates(wlc_hw_info_t *wlc_hw, void *bcn, 234extern void wlc_bmac_write_hw_bcntemplates(struct wlc_hw_info *wlc_hw,
231 int len, bool both); 235 void *bcn, int len, bool both);
232 236
233extern void wlc_bmac_read_tsf(wlc_hw_info_t *wlc_hw, u32 *tsf_l_ptr, 237extern void wlc_bmac_read_tsf(struct wlc_hw_info *wlc_hw, u32 *tsf_l_ptr,
234 u32 *tsf_h_ptr); 238 u32 *tsf_h_ptr);
235extern void wlc_bmac_set_cwmin(wlc_hw_info_t *wlc_hw, u16 newmin); 239extern void wlc_bmac_set_cwmin(struct wlc_hw_info *wlc_hw, u16 newmin);
236extern void wlc_bmac_set_cwmax(wlc_hw_info_t *wlc_hw, u16 newmax); 240extern void wlc_bmac_set_cwmax(struct wlc_hw_info *wlc_hw, u16 newmax);
237extern void wlc_bmac_set_noreset(wlc_hw_info_t *wlc, bool noreset_flag); 241extern void wlc_bmac_set_noreset(struct wlc_hw_info *wlc, bool noreset_flag);
238extern void wlc_bmac_set_ucode_loaded(wlc_hw_info_t *wlc, bool ucode_loaded); 242extern void wlc_bmac_set_ucode_loaded(struct wlc_hw_info *wlc,
243 bool ucode_loaded);
239 244
240extern void wlc_bmac_retrylimit_upd(wlc_hw_info_t *wlc_hw, u16 SRL, 245extern void wlc_bmac_retrylimit_upd(struct wlc_hw_info *wlc_hw, u16 SRL,
241 u16 LRL); 246 u16 LRL);
242 247
243extern void wlc_bmac_fifoerrors(wlc_hw_info_t *wlc_hw); 248extern void wlc_bmac_fifoerrors(struct wlc_hw_info *wlc_hw);
244 249
245#ifdef WLC_HIGH_ONLY
246extern void wlc_bmac_dngl_reboot(rpc_info_t *);
247extern void wlc_bmac_dngl_rpc_agg(rpc_info_t *, u16 agg);
248extern void wlc_bmac_dngl_rpc_msglevel(rpc_info_t *, u16 level);
249extern void wlc_bmac_dngl_rpc_txq_wm_set(rpc_info_t *rpc, u32 wm);
250extern void wlc_bmac_dngl_rpc_txq_wm_get(rpc_info_t *rpc, u32 *wm);
251extern void wlc_bmac_dngl_rpc_agg_limit_set(rpc_info_t *rpc, u32 val);
252extern void wlc_bmac_dngl_rpc_agg_limit_get(rpc_info_t *rpc, u32 *pval);
253extern int wlc_bmac_debug_template(wlc_hw_info_t *wlc_hw);
254#endif
255 250
256/* API for BMAC driver (e.g. wlc_phy.c etc) */ 251/* API for BMAC driver (e.g. wlc_phy.c etc) */
257 252
258extern void wlc_bmac_bw_set(wlc_hw_info_t *wlc_hw, u16 bw); 253extern void wlc_bmac_bw_set(struct wlc_hw_info *wlc_hw, u16 bw);
259extern void wlc_bmac_pllreq(wlc_hw_info_t *wlc_hw, bool set, mbool req_bit); 254extern void wlc_bmac_pllreq(struct wlc_hw_info *wlc_hw, bool set,
260extern void wlc_bmac_set_clk(wlc_hw_info_t *wlc_hw, bool on); 255 mbool req_bit);
261extern bool wlc_bmac_taclear(wlc_hw_info_t *wlc_hw, bool ta_ok); 256extern void wlc_bmac_set_clk(struct wlc_hw_info *wlc_hw, bool on);
257extern bool wlc_bmac_taclear(struct wlc_hw_info *wlc_hw, bool ta_ok);
262extern void wlc_bmac_hw_up(struct wlc_hw_info *wlc_hw); 258extern void wlc_bmac_hw_up(struct wlc_hw_info *wlc_hw);
263 259
264extern void wlc_bmac_dump(wlc_hw_info_t *wlc_hw, struct bcmstrbuf *b, 260extern void wlc_bmac_dump(struct wlc_hw_info *wlc_hw, struct bcmstrbuf *b,
265 wlc_bmac_dump_id_t dump_id); 261 wlc_bmac_dump_id_t dump_id);
266extern void wlc_gpio_fast_deinit(wlc_hw_info_t *wlc_hw); 262extern void wlc_gpio_fast_deinit(struct wlc_hw_info *wlc_hw);
267 263
268extern bool wlc_bmac_radio_hw(wlc_hw_info_t *wlc_hw, bool enable); 264extern bool wlc_bmac_radio_hw(struct wlc_hw_info *wlc_hw, bool enable);
269extern u16 wlc_bmac_rate_shm_offset(wlc_hw_info_t *wlc_hw, u8 rate); 265extern u16 wlc_bmac_rate_shm_offset(struct wlc_hw_info *wlc_hw, u8 rate);
270 266
271extern void wlc_bmac_assert_type_set(wlc_hw_info_t *wlc_hw, u32 type); 267extern void wlc_bmac_assert_type_set(struct wlc_hw_info *wlc_hw, u32 type);
272extern void wlc_bmac_set_txpwr_percent(wlc_hw_info_t *wlc_hw, u8 val); 268extern void wlc_bmac_set_txpwr_percent(struct wlc_hw_info *wlc_hw, u8 val);
273extern void wlc_bmac_blink_sync(wlc_hw_info_t *wlc_hw, u32 led_pins); 269extern void wlc_bmac_blink_sync(struct wlc_hw_info *wlc_hw, u32 led_pins);
274extern void wlc_bmac_ifsctl_edcrs_set(wlc_hw_info_t *wlc_hw, bool abie, 270extern void wlc_bmac_ifsctl_edcrs_set(struct wlc_hw_info *wlc_hw, bool abie,
275 bool isht); 271 bool isht);
276 272
277extern void wlc_bmac_antsel_set(wlc_hw_info_t *wlc_hw, u32 antsel_avail); 273extern void wlc_bmac_antsel_set(struct wlc_hw_info *wlc_hw, u32 antsel_avail);
diff --git a/drivers/staging/brcm80211/sys/wlc_bsscfg.h b/drivers/staging/brcm80211/sys/wlc_bsscfg.h
index ae5542ab0334..d6a1971c69a0 100644
--- a/drivers/staging/brcm80211/sys/wlc_bsscfg.h
+++ b/drivers/staging/brcm80211/sys/wlc_bsscfg.h
@@ -34,7 +34,8 @@ typedef struct wlc_bsscfg wlc_bsscfg_t;
34#define MAXMACLIST 64 /* max # source MAC matches */ 34#define MAXMACLIST 64 /* max # source MAC matches */
35#define BCN_TEMPLATE_COUNT 2 35#define BCN_TEMPLATE_COUNT 2
36 36
37/* Iterator for "associated" STA bss configs: (wlc_info_t *wlc, int idx, wlc_bsscfg_t *cfg) */ 37/* Iterator for "associated" STA bss configs:
38 (struct wlc_info *wlc, int idx, wlc_bsscfg_t *cfg) */
38#define FOREACH_AS_STA(wlc, idx, cfg) \ 39#define FOREACH_AS_STA(wlc, idx, cfg) \
39 for (idx = 0; (int) idx < WLC_MAXBSSCFG; idx++) \ 40 for (idx = 0; (int) idx < WLC_MAXBSSCFG; idx++) \
40 if ((cfg = (wlc)->bsscfg[idx]) && BSSCFG_STA(cfg) && cfg->associated) 41 if ((cfg = (wlc)->bsscfg[idx]) && BSSCFG_STA(cfg) && cfg->associated)
diff --git a/drivers/staging/brcm80211/sys/wlc_cfg.h b/drivers/staging/brcm80211/sys/wlc_cfg.h
index a415e1fd2c05..3decb7d1a5e5 100644
--- a/drivers/staging/brcm80211/sys/wlc_cfg.h
+++ b/drivers/staging/brcm80211/sys/wlc_cfg.h
@@ -23,14 +23,6 @@
23 23
24#define IS_SINGLEBAND_5G(device) 0 24#define IS_SINGLEBAND_5G(device) 0
25 25
26/* Keep WLC_HIGH_ONLY, WLC_SPLIT for USB extension later on */
27#if !defined(WLC_LOW)
28#define WLC_HIGH_ONLY
29#endif
30#if !defined(WLC_LOW)
31#define WLC_SPLIT
32#endif
33
34/* **** Core type/rev defaults **** */ 26/* **** Core type/rev defaults **** */
35#define D11_DEFAULT 0x0fffffb0 /* Supported D11 revs: 4, 5, 7-27 27#define D11_DEFAULT 0x0fffffb0 /* Supported D11 revs: 4, 5, 7-27
36 * also need to update wlc.h MAXCOREREV 28 * also need to update wlc.h MAXCOREREV
@@ -61,22 +53,6 @@
61 * 3 5356a0 53 * 3 5356a0
62 */ 54 */
63 55
64#ifdef BCMSDIO
65#define D11CONF 0x100000
66#define SSLPNCONF 2
67#define GCCONF 0
68#define ACCONF 0
69#define NCONF 0
70#define LPCONF 0
71#define LCNCONF 0
72#define NTXD 32
73#define NRXD 16
74#define NRXBUFPOST 8
75#define WLC_DATAHIWAT 32
76#define RXBND 8
77#define MAXPKTCB 64
78#define AMPDU_NUM_MPDU 8
79#endif
80 56
81/* For undefined values, use defaults */ 57/* For undefined values, use defaults */
82#ifndef D11CONF 58#ifndef D11CONF
diff --git a/drivers/staging/brcm80211/sys/wlc_channel.c b/drivers/staging/brcm80211/sys/wlc_channel.c
index 509280337e34..a35c15214880 100644
--- a/drivers/staging/brcm80211/sys/wlc_channel.c
+++ b/drivers/staging/brcm80211/sys/wlc_channel.c
@@ -19,16 +19,21 @@
19#include <bcmdefs.h> 19#include <bcmdefs.h>
20#include <wlc_cfg.h> 20#include <wlc_cfg.h>
21#include <osl.h> 21#include <osl.h>
22#include <linuxver.h> 22#include <linux/module.h>
23#include <linux/pci.h>
23#include <bcmutils.h> 24#include <bcmutils.h>
24#include <siutils.h> 25#include <siutils.h>
26#include <sbhndpio.h>
27#include <sbhnddma.h>
25#include <wlioctl.h> 28#include <wlioctl.h>
26#include <wlc_pub.h> 29#include <wlc_pub.h>
27#include <wlc_key.h> 30#include <wlc_key.h>
31#include <wlc_event.h>
28#include <wlc_mac80211.h> 32#include <wlc_mac80211.h>
29#include <wlc_bmac.h> 33#include <wlc_bmac.h>
30#include <wlc_stf.h> 34#include <wlc_stf.h>
31#include <wlc_channel.h> 35#include <wlc_channel.h>
36#include <wl_dbg.h>
32 37
33typedef struct wlc_cm_band { 38typedef struct wlc_cm_band {
34 u8 locale_flags; /* locale_info_t flags */ 39 u8 locale_flags; /* locale_info_t flags */
@@ -39,8 +44,8 @@ typedef struct wlc_cm_band {
39} wlc_cm_band_t; 44} wlc_cm_band_t;
40 45
41struct wlc_cm_info { 46struct wlc_cm_info {
42 wlc_pub_t *pub; 47 struct wlc_pub *pub;
43 wlc_info_t *wlc; 48 struct wlc_info *wlc;
44 char srom_ccode[WLC_CNTRY_BUF_SZ]; /* Country Code in SROM */ 49 char srom_ccode[WLC_CNTRY_BUF_SZ]; /* Country Code in SROM */
45 uint srom_regrev; /* Regulatory Rev for the SROM ccode */ 50 uint srom_regrev; /* Regulatory Rev for the SROM ccode */
46 const country_info_t *country; /* current country def */ 51 const country_info_t *country; /* current country def */
@@ -377,7 +382,7 @@ void wlc_locale_get_channels(const locale_info_t *locale, chanvec_t *channels)
377{ 382{
378 u8 i; 383 u8 i;
379 384
380 bzero(channels, sizeof(chanvec_t)); 385 memset(channels, 0, sizeof(chanvec_t));
381 386
382 for (i = 0; i < ARRAY_SIZE(g_table_locale_base); i++) { 387 for (i = 0; i < ARRAY_SIZE(g_table_locale_base); i++) {
383 if (locale->valid_channels & (1 << i)) { 388 if (locale->valid_channels & (1 << i)) {
@@ -562,8 +567,8 @@ struct chan20_info chan20_info[] = {
562const locale_info_t *wlc_get_locale_2g(u8 locale_idx) 567const locale_info_t *wlc_get_locale_2g(u8 locale_idx)
563{ 568{
564 if (locale_idx >= ARRAY_SIZE(g_locale_2g_table)) { 569 if (locale_idx >= ARRAY_SIZE(g_locale_2g_table)) {
565 WL_ERROR(("%s: locale 2g index size out of range %d\n", 570 WL_ERROR("%s: locale 2g index size out of range %d\n",
566 __func__, locale_idx)); 571 __func__, locale_idx);
567 ASSERT(locale_idx < ARRAY_SIZE(g_locale_2g_table)); 572 ASSERT(locale_idx < ARRAY_SIZE(g_locale_2g_table));
568 return NULL; 573 return NULL;
569 } 574 }
@@ -573,8 +578,8 @@ const locale_info_t *wlc_get_locale_2g(u8 locale_idx)
573const locale_info_t *wlc_get_locale_5g(u8 locale_idx) 578const locale_info_t *wlc_get_locale_5g(u8 locale_idx)
574{ 579{
575 if (locale_idx >= ARRAY_SIZE(g_locale_5g_table)) { 580 if (locale_idx >= ARRAY_SIZE(g_locale_5g_table)) {
576 WL_ERROR(("%s: locale 5g index size out of range %d\n", 581 WL_ERROR("%s: locale 5g index size out of range %d\n",
577 __func__, locale_idx)); 582 __func__, locale_idx);
578 ASSERT(locale_idx < ARRAY_SIZE(g_locale_5g_table)); 583 ASSERT(locale_idx < ARRAY_SIZE(g_locale_5g_table));
579 return NULL; 584 return NULL;
580 } 585 }
@@ -584,8 +589,8 @@ const locale_info_t *wlc_get_locale_5g(u8 locale_idx)
584const locale_mimo_info_t *wlc_get_mimo_2g(u8 locale_idx) 589const locale_mimo_info_t *wlc_get_mimo_2g(u8 locale_idx)
585{ 590{
586 if (locale_idx >= ARRAY_SIZE(g_mimo_2g_table)) { 591 if (locale_idx >= ARRAY_SIZE(g_mimo_2g_table)) {
587 WL_ERROR(("%s: mimo 2g index size out of range %d\n", __func__, 592 WL_ERROR("%s: mimo 2g index size out of range %d\n",
588 locale_idx)); 593 __func__, locale_idx);
589 return NULL; 594 return NULL;
590 } 595 }
591 return g_mimo_2g_table[locale_idx]; 596 return g_mimo_2g_table[locale_idx];
@@ -594,26 +599,26 @@ const locale_mimo_info_t *wlc_get_mimo_2g(u8 locale_idx)
594const locale_mimo_info_t *wlc_get_mimo_5g(u8 locale_idx) 599const locale_mimo_info_t *wlc_get_mimo_5g(u8 locale_idx)
595{ 600{
596 if (locale_idx >= ARRAY_SIZE(g_mimo_5g_table)) { 601 if (locale_idx >= ARRAY_SIZE(g_mimo_5g_table)) {
597 WL_ERROR(("%s: mimo 5g index size out of range %d\n", __func__, 602 WL_ERROR("%s: mimo 5g index size out of range %d\n",
598 locale_idx)); 603 __func__, locale_idx);
599 return NULL; 604 return NULL;
600 } 605 }
601 return g_mimo_5g_table[locale_idx]; 606 return g_mimo_5g_table[locale_idx];
602} 607}
603 608
604wlc_cm_info_t *wlc_channel_mgr_attach(wlc_info_t *wlc) 609wlc_cm_info_t *wlc_channel_mgr_attach(struct wlc_info *wlc)
605{ 610{
606 wlc_cm_info_t *wlc_cm; 611 wlc_cm_info_t *wlc_cm;
607 char country_abbrev[WLC_CNTRY_BUF_SZ]; 612 char country_abbrev[WLC_CNTRY_BUF_SZ];
608 const country_info_t *country; 613 const country_info_t *country;
609 wlc_pub_t *pub = wlc->pub; 614 struct wlc_pub *pub = wlc->pub;
610 char *ccode; 615 char *ccode;
611 616
612 WL_TRACE(("wl%d: wlc_channel_mgr_attach\n", wlc->pub->unit)); 617 WL_TRACE("wl%d: wlc_channel_mgr_attach\n", wlc->pub->unit);
613 618
614 wlc_cm = kzalloc(sizeof(wlc_cm_info_t), GFP_ATOMIC); 619 wlc_cm = kzalloc(sizeof(wlc_cm_info_t), GFP_ATOMIC);
615 if (wlc_cm == NULL) { 620 if (wlc_cm == NULL) {
616 WL_ERROR(("wl%d: %s: out of memory", pub->unit, __func__)); 621 WL_ERROR("wl%d: %s: out of memory", pub->unit, __func__);
617 return NULL; 622 return NULL;
618 } 623 }
619 wlc_cm->pub = pub; 624 wlc_cm->pub = pub;
@@ -624,12 +629,13 @@ wlc_cm_info_t *wlc_channel_mgr_attach(wlc_info_t *wlc)
624 ccode = getvar(wlc->pub->vars, "ccode"); 629 ccode = getvar(wlc->pub->vars, "ccode");
625 if (ccode) { 630 if (ccode) {
626 strncpy(wlc->pub->srom_ccode, ccode, WLC_CNTRY_BUF_SZ - 1); 631 strncpy(wlc->pub->srom_ccode, ccode, WLC_CNTRY_BUF_SZ - 1);
627 WL_NONE(("%s: SROM country code is %c%c\n", __func__, 632 WL_NONE("%s: SROM country code is %c%c\n",
628 wlc->pub->srom_ccode[0], wlc->pub->srom_ccode[1])); 633 __func__,
634 wlc->pub->srom_ccode[0], wlc->pub->srom_ccode[1]);
629 } 635 }
630 636
631 /* internal country information which must match regulatory constraints in firmware */ 637 /* internal country information which must match regulatory constraints in firmware */
632 bzero(country_abbrev, WLC_CNTRY_BUF_SZ); 638 memset(country_abbrev, 0, WLC_CNTRY_BUF_SZ);
633 strncpy(country_abbrev, "X2", sizeof(country_abbrev) - 1); 639 strncpy(country_abbrev, "X2", sizeof(country_abbrev) - 1);
634 country = wlc_country_lookup(wlc, country_abbrev); 640 country = wlc_country_lookup(wlc, country_abbrev);
635 641
@@ -659,7 +665,7 @@ const char *wlc_channel_country_abbrev(wlc_cm_info_t *wlc_cm)
659 665
660u8 wlc_channel_locale_flags(wlc_cm_info_t *wlc_cm) 666u8 wlc_channel_locale_flags(wlc_cm_info_t *wlc_cm)
661{ 667{
662 wlc_info_t *wlc = wlc_cm->wlc; 668 struct wlc_info *wlc = wlc_cm->wlc;
663 669
664 return wlc_cm->bandstate[wlc->band->bandunit].locale_flags; 670 return wlc_cm->bandstate[wlc->band->bandunit].locale_flags;
665} 671}
@@ -711,7 +717,9 @@ wlc_set_countrycode_rev(wlc_cm_info_t *wlc_cm,
711 char mapped_ccode[WLC_CNTRY_BUF_SZ]; 717 char mapped_ccode[WLC_CNTRY_BUF_SZ];
712 uint mapped_regrev; 718 uint mapped_regrev;
713 719
714 WL_NONE(("%s: (country_abbrev \"%s\", ccode \"%s\", regrev %d) SPROM \"%s\"/%u\n", __func__, country_abbrev, ccode, regrev, wlc_cm->srom_ccode, wlc_cm->srom_regrev)); 720 WL_NONE("%s: (country_abbrev \"%s\", ccode \"%s\", regrev %d) SPROM \"%s\"/%u\n",
721 __func__, country_abbrev, ccode, regrev,
722 wlc_cm->srom_ccode, wlc_cm->srom_regrev);
715 723
716 /* if regrev is -1, lookup the mapped country code, 724 /* if regrev is -1, lookup the mapped country code,
717 * otherwise use the ccode and regrev directly 725 * otherwise use the ccode and regrev directly
@@ -750,7 +758,7 @@ wlc_set_country_common(wlc_cm_info_t *wlc_cm,
750{ 758{
751 const locale_mimo_info_t *li_mimo; 759 const locale_mimo_info_t *li_mimo;
752 const locale_info_t *locale; 760 const locale_info_t *locale;
753 wlc_info_t *wlc = wlc_cm->wlc; 761 struct wlc_info *wlc = wlc_cm->wlc;
754 char prev_country_abbrev[WLC_CNTRY_BUF_SZ]; 762 char prev_country_abbrev[WLC_CNTRY_BUF_SZ];
755 763
756 ASSERT(country != NULL); 764 ASSERT(country != NULL);
@@ -758,7 +766,7 @@ wlc_set_country_common(wlc_cm_info_t *wlc_cm,
758 /* save current country state */ 766 /* save current country state */
759 wlc_cm->country = country; 767 wlc_cm->country = country;
760 768
761 bzero(&prev_country_abbrev, WLC_CNTRY_BUF_SZ); 769 memset(&prev_country_abbrev, 0, WLC_CNTRY_BUF_SZ);
762 strncpy(prev_country_abbrev, wlc_cm->country_abbrev, 770 strncpy(prev_country_abbrev, wlc_cm->country_abbrev,
763 WLC_CNTRY_BUF_SZ - 1); 771 WLC_CNTRY_BUF_SZ - 1);
764 772
@@ -814,7 +822,7 @@ static const country_info_t *wlc_countrycode_map(wlc_cm_info_t *wlc_cm,
814 char *mapped_ccode, 822 char *mapped_ccode,
815 uint *mapped_regrev) 823 uint *mapped_regrev)
816{ 824{
817 wlc_info_t *wlc = wlc_cm->wlc; 825 struct wlc_info *wlc = wlc_cm->wlc;
818 const country_info_t *country; 826 const country_info_t *country;
819 uint srom_regrev = wlc_cm->srom_regrev; 827 uint srom_regrev = wlc_cm->srom_regrev;
820 const char *srom_ccode = wlc_cm->srom_ccode; 828 const char *srom_ccode = wlc_cm->srom_ccode;
@@ -822,8 +830,8 @@ static const country_info_t *wlc_countrycode_map(wlc_cm_info_t *wlc_cm,
822 830
823 /* check for currently supported ccode size */ 831 /* check for currently supported ccode size */
824 if (strlen(ccode) > (WLC_CNTRY_BUF_SZ - 1)) { 832 if (strlen(ccode) > (WLC_CNTRY_BUF_SZ - 1)) {
825 WL_ERROR(("wl%d: %s: ccode \"%s\" too long for match\n", 833 WL_ERROR("wl%d: %s: ccode \"%s\" too long for match\n",
826 wlc->pub->unit, __func__, ccode)); 834 wlc->pub->unit, __func__, ccode);
827 return NULL; 835 return NULL;
828 } 836 }
829 837
@@ -838,7 +846,7 @@ static const country_info_t *wlc_countrycode_map(wlc_cm_info_t *wlc_cm,
838 if (!strcmp(srom_ccode, ccode)) { 846 if (!strcmp(srom_ccode, ccode)) {
839 *mapped_regrev = srom_regrev; 847 *mapped_regrev = srom_regrev;
840 mapped = 0; 848 mapped = 0;
841 WL_ERROR(("srom_code == ccode %s\n", __func__)); 849 WL_ERROR("srom_code == ccode %s\n", __func__);
842 ASSERT(0); 850 ASSERT(0);
843 } else { 851 } else {
844 mapped = 852 mapped =
@@ -890,7 +898,7 @@ static const country_info_t *wlc_country_lookup_direct(const char *ccode,
890 } 898 }
891 } 899 }
892 900
893 WL_ERROR(("%s: Returning NULL\n", __func__)); 901 WL_ERROR("%s: Returning NULL\n", __func__);
894 ASSERT(0); 902 ASSERT(0);
895 return NULL; 903 return NULL;
896} 904}
@@ -898,9 +906,9 @@ static const country_info_t *wlc_country_lookup_direct(const char *ccode,
898static int 906static int
899wlc_channels_init(wlc_cm_info_t *wlc_cm, const country_info_t *country) 907wlc_channels_init(wlc_cm_info_t *wlc_cm, const country_info_t *country)
900{ 908{
901 wlc_info_t *wlc = wlc_cm->wlc; 909 struct wlc_info *wlc = wlc_cm->wlc;
902 uint i, j; 910 uint i, j;
903 wlcband_t *band; 911 struct wlcband *band;
904 const locale_info_t *li; 912 const locale_info_t *li;
905 chanvec_t sup_chan; 913 chanvec_t sup_chan;
906 const locale_mimo_info_t *li_mimo; 914 const locale_mimo_info_t *li_mimo;
@@ -952,7 +960,7 @@ wlc_channels_init(wlc_cm_info_t *wlc_cm, const country_info_t *country)
952 */ 960 */
953static void wlc_channels_commit(wlc_cm_info_t *wlc_cm) 961static void wlc_channels_commit(wlc_cm_info_t *wlc_cm)
954{ 962{
955 wlc_info_t *wlc = wlc_cm->wlc; 963 struct wlc_info *wlc = wlc_cm->wlc;
956 uint chan; 964 uint chan;
957 struct txpwr_limits txpwr; 965 struct txpwr_limits txpwr;
958 966
@@ -969,7 +977,9 @@ static void wlc_channels_commit(wlc_cm_info_t *wlc_cm)
969 if (chan == INVCHANNEL) { 977 if (chan == INVCHANNEL) {
970 /* country/locale with no valid channels, set the radio disable bit */ 978 /* country/locale with no valid channels, set the radio disable bit */
971 mboolset(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE); 979 mboolset(wlc->pub->radio_disabled, WL_RADIO_COUNTRY_DISABLE);
972 WL_ERROR(("wl%d: %s: no valid channel for \"%s\" nbands %d bandlocked %d\n", wlc->pub->unit, __func__, wlc_cm->country_abbrev, NBANDS(wlc), wlc->bandlocked)); 980 WL_ERROR("wl%d: %s: no valid channel for \"%s\" nbands %d bandlocked %d\n",
981 wlc->pub->unit, __func__,
982 wlc_cm->country_abbrev, NBANDS(wlc), wlc->bandlocked);
973 } else 983 } else
974 if (mboolisset(wlc->pub->radio_disabled, 984 if (mboolisset(wlc->pub->radio_disabled,
975 WL_RADIO_COUNTRY_DISABLE)) { 985 WL_RADIO_COUNTRY_DISABLE)) {
@@ -998,12 +1008,12 @@ static void wlc_channels_commit(wlc_cm_info_t *wlc_cm)
998/* reset the quiet channels vector to the union of the restricted and radar channel sets */ 1008/* reset the quiet channels vector to the union of the restricted and radar channel sets */
999void wlc_quiet_channels_reset(wlc_cm_info_t *wlc_cm) 1009void wlc_quiet_channels_reset(wlc_cm_info_t *wlc_cm)
1000{ 1010{
1001 wlc_info_t *wlc = wlc_cm->wlc; 1011 struct wlc_info *wlc = wlc_cm->wlc;
1002 uint i, j; 1012 uint i, j;
1003 wlcband_t *band; 1013 struct wlcband *band;
1004 const chanvec_t *chanvec; 1014 const chanvec_t *chanvec;
1005 1015
1006 bzero(&wlc_cm->quiet_channels, sizeof(chanvec_t)); 1016 memset(&wlc_cm->quiet_channels, 0, sizeof(chanvec_t));
1007 1017
1008 band = wlc->band; 1018 band = wlc->band;
1009 for (i = 0; i < NBANDS(wlc); 1019 for (i = 0; i < NBANDS(wlc);
@@ -1036,7 +1046,7 @@ bool wlc_quiet_chanspec(wlc_cm_info_t *wlc_cm, chanspec_t chspec)
1036 */ 1046 */
1037bool wlc_valid_channel20_db(wlc_cm_info_t *wlc_cm, uint val) 1047bool wlc_valid_channel20_db(wlc_cm_info_t *wlc_cm, uint val)
1038{ 1048{
1039 wlc_info_t *wlc = wlc_cm->wlc; 1049 struct wlc_info *wlc = wlc_cm->wlc;
1040 1050
1041 return VALID_CHANNEL20(wlc, val) || 1051 return VALID_CHANNEL20(wlc, val) ||
1042 (!wlc->bandlocked 1052 (!wlc->bandlocked
@@ -1054,7 +1064,7 @@ wlc_valid_channel20_in_band(wlc_cm_info_t *wlc_cm, uint bandunit, uint val)
1054/* Is the channel valid for the current locale and current band? */ 1064/* Is the channel valid for the current locale and current band? */
1055bool wlc_valid_channel20(wlc_cm_info_t *wlc_cm, uint val) 1065bool wlc_valid_channel20(wlc_cm_info_t *wlc_cm, uint val)
1056{ 1066{
1057 wlc_info_t *wlc = wlc_cm->wlc; 1067 struct wlc_info *wlc = wlc_cm->wlc;
1058 1068
1059 return ((val < MAXCHANNEL) && 1069 return ((val < MAXCHANNEL) &&
1060 isset(wlc_cm->bandstate[wlc->band->bandunit].valid_channels.vec, 1070 isset(wlc_cm->bandstate[wlc->band->bandunit].valid_channels.vec,
@@ -1064,7 +1074,7 @@ bool wlc_valid_channel20(wlc_cm_info_t *wlc_cm, uint val)
1064/* Is the 40 MHz allowed for the current locale and specified band? */ 1074/* Is the 40 MHz allowed for the current locale and specified band? */
1065bool wlc_valid_40chanspec_in_band(wlc_cm_info_t *wlc_cm, uint bandunit) 1075bool wlc_valid_40chanspec_in_band(wlc_cm_info_t *wlc_cm, uint bandunit)
1066{ 1076{
1067 wlc_info_t *wlc = wlc_cm->wlc; 1077 struct wlc_info *wlc = wlc_cm->wlc;
1068 1078
1069 return (((wlc_cm->bandstate[bandunit]. 1079 return (((wlc_cm->bandstate[bandunit].
1070 locale_flags & (WLC_NO_MIMO | WLC_NO_40MHZ)) == 0) 1080 locale_flags & (WLC_NO_MIMO | WLC_NO_40MHZ)) == 0)
@@ -1162,7 +1172,7 @@ void
1162wlc_channel_set_chanspec(wlc_cm_info_t *wlc_cm, chanspec_t chanspec, 1172wlc_channel_set_chanspec(wlc_cm_info_t *wlc_cm, chanspec_t chanspec,
1163 u8 local_constraint_qdbm) 1173 u8 local_constraint_qdbm)
1164{ 1174{
1165 wlc_info_t *wlc = wlc_cm->wlc; 1175 struct wlc_info *wlc = wlc_cm->wlc;
1166 struct txpwr_limits txpwr; 1176 struct txpwr_limits txpwr;
1167 1177
1168 wlc_channel_reg_limits(wlc_cm, chanspec, &txpwr); 1178 wlc_channel_reg_limits(wlc_cm, chanspec, &txpwr);
@@ -1179,7 +1189,7 @@ int
1179wlc_channel_set_txpower_limit(wlc_cm_info_t *wlc_cm, 1189wlc_channel_set_txpower_limit(wlc_cm_info_t *wlc_cm,
1180 u8 local_constraint_qdbm) 1190 u8 local_constraint_qdbm)
1181{ 1191{
1182 wlc_info_t *wlc = wlc_cm->wlc; 1192 struct wlc_info *wlc = wlc_cm->wlc;
1183 struct txpwr_limits txpwr; 1193 struct txpwr_limits txpwr;
1184 1194
1185 wlc_channel_reg_limits(wlc_cm, wlc->chanspec, &txpwr); 1195 wlc_channel_reg_limits(wlc_cm, wlc->chanspec, &txpwr);
@@ -1299,13 +1309,13 @@ void
1299wlc_channel_reg_limits(wlc_cm_info_t *wlc_cm, chanspec_t chanspec, 1309wlc_channel_reg_limits(wlc_cm_info_t *wlc_cm, chanspec_t chanspec,
1300 txpwr_limits_t *txpwr) 1310 txpwr_limits_t *txpwr)
1301{ 1311{
1302 wlc_info_t *wlc = wlc_cm->wlc; 1312 struct wlc_info *wlc = wlc_cm->wlc;
1303 uint i; 1313 uint i;
1304 uint chan; 1314 uint chan;
1305 int maxpwr; 1315 int maxpwr;
1306 int delta; 1316 int delta;
1307 const country_info_t *country; 1317 const country_info_t *country;
1308 wlcband_t *band; 1318 struct wlcband *band;
1309 const locale_info_t *li; 1319 const locale_info_t *li;
1310 int conducted_max; 1320 int conducted_max;
1311 int conducted_ofdm_max; 1321 int conducted_ofdm_max;
@@ -1314,7 +1324,7 @@ wlc_channel_reg_limits(wlc_cm_info_t *wlc_cm, chanspec_t chanspec,
1314 int maxpwr_idx; 1324 int maxpwr_idx;
1315 uint j; 1325 uint j;
1316 1326
1317 bzero(txpwr, sizeof(txpwr_limits_t)); 1327 memset(txpwr, 0, sizeof(txpwr_limits_t));
1318 1328
1319 if (!wlc_valid_chanspec_db(wlc_cm, chanspec)) { 1329 if (!wlc_valid_chanspec_db(wlc_cm, chanspec)) {
1320 country = wlc_country_lookup(wlc, wlc->autocountry_default); 1330 country = wlc_country_lookup(wlc, wlc->autocountry_default);
@@ -1528,13 +1538,13 @@ static bool wlc_japan_ccode(const char *ccode)
1528static bool 1538static bool
1529wlc_valid_chanspec_ext(wlc_cm_info_t *wlc_cm, chanspec_t chspec, bool dualband) 1539wlc_valid_chanspec_ext(wlc_cm_info_t *wlc_cm, chanspec_t chspec, bool dualband)
1530{ 1540{
1531 wlc_info_t *wlc = wlc_cm->wlc; 1541 struct wlc_info *wlc = wlc_cm->wlc;
1532 u8 channel = CHSPEC_CHANNEL(chspec); 1542 u8 channel = CHSPEC_CHANNEL(chspec);
1533 1543
1534 /* check the chanspec */ 1544 /* check the chanspec */
1535 if (wf_chspec_malformed(chspec)) { 1545 if (wf_chspec_malformed(chspec)) {
1536 WL_ERROR(("wl%d: malformed chanspec 0x%x\n", wlc->pub->unit, 1546 WL_ERROR("wl%d: malformed chanspec 0x%x\n",
1537 chspec)); 1547 wlc->pub->unit, chspec);
1538 ASSERT(0); 1548 ASSERT(0);
1539 return false; 1549 return false;
1540 } 1550 }
diff --git a/drivers/staging/brcm80211/sys/wlc_event.c b/drivers/staging/brcm80211/sys/wlc_event.c
index 7e1bf0e2ecdd..dabd7094cd73 100644
--- a/drivers/staging/brcm80211/sys/wlc_event.c
+++ b/drivers/staging/brcm80211/sys/wlc_event.c
@@ -16,9 +16,13 @@
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <bcmdefs.h> 18#include <bcmdefs.h>
19#include <linuxver.h> 19#include <linux/module.h>
20#include <linux/pci.h>
21#include <osl.h>
20#include <bcmutils.h> 22#include <bcmutils.h>
21#include <siutils.h> 23#include <siutils.h>
24#include <sbhndpio.h>
25#include <sbhnddma.h>
22#include <wlioctl.h> 26#include <wlioctl.h>
23#include <wlc_cfg.h> 27#include <wlc_cfg.h>
24#include <wlc_pub.h> 28#include <wlc_pub.h>
@@ -32,6 +36,7 @@
32#ifdef MSGTRACE 36#ifdef MSGTRACE
33#include <msgtrace.h> 37#include <msgtrace.h>
34#endif 38#endif
39#include <wl_dbg.h>
35 40
36/* Local prototypes */ 41/* Local prototypes */
37static void wlc_timer_cb(void *arg); 42static void wlc_timer_cb(void *arg);
@@ -42,7 +47,7 @@ struct wlc_eventq {
42 wlc_event_t *tail; 47 wlc_event_t *tail;
43 struct wlc_info *wlc; 48 struct wlc_info *wlc;
44 void *wl; 49 void *wl;
45 wlc_pub_t *pub; 50 struct wlc_pub *pub;
46 bool tpending; 51 bool tpending;
47 bool workpending; 52 bool workpending;
48 struct wl_timer *timer; 53 struct wl_timer *timer;
@@ -53,7 +58,8 @@ struct wlc_eventq {
53/* 58/*
54 * Export functions 59 * Export functions
55 */ 60 */
56wlc_eventq_t *wlc_eventq_attach(wlc_pub_t *pub, struct wlc_info *wlc, void *wl, 61wlc_eventq_t *wlc_eventq_attach(struct wlc_pub *pub, struct wlc_info *wlc,
62 void *wl,
57 wlc_eventq_cb_t cb) 63 wlc_eventq_cb_t cb)
58{ 64{
59 wlc_eventq_t *eq; 65 wlc_eventq_t *eq;
@@ -69,8 +75,8 @@ wlc_eventq_t *wlc_eventq_attach(wlc_pub_t *pub, struct wlc_info *wlc, void *wl,
69 75
70 eq->timer = wl_init_timer(eq->wl, wlc_timer_cb, eq, "eventq"); 76 eq->timer = wl_init_timer(eq->wl, wlc_timer_cb, eq, "eventq");
71 if (!eq->timer) { 77 if (!eq->timer) {
72 WL_ERROR(("wl%d: wlc_eventq_attach: timer failed\n", 78 WL_ERROR("wl%d: wlc_eventq_attach: timer failed\n",
73 pub->unit)); 79 pub->unit);
74 kfree(eq); 80 kfree(eq);
75 return NULL; 81 return NULL;
76 } 82 }
diff --git a/drivers/staging/brcm80211/sys/wlc_event.h b/drivers/staging/brcm80211/sys/wlc_event.h
index e443dae258b7..e75582dcdd93 100644
--- a/drivers/staging/brcm80211/sys/wlc_event.h
+++ b/drivers/staging/brcm80211/sys/wlc_event.h
@@ -21,7 +21,8 @@ typedef struct wlc_eventq wlc_eventq_t;
21 21
22typedef void (*wlc_eventq_cb_t) (void *arg); 22typedef void (*wlc_eventq_cb_t) (void *arg);
23 23
24extern wlc_eventq_t *wlc_eventq_attach(wlc_pub_t *pub, struct wlc_info *wlc, 24extern wlc_eventq_t *wlc_eventq_attach(struct wlc_pub *pub,
25 struct wlc_info *wlc,
25 void *wl, wlc_eventq_cb_t cb); 26 void *wl, wlc_eventq_cb_t cb);
26extern int wlc_eventq_detach(wlc_eventq_t *eq); 27extern int wlc_eventq_detach(wlc_eventq_t *eq);
27extern int wlc_eventq_down(wlc_eventq_t *eq); 28extern int wlc_eventq_down(wlc_eventq_t *eq);
@@ -38,7 +39,7 @@ extern int wlc_eventq_query_ind(wlc_eventq_t *eq, void *bitvect);
38extern int wlc_eventq_test_ind(wlc_eventq_t *eq, int et); 39extern int wlc_eventq_test_ind(wlc_eventq_t *eq, int et);
39extern int wlc_eventq_set_ind(wlc_eventq_t *eq, uint et, bool on); 40extern int wlc_eventq_set_ind(wlc_eventq_t *eq, uint et, bool on);
40extern void wlc_eventq_flush(wlc_eventq_t *eq); 41extern void wlc_eventq_flush(wlc_eventq_t *eq);
41extern void wlc_assign_event_msg(wlc_info_t *wlc, wl_event_msg_t *msg, 42extern void wlc_assign_event_msg(struct wlc_info *wlc, wl_event_msg_t *msg,
42 const wlc_event_t *e, u8 *data, 43 const wlc_event_t *e, u8 *data,
43 u32 len); 44 u32 len);
44 45
diff --git a/drivers/staging/brcm80211/sys/wlc_mac80211.c b/drivers/staging/brcm80211/sys/wlc_mac80211.c
index feaffcc64ec6..1d5d01ac0a9b 100644
--- a/drivers/staging/brcm80211/sys/wlc_mac80211.c
+++ b/drivers/staging/brcm80211/sys/wlc_mac80211.c
@@ -15,9 +15,10 @@
15 */ 15 */
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/ctype.h> 17#include <linux/ctype.h>
18#include <linux/etherdevice.h>
18#include <bcmdefs.h> 19#include <bcmdefs.h>
20#include <bcmdevs.h>
19#include <wlc_cfg.h> 21#include <wlc_cfg.h>
20#include <linuxver.h>
21#include <osl.h> 22#include <osl.h>
22#include <bcmutils.h> 23#include <bcmutils.h>
23#include <bcmwifi.h> 24#include <bcmwifi.h>
@@ -27,7 +28,7 @@
27#include <pcicfg.h> 28#include <pcicfg.h>
28#include <bcmsrom.h> 29#include <bcmsrom.h>
29#include <wlioctl.h> 30#include <wlioctl.h>
30#include <epivers.h> 31#include <sbhndpio.h>
31#include <sbhnddma.h> 32#include <sbhnddma.h>
32#include <hnddma.h> 33#include <hnddma.h>
33#include <hndpmu.h> 34#include <hndpmu.h>
@@ -37,6 +38,7 @@
37#include <wlc_key.h> 38#include <wlc_key.h>
38#include <wlc_bsscfg.h> 39#include <wlc_bsscfg.h>
39#include <wlc_channel.h> 40#include <wlc_channel.h>
41#include <wlc_event.h>
40#include <wlc_mac80211.h> 42#include <wlc_mac80211.h>
41#include <wlc_bmac.h> 43#include <wlc_bmac.h>
42#include <wlc_scb.h> 44#include <wlc_scb.h>
@@ -47,27 +49,11 @@
47#include <wlc_ampdu.h> 49#include <wlc_ampdu.h>
48#include <wlc_event.h> 50#include <wlc_event.h>
49#include <wl_export.h> 51#include <wl_export.h>
50#ifdef BCMSDIO
51#include <bcmsdh.h>
52#else
53#include "d11ucode_ext.h" 52#include "d11ucode_ext.h"
54#endif
55#ifdef WLC_HIGH_ONLY
56#include <bcm_rpc_tp.h>
57#include <bcm_rpc.h>
58#include <bcm_xdr.h>
59#include <wlc_rpc.h>
60#include <wlc_rpctx.h>
61#endif /* WLC_HIGH_ONLY */
62#include <wlc_alloc.h> 53#include <wlc_alloc.h>
63#include <net/mac80211.h> 54#include <net/mac80211.h>
55#include <wl_dbg.h>
64 56
65#ifdef WLC_HIGH_ONLY
66#undef R_REG
67#undef W_REG
68#define R_REG(osh, r) RPC_READ_REG(osh, r)
69#define W_REG(osh, r, v) RPC_WRITE_REG(osh, r, v)
70#endif
71 57
72/* 58/*
73 * buffer length needed for wlc_format_ssid 59 * buffer length needed for wlc_format_ssid
@@ -107,12 +93,8 @@
107/* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */ 93/* To inform the ucode of the last mcast frame posted so that it can clear moredata bit */
108#define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid)) 94#define BCMCFID(wlc, fid) wlc_bmac_write_shm((wlc)->hw, M_BCMC_FID, (fid))
109 95
110#ifndef WLC_HIGH_ONLY 96#define WLC_WAR16165(wlc) (wlc->pub->sih->bustype == PCI_BUS && \
111#define WLC_WAR16165(wlc) (BUSTYPE(wlc->pub->sih->bustype) == PCI_BUS && \
112 (!AP_ENAB(wlc->pub)) && (wlc->war16165)) 97 (!AP_ENAB(wlc->pub)) && (wlc->war16165))
113#else
114#define WLC_WAR16165(wlc) (false)
115#endif /* WLC_HIGH_ONLY */
116 98
117/* debug/trace */ 99/* debug/trace */
118uint wl_msg_level = 100uint wl_msg_level =
@@ -135,9 +117,11 @@ uint wl_msg_level =
135 117
136#define SCAN_IN_PROGRESS(x) 0 118#define SCAN_IN_PROGRESS(x) 0
137 119
120#define EPI_VERSION_NUM 0x054b0b00
121
138#ifdef BCMDBG 122#ifdef BCMDBG
139/* pointer to most recently allocated wl/wlc */ 123/* pointer to most recently allocated wl/wlc */
140static wlc_info_t *wlc_info_dbg = (wlc_info_t *) (NULL); 124static struct wlc_info *wlc_info_dbg = (struct wlc_info *) (NULL);
141#endif 125#endif
142 126
143/* IOVar table */ 127/* IOVar table */
@@ -238,91 +222,91 @@ static const u8 acbitmap2maxprio[] = {
238#define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS 222#define WLC_REPLAY_CNTRS_VALUE WPA_CAP_16_REPLAY_CNTRS
239 223
240/* local prototypes */ 224/* local prototypes */
241extern void wlc_txq_enq(void *ctx, struct scb *scb, void *sdu, uint prec); 225static u16 BCMFASTPATH wlc_d11hdrs_mac80211(struct wlc_info *wlc,
242static u16 BCMFASTPATH wlc_d11hdrs_mac80211(wlc_info_t *wlc, 226 struct ieee80211_hw *hw,
243 struct ieee80211_hw *hw, void *p, 227 struct sk_buff *p,
244 struct scb *scb, uint frag, 228 struct scb *scb, uint frag,
245 uint nfrags, uint queue, 229 uint nfrags, uint queue,
246 uint next_frag_len, 230 uint next_frag_len,
247 wsec_key_t *key, 231 wsec_key_t *key,
248 ratespec_t rspec_override); 232 ratespec_t rspec_override);
249bool wlc_sendpkt_mac80211(wlc_info_t *wlc, void *sdu, struct ieee80211_hw *hw); 233
250void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg, bool suspend); 234static void wlc_bss_default_init(struct wlc_info *wlc);
251static void wlc_bss_default_init(wlc_info_t *wlc); 235static void wlc_ucode_mac_upd(struct wlc_info *wlc);
252static void wlc_ucode_mac_upd(wlc_info_t *wlc); 236static ratespec_t mac80211_wlc_set_nrate(struct wlc_info *wlc,
253static ratespec_t mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band, 237 struct wlcband *cur_band, u32 int_val);
254 u32 int_val); 238static void wlc_tx_prec_map_init(struct wlc_info *wlc);
255static void wlc_tx_prec_map_init(wlc_info_t *wlc);
256static void wlc_watchdog(void *arg); 239static void wlc_watchdog(void *arg);
257static void wlc_watchdog_by_timer(void *arg); 240static void wlc_watchdog_by_timer(void *arg);
258static int wlc_set_rateset(wlc_info_t *wlc, wlc_rateset_t *rs_arg); 241static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg);
259static int wlc_iovar_rangecheck(wlc_info_t *wlc, u32 val, 242static int wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val,
260 const bcm_iovar_t *vi); 243 const bcm_iovar_t *vi);
261static u8 wlc_local_constraint_qdbm(wlc_info_t *wlc); 244static u8 wlc_local_constraint_qdbm(struct wlc_info *wlc);
262 245
263/* send and receive */ 246/* send and receive */
264static wlc_txq_info_t *wlc_txq_alloc(wlc_info_t *wlc, osl_t *osh); 247static wlc_txq_info_t *wlc_txq_alloc(struct wlc_info *wlc,
265static void wlc_txq_free(wlc_info_t *wlc, osl_t *osh, wlc_txq_info_t *qi); 248 struct osl_info *osh);
266static void wlc_txflowcontrol_signal(wlc_info_t *wlc, wlc_txq_info_t *qi, 249static void wlc_txq_free(struct wlc_info *wlc, struct osl_info *osh,
250 wlc_txq_info_t *qi);
251static void wlc_txflowcontrol_signal(struct wlc_info *wlc, wlc_txq_info_t *qi,
267 bool on, int prio); 252 bool on, int prio);
268static void wlc_txflowcontrol_reset(wlc_info_t *wlc); 253static void wlc_txflowcontrol_reset(struct wlc_info *wlc);
269static u16 wlc_compute_airtime(wlc_info_t *wlc, ratespec_t rspec, 254static u16 wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec,
270 uint length); 255 uint length);
271static void wlc_compute_cck_plcp(ratespec_t rate, uint length, u8 *plcp); 256static void wlc_compute_cck_plcp(ratespec_t rate, uint length, u8 *plcp);
272static void wlc_compute_ofdm_plcp(ratespec_t rate, uint length, u8 *plcp); 257static void wlc_compute_ofdm_plcp(ratespec_t rate, uint length, u8 *plcp);
273static void wlc_compute_mimo_plcp(ratespec_t rate, uint length, u8 *plcp); 258static void wlc_compute_mimo_plcp(ratespec_t rate, uint length, u8 *plcp);
274static u16 wlc_compute_frame_dur(wlc_info_t *wlc, ratespec_t rate, 259static u16 wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate,
275 u8 preamble_type, uint next_frag_len); 260 u8 preamble_type, uint next_frag_len);
276static void wlc_recvctl(wlc_info_t *wlc, osl_t *osh, d11rxhdr_t *rxh, 261static void wlc_recvctl(struct wlc_info *wlc, struct osl_info *osh,
277 void *p); 262 d11rxhdr_t *rxh, struct sk_buff *p);
278static uint wlc_calc_frame_len(wlc_info_t *wlc, ratespec_t rate, 263static uint wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t rate,
279 u8 preamble_type, uint dur); 264 u8 preamble_type, uint dur);
280static uint wlc_calc_ack_time(wlc_info_t *wlc, ratespec_t rate, 265static uint wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rate,
281 u8 preamble_type); 266 u8 preamble_type);
282static uint wlc_calc_cts_time(wlc_info_t *wlc, ratespec_t rate, 267static uint wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rate,
283 u8 preamble_type); 268 u8 preamble_type);
284/* interrupt, up/down, band */ 269/* interrupt, up/down, band */
285static void wlc_setband(wlc_info_t *wlc, uint bandunit); 270static void wlc_setband(struct wlc_info *wlc, uint bandunit);
286static chanspec_t wlc_init_chanspec(wlc_info_t *wlc); 271static chanspec_t wlc_init_chanspec(struct wlc_info *wlc);
287static void wlc_bandinit_ordered(wlc_info_t *wlc, chanspec_t chanspec); 272static void wlc_bandinit_ordered(struct wlc_info *wlc, chanspec_t chanspec);
288static void wlc_bsinit(wlc_info_t *wlc); 273static void wlc_bsinit(struct wlc_info *wlc);
289static int wlc_duty_cycle_set(wlc_info_t *wlc, int duty_cycle, bool isOFDM, 274static int wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
290 bool writeToShm); 275 bool writeToShm);
291static void wlc_radio_hwdisable_upd(wlc_info_t *wlc); 276static void wlc_radio_hwdisable_upd(struct wlc_info *wlc);
292static bool wlc_radio_monitor_start(wlc_info_t *wlc); 277static bool wlc_radio_monitor_start(struct wlc_info *wlc);
293static void wlc_radio_timer(void *arg); 278static void wlc_radio_timer(void *arg);
294static void wlc_radio_enable(wlc_info_t *wlc); 279static void wlc_radio_enable(struct wlc_info *wlc);
295static void wlc_radio_upd(wlc_info_t *wlc); 280static void wlc_radio_upd(struct wlc_info *wlc);
296 281
297/* scan, association, BSS */ 282/* scan, association, BSS */
298static uint wlc_calc_ba_time(wlc_info_t *wlc, ratespec_t rate, 283static uint wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rate,
299 u8 preamble_type); 284 u8 preamble_type);
300static void wlc_update_mimo_band_bwcap(wlc_info_t *wlc, u8 bwcap); 285static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap);
301static void wlc_ht_update_sgi_rx(wlc_info_t *wlc, int val); 286static void wlc_ht_update_sgi_rx(struct wlc_info *wlc, int val);
302void wlc_ht_mimops_cap_update(wlc_info_t *wlc, u8 mimops_mode); 287static void wlc_ht_update_ldpc(struct wlc_info *wlc, s8 val);
303static void wlc_ht_update_ldpc(wlc_info_t *wlc, s8 val); 288static void wlc_war16165(struct wlc_info *wlc, bool tx);
304static void wlc_war16165(wlc_info_t *wlc, bool tx);
305 289
306static void wlc_process_eventq(void *arg); 290static void wlc_process_eventq(void *arg);
307static void wlc_wme_retries_write(wlc_info_t *wlc); 291static void wlc_wme_retries_write(struct wlc_info *wlc);
308static bool wlc_attach_stf_ant_init(wlc_info_t *wlc); 292static bool wlc_attach_stf_ant_init(struct wlc_info *wlc);
309static uint wlc_attach_module(wlc_info_t *wlc); 293static uint wlc_attach_module(struct wlc_info *wlc);
310static void wlc_detach_module(wlc_info_t *wlc); 294static void wlc_detach_module(struct wlc_info *wlc);
311static void wlc_timers_deinit(wlc_info_t *wlc); 295static void wlc_timers_deinit(struct wlc_info *wlc);
312static void wlc_down_led_upd(wlc_info_t *wlc); 296static void wlc_down_led_upd(struct wlc_info *wlc);
313static uint wlc_down_del_timer(wlc_info_t *wlc); 297static uint wlc_down_del_timer(struct wlc_info *wlc);
314static void wlc_ofdm_rateset_war(wlc_info_t *wlc); 298static void wlc_ofdm_rateset_war(struct wlc_info *wlc);
315static int _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, 299static int _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
316 struct wlc_if *wlcif); 300 struct wlc_if *wlcif);
317 301
318#if defined(BCMDBG) 302#if defined(BCMDBG)
319void wlc_get_rcmta(wlc_info_t *wlc, int idx, struct ether_addr *addr) 303void wlc_get_rcmta(struct wlc_info *wlc, int idx, struct ether_addr *addr)
320{ 304{
321 d11regs_t *regs = wlc->regs; 305 d11regs_t *regs = wlc->regs;
322 u32 v32; 306 u32 v32;
323 osl_t *osh; 307 struct osl_info *osh;
324 308
325 WL_TRACE(("wl%d: %s\n", WLCWLUNIT(wlc), __func__)); 309 WL_TRACE("wl%d: %s\n", WLCWLUNIT(wlc), __func__);
326 310
327 ASSERT(wlc->pub->corerev > 4); 311 ASSERT(wlc->pub->corerev > 4);
328 312
@@ -344,14 +328,14 @@ void wlc_get_rcmta(wlc_info_t *wlc, int idx, struct ether_addr *addr)
344#endif /* defined(BCMDBG) */ 328#endif /* defined(BCMDBG) */
345 329
346/* keep the chip awake if needed */ 330/* keep the chip awake if needed */
347bool wlc_stay_awake(wlc_info_t *wlc) 331bool wlc_stay_awake(struct wlc_info *wlc)
348{ 332{
349 return true; 333 return true;
350} 334}
351 335
352/* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful 336/* conditions under which the PM bit should be set in outgoing frames and STAY_AWAKE is meaningful
353 */ 337 */
354bool wlc_ps_allowed(wlc_info_t *wlc) 338bool wlc_ps_allowed(struct wlc_info *wlc)
355{ 339{
356 int idx; 340 int idx;
357 wlc_bsscfg_t *cfg; 341 wlc_bsscfg_t *cfg;
@@ -378,9 +362,9 @@ bool wlc_ps_allowed(wlc_info_t *wlc)
378 return true; 362 return true;
379} 363}
380 364
381void wlc_reset(wlc_info_t *wlc) 365void wlc_reset(struct wlc_info *wlc)
382{ 366{
383 WL_TRACE(("wl%d: wlc_reset\n", wlc->pub->unit)); 367 WL_TRACE("wl%d: wlc_reset\n", wlc->pub->unit);
384 368
385 wlc->check_for_unaligned_tbtt = false; 369 wlc->check_for_unaligned_tbtt = false;
386 370
@@ -389,34 +373,19 @@ void wlc_reset(wlc_info_t *wlc)
389 wlc_statsupd(wlc); 373 wlc_statsupd(wlc);
390 374
391 /* reset our snapshot of macstat counters */ 375 /* reset our snapshot of macstat counters */
392 bzero((char *)wlc->core->macstat_snapshot, sizeof(macstat_t)); 376 memset((char *)wlc->core->macstat_snapshot, 0,
377 sizeof(macstat_t));
393 } 378 }
394 379
395 wlc_bmac_reset(wlc->hw); 380 wlc_bmac_reset(wlc->hw);
396 wlc_ampdu_reset(wlc->ampdu); 381 wlc_ampdu_reset(wlc->ampdu);
397 wlc->txretried = 0; 382 wlc->txretried = 0;
398 383
399#ifdef WLC_HIGH_ONLY
400 /* Need to set a flag(to be cleared asynchronously by BMAC driver with high call)
401 * in order to prevent wlc_rpctx_txreclaim() from screwing wlc_rpctx_getnexttxp(),
402 * which could be invoked by already QUEUED high call(s) from BMAC driver before
403 * wlc_bmac_reset() finishes.
404 * It's not needed before in monolithic driver model because d11core interrupts would
405 * have been cleared instantly in wlc_bmac_reset() and no txstatus interrupt
406 * will come to driver to fetch those flushed dma pkt pointers.
407 */
408 wlc->reset_bmac_pending = true;
409
410 wlc_rpctx_txreclaim(wlc->rpctx);
411
412 wlc_stf_phy_txant_upd(wlc);
413 wlc_phy_ant_rxdiv_set(wlc->band->pi, wlc->stf->ant_rx_ovr);
414#endif
415} 384}
416 385
417void wlc_fatal_error(wlc_info_t *wlc) 386void wlc_fatal_error(struct wlc_info *wlc)
418{ 387{
419 WL_ERROR(("wl%d: fatal error, reinitializing\n", wlc->pub->unit)); 388 WL_ERROR("wl%d: fatal error, reinitializing\n", wlc->pub->unit);
420 wl_init(wlc->wl); 389 wl_init(wlc->wl);
421} 390}
422 391
@@ -425,7 +394,7 @@ void wlc_fatal_error(wlc_info_t *wlc)
425 * if other configurations are in conflict (bandlocked, 11n mode disabled, 394 * if other configurations are in conflict (bandlocked, 11n mode disabled,
426 * invalid channel for current country, etc.) 395 * invalid channel for current country, etc.)
427 */ 396 */
428static chanspec_t wlc_init_chanspec(wlc_info_t *wlc) 397static chanspec_t wlc_init_chanspec(struct wlc_info *wlc)
429{ 398{
430 chanspec_t chanspec = 399 chanspec_t chanspec =
431 1 | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE | 400 1 | WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE |
@@ -441,7 +410,7 @@ static chanspec_t wlc_init_chanspec(wlc_info_t *wlc)
441 410
442struct scb global_scb; 411struct scb global_scb;
443 412
444static void wlc_init_scb(wlc_info_t *wlc, struct scb *scb) 413static void wlc_init_scb(struct wlc_info *wlc, struct scb *scb)
445{ 414{
446 int i; 415 int i;
447 scb->flags = SCB_WMECAP | SCB_HTCAP; 416 scb->flags = SCB_WMECAP | SCB_HTCAP;
@@ -449,7 +418,7 @@ static void wlc_init_scb(wlc_info_t *wlc, struct scb *scb)
449 scb->seqnum[i] = 0; 418 scb->seqnum[i] = 0;
450} 419}
451 420
452void wlc_init(wlc_info_t *wlc) 421void wlc_init(struct wlc_info *wlc)
453{ 422{
454 d11regs_t *regs; 423 d11regs_t *regs;
455 chanspec_t chanspec; 424 chanspec_t chanspec;
@@ -457,7 +426,7 @@ void wlc_init(wlc_info_t *wlc)
457 wlc_bsscfg_t *bsscfg; 426 wlc_bsscfg_t *bsscfg;
458 bool mute = false; 427 bool mute = false;
459 428
460 WL_TRACE(("wl%d: wlc_init\n", wlc->pub->unit)); 429 WL_TRACE("wl%d: wlc_init\n", wlc->pub->unit);
461 430
462 regs = wlc->regs; 431 regs = wlc->regs;
463 432
@@ -583,13 +552,13 @@ void wlc_init(wlc_info_t *wlc)
583 } 552 }
584} 553}
585 554
586void wlc_mac_bcn_promisc_change(wlc_info_t *wlc, bool promisc) 555void wlc_mac_bcn_promisc_change(struct wlc_info *wlc, bool promisc)
587{ 556{
588 wlc->bcnmisc_monitor = promisc; 557 wlc->bcnmisc_monitor = promisc;
589 wlc_mac_bcn_promisc(wlc); 558 wlc_mac_bcn_promisc(wlc);
590} 559}
591 560
592void wlc_mac_bcn_promisc(wlc_info_t *wlc) 561void wlc_mac_bcn_promisc(struct wlc_info *wlc)
593{ 562{
594 if ((AP_ENAB(wlc->pub) && (N_ENAB(wlc->pub) || wlc->band->gmode)) || 563 if ((AP_ENAB(wlc->pub) && (N_ENAB(wlc->pub) || wlc->band->gmode)) ||
595 wlc->bcnmisc_ibss || wlc->bcnmisc_scan || wlc->bcnmisc_monitor) 564 wlc->bcnmisc_ibss || wlc->bcnmisc_scan || wlc->bcnmisc_monitor)
@@ -599,7 +568,7 @@ void wlc_mac_bcn_promisc(wlc_info_t *wlc)
599} 568}
600 569
601/* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */ 570/* set or clear maccontrol bits MCTL_PROMISC and MCTL_KEEPCONTROL */
602void wlc_mac_promisc(wlc_info_t *wlc) 571void wlc_mac_promisc(struct wlc_info *wlc)
603{ 572{
604 u32 promisc_bits = 0; 573 u32 promisc_bits = 0;
605 574
@@ -621,7 +590,7 @@ void wlc_mac_promisc(wlc_info_t *wlc)
621} 590}
622 591
623/* check if hps and wake states of sw and hw are in sync */ 592/* check if hps and wake states of sw and hw are in sync */
624bool wlc_ps_check(wlc_info_t *wlc) 593bool wlc_ps_check(struct wlc_info *wlc)
625{ 594{
626 bool res = true; 595 bool res = true;
627 bool hps, wake; 596 bool hps, wake;
@@ -636,8 +605,8 @@ bool wlc_ps_check(wlc_info_t *wlc)
636 * to avoid assert 605 * to avoid assert
637 */ 606 */
638 if (tmp == 0xffffffff) { 607 if (tmp == 0xffffffff) {
639 WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, 608 WL_ERROR("wl%d: %s: dead chip\n",
640 __func__)); 609 wlc->pub->unit, __func__);
641 return DEVICEREMOVED(wlc); 610 return DEVICEREMOVED(wlc);
642 } 611 }
643 612
@@ -646,7 +615,8 @@ bool wlc_ps_check(wlc_info_t *wlc)
646 if (hps != ((tmp & MCTL_HPS) != 0)) { 615 if (hps != ((tmp & MCTL_HPS) != 0)) {
647 int idx; 616 int idx;
648 wlc_bsscfg_t *cfg; 617 wlc_bsscfg_t *cfg;
649 WL_ERROR(("wl%d: hps not sync, sw %d, maccontrol 0x%x\n", wlc->pub->unit, hps, tmp)); 618 WL_ERROR("wl%d: hps not sync, sw %d, maccontrol 0x%x\n",
619 wlc->pub->unit, hps, tmp);
650 FOREACH_BSS(wlc, idx, cfg) { 620 FOREACH_BSS(wlc, idx, cfg) {
651 if (!BSSCFG_STA(cfg)) 621 if (!BSSCFG_STA(cfg))
652 continue; 622 continue;
@@ -654,23 +624,14 @@ bool wlc_ps_check(wlc_info_t *wlc)
654 624
655 res = false; 625 res = false;
656 } 626 }
657#ifdef WLC_LOW
658 /* For a monolithic build the wake check can be exact since it looks at wake 627 /* For a monolithic build the wake check can be exact since it looks at wake
659 * override bits. The MCTL_WAKE bit should match the 'wake' value. 628 * override bits. The MCTL_WAKE bit should match the 'wake' value.
660 */ 629 */
661 wake = STAY_AWAKE(wlc) || wlc->hw->wake_override; 630 wake = STAY_AWAKE(wlc) || wlc->hw->wake_override;
662 wake_ok = (wake == ((tmp & MCTL_WAKE) != 0)); 631 wake_ok = (wake == ((tmp & MCTL_WAKE) != 0));
663#else
664 /* For a split build we will not have access to any wake overrides from the low
665 * level. The check can only make sure the MCTL_WAKE bit is on if the high
666 * level 'wake' value is true. If the high level 'wake' is false, the MCTL_WAKE
667 * may be either true or false due to the low level override.
668 */
669 wake = STAY_AWAKE(wlc);
670 wake_ok = (wake && ((tmp & MCTL_WAKE) != 0)) || !wake;
671#endif
672 if (hps && !wake_ok) { 632 if (hps && !wake_ok) {
673 WL_ERROR(("wl%d: wake not sync, sw %d maccontrol 0x%x\n", wlc->pub->unit, wake, tmp)); 633 WL_ERROR("wl%d: wake not sync, sw %d maccontrol 0x%x\n",
634 wlc->pub->unit, wake, tmp);
674 res = false; 635 res = false;
675 } 636 }
676 } 637 }
@@ -679,7 +640,7 @@ bool wlc_ps_check(wlc_info_t *wlc)
679} 640}
680 641
681/* push sw hps and wake state through hardware */ 642/* push sw hps and wake state through hardware */
682void wlc_set_ps_ctrl(wlc_info_t *wlc) 643void wlc_set_ps_ctrl(struct wlc_info *wlc)
683{ 644{
684 u32 v1, v2; 645 u32 v1, v2;
685 bool hps, wake; 646 bool hps, wake;
@@ -688,8 +649,8 @@ void wlc_set_ps_ctrl(wlc_info_t *wlc)
688 hps = PS_ALLOWED(wlc); 649 hps = PS_ALLOWED(wlc);
689 wake = hps ? (STAY_AWAKE(wlc)) : true; 650 wake = hps ? (STAY_AWAKE(wlc)) : true;
690 651
691 WL_TRACE(("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n", wlc->pub->unit, 652 WL_TRACE("wl%d: wlc_set_ps_ctrl: hps %d wake %d\n",
692 hps, wake)); 653 wlc->pub->unit, hps, wake);
693 654
694 v1 = R_REG(wlc->osh, &wlc->regs->maccontrol); 655 v1 = R_REG(wlc->osh, &wlc->regs->maccontrol);
695 v2 = 0; 656 v2 = 0;
@@ -714,7 +675,7 @@ void wlc_set_ps_ctrl(wlc_info_t *wlc)
714int wlc_set_mac(wlc_bsscfg_t *cfg) 675int wlc_set_mac(wlc_bsscfg_t *cfg)
715{ 676{
716 int err = 0; 677 int err = 0;
717 wlc_info_t *wlc = cfg->wlc; 678 struct wlc_info *wlc = cfg->wlc;
718 679
719 if (cfg == wlc->cfg) { 680 if (cfg == wlc->cfg) {
720 /* enter the MAC addr into the RXE match registers */ 681 /* enter the MAC addr into the RXE match registers */
@@ -731,7 +692,7 @@ int wlc_set_mac(wlc_bsscfg_t *cfg)
731 */ 692 */
732void wlc_set_bssid(wlc_bsscfg_t *cfg) 693void wlc_set_bssid(wlc_bsscfg_t *cfg)
733{ 694{
734 wlc_info_t *wlc = cfg->wlc; 695 struct wlc_info *wlc = cfg->wlc;
735 696
736 /* if primary config, we need to update BSSID in RXE match registers */ 697 /* if primary config, we need to update BSSID in RXE match registers */
737 if (cfg == wlc->cfg) { 698 if (cfg == wlc->cfg) {
@@ -748,7 +709,7 @@ void wlc_set_bssid(wlc_bsscfg_t *cfg)
748 * Suspend the the MAC and update the slot timing 709 * Suspend the the MAC and update the slot timing
749 * for standard 11b/g (20us slots) or shortslot 11g (9us slots). 710 * for standard 11b/g (20us slots) or shortslot 11g (9us slots).
750 */ 711 */
751void wlc_switch_shortslot(wlc_info_t *wlc, bool shortslot) 712void wlc_switch_shortslot(struct wlc_info *wlc, bool shortslot)
752{ 713{
753 int idx; 714 int idx;
754 wlc_bsscfg_t *cfg; 715 wlc_bsscfg_t *cfg;
@@ -776,7 +737,7 @@ void wlc_switch_shortslot(wlc_info_t *wlc, bool shortslot)
776 wlc_bmac_set_shortslot(wlc->hw, shortslot); 737 wlc_bmac_set_shortslot(wlc->hw, shortslot);
777} 738}
778 739
779static u8 wlc_local_constraint_qdbm(wlc_info_t *wlc) 740static u8 wlc_local_constraint_qdbm(struct wlc_info *wlc)
780{ 741{
781 u8 local; 742 u8 local;
782 s16 local_max; 743 s16 local_max;
@@ -803,7 +764,7 @@ static u8 wlc_local_constraint_qdbm(wlc_info_t *wlc)
803} 764}
804 765
805/* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */ 766/* propagate home chanspec to all bsscfgs in case bsscfg->current_bss->chanspec is referenced */
806void wlc_set_home_chanspec(wlc_info_t *wlc, chanspec_t chanspec) 767void wlc_set_home_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
807{ 768{
808 if (wlc->home_chanspec != chanspec) { 769 if (wlc->home_chanspec != chanspec) {
809 int idx; 770 int idx;
@@ -821,7 +782,7 @@ void wlc_set_home_chanspec(wlc_info_t *wlc, chanspec_t chanspec)
821 } 782 }
822} 783}
823 784
824static void wlc_set_phy_chanspec(wlc_info_t *wlc, chanspec_t chanspec) 785static void wlc_set_phy_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
825{ 786{
826 /* Save our copy of the chanspec */ 787 /* Save our copy of the chanspec */
827 wlc->chanspec = chanspec; 788 wlc->chanspec = chanspec;
@@ -840,15 +801,15 @@ static void wlc_set_phy_chanspec(wlc_info_t *wlc, chanspec_t chanspec)
840 801
841} 802}
842 803
843void wlc_set_chanspec(wlc_info_t *wlc, chanspec_t chanspec) 804void wlc_set_chanspec(struct wlc_info *wlc, chanspec_t chanspec)
844{ 805{
845 uint bandunit; 806 uint bandunit;
846 bool switchband = false; 807 bool switchband = false;
847 chanspec_t old_chanspec = wlc->chanspec; 808 chanspec_t old_chanspec = wlc->chanspec;
848 809
849 if (!wlc_valid_chanspec_db(wlc->cmi, chanspec)) { 810 if (!wlc_valid_chanspec_db(wlc->cmi, chanspec)) {
850 WL_ERROR(("wl%d: %s: Bad channel %d\n", 811 WL_ERROR("wl%d: %s: Bad channel %d\n",
851 wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec))); 812 wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec));
852 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec)); 813 ASSERT(wlc_valid_chanspec_db(wlc->cmi, chanspec));
853 return; 814 return;
854 } 815 }
@@ -859,7 +820,9 @@ void wlc_set_chanspec(wlc_info_t *wlc, chanspec_t chanspec)
859 if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) { 820 if (wlc->band->bandunit != bandunit || wlc->bandinit_pending) {
860 switchband = true; 821 switchband = true;
861 if (wlc->bandlocked) { 822 if (wlc->bandlocked) {
862 WL_ERROR(("wl%d: %s: chspec %d band is locked!\n", wlc->pub->unit, __func__, CHSPEC_CHANNEL(chanspec))); 823 WL_ERROR("wl%d: %s: chspec %d band is locked!\n",
824 wlc->pub->unit, __func__,
825 CHSPEC_CHANNEL(chanspec));
863 return; 826 return;
864 } 827 }
865 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ? 828 /* BMAC_NOTE: should the setband call come after the wlc_bmac_chanspec() ?
@@ -895,7 +858,7 @@ void wlc_set_chanspec(wlc_info_t *wlc, chanspec_t chanspec)
895} 858}
896 859
897#if defined(BCMDBG) 860#if defined(BCMDBG)
898static int wlc_get_current_txpwr(wlc_info_t *wlc, void *pwr, uint len) 861static int wlc_get_current_txpwr(struct wlc_info *wlc, void *pwr, uint len)
899{ 862{
900 txpwr_limits_t txpwr; 863 txpwr_limits_t txpwr;
901 tx_power_t power; 864 tx_power_t power;
@@ -909,7 +872,7 @@ static int wlc_get_current_txpwr(wlc_info_t *wlc, void *pwr, uint len)
909 else if (len < sizeof(tx_power_t)) 872 else if (len < sizeof(tx_power_t))
910 return BCME_BUFTOOSHORT; 873 return BCME_BUFTOOSHORT;
911 874
912 bzero(&power, sizeof(tx_power_t)); 875 memset(&power, 0, sizeof(tx_power_t));
913 876
914 power.chanspec = WLC_BAND_PI_RADIO_CHANSPEC; 877 power.chanspec = WLC_BAND_PI_RADIO_CHANSPEC;
915 if (wlc->pub->associated) 878 if (wlc->pub->associated)
@@ -1031,7 +994,7 @@ static int wlc_get_current_txpwr(wlc_info_t *wlc, void *pwr, uint len)
1031 } else { 994 } else {
1032 int band_idx = CHSPEC_IS2G(power.chanspec) ? 0 : 1; 995 int band_idx = CHSPEC_IS2G(power.chanspec) ? 0 : 1;
1033 996
1034 bzero(old_power, sizeof(tx_power_legacy_t)); 997 memset(old_power, 0, sizeof(tx_power_legacy_t));
1035 998
1036 old_power->txpwr_local_max = power.local_max; 999 old_power->txpwr_local_max = power.local_max;
1037 old_power->txpwr_local_constraint = power.local_constraint; 1000 old_power->txpwr_local_constraint = power.local_constraint;
@@ -1064,7 +1027,7 @@ static int wlc_get_current_txpwr(wlc_info_t *wlc, void *pwr, uint len)
1064} 1027}
1065#endif /* defined(BCMDBG) */ 1028#endif /* defined(BCMDBG) */
1066 1029
1067static u32 wlc_watchdog_backup_bi(wlc_info_t *wlc) 1030static u32 wlc_watchdog_backup_bi(struct wlc_info *wlc)
1068{ 1031{
1069 u32 bi; 1032 u32 bi;
1070 bi = 2 * wlc->cfg->current_bss->dtim_period * 1033 bi = 2 * wlc->cfg->current_bss->dtim_period *
@@ -1083,7 +1046,7 @@ static u32 wlc_watchdog_backup_bi(wlc_info_t *wlc)
1083/* Change to run the watchdog either from a periodic timer or from tbtt handler. 1046/* Change to run the watchdog either from a periodic timer or from tbtt handler.
1084 * Call watchdog from tbtt handler if tbtt is true, watchdog timer otherwise. 1047 * Call watchdog from tbtt handler if tbtt is true, watchdog timer otherwise.
1085 */ 1048 */
1086void wlc_watchdog_upd(wlc_info_t *wlc, bool tbtt) 1049void wlc_watchdog_upd(struct wlc_info *wlc, bool tbtt)
1087{ 1050{
1088 /* make sure changing watchdog driver is allowed */ 1051 /* make sure changing watchdog driver is allowed */
1089 if (!wlc->pub->up || !wlc->pub->align_wd_tbtt) 1052 if (!wlc->pub->up || !wlc->pub->align_wd_tbtt)
@@ -1112,7 +1075,7 @@ void wlc_watchdog_upd(wlc_info_t *wlc, bool tbtt)
1112 } 1075 }
1113} 1076}
1114 1077
1115ratespec_t wlc_lowest_basic_rspec(wlc_info_t *wlc, wlc_rateset_t *rs) 1078ratespec_t wlc_lowest_basic_rspec(struct wlc_info *wlc, wlc_rateset_t *rs)
1116{ 1079{
1117 ratespec_t lowest_basic_rspec; 1080 ratespec_t lowest_basic_rspec;
1118 uint i; 1081 uint i;
@@ -1140,7 +1103,7 @@ ratespec_t wlc_lowest_basic_rspec(wlc_info_t *wlc, wlc_rateset_t *rs)
1140 * ratespec CCK ant = wlc->stf->txant 1103 * ratespec CCK ant = wlc->stf->txant
1141 * OFDM ant = 3 1104 * OFDM ant = 3
1142 */ 1105 */
1143void wlc_beacon_phytxctl_txant_upd(wlc_info_t *wlc, ratespec_t bcn_rspec) 1106void wlc_beacon_phytxctl_txant_upd(struct wlc_info *wlc, ratespec_t bcn_rspec)
1144{ 1107{
1145 u16 phyctl; 1108 u16 phyctl;
1146 u16 phytxant = wlc->stf->phytxant; 1109 u16 phytxant = wlc->stf->phytxant;
@@ -1159,9 +1122,9 @@ void wlc_beacon_phytxctl_txant_upd(wlc_info_t *wlc, ratespec_t bcn_rspec)
1159/* centralized protection config change function to simplify debugging, no consistency checking 1122/* centralized protection config change function to simplify debugging, no consistency checking
1160 * this should be called only on changes to avoid overhead in periodic function 1123 * this should be called only on changes to avoid overhead in periodic function
1161*/ 1124*/
1162void wlc_protection_upd(wlc_info_t *wlc, uint idx, int val) 1125void wlc_protection_upd(struct wlc_info *wlc, uint idx, int val)
1163{ 1126{
1164 WL_TRACE(("wlc_protection_upd: idx %d, val %d\n", idx, val)); 1127 WL_TRACE("wlc_protection_upd: idx %d, val %d\n", idx, val);
1165 1128
1166 switch (idx) { 1129 switch (idx) {
1167 case WLC_PROT_G_SPEC: 1130 case WLC_PROT_G_SPEC:
@@ -1205,7 +1168,7 @@ void wlc_protection_upd(wlc_info_t *wlc, uint idx, int val)
1205 1168
1206} 1169}
1207 1170
1208static void wlc_ht_update_sgi_rx(wlc_info_t *wlc, int val) 1171static void wlc_ht_update_sgi_rx(struct wlc_info *wlc, int val)
1209{ 1172{
1210 wlc->ht_cap.cap &= ~(HT_CAP_SHORT_GI_20 | HT_CAP_SHORT_GI_40); 1173 wlc->ht_cap.cap &= ~(HT_CAP_SHORT_GI_20 | HT_CAP_SHORT_GI_40);
1211 wlc->ht_cap.cap |= (val & WLC_N_SGI_20) ? HT_CAP_SHORT_GI_20 : 0; 1174 wlc->ht_cap.cap |= (val & WLC_N_SGI_20) ? HT_CAP_SHORT_GI_20 : 0;
@@ -1217,7 +1180,7 @@ static void wlc_ht_update_sgi_rx(wlc_info_t *wlc, int val)
1217 } 1180 }
1218} 1181}
1219 1182
1220static void wlc_ht_update_ldpc(wlc_info_t *wlc, s8 val) 1183static void wlc_ht_update_ldpc(struct wlc_info *wlc, s8 val)
1221{ 1184{
1222 wlc->stf->ldpc = val; 1185 wlc->stf->ldpc = val;
1223 1186
@@ -1236,7 +1199,7 @@ static void wlc_ht_update_ldpc(wlc_info_t *wlc, s8 val)
1236 * ucode, hwmac update 1199 * ucode, hwmac update
1237 * Channel dependent updates for ucode and hw 1200 * Channel dependent updates for ucode and hw
1238 */ 1201 */
1239static void wlc_ucode_mac_upd(wlc_info_t *wlc) 1202static void wlc_ucode_mac_upd(struct wlc_info *wlc)
1240{ 1203{
1241 /* enable or disable any active IBSSs depending on whether or not 1204 /* enable or disable any active IBSSs depending on whether or not
1242 * we are on the home channel 1205 * we are on the home channel
@@ -1263,13 +1226,13 @@ static void wlc_ucode_mac_upd(wlc_info_t *wlc)
1263 wlc_mac_promisc(wlc); 1226 wlc_mac_promisc(wlc);
1264} 1227}
1265 1228
1266static void wlc_bandinit_ordered(wlc_info_t *wlc, chanspec_t chanspec) 1229static void wlc_bandinit_ordered(struct wlc_info *wlc, chanspec_t chanspec)
1267{ 1230{
1268 wlc_rateset_t default_rateset; 1231 wlc_rateset_t default_rateset;
1269 uint parkband; 1232 uint parkband;
1270 uint i, band_order[2]; 1233 uint i, band_order[2];
1271 1234
1272 WL_TRACE(("wl%d: wlc_bandinit_ordered\n", wlc->pub->unit)); 1235 WL_TRACE("wl%d: wlc_bandinit_ordered\n", wlc->pub->unit);
1273 /* 1236 /*
1274 * We might have been bandlocked during down and the chip power-cycled (hibernate). 1237 * We might have been bandlocked during down and the chip power-cycled (hibernate).
1275 * figure out the right band to park on 1238 * figure out the right band to park on
@@ -1310,10 +1273,10 @@ static void wlc_bandinit_ordered(wlc_info_t *wlc, chanspec_t chanspec)
1310} 1273}
1311 1274
1312/* band-specific init */ 1275/* band-specific init */
1313static void WLBANDINITFN(wlc_bsinit) (wlc_info_t *wlc) 1276static void WLBANDINITFN(wlc_bsinit) (struct wlc_info *wlc)
1314{ 1277{
1315 WL_TRACE(("wl%d: wlc_bsinit: bandunit %d\n", wlc->pub->unit, 1278 WL_TRACE("wl%d: wlc_bsinit: bandunit %d\n",
1316 wlc->band->bandunit)); 1279 wlc->pub->unit, wlc->band->bandunit);
1317 1280
1318 /* write ucode ACK/CTS rate table */ 1281 /* write ucode ACK/CTS rate table */
1319 wlc_set_ratetable(wlc); 1282 wlc_set_ratetable(wlc);
@@ -1328,7 +1291,7 @@ static void WLBANDINITFN(wlc_bsinit) (wlc_info_t *wlc)
1328} 1291}
1329 1292
1330/* switch to and initialize new band */ 1293/* switch to and initialize new band */
1331static void WLBANDINITFN(wlc_setband) (wlc_info_t *wlc, uint bandunit) 1294static void WLBANDINITFN(wlc_setband) (struct wlc_info *wlc, uint bandunit)
1332{ 1295{
1333 int idx; 1296 int idx;
1334 wlc_bsscfg_t *cfg; 1297 wlc_bsscfg_t *cfg;
@@ -1353,7 +1316,7 @@ static void WLBANDINITFN(wlc_setband) (wlc_info_t *wlc, uint bandunit)
1353} 1316}
1354 1317
1355/* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */ 1318/* Initialize a WME Parameter Info Element with default STA parameters from WMM Spec, Table 12 */
1356void wlc_wme_initparams_sta(wlc_info_t *wlc, wme_param_ie_t *pe) 1319void wlc_wme_initparams_sta(struct wlc_info *wlc, wme_param_ie_t *pe)
1357{ 1320{
1358 static const wme_param_ie_t stadef = { 1321 static const wme_param_ie_t stadef = {
1359 WME_OUI, 1322 WME_OUI,
@@ -1378,7 +1341,7 @@ void wlc_wme_initparams_sta(wlc_info_t *wlc, wme_param_ie_t *pe)
1378 memcpy(pe, &stadef, sizeof(*pe)); 1341 memcpy(pe, &stadef, sizeof(*pe));
1379} 1342}
1380 1343
1381void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg, bool suspend) 1344void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, void *arg, bool suspend)
1382{ 1345{
1383 int i; 1346 int i;
1384 shm_acparams_t acp_shm; 1347 shm_acparams_t acp_shm;
@@ -1389,7 +1352,7 @@ void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg, bool suspend)
1389 1352
1390 /* Only apply params if the core is out of reset and has clocks */ 1353 /* Only apply params if the core is out of reset and has clocks */
1391 if (!wlc->clk) { 1354 if (!wlc->clk) {
1392 WL_ERROR(("wl%d: %s : no-clock\n", wlc->pub->unit, __func__)); 1355 WL_ERROR("wl%d: %s : no-clock\n", wlc->pub->unit, __func__);
1393 return; 1356 return;
1394 } 1357 }
1395 1358
@@ -1402,7 +1365,7 @@ void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg, bool suspend)
1402 wlc->wme_admctl = 0; 1365 wlc->wme_admctl = 0;
1403 1366
1404 do { 1367 do {
1405 bzero((char *)&acp_shm, sizeof(shm_acparams_t)); 1368 memset((char *)&acp_shm, 0, sizeof(shm_acparams_t));
1406 /* find out which ac this set of params applies to */ 1369 /* find out which ac this set of params applies to */
1407 ASSERT(aci < AC_COUNT); 1370 ASSERT(aci < AC_COUNT);
1408 /* set the admission control policy for this AC */ 1371 /* set the admission control policy for this AC */
@@ -1421,8 +1384,8 @@ void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg, bool suspend)
1421 1384
1422 if (acp_shm.aifs < EDCF_AIFSN_MIN 1385 if (acp_shm.aifs < EDCF_AIFSN_MIN
1423 || acp_shm.aifs > EDCF_AIFSN_MAX) { 1386 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1424 WL_ERROR(("wl%d: wlc_edcf_setparams: bad aifs %d\n", 1387 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1425 wlc->pub->unit, acp_shm.aifs)); 1388 wlc->pub->unit, acp_shm.aifs);
1426 continue; 1389 continue;
1427 } 1390 }
1428 1391
@@ -1459,7 +1422,7 @@ void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg, bool suspend)
1459 1422
1460void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend) 1423void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend)
1461{ 1424{
1462 wlc_info_t *wlc = cfg->wlc; 1425 struct wlc_info *wlc = cfg->wlc;
1463 uint aci, i, j; 1426 uint aci, i, j;
1464 edcf_acparam_t *edcf_acp; 1427 edcf_acparam_t *edcf_acp;
1465 shm_acparams_t acp_shm; 1428 shm_acparams_t acp_shm;
@@ -1483,7 +1446,7 @@ void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend)
1483 wlc->wme_admctl = 0; 1446 wlc->wme_admctl = 0;
1484 1447
1485 for (i = 0; i < AC_COUNT; i++, edcf_acp++) { 1448 for (i = 0; i < AC_COUNT; i++, edcf_acp++) {
1486 bzero((char *)&acp_shm, sizeof(shm_acparams_t)); 1449 memset((char *)&acp_shm, 0, sizeof(shm_acparams_t));
1487 /* find out which ac this set of params applies to */ 1450 /* find out which ac this set of params applies to */
1488 aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT; 1451 aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT;
1489 ASSERT(aci < AC_COUNT); 1452 ASSERT(aci < AC_COUNT);
@@ -1505,8 +1468,8 @@ void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend)
1505 1468
1506 if (acp_shm.aifs < EDCF_AIFSN_MIN 1469 if (acp_shm.aifs < EDCF_AIFSN_MIN
1507 || acp_shm.aifs > EDCF_AIFSN_MAX) { 1470 || acp_shm.aifs > EDCF_AIFSN_MAX) {
1508 WL_ERROR(("wl%d: wlc_edcf_setparams: bad aifs %d\n", 1471 WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n",
1509 wlc->pub->unit, acp_shm.aifs)); 1472 wlc->pub->unit, acp_shm.aifs);
1510 continue; 1473 continue;
1511 } 1474 }
1512 1475
@@ -1548,20 +1511,19 @@ void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend)
1548 1511
1549} 1512}
1550 1513
1551bool wlc_timers_init(wlc_info_t *wlc, int unit) 1514bool wlc_timers_init(struct wlc_info *wlc, int unit)
1552{ 1515{
1553 wlc->wdtimer = wl_init_timer(wlc->wl, wlc_watchdog_by_timer, 1516 wlc->wdtimer = wl_init_timer(wlc->wl, wlc_watchdog_by_timer,
1554 wlc, "watchdog"); 1517 wlc, "watchdog");
1555 if (!wlc->wdtimer) { 1518 if (!wlc->wdtimer) {
1556 WL_ERROR(("wl%d: wl_init_timer for wdtimer failed\n", unit)); 1519 WL_ERROR("wl%d: wl_init_timer for wdtimer failed\n", unit);
1557 goto fail; 1520 goto fail;
1558 } 1521 }
1559 1522
1560 wlc->radio_timer = wl_init_timer(wlc->wl, wlc_radio_timer, 1523 wlc->radio_timer = wl_init_timer(wlc->wl, wlc_radio_timer,
1561 wlc, "radio"); 1524 wlc, "radio");
1562 if (!wlc->radio_timer) { 1525 if (!wlc->radio_timer) {
1563 WL_ERROR(("wl%d: wl_init_timer for radio_timer failed\n", 1526 WL_ERROR("wl%d: wl_init_timer for radio_timer failed\n", unit);
1564 unit));
1565 goto fail; 1527 goto fail;
1566 } 1528 }
1567 1529
@@ -1575,7 +1537,7 @@ bool wlc_timers_init(wlc_info_t *wlc, int unit)
1575 * Initialize wlc_info default values ... 1537 * Initialize wlc_info default values ...
1576 * may get overrides later in this function 1538 * may get overrides later in this function
1577 */ 1539 */
1578void wlc_info_init(wlc_info_t *wlc, int unit) 1540void wlc_info_init(struct wlc_info *wlc, int unit)
1579{ 1541{
1580 int i; 1542 int i;
1581 /* Assume the device is there until proven otherwise */ 1543 /* Assume the device is there until proven otherwise */
@@ -1686,7 +1648,7 @@ void wlc_info_init(wlc_info_t *wlc, int unit)
1686 wlc->pr80838_war = true; 1648 wlc->pr80838_war = true;
1687} 1649}
1688 1650
1689static bool wlc_state_bmac_sync(wlc_info_t *wlc) 1651static bool wlc_state_bmac_sync(struct wlc_info *wlc)
1690{ 1652{
1691 wlc_bmac_state_t state_bmac; 1653 wlc_bmac_state_t state_bmac;
1692 1654
@@ -1700,7 +1662,7 @@ static bool wlc_state_bmac_sync(wlc_info_t *wlc)
1700 return true; 1662 return true;
1701} 1663}
1702 1664
1703static uint wlc_attach_module(wlc_info_t *wlc) 1665static uint wlc_attach_module(struct wlc_info *wlc)
1704{ 1666{
1705 uint err = 0; 1667 uint err = 0;
1706 uint unit; 1668 uint unit;
@@ -1708,15 +1670,14 @@ static uint wlc_attach_module(wlc_info_t *wlc)
1708 1670
1709 wlc->asi = wlc_antsel_attach(wlc, wlc->osh, wlc->pub, wlc->hw); 1671 wlc->asi = wlc_antsel_attach(wlc, wlc->osh, wlc->pub, wlc->hw);
1710 if (wlc->asi == NULL) { 1672 if (wlc->asi == NULL) {
1711 WL_ERROR(("wl%d: wlc_attach: wlc_antsel_attach failed\n", 1673 WL_ERROR("wl%d: wlc_attach: wlc_antsel_attach failed\n", unit);
1712 unit));
1713 err = 44; 1674 err = 44;
1714 goto fail; 1675 goto fail;
1715 } 1676 }
1716 1677
1717 wlc->ampdu = wlc_ampdu_attach(wlc); 1678 wlc->ampdu = wlc_ampdu_attach(wlc);
1718 if (wlc->ampdu == NULL) { 1679 if (wlc->ampdu == NULL) {
1719 WL_ERROR(("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit)); 1680 WL_ERROR("wl%d: wlc_attach: wlc_ampdu_attach failed\n", unit);
1720 err = 50; 1681 err = 50;
1721 goto fail; 1682 goto fail;
1722 } 1683 }
@@ -1725,13 +1686,13 @@ static uint wlc_attach_module(wlc_info_t *wlc)
1725 wlc->eventq = 1686 wlc->eventq =
1726 wlc_eventq_attach(wlc->pub, wlc, wlc->wl, wlc_process_eventq); 1687 wlc_eventq_attach(wlc->pub, wlc, wlc->wl, wlc_process_eventq);
1727 if (wlc->eventq == NULL) { 1688 if (wlc->eventq == NULL) {
1728 WL_ERROR(("wl%d: wlc_attach: wlc_eventq_attachfailed\n", unit)); 1689 WL_ERROR("wl%d: wlc_attach: wlc_eventq_attachfailed\n", unit);
1729 err = 57; 1690 err = 57;
1730 goto fail; 1691 goto fail;
1731 } 1692 }
1732 1693
1733 if ((wlc_stf_attach(wlc) != 0)) { 1694 if ((wlc_stf_attach(wlc) != 0)) {
1734 WL_ERROR(("wl%d: wlc_attach: wlc_stf_attach failed\n", unit)); 1695 WL_ERROR("wl%d: wlc_attach: wlc_stf_attach failed\n", unit);
1735 err = 68; 1696 err = 68;
1736 goto fail; 1697 goto fail;
1737 } 1698 }
@@ -1739,9 +1700,9 @@ static uint wlc_attach_module(wlc_info_t *wlc)
1739 return err; 1700 return err;
1740} 1701}
1741 1702
1742wlc_pub_t *wlc_pub(void *wlc) 1703struct wlc_pub *wlc_pub(void *wlc)
1743{ 1704{
1744 return ((wlc_info_t *) wlc)->pub; 1705 return ((struct wlc_info *) wlc)->pub;
1745} 1706}
1746 1707
1747#define CHIP_SUPPORTS_11N(wlc) 1 1708#define CHIP_SUPPORTS_11N(wlc) 1
@@ -1750,25 +1711,25 @@ wlc_pub_t *wlc_pub(void *wlc)
1750 * The common driver entry routine. Error codes should be unique 1711 * The common driver entry routine. Error codes should be unique
1751 */ 1712 */
1752void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode, 1713void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1753 osl_t *osh, void *regsva, uint bustype, void *btparam, 1714 struct osl_info *osh, void *regsva, uint bustype,
1754 uint *perr) 1715 void *btparam, uint *perr)
1755{ 1716{
1756 wlc_info_t *wlc; 1717 struct wlc_info *wlc;
1757 uint err = 0; 1718 uint err = 0;
1758 uint j; 1719 uint j;
1759 wlc_pub_t *pub; 1720 struct wlc_pub *pub;
1760 wlc_txq_info_t *qi; 1721 wlc_txq_info_t *qi;
1761 uint n_disabled; 1722 uint n_disabled;
1762 1723
1763 WL_NONE(("wl%d: %s: vendor 0x%x device 0x%x\n", unit, __func__, vendor, 1724 WL_NONE("wl%d: %s: vendor 0x%x device 0x%x\n",
1764 device)); 1725 unit, __func__, vendor, device);
1765 1726
1766 ASSERT(WSEC_MAX_RCMTA_KEYS <= WSEC_MAX_KEYS); 1727 ASSERT(WSEC_MAX_RCMTA_KEYS <= WSEC_MAX_KEYS);
1767 ASSERT(WSEC_MAX_DEFAULT_KEYS == WLC_DEFAULT_KEYS); 1728 ASSERT(WSEC_MAX_DEFAULT_KEYS == WLC_DEFAULT_KEYS);
1768 1729
1769 /* some code depends on packed structures */ 1730 /* some code depends on packed structures */
1770 ASSERT(sizeof(struct ether_addr) == ETHER_ADDR_LEN); 1731 ASSERT(sizeof(struct ether_addr) == ETH_ALEN);
1771 ASSERT(sizeof(struct ether_header) == ETHER_HDR_LEN); 1732 ASSERT(sizeof(struct ether_header) == ETH_HLEN);
1772 ASSERT(sizeof(d11regs_t) == SI_CORE_SIZE); 1733 ASSERT(sizeof(d11regs_t) == SI_CORE_SIZE);
1773 ASSERT(sizeof(ofdm_phy_hdr_t) == D11_PHY_HDR_LEN); 1734 ASSERT(sizeof(ofdm_phy_hdr_t) == D11_PHY_HDR_LEN);
1774 ASSERT(sizeof(cck_phy_hdr_t) == D11_PHY_HDR_LEN); 1735 ASSERT(sizeof(cck_phy_hdr_t) == D11_PHY_HDR_LEN);
@@ -1780,8 +1741,10 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1780 ASSERT(sizeof(struct dot11_bcn_prb) == DOT11_BCN_PRB_LEN); 1741 ASSERT(sizeof(struct dot11_bcn_prb) == DOT11_BCN_PRB_LEN);
1781 ASSERT(sizeof(tx_status_t) == TXSTATUS_LEN); 1742 ASSERT(sizeof(tx_status_t) == TXSTATUS_LEN);
1782 ASSERT(sizeof(ht_cap_ie_t) == HT_CAP_IE_LEN); 1743 ASSERT(sizeof(ht_cap_ie_t) == HT_CAP_IE_LEN);
1744#ifdef BRCM_FULLMAC
1783 ASSERT(offsetof(wl_scan_params_t, channel_list) == 1745 ASSERT(offsetof(wl_scan_params_t, channel_list) ==
1784 WL_SCAN_PARAMS_FIXED_SIZE); 1746 WL_SCAN_PARAMS_FIXED_SIZE);
1747#endif
1785 ASSERT(IS_ALIGNED(offsetof(wsec_key_t, data), sizeof(u32))); 1748 ASSERT(IS_ALIGNED(offsetof(wsec_key_t, data), sizeof(u32)));
1786 ASSERT(ISPOWEROF2(MA_WINDOW_SZ)); 1749 ASSERT(ISPOWEROF2(MA_WINDOW_SZ));
1787 1750
@@ -1797,8 +1760,8 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1797 || (WPA_CAP_4_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE 1760 || (WPA_CAP_4_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE
1798 && 4 == WLC_NUMRXIVS)); 1761 && 4 == WLC_NUMRXIVS));
1799 1762
1800 /* allocate wlc_info_t state and its substructures */ 1763 /* allocate struct wlc_info state and its substructures */
1801 wlc = (wlc_info_t *) wlc_attach_malloc(osh, unit, &err, device); 1764 wlc = (struct wlc_info *) wlc_attach_malloc(osh, unit, &err, device);
1802 if (wlc == NULL) 1765 if (wlc == NULL)
1803 goto fail; 1766 goto fail;
1804 wlc->osh = osh; 1767 wlc->osh = osh;
@@ -1819,7 +1782,7 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1819 /* By default restrict TKIP associations from 11n STA's */ 1782 /* By default restrict TKIP associations from 11n STA's */
1820 wlc->ht_wsec_restriction = WLC_HT_TKIP_RESTRICT; 1783 wlc->ht_wsec_restriction = WLC_HT_TKIP_RESTRICT;
1821 1784
1822 /* populate wlc_info_t with default values */ 1785 /* populate struct wlc_info with default values */
1823 wlc_info_init(wlc, unit); 1786 wlc_info_init(wlc, unit);
1824 1787
1825 /* update sta/ap related parameters */ 1788 /* update sta/ap related parameters */
@@ -1851,10 +1814,6 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1851 /* propagate *vars* from BMAC driver to high driver */ 1814 /* propagate *vars* from BMAC driver to high driver */
1852 wlc_bmac_copyfrom_vars(wlc->hw, &pub->vars, &wlc->vars_size); 1815 wlc_bmac_copyfrom_vars(wlc->hw, &pub->vars, &wlc->vars_size);
1853 1816
1854#ifdef WLC_HIGH_ONLY
1855 WL_TRACE(("nvram : vars %p , vars_size %d\n", pub->vars,
1856 wlc->vars_size));
1857#endif
1858 1817
1859 /* set maximum allowed duty cycle */ 1818 /* set maximum allowed duty cycle */
1860 wlc->tx_duty_cycle_ofdm = 1819 wlc->tx_duty_cycle_ofdm =
@@ -1872,19 +1831,17 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1872 wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain, 1831 wlc_phy_stf_chain_init(wlc->band->pi, wlc->stf->hw_txchain,
1873 wlc->stf->hw_rxchain); 1832 wlc->stf->hw_rxchain);
1874 1833
1875#ifdef WLC_LOW
1876 /* pull up some info resulting from the low attach */ 1834 /* pull up some info resulting from the low attach */
1877 { 1835 {
1878 int i; 1836 int i;
1879 for (i = 0; i < NFIFO; i++) 1837 for (i = 0; i < NFIFO; i++)
1880 wlc->core->txavail[i] = wlc->hw->txavail[i]; 1838 wlc->core->txavail[i] = wlc->hw->txavail[i];
1881 } 1839 }
1882#endif /* WLC_LOW */
1883 1840
1884 wlc_bmac_hw_etheraddr(wlc->hw, &wlc->perm_etheraddr); 1841 wlc_bmac_hw_etheraddr(wlc->hw, &wlc->perm_etheraddr);
1885 1842
1886 bcopy((char *)&wlc->perm_etheraddr, (char *)&pub->cur_etheraddr, 1843 bcopy((char *)&wlc->perm_etheraddr, (char *)&pub->cur_etheraddr,
1887 ETHER_ADDR_LEN); 1844 ETH_ALEN);
1888 1845
1889 for (j = 0; j < NBANDS(wlc); j++) { 1846 for (j = 0; j < NBANDS(wlc); j++) {
1890 /* Use band 1 for single band 11a */ 1847 /* Use band 1 for single band 11a */
@@ -1942,7 +1899,7 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1942 goto fail; 1899 goto fail;
1943 1900
1944 if (!wlc_timers_init(wlc, unit)) { 1901 if (!wlc_timers_init(wlc, unit)) {
1945 WL_ERROR(("wl%d: %s: wlc_init_timer failed\n", unit, __func__)); 1902 WL_ERROR("wl%d: %s: wlc_init_timer failed\n", unit, __func__);
1946 err = 32; 1903 err = 32;
1947 goto fail; 1904 goto fail;
1948 } 1905 }
@@ -1950,8 +1907,8 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1950 /* depend on rateset, gmode */ 1907 /* depend on rateset, gmode */
1951 wlc->cmi = wlc_channel_mgr_attach(wlc); 1908 wlc->cmi = wlc_channel_mgr_attach(wlc);
1952 if (!wlc->cmi) { 1909 if (!wlc->cmi) {
1953 WL_ERROR(("wl%d: %s: wlc_channel_mgr_attach failed\n", unit, 1910 WL_ERROR("wl%d: %s: wlc_channel_mgr_attach failed\n",
1954 __func__)); 1911 unit, __func__);
1955 err = 33; 1912 err = 33;
1956 goto fail; 1913 goto fail;
1957 } 1914 }
@@ -1966,8 +1923,8 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
1966 /* allocate our initial queue */ 1923 /* allocate our initial queue */
1967 qi = wlc_txq_alloc(wlc, osh); 1924 qi = wlc_txq_alloc(wlc, osh);
1968 if (qi == NULL) { 1925 if (qi == NULL) {
1969 WL_ERROR(("wl%d: %s: failed to malloc tx queue\n", unit, 1926 WL_ERROR("wl%d: %s: failed to malloc tx queue\n",
1970 __func__)); 1927 unit, __func__);
1971 err = 100; 1928 err = 100;
1972 goto fail; 1929 goto fail;
1973 } 1930 }
@@ -2037,7 +1994,7 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
2037 wlc_radio_mpc_upd(wlc); 1994 wlc_radio_mpc_upd(wlc);
2038 1995
2039 if (WLANTSEL_ENAB(wlc)) { 1996 if (WLANTSEL_ENAB(wlc)) {
2040 if ((CHIPID(wlc->pub->sih->chip)) == BCM43235_CHIP_ID) { 1997 if ((wlc->pub->sih->chip) == BCM43235_CHIP_ID) {
2041 if ((getintvar(wlc->pub->vars, "aa2g") == 7) || 1998 if ((getintvar(wlc->pub->vars, "aa2g") == 7) ||
2042 (getintvar(wlc->pub->vars, "aa5g") == 7)) { 1999 (getintvar(wlc->pub->vars, "aa5g") == 7)) {
2043 wlc_bmac_antsel_set(wlc->hw, 1); 2000 wlc_bmac_antsel_set(wlc->hw, 1);
@@ -2053,7 +2010,7 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
2053 return (void *)wlc; 2010 return (void *)wlc;
2054 2011
2055 fail: 2012 fail:
2056 WL_ERROR(("wl%d: %s: failed with err %d\n", unit, __func__, err)); 2013 WL_ERROR("wl%d: %s: failed with err %d\n", unit, __func__, err);
2057 if (wlc) 2014 if (wlc)
2058 wlc_detach(wlc); 2015 wlc_detach(wlc);
2059 2016
@@ -2062,7 +2019,7 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode,
2062 return NULL; 2019 return NULL;
2063} 2020}
2064 2021
2065static void wlc_attach_antgain_init(wlc_info_t *wlc) 2022static void wlc_attach_antgain_init(struct wlc_info *wlc)
2066{ 2023{
2067 uint unit; 2024 uint unit;
2068 unit = wlc->pub->unit; 2025 unit = wlc->pub->unit;
@@ -2071,7 +2028,8 @@ static void wlc_attach_antgain_init(wlc_info_t *wlc)
2071 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */ 2028 /* default antenna gain for srom rev 1 is 2 dBm (8 qdbm) */
2072 wlc->band->antgain = 8; 2029 wlc->band->antgain = 8;
2073 } else if (wlc->band->antgain == -1) { 2030 } else if (wlc->band->antgain == -1) {
2074 WL_ERROR(("wl%d: %s: Invalid antennas available in srom, using 2dB\n", unit, __func__)); 2031 WL_ERROR("wl%d: %s: Invalid antennas available in srom, using 2dB\n",
2032 unit, __func__);
2075 wlc->band->antgain = 8; 2033 wlc->band->antgain = 8;
2076 } else { 2034 } else {
2077 s8 gain, fract; 2035 s8 gain, fract;
@@ -2093,7 +2051,7 @@ static void wlc_attach_antgain_init(wlc_info_t *wlc)
2093 } 2051 }
2094} 2052}
2095 2053
2096static bool wlc_attach_stf_ant_init(wlc_info_t *wlc) 2054static bool wlc_attach_stf_ant_init(struct wlc_info *wlc)
2097{ 2055{
2098 int aa; 2056 int aa;
2099 uint unit; 2057 uint unit;
@@ -2110,7 +2068,8 @@ static bool wlc_attach_stf_ant_init(wlc_info_t *wlc)
2110 aa = (s8) getintvar(vars, 2068 aa = (s8) getintvar(vars,
2111 (BAND_5G(bandtype) ? "aa1" : "aa0")); 2069 (BAND_5G(bandtype) ? "aa1" : "aa0"));
2112 if ((aa < 1) || (aa > 15)) { 2070 if ((aa < 1) || (aa > 15)) {
2113 WL_ERROR(("wl%d: %s: Invalid antennas available in srom (0x%x), using 3.\n", unit, __func__, aa)); 2071 WL_ERROR("wl%d: %s: Invalid antennas available in srom (0x%x), using 3\n",
2072 unit, __func__, aa);
2114 aa = 3; 2073 aa = 3;
2115 } 2074 }
2116 2075
@@ -2132,136 +2091,8 @@ static bool wlc_attach_stf_ant_init(wlc_info_t *wlc)
2132 return true; 2091 return true;
2133} 2092}
2134 2093
2135#ifdef WLC_HIGH_ONLY
2136/* HIGH_ONLY bmac_attach, which sync over LOW_ONLY bmac_attach states */
2137int wlc_bmac_attach(wlc_info_t *wlc, u16 vendor, u16 device, uint unit,
2138 bool piomode, osl_t *osh, void *regsva, uint bustype,
2139 void *btparam)
2140{
2141 wlc_bmac_revinfo_t revinfo;
2142 uint idx = 0;
2143 rpc_info_t *rpc = (rpc_info_t *) btparam;
2144 2094
2145 ASSERT(bustype == RPC_BUS); 2095static void wlc_timers_deinit(struct wlc_info *wlc)
2146
2147 /* install the rpc handle in the various state structures used by stub RPC functions */
2148 wlc->rpc = rpc;
2149 wlc->hw->rpc = rpc;
2150 wlc->hw->osh = osh;
2151
2152 wlc->regs = 0;
2153
2154 wlc->rpctx = wlc_rpctx_attach(wlc->pub, wlc);
2155 if (wlc->rpctx == NULL)
2156 return -1;
2157
2158 /*
2159 * FIFO 0
2160 * TX: TX_AC_BK_FIFO (TX AC Background data packets)
2161 */
2162 /* Always initialized */
2163 ASSERT(NRPCTXBUFPOST <= NTXD);
2164 wlc_rpctx_fifoinit(wlc->rpctx, TX_DATA_FIFO, NRPCTXBUFPOST);
2165 wlc_rpctx_fifoinit(wlc->rpctx, TX_CTL_FIFO, NRPCTXBUFPOST);
2166 wlc_rpctx_fifoinit(wlc->rpctx, TX_BCMC_FIFO, NRPCTXBUFPOST);
2167
2168 /* VI and BK inited only if WME */
2169 if (WME_ENAB(wlc->pub)) {
2170 wlc_rpctx_fifoinit(wlc->rpctx, TX_AC_BK_FIFO, NRPCTXBUFPOST);
2171 wlc_rpctx_fifoinit(wlc->rpctx, TX_AC_VI_FIFO, NRPCTXBUFPOST);
2172 }
2173
2174 /* Allocate SB handle */
2175 wlc->pub->sih = osl_malloc(wlc->osh, sizeof(si_t));
2176 if (!wlc->pub->sih)
2177 return -1;
2178 bzero(wlc->pub->sih, sizeof(si_t));
2179
2180 /* sync up revinfo with BMAC */
2181 bzero(&revinfo, sizeof(wlc_bmac_revinfo_t));
2182 if (wlc_bmac_revinfo_get(wlc->hw, &revinfo) != 0)
2183 return -1;
2184 wlc->vendorid = (u16) revinfo.vendorid;
2185 wlc->deviceid = (u16) revinfo.deviceid;
2186
2187 wlc->pub->boardrev = (u16) revinfo.boardrev;
2188 wlc->pub->corerev = revinfo.corerev;
2189 wlc->pub->sromrev = (u8) revinfo.sromrev;
2190 wlc->pub->sih->chiprev = revinfo.chiprev;
2191 wlc->pub->sih->chip = revinfo.chip;
2192 wlc->pub->sih->chippkg = revinfo.chippkg;
2193 wlc->pub->sih->boardtype = revinfo.boardtype;
2194 wlc->pub->sih->boardvendor = revinfo.boardvendor;
2195 wlc->pub->sih->bustype = revinfo.bustype;
2196 wlc->pub->sih->buscoretype = revinfo.buscoretype;
2197 wlc->pub->sih->buscorerev = revinfo.buscorerev;
2198 wlc->pub->sih->issim = (bool) revinfo.issim;
2199 wlc->pub->sih->rpc = rpc;
2200
2201 if (revinfo.nbands == 0 || revinfo.nbands > 2)
2202 return -1;
2203 wlc->pub->_nbands = revinfo.nbands;
2204
2205 for (idx = 0; idx < wlc->pub->_nbands; idx++) {
2206 uint bandunit, bandtype; /* To access bandstate */
2207 wlc_phy_t *pi = osl_malloc(wlc->osh, sizeof(wlc_phy_t));
2208
2209 if (!pi)
2210 return -1;
2211 bzero(pi, sizeof(wlc_phy_t));
2212 pi->rpc = rpc;
2213
2214 bandunit = revinfo.band[idx].bandunit;
2215 bandtype = revinfo.band[idx].bandtype;
2216 wlc->bandstate[bandunit]->radiorev =
2217 (u8) revinfo.band[idx].radiorev;
2218 wlc->bandstate[bandunit]->phytype =
2219 (u16) revinfo.band[idx].phytype;
2220 wlc->bandstate[bandunit]->phyrev =
2221 (u16) revinfo.band[idx].phyrev;
2222 wlc->bandstate[bandunit]->radioid =
2223 (u16) revinfo.band[idx].radioid;
2224 wlc->bandstate[bandunit]->abgphy_encore =
2225 revinfo.band[idx].abgphy_encore;
2226
2227 wlc->bandstate[bandunit]->pi = pi;
2228 wlc->bandstate[bandunit]->bandunit = bandunit;
2229 wlc->bandstate[bandunit]->bandtype = bandtype;
2230 }
2231
2232 /* misc stuff */
2233
2234 return 0;
2235}
2236
2237/* Free the convenience handles */
2238int wlc_bmac_detach(wlc_info_t *wlc)
2239{
2240 uint idx;
2241
2242 if (wlc->pub->sih) {
2243 osl_mfree(wlc->osh, (void *)wlc->pub->sih, sizeof(si_t));
2244 wlc->pub->sih = NULL;
2245 }
2246
2247 for (idx = 0; idx < MAXBANDS; idx++)
2248 if (wlc->bandstate[idx]->pi) {
2249 kfree(wlc->bandstate[idx]->pi);
2250 wlc->bandstate[idx]->pi = NULL;
2251 }
2252
2253 if (wlc->rpctx) {
2254 wlc_rpctx_detach(wlc->rpctx);
2255 wlc->rpctx = NULL;
2256 }
2257
2258 return 0;
2259
2260}
2261
2262#endif /* WLC_HIGH_ONLY */
2263
2264static void wlc_timers_deinit(wlc_info_t *wlc)
2265{ 2096{
2266 /* free timer state */ 2097 /* free timer state */
2267 if (wlc->wdtimer) { 2098 if (wlc->wdtimer) {
@@ -2274,7 +2105,7 @@ static void wlc_timers_deinit(wlc_info_t *wlc)
2274 } 2105 }
2275} 2106}
2276 2107
2277static void wlc_detach_module(wlc_info_t *wlc) 2108static void wlc_detach_module(struct wlc_info *wlc)
2278{ 2109{
2279 if (wlc->asi) { 2110 if (wlc->asi) {
2280 wlc_antsel_detach(wlc->asi); 2111 wlc_antsel_detach(wlc->asi);
@@ -2297,7 +2128,7 @@ static void wlc_detach_module(wlc_info_t *wlc)
2297 * One exception is sb register access, which is possible if crystal is turned on 2128 * One exception is sb register access, which is possible if crystal is turned on
2298 * After "down" state, driver should avoid software timer with the exception of radio_monitor. 2129 * After "down" state, driver should avoid software timer with the exception of radio_monitor.
2299 */ 2130 */
2300uint wlc_detach(wlc_info_t *wlc) 2131uint wlc_detach(struct wlc_info *wlc)
2301{ 2132{
2302 uint i; 2133 uint i;
2303 uint callbacks = 0; 2134 uint callbacks = 0;
@@ -2305,7 +2136,7 @@ uint wlc_detach(wlc_info_t *wlc)
2305 if (wlc == NULL) 2136 if (wlc == NULL)
2306 return 0; 2137 return 0;
2307 2138
2308 WL_TRACE(("wl%d: %s\n", wlc->pub->unit, __func__)); 2139 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
2309 2140
2310 ASSERT(!wlc->pub->up); 2141 ASSERT(!wlc->pub->up);
2311 2142
@@ -2328,15 +2159,6 @@ uint wlc_detach(wlc_info_t *wlc)
2328 2159
2329 /* free other state */ 2160 /* free other state */
2330 2161
2331#ifdef WLC_HIGH_ONLY
2332 /* High-Only driver has an allocated copy of vars, monolithic just
2333 * references the wlc->hw->vars which is freed in wlc_bmac_detach()
2334 */
2335 if (wlc->pub->vars) {
2336 kfree(wlc->pub->vars);
2337 wlc->pub->vars = NULL;
2338 }
2339#endif
2340 2162
2341#ifdef BCMDBG 2163#ifdef BCMDBG
2342 if (wlc->country_ie_override) { 2164 if (wlc->country_ie_override) {
@@ -2360,13 +2182,6 @@ uint wlc_detach(wlc_info_t *wlc)
2360 /* Detach from iovar manager */ 2182 /* Detach from iovar manager */
2361 wlc_module_unregister(wlc->pub, "wlc_iovars", wlc); 2183 wlc_module_unregister(wlc->pub, "wlc_iovars", wlc);
2362 2184
2363 /*
2364 if (wlc->ap) {
2365 wlc_ap_detach(wlc->ap);
2366 wlc->ap = NULL;
2367 }
2368 */
2369
2370 while (wlc->tx_queues != NULL) { 2185 while (wlc->tx_queues != NULL) {
2371 wlc_txq_free(wlc, wlc->osh, wlc->tx_queues); 2186 wlc_txq_free(wlc, wlc->osh, wlc->tx_queues);
2372 } 2187 }
@@ -2383,7 +2198,7 @@ uint wlc_detach(wlc_info_t *wlc)
2383} 2198}
2384 2199
2385/* update state that depends on the current value of "ap" */ 2200/* update state that depends on the current value of "ap" */
2386void wlc_ap_upd(wlc_info_t *wlc) 2201void wlc_ap_upd(struct wlc_info *wlc)
2387{ 2202{
2388 if (AP_ENAB(wlc->pub)) 2203 if (AP_ENAB(wlc->pub))
2389 wlc->PLCPHdr_override = WLC_PLCP_AUTO; /* AP: short not allowed, but not enforced */ 2204 wlc->PLCPHdr_override = WLC_PLCP_AUTO; /* AP: short not allowed, but not enforced */
@@ -2398,7 +2213,7 @@ void wlc_ap_upd(wlc_info_t *wlc)
2398} 2213}
2399 2214
2400/* read hwdisable state and propagate to wlc flag */ 2215/* read hwdisable state and propagate to wlc flag */
2401static void wlc_radio_hwdisable_upd(wlc_info_t *wlc) 2216static void wlc_radio_hwdisable_upd(struct wlc_info *wlc)
2402{ 2217{
2403 if (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO || wlc->pub->hw_off) 2218 if (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO || wlc->pub->hw_off)
2404 return; 2219 return;
@@ -2411,17 +2226,17 @@ static void wlc_radio_hwdisable_upd(wlc_info_t *wlc)
2411} 2226}
2412 2227
2413/* return true if Minimum Power Consumption should be entered, false otherwise */ 2228/* return true if Minimum Power Consumption should be entered, false otherwise */
2414bool wlc_is_non_delay_mpc(wlc_info_t *wlc) 2229bool wlc_is_non_delay_mpc(struct wlc_info *wlc)
2415{ 2230{
2416 return false; 2231 return false;
2417} 2232}
2418 2233
2419bool wlc_ismpc(wlc_info_t *wlc) 2234bool wlc_ismpc(struct wlc_info *wlc)
2420{ 2235{
2421 return (wlc->mpc_delay_off == 0) && (wlc_is_non_delay_mpc(wlc)); 2236 return (wlc->mpc_delay_off == 0) && (wlc_is_non_delay_mpc(wlc));
2422} 2237}
2423 2238
2424void wlc_radio_mpc_upd(wlc_info_t *wlc) 2239void wlc_radio_mpc_upd(struct wlc_info *wlc)
2425{ 2240{
2426 bool mpc_radio, radio_state; 2241 bool mpc_radio, radio_state;
2427 2242
@@ -2477,7 +2292,7 @@ void wlc_radio_mpc_upd(wlc_info_t *wlc)
2477 * centralized radio disable/enable function, 2292 * centralized radio disable/enable function,
2478 * invoke radio enable/disable after updating hwradio status 2293 * invoke radio enable/disable after updating hwradio status
2479 */ 2294 */
2480static void wlc_radio_upd(wlc_info_t *wlc) 2295static void wlc_radio_upd(struct wlc_info *wlc)
2481{ 2296{
2482 if (wlc->pub->radio_disabled) 2297 if (wlc->pub->radio_disabled)
2483 wlc_radio_disable(wlc); 2298 wlc_radio_disable(wlc);
@@ -2486,7 +2301,7 @@ static void wlc_radio_upd(wlc_info_t *wlc)
2486} 2301}
2487 2302
2488/* maintain LED behavior in down state */ 2303/* maintain LED behavior in down state */
2489static void wlc_down_led_upd(wlc_info_t *wlc) 2304static void wlc_down_led_upd(struct wlc_info *wlc)
2490{ 2305{
2491 ASSERT(!wlc->pub->up); 2306 ASSERT(!wlc->pub->up);
2492 2307
@@ -2499,7 +2314,7 @@ static void wlc_down_led_upd(wlc_info_t *wlc)
2499 } 2314 }
2500} 2315}
2501 2316
2502void wlc_radio_disable(wlc_info_t *wlc) 2317void wlc_radio_disable(struct wlc_info *wlc)
2503{ 2318{
2504 if (!wlc->pub->up) { 2319 if (!wlc->pub->up) {
2505 wlc_down_led_upd(wlc); 2320 wlc_down_led_upd(wlc);
@@ -2510,7 +2325,7 @@ void wlc_radio_disable(wlc_info_t *wlc)
2510 wl_down(wlc->wl); 2325 wl_down(wlc->wl);
2511} 2326}
2512 2327
2513static void wlc_radio_enable(wlc_info_t *wlc) 2328static void wlc_radio_enable(struct wlc_info *wlc)
2514{ 2329{
2515 if (wlc->pub->up) 2330 if (wlc->pub->up)
2516 return; 2331 return;
@@ -2526,10 +2341,10 @@ static void wlc_radio_enable(wlc_info_t *wlc)
2526/* periodical query hw radio button while driver is "down" */ 2341/* periodical query hw radio button while driver is "down" */
2527static void wlc_radio_timer(void *arg) 2342static void wlc_radio_timer(void *arg)
2528{ 2343{
2529 wlc_info_t *wlc = (wlc_info_t *) arg; 2344 struct wlc_info *wlc = (struct wlc_info *) arg;
2530 2345
2531 if (DEVICEREMOVED(wlc)) { 2346 if (DEVICEREMOVED(wlc)) {
2532 WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, __func__)); 2347 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
2533 wl_down(wlc->wl); 2348 wl_down(wlc->wl);
2534 return; 2349 return;
2535 } 2350 }
@@ -2544,7 +2359,7 @@ static void wlc_radio_timer(void *arg)
2544 wlc_radio_upd(wlc); 2359 wlc_radio_upd(wlc);
2545} 2360}
2546 2361
2547static bool wlc_radio_monitor_start(wlc_info_t *wlc) 2362static bool wlc_radio_monitor_start(struct wlc_info *wlc)
2548{ 2363{
2549 /* Don't start the timer if HWRADIO feature is disabled */ 2364 /* Don't start the timer if HWRADIO feature is disabled */
2550 if (wlc->radio_monitor || (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO)) 2365 if (wlc->radio_monitor || (wlc->pub->wlfeatureflag & WL_SWFL_NOHWRADIO))
@@ -2556,7 +2371,7 @@ static bool wlc_radio_monitor_start(wlc_info_t *wlc)
2556 return true; 2371 return true;
2557} 2372}
2558 2373
2559bool wlc_radio_monitor_stop(wlc_info_t *wlc) 2374bool wlc_radio_monitor_stop(struct wlc_info *wlc)
2560{ 2375{
2561 if (!wlc->radio_monitor) 2376 if (!wlc->radio_monitor)
2562 return true; 2377 return true;
@@ -2570,7 +2385,7 @@ bool wlc_radio_monitor_stop(wlc_info_t *wlc)
2570} 2385}
2571 2386
2572/* bring the driver down, but don't reset hardware */ 2387/* bring the driver down, but don't reset hardware */
2573void wlc_out(wlc_info_t *wlc) 2388void wlc_out(struct wlc_info *wlc)
2574{ 2389{
2575 wlc_bmac_set_noreset(wlc->hw, true); 2390 wlc_bmac_set_noreset(wlc->hw, true);
2576 wlc_radio_upd(wlc); 2391 wlc_radio_upd(wlc);
@@ -2591,7 +2406,7 @@ void wlc_out(wlc_info_t *wlc)
2591 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set 2406 * if there is no packet pending for the FIFO, then the corresponding prec bits should be set
2592 * in prec_map. Of course, ignore this rule when block_datafifo is set 2407 * in prec_map. Of course, ignore this rule when block_datafifo is set
2593 */ 2408 */
2594static bool wlc_tx_prec_map_verify(wlc_info_t *wlc) 2409static bool wlc_tx_prec_map_verify(struct wlc_info *wlc)
2595{ 2410{
2596 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both 2411 /* For non-WME, both fifos have overlapping prec_map. So it's an error only if both
2597 * fail the check. 2412 * fail the check.
@@ -2613,7 +2428,7 @@ static bool wlc_tx_prec_map_verify(wlc_info_t *wlc)
2613 2428
2614static void wlc_watchdog_by_timer(void *arg) 2429static void wlc_watchdog_by_timer(void *arg)
2615{ 2430{
2616 wlc_info_t *wlc = (wlc_info_t *) arg; 2431 struct wlc_info *wlc = (struct wlc_info *) arg;
2617 wlc_watchdog(arg); 2432 wlc_watchdog(arg);
2618 if (WLC_WATCHDOG_TBTT(wlc)) { 2433 if (WLC_WATCHDOG_TBTT(wlc)) {
2619 /* set to normal osl watchdog period */ 2434 /* set to normal osl watchdog period */
@@ -2626,17 +2441,17 @@ static void wlc_watchdog_by_timer(void *arg)
2626/* common watchdog code */ 2441/* common watchdog code */
2627static void wlc_watchdog(void *arg) 2442static void wlc_watchdog(void *arg)
2628{ 2443{
2629 wlc_info_t *wlc = (wlc_info_t *) arg; 2444 struct wlc_info *wlc = (struct wlc_info *) arg;
2630 int i; 2445 int i;
2631 wlc_bsscfg_t *cfg; 2446 wlc_bsscfg_t *cfg;
2632 2447
2633 WL_TRACE(("wl%d: wlc_watchdog\n", wlc->pub->unit)); 2448 WL_TRACE("wl%d: wlc_watchdog\n", wlc->pub->unit);
2634 2449
2635 if (!wlc->pub->up) 2450 if (!wlc->pub->up)
2636 return; 2451 return;
2637 2452
2638 if (DEVICEREMOVED(wlc)) { 2453 if (DEVICEREMOVED(wlc)) {
2639 WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, __func__)); 2454 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
2640 wl_down(wlc->wl); 2455 wl_down(wlc->wl);
2641 return; 2456 return;
2642 } 2457 }
@@ -2667,13 +2482,7 @@ static void wlc_watchdog(void *arg)
2667 if (wlc->pub->radio_disabled) 2482 if (wlc->pub->radio_disabled)
2668 return; 2483 return;
2669 2484
2670#ifdef WLC_LOW
2671 wlc_bmac_watchdog(wlc); 2485 wlc_bmac_watchdog(wlc);
2672#endif
2673#ifdef WLC_HIGH_ONLY
2674 /* maintenance */
2675 wlc_bmac_rpc_watchdog(wlc);
2676#endif
2677 2486
2678 /* occasionally sample mac stat counters to detect 16-bit counter wrap */ 2487 /* occasionally sample mac stat counters to detect 16-bit counter wrap */
2679 if ((WLC_UPDATE_STATS(wlc)) 2488 if ((WLC_UPDATE_STATS(wlc))
@@ -2702,10 +2511,8 @@ static void wlc_watchdog(void *arg)
2702 wlc->tempsense_lasttime = wlc->pub->now; 2511 wlc->tempsense_lasttime = wlc->pub->now;
2703 wlc_tempsense_upd(wlc); 2512 wlc_tempsense_upd(wlc);
2704 } 2513 }
2705#ifdef WLC_LOW
2706 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */ 2514 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
2707 ASSERT(wlc_bmac_taclear(wlc->hw, true)); 2515 ASSERT(wlc_bmac_taclear(wlc->hw, true));
2708#endif
2709 2516
2710 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */ 2517 /* Verify that tx_prec_map and fifos are in sync to avoid lock ups */
2711 ASSERT(wlc_tx_prec_map_verify(wlc)); 2518 ASSERT(wlc_tx_prec_map_verify(wlc));
@@ -2714,9 +2521,9 @@ static void wlc_watchdog(void *arg)
2714} 2521}
2715 2522
2716/* make interface operational */ 2523/* make interface operational */
2717int wlc_up(wlc_info_t *wlc) 2524int wlc_up(struct wlc_info *wlc)
2718{ 2525{
2719 WL_TRACE(("wl%d: %s:\n", wlc->pub->unit, __func__)); 2526 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2720 2527
2721 /* HW is turned off so don't try to access it */ 2528 /* HW is turned off so don't try to access it */
2722 if (wlc->pub->hw_off || DEVICEREMOVED(wlc)) 2529 if (wlc->pub->hw_off || DEVICEREMOVED(wlc))
@@ -2728,7 +2535,7 @@ int wlc_up(wlc_info_t *wlc)
2728 } 2535 }
2729 2536
2730 if ((wlc->pub->boardflags & BFL_FEM) 2537 if ((wlc->pub->boardflags & BFL_FEM)
2731 && (CHIPID(wlc->pub->sih->chip) == BCM4313_CHIP_ID)) { 2538 && (wlc->pub->sih->chip == BCM4313_CHIP_ID)) {
2732 if (wlc->pub->boardrev >= 0x1250 2539 if (wlc->pub->boardrev >= 0x1250
2733 && (wlc->pub->boardflags & BFL_FEM_BT)) { 2540 && (wlc->pub->boardflags & BFL_FEM_BT)) {
2734 wlc_mhf(wlc, MHF5, MHF5_4313_GPIOCTRL, 2541 wlc_mhf(wlc, MHF5, MHF5_4313_GPIOCTRL,
@@ -2761,7 +2568,8 @@ int wlc_up(wlc_info_t *wlc)
2761 if (!BSSCFG_STA(bsscfg) 2568 if (!BSSCFG_STA(bsscfg)
2762 || !bsscfg->enable || !bsscfg->BSS) 2569 || !bsscfg->enable || !bsscfg->BSS)
2763 continue; 2570 continue;
2764 WL_ERROR(("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n", wlc->pub->unit, idx)); 2571 WL_ERROR("wl%d.%d: wlc_up: rfdisable -> " "wlc_bsscfg_disable()\n",
2572 wlc->pub->unit, idx);
2765 } 2573 }
2766 } 2574 }
2767 } else 2575 } else
@@ -2822,10 +2630,10 @@ int wlc_up(wlc_info_t *wlc)
2822} 2630}
2823 2631
2824/* Initialize the base precedence map for dequeueing from txq based on WME settings */ 2632/* Initialize the base precedence map for dequeueing from txq based on WME settings */
2825static void wlc_tx_prec_map_init(wlc_info_t *wlc) 2633static void wlc_tx_prec_map_init(struct wlc_info *wlc)
2826{ 2634{
2827 wlc->tx_prec_map = WLC_PREC_BMP_ALL; 2635 wlc->tx_prec_map = WLC_PREC_BMP_ALL;
2828 bzero(wlc->fifo2prec_map, sizeof(u16) * NFIFO); 2636 memset(wlc->fifo2prec_map, 0, NFIFO * sizeof(u16));
2829 2637
2830 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences 2638 /* For non-WME, both fifos have overlapping MAXPRIO. So just disable all precedences
2831 * if either is full. 2639 * if either is full.
@@ -2841,7 +2649,7 @@ static void wlc_tx_prec_map_init(wlc_info_t *wlc)
2841 } 2649 }
2842} 2650}
2843 2651
2844static uint wlc_down_del_timer(wlc_info_t *wlc) 2652static uint wlc_down_del_timer(struct wlc_info *wlc)
2845{ 2653{
2846 uint callbacks = 0; 2654 uint callbacks = 0;
2847 2655
@@ -2853,7 +2661,7 @@ static uint wlc_down_del_timer(wlc_info_t *wlc)
2853 * disable the hardware, free any transient buffer state. 2661 * disable the hardware, free any transient buffer state.
2854 * Return a count of the number of driver callbacks still pending. 2662 * Return a count of the number of driver callbacks still pending.
2855 */ 2663 */
2856uint wlc_down(wlc_info_t *wlc) 2664uint wlc_down(struct wlc_info *wlc)
2857{ 2665{
2858 2666
2859 uint callbacks = 0; 2667 uint callbacks = 0;
@@ -2861,12 +2669,12 @@ uint wlc_down(wlc_info_t *wlc)
2861 bool dev_gone = false; 2669 bool dev_gone = false;
2862 wlc_txq_info_t *qi; 2670 wlc_txq_info_t *qi;
2863 2671
2864 WL_TRACE(("wl%d: %s:\n", wlc->pub->unit, __func__)); 2672 WL_TRACE("wl%d: %s:\n", wlc->pub->unit, __func__);
2865 2673
2866 /* check if we are already in the going down path */ 2674 /* check if we are already in the going down path */
2867 if (wlc->going_down) { 2675 if (wlc->going_down) {
2868 WL_ERROR(("wl%d: %s: Driver going down so return\n", 2676 WL_ERROR("wl%d: %s: Driver going down so return\n",
2869 wlc->pub->unit, __func__)); 2677 wlc->pub->unit, __func__);
2870 return 0; 2678 return 0;
2871 } 2679 }
2872 if (!wlc->pub->up) 2680 if (!wlc->pub->up)
@@ -2922,14 +2730,11 @@ uint wlc_down(wlc_info_t *wlc)
2922 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */ 2730 /* wlc_bmac_down_finish has done wlc_coredisable(). so clk is off */
2923 wlc->clk = false; 2731 wlc->clk = false;
2924 2732
2925#ifdef WLC_HIGH_ONLY
2926 wlc_rpctx_txreclaim(wlc->rpctx);
2927#endif
2928 2733
2929 /* Verify all packets are flushed from the driver */ 2734 /* Verify all packets are flushed from the driver */
2930 if (PKTALLOCED(wlc->osh) != 0) { 2735 if (wlc->osh->pktalloced != 0) {
2931 WL_ERROR(("%d packets not freed at wlc_down!!!!!!\n", 2736 WL_ERROR("%d packets not freed at wlc_down!!!!!!\n",
2932 PKTALLOCED(wlc->osh))); 2737 wlc->osh->pktalloced);
2933 } 2738 }
2934#ifdef BCMDBG 2739#ifdef BCMDBG
2935 /* Since all the packets should have been freed, 2740 /* Since all the packets should have been freed,
@@ -2943,7 +2748,7 @@ uint wlc_down(wlc_info_t *wlc)
2943} 2748}
2944 2749
2945/* Set the current gmode configuration */ 2750/* Set the current gmode configuration */
2946int wlc_set_gmode(wlc_info_t *wlc, u8 gmode, bool config) 2751int wlc_set_gmode(struct wlc_info *wlc, u8 gmode, bool config)
2947{ 2752{
2948 int ret = 0; 2753 int ret = 0;
2949 uint i; 2754 uint i;
@@ -2958,7 +2763,7 @@ int wlc_set_gmode(wlc_info_t *wlc, u8 gmode, bool config)
2958 bool preamble_restrict = false; /* Restrict association to stations that support short 2763 bool preamble_restrict = false; /* Restrict association to stations that support short
2959 * preambles 2764 * preambles
2960 */ 2765 */
2961 wlcband_t *band; 2766 struct wlcband *band;
2962 2767
2963 /* if N-support is enabled, allow Gmode set as long as requested 2768 /* if N-support is enabled, allow Gmode set as long as requested
2964 * Gmode is not GMODE_LEGACY_B 2769 * Gmode is not GMODE_LEGACY_B
@@ -2985,10 +2790,10 @@ int wlc_set_gmode(wlc_info_t *wlc, u8 gmode, bool config)
2985 wlc_protection_upd(wlc, WLC_PROT_G_USER, gmode); 2790 wlc_protection_upd(wlc, WLC_PROT_G_USER, gmode);
2986 2791
2987 /* Clear supported rates filter */ 2792 /* Clear supported rates filter */
2988 bzero(&wlc->sup_rates_override, sizeof(wlc_rateset_t)); 2793 memset(&wlc->sup_rates_override, 0, sizeof(wlc_rateset_t));
2989 2794
2990 /* Clear rateset override */ 2795 /* Clear rateset override */
2991 bzero(&rs, sizeof(wlc_rateset_t)); 2796 memset(&rs, 0, sizeof(wlc_rateset_t));
2992 2797
2993 switch (gmode) { 2798 switch (gmode) {
2994 case GMODE_LEGACY_B: 2799 case GMODE_LEGACY_B:
@@ -3026,8 +2831,8 @@ int wlc_set_gmode(wlc_info_t *wlc, u8 gmode, bool config)
3026 2831
3027 default: 2832 default:
3028 /* Error */ 2833 /* Error */
3029 WL_ERROR(("wl%d: %s: invalid gmode %d\n", wlc->pub->unit, 2834 WL_ERROR("wl%d: %s: invalid gmode %d\n",
3030 __func__, gmode)); 2835 wlc->pub->unit, __func__, gmode);
3031 return BCME_UNSUPPORTED; 2836 return BCME_UNSUPPORTED;
3032 } 2837 }
3033 2838
@@ -3093,7 +2898,7 @@ int wlc_set_gmode(wlc_info_t *wlc, u8 gmode, bool config)
3093 return ret; 2898 return ret;
3094} 2899}
3095 2900
3096static int wlc_nmode_validate(wlc_info_t *wlc, s32 nmode) 2901static int wlc_nmode_validate(struct wlc_info *wlc, s32 nmode)
3097{ 2902{
3098 int err = 0; 2903 int err = 0;
3099 2904
@@ -3117,7 +2922,7 @@ static int wlc_nmode_validate(wlc_info_t *wlc, s32 nmode)
3117 return err; 2922 return err;
3118} 2923}
3119 2924
3120int wlc_set_nmode(wlc_info_t *wlc, s32 nmode) 2925int wlc_set_nmode(struct wlc_info *wlc, s32 nmode)
3121{ 2926{
3122 uint i; 2927 uint i;
3123 int err; 2928 int err;
@@ -3176,7 +2981,7 @@ int wlc_set_nmode(wlc_info_t *wlc, s32 nmode)
3176 return err; 2981 return err;
3177} 2982}
3178 2983
3179static int wlc_set_rateset(wlc_info_t *wlc, wlc_rateset_t *rs_arg) 2984static int wlc_set_rateset(struct wlc_info *wlc, wlc_rateset_t *rs_arg)
3180{ 2985{
3181 wlc_rateset_t rs, new; 2986 wlc_rateset_t rs, new;
3182 uint bandunit; 2987 uint bandunit;
@@ -3219,18 +3024,18 @@ static int wlc_set_rateset(wlc_info_t *wlc, wlc_rateset_t *rs_arg)
3219} 3024}
3220 3025
3221/* simplified integer set interface for common ioctl handler */ 3026/* simplified integer set interface for common ioctl handler */
3222int wlc_set(wlc_info_t *wlc, int cmd, int arg) 3027int wlc_set(struct wlc_info *wlc, int cmd, int arg)
3223{ 3028{
3224 return wlc_ioctl(wlc, cmd, (void *)&arg, sizeof(arg), NULL); 3029 return wlc_ioctl(wlc, cmd, (void *)&arg, sizeof(arg), NULL);
3225} 3030}
3226 3031
3227/* simplified integer get interface for common ioctl handler */ 3032/* simplified integer get interface for common ioctl handler */
3228int wlc_get(wlc_info_t *wlc, int cmd, int *arg) 3033int wlc_get(struct wlc_info *wlc, int cmd, int *arg)
3229{ 3034{
3230 return wlc_ioctl(wlc, cmd, arg, sizeof(int), NULL); 3035 return wlc_ioctl(wlc, cmd, arg, sizeof(int), NULL);
3231} 3036}
3232 3037
3233static void wlc_ofdm_rateset_war(wlc_info_t *wlc) 3038static void wlc_ofdm_rateset_war(struct wlc_info *wlc)
3234{ 3039{
3235 u8 r; 3040 u8 r;
3236 bool war = false; 3041 bool war = false;
@@ -3246,14 +3051,16 @@ static void wlc_ofdm_rateset_war(wlc_info_t *wlc)
3246} 3051}
3247 3052
3248int 3053int
3249wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif) 3054wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
3055 struct wlc_if *wlcif)
3250{ 3056{
3251 return _wlc_ioctl(wlc, cmd, arg, len, wlcif); 3057 return _wlc_ioctl(wlc, cmd, arg, len, wlcif);
3252} 3058}
3253 3059
3254/* common ioctl handler. return: 0=ok, -1=error, positive=particular error */ 3060/* common ioctl handler. return: 0=ok, -1=error, positive=particular error */
3255static int 3061static int
3256_wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif) 3062_wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
3063 struct wlc_if *wlcif)
3257{ 3064{
3258 int val, *pval; 3065 int val, *pval;
3259 bool bool_val; 3066 bool bool_val;
@@ -3265,7 +3072,7 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3265 uint band; 3072 uint band;
3266 rw_reg_t *r; 3073 rw_reg_t *r;
3267 wlc_bsscfg_t *bsscfg; 3074 wlc_bsscfg_t *bsscfg;
3268 osl_t *osh; 3075 struct osl_info *osh;
3269 wlc_bss_info_t *current_bss; 3076 wlc_bss_info_t *current_bss;
3270 3077
3271 /* update bsscfg pointer */ 3078 /* update bsscfg pointer */
@@ -3280,7 +3087,7 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3280 3087
3281 /* If the device is turned off, then it's not "removed" */ 3088 /* If the device is turned off, then it's not "removed" */
3282 if (!wlc->pub->hw_off && DEVICEREMOVED(wlc)) { 3089 if (!wlc->pub->hw_off && DEVICEREMOVED(wlc)) {
3283 WL_ERROR(("wl%d: %s: dead chip\n", wlc->pub->unit, __func__)); 3090 WL_ERROR("wl%d: %s: dead chip\n", wlc->pub->unit, __func__);
3284 wl_down(wlc->wl); 3091 wl_down(wlc->wl);
3285 return BCME_ERROR; 3092 return BCME_ERROR;
3286 } 3093 }
@@ -3300,8 +3107,8 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3300 bool_val = val != 0; 3107 bool_val = val != 0;
3301 3108
3302 if (cmd != WLC_SET_CHANNEL) 3109 if (cmd != WLC_SET_CHANNEL)
3303 WL_NONE(("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n", cmd, 3110 WL_NONE("WLC_IOCTL: cmd %d val 0x%x (%d) len %d\n",
3304 (uint) val, val, len)); 3111 cmd, (uint)val, val, len);
3305 3112
3306 bcmerror = 0; 3113 bcmerror = 0;
3307 regs = wlc->regs; 3114 regs = wlc->regs;
@@ -3321,8 +3128,8 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3321 3128
3322 default: 3129 default:
3323 if ((arg == NULL) || (len <= 0)) { 3130 if ((arg == NULL) || (len <= 0)) {
3324 WL_ERROR(("wl%d: %s: Command %d needs arguments\n", 3131 WL_ERROR("wl%d: %s: Command %d needs arguments\n",
3325 wlc->pub->unit, __func__, cmd)); 3132 wlc->pub->unit, __func__, cmd);
3326 bcmerror = BCME_BADARG; 3133 bcmerror = BCME_BADARG;
3327 goto done; 3134 goto done;
3328 } 3135 }
@@ -3388,10 +3195,6 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3388 wlc_set_chanspec(wlc, chspec); 3195 wlc_set_chanspec(wlc, chspec);
3389 wlc_enable_mac(wlc); 3196 wlc_enable_mac(wlc);
3390 } 3197 }
3391#ifdef WLC_HIGH_ONLY
3392 /* delay for channel change */
3393 msleep(50);
3394#endif
3395 break; 3198 break;
3396 } 3199 }
3397 3200
@@ -3659,8 +3462,8 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3659 /* 4322 supports antdiv in phy, no need to set it to ucode */ 3462 /* 4322 supports antdiv in phy, no need to set it to ucode */
3660 if (WLCISNPHY(wlc->band) 3463 if (WLCISNPHY(wlc->band)
3661 && D11REV_IS(wlc->pub->corerev, 16)) { 3464 && D11REV_IS(wlc->pub->corerev, 16)) {
3662 WL_ERROR(("wl%d: can't set ucantdiv for 4322\n", 3465 WL_ERROR("wl%d: can't set ucantdiv for 4322\n",
3663 wlc->pub->unit)); 3466 wlc->pub->unit);
3664 bcmerror = BCME_UNSUPPORTED; 3467 bcmerror = BCME_UNSUPPORTED;
3665 } else 3468 } else
3666 wlc_mhf(wlc, MHF1, MHF1_ANTDIV, 3469 wlc_mhf(wlc, MHF1, MHF1_ANTDIV,
@@ -3757,8 +3560,8 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3757 if ((radiomask == 0) || (radiomask & ~validbits) 3560 if ((radiomask == 0) || (radiomask & ~validbits)
3758 || (radioval & ~validbits) 3561 || (radioval & ~validbits)
3759 || ((radioval & ~radiomask) != 0)) { 3562 || ((radioval & ~radiomask) != 0)) {
3760 WL_ERROR(("SET_RADIO with wrong bits 0x%x\n", 3563 WL_ERROR("SET_RADIO with wrong bits 0x%x\n",
3761 val)); 3564 val);
3762 bcmerror = BCME_RANGE; 3565 bcmerror = BCME_RANGE;
3763 break; 3566 break;
3764 } 3567 }
@@ -3788,7 +3591,7 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3788 break; 3591 break;
3789 } 3592 }
3790 3593
3791 bzero((char *)&key, sizeof(key)); 3594 memset((char *)&key, 0, sizeof(key));
3792 if (src_key) { 3595 if (src_key) {
3793 key.index = src_key->id; 3596 key.index = src_key->id;
3794 key.len = src_key->len; 3597 key.len = src_key->len;
@@ -3800,7 +3603,7 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3800 key.flags |= WL_PRIMARY_KEY; 3603 key.flags |= WL_PRIMARY_KEY;
3801 3604
3802 bcopy(src_key->ea.octet, key.ea.octet, 3605 bcopy(src_key->ea.octet, key.ea.octet,
3803 ETHER_ADDR_LEN); 3606 ETH_ALEN);
3804 } 3607 }
3805 3608
3806 bcopy((char *)&key, arg, sizeof(key)); 3609 bcopy((char *)&key, arg, sizeof(key));
@@ -3835,8 +3638,8 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3835 u16 lo; 3638 u16 lo;
3836 u32 hi; 3639 u32 hi;
3837 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */ 3640 /* group keys in WPA-NONE (IBSS only, AES and TKIP) use a global TXIV */
3838 if ((bsscfg->WPA_auth & WPA_AUTH_NONE) 3641 if ((bsscfg->WPA_auth & WPA_AUTH_NONE) &&
3839 && ETHER_ISNULLADDR(&key->ea)) { 3642 is_zero_ether_addr(key->ea.octet)) {
3840 lo = bsscfg->wpa_none_txiv.lo; 3643 lo = bsscfg->wpa_none_txiv.lo;
3841 hi = bsscfg->wpa_none_txiv.hi; 3644 hi = bsscfg->wpa_none_txiv.hi;
3842 } else { 3645 } else {
@@ -3885,7 +3688,7 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3885 wlc_rateset_t rs; 3688 wlc_rateset_t rs;
3886 wl_rateset_t *ret_rs = (wl_rateset_t *) arg; 3689 wl_rateset_t *ret_rs = (wl_rateset_t *) arg;
3887 3690
3888 bzero(&rs, sizeof(wlc_rateset_t)); 3691 memset(&rs, 0, sizeof(wlc_rateset_t));
3889 wlc_default_rateset(wlc, (wlc_rateset_t *) &rs); 3692 wlc_default_rateset(wlc, (wlc_rateset_t *) &rs);
3890 3693
3891 if (len < (int)(rs.count + sizeof(rs.count))) { 3694 if (len < (int)(rs.count + sizeof(rs.count))) {
@@ -3913,7 +3716,7 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
3913 break; 3716 break;
3914 } 3717 }
3915 3718
3916 bzero(&rs, sizeof(wlc_rateset_t)); 3719 memset(&rs, 0, sizeof(wlc_rateset_t));
3917 3720
3918 /* Copy only legacy rateset section */ 3721 /* Copy only legacy rateset section */
3919 rs.count = in_rs->count; 3722 rs.count = in_rs->count;
@@ -4247,7 +4050,7 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
4247 4050
4248 /* check for an empty rateset to clear the override */ 4051 /* check for an empty rateset to clear the override */
4249 if (rs.count == 0) { 4052 if (rs.count == 0) {
4250 bzero(&wlc->sup_rates_override, 4053 memset(&wlc->sup_rates_override, 0,
4251 sizeof(wlc_rateset_t)); 4054 sizeof(wlc_rateset_t));
4252 break; 4055 break;
4253 } 4056 }
@@ -4394,7 +4197,7 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
4394#endif 4197#endif
4395 4198
4396 case WLC_LAST: 4199 case WLC_LAST:
4397 WL_ERROR(("%s: WLC_LAST\n", __func__)); 4200 WL_ERROR("%s: WLC_LAST\n", __func__);
4398 } 4201 }
4399 done: 4202 done:
4400 4203
@@ -4406,21 +4209,19 @@ _wlc_ioctl(wlc_info_t *wlc, int cmd, void *arg, int len, struct wlc_if *wlcif)
4406 } 4209 }
4407 4210
4408 } 4211 }
4409#ifdef WLC_LOW
4410 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */ 4212 /* BMAC_NOTE: for HIGH_ONLY driver, this seems being called after RPC bus failed */
4411 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would 4213 /* In hw_off condition, IOCTLs that reach here are deemed safe but taclear would
4412 * certainly result in getting -1 for register reads. So skip ta_clear altogether 4214 * certainly result in getting -1 for register reads. So skip ta_clear altogether
4413 */ 4215 */
4414 if (!(wlc->pub->hw_off)) 4216 if (!(wlc->pub->hw_off))
4415 ASSERT(wlc_bmac_taclear(wlc->hw, ta_ok) || !ta_ok); 4217 ASSERT(wlc_bmac_taclear(wlc->hw, ta_ok) || !ta_ok);
4416#endif
4417 4218
4418 return bcmerror; 4219 return bcmerror;
4419} 4220}
4420 4221
4421#if defined(BCMDBG) 4222#if defined(BCMDBG)
4422/* consolidated register access ioctl error checking */ 4223/* consolidated register access ioctl error checking */
4423int wlc_iocregchk(wlc_info_t *wlc, uint band) 4224int wlc_iocregchk(struct wlc_info *wlc, uint band)
4424{ 4225{
4425 /* if band is specified, it must be the current band */ 4226 /* if band is specified, it must be the current band */
4426 if ((band != WLC_BAND_AUTO) && (band != (uint) wlc->band->bandtype)) 4227 if ((band != WLC_BAND_AUTO) && (band != (uint) wlc->band->bandtype))
@@ -4440,7 +4241,7 @@ int wlc_iocregchk(wlc_info_t *wlc, uint band)
4440 4241
4441#if defined(BCMDBG) 4242#if defined(BCMDBG)
4442/* For some ioctls, make sure that the pi pointer matches the current phy */ 4243/* For some ioctls, make sure that the pi pointer matches the current phy */
4443int wlc_iocpichk(wlc_info_t *wlc, uint phytype) 4244int wlc_iocpichk(struct wlc_info *wlc, uint phytype)
4444{ 4245{
4445 if (wlc->band->phytype != phytype) 4246 if (wlc->band->phytype != phytype)
4446 return BCME_BADBAND; 4247 return BCME_BADBAND;
@@ -4474,21 +4275,21 @@ static const bcm_iovar_t *wlc_iovar_lookup(const bcm_iovar_t *table,
4474} 4275}
4475 4276
4476/* simplified integer get interface for common WLC_GET_VAR ioctl handler */ 4277/* simplified integer get interface for common WLC_GET_VAR ioctl handler */
4477int wlc_iovar_getint(wlc_info_t *wlc, const char *name, int *arg) 4278int wlc_iovar_getint(struct wlc_info *wlc, const char *name, int *arg)
4478{ 4279{
4479 return wlc_iovar_op(wlc, name, NULL, 0, arg, sizeof(s32), IOV_GET, 4280 return wlc_iovar_op(wlc, name, NULL, 0, arg, sizeof(s32), IOV_GET,
4480 NULL); 4281 NULL);
4481} 4282}
4482 4283
4483/* simplified integer set interface for common WLC_SET_VAR ioctl handler */ 4284/* simplified integer set interface for common WLC_SET_VAR ioctl handler */
4484int wlc_iovar_setint(wlc_info_t *wlc, const char *name, int arg) 4285int wlc_iovar_setint(struct wlc_info *wlc, const char *name, int arg)
4485{ 4286{
4486 return wlc_iovar_op(wlc, name, NULL, 0, (void *)&arg, sizeof(arg), 4287 return wlc_iovar_op(wlc, name, NULL, 0, (void *)&arg, sizeof(arg),
4487 IOV_SET, NULL); 4288 IOV_SET, NULL);
4488} 4289}
4489 4290
4490/* simplified s8 get interface for common WLC_GET_VAR ioctl handler */ 4291/* simplified s8 get interface for common WLC_GET_VAR ioctl handler */
4491int wlc_iovar_gets8(wlc_info_t *wlc, const char *name, s8 *arg) 4292int wlc_iovar_gets8(struct wlc_info *wlc, const char *name, s8 *arg)
4492{ 4293{
4493 int iovar_int; 4294 int iovar_int;
4494 int err; 4295 int err;
@@ -4507,11 +4308,11 @@ int wlc_iovar_gets8(wlc_info_t *wlc, const char *name, s8 *arg)
4507 * calling function must keep 'iovars' until wlc_module_unregister is called. 4308 * calling function must keep 'iovars' until wlc_module_unregister is called.
4508 * 'iovar' must have the last entry's name field being NULL as terminator. 4309 * 'iovar' must have the last entry's name field being NULL as terminator.
4509 */ 4310 */
4510int wlc_module_register(wlc_pub_t *pub, const bcm_iovar_t *iovars, 4311int wlc_module_register(struct wlc_pub *pub, const bcm_iovar_t *iovars,
4511 const char *name, void *hdl, iovar_fn_t i_fn, 4312 const char *name, void *hdl, iovar_fn_t i_fn,
4512 watchdog_fn_t w_fn, down_fn_t d_fn) 4313 watchdog_fn_t w_fn, down_fn_t d_fn)
4513{ 4314{
4514 wlc_info_t *wlc = (wlc_info_t *) pub->wlc; 4315 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4515 int i; 4316 int i;
4516 4317
4517 ASSERT(name != NULL); 4318 ASSERT(name != NULL);
@@ -4537,9 +4338,9 @@ int wlc_module_register(wlc_pub_t *pub, const bcm_iovar_t *iovars,
4537} 4338}
4538 4339
4539/* unregister module callbacks */ 4340/* unregister module callbacks */
4540int wlc_module_unregister(wlc_pub_t *pub, const char *name, void *hdl) 4341int wlc_module_unregister(struct wlc_pub *pub, const char *name, void *hdl)
4541{ 4342{
4542 wlc_info_t *wlc = (wlc_info_t *) pub->wlc; 4343 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4543 int i; 4344 int i;
4544 4345
4545 if (wlc == NULL) 4346 if (wlc == NULL)
@@ -4550,7 +4351,7 @@ int wlc_module_unregister(wlc_pub_t *pub, const char *name, void *hdl)
4550 for (i = 0; i < WLC_MAXMODULES; i++) { 4351 for (i = 0; i < WLC_MAXMODULES; i++) {
4551 if (!strcmp(wlc->modulecb[i].name, name) && 4352 if (!strcmp(wlc->modulecb[i].name, name) &&
4552 (wlc->modulecb[i].hdl == hdl)) { 4353 (wlc->modulecb[i].hdl == hdl)) {
4553 bzero(&wlc->modulecb[i], sizeof(modulecb_t)); 4354 memset(&wlc->modulecb[i], 0, sizeof(modulecb_t));
4554 return 0; 4355 return 0;
4555 } 4356 }
4556 } 4357 }
@@ -4560,7 +4361,7 @@ int wlc_module_unregister(wlc_pub_t *pub, const char *name, void *hdl)
4560} 4361}
4561 4362
4562/* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */ 4363/* Write WME tunable parameters for retransmit/max rate from wlc struct to ucode */
4563static void wlc_wme_retries_write(wlc_info_t *wlc) 4364static void wlc_wme_retries_write(struct wlc_info *wlc)
4564{ 4365{
4565 int ac; 4366 int ac;
4566 4367
@@ -4582,7 +4383,7 @@ static void wlc_wme_retries_write(wlc_info_t *wlc)
4582 * All pointers may point into the same buffer. 4383 * All pointers may point into the same buffer.
4583 */ 4384 */
4584int 4385int
4585wlc_iovar_op(wlc_info_t *wlc, const char *name, 4386wlc_iovar_op(struct wlc_info *wlc, const char *name,
4586 void *params, int p_len, void *arg, int len, 4387 void *params, int p_len, void *arg, int len,
4587 bool set, struct wlc_if *wlcif) 4388 bool set, struct wlc_if *wlcif)
4588{ 4389{
@@ -4606,8 +4407,8 @@ wlc_iovar_op(wlc_info_t *wlc, const char *name,
4606 4407
4607 if (!set && (len == sizeof(int)) && 4408 if (!set && (len == sizeof(int)) &&
4608 !(IS_ALIGNED((unsigned long)(arg), (uint) sizeof(int)))) { 4409 !(IS_ALIGNED((unsigned long)(arg), (uint) sizeof(int)))) {
4609 WL_ERROR(("wl%d: %s unaligned get ptr for %s\n", 4410 WL_ERROR("wl%d: %s unaligned get ptr for %s\n",
4610 wlc->pub->unit, __func__, name)); 4411 wlc->pub->unit, __func__, name);
4611 ASSERT(0); 4412 ASSERT(0);
4612 } 4413 }
4613 4414
@@ -4622,11 +4423,6 @@ wlc_iovar_op(wlc_info_t *wlc, const char *name,
4622 /* iovar name not found */ 4423 /* iovar name not found */
4623 if (i >= WLC_MAXMODULES) { 4424 if (i >= WLC_MAXMODULES) {
4624 err = BCME_UNSUPPORTED; 4425 err = BCME_UNSUPPORTED;
4625#ifdef WLC_HIGH_ONLY
4626 err =
4627 bcmsdh_iovar_op(wlc->btparam, name, params, p_len, arg, len,
4628 set);
4629#endif
4630 goto exit; 4426 goto exit;
4631 } 4427 }
4632 4428
@@ -4658,10 +4454,10 @@ wlc_iovar_op(wlc_info_t *wlc, const char *name,
4658} 4454}
4659 4455
4660int 4456int
4661wlc_iovar_check(wlc_pub_t *pub, const bcm_iovar_t *vi, void *arg, int len, 4457wlc_iovar_check(struct wlc_pub *pub, const bcm_iovar_t *vi, void *arg, int len,
4662 bool set) 4458 bool set)
4663{ 4459{
4664 wlc_info_t *wlc = (wlc_info_t *) pub->wlc; 4460 struct wlc_info *wlc = (struct wlc_info *) pub->wlc;
4665 int err = 0; 4461 int err = 0;
4666 s32 int_val = 0; 4462 s32 int_val = 0;
4667 4463
@@ -4729,7 +4525,7 @@ wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
4729 const char *name, void *params, uint p_len, void *arg, int len, 4525 const char *name, void *params, uint p_len, void *arg, int len,
4730 int val_size, struct wlc_if *wlcif) 4526 int val_size, struct wlc_if *wlcif)
4731{ 4527{
4732 wlc_info_t *wlc = hdl; 4528 struct wlc_info *wlc = hdl;
4733 wlc_bsscfg_t *bsscfg; 4529 wlc_bsscfg_t *bsscfg;
4734 int err = 0; 4530 int err = 0;
4735 s32 int_val = 0; 4531 s32 int_val = 0;
@@ -4739,7 +4535,7 @@ wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
4739 bool bool_val2; 4535 bool bool_val2;
4740 wlc_bss_info_t *current_bss; 4536 wlc_bss_info_t *current_bss;
4741 4537
4742 WL_TRACE(("wl%d: %s\n", wlc->pub->unit, __func__)); 4538 WL_TRACE("wl%d: %s\n", wlc->pub->unit, __func__);
4743 4539
4744 bsscfg = NULL; 4540 bsscfg = NULL;
4745 current_bss = NULL; 4541 current_bss = NULL;
@@ -4762,8 +4558,8 @@ wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
4762 bool_val = (int_val != 0) ? true : false; 4558 bool_val = (int_val != 0) ? true : false;
4763 bool_val2 = (int_val2 != 0) ? true : false; 4559 bool_val2 = (int_val2 != 0) ? true : false;
4764 4560
4765 WL_TRACE(("wl%d: %s: id %d\n", wlc->pub->unit, __func__, 4561 WL_TRACE("wl%d: %s: id %d\n",
4766 IOV_ID(actionid))); 4562 wlc->pub->unit, __func__, IOV_ID(actionid));
4767 /* Do the actual parameter implementation */ 4563 /* Do the actual parameter implementation */
4768 switch (actionid) { 4564 switch (actionid) {
4769 4565
@@ -4821,7 +4617,7 @@ wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
4821 break; 4617 break;
4822 4618
4823 default: 4619 default:
4824 WL_ERROR(("wl%d: %s: unsupported\n", wlc->pub->unit, __func__)); 4620 WL_ERROR("wl%d: %s: unsupported\n", wlc->pub->unit, __func__);
4825 err = BCME_UNSUPPORTED; 4621 err = BCME_UNSUPPORTED;
4826 break; 4622 break;
4827 } 4623 }
@@ -4833,7 +4629,7 @@ wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
4833} 4629}
4834 4630
4835static int 4631static int
4836wlc_iovar_rangecheck(wlc_info_t *wlc, u32 val, const bcm_iovar_t *vi) 4632wlc_iovar_rangecheck(struct wlc_info *wlc, u32 val, const bcm_iovar_t *vi)
4837{ 4633{
4838 int err = 0; 4634 int err = 0;
4839 u32 min_val = 0; 4635 u32 min_val = 0;
@@ -4930,7 +4726,7 @@ void wlc_print_txstatus(tx_status_t *txs)
4930#define MACSTATUPD(name) \ 4726#define MACSTATUPD(name) \
4931 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name) 4727 wlc_ctrupd_cache(macstats.name, &wlc->core->macstat_snapshot->name, &wlc->pub->_cnt->name)
4932 4728
4933void wlc_statsupd(wlc_info_t *wlc) 4729void wlc_statsupd(struct wlc_info *wlc)
4934{ 4730{
4935 int i; 4731 int i;
4936#ifdef BCMDBG 4732#ifdef BCMDBG
@@ -4956,8 +4752,8 @@ void wlc_statsupd(wlc_info_t *wlc)
4956 /* check for rx fifo 0 overflow */ 4752 /* check for rx fifo 0 overflow */
4957 delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl); 4753 delta = (u16) (wlc->core->macstat_snapshot->rxf0ovfl - rxf0ovfl);
4958 if (delta) 4754 if (delta)
4959 WL_ERROR(("wl%d: %u rx fifo 0 overflows!\n", wlc->pub->unit, 4755 WL_ERROR("wl%d: %u rx fifo 0 overflows!\n",
4960 delta)); 4756 wlc->pub->unit, delta);
4961 4757
4962 /* check for tx fifo underflows */ 4758 /* check for tx fifo underflows */
4963 for (i = 0; i < NFIFO; i++) { 4759 for (i = 0; i < NFIFO; i++) {
@@ -4965,8 +4761,8 @@ void wlc_statsupd(wlc_info_t *wlc)
4965 (u16) (wlc->core->macstat_snapshot->txfunfl[i] - 4761 (u16) (wlc->core->macstat_snapshot->txfunfl[i] -
4966 txfunfl[i]); 4762 txfunfl[i]);
4967 if (delta) 4763 if (delta)
4968 WL_ERROR(("wl%d: %u tx fifo %d underflows!\n", 4764 WL_ERROR("wl%d: %u tx fifo %d underflows!\n",
4969 wlc->pub->unit, delta, i)); 4765 wlc->pub->unit, delta, i);
4970 } 4766 }
4971#endif /* BCMDBG */ 4767#endif /* BCMDBG */
4972 4768
@@ -5015,7 +4811,7 @@ void wlc_statsupd(wlc_info_t *wlc)
5015bool wlc_chipmatch(u16 vendor, u16 device) 4811bool wlc_chipmatch(u16 vendor, u16 device)
5016{ 4812{
5017 if (vendor != VENDOR_BROADCOM) { 4813 if (vendor != VENDOR_BROADCOM) {
5018 WL_ERROR(("wlc_chipmatch: unknown vendor id %04x\n", vendor)); 4814 WL_ERROR("wlc_chipmatch: unknown vendor id %04x\n", vendor);
5019 return false; 4815 return false;
5020 } 4816 }
5021 4817
@@ -5027,7 +4823,7 @@ bool wlc_chipmatch(u16 vendor, u16 device)
5027 if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID)) 4823 if ((device == BCM43236_D11N_ID) || (device == BCM43236_D11N2G_ID))
5028 return true; 4824 return true;
5029 4825
5030 WL_ERROR(("wlc_chipmatch: unknown device id %04x\n", device)); 4826 WL_ERROR("wlc_chipmatch: unknown device id %04x\n", device);
5031 return false; 4827 return false;
5032} 4828}
5033 4829
@@ -5182,20 +4978,12 @@ int wlc_format_ssid(char *buf, const unsigned char ssid[], uint ssid_len)
5182} 4978}
5183#endif /* defined(BCMDBG) */ 4979#endif /* defined(BCMDBG) */
5184 4980
5185u16 wlc_rate_shm_offset(wlc_info_t *wlc, u8 rate) 4981u16 wlc_rate_shm_offset(struct wlc_info *wlc, u8 rate)
5186{ 4982{
5187 return wlc_bmac_rate_shm_offset(wlc->hw, rate); 4983 return wlc_bmac_rate_shm_offset(wlc->hw, rate);
5188} 4984}
5189 4985
5190/* Callback for device removed */ 4986/* Callback for device removed */
5191#if defined(WLC_HIGH_ONLY)
5192void wlc_device_removed(void *arg)
5193{
5194 wlc_info_t *wlc = (wlc_info_t *) arg;
5195
5196 wlc->device_present = false;
5197}
5198#endif /* WLC_HIGH_ONLY */
5199 4987
5200/* 4988/*
5201 * Attempts to queue a packet onto a multiple-precedence queue, 4989 * Attempts to queue a packet onto a multiple-precedence queue,
@@ -5207,16 +4995,16 @@ void wlc_device_removed(void *arg)
5207 * Returns true if packet consumed (queued), false if not. 4995 * Returns true if packet consumed (queued), false if not.
5208 */ 4996 */
5209bool BCMFASTPATH 4997bool BCMFASTPATH
5210wlc_prec_enq(wlc_info_t *wlc, struct pktq *q, void *pkt, int prec) 4998wlc_prec_enq(struct wlc_info *wlc, struct pktq *q, void *pkt, int prec)
5211{ 4999{
5212 return wlc_prec_enq_head(wlc, q, pkt, prec, false); 5000 return wlc_prec_enq_head(wlc, q, pkt, prec, false);
5213} 5001}
5214 5002
5215bool BCMFASTPATH 5003bool BCMFASTPATH
5216wlc_prec_enq_head(wlc_info_t *wlc, struct pktq *q, void *pkt, int prec, 5004wlc_prec_enq_head(struct wlc_info *wlc, struct pktq *q, struct sk_buff *pkt,
5217 bool head) 5005 int prec, bool head)
5218{ 5006{
5219 void *p; 5007 struct sk_buff *p;
5220 int eprec = -1; /* precedence to evict from */ 5008 int eprec = -1; /* precedence to evict from */
5221 5009
5222 /* Determine precedence from which to evict packet, if any */ 5010 /* Determine precedence from which to evict packet, if any */
@@ -5226,8 +5014,8 @@ wlc_prec_enq_head(wlc_info_t *wlc, struct pktq *q, void *pkt, int prec,
5226 p = pktq_peek_tail(q, &eprec); 5014 p = pktq_peek_tail(q, &eprec);
5227 ASSERT(p != NULL); 5015 ASSERT(p != NULL);
5228 if (eprec > prec) { 5016 if (eprec > prec) {
5229 WL_ERROR(("%s: Failing: eprec %d > prec %d\n", __func__, 5017 WL_ERROR("%s: Failing: eprec %d > prec %d\n",
5230 eprec, prec)); 5018 __func__, eprec, prec);
5231 return false; 5019 return false;
5232 } 5020 }
5233 } 5021 }
@@ -5243,8 +5031,8 @@ wlc_prec_enq_head(wlc_info_t *wlc, struct pktq *q, void *pkt, int prec,
5243 5031
5244 /* Refuse newer packet unless configured to discard oldest */ 5032 /* Refuse newer packet unless configured to discard oldest */
5245 if (eprec == prec && !discard_oldest) { 5033 if (eprec == prec && !discard_oldest) {
5246 WL_ERROR(("%s: No where to go, prec == %d\n", __func__, 5034 WL_ERROR("%s: No where to go, prec == %d\n",
5247 prec)); 5035 __func__, prec);
5248 return false; 5036 return false;
5249 } 5037 }
5250 5038
@@ -5256,14 +5044,14 @@ wlc_prec_enq_head(wlc_info_t *wlc, struct pktq *q, void *pkt, int prec,
5256 /* Increment wme stats */ 5044 /* Increment wme stats */
5257 if (WME_ENAB(wlc->pub)) { 5045 if (WME_ENAB(wlc->pub)) {
5258 WLCNTINCR(wlc->pub->_wme_cnt-> 5046 WLCNTINCR(wlc->pub->_wme_cnt->
5259 tx_failed[WME_PRIO2AC(PKTPRIO(p))].packets); 5047 tx_failed[WME_PRIO2AC(p->priority)].packets);
5260 WLCNTADD(wlc->pub->_wme_cnt-> 5048 WLCNTADD(wlc->pub->_wme_cnt->
5261 tx_failed[WME_PRIO2AC(PKTPRIO(p))].bytes, 5049 tx_failed[WME_PRIO2AC(p->priority)].bytes,
5262 pkttotlen(wlc->osh, p)); 5050 pkttotlen(wlc->osh, p));
5263 } 5051 }
5264 5052
5265 ASSERT(0); 5053 ASSERT(0);
5266 PKTFREE(wlc->osh, p, true); 5054 pkt_buf_free_skb(wlc->osh, p, true);
5267 WLCNTINCR(wlc->pub->_cnt->txnobuf); 5055 WLCNTINCR(wlc->pub->_cnt->txnobuf);
5268 } 5056 }
5269 5057
@@ -5277,25 +5065,26 @@ wlc_prec_enq_head(wlc_info_t *wlc, struct pktq *q, void *pkt, int prec,
5277 return true; 5065 return true;
5278} 5066}
5279 5067
5280void BCMFASTPATH wlc_txq_enq(void *ctx, struct scb *scb, void *sdu, uint prec) 5068void BCMFASTPATH wlc_txq_enq(void *ctx, struct scb *scb, struct sk_buff *sdu,
5069 uint prec)
5281{ 5070{
5282 wlc_info_t *wlc = (wlc_info_t *) ctx; 5071 struct wlc_info *wlc = (struct wlc_info *) ctx;
5283 wlc_txq_info_t *qi = wlc->active_queue; /* Check me */ 5072 wlc_txq_info_t *qi = wlc->active_queue; /* Check me */
5284 struct pktq *q = &qi->q; 5073 struct pktq *q = &qi->q;
5285 int prio; 5074 int prio;
5286 5075
5287 prio = PKTPRIO(sdu); 5076 prio = sdu->priority;
5288 5077
5289 ASSERT(pktq_max(q) >= wlc->pub->tunables->datahiwat); 5078 ASSERT(pktq_max(q) >= wlc->pub->tunables->datahiwat);
5290 5079
5291 if (!wlc_prec_enq(wlc, q, sdu, prec)) { 5080 if (!wlc_prec_enq(wlc, q, sdu, prec)) {
5292 if (!EDCF_ENAB(wlc->pub) 5081 if (!EDCF_ENAB(wlc->pub)
5293 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL)) 5082 || (wlc->pub->wlfeatureflag & WL_SWFL_FLOWCONTROL))
5294 WL_ERROR(("wl%d: wlc_txq_enq: txq overflow\n", 5083 WL_ERROR("wl%d: wlc_txq_enq: txq overflow\n",
5295 wlc->pub->unit)); 5084 wlc->pub->unit);
5296 5085
5297 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */ 5086 /* ASSERT(9 == 8); *//* XXX we might hit this condtion in case packet flooding from mac80211 stack */
5298 PKTFREE(wlc->osh, sdu, true); 5087 pkt_buf_free_skb(wlc->osh, sdu, true);
5299 WLCNTINCR(wlc->pub->_cnt->txnobuf); 5088 WLCNTINCR(wlc->pub->_cnt->txnobuf);
5300 } 5089 }
5301 5090
@@ -5317,13 +5106,14 @@ void BCMFASTPATH wlc_txq_enq(void *ctx, struct scb *scb, void *sdu, uint prec)
5317} 5106}
5318 5107
5319bool BCMFASTPATH 5108bool BCMFASTPATH
5320wlc_sendpkt_mac80211(wlc_info_t *wlc, void *sdu, struct ieee80211_hw *hw) 5109wlc_sendpkt_mac80211(struct wlc_info *wlc, struct sk_buff *sdu,
5110 struct ieee80211_hw *hw)
5321{ 5111{
5322 u8 prio; 5112 u8 prio;
5323 uint fifo; 5113 uint fifo;
5324 void *pkt; 5114 void *pkt;
5325 struct scb *scb = &global_scb; 5115 struct scb *scb = &global_scb;
5326 struct dot11_header *d11_header = (struct dot11_header *)PKTDATA(sdu); 5116 struct dot11_header *d11_header = (struct dot11_header *)(sdu->data);
5327 u16 type, fc; 5117 u16 type, fc;
5328 5118
5329 ASSERT(sdu); 5119 ASSERT(sdu);
@@ -5332,13 +5122,13 @@ wlc_sendpkt_mac80211(wlc_info_t *wlc, void *sdu, struct ieee80211_hw *hw)
5332 type = FC_TYPE(fc); 5122 type = FC_TYPE(fc);
5333 5123
5334 /* 802.11 standard requires management traffic to go at highest priority */ 5124 /* 802.11 standard requires management traffic to go at highest priority */
5335 prio = (type == FC_TYPE_DATA ? PKTPRIO(sdu) : MAXPRIO); 5125 prio = (type == FC_TYPE_DATA ? sdu->priority : MAXPRIO);
5336 fifo = prio2fifo[prio]; 5126 fifo = prio2fifo[prio];
5337 5127
5338 ASSERT((uint) PKTHEADROOM(sdu) >= TXOFF); 5128 ASSERT((uint) skb_headroom(sdu) >= TXOFF);
5339 ASSERT(!PKTSHARED(sdu)); 5129 ASSERT(!(sdu->cloned));
5340 ASSERT(!PKTNEXT(sdu)); 5130 ASSERT(!(sdu->next));
5341 ASSERT(!PKTLINK(sdu)); 5131 ASSERT(!(sdu->prev));
5342 ASSERT(fifo < NFIFO); 5132 ASSERT(fifo < NFIFO);
5343 5133
5344 pkt = sdu; 5134 pkt = sdu;
@@ -5352,9 +5142,9 @@ wlc_sendpkt_mac80211(wlc_info_t *wlc, void *sdu, struct ieee80211_hw *hw)
5352 return 0; 5142 return 0;
5353} 5143}
5354 5144
5355void BCMFASTPATH wlc_send_q(wlc_info_t *wlc, wlc_txq_info_t *qi) 5145void BCMFASTPATH wlc_send_q(struct wlc_info *wlc, wlc_txq_info_t *qi)
5356{ 5146{
5357 void *pkt[DOT11_MAXNUMFRAGS]; 5147 struct sk_buff *pkt[DOT11_MAXNUMFRAGS];
5358 int prec; 5148 int prec;
5359 u16 prec_map; 5149 u16 prec_map;
5360 int err = 0, i, count; 5150 int err = 0, i, count;
@@ -5427,7 +5217,7 @@ void BCMFASTPATH wlc_send_q(wlc_info_t *wlc, wlc_txq_info_t *qi)
5427 * for MC frames so is used as part of the sequence number. 5217 * for MC frames so is used as part of the sequence number.
5428 */ 5218 */
5429static inline u16 5219static inline u16
5430bcmc_fid_generate(wlc_info_t *wlc, wlc_bsscfg_t *bsscfg, d11txh_t *txh) 5220bcmc_fid_generate(struct wlc_info *wlc, wlc_bsscfg_t *bsscfg, d11txh_t *txh)
5431{ 5221{
5432 u16 frameid; 5222 u16 frameid;
5433 5223
@@ -5441,13 +5231,14 @@ bcmc_fid_generate(wlc_info_t *wlc, wlc_bsscfg_t *bsscfg, d11txh_t *txh)
5441} 5231}
5442 5232
5443void BCMFASTPATH 5233void BCMFASTPATH
5444wlc_txfifo(wlc_info_t *wlc, uint fifo, void *p, bool commit, s8 txpktpend) 5234wlc_txfifo(struct wlc_info *wlc, uint fifo, struct sk_buff *p, bool commit,
5235 s8 txpktpend)
5445{ 5236{
5446 u16 frameid = INVALIDFID; 5237 u16 frameid = INVALIDFID;
5447 d11txh_t *txh; 5238 d11txh_t *txh;
5448 5239
5449 ASSERT(fifo < NFIFO); 5240 ASSERT(fifo < NFIFO);
5450 txh = (d11txh_t *) PKTDATA(p); 5241 txh = (d11txh_t *) (p->data);
5451 5242
5452 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update 5243 /* When a BC/MC frame is being committed to the BCMC fifo via DMA (NOT PIO), update
5453 * ucode or BSS info as appropriate. 5244 * ucode or BSS info as appropriate.
@@ -5460,21 +5251,14 @@ wlc_txfifo(wlc_info_t *wlc, uint fifo, void *p, bool commit, s8 txpktpend)
5460 if (WLC_WAR16165(wlc)) 5251 if (WLC_WAR16165(wlc))
5461 wlc_war16165(wlc, true); 5252 wlc_war16165(wlc, true);
5462 5253
5463#ifdef WLC_HIGH_ONLY
5464 if (RPCTX_ENAB(wlc->pub)) {
5465 (void)wlc_rpctx_tx(wlc->rpctx, fifo, p, commit, frameid,
5466 txpktpend);
5467 return;
5468 }
5469#else
5470 5254
5471 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled 5255 /* Bump up pending count for if not using rpc. If rpc is used, this will be handled
5472 * in wlc_bmac_txfifo() 5256 * in wlc_bmac_txfifo()
5473 */ 5257 */
5474 if (commit) { 5258 if (commit) {
5475 TXPKTPENDINC(wlc, fifo, txpktpend); 5259 TXPKTPENDINC(wlc, fifo, txpktpend);
5476 WL_TRACE(("wlc_txfifo, pktpend inc %d to %d\n", txpktpend, 5260 WL_TRACE("wlc_txfifo, pktpend inc %d to %d\n",
5477 TXPKTPENDGET(wlc, fifo))); 5261 txpktpend, TXPKTPENDGET(wlc, fifo));
5478 } 5262 }
5479 5263
5480 /* Commit BCMC sequence number in the SHM frame ID location */ 5264 /* Commit BCMC sequence number in the SHM frame ID location */
@@ -5482,13 +5266,12 @@ wlc_txfifo(wlc_info_t *wlc, uint fifo, void *p, bool commit, s8 txpktpend)
5482 BCMCFID(wlc, frameid); 5266 BCMCFID(wlc, frameid);
5483 5267
5484 if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) { 5268 if (dma_txfast(wlc->hw->di[fifo], p, commit) < 0) {
5485 WL_ERROR(("wlc_txfifo: fatal, toss frames !!!\n")); 5269 WL_ERROR("wlc_txfifo: fatal, toss frames !!!\n");
5486 } 5270 }
5487#endif /* WLC_HIGH_ONLY */
5488} 5271}
5489 5272
5490static u16 5273static u16
5491wlc_compute_airtime(wlc_info_t *wlc, ratespec_t rspec, uint length) 5274wlc_compute_airtime(struct wlc_info *wlc, ratespec_t rspec, uint length)
5492{ 5275{
5493 u16 usec = 0; 5276 u16 usec = 0;
5494 uint mac_rate = RSPEC2RATE(rspec); 5277 uint mac_rate = RSPEC2RATE(rspec);
@@ -5523,7 +5306,8 @@ wlc_compute_airtime(wlc_info_t *wlc, ratespec_t rspec, uint length)
5523 usec = (length << 3) / 11; 5306 usec = (length << 3) / 11;
5524 break; 5307 break;
5525 default: 5308 default:
5526 WL_ERROR(("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n", wlc->pub->unit, rspec)); 5309 WL_ERROR("wl%d: wlc_compute_airtime: unsupported rspec 0x%x\n",
5310 wlc->pub->unit, rspec);
5527 ASSERT((const char *)"Bad phy_rate" == NULL); 5311 ASSERT((const char *)"Bad phy_rate" == NULL);
5528 break; 5312 break;
5529 } 5313 }
@@ -5533,7 +5317,7 @@ wlc_compute_airtime(wlc_info_t *wlc, ratespec_t rspec, uint length)
5533} 5317}
5534 5318
5535void BCMFASTPATH 5319void BCMFASTPATH
5536wlc_compute_plcp(wlc_info_t *wlc, ratespec_t rspec, uint length, u8 *plcp) 5320wlc_compute_plcp(struct wlc_info *wlc, ratespec_t rspec, uint length, u8 *plcp)
5537{ 5321{
5538 if (IS_MCS(rspec)) { 5322 if (IS_MCS(rspec)) {
5539 wlc_compute_mimo_plcp(rspec, length, plcp); 5323 wlc_compute_mimo_plcp(rspec, length, plcp);
@@ -5574,7 +5358,7 @@ wlc_compute_ofdm_plcp(ratespec_t rspec, u32 length, u8 *plcp)
5574 rate_signal = rate_info[rate] & RATE_MASK; 5358 rate_signal = rate_info[rate] & RATE_MASK;
5575 ASSERT(rate_signal != 0); 5359 ASSERT(rate_signal != 0);
5576 5360
5577 bzero(plcp, D11_PHY_HDR_LEN); 5361 memset(plcp, 0, D11_PHY_HDR_LEN);
5578 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t *) plcp, rate_signal); 5362 D11A_PHY_HDR_SRATE((ofdm_phy_hdr_t *) plcp, rate_signal);
5579 5363
5580 tmp = (length & 0xfff) << 5; 5364 tmp = (length & 0xfff) << 5;
@@ -5619,7 +5403,7 @@ static void wlc_cck_plcp_set(int rate_500, uint length, u8 *plcp)
5619 break; 5403 break;
5620 5404
5621 default: 5405 default:
5622 WL_ERROR(("wlc_cck_plcp_set: unsupported rate %d\n", rate_500)); 5406 WL_ERROR("wlc_cck_plcp_set: unsupported rate %d\n", rate_500);
5623 rate_500 = WLC_RATE_1M; 5407 rate_500 = WLC_RATE_1M;
5624 usec = length << 3; 5408 usec = length << 3;
5625 break; 5409 break;
@@ -5657,7 +5441,7 @@ static void wlc_compute_cck_plcp(ratespec_t rspec, uint length, u8 *plcp)
5657 * preamble_type use short/GF or long/MM PLCP header 5441 * preamble_type use short/GF or long/MM PLCP header
5658 */ 5442 */
5659static u16 BCMFASTPATH 5443static u16 BCMFASTPATH
5660wlc_compute_frame_dur(wlc_info_t *wlc, ratespec_t rate, u8 preamble_type, 5444wlc_compute_frame_dur(struct wlc_info *wlc, ratespec_t rate, u8 preamble_type,
5661 uint next_frag_len) 5445 uint next_frag_len)
5662{ 5446{
5663 u16 dur, sifs; 5447 u16 dur, sifs;
@@ -5691,7 +5475,7 @@ wlc_compute_frame_dur(wlc_info_t *wlc, ratespec_t rate, u8 preamble_type,
5691 * frame_len next MPDU frame length in bytes 5475 * frame_len next MPDU frame length in bytes
5692 */ 5476 */
5693u16 BCMFASTPATH 5477u16 BCMFASTPATH
5694wlc_compute_rtscts_dur(wlc_info_t *wlc, bool cts_only, ratespec_t rts_rate, 5478wlc_compute_rtscts_dur(struct wlc_info *wlc, bool cts_only, ratespec_t rts_rate,
5695 ratespec_t frame_rate, u8 rts_preamble_type, 5479 ratespec_t frame_rate, u8 rts_preamble_type,
5696 u8 frame_preamble_type, uint frame_len, bool ba) 5480 u8 frame_preamble_type, uint frame_len, bool ba)
5697{ 5481{
@@ -5722,7 +5506,7 @@ wlc_compute_rtscts_dur(wlc_info_t *wlc, bool cts_only, ratespec_t rts_rate,
5722 return dur; 5506 return dur;
5723} 5507}
5724 5508
5725static bool wlc_phy_rspec_check(wlc_info_t *wlc, u16 bw, ratespec_t rspec) 5509static bool wlc_phy_rspec_check(struct wlc_info *wlc, u16 bw, ratespec_t rspec)
5726{ 5510{
5727 if (IS_MCS(rspec)) { 5511 if (IS_MCS(rspec)) {
5728 uint mcs = rspec & RSPEC_RATE_MASK; 5512 uint mcs = rspec & RSPEC_RATE_MASK;
@@ -5748,7 +5532,7 @@ static bool wlc_phy_rspec_check(wlc_info_t *wlc, u16 bw, ratespec_t rspec)
5748 return true; 5532 return true;
5749} 5533}
5750 5534
5751u16 BCMFASTPATH wlc_phytxctl1_calc(wlc_info_t *wlc, ratespec_t rspec) 5535u16 BCMFASTPATH wlc_phytxctl1_calc(struct wlc_info *wlc, ratespec_t rspec)
5752{ 5536{
5753 u16 phyctl1 = 0; 5537 u16 phyctl1 = 0;
5754 u16 bw; 5538 u16 bw;
@@ -5759,7 +5543,8 @@ u16 BCMFASTPATH wlc_phytxctl1_calc(wlc_info_t *wlc, ratespec_t rspec)
5759 bw = RSPEC_GET_BW(rspec); 5543 bw = RSPEC_GET_BW(rspec);
5760 /* 10Mhz is not supported yet */ 5544 /* 10Mhz is not supported yet */
5761 if (bw < PHY_TXC1_BW_20MHZ) { 5545 if (bw < PHY_TXC1_BW_20MHZ) {
5762 WL_ERROR(("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n", bw)); 5546 WL_ERROR("wlc_phytxctl1_calc: bw %d is not supported yet, set to 20L\n",
5547 bw);
5763 bw = PHY_TXC1_BW_20MHZ; 5548 bw = PHY_TXC1_BW_20MHZ;
5764 } 5549 }
5765 5550
@@ -5784,7 +5569,7 @@ u16 BCMFASTPATH wlc_phytxctl1_calc(wlc_info_t *wlc, ratespec_t rspec)
5784 /* get the phyctl byte from rate phycfg table */ 5569 /* get the phyctl byte from rate phycfg table */
5785 phycfg = wlc_rate_legacy_phyctl(RSPEC2RATE(rspec)); 5570 phycfg = wlc_rate_legacy_phyctl(RSPEC2RATE(rspec));
5786 if (phycfg == -1) { 5571 if (phycfg == -1) {
5787 WL_ERROR(("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n")); 5572 WL_ERROR("wlc_phytxctl1_calc: wrong legacy OFDM/CCK rate\n");
5788 ASSERT(0); 5573 ASSERT(0);
5789 phycfg = 0; 5574 phycfg = 0;
5790 } 5575 }
@@ -5798,16 +5583,14 @@ u16 BCMFASTPATH wlc_phytxctl1_calc(wlc_info_t *wlc, ratespec_t rspec)
5798 /* phy clock must support 40Mhz if tx descriptor uses it */ 5583 /* phy clock must support 40Mhz if tx descriptor uses it */
5799 if ((phyctl1 & PHY_TXC1_BW_MASK) >= PHY_TXC1_BW_40MHZ) { 5584 if ((phyctl1 & PHY_TXC1_BW_MASK) >= PHY_TXC1_BW_40MHZ) {
5800 ASSERT(CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ); 5585 ASSERT(CHSPEC_WLC_BW(wlc->chanspec) == WLC_40_MHZ);
5801#ifndef WLC_HIGH_ONLY
5802 ASSERT(wlc->chanspec == wlc_phy_chanspec_get(wlc->band->pi)); 5586 ASSERT(wlc->chanspec == wlc_phy_chanspec_get(wlc->band->pi));
5803#endif
5804 } 5587 }
5805#endif /* BCMDBG */ 5588#endif /* BCMDBG */
5806 return phyctl1; 5589 return phyctl1;
5807} 5590}
5808 5591
5809ratespec_t BCMFASTPATH 5592ratespec_t BCMFASTPATH
5810wlc_rspec_to_rts_rspec(wlc_info_t *wlc, ratespec_t rspec, bool use_rspec, 5593wlc_rspec_to_rts_rspec(struct wlc_info *wlc, ratespec_t rspec, bool use_rspec,
5811 u16 mimo_ctlchbw) 5594 u16 mimo_ctlchbw)
5812{ 5595{
5813 ratespec_t rts_rspec = 0; 5596 ratespec_t rts_rspec = 0;
@@ -5863,15 +5646,15 @@ wlc_rspec_to_rts_rspec(wlc_info_t *wlc, ratespec_t rspec, bool use_rspec,
5863 * 5646 *
5864 */ 5647 */
5865static u16 BCMFASTPATH 5648static u16 BCMFASTPATH
5866wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw, 5649wlc_d11hdrs_mac80211(struct wlc_info *wlc, struct ieee80211_hw *hw,
5867 void *p, struct scb *scb, uint frag, 5650 struct sk_buff *p, struct scb *scb, uint frag,
5868 uint nfrags, uint queue, uint next_frag_len, 5651 uint nfrags, uint queue, uint next_frag_len,
5869 wsec_key_t *key, ratespec_t rspec_override) 5652 wsec_key_t *key, ratespec_t rspec_override)
5870{ 5653{
5871 struct dot11_header *h; 5654 struct dot11_header *h;
5872 d11txh_t *txh; 5655 d11txh_t *txh;
5873 u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN]; 5656 u8 *plcp, plcp_fallback[D11_PHY_HDR_LEN];
5874 osl_t *osh; 5657 struct osl_info *osh;
5875 int len, phylen, rts_phylen; 5658 int len, phylen, rts_phylen;
5876 u16 fc, type, frameid, mch, phyctl, xfts, mainrates; 5659 u16 fc, type, frameid, mch, phyctl, xfts, mainrates;
5877 u16 seq = 0, mcl = 0, status = 0; 5660 u16 seq = 0, mcl = 0, status = 0;
@@ -5911,7 +5694,7 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
5911 osh = wlc->osh; 5694 osh = wlc->osh;
5912 5695
5913 /* locate 802.11 MAC header */ 5696 /* locate 802.11 MAC header */
5914 h = (struct dot11_header *)PKTDATA(p); 5697 h = (struct dot11_header *)(p->data);
5915 fc = ltoh16(h->fc); 5698 fc = ltoh16(h->fc);
5916 type = FC_TYPE(fc); 5699 type = FC_TYPE(fc);
5917 5700
@@ -5935,29 +5718,29 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
5935 ASSERT(tx_info); 5718 ASSERT(tx_info);
5936 5719
5937 /* add PLCP */ 5720 /* add PLCP */
5938 plcp = PKTPUSH(p, D11_PHY_HDR_LEN); 5721 plcp = skb_push(p, D11_PHY_HDR_LEN);
5939 5722
5940 /* add Broadcom tx descriptor header */ 5723 /* add Broadcom tx descriptor header */
5941 txh = (d11txh_t *) PKTPUSH(p, D11_TXH_LEN); 5724 txh = (d11txh_t *) skb_push(p, D11_TXH_LEN);
5942 bzero((char *)txh, D11_TXH_LEN); 5725 memset((char *)txh, 0, D11_TXH_LEN);
5943 5726
5944 /* setup frameid */ 5727 /* setup frameid */
5945 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { 5728 if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
5946 /* non-AP STA should never use BCMC queue */ 5729 /* non-AP STA should never use BCMC queue */
5947 ASSERT(queue != TX_BCMC_FIFO); 5730 ASSERT(queue != TX_BCMC_FIFO);
5948 if (queue == TX_BCMC_FIFO) { 5731 if (queue == TX_BCMC_FIFO) {
5949 WL_ERROR(("wl%d: %s: ASSERT queue == TX_BCMC!\n", 5732 WL_ERROR("wl%d: %s: ASSERT queue == TX_BCMC!\n",
5950 WLCWLUNIT(wlc), __func__)); 5733 WLCWLUNIT(wlc), __func__);
5951 frameid = bcmc_fid_generate(wlc, NULL, txh); 5734 frameid = bcmc_fid_generate(wlc, NULL, txh);
5952 } else { 5735 } else {
5953 /* Increment the counter for first fragment */ 5736 /* Increment the counter for first fragment */
5954 if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) { 5737 if (tx_info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) {
5955 SCB_SEQNUM(scb, PKTPRIO(p))++; 5738 SCB_SEQNUM(scb, p->priority)++;
5956 } 5739 }
5957 5740
5958 /* extract fragment number from frame first */ 5741 /* extract fragment number from frame first */
5959 seq = ltoh16(seq) & FRAGNUM_MASK; 5742 seq = ltoh16(seq) & FRAGNUM_MASK;
5960 seq |= (SCB_SEQNUM(scb, PKTPRIO(p)) << SEQNUM_SHIFT); 5743 seq |= (SCB_SEQNUM(scb, p->priority) << SEQNUM_SHIFT);
5961 h->seq = htol16(seq); 5744 h->seq = htol16(seq);
5962 5745
5963 frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) | 5746 frameid = ((seq << TXFID_SEQ_SHIFT) & TXFID_SEQ_MASK) |
@@ -5981,13 +5764,6 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
5981 if (txrate[1]->idx < 0) { 5764 if (txrate[1]->idx < 0) {
5982 txrate[1] = txrate[0]; 5765 txrate[1] = txrate[0];
5983 } 5766 }
5984#ifdef WLC_HIGH_ONLY
5985 /* Double protection , just in case */
5986 if (txrate[0]->idx > HIGHEST_SINGLE_STREAM_MCS)
5987 txrate[0]->idx = HIGHEST_SINGLE_STREAM_MCS;
5988 if (txrate[1]->idx > HIGHEST_SINGLE_STREAM_MCS)
5989 txrate[1]->idx = HIGHEST_SINGLE_STREAM_MCS;
5990#endif
5991 5767
5992 for (k = 0; k < hw->max_rates; k++) { 5768 for (k = 0; k < hw->max_rates; k++) {
5993 is_mcs[k] = 5769 is_mcs[k] =
@@ -6034,7 +5810,8 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6034 ASSERT(RSPEC_ACTIVE(rspec[k])); 5810 ASSERT(RSPEC_ACTIVE(rspec[k]));
6035 rspec[k] = WLC_RATE_1M; 5811 rspec[k] = WLC_RATE_1M;
6036 } else { 5812 } else {
6037 if (WLANTSEL_ENAB(wlc) && !ETHER_ISMULTI(&h->a1)) { 5813 if (WLANTSEL_ENAB(wlc) &&
5814 !is_multicast_ether_addr(h->a1.octet)) {
6038 /* set tx antenna config */ 5815 /* set tx antenna config */
6039 wlc_antsel_antcfg_get(wlc->asi, false, false, 0, 5816 wlc_antsel_antcfg_get(wlc->asi, false, false, 0,
6040 0, &antcfg, &fbantcfg); 5817 0, &antcfg, &fbantcfg);
@@ -6131,7 +5908,8 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6131 5908
6132 if ((txrate[k]->flags & IEEE80211_TX_RC_MCS) 5909 if ((txrate[k]->flags & IEEE80211_TX_RC_MCS)
6133 && (!IS_MCS(rspec[k]))) { 5910 && (!IS_MCS(rspec[k]))) {
6134 WL_ERROR(("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n", WLCWLUNIT(wlc), __func__)); 5911 WL_ERROR("wl%d: %s: IEEE80211_TX_RC_MCS != IS_MCS(rspec)\n",
5912 WLCWLUNIT(wlc), __func__);
6135 ASSERT(0 && "Rate mismatch"); 5913 ASSERT(0 && "Rate mismatch");
6136 } 5914 }
6137 5915
@@ -6195,7 +5973,8 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6195 plcp[0]; 5973 plcp[0];
6196 5974
6197 /* DUR field for main rate */ 5975 /* DUR field for main rate */
6198 if ((fc != FC_PS_POLL) && !ETHER_ISMULTI(&h->a1) && !use_rifs) { 5976 if ((fc != FC_PS_POLL) &&
5977 !is_multicast_ether_addr(h->a1.octet) && !use_rifs) {
6199 durid = 5978 durid =
6200 wlc_compute_frame_dur(wlc, rspec[0], preamble_type[0], 5979 wlc_compute_frame_dur(wlc, rspec[0], preamble_type[0],
6201 next_frag_len); 5980 next_frag_len);
@@ -6213,7 +5992,7 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6213 /* DUR field for fallback rate */ 5992 /* DUR field for fallback rate */
6214 if (fc == FC_PS_POLL) 5993 if (fc == FC_PS_POLL)
6215 txh->FragDurFallback = h->durid; 5994 txh->FragDurFallback = h->durid;
6216 else if (ETHER_ISMULTI(&h->a1) || use_rifs) 5995 else if (is_multicast_ether_addr(h->a1.octet) || use_rifs)
6217 txh->FragDurFallback = 0; 5996 txh->FragDurFallback = 0;
6218 else { 5997 else {
6219 durid = wlc_compute_frame_dur(wlc, rspec[1], 5998 durid = wlc_compute_frame_dur(wlc, rspec[1],
@@ -6225,7 +6004,7 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6225 if (frag == 0) 6004 if (frag == 0)
6226 mcl |= TXC_STARTMSDU; 6005 mcl |= TXC_STARTMSDU;
6227 6006
6228 if (!ETHER_ISMULTI(&h->a1)) 6007 if (!is_multicast_ether_addr(h->a1.octet))
6229 mcl |= TXC_IMMEDACK; 6008 mcl |= TXC_IMMEDACK;
6230 6009
6231 if (BAND_5G(wlc->band->bandtype)) 6010 if (BAND_5G(wlc->band->bandtype))
@@ -6260,7 +6039,7 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6260 txh->TxFesTimeFallback = htol16(0); 6039 txh->TxFesTimeFallback = htol16(0);
6261 6040
6262 /* TxFrameRA */ 6041 /* TxFrameRA */
6263 bcopy((char *)&h->a1, (char *)&txh->TxFrameRA, ETHER_ADDR_LEN); 6042 bcopy((char *)&h->a1, (char *)&txh->TxFrameRA, ETH_ALEN);
6264 6043
6265 /* TxFrameID */ 6044 /* TxFrameID */
6266 txh->TxFrameID = htol16(frameid); 6045 txh->TxFrameID = htol16(frameid);
@@ -6347,11 +6126,11 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6347 6126
6348 if (use_cts) { 6127 if (use_cts) {
6349 rts->fc = htol16(FC_CTS); 6128 rts->fc = htol16(FC_CTS);
6350 bcopy((char *)&h->a2, (char *)&rts->ra, ETHER_ADDR_LEN); 6129 bcopy((char *)&h->a2, (char *)&rts->ra, ETH_ALEN);
6351 } else { 6130 } else {
6352 rts->fc = htol16((u16) FC_RTS); 6131 rts->fc = htol16((u16) FC_RTS);
6353 bcopy((char *)&h->a1, (char *)&rts->ra, 6132 bcopy((char *)&h->a1, (char *)&rts->ra,
6354 2 * ETHER_ADDR_LEN); 6133 2 * ETH_ALEN);
6355 } 6134 }
6356 6135
6357 /* mainrate 6136 /* mainrate
@@ -6362,9 +6141,10 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6362 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) rts_plcp) : 6141 D11A_PHY_HDR_GRATE((ofdm_phy_hdr_t *) rts_plcp) :
6363 rts_plcp[0]) << 8; 6142 rts_plcp[0]) << 8;
6364 } else { 6143 } else {
6365 bzero((char *)txh->RTSPhyHeader, D11_PHY_HDR_LEN); 6144 memset((char *)txh->RTSPhyHeader, 0, D11_PHY_HDR_LEN);
6366 bzero((char *)&txh->rts_frame, sizeof(struct dot11_rts_frame)); 6145 memset((char *)&txh->rts_frame, 0,
6367 bzero((char *)txh->RTSPLCPFallback, 6146 sizeof(struct dot11_rts_frame));
6147 memset((char *)txh->RTSPLCPFallback, 0,
6368 sizeof(txh->RTSPLCPFallback)); 6148 sizeof(txh->RTSPLCPFallback));
6369 txh->RTSDurFallback = 0; 6149 txh->RTSDurFallback = 0;
6370 } 6150 }
@@ -6453,7 +6233,7 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6453 if (SCB_WME(scb) && qos && wlc->edcf_txop[ac]) { 6233 if (SCB_WME(scb) && qos && wlc->edcf_txop[ac]) {
6454 uint frag_dur, dur, dur_fallback; 6234 uint frag_dur, dur, dur_fallback;
6455 6235
6456 ASSERT(!ETHER_ISMULTI(&h->a1)); 6236 ASSERT(!is_multicast_ether_addr(h->a1.octet));
6457 6237
6458 /* WME: Update TXOP threshold */ 6238 /* WME: Update TXOP threshold */
6459 if ((!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) && (frag == 0)) { 6239 if ((!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) && (frag == 0)) {
@@ -6523,19 +6303,23 @@ wlc_d11hdrs_mac80211(wlc_info_t *wlc, struct ieee80211_hw *hw,
6523 } 6303 }
6524 } 6304 }
6525 } else 6305 } else
6526 WL_ERROR(("wl%d: %s txop invalid for rate %d\n", 6306 WL_ERROR("wl%d: %s txop invalid for rate %d\n",
6527 wlc->pub->unit, fifo_names[queue], 6307 wlc->pub->unit, fifo_names[queue],
6528 RSPEC2RATE(rspec[0]))); 6308 RSPEC2RATE(rspec[0]));
6529 6309
6530 if (dur > wlc->edcf_txop[ac]) 6310 if (dur > wlc->edcf_txop[ac])
6531 WL_ERROR(("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n", wlc->pub->unit, __func__, fifo_names[queue], phylen, wlc->fragthresh[queue], dur, wlc->edcf_txop[ac])); 6311 WL_ERROR("wl%d: %s: %s txop exceeded phylen %d/%d dur %d/%d\n",
6312 wlc->pub->unit, __func__,
6313 fifo_names[queue],
6314 phylen, wlc->fragthresh[queue],
6315 dur, wlc->edcf_txop[ac]);
6532 } 6316 }
6533 } 6317 }
6534 6318
6535 return 0; 6319 return 0;
6536} 6320}
6537 6321
6538void wlc_tbtt(wlc_info_t *wlc, d11regs_t *regs) 6322void wlc_tbtt(struct wlc_info *wlc, d11regs_t *regs)
6539{ 6323{
6540 wlc_bsscfg_t *cfg = wlc->cfg; 6324 wlc_bsscfg_t *cfg = wlc->cfg;
6541 6325
@@ -6571,19 +6355,19 @@ void wlc_tbtt(wlc_info_t *wlc, d11regs_t *regs)
6571} 6355}
6572 6356
6573/* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */ 6357/* GP timer is a freerunning 32 bit counter, decrements at 1 us rate */
6574void wlc_hwtimer_gptimer_set(wlc_info_t *wlc, uint us) 6358void wlc_hwtimer_gptimer_set(struct wlc_info *wlc, uint us)
6575{ 6359{
6576 ASSERT(wlc->pub->corerev >= 3); /* no gptimer in earlier revs */ 6360 ASSERT(wlc->pub->corerev >= 3); /* no gptimer in earlier revs */
6577 W_REG(wlc->osh, &wlc->regs->gptimer, us); 6361 W_REG(wlc->osh, &wlc->regs->gptimer, us);
6578} 6362}
6579 6363
6580void wlc_hwtimer_gptimer_abort(wlc_info_t *wlc) 6364void wlc_hwtimer_gptimer_abort(struct wlc_info *wlc)
6581{ 6365{
6582 ASSERT(wlc->pub->corerev >= 3); 6366 ASSERT(wlc->pub->corerev >= 3);
6583 W_REG(wlc->osh, &wlc->regs->gptimer, 0); 6367 W_REG(wlc->osh, &wlc->regs->gptimer, 0);
6584} 6368}
6585 6369
6586static void wlc_hwtimer_gptimer_cb(wlc_info_t *wlc) 6370static void wlc_hwtimer_gptimer_cb(struct wlc_info *wlc)
6587{ 6371{
6588 /* when interrupt is generated, the counter is loaded with last value 6372 /* when interrupt is generated, the counter is loaded with last value
6589 * written and continue to decrement. So it has to be cleaned first 6373 * written and continue to decrement. So it has to be cleaned first
@@ -6596,7 +6380,7 @@ static void wlc_hwtimer_gptimer_cb(wlc_info_t *wlc)
6596 * POLICY: no macinstatus change, no bounding loop. 6380 * POLICY: no macinstatus change, no bounding loop.
6597 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint 6381 * All dpc bounding should be handled in BMAC dpc, like txstatus and rxint
6598 */ 6382 */
6599void wlc_high_dpc(wlc_info_t *wlc, u32 macintstatus) 6383void wlc_high_dpc(struct wlc_info *wlc, u32 macintstatus)
6600{ 6384{
6601 d11regs_t *regs = wlc->regs; 6385 d11regs_t *regs = wlc->regs;
6602#ifdef BCMDBG 6386#ifdef BCMDBG
@@ -6634,8 +6418,8 @@ void wlc_high_dpc(wlc_info_t *wlc, u32 macintstatus)
6634 if (macintstatus & ~(MI_TBTT | MI_TXSTOP)) { 6418 if (macintstatus & ~(MI_TBTT | MI_TXSTOP)) {
6635 bcm_format_flags(int_flags, macintstatus, flagstr, 6419 bcm_format_flags(int_flags, macintstatus, flagstr,
6636 sizeof(flagstr)); 6420 sizeof(flagstr));
6637 WL_TRACE(("wl%d: macintstatus 0x%x %s\n", wlc->pub->unit, 6421 WL_TRACE("wl%d: macintstatus 0x%x %s\n",
6638 macintstatus, flagstr)); 6422 wlc->pub->unit, macintstatus, flagstr);
6639 } 6423 }
6640#endif /* BCMDBG */ 6424#endif /* BCMDBG */
6641 6425
@@ -6650,11 +6434,12 @@ void wlc_high_dpc(wlc_info_t *wlc, u32 macintstatus)
6650 wlc_tbtt(wlc, regs); 6434 wlc_tbtt(wlc, regs);
6651 6435
6652 if (macintstatus & MI_GP0) { 6436 if (macintstatus & MI_GP0) {
6653 WL_ERROR(("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n", wlc->pub->unit, wlc->pub->now)); 6437 WL_ERROR("wl%d: PSM microcode watchdog fired at %d (seconds). Resetting.\n",
6438 wlc->pub->unit, wlc->pub->now);
6654 6439
6655 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n", 6440 printk_once("%s : PSM Watchdog, chipid 0x%x, chiprev 0x%x\n",
6656 __func__, CHIPID(wlc->pub->sih->chip), 6441 __func__, wlc->pub->sih->chip,
6657 CHIPREV(wlc->pub->sih->chiprev)); 6442 wlc->pub->sih->chiprev);
6658 6443
6659 WLCNTINCR(wlc->pub->_cnt->psmwds); 6444 WLCNTINCR(wlc->pub->_cnt->psmwds);
6660 6445
@@ -6668,7 +6453,9 @@ void wlc_high_dpc(wlc_info_t *wlc, u32 macintstatus)
6668 } 6453 }
6669 6454
6670 if (macintstatus & MI_RFDISABLE) { 6455 if (macintstatus & MI_RFDISABLE) {
6671 WL_ERROR(("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n", wlc->pub->unit, R_REG(wlc->osh, &regs->phydebug) & PDBG_RFD)); 6456 WL_ERROR("wl%d: MAC Detected a change on the RF Disable Input 0x%x\n",
6457 wlc->pub->unit,
6458 R_REG(wlc->osh, &regs->phydebug) & PDBG_RFD);
6672 /* delay the cleanup to wl_down in IBSS case */ 6459 /* delay the cleanup to wl_down in IBSS case */
6673 if ((R_REG(wlc->osh, &regs->phydebug) & PDBG_RFD)) { 6460 if ((R_REG(wlc->osh, &regs->phydebug) & PDBG_RFD)) {
6674 int idx; 6461 int idx;
@@ -6677,7 +6464,8 @@ void wlc_high_dpc(wlc_info_t *wlc, u32 macintstatus)
6677 if (!BSSCFG_STA(bsscfg) || !bsscfg->enable 6464 if (!BSSCFG_STA(bsscfg) || !bsscfg->enable
6678 || !bsscfg->BSS) 6465 || !bsscfg->BSS)
6679 continue; 6466 continue;
6680 WL_ERROR(("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n", wlc->pub->unit)); 6467 WL_ERROR("wl%d: wlc_dpc: rfdisable -> wlc_bsscfg_disable()\n",
6468 wlc->pub->unit);
6681 } 6469 }
6682 } 6470 }
6683 } 6471 }
@@ -6686,14 +6474,12 @@ void wlc_high_dpc(wlc_info_t *wlc, u32 macintstatus)
6686 if (!pktq_empty(&wlc->active_queue->q)) 6474 if (!pktq_empty(&wlc->active_queue->q))
6687 wlc_send_q(wlc, wlc->active_queue); 6475 wlc_send_q(wlc, wlc->active_queue);
6688 6476
6689#ifndef WLC_HIGH_ONLY
6690 ASSERT(wlc_ps_check(wlc)); 6477 ASSERT(wlc_ps_check(wlc));
6691#endif
6692} 6478}
6693 6479
6694static void *wlc_15420war(wlc_info_t *wlc, uint queue) 6480static void *wlc_15420war(struct wlc_info *wlc, uint queue)
6695{ 6481{
6696 hnddma_t *di; 6482 struct hnddma_pub *di;
6697 void *p; 6483 void *p;
6698 6484
6699 ASSERT(queue < NFIFO); 6485 ASSERT(queue < NFIFO);
@@ -6715,13 +6501,14 @@ static void *wlc_15420war(wlc_info_t *wlc, uint queue)
6715 if (dma_txactive(wlc->hw->di[queue]) == 0) { 6501 if (dma_txactive(wlc->hw->di[queue]) == 0) {
6716 WLCNTINCR(wlc->pub->_cnt->txdmawar); 6502 WLCNTINCR(wlc->pub->_cnt->txdmawar);
6717 if (!dma_txreset(di)) 6503 if (!dma_txreset(di))
6718 WL_ERROR(("wl%d: %s: dma_txreset[%d]: cannot stop dma\n", wlc->pub->unit, __func__, queue)); 6504 WL_ERROR("wl%d: %s: dma_txreset[%d]: cannot stop dma\n",
6505 wlc->pub->unit, __func__, queue);
6719 dma_txinit(di); 6506 dma_txinit(di);
6720 } 6507 }
6721 return p; 6508 return p;
6722} 6509}
6723 6510
6724static void wlc_war16165(wlc_info_t *wlc, bool tx) 6511static void wlc_war16165(struct wlc_info *wlc, bool tx)
6725{ 6512{
6726 if (tx) { 6513 if (tx) {
6727 /* the post-increment is used in STAY_AWAKE macro */ 6514 /* the post-increment is used in STAY_AWAKE macro */
@@ -6737,14 +6524,14 @@ static void wlc_war16165(wlc_info_t *wlc, bool tx)
6737/* process an individual tx_status_t */ 6524/* process an individual tx_status_t */
6738/* WLC_HIGH_API */ 6525/* WLC_HIGH_API */
6739bool BCMFASTPATH 6526bool BCMFASTPATH
6740wlc_dotxstatus(wlc_info_t *wlc, tx_status_t *txs, u32 frm_tx2) 6527wlc_dotxstatus(struct wlc_info *wlc, tx_status_t *txs, u32 frm_tx2)
6741{ 6528{
6742 void *p; 6529 struct sk_buff *p;
6743 uint queue; 6530 uint queue;
6744 d11txh_t *txh; 6531 d11txh_t *txh;
6745 struct scb *scb = NULL; 6532 struct scb *scb = NULL;
6746 bool free_pdu; 6533 bool free_pdu;
6747 osl_t *osh; 6534 struct osl_info *osh;
6748 int tx_rts, tx_frame_count, tx_rts_count; 6535 int tx_rts, tx_frame_count, tx_rts_count;
6749 uint totlen, supr_status; 6536 uint totlen, supr_status;
6750 bool lastframe; 6537 bool lastframe;
@@ -6768,7 +6555,7 @@ wlc_dotxstatus(wlc_info_t *wlc, tx_status_t *txs, u32 frm_tx2)
6768 ((txs-> 6555 ((txs->
6769 status & TX_STATUS_FRM_RTX_MASK) >> 6556 status & TX_STATUS_FRM_RTX_MASK) >>
6770 TX_STATUS_FRM_RTX_SHIFT)); 6557 TX_STATUS_FRM_RTX_SHIFT));
6771 WL_ERROR(("%s: INTERMEDIATE but not AMPDU\n", __func__)); 6558 WL_ERROR("%s: INTERMEDIATE but not AMPDU\n", __func__);
6772 return false; 6559 return false;
6773 } 6560 }
6774 6561
@@ -6789,12 +6576,12 @@ wlc_dotxstatus(wlc_info_t *wlc, tx_status_t *txs, u32 frm_tx2)
6789 if (p == NULL) 6576 if (p == NULL)
6790 goto fatal; 6577 goto fatal;
6791 6578
6792 txh = (d11txh_t *) PKTDATA(p); 6579 txh = (d11txh_t *) (p->data);
6793 mcl = ltoh16(txh->MacTxControlLow); 6580 mcl = ltoh16(txh->MacTxControlLow);
6794 6581
6795 if (txs->phyerr) { 6582 if (txs->phyerr) {
6796 WL_ERROR(("phyerr 0x%x, rate 0x%x\n", txs->phyerr, 6583 WL_ERROR("phyerr 0x%x, rate 0x%x\n",
6797 txh->MainRates)); 6584 txs->phyerr, txh->MainRates);
6798 wlc_print_txdesc(txh); 6585 wlc_print_txdesc(txh);
6799 wlc_print_txstatus(txs); 6586 wlc_print_txstatus(txs);
6800 } 6587 }
@@ -6825,8 +6612,8 @@ wlc_dotxstatus(wlc_info_t *wlc, tx_status_t *txs, u32 frm_tx2)
6825 6612
6826 supr_status = txs->status & TX_STATUS_SUPR_MASK; 6613 supr_status = txs->status & TX_STATUS_SUPR_MASK;
6827 if (supr_status == TX_STATUS_SUPR_BADCH) 6614 if (supr_status == TX_STATUS_SUPR_BADCH)
6828 WL_NONE(("%s: Pkt tx suppressed, possibly channel %d\n", 6615 WL_NONE("%s: Pkt tx suppressed, possibly channel %d\n",
6829 __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec))); 6616 __func__, CHSPEC_CHANNEL(wlc->default_bss->chanspec));
6830 6617
6831 tx_rts = htol16(txh->MacTxControlLow) & TXC_SENDRTS; 6618 tx_rts = htol16(txh->MacTxControlLow) & TXC_SENDRTS;
6832 tx_frame_count = 6619 tx_frame_count =
@@ -6837,7 +6624,7 @@ wlc_dotxstatus(wlc_info_t *wlc, tx_status_t *txs, u32 frm_tx2)
6837 lastframe = (fc & FC_MOREFRAG) == 0; 6624 lastframe = (fc & FC_MOREFRAG) == 0;
6838 6625
6839 if (!lastframe) { 6626 if (!lastframe) {
6840 WL_ERROR(("Not last frame!\n")); 6627 WL_ERROR("Not last frame!\n");
6841 } else { 6628 } else {
6842 u16 sfbl, lfbl; 6629 u16 sfbl, lfbl;
6843 ieee80211_tx_info_clear_status(tx_info); 6630 ieee80211_tx_info_clear_status(tx_info);
@@ -6879,17 +6666,17 @@ wlc_dotxstatus(wlc_info_t *wlc, tx_status_t *txs, u32 frm_tx2)
6879 wlc_txfifo_complete(wlc, queue, 1); 6666 wlc_txfifo_complete(wlc, queue, 1);
6880 6667
6881 if (lastframe) { 6668 if (lastframe) {
6882 PKTSETNEXT(p, NULL); 6669 p->next = NULL;
6883 PKTSETLINK(p, NULL); 6670 p->prev = NULL;
6884 wlc->txretried = 0; 6671 wlc->txretried = 0;
6885 /* remove PLCP & Broadcom tx descriptor header */ 6672 /* remove PLCP & Broadcom tx descriptor header */
6886 PKTPULL(p, D11_PHY_HDR_LEN); 6673 skb_pull(p, D11_PHY_HDR_LEN);
6887 PKTPULL(p, D11_TXH_LEN); 6674 skb_pull(p, D11_TXH_LEN);
6888 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p); 6675 ieee80211_tx_status_irqsafe(wlc->pub->ieee_hw, p);
6889 WLCNTINCR(wlc->pub->_cnt->ieee_tx_status); 6676 WLCNTINCR(wlc->pub->_cnt->ieee_tx_status);
6890 } else { 6677 } else {
6891 WL_ERROR(("%s: Not last frame => not calling tx_status\n", 6678 WL_ERROR("%s: Not last frame => not calling tx_status\n",
6892 __func__)); 6679 __func__);
6893 } 6680 }
6894 6681
6895 return false; 6682 return false;
@@ -6897,24 +6684,18 @@ wlc_dotxstatus(wlc_info_t *wlc, tx_status_t *txs, u32 frm_tx2)
6897 fatal: 6684 fatal:
6898 ASSERT(0); 6685 ASSERT(0);
6899 if (p) 6686 if (p)
6900 PKTFREE(osh, p, true); 6687 pkt_buf_free_skb(osh, p, true);
6901 6688
6902#ifdef WLC_HIGH_ONLY
6903 /* If this is a split driver, do the big-hammer here.
6904 * If this is a monolithic driver, wlc_bmac.c:wlc_dpc() will do the big-hammer.
6905 */
6906 wl_init(wlc->wl);
6907#endif
6908 return true; 6689 return true;
6909 6690
6910} 6691}
6911 6692
6912void BCMFASTPATH 6693void BCMFASTPATH
6913wlc_txfifo_complete(wlc_info_t *wlc, uint fifo, s8 txpktpend) 6694wlc_txfifo_complete(struct wlc_info *wlc, uint fifo, s8 txpktpend)
6914{ 6695{
6915 TXPKTPENDDEC(wlc, fifo, txpktpend); 6696 TXPKTPENDDEC(wlc, fifo, txpktpend);
6916 WL_TRACE(("wlc_txfifo_complete, pktpend dec %d to %d\n", txpktpend, 6697 WL_TRACE("wlc_txfifo_complete, pktpend dec %d to %d\n",
6917 TXPKTPENDGET(wlc, fifo))); 6698 txpktpend, TXPKTPENDGET(wlc, fifo));
6918 6699
6919 /* There is more room; mark precedences related to this FIFO sendable */ 6700 /* There is more room; mark precedences related to this FIFO sendable */
6920 WLC_TX_FIFO_ENAB(wlc, fifo); 6701 WLC_TX_FIFO_ENAB(wlc, fifo);
@@ -7014,7 +6795,7 @@ u32 wlc_calc_tbtt_offset(u32 bp, u32 tsf_h, u32 tsf_l)
7014} 6795}
7015 6796
7016/* Update beacon listen interval in shared memory */ 6797/* Update beacon listen interval in shared memory */
7017void wlc_bcn_li_upd(wlc_info_t *wlc) 6798void wlc_bcn_li_upd(struct wlc_info *wlc)
7018{ 6799{
7019 if (AP_ENAB(wlc->pub)) 6800 if (AP_ENAB(wlc->pub))
7020 return; 6801 return;
@@ -7028,7 +6809,7 @@ void wlc_bcn_li_upd(wlc_info_t *wlc)
7028} 6809}
7029 6810
7030static void 6811static void
7031prep_mac80211_status(wlc_info_t *wlc, d11rxhdr_t *rxh, void *p, 6812prep_mac80211_status(struct wlc_info *wlc, d11rxhdr_t *rxh, struct sk_buff *p,
7032 struct ieee80211_rx_status *rx_status) 6813 struct ieee80211_rx_status *rx_status)
7033{ 6814{
7034 u32 tsf_l, tsf_h; 6815 u32 tsf_l, tsf_h;
@@ -7061,7 +6842,7 @@ prep_mac80211_status(wlc_info_t *wlc, d11rxhdr_t *rxh, void *p,
7061 /* qual */ 6842 /* qual */
7062 rx_status->antenna = (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; /* ant */ 6843 rx_status->antenna = (rxh->PhyRxStatus_0 & PRXS0_RXANT_UPSUBBAND) ? 1 : 0; /* ant */
7063 6844
7064 plcp = PKTDATA(p); 6845 plcp = p->data;
7065 6846
7066 rspec = wlc_compute_rspec(rxh, plcp); 6847 rspec = wlc_compute_rspec(rxh, plcp);
7067 if (IS_MCS(rspec)) { 6848 if (IS_MCS(rspec)) {
@@ -7108,19 +6889,19 @@ prep_mac80211_status(wlc_info_t *wlc, d11rxhdr_t *rxh, void *p,
7108 rx_status->rate_idx = 11; 6889 rx_status->rate_idx = 11;
7109 break; 6890 break;
7110 default: 6891 default:
7111 WL_ERROR(("%s: Unknown rate\n", __func__)); 6892 WL_ERROR("%s: Unknown rate\n", __func__);
7112 } 6893 }
7113 6894
7114 /* Determine short preamble and rate_idx */ 6895 /* Determine short preamble and rate_idx */
7115 preamble = 0; 6896 preamble = 0;
7116 if (IS_CCK(rspec)) { 6897 if (IS_CCK(rspec)) {
7117 if (rxh->PhyRxStatus_0 & PRXS0_SHORTH) 6898 if (rxh->PhyRxStatus_0 & PRXS0_SHORTH)
7118 WL_ERROR(("Short CCK\n")); 6899 WL_ERROR("Short CCK\n");
7119 rx_status->flag |= RX_FLAG_SHORTPRE; 6900 rx_status->flag |= RX_FLAG_SHORTPRE;
7120 } else if (IS_OFDM(rspec)) { 6901 } else if (IS_OFDM(rspec)) {
7121 rx_status->flag |= RX_FLAG_SHORTPRE; 6902 rx_status->flag |= RX_FLAG_SHORTPRE;
7122 } else { 6903 } else {
7123 WL_ERROR(("%s: Unknown modulation\n", __func__)); 6904 WL_ERROR("%s: Unknown modulation\n", __func__);
7124 } 6905 }
7125 } 6906 }
7126 6907
@@ -7129,16 +6910,17 @@ prep_mac80211_status(wlc_info_t *wlc, d11rxhdr_t *rxh, void *p,
7129 6910
7130 if (rxh->RxStatus1 & RXS_DECERR) { 6911 if (rxh->RxStatus1 & RXS_DECERR) {
7131 rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC; 6912 rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC;
7132 WL_ERROR(("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__)); 6913 WL_ERROR("%s: RX_FLAG_FAILED_PLCP_CRC\n", __func__);
7133 } 6914 }
7134 if (rxh->RxStatus1 & RXS_FCSERR) { 6915 if (rxh->RxStatus1 & RXS_FCSERR) {
7135 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; 6916 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
7136 WL_ERROR(("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__)); 6917 WL_ERROR("%s: RX_FLAG_FAILED_FCS_CRC\n", __func__);
7137 } 6918 }
7138} 6919}
7139 6920
7140static void 6921static void
7141wlc_recvctl(wlc_info_t *wlc, osl_t *osh, d11rxhdr_t *rxh, void *p) 6922wlc_recvctl(struct wlc_info *wlc, struct osl_info *osh, d11rxhdr_t *rxh,
6923 struct sk_buff *p)
7142{ 6924{
7143 int len_mpdu; 6925 int len_mpdu;
7144 struct ieee80211_rx_status rx_status; 6926 struct ieee80211_rx_status rx_status;
@@ -7155,12 +6937,12 @@ wlc_recvctl(wlc_info_t *wlc, osl_t *osh, d11rxhdr_t *rxh, void *p)
7155 prep_mac80211_status(wlc, rxh, p, &rx_status); 6937 prep_mac80211_status(wlc, rxh, p, &rx_status);
7156 6938
7157 /* mac header+body length, exclude CRC and plcp header */ 6939 /* mac header+body length, exclude CRC and plcp header */
7158 len_mpdu = PKTLEN(p) - D11_PHY_HDR_LEN - DOT11_FCS_LEN; 6940 len_mpdu = p->len - D11_PHY_HDR_LEN - DOT11_FCS_LEN;
7159 PKTPULL(p, D11_PHY_HDR_LEN); 6941 skb_pull(p, D11_PHY_HDR_LEN);
7160 PKTSETLEN(p, len_mpdu); 6942 __skb_trim(p, len_mpdu);
7161 6943
7162 ASSERT(!PKTNEXT(p)); 6944 ASSERT(!(p->next));
7163 ASSERT(!PKTLINK(p)); 6945 ASSERT(!(p->prev));
7164 6946
7165 ASSERT(IS_ALIGNED((unsigned long)skb->data, 2)); 6947 ASSERT(IS_ALIGNED((unsigned long)skb->data, 2));
7166 6948
@@ -7168,17 +6950,17 @@ wlc_recvctl(wlc_info_t *wlc, osl_t *osh, d11rxhdr_t *rxh, void *p)
7168 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p); 6950 ieee80211_rx_irqsafe(wlc->pub->ieee_hw, p);
7169 6951
7170 WLCNTINCR(wlc->pub->_cnt->ieee_rx); 6952 WLCNTINCR(wlc->pub->_cnt->ieee_rx);
7171 PKTUNALLOC(osh); 6953 osh->pktalloced--;
7172 return; 6954 return;
7173} 6955}
7174 6956
7175void wlc_bss_list_free(wlc_info_t *wlc, wlc_bss_list_t *bss_list) 6957void wlc_bss_list_free(struct wlc_info *wlc, wlc_bss_list_t *bss_list)
7176{ 6958{
7177 uint index; 6959 uint index;
7178 wlc_bss_info_t *bi; 6960 wlc_bss_info_t *bi;
7179 6961
7180 if (!bss_list) { 6962 if (!bss_list) {
7181 WL_ERROR(("%s: Attempting to free NULL list\n", __func__)); 6963 WL_ERROR("%s: Attempting to free NULL list\n", __func__);
7182 return; 6964 return;
7183 } 6965 }
7184 /* inspect all BSS descriptor */ 6966 /* inspect all BSS descriptor */
@@ -7201,48 +6983,48 @@ void wlc_bss_list_free(wlc_info_t *wlc, wlc_bss_list_t *bss_list)
7201 * Param 'bound' indicates max. # frames to process before break out. 6983 * Param 'bound' indicates max. # frames to process before break out.
7202 */ 6984 */
7203/* WLC_HIGH_API */ 6985/* WLC_HIGH_API */
7204void BCMFASTPATH wlc_recv(wlc_info_t *wlc, void *p) 6986void BCMFASTPATH wlc_recv(struct wlc_info *wlc, struct sk_buff *p)
7205{ 6987{
7206 d11rxhdr_t *rxh; 6988 d11rxhdr_t *rxh;
7207 struct dot11_header *h; 6989 struct dot11_header *h;
7208 osl_t *osh; 6990 struct osl_info *osh;
7209 u16 fc; 6991 u16 fc;
7210 uint len; 6992 uint len;
7211 bool is_amsdu; 6993 bool is_amsdu;
7212 6994
7213 WL_TRACE(("wl%d: wlc_recv\n", wlc->pub->unit)); 6995 WL_TRACE("wl%d: wlc_recv\n", wlc->pub->unit);
7214 6996
7215 osh = wlc->osh; 6997 osh = wlc->osh;
7216 6998
7217 /* frame starts with rxhdr */ 6999 /* frame starts with rxhdr */
7218 rxh = (d11rxhdr_t *) PKTDATA(p); 7000 rxh = (d11rxhdr_t *) (p->data);
7219 7001
7220 /* strip off rxhdr */ 7002 /* strip off rxhdr */
7221 PKTPULL(p, wlc->hwrxoff); 7003 skb_pull(p, wlc->hwrxoff);
7222 7004
7223 /* fixup rx header endianness */ 7005 /* fixup rx header endianness */
7224 ltoh16_buf((void *)rxh, sizeof(d11rxhdr_t)); 7006 ltoh16_buf((void *)rxh, sizeof(d11rxhdr_t));
7225 7007
7226 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */ 7008 /* MAC inserts 2 pad bytes for a4 headers or QoS or A-MSDU subframes */
7227 if (rxh->RxStatus1 & RXS_PBPRES) { 7009 if (rxh->RxStatus1 & RXS_PBPRES) {
7228 if (PKTLEN(p) < 2) { 7010 if (p->len < 2) {
7229 WLCNTINCR(wlc->pub->_cnt->rxrunt); 7011 WLCNTINCR(wlc->pub->_cnt->rxrunt);
7230 WL_ERROR(("wl%d: wlc_recv: rcvd runt of len %d\n", 7012 WL_ERROR("wl%d: wlc_recv: rcvd runt of len %d\n",
7231 wlc->pub->unit, PKTLEN(p))); 7013 wlc->pub->unit, p->len);
7232 goto toss; 7014 goto toss;
7233 } 7015 }
7234 PKTPULL(p, 2); 7016 skb_pull(p, 2);
7235 } 7017 }
7236 7018
7237 h = (struct dot11_header *)(PKTDATA(p) + D11_PHY_HDR_LEN); 7019 h = (struct dot11_header *)(p->data + D11_PHY_HDR_LEN);
7238 len = PKTLEN(p); 7020 len = p->len;
7239 7021
7240 if (rxh->RxStatus1 & RXS_FCSERR) { 7022 if (rxh->RxStatus1 & RXS_FCSERR) {
7241 if (wlc->pub->mac80211_state & MAC80211_PROMISC_BCNS) { 7023 if (wlc->pub->mac80211_state & MAC80211_PROMISC_BCNS) {
7242 WL_ERROR(("FCSERR while scanning******* - tossing\n")); 7024 WL_ERROR("FCSERR while scanning******* - tossing\n");
7243 goto toss; 7025 goto toss;
7244 } else { 7026 } else {
7245 WL_ERROR(("RCSERR!!!\n")); 7027 WL_ERROR("RCSERR!!!\n");
7246 goto toss; 7028 goto toss;
7247 } 7029 }
7248 } 7030 }
@@ -7261,10 +7043,10 @@ void BCMFASTPATH wlc_recv(wlc_info_t *wlc, void *p)
7261 if (!is_amsdu) { 7043 if (!is_amsdu) {
7262 /* CTS and ACK CTL frames are w/o a2 */ 7044 /* CTS and ACK CTL frames are w/o a2 */
7263 if (FC_TYPE(fc) == FC_TYPE_DATA || FC_TYPE(fc) == FC_TYPE_MNG) { 7045 if (FC_TYPE(fc) == FC_TYPE_DATA || FC_TYPE(fc) == FC_TYPE_MNG) {
7264 if ((ETHER_ISNULLADDR(&h->a2) || ETHER_ISMULTI(&h->a2))) { 7046 if ((is_zero_ether_addr(h->a2.octet) ||
7265 WL_ERROR(("wl%d: %s: dropping a frame with " 7047 is_multicast_ether_addr(h->a2.octet))) {
7266 "invalid src mac address, a2: %pM\n", 7048 WL_ERROR("wl%d: %s: dropping a frame with invalid src mac address, a2: %pM\n",
7267 wlc->pub->unit, __func__, &h->a2)); 7049 wlc->pub->unit, __func__, &h->a2);
7268 WLCNTINCR(wlc->pub->_cnt->rxbadsrcmac); 7050 WLCNTINCR(wlc->pub->_cnt->rxbadsrcmac);
7269 goto toss; 7051 goto toss;
7270 } 7052 }
@@ -7279,7 +7061,7 @@ void BCMFASTPATH wlc_recv(wlc_info_t *wlc, void *p)
7279 } 7061 }
7280 7062
7281 if (is_amsdu) { 7063 if (is_amsdu) {
7282 WL_ERROR(("%s: is_amsdu causing toss\n", __func__)); 7064 WL_ERROR("%s: is_amsdu causing toss\n", __func__);
7283 goto toss; 7065 goto toss;
7284 } 7066 }
7285 7067
@@ -7287,7 +7069,7 @@ void BCMFASTPATH wlc_recv(wlc_info_t *wlc, void *p)
7287 return; 7069 return;
7288 7070
7289 toss: 7071 toss:
7290 PKTFREE(osh, p, false); 7072 pkt_buf_free_skb(osh, p, false);
7291} 7073}
7292 7074
7293/* calculate frame duration for Mixed-mode L-SIG spoofing, return 7075/* calculate frame duration for Mixed-mode L-SIG spoofing, return
@@ -7297,12 +7079,12 @@ void BCMFASTPATH wlc_recv(wlc_info_t *wlc, void *p)
7297 * len = 3(nsyms + nstream + 3) - 3 7079 * len = 3(nsyms + nstream + 3) - 3
7298 */ 7080 */
7299u16 BCMFASTPATH 7081u16 BCMFASTPATH
7300wlc_calc_lsig_len(wlc_info_t *wlc, ratespec_t ratespec, uint mac_len) 7082wlc_calc_lsig_len(struct wlc_info *wlc, ratespec_t ratespec, uint mac_len)
7301{ 7083{
7302 uint nsyms, len = 0, kNdps; 7084 uint nsyms, len = 0, kNdps;
7303 7085
7304 WL_TRACE(("wl%d: wlc_calc_lsig_len: rate %d, len%d\n", wlc->pub->unit, 7086 WL_TRACE("wl%d: wlc_calc_lsig_len: rate %d, len%d\n",
7305 RSPEC2RATE(ratespec), mac_len)); 7087 wlc->pub->unit, RSPEC2RATE(ratespec), mac_len);
7306 7088
7307 if (IS_MCS(ratespec)) { 7089 if (IS_MCS(ratespec)) {
7308 uint mcs = ratespec & RSPEC_RATE_MASK; 7090 uint mcs = ratespec & RSPEC_RATE_MASK;
@@ -7338,7 +7120,7 @@ wlc_calc_lsig_len(wlc_info_t *wlc, ratespec_t ratespec, uint mac_len)
7338 7120
7339/* calculate frame duration of a given rate and length, return time in usec unit */ 7121/* calculate frame duration of a given rate and length, return time in usec unit */
7340uint BCMFASTPATH 7122uint BCMFASTPATH
7341wlc_calc_frame_time(wlc_info_t *wlc, ratespec_t ratespec, u8 preamble_type, 7123wlc_calc_frame_time(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7342 uint mac_len) 7124 uint mac_len)
7343{ 7125{
7344 uint nsyms, dur = 0, Ndps, kNdps; 7126 uint nsyms, dur = 0, Ndps, kNdps;
@@ -7346,11 +7128,12 @@ wlc_calc_frame_time(wlc_info_t *wlc, ratespec_t ratespec, u8 preamble_type,
7346 7128
7347 if (rate == 0) { 7129 if (rate == 0) {
7348 ASSERT(0); 7130 ASSERT(0);
7349 WL_ERROR(("wl%d: WAR: using rate of 1 mbps\n", wlc->pub->unit)); 7131 WL_ERROR("wl%d: WAR: using rate of 1 mbps\n", wlc->pub->unit);
7350 rate = WLC_RATE_1M; 7132 rate = WLC_RATE_1M;
7351 } 7133 }
7352 7134
7353 WL_TRACE(("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n", wlc->pub->unit, ratespec, preamble_type, mac_len)); 7135 WL_TRACE("wl%d: wlc_calc_frame_time: rspec 0x%x, preamble_type %d, len%d\n",
7136 wlc->pub->unit, ratespec, preamble_type, mac_len);
7354 7137
7355 if (IS_MCS(ratespec)) { 7138 if (IS_MCS(ratespec)) {
7356 uint mcs = ratespec & RSPEC_RATE_MASK; 7139 uint mcs = ratespec & RSPEC_RATE_MASK;
@@ -7408,13 +7191,14 @@ wlc_calc_frame_time(wlc_info_t *wlc, ratespec_t ratespec, u8 preamble_type,
7408 7191
7409/* The opposite of wlc_calc_frame_time */ 7192/* The opposite of wlc_calc_frame_time */
7410static uint 7193static uint
7411wlc_calc_frame_len(wlc_info_t *wlc, ratespec_t ratespec, u8 preamble_type, 7194wlc_calc_frame_len(struct wlc_info *wlc, ratespec_t ratespec, u8 preamble_type,
7412 uint dur) 7195 uint dur)
7413{ 7196{
7414 uint nsyms, mac_len, Ndps, kNdps; 7197 uint nsyms, mac_len, Ndps, kNdps;
7415 uint rate = RSPEC2RATE(ratespec); 7198 uint rate = RSPEC2RATE(ratespec);
7416 7199
7417 WL_TRACE(("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n", wlc->pub->unit, ratespec, preamble_type, dur)); 7200 WL_TRACE("wl%d: wlc_calc_frame_len: rspec 0x%x, preamble_type %d, dur %d\n",
7201 wlc->pub->unit, ratespec, preamble_type, dur);
7418 7202
7419 if (IS_MCS(ratespec)) { 7203 if (IS_MCS(ratespec)) {
7420 uint mcs = ratespec & RSPEC_RATE_MASK; 7204 uint mcs = ratespec & RSPEC_RATE_MASK;
@@ -7454,10 +7238,10 @@ wlc_calc_frame_len(wlc_info_t *wlc, ratespec_t ratespec, u8 preamble_type,
7454} 7238}
7455 7239
7456static uint 7240static uint
7457wlc_calc_ba_time(wlc_info_t *wlc, ratespec_t rspec, u8 preamble_type) 7241wlc_calc_ba_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7458{ 7242{
7459 WL_TRACE(("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n", 7243 WL_TRACE("wl%d: wlc_calc_ba_time: rspec 0x%x, preamble_type %d\n",
7460 wlc->pub->unit, rspec, preamble_type)); 7244 wlc->pub->unit, rspec, preamble_type);
7461 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than 7245 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7462 * or equal to the rate of the immediately previous frame in the FES 7246 * or equal to the rate of the immediately previous frame in the FES
7463 */ 7247 */
@@ -7471,12 +7255,12 @@ wlc_calc_ba_time(wlc_info_t *wlc, ratespec_t rspec, u8 preamble_type)
7471} 7255}
7472 7256
7473static uint BCMFASTPATH 7257static uint BCMFASTPATH
7474wlc_calc_ack_time(wlc_info_t *wlc, ratespec_t rspec, u8 preamble_type) 7258wlc_calc_ack_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7475{ 7259{
7476 uint dur = 0; 7260 uint dur = 0;
7477 7261
7478 WL_TRACE(("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n", 7262 WL_TRACE("wl%d: wlc_calc_ack_time: rspec 0x%x, preamble_type %d\n",
7479 wlc->pub->unit, rspec, preamble_type)); 7263 wlc->pub->unit, rspec, preamble_type);
7480 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than 7264 /* Spec 9.6: ack rate is the highest rate in BSSBasicRateSet that is less than
7481 * or equal to the rate of the immediately previous frame in the FES 7265 * or equal to the rate of the immediately previous frame in the FES
7482 */ 7266 */
@@ -7491,15 +7275,15 @@ wlc_calc_ack_time(wlc_info_t *wlc, ratespec_t rspec, u8 preamble_type)
7491} 7275}
7492 7276
7493static uint 7277static uint
7494wlc_calc_cts_time(wlc_info_t *wlc, ratespec_t rspec, u8 preamble_type) 7278wlc_calc_cts_time(struct wlc_info *wlc, ratespec_t rspec, u8 preamble_type)
7495{ 7279{
7496 WL_TRACE(("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n", 7280 WL_TRACE("wl%d: wlc_calc_cts_time: ratespec 0x%x, preamble_type %d\n",
7497 wlc->pub->unit, rspec, preamble_type)); 7281 wlc->pub->unit, rspec, preamble_type);
7498 return wlc_calc_ack_time(wlc, rspec, preamble_type); 7282 return wlc_calc_ack_time(wlc, rspec, preamble_type);
7499} 7283}
7500 7284
7501/* derive wlc->band->basic_rate[] table from 'rateset' */ 7285/* derive wlc->band->basic_rate[] table from 'rateset' */
7502void wlc_rate_lookup_init(wlc_info_t *wlc, wlc_rateset_t *rateset) 7286void wlc_rate_lookup_init(struct wlc_info *wlc, wlc_rateset_t *rateset)
7503{ 7287{
7504 u8 rate; 7288 u8 rate;
7505 u8 mandatory; 7289 u8 mandatory;
@@ -7509,7 +7293,7 @@ void wlc_rate_lookup_init(wlc_info_t *wlc, wlc_rateset_t *rateset)
7509 uint i; 7293 uint i;
7510 7294
7511 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */ 7295 /* incoming rates are in 500kbps units as in 802.11 Supported Rates */
7512 bzero(br, WLC_MAXRATE + 1); 7296 memset(br, 0, WLC_MAXRATE + 1);
7513 7297
7514 /* For each basic rate in the rates list, make an entry in the 7298 /* For each basic rate in the rates list, make an entry in the
7515 * best basic lookup. 7299 * best basic lookup.
@@ -7523,7 +7307,8 @@ void wlc_rate_lookup_init(wlc_info_t *wlc, wlc_rateset_t *rateset)
7523 rate = (rateset->rates[i] & RATE_MASK); 7307 rate = (rateset->rates[i] & RATE_MASK);
7524 7308
7525 if (rate > WLC_MAXRATE) { 7309 if (rate > WLC_MAXRATE) {
7526 WL_ERROR(("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n", rateset->rates[i])); 7310 WL_ERROR("wlc_rate_lookup_init: invalid rate 0x%X in rate set\n",
7311 rateset->rates[i]);
7527 continue; 7312 continue;
7528 } 7313 }
7529 7314
@@ -7588,7 +7373,7 @@ void wlc_rate_lookup_init(wlc_info_t *wlc, wlc_rateset_t *rateset)
7588 } 7373 }
7589} 7374}
7590 7375
7591static void wlc_write_rate_shm(wlc_info_t *wlc, u8 rate, u8 basic_rate) 7376static void wlc_write_rate_shm(struct wlc_info *wlc, u8 rate, u8 basic_rate)
7592{ 7377{
7593 u8 phy_rate, index; 7378 u8 phy_rate, index;
7594 u8 basic_phy_rate, basic_index; 7379 u8 basic_phy_rate, basic_index;
@@ -7621,7 +7406,7 @@ static void wlc_write_rate_shm(wlc_info_t *wlc, u8 rate, u8 basic_rate)
7621 wlc_write_shm(wlc, (basic_table + index * 2), basic_ptr); 7406 wlc_write_shm(wlc, (basic_table + index * 2), basic_ptr);
7622} 7407}
7623 7408
7624static const wlc_rateset_t *wlc_rateset_get_hwrs(wlc_info_t *wlc) 7409static const wlc_rateset_t *wlc_rateset_get_hwrs(struct wlc_info *wlc)
7625{ 7410{
7626 const wlc_rateset_t *rs_dflt; 7411 const wlc_rateset_t *rs_dflt;
7627 7412
@@ -7638,7 +7423,7 @@ static const wlc_rateset_t *wlc_rateset_get_hwrs(wlc_info_t *wlc)
7638 return rs_dflt; 7423 return rs_dflt;
7639} 7424}
7640 7425
7641void wlc_set_ratetable(wlc_info_t *wlc) 7426void wlc_set_ratetable(struct wlc_info *wlc)
7642{ 7427{
7643 const wlc_rateset_t *rs_dflt; 7428 const wlc_rateset_t *rs_dflt;
7644 wlc_rateset_t rs; 7429 wlc_rateset_t rs;
@@ -7674,7 +7459,8 @@ void wlc_set_ratetable(wlc_info_t *wlc)
7674 * Return true if the specified rate is supported by the specified band. 7459 * Return true if the specified rate is supported by the specified band.
7675 * WLC_BAND_AUTO indicates the current band. 7460 * WLC_BAND_AUTO indicates the current band.
7676 */ 7461 */
7677bool wlc_valid_rate(wlc_info_t *wlc, ratespec_t rspec, int band, bool verbose) 7462bool wlc_valid_rate(struct wlc_info *wlc, ratespec_t rspec, int band,
7463 bool verbose)
7678{ 7464{
7679 wlc_rateset_t *hw_rateset; 7465 wlc_rateset_t *hw_rateset;
7680 uint i; 7466 uint i;
@@ -7701,16 +7487,17 @@ bool wlc_valid_rate(wlc_info_t *wlc, ratespec_t rspec, int band, bool verbose)
7701 return true; 7487 return true;
7702 error: 7488 error:
7703 if (verbose) { 7489 if (verbose) {
7704 WL_ERROR(("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n", wlc->pub->unit, rspec)); 7490 WL_ERROR("wl%d: wlc_valid_rate: rate spec 0x%x not in hw_rateset\n",
7491 wlc->pub->unit, rspec);
7705 } 7492 }
7706 7493
7707 return false; 7494 return false;
7708} 7495}
7709 7496
7710static void wlc_update_mimo_band_bwcap(wlc_info_t *wlc, u8 bwcap) 7497static void wlc_update_mimo_band_bwcap(struct wlc_info *wlc, u8 bwcap)
7711{ 7498{
7712 uint i; 7499 uint i;
7713 wlcband_t *band; 7500 struct wlcband *band;
7714 7501
7715 for (i = 0; i < NBANDS(wlc); i++) { 7502 for (i = 0; i < NBANDS(wlc); i++) {
7716 if (IS_SINGLEBAND_5G(wlc->deviceid)) 7503 if (IS_SINGLEBAND_5G(wlc->deviceid))
@@ -7734,7 +7521,7 @@ static void wlc_update_mimo_band_bwcap(wlc_info_t *wlc, u8 bwcap)
7734 wlc->mimo_band_bwcap = bwcap; 7521 wlc->mimo_band_bwcap = bwcap;
7735} 7522}
7736 7523
7737void wlc_mod_prb_rsp_rate_table(wlc_info_t *wlc, uint frame_len) 7524void wlc_mod_prb_rsp_rate_table(struct wlc_info *wlc, uint frame_len)
7738{ 7525{
7739 const wlc_rateset_t *rs_dflt; 7526 const wlc_rateset_t *rs_dflt;
7740 wlc_rateset_t rs; 7527 wlc_rateset_t rs;
@@ -7777,14 +7564,14 @@ void wlc_mod_prb_rsp_rate_table(wlc_info_t *wlc, uint frame_len)
7777} 7564}
7778 7565
7779u16 7566u16
7780wlc_compute_bcntsfoff(wlc_info_t *wlc, ratespec_t rspec, bool short_preamble, 7567wlc_compute_bcntsfoff(struct wlc_info *wlc, ratespec_t rspec,
7781 bool phydelay) 7568 bool short_preamble, bool phydelay)
7782{ 7569{
7783 uint bcntsfoff = 0; 7570 uint bcntsfoff = 0;
7784 7571
7785 if (IS_MCS(rspec)) { 7572 if (IS_MCS(rspec)) {
7786 WL_ERROR(("wl%d: recd beacon with mcs rate; rspec 0x%x\n", 7573 WL_ERROR("wl%d: recd beacon with mcs rate; rspec 0x%x\n",
7787 wlc->pub->unit, rspec)); 7574 wlc->pub->unit, rspec);
7788 } else if (IS_OFDM(rspec)) { 7575 } else if (IS_OFDM(rspec)) {
7789 /* tx delay from MAC through phy to air (2.1 usec) + 7576 /* tx delay from MAC through phy to air (2.1 usec) +
7790 * phy header time (preamble + PLCP SIGNAL == 20 usec) + 7577 * phy header time (preamble + PLCP SIGNAL == 20 usec) +
@@ -7824,7 +7611,7 @@ wlc_compute_bcntsfoff(wlc_info_t *wlc, ratespec_t rspec, bool short_preamble,
7824 * and included up to, but not including, the 4 byte FCS. 7611 * and included up to, but not including, the 4 byte FCS.
7825 */ 7612 */
7826static void 7613static void
7827wlc_bcn_prb_template(wlc_info_t *wlc, uint type, ratespec_t bcn_rspec, 7614wlc_bcn_prb_template(struct wlc_info *wlc, uint type, ratespec_t bcn_rspec,
7828 wlc_bsscfg_t *cfg, u16 *buf, int *len) 7615 wlc_bsscfg_t *cfg, u16 *buf, int *len)
7829{ 7616{
7830 cck_phy_hdr_t *plcp; 7617 cck_phy_hdr_t *plcp;
@@ -7843,7 +7630,7 @@ wlc_bcn_prb_template(wlc_info_t *wlc, uint type, ratespec_t bcn_rspec,
7843 *len = hdr_len + body_len; /* return actual size */ 7630 *len = hdr_len + body_len; /* return actual size */
7844 7631
7845 /* format PHY and MAC headers */ 7632 /* format PHY and MAC headers */
7846 bzero((char *)buf, hdr_len); 7633 memset((char *)buf, 0, hdr_len);
7847 7634
7848 plcp = (cck_phy_hdr_t *) buf; 7635 plcp = (cck_phy_hdr_t *) buf;
7849 7636
@@ -7872,9 +7659,9 @@ wlc_bcn_prb_template(wlc_info_t *wlc, uint type, ratespec_t bcn_rspec,
7872 /* A1 filled in by MAC for prb resp, broadcast for bcn */ 7659 /* A1 filled in by MAC for prb resp, broadcast for bcn */
7873 if (type == FC_BEACON) 7660 if (type == FC_BEACON)
7874 bcopy((const char *)&ether_bcast, (char *)&h->da, 7661 bcopy((const char *)&ether_bcast, (char *)&h->da,
7875 ETHER_ADDR_LEN); 7662 ETH_ALEN);
7876 bcopy((char *)&cfg->cur_etheraddr, (char *)&h->sa, ETHER_ADDR_LEN); 7663 bcopy((char *)&cfg->cur_etheraddr, (char *)&h->sa, ETH_ALEN);
7877 bcopy((char *)&cfg->BSSID, (char *)&h->bssid, ETHER_ADDR_LEN); 7664 bcopy((char *)&cfg->BSSID, (char *)&h->bssid, ETH_ALEN);
7878 7665
7879 /* SEQ filled in by MAC */ 7666 /* SEQ filled in by MAC */
7880 7667
@@ -7891,7 +7678,7 @@ int wlc_get_header_len()
7891 * template updated. 7678 * template updated.
7892 * Otherwise, it updates the hardware template. 7679 * Otherwise, it updates the hardware template.
7893 */ 7680 */
7894void wlc_bss_update_beacon(wlc_info_t *wlc, wlc_bsscfg_t *cfg) 7681void wlc_bss_update_beacon(struct wlc_info *wlc, wlc_bsscfg_t *cfg)
7895{ 7682{
7896 int len = BCN_TMPL_LEN; 7683 int len = BCN_TMPL_LEN;
7897 7684
@@ -7907,7 +7694,7 @@ void wlc_bss_update_beacon(wlc_info_t *wlc, wlc_bsscfg_t *cfg)
7907 u16 bcn[BCN_TMPL_LEN / 2]; 7694 u16 bcn[BCN_TMPL_LEN / 2];
7908 u32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD; 7695 u32 both_valid = MCMD_BCN0VLD | MCMD_BCN1VLD;
7909 d11regs_t *regs = wlc->regs; 7696 d11regs_t *regs = wlc->regs;
7910 osl_t *osh = NULL; 7697 struct osl_info *osh = NULL;
7911 7698
7912 osh = wlc->osh; 7699 osh = wlc->osh;
7913 7700
@@ -7944,7 +7731,7 @@ void wlc_bss_update_beacon(wlc_info_t *wlc, wlc_bsscfg_t *cfg)
7944/* 7731/*
7945 * Update all beacons for the system. 7732 * Update all beacons for the system.
7946 */ 7733 */
7947void wlc_update_beacon(wlc_info_t *wlc) 7734void wlc_update_beacon(struct wlc_info *wlc)
7948{ 7735{
7949 int idx; 7736 int idx;
7950 wlc_bsscfg_t *bsscfg; 7737 wlc_bsscfg_t *bsscfg;
@@ -7957,14 +7744,14 @@ void wlc_update_beacon(wlc_info_t *wlc)
7957} 7744}
7958 7745
7959/* Write ssid into shared memory */ 7746/* Write ssid into shared memory */
7960void wlc_shm_ssid_upd(wlc_info_t *wlc, wlc_bsscfg_t *cfg) 7747void wlc_shm_ssid_upd(struct wlc_info *wlc, wlc_bsscfg_t *cfg)
7961{ 7748{
7962 u8 *ssidptr = cfg->SSID; 7749 u8 *ssidptr = cfg->SSID;
7963 u16 base = M_SSID; 7750 u16 base = M_SSID;
7964 u8 ssidbuf[DOT11_MAX_SSID_LEN]; 7751 u8 ssidbuf[DOT11_MAX_SSID_LEN];
7965 7752
7966 /* padding the ssid with zero and copy it into shm */ 7753 /* padding the ssid with zero and copy it into shm */
7967 bzero(ssidbuf, DOT11_MAX_SSID_LEN); 7754 memset(ssidbuf, 0, DOT11_MAX_SSID_LEN);
7968 bcopy(ssidptr, ssidbuf, cfg->SSID_len); 7755 bcopy(ssidptr, ssidbuf, cfg->SSID_len);
7969 7756
7970 wlc_copyto_shm(wlc, base, ssidbuf, DOT11_MAX_SSID_LEN); 7757 wlc_copyto_shm(wlc, base, ssidbuf, DOT11_MAX_SSID_LEN);
@@ -7973,7 +7760,7 @@ void wlc_shm_ssid_upd(wlc_info_t *wlc, wlc_bsscfg_t *cfg)
7973 wlc_write_shm(wlc, M_SSIDLEN, (u16) cfg->SSID_len); 7760 wlc_write_shm(wlc, M_SSIDLEN, (u16) cfg->SSID_len);
7974} 7761}
7975 7762
7976void wlc_update_probe_resp(wlc_info_t *wlc, bool suspend) 7763void wlc_update_probe_resp(struct wlc_info *wlc, bool suspend)
7977{ 7764{
7978 int idx; 7765 int idx;
7979 wlc_bsscfg_t *bsscfg; 7766 wlc_bsscfg_t *bsscfg;
@@ -7986,7 +7773,7 @@ void wlc_update_probe_resp(wlc_info_t *wlc, bool suspend)
7986} 7773}
7987 7774
7988void 7775void
7989wlc_bss_update_probe_resp(wlc_info_t *wlc, wlc_bsscfg_t *cfg, bool suspend) 7776wlc_bss_update_probe_resp(struct wlc_info *wlc, wlc_bsscfg_t *cfg, bool suspend)
7990{ 7777{
7991 u16 prb_resp[BCN_TMPL_LEN / 2]; 7778 u16 prb_resp[BCN_TMPL_LEN / 2];
7992 int len = BCN_TMPL_LEN; 7779 int len = BCN_TMPL_LEN;
@@ -8027,9 +7814,9 @@ wlc_bss_update_probe_resp(wlc_info_t *wlc, wlc_bsscfg_t *cfg, bool suspend)
8027} 7814}
8028 7815
8029/* prepares pdu for transmission. returns BCM error codes */ 7816/* prepares pdu for transmission. returns BCM error codes */
8030int wlc_prep_pdu(wlc_info_t *wlc, void *pdu, uint *fifop) 7817int wlc_prep_pdu(struct wlc_info *wlc, struct sk_buff *pdu, uint *fifop)
8031{ 7818{
8032 osl_t *osh; 7819 struct osl_info *osh;
8033 uint fifo; 7820 uint fifo;
8034 d11txh_t *txh; 7821 d11txh_t *txh;
8035 struct dot11_header *h; 7822 struct dot11_header *h;
@@ -8039,7 +7826,7 @@ int wlc_prep_pdu(wlc_info_t *wlc, void *pdu, uint *fifop)
8039 osh = wlc->osh; 7826 osh = wlc->osh;
8040 7827
8041 ASSERT(pdu); 7828 ASSERT(pdu);
8042 txh = (d11txh_t *) PKTDATA(pdu); 7829 txh = (d11txh_t *) (pdu->data);
8043 ASSERT(txh); 7830 ASSERT(txh);
8044 h = (struct dot11_header *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN); 7831 h = (struct dot11_header *)((u8 *) (txh + 1) + D11_PHY_HDR_LEN);
8045 ASSERT(h); 7832 ASSERT(h);
@@ -8066,7 +7853,7 @@ int wlc_prep_pdu(wlc_info_t *wlc, void *pdu, uint *fifop)
8066} 7853}
8067 7854
8068/* init tx reported rate mechanism */ 7855/* init tx reported rate mechanism */
8069void wlc_reprate_init(wlc_info_t *wlc) 7856void wlc_reprate_init(struct wlc_info *wlc)
8070{ 7857{
8071 int i; 7858 int i;
8072 wlc_bsscfg_t *bsscfg; 7859 wlc_bsscfg_t *bsscfg;
@@ -8080,13 +7867,13 @@ void wlc_reprate_init(wlc_info_t *wlc)
8080void wlc_bsscfg_reprate_init(wlc_bsscfg_t *bsscfg) 7867void wlc_bsscfg_reprate_init(wlc_bsscfg_t *bsscfg)
8081{ 7868{
8082 bsscfg->txrspecidx = 0; 7869 bsscfg->txrspecidx = 0;
8083 bzero((char *)bsscfg->txrspec, sizeof(bsscfg->txrspec)); 7870 memset((char *)bsscfg->txrspec, 0, sizeof(bsscfg->txrspec));
8084} 7871}
8085 7872
8086/* Retrieve a consolidated set of revision information, 7873/* Retrieve a consolidated set of revision information,
8087 * typically for the WLC_GET_REVINFO ioctl 7874 * typically for the WLC_GET_REVINFO ioctl
8088 */ 7875 */
8089int wlc_get_revision_info(wlc_info_t *wlc, void *buf, uint len) 7876int wlc_get_revision_info(struct wlc_info *wlc, void *buf, uint len)
8090{ 7877{
8091 wlc_rev_info_t *rinfo = (wlc_rev_info_t *) buf; 7878 wlc_rev_info_t *rinfo = (wlc_rev_info_t *) buf;
8092 7879
@@ -8120,7 +7907,7 @@ int wlc_get_revision_info(wlc_info_t *wlc, void *buf, uint len)
8120 return BCME_OK; 7907 return BCME_OK;
8121} 7908}
8122 7909
8123void wlc_default_rateset(wlc_info_t *wlc, wlc_rateset_t *rs) 7910void wlc_default_rateset(struct wlc_info *wlc, wlc_rateset_t *rs)
8124{ 7911{
8125 wlc_rateset_default(rs, NULL, wlc->band->phytype, wlc->band->bandtype, 7912 wlc_rateset_default(rs, NULL, wlc->band->phytype, wlc->band->bandtype,
8126 false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub), 7913 false, RATE_MASK_FULL, (bool) N_ENAB(wlc->pub),
@@ -8128,14 +7915,14 @@ void wlc_default_rateset(wlc_info_t *wlc, wlc_rateset_t *rs)
8128 wlc->stf->txstreams); 7915 wlc->stf->txstreams);
8129} 7916}
8130 7917
8131static void wlc_bss_default_init(wlc_info_t *wlc) 7918static void wlc_bss_default_init(struct wlc_info *wlc)
8132{ 7919{
8133 chanspec_t chanspec; 7920 chanspec_t chanspec;
8134 wlcband_t *band; 7921 struct wlcband *band;
8135 wlc_bss_info_t *bi = wlc->default_bss; 7922 wlc_bss_info_t *bi = wlc->default_bss;
8136 7923
8137 /* init default and target BSS with some sane initial values */ 7924 /* init default and target BSS with some sane initial values */
8138 bzero((char *)(bi), sizeof(wlc_bss_info_t)); 7925 memset((char *)(bi), 0, sizeof(wlc_bss_info_t));
8139 bi->beacon_period = ISSIM_ENAB(wlc->pub->sih) ? BEACON_INTERVAL_DEF_QT : 7926 bi->beacon_period = ISSIM_ENAB(wlc->pub->sih) ? BEACON_INTERVAL_DEF_QT :
8140 BEACON_INTERVAL_DEFAULT; 7927 BEACON_INTERVAL_DEFAULT;
8141 bi->dtim_period = ISSIM_ENAB(wlc->pub->sih) ? DTIM_INTERVAL_DEF_QT : 7928 bi->dtim_period = ISSIM_ENAB(wlc->pub->sih) ? DTIM_INTERVAL_DEF_QT :
@@ -8166,7 +7953,7 @@ static void wlc_bss_default_init(wlc_info_t *wlc)
8166/* Deferred event processing */ 7953/* Deferred event processing */
8167static void wlc_process_eventq(void *arg) 7954static void wlc_process_eventq(void *arg)
8168{ 7955{
8169 wlc_info_t *wlc = (wlc_info_t *) arg; 7956 struct wlc_info *wlc = (struct wlc_info *) arg;
8170 wlc_event_t *etmp; 7957 wlc_event_t *etmp;
8171 7958
8172 while ((etmp = wlc_eventq_deq(wlc->eventq))) { 7959 while ((etmp = wlc_eventq_deq(wlc->eventq))) {
@@ -8192,7 +7979,8 @@ wlc_uint64_sub(u32 *a_high, u32 *a_low, u32 b_high, u32 b_low)
8192} 7979}
8193 7980
8194static ratespec_t 7981static ratespec_t
8195mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band, u32 int_val) 7982mac80211_wlc_set_nrate(struct wlc_info *wlc, struct wlcband *cur_band,
7983 u32 int_val)
8196{ 7984{
8197 u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT; 7985 u8 stf = (int_val & NRATE_STF_MASK) >> NRATE_STF_SHIFT;
8198 u8 rate = int_val & NRATE_RATE_MASK; 7986 u8 rate = int_val & NRATE_RATE_MASK;
@@ -8211,8 +7999,8 @@ mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band, u32 int_val)
8211 if (N_ENAB(wlc->pub) && ismcs) { 7999 if (N_ENAB(wlc->pub) && ismcs) {
8212 /* mcs only allowed when nmode */ 8000 /* mcs only allowed when nmode */
8213 if (stf > PHY_TXC1_MODE_SDM) { 8001 if (stf > PHY_TXC1_MODE_SDM) {
8214 WL_ERROR(("wl%d: %s: Invalid stf\n", WLCWLUNIT(wlc), 8002 WL_ERROR("wl%d: %s: Invalid stf\n",
8215 __func__)); 8003 WLCWLUNIT(wlc), __func__);
8216 bcmerror = BCME_RANGE; 8004 bcmerror = BCME_RANGE;
8217 goto done; 8005 goto done;
8218 } 8006 }
@@ -8222,8 +8010,8 @@ mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band, u32 int_val)
8222 if (!CHSPEC_IS40(wlc->home_chanspec) || 8010 if (!CHSPEC_IS40(wlc->home_chanspec) ||
8223 ((stf != PHY_TXC1_MODE_SISO) 8011 ((stf != PHY_TXC1_MODE_SISO)
8224 && (stf != PHY_TXC1_MODE_CDD))) { 8012 && (stf != PHY_TXC1_MODE_CDD))) {
8225 WL_ERROR(("wl%d: %s: Invalid mcs 32\n", 8013 WL_ERROR("wl%d: %s: Invalid mcs 32\n",
8226 WLCWLUNIT(wlc), __func__)); 8014 WLCWLUNIT(wlc), __func__);
8227 bcmerror = BCME_RANGE; 8015 bcmerror = BCME_RANGE;
8228 goto done; 8016 goto done;
8229 } 8017 }
@@ -8231,7 +8019,8 @@ mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band, u32 int_val)
8231 } else if (rate > HIGHEST_SINGLE_STREAM_MCS) { 8019 } else if (rate > HIGHEST_SINGLE_STREAM_MCS) {
8232 /* mcs > 7 must use stf SDM */ 8020 /* mcs > 7 must use stf SDM */
8233 if (stf != PHY_TXC1_MODE_SDM) { 8021 if (stf != PHY_TXC1_MODE_SDM) {
8234 WL_TRACE(("wl%d: %s: enabling SDM mode for mcs %d\n", WLCWLUNIT(wlc), __func__, rate)); 8022 WL_TRACE("wl%d: %s: enabling SDM mode for mcs %d\n",
8023 WLCWLUNIT(wlc), __func__, rate);
8235 stf = PHY_TXC1_MODE_SDM; 8024 stf = PHY_TXC1_MODE_SDM;
8236 } 8025 }
8237 } else { 8026 } else {
@@ -8239,37 +8028,37 @@ mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band, u32 int_val)
8239 if ((stf > PHY_TXC1_MODE_STBC) || 8028 if ((stf > PHY_TXC1_MODE_STBC) ||
8240 (!WLC_STBC_CAP_PHY(wlc) 8029 (!WLC_STBC_CAP_PHY(wlc)
8241 && (stf == PHY_TXC1_MODE_STBC))) { 8030 && (stf == PHY_TXC1_MODE_STBC))) {
8242 WL_ERROR(("wl%d: %s: Invalid STBC\n", 8031 WL_ERROR("wl%d: %s: Invalid STBC\n",
8243 WLCWLUNIT(wlc), __func__)); 8032 WLCWLUNIT(wlc), __func__);
8244 bcmerror = BCME_RANGE; 8033 bcmerror = BCME_RANGE;
8245 goto done; 8034 goto done;
8246 } 8035 }
8247 } 8036 }
8248 } else if (IS_OFDM(rate)) { 8037 } else if (IS_OFDM(rate)) {
8249 if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) { 8038 if ((stf != PHY_TXC1_MODE_CDD) && (stf != PHY_TXC1_MODE_SISO)) {
8250 WL_ERROR(("wl%d: %s: Invalid OFDM\n", WLCWLUNIT(wlc), 8039 WL_ERROR("wl%d: %s: Invalid OFDM\n",
8251 __func__)); 8040 WLCWLUNIT(wlc), __func__);
8252 bcmerror = BCME_RANGE; 8041 bcmerror = BCME_RANGE;
8253 goto done; 8042 goto done;
8254 } 8043 }
8255 } else if (IS_CCK(rate)) { 8044 } else if (IS_CCK(rate)) {
8256 if ((cur_band->bandtype != WLC_BAND_2G) 8045 if ((cur_band->bandtype != WLC_BAND_2G)
8257 || (stf != PHY_TXC1_MODE_SISO)) { 8046 || (stf != PHY_TXC1_MODE_SISO)) {
8258 WL_ERROR(("wl%d: %s: Invalid CCK\n", WLCWLUNIT(wlc), 8047 WL_ERROR("wl%d: %s: Invalid CCK\n",
8259 __func__)); 8048 WLCWLUNIT(wlc), __func__);
8260 bcmerror = BCME_RANGE; 8049 bcmerror = BCME_RANGE;
8261 goto done; 8050 goto done;
8262 } 8051 }
8263 } else { 8052 } else {
8264 WL_ERROR(("wl%d: %s: Unknown rate type\n", WLCWLUNIT(wlc), 8053 WL_ERROR("wl%d: %s: Unknown rate type\n",
8265 __func__)); 8054 WLCWLUNIT(wlc), __func__);
8266 bcmerror = BCME_RANGE; 8055 bcmerror = BCME_RANGE;
8267 goto done; 8056 goto done;
8268 } 8057 }
8269 /* make sure multiple antennae are available for non-siso rates */ 8058 /* make sure multiple antennae are available for non-siso rates */
8270 if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) { 8059 if ((stf != PHY_TXC1_MODE_SISO) && (wlc->stf->txstreams == 1)) {
8271 WL_ERROR(("wl%d: %s: SISO antenna but !SISO request\n", 8060 WL_ERROR("wl%d: %s: SISO antenna but !SISO request\n",
8272 WLCWLUNIT(wlc), __func__)); 8061 WLCWLUNIT(wlc), __func__);
8273 bcmerror = BCME_RANGE; 8062 bcmerror = BCME_RANGE;
8274 goto done; 8063 goto done;
8275 } 8064 }
@@ -8300,13 +8089,13 @@ mac80211_wlc_set_nrate(wlc_info_t *wlc, wlcband_t *cur_band, u32 int_val)
8300 8089
8301 return rspec; 8090 return rspec;
8302 done: 8091 done:
8303 WL_ERROR(("Hoark\n")); 8092 WL_ERROR("Hoark\n");
8304 return rate; 8093 return rate;
8305} 8094}
8306 8095
8307/* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */ 8096/* formula: IDLE_BUSY_RATIO_X_16 = (100-duty_cycle)/duty_cycle*16 */
8308static int 8097static int
8309wlc_duty_cycle_set(wlc_info_t *wlc, int duty_cycle, bool isOFDM, 8098wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM,
8310 bool writeToShm) 8099 bool writeToShm)
8311{ 8100{
8312 int idle_busy_ratio_x_16 = 0; 8101 int idle_busy_ratio_x_16 = 0;
@@ -8314,8 +8103,7 @@ wlc_duty_cycle_set(wlc_info_t *wlc, int duty_cycle, bool isOFDM,
8314 isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM : 8103 isOFDM ? M_TX_IDLE_BUSY_RATIO_X_16_OFDM :
8315 M_TX_IDLE_BUSY_RATIO_X_16_CCK; 8104 M_TX_IDLE_BUSY_RATIO_X_16_CCK;
8316 if (duty_cycle > 100 || duty_cycle < 0) { 8105 if (duty_cycle > 100 || duty_cycle < 0) {
8317 WL_ERROR(("wl%d: duty cycle value off limit\n", 8106 WL_ERROR("wl%d: duty cycle value off limit\n", wlc->pub->unit);
8318 wlc->pub->unit));
8319 return BCME_RANGE; 8107 return BCME_RANGE;
8320 } 8108 }
8321 if (duty_cycle) 8109 if (duty_cycle)
@@ -8335,7 +8123,7 @@ wlc_duty_cycle_set(wlc_info_t *wlc, int duty_cycle, bool isOFDM,
8335/* Read a single u16 from shared memory. 8123/* Read a single u16 from shared memory.
8336 * SHM 'offset' needs to be an even address 8124 * SHM 'offset' needs to be an even address
8337 */ 8125 */
8338u16 wlc_read_shm(wlc_info_t *wlc, uint offset) 8126u16 wlc_read_shm(struct wlc_info *wlc, uint offset)
8339{ 8127{
8340 return wlc_bmac_read_shm(wlc->hw, offset); 8128 return wlc_bmac_read_shm(wlc->hw, offset);
8341} 8129}
@@ -8343,7 +8131,7 @@ u16 wlc_read_shm(wlc_info_t *wlc, uint offset)
8343/* Write a single u16 to shared memory. 8131/* Write a single u16 to shared memory.
8344 * SHM 'offset' needs to be an even address 8132 * SHM 'offset' needs to be an even address
8345 */ 8133 */
8346void wlc_write_shm(wlc_info_t *wlc, uint offset, u16 v) 8134void wlc_write_shm(struct wlc_info *wlc, uint offset, u16 v)
8347{ 8135{
8348 wlc_bmac_write_shm(wlc->hw, offset, v); 8136 wlc_bmac_write_shm(wlc->hw, offset, v);
8349} 8137}
@@ -8352,7 +8140,7 @@ void wlc_write_shm(wlc_info_t *wlc, uint offset, u16 v)
8352 * SHM 'offset' needs to be an even address and 8140 * SHM 'offset' needs to be an even address and
8353 * Range length 'len' must be an even number of bytes 8141 * Range length 'len' must be an even number of bytes
8354 */ 8142 */
8355void wlc_set_shm(wlc_info_t *wlc, uint offset, u16 v, int len) 8143void wlc_set_shm(struct wlc_info *wlc, uint offset, u16 v, int len)
8356{ 8144{
8357 /* offset and len need to be even */ 8145 /* offset and len need to be even */
8358 ASSERT((offset & 1) == 0); 8146 ASSERT((offset & 1) == 0);
@@ -8368,7 +8156,7 @@ void wlc_set_shm(wlc_info_t *wlc, uint offset, u16 v, int len)
8368 * SHM 'offset' needs to be an even address and 8156 * SHM 'offset' needs to be an even address and
8369 * Buffer length 'len' must be an even number of bytes 8157 * Buffer length 'len' must be an even number of bytes
8370 */ 8158 */
8371void wlc_copyto_shm(wlc_info_t *wlc, uint offset, const void *buf, int len) 8159void wlc_copyto_shm(struct wlc_info *wlc, uint offset, const void *buf, int len)
8372{ 8160{
8373 /* offset and len need to be even */ 8161 /* offset and len need to be even */
8374 ASSERT((offset & 1) == 0); 8162 ASSERT((offset & 1) == 0);
@@ -8384,7 +8172,7 @@ void wlc_copyto_shm(wlc_info_t *wlc, uint offset, const void *buf, int len)
8384 * SHM 'offset' needs to be an even address and 8172 * SHM 'offset' needs to be an even address and
8385 * Buffer length 'len' must be an even number of bytes 8173 * Buffer length 'len' must be an even number of bytes
8386 */ 8174 */
8387void wlc_copyfrom_shm(wlc_info_t *wlc, uint offset, void *buf, int len) 8175void wlc_copyfrom_shm(struct wlc_info *wlc, uint offset, void *buf, int len)
8388{ 8176{
8389 /* offset and len need to be even */ 8177 /* offset and len need to be even */
8390 ASSERT((offset & 1) == 0); 8178 ASSERT((offset & 1) == 0);
@@ -8397,71 +8185,73 @@ void wlc_copyfrom_shm(wlc_info_t *wlc, uint offset, void *buf, int len)
8397} 8185}
8398 8186
8399/* wrapper BMAC functions to for HIGH driver access */ 8187/* wrapper BMAC functions to for HIGH driver access */
8400void wlc_mctrl(wlc_info_t *wlc, u32 mask, u32 val) 8188void wlc_mctrl(struct wlc_info *wlc, u32 mask, u32 val)
8401{ 8189{
8402 wlc_bmac_mctrl(wlc->hw, mask, val); 8190 wlc_bmac_mctrl(wlc->hw, mask, val);
8403} 8191}
8404 8192
8405void wlc_corereset(wlc_info_t *wlc, u32 flags) 8193void wlc_corereset(struct wlc_info *wlc, u32 flags)
8406{ 8194{
8407 wlc_bmac_corereset(wlc->hw, flags); 8195 wlc_bmac_corereset(wlc->hw, flags);
8408} 8196}
8409 8197
8410void wlc_mhf(wlc_info_t *wlc, u8 idx, u16 mask, u16 val, int bands) 8198void wlc_mhf(struct wlc_info *wlc, u8 idx, u16 mask, u16 val, int bands)
8411{ 8199{
8412 wlc_bmac_mhf(wlc->hw, idx, mask, val, bands); 8200 wlc_bmac_mhf(wlc->hw, idx, mask, val, bands);
8413} 8201}
8414 8202
8415u16 wlc_mhf_get(wlc_info_t *wlc, u8 idx, int bands) 8203u16 wlc_mhf_get(struct wlc_info *wlc, u8 idx, int bands)
8416{ 8204{
8417 return wlc_bmac_mhf_get(wlc->hw, idx, bands); 8205 return wlc_bmac_mhf_get(wlc->hw, idx, bands);
8418} 8206}
8419 8207
8420int wlc_xmtfifo_sz_get(wlc_info_t *wlc, uint fifo, uint *blocks) 8208int wlc_xmtfifo_sz_get(struct wlc_info *wlc, uint fifo, uint *blocks)
8421{ 8209{
8422 return wlc_bmac_xmtfifo_sz_get(wlc->hw, fifo, blocks); 8210 return wlc_bmac_xmtfifo_sz_get(wlc->hw, fifo, blocks);
8423} 8211}
8424 8212
8425void wlc_write_template_ram(wlc_info_t *wlc, int offset, int len, void *buf) 8213void wlc_write_template_ram(struct wlc_info *wlc, int offset, int len,
8214 void *buf)
8426{ 8215{
8427 wlc_bmac_write_template_ram(wlc->hw, offset, len, buf); 8216 wlc_bmac_write_template_ram(wlc->hw, offset, len, buf);
8428} 8217}
8429 8218
8430void wlc_write_hw_bcntemplates(wlc_info_t *wlc, void *bcn, int len, bool both) 8219void wlc_write_hw_bcntemplates(struct wlc_info *wlc, void *bcn, int len,
8220 bool both)
8431{ 8221{
8432 wlc_bmac_write_hw_bcntemplates(wlc->hw, bcn, len, both); 8222 wlc_bmac_write_hw_bcntemplates(wlc->hw, bcn, len, both);
8433} 8223}
8434 8224
8435void 8225void
8436wlc_set_addrmatch(wlc_info_t *wlc, int match_reg_offset, 8226wlc_set_addrmatch(struct wlc_info *wlc, int match_reg_offset,
8437 const struct ether_addr *addr) 8227 const struct ether_addr *addr)
8438{ 8228{
8439 wlc_bmac_set_addrmatch(wlc->hw, match_reg_offset, addr); 8229 wlc_bmac_set_addrmatch(wlc->hw, match_reg_offset, addr);
8440} 8230}
8441 8231
8442void wlc_set_rcmta(wlc_info_t *wlc, int idx, const struct ether_addr *addr) 8232void wlc_set_rcmta(struct wlc_info *wlc, int idx, const struct ether_addr *addr)
8443{ 8233{
8444 wlc_bmac_set_rcmta(wlc->hw, idx, addr); 8234 wlc_bmac_set_rcmta(wlc->hw, idx, addr);
8445} 8235}
8446 8236
8447void wlc_read_tsf(wlc_info_t *wlc, u32 *tsf_l_ptr, u32 *tsf_h_ptr) 8237void wlc_read_tsf(struct wlc_info *wlc, u32 *tsf_l_ptr, u32 *tsf_h_ptr)
8448{ 8238{
8449 wlc_bmac_read_tsf(wlc->hw, tsf_l_ptr, tsf_h_ptr); 8239 wlc_bmac_read_tsf(wlc->hw, tsf_l_ptr, tsf_h_ptr);
8450} 8240}
8451 8241
8452void wlc_set_cwmin(wlc_info_t *wlc, u16 newmin) 8242void wlc_set_cwmin(struct wlc_info *wlc, u16 newmin)
8453{ 8243{
8454 wlc->band->CWmin = newmin; 8244 wlc->band->CWmin = newmin;
8455 wlc_bmac_set_cwmin(wlc->hw, newmin); 8245 wlc_bmac_set_cwmin(wlc->hw, newmin);
8456} 8246}
8457 8247
8458void wlc_set_cwmax(wlc_info_t *wlc, u16 newmax) 8248void wlc_set_cwmax(struct wlc_info *wlc, u16 newmax)
8459{ 8249{
8460 wlc->band->CWmax = newmax; 8250 wlc->band->CWmax = newmax;
8461 wlc_bmac_set_cwmax(wlc->hw, newmax); 8251 wlc_bmac_set_cwmax(wlc->hw, newmax);
8462} 8252}
8463 8253
8464void wlc_fifoerrors(wlc_info_t *wlc) 8254void wlc_fifoerrors(struct wlc_info *wlc)
8465{ 8255{
8466 8256
8467 wlc_bmac_fifoerrors(wlc->hw); 8257 wlc_bmac_fifoerrors(wlc->hw);
@@ -8469,19 +8259,16 @@ void wlc_fifoerrors(wlc_info_t *wlc)
8469 8259
8470/* Search mem rw utilities */ 8260/* Search mem rw utilities */
8471 8261
8472void wlc_pllreq(wlc_info_t *wlc, bool set, mbool req_bit) 8262void wlc_pllreq(struct wlc_info *wlc, bool set, mbool req_bit)
8473{ 8263{
8474 wlc_bmac_pllreq(wlc->hw, set, req_bit); 8264 wlc_bmac_pllreq(wlc->hw, set, req_bit);
8475} 8265}
8476 8266
8477void wlc_reset_bmac_done(wlc_info_t *wlc) 8267void wlc_reset_bmac_done(struct wlc_info *wlc)
8478{ 8268{
8479#ifdef WLC_HIGH_ONLY
8480 wlc->reset_bmac_pending = false;
8481#endif
8482} 8269}
8483 8270
8484void wlc_ht_mimops_cap_update(wlc_info_t *wlc, u8 mimops_mode) 8271void wlc_ht_mimops_cap_update(struct wlc_info *wlc, u8 mimops_mode)
8485{ 8272{
8486 wlc->ht_cap.cap &= ~HT_CAP_MIMO_PS_MASK; 8273 wlc->ht_cap.cap &= ~HT_CAP_MIMO_PS_MASK;
8487 wlc->ht_cap.cap |= (mimops_mode << HT_CAP_MIMO_PS_SHIFT); 8274 wlc->ht_cap.cap |= (mimops_mode << HT_CAP_MIMO_PS_SHIFT);
@@ -8494,7 +8281,7 @@ void wlc_ht_mimops_cap_update(wlc_info_t *wlc, u8 mimops_mode)
8494 8281
8495/* check for the particular priority flow control bit being set */ 8282/* check for the particular priority flow control bit being set */
8496bool 8283bool
8497wlc_txflowcontrol_prio_isset(wlc_info_t *wlc, wlc_txq_info_t *q, int prio) 8284wlc_txflowcontrol_prio_isset(struct wlc_info *wlc, wlc_txq_info_t *q, int prio)
8498{ 8285{
8499 uint prio_mask; 8286 uint prio_mask;
8500 8287
@@ -8509,12 +8296,13 @@ wlc_txflowcontrol_prio_isset(wlc_info_t *wlc, wlc_txq_info_t *q, int prio)
8509} 8296}
8510 8297
8511/* propogate the flow control to all interfaces using the given tx queue */ 8298/* propogate the flow control to all interfaces using the given tx queue */
8512void wlc_txflowcontrol(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on, int prio) 8299void wlc_txflowcontrol(struct wlc_info *wlc, wlc_txq_info_t *qi,
8300 bool on, int prio)
8513{ 8301{
8514 uint prio_bits; 8302 uint prio_bits;
8515 uint cur_bits; 8303 uint cur_bits;
8516 8304
8517 WL_ERROR(("%s: flow contro kicks in\n", __func__)); 8305 WL_ERROR("%s: flow control kicks in\n", __func__);
8518 8306
8519 if (prio == ALLPRIO) { 8307 if (prio == ALLPRIO) {
8520 prio_bits = TXQ_STOP_FOR_PRIOFC_MASK; 8308 prio_bits = TXQ_STOP_FOR_PRIOFC_MASK;
@@ -8551,7 +8339,7 @@ void wlc_txflowcontrol(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on, int prio)
8551} 8339}
8552 8340
8553void 8341void
8554wlc_txflowcontrol_override(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on, 8342wlc_txflowcontrol_override(struct wlc_info *wlc, wlc_txq_info_t *qi, bool on,
8555 uint override) 8343 uint override)
8556{ 8344{
8557 uint prev_override; 8345 uint prev_override;
@@ -8598,7 +8386,7 @@ wlc_txflowcontrol_override(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on,
8598 } 8386 }
8599} 8387}
8600 8388
8601static void wlc_txflowcontrol_reset(wlc_info_t *wlc) 8389static void wlc_txflowcontrol_reset(struct wlc_info *wlc)
8602{ 8390{
8603 wlc_txq_info_t *qi; 8391 wlc_txq_info_t *qi;
8604 8392
@@ -8611,10 +8399,10 @@ static void wlc_txflowcontrol_reset(wlc_info_t *wlc)
8611} 8399}
8612 8400
8613static void 8401static void
8614wlc_txflowcontrol_signal(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on, 8402wlc_txflowcontrol_signal(struct wlc_info *wlc, wlc_txq_info_t *qi, bool on,
8615 int prio) 8403 int prio)
8616{ 8404{
8617 wlc_if_t *wlcif; 8405 struct wlc_if *wlcif;
8618 8406
8619 for (wlcif = wlc->wlcif_list; wlcif != NULL; wlcif = wlcif->next) { 8407 for (wlcif = wlc->wlcif_list; wlcif != NULL; wlcif = wlcif->next) {
8620 if (wlcif->qi == qi && wlcif->flags & WLC_IF_LINKED) 8408 if (wlcif->qi == qi && wlcif->flags & WLC_IF_LINKED)
@@ -8622,7 +8410,7 @@ wlc_txflowcontrol_signal(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on,
8622 } 8410 }
8623} 8411}
8624 8412
8625static wlc_txq_info_t *wlc_txq_alloc(wlc_info_t *wlc, osl_t *osh) 8413static wlc_txq_info_t *wlc_txq_alloc(struct wlc_info *wlc, struct osl_info *osh)
8626{ 8414{
8627 wlc_txq_info_t *qi, *p; 8415 wlc_txq_info_t *qi, *p;
8628 8416
@@ -8652,7 +8440,8 @@ static wlc_txq_info_t *wlc_txq_alloc(wlc_info_t *wlc, osl_t *osh)
8652 return qi; 8440 return qi;
8653} 8441}
8654 8442
8655static void wlc_txq_free(wlc_info_t *wlc, osl_t *osh, wlc_txq_info_t *qi) 8443static void wlc_txq_free(struct wlc_info *wlc, struct osl_info *osh,
8444 wlc_txq_info_t *qi)
8656{ 8445{
8657 wlc_txq_info_t *p; 8446 wlc_txq_info_t *p;
8658 8447
diff --git a/drivers/staging/brcm80211/sys/wlc_mac80211.h b/drivers/staging/brcm80211/sys/wlc_mac80211.h
index 6a77591234b7..5df996b78911 100644
--- a/drivers/staging/brcm80211/sys/wlc_mac80211.h
+++ b/drivers/staging/brcm80211/sys/wlc_mac80211.h
@@ -17,19 +17,10 @@
17#ifndef _wlc_h_ 17#ifndef _wlc_h_
18#define _wlc_h_ 18#define _wlc_h_
19 19
20#include <wlc_types.h>
21
22#include <wl_dbg.h>
23#include <wlioctl.h> 20#include <wlioctl.h>
24#include <wlc_event.h>
25#include <wlc_phy_hal.h> 21#include <wlc_phy_hal.h>
26#include <wlc_channel.h> 22#include <wlc_channel.h>
27#ifdef WLC_SPLIT
28#include <bcm_rpc.h>
29#endif
30
31#include <wlc_bsscfg.h> 23#include <wlc_bsscfg.h>
32
33#include <wlc_scb.h> 24#include <wlc_scb.h>
34 25
35#define MA_WINDOW_SZ 8 /* moving average window size */ 26#define MA_WINDOW_SZ 8 /* moving average window size */
@@ -220,15 +211,11 @@ extern const u8 prio2fifo[];
220 * (some platforms return all 0). 211 * (some platforms return all 0).
221 * If clocks are present, call the sb routine which will figure out if the device is removed. 212 * If clocks are present, call the sb routine which will figure out if the device is removed.
222 */ 213 */
223#ifdef WLC_HIGH_ONLY
224#define DEVICEREMOVED(wlc) (!wlc->device_present)
225#else
226#define DEVICEREMOVED(wlc) \ 214#define DEVICEREMOVED(wlc) \
227 ((wlc->hw->clk) ? \ 215 ((wlc->hw->clk) ? \
228 ((R_REG(wlc->hw->osh, &wlc->hw->regs->maccontrol) & \ 216 ((R_REG(wlc->hw->osh, &wlc->hw->regs->maccontrol) & \
229 (MCTL_PSM_JMP_0 | MCTL_IHR_EN)) != MCTL_IHR_EN) : \ 217 (MCTL_PSM_JMP_0 | MCTL_IHR_EN)) != MCTL_IHR_EN) : \
230 (si_deviceremoved(wlc->hw->sih))) 218 (si_deviceremoved(wlc->hw->sih)))
231#endif /* WLC_HIGH_ONLY */
232 219
233#define WLCWLUNIT(wlc) ((wlc)->pub->unit) 220#define WLCWLUNIT(wlc) ((wlc)->pub->unit)
234 221
@@ -315,22 +302,20 @@ typedef struct wlc_stf {
315/* 302/*
316 * core state (mac) 303 * core state (mac)
317 */ 304 */
318typedef struct wlccore { 305struct wlccore {
319#ifdef WLC_LOW
320 uint coreidx; /* # sb enumerated core */ 306 uint coreidx; /* # sb enumerated core */
321 307
322 /* fifo */ 308 /* fifo */
323 uint *txavail[NFIFO]; /* # tx descriptors available */ 309 uint *txavail[NFIFO]; /* # tx descriptors available */
324 s16 txpktpend[NFIFO]; /* tx admission control */ 310 s16 txpktpend[NFIFO]; /* tx admission control */
325#endif /* WLC_LOW */
326 311
327 macstat_t *macstat_snapshot; /* mac hw prev read values */ 312 macstat_t *macstat_snapshot; /* mac hw prev read values */
328} wlccore_t; 313};
329 314
330/* 315/*
331 * band state (phy+ana+radio) 316 * band state (phy+ana+radio)
332 */ 317 */
333typedef struct wlcband { 318struct wlcband {
334 int bandtype; /* WLC_BAND_2G, WLC_BAND_5G */ 319 int bandtype; /* WLC_BAND_2G, WLC_BAND_5G */
335 uint bandunit; /* bandstate[] index */ 320 uint bandunit; /* bandstate[] index */
336 321
@@ -359,13 +344,13 @@ typedef struct wlcband {
359 u16 CWmin; /* The minimum size of contention window, in unit of aSlotTime */ 344 u16 CWmin; /* The minimum size of contention window, in unit of aSlotTime */
360 u16 CWmax; /* The maximum size of contention window, in unit of aSlotTime */ 345 u16 CWmax; /* The maximum size of contention window, in unit of aSlotTime */
361 u16 bcntsfoff; /* beacon tsf offset */ 346 u16 bcntsfoff; /* beacon tsf offset */
362} wlcband_t; 347};
363 348
364/* generic function callback takes just one arg */ 349/* generic function callback takes just one arg */
365typedef void (*cb_fn_t) (void *); 350typedef void (*cb_fn_t) (void *);
366 351
367/* tx completion callback takes 3 args */ 352/* tx completion callback takes 3 args */
368typedef void (*pkcb_fn_t) (wlc_info_t *wlc, uint txstatus, void *arg); 353typedef void (*pkcb_fn_t) (struct wlc_info *wlc, uint txstatus, void *arg);
369 354
370typedef struct pkt_cb { 355typedef struct pkt_cb {
371 pkcb_fn_t fn; /* function to call when tx frame completes */ 356 pkcb_fn_t fn; /* function to call when tx frame completes */
@@ -398,14 +383,14 @@ typedef struct dumpcb_s {
398 383
399/* virtual interface */ 384/* virtual interface */
400struct wlc_if { 385struct wlc_if {
401 wlc_if_t *next; 386 struct wlc_if *next;
402 u8 type; /* WLC_IFTYPE_BSS or WLC_IFTYPE_WDS */ 387 u8 type; /* WLC_IFTYPE_BSS or WLC_IFTYPE_WDS */
403 u8 index; /* assigned in wl_add_if(), index of the wlif if any, 388 u8 index; /* assigned in wl_add_if(), index of the wlif if any,
404 * not necessarily corresponding to bsscfg._idx or 389 * not necessarily corresponding to bsscfg._idx or
405 * AID2PVBMAP(scb). 390 * AID2PVBMAP(scb).
406 */ 391 */
407 u8 flags; /* flags for the interface */ 392 u8 flags; /* flags for the interface */
408 wl_if_t *wlif; /* pointer to wlif */ 393 struct wl_if *wlif; /* pointer to wlif */
409 struct wlc_txq_info *qi; /* pointer to associated tx queue */ 394 struct wlc_txq_info *qi; /* pointer to associated tx queue */
410 union { 395 union {
411 struct scb *scb; /* pointer to scb if WLC_IFTYPE_WDS */ 396 struct scb *scb; /* pointer to scb if WLC_IFTYPE_WDS */
@@ -416,7 +401,6 @@ struct wlc_if {
416/* flags for the interface */ 401/* flags for the interface */
417#define WLC_IF_LINKED 0x02 /* this interface is linked to a wl_if */ 402#define WLC_IF_LINKED 0x02 /* this interface is linked to a wl_if */
418 403
419#ifdef WLC_LOW
420typedef struct wlc_hwband { 404typedef struct wlc_hwband {
421 int bandtype; /* WLC_BAND_2G, WLC_BAND_5G */ 405 int bandtype; /* WLC_BAND_2G, WLC_BAND_5G */
422 uint bandunit; /* bandstate[] index */ 406 uint bandunit; /* bandstate[] index */
@@ -433,20 +417,15 @@ typedef struct wlc_hwband {
433 wlc_phy_t *pi; /* pointer to phy specific information */ 417 wlc_phy_t *pi; /* pointer to phy specific information */
434 bool abgphy_encore; 418 bool abgphy_encore;
435} wlc_hwband_t; 419} wlc_hwband_t;
436#endif /* WLC_LOW */
437 420
438struct wlc_hw_info { 421struct wlc_hw_info {
439#ifdef WLC_SPLIT 422 struct osl_info *osh; /* pointer to os handle */
440 rpc_info_t *rpc; /* Handle to RPC module */
441#endif
442 osl_t *osh; /* pointer to os handle */
443 bool _piomode; /* true if pio mode */ 423 bool _piomode; /* true if pio mode */
444 wlc_info_t *wlc; 424 struct wlc_info *wlc;
445 425
446 /* fifo */ 426 /* fifo */
447 hnddma_t *di[NFIFO]; /* hnddma handles, per fifo */ 427 struct hnddma_pub *di[NFIFO]; /* hnddma handles, per fifo */
448 428
449#ifdef WLC_LOW
450 uint unit; /* device instance number */ 429 uint unit; /* device instance number */
451 430
452 /* version info */ 431 /* version info */
@@ -497,31 +476,21 @@ struct wlc_hw_info {
497 bool forcefastclk; /* true if the h/w is forcing the use of fast clk */ 476 bool forcefastclk; /* true if the h/w is forcing the use of fast clk */
498 bool clk; /* core is out of reset and has clock */ 477 bool clk; /* core is out of reset and has clock */
499 bool sbclk; /* sb has clock */ 478 bool sbclk; /* sb has clock */
500 bmac_pmq_t *bmac_pmq; /* bmac PM states derived from ucode PMQ */ 479 struct bmac_pmq *bmac_pmq; /* bmac PM states derived from ucode PMQ */
501 bool phyclk; /* phy is out of reset and has clock */ 480 bool phyclk; /* phy is out of reset and has clock */
502 bool dma_lpbk; /* core is in DMA loopback */ 481 bool dma_lpbk; /* core is in DMA loopback */
503 482
504#ifdef BCMSDIO
505 void *sdh;
506#endif
507 bool ucode_loaded; /* true after ucode downloaded */ 483 bool ucode_loaded; /* true after ucode downloaded */
508 484
509#ifdef WLC_LOW_ONLY
510 struct wl_timer *wdtimer; /* timer for watchdog routine */
511 struct ether_addr orig_etheraddr; /* original hw ethernet address */
512 u16 rpc_dngl_agg; /* rpc agg control for dongle */
513 u32 mem_required_def; /* memory required to replenish RX DMA ring */
514 u32 mem_required_lower; /* memory required with lower RX bound */
515 u32 mem_required_least; /* minimum memory requirement to handle RX */
516
517#endif /* WLC_LOW_ONLY */
518 485
519 u8 hw_stf_ss_opmode; /* STF single stream operation mode */ 486 u8 hw_stf_ss_opmode; /* STF single stream operation mode */
520 u8 antsel_type; /* Type of boardlevel mimo antenna switch-logic 487 u8 antsel_type; /* Type of boardlevel mimo antenna switch-logic
521 * 0 = N/A, 1 = 2x4 board, 2 = 2x3 CB2 board 488 * 0 = N/A, 1 = 2x4 board, 2 = 2x3 CB2 board
522 */ 489 */
523 u32 antsel_avail; /* put antsel_info_t here if more info is needed */ 490 u32 antsel_avail; /*
524#endif /* WLC_LOW */ 491 * put struct antsel_info here if more info is
492 * needed
493 */
525}; 494};
526 495
527/* TX Queue information 496/* TX Queue information
@@ -541,15 +510,12 @@ typedef struct wlc_txq_info {
541 * Principal common (os-independent) software data structure. 510 * Principal common (os-independent) software data structure.
542 */ 511 */
543struct wlc_info { 512struct wlc_info {
544 wlc_pub_t *pub; /* pointer to wlc public state */ 513 struct wlc_pub *pub; /* pointer to wlc public state */
545 osl_t *osh; /* pointer to os handle */ 514 struct osl_info *osh; /* pointer to os handle */
546 struct wl_info *wl; /* pointer to os-specific private state */ 515 struct wl_info *wl; /* pointer to os-specific private state */
547 d11regs_t *regs; /* pointer to device registers */ 516 d11regs_t *regs; /* pointer to device registers */
548 517
549 wlc_hw_info_t *hw; /* HW related state used primarily by BMAC */ 518 struct wlc_hw_info *hw; /* HW related state used primarily by BMAC */
550#ifdef WLC_SPLIT
551 rpc_info_t *rpc; /* Handle to RPC module */
552#endif
553 519
554 /* clock */ 520 /* clock */
555 int clkreq_override; /* setting for clkreq for PCIE : Auto, 0, 1 */ 521 int clkreq_override; /* setting for clkreq for PCIE : Auto, 0, 1 */
@@ -566,10 +532,11 @@ struct wlc_info {
566 bool clk; /* core is out of reset and has clock */ 532 bool clk; /* core is out of reset and has clock */
567 533
568 /* multiband */ 534 /* multiband */
569 wlccore_t *core; /* pointer to active io core */ 535 struct wlccore *core; /* pointer to active io core */
570 wlcband_t *band; /* pointer to active per-band state */ 536 struct wlcband *band; /* pointer to active per-band state */
571 wlccore_t *corestate; /* per-core state (one per hw core) */ 537 struct wlccore *corestate; /* per-core state (one per hw core) */
572 wlcband_t *bandstate[MAXBANDS]; /* per-band state (one per phy/radio) */ 538 /* per-band state (one per phy/radio): */
539 struct wlcband *bandstate[MAXBANDS];
573 540
574 bool war16165; /* PCI slow clock 16165 war flag */ 541 bool war16165; /* PCI slow clock 16165 war flag */
575 542
@@ -584,15 +551,9 @@ struct wlc_info {
584 s8 txpwr_local_max; /* regulatory local txpwr max */ 551 s8 txpwr_local_max; /* regulatory local txpwr max */
585 u8 txpwr_local_constraint; /* local power contraint in dB */ 552 u8 txpwr_local_constraint; /* local power contraint in dB */
586 553
587#ifdef WLC_HIGH_ONLY
588 rpctx_info_t *rpctx; /* RPC TX module */
589 bool reset_bmac_pending; /* bmac reset is in progressing */
590 u32 rpc_agg; /* host agg: bit 16-31, bmac agg: bit 0-15 */
591 u32 rpc_msglevel; /* host rpc: bit 16-31, bmac rpc: bit 0-15 */
592#endif
593 554
594 ampdu_info_t *ampdu; /* ampdu module handler */ 555 struct ampdu_info *ampdu; /* ampdu module handler */
595 antsel_info_t *asi; /* antsel module handler */ 556 struct antsel_info *asi; /* antsel module handler */
596 wlc_cm_info_t *cmi; /* channel manager module handler */ 557 wlc_cm_info_t *cmi; /* channel manager module handler */
597 558
598 void *btparam; /* bus type specific cookie */ 559 void *btparam; /* bus type specific cookie */
@@ -792,8 +753,6 @@ struct wlc_info {
792 ac_bitmap_t apsd_trigger_ac; /* Permissible Acess Category in which APSD Null 753 ac_bitmap_t apsd_trigger_ac; /* Permissible Acess Category in which APSD Null
793 * Trigger frames can be send 754 * Trigger frames can be send
794 */ 755 */
795 wlc_ap_info_t *ap;
796
797 u8 htphy_membership; /* HT PHY membership */ 756 u8 htphy_membership; /* HT PHY membership */
798 757
799 bool _regulatory_domain; /* 802.11d enabled? */ 758 bool _regulatory_domain; /* 802.11d enabled? */
@@ -811,7 +770,7 @@ struct wlc_info {
811 770
812 u16 next_bsscfg_ID; 771 u16 next_bsscfg_ID;
813 772
814 wlc_if_t *wlcif_list; /* linked list of wlc_if structs */ 773 struct wlc_if *wlcif_list; /* linked list of wlc_if structs */
815 wlc_txq_info_t *active_queue; /* txq for the currently active transmit context */ 774 wlc_txq_info_t *active_queue; /* txq for the currently active transmit context */
816 u32 mpc_dur; /* total time (ms) in mpc mode except for the 775 u32 mpc_dur; /* total time (ms) in mpc mode except for the
817 * portion since radio is turned off last time 776 * portion since radio is turned off last time
@@ -825,8 +784,8 @@ struct wlc_info {
825 784
826/* antsel module specific state */ 785/* antsel module specific state */
827struct antsel_info { 786struct antsel_info {
828 wlc_info_t *wlc; /* pointer to main wlc structure */ 787 struct wlc_info *wlc; /* pointer to main wlc structure */
829 wlc_pub_t *pub; /* pointer to public fn */ 788 struct wlc_pub *pub; /* pointer to public fn */
830 u8 antsel_type; /* Type of boardlevel mimo antenna switch-logic 789 u8 antsel_type; /* Type of boardlevel mimo antenna switch-logic
831 * 0 = N/A, 1 = 2x4 board, 2 = 2x3 CB2 board 790 * 0 = N/A, 1 = 2x4 board, 2 = 2x3 CB2 board
832 */ 791 */
@@ -842,23 +801,9 @@ struct antsel_info {
842#define IS_MBAND_UNLOCKED(wlc) \ 801#define IS_MBAND_UNLOCKED(wlc) \
843 ((NBANDS(wlc) > 1) && !(wlc)->bandlocked) 802 ((NBANDS(wlc) > 1) && !(wlc)->bandlocked)
844 803
845#ifdef WLC_LOW
846#define WLC_BAND_PI_RADIO_CHANSPEC wlc_phy_chanspec_get(wlc->band->pi) 804#define WLC_BAND_PI_RADIO_CHANSPEC wlc_phy_chanspec_get(wlc->band->pi)
847#else
848#define WLC_BAND_PI_RADIO_CHANSPEC (wlc->chanspec)
849#endif
850 805
851/* sum the individual fifo tx pending packet counts */ 806/* sum the individual fifo tx pending packet counts */
852#if defined(WLC_HIGH_ONLY)
853#define TXPKTPENDTOT(wlc) (wlc_rpctx_txpktpend((wlc)->rpctx, 0, true))
854#define TXPKTPENDGET(wlc, fifo) (wlc_rpctx_txpktpend((wlc)->rpctx, (fifo), false))
855#define TXPKTPENDINC(wlc, fifo, val) (wlc_rpctx_txpktpendinc((wlc)->rpctx, (fifo), (val)))
856#define TXPKTPENDDEC(wlc, fifo, val) (wlc_rpctx_txpktpenddec((wlc)->rpctx, (fifo), (val)))
857#define TXPKTPENDCLR(wlc, fifo) (wlc_rpctx_txpktpendclr((wlc)->rpctx, (fifo)))
858#define TXAVAIL(wlc, fifo) (wlc_rpctx_txavail((wlc)->rpctx, (fifo)))
859#define GETNEXTTXP(wlc, _queue) (wlc_rpctx_getnexttxp((wlc)->rpctx, (_queue)))
860
861#else
862#define TXPKTPENDTOT(wlc) ((wlc)->core->txpktpend[0] + (wlc)->core->txpktpend[1] + \ 807#define TXPKTPENDTOT(wlc) ((wlc)->core->txpktpend[0] + (wlc)->core->txpktpend[1] + \
863 (wlc)->core->txpktpend[2] + (wlc)->core->txpktpend[3]) 808 (wlc)->core->txpktpend[2] + (wlc)->core->txpktpend[3])
864#define TXPKTPENDGET(wlc, fifo) ((wlc)->core->txpktpend[(fifo)]) 809#define TXPKTPENDGET(wlc, fifo) ((wlc)->core->txpktpend[(fifo)])
@@ -868,48 +813,49 @@ struct antsel_info {
868#define TXAVAIL(wlc, fifo) (*(wlc)->core->txavail[(fifo)]) 813#define TXAVAIL(wlc, fifo) (*(wlc)->core->txavail[(fifo)])
869#define GETNEXTTXP(wlc, _queue) \ 814#define GETNEXTTXP(wlc, _queue) \
870 dma_getnexttxp((wlc)->hw->di[(_queue)], HNDDMA_RANGE_TRANSMITTED) 815 dma_getnexttxp((wlc)->hw->di[(_queue)], HNDDMA_RANGE_TRANSMITTED)
871#endif /* WLC_HIGH_ONLY */
872 816
873#define WLC_IS_MATCH_SSID(wlc, ssid1, ssid2, len1, len2) \ 817#define WLC_IS_MATCH_SSID(wlc, ssid1, ssid2, len1, len2) \
874 ((len1 == len2) && !bcmp(ssid1, ssid2, len1)) 818 ((len1 == len2) && !memcmp(ssid1, ssid2, len1))
875 819
876/* API shared by both WLC_HIGH and WLC_LOW driver */ 820extern void wlc_high_dpc(struct wlc_info *wlc, u32 macintstatus);
877extern void wlc_high_dpc(wlc_info_t *wlc, u32 macintstatus); 821extern void wlc_fatal_error(struct wlc_info *wlc);
878extern void wlc_fatal_error(wlc_info_t *wlc); 822extern void wlc_bmac_rpc_watchdog(struct wlc_info *wlc);
879extern void wlc_bmac_rpc_watchdog(wlc_info_t *wlc); 823extern void wlc_recv(struct wlc_info *wlc, struct sk_buff *p);
880extern void wlc_recv(wlc_info_t *wlc, void *p); 824extern bool wlc_dotxstatus(struct wlc_info *wlc, tx_status_t *txs, u32 frm_tx2);
881extern bool wlc_dotxstatus(wlc_info_t *wlc, tx_status_t *txs, u32 frm_tx2); 825extern void wlc_txfifo(struct wlc_info *wlc, uint fifo, struct sk_buff *p,
882extern void wlc_txfifo(wlc_info_t *wlc, uint fifo, void *p, bool commit, 826 bool commit, s8 txpktpend);
883 s8 txpktpend); 827extern void wlc_txfifo_complete(struct wlc_info *wlc, uint fifo, s8 txpktpend);
884extern void wlc_txfifo_complete(wlc_info_t *wlc, uint fifo, s8 txpktpend); 828extern void wlc_txq_enq(void *ctx, struct scb *scb, struct sk_buff *sdu,
885extern void wlc_info_init(wlc_info_t *wlc, int unit); 829 uint prec);
830extern void wlc_info_init(struct wlc_info *wlc, int unit);
886extern void wlc_print_txstatus(tx_status_t *txs); 831extern void wlc_print_txstatus(tx_status_t *txs);
887extern int wlc_xmtfifo_sz_get(wlc_info_t *wlc, uint fifo, uint *blocks); 832extern int wlc_xmtfifo_sz_get(struct wlc_info *wlc, uint fifo, uint *blocks);
888extern void wlc_write_template_ram(wlc_info_t *wlc, int offset, int len, 833extern void wlc_write_template_ram(struct wlc_info *wlc, int offset, int len,
889 void *buf); 834 void *buf);
890extern void wlc_write_hw_bcntemplates(wlc_info_t *wlc, void *bcn, int len, 835extern void wlc_write_hw_bcntemplates(struct wlc_info *wlc, void *bcn, int len,
891 bool both); 836 bool both);
892#if defined(BCMDBG) 837#if defined(BCMDBG)
893extern void wlc_get_rcmta(wlc_info_t *wlc, int idx, struct ether_addr *addr); 838extern void wlc_get_rcmta(struct wlc_info *wlc, int idx,
839 struct ether_addr *addr);
894#endif 840#endif
895extern void wlc_set_rcmta(wlc_info_t *wlc, int idx, 841extern void wlc_set_rcmta(struct wlc_info *wlc, int idx,
896 const struct ether_addr *addr); 842 const struct ether_addr *addr);
897extern void wlc_set_addrmatch(wlc_info_t *wlc, int match_reg_offset, 843extern void wlc_set_addrmatch(struct wlc_info *wlc, int match_reg_offset,
898 const struct ether_addr *addr); 844 const struct ether_addr *addr);
899extern void wlc_read_tsf(wlc_info_t *wlc, u32 *tsf_l_ptr, 845extern void wlc_read_tsf(struct wlc_info *wlc, u32 *tsf_l_ptr,
900 u32 *tsf_h_ptr); 846 u32 *tsf_h_ptr);
901extern void wlc_set_cwmin(wlc_info_t *wlc, u16 newmin); 847extern void wlc_set_cwmin(struct wlc_info *wlc, u16 newmin);
902extern void wlc_set_cwmax(wlc_info_t *wlc, u16 newmax); 848extern void wlc_set_cwmax(struct wlc_info *wlc, u16 newmax);
903extern void wlc_fifoerrors(wlc_info_t *wlc); 849extern void wlc_fifoerrors(struct wlc_info *wlc);
904extern void wlc_pllreq(wlc_info_t *wlc, bool set, mbool req_bit); 850extern void wlc_pllreq(struct wlc_info *wlc, bool set, mbool req_bit);
905extern void wlc_reset_bmac_done(wlc_info_t *wlc); 851extern void wlc_reset_bmac_done(struct wlc_info *wlc);
906extern void wlc_protection_upd(wlc_info_t *wlc, uint idx, int val); 852extern void wlc_protection_upd(struct wlc_info *wlc, uint idx, int val);
907extern void wlc_hwtimer_gptimer_set(wlc_info_t *wlc, uint us); 853extern void wlc_hwtimer_gptimer_set(struct wlc_info *wlc, uint us);
908extern void wlc_hwtimer_gptimer_abort(wlc_info_t *wlc); 854extern void wlc_hwtimer_gptimer_abort(struct wlc_info *wlc);
909 855
910#if defined(BCMDBG) 856#if defined(BCMDBG)
911extern void wlc_print_rxh(d11rxhdr_t *rxh); 857extern void wlc_print_rxh(d11rxhdr_t *rxh);
912extern void wlc_print_hdrs(wlc_info_t *wlc, const char *prefix, u8 *frame, 858extern void wlc_print_hdrs(struct wlc_info *wlc, const char *prefix, u8 *frame,
913 d11txh_t *txh, d11rxhdr_t *rxh, uint len); 859 d11txh_t *txh, d11rxhdr_t *rxh, uint len);
914extern void wlc_print_txdesc(d11txh_t *txh); 860extern void wlc_print_txdesc(d11txh_t *txh);
915#endif 861#endif
@@ -917,124 +863,126 @@ extern void wlc_print_txdesc(d11txh_t *txh);
917extern void wlc_print_dot11_mac_hdr(u8 *buf, int len); 863extern void wlc_print_dot11_mac_hdr(u8 *buf, int len);
918#endif 864#endif
919 865
920#ifdef WLC_LOW 866extern void wlc_setxband(struct wlc_hw_info *wlc_hw, uint bandunit);
921extern void wlc_setxband(wlc_hw_info_t *wlc_hw, uint bandunit); 867extern void wlc_coredisable(struct wlc_hw_info *wlc_hw);
922extern void wlc_coredisable(wlc_hw_info_t *wlc_hw);
923#endif
924 868
925extern bool wlc_valid_rate(wlc_info_t *wlc, ratespec_t rate, int band, 869extern bool wlc_valid_rate(struct wlc_info *wlc, ratespec_t rate, int band,
926 bool verbose); 870 bool verbose);
927extern void wlc_ap_upd(wlc_info_t *wlc); 871extern void wlc_ap_upd(struct wlc_info *wlc);
928 872
929/* helper functions */ 873/* helper functions */
930extern void wlc_shm_ssid_upd(wlc_info_t *wlc, wlc_bsscfg_t *cfg); 874extern void wlc_shm_ssid_upd(struct wlc_info *wlc, wlc_bsscfg_t *cfg);
931extern int wlc_set_gmode(wlc_info_t *wlc, u8 gmode, bool config); 875extern int wlc_set_gmode(struct wlc_info *wlc, u8 gmode, bool config);
932 876
933extern void wlc_mac_bcn_promisc_change(wlc_info_t *wlc, bool promisc); 877extern void wlc_mac_bcn_promisc_change(struct wlc_info *wlc, bool promisc);
934extern void wlc_mac_bcn_promisc(wlc_info_t *wlc); 878extern void wlc_mac_bcn_promisc(struct wlc_info *wlc);
935extern void wlc_mac_promisc(wlc_info_t *wlc); 879extern void wlc_mac_promisc(struct wlc_info *wlc);
936extern void wlc_txflowcontrol(wlc_info_t *wlc, wlc_txq_info_t *qi, bool on, 880extern void wlc_txflowcontrol(struct wlc_info *wlc, wlc_txq_info_t *qi, bool on,
937 int prio); 881 int prio);
938extern void wlc_txflowcontrol_override(wlc_info_t *wlc, wlc_txq_info_t *qi, 882extern void wlc_txflowcontrol_override(struct wlc_info *wlc, wlc_txq_info_t *qi,
939 bool on, uint override); 883 bool on, uint override);
940extern bool wlc_txflowcontrol_prio_isset(wlc_info_t *wlc, wlc_txq_info_t *qi, 884extern bool wlc_txflowcontrol_prio_isset(struct wlc_info *wlc,
941 int prio); 885 wlc_txq_info_t *qi, int prio);
942extern void wlc_send_q(wlc_info_t *wlc, wlc_txq_info_t *qi); 886extern void wlc_send_q(struct wlc_info *wlc, wlc_txq_info_t *qi);
943extern int wlc_prep_pdu(wlc_info_t *wlc, void *pdu, uint *fifo); 887extern int wlc_prep_pdu(struct wlc_info *wlc, struct sk_buff *pdu, uint *fifo);
944 888
945extern u16 wlc_calc_lsig_len(wlc_info_t *wlc, ratespec_t ratespec, 889extern u16 wlc_calc_lsig_len(struct wlc_info *wlc, ratespec_t ratespec,
946 uint mac_len); 890 uint mac_len);
947extern ratespec_t wlc_rspec_to_rts_rspec(wlc_info_t *wlc, ratespec_t rspec, 891extern ratespec_t wlc_rspec_to_rts_rspec(struct wlc_info *wlc, ratespec_t rspec,
948 bool use_rspec, u16 mimo_ctlchbw); 892 bool use_rspec, u16 mimo_ctlchbw);
949extern u16 wlc_compute_rtscts_dur(wlc_info_t *wlc, bool cts_only, 893extern u16 wlc_compute_rtscts_dur(struct wlc_info *wlc, bool cts_only,
950 ratespec_t rts_rate, ratespec_t frame_rate, 894 ratespec_t rts_rate, ratespec_t frame_rate,
951 u8 rts_preamble_type, 895 u8 rts_preamble_type,
952 u8 frame_preamble_type, uint frame_len, 896 u8 frame_preamble_type, uint frame_len,
953 bool ba); 897 bool ba);
954 898
955extern void wlc_tbtt(wlc_info_t *wlc, d11regs_t *regs); 899extern void wlc_tbtt(struct wlc_info *wlc, d11regs_t *regs);
956 900
957#if defined(BCMDBG) 901#if defined(BCMDBG)
958extern void wlc_dump_ie(wlc_info_t *wlc, bcm_tlv_t *ie, struct bcmstrbuf *b); 902extern void wlc_dump_ie(struct wlc_info *wlc, bcm_tlv_t *ie,
903 struct bcmstrbuf *b);
959#endif 904#endif
960 905
961extern bool wlc_ps_check(wlc_info_t *wlc); 906extern bool wlc_ps_check(struct wlc_info *wlc);
962extern void wlc_reprate_init(wlc_info_t *wlc); 907extern void wlc_reprate_init(struct wlc_info *wlc);
963extern void wlc_bsscfg_reprate_init(wlc_bsscfg_t *bsscfg); 908extern void wlc_bsscfg_reprate_init(wlc_bsscfg_t *bsscfg);
964extern void wlc_uint64_sub(u32 *a_high, u32 *a_low, u32 b_high, 909extern void wlc_uint64_sub(u32 *a_high, u32 *a_low, u32 b_high,
965 u32 b_low); 910 u32 b_low);
966extern u32 wlc_calc_tbtt_offset(u32 bi, u32 tsf_h, u32 tsf_l); 911extern u32 wlc_calc_tbtt_offset(u32 bi, u32 tsf_h, u32 tsf_l);
967 912
968/* Shared memory access */ 913/* Shared memory access */
969extern void wlc_write_shm(wlc_info_t *wlc, uint offset, u16 v); 914extern void wlc_write_shm(struct wlc_info *wlc, uint offset, u16 v);
970extern u16 wlc_read_shm(wlc_info_t *wlc, uint offset); 915extern u16 wlc_read_shm(struct wlc_info *wlc, uint offset);
971extern void wlc_set_shm(wlc_info_t *wlc, uint offset, u16 v, int len); 916extern void wlc_set_shm(struct wlc_info *wlc, uint offset, u16 v, int len);
972extern void wlc_copyto_shm(wlc_info_t *wlc, uint offset, const void *buf, 917extern void wlc_copyto_shm(struct wlc_info *wlc, uint offset, const void *buf,
973 int len); 918 int len);
974extern void wlc_copyfrom_shm(wlc_info_t *wlc, uint offset, void *buf, int len); 919extern void wlc_copyfrom_shm(struct wlc_info *wlc, uint offset, void *buf,
920 int len);
975 921
976extern void wlc_update_beacon(wlc_info_t *wlc); 922extern void wlc_update_beacon(struct wlc_info *wlc);
977extern void wlc_bss_update_beacon(wlc_info_t *wlc, struct wlc_bsscfg *bsscfg); 923extern void wlc_bss_update_beacon(struct wlc_info *wlc,
924 struct wlc_bsscfg *bsscfg);
978 925
979extern void wlc_update_probe_resp(wlc_info_t *wlc, bool suspend); 926extern void wlc_update_probe_resp(struct wlc_info *wlc, bool suspend);
980extern void wlc_bss_update_probe_resp(wlc_info_t *wlc, wlc_bsscfg_t *cfg, 927extern void wlc_bss_update_probe_resp(struct wlc_info *wlc, wlc_bsscfg_t *cfg,
981 bool suspend); 928 bool suspend);
982 929
983extern bool wlc_ismpc(wlc_info_t *wlc); 930extern bool wlc_ismpc(struct wlc_info *wlc);
984extern bool wlc_is_non_delay_mpc(wlc_info_t *wlc); 931extern bool wlc_is_non_delay_mpc(struct wlc_info *wlc);
985extern void wlc_radio_mpc_upd(wlc_info_t *wlc); 932extern void wlc_radio_mpc_upd(struct wlc_info *wlc);
986extern bool wlc_prec_enq(wlc_info_t *wlc, struct pktq *q, void *pkt, int prec); 933extern bool wlc_prec_enq(struct wlc_info *wlc, struct pktq *q, void *pkt,
987extern bool wlc_prec_enq_head(wlc_info_t *wlc, struct pktq *q, void *pkt, 934 int prec);
988 int prec, bool head); 935extern bool wlc_prec_enq_head(struct wlc_info *wlc, struct pktq *q,
989extern u16 wlc_phytxctl1_calc(wlc_info_t *wlc, ratespec_t rspec); 936 struct sk_buff *pkt, int prec, bool head);
990extern void wlc_compute_plcp(wlc_info_t *wlc, ratespec_t rate, uint length, 937extern u16 wlc_phytxctl1_calc(struct wlc_info *wlc, ratespec_t rspec);
938extern void wlc_compute_plcp(struct wlc_info *wlc, ratespec_t rate, uint length,
991 u8 *plcp); 939 u8 *plcp);
992extern uint wlc_calc_frame_time(wlc_info_t *wlc, ratespec_t ratespec, 940extern uint wlc_calc_frame_time(struct wlc_info *wlc, ratespec_t ratespec,
993 u8 preamble_type, uint mac_len); 941 u8 preamble_type, uint mac_len);
994 942
995extern void wlc_set_chanspec(wlc_info_t *wlc, chanspec_t chanspec); 943extern void wlc_set_chanspec(struct wlc_info *wlc, chanspec_t chanspec);
996 944
997extern bool wlc_timers_init(wlc_info_t *wlc, int unit); 945extern bool wlc_timers_init(struct wlc_info *wlc, int unit);
998 946
999extern const bcm_iovar_t wlc_iovars[]; 947extern const bcm_iovar_t wlc_iovars[];
1000 948
1001extern int wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid, 949extern int wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid,
1002 const char *name, void *params, uint p_len, void *arg, 950 const char *name, void *params, uint p_len, void *arg,
1003 int len, int val_size, wlc_if_t *wlcif); 951 int len, int val_size, struct wlc_if *wlcif);
1004 952
1005#if defined(BCMDBG) 953#if defined(BCMDBG)
1006extern void wlc_print_ies(wlc_info_t *wlc, u8 *ies, uint ies_len); 954extern void wlc_print_ies(struct wlc_info *wlc, u8 *ies, uint ies_len);
1007#endif 955#endif
1008 956
1009extern int wlc_set_nmode(wlc_info_t *wlc, s32 nmode); 957extern int wlc_set_nmode(struct wlc_info *wlc, s32 nmode);
1010extern void wlc_ht_mimops_cap_update(wlc_info_t *wlc, u8 mimops_mode); 958extern void wlc_ht_mimops_cap_update(struct wlc_info *wlc, u8 mimops_mode);
1011extern void wlc_mimops_action_ht_send(wlc_info_t *wlc, wlc_bsscfg_t *bsscfg, 959extern void wlc_mimops_action_ht_send(struct wlc_info *wlc,
1012 u8 mimops_mode); 960 wlc_bsscfg_t *bsscfg, u8 mimops_mode);
1013 961
1014extern void wlc_switch_shortslot(wlc_info_t *wlc, bool shortslot); 962extern void wlc_switch_shortslot(struct wlc_info *wlc, bool shortslot);
1015extern void wlc_set_bssid(wlc_bsscfg_t *cfg); 963extern void wlc_set_bssid(wlc_bsscfg_t *cfg);
1016extern void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend); 964extern void wlc_edcf_setparams(wlc_bsscfg_t *cfg, bool suspend);
1017extern void wlc_wme_setparams(wlc_info_t *wlc, u16 aci, void *arg,
1018 bool suspend);
1019 965
1020extern void wlc_set_ratetable(wlc_info_t *wlc); 966extern void wlc_set_ratetable(struct wlc_info *wlc);
1021extern int wlc_set_mac(wlc_bsscfg_t *cfg); 967extern int wlc_set_mac(wlc_bsscfg_t *cfg);
1022extern void wlc_beacon_phytxctl_txant_upd(wlc_info_t *wlc, 968extern void wlc_beacon_phytxctl_txant_upd(struct wlc_info *wlc,
1023 ratespec_t bcn_rate); 969 ratespec_t bcn_rate);
1024extern void wlc_mod_prb_rsp_rate_table(wlc_info_t *wlc, uint frame_len); 970extern void wlc_mod_prb_rsp_rate_table(struct wlc_info *wlc, uint frame_len);
1025extern ratespec_t wlc_lowest_basic_rspec(wlc_info_t *wlc, wlc_rateset_t *rs); 971extern ratespec_t wlc_lowest_basic_rspec(struct wlc_info *wlc,
1026extern u16 wlc_compute_bcntsfoff(wlc_info_t *wlc, ratespec_t rspec, 972 wlc_rateset_t *rs);
973extern u16 wlc_compute_bcntsfoff(struct wlc_info *wlc, ratespec_t rspec,
1027 bool short_preamble, bool phydelay); 974 bool short_preamble, bool phydelay);
1028extern void wlc_radio_disable(wlc_info_t *wlc); 975extern void wlc_radio_disable(struct wlc_info *wlc);
1029extern void wlc_bcn_li_upd(wlc_info_t *wlc); 976extern void wlc_bcn_li_upd(struct wlc_info *wlc);
1030 977
1031extern int wlc_get_revision_info(wlc_info_t *wlc, void *buf, uint len); 978extern int wlc_get_revision_info(struct wlc_info *wlc, void *buf, uint len);
1032extern void wlc_out(wlc_info_t *wlc); 979extern void wlc_out(struct wlc_info *wlc);
1033extern void wlc_set_home_chanspec(wlc_info_t *wlc, chanspec_t chanspec); 980extern void wlc_set_home_chanspec(struct wlc_info *wlc, chanspec_t chanspec);
1034extern void wlc_watchdog_upd(wlc_info_t *wlc, bool tbtt); 981extern void wlc_watchdog_upd(struct wlc_info *wlc, bool tbtt);
1035extern bool wlc_ps_allowed(wlc_info_t *wlc); 982extern bool wlc_ps_allowed(struct wlc_info *wlc);
1036extern bool wlc_stay_awake(wlc_info_t *wlc); 983extern bool wlc_stay_awake(struct wlc_info *wlc);
1037extern void wlc_wme_initparams_sta(wlc_info_t *wlc, wme_param_ie_t *pe); 984extern void wlc_wme_initparams_sta(struct wlc_info *wlc, wme_param_ie_t *pe);
1038 985
1039extern void wlc_bss_list_free(wlc_info_t *wlc, wlc_bss_list_t *bss_list); 986extern void wlc_bss_list_free(struct wlc_info *wlc, wlc_bss_list_t *bss_list);
987extern void wlc_ht_mimops_cap_update(struct wlc_info *wlc, u8 mimops_mode);
1040#endif /* _wlc_h_ */ 988#endif /* _wlc_h_ */
diff --git a/drivers/staging/brcm80211/sys/wlc_phy_shim.c b/drivers/staging/brcm80211/sys/wlc_phy_shim.c
index bf8e2e1a15f6..8bd4ede4c92a 100644
--- a/drivers/staging/brcm80211/sys/wlc_phy_shim.c
+++ b/drivers/staging/brcm80211/sys/wlc_phy_shim.c
@@ -24,9 +24,10 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <bcmdefs.h> 25#include <bcmdefs.h>
26#include <wlc_cfg.h> 26#include <wlc_cfg.h>
27#include <linuxver.h> 27#include <linux/module.h>
28#include <bcmutils.h> 28#include <linux/pci.h>
29#include <osl.h> 29#include <osl.h>
30#include <bcmutils.h>
30 31
31#include <proto/802.11.h> 32#include <proto/802.11.h>
32#include <bcmwifi.h> 33#include <bcmwifi.h>
@@ -46,6 +47,7 @@
46#include <wlc_channel.h> 47#include <wlc_channel.h>
47#include <bcmsrom.h> 48#include <bcmsrom.h>
48#include <wlc_key.h> 49#include <wlc_key.h>
50#include <wlc_event.h>
49 51
50#include <wlc_mac80211.h> 52#include <wlc_mac80211.h>
51 53
@@ -53,21 +55,23 @@
53#include <wlc_phy_shim.h> 55#include <wlc_phy_shim.h>
54#include <wlc_phy_hal.h> 56#include <wlc_phy_hal.h>
55#include <wl_export.h> 57#include <wl_export.h>
58#include <wl_dbg.h>
56 59
57/* PHY SHIM module specific state */ 60/* PHY SHIM module specific state */
58struct wlc_phy_shim_info { 61struct wlc_phy_shim_info {
59 wlc_hw_info_t *wlc_hw; /* pointer to main wlc_hw structure */ 62 struct wlc_hw_info *wlc_hw; /* pointer to main wlc_hw structure */
60 void *wlc; /* pointer to main wlc structure */ 63 void *wlc; /* pointer to main wlc structure */
61 void *wl; /* pointer to os-specific private state */ 64 void *wl; /* pointer to os-specific private state */
62}; 65};
63 66
64wlc_phy_shim_info_t *wlc_phy_shim_attach(wlc_hw_info_t *wlc_hw, 67wlc_phy_shim_info_t *wlc_phy_shim_attach(struct wlc_hw_info *wlc_hw,
65 void *wl, void *wlc) { 68 void *wl, void *wlc) {
66 wlc_phy_shim_info_t *physhim = NULL; 69 wlc_phy_shim_info_t *physhim = NULL;
67 70
68 physhim = kzalloc(sizeof(wlc_phy_shim_info_t), GFP_ATOMIC); 71 physhim = kzalloc(sizeof(wlc_phy_shim_info_t), GFP_ATOMIC);
69 if (!physhim) { 72 if (!physhim) {
70 WL_ERROR(("wl%d: wlc_phy_shim_attach: out of mem\n", wlc_hw->unit)); 73 WL_ERROR("wl%d: wlc_phy_shim_attach: out of mem\n",
74 wlc_hw->unit);
71 return NULL; 75 return NULL;
72 } 76 }
73 physhim->wlc_hw = wlc_hw; 77 physhim->wlc_hw = wlc_hw;
diff --git a/drivers/staging/brcm80211/sys/wlc_pub.h b/drivers/staging/brcm80211/sys/wlc_pub.h
index a6a8c33483c9..146a6904a39b 100644
--- a/drivers/staging/brcm80211/sys/wlc_pub.h
+++ b/drivers/staging/brcm80211/sys/wlc_pub.h
@@ -251,7 +251,7 @@ typedef int (*iovar_fn_t) (void *handle, const bcm_iovar_t *vi,
251 * Public portion of "common" os-independent state structure. 251 * Public portion of "common" os-independent state structure.
252 * The wlc handle points at this. 252 * The wlc handle points at this.
253 */ 253 */
254typedef struct wlc_pub { 254struct wlc_pub {
255 void *wlc; 255 void *wlc;
256 256
257 struct ieee80211_hw *ieee_hw; 257 struct ieee80211_hw *ieee_hw;
@@ -260,7 +260,7 @@ typedef struct wlc_pub {
260 uint mac80211_state; 260 uint mac80211_state;
261 uint unit; /* device instance number */ 261 uint unit; /* device instance number */
262 uint corerev; /* core revision */ 262 uint corerev; /* core revision */
263 osl_t *osh; /* pointer to os handle */ 263 struct osl_info *osh; /* pointer to os handle */
264 si_t *sih; /* SB handle (cookie for siutils calls) */ 264 si_t *sih; /* SB handle (cookie for siutils calls) */
265 char *vars; /* "environment" name=value */ 265 char *vars; /* "environment" name=value */
266 bool up; /* interface up and running */ 266 bool up; /* interface up and running */
@@ -318,9 +318,6 @@ typedef struct wlc_pub {
318 * is implemented properly in osl of that port 318 * is implemented properly in osl of that port
319 * when it enables this Power Save feature. 319 * when it enables this Power Save feature.
320 */ 320 */
321#ifdef BCMSDIO
322 uint sdiod_drive_strength; /* SDIO drive strength */
323#endif /* BCMSDIO */
324 321
325 u16 boardrev; /* version # of particular board */ 322 u16 boardrev; /* version # of particular board */
326 u8 sromrev; /* version # of the srom */ 323 u8 sromrev; /* version # of the srom */
@@ -333,7 +330,7 @@ typedef struct wlc_pub {
333 bool _lmacproto; /* lmac protocol module included and enabled */ 330 bool _lmacproto; /* lmac protocol module included and enabled */
334 bool phy_11ncapable; /* the PHY/HW is capable of 802.11N */ 331 bool phy_11ncapable; /* the PHY/HW is capable of 802.11N */
335 bool _ampdumac; /* mac assist ampdu enabled or not */ 332 bool _ampdumac; /* mac assist ampdu enabled or not */
336} wlc_pub_t; 333};
337 334
338/* wl_monitor rx status per packet */ 335/* wl_monitor rx status per packet */
339typedef struct wl_rxsts { 336typedef struct wl_rxsts {
@@ -437,17 +434,13 @@ struct wlc_if;
437#define EDCF_ENAB(pub) (WME_ENAB(pub)) 434#define EDCF_ENAB(pub) (WME_ENAB(pub))
438#define QOS_ENAB(pub) (WME_ENAB(pub) || N_ENAB(pub)) 435#define QOS_ENAB(pub) (WME_ENAB(pub) || N_ENAB(pub))
439 436
440#define MONITOR_ENAB(wlc) (bcmspace && (wlc)->monitor) 437#define MONITOR_ENAB(wlc) ((wlc)->monitor)
441
442#define PROMISC_ENAB(wlc) (bcmspace && (wlc)->promisc)
443
444extern void wlc_pkttag_info_move(wlc_pub_t *pub, void *pkt_from, void *pkt_to);
445 438
446#define WLPKTTAGSCB(p) (WLPKTTAG(p)->_scb) 439#define PROMISC_ENAB(wlc) ((wlc)->promisc)
447 440
448#define WLC_PREC_COUNT 16 /* Max precedence level implemented */ 441#define WLC_PREC_COUNT 16 /* Max precedence level implemented */
449 442
450/* pri is PKTPRIO encoded in the packet. This maps the Packet priority to 443/* pri is priority encoded in the packet. This maps the Packet priority to
451 * enqueue precedence as defined in wlc_prec_map 444 * enqueue precedence as defined in wlc_prec_map
452 */ 445 */
453extern const u8 wlc_prio2prec_map[]; 446extern const u8 wlc_prio2prec_map[];
@@ -497,8 +490,8 @@ extern const u8 wme_fifo2ac[];
497 490
498/* common functions for every port */ 491/* common functions for every port */
499extern void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, 492extern void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit,
500 bool piomode, osl_t *osh, void *regsva, uint bustype, 493 bool piomode, struct osl_info *osh, void *regsva,
501 void *btparam, uint *perr); 494 uint bustype, void *btparam, uint *perr);
502extern uint wlc_detach(struct wlc_info *wlc); 495extern uint wlc_detach(struct wlc_info *wlc);
503extern int wlc_up(struct wlc_info *wlc); 496extern int wlc_up(struct wlc_info *wlc);
504extern uint wlc_down(struct wlc_info *wlc); 497extern uint wlc_down(struct wlc_info *wlc);
@@ -517,8 +510,10 @@ extern void wlc_intrsrestore(struct wlc_info *wlc, u32 macintmask);
517extern bool wlc_intrsupd(struct wlc_info *wlc); 510extern bool wlc_intrsupd(struct wlc_info *wlc);
518extern bool wlc_isr(struct wlc_info *wlc, bool *wantdpc); 511extern bool wlc_isr(struct wlc_info *wlc, bool *wantdpc);
519extern bool wlc_dpc(struct wlc_info *wlc, bool bounded); 512extern bool wlc_dpc(struct wlc_info *wlc, bool bounded);
520extern bool wlc_send80211_raw(struct wlc_info *wlc, wlc_if_t *wlcif, void *p, 513extern bool wlc_send80211_raw(struct wlc_info *wlc, struct wlc_if *wlcif,
521 uint ac); 514 void *p, uint ac);
515extern bool wlc_sendpkt_mac80211(struct wlc_info *wlc, struct sk_buff *sdu,
516 struct ieee80211_hw *hw);
522extern int wlc_iovar_op(struct wlc_info *wlc, const char *name, void *params, 517extern int wlc_iovar_op(struct wlc_info *wlc, const char *name, void *params,
523 int p_len, void *arg, int len, bool set, 518 int p_len, void *arg, int len, bool set,
524 struct wlc_if *wlcif); 519 struct wlc_if *wlcif);
@@ -527,8 +522,13 @@ extern int wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len,
527/* helper functions */ 522/* helper functions */
528extern void wlc_statsupd(struct wlc_info *wlc); 523extern void wlc_statsupd(struct wlc_info *wlc);
529extern int wlc_get_header_len(void); 524extern int wlc_get_header_len(void);
525extern void wlc_mac_bcn_promisc_change(struct wlc_info *wlc, bool promisc);
526extern void wlc_set_addrmatch(struct wlc_info *wlc, int match_reg_offset,
527 const struct ether_addr *addr);
528extern void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, void *arg,
529 bool suspend);
530 530
531extern wlc_pub_t *wlc_pub(void *wlc); 531extern struct wlc_pub *wlc_pub(void *wlc);
532 532
533/* common functions for every port */ 533/* common functions for every port */
534extern int wlc_bmac_up_prep(struct wlc_hw_info *wlc_hw); 534extern int wlc_bmac_up_prep(struct wlc_hw_info *wlc_hw);
@@ -554,13 +554,15 @@ extern void wlc_scb_ratesel_init_all(struct wlc_info *wlc);
554/* ioctl */ 554/* ioctl */
555extern int wlc_iovar_gets8(struct wlc_info *wlc, const char *name, 555extern int wlc_iovar_gets8(struct wlc_info *wlc, const char *name,
556 s8 *arg); 556 s8 *arg);
557extern int wlc_iovar_check(wlc_pub_t *pub, const bcm_iovar_t *vi, void *arg, 557extern int wlc_iovar_check(struct wlc_pub *pub, const bcm_iovar_t *vi,
558 void *arg,
558 int len, bool set); 559 int len, bool set);
559 560
560extern int wlc_module_register(wlc_pub_t *pub, const bcm_iovar_t *iovars, 561extern int wlc_module_register(struct wlc_pub *pub, const bcm_iovar_t *iovars,
561 const char *name, void *hdl, iovar_fn_t iovar_fn, 562 const char *name, void *hdl, iovar_fn_t iovar_fn,
562 watchdog_fn_t watchdog_fn, down_fn_t down_fn); 563 watchdog_fn_t watchdog_fn, down_fn_t down_fn);
563extern int wlc_module_unregister(wlc_pub_t *pub, const char *name, void *hdl); 564extern int wlc_module_unregister(struct wlc_pub *pub, const char *name,
565 void *hdl);
564extern void wlc_event_if(struct wlc_info *wlc, struct wlc_bsscfg *cfg, 566extern void wlc_event_if(struct wlc_info *wlc, struct wlc_bsscfg *cfg,
565 wlc_event_t *e, const struct ether_addr *addr); 567 wlc_event_t *e, const struct ether_addr *addr);
566extern void wlc_suspend_mac_and_wait(struct wlc_info *wlc); 568extern void wlc_suspend_mac_and_wait(struct wlc_info *wlc);
@@ -617,10 +619,6 @@ extern void wlc_pmkid_event(struct wlc_bsscfg *cfg);
617#define BAND_2G_NAME "2.4G" 619#define BAND_2G_NAME "2.4G"
618#define BAND_5G_NAME "5G" 620#define BAND_5G_NAME "5G"
619 621
620#if defined(BCMSDIO) || defined(WLC_HIGH_ONLY)
621void wlc_device_removed(void *arg);
622#endif
623
624/* BMAC RPC: 7 u32 params: pkttotlen, fifo, commit, fid, txpktpend, pktflag, rpc_id */ 622/* BMAC RPC: 7 u32 params: pkttotlen, fifo, commit, fid, txpktpend, pktflag, rpc_id */
625#define WLC_RPCTX_PARAMS 32 623#define WLC_RPCTX_PARAMS 32
626 624
diff --git a/drivers/staging/brcm80211/sys/wlc_rate.c b/drivers/staging/brcm80211/sys/wlc_rate.c
index d2d72568756d..ab7d0bed3c0a 100644
--- a/drivers/staging/brcm80211/sys/wlc_rate.c
+++ b/drivers/staging/brcm80211/sys/wlc_rate.c
@@ -17,12 +17,14 @@
17#include <bcmdefs.h> 17#include <bcmdefs.h>
18#include <wlc_cfg.h> 18#include <wlc_cfg.h>
19#include <osl.h> 19#include <osl.h>
20#include <linuxver.h> 20#include <linux/module.h>
21#include <bcmutils.h> 21#include <bcmutils.h>
22#include <siutils.h> 22#include <siutils.h>
23#include <bcmendian.h> 23#include <bcmendian.h>
24#include <wlioctl.h> 24#include <wlioctl.h>
25 25
26#include <sbhndpio.h>
27#include <sbhnddma.h>
26#include <proto/802.11.h> 28#include <proto/802.11.h>
27#include <d11.h> 29#include <d11.h>
28#include <wlc_rate.h> 30#include <wlc_rate.h>
@@ -297,7 +299,7 @@ wlc_rate_hwrs_filter_sort_validate(wlc_rateset_t *rs,
297 uint count; 299 uint count;
298 uint i; 300 uint i;
299 301
300 bzero(rateset, sizeof(rateset)); 302 memset(rateset, 0, sizeof(rateset));
301 count = rs->count; 303 count = rs->count;
302 304
303 for (i = 0; i < count; i++) { 305 for (i = 0; i < count; i++) {
diff --git a/drivers/staging/brcm80211/sys/wlc_rpc.h b/drivers/staging/brcm80211/sys/wlc_rpc.h
deleted file mode 100644
index db39645ccbdc..000000000000
--- a/drivers/staging/brcm80211/sys/wlc_rpc.h
+++ /dev/null
@@ -1,527 +0,0 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _WLC_RPC_H_
18#define _WLC_RPC_H_
19
20#include <wlc_types.h>
21
22/* RPC IDs, reordering is OK. This needs to be in sync with RPC_ID_TABLE below */
23typedef enum {
24 WLRPC_NULL_ID = 0,
25 WLRPC_WLC_REG_READ_ID,
26 WLRPC_WLC_REG_WRITE_ID,
27 WLRPC_WLC_MHF_SET_ID,
28 WLRPC_WLC_MHF_GET_ID,
29 WLRPC_WLC_BMAC_UP_PREP_ID,
30 WLRPC_WLC_BMAC_UP_FINISH_ID,
31 WLRPC_WLC_BMAC_DOWN_PREP_ID,
32 WLRPC_WLC_BMAC_DOWN_FINISH_ID,
33 WLRPC_WLC_BMAC_WRITE_HW_BCNTEMPLATES_ID,
34 WLRPC_WLC_BMAC_RESET_ID,
35 WLRPC_WLC_DNGL_REBOOT_ID,
36 WLRPC_WLC_BMAC_RPC_TXQ_WM_SET_ID,
37 WLRPC_WLC_BMAC_RPC_TXQ_WM_GET_ID,
38 WLRPC_WLC_BMAC_RPC_AGG_SET_ID,
39 WLRPC_WLC_BMAC_RPC_MSGLEVEL_SET_ID,
40 WLRPC_WLC_BMAC_RPC_AGG_LIMIT_SET_ID,
41 WLRPC_WLC_BMAC_RPC_AGG_LIMIT_GET_ID,
42 WLRPC_WLC_BMAC_INIT_ID,
43 WLRPC_WLC_BMAC_SET_CWMIN_ID,
44 WLRPC_WLC_BMAC_MUTE_ID,
45 WLRPC_WLC_PHY_DOIOVAR_ID,
46 WLRPC_WLC_PHY_HOLD_UPD_ID,
47 WLRPC_WLC_PHY_MUTE_UPD_ID,
48 WLRPC_WLC_PHY_CLEAR_TSSI_ID,
49 WLRPC_WLC_PHY_ANT_RXDIV_GET_ID,
50 WLRPC_WLC_PHY_ANT_RXDIV_SET_ID,
51 WLRPC_WLC_PHY_PREAMBLE_SET_ID,
52 WLRPC_WLC_PHY_FREQTRACK_END_ID,
53 WLRPC_WLC_PHY_FREQTRACK_START_ID,
54 WLRPC_WLC_PHY_IOCTL_ID,
55 WLRPC_WLC_PHY_NOISE_SAMPLE_REQUEST_ID,
56 WLRPC_WLC_PHY_CAL_PERICAL_ID,
57 WLRPC_WLC_PHY_TXPOWER_GET_ID,
58 WLRPC_WLC_PHY_TXPOWER_SET_ID,
59 WLRPC_WLC_PHY_TXPOWER_SROMLIMIT_ID,
60 WLRPC_WLC_PHY_RADAR_DETECT_ENABLE_ID,
61 WLRPC_WLC_PHY_RADAR_DETECT_RUN_ID,
62 WLRPC_WLC_PHY_TEST_ISON_ID,
63 WLRPC_WLC_BMAC_COPYFROM_OBJMEM_ID,
64 WLRPC_WLC_BMAC_COPYTO_OBJMEM_ID,
65 WLRPC_WLC_ENABLE_MAC_ID,
66 WLRPC_WLC_MCTRL_ID,
67 WLRPC_WLC_CORERESET_ID,
68 WLRPC_WLC_BMAC_READ_SHM_ID,
69 WLRPC_WLC_BMAC_READ_TSF_ID,
70 WLRPC_WLC_BMAC_SET_ADDRMATCH_ID,
71 WLRPC_WLC_BMAC_SET_CWMAX_ID,
72 WLRPC_WLC_BMAC_SET_RCMTA_ID,
73 WLRPC_WLC_BMAC_SET_SHM_ID,
74 WLRPC_WLC_SUSPEND_MAC_AND_WAIT_ID,
75 WLRPC_WLC_BMAC_WRITE_SHM_ID,
76 WLRPC_WLC_BMAC_WRITE_TEMPLATE_RAM_ID,
77 WLRPC_WLC_TX_FIFO_SUSPEND_ID,
78 WLRPC_WLC_TX_FIFO_RESUME_ID,
79 WLRPC_WLC_TX_FIFO_SUSPENDED_ID,
80 WLRPC_WLC_HW_ETHERADDR_ID,
81 WLRPC_WLC_SET_HW_ETHERADDR_ID,
82 WLRPC_WLC_BMAC_CHANSPEC_SET_ID,
83 WLRPC_WLC_BMAC_TXANT_SET_ID,
84 WLRPC_WLC_BMAC_ANTSEL_TYPE_SET_ID,
85 WLRPC_WLC_BMAC_TXFIFO_ID,
86 WLRPC_WLC_RADIO_READ_HWDISABLED_ID,
87 WLRPC_WLC_RM_CCA_MEASURE_ID,
88 WLRPC_WLC_SET_SHORTSLOT_ID,
89 WLRPC_WLC_WAIT_FOR_WAKE_ID,
90 WLRPC_WLC_PHY_TXPOWER_GET_CURRENT_ID,
91 WLRPC_WLC_PHY_TXPOWER_HW_CTRL_GET_ID,
92 WLRPC_WLC_PHY_TXPOWER_HW_CTRL_SET_ID,
93 WLRPC_WLC_PHY_BSSINIT_ID,
94 WLRPC_WLC_BAND_STF_SS_SET_ID,
95 WLRPC_WLC_PHY_BAND_FIRST_CHANSPEC_ID,
96 WLRPC_WLC_PHY_TXPOWER_LIMIT_SET_ID,
97 WLRPC_WLC_PHY_BAND_CHANNELS_ID,
98 WLRPC_WLC_BMAC_REVINFO_GET_ID,
99 WLRPC_WLC_BMAC_STATE_GET_ID,
100 WLRPC_WLC_BMAC_XMTFIFO_SZ_GET_ID,
101 WLRPC_WLC_BMAC_XMTFIFO_SZ_SET_ID,
102 WLRPC_WLC_BMAC_VALIDATE_CHIP_ACCESS_ID,
103 WLRPC_WLC_RM_CCA_COMPLETE_ID,
104 WLRPC_WLC_RECV_ID,
105 WLRPC_WLC_DOTXSTATUS_ID,
106 WLRPC_WLC_HIGH_DPC_ID,
107 WLRPC_WLC_FATAL_ERROR_ID,
108 WLRPC_WLC_PHY_SET_CHANNEL_14_WIDE_FILTER_ID,
109 WLRPC_WLC_PHY_NOISE_AVG_ID,
110 WLRPC_WLC_PHYCHAIN_INIT_ID,
111 WLRPC_WLC_PHYCHAIN_SET_ID,
112 WLRPC_WLC_PHYCHAIN_GET_ID,
113 WLRPC_WLC_PHY_TKIP_RIFS_WAR_ID,
114 WLRPC_WLC_BMAC_COPYFROM_VARS_ID,
115 WLRPC_WLC_BMAC_RETRYLIMIT_UPD_ID,
116 WLRPC_WLC_BMAC_BTC_MODE_SET_ID,
117 WLRPC_WLC_BMAC_BTC_MODE_GET_ID,
118 WLRPC_WLC_BMAC_BTC_WIRE_SET_ID,
119 WLRPC_WLC_BMAC_BTC_WIRE_GET_ID,
120 WLRPC_WLC_BMAC_SET_NORESET_ID,
121 WLRPC_WLC_AMPDU_TXSTATUS_COMPLETE_ID,
122 WLRPC_WLC_BMAC_FIFOERRORS_ID,
123 WLRPC_WLC_PHY_TXPOWER_GET_TARGET_MIN_ID,
124 WLRPC_WLC_PHY_TXPOWER_GET_TARGET_MAX_ID,
125 WLRPC_WLC_NOISE_CB_ID,
126 WLRPC_WLC_BMAC_LED_HW_DEINIT_ID,
127 WLRPC_WLC_BMAC_LED_HW_MASK_INIT_ID,
128 WLRPC_WLC_PLLREQ_ID,
129 WLRPC_WLC_BMAC_TACLEAR_ID,
130 WLRPC_WLC_BMAC_SET_CLK_ID,
131 WLRPC_WLC_PHY_OFDM_RATESET_WAR_ID,
132 WLRPC_WLC_PHY_BF_PREEMPT_ENABLE_ID,
133 WLRPC_WLC_BMAC_DOIOVARS_ID,
134 WLRPC_WLC_BMAC_DUMP_ID,
135 WLRPC_WLC_CISWRITE_ID,
136 WLRPC_WLC_CISDUMP_ID,
137 WLRPC_WLC_UPDATE_PHY_MODE_ID,
138 WLRPC_WLC_RESET_BMAC_DONE_ID,
139 WLRPC_WLC_BMAC_LED_BLINK_EVENT_ID,
140 WLRPC_WLC_BMAC_LED_SET_ID,
141 WLRPC_WLC_BMAC_LED_BLINK_ID,
142 WLRPC_WLC_BMAC_LED_ID,
143 WLRPC_WLC_BMAC_RATE_SHM_OFFSET_ID,
144 WLRPC_SI_ISCORE_UP_ID,
145 WLRPC_WLC_BMAC_PS_SWITCH_ID,
146 WLRPC_WLC_PHY_STF_SSMODE_GET_ID,
147 WLRPC_WLC_BMAC_DEBUG_ID,
148 WLRPC_WLC_EXTLOG_MSG_ID,
149 WLRPC_WLC_EXTLOG_CFG_ID,
150 WLRPC_BCM_ASSERT_LOG_ID,
151 WLRPC_BCM_ASSERT_TYPE_ID,
152 WLRPC_WLC_BMAC_SET_PHYCAL_CACHE_FLAG_ID,
153 WLRPC_WLC_BMAC_GET_PHYCAL_CACHE_FLAG_ID,
154 WLRPC_WLC_PHY_CAL_CACHE_INIT_ID,
155 WLRPC_WLC_PHY_CAL_CACHE_DEINIT_ID,
156 WLRPC_WLC_BMAC_HW_UP_ID,
157 WLRPC_WLC_BMAC_SET_TXPWR_PERCENT_ID,
158 WLRPC_WLC_PHYCHAIN_ACTIVE_GET_ID,
159 WLRPC_WLC_BMAC_BLINK_SYNC_ID,
160 WLRPC_WLC_BMAC_UCODE_DBGSEL_SET_ID,
161 WLRPC_WLC_BMAC_UCODE_DBGSEL_GET_ID,
162 WLRPC_WLC_PHY_RADAR_DETECT_MODE_SET_ID,
163 WLRPC_WLC_PHY_ACIM_NOISEM_RESET_NPHY_ID,
164 WLRPC_WLC_PHY_INTERFER_SET_NPHY_ID,
165 WLRPC_WLC_BMAC_IFSCTL_EDCRS_SET_ID,
166 WLRPC_WLC_PKTENGTX,
167 WLRPC_WLC_BMAC_SET_DEAF,
168 WLRPC_WLC_BMAC_CLEAR_DEAF,
169 WLRPC_WLC_BMAC_BTC_FLAGS_SET_ID,
170 WLRPC_WLC_BMAC_BTC_FLAGS_GET_ID,
171 WLRPC_WLC_BMAC_SET_RCMTA_TYPE_ID,
172 WLRPC_WLC_BMAC_BTC_FLAGS_UPD_ID,
173 WLRPC_WLC_BMAC_BTC_STUCKWAR_ID,
174 WLRPC_WLC_BMAC_CCA_STATS_READ_ID,
175 WLRPC_WLC_BMAC_ANTSEL_SET_ID,
176 WLRPC_WLC_BMAC_SET_UCODE_LOADED,
177 WLRPC_WLC_PHY_LDPC_SET_ID,
178
179 WLRPC_LAST
180} wlc_rpc_id_t;
181
182#if defined(BCMDBG) | 0
183struct name_entry {
184 int id;
185 char *name;
186};
187
188#define NAME_ENTRY(x) {x, #x}
189
190#define RPC_ID_TABLE { \
191 NAME_ENTRY(WLRPC_WLC_REG_READ_ID), \
192 NAME_ENTRY(WLRPC_WLC_REG_WRITE_ID), \
193 NAME_ENTRY(WLRPC_WLC_MHF_SET_ID), \
194 NAME_ENTRY(WLRPC_WLC_MHF_GET_ID), \
195 NAME_ENTRY(WLRPC_WLC_BMAC_UP_PREP_ID), \
196 NAME_ENTRY(WLRPC_WLC_BMAC_UP_FINISH_ID), \
197 NAME_ENTRY(WLRPC_WLC_BMAC_DOWN_PREP_ID), \
198 NAME_ENTRY(WLRPC_WLC_BMAC_DOWN_FINISH_ID), \
199 NAME_ENTRY(WLRPC_WLC_BMAC_WRITE_HW_BCNTEMPLATES_ID), \
200 NAME_ENTRY(WLRPC_WLC_BMAC_RESET_ID), \
201 NAME_ENTRY(WLRPC_WLC_DNGL_REBOOT_ID), \
202 NAME_ENTRY(WLRPC_WLC_BMAC_RPC_TXQ_WM_SET_ID), \
203 NAME_ENTRY(WLRPC_WLC_BMAC_RPC_TXQ_WM_GET_ID), \
204 NAME_ENTRY(WLRPC_WLC_BMAC_RPC_AGG_SET_ID), \
205 NAME_ENTRY(WLRPC_WLC_BMAC_RPC_MSGLEVEL_SET_ID), \
206 NAME_ENTRY(WLRPC_WLC_BMAC_RPC_AGG_LIMIT_SET_ID), \
207 NAME_ENTRY(WLRPC_WLC_BMAC_RPC_AGG_LIMIT_GET_ID), \
208 NAME_ENTRY(WLRPC_WLC_BMAC_INIT_ID), \
209 NAME_ENTRY(WLRPC_WLC_BMAC_SET_CWMIN_ID), \
210 NAME_ENTRY(WLRPC_WLC_BMAC_MUTE_ID), \
211 NAME_ENTRY(WLRPC_WLC_PHY_DOIOVAR_ID), \
212 NAME_ENTRY(WLRPC_WLC_PHY_HOLD_UPD_ID), \
213 NAME_ENTRY(WLRPC_WLC_PHY_MUTE_UPD_ID), \
214 NAME_ENTRY(WLRPC_WLC_PHY_CLEAR_TSSI_ID), \
215 NAME_ENTRY(WLRPC_WLC_PHY_ANT_RXDIV_GET_ID), \
216 NAME_ENTRY(WLRPC_WLC_PHY_ANT_RXDIV_SET_ID), \
217 NAME_ENTRY(WLRPC_WLC_PHY_PREAMBLE_SET_ID), \
218 NAME_ENTRY(WLRPC_WLC_PHY_FREQTRACK_END_ID), \
219 NAME_ENTRY(WLRPC_WLC_PHY_FREQTRACK_START_ID), \
220 NAME_ENTRY(WLRPC_WLC_PHY_IOCTL_ID), \
221 NAME_ENTRY(WLRPC_WLC_PHY_NOISE_SAMPLE_REQUEST_ID), \
222 NAME_ENTRY(WLRPC_WLC_PHY_CAL_PERICAL_ID), \
223 NAME_ENTRY(WLRPC_WLC_PHY_TXPOWER_GET_ID), \
224 NAME_ENTRY(WLRPC_WLC_PHY_TXPOWER_SET_ID), \
225 NAME_ENTRY(WLRPC_WLC_PHY_TXPOWER_SROMLIMIT_ID), \
226 NAME_ENTRY(WLRPC_WLC_PHY_RADAR_DETECT_ENABLE_ID), \
227 NAME_ENTRY(WLRPC_WLC_PHY_RADAR_DETECT_RUN_ID), \
228 NAME_ENTRY(WLRPC_WLC_PHY_TEST_ISON_ID), \
229 NAME_ENTRY(WLRPC_WLC_BMAC_COPYFROM_OBJMEM_ID), \
230 NAME_ENTRY(WLRPC_WLC_BMAC_COPYTO_OBJMEM_ID), \
231 NAME_ENTRY(WLRPC_WLC_ENABLE_MAC_ID), \
232 NAME_ENTRY(WLRPC_WLC_MCTRL_ID), \
233 NAME_ENTRY(WLRPC_WLC_CORERESET_ID), \
234 NAME_ENTRY(WLRPC_WLC_BMAC_READ_SHM_ID), \
235 NAME_ENTRY(WLRPC_WLC_BMAC_READ_TSF_ID), \
236 NAME_ENTRY(WLRPC_WLC_BMAC_SET_ADDRMATCH_ID), \
237 NAME_ENTRY(WLRPC_WLC_BMAC_SET_CWMAX_ID), \
238 NAME_ENTRY(WLRPC_WLC_BMAC_SET_RCMTA_ID), \
239 NAME_ENTRY(WLRPC_WLC_BMAC_SET_SHM_ID), \
240 NAME_ENTRY(WLRPC_WLC_SUSPEND_MAC_AND_WAIT_ID), \
241 NAME_ENTRY(WLRPC_WLC_BMAC_WRITE_SHM_ID), \
242 NAME_ENTRY(WLRPC_WLC_BMAC_WRITE_TEMPLATE_RAM_ID), \
243 NAME_ENTRY(WLRPC_WLC_TX_FIFO_SUSPEND_ID), \
244 NAME_ENTRY(WLRPC_WLC_TX_FIFO_RESUME_ID), \
245 NAME_ENTRY(WLRPC_WLC_TX_FIFO_SUSPENDED_ID), \
246 NAME_ENTRY(WLRPC_WLC_HW_ETHERADDR_ID), \
247 NAME_ENTRY(WLRPC_WLC_SET_HW_ETHERADDR_ID), \
248 NAME_ENTRY(WLRPC_WLC_BMAC_CHANSPEC_SET_ID), \
249 NAME_ENTRY(WLRPC_WLC_BMAC_TXANT_SET_ID), \
250 NAME_ENTRY(WLRPC_WLC_BMAC_ANTSEL_TYPE_SET_ID), \
251 NAME_ENTRY(WLRPC_WLC_BMAC_TXFIFO_ID), \
252 NAME_ENTRY(WLRPC_WLC_RADIO_READ_HWDISABLED_ID), \
253 NAME_ENTRY(WLRPC_WLC_RM_CCA_MEASURE_ID), \
254 NAME_ENTRY(WLRPC_WLC_SET_SHORTSLOT_ID), \
255 NAME_ENTRY(WLRPC_WLC_WAIT_FOR_WAKE_ID), \
256 NAME_ENTRY(WLRPC_WLC_PHY_TXPOWER_GET_CURRENT_ID), \
257 NAME_ENTRY(WLRPC_WLC_PHY_TXPOWER_HW_CTRL_GET_ID), \
258 NAME_ENTRY(WLRPC_WLC_PHY_TXPOWER_HW_CTRL_SET_ID), \
259 NAME_ENTRY(WLRPC_WLC_PHY_BSSINIT_ID), \
260 NAME_ENTRY(WLRPC_WLC_BAND_STF_SS_SET_ID), \
261 NAME_ENTRY(WLRPC_WLC_PHY_BAND_FIRST_CHANSPEC_ID), \
262 NAME_ENTRY(WLRPC_WLC_PHY_TXPOWER_LIMIT_SET_ID), \
263 NAME_ENTRY(WLRPC_WLC_PHY_BAND_CHANNELS_ID), \
264 NAME_ENTRY(WLRPC_WLC_BMAC_REVINFO_GET_ID), \
265 NAME_ENTRY(WLRPC_WLC_BMAC_STATE_GET_ID), \
266 NAME_ENTRY(WLRPC_WLC_BMAC_XMTFIFO_SZ_GET_ID), \
267 NAME_ENTRY(WLRPC_WLC_BMAC_XMTFIFO_SZ_SET_ID), \
268 NAME_ENTRY(WLRPC_WLC_BMAC_VALIDATE_CHIP_ACCESS_ID), \
269 NAME_ENTRY(WLRPC_WLC_RM_CCA_COMPLETE_ID), \
270 NAME_ENTRY(WLRPC_WLC_RECV_ID), \
271 NAME_ENTRY(WLRPC_WLC_DOTXSTATUS_ID), \
272 NAME_ENTRY(WLRPC_WLC_HIGH_DPC_ID), \
273 NAME_ENTRY(WLRPC_WLC_FATAL_ERROR_ID), \
274 NAME_ENTRY(WLRPC_WLC_PHY_SET_CHANNEL_14_WIDE_FILTER_ID), \
275 NAME_ENTRY(WLRPC_WLC_PHY_NOISE_AVG_ID), \
276 NAME_ENTRY(WLRPC_WLC_PHYCHAIN_INIT_ID), \
277 NAME_ENTRY(WLRPC_WLC_PHYCHAIN_SET_ID), \
278 NAME_ENTRY(WLRPC_WLC_PHYCHAIN_GET_ID), \
279 NAME_ENTRY(WLRPC_WLC_PHY_TKIP_RIFS_WAR_ID), \
280 NAME_ENTRY(WLRPC_WLC_BMAC_COPYFROM_VARS_ID), \
281 NAME_ENTRY(WLRPC_WLC_BMAC_RETRYLIMIT_UPD_ID), \
282 NAME_ENTRY(WLRPC_WLC_BMAC_BTC_MODE_SET_ID), \
283 NAME_ENTRY(WLRPC_WLC_BMAC_BTC_MODE_GET_ID), \
284 NAME_ENTRY(WLRPC_WLC_BMAC_BTC_WIRE_SET_ID), \
285 NAME_ENTRY(WLRPC_WLC_BMAC_BTC_WIRE_GET_ID), \
286 NAME_ENTRY(WLRPC_WLC_BMAC_SET_NORESET_ID), \
287 NAME_ENTRY(WLRPC_WLC_AMPDU_TXSTATUS_COMPLETE_ID), \
288 NAME_ENTRY(WLRPC_WLC_BMAC_FIFOERRORS_ID), \
289 NAME_ENTRY(WLRPC_WLC_PHY_TXPOWER_GET_TARGET_MIN_ID), \
290 NAME_ENTRY(WLRPC_WLC_PHY_TXPOWER_GET_TARGET_MAX_ID), \
291 NAME_ENTRY(WLRPC_WLC_NOISE_CB_ID), \
292 NAME_ENTRY(WLRPC_WLC_BMAC_LED_HW_DEINIT_ID), \
293 NAME_ENTRY(WLRPC_WLC_BMAC_LED_HW_MASK_INIT_ID), \
294 NAME_ENTRY(WLRPC_WLC_PLLREQ_ID), \
295 NAME_ENTRY(WLRPC_WLC_BMAC_TACLEAR_ID), \
296 NAME_ENTRY(WLRPC_WLC_BMAC_SET_CLK_ID), \
297 NAME_ENTRY(WLRPC_WLC_PHY_OFDM_RATESET_WAR_ID), \
298 NAME_ENTRY(WLRPC_WLC_PHY_BF_PREEMPT_ENABLE_ID), \
299 NAME_ENTRY(WLRPC_WLC_BMAC_DOIOVARS_ID), \
300 NAME_ENTRY(WLRPC_WLC_BMAC_DUMP_ID), \
301 NAME_ENTRY(WLRPC_WLC_CISWRITE_ID), \
302 NAME_ENTRY(WLRPC_WLC_CISDUMP_ID), \
303 NAME_ENTRY(WLRPC_WLC_UPDATE_PHY_MODE_ID), \
304 NAME_ENTRY(WLRPC_WLC_RESET_BMAC_DONE_ID), \
305 NAME_ENTRY(WLRPC_WLC_BMAC_LED_BLINK_EVENT_ID), \
306 NAME_ENTRY(WLRPC_WLC_BMAC_LED_SET_ID), \
307 NAME_ENTRY(WLRPC_WLC_BMAC_LED_BLINK_ID), \
308 NAME_ENTRY(WLRPC_WLC_BMAC_LED_ID), \
309 NAME_ENTRY(WLRPC_WLC_BMAC_RATE_SHM_OFFSET_ID), \
310 NAME_ENTRY(WLRPC_SI_ISCORE_UP_ID), \
311 NAME_ENTRY(WLRPC_WLC_BMAC_PS_SWITCH_ID), \
312 NAME_ENTRY(WLRPC_WLC_PHY_STF_SSMODE_GET_ID), \
313 NAME_ENTRY(WLRPC_WLC_BMAC_DEBUG_ID), \
314 NAME_ENTRY(WLRPC_WLC_EXTLOG_MSG_ID), \
315 NAME_ENTRY(WLRPC_WLC_EXTLOG_CFG_ID), \
316 NAME_ENTRY(WLRPC_BCM_ASSERT_LOG_ID), \
317 NAME_ENTRY(WLRPC_BCM_ASSERT_TYPE_ID), \
318 NAME_ENTRY(WLRPC_WLC_BMAC_SET_PHYCAL_CACHE_FLAG_ID), \
319 NAME_ENTRY(WLRPC_WLC_BMAC_GET_PHYCAL_CACHE_FLAG_ID), \
320 NAME_ENTRY(WLRPC_WLC_PHY_CAL_CACHE_INIT_ID), \
321 NAME_ENTRY(WLRPC_WLC_PHY_CAL_CACHE_DEINIT_ID), \
322 NAME_ENTRY(WLRPC_WLC_BMAC_HW_UP_ID), \
323 NAME_ENTRY(WLRPC_WLC_BMAC_SET_TXPWR_PERCENT_ID), \
324 NAME_ENTRY(WLRPC_WLC_PHYCHAIN_ACTIVE_GET_ID), \
325 NAME_ENTRY(WLRPC_WLC_BMAC_BLINK_SYNC_ID), \
326 NAME_ENTRY(WLRPC_WLC_BMAC_UCODE_DBGSEL_SET_ID), \
327 NAME_ENTRY(WLRPC_WLC_BMAC_UCODE_DBGSEL_GET_ID), \
328 NAME_ENTRY(WLRPC_WLC_PHY_RADAR_DETECT_MODE_SET_ID), \
329 NAME_ENTRY(WLRPC_WLC_PHY_ACIM_NOISEM_RESET_NPHY_ID), \
330 NAME_ENTRY(WLRPC_WLC_PHY_INTERFER_SET_NPHY_ID), \
331 NAME_ENTRY(WLRPC_WLC_BMAC_IFSCTL_EDCRS_SET_ID), \
332 NAME_ENTRY(WLRPC_WLC_PKTENGTX), \
333 NAME_ENTRY(WLRPC_WLC_BMAC_SET_DEAF), \
334 NAME_ENTRY(WLRPC_WLC_BMAC_CLEAR_DEAF), \
335 NAME_ENTRY(WLRPC_WLC_BMAC_BTC_FLAGS_SET_ID), \
336 NAME_ENTRY(WLRPC_WLC_BMAC_BTC_FLAGS_GET_ID), \
337 NAME_ENTRY(WLRPC_WLC_BMAC_SET_RCMTA_TYPE_ID), \
338 NAME_ENTRY(WLRPC_WLC_BMAC_CCA_STATS_READ_ID), \
339 NAME_ENTRY(WLRPC_WLC_BMAC_ANTSEL_SET_ID), \
340 NAME_ENTRY(WLRPC_WLC_BMAC_SET_UCODE_LOADED), \
341 NAME_ENTRY(WLRPC_WLC_PHY_LDPC_SET_ID), \
342 {0, NULL} \
343 }
344
345static __inline char *_wlc_rpc_id_lookup(const struct name_entry *tbl, int _id)
346{
347 const struct name_entry *elt = tbl;
348 static char __unknown[64];
349 for (; elt->name != NULL; elt++) {
350 if (_id == elt->id)
351 break;
352 }
353 if (_id == elt->id)
354 strncpy(__unknown, elt->name, sizeof(__unknown));
355 else
356 snprintf(__unknown, sizeof(__unknown), "ID:%d", _id);
357 return __unknown;
358}
359
360#define WLC_RPC_ID_LOOKUP(tbl, _id) (_wlc_rpc_id_lookup(tbl, _id))
361
362#endif /* BCMDBG */
363
364/* refer to txpwr_limits_t for each elements, mcs32 is the at the end for 1 byte */
365#define TXPOWER_XDR_SZ (roundup(WLC_NUM_RATES_CCK, 4) + roundup(WLC_NUM_RATES_OFDM, 4) * 4 + \
366 roundup(WLC_NUM_RATES_MCS_1_STREAM, 4) * 6 + roundup(WLC_NUM_RATES_MCS_2_STREAM, 4) * 2 + \
367 roundup(1, 4))
368
369#define wlc_rpc_txpwr_limits(b, txpwr, op, err) \
370 do { \
371 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->cck, WLC_NUM_RATES_CCK); \
372 ASSERT(!(err)); \
373 \
374 /* 20 MHz Legacy OFDM rates with SISO transmission */ \
375 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->ofdm, WLC_NUM_RATES_OFDM); \
376 ASSERT(!(err)); \
377 \
378 /* 20 MHz Legacy OFDM rates with CDD transmission */ \
379 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->ofdm_cdd, WLC_NUM_RATES_OFDM); \
380 ASSERT(!(err)); \
381 \
382 /* 40 MHz Legacy OFDM rates with SISO transmission */ \
383 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->ofdm_40_siso, WLC_NUM_RATES_OFDM); \
384 ASSERT(!(err)); \
385 \
386 /* 40 MHz Legacy OFDM rates with CDD transmission */ \
387 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->ofdm_40_cdd, WLC_NUM_RATES_OFDM); \
388 ASSERT(!(err)); \
389 \
390 /* 20MHz MCS rates SISO/CDD/STBC/SDM */ \
391 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->mcs_20_siso, WLC_NUM_RATES_MCS_1_STREAM); \
392 ASSERT(!(err)); \
393 \
394 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->mcs_20_cdd, WLC_NUM_RATES_MCS_1_STREAM); \
395 ASSERT(!(err)); \
396 \
397 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->mcs_20_stbc, WLC_NUM_RATES_MCS_1_STREAM); \
398 ASSERT(!(err)); \
399 \
400 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->mcs_20_mimo, WLC_NUM_RATES_MCS_2_STREAM); \
401 ASSERT(!(err)); \
402 \
403 /* 40MHz MCS rates SISO/CDD/STBC/SDM */ \
404 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->mcs_40_siso, WLC_NUM_RATES_MCS_1_STREAM); \
405 ASSERT(!(err)); \
406 \
407 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->mcs_40_cdd, WLC_NUM_RATES_MCS_1_STREAM); \
408 ASSERT(!(err)); \
409 \
410 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->mcs_40_stbc, WLC_NUM_RATES_MCS_1_STREAM); \
411 ASSERT(!(err)); \
412 \
413 (err) = bcm_xdr_##op##_u8_vec((b), (txpwr)->mcs_40_mimo, WLC_NUM_RATES_MCS_2_STREAM); \
414 ASSERT(!(err)); \
415 } while (0)
416
417typedef struct wlc_rpc_ctx {
418 rpc_info_t *rpc;
419 wlc_info_t *wlc;
420 wlc_hw_info_t *wlc_hw;
421} wlc_rpc_ctx_t;
422
423static inline rpc_buf_t *wlc_rpc_buf_alloc(rpc_info_t *rpc, bcm_xdr_buf_t *b,
424 uint len, wlc_rpc_id_t rpc_id)
425{
426 rpc_buf_t *rpc_buf;
427
428 rpc_buf = bcm_rpc_buf_alloc(rpc, len + sizeof(u32));
429
430 if (!rpc_buf)
431 return NULL;
432
433 bcm_xdr_buf_init(b, bcm_rpc_buf_data(bcm_rpc_tp_get(rpc), rpc_buf),
434 len + sizeof(u32));
435
436 bcm_xdr_pack_u32(b, rpc_id);
437
438 return rpc_buf;
439}
440
441#if defined(BCMDBG)
442static __inline wlc_rpc_id_t
443wlc_rpc_id_get(struct rpc_info *rpc, rpc_buf_t *buf)
444{
445 wlc_rpc_id_t rpc_id;
446 bcm_xdr_buf_t b;
447
448 bcm_xdr_buf_init(&b, bcm_rpc_buf_data(bcm_rpc_tp_get(rpc), buf),
449 sizeof(u32));
450
451 bcm_xdr_unpack_u32(&b, (u32 *)((unsigned long) & rpc_id));
452 return rpc_id;
453}
454#endif
455
456static __inline int _wlc_rpc_call(struct rpc_info *rpc, rpc_buf_t *send)
457{
458 int _err = 0;
459#if defined(BCMDBG)
460 wlc_rpc_id_t rpc_id = wlc_rpc_id_get(rpc, send);
461 /* const struct name_entry rpc_name_tbl[] = RPC_ID_TABLE; */
462 static struct name_entry rpc_name_tbl[] = RPC_ID_TABLE;
463 WL_TRACE(("%s: Called id %s\n", __func__,
464 WLC_RPC_ID_LOOKUP(rpc_name_tbl, rpc_id)));
465#endif
466 _err = bcm_rpc_call(rpc, send);
467 if (_err) {
468#if defined(BCMDBG)
469 WL_ERROR(("%s: Call id %s FAILED\n", __func__,
470 WLC_RPC_ID_LOOKUP(rpc_name_tbl, rpc_id)));
471#endif
472 _err = 0;
473 }
474 return _err;
475}
476
477#define wlc_rpc_call(rpc, send) (_wlc_rpc_call(rpc, send))
478
479#include <sbhnddma.h>
480#include <sbhndpio.h>
481#include <d11.h>
482
483#ifdef WLC_LOW
484extern void wlc_rpc_bmac_dispatch(wlc_rpc_ctx_t *rpc_ctx, struct rpc_buf *buf);
485extern void wlc_rpc_bmac_dump_txfifohist(wlc_hw_info_t *wlc_hw,
486 bool dump_clear);
487#else
488extern void wlc_rpc_high_dispatch(wlc_rpc_ctx_t *ctx, struct rpc_buf *buf);
489#endif
490
491/* Packed structure for ease of transport across RPC bus along u32 boundary */
492typedef struct wlc_rpc_txstatus {
493 u32 PAD_framelen;
494 u32 status_frameid;
495 u32 sequence_lasttxtime;
496 u32 ackphyrxsh_phyerr;
497} wlc_rpc_txstatus_t;
498
499static inline
500 void txstatus2rpc_txstatus(tx_status_t *txstatus,
501 wlc_rpc_txstatus_t *rpc_txstatus)
502{
503 rpc_txstatus->PAD_framelen = txstatus->framelen;
504 rpc_txstatus->status_frameid =
505 (txstatus->status << 16) | txstatus->frameid;
506 rpc_txstatus->sequence_lasttxtime =
507 (txstatus->sequence << 16) | txstatus->lasttxtime;
508 rpc_txstatus->ackphyrxsh_phyerr =
509 (txstatus->ackphyrxsh << 16) | txstatus->phyerr;
510}
511
512static inline
513 void rpc_txstatus2txstatus(wlc_rpc_txstatus_t *rpc_txstatus,
514 tx_status_t *txstatus)
515{
516 txstatus->framelen = rpc_txstatus->PAD_framelen & 0xffff;
517 txstatus->status = (rpc_txstatus->status_frameid >> 16) & 0xffff;
518 txstatus->frameid = rpc_txstatus->status_frameid & 0xffff;
519 txstatus->sequence = (rpc_txstatus->sequence_lasttxtime >> 16) & 0xffff;
520 txstatus->lasttxtime = rpc_txstatus->sequence_lasttxtime & 0xffff;
521 txstatus->ackphyrxsh = (rpc_txstatus->ackphyrxsh_phyerr >> 16) & 0xffff;
522 txstatus->phyerr = rpc_txstatus->ackphyrxsh_phyerr & 0xffff;
523}
524
525extern void wlc_bmac_dngl_reboot(rpc_info_t *rpc);
526
527#endif /* WLC_RPC_H */
diff --git a/drivers/staging/brcm80211/sys/wlc_rpctx.h b/drivers/staging/brcm80211/sys/wlc_rpctx.h
deleted file mode 100644
index 7427154a4bd4..000000000000
--- a/drivers/staging/brcm80211/sys/wlc_rpctx.h
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef _wlc_rpctx_h_
18#define _wlc_rpctx_h_
19
20/* forward declaration */
21struct wlc_info;
22
23/* This controls how many packets are given to the dongle. This is required as
24 * NTXD needs to be power of 2 but we may not have enough memory to absorb that
25 * large number of frames
26 */
27#ifndef NRPCTXBUFPOST
28#define NRPCTXBUFPOST NTXD
29#endif
30
31#if defined(WLC_HIGH_ONLY)
32
33struct wlc_rpc_phy {
34 struct rpc_info *rpc;
35};
36
37#define RPCTX_ENAB(pub) (true)
38extern rpctx_info_t *wlc_rpctx_attach(wlc_pub_t *pub, struct wlc_info *wlc);
39extern int wlc_rpctx_fifoinit(rpctx_info_t *rpctx, uint fifo, uint ntxd);
40extern void wlc_rpctx_detach(rpctx_info_t *rpctx);
41extern int wlc_rpctx_dump(rpctx_info_t *rpctx, struct bcmstrbuf *b);
42extern void *wlc_rpctx_getnexttxp(rpctx_info_t *rpctx, uint fifo);
43extern void wlc_rpctx_txreclaim(rpctx_info_t *rpctx);
44extern uint wlc_rpctx_txavail(rpctx_info_t *rpctx, uint fifo);
45extern int wlc_rpctx_pkteng(rpctx_info_t *rpctx, uint fifo, void *p);
46extern int wlc_rpctx_tx(rpctx_info_t *rpctx, uint fifo, void *p, bool commit,
47 u16 frameid, u8 txpktpend);
48extern void wlc_rpctx_txpktpendinc(rpctx_info_t *rpctx, uint fifo, u8 val);
49extern void wlc_rpctx_txpktpenddec(rpctx_info_t *rpctx, uint fifo, u8 val);
50extern void wlc_rpctx_txpktpendclr(rpctx_info_t *rpctx, uint fifo);
51extern int wlc_rpctx_txpktpend(rpctx_info_t *rpctx, uint fifo, bool all);
52
53#else
54#define RPCTX_ENAB(pub) (false)
55#define wlc_rpctx_attach(pub, wlc) (NULL)
56#define wlc_rpctx_fifoinit(rpctx, fifo, ntxd) (0)
57#define wlc_rpctx_detach(rpctx) ASSERT(0)
58#define wlc_rpctx_txavail(rpctx, f) (false)
59#define wlc_rpctx_dump(rpctx, b) (0)
60#define wlc_rpctx_getnexttxp(rpctx, f) (NULL)
61#define wlc_rpctx_txreclaim(rpctx) ASSERT(0)
62#define wlc_rpctx_pkteng(rpctx, fifo, p) do { } while (0)
63#define wlc_rpctx_tx(rpctx, f, p, c, fid, t) (0)
64#define wlc_rpctx_txpktpendinc(rpctx, f, val) do { } while (0)
65#define wlc_rpctx_txpktpenddec(rpctx, f, val) do { } while (0)
66#define wlc_rpctx_txpktpendclr(rpctx, f) do { } while (0)
67#define wlc_rpctx_txpktpend(rpctx, f, all) (0)
68
69#endif /* WLC_HIGH */
70
71#endif /* _wlc_rpctx_h_ */
diff --git a/drivers/staging/brcm80211/sys/wlc_scb.h b/drivers/staging/brcm80211/sys/wlc_scb.h
index ce26c740e6c1..fe84e993b52a 100644
--- a/drivers/staging/brcm80211/sys/wlc_scb.h
+++ b/drivers/staging/brcm80211/sys/wlc_scb.h
@@ -19,7 +19,7 @@
19 19
20#include <proto/802.1d.h> 20#include <proto/802.1d.h>
21 21
22extern bool wlc_aggregatable(wlc_info_t *wlc, u8 tid); 22extern bool wlc_aggregatable(struct wlc_info *wlc, u8 tid);
23 23
24#define AMPDU_TX_BA_MAX_WSIZE 64 /* max Tx ba window size (in pdu) */ 24#define AMPDU_TX_BA_MAX_WSIZE 64 /* max Tx ba window size (in pdu) */
25/* structure to store per-tid state for the ampdu initiator */ 25/* structure to store per-tid state for the ampdu initiator */
diff --git a/drivers/staging/brcm80211/sys/wlc_stf.c b/drivers/staging/brcm80211/sys/wlc_stf.c
index 4728ad90e295..8975b09a7438 100644
--- a/drivers/staging/brcm80211/sys/wlc_stf.c
+++ b/drivers/staging/brcm80211/sys/wlc_stf.c
@@ -15,8 +15,8 @@
15 */ 15 */
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/module.h>
18#include <wlc_cfg.h> 19#include <wlc_cfg.h>
19#include <linuxver.h>
20#include <bcmdefs.h> 20#include <bcmdefs.h>
21#include <osl.h> 21#include <osl.h>
22#include <bcmutils.h> 22#include <bcmutils.h>
@@ -25,29 +25,33 @@
25#include <proto/802.11.h> 25#include <proto/802.11.h>
26#include <wlioctl.h> 26#include <wlioctl.h>
27#include <bcmwifi.h> 27#include <bcmwifi.h>
28#include <sbhndpio.h>
29#include <sbhnddma.h>
28#include <d11.h> 30#include <d11.h>
29#include <wlc_rate.h> 31#include <wlc_rate.h>
30#include <wlc_pub.h> 32#include <wlc_pub.h>
31#include <wlc_key.h> 33#include <wlc_key.h>
32#include <wlc_channel.h> 34#include <wlc_channel.h>
33#include <wlc_bsscfg.h> 35#include <wlc_bsscfg.h>
36#include <wlc_event.h>
34#include <wlc_mac80211.h> 37#include <wlc_mac80211.h>
35#include <wlc_scb.h> 38#include <wlc_scb.h>
36#include <wl_export.h> 39#include <wl_export.h>
37#include <wlc_bmac.h> 40#include <wlc_bmac.h>
38#include <wlc_stf.h> 41#include <wlc_stf.h>
42#include <wl_dbg.h>
39 43
40#define WLC_STF_SS_STBC_RX(wlc) (WLCISNPHY(wlc->band) && \ 44#define WLC_STF_SS_STBC_RX(wlc) (WLCISNPHY(wlc->band) && \
41 NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6)) 45 NREV_GT(wlc->band->phyrev, 3) && NREV_LE(wlc->band->phyrev, 6))
42 46
43static s8 wlc_stf_stbc_rx_get(wlc_info_t *wlc); 47static s8 wlc_stf_stbc_rx_get(struct wlc_info *wlc);
44static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, s32 int_val); 48static bool wlc_stf_stbc_tx_set(struct wlc_info *wlc, s32 int_val);
45static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 val); 49static int wlc_stf_txcore_set(struct wlc_info *wlc, u8 Nsts, u8 val);
46static int wlc_stf_spatial_policy_set(wlc_info_t *wlc, int val); 50static int wlc_stf_spatial_policy_set(struct wlc_info *wlc, int val);
47static void wlc_stf_stbc_rx_ht_update(wlc_info_t *wlc, int val); 51static void wlc_stf_stbc_rx_ht_update(struct wlc_info *wlc, int val);
48 52
49static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc); 53static void _wlc_stf_phy_txant_upd(struct wlc_info *wlc);
50static u16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec); 54static u16 _wlc_stf_phytxchain_sel(struct wlc_info *wlc, ratespec_t rspec);
51 55
52#define NSTS_1 1 56#define NSTS_1 1
53#define NSTS_2 2 57#define NSTS_2 2
@@ -61,7 +65,7 @@ const u8 txcore_default[5] = {
61 (0x0f) /* For Nsts = 4, enable all cores */ 65 (0x0f) /* For Nsts = 4, enable all cores */
62}; 66};
63 67
64static void wlc_stf_stbc_rx_ht_update(wlc_info_t *wlc, int val) 68static void wlc_stf_stbc_rx_ht_update(struct wlc_info *wlc, int val)
65{ 69{
66 ASSERT((val == HT_CAP_RX_STBC_NO) 70 ASSERT((val == HT_CAP_RX_STBC_NO)
67 || (val == HT_CAP_RX_STBC_ONE_STREAM)); 71 || (val == HT_CAP_RX_STBC_ONE_STREAM));
@@ -82,7 +86,7 @@ static void wlc_stf_stbc_rx_ht_update(wlc_info_t *wlc, int val)
82} 86}
83 87
84/* every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to turn on/off txchain */ 88/* every WLC_TEMPSENSE_PERIOD seconds temperature check to decide whether to turn on/off txchain */
85void wlc_tempsense_upd(wlc_info_t *wlc) 89void wlc_tempsense_upd(struct wlc_info *wlc)
86{ 90{
87 wlc_phy_t *pi = wlc->band->pi; 91 wlc_phy_t *pi = wlc->band->pi;
88 uint active_chains, txchain; 92 uint active_chains, txchain;
@@ -106,7 +110,7 @@ void wlc_tempsense_upd(wlc_info_t *wlc)
106} 110}
107 111
108void 112void
109wlc_stf_ss_algo_channel_get(wlc_info_t *wlc, u16 *ss_algo_channel, 113wlc_stf_ss_algo_channel_get(struct wlc_info *wlc, u16 *ss_algo_channel,
110 chanspec_t chanspec) 114 chanspec_t chanspec)
111{ 115{
112 tx_power_t power; 116 tx_power_t power;
@@ -147,12 +151,12 @@ wlc_stf_ss_algo_channel_get(wlc_info_t *wlc, u16 *ss_algo_channel,
147 setbit(ss_algo_channel, PHY_TXC1_MODE_STBC); 151 setbit(ss_algo_channel, PHY_TXC1_MODE_STBC);
148} 152}
149 153
150static s8 wlc_stf_stbc_rx_get(wlc_info_t *wlc) 154static s8 wlc_stf_stbc_rx_get(struct wlc_info *wlc)
151{ 155{
152 return (wlc->ht_cap.cap & HT_CAP_RX_STBC_MASK) >> HT_CAP_RX_STBC_SHIFT; 156 return (wlc->ht_cap.cap & HT_CAP_RX_STBC_MASK) >> HT_CAP_RX_STBC_SHIFT;
153} 157}
154 158
155static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, s32 int_val) 159static bool wlc_stf_stbc_tx_set(struct wlc_info *wlc, s32 int_val)
156{ 160{
157 if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON)) { 161 if ((int_val != AUTO) && (int_val != OFF) && (int_val != ON)) {
158 return false; 162 return false;
@@ -173,7 +177,7 @@ static bool wlc_stf_stbc_tx_set(wlc_info_t *wlc, s32 int_val)
173 return true; 177 return true;
174} 178}
175 179
176bool wlc_stf_stbc_rx_set(wlc_info_t *wlc, s32 int_val) 180bool wlc_stf_stbc_rx_set(struct wlc_info *wlc, s32 int_val)
177{ 181{
178 if ((int_val != HT_CAP_RX_STBC_NO) 182 if ((int_val != HT_CAP_RX_STBC_NO)
179 && (int_val != HT_CAP_RX_STBC_ONE_STREAM)) { 183 && (int_val != HT_CAP_RX_STBC_ONE_STREAM)) {
@@ -190,10 +194,10 @@ bool wlc_stf_stbc_rx_set(wlc_info_t *wlc, s32 int_val)
190 return true; 194 return true;
191} 195}
192 196
193static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 core_mask) 197static int wlc_stf_txcore_set(struct wlc_info *wlc, u8 Nsts, u8 core_mask)
194{ 198{
195 WL_TRACE(("wl%d: %s: Nsts %d core_mask %x\n", 199 WL_TRACE("wl%d: %s: Nsts %d core_mask %x\n",
196 wlc->pub->unit, __func__, Nsts, core_mask)); 200 wlc->pub->unit, __func__, Nsts, core_mask);
197 201
198 ASSERT((Nsts > 0) && (Nsts <= MAX_STREAMS_SUPPORTED)); 202 ASSERT((Nsts > 0) && (Nsts <= MAX_STREAMS_SUPPORTED));
199 203
@@ -227,12 +231,12 @@ static int wlc_stf_txcore_set(wlc_info_t *wlc, u8 Nsts, u8 core_mask)
227 return BCME_OK; 231 return BCME_OK;
228} 232}
229 233
230static int wlc_stf_spatial_policy_set(wlc_info_t *wlc, int val) 234static int wlc_stf_spatial_policy_set(struct wlc_info *wlc, int val)
231{ 235{
232 int i; 236 int i;
233 u8 core_mask = 0; 237 u8 core_mask = 0;
234 238
235 WL_TRACE(("wl%d: %s: val %x\n", wlc->pub->unit, __func__, val)); 239 WL_TRACE("wl%d: %s: val %x\n", wlc->pub->unit, __func__, val);
236 240
237 wlc->stf->spatial_policy = (s8) val; 241 wlc->stf->spatial_policy = (s8) val;
238 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) { 242 for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) {
@@ -243,7 +247,7 @@ static int wlc_stf_spatial_policy_set(wlc_info_t *wlc, int val)
243 return BCME_OK; 247 return BCME_OK;
244} 248}
245 249
246int wlc_stf_txchain_set(wlc_info_t *wlc, s32 int_val, bool force) 250int wlc_stf_txchain_set(struct wlc_info *wlc, s32 int_val, bool force)
247{ 251{
248 u8 txchain = (u8) int_val; 252 u8 txchain = (u8) int_val;
249 u8 txstreams; 253 u8 txstreams;
@@ -274,13 +278,15 @@ int wlc_stf_txchain_set(wlc_info_t *wlc, s32 int_val, bool force)
274 if (RSPEC_STF(wlc->bandstate[i]->rspec_override) 278 if (RSPEC_STF(wlc->bandstate[i]->rspec_override)
275 != PHY_TXC1_MODE_SISO) { 279 != PHY_TXC1_MODE_SISO) {
276 wlc->bandstate[i]->rspec_override = 0; 280 wlc->bandstate[i]->rspec_override = 0;
277 WL_ERROR(("%s(): temp sense override non-SISO" " rspec_override.\n", __func__)); 281 WL_ERROR("%s(): temp sense override non-SISO rspec_override\n",
282 __func__);
278 } 283 }
279 if (RSPEC_STF 284 if (RSPEC_STF
280 (wlc->bandstate[i]->mrspec_override) != 285 (wlc->bandstate[i]->mrspec_override) !=
281 PHY_TXC1_MODE_SISO) { 286 PHY_TXC1_MODE_SISO) {
282 wlc->bandstate[i]->mrspec_override = 0; 287 wlc->bandstate[i]->mrspec_override = 0;
283 WL_ERROR(("%s(): temp sense override non-SISO" " mrspec_override.\n", __func__)); 288 WL_ERROR("%s(): temp sense override non-SISO mrspec_override\n",
289 __func__);
284 } 290 }
285 } 291 }
286 } 292 }
@@ -303,7 +309,7 @@ int wlc_stf_txchain_set(wlc_info_t *wlc, s32 int_val, bool force)
303 return BCME_OK; 309 return BCME_OK;
304} 310}
305 311
306int wlc_stf_rxchain_set(wlc_info_t *wlc, s32 int_val) 312int wlc_stf_rxchain_set(struct wlc_info *wlc, s32 int_val)
307{ 313{
308 u8 rxchain_cnt; 314 u8 rxchain_cnt;
309 u8 rxchain = (u8) int_val; 315 u8 rxchain = (u8) int_val;
@@ -367,7 +373,7 @@ int wlc_stf_rxchain_set(wlc_info_t *wlc, s32 int_val)
367} 373}
368 374
369/* update wlc->stf->ss_opmode which represents the operational stf_ss mode we're using */ 375/* update wlc->stf->ss_opmode which represents the operational stf_ss mode we're using */
370int wlc_stf_ss_update(wlc_info_t *wlc, wlcband_t *band) 376int wlc_stf_ss_update(struct wlc_info *wlc, struct wlcband *band)
371{ 377{
372 int ret_code = 0; 378 int ret_code = 0;
373 u8 prev_stf_ss; 379 u8 prev_stf_ss;
@@ -402,7 +408,7 @@ int wlc_stf_ss_update(wlc_info_t *wlc, wlcband_t *band)
402 return ret_code; 408 return ret_code;
403} 409}
404 410
405int wlc_stf_attach(wlc_info_t *wlc) 411int wlc_stf_attach(struct wlc_info *wlc)
406{ 412{
407 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_SISO; 413 wlc->bandstate[BAND_2G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_SISO;
408 wlc->bandstate[BAND_5G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_CDD; 414 wlc->bandstate[BAND_5G_INDEX]->band_stf_ss_mode = PHY_TXC1_MODE_CDD;
@@ -425,11 +431,11 @@ int wlc_stf_attach(wlc_info_t *wlc)
425 return 0; 431 return 0;
426} 432}
427 433
428void wlc_stf_detach(wlc_info_t *wlc) 434void wlc_stf_detach(struct wlc_info *wlc)
429{ 435{
430} 436}
431 437
432int wlc_stf_ant_txant_validate(wlc_info_t *wlc, s8 val) 438int wlc_stf_ant_txant_validate(struct wlc_info *wlc, s8 val)
433{ 439{
434 int bcmerror = BCME_OK; 440 int bcmerror = BCME_OK;
435 441
@@ -476,7 +482,7 @@ int wlc_stf_ant_txant_validate(wlc_info_t *wlc, s8 val)
476 * do tx-antenna selection for SISO transmissions 482 * do tx-antenna selection for SISO transmissions
477 * for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7 means both cores active 483 * for NREV>=7, bit 6 and bit 7 mean antenna 0 and 1 respectively, nit6+bit7 means both cores active
478*/ 484*/
479static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc) 485static void _wlc_stf_phy_txant_upd(struct wlc_info *wlc)
480{ 486{
481 s8 txant; 487 s8 txant;
482 488
@@ -517,12 +523,12 @@ static void _wlc_stf_phy_txant_upd(wlc_info_t *wlc)
517 wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant); 523 wlc_bmac_txant_set(wlc->hw, wlc->stf->phytxant);
518} 524}
519 525
520void wlc_stf_phy_txant_upd(wlc_info_t *wlc) 526void wlc_stf_phy_txant_upd(struct wlc_info *wlc)
521{ 527{
522 _wlc_stf_phy_txant_upd(wlc); 528 _wlc_stf_phy_txant_upd(wlc);
523} 529}
524 530
525void wlc_stf_phy_chain_calc(wlc_info_t *wlc) 531void wlc_stf_phy_chain_calc(struct wlc_info *wlc)
526{ 532{
527 /* get available rx/tx chains */ 533 /* get available rx/tx chains */
528 wlc->stf->hw_txchain = (u8) getintvar(wlc->pub->vars, "txchain"); 534 wlc->stf->hw_txchain = (u8) getintvar(wlc->pub->vars, "txchain");
@@ -559,7 +565,7 @@ void wlc_stf_phy_chain_calc(wlc_info_t *wlc)
559 wlc_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION); 565 wlc_stf_spatial_policy_set(wlc, MIN_SPATIAL_EXPANSION);
560} 566}
561 567
562static u16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec) 568static u16 _wlc_stf_phytxchain_sel(struct wlc_info *wlc, ratespec_t rspec)
563{ 569{
564 u16 phytxant = wlc->stf->phytxant; 570 u16 phytxant = wlc->stf->phytxant;
565 571
@@ -572,12 +578,12 @@ static u16 _wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec)
572 return phytxant; 578 return phytxant;
573} 579}
574 580
575u16 wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec) 581u16 wlc_stf_phytxchain_sel(struct wlc_info *wlc, ratespec_t rspec)
576{ 582{
577 return _wlc_stf_phytxchain_sel(wlc, rspec); 583 return _wlc_stf_phytxchain_sel(wlc, rspec);
578} 584}
579 585
580u16 wlc_stf_d11hdrs_phyctl_txant(wlc_info_t *wlc, ratespec_t rspec) 586u16 wlc_stf_d11hdrs_phyctl_txant(struct wlc_info *wlc, ratespec_t rspec)
581{ 587{
582 u16 phytxant = wlc->stf->phytxant; 588 u16 phytxant = wlc->stf->phytxant;
583 u16 mask = PHY_TXC_ANT_MASK; 589 u16 mask = PHY_TXC_ANT_MASK;
diff --git a/drivers/staging/brcm80211/sys/wlc_stf.h b/drivers/staging/brcm80211/sys/wlc_stf.h
index ee9b02a119bb..8de6382e620d 100644
--- a/drivers/staging/brcm80211/sys/wlc_stf.h
+++ b/drivers/staging/brcm80211/sys/wlc_stf.h
@@ -20,23 +20,24 @@
20#define MIN_SPATIAL_EXPANSION 0 20#define MIN_SPATIAL_EXPANSION 0
21#define MAX_SPATIAL_EXPANSION 1 21#define MAX_SPATIAL_EXPANSION 1
22 22
23extern int wlc_stf_attach(wlc_info_t *wlc); 23extern int wlc_stf_attach(struct wlc_info *wlc);
24extern void wlc_stf_detach(wlc_info_t *wlc); 24extern void wlc_stf_detach(struct wlc_info *wlc);
25 25
26extern void wlc_tempsense_upd(wlc_info_t *wlc); 26extern void wlc_tempsense_upd(struct wlc_info *wlc);
27extern void wlc_stf_ss_algo_channel_get(wlc_info_t *wlc, 27extern void wlc_stf_ss_algo_channel_get(struct wlc_info *wlc,
28 u16 *ss_algo_channel, 28 u16 *ss_algo_channel,
29 chanspec_t chanspec); 29 chanspec_t chanspec);
30extern int wlc_stf_ss_update(wlc_info_t *wlc, struct wlcband *band); 30extern int wlc_stf_ss_update(struct wlc_info *wlc, struct wlcband *band);
31extern void wlc_stf_phy_txant_upd(wlc_info_t *wlc); 31extern void wlc_stf_phy_txant_upd(struct wlc_info *wlc);
32extern int wlc_stf_txchain_set(wlc_info_t *wlc, s32 int_val, bool force); 32extern int wlc_stf_txchain_set(struct wlc_info *wlc, s32 int_val, bool force);
33extern int wlc_stf_rxchain_set(wlc_info_t *wlc, s32 int_val); 33extern int wlc_stf_rxchain_set(struct wlc_info *wlc, s32 int_val);
34extern bool wlc_stf_stbc_rx_set(wlc_info_t *wlc, s32 int_val); 34extern bool wlc_stf_stbc_rx_set(struct wlc_info *wlc, s32 int_val);
35 35
36extern int wlc_stf_ant_txant_validate(wlc_info_t *wlc, s8 val); 36extern int wlc_stf_ant_txant_validate(struct wlc_info *wlc, s8 val);
37extern void wlc_stf_phy_txant_upd(wlc_info_t *wlc); 37extern void wlc_stf_phy_txant_upd(struct wlc_info *wlc);
38extern void wlc_stf_phy_chain_calc(wlc_info_t *wlc); 38extern void wlc_stf_phy_chain_calc(struct wlc_info *wlc);
39extern u16 wlc_stf_phytxchain_sel(wlc_info_t *wlc, ratespec_t rspec); 39extern u16 wlc_stf_phytxchain_sel(struct wlc_info *wlc, ratespec_t rspec);
40extern u16 wlc_stf_d11hdrs_phyctl_txant(wlc_info_t *wlc, ratespec_t rspec); 40extern u16 wlc_stf_d11hdrs_phyctl_txant(struct wlc_info *wlc, ratespec_t rspec);
41extern u16 wlc_stf_spatial_expansion_get(wlc_info_t *wlc, ratespec_t rspec); 41extern u16 wlc_stf_spatial_expansion_get(struct wlc_info *wlc,
42 ratespec_t rspec);
42#endif /* _wlc_stf_h_ */ 43#endif /* _wlc_stf_h_ */
diff --git a/drivers/staging/brcm80211/sys/wlc_types.h b/drivers/staging/brcm80211/sys/wlc_types.h
index 33047ebab979..df6e04c6ac58 100644
--- a/drivers/staging/brcm80211/sys/wlc_types.h
+++ b/drivers/staging/brcm80211/sys/wlc_types.h
@@ -19,34 +19,19 @@
19 19
20/* forward declarations */ 20/* forward declarations */
21 21
22typedef struct wlc_info wlc_info_t; 22struct wlc_info;
23typedef struct wlc_hw_info wlc_hw_info_t; 23struct wlc_hw_info;
24typedef struct wlc_if wlc_if_t; 24struct wlc_if;
25typedef struct wl_if wl_if_t; 25struct wl_if;
26typedef struct led_info led_info_t; 26struct ampdu_info;
27typedef struct bmac_led bmac_led_t; 27struct antsel_info;
28typedef struct bmac_led_info bmac_led_info_t; 28struct bmac_pmq;
29typedef struct scb_module scb_module_t;
30typedef struct ba_info ba_info_t;
31typedef struct ampdu_info ampdu_info_t;
32typedef struct ratesel_info ratesel_info_t;
33typedef struct wlc_ap_info wlc_ap_info_t;
34typedef struct wlc_auth_info wlc_auth_info_t;
35typedef struct supplicant supplicant_t;
36typedef struct authenticator authenticator_t;
37typedef struct antsel_info antsel_info_t;
38#if !defined(WLC_LOW)
39typedef struct rpctx_info rpctx_info_t;
40#endif
41#ifdef WLC_LOW
42typedef struct bmac_pmq bmac_pmq_t;
43#endif
44 29
45struct d11init; 30struct d11init;
46 31
47#ifndef _hnddma_pub_ 32#ifndef _hnddma_pub_
48#define _hnddma_pub_ 33#define _hnddma_pub_
49typedef const struct hnddma_pub hnddma_t; 34struct hnddma_pub;
50#endif /* _hnddma_pub_ */ 35#endif /* _hnddma_pub_ */
51 36
52#endif /* _wlc_types_h_ */ 37#endif /* _wlc_types_h_ */
diff --git a/drivers/staging/brcm80211/util/aiutils.c b/drivers/staging/brcm80211/util/aiutils.c
index 75a7e3a5c009..ddd2f9d64c20 100644
--- a/drivers/staging/brcm80211/util/aiutils.c
+++ b/drivers/staging/brcm80211/util/aiutils.c
@@ -14,11 +14,16 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/delay.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/string.h> 19#include <linux/string.h>
19#include <bcmdefs.h> 20#include <bcmdefs.h>
21#ifdef BRCM_FULLMAC
22#include <linux/netdevice.h>
23#endif
20#include <osl.h> 24#include <osl.h>
21#include <linuxver.h> 25#include <linux/module.h>
26#include <linux/pci.h>
22#include <bcmutils.h> 27#include <bcmutils.h>
23#include <siutils.h> 28#include <siutils.h>
24#include <hndsoc.h> 29#include <hndsoc.h>
@@ -26,8 +31,8 @@
26#include <pcicfg.h> 31#include <pcicfg.h>
27#include <bcmdevs.h> 32#include <bcmdevs.h>
28 33
29#define BCM47162_DMP() ((CHIPID(sih->chip) == BCM47162_CHIP_ID) && \ 34#define BCM47162_DMP() ((sih->chip == BCM47162_CHIP_ID) && \
30 (CHIPREV(sih->chiprev) == 0) && \ 35 (sih->chiprev == 0) && \
31 (sii->coreid[sii->curidx] == MIPS74K_CORE_ID)) 36 (sii->coreid[sii->curidx] == MIPS74K_CORE_ID))
32 37
33/* EROM parsing */ 38/* EROM parsing */
@@ -115,7 +120,7 @@ void ai_scan(si_t *sih, void *regs, uint devid)
115 120
116 erombase = R_REG(sii->osh, &cc->eromptr); 121 erombase = R_REG(sii->osh, &cc->eromptr);
117 122
118 switch (BUSTYPE(sih->bustype)) { 123 switch (sih->bustype) {
119 case SI_BUS: 124 case SI_BUS:
120 eromptr = (u32 *) REG_MAP(erombase, SI_CORE_SIZE); 125 eromptr = (u32 *) REG_MAP(erombase, SI_CORE_SIZE);
121 break; 126 break;
@@ -125,7 +130,7 @@ void ai_scan(si_t *sih, void *regs, uint devid)
125 sii->curwrap = (void *)((unsigned long)regs + SI_CORE_SIZE); 130 sii->curwrap = (void *)((unsigned long)regs + SI_CORE_SIZE);
126 131
127 /* Now point the window at the erom */ 132 /* Now point the window at the erom */
128 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN, 4, erombase); 133 pci_write_config_dword(sii->osh->pdev, PCI_BAR0_WIN, erombase);
129 eromptr = regs; 134 eromptr = regs;
130 break; 135 break;
131 136
@@ -330,7 +335,7 @@ void *ai_setcoreidx(si_t *sih, uint coreidx)
330 ASSERT((sii->intrsenabled_fn == NULL) 335 ASSERT((sii->intrsenabled_fn == NULL)
331 || !(*(sii)->intrsenabled_fn) ((sii)->intr_arg)); 336 || !(*(sii)->intrsenabled_fn) ((sii)->intr_arg));
332 337
333 switch (BUSTYPE(sih->bustype)) { 338 switch (sih->bustype) {
334 case SI_BUS: 339 case SI_BUS:
335 /* map new one */ 340 /* map new one */
336 if (!sii->regs[coreidx]) { 341 if (!sii->regs[coreidx]) {
@@ -347,10 +352,10 @@ void *ai_setcoreidx(si_t *sih, uint coreidx)
347 352
348 case PCI_BUS: 353 case PCI_BUS:
349 /* point bar0 window */ 354 /* point bar0 window */
350 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN, 4, addr); 355 pci_write_config_dword(sii->osh->pdev, PCI_BAR0_WIN, addr);
351 regs = sii->curmap; 356 regs = sii->curmap;
352 /* point bar0 2nd 4KB window */ 357 /* point bar0 2nd 4KB window */
353 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN2, 4, wrap); 358 pci_write_config_dword(sii->osh->pdev, PCI_BAR0_WIN2, wrap);
354 break; 359 break;
355 360
356#ifdef BCMSDIO 361#ifdef BCMSDIO
@@ -504,7 +509,7 @@ uint ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val)
504 if (coreidx >= SI_MAXCORES) 509 if (coreidx >= SI_MAXCORES)
505 return 0; 510 return 0;
506 511
507 if (BUSTYPE(sih->bustype) == SI_BUS) { 512 if (sih->bustype == SI_BUS) {
508 /* If internal bus, we can always get at everything */ 513 /* If internal bus, we can always get at everything */
509 fast = true; 514 fast = true;
510 /* map if does not exist */ 515 /* map if does not exist */
@@ -514,7 +519,7 @@ uint ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val)
514 ASSERT(GOODREGS(sii->regs[coreidx])); 519 ASSERT(GOODREGS(sii->regs[coreidx]));
515 } 520 }
516 r = (u32 *) ((unsigned char *) sii->regs[coreidx] + regoff); 521 r = (u32 *) ((unsigned char *) sii->regs[coreidx] + regoff);
517 } else if (BUSTYPE(sih->bustype) == PCI_BUS) { 522 } else if (sih->bustype == PCI_BUS) {
518 /* If pci/pcie, we can get at pci/pcie regs and on newer cores to chipc */ 523 /* If pci/pcie, we can get at pci/pcie regs and on newer cores to chipc */
519 524
520 if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sii)) { 525 if ((sii->coreid[coreidx] == CC_CORE_ID) && SI_FAST(sii)) {
diff --git a/drivers/staging/brcm80211/util/bcmotp.c b/drivers/staging/brcm80211/util/bcmotp.c
index c909832c7ee1..d820e7b9e970 100644
--- a/drivers/staging/brcm80211/util/bcmotp.c
+++ b/drivers/staging/brcm80211/util/bcmotp.c
@@ -14,11 +14,13 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/delay.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/string.h> 19#include <linux/string.h>
19#include <bcmdefs.h> 20#include <bcmdefs.h>
20#include <osl.h> 21#include <osl.h>
21#include <linuxver.h> 22#include <linux/module.h>
23#include <linux/pci.h>
22#include <bcmdevs.h> 24#include <bcmdevs.h>
23#include <bcmutils.h> 25#include <bcmutils.h>
24#include <siutils.h> 26#include <siutils.h>
@@ -77,7 +79,7 @@ typedef struct {
77 uint ccrev; /* chipc revision */ 79 uint ccrev; /* chipc revision */
78 otp_fn_t *fn; /* OTP functions */ 80 otp_fn_t *fn; /* OTP functions */
79 si_t *sih; /* Saved sb handle */ 81 si_t *sih; /* Saved sb handle */
80 osl_t *osh; 82 struct osl_info *osh;
81 83
82#ifdef BCMIPXOTP 84#ifdef BCMIPXOTP
83 /* IPX OTP section */ 85 /* IPX OTP section */
@@ -221,7 +223,7 @@ static int ipxotp_max_rgnsz(si_t *sih, int osizew)
221{ 223{
222 int ret = 0; 224 int ret = 0;
223 225
224 switch (CHIPID(sih->chip)) { 226 switch (sih->chip) {
225 case BCM43224_CHIP_ID: 227 case BCM43224_CHIP_ID:
226 case BCM43225_CHIP_ID: 228 case BCM43225_CHIP_ID:
227 ret = osizew * 2 - OTP_SZ_FU_72 - OTP_SZ_CHECKSUM; 229 ret = osizew * 2 - OTP_SZ_FU_72 - OTP_SZ_CHECKSUM;
@@ -271,8 +273,8 @@ static void _ipxotp_init(otpinfo_t *oi, chipcregs_t *cc)
271 /* Read OTP lock bits and subregion programmed indication bits */ 273 /* Read OTP lock bits and subregion programmed indication bits */
272 oi->status = R_REG(oi->osh, &cc->otpstatus); 274 oi->status = R_REG(oi->osh, &cc->otpstatus);
273 275
274 if ((CHIPID(oi->sih->chip) == BCM43224_CHIP_ID) 276 if ((oi->sih->chip == BCM43224_CHIP_ID)
275 || (CHIPID(oi->sih->chip) == BCM43225_CHIP_ID)) { 277 || (oi->sih->chip == BCM43225_CHIP_ID)) {
276 u32 p_bits; 278 u32 p_bits;
277 p_bits = 279 p_bits =
278 (ipxotp_otpr(oi, cc, oi->otpgu_base + OTPGU_P_OFF) & 280 (ipxotp_otpr(oi, cc, oi->otpgu_base + OTPGU_P_OFF) &
@@ -569,7 +571,7 @@ static int hndotp_size(void *oh)
569static u16 hndotp_otpr(void *oh, chipcregs_t *cc, uint wn) 571static u16 hndotp_otpr(void *oh, chipcregs_t *cc, uint wn)
570{ 572{
571 otpinfo_t *oi = (otpinfo_t *) oh; 573 otpinfo_t *oi = (otpinfo_t *) oh;
572 osl_t *osh; 574 struct osl_info *osh;
573 volatile u16 *ptr; 575 volatile u16 *ptr;
574 576
575 ASSERT(wn < ((oi->size / 2) + OTP_RC_LIM_OFF)); 577 ASSERT(wn < ((oi->size / 2) + OTP_RC_LIM_OFF));
@@ -584,7 +586,7 @@ static u16 hndotp_otpr(void *oh, chipcregs_t *cc, uint wn)
584static u16 hndotp_otproff(void *oh, chipcregs_t *cc, int woff) 586static u16 hndotp_otproff(void *oh, chipcregs_t *cc, int woff)
585{ 587{
586 otpinfo_t *oi = (otpinfo_t *) oh; 588 otpinfo_t *oi = (otpinfo_t *) oh;
587 osl_t *osh; 589 struct osl_info *osh;
588 volatile u16 *ptr; 590 volatile u16 *ptr;
589 591
590 ASSERT(woff >= (-((int)oi->size / 2))); 592 ASSERT(woff >= (-((int)oi->size / 2)));
@@ -603,7 +605,7 @@ static u16 hndotp_read_bit(void *oh, chipcregs_t *cc, uint idx)
603 otpinfo_t *oi = (otpinfo_t *) oh; 605 otpinfo_t *oi = (otpinfo_t *) oh;
604 uint k, row, col; 606 uint k, row, col;
605 u32 otpp, st; 607 u32 otpp, st;
606 osl_t *osh; 608 struct osl_info *osh;
607 609
608 osh = si_osh(oi->sih); 610 osh = si_osh(oi->sih);
609 row = idx / 65; 611 row = idx / 65;
@@ -636,7 +638,7 @@ static void *hndotp_init(si_t *sih)
636 otpinfo_t *oi; 638 otpinfo_t *oi;
637 u32 cap = 0, clkdiv, otpdiv = 0; 639 u32 cap = 0, clkdiv, otpdiv = 0;
638 void *ret = NULL; 640 void *ret = NULL;
639 osl_t *osh; 641 struct osl_info *osh;
640 642
641 oi = &otpinfo; 643 oi = &otpinfo;
642 644
@@ -900,7 +902,7 @@ void *otp_init(si_t *sih)
900 void *ret = NULL; 902 void *ret = NULL;
901 903
902 oi = &otpinfo; 904 oi = &otpinfo;
903 bzero(oi, sizeof(otpinfo_t)); 905 memset(oi, 0, sizeof(otpinfo_t));
904 906
905 oi->ccrev = sih->ccrev; 907 oi->ccrev = sih->ccrev;
906 908
diff --git a/drivers/staging/brcm80211/util/bcmsrom.c b/drivers/staging/brcm80211/util/bcmsrom.c
index 1282ef7eb922..19d45026a5ee 100644
--- a/drivers/staging/brcm80211/util/bcmsrom.c
+++ b/drivers/staging/brcm80211/util/bcmsrom.c
@@ -15,9 +15,11 @@
15 */ 15 */
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/etherdevice.h>
18#include <bcmdefs.h> 19#include <bcmdefs.h>
19#include <osl.h> 20#include <osl.h>
20#include <linuxver.h> 21#include <linux/module.h>
22#include <linux/pci.h>
21#include <stdarg.h> 23#include <stdarg.h>
22#include <bcmutils.h> 24#include <bcmutils.h>
23#include <hndsoc.h> 25#include <hndsoc.h>
@@ -66,29 +68,30 @@ extern uint _varsz;
66 68
67#define SROM_CIS_SINGLE 1 69#define SROM_CIS_SINGLE 1
68 70
69static int initvars_srom_si(si_t *sih, osl_t *osh, void *curmap, char **vars, 71static int initvars_srom_si(si_t *sih, struct osl_info *osh, void *curmap,
70 uint *count); 72 char **vars, uint *count);
71static void _initvars_srom_pci(u8 sromrev, u16 *srom, uint off, 73static void _initvars_srom_pci(u8 sromrev, u16 *srom, uint off,
72 varbuf_t *b); 74 varbuf_t *b);
73static int initvars_srom_pci(si_t *sih, void *curmap, char **vars, 75static int initvars_srom_pci(si_t *sih, void *curmap, char **vars,
74 uint *count); 76 uint *count);
75static int initvars_flash_si(si_t *sih, char **vars, uint *count); 77static int initvars_flash_si(si_t *sih, char **vars, uint *count);
76#ifdef BCMSDIO 78#ifdef BCMSDIO
77static int initvars_cis_sdio(osl_t *osh, char **vars, uint *count); 79static int initvars_cis_sdio(struct osl_info *osh, char **vars, uint *count);
78static int sprom_cmd_sdio(osl_t *osh, u8 cmd); 80static int sprom_cmd_sdio(struct osl_info *osh, u8 cmd);
79static int sprom_read_sdio(osl_t *osh, u16 addr, u16 *data); 81static int sprom_read_sdio(struct osl_info *osh, u16 addr, u16 *data);
80#endif /* BCMSDIO */ 82#endif /* BCMSDIO */
81static int sprom_read_pci(osl_t *osh, si_t *sih, u16 *sprom, uint wordoff, 83static int sprom_read_pci(struct osl_info *osh, si_t *sih, u16 *sprom,
82 u16 *buf, uint nwords, bool check_crc); 84 uint wordoff, u16 *buf, uint nwords, bool check_crc);
83#if defined(BCMNVRAMR) 85#if defined(BCMNVRAMR)
84static int otp_read_pci(osl_t *osh, si_t *sih, u16 *buf, uint bufsz); 86static int otp_read_pci(struct osl_info *osh, si_t *sih, u16 *buf, uint bufsz);
85#endif 87#endif
86static u16 srom_cc_cmd(si_t *sih, osl_t *osh, void *ccregs, u32 cmd, 88static u16 srom_cc_cmd(si_t *sih, struct osl_info *osh, void *ccregs, u32 cmd,
87 uint wordoff, u16 data); 89 uint wordoff, u16 data);
88 90
89static int initvars_table(osl_t *osh, char *start, char *end, char **vars, 91static int initvars_table(struct osl_info *osh, char *start, char *end,
90 uint *count); 92 char **vars, uint *count);
91static int initvars_flash(si_t *sih, osl_t *osh, char **vp, uint len); 93static int initvars_flash(si_t *sih, struct osl_info *osh, char **vp,
94 uint len);
92 95
93/* Initialization of varbuf structure */ 96/* Initialization of varbuf structure */
94static void varbuf_init(varbuf_t *b, char *buf, uint size) 97static void varbuf_init(varbuf_t *b, char *buf, uint size)
@@ -129,7 +132,7 @@ static int varbuf_append(varbuf_t *b, const char *fmt, ...)
129 if (s != NULL) { 132 if (s != NULL) {
130 len = (size_t) (s - b->buf); 133 len = (size_t) (s - b->buf);
131 for (s = b->base; s < b->buf;) { 134 for (s = b->base; s < b->buf;) {
132 if ((bcmp(s, b->buf, len) == 0) && s[len] == '=') { 135 if ((memcmp(s, b->buf, len) == 0) && s[len] == '=') {
133 len = strlen(s) + 1; 136 len = strlen(s) + 1;
134 memmove(s, (s + len), 137 memmove(s, (s + len),
135 ((b->buf + r + 1) - (s + len))); 138 ((b->buf + r + 1) - (s + len)));
@@ -155,21 +158,21 @@ static int varbuf_append(varbuf_t *b, const char *fmt, ...)
155 * Initialize local vars from the right source for this platform. 158 * Initialize local vars from the right source for this platform.
156 * Return 0 on success, nonzero on error. 159 * Return 0 on success, nonzero on error.
157 */ 160 */
158int srom_var_init(si_t *sih, uint bustype, void *curmap, osl_t *osh, 161int srom_var_init(si_t *sih, uint bustype, void *curmap, struct osl_info *osh,
159 char **vars, uint *count) 162 char **vars, uint *count)
160{ 163{
161 uint len; 164 uint len;
162 165
163 len = 0; 166 len = 0;
164 167
165 ASSERT(bustype == BUSTYPE(bustype)); 168 ASSERT(bustype == bustype);
166 if (vars == NULL || count == NULL) 169 if (vars == NULL || count == NULL)
167 return 0; 170 return 0;
168 171
169 *vars = NULL; 172 *vars = NULL;
170 *count = 0; 173 *count = 0;
171 174
172 switch (BUSTYPE(bustype)) { 175 switch (bustype) {
173 case SI_BUS: 176 case SI_BUS:
174 case JTAG_BUS: 177 case JTAG_BUS:
175 return initvars_srom_si(sih, osh, curmap, vars, count); 178 return initvars_srom_si(sih, osh, curmap, vars, count);
@@ -194,7 +197,7 @@ int srom_var_init(si_t *sih, uint bustype, void *curmap, osl_t *osh,
194 197
195/* support only 16-bit word read from srom */ 198/* support only 16-bit word read from srom */
196int 199int
197srom_read(si_t *sih, uint bustype, void *curmap, osl_t *osh, 200srom_read(si_t *sih, uint bustype, void *curmap, struct osl_info *osh,
198 uint byteoff, uint nbytes, u16 *buf, bool check_crc) 201 uint byteoff, uint nbytes, u16 *buf, bool check_crc)
199{ 202{
200 uint off, nw; 203 uint off, nw;
@@ -202,7 +205,7 @@ srom_read(si_t *sih, uint bustype, void *curmap, osl_t *osh,
202 uint i; 205 uint i;
203#endif /* BCMSDIO */ 206#endif /* BCMSDIO */
204 207
205 ASSERT(bustype == BUSTYPE(bustype)); 208 ASSERT(bustype == bustype);
206 209
207 /* check input - 16-bit access only */ 210 /* check input - 16-bit access only */
208 if (byteoff & 1 || nbytes & 1 || (byteoff + nbytes) > SROM_MAX) 211 if (byteoff & 1 || nbytes & 1 || (byteoff + nbytes) > SROM_MAX)
@@ -211,7 +214,7 @@ srom_read(si_t *sih, uint bustype, void *curmap, osl_t *osh,
211 off = byteoff / 2; 214 off = byteoff / 2;
212 nw = nbytes / 2; 215 nw = nbytes / 2;
213 216
214 if (BUSTYPE(bustype) == PCI_BUS) { 217 if (bustype == PCI_BUS) {
215 if (!curmap) 218 if (!curmap)
216 return 1; 219 return 1;
217 220
@@ -233,7 +236,7 @@ srom_read(si_t *sih, uint bustype, void *curmap, osl_t *osh,
233 } 236 }
234#endif 237#endif
235#ifdef BCMSDIO 238#ifdef BCMSDIO
236 } else if (BUSTYPE(bustype) == SDIO_BUS) { 239 } else if (bustype == SDIO_BUS) {
237 off = byteoff / 2; 240 off = byteoff / 2;
238 nw = nbytes / 2; 241 nw = nbytes / 2;
239 for (i = 0; i < nw; i++) { 242 for (i = 0; i < nw; i++) {
@@ -242,7 +245,7 @@ srom_read(si_t *sih, uint bustype, void *curmap, osl_t *osh,
242 return 1; 245 return 1;
243 } 246 }
244#endif /* BCMSDIO */ 247#endif /* BCMSDIO */
245 } else if (BUSTYPE(bustype) == SI_BUS) { 248 } else if (bustype == SI_BUS) {
246 return 1; 249 return 1;
247 } else { 250 } else {
248 return 1; 251 return 1;
@@ -376,7 +379,8 @@ u8 patch_pair;
376/* For dongle HW, accept partial calibration parameters */ 379/* For dongle HW, accept partial calibration parameters */
377#define BCMDONGLECASE(n) 380#define BCMDONGLECASE(n)
378 381
379int srom_parsecis(osl_t *osh, u8 *pcis[], uint ciscnt, char **vars, uint *count) 382int srom_parsecis(struct osl_info *osh, u8 *pcis[], uint ciscnt, char **vars,
383 uint *count)
380{ 384{
381 char eabuf[32]; 385 char eabuf[32];
382 char *base; 386 char *base;
@@ -402,7 +406,7 @@ int srom_parsecis(osl_t *osh, u8 *pcis[], uint ciscnt, char **vars, uint *count)
402 return -2; 406 return -2;
403 407
404 varbuf_init(&b, base, MAXSZ_NVRAM_VARS); 408 varbuf_init(&b, base, MAXSZ_NVRAM_VARS);
405 bzero(base, MAXSZ_NVRAM_VARS); 409 memset(base, 0, MAXSZ_NVRAM_VARS);
406 eabuf[0] = '\0'; 410 eabuf[0] = '\0';
407 for (cisnum = 0; cisnum < ciscnt; cisnum++) { 411 for (cisnum = 0; cisnum < ciscnt; cisnum++) {
408 cis = *pcis++; 412 cis = *pcis++;
@@ -496,12 +500,12 @@ int srom_parsecis(osl_t *osh, u8 *pcis[], uint ciscnt, char **vars, uint *count)
496 break; 500 break;
497 default: 501 default:
498 /* set macaddr if HNBU_MACADDR not seen yet */ 502 /* set macaddr if HNBU_MACADDR not seen yet */
499 if (eabuf[0] == '\0' 503 if (eabuf[0] == '\0' &&
500 && cis[i] == LAN_NID 504 cis[i] == LAN_NID &&
501 && !(ETHER_ISNULLADDR(&cis[i + 2])) 505 !is_zero_ether_addr(&cis[i + 2]) &&
502 && !(ETHER_ISMULTI(&cis[i + 2]))) { 506 !is_multicast_ether_addr(&cis[i + 2])) {
503 ASSERT(cis[i + 1] == 507 ASSERT(cis[i + 1] ==
504 ETHER_ADDR_LEN); 508 ETH_ALEN);
505 snprintf(eabuf, sizeof(eabuf), 509 snprintf(eabuf, sizeof(eabuf),
506 "%pM", &cis[i + 2]); 510 "%pM", &cis[i + 2]);
507 511
@@ -970,8 +974,8 @@ int srom_parsecis(osl_t *osh, u8 *pcis[], uint ciscnt, char **vars, uint *count)
970 break; 974 break;
971 975
972 case HNBU_MACADDR: 976 case HNBU_MACADDR:
973 if (!(ETHER_ISNULLADDR(&cis[i + 1])) && 977 if (!is_zero_ether_addr(&cis[i + 1]) &&
974 !(ETHER_ISMULTI(&cis[i + 1]))) { 978 !is_multicast_ether_addr(&cis[i + 1])) {
975 snprintf(eabuf, sizeof(eabuf), 979 snprintf(eabuf, sizeof(eabuf),
976 "%pM", &cis[i + 1]); 980 "%pM", &cis[i + 1]);
977 981
@@ -1405,8 +1409,8 @@ int srom_parsecis(osl_t *osh, u8 *pcis[], uint ciscnt, char **vars, uint *count)
1405 * not in the bus cores. 1409 * not in the bus cores.
1406 */ 1410 */
1407static u16 1411static u16
1408srom_cc_cmd(si_t *sih, osl_t *osh, void *ccregs, u32 cmd, uint wordoff, 1412srom_cc_cmd(si_t *sih, struct osl_info *osh, void *ccregs, u32 cmd,
1409 u16 data) 1413 uint wordoff, u16 data)
1410{ 1414{
1411 chipcregs_t *cc = (chipcregs_t *) ccregs; 1415 chipcregs_t *cc = (chipcregs_t *) ccregs;
1412 uint wait_cnt = 1000; 1416 uint wait_cnt = 1000;
@@ -1439,7 +1443,7 @@ srom_cc_cmd(si_t *sih, osl_t *osh, void *ccregs, u32 cmd, uint wordoff,
1439 * Return 0 on success, nonzero on error. 1443 * Return 0 on success, nonzero on error.
1440 */ 1444 */
1441static int 1445static int
1442sprom_read_pci(osl_t *osh, si_t *sih, u16 *sprom, uint wordoff, 1446sprom_read_pci(struct osl_info *osh, si_t *sih, u16 *sprom, uint wordoff,
1443 u16 *buf, uint nwords, bool check_crc) 1447 u16 *buf, uint nwords, bool check_crc)
1444{ 1448{
1445 int err = 0; 1449 int err = 0;
@@ -1499,7 +1503,7 @@ sprom_read_pci(osl_t *osh, si_t *sih, u16 *sprom, uint wordoff,
1499} 1503}
1500 1504
1501#if defined(BCMNVRAMR) 1505#if defined(BCMNVRAMR)
1502static int otp_read_pci(osl_t *osh, si_t *sih, u16 *buf, uint bufsz) 1506static int otp_read_pci(struct osl_info *osh, si_t *sih, u16 *buf, uint bufsz)
1503{ 1507{
1504 u8 *otp; 1508 u8 *otp;
1505 uint sz = OTP_SZ_MAX / 2; /* size in words */ 1509 uint sz = OTP_SZ_MAX / 2; /* size in words */
@@ -1547,8 +1551,8 @@ static int otp_read_pci(osl_t *osh, si_t *sih, u16 *buf, uint bufsz)
1547* Create variable table from memory. 1551* Create variable table from memory.
1548* Return 0 on success, nonzero on error. 1552* Return 0 on success, nonzero on error.
1549*/ 1553*/
1550static int initvars_table(osl_t *osh, char *start, char *end, char **vars, 1554static int initvars_table(struct osl_info *osh, char *start, char *end,
1551 uint *count) 1555 char **vars, uint *count)
1552{ 1556{
1553 int c = (int)(end - start); 1557 int c = (int)(end - start);
1554 1558
@@ -1574,7 +1578,8 @@ static int initvars_table(osl_t *osh, char *start, char *end, char **vars,
1574 * of the table upon enter and to the end of the table upon exit when success. 1578 * of the table upon enter and to the end of the table upon exit when success.
1575 * Return 0 on success, nonzero on error. 1579 * Return 0 on success, nonzero on error.
1576 */ 1580 */
1577static int initvars_flash(si_t *sih, osl_t *osh, char **base, uint len) 1581static int initvars_flash(si_t *sih, struct osl_info *osh, char **base,
1582 uint len)
1578{ 1583{
1579 char *vp = *base; 1584 char *vp = *base;
1580 char *flash; 1585 char *flash;
@@ -1634,7 +1639,7 @@ static int initvars_flash(si_t *sih, osl_t *osh, char **base, uint len)
1634 */ 1639 */
1635static int initvars_flash_si(si_t *sih, char **vars, uint *count) 1640static int initvars_flash_si(si_t *sih, char **vars, uint *count)
1636{ 1641{
1637 osl_t *osh = si_osh(sih); 1642 struct osl_info *osh = si_osh(sih);
1638 char *vp, *base; 1643 char *vp, *base;
1639 int err; 1644 int err;
1640 1645
@@ -1845,7 +1850,7 @@ static int initvars_srom_pci(si_t *sih, void *curmap, char **vars, uint *count)
1845 u32 sr; 1850 u32 sr;
1846 varbuf_t b; 1851 varbuf_t b;
1847 char *vp, *base = NULL; 1852 char *vp, *base = NULL;
1848 osl_t *osh = si_osh(sih); 1853 struct osl_info *osh = si_osh(sih);
1849 bool flash = false; 1854 bool flash = false;
1850 int err = 0; 1855 int err = 0;
1851 1856
@@ -1986,7 +1991,7 @@ static int initvars_srom_pci(si_t *sih, void *curmap, char **vars, uint *count)
1986 * Read the SDIO cis and call parsecis to initialize the vars. 1991 * Read the SDIO cis and call parsecis to initialize the vars.
1987 * Return 0 on success, nonzero on error. 1992 * Return 0 on success, nonzero on error.
1988 */ 1993 */
1989static int initvars_cis_sdio(osl_t *osh, char **vars, uint *count) 1994static int initvars_cis_sdio(struct osl_info *osh, char **vars, uint *count)
1990{ 1995{
1991 u8 *cis[SBSDIO_NUM_FUNCTION + 1]; 1996 u8 *cis[SBSDIO_NUM_FUNCTION + 1];
1992 uint fn, numfn; 1997 uint fn, numfn;
@@ -2020,7 +2025,7 @@ static int initvars_cis_sdio(osl_t *osh, char **vars, uint *count)
2020} 2025}
2021 2026
2022/* set SDIO sprom command register */ 2027/* set SDIO sprom command register */
2023static int sprom_cmd_sdio(osl_t *osh, u8 cmd) 2028static int sprom_cmd_sdio(struct osl_info *osh, u8 cmd)
2024{ 2029{
2025 u8 status = 0; 2030 u8 status = 0;
2026 uint wait_cnt = 1000; 2031 uint wait_cnt = 1000;
@@ -2040,7 +2045,7 @@ static int sprom_cmd_sdio(osl_t *osh, u8 cmd)
2040} 2045}
2041 2046
2042/* read a word from the SDIO srom */ 2047/* read a word from the SDIO srom */
2043static int sprom_read_sdio(osl_t *osh, u16 addr, u16 *data) 2048static int sprom_read_sdio(struct osl_info *osh, u16 addr, u16 *data)
2044{ 2049{
2045 u8 addr_l, addr_h, data_l, data_h; 2050 u8 addr_l, addr_h, data_l, data_h;
2046 2051
@@ -2068,8 +2073,8 @@ static int sprom_read_sdio(osl_t *osh, u16 addr, u16 *data)
2068} 2073}
2069#endif /* BCMSDIO */ 2074#endif /* BCMSDIO */
2070 2075
2071static int initvars_srom_si(si_t *sih, osl_t *osh, void *curmap, char **vars, 2076static int initvars_srom_si(si_t *sih, struct osl_info *osh, void *curmap,
2072 uint *varsz) 2077 char **vars, uint *varsz)
2073{ 2078{
2074 /* Search flash nvram section for srom variables */ 2079 /* Search flash nvram section for srom variables */
2075 return initvars_flash_si(sih, vars, varsz); 2080 return initvars_flash_si(sih, vars, varsz);
diff --git a/drivers/staging/brcm80211/util/bcmutils.c b/drivers/staging/brcm80211/util/bcmutils.c
index 9789ea45ecd6..fd30cc6fb7f8 100644
--- a/drivers/staging/brcm80211/util/bcmutils.c
+++ b/drivers/staging/brcm80211/util/bcmutils.c
@@ -19,8 +19,10 @@
19#include <linux/string.h> 19#include <linux/string.h>
20#include <bcmdefs.h> 20#include <bcmdefs.h>
21#include <stdarg.h> 21#include <stdarg.h>
22#include <linux/module.h>
23#include <linux/pci.h>
24#include <linux/netdevice.h>
22#include <osl.h> 25#include <osl.h>
23#include <linuxver.h>
24#include <bcmutils.h> 26#include <bcmutils.h>
25#include <siutils.h> 27#include <siutils.h>
26#include <bcmnvram.h> 28#include <bcmnvram.h>
@@ -30,26 +32,26 @@
30#include <proto/802.1d.h> 32#include <proto/802.1d.h>
31#include <proto/802.11.h> 33#include <proto/802.11.h>
32 34
33
34/* copy a buffer into a pkt buffer chain */ 35/* copy a buffer into a pkt buffer chain */
35uint pktfrombuf(osl_t *osh, void *p, uint offset, int len, unsigned char *buf) 36uint pktfrombuf(struct osl_info *osh, struct sk_buff *p, uint offset, int len,
37 unsigned char *buf)
36{ 38{
37 uint n, ret = 0; 39 uint n, ret = 0;
38 40
39 /* skip 'offset' bytes */ 41 /* skip 'offset' bytes */
40 for (; p && offset; p = PKTNEXT(p)) { 42 for (; p && offset; p = p->next) {
41 if (offset < (uint) PKTLEN(p)) 43 if (offset < (uint) (p->len))
42 break; 44 break;
43 offset -= PKTLEN(p); 45 offset -= p->len;
44 } 46 }
45 47
46 if (!p) 48 if (!p)
47 return 0; 49 return 0;
48 50
49 /* copy the data */ 51 /* copy the data */
50 for (; p && len; p = PKTNEXT(p)) { 52 for (; p && len; p = p->next) {
51 n = min((uint) PKTLEN(p) - offset, (uint) len); 53 n = min((uint) (p->len) - offset, (uint) len);
52 bcopy(buf, PKTDATA(p) + offset, n); 54 bcopy(buf, p->data + offset, n);
53 buf += n; 55 buf += n;
54 len -= n; 56 len -= n;
55 ret += n; 57 ret += n;
@@ -59,13 +61,13 @@ uint pktfrombuf(osl_t *osh, void *p, uint offset, int len, unsigned char *buf)
59 return ret; 61 return ret;
60} 62}
61/* return total length of buffer chain */ 63/* return total length of buffer chain */
62uint BCMFASTPATH pkttotlen(osl_t *osh, void *p) 64uint BCMFASTPATH pkttotlen(struct osl_info *osh, struct sk_buff *p)
63{ 65{
64 uint total; 66 uint total;
65 67
66 total = 0; 68 total = 0;
67 for (; p; p = PKTNEXT(p)) 69 for (; p; p = p->next)
68 total += PKTLEN(p); 70 total += p->len;
69 return total; 71 return total;
70} 72}
71 73
@@ -73,12 +75,13 @@ uint BCMFASTPATH pkttotlen(osl_t *osh, void *p)
73 * osl multiple-precedence packet queue 75 * osl multiple-precedence packet queue
74 * hi_prec is always >= the number of the highest non-empty precedence 76 * hi_prec is always >= the number of the highest non-empty precedence
75 */ 77 */
76void *BCMFASTPATH pktq_penq(struct pktq *pq, int prec, void *p) 78struct sk_buff *BCMFASTPATH pktq_penq(struct pktq *pq, int prec,
79 struct sk_buff *p)
77{ 80{
78 struct pktq_prec *q; 81 struct pktq_prec *q;
79 82
80 ASSERT(prec >= 0 && prec < pq->num_prec); 83 ASSERT(prec >= 0 && prec < pq->num_prec);
81 ASSERT(PKTLINK(p) == NULL); /* queueing chains not allowed */ 84 ASSERT(p->prev == NULL); /* queueing chains not allowed */
82 85
83 ASSERT(!pktq_full(pq)); 86 ASSERT(!pktq_full(pq));
84 ASSERT(!pktq_pfull(pq, prec)); 87 ASSERT(!pktq_pfull(pq, prec));
@@ -86,7 +89,7 @@ void *BCMFASTPATH pktq_penq(struct pktq *pq, int prec, void *p)
86 q = &pq->q[prec]; 89 q = &pq->q[prec];
87 90
88 if (q->head) 91 if (q->head)
89 PKTSETLINK(q->tail, p); 92 q->tail->prev = p;
90 else 93 else
91 q->head = p; 94 q->head = p;
92 95
@@ -101,12 +104,13 @@ void *BCMFASTPATH pktq_penq(struct pktq *pq, int prec, void *p)
101 return p; 104 return p;
102} 105}
103 106
104void *BCMFASTPATH pktq_penq_head(struct pktq *pq, int prec, void *p) 107struct sk_buff *BCMFASTPATH pktq_penq_head(struct pktq *pq, int prec,
108 struct sk_buff *p)
105{ 109{
106 struct pktq_prec *q; 110 struct pktq_prec *q;
107 111
108 ASSERT(prec >= 0 && prec < pq->num_prec); 112 ASSERT(prec >= 0 && prec < pq->num_prec);
109 ASSERT(PKTLINK(p) == NULL); /* queueing chains not allowed */ 113 ASSERT(p->prev == NULL); /* queueing chains not allowed */
110 114
111 ASSERT(!pktq_full(pq)); 115 ASSERT(!pktq_full(pq));
112 ASSERT(!pktq_pfull(pq, prec)); 116 ASSERT(!pktq_pfull(pq, prec));
@@ -116,7 +120,7 @@ void *BCMFASTPATH pktq_penq_head(struct pktq *pq, int prec, void *p)
116 if (q->head == NULL) 120 if (q->head == NULL)
117 q->tail = p; 121 q->tail = p;
118 122
119 PKTSETLINK(p, q->head); 123 p->prev = q->head;
120 q->head = p; 124 q->head = p;
121 q->len++; 125 q->len++;
122 126
@@ -128,10 +132,10 @@ void *BCMFASTPATH pktq_penq_head(struct pktq *pq, int prec, void *p)
128 return p; 132 return p;
129} 133}
130 134
131void *BCMFASTPATH pktq_pdeq(struct pktq *pq, int prec) 135struct sk_buff *BCMFASTPATH pktq_pdeq(struct pktq *pq, int prec)
132{ 136{
133 struct pktq_prec *q; 137 struct pktq_prec *q;
134 void *p; 138 struct sk_buff *p;
135 139
136 ASSERT(prec >= 0 && prec < pq->num_prec); 140 ASSERT(prec >= 0 && prec < pq->num_prec);
137 141
@@ -141,7 +145,7 @@ void *BCMFASTPATH pktq_pdeq(struct pktq *pq, int prec)
141 if (p == NULL) 145 if (p == NULL)
142 return NULL; 146 return NULL;
143 147
144 q->head = PKTLINK(p); 148 q->head = p->prev;
145 if (q->head == NULL) 149 if (q->head == NULL)
146 q->tail = NULL; 150 q->tail = NULL;
147 151
@@ -149,15 +153,15 @@ void *BCMFASTPATH pktq_pdeq(struct pktq *pq, int prec)
149 153
150 pq->len--; 154 pq->len--;
151 155
152 PKTSETLINK(p, NULL); 156 p->prev = NULL;
153 157
154 return p; 158 return p;
155} 159}
156 160
157void *BCMFASTPATH pktq_pdeq_tail(struct pktq *pq, int prec) 161struct sk_buff *BCMFASTPATH pktq_pdeq_tail(struct pktq *pq, int prec)
158{ 162{
159 struct pktq_prec *q; 163 struct pktq_prec *q;
160 void *p, *prev; 164 struct sk_buff *p, *prev;
161 165
162 ASSERT(prec >= 0 && prec < pq->num_prec); 166 ASSERT(prec >= 0 && prec < pq->num_prec);
163 167
@@ -167,11 +171,11 @@ void *BCMFASTPATH pktq_pdeq_tail(struct pktq *pq, int prec)
167 if (p == NULL) 171 if (p == NULL)
168 return NULL; 172 return NULL;
169 173
170 for (prev = NULL; p != q->tail; p = PKTLINK(p)) 174 for (prev = NULL; p != q->tail; p = p->prev)
171 prev = p; 175 prev = p;
172 176
173 if (prev) 177 if (prev)
174 PKTSETLINK(prev, NULL); 178 prev->prev = NULL;
175 else 179 else
176 q->head = NULL; 180 q->head = NULL;
177 181
@@ -184,17 +188,17 @@ void *BCMFASTPATH pktq_pdeq_tail(struct pktq *pq, int prec)
184} 188}
185 189
186#ifdef BRCM_FULLMAC 190#ifdef BRCM_FULLMAC
187void pktq_pflush(osl_t *osh, struct pktq *pq, int prec, bool dir) 191void pktq_pflush(struct osl_info *osh, struct pktq *pq, int prec, bool dir)
188{ 192{
189 struct pktq_prec *q; 193 struct pktq_prec *q;
190 void *p; 194 struct sk_buff *p;
191 195
192 q = &pq->q[prec]; 196 q = &pq->q[prec];
193 p = q->head; 197 p = q->head;
194 while (p) { 198 while (p) {
195 q->head = PKTLINK(p); 199 q->head = p->prev;
196 PKTSETLINK(p, NULL); 200 p->prev = NULL;
197 PKTFREE(osh, p, dir); 201 pkt_buf_free_skb(osh, p, dir);
198 q->len--; 202 q->len--;
199 pq->len--; 203 pq->len--;
200 p = q->head; 204 p = q->head;
@@ -203,7 +207,7 @@ void pktq_pflush(osl_t *osh, struct pktq *pq, int prec, bool dir)
203 q->tail = NULL; 207 q->tail = NULL;
204} 208}
205 209
206void pktq_flush(osl_t *osh, struct pktq *pq, bool dir) 210void pktq_flush(struct osl_info *osh, struct pktq *pq, bool dir)
207{ 211{
208 int prec; 212 int prec;
209 for (prec = 0; prec < pq->num_prec; prec++) 213 for (prec = 0; prec < pq->num_prec; prec++)
@@ -212,11 +216,11 @@ void pktq_flush(osl_t *osh, struct pktq *pq, bool dir)
212} 216}
213#else /* !BRCM_FULLMAC */ 217#else /* !BRCM_FULLMAC */
214void 218void
215pktq_pflush(osl_t *osh, struct pktq *pq, int prec, bool dir, ifpkt_cb_t fn, 219pktq_pflush(struct osl_info *osh, struct pktq *pq, int prec, bool dir,
216 int arg) 220 ifpkt_cb_t fn, int arg)
217{ 221{
218 struct pktq_prec *q; 222 struct pktq_prec *q;
219 void *p, *prev = NULL; 223 struct sk_buff *p, *prev = NULL;
220 224
221 q = &pq->q[prec]; 225 q = &pq->q[prec];
222 p = q->head; 226 p = q->head;
@@ -224,17 +228,17 @@ pktq_pflush(osl_t *osh, struct pktq *pq, int prec, bool dir, ifpkt_cb_t fn,
224 if (fn == NULL || (*fn) (p, arg)) { 228 if (fn == NULL || (*fn) (p, arg)) {
225 bool head = (p == q->head); 229 bool head = (p == q->head);
226 if (head) 230 if (head)
227 q->head = PKTLINK(p); 231 q->head = p->prev;
228 else 232 else
229 PKTSETLINK(prev, PKTLINK(p)); 233 prev->prev = p->prev;
230 PKTSETLINK(p, NULL); 234 p->prev = NULL;
231 PKTFREE(osh, p, dir); 235 pkt_buf_free_skb(osh, p, dir);
232 q->len--; 236 q->len--;
233 pq->len--; 237 pq->len--;
234 p = (head ? q->head : PKTLINK(prev)); 238 p = (head ? q->head : prev->prev);
235 } else { 239 } else {
236 prev = p; 240 prev = p;
237 p = PKTLINK(p); 241 p = p->prev;
238 } 242 }
239 } 243 }
240 244
@@ -244,7 +248,8 @@ pktq_pflush(osl_t *osh, struct pktq *pq, int prec, bool dir, ifpkt_cb_t fn,
244 } 248 }
245} 249}
246 250
247void pktq_flush(osl_t *osh, struct pktq *pq, bool dir, ifpkt_cb_t fn, int arg) 251void pktq_flush(struct osl_info *osh, struct pktq *pq, bool dir,
252 ifpkt_cb_t fn, int arg)
248{ 253{
249 int prec; 254 int prec;
250 for (prec = 0; prec < pq->num_prec; prec++) 255 for (prec = 0; prec < pq->num_prec; prec++)
@@ -261,7 +266,7 @@ void pktq_init(struct pktq *pq, int num_prec, int max_len)
261 ASSERT(num_prec > 0 && num_prec <= PKTQ_MAX_PREC); 266 ASSERT(num_prec > 0 && num_prec <= PKTQ_MAX_PREC);
262 267
263 /* pq is variable size; only zero out what's requested */ 268 /* pq is variable size; only zero out what's requested */
264 bzero(pq, 269 memset(pq, 0,
265 offsetof(struct pktq, q) + (sizeof(struct pktq_prec) * num_prec)); 270 offsetof(struct pktq, q) + (sizeof(struct pktq_prec) * num_prec));
266 271
267 pq->num_prec = (u16) num_prec; 272 pq->num_prec = (u16) num_prec;
@@ -272,7 +277,7 @@ void pktq_init(struct pktq *pq, int num_prec, int max_len)
272 pq->q[prec].max = pq->max; 277 pq->q[prec].max = pq->max;
273} 278}
274 279
275void *pktq_peek_tail(struct pktq *pq, int *prec_out) 280struct sk_buff *pktq_peek_tail(struct pktq *pq, int *prec_out)
276{ 281{
277 int prec; 282 int prec;
278 283
@@ -303,10 +308,11 @@ int pktq_mlen(struct pktq *pq, uint prec_bmp)
303 return len; 308 return len;
304} 309}
305/* Priority dequeue from a specific set of precedences */ 310/* Priority dequeue from a specific set of precedences */
306void *BCMFASTPATH pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out) 311struct sk_buff *BCMFASTPATH pktq_mdeq(struct pktq *pq, uint prec_bmp,
312 int *prec_out)
307{ 313{
308 struct pktq_prec *q; 314 struct pktq_prec *q;
309 void *p; 315 struct sk_buff *p;
310 int prec; 316 int prec;
311 317
312 if (pq->len == 0) 318 if (pq->len == 0)
@@ -325,7 +331,7 @@ void *BCMFASTPATH pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out)
325 if (p == NULL) 331 if (p == NULL)
326 return NULL; 332 return NULL;
327 333
328 q->head = PKTLINK(p); 334 q->head = p->prev;
329 if (q->head == NULL) 335 if (q->head == NULL)
330 q->tail = NULL; 336 q->tail = NULL;
331 337
@@ -336,7 +342,7 @@ void *BCMFASTPATH pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out)
336 342
337 pq->len--; 343 pq->len--;
338 344
339 PKTSETLINK(p, NULL); 345 p->prev = NULL;
340 346
341 return p; 347 return p;
342} 348}
@@ -373,7 +379,7 @@ char *getvar(char *vars, const char *name)
373 379
374 /* first look in vars[] */ 380 /* first look in vars[] */
375 for (s = vars; s && *s;) { 381 for (s = vars; s && *s;) {
376 if ((bcmp(s, name, len) == 0) && (s[len] == '=')) 382 if ((memcmp(s, name, len) == 0) && (s[len] == '='))
377 return &s[len + 1]; 383 return &s[len + 1];
378 384
379 while (*s++) 385 while (*s++)
@@ -404,15 +410,15 @@ int getintvar(char *vars, const char *name)
404 410
405#if defined(BCMDBG) 411#if defined(BCMDBG)
406/* pretty hex print a pkt buffer chain */ 412/* pretty hex print a pkt buffer chain */
407void prpkt(const char *msg, osl_t *osh, void *p0) 413void prpkt(const char *msg, struct osl_info *osh, struct sk_buff *p0)
408{ 414{
409 void *p; 415 struct sk_buff *p;
410 416
411 if (msg && (msg[0] != '\0')) 417 if (msg && (msg[0] != '\0'))
412 printf("%s:\n", msg); 418 printf("%s:\n", msg);
413 419
414 for (p = p0; p; p = PKTNEXT(p)) 420 for (p = p0; p; p = p->next)
415 prhex(NULL, PKTDATA(p), PKTLEN(p)); 421 prhex(NULL, p->data, p->len);
416} 422}
417#endif /* defined(BCMDBG) */ 423#endif /* defined(BCMDBG) */
418 424
diff --git a/drivers/staging/brcm80211/util/bcmwifi.c b/drivers/staging/brcm80211/util/bcmwifi.c
index 1bb6c78eece7..81e54bd7a554 100644
--- a/drivers/staging/brcm80211/util/bcmwifi.c
+++ b/drivers/staging/brcm80211/util/bcmwifi.c
@@ -15,6 +15,10 @@
15 */ 15 */
16#include <linux/ctype.h> 16#include <linux/ctype.h>
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#ifdef BRCM_FULLMAC
19#include <linux/netdevice.h>
20#endif
21#include <osl.h>
18#include <bcmdefs.h> 22#include <bcmdefs.h>
19#include <bcmutils.h> 23#include <bcmutils.h>
20#include <bcmwifi.h> 24#include <bcmwifi.h>
diff --git a/drivers/staging/brcm80211/util/hnddma.c b/drivers/staging/brcm80211/util/hnddma.c
index fe503e7de563..d08869239d5b 100644
--- a/drivers/staging/brcm80211/util/hnddma.c
+++ b/drivers/staging/brcm80211/util/hnddma.c
@@ -16,7 +16,8 @@
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linuxver.h> 19#include <linux/netdevice.h>
20#include <linux/pci.h>
20#include <bcmdefs.h> 21#include <bcmdefs.h>
21#include <bcmdevs.h> 22#include <bcmdevs.h>
22#include <osl.h> 23#include <osl.h>
@@ -28,6 +29,10 @@
28#include <sbhnddma.h> 29#include <sbhnddma.h>
29#include <hnddma.h> 30#include <hnddma.h>
30 31
32#if defined(__mips__)
33#include <asm/addrspace.h>
34#endif
35
31/* debug/trace */ 36/* debug/trace */
32#ifdef BCMDBG 37#ifdef BCMDBG
33#define DMA_ERROR(args) \ 38#define DMA_ERROR(args) \
@@ -68,11 +73,12 @@ static uint dma_msg_level;
68 73
69#define DI_INFO(dmah) ((dma_info_t *)dmah) 74#define DI_INFO(dmah) ((dma_info_t *)dmah)
70 75
76#define R_SM(r) (*(r))
77#define W_SM(r, v) (*(r) = (v))
78
71/* dma engine software state */ 79/* dma engine software state */
72typedef struct dma_info { 80typedef struct dma_info {
73 struct hnddma_pub hnddma; /* exported structure, don't use hnddma_t, 81 struct hnddma_pub hnddma; /* exported structure */
74 * which could be const
75 */
76 uint *msg_level; /* message level pointer */ 82 uint *msg_level; /* message level pointer */
77 char name[MAXNAMEL]; /* callers name for diag msgs */ 83 char name[MAXNAMEL]; /* callers name for diag msgs */
78 84
@@ -222,7 +228,7 @@ static void _dma_counterreset(dma_info_t *di);
222static void _dma_fifoloopbackenable(dma_info_t *di); 228static void _dma_fifoloopbackenable(dma_info_t *di);
223static uint _dma_ctrlflags(dma_info_t *di, uint mask, uint flags); 229static uint _dma_ctrlflags(dma_info_t *di, uint mask, uint flags);
224static u8 dma_align_sizetobits(uint size); 230static u8 dma_align_sizetobits(uint size);
225static void *dma_ringalloc(osl_t *osh, u32 boundary, uint size, 231static void *dma_ringalloc(struct osl_info *osh, u32 boundary, uint size,
226 u16 *alignbits, uint *alloced, 232 u16 *alignbits, uint *alloced,
227 dmaaddr_t *descpa, osldma_t **dmah); 233 dmaaddr_t *descpa, osldma_t **dmah);
228 234
@@ -231,7 +237,7 @@ static bool dma32_alloc(dma_info_t *di, uint direction);
231static bool dma32_txreset(dma_info_t *di); 237static bool dma32_txreset(dma_info_t *di);
232static bool dma32_rxreset(dma_info_t *di); 238static bool dma32_rxreset(dma_info_t *di);
233static bool dma32_txsuspendedidle(dma_info_t *di); 239static bool dma32_txsuspendedidle(dma_info_t *di);
234static int dma32_txfast(dma_info_t *di, void *p0, bool commit); 240static int dma32_txfast(dma_info_t *di, struct sk_buff *p0, bool commit);
235static void *dma32_getnexttxp(dma_info_t *di, txd_range_t range); 241static void *dma32_getnexttxp(dma_info_t *di, txd_range_t range);
236static void *dma32_getnextrxp(dma_info_t *di, bool forceall); 242static void *dma32_getnextrxp(dma_info_t *di, bool forceall);
237static void dma32_txrotate(dma_info_t *di); 243static void dma32_txrotate(dma_info_t *di);
@@ -246,14 +252,14 @@ static bool dma32_txstopped(dma_info_t *di);
246static bool dma32_rxstopped(dma_info_t *di); 252static bool dma32_rxstopped(dma_info_t *di);
247static bool dma32_rxenabled(dma_info_t *di); 253static bool dma32_rxenabled(dma_info_t *di);
248 254
249static bool _dma32_addrext(osl_t *osh, dma32regs_t *dma32regs); 255static bool _dma32_addrext(struct osl_info *osh, dma32regs_t *dma32regs);
250 256
251/* Prototypes for 64-bit routines */ 257/* Prototypes for 64-bit routines */
252static bool dma64_alloc(dma_info_t *di, uint direction); 258static bool dma64_alloc(dma_info_t *di, uint direction);
253static bool dma64_txreset(dma_info_t *di); 259static bool dma64_txreset(dma_info_t *di);
254static bool dma64_rxreset(dma_info_t *di); 260static bool dma64_rxreset(dma_info_t *di);
255static bool dma64_txsuspendedidle(dma_info_t *di); 261static bool dma64_txsuspendedidle(dma_info_t *di);
256static int dma64_txfast(dma_info_t *di, void *p0, bool commit); 262static int dma64_txfast(dma_info_t *di, struct sk_buff *p0, bool commit);
257static int dma64_txunframed(dma_info_t *di, void *p0, uint len, bool commit); 263static int dma64_txunframed(dma_info_t *di, void *p0, uint len, bool commit);
258static void *dma64_getpos(dma_info_t *di, bool direction); 264static void *dma64_getpos(dma_info_t *di, bool direction);
259static void *dma64_getnexttxp(dma_info_t *di, txd_range_t range); 265static void *dma64_getnexttxp(dma_info_t *di, txd_range_t range);
@@ -270,7 +276,7 @@ static void dma64_txreclaim(dma_info_t *di, txd_range_t range);
270static bool dma64_txstopped(dma_info_t *di); 276static bool dma64_txstopped(dma_info_t *di);
271static bool dma64_rxstopped(dma_info_t *di); 277static bool dma64_rxstopped(dma_info_t *di);
272static bool dma64_rxenabled(dma_info_t *di); 278static bool dma64_rxenabled(dma_info_t *di);
273static bool _dma64_addrext(osl_t *osh, dma64regs_t *dma64regs); 279static bool _dma64_addrext(struct osl_info *osh, dma64regs_t *dma64regs);
274 280
275static inline u32 parity32(u32 data); 281static inline u32 parity32(u32 data);
276 282
@@ -368,10 +374,10 @@ static const di_fcn_t dma32proc = {
368 39 374 39
369}; 375};
370 376
371hnddma_t *dma_attach(osl_t *osh, char *name, si_t *sih, void *dmaregstx, 377struct hnddma_pub *dma_attach(struct osl_info *osh, char *name, si_t *sih,
372 void *dmaregsrx, uint ntxd, uint nrxd, uint rxbufsize, 378 void *dmaregstx, void *dmaregsrx, uint ntxd,
373 int rxextheadroom, uint nrxpost, uint rxoffset, 379 uint nrxd, uint rxbufsize, int rxextheadroom,
374 uint *msg_level) 380 uint nrxpost, uint rxoffset, uint *msg_level)
375{ 381{
376 dma_info_t *di; 382 dma_info_t *di;
377 uint size; 383 uint size;
@@ -570,7 +576,7 @@ hnddma_t *dma_attach(osl_t *osh, char *name, si_t *sih, void *dmaregstx,
570 } 576 }
571 } 577 }
572 578
573 return (hnddma_t *) di; 579 return (struct hnddma_pub *) di;
574 580
575 fail: 581 fail:
576 _dma_detach(di); 582 _dma_detach(di);
@@ -663,7 +669,7 @@ dma64_dd_upd(dma_info_t *di, dma64dd_t *ddring, dmaaddr_t pa, uint outidx,
663 } 669 }
664} 670}
665 671
666static bool _dma32_addrext(osl_t *osh, dma32regs_t *dma32regs) 672static bool _dma32_addrext(struct osl_info *osh, dma32regs_t *dma32regs)
667{ 673{
668 u32 w; 674 u32 w;
669 675
@@ -902,7 +908,7 @@ static void _dma_rxinit(dma_info_t *di)
902 908
903 /* clear rx descriptor ring */ 909 /* clear rx descriptor ring */
904 if (DMA64_ENAB(di) && DMA64_MODE(di)) { 910 if (DMA64_ENAB(di) && DMA64_MODE(di)) {
905 BZERO_SM((void *)di->rxd64, 911 memset((void *)di->rxd64, '\0',
906 (di->nrxd * sizeof(dma64dd_t))); 912 (di->nrxd * sizeof(dma64dd_t)));
907 913
908 /* DMA engine with out alignment requirement requires table to be inited 914 /* DMA engine with out alignment requirement requires table to be inited
@@ -916,7 +922,7 @@ static void _dma_rxinit(dma_info_t *di)
916 if (di->aligndesc_4k) 922 if (di->aligndesc_4k)
917 _dma_ddtable_init(di, DMA_RX, di->rxdpa); 923 _dma_ddtable_init(di, DMA_RX, di->rxdpa);
918 } else if (DMA32_ENAB(di)) { 924 } else if (DMA32_ENAB(di)) {
919 BZERO_SM((void *)di->rxd32, 925 memset((void *)di->rxd32, '\0',
920 (di->nrxd * sizeof(dma32dd_t))); 926 (di->nrxd * sizeof(dma32dd_t)));
921 _dma_rxenable(di); 927 _dma_rxenable(di);
922 _dma_ddtable_init(di, DMA_RX, di->rxdpa); 928 _dma_ddtable_init(di, DMA_RX, di->rxdpa);
@@ -978,7 +984,7 @@ _dma_rx_param_get(dma_info_t *di, u16 *rxoffset, u16 *rxbufsize)
978 */ 984 */
979static void *BCMFASTPATH _dma_rx(dma_info_t *di) 985static void *BCMFASTPATH _dma_rx(dma_info_t *di)
980{ 986{
981 void *p, *head, *tail; 987 struct sk_buff *p, *head, *tail;
982 uint len; 988 uint len;
983 uint pkt_len; 989 uint pkt_len;
984 int resid = 0; 990 int resid = 0;
@@ -988,30 +994,31 @@ static void *BCMFASTPATH _dma_rx(dma_info_t *di)
988 if (head == NULL) 994 if (head == NULL)
989 return NULL; 995 return NULL;
990 996
991 len = ltoh16(*(u16 *) (PKTDATA(head))); 997 len = ltoh16(*(u16 *) (head->data));
992 DMA_TRACE(("%s: dma_rx len %d\n", di->name, len)); 998 DMA_TRACE(("%s: dma_rx len %d\n", di->name, len));
993 999
994#if defined(__mips__) 1000#if defined(__mips__)
1001#define OSL_UNCACHED(va) ((void *)KSEG1ADDR((va)))
995 if (!len) { 1002 if (!len) {
996 while (!(len = *(u16 *) OSL_UNCACHED(PKTDATA(head)))) 1003 while (!(len = *(u16 *) OSL_UNCACHED(head->data)))
997 udelay(1); 1004 udelay(1);
998 1005
999 *(u16 *) PKTDATA(head) = htol16((u16) len); 1006 *(u16 *) (head->data) = htol16((u16) len);
1000 } 1007 }
1001#endif /* defined(__mips__) */ 1008#endif /* defined(__mips__) */
1002 1009
1003 /* set actual length */ 1010 /* set actual length */
1004 pkt_len = min((di->rxoffset + len), di->rxbufsize); 1011 pkt_len = min((di->rxoffset + len), di->rxbufsize);
1005 PKTSETLEN(head, pkt_len); 1012 __skb_trim(head, pkt_len);
1006 resid = len - (di->rxbufsize - di->rxoffset); 1013 resid = len - (di->rxbufsize - di->rxoffset);
1007 1014
1008 /* check for single or multi-buffer rx */ 1015 /* check for single or multi-buffer rx */
1009 if (resid > 0) { 1016 if (resid > 0) {
1010 tail = head; 1017 tail = head;
1011 while ((resid > 0) && (p = _dma_getnextrxp(di, false))) { 1018 while ((resid > 0) && (p = _dma_getnextrxp(di, false))) {
1012 PKTSETNEXT(tail, p); 1019 tail->next = p;
1013 pkt_len = min(resid, (int)di->rxbufsize); 1020 pkt_len = min(resid, (int)di->rxbufsize);
1014 PKTSETLEN(p, pkt_len); 1021 __skb_trim(p, pkt_len);
1015 1022
1016 tail = p; 1023 tail = p;
1017 resid -= di->rxbufsize; 1024 resid -= di->rxbufsize;
@@ -1037,7 +1044,7 @@ static void *BCMFASTPATH _dma_rx(dma_info_t *di)
1037 if ((di->hnddma.dmactrlflags & DMA_CTRL_RXMULTI) == 0) { 1044 if ((di->hnddma.dmactrlflags & DMA_CTRL_RXMULTI) == 0) {
1038 DMA_ERROR(("%s: dma_rx: bad frame length (%d)\n", 1045 DMA_ERROR(("%s: dma_rx: bad frame length (%d)\n",
1039 di->name, len)); 1046 di->name, len));
1040 PKTFREE(di->osh, head, false); 1047 pkt_buf_free_skb(di->osh, head, false);
1041 di->hnddma.rxgiants++; 1048 di->hnddma.rxgiants++;
1042 goto next_frame; 1049 goto next_frame;
1043 } 1050 }
@@ -1053,7 +1060,7 @@ static void *BCMFASTPATH _dma_rx(dma_info_t *di)
1053 */ 1060 */
1054static bool BCMFASTPATH _dma_rxfill(dma_info_t *di) 1061static bool BCMFASTPATH _dma_rxfill(dma_info_t *di)
1055{ 1062{
1056 void *p; 1063 struct sk_buff *p;
1057 u16 rxin, rxout; 1064 u16 rxin, rxout;
1058 u32 flags = 0; 1065 u32 flags = 0;
1059 uint n; 1066 uint n;
@@ -1085,7 +1092,7 @@ static bool BCMFASTPATH _dma_rxfill(dma_info_t *di)
1085 size to be allocated 1092 size to be allocated
1086 */ 1093 */
1087 1094
1088 p = osl_pktget(di->osh, di->rxbufsize + extra_offset); 1095 p = pkt_buf_get_skb(di->osh, di->rxbufsize + extra_offset);
1089 1096
1090 if (p == NULL) { 1097 if (p == NULL) {
1091 DMA_ERROR(("%s: dma_rxfill: out of rxbufs\n", 1098 DMA_ERROR(("%s: dma_rxfill: out of rxbufs\n",
@@ -1109,17 +1116,18 @@ static bool BCMFASTPATH _dma_rxfill(dma_info_t *di)
1109 } 1116 }
1110 /* reserve an extra headroom, if applicable */ 1117 /* reserve an extra headroom, if applicable */
1111 if (extra_offset) 1118 if (extra_offset)
1112 PKTPULL(p, extra_offset); 1119 skb_pull(p, extra_offset);
1113 1120
1114 /* Do a cached write instead of uncached write since DMA_MAP 1121 /* Do a cached write instead of uncached write since DMA_MAP
1115 * will flush the cache. 1122 * will flush the cache.
1116 */ 1123 */
1117 *(u32 *) (PKTDATA(p)) = 0; 1124 *(u32 *) (p->data) = 0;
1118 1125
1119 if (DMASGLIST_ENAB) 1126 if (DMASGLIST_ENAB)
1120 bzero(&di->rxp_dmah[rxout], sizeof(hnddma_seg_map_t)); 1127 memset(&di->rxp_dmah[rxout], 0,
1128 sizeof(hnddma_seg_map_t));
1121 1129
1122 pa = DMA_MAP(di->osh, PKTDATA(p), 1130 pa = DMA_MAP(di->osh, p->data,
1123 di->rxbufsize, DMA_RX, p, &di->rxp_dmah[rxout]); 1131 di->rxbufsize, DMA_RX, p, &di->rxp_dmah[rxout]);
1124 1132
1125 ASSERT(IS_ALIGNED(PHYSADDRLO(pa), 4)); 1133 ASSERT(IS_ALIGNED(PHYSADDRLO(pa), 4));
@@ -1220,15 +1228,10 @@ static void _dma_rxreclaim(dma_info_t *di)
1220{ 1228{
1221 void *p; 1229 void *p;
1222 1230
1223 /* "unused local" warning suppression for OSLs that
1224 * define PKTFREE() without using the di->osh arg
1225 */
1226 di = di;
1227
1228 DMA_TRACE(("%s: dma_rxreclaim\n", di->name)); 1231 DMA_TRACE(("%s: dma_rxreclaim\n", di->name));
1229 1232
1230 while ((p = _dma_getnextrxp(di, true))) 1233 while ((p = _dma_getnextrxp(di, true)))
1231 PKTFREE(di->osh, p, false); 1234 pkt_buf_free_skb(di->osh, p, false);
1232} 1235}
1233 1236
1234static void *BCMFASTPATH _dma_getnextrxp(dma_info_t *di, bool forceall) 1237static void *BCMFASTPATH _dma_getnextrxp(dma_info_t *di, bool forceall)
@@ -1372,7 +1375,7 @@ static unsigned long _dma_getvar(dma_info_t *di, const char *name)
1372 return 0; 1375 return 0;
1373} 1376}
1374 1377
1375void dma_txpioloopback(osl_t *osh, dma32regs_t *regs) 1378void dma_txpioloopback(struct osl_info *osh, dma32regs_t *regs)
1376{ 1379{
1377 OR_REG(osh, &regs->control, XC_LE); 1380 OR_REG(osh, &regs->control, XC_LE);
1378} 1381}
@@ -1395,7 +1398,7 @@ u8 dma_align_sizetobits(uint size)
1395 * descriptor ring size aligned location. This will ensure that the ring will 1398 * descriptor ring size aligned location. This will ensure that the ring will
1396 * not cross page boundary 1399 * not cross page boundary
1397 */ 1400 */
1398static void *dma_ringalloc(osl_t *osh, u32 boundary, uint size, 1401static void *dma_ringalloc(struct osl_info *osh, u32 boundary, uint size,
1399 u16 *alignbits, uint *alloced, 1402 u16 *alignbits, uint *alloced,
1400 dmaaddr_t *descpa, osldma_t **dmah) 1403 dmaaddr_t *descpa, osldma_t **dmah)
1401{ 1404{
@@ -1434,7 +1437,7 @@ static void dma32_txinit(dma_info_t *di)
1434 di->hnddma.txavail = di->ntxd - 1; 1437 di->hnddma.txavail = di->ntxd - 1;
1435 1438
1436 /* clear tx descriptor ring */ 1439 /* clear tx descriptor ring */
1437 BZERO_SM((void *)di->txd32, (di->ntxd * sizeof(dma32dd_t))); 1440 memset((void *)di->txd32, '\0', (di->ntxd * sizeof(dma32dd_t)));
1438 1441
1439 if ((di->hnddma.dmactrlflags & DMA_CTRL_PEN) == 0) 1442 if ((di->hnddma.dmactrlflags & DMA_CTRL_PEN) == 0)
1440 control |= XC_PD; 1443 control |= XC_PD;
@@ -1491,7 +1494,7 @@ static void dma32_txreclaim(dma_info_t *di, txd_range_t range)
1491 return; 1494 return;
1492 1495
1493 while ((p = dma32_getnexttxp(di, range))) 1496 while ((p = dma32_getnexttxp(di, range)))
1494 PKTFREE(di->osh, p, true); 1497 pkt_buf_free_skb(di->osh, p, true);
1495} 1498}
1496 1499
1497static bool dma32_txstopped(dma_info_t *di) 1500static bool dma32_txstopped(dma_info_t *di)
@@ -1651,9 +1654,9 @@ static bool dma32_txsuspendedidle(dma_info_t *di)
1651 * WARNING: call must check the return value for error. 1654 * WARNING: call must check the return value for error.
1652 * the error(toss frames) could be fatal and cause many subsequent hard to debug problems 1655 * the error(toss frames) could be fatal and cause many subsequent hard to debug problems
1653 */ 1656 */
1654static int dma32_txfast(dma_info_t *di, void *p0, bool commit) 1657static int dma32_txfast(dma_info_t *di, struct sk_buff *p0, bool commit)
1655{ 1658{
1656 void *p, *next; 1659 struct sk_buff *p, *next;
1657 unsigned char *data; 1660 unsigned char *data;
1658 uint len; 1661 uint len;
1659 u16 txout; 1662 u16 txout;
@@ -1672,12 +1675,12 @@ static int dma32_txfast(dma_info_t *di, void *p0, bool commit)
1672 uint nsegs, j; 1675 uint nsegs, j;
1673 hnddma_seg_map_t *map; 1676 hnddma_seg_map_t *map;
1674 1677
1675 data = PKTDATA(p); 1678 data = p->data;
1676 len = PKTLEN(p); 1679 len = p->len;
1677#ifdef BCM_DMAPAD 1680#ifdef BCM_DMAPAD
1678 len += PKTDMAPAD(di->osh, p); 1681 len += PKTDMAPAD(di->osh, p);
1679#endif 1682#endif
1680 next = PKTNEXT(p); 1683 next = p->next;
1681 1684
1682 /* return nonzero if out of tx descriptors */ 1685 /* return nonzero if out of tx descriptors */
1683 if (NEXTTXD(txout) == di->txin) 1686 if (NEXTTXD(txout) == di->txin)
@@ -1687,7 +1690,8 @@ static int dma32_txfast(dma_info_t *di, void *p0, bool commit)
1687 continue; 1690 continue;
1688 1691
1689 if (DMASGLIST_ENAB) 1692 if (DMASGLIST_ENAB)
1690 bzero(&di->txp_dmah[txout], sizeof(hnddma_seg_map_t)); 1693 memset(&di->txp_dmah[txout], 0,
1694 sizeof(hnddma_seg_map_t));
1691 1695
1692 /* get physical address of buffer start */ 1696 /* get physical address of buffer start */
1693 pa = DMA_MAP(di->osh, data, len, DMA_TX, p, 1697 pa = DMA_MAP(di->osh, data, len, DMA_TX, p,
@@ -1761,7 +1765,7 @@ static int dma32_txfast(dma_info_t *di, void *p0, bool commit)
1761 1765
1762 outoftxd: 1766 outoftxd:
1763 DMA_ERROR(("%s: dma_txfast: out of txds\n", di->name)); 1767 DMA_ERROR(("%s: dma_txfast: out of txds\n", di->name));
1764 PKTFREE(di->osh, p0, true); 1768 pkt_buf_free_skb(di->osh, p0, true);
1765 di->hnddma.txavail = 0; 1769 di->hnddma.txavail = 0;
1766 di->hnddma.txnobuf++; 1770 di->hnddma.txnobuf++;
1767 return -1; 1771 return -1;
@@ -1959,7 +1963,7 @@ static void dma32_txrotate(dma_info_t *di)
1959 if (DMASGLIST_ENAB) { 1963 if (DMASGLIST_ENAB) {
1960 bcopy(&di->txp_dmah[old], &di->txp_dmah[new], 1964 bcopy(&di->txp_dmah[old], &di->txp_dmah[new],
1961 sizeof(hnddma_seg_map_t)); 1965 sizeof(hnddma_seg_map_t));
1962 bzero(&di->txp_dmah[old], sizeof(hnddma_seg_map_t)); 1966 memset(&di->txp_dmah[old], 0, sizeof(hnddma_seg_map_t));
1963 } 1967 }
1964 1968
1965 di->txp[old] = NULL; 1969 di->txp[old] = NULL;
@@ -1989,7 +1993,7 @@ static void dma64_txinit(dma_info_t *di)
1989 di->hnddma.txavail = di->ntxd - 1; 1993 di->hnddma.txavail = di->ntxd - 1;
1990 1994
1991 /* clear tx descriptor ring */ 1995 /* clear tx descriptor ring */
1992 BZERO_SM((void *)di->txd64, (di->ntxd * sizeof(dma64dd_t))); 1996 memset((void *)di->txd64, '\0', (di->ntxd * sizeof(dma64dd_t)));
1993 1997
1994 /* DMA engine with out alignment requirement requires table to be inited 1998 /* DMA engine with out alignment requirement requires table to be inited
1995 * before enabling the engine 1999 * before enabling the engine
@@ -2060,7 +2064,7 @@ static void BCMFASTPATH dma64_txreclaim(dma_info_t *di, txd_range_t range)
2060 while ((p = dma64_getnexttxp(di, range))) { 2064 while ((p = dma64_getnexttxp(di, range))) {
2061 /* For unframed data, we don't have any packets to free */ 2065 /* For unframed data, we don't have any packets to free */
2062 if (!(di->hnddma.dmactrlflags & DMA_CTRL_UNFRAMED)) 2066 if (!(di->hnddma.dmactrlflags & DMA_CTRL_UNFRAMED))
2063 PKTFREE(di->osh, p, true); 2067 pkt_buf_free_skb(di->osh, p, true);
2064 } 2068 }
2065} 2069}
2066 2070
@@ -2300,9 +2304,10 @@ static int dma64_txunframed(dma_info_t *di, void *buf, uint len, bool commit)
2300 * WARNING: call must check the return value for error. 2304 * WARNING: call must check the return value for error.
2301 * the error(toss frames) could be fatal and cause many subsequent hard to debug problems 2305 * the error(toss frames) could be fatal and cause many subsequent hard to debug problems
2302 */ 2306 */
2303static int BCMFASTPATH dma64_txfast(dma_info_t *di, void *p0, bool commit) 2307static int BCMFASTPATH dma64_txfast(dma_info_t *di, struct sk_buff *p0,
2308 bool commit)
2304{ 2309{
2305 void *p, *next; 2310 struct sk_buff *p, *next;
2306 unsigned char *data; 2311 unsigned char *data;
2307 uint len; 2312 uint len;
2308 u16 txout; 2313 u16 txout;
@@ -2321,12 +2326,12 @@ static int BCMFASTPATH dma64_txfast(dma_info_t *di, void *p0, bool commit)
2321 uint nsegs, j; 2326 uint nsegs, j;
2322 hnddma_seg_map_t *map; 2327 hnddma_seg_map_t *map;
2323 2328
2324 data = PKTDATA(p); 2329 data = p->data;
2325 len = PKTLEN(p); 2330 len = p->len;
2326#ifdef BCM_DMAPAD 2331#ifdef BCM_DMAPAD
2327 len += PKTDMAPAD(di->osh, p); 2332 len += PKTDMAPAD(di->osh, p);
2328#endif /* BCM_DMAPAD */ 2333#endif /* BCM_DMAPAD */
2329 next = PKTNEXT(p); 2334 next = p->next;
2330 2335
2331 /* return nonzero if out of tx descriptors */ 2336 /* return nonzero if out of tx descriptors */
2332 if (NEXTTXD(txout) == di->txin) 2337 if (NEXTTXD(txout) == di->txin)
@@ -2337,7 +2342,8 @@ static int BCMFASTPATH dma64_txfast(dma_info_t *di, void *p0, bool commit)
2337 2342
2338 /* get physical address of buffer start */ 2343 /* get physical address of buffer start */
2339 if (DMASGLIST_ENAB) 2344 if (DMASGLIST_ENAB)
2340 bzero(&di->txp_dmah[txout], sizeof(hnddma_seg_map_t)); 2345 memset(&di->txp_dmah[txout], 0,
2346 sizeof(hnddma_seg_map_t));
2341 2347
2342 pa = DMA_MAP(di->osh, data, len, DMA_TX, p, 2348 pa = DMA_MAP(di->osh, data, len, DMA_TX, p,
2343 &di->txp_dmah[txout]); 2349 &di->txp_dmah[txout]);
@@ -2409,7 +2415,7 @@ static int BCMFASTPATH dma64_txfast(dma_info_t *di, void *p0, bool commit)
2409 2415
2410 outoftxd: 2416 outoftxd:
2411 DMA_ERROR(("%s: dma_txfast: out of txds !!!\n", di->name)); 2417 DMA_ERROR(("%s: dma_txfast: out of txds !!!\n", di->name));
2412 PKTFREE(di->osh, p0, true); 2418 pkt_buf_free_skb(di->osh, p0, true);
2413 di->hnddma.txavail = 0; 2419 di->hnddma.txavail = 0;
2414 di->hnddma.txnobuf++; 2420 di->hnddma.txnobuf++;
2415 return -1; 2421 return -1;
@@ -2563,7 +2569,7 @@ static void *BCMFASTPATH dma64_getnextrxp(dma_info_t *di, bool forceall)
2563 return rxp; 2569 return rxp;
2564} 2570}
2565 2571
2566static bool _dma64_addrext(osl_t *osh, dma64regs_t * dma64regs) 2572static bool _dma64_addrext(struct osl_info *osh, dma64regs_t * dma64regs)
2567{ 2573{
2568 u32 w; 2574 u32 w;
2569 OR_REG(osh, &dma64regs->control, D64_XC_AE); 2575 OR_REG(osh, &dma64regs->control, D64_XC_AE);
@@ -2635,7 +2641,7 @@ static void dma64_txrotate(dma_info_t *di)
2635 if (DMASGLIST_ENAB) { 2641 if (DMASGLIST_ENAB) {
2636 bcopy(&di->txp_dmah[old], &di->txp_dmah[new], 2642 bcopy(&di->txp_dmah[old], &di->txp_dmah[new],
2637 sizeof(hnddma_seg_map_t)); 2643 sizeof(hnddma_seg_map_t));
2638 bzero(&di->txp_dmah[old], sizeof(hnddma_seg_map_t)); 2644 memset(&di->txp_dmah[old], 0, sizeof(hnddma_seg_map_t));
2639 } 2645 }
2640 2646
2641 di->txp[old] = NULL; 2647 di->txp[old] = NULL;
@@ -2654,7 +2660,7 @@ static void dma64_txrotate(dma_info_t *di)
2654uint dma_addrwidth(si_t *sih, void *dmaregs) 2660uint dma_addrwidth(si_t *sih, void *dmaregs)
2655{ 2661{
2656 dma32regs_t *dma32regs; 2662 dma32regs_t *dma32regs;
2657 osl_t *osh; 2663 struct osl_info *osh;
2658 2664
2659 osh = si_osh(sih); 2665 osh = si_osh(sih);
2660 2666
@@ -2664,8 +2670,8 @@ uint dma_addrwidth(si_t *sih, void *dmaregs)
2664 /* backplane are 64-bit capable */ 2670 /* backplane are 64-bit capable */
2665 if (si_backplane64(sih)) 2671 if (si_backplane64(sih))
2666 /* If bus is System Backplane or PCIE then we can access 64-bits */ 2672 /* If bus is System Backplane or PCIE then we can access 64-bits */
2667 if ((BUSTYPE(sih->bustype) == SI_BUS) || 2673 if ((sih->bustype == SI_BUS) ||
2668 ((BUSTYPE(sih->bustype) == PCI_BUS) && 2674 ((sih->bustype == PCI_BUS) &&
2669 (sih->buscoretype == PCIE_CORE_ID))) 2675 (sih->buscoretype == PCIE_CORE_ID)))
2670 return DMADDRWIDTH_64; 2676 return DMADDRWIDTH_64;
2671 2677
@@ -2679,8 +2685,8 @@ uint dma_addrwidth(si_t *sih, void *dmaregs)
2679 dma32regs = (dma32regs_t *) dmaregs; 2685 dma32regs = (dma32regs_t *) dmaregs;
2680 2686
2681 /* For System Backplane, PCIE bus or addrext feature, 32-bits ok */ 2687 /* For System Backplane, PCIE bus or addrext feature, 32-bits ok */
2682 if ((BUSTYPE(sih->bustype) == SI_BUS) || 2688 if ((sih->bustype == SI_BUS) ||
2683 ((BUSTYPE(sih->bustype) == PCI_BUS) 2689 ((sih->bustype == PCI_BUS)
2684 && sih->buscoretype == PCIE_CORE_ID) 2690 && sih->buscoretype == PCIE_CORE_ID)
2685 || (_dma32_addrext(osh, dma32regs))) 2691 || (_dma32_addrext(osh, dma32regs)))
2686 return DMADDRWIDTH_32; 2692 return DMADDRWIDTH_32;
diff --git a/drivers/staging/brcm80211/util/hndpmu.c b/drivers/staging/brcm80211/util/hndpmu.c
index a8f3306c1d2b..6cc59a895868 100644
--- a/drivers/staging/brcm80211/util/hndpmu.c
+++ b/drivers/staging/brcm80211/util/hndpmu.c
@@ -13,9 +13,14 @@
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16#include <linux/delay.h>
16#include <linux/kernel.h> 17#include <linux/kernel.h>
17#include <linux/string.h> 18#include <linux/string.h>
18#include <linuxver.h> 19#include <linux/module.h>
20#include <linux/pci.h>
21#ifdef BRCM_FULLMAC
22#include <linux/netdevice.h>
23#endif
19#include <bcmdefs.h> 24#include <bcmdefs.h>
20#include <osl.h> 25#include <osl.h>
21#include <bcmutils.h> 26#include <bcmutils.h>
@@ -40,23 +45,23 @@
40#define PMU_NONE(args) 45#define PMU_NONE(args)
41 46
42/* PLL controls/clocks */ 47/* PLL controls/clocks */
43static void si_pmu1_pllinit0(si_t *sih, osl_t *osh, chipcregs_t *cc, 48static void si_pmu1_pllinit0(si_t *sih, struct osl_info *osh, chipcregs_t *cc,
44 u32 xtal); 49 u32 xtal);
45static u32 si_pmu1_cpuclk0(si_t *sih, osl_t *osh, chipcregs_t *cc); 50static u32 si_pmu1_cpuclk0(si_t *sih, struct osl_info *osh, chipcregs_t *cc);
46static u32 si_pmu1_alpclk0(si_t *sih, osl_t *osh, chipcregs_t *cc); 51static u32 si_pmu1_alpclk0(si_t *sih, struct osl_info *osh, chipcregs_t *cc);
47 52
48/* PMU resources */ 53/* PMU resources */
49static bool si_pmu_res_depfltr_bb(si_t *sih); 54static bool si_pmu_res_depfltr_bb(si_t *sih);
50static bool si_pmu_res_depfltr_ncb(si_t *sih); 55static bool si_pmu_res_depfltr_ncb(si_t *sih);
51static bool si_pmu_res_depfltr_paldo(si_t *sih); 56static bool si_pmu_res_depfltr_paldo(si_t *sih);
52static bool si_pmu_res_depfltr_npaldo(si_t *sih); 57static bool si_pmu_res_depfltr_npaldo(si_t *sih);
53static u32 si_pmu_res_deps(si_t *sih, osl_t *osh, chipcregs_t *cc, 58static u32 si_pmu_res_deps(si_t *sih, struct osl_info *osh, chipcregs_t *cc,
54 u32 rsrcs, bool all); 59 u32 rsrcs, bool all);
55static uint si_pmu_res_uptime(si_t *sih, osl_t *osh, chipcregs_t *cc, 60static uint si_pmu_res_uptime(si_t *sih, struct osl_info *osh, chipcregs_t *cc,
56 u8 rsrc); 61 u8 rsrc);
57static void si_pmu_res_masks(si_t *sih, u32 * pmin, u32 * pmax); 62static void si_pmu_res_masks(si_t *sih, u32 * pmin, u32 * pmax);
58static void si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc, 63static void si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc,
59 osl_t *osh, u8 spuravoid); 64 struct osl_info *osh, u8 spuravoid);
60 65
61static void si_pmu_set_4330_plldivs(si_t *sih); 66static void si_pmu_set_4330_plldivs(si_t *sih);
62 67
@@ -101,7 +106,7 @@ void si_pmu_pllupd(si_t *sih)
101} 106}
102 107
103/* Setup switcher voltage */ 108/* Setup switcher voltage */
104void si_pmu_set_switcher_voltage(si_t *sih, osl_t *osh, u8 bb_voltage, 109void si_pmu_set_switcher_voltage(si_t *sih, struct osl_info *osh, u8 bb_voltage,
105 u8 rf_voltage) 110 u8 rf_voltage)
106{ 111{
107 chipcregs_t *cc; 112 chipcregs_t *cc;
@@ -124,14 +129,14 @@ void si_pmu_set_switcher_voltage(si_t *sih, osl_t *osh, u8 bb_voltage,
124 si_setcoreidx(sih, origidx); 129 si_setcoreidx(sih, origidx);
125} 130}
126 131
127void si_pmu_set_ldo_voltage(si_t *sih, osl_t *osh, u8 ldo, u8 voltage) 132void si_pmu_set_ldo_voltage(si_t *sih, struct osl_info *osh, u8 ldo, u8 voltage)
128{ 133{
129 u8 sr_cntl_shift = 0, rc_shift = 0, shift = 0, mask = 0; 134 u8 sr_cntl_shift = 0, rc_shift = 0, shift = 0, mask = 0;
130 u8 addr = 0; 135 u8 addr = 0;
131 136
132 ASSERT(sih->cccaps & CC_CAP_PMU); 137 ASSERT(sih->cccaps & CC_CAP_PMU);
133 138
134 switch (CHIPID(sih->chip)) { 139 switch (sih->chip) {
135 case BCM4336_CHIP_ID: 140 case BCM4336_CHIP_ID:
136 switch (ldo) { 141 switch (ldo) {
137 case SET_LDO_VOLTAGE_CLDO_PWM: 142 case SET_LDO_VOLTAGE_CLDO_PWM:
@@ -182,7 +187,7 @@ void si_pmu_set_ldo_voltage(si_t *sih, osl_t *osh, u8 ldo, u8 voltage)
182/* d11 slow to fast clock transition time in slow clock cycles */ 187/* d11 slow to fast clock transition time in slow clock cycles */
183#define D11SCC_SLOW2FAST_TRANSITION 2 188#define D11SCC_SLOW2FAST_TRANSITION 2
184 189
185u16 si_pmu_fast_pwrup_delay(si_t *sih, osl_t *osh) 190u16 si_pmu_fast_pwrup_delay(si_t *sih, struct osl_info *osh)
186{ 191{
187 uint delay = PMU_MAX_TRANSITION_DLY; 192 uint delay = PMU_MAX_TRANSITION_DLY;
188 chipcregs_t *cc; 193 chipcregs_t *cc;
@@ -199,7 +204,7 @@ u16 si_pmu_fast_pwrup_delay(si_t *sih, osl_t *osh)
199 cc = si_setcoreidx(sih, SI_CC_IDX); 204 cc = si_setcoreidx(sih, SI_CC_IDX);
200 ASSERT(cc != NULL); 205 ASSERT(cc != NULL);
201 206
202 switch (CHIPID(sih->chip)) { 207 switch (sih->chip) {
203 case BCM43224_CHIP_ID: 208 case BCM43224_CHIP_ID:
204 case BCM43225_CHIP_ID: 209 case BCM43225_CHIP_ID:
205 case BCM43421_CHIP_ID: 210 case BCM43421_CHIP_ID:
@@ -259,7 +264,7 @@ u16 si_pmu_fast_pwrup_delay(si_t *sih, osl_t *osh)
259 return (u16) delay; 264 return (u16) delay;
260} 265}
261 266
262u32 si_pmu_force_ilp(si_t *sih, osl_t *osh, bool force) 267u32 si_pmu_force_ilp(si_t *sih, struct osl_info *osh, bool force)
263{ 268{
264 chipcregs_t *cc; 269 chipcregs_t *cc;
265 uint origidx; 270 uint origidx;
@@ -599,7 +604,7 @@ static void si_pmu_res_masks(si_t *sih, u32 * pmin, u32 * pmax)
599 rsrcs = (sih->pmucaps & PCAP_RC_MASK) >> PCAP_RC_SHIFT; 604 rsrcs = (sih->pmucaps & PCAP_RC_MASK) >> PCAP_RC_SHIFT;
600 605
601 /* determine min/max rsrc masks */ 606 /* determine min/max rsrc masks */
602 switch (CHIPID(sih->chip)) { 607 switch (sih->chip) {
603 case BCM43224_CHIP_ID: 608 case BCM43224_CHIP_ID:
604 case BCM43225_CHIP_ID: 609 case BCM43225_CHIP_ID:
605 case BCM43421_CHIP_ID: 610 case BCM43421_CHIP_ID:
@@ -677,7 +682,7 @@ static void si_pmu_res_masks(si_t *sih, u32 * pmin, u32 * pmax)
677} 682}
678 683
679/* initialize PMU resources */ 684/* initialize PMU resources */
680void si_pmu_res_init(si_t *sih, osl_t *osh) 685void si_pmu_res_init(si_t *sih, struct osl_info *osh)
681{ 686{
682 chipcregs_t *cc; 687 chipcregs_t *cc;
683 uint origidx; 688 uint origidx;
@@ -696,7 +701,7 @@ void si_pmu_res_init(si_t *sih, osl_t *osh)
696 cc = si_setcoreidx(sih, SI_CC_IDX); 701 cc = si_setcoreidx(sih, SI_CC_IDX);
697 ASSERT(cc != NULL); 702 ASSERT(cc != NULL);
698 703
699 switch (CHIPID(sih->chip)) { 704 switch (sih->chip) {
700 case BCM4329_CHIP_ID: 705 case BCM4329_CHIP_ID:
701 /* Optimize resources up/down timers */ 706 /* Optimize resources up/down timers */
702 if (ISSIM_ENAB(sih)) { 707 if (ISSIM_ENAB(sih)) {
@@ -1095,7 +1100,7 @@ static const pmu1_xtaltab0_t *si_pmu1_xtaltab0(si_t *sih)
1095#ifdef BCMDBG 1100#ifdef BCMDBG
1096 char chn[8]; 1101 char chn[8];
1097#endif 1102#endif
1098 switch (CHIPID(sih->chip)) { 1103 switch (sih->chip) {
1099 case BCM4329_CHIP_ID: 1104 case BCM4329_CHIP_ID:
1100 return pmu1_xtaltab0_880_4329; 1105 return pmu1_xtaltab0_880_4329;
1101 case BCM4319_CHIP_ID: 1106 case BCM4319_CHIP_ID:
@@ -1123,7 +1128,7 @@ static const pmu1_xtaltab0_t *si_pmu1_xtaldef0(si_t *sih)
1123 char chn[8]; 1128 char chn[8];
1124#endif 1129#endif
1125 1130
1126 switch (CHIPID(sih->chip)) { 1131 switch (sih->chip) {
1127 case BCM4329_CHIP_ID: 1132 case BCM4329_CHIP_ID:
1128 /* Default to 38400Khz */ 1133 /* Default to 38400Khz */
1129 return &pmu1_xtaltab0_880_4329[PMU1_XTALTAB0_880_38400K]; 1134 return &pmu1_xtaltab0_880_4329[PMU1_XTALTAB0_880_38400K];
@@ -1155,7 +1160,7 @@ static u32 si_pmu1_pllfvco0(si_t *sih)
1155 char chn[8]; 1160 char chn[8];
1156#endif 1161#endif
1157 1162
1158 switch (CHIPID(sih->chip)) { 1163 switch (sih->chip) {
1159 case BCM4329_CHIP_ID: 1164 case BCM4329_CHIP_ID:
1160 return FVCO_880; 1165 return FVCO_880;
1161 case BCM4319_CHIP_ID: 1166 case BCM4319_CHIP_ID:
@@ -1178,7 +1183,7 @@ static u32 si_pmu1_pllfvco0(si_t *sih)
1178 1183
1179/* query alp/xtal clock frequency */ 1184/* query alp/xtal clock frequency */
1180static u32 1185static u32
1181si_pmu1_alpclk0(si_t *sih, osl_t *osh, chipcregs_t *cc) 1186si_pmu1_alpclk0(si_t *sih, struct osl_info *osh, chipcregs_t *cc)
1182{ 1187{
1183 const pmu1_xtaltab0_t *xt; 1188 const pmu1_xtaltab0_t *xt;
1184 u32 xf; 1189 u32 xf;
@@ -1203,7 +1208,8 @@ si_pmu1_alpclk0(si_t *sih, osl_t *osh, chipcregs_t *cc)
1203 * case the xtal frequency is unknown to the s/w so we need to call 1208 * case the xtal frequency is unknown to the s/w so we need to call
1204 * si_pmu1_xtaldef0() wherever it is needed to return a default value. 1209 * si_pmu1_xtaldef0() wherever it is needed to return a default value.
1205 */ 1210 */
1206static void si_pmu1_pllinit0(si_t *sih, osl_t *osh, chipcregs_t *cc, u32 xtal) 1211static void si_pmu1_pllinit0(si_t *sih, struct osl_info *osh, chipcregs_t *cc,
1212 u32 xtal)
1207{ 1213{
1208 const pmu1_xtaltab0_t *xt; 1214 const pmu1_xtaltab0_t *xt;
1209 u32 tmp; 1215 u32 tmp;
@@ -1233,8 +1239,8 @@ static void si_pmu1_pllinit0(si_t *sih, osl_t *osh, chipcregs_t *cc, u32 xtal)
1233 */ 1239 */
1234 if ((((R_REG(osh, &cc->pmucontrol) & PCTL_XTALFREQ_MASK) >> 1240 if ((((R_REG(osh, &cc->pmucontrol) & PCTL_XTALFREQ_MASK) >>
1235 PCTL_XTALFREQ_SHIFT) == xt->xf) && 1241 PCTL_XTALFREQ_SHIFT) == xt->xf) &&
1236 !((CHIPID(sih->chip) == BCM4319_CHIP_ID) 1242 !((sih->chip == BCM4319_CHIP_ID)
1237 || (CHIPID(sih->chip) == BCM4330_CHIP_ID))) { 1243 || (sih->chip == BCM4330_CHIP_ID))) {
1238 PMU_MSG(("PLL already programmed for %d.%d MHz\n", 1244 PMU_MSG(("PLL already programmed for %d.%d MHz\n",
1239 xt->fref / 1000, xt->fref % 1000)); 1245 xt->fref / 1000, xt->fref % 1000));
1240 return; 1246 return;
@@ -1244,7 +1250,7 @@ static void si_pmu1_pllinit0(si_t *sih, osl_t *osh, chipcregs_t *cc, u32 xtal)
1244 PMU_MSG(("Programming PLL for %d.%d MHz\n", xt->fref / 1000, 1250 PMU_MSG(("Programming PLL for %d.%d MHz\n", xt->fref / 1000,
1245 xt->fref % 1000)); 1251 xt->fref % 1000));
1246 1252
1247 switch (CHIPID(sih->chip)) { 1253 switch (sih->chip) {
1248 case BCM4329_CHIP_ID: 1254 case BCM4329_CHIP_ID:
1249 /* Change the BBPLL drive strength to 8 for all channels */ 1255 /* Change the BBPLL drive strength to 8 for all channels */
1250 buf_strength = 0x888888; 1256 buf_strength = 0x888888;
@@ -1351,11 +1357,11 @@ static void si_pmu1_pllinit0(si_t *sih, osl_t *osh, chipcregs_t *cc, u32 xtal)
1351 p2div << PMU1_PLL0_PC0_P2DIV_SHIFT) & PMU1_PLL0_PC0_P2DIV_MASK); 1357 p2div << PMU1_PLL0_PC0_P2DIV_SHIFT) & PMU1_PLL0_PC0_P2DIV_MASK);
1352 W_REG(osh, &cc->pllcontrol_data, tmp); 1358 W_REG(osh, &cc->pllcontrol_data, tmp);
1353 1359
1354 if ((CHIPID(sih->chip) == BCM4330_CHIP_ID)) 1360 if ((sih->chip == BCM4330_CHIP_ID))
1355 si_pmu_set_4330_plldivs(sih); 1361 si_pmu_set_4330_plldivs(sih);
1356 1362
1357 if ((CHIPID(sih->chip) == BCM4329_CHIP_ID) 1363 if ((sih->chip == BCM4329_CHIP_ID)
1358 && (CHIPREV(sih->chiprev) == 0)) { 1364 && (sih->chiprev == 0)) {
1359 1365
1360 W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); 1366 W_REG(osh, &cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1);
1361 tmp = R_REG(osh, &cc->pllcontrol_data); 1367 tmp = R_REG(osh, &cc->pllcontrol_data);
@@ -1363,9 +1369,9 @@ static void si_pmu1_pllinit0(si_t *sih, osl_t *osh, chipcregs_t *cc, u32 xtal)
1363 tmp = tmp | DOT11MAC_880MHZ_CLK_DIVISOR_VAL; 1369 tmp = tmp | DOT11MAC_880MHZ_CLK_DIVISOR_VAL;
1364 W_REG(osh, &cc->pllcontrol_data, tmp); 1370 W_REG(osh, &cc->pllcontrol_data, tmp);
1365 } 1371 }
1366 if ((CHIPID(sih->chip) == BCM4319_CHIP_ID) || 1372 if ((sih->chip == BCM4319_CHIP_ID) ||
1367 (CHIPID(sih->chip) == BCM4336_CHIP_ID) || 1373 (sih->chip == BCM4336_CHIP_ID) ||
1368 (CHIPID(sih->chip) == BCM4330_CHIP_ID)) 1374 (sih->chip == BCM4330_CHIP_ID))
1369 ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MFB; 1375 ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MFB;
1370 else 1376 else
1371 ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MASH; 1377 ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MASH;
@@ -1407,7 +1413,7 @@ static void si_pmu1_pllinit0(si_t *sih, osl_t *osh, chipcregs_t *cc, u32 xtal)
1407 /* to operate the 4319 usb in 24MHz/48MHz; chipcontrol[2][84:83] needs 1413 /* to operate the 4319 usb in 24MHz/48MHz; chipcontrol[2][84:83] needs
1408 * to be updated. 1414 * to be updated.
1409 */ 1415 */
1410 if ((CHIPID(sih->chip) == BCM4319_CHIP_ID) 1416 if ((sih->chip == BCM4319_CHIP_ID)
1411 && (xt->fref != XTAL_FREQ_30000MHZ)) { 1417 && (xt->fref != XTAL_FREQ_30000MHZ)) {
1412 W_REG(osh, &cc->chipcontrol_addr, PMU1_PLL0_CHIPCTL2); 1418 W_REG(osh, &cc->chipcontrol_addr, PMU1_PLL0_CHIPCTL2);
1413 tmp = 1419 tmp =
@@ -1436,8 +1442,8 @@ static void si_pmu1_pllinit0(si_t *sih, osl_t *osh, chipcregs_t *cc, u32 xtal)
1436 PCTL_ILP_DIV_MASK) | 1442 PCTL_ILP_DIV_MASK) |
1437 ((xt->xf << PCTL_XTALFREQ_SHIFT) & PCTL_XTALFREQ_MASK); 1443 ((xt->xf << PCTL_XTALFREQ_SHIFT) & PCTL_XTALFREQ_MASK);
1438 1444
1439 if ((CHIPID(sih->chip) == BCM4329_CHIP_ID) 1445 if ((sih->chip == BCM4329_CHIP_ID)
1440 && CHIPREV(sih->chiprev) == 0) { 1446 && sih->chiprev == 0) {
1441 /* clear the htstretch before clearing HTReqEn */ 1447 /* clear the htstretch before clearing HTReqEn */
1442 AND_REG(osh, &cc->clkstretch, ~CSTRETCH_HT); 1448 AND_REG(osh, &cc->clkstretch, ~CSTRETCH_HT);
1443 tmp &= ~PCTL_HT_REQ_EN; 1449 tmp &= ~PCTL_HT_REQ_EN;
@@ -1448,7 +1454,7 @@ static void si_pmu1_pllinit0(si_t *sih, osl_t *osh, chipcregs_t *cc, u32 xtal)
1448 1454
1449/* query the CPU clock frequency */ 1455/* query the CPU clock frequency */
1450static u32 1456static u32
1451si_pmu1_cpuclk0(si_t *sih, osl_t *osh, chipcregs_t *cc) 1457si_pmu1_cpuclk0(si_t *sih, struct osl_info *osh, chipcregs_t *cc)
1452{ 1458{
1453 u32 tmp, m1div; 1459 u32 tmp, m1div;
1454#ifdef BCMDBG 1460#ifdef BCMDBG
@@ -1502,7 +1508,7 @@ si_pmu1_cpuclk0(si_t *sih, osl_t *osh, chipcregs_t *cc)
1502} 1508}
1503 1509
1504/* initialize PLL */ 1510/* initialize PLL */
1505void si_pmu_pll_init(si_t *sih, osl_t *osh, uint xtalfreq) 1511void si_pmu_pll_init(si_t *sih, struct osl_info *osh, uint xtalfreq)
1506{ 1512{
1507 chipcregs_t *cc; 1513 chipcregs_t *cc;
1508 uint origidx; 1514 uint origidx;
@@ -1517,7 +1523,7 @@ void si_pmu_pll_init(si_t *sih, osl_t *osh, uint xtalfreq)
1517 cc = si_setcoreidx(sih, SI_CC_IDX); 1523 cc = si_setcoreidx(sih, SI_CC_IDX);
1518 ASSERT(cc != NULL); 1524 ASSERT(cc != NULL);
1519 1525
1520 switch (CHIPID(sih->chip)) { 1526 switch (sih->chip) {
1521 case BCM4329_CHIP_ID: 1527 case BCM4329_CHIP_ID:
1522 if (xtalfreq == 0) 1528 if (xtalfreq == 0)
1523 xtalfreq = 38400; 1529 xtalfreq = 38400;
@@ -1555,7 +1561,7 @@ void si_pmu_pll_init(si_t *sih, osl_t *osh, uint xtalfreq)
1555} 1561}
1556 1562
1557/* query alp/xtal clock frequency */ 1563/* query alp/xtal clock frequency */
1558u32 si_pmu_alp_clock(si_t *sih, osl_t *osh) 1564u32 si_pmu_alp_clock(si_t *sih, struct osl_info *osh)
1559{ 1565{
1560 chipcregs_t *cc; 1566 chipcregs_t *cc;
1561 uint origidx; 1567 uint origidx;
@@ -1571,7 +1577,7 @@ u32 si_pmu_alp_clock(si_t *sih, osl_t *osh)
1571 cc = si_setcoreidx(sih, SI_CC_IDX); 1577 cc = si_setcoreidx(sih, SI_CC_IDX);
1572 ASSERT(cc != NULL); 1578 ASSERT(cc != NULL);
1573 1579
1574 switch (CHIPID(sih->chip)) { 1580 switch (sih->chip) {
1575 case BCM43224_CHIP_ID: 1581 case BCM43224_CHIP_ID:
1576 case BCM43225_CHIP_ID: 1582 case BCM43225_CHIP_ID:
1577 case BCM43421_CHIP_ID: 1583 case BCM43421_CHIP_ID:
@@ -1616,7 +1622,7 @@ u32 si_pmu_alp_clock(si_t *sih, osl_t *osh)
1616 * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc. 1622 * pllreg "pll0" i.e. 12 for main 6 for phy, 0 for misc.
1617 */ 1623 */
1618static u32 1624static u32
1619si_pmu5_clock(si_t *sih, osl_t *osh, chipcregs_t *cc, uint pll0, 1625si_pmu5_clock(si_t *sih, struct osl_info *osh, chipcregs_t *cc, uint pll0,
1620 uint m) { 1626 uint m) {
1621 u32 tmp, div, ndiv, p1, p2, fc; 1627 u32 tmp, div, ndiv, p1, p2, fc;
1622 1628
@@ -1631,7 +1637,7 @@ si_pmu5_clock(si_t *sih, osl_t *osh, chipcregs_t *cc, uint pll0,
1631 return 0; 1637 return 0;
1632 } 1638 }
1633 1639
1634 if (CHIPID(sih->chip) == BCM5357_CHIP_ID) { 1640 if (sih->chip == BCM5357_CHIP_ID) {
1635 /* Detect failure in clock setting */ 1641 /* Detect failure in clock setting */
1636 if ((R_REG(osh, &cc->chipstatus) & 0x40000) != 0) { 1642 if ((R_REG(osh, &cc->chipstatus) & 0x40000) != 0) {
1637 return 133 * 1000000; 1643 return 133 * 1000000;
@@ -1669,7 +1675,7 @@ si_pmu5_clock(si_t *sih, osl_t *osh, chipcregs_t *cc, uint pll0,
1669/* For designs that feed the same clock to both backplane 1675/* For designs that feed the same clock to both backplane
1670 * and CPU just return the CPU clock speed. 1676 * and CPU just return the CPU clock speed.
1671 */ 1677 */
1672u32 si_pmu_si_clock(si_t *sih, osl_t *osh) 1678u32 si_pmu_si_clock(si_t *sih, struct osl_info *osh)
1673{ 1679{
1674 chipcregs_t *cc; 1680 chipcregs_t *cc;
1675 uint origidx; 1681 uint origidx;
@@ -1685,7 +1691,7 @@ u32 si_pmu_si_clock(si_t *sih, osl_t *osh)
1685 cc = si_setcoreidx(sih, SI_CC_IDX); 1691 cc = si_setcoreidx(sih, SI_CC_IDX);
1686 ASSERT(cc != NULL); 1692 ASSERT(cc != NULL);
1687 1693
1688 switch (CHIPID(sih->chip)) { 1694 switch (sih->chip) {
1689 case BCM43224_CHIP_ID: 1695 case BCM43224_CHIP_ID:
1690 case BCM43225_CHIP_ID: 1696 case BCM43225_CHIP_ID:
1691 case BCM43421_CHIP_ID: 1697 case BCM43421_CHIP_ID:
@@ -1702,7 +1708,7 @@ u32 si_pmu_si_clock(si_t *sih, osl_t *osh)
1702 PMU5_MAINPLL_SI); 1708 PMU5_MAINPLL_SI);
1703 break; 1709 break;
1704 case BCM4329_CHIP_ID: 1710 case BCM4329_CHIP_ID:
1705 if (CHIPREV(sih->chiprev) == 0) 1711 if (sih->chiprev == 0)
1706 clock = 38400 * 1000; 1712 clock = 38400 * 1000;
1707 else 1713 else
1708 clock = si_pmu1_cpuclk0(sih, osh, cc); 1714 clock = si_pmu1_cpuclk0(sih, osh, cc);
@@ -1748,7 +1754,7 @@ u32 si_pmu_si_clock(si_t *sih, osl_t *osh)
1748} 1754}
1749 1755
1750/* query CPU clock frequency */ 1756/* query CPU clock frequency */
1751u32 si_pmu_cpu_clock(si_t *sih, osl_t *osh) 1757u32 si_pmu_cpu_clock(si_t *sih, struct osl_info *osh)
1752{ 1758{
1753 chipcregs_t *cc; 1759 chipcregs_t *cc;
1754 uint origidx; 1760 uint origidx;
@@ -1757,14 +1763,14 @@ u32 si_pmu_cpu_clock(si_t *sih, osl_t *osh)
1757 ASSERT(sih->cccaps & CC_CAP_PMU); 1763 ASSERT(sih->cccaps & CC_CAP_PMU);
1758 1764
1759 if ((sih->pmurev >= 5) && 1765 if ((sih->pmurev >= 5) &&
1760 !((CHIPID(sih->chip) == BCM4329_CHIP_ID) || 1766 !((sih->chip == BCM4329_CHIP_ID) ||
1761 (CHIPID(sih->chip) == BCM4319_CHIP_ID) || 1767 (sih->chip == BCM4319_CHIP_ID) ||
1762 (CHIPID(sih->chip) == BCM43236_CHIP_ID) || 1768 (sih->chip == BCM43236_CHIP_ID) ||
1763 (CHIPID(sih->chip) == BCM4336_CHIP_ID) || 1769 (sih->chip == BCM4336_CHIP_ID) ||
1764 (CHIPID(sih->chip) == BCM4330_CHIP_ID))) { 1770 (sih->chip == BCM4330_CHIP_ID))) {
1765 uint pll; 1771 uint pll;
1766 1772
1767 switch (CHIPID(sih->chip)) { 1773 switch (sih->chip) {
1768 case BCM5356_CHIP_ID: 1774 case BCM5356_CHIP_ID:
1769 pll = PMU5356_MAINPLL_PLL0; 1775 pll = PMU5356_MAINPLL_PLL0;
1770 break; 1776 break;
@@ -1792,7 +1798,7 @@ u32 si_pmu_cpu_clock(si_t *sih, osl_t *osh)
1792} 1798}
1793 1799
1794/* query memory clock frequency */ 1800/* query memory clock frequency */
1795u32 si_pmu_mem_clock(si_t *sih, osl_t *osh) 1801u32 si_pmu_mem_clock(si_t *sih, struct osl_info *osh)
1796{ 1802{
1797 chipcregs_t *cc; 1803 chipcregs_t *cc;
1798 uint origidx; 1804 uint origidx;
@@ -1801,14 +1807,14 @@ u32 si_pmu_mem_clock(si_t *sih, osl_t *osh)
1801 ASSERT(sih->cccaps & CC_CAP_PMU); 1807 ASSERT(sih->cccaps & CC_CAP_PMU);
1802 1808
1803 if ((sih->pmurev >= 5) && 1809 if ((sih->pmurev >= 5) &&
1804 !((CHIPID(sih->chip) == BCM4329_CHIP_ID) || 1810 !((sih->chip == BCM4329_CHIP_ID) ||
1805 (CHIPID(sih->chip) == BCM4319_CHIP_ID) || 1811 (sih->chip == BCM4319_CHIP_ID) ||
1806 (CHIPID(sih->chip) == BCM4330_CHIP_ID) || 1812 (sih->chip == BCM4330_CHIP_ID) ||
1807 (CHIPID(sih->chip) == BCM4336_CHIP_ID) || 1813 (sih->chip == BCM4336_CHIP_ID) ||
1808 (CHIPID(sih->chip) == BCM43236_CHIP_ID))) { 1814 (sih->chip == BCM43236_CHIP_ID))) {
1809 uint pll; 1815 uint pll;
1810 1816
1811 switch (CHIPID(sih->chip)) { 1817 switch (sih->chip) {
1812 case BCM5356_CHIP_ID: 1818 case BCM5356_CHIP_ID:
1813 pll = PMU5356_MAINPLL_PLL0; 1819 pll = PMU5356_MAINPLL_PLL0;
1814 break; 1820 break;
@@ -1841,7 +1847,7 @@ u32 si_pmu_mem_clock(si_t *sih, osl_t *osh)
1841 1847
1842static u32 ilpcycles_per_sec; 1848static u32 ilpcycles_per_sec;
1843 1849
1844u32 si_pmu_ilp_clock(si_t *sih, osl_t *osh) 1850u32 si_pmu_ilp_clock(si_t *sih, struct osl_info *osh)
1845{ 1851{
1846 if (ISSIM_ENAB(sih)) 1852 if (ISSIM_ENAB(sih))
1847 return ILP_CLOCK; 1853 return ILP_CLOCK;
@@ -1905,7 +1911,7 @@ static const sdiod_drive_str_t sdiod_drive_strength_tab3[] = {
1905#define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu)) 1911#define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu))
1906 1912
1907void 1913void
1908si_sdiod_drive_strength_init(si_t *sih, osl_t *osh, 1914si_sdiod_drive_strength_init(si_t *sih, struct osl_info *osh,
1909 u32 drivestrength) { 1915 u32 drivestrength) {
1910 chipcregs_t *cc; 1916 chipcregs_t *cc;
1911 uint origidx, intr_val = 0; 1917 uint origidx, intr_val = 0;
@@ -1976,7 +1982,7 @@ si_sdiod_drive_strength_init(si_t *sih, osl_t *osh,
1976} 1982}
1977 1983
1978/* initialize PMU */ 1984/* initialize PMU */
1979void si_pmu_init(si_t *sih, osl_t *osh) 1985void si_pmu_init(si_t *sih, struct osl_info *osh)
1980{ 1986{
1981 chipcregs_t *cc; 1987 chipcregs_t *cc;
1982 uint origidx; 1988 uint origidx;
@@ -1993,7 +1999,7 @@ void si_pmu_init(si_t *sih, osl_t *osh)
1993 else if (sih->pmurev >= 2) 1999 else if (sih->pmurev >= 2)
1994 OR_REG(osh, &cc->pmucontrol, PCTL_NOILP_ON_WAIT); 2000 OR_REG(osh, &cc->pmucontrol, PCTL_NOILP_ON_WAIT);
1995 2001
1996 if ((CHIPID(sih->chip) == BCM4329_CHIP_ID) && (sih->chiprev == 2)) { 2002 if ((sih->chip == BCM4329_CHIP_ID) && (sih->chiprev == 2)) {
1997 /* Fix for 4329b0 bad LPOM state. */ 2003 /* Fix for 4329b0 bad LPOM state. */
1998 W_REG(osh, &cc->regcontrol_addr, 2); 2004 W_REG(osh, &cc->regcontrol_addr, 2);
1999 OR_REG(osh, &cc->regcontrol_data, 0x100); 2005 OR_REG(osh, &cc->regcontrol_data, 0x100);
@@ -2008,7 +2014,7 @@ void si_pmu_init(si_t *sih, osl_t *osh)
2008 2014
2009/* Return up time in ILP cycles for the given resource. */ 2015/* Return up time in ILP cycles for the given resource. */
2010static uint 2016static uint
2011si_pmu_res_uptime(si_t *sih, osl_t *osh, chipcregs_t *cc, 2017si_pmu_res_uptime(si_t *sih, struct osl_info *osh, chipcregs_t *cc,
2012 u8 rsrc) { 2018 u8 rsrc) {
2013 u32 deps; 2019 u32 deps;
2014 uint up, i, dup, dmax; 2020 uint up, i, dup, dmax;
@@ -2045,7 +2051,7 @@ si_pmu_res_uptime(si_t *sih, osl_t *osh, chipcregs_t *cc,
2045 2051
2046/* Return dependancies (direct or all/indirect) for the given resources */ 2052/* Return dependancies (direct or all/indirect) for the given resources */
2047static u32 2053static u32
2048si_pmu_res_deps(si_t *sih, osl_t *osh, chipcregs_t *cc, u32 rsrcs, 2054si_pmu_res_deps(si_t *sih, struct osl_info *osh, chipcregs_t *cc, u32 rsrcs,
2049 bool all) 2055 bool all)
2050{ 2056{
2051 u32 deps = 0; 2057 u32 deps = 0;
@@ -2065,7 +2071,7 @@ si_pmu_res_deps(si_t *sih, osl_t *osh, chipcregs_t *cc, u32 rsrcs,
2065} 2071}
2066 2072
2067/* power up/down OTP through PMU resources */ 2073/* power up/down OTP through PMU resources */
2068void si_pmu_otp_power(si_t *sih, osl_t *osh, bool on) 2074void si_pmu_otp_power(si_t *sih, struct osl_info *osh, bool on)
2069{ 2075{
2070 chipcregs_t *cc; 2076 chipcregs_t *cc;
2071 uint origidx; 2077 uint origidx;
@@ -2084,7 +2090,7 @@ void si_pmu_otp_power(si_t *sih, osl_t *osh, bool on)
2084 cc = si_setcoreidx(sih, SI_CC_IDX); 2090 cc = si_setcoreidx(sih, SI_CC_IDX);
2085 ASSERT(cc != NULL); 2091 ASSERT(cc != NULL);
2086 2092
2087 switch (CHIPID(sih->chip)) { 2093 switch (sih->chip) {
2088 case BCM4329_CHIP_ID: 2094 case BCM4329_CHIP_ID:
2089 rsrcs = PMURES_BIT(RES4329_OTP_PU); 2095 rsrcs = PMURES_BIT(RES4329_OTP_PU);
2090 break; 2096 break;
@@ -2135,7 +2141,7 @@ void si_pmu_otp_power(si_t *sih, osl_t *osh, bool on)
2135 si_setcoreidx(sih, origidx); 2141 si_setcoreidx(sih, origidx);
2136} 2142}
2137 2143
2138void si_pmu_rcal(si_t *sih, osl_t *osh) 2144void si_pmu_rcal(si_t *sih, struct osl_info *osh)
2139{ 2145{
2140 chipcregs_t *cc; 2146 chipcregs_t *cc;
2141 uint origidx; 2147 uint origidx;
@@ -2147,7 +2153,7 @@ void si_pmu_rcal(si_t *sih, osl_t *osh)
2147 cc = si_setcoreidx(sih, SI_CC_IDX); 2153 cc = si_setcoreidx(sih, SI_CC_IDX);
2148 ASSERT(cc != NULL); 2154 ASSERT(cc != NULL);
2149 2155
2150 switch (CHIPID(sih->chip)) { 2156 switch (sih->chip) {
2151 case BCM4329_CHIP_ID:{ 2157 case BCM4329_CHIP_ID:{
2152 u8 rcal_code; 2158 u8 rcal_code;
2153 u32 val; 2159 u32 val;
@@ -2218,7 +2224,7 @@ void si_pmu_rcal(si_t *sih, osl_t *osh)
2218 si_setcoreidx(sih, origidx); 2224 si_setcoreidx(sih, origidx);
2219} 2225}
2220 2226
2221void si_pmu_spuravoid(si_t *sih, osl_t *osh, u8 spuravoid) 2227void si_pmu_spuravoid(si_t *sih, struct osl_info *osh, u8 spuravoid)
2222{ 2228{
2223 chipcregs_t *cc; 2229 chipcregs_t *cc;
2224 uint origidx, intr_val; 2230 uint origidx, intr_val;
@@ -2230,7 +2236,7 @@ void si_pmu_spuravoid(si_t *sih, osl_t *osh, u8 spuravoid)
2230 ASSERT(cc != NULL); 2236 ASSERT(cc != NULL);
2231 2237
2232 /* force the HT off */ 2238 /* force the HT off */
2233 if (CHIPID(sih->chip) == BCM4336_CHIP_ID) { 2239 if (sih->chip == BCM4336_CHIP_ID) {
2234 tmp = R_REG(osh, &cc->max_res_mask); 2240 tmp = R_REG(osh, &cc->max_res_mask);
2235 tmp &= ~RES4336_HT_AVAIL; 2241 tmp &= ~RES4336_HT_AVAIL;
2236 W_REG(osh, &cc->max_res_mask, tmp); 2242 W_REG(osh, &cc->max_res_mask, tmp);
@@ -2244,7 +2250,7 @@ void si_pmu_spuravoid(si_t *sih, osl_t *osh, u8 spuravoid)
2244 si_pmu_spuravoid_pllupdate(sih, cc, osh, spuravoid); 2250 si_pmu_spuravoid_pllupdate(sih, cc, osh, spuravoid);
2245 2251
2246 /* enable HT back on */ 2252 /* enable HT back on */
2247 if (CHIPID(sih->chip) == BCM4336_CHIP_ID) { 2253 if (sih->chip == BCM4336_CHIP_ID) {
2248 tmp = R_REG(osh, &cc->max_res_mask); 2254 tmp = R_REG(osh, &cc->max_res_mask);
2249 tmp |= RES4336_HT_AVAIL; 2255 tmp |= RES4336_HT_AVAIL;
2250 W_REG(osh, &cc->max_res_mask, tmp); 2256 W_REG(osh, &cc->max_res_mask, tmp);
@@ -2255,7 +2261,7 @@ void si_pmu_spuravoid(si_t *sih, osl_t *osh, u8 spuravoid)
2255} 2261}
2256 2262
2257static void 2263static void
2258si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc, osl_t *osh, 2264si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc, struct osl_info *osh,
2259 u8 spuravoid) 2265 u8 spuravoid)
2260{ 2266{
2261 u32 tmp = 0; 2267 u32 tmp = 0;
@@ -2263,14 +2269,14 @@ si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc, osl_t *osh,
2263 u8 bcm5357_bcm43236_p1div[] = { 0x1, 0x5, 0x5 }; 2269 u8 bcm5357_bcm43236_p1div[] = { 0x1, 0x5, 0x5 };
2264 u8 bcm5357_bcm43236_ndiv[] = { 0x30, 0xf6, 0xfc }; 2270 u8 bcm5357_bcm43236_ndiv[] = { 0x30, 0xf6, 0xfc };
2265 2271
2266 switch (CHIPID(sih->chip)) { 2272 switch (sih->chip) {
2267 case BCM5357_CHIP_ID: 2273 case BCM5357_CHIP_ID:
2268 case BCM43235_CHIP_ID: 2274 case BCM43235_CHIP_ID:
2269 case BCM43236_CHIP_ID: 2275 case BCM43236_CHIP_ID:
2270 case BCM43238_CHIP_ID: 2276 case BCM43238_CHIP_ID:
2271 2277
2272 /* BCM5357 needs to touch PLL1_PLLCTL[02], so offset PLL0_PLLCTL[02] by 6 */ 2278 /* BCM5357 needs to touch PLL1_PLLCTL[02], so offset PLL0_PLLCTL[02] by 6 */
2273 phypll_offset = (CHIPID(sih->chip) == BCM5357_CHIP_ID) ? 6 : 0; 2279 phypll_offset = (sih->chip == BCM5357_CHIP_ID) ? 6 : 0;
2274 2280
2275 /* RMW only the P1 divider */ 2281 /* RMW only the P1 divider */
2276 W_REG(osh, &cc->pllcontrol_addr, 2282 W_REG(osh, &cc->pllcontrol_addr,
@@ -2451,7 +2457,7 @@ si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc, osl_t *osh,
2451 W_REG(osh, &cc->pmucontrol, tmp); 2457 W_REG(osh, &cc->pmucontrol, tmp);
2452} 2458}
2453 2459
2454bool si_pmu_is_otp_powered(si_t *sih, osl_t *osh) 2460bool si_pmu_is_otp_powered(si_t *sih, struct osl_info *osh)
2455{ 2461{
2456 uint idx; 2462 uint idx;
2457 chipcregs_t *cc; 2463 chipcregs_t *cc;
@@ -2462,7 +2468,7 @@ bool si_pmu_is_otp_powered(si_t *sih, osl_t *osh)
2462 cc = si_setcoreidx(sih, SI_CC_IDX); 2468 cc = si_setcoreidx(sih, SI_CC_IDX);
2463 ASSERT(cc != NULL); 2469 ASSERT(cc != NULL);
2464 2470
2465 switch (CHIPID(sih->chip)) { 2471 switch (sih->chip) {
2466 case BCM4329_CHIP_ID: 2472 case BCM4329_CHIP_ID:
2467 st = (R_REG(osh, &cc->res_state) & PMURES_BIT(RES4329_OTP_PU)) 2473 st = (R_REG(osh, &cc->res_state) & PMURES_BIT(RES4329_OTP_PU))
2468 != 0; 2474 != 0;
@@ -2503,9 +2509,9 @@ bool si_pmu_is_otp_powered(si_t *sih, osl_t *osh)
2503 2509
2504void 2510void
2505#if defined(BCMDBG) 2511#if defined(BCMDBG)
2506si_pmu_sprom_enable(si_t *sih, osl_t *osh, bool enable) 2512si_pmu_sprom_enable(si_t *sih, struct osl_info *osh, bool enable)
2507#else 2513#else
2508si_pmu_sprom_enable(si_t *sih, osl_t *osh, bool enable) 2514si_pmu_sprom_enable(si_t *sih, struct osl_info *osh, bool enable)
2509#endif 2515#endif
2510{ 2516{
2511 chipcregs_t *cc; 2517 chipcregs_t *cc;
@@ -2521,7 +2527,7 @@ si_pmu_sprom_enable(si_t *sih, osl_t *osh, bool enable)
2521} 2527}
2522 2528
2523/* initialize PMU chip controls and other chip level stuff */ 2529/* initialize PMU chip controls and other chip level stuff */
2524void si_pmu_chip_init(si_t *sih, osl_t *osh) 2530void si_pmu_chip_init(si_t *sih, struct osl_info *osh)
2525{ 2531{
2526 uint origidx; 2532 uint origidx;
2527 2533
@@ -2543,11 +2549,11 @@ void si_pmu_chip_init(si_t *sih, osl_t *osh)
2543} 2549}
2544 2550
2545/* initialize PMU switch/regulators */ 2551/* initialize PMU switch/regulators */
2546void si_pmu_swreg_init(si_t *sih, osl_t *osh) 2552void si_pmu_swreg_init(si_t *sih, struct osl_info *osh)
2547{ 2553{
2548 ASSERT(sih->cccaps & CC_CAP_PMU); 2554 ASSERT(sih->cccaps & CC_CAP_PMU);
2549 2555
2550 switch (CHIPID(sih->chip)) { 2556 switch (sih->chip) {
2551 case BCM4336_CHIP_ID: 2557 case BCM4336_CHIP_ID:
2552 /* Reduce CLDO PWM output voltage to 1.2V */ 2558 /* Reduce CLDO PWM output voltage to 1.2V */
2553 si_pmu_set_ldo_voltage(sih, osh, SET_LDO_VOLTAGE_CLDO_PWM, 0xe); 2559 si_pmu_set_ldo_voltage(sih, osh, SET_LDO_VOLTAGE_CLDO_PWM, 0xe);
@@ -2556,7 +2562,7 @@ void si_pmu_swreg_init(si_t *sih, osl_t *osh)
2556 0xe); 2562 0xe);
2557 /* Reduce LNLDO1 output voltage to 1.2V */ 2563 /* Reduce LNLDO1 output voltage to 1.2V */
2558 si_pmu_set_ldo_voltage(sih, osh, SET_LDO_VOLTAGE_LNLDO1, 0xe); 2564 si_pmu_set_ldo_voltage(sih, osh, SET_LDO_VOLTAGE_LNLDO1, 0xe);
2559 if (CHIPREV(sih->chiprev) == 0) 2565 if (sih->chiprev == 0)
2560 si_pmu_regcontrol(sih, 2, 0x400000, 0x400000); 2566 si_pmu_regcontrol(sih, 2, 0x400000, 0x400000);
2561 break; 2567 break;
2562 2568
@@ -2573,7 +2579,7 @@ void si_pmu_radio_enable(si_t *sih, bool enable)
2573{ 2579{
2574 ASSERT(sih->cccaps & CC_CAP_PMU); 2580 ASSERT(sih->cccaps & CC_CAP_PMU);
2575 2581
2576 switch (CHIPID(sih->chip)) { 2582 switch (sih->chip) {
2577 case BCM4319_CHIP_ID: 2583 case BCM4319_CHIP_ID:
2578 if (enable) 2584 if (enable)
2579 si_write_wrapperreg(sih, AI_OOBSELOUTB74, 2585 si_write_wrapperreg(sih, AI_OOBSELOUTB74,
@@ -2587,7 +2593,7 @@ void si_pmu_radio_enable(si_t *sih, bool enable)
2587 2593
2588/* Wait for a particular clock level to be on the backplane */ 2594/* Wait for a particular clock level to be on the backplane */
2589u32 2595u32
2590si_pmu_waitforclk_on_backplane(si_t *sih, osl_t *osh, u32 clk, 2596si_pmu_waitforclk_on_backplane(si_t *sih, struct osl_info *osh, u32 clk,
2591 u32 delay) 2597 u32 delay)
2592{ 2598{
2593 chipcregs_t *cc; 2599 chipcregs_t *cc;
@@ -2616,7 +2622,7 @@ si_pmu_waitforclk_on_backplane(si_t *sih, osl_t *osh, u32 clk,
2616 2622
2617#define EXT_ILP_HZ 32768 2623#define EXT_ILP_HZ 32768
2618 2624
2619u32 si_pmu_measure_alpclk(si_t *sih, osl_t *osh) 2625u32 si_pmu_measure_alpclk(si_t *sih, struct osl_info *osh)
2620{ 2626{
2621 chipcregs_t *cc; 2627 chipcregs_t *cc;
2622 uint origidx; 2628 uint origidx;
diff --git a/drivers/staging/brcm80211/util/linux_osl.c b/drivers/staging/brcm80211/util/linux_osl.c
index 2bb5b8722df6..e6716e823baa 100644
--- a/drivers/staging/brcm80211/util/linux_osl.c
+++ b/drivers/staging/brcm80211/util/linux_osl.c
@@ -20,145 +20,57 @@
20#include <asm/paccess.h> 20#include <asm/paccess.h>
21#endif /* mips */ 21#endif /* mips */
22#include <bcmendian.h> 22#include <bcmendian.h>
23#include <linuxver.h> 23#include <linux/module.h>
24#include <linux/pci.h>
25#include <linux/netdevice.h>
26#include <linux/sched.h>
24#include <bcmdefs.h> 27#include <bcmdefs.h>
25#include <osl.h> 28#include <osl.h>
26#include <bcmutils.h> 29#include <bcmutils.h>
27#include <pcicfg.h> 30#include <pcicfg.h>
28 31
29 32
30#define PCI_CFG_RETRY 10
31
32#define OS_HANDLE_MAGIC 0x1234abcd /* Magic # to recognise osh */ 33#define OS_HANDLE_MAGIC 0x1234abcd /* Magic # to recognise osh */
33#define BCM_MEM_FILENAME_LEN 24 /* Mem. filename length */ 34#define BCM_MEM_FILENAME_LEN 24 /* Mem. filename length */
34 35
35struct osl_info {
36 osl_pubinfo_t pub;
37 uint magic;
38 void *pdev;
39 uint failed;
40 uint bustype;
41};
42
43/* Global ASSERT type flag */ 36/* Global ASSERT type flag */
44u32 g_assert_type; 37u32 g_assert_type;
45 38
46#ifdef BRCM_FULLMAC 39struct osl_info *osl_attach(void *pdev, uint bustype)
47static s16 linuxbcmerrormap[] = { 0, /* 0 */
48 -EINVAL, /* BCME_ERROR */
49 -EINVAL, /* BCME_BADARG */
50 -EINVAL, /* BCME_BADOPTION */
51 -EINVAL, /* BCME_NOTUP */
52 -EINVAL, /* BCME_NOTDOWN */
53 -EINVAL, /* BCME_NOTAP */
54 -EINVAL, /* BCME_NOTSTA */
55 -EINVAL, /* BCME_BADKEYIDX */
56 -EINVAL, /* BCME_RADIOOFF */
57 -EINVAL, /* BCME_NOTBANDLOCKED */
58 -EINVAL, /* BCME_NOCLK */
59 -EINVAL, /* BCME_BADRATESET */
60 -EINVAL, /* BCME_BADBAND */
61 -E2BIG, /* BCME_BUFTOOSHORT */
62 -E2BIG, /* BCME_BUFTOOLONG */
63 -EBUSY, /* BCME_BUSY */
64 -EINVAL, /* BCME_NOTASSOCIATED */
65 -EINVAL, /* BCME_BADSSIDLEN */
66 -EINVAL, /* BCME_OUTOFRANGECHAN */
67 -EINVAL, /* BCME_BADCHAN */
68 -EFAULT, /* BCME_BADADDR */
69 -ENOMEM, /* BCME_NORESOURCE */
70 -EOPNOTSUPP, /* BCME_UNSUPPORTED */
71 -EMSGSIZE, /* BCME_BADLENGTH */
72 -EINVAL, /* BCME_NOTREADY */
73 -EPERM, /* BCME_NOTPERMITTED */
74 -ENOMEM, /* BCME_NOMEM */
75 -EINVAL, /* BCME_ASSOCIATED */
76 -ERANGE, /* BCME_RANGE */
77 -EINVAL, /* BCME_NOTFOUND */
78 -EINVAL, /* BCME_WME_NOT_ENABLED */
79 -EINVAL, /* BCME_TSPEC_NOTFOUND */
80 -EINVAL, /* BCME_ACM_NOTSUPPORTED */
81 -EINVAL, /* BCME_NOT_WME_ASSOCIATION */
82 -EIO, /* BCME_SDIO_ERROR */
83 -ENODEV, /* BCME_DONGLE_DOWN */
84 -EINVAL, /* BCME_VERSION */
85 -EIO, /* BCME_TXFAIL */
86 -EIO, /* BCME_RXFAIL */
87 -EINVAL, /* BCME_NODEVICE */
88 -EINVAL, /* BCME_NMODE_DISABLED */
89 -ENODATA, /* BCME_NONRESIDENT */
90
91/* When an new error code is added to bcmutils.h, add os
92 * spcecific error translation here as well
93 */
94/* check if BCME_LAST changed since the last time this function was updated */
95#if BCME_LAST != -42
96#error "You need to add a OS error translation in the linuxbcmerrormap \
97 for new error code defined in bcmutils.h"
98#endif
99};
100
101/* translate bcmerrors into linux errors */
102int osl_error(int bcmerror)
103{
104 if (bcmerror > 0)
105 bcmerror = 0;
106 else if (bcmerror < BCME_LAST)
107 bcmerror = BCME_ERROR;
108
109 /* Array bounds covered by ASSERT in osl_attach */
110 return linuxbcmerrormap[-bcmerror];
111}
112#endif /* BRCM_FULLMAC */
113
114osl_t *osl_attach(void *pdev, uint bustype, bool pkttag)
115{ 40{
116 osl_t *osh; 41 struct osl_info *osh;
117 42
118 osh = kmalloc(sizeof(osl_t), GFP_ATOMIC); 43 osh = kmalloc(sizeof(struct osl_info), GFP_ATOMIC);
119 ASSERT(osh); 44 ASSERT(osh);
120 45
121 bzero(osh, sizeof(osl_t)); 46 memset(osh, 0, sizeof(struct osl_info));
122
123#ifdef BRCM_FULLMAC
124 /* Check that error map has the right number of entries in it */
125 ASSERT(ABS(BCME_LAST) == (ARRAY_SIZE(linuxbcmerrormap) - 1));
126#endif /* BRCM_FULLMAC */
127 47
128 osh->magic = OS_HANDLE_MAGIC; 48 osh->magic = OS_HANDLE_MAGIC;
129 osh->failed = 0;
130 osh->pdev = pdev; 49 osh->pdev = pdev;
131 osh->pub.pkttag = pkttag;
132 osh->bustype = bustype; 50 osh->bustype = bustype;
133 51
134 switch (bustype) { 52 switch (bustype) {
135 case PCI_BUS: 53 case PCI_BUS:
136 case SI_BUS: 54 case SI_BUS:
137 case PCMCIA_BUS: 55 case PCMCIA_BUS:
138 osh->pub.mmbus = true; 56 osh->mmbus = true;
139 break; 57 break;
140 case JTAG_BUS: 58 case JTAG_BUS:
141 case SDIO_BUS: 59 case SDIO_BUS:
142 case USB_BUS: 60 case USB_BUS:
143 case SPI_BUS: 61 case SPI_BUS:
144 case RPC_BUS: 62 case RPC_BUS:
145 osh->pub.mmbus = false; 63 osh->mmbus = false;
146 break; 64 break;
147 default: 65 default:
148 ASSERT(false); 66 ASSERT(false);
149 break; 67 break;
150 } 68 }
151 69
152#if defined(BCMDBG) && !defined(BRCM_FULLMAC)
153 if (pkttag) {
154 struct sk_buff *skb;
155 ASSERT(OSL_PKTTAG_SZ <= sizeof(skb->cb));
156 }
157#endif
158 return osh; 70 return osh;
159} 71}
160 72
161void osl_detach(osl_t *osh) 73void osl_detach(struct osl_info *osh)
162{ 74{
163 if (osh == NULL) 75 if (osh == NULL)
164 return; 76 return;
@@ -167,8 +79,7 @@ void osl_detach(osl_t *osh)
167 kfree(osh); 79 kfree(osh);
168} 80}
169 81
170/* Return a new packet. zero out pkttag */ 82struct sk_buff *BCMFASTPATH pkt_buf_get_skb(struct osl_info *osh, uint len)
171void *BCMFASTPATH osl_pktget(osl_t *osh, uint len)
172{ 83{
173 struct sk_buff *skb; 84 struct sk_buff *skb;
174 85
@@ -177,24 +88,20 @@ void *BCMFASTPATH osl_pktget(osl_t *osh, uint len)
177 skb_put(skb, len); 88 skb_put(skb, len);
178 skb->priority = 0; 89 skb->priority = 0;
179 90
180 osh->pub.pktalloced++; 91 osh->pktalloced++;
181 } 92 }
182 93
183 return (void *)skb; 94 return skb;
184} 95}
185 96
186/* Free the driver packet. Free the tag if present */ 97/* Free the driver packet. Free the tag if present */
187void BCMFASTPATH osl_pktfree(osl_t *osh, void *p, bool send) 98void BCMFASTPATH pkt_buf_free_skb(struct osl_info *osh, struct sk_buff *skb, bool send)
188{ 99{
189 struct sk_buff *skb, *nskb; 100 struct sk_buff *nskb;
190 int nest = 0; 101 int nest = 0;
191 102
192 skb = (struct sk_buff *)p;
193 ASSERT(skb); 103 ASSERT(skb);
194 104
195 if (send && osh->pub.tx_fn)
196 osh->pub.tx_fn(osh->pub.tx_ctx, p, 0);
197
198 /* perversion: we use skb->next to chain multi-skb packets */ 105 /* perversion: we use skb->next to chain multi-skb packets */
199 while (skb) { 106 while (skb) {
200 nskb = skb->next; 107 nskb = skb->next;
@@ -211,63 +118,14 @@ void BCMFASTPATH osl_pktfree(osl_t *osh, void *p, bool send)
211 */ 118 */
212 dev_kfree_skb(skb); 119 dev_kfree_skb(skb);
213 120
214 osh->pub.pktalloced--; 121 osh->pktalloced--;
215 nest++; 122 nest++;
216 skb = nskb; 123 skb = nskb;
217 } 124 }
218} 125}
219 126
220u32 osl_pci_read_config(osl_t *osh, uint offset, uint size)
221{
222 uint val = 0;
223 uint retry = PCI_CFG_RETRY;
224
225 ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
226
227 /* only 4byte access supported */
228 ASSERT(size == 4);
229
230 do {
231 pci_read_config_dword(osh->pdev, offset, &val);
232 if (val != 0xffffffff)
233 break;
234 } while (retry--);
235
236#ifdef BCMDBG
237 if (retry < PCI_CFG_RETRY)
238 printk("PCI CONFIG READ access to %d required %d retries\n",
239 offset, (PCI_CFG_RETRY - retry));
240#endif /* BCMDBG */
241
242 return val;
243}
244
245void osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val)
246{
247 uint retry = PCI_CFG_RETRY;
248
249 ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
250
251 /* only 4byte access supported */
252 ASSERT(size == 4);
253
254 do {
255 pci_write_config_dword(osh->pdev, offset, val);
256 if (offset != PCI_BAR0_WIN)
257 break;
258 if (osl_pci_read_config(osh, offset, size) == val)
259 break;
260 } while (retry--);
261
262#if defined(BCMDBG) && !defined(BRCM_FULLMAC)
263 if (retry < PCI_CFG_RETRY)
264 printk("PCI CONFIG WRITE access to %d required %d retries\n",
265 offset, (PCI_CFG_RETRY - retry));
266#endif /* BCMDBG */
267}
268
269/* return bus # for the pci device pointed by osh->pdev */ 127/* return bus # for the pci device pointed by osh->pdev */
270uint osl_pci_bus(osl_t *osh) 128uint osl_pci_bus(struct osl_info *osh)
271{ 129{
272 ASSERT(osh && (osh->magic == OS_HANDLE_MAGIC) && osh->pdev); 130 ASSERT(osh && (osh->magic == OS_HANDLE_MAGIC) && osh->pdev);
273 131
@@ -275,40 +133,37 @@ uint osl_pci_bus(osl_t *osh)
275} 133}
276 134
277/* return slot # for the pci device pointed by osh->pdev */ 135/* return slot # for the pci device pointed by osh->pdev */
278uint osl_pci_slot(osl_t *osh) 136uint osl_pci_slot(struct osl_info *osh)
279{ 137{
280 ASSERT(osh && (osh->magic == OS_HANDLE_MAGIC) && osh->pdev); 138 ASSERT(osh && (osh->magic == OS_HANDLE_MAGIC) && osh->pdev);
281 139
282 return PCI_SLOT(((struct pci_dev *)osh->pdev)->devfn); 140 return PCI_SLOT(((struct pci_dev *)osh->pdev)->devfn);
283} 141}
284 142
285uint osl_dma_consistent_align(void) 143void *osl_dma_alloc_consistent(struct osl_info *osh, uint size, u16 align_bits,
286{
287 return PAGE_SIZE;
288}
289
290void *osl_dma_alloc_consistent(osl_t *osh, uint size, u16 align_bits,
291 uint *alloced, unsigned long *pap) 144 uint *alloced, unsigned long *pap)
292{ 145{
293 ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC))); 146 ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
294 147
295 if (align_bits) { 148 if (align_bits) {
296 u16 align = (1 << align_bits); 149 u16 align = (1 << align_bits);
297 if (!IS_ALIGNED(DMA_CONSISTENT_ALIGN, align)) 150 if (!IS_ALIGNED(PAGE_SIZE, align))
298 size += align; 151 size += align;
299 *alloced = size; 152 *alloced = size;
300 } 153 }
301 return pci_alloc_consistent(osh->pdev, size, (dma_addr_t *) pap); 154 return pci_alloc_consistent(osh->pdev, size, (dma_addr_t *) pap);
302} 155}
303 156
304void osl_dma_free_consistent(osl_t *osh, void *va, uint size, unsigned long pa) 157void osl_dma_free_consistent(struct osl_info *osh, void *va, uint size,
158 unsigned long pa)
305{ 159{
306 ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC))); 160 ASSERT((osh && (osh->magic == OS_HANDLE_MAGIC)));
307 161
308 pci_free_consistent(osh->pdev, size, va, (dma_addr_t) pa); 162 pci_free_consistent(osh->pdev, size, va, (dma_addr_t) pa);
309} 163}
310 164
311uint BCMFASTPATH osl_dma_map(osl_t *osh, void *va, uint size, int direction) 165uint BCMFASTPATH osl_dma_map(struct osl_info *osh, void *va, uint size,
166 int direction)
312{ 167{
313 int dir; 168 int dir;
314 169
@@ -317,7 +172,8 @@ uint BCMFASTPATH osl_dma_map(osl_t *osh, void *va, uint size, int direction)
317 return pci_map_single(osh->pdev, va, size, dir); 172 return pci_map_single(osh->pdev, va, size, dir);
318} 173}
319 174
320void BCMFASTPATH osl_dma_unmap(osl_t *osh, uint pa, uint size, int direction) 175void BCMFASTPATH osl_dma_unmap(struct osl_info *osh, uint pa, uint size,
176 int direction)
321{ 177{
322 int dir; 178 int dir;
323 179
@@ -373,52 +229,3 @@ void osl_assert(char *exp, char *file, int line)
373} 229}
374#endif /* defined(BCMDBG_ASSERT) */ 230#endif /* defined(BCMDBG_ASSERT) */
375 231
376#if defined(BCMSDIO) && !defined(BRCM_FULLMAC)
377u8 osl_readb(osl_t *osh, volatile u8 *r)
378{
379 osl_rreg_fn_t rreg = ((osl_pubinfo_t *) osh)->rreg_fn;
380 void *ctx = ((osl_pubinfo_t *) osh)->reg_ctx;
381
382 return (u8) ((rreg) (ctx, (void *)r, sizeof(u8)));
383}
384
385u16 osl_readw(osl_t *osh, volatile u16 *r)
386{
387 osl_rreg_fn_t rreg = ((osl_pubinfo_t *) osh)->rreg_fn;
388 void *ctx = ((osl_pubinfo_t *) osh)->reg_ctx;
389
390 return (u16) ((rreg) (ctx, (void *)r, sizeof(u16)));
391}
392
393u32 osl_readl(osl_t *osh, volatile u32 *r)
394{
395 osl_rreg_fn_t rreg = ((osl_pubinfo_t *) osh)->rreg_fn;
396 void *ctx = ((osl_pubinfo_t *) osh)->reg_ctx;
397
398 return (u32) ((rreg) (ctx, (void *)r, sizeof(u32)));
399}
400
401void osl_writeb(osl_t *osh, volatile u8 *r, u8 v)
402{
403 osl_wreg_fn_t wreg = ((osl_pubinfo_t *) osh)->wreg_fn;
404 void *ctx = ((osl_pubinfo_t *) osh)->reg_ctx;
405
406 ((wreg) (ctx, (void *)r, v, sizeof(u8)));
407}
408
409void osl_writew(osl_t *osh, volatile u16 *r, u16 v)
410{
411 osl_wreg_fn_t wreg = ((osl_pubinfo_t *) osh)->wreg_fn;
412 void *ctx = ((osl_pubinfo_t *) osh)->reg_ctx;
413
414 ((wreg) (ctx, (void *)r, v, sizeof(u16)));
415}
416
417void osl_writel(osl_t *osh, volatile u32 *r, u32 v)
418{
419 osl_wreg_fn_t wreg = ((osl_pubinfo_t *) osh)->wreg_fn;
420 void *ctx = ((osl_pubinfo_t *) osh)->reg_ctx;
421
422 ((wreg) (ctx, (void *)r, v, sizeof(u32)));
423}
424#endif /* BCMSDIO */
diff --git a/drivers/staging/brcm80211/util/nicpci.c b/drivers/staging/brcm80211/util/nicpci.c
index 23f86dd7b159..56e658c429a8 100644
--- a/drivers/staging/brcm80211/util/nicpci.c
+++ b/drivers/staging/brcm80211/util/nicpci.c
@@ -14,8 +14,9 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/delay.h>
17#include <linux/string.h> 18#include <linux/string.h>
18#include <linuxver.h> 19#include <linux/pci.h>
19#include <bcmdefs.h> 20#include <bcmdefs.h>
20#include <osl.h> 21#include <osl.h>
21#include <bcmutils.h> 22#include <bcmutils.h>
@@ -35,7 +36,7 @@ typedef struct {
35 } regs; /* Memory mapped register to the core */ 36 } regs; /* Memory mapped register to the core */
36 37
37 si_t *sih; /* System interconnect handle */ 38 si_t *sih; /* System interconnect handle */
38 osl_t *osh; /* OSL handle */ 39 struct osl_info *osh; /* OSL handle */
39 u8 pciecap_lcreg_offset; /* PCIE capability LCreg offset in the config space */ 40 u8 pciecap_lcreg_offset; /* PCIE capability LCreg offset in the config space */
40 bool pcie_pr42767; 41 bool pcie_pr42767;
41 u8 pcie_polarity; 42 u8 pcie_polarity;
@@ -47,7 +48,8 @@ typedef struct {
47 48
48/* debug/trace */ 49/* debug/trace */
49#define PCI_ERROR(args) 50#define PCI_ERROR(args)
50#define PCIE_PUB(sih) ((BUSTYPE((sih)->bustype) == PCI_BUS) && ((sih)->buscoretype == PCIE_CORE_ID)) 51#define PCIE_PUB(sih) \
52 (((sih)->bustype == PCI_BUS) && ((sih)->buscoretype == PCIE_CORE_ID))
51 53
52/* routines to access mdio slave device registers */ 54/* routines to access mdio slave device registers */
53static bool pcie_mdiosetblock(pcicore_info_t *pi, uint blk); 55static bool pcie_mdiosetblock(pcicore_info_t *pi, uint blk);
@@ -71,35 +73,6 @@ static bool pcicore_pmecap(pcicore_info_t *pi);
71 73
72#define PCIE_ASPM(sih) ((PCIE_PUB(sih)) && (((sih)->buscorerev >= 3) && ((sih)->buscorerev <= 5))) 74#define PCIE_ASPM(sih) ((PCIE_PUB(sih)) && (((sih)->buscorerev >= 3) && ((sih)->buscorerev <= 5)))
73 75
74#define DWORD_ALIGN(x) (x & ~(0x03))
75#define BYTE_POS(x) (x & 0x3)
76#define WORD_POS(x) (x & 0x1)
77
78#define BYTE_SHIFT(x) (8 * BYTE_POS(x))
79#define WORD_SHIFT(x) (16 * WORD_POS(x))
80
81#define BYTE_VAL(a, x) ((a >> BYTE_SHIFT(x)) & 0xFF)
82#define WORD_VAL(a, x) ((a >> WORD_SHIFT(x)) & 0xFFFF)
83
84#define read_pci_cfg_byte(a) \
85 (BYTE_VAL(OSL_PCI_READ_CONFIG(osh, DWORD_ALIGN(a), 4), a) & 0xff)
86
87#define read_pci_cfg_word(a) \
88 (WORD_VAL(OSL_PCI_READ_CONFIG(osh, DWORD_ALIGN(a), 4), a) & 0xffff)
89
90#define write_pci_cfg_byte(a, val) do { \
91 u32 tmpval; \
92 tmpval = (OSL_PCI_READ_CONFIG(osh, DWORD_ALIGN(a), 4) & ~0xFF << BYTE_POS(a)) | \
93 val << BYTE_POS(a); \
94 OSL_PCI_WRITE_CONFIG(osh, DWORD_ALIGN(a), 4, tmpval); \
95 } while (0)
96
97#define write_pci_cfg_word(a, val) do { \
98 u32 tmpval; \
99 tmpval = (OSL_PCI_READ_CONFIG(osh, DWORD_ALIGN(a), 4) & ~0xFFFF << WORD_POS(a)) | \
100 val << WORD_POS(a); \
101 OSL_PCI_WRITE_CONFIG(osh, DWORD_ALIGN(a), 4, tmpval); \
102 } while (0)
103 76
104/* delay needed between the mdio control/ mdiodata register data access */ 77/* delay needed between the mdio control/ mdiodata register data access */
105#define PR28829_DELAY() udelay(10) 78#define PR28829_DELAY() udelay(10)
@@ -107,7 +80,7 @@ static bool pcicore_pmecap(pcicore_info_t *pi);
107/* Initialize the PCI core. It's caller's responsibility to make sure that this is done 80/* Initialize the PCI core. It's caller's responsibility to make sure that this is done
108 * only once 81 * only once
109 */ 82 */
110void *pcicore_init(si_t *sih, osl_t *osh, void *regs) 83void *pcicore_init(si_t *sih, struct osl_info *osh, void *regs)
111{ 84{
112 pcicore_info_t *pi; 85 pcicore_info_t *pi;
113 86
@@ -149,8 +122,8 @@ void pcicore_deinit(void *pch)
149/* return cap_offset if requested capability exists in the PCI config space */ 122/* return cap_offset if requested capability exists in the PCI config space */
150/* Note that it's caller's responsibility to make sure it's a pci bus */ 123/* Note that it's caller's responsibility to make sure it's a pci bus */
151u8 124u8
152pcicore_find_pci_capability(osl_t *osh, u8 req_cap_id, unsigned char *buf, 125pcicore_find_pci_capability(struct osl_info *osh, u8 req_cap_id,
153 u32 *buflen) 126 unsigned char *buf, u32 *buflen)
154{ 127{
155 u8 cap_id; 128 u8 cap_id;
156 u8 cap_ptr = 0; 129 u8 cap_ptr = 0;
@@ -158,29 +131,29 @@ pcicore_find_pci_capability(osl_t *osh, u8 req_cap_id, unsigned char *buf,
158 u8 byte_val; 131 u8 byte_val;
159 132
160 /* check for Header type 0 */ 133 /* check for Header type 0 */
161 byte_val = read_pci_cfg_byte(PCI_CFG_HDR); 134 pci_read_config_byte(osh->pdev, PCI_CFG_HDR, &byte_val);
162 if ((byte_val & 0x7f) != PCI_HEADER_NORMAL) 135 if ((byte_val & 0x7f) != PCI_HEADER_NORMAL)
163 goto end; 136 goto end;
164 137
165 /* check if the capability pointer field exists */ 138 /* check if the capability pointer field exists */
166 byte_val = read_pci_cfg_byte(PCI_CFG_STAT); 139 pci_read_config_byte(osh->pdev, PCI_CFG_STAT, &byte_val);
167 if (!(byte_val & PCI_CAPPTR_PRESENT)) 140 if (!(byte_val & PCI_CAPPTR_PRESENT))
168 goto end; 141 goto end;
169 142
170 cap_ptr = read_pci_cfg_byte(PCI_CFG_CAPPTR); 143 pci_read_config_byte(osh->pdev, PCI_CFG_CAPPTR, &cap_ptr);
171 /* check if the capability pointer is 0x00 */ 144 /* check if the capability pointer is 0x00 */
172 if (cap_ptr == 0x00) 145 if (cap_ptr == 0x00)
173 goto end; 146 goto end;
174 147
175 /* loop thr'u the capability list and see if the pcie capabilty exists */ 148 /* loop thr'u the capability list and see if the pcie capabilty exists */
176 149
177 cap_id = read_pci_cfg_byte(cap_ptr); 150 pci_read_config_byte(osh->pdev, cap_ptr, &cap_id);
178 151
179 while (cap_id != req_cap_id) { 152 while (cap_id != req_cap_id) {
180 cap_ptr = read_pci_cfg_byte((cap_ptr + 1)); 153 pci_read_config_byte(osh->pdev, cap_ptr + 1, &cap_ptr);
181 if (cap_ptr == 0x00) 154 if (cap_ptr == 0x00)
182 break; 155 break;
183 cap_id = read_pci_cfg_byte(cap_ptr); 156 pci_read_config_byte(osh->pdev, cap_ptr, &cap_id);
184 } 157 }
185 if (cap_id != req_cap_id) { 158 if (cap_id != req_cap_id) {
186 goto end; 159 goto end;
@@ -199,7 +172,7 @@ pcicore_find_pci_capability(osl_t *osh, u8 req_cap_id, unsigned char *buf,
199 bufsize = SZPCR - cap_data; 172 bufsize = SZPCR - cap_data;
200 *buflen = bufsize; 173 *buflen = bufsize;
201 while (bufsize--) { 174 while (bufsize--) {
202 *buf = read_pci_cfg_byte(cap_data); 175 pci_read_config_byte(osh->pdev, cap_data, buf);
203 cap_data++; 176 cap_data++;
204 buf++; 177 buf++;
205 } 178 }
@@ -210,7 +183,8 @@ pcicore_find_pci_capability(osl_t *osh, u8 req_cap_id, unsigned char *buf,
210 183
211/* ***** Register Access API */ 184/* ***** Register Access API */
212uint 185uint
213pcie_readreg(osl_t *osh, sbpcieregs_t *pcieregs, uint addrtype, uint offset) 186pcie_readreg(struct osl_info *osh, sbpcieregs_t *pcieregs, uint addrtype,
187 uint offset)
214{ 188{
215 uint retval = 0xFFFFFFFF; 189 uint retval = 0xFFFFFFFF;
216 190
@@ -236,8 +210,8 @@ pcie_readreg(osl_t *osh, sbpcieregs_t *pcieregs, uint addrtype, uint offset)
236} 210}
237 211
238uint 212uint
239pcie_writereg(osl_t *osh, sbpcieregs_t *pcieregs, uint addrtype, uint offset, 213pcie_writereg(struct osl_info *osh, sbpcieregs_t *pcieregs, uint addrtype,
240 uint val) 214 uint offset, uint val)
241{ 215{
242 ASSERT(pcieregs != NULL); 216 ASSERT(pcieregs != NULL);
243 217
@@ -373,15 +347,15 @@ u8 pcie_clkreq(void *pch, u32 mask, u32 val)
373 if (!offset) 347 if (!offset)
374 return 0; 348 return 0;
375 349
376 reg_val = OSL_PCI_READ_CONFIG(pi->osh, offset, sizeof(u32)); 350 pci_read_config_dword(pi->osh->pdev, offset, &reg_val);
377 /* set operation */ 351 /* set operation */
378 if (mask) { 352 if (mask) {
379 if (val) 353 if (val)
380 reg_val |= PCIE_CLKREQ_ENAB; 354 reg_val |= PCIE_CLKREQ_ENAB;
381 else 355 else
382 reg_val &= ~PCIE_CLKREQ_ENAB; 356 reg_val &= ~PCIE_CLKREQ_ENAB;
383 OSL_PCI_WRITE_CONFIG(pi->osh, offset, sizeof(u32), reg_val); 357 pci_write_config_dword(pi->osh->pdev, offset, reg_val);
384 reg_val = OSL_PCI_READ_CONFIG(pi->osh, offset, sizeof(u32)); 358 pci_read_config_dword(pi->osh->pdev, offset, &reg_val);
385 } 359 }
386 if (reg_val & PCIE_CLKREQ_ENAB) 360 if (reg_val & PCIE_CLKREQ_ENAB)
387 return 1; 361 return 1;
@@ -393,7 +367,7 @@ static void pcie_extendL1timer(pcicore_info_t *pi, bool extend)
393{ 367{
394 u32 w; 368 u32 w;
395 si_t *sih = pi->sih; 369 si_t *sih = pi->sih;
396 osl_t *osh = pi->osh; 370 struct osl_info *osh = pi->osh;
397 sbpcieregs_t *pcieregs = pi->regs.pcieregs; 371 sbpcieregs_t *pcieregs = pi->regs.pcieregs;
398 372
399 if (!PCIE_PUB(sih) || sih->buscorerev < 7) 373 if (!PCIE_PUB(sih) || sih->buscorerev < 7)
@@ -502,12 +476,12 @@ static void pcie_war_aspm_clkreq(pcicore_info_t *pi)
502 476
503 W_REG(pi->osh, reg16, val16); 477 W_REG(pi->osh, reg16, val16);
504 478
505 w = OSL_PCI_READ_CONFIG(pi->osh, pi->pciecap_lcreg_offset, 479 pci_read_config_dword(pi->osh->pdev, pi->pciecap_lcreg_offset,
506 sizeof(u32)); 480 &w);
507 w &= ~PCIE_ASPM_ENAB; 481 w &= ~PCIE_ASPM_ENAB;
508 w |= pi->pcie_war_aspm_ovr; 482 w |= pi->pcie_war_aspm_ovr;
509 OSL_PCI_WRITE_CONFIG(pi->osh, pi->pciecap_lcreg_offset, 483 pci_write_config_dword(pi->osh->pdev,
510 sizeof(u32), w); 484 pi->pciecap_lcreg_offset, w);
511 } 485 }
512 486
513 reg16 = &pcieregs->sprom[SRSH_CLKREQ_OFFSET_REV5]; 487 reg16 = &pcieregs->sprom[SRSH_CLKREQ_OFFSET_REV5];
@@ -577,7 +551,7 @@ static void pcie_war_noplldown(pcicore_info_t *pi)
577static void pcie_war_pci_setup(pcicore_info_t *pi) 551static void pcie_war_pci_setup(pcicore_info_t *pi)
578{ 552{
579 si_t *sih = pi->sih; 553 si_t *sih = pi->sih;
580 osl_t *osh = pi->osh; 554 struct osl_info *osh = pi->osh;
581 sbpcieregs_t *pcieregs = pi->regs.pcieregs; 555 sbpcieregs_t *pcieregs = pi->regs.pcieregs;
582 u32 w; 556 u32 w;
583 557
@@ -694,11 +668,9 @@ void pcicore_sleep(void *pch)
694 if (!pi || !PCIE_ASPM(pi->sih)) 668 if (!pi || !PCIE_ASPM(pi->sih))
695 return; 669 return;
696 670
697 w = OSL_PCI_READ_CONFIG(pi->osh, pi->pciecap_lcreg_offset, 671 pci_read_config_dword(pi->osh->pdev, pi->pciecap_lcreg_offset, &w);
698 sizeof(u32));
699 w &= ~PCIE_CAP_LCREG_ASPML1; 672 w &= ~PCIE_CAP_LCREG_ASPML1;
700 OSL_PCI_WRITE_CONFIG(pi->osh, pi->pciecap_lcreg_offset, sizeof(u32), 673 pci_write_config_dword(pi->osh->pdev, pi->pciecap_lcreg_offset, w);
701 w);
702 674
703 pi->pcie_pr42767 = false; 675 pi->pcie_pr42767 = false;
704} 676}
@@ -718,7 +690,7 @@ void pcicore_down(void *pch, int state)
718 690
719/* ***** Wake-on-wireless-LAN (WOWL) support functions ***** */ 691/* ***** Wake-on-wireless-LAN (WOWL) support functions ***** */
720/* Just uses PCI config accesses to find out, when needed before sb_attach is done */ 692/* Just uses PCI config accesses to find out, when needed before sb_attach is done */
721bool pcicore_pmecap_fast(osl_t *osh) 693bool pcicore_pmecap_fast(struct osl_info *osh)
722{ 694{
723 u8 cap_ptr; 695 u8 cap_ptr;
724 u32 pmecap; 696 u32 pmecap;
@@ -730,7 +702,7 @@ bool pcicore_pmecap_fast(osl_t *osh)
730 if (!cap_ptr) 702 if (!cap_ptr)
731 return false; 703 return false;
732 704
733 pmecap = OSL_PCI_READ_CONFIG(osh, cap_ptr, sizeof(u32)); 705 pci_read_config_dword(osh->pdev, cap_ptr, &pmecap);
734 706
735 return (pmecap & PME_CAP_PM_STATES) != 0; 707 return (pmecap & PME_CAP_PM_STATES) != 0;
736} 708}
@@ -753,9 +725,8 @@ static bool pcicore_pmecap(pcicore_info_t *pi)
753 725
754 pi->pmecap_offset = cap_ptr; 726 pi->pmecap_offset = cap_ptr;
755 727
756 pmecap = 728 pci_read_config_dword(pi->osh->pdev, pi->pmecap_offset,
757 OSL_PCI_READ_CONFIG(pi->osh, pi->pmecap_offset, 729 &pmecap);
758 sizeof(u32));
759 730
760 /* At least one state can generate PME */ 731 /* At least one state can generate PME */
761 pi->pmecap = (pmecap & PME_CAP_PM_STATES) != 0; 732 pi->pmecap = (pmecap & PME_CAP_PM_STATES) != 0;
@@ -774,11 +745,11 @@ void pcicore_pmeen(void *pch)
774 if (!pcicore_pmecap(pi)) 745 if (!pcicore_pmecap(pi))
775 return; 746 return;
776 747
777 w = OSL_PCI_READ_CONFIG(pi->osh, pi->pmecap_offset + PME_CSR_OFFSET, 748 pci_read_config_dword(pi->osh->pdev, pi->pmecap_offset + PME_CSR_OFFSET,
778 sizeof(u32)); 749 &w);
779 w |= (PME_CSR_PME_EN); 750 w |= (PME_CSR_PME_EN);
780 OSL_PCI_WRITE_CONFIG(pi->osh, pi->pmecap_offset + PME_CSR_OFFSET, 751 pci_write_config_dword(pi->osh->pdev,
781 sizeof(u32), w); 752 pi->pmecap_offset + PME_CSR_OFFSET, w);
782} 753}
783 754
784/* 755/*
@@ -792,8 +763,8 @@ bool pcicore_pmestat(void *pch)
792 if (!pcicore_pmecap(pi)) 763 if (!pcicore_pmecap(pi))
793 return false; 764 return false;
794 765
795 w = OSL_PCI_READ_CONFIG(pi->osh, pi->pmecap_offset + PME_CSR_OFFSET, 766 pci_read_config_dword(pi->osh->pdev, pi->pmecap_offset + PME_CSR_OFFSET,
796 sizeof(u32)); 767 &w);
797 768
798 return (w & PME_CSR_PME_STAT) == PME_CSR_PME_STAT; 769 return (w & PME_CSR_PME_STAT) == PME_CSR_PME_STAT;
799} 770}
@@ -808,22 +779,23 @@ void pcicore_pmeclr(void *pch)
808 if (!pcicore_pmecap(pi)) 779 if (!pcicore_pmecap(pi))
809 return; 780 return;
810 781
811 w = OSL_PCI_READ_CONFIG(pi->osh, pi->pmecap_offset + PME_CSR_OFFSET, 782 pci_read_config_dword(pi->osh->pdev, pi->pmecap_offset + PME_CSR_OFFSET,
812 sizeof(u32)); 783 &w);
813 784
814 PCI_ERROR(("pcicore_pci_pmeclr PMECSR : 0x%x\n", w)); 785 PCI_ERROR(("pcicore_pci_pmeclr PMECSR : 0x%x\n", w));
815 786
816 /* PMESTAT is cleared by writing 1 to it */ 787 /* PMESTAT is cleared by writing 1 to it */
817 w &= ~(PME_CSR_PME_EN); 788 w &= ~(PME_CSR_PME_EN);
818 789
819 OSL_PCI_WRITE_CONFIG(pi->osh, pi->pmecap_offset + PME_CSR_OFFSET, 790 pci_write_config_dword(pi->osh->pdev,
820 sizeof(u32), w); 791 pi->pmecap_offset + PME_CSR_OFFSET, w);
821} 792}
822 793
823u32 pcie_lcreg(void *pch, u32 mask, u32 val) 794u32 pcie_lcreg(void *pch, u32 mask, u32 val)
824{ 795{
825 pcicore_info_t *pi = (pcicore_info_t *) pch; 796 pcicore_info_t *pi = (pcicore_info_t *) pch;
826 u8 offset; 797 u8 offset;
798 u32 tmpval;
827 799
828 offset = pi->pciecap_lcreg_offset; 800 offset = pi->pciecap_lcreg_offset;
829 if (!offset) 801 if (!offset)
@@ -831,9 +803,10 @@ u32 pcie_lcreg(void *pch, u32 mask, u32 val)
831 803
832 /* set operation */ 804 /* set operation */
833 if (mask) 805 if (mask)
834 OSL_PCI_WRITE_CONFIG(pi->osh, offset, sizeof(u32), val); 806 pci_write_config_dword(pi->osh->pdev, offset, val);
835 807
836 return OSL_PCI_READ_CONFIG(pi->osh, offset, sizeof(u32)); 808 pci_read_config_dword(pi->osh->pdev, offset, &tmpval);
809 return tmpval;
837} 810}
838 811
839u32 812u32
@@ -842,7 +815,7 @@ pcicore_pciereg(void *pch, u32 offset, u32 mask, u32 val, uint type)
842 u32 reg_val = 0; 815 u32 reg_val = 0;
843 pcicore_info_t *pi = (pcicore_info_t *) pch; 816 pcicore_info_t *pi = (pcicore_info_t *) pch;
844 sbpcieregs_t *pcieregs = pi->regs.pcieregs; 817 sbpcieregs_t *pcieregs = pi->regs.pcieregs;
845 osl_t *osh = pi->osh; 818 struct osl_info *osh = pi->osh;
846 819
847 if (mask) { 820 if (mask) {
848 PCI_ERROR(("PCIEREG: 0x%x writeval 0x%x\n", offset, val)); 821 PCI_ERROR(("PCIEREG: 0x%x writeval 0x%x\n", offset, val));
diff --git a/drivers/staging/brcm80211/util/nvram/nvram_ro.c b/drivers/staging/brcm80211/util/nvram/nvram_ro.c
index f80375cd6801..e4d41ee78e2a 100644
--- a/drivers/staging/brcm80211/util/nvram/nvram_ro.c
+++ b/drivers/staging/brcm80211/util/nvram/nvram_ro.c
@@ -49,7 +49,7 @@ static char *findvar(char *vars, char *lim, const char *name);
49/* copy flash to ram */ 49/* copy flash to ram */
50static void get_flash_nvram(si_t *sih, struct nvram_header *nvh) 50static void get_flash_nvram(si_t *sih, struct nvram_header *nvh)
51{ 51{
52 osl_t *osh; 52 struct osl_info *osh;
53 uint nvs, bufsz; 53 uint nvs, bufsz;
54 vars_t *new; 54 vars_t *new;
55 55
@@ -133,7 +133,7 @@ static char *findvar(char *vars, char *lim, const char *name)
133 len = strlen(name); 133 len = strlen(name);
134 134
135 for (s = vars; (s < lim) && *s;) { 135 for (s = vars; (s < lim) && *s;) {
136 if ((bcmp(s, name, len) == 0) && (s[len] == '=')) 136 if ((memcmp(s, name, len) == 0) && (s[len] == '='))
137 return &s[len + 1]; 137 return &s[len + 1];
138 138
139 while (*s++) 139 while (*s++)
diff --git a/drivers/staging/brcm80211/util/sbutils.c b/drivers/staging/brcm80211/util/sbutils.c
index e4c0baba553d..63c3ab1866a4 100644
--- a/drivers/staging/brcm80211/util/sbutils.c
+++ b/drivers/staging/brcm80211/util/sbutils.c
@@ -16,6 +16,9 @@
16 16
17#include <linux/types.h> 17#include <linux/types.h>
18#include <bcmdefs.h> 18#include <bcmdefs.h>
19#ifdef BRCM_FULLMAC
20#include <linux/netdevice.h>
21#endif
19#include <osl.h> 22#include <osl.h>
20#include <bcmutils.h> 23#include <bcmutils.h>
21#include <siutils.h> 24#include <siutils.h>
@@ -87,7 +90,7 @@ static u32 _sb_coresba(si_info_t *sii)
87{ 90{
88 u32 sbaddr = 0; 91 u32 sbaddr = 0;
89 92
90 switch (BUSTYPE(sii->pub.bustype)) { 93 switch (sii->pub.bustype) {
91 case SPI_BUS: 94 case SPI_BUS:
92 case SDIO_BUS: 95 case SDIO_BUS:
93 sbaddr = (u32)(unsigned long)sii->curmap; 96 sbaddr = (u32)(unsigned long)sii->curmap;
@@ -248,7 +251,7 @@ static uint _sb_scan(si_info_t *sii, u32 sba, void *regs, uint bus, u32 sbba,
248 else { 251 else {
249 /* Older chips */ 252 /* Older chips */
250 SI_ERROR(("sb_chip2numcores: unsupported chip " 253 SI_ERROR(("sb_chip2numcores: unsupported chip "
251 "0x%x\n", CHIPID(sii->pub.chip))); 254 "0x%x\n", sii->pub.chip));
252 ASSERT(0); 255 ASSERT(0);
253 numcores = 1; 256 numcores = 1;
254 } 257 }
@@ -344,7 +347,7 @@ static void *_sb_setcoreidx(si_info_t *sii, uint coreidx)
344 u32 sbaddr = sii->coresba[coreidx]; 347 u32 sbaddr = sii->coresba[coreidx];
345 void *regs; 348 void *regs;
346 349
347 switch (BUSTYPE(sii->pub.bustype)) { 350 switch (sii->pub.bustype) {
348#ifdef BCMSDIO 351#ifdef BCMSDIO
349 case SPI_BUS: 352 case SPI_BUS:
350 case SDIO_BUS: 353 case SDIO_BUS:
@@ -409,8 +412,8 @@ bool sb_taclear(si_t *sih, bool details)
409 412
410 sii = SI_INFO(sih); 413 sii = SI_INFO(sih);
411 414
412 if ((BUSTYPE(sii->pub.bustype) == SDIO_BUS) || 415 if ((sii->pub.bustype == SDIO_BUS) ||
413 (BUSTYPE(sii->pub.bustype) == SPI_BUS)) { 416 (sii->pub.bustype == SPI_BUS)) {
414 417
415 INTR_OFF(sii, intr_val); 418 INTR_OFF(sii, intr_val);
416 origidx = si_coreidx(sih); 419 origidx = si_coreidx(sih);
diff --git a/drivers/staging/brcm80211/util/siutils.c b/drivers/staging/brcm80211/util/siutils.c
index f3ea7e1a7aef..b66de9b35a5a 100644
--- a/drivers/staging/brcm80211/util/siutils.c
+++ b/drivers/staging/brcm80211/util/siutils.c
@@ -14,11 +14,16 @@
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/delay.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/string.h> 19#include <linux/string.h>
19#include <bcmdefs.h> 20#include <bcmdefs.h>
21#ifdef BRCM_FULLMAC
22#include <linux/netdevice.h>
23#endif
20#include <osl.h> 24#include <osl.h>
21#include <linuxver.h> 25#include <linux/module.h>
26#include <linux/pci.h>
22#include <bcmutils.h> 27#include <bcmutils.h>
23#include <siutils.h> 28#include <siutils.h>
24#include <bcmdevs.h> 29#include <bcmdevs.h>
@@ -53,7 +58,7 @@
53#endif 58#endif
54 59
55/* local prototypes */ 60/* local prototypes */
56static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh, 61static si_info_t *si_doattach(si_info_t *sii, uint devid, struct osl_info *osh,
57 void *regs, uint bustype, void *sdh, char **vars, 62 void *regs, uint bustype, void *sdh, char **vars,
58 uint *varsz); 63 uint *varsz);
59static bool si_buscore_prep(si_info_t *sii, uint bustype, uint devid, 64static bool si_buscore_prep(si_info_t *sii, uint bustype, uint devid,
@@ -81,8 +86,8 @@ static u32 si_gpioreservation;
81 * vars - pointer to a pointer area for "environment" variables 86 * vars - pointer to a pointer area for "environment" variables
82 * varsz - pointer to int to return the size of the vars 87 * varsz - pointer to int to return the size of the vars
83 */ 88 */
84si_t *si_attach(uint devid, osl_t *osh, void *regs, uint bustype, void *sdh, 89si_t *si_attach(uint devid, struct osl_info *osh, void *regs, uint bustype,
85 char **vars, uint *varsz) 90 void *sdh, char **vars, uint *varsz)
86{ 91{
87 si_info_t *sii; 92 si_info_t *sii;
88 93
@@ -113,12 +118,12 @@ static bool si_buscore_prep(si_info_t *sii, uint bustype, uint devid,
113 118
114#ifndef BRCM_FULLMAC 119#ifndef BRCM_FULLMAC
115 /* kludge to enable the clock on the 4306 which lacks a slowclock */ 120 /* kludge to enable the clock on the 4306 which lacks a slowclock */
116 if (BUSTYPE(bustype) == PCI_BUS && !si_ispcie(sii)) 121 if (bustype == PCI_BUS && !si_ispcie(sii))
117 si_clkctl_xtal(&sii->pub, XTAL | PLL, ON); 122 si_clkctl_xtal(&sii->pub, XTAL | PLL, ON);
118#endif 123#endif
119 124
120#if defined(BCMSDIO) 125#if defined(BCMSDIO)
121 if (BUSTYPE(bustype) == SDIO_BUS) { 126 if (bustype == SDIO_BUS) {
122 int err; 127 int err;
123 u8 clkset; 128 u8 clkset;
124 129
@@ -220,7 +225,7 @@ static bool si_buscore_setup(si_info_t *sii, chipcregs_t *cc, uint bustype,
220 SI_VMSG(("CORE[%d]: id 0x%x rev %d base 0x%x regs 0x%p\n", 225 SI_VMSG(("CORE[%d]: id 0x%x rev %d base 0x%x regs 0x%p\n",
221 i, cid, crev, sii->coresba[i], sii->regs[i])); 226 i, cid, crev, sii->coresba[i], sii->regs[i]));
222 227
223 if (BUSTYPE(bustype) == PCI_BUS) { 228 if (bustype == PCI_BUS) {
224 if (cid == PCI_CORE_ID) { 229 if (cid == PCI_CORE_ID) {
225 pciidx = i; 230 pciidx = i;
226 pcirev = crev; 231 pcirev = crev;
@@ -232,8 +237,8 @@ static bool si_buscore_setup(si_info_t *sii, chipcregs_t *cc, uint bustype,
232 } 237 }
233 } 238 }
234#ifdef BCMSDIO 239#ifdef BCMSDIO
235 else if (((BUSTYPE(bustype) == SDIO_BUS) || 240 else if (((bustype == SDIO_BUS) ||
236 (BUSTYPE(bustype) == SPI_BUS)) && 241 (bustype == SPI_BUS)) &&
237 ((cid == PCMCIA_CORE_ID) || (cid == SDIOD_CORE_ID))) { 242 ((cid == PCMCIA_CORE_ID) || (cid == SDIOD_CORE_ID))) {
238 sii->pub.buscorerev = crev; 243 sii->pub.buscorerev = crev;
239 sii->pub.buscoretype = cid; 244 sii->pub.buscoretype = cid;
@@ -255,7 +260,7 @@ static bool si_buscore_setup(si_info_t *sii, chipcregs_t *cc, uint bustype,
255 * or downloaded code was 260 * or downloaded code was
256 * already running. 261 * already running.
257 */ 262 */
258 if ((BUSTYPE(bustype) == SDIO_BUS) || (BUSTYPE(bustype) == SPI_BUS)) { 263 if ((bustype == SDIO_BUS) || (bustype == SPI_BUS)) {
259 if (si_setcore(&sii->pub, ARM7S_CORE_ID, 0) || 264 if (si_setcore(&sii->pub, ARM7S_CORE_ID, 0) ||
260 si_setcore(&sii->pub, ARMCM3_CORE_ID, 0)) 265 si_setcore(&sii->pub, ARMCM3_CORE_ID, 0))
261 si_core_disable(&sii->pub, 0); 266 si_core_disable(&sii->pub, 0);
@@ -281,7 +286,7 @@ static bool si_buscore_setup(si_info_t *sii, chipcregs_t *cc, uint bustype,
281 sii->pub.buscoretype, sii->pub.buscorerev)); 286 sii->pub.buscoretype, sii->pub.buscorerev));
282 287
283 /* fixup necessary chip/core configurations */ 288 /* fixup necessary chip/core configurations */
284 if (BUSTYPE(sii->pub.bustype) == PCI_BUS) { 289 if (sii->pub.bustype == PCI_BUS) {
285 if (SI_FAST(sii)) { 290 if (SI_FAST(sii)) {
286 if (!sii->pch) { 291 if (!sii->pch) {
287 sii->pch = (void *)pcicore_init( 292 sii->pch = (void *)pcicore_init(
@@ -308,10 +313,10 @@ static __used void si_nvram_process(si_info_t *sii, char *pvars)
308 uint w = 0; 313 uint w = 0;
309 314
310 /* get boardtype and boardrev */ 315 /* get boardtype and boardrev */
311 switch (BUSTYPE(sii->pub.bustype)) { 316 switch (sii->pub.bustype) {
312 case PCI_BUS: 317 case PCI_BUS:
313 /* do a pci config read to get subsystem id and subvendor id */ 318 /* do a pci config read to get subsystem id and subvendor id */
314 w = OSL_PCI_READ_CONFIG(sii->osh, PCI_CFG_SVID, sizeof(u32)); 319 pci_read_config_dword(sii->osh->pdev, PCI_CFG_SVID, &w);
315 /* Let nvram variables override subsystem Vend/ID */ 320 /* Let nvram variables override subsystem Vend/ID */
316 sii->pub.boardvendor = (u16)si_getdevpathintvar(&sii->pub, 321 sii->pub.boardvendor = (u16)si_getdevpathintvar(&sii->pub,
317 "boardvendor"); 322 "boardvendor");
@@ -364,7 +369,7 @@ static __used void si_nvram_process(si_info_t *sii, char *pvars)
364/* this is will make Sonics calls directly, since Sonics is no longer supported in the Si abstraction */ 369/* this is will make Sonics calls directly, since Sonics is no longer supported in the Si abstraction */
365/* this has been customized for the bcm 4329 ONLY */ 370/* this has been customized for the bcm 4329 ONLY */
366#ifdef BCMSDIO 371#ifdef BCMSDIO
367static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh, 372static si_info_t *si_doattach(si_info_t *sii, uint devid, struct osl_info *osh,
368 void *regs, uint bustype, void *sdh, 373 void *regs, uint bustype, void *sdh,
369 char **vars, uint *varsz) 374 char **vars, uint *varsz)
370{ 375{
@@ -376,7 +381,7 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
376 381
377 ASSERT(GOODREGS(regs)); 382 ASSERT(GOODREGS(regs));
378 383
379 bzero((unsigned char *) sii, sizeof(si_info_t)); 384 memset((unsigned char *) sii, 0, sizeof(si_info_t));
380 385
381 savewin = 0; 386 savewin = 0;
382 387
@@ -390,11 +395,6 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
390 cc = (chipcregs_t *) sii->curmap; 395 cc = (chipcregs_t *) sii->curmap;
391 sih->bustype = bustype; 396 sih->bustype = bustype;
392 397
393 if (bustype != BUSTYPE(bustype)) {
394 SI_ERROR(("si_doattach: bus type %d does not match configured bus type %d\n", bustype, BUSTYPE(bustype)));
395 return NULL;
396 }
397
398 /* bus/core/clk setup for register access */ 398 /* bus/core/clk setup for register access */
399 if (!si_buscore_prep(sii, bustype, devid, sdh)) { 399 if (!si_buscore_prep(sii, bustype, devid, sdh)) {
400 SI_ERROR(("si_doattach: si_core_clk_prep failed %d\n", 400 SI_ERROR(("si_doattach: si_core_clk_prep failed %d\n",
@@ -414,7 +414,7 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
414 sih->chiprev = (w & CID_REV_MASK) >> CID_REV_SHIFT; 414 sih->chiprev = (w & CID_REV_MASK) >> CID_REV_SHIFT;
415 sih->chippkg = (w & CID_PKG_MASK) >> CID_PKG_SHIFT; 415 sih->chippkg = (w & CID_PKG_MASK) >> CID_PKG_SHIFT;
416 416
417 if ((CHIPID(sih->chip) == BCM4329_CHIP_ID) && 417 if ((sih->chip == BCM4329_CHIP_ID) &&
418 (sih->chippkg != BCM4329_289PIN_PKG_ID)) 418 (sih->chippkg != BCM4329_289PIN_PKG_ID))
419 sih->chippkg = BCM4329_182PIN_PKG_ID; 419 sih->chippkg = BCM4329_182PIN_PKG_ID;
420 420
@@ -444,7 +444,7 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
444 444
445 /* Init nvram from sprom/otp if they exist */ 445 /* Init nvram from sprom/otp if they exist */
446 if (srom_var_init 446 if (srom_var_init
447 (&sii->pub, BUSTYPE(bustype), regs, sii->osh, vars, varsz)) { 447 (&sii->pub, bustype, regs, sii->osh, vars, varsz)) {
448 SI_ERROR(("si_doattach: srom_var_init failed: bad srom\n")); 448 SI_ERROR(("si_doattach: srom_var_init failed: bad srom\n"));
449 goto exit; 449 goto exit;
450 } 450 }
@@ -499,7 +499,7 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
499} 499}
500 500
501#else /* BCMSDIO */ 501#else /* BCMSDIO */
502static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh, 502static si_info_t *si_doattach(si_info_t *sii, uint devid, struct osl_info *osh,
503 void *regs, uint bustype, void *sdh, 503 void *regs, uint bustype, void *sdh,
504 char **vars, uint *varsz) 504 char **vars, uint *varsz)
505{ 505{
@@ -511,7 +511,7 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
511 511
512 ASSERT(GOODREGS(regs)); 512 ASSERT(GOODREGS(regs));
513 513
514 bzero((unsigned char *) sii, sizeof(si_info_t)); 514 memset((unsigned char *) sii, 0, sizeof(si_info_t));
515 515
516 savewin = 0; 516 savewin = 0;
517 517
@@ -522,30 +522,29 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
522 sii->osh = osh; 522 sii->osh = osh;
523 523
524 /* check to see if we are a si core mimic'ing a pci core */ 524 /* check to see if we are a si core mimic'ing a pci core */
525 if ((bustype == PCI_BUS) && 525 if (bustype == PCI_BUS) {
526 (OSL_PCI_READ_CONFIG(sii->osh, PCI_SPROM_CONTROL, sizeof(u32)) == 526 pci_read_config_dword(sii->osh->pdev, PCI_SPROM_CONTROL, &w);
527 0xffffffff)) { 527 if (w == 0xffffffff) {
528 SI_ERROR(("%s: incoming bus is PCI but it's a lie, switching to SI " "devid:0x%x\n", __func__, devid)); 528 SI_ERROR(("%s: incoming bus is PCI but it's a lie, "
529 bustype = SI_BUS; 529 " switching to SI devid:0x%x\n",
530 __func__, devid));
531 bustype = SI_BUS;
532 }
530 } 533 }
531 534
532 /* find Chipcommon address */ 535 /* find Chipcommon address */
533 if (bustype == PCI_BUS) { 536 if (bustype == PCI_BUS) {
534 savewin = 537 pci_read_config_dword(sii->osh->pdev, PCI_BAR0_WIN, &savewin);
535 OSL_PCI_READ_CONFIG(sii->osh, PCI_BAR0_WIN, sizeof(u32));
536 if (!GOODCOREADDR(savewin, SI_ENUM_BASE)) 538 if (!GOODCOREADDR(savewin, SI_ENUM_BASE))
537 savewin = SI_ENUM_BASE; 539 savewin = SI_ENUM_BASE;
538 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_BAR0_WIN, 4, SI_ENUM_BASE); 540 pci_write_config_dword(sii->osh->pdev, PCI_BAR0_WIN,
541 SI_ENUM_BASE);
539 cc = (chipcregs_t *) regs; 542 cc = (chipcregs_t *) regs;
540 } else { 543 } else {
541 cc = (chipcregs_t *) REG_MAP(SI_ENUM_BASE, SI_CORE_SIZE); 544 cc = (chipcregs_t *) REG_MAP(SI_ENUM_BASE, SI_CORE_SIZE);
542 } 545 }
543 546
544 sih->bustype = bustype; 547 sih->bustype = bustype;
545 if (bustype != BUSTYPE(bustype)) {
546 SI_ERROR(("si_doattach: bus type %d does not match configured bus type %d\n", bustype, BUSTYPE(bustype)));
547 return NULL;
548 }
549 548
550 /* bus/core/clk setup for register access */ 549 /* bus/core/clk setup for register access */
551 if (!si_buscore_prep(sii, bustype, devid, sdh)) { 550 if (!si_buscore_prep(sii, bustype, devid, sdh)) {
@@ -569,7 +568,7 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
569 sih->issim = IS_SIM(sih->chippkg); 568 sih->issim = IS_SIM(sih->chippkg);
570 569
571 /* scan for cores */ 570 /* scan for cores */
572 if (CHIPTYPE(sii->pub.socitype) == SOCI_AI) { 571 if (sii->pub.socitype == SOCI_AI) {
573 SI_MSG(("Found chip type AI (0x%08x)\n", w)); 572 SI_MSG(("Found chip type AI (0x%08x)\n", w));
574 /* pass chipc address instead of original core base */ 573 /* pass chipc address instead of original core base */
575 ai_scan(&sii->pub, (void *)cc, devid); 574 ai_scan(&sii->pub, (void *)cc, devid);
@@ -592,10 +591,10 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
592 /* assume current core is CC */ 591 /* assume current core is CC */
593 if ((sii->pub.ccrev == 0x25) 592 if ((sii->pub.ccrev == 0x25)
594 && 593 &&
595 ((CHIPID(sih->chip) == BCM43236_CHIP_ID 594 ((sih->chip == BCM43236_CHIP_ID
596 || CHIPID(sih->chip) == BCM43235_CHIP_ID 595 || sih->chip == BCM43235_CHIP_ID
597 || CHIPID(sih->chip) == BCM43238_CHIP_ID) 596 || sih->chip == BCM43238_CHIP_ID)
598 && (CHIPREV(sii->pub.chiprev) <= 2))) { 597 && (sii->pub.chiprev <= 2))) {
599 598
600 if ((cc->chipstatus & CST43236_BP_CLK) != 0) { 599 if ((cc->chipstatus & CST43236_BP_CLK) != 0) {
601 uint clkdiv; 600 uint clkdiv;
@@ -613,7 +612,7 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
613 612
614 /* Init nvram from sprom/otp if they exist */ 613 /* Init nvram from sprom/otp if they exist */
615 if (srom_var_init 614 if (srom_var_init
616 (&sii->pub, BUSTYPE(bustype), regs, sii->osh, vars, varsz)) { 615 (&sii->pub, bustype, regs, sii->osh, vars, varsz)) {
617 SI_ERROR(("si_doattach: srom_var_init failed: bad srom\n")); 616 SI_ERROR(("si_doattach: srom_var_init failed: bad srom\n"));
618 goto exit; 617 goto exit;
619 } 618 }
@@ -651,10 +650,10 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
651 pcicore_attach(sii->pch, pvars, SI_DOATTACH); 650 pcicore_attach(sii->pch, pvars, SI_DOATTACH);
652 } 651 }
653 652
654 if ((CHIPID(sih->chip) == BCM43224_CHIP_ID) || 653 if ((sih->chip == BCM43224_CHIP_ID) ||
655 (CHIPID(sih->chip) == BCM43421_CHIP_ID)) { 654 (sih->chip == BCM43421_CHIP_ID)) {
656 /* enable 12 mA drive strenth for 43224 and set chipControl register bit 15 */ 655 /* enable 12 mA drive strenth for 43224 and set chipControl register bit 15 */
657 if (CHIPREV(sih->chiprev) == 0) { 656 if (sih->chiprev == 0) {
658 SI_MSG(("Applying 43224A0 WARs\n")); 657 SI_MSG(("Applying 43224A0 WARs\n"));
659 si_corereg(sih, SI_CC_IDX, 658 si_corereg(sih, SI_CC_IDX,
660 offsetof(chipcregs_t, chipcontrol), 659 offsetof(chipcregs_t, chipcontrol),
@@ -663,28 +662,28 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, osl_t *osh,
663 si_pmu_chipcontrol(sih, 0, CCTRL_43224A0_12MA_LED_DRIVE, 662 si_pmu_chipcontrol(sih, 0, CCTRL_43224A0_12MA_LED_DRIVE,
664 CCTRL_43224A0_12MA_LED_DRIVE); 663 CCTRL_43224A0_12MA_LED_DRIVE);
665 } 664 }
666 if (CHIPREV(sih->chiprev) >= 1) { 665 if (sih->chiprev >= 1) {
667 SI_MSG(("Applying 43224B0+ WARs\n")); 666 SI_MSG(("Applying 43224B0+ WARs\n"));
668 si_pmu_chipcontrol(sih, 0, CCTRL_43224B0_12MA_LED_DRIVE, 667 si_pmu_chipcontrol(sih, 0, CCTRL_43224B0_12MA_LED_DRIVE,
669 CCTRL_43224B0_12MA_LED_DRIVE); 668 CCTRL_43224B0_12MA_LED_DRIVE);
670 } 669 }
671 } 670 }
672 671
673 if (CHIPID(sih->chip) == BCM4313_CHIP_ID) { 672 if (sih->chip == BCM4313_CHIP_ID) {
674 /* enable 12 mA drive strenth for 4313 and set chipControl register bit 1 */ 673 /* enable 12 mA drive strenth for 4313 and set chipControl register bit 1 */
675 SI_MSG(("Applying 4313 WARs\n")); 674 SI_MSG(("Applying 4313 WARs\n"));
676 si_pmu_chipcontrol(sih, 0, CCTRL_4313_12MA_LED_DRIVE, 675 si_pmu_chipcontrol(sih, 0, CCTRL_4313_12MA_LED_DRIVE,
677 CCTRL_4313_12MA_LED_DRIVE); 676 CCTRL_4313_12MA_LED_DRIVE);
678 } 677 }
679 678
680 if (CHIPID(sih->chip) == BCM4331_CHIP_ID) { 679 if (sih->chip == BCM4331_CHIP_ID) {
681 /* Enable Ext PA lines depending on chip package option */ 680 /* Enable Ext PA lines depending on chip package option */
682 si_chipcontrl_epa4331(sih, true); 681 si_chipcontrl_epa4331(sih, true);
683 } 682 }
684 683
685 return sii; 684 return sii;
686 exit: 685 exit:
687 if (BUSTYPE(sih->bustype) == PCI_BUS) { 686 if (sih->bustype == PCI_BUS) {
688 if (sii->pch) 687 if (sii->pch)
689 pcicore_deinit(sii->pch); 688 pcicore_deinit(sii->pch);
690 sii->pch = NULL; 689 sii->pch = NULL;
@@ -708,17 +707,17 @@ void si_detach(si_t *sih)
708 if (sii == NULL) 707 if (sii == NULL)
709 return; 708 return;
710 709
711 if (BUSTYPE(sih->bustype) == SI_BUS) 710 if (sih->bustype == SI_BUS)
712 for (idx = 0; idx < SI_MAXCORES; idx++) 711 for (idx = 0; idx < SI_MAXCORES; idx++)
713 if (sii->regs[idx]) { 712 if (sii->regs[idx]) {
714 REG_UNMAP(sii->regs[idx]); 713 iounmap(sii->regs[idx]);
715 sii->regs[idx] = NULL; 714 sii->regs[idx] = NULL;
716 } 715 }
717 716
718#ifndef BRCM_FULLMAC 717#ifndef BRCM_FULLMAC
719 nvram_exit((void *)si_local); /* free up nvram buffers */ 718 nvram_exit((void *)si_local); /* free up nvram buffers */
720 719
721 if (BUSTYPE(sih->bustype) == PCI_BUS) { 720 if (sih->bustype == PCI_BUS) {
722 if (sii->pch) 721 if (sii->pch)
723 pcicore_deinit(sii->pch); 722 pcicore_deinit(sii->pch);
724 sii->pch = NULL; 723 sii->pch = NULL;
@@ -730,7 +729,7 @@ void si_detach(si_t *sih)
730 kfree(sii); 729 kfree(sii);
731} 730}
732 731
733void *si_osh(si_t *sih) 732struct osl_info *si_osh(si_t *sih)
734{ 733{
735 si_info_t *sii; 734 si_info_t *sii;
736 735
@@ -766,7 +765,7 @@ void si_deregister_intr_callback(si_t *sih)
766 765
767uint si_flag(si_t *sih) 766uint si_flag(si_t *sih)
768{ 767{
769 if (CHIPTYPE(sih->socitype) == SOCI_AI) 768 if (sih->socitype == SOCI_AI)
770 return ai_flag(sih); 769 return ai_flag(sih);
771 else { 770 else {
772 ASSERT(0); 771 ASSERT(0);
@@ -776,7 +775,7 @@ uint si_flag(si_t *sih)
776 775
777void si_setint(si_t *sih, int siflag) 776void si_setint(si_t *sih, int siflag)
778{ 777{
779 if (CHIPTYPE(sih->socitype) == SOCI_AI) 778 if (sih->socitype == SOCI_AI)
780 ai_setint(sih, siflag); 779 ai_setint(sih, siflag);
781 else 780 else
782 ASSERT(0); 781 ASSERT(0);
@@ -808,7 +807,7 @@ bool si_backplane64(si_t *sih)
808#ifndef BCMSDIO 807#ifndef BCMSDIO
809uint si_corerev(si_t *sih) 808uint si_corerev(si_t *sih)
810{ 809{
811 if (CHIPTYPE(sih->socitype) == SOCI_AI) 810 if (sih->socitype == SOCI_AI)
812 return ai_corerev(sih); 811 return ai_corerev(sih);
813 else { 812 else {
814 ASSERT(0); 813 ASSERT(0);
@@ -851,7 +850,7 @@ void *si_setcore(si_t *sih, uint coreid, uint coreunit)
851 if (!GOODIDX(idx)) 850 if (!GOODIDX(idx))
852 return NULL; 851 return NULL;
853 852
854 if (CHIPTYPE(sih->socitype) == SOCI_AI) 853 if (sih->socitype == SOCI_AI)
855 return ai_setcoreidx(sih, idx); 854 return ai_setcoreidx(sih, idx);
856 else { 855 else {
857#ifdef BCMSDIO 856#ifdef BCMSDIO
@@ -866,7 +865,7 @@ void *si_setcore(si_t *sih, uint coreid, uint coreunit)
866#ifndef BCMSDIO 865#ifndef BCMSDIO
867void *si_setcoreidx(si_t *sih, uint coreidx) 866void *si_setcoreidx(si_t *sih, uint coreidx)
868{ 867{
869 if (CHIPTYPE(sih->socitype) == SOCI_AI) 868 if (sih->socitype == SOCI_AI)
870 return ai_setcoreidx(sih, coreidx); 869 return ai_setcoreidx(sih, coreidx);
871 else { 870 else {
872 ASSERT(0); 871 ASSERT(0);
@@ -918,7 +917,7 @@ void si_restore_core(si_t *sih, uint coreid, uint intr_val)
918 917
919u32 si_core_cflags(si_t *sih, u32 mask, u32 val) 918u32 si_core_cflags(si_t *sih, u32 mask, u32 val)
920{ 919{
921 if (CHIPTYPE(sih->socitype) == SOCI_AI) 920 if (sih->socitype == SOCI_AI)
922 return ai_core_cflags(sih, mask, val); 921 return ai_core_cflags(sih, mask, val);
923 else { 922 else {
924 ASSERT(0); 923 ASSERT(0);
@@ -928,7 +927,7 @@ u32 si_core_cflags(si_t *sih, u32 mask, u32 val)
928 927
929u32 si_core_sflags(si_t *sih, u32 mask, u32 val) 928u32 si_core_sflags(si_t *sih, u32 mask, u32 val)
930{ 929{
931 if (CHIPTYPE(sih->socitype) == SOCI_AI) 930 if (sih->socitype == SOCI_AI)
932 return ai_core_sflags(sih, mask, val); 931 return ai_core_sflags(sih, mask, val);
933 else { 932 else {
934 ASSERT(0); 933 ASSERT(0);
@@ -938,7 +937,7 @@ u32 si_core_sflags(si_t *sih, u32 mask, u32 val)
938 937
939bool si_iscoreup(si_t *sih) 938bool si_iscoreup(si_t *sih)
940{ 939{
941 if (CHIPTYPE(sih->socitype) == SOCI_AI) 940 if (sih->socitype == SOCI_AI)
942 return ai_iscoreup(sih); 941 return ai_iscoreup(sih);
943 else { 942 else {
944#ifdef BCMSDIO 943#ifdef BCMSDIO
@@ -953,7 +952,7 @@ bool si_iscoreup(si_t *sih)
953void si_write_wrapperreg(si_t *sih, u32 offset, u32 val) 952void si_write_wrapperreg(si_t *sih, u32 offset, u32 val)
954{ 953{
955 /* only for 4319, no requirement for SOCI_SB */ 954 /* only for 4319, no requirement for SOCI_SB */
956 if (CHIPTYPE(sih->socitype) == SOCI_AI) { 955 if (sih->socitype == SOCI_AI) {
957 ai_write_wrap_reg(sih, offset, val); 956 ai_write_wrap_reg(sih, offset, val);
958 } 957 }
959} 958}
@@ -961,7 +960,7 @@ void si_write_wrapperreg(si_t *sih, u32 offset, u32 val)
961uint si_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val) 960uint si_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val)
962{ 961{
963 962
964 if (CHIPTYPE(sih->socitype) == SOCI_AI) 963 if (sih->socitype == SOCI_AI)
965 return ai_corereg(sih, coreidx, regoff, mask, val); 964 return ai_corereg(sih, coreidx, regoff, mask, val);
966 else { 965 else {
967#ifdef BCMSDIO 966#ifdef BCMSDIO
@@ -976,7 +975,7 @@ uint si_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val)
976void si_core_disable(si_t *sih, u32 bits) 975void si_core_disable(si_t *sih, u32 bits)
977{ 976{
978 977
979 if (CHIPTYPE(sih->socitype) == SOCI_AI) 978 if (sih->socitype == SOCI_AI)
980 ai_core_disable(sih, bits); 979 ai_core_disable(sih, bits);
981#ifdef BCMSDIO 980#ifdef BCMSDIO
982 else 981 else
@@ -986,7 +985,7 @@ void si_core_disable(si_t *sih, u32 bits)
986 985
987void si_core_reset(si_t *sih, u32 bits, u32 resetbits) 986void si_core_reset(si_t *sih, u32 bits, u32 resetbits)
988{ 987{
989 if (CHIPTYPE(sih->socitype) == SOCI_AI) 988 if (sih->socitype == SOCI_AI)
990 ai_core_reset(sih, bits, resetbits); 989 ai_core_reset(sih, bits, resetbits);
991#ifdef BCMSDIO 990#ifdef BCMSDIO
992 else 991 else
@@ -1043,8 +1042,8 @@ void si_watchdog(si_t *sih, uint ticks)
1043 1042
1044 if (PMUCTL_ENAB(sih)) { 1043 if (PMUCTL_ENAB(sih)) {
1045 1044
1046 if ((CHIPID(sih->chip) == BCM4319_CHIP_ID) && 1045 if ((sih->chip == BCM4319_CHIP_ID) &&
1047 (CHIPREV(sih->chiprev) == 0) && (ticks != 0)) { 1046 (sih->chiprev == 0) && (ticks != 0)) {
1048 si_corereg(sih, SI_CC_IDX, 1047 si_corereg(sih, SI_CC_IDX,
1049 offsetof(chipcregs_t, clk_ctl_st), ~0, 0x2); 1048 offsetof(chipcregs_t, clk_ctl_st), ~0, 0x2);
1050 si_setcore(sih, USB20D_CORE_ID, 0); 1049 si_setcore(sih, USB20D_CORE_ID, 0);
@@ -1085,16 +1084,18 @@ void si_watchdog(si_t *sih, uint ticks)
1085static uint si_slowclk_src(si_info_t *sii) 1084static uint si_slowclk_src(si_info_t *sii)
1086{ 1085{
1087 chipcregs_t *cc; 1086 chipcregs_t *cc;
1087 u32 val;
1088 1088
1089 ASSERT(SI_FAST(sii) || si_coreid(&sii->pub) == CC_CORE_ID); 1089 ASSERT(SI_FAST(sii) || si_coreid(&sii->pub) == CC_CORE_ID);
1090 1090
1091 if (sii->pub.ccrev < 6) { 1091 if (sii->pub.ccrev < 6) {
1092 if ((BUSTYPE(sii->pub.bustype) == PCI_BUS) && 1092 if (sii->pub.bustype == PCI_BUS) {
1093 (OSL_PCI_READ_CONFIG(sii->osh, PCI_GPIO_OUT, sizeof(u32)) 1093 pci_read_config_dword(sii->osh->pdev, PCI_GPIO_OUT,
1094 & PCI_CFG_GPIO_SCS)) 1094 &val);
1095 return SCC_SS_PCI; 1095 if (val & PCI_CFG_GPIO_SCS)
1096 else 1096 return SCC_SS_PCI;
1097 return SCC_SS_XTAL; 1097 }
1098 return SCC_SS_XTAL;
1098 } else if (sii->pub.ccrev < 10) { 1099 } else if (sii->pub.ccrev < 10) {
1099 cc = (chipcregs_t *) si_setcoreidx(&sii->pub, sii->curidx); 1100 cc = (chipcregs_t *) si_setcoreidx(&sii->pub, sii->curidx);
1100 return R_REG(sii->osh, &cc->slow_clk_ctl) & SCC_SS_MASK; 1101 return R_REG(sii->osh, &cc->slow_clk_ctl) & SCC_SS_MASK;
@@ -1264,7 +1265,7 @@ int si_clkctl_xtal(si_t *sih, uint what, bool on)
1264 1265
1265 sii = SI_INFO(sih); 1266 sii = SI_INFO(sih);
1266 1267
1267 switch (BUSTYPE(sih->bustype)) { 1268 switch (sih->bustype) {
1268 1269
1269#ifdef BCMSDIO 1270#ifdef BCMSDIO
1270 case SDIO_BUS: 1271 case SDIO_BUS:
@@ -1276,12 +1277,9 @@ int si_clkctl_xtal(si_t *sih, uint what, bool on)
1276 if (PCIE(sii)) 1277 if (PCIE(sii))
1277 return -1; 1278 return -1;
1278 1279
1279 in = OSL_PCI_READ_CONFIG(sii->osh, PCI_GPIO_IN, sizeof(u32)); 1280 pci_read_config_dword(sii->osh->pdev, PCI_GPIO_IN, &in);
1280 out = 1281 pci_read_config_dword(sii->osh->pdev, PCI_GPIO_OUT, &out);
1281 OSL_PCI_READ_CONFIG(sii->osh, PCI_GPIO_OUT, sizeof(u32)); 1282 pci_read_config_dword(sii->osh->pdev, PCI_GPIO_OUTEN, &outen);
1282 outen =
1283 OSL_PCI_READ_CONFIG(sii->osh, PCI_GPIO_OUTEN,
1284 sizeof(u32));
1285 1283
1286 /* 1284 /*
1287 * Avoid glitching the clock if GPRS is already using it. 1285 * Avoid glitching the clock if GPRS is already using it.
@@ -1302,18 +1300,18 @@ int si_clkctl_xtal(si_t *sih, uint what, bool on)
1302 out |= PCI_CFG_GPIO_XTAL; 1300 out |= PCI_CFG_GPIO_XTAL;
1303 if (what & PLL) 1301 if (what & PLL)
1304 out |= PCI_CFG_GPIO_PLL; 1302 out |= PCI_CFG_GPIO_PLL;
1305 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_GPIO_OUT, 1303 pci_write_config_dword(sii->osh->pdev,
1306 sizeof(u32), out); 1304 PCI_GPIO_OUT, out);
1307 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_GPIO_OUTEN, 1305 pci_write_config_dword(sii->osh->pdev,
1308 sizeof(u32), outen); 1306 PCI_GPIO_OUTEN, outen);
1309 udelay(XTAL_ON_DELAY); 1307 udelay(XTAL_ON_DELAY);
1310 } 1308 }
1311 1309
1312 /* turn pll on */ 1310 /* turn pll on */
1313 if (what & PLL) { 1311 if (what & PLL) {
1314 out &= ~PCI_CFG_GPIO_PLL; 1312 out &= ~PCI_CFG_GPIO_PLL;
1315 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_GPIO_OUT, 1313 pci_write_config_dword(sii->osh->pdev,
1316 sizeof(u32), out); 1314 PCI_GPIO_OUT, out);
1317 mdelay(2); 1315 mdelay(2);
1318 } 1316 }
1319 } else { 1317 } else {
@@ -1321,10 +1319,10 @@ int si_clkctl_xtal(si_t *sih, uint what, bool on)
1321 out &= ~PCI_CFG_GPIO_XTAL; 1319 out &= ~PCI_CFG_GPIO_XTAL;
1322 if (what & PLL) 1320 if (what & PLL)
1323 out |= PCI_CFG_GPIO_PLL; 1321 out |= PCI_CFG_GPIO_PLL;
1324 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_GPIO_OUT, 1322 pci_write_config_dword(sii->osh->pdev,
1325 sizeof(u32), out); 1323 PCI_GPIO_OUT, out);
1326 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_GPIO_OUTEN, 1324 pci_write_config_dword(sii->osh->pdev,
1327 sizeof(u32), outen); 1325 PCI_GPIO_OUTEN, outen);
1328 } 1326 }
1329 1327
1330 default: 1328 default:
@@ -1378,7 +1376,7 @@ static bool _si_clkctl_cc(si_info_t *sii, uint mode)
1378 INTR_OFF(sii, intr_val); 1376 INTR_OFF(sii, intr_val);
1379 origidx = sii->curidx; 1377 origidx = sii->curidx;
1380 1378
1381 if ((BUSTYPE(sii->pub.bustype) == SI_BUS) && 1379 if ((sii->pub.bustype == SI_BUS) &&
1382 si_setcore(&sii->pub, MIPS33_CORE_ID, 0) && 1380 si_setcore(&sii->pub, MIPS33_CORE_ID, 0) &&
1383 (si_corerev(&sii->pub) <= 7) && (sii->pub.ccrev >= 10)) 1381 (si_corerev(&sii->pub) <= 7) && (sii->pub.ccrev >= 10))
1384 goto done; 1382 goto done;
@@ -1460,7 +1458,7 @@ int si_devpath(si_t *sih, char *path, int size)
1460 if (!path || size <= 0) 1458 if (!path || size <= 0)
1461 return -1; 1459 return -1;
1462 1460
1463 switch (BUSTYPE(sih->bustype)) { 1461 switch (sih->bustype) {
1464 case SI_BUS: 1462 case SI_BUS:
1465 case JTAG_BUS: 1463 case JTAG_BUS:
1466 slen = snprintf(path, (size_t) size, "sb/%u/", si_coreidx(sih)); 1464 slen = snprintf(path, (size_t) size, "sb/%u/", si_coreidx(sih));
@@ -1550,7 +1548,7 @@ static __used bool si_ispcie(si_info_t *sii)
1550{ 1548{
1551 u8 cap_ptr; 1549 u8 cap_ptr;
1552 1550
1553 if (BUSTYPE(sii->pub.bustype) != PCI_BUS) 1551 if (sii->pub.bustype != PCI_BUS)
1554 return false; 1552 return false;
1555 1553
1556 cap_ptr = 1554 cap_ptr =
@@ -1617,7 +1615,7 @@ void si_pci_up(si_t *sih)
1617 sii = SI_INFO(sih); 1615 sii = SI_INFO(sih);
1618 1616
1619 /* if not pci bus, we're done */ 1617 /* if not pci bus, we're done */
1620 if (BUSTYPE(sih->bustype) != PCI_BUS) 1618 if (sih->bustype != PCI_BUS)
1621 return; 1619 return;
1622 1620
1623 if (PCI_FORCEHT(sii)) 1621 if (PCI_FORCEHT(sii))
@@ -1646,7 +1644,7 @@ void si_pci_down(si_t *sih)
1646 sii = SI_INFO(sih); 1644 sii = SI_INFO(sih);
1647 1645
1648 /* if not pci bus, we're done */ 1646 /* if not pci bus, we're done */
1649 if (BUSTYPE(sih->bustype) != PCI_BUS) 1647 if (sih->bustype != PCI_BUS)
1650 return; 1648 return;
1651 1649
1652 /* release FORCEHT since chip is going to "down" state */ 1650 /* release FORCEHT since chip is going to "down" state */
@@ -1669,7 +1667,7 @@ void si_pci_setup(si_t *sih, uint coremask)
1669 1667
1670 sii = SI_INFO(sih); 1668 sii = SI_INFO(sih);
1671 1669
1672 if (BUSTYPE(sii->pub.bustype) != PCI_BUS) 1670 if (sii->pub.bustype != PCI_BUS)
1673 return; 1671 return;
1674 1672
1675 ASSERT(PCI(sii) || PCIE(sii)); 1673 ASSERT(PCI(sii) || PCIE(sii));
@@ -1692,9 +1690,9 @@ void si_pci_setup(si_t *sih, uint coremask)
1692 */ 1690 */
1693 if (PCIE(sii) || (PCI(sii) && ((sii->pub.buscorerev) >= 6))) { 1691 if (PCIE(sii) || (PCI(sii) && ((sii->pub.buscorerev) >= 6))) {
1694 /* pci config write to set this core bit in PCIIntMask */ 1692 /* pci config write to set this core bit in PCIIntMask */
1695 w = OSL_PCI_READ_CONFIG(sii->osh, PCI_INT_MASK, sizeof(u32)); 1693 pci_read_config_dword(sii->osh->pdev, PCI_INT_MASK, &w);
1696 w |= (coremask << PCI_SBIM_SHIFT); 1694 w |= (coremask << PCI_SBIM_SHIFT);
1697 OSL_PCI_WRITE_CONFIG(sii->osh, PCI_INT_MASK, sizeof(u32), w); 1695 pci_write_config_dword(sii->osh->pdev, PCI_INT_MASK, w);
1698 } else { 1696 } else {
1699 /* set sbintvec bit for our flag number */ 1697 /* set sbintvec bit for our flag number */
1700 si_setint(sih, siflag); 1698 si_setint(sih, siflag);
@@ -1731,7 +1729,7 @@ int si_pci_fixcfg(si_t *sih)
1731 1729
1732 si_info_t *sii = SI_INFO(sih); 1730 si_info_t *sii = SI_INFO(sih);
1733 1731
1734 ASSERT(BUSTYPE(sii->pub.bustype) == PCI_BUS); 1732 ASSERT(sii->pub.bustype == PCI_BUS);
1735 1733
1736 /* Fixup PI in SROM shadow area to enable the correct PCI core access */ 1734 /* Fixup PI in SROM shadow area to enable the correct PCI core access */
1737 /* save the current index */ 1735 /* save the current index */
@@ -1777,7 +1775,7 @@ u32 si_gpiocontrol(si_t *sih, u32 mask, u32 val, u8 priority)
1777 * ignore reservation if it's high priority (e.g., test apps) 1775 * ignore reservation if it's high priority (e.g., test apps)
1778 */ 1776 */
1779 if ((priority != GPIO_HI_PRIORITY) && 1777 if ((priority != GPIO_HI_PRIORITY) &&
1780 (BUSTYPE(sih->bustype) == SI_BUS) && (val || mask)) { 1778 (sih->bustype == SI_BUS) && (val || mask)) {
1781 mask = priority ? (si_gpioreservation & mask) : 1779 mask = priority ? (si_gpioreservation & mask) :
1782 ((si_gpioreservation | mask) & ~(si_gpioreservation)); 1780 ((si_gpioreservation | mask) & ~(si_gpioreservation));
1783 val &= mask; 1781 val &= mask;
@@ -1929,10 +1927,10 @@ bool si_deviceremoved(si_t *sih)
1929 1927
1930 sii = SI_INFO(sih); 1928 sii = SI_INFO(sih);
1931 1929
1932 switch (BUSTYPE(sih->bustype)) { 1930 switch (sih->bustype) {
1933 case PCI_BUS: 1931 case PCI_BUS:
1934 ASSERT(sii->osh != NULL); 1932 ASSERT(sii->osh != NULL);
1935 w = OSL_PCI_READ_CONFIG(sii->osh, PCI_CFG_VID, sizeof(u32)); 1933 pci_read_config_dword(sii->osh->pdev, PCI_CFG_VID, &w);
1936 if ((w & 0xFFFF) != VENDOR_BROADCOM) 1934 if ((w & 0xFFFF) != VENDOR_BROADCOM)
1937 return true; 1935 return true;
1938 break; 1936 break;
@@ -1959,7 +1957,7 @@ bool si_is_sprom_available(si_t *sih)
1959 return sromctrl & SRC_PRESENT; 1957 return sromctrl & SRC_PRESENT;
1960 } 1958 }
1961 1959
1962 switch (CHIPID(sih->chip)) { 1960 switch (sih->chip) {
1963 case BCM4329_CHIP_ID: 1961 case BCM4329_CHIP_ID:
1964 return (sih->chipst & CST4329_SPROM_SEL) != 0; 1962 return (sih->chipst & CST4329_SPROM_SEL) != 0;
1965 case BCM4319_CHIP_ID: 1963 case BCM4319_CHIP_ID:
@@ -1979,7 +1977,7 @@ bool si_is_sprom_available(si_t *sih)
1979 1977
1980bool si_is_otp_disabled(si_t *sih) 1978bool si_is_otp_disabled(si_t *sih)
1981{ 1979{
1982 switch (CHIPID(sih->chip)) { 1980 switch (sih->chip) {
1983 case BCM4329_CHIP_ID: 1981 case BCM4329_CHIP_ID:
1984 return (sih->chipst & CST4329_SPROM_OTP_SEL_MASK) == 1982 return (sih->chipst & CST4329_SPROM_OTP_SEL_MASK) ==
1985 CST4329_OTP_PWRDN; 1983 CST4329_OTP_PWRDN;
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 4a29ed737e3f..dca861ee0466 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -117,8 +117,7 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
117 117
118 for (driv = comedi_drivers; driv; driv = driv->next) { 118 for (driv = comedi_drivers; driv; driv = driv->next) {
119 if (!try_module_get(driv->module)) { 119 if (!try_module_get(driv->module)) {
120 printk 120 printk(KERN_INFO "comedi: failed to increment module count, skipping\n");
121 (KERN_INFO "comedi: failed to increment module count, skipping\n");
122 continue; 121 continue;
123 } 122 }
124 if (driv->num_names) { 123 if (driv->num_names) {
@@ -205,9 +204,8 @@ int comedi_driver_unregister(struct comedi_driver *driver)
205 mutex_lock(&dev->mutex); 204 mutex_lock(&dev->mutex);
206 if (dev->attached && dev->driver == driver) { 205 if (dev->attached && dev->driver == driver) {
207 if (dev->use_count) 206 if (dev->use_count)
208 printk 207 printk(KERN_WARNING "BUG! detaching device with use_count=%d\n",
209 (KERN_WARNING "BUG! detaching device with use_count=%d\n", 208 dev->use_count);
210 dev->use_count);
211 comedi_device_detach(dev); 209 comedi_device_detach(dev);
212 } 210 }
213 mutex_unlock(&dev->mutex); 211 mutex_unlock(&dev->mutex);
@@ -442,7 +440,9 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
442 unsigned i; 440 unsigned i;
443 for (i = 0; i < async->n_buf_pages; ++i) { 441 for (i = 0; i < async->n_buf_pages; ++i) {
444 if (async->buf_page_list[i].virt_addr) { 442 if (async->buf_page_list[i].virt_addr) {
445 clear_bit(PG_reserved, &(virt_to_page(async->buf_page_list[i].virt_addr)->flags)); 443 clear_bit(PG_reserved,
444 &(virt_to_page(async->buf_page_list[i].
445 virt_addr)->flags));
446 if (s->async_dma_dir != DMA_NONE) { 446 if (s->async_dma_dir != DMA_NONE) {
447 dma_free_coherent(dev->hw_dev, 447 dma_free_coherent(dev->hw_dev,
448 PAGE_SIZE, 448 PAGE_SIZE,
@@ -470,10 +470,8 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
470 struct page **pages = NULL; 470 struct page **pages = NULL;
471 471
472 async->buf_page_list = 472 async->buf_page_list =
473 vmalloc(sizeof(struct comedi_buf_page) * n_pages); 473 vzalloc(sizeof(struct comedi_buf_page) * n_pages);
474 if (async->buf_page_list) { 474 if (async->buf_page_list) {
475 memset(async->buf_page_list, 0,
476 sizeof(struct comedi_buf_page) * n_pages);
477 pages = vmalloc(sizeof(struct page *) * n_pages); 475 pages = vmalloc(sizeof(struct page *) * n_pages);
478 } 476 }
479 if (pages) { 477 if (pages) {
@@ -496,8 +494,10 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
496 break; 494 break;
497 495
498 set_bit(PG_reserved, 496 set_bit(PG_reserved,
499 &(virt_to_page(async->buf_page_list[i].virt_addr)->flags)); 497 &(virt_to_page(async->buf_page_list[i].
500 pages[i] = virt_to_page(async->buf_page_list[i].virt_addr); 498 virt_addr)->flags));
499 pages[i] = virt_to_page(async->buf_page_list[i].
500 virt_addr);
501 } 501 }
502 } 502 }
503 if (i == n_pages) { 503 if (i == n_pages) {
@@ -514,7 +514,10 @@ int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
514 NULL) { 514 NULL) {
515 break; 515 break;
516 } 516 }
517 clear_bit(PG_reserved, &(virt_to_page(async->buf_page_list[i].virt_addr)->flags)); 517 clear_bit(PG_reserved,
518 &(virt_to_page(async->
519 buf_page_list[i].
520 virt_addr)->flags));
518 if (s->async_dma_dir != DMA_NONE) { 521 if (s->async_dma_dir != DMA_NONE) {
519 dma_free_coherent(dev->hw_dev, 522 dma_free_coherent(dev->hw_dev,
520 PAGE_SIZE, 523 PAGE_SIZE,
@@ -646,8 +649,7 @@ unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes)
646{ 649{
647 if ((int)(async->buf_write_count + nbytes - 650 if ((int)(async->buf_write_count + nbytes -
648 async->buf_write_alloc_count) > 0) { 651 async->buf_write_alloc_count) > 0) {
649 printk 652 printk(KERN_INFO "comedi: attempted to write-free more bytes than have been write-allocated.\n");
650 (KERN_INFO "comedi: attempted to write-free more bytes than have been write-allocated.\n");
651 nbytes = async->buf_write_alloc_count - async->buf_write_count; 653 nbytes = async->buf_write_alloc_count - async->buf_write_count;
652 } 654 }
653 async->buf_write_count += nbytes; 655 async->buf_write_count += nbytes;
diff --git a/drivers/staging/comedi/drivers/addi-data/APCI1710_Tor.c b/drivers/staging/comedi/drivers/addi-data/APCI1710_Tor.c
index 7361d508bf37..0e6affd95962 100644
--- a/drivers/staging/comedi/drivers/addi-data/APCI1710_Tor.c
+++ b/drivers/staging/comedi/drivers/addi-data/APCI1710_Tor.c
@@ -1008,7 +1008,7 @@ int i_APCI1710_InsnWriteEnableDisableTorCounter(struct comedi_device *dev,
1008 b_ExternGate = (unsigned char) data[3]; 1008 b_ExternGate = (unsigned char) data[3];
1009 b_CycleMode = (unsigned char) data[4]; 1009 b_CycleMode = (unsigned char) data[4];
1010 b_InterruptEnable = (unsigned char) data[5]; 1010 b_InterruptEnable = (unsigned char) data[5];
1011 i_ReturnValue = insn->n;; 1011 i_ReturnValue = insn->n;
1012 devpriv->tsk_Current = current; /* Save the current process task structure */ 1012 devpriv->tsk_Current = current; /* Save the current process task structure */
1013 /**************************/ 1013 /**************************/
1014 /* Test the module number */ 1014 /* Test the module number */
diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.c b/drivers/staging/comedi/drivers/addi-data/addi_common.c
index 93d7c056741d..76f2483871a7 100644
--- a/drivers/staging/comedi/drivers/addi-data/addi_common.c
+++ b/drivers/staging/comedi/drivers/addi-data/addi_common.c
@@ -2710,10 +2710,10 @@ static int i_ADDI_Attach(struct comedi_device *dev, struct comedi_devconfig *it)
2710 } else { 2710 } else {
2711 outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); 2711 outl(0x83838383, devpriv->i_IobaseAmcc + 0x60);
2712 } 2712 }
2713 /* Enable the interrupt for the controler */ 2713 /* Enable the interrupt for the controller */
2714 dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); 2714 dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38);
2715 outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); 2715 outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38);
2716 printk("\nEnable the interrupt for the controler"); 2716 printk("\nEnable the interrupt for the controller");
2717 } 2717 }
2718 printk("\nRead Eeprom"); 2718 printk("\nRead Eeprom");
2719 i_EepromReadMainHeader(io_addr[0], this_board->pc_EepromChip, 2719 i_EepromReadMainHeader(io_addr[0], this_board->pc_EepromChip,
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_APCI1710.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_APCI1710.c
index 912bc0fc54bf..a76ed2553fb4 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_APCI1710.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_APCI1710.c
@@ -225,7 +225,7 @@ int i_APCI1710_Reset(struct comedi_device *dev)
225 225
226 devpriv->s_BoardInfos.b_BoardVersion = 1; 226 devpriv->s_BoardInfos.b_BoardVersion = 1;
227 227
228 /* Enable the interrupt for the controler */ 228 /* Enable the interrupt for the controller */
229 dw_Dummy = inl(devpriv->s_BoardInfos.ui_Address + 0x38); 229 dw_Dummy = inl(devpriv->s_BoardInfos.ui_Address + 0x38);
230 outl(dw_Dummy | 0x2000, devpriv->s_BoardInfos.ui_Address + 0x38); 230 outl(dw_Dummy | 0x2000, devpriv->s_BoardInfos.ui_Address + 0x38);
231 231
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c
index 2a8a6c730920..62f421a06f05 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c
@@ -2850,7 +2850,7 @@ static int i_APCI1500_Reset(struct comedi_device *dev)
2850 i_Logic = 0; 2850 i_Logic = 0;
2851 i_CounterLogic = 0; 2851 i_CounterLogic = 0;
2852 i_InterruptMask = 0; 2852 i_InterruptMask = 0;
2853 i_InputChannel = 0;; 2853 i_InputChannel = 0;
2854 i_TimerCounter1Enabled = 0; 2854 i_TimerCounter1Enabled = 0;
2855 i_TimerCounter2Enabled = 0; 2855 i_TimerCounter2Enabled = 0;
2856 i_WatchdogCounter3Enabled = 0; 2856 i_WatchdogCounter3Enabled = 0;
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1516.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1516.c
index 12fcc35ecc52..8a584a014b0b 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1516.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1516.c
@@ -335,7 +335,7 @@ int i_APCI1516_WriteDigitalOutput(struct comedi_device *dev, struct comedi_subde
335 return -EINVAL; 335 return -EINVAL;
336 } /* if else data[3]==1) */ 336 } /* if else data[3]==1) */
337 } /* if else data[3]==0) */ 337 } /* if else data[3]==0) */
338 return (insn->n);; 338 return (insn->n);
339} 339}
340 340
341/* 341/*
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
index b943a06e70dc..a93e2349ad3a 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
@@ -3011,7 +3011,7 @@ int i_APCI3200_Reset(struct comedi_device *dev)
3011 3011
3012 outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); 3012 outl(0x83838383, devpriv->i_IobaseAmcc + 0x60);
3013 3013
3014 /* Enable the interrupt for the controler */ 3014 /* Enable the interrupt for the controller */
3015 dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); 3015 dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38);
3016 outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); 3016 outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38);
3017 outl(0, devpriv->i_IobaseAddon); /* Resets the output */ 3017 outl(0, devpriv->i_IobaseAddon); /* Resets the output */
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
index 356a1891e2e7..acaceb01629a 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
@@ -339,7 +339,7 @@ int i_APCI3501_ConfigAnalogOutput(struct comedi_device *dev, struct comedi_subde
339int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, struct comedi_subdevice *s, 339int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev, struct comedi_subdevice *s,
340 struct comedi_insn *insn, unsigned int *data) 340 struct comedi_insn *insn, unsigned int *data)
341{ 341{
342 unsigned int ul_Command1 = 0, ul_Channel_no, ul_Polarity, ul_DAC_Ready = 0;; 342 unsigned int ul_Command1 = 0, ul_Channel_no, ul_Polarity, ul_DAC_Ready = 0;
343 343
344 ul_Channel_no = CR_CHAN(insn->chanspec); 344 ul_Channel_no = CR_CHAN(insn->chanspec);
345 345
diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c
index 5d064577b2f1..7edeb1103dc8 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -971,7 +971,7 @@ static int pci230_attach(struct comedi_device *dev, struct comedi_devconfig *it)
971 if (thisboard->ao_chans > 0) { 971 if (thisboard->ao_chans > 0) {
972 s->type = COMEDI_SUBD_AO; 972 s->type = COMEDI_SUBD_AO;
973 s->subdev_flags = SDF_WRITABLE | SDF_GROUND; 973 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
974 s->n_chan = thisboard->ao_chans;; 974 s->n_chan = thisboard->ao_chans;
975 s->maxdata = (1 << thisboard->ao_bits) - 1; 975 s->maxdata = (1 << thisboard->ao_bits) - 1;
976 s->range_table = &pci230_ao_range; 976 s->range_table = &pci230_ao_range;
977 s->insn_write = &pci230_ao_winsn; 977 s->insn_write = &pci230_ao_winsn;
diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c
index 0345b4caba73..bb93685d8b93 100644
--- a/drivers/staging/comedi/drivers/cb_das16_cs.c
+++ b/drivers/staging/comedi/drivers/cb_das16_cs.c
@@ -169,7 +169,7 @@ static int das16cs_attach(struct comedi_device *dev,
169 if (!link) 169 if (!link)
170 return -EIO; 170 return -EIO;
171 171
172 dev->iobase = link->resource[0]->start;; 172 dev->iobase = link->resource[0]->start;
173 printk("I/O base=0x%04lx ", dev->iobase); 173 printk("I/O base=0x%04lx ", dev->iobase);
174 174
175 printk("fingerprint:\n"); 175 printk("fingerprint:\n");
diff --git a/drivers/staging/comedi/drivers/comedi_bond.c b/drivers/staging/comedi/drivers/comedi_bond.c
index cfcbd9b8f393..d8aefb23d6b9 100644
--- a/drivers/staging/comedi/drivers/comedi_bond.c
+++ b/drivers/staging/comedi/drivers/comedi_bond.c
@@ -370,7 +370,7 @@ static int doDevConfig(struct comedi_device *dev, struct comedi_devconfig *it)
370 struct comedi_device *devs_opened[COMEDI_NUM_BOARD_MINORS]; 370 struct comedi_device *devs_opened[COMEDI_NUM_BOARD_MINORS];
371 371
372 memset(devs_opened, 0, sizeof(devs_opened)); 372 memset(devs_opened, 0, sizeof(devs_opened));
373 devpriv->name[0] = 0;; 373 devpriv->name[0] = 0;
374 /* Loop through all comedi devices specified on the command-line, 374 /* Loop through all comedi devices specified on the command-line,
375 building our device list */ 375 building our device list */
376 for (i = 0; i < COMEDI_NDEVCONFOPTS && (!i || it->options[i]); ++i) { 376 for (i = 0; i < COMEDI_NDEVCONFOPTS && (!i || it->options[i]); ++i) {
diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c b/drivers/staging/comedi/drivers/ii_pci20kc.c
index 39a6a850d63c..e4711ef54719 100644
--- a/drivers/staging/comedi/drivers/ii_pci20kc.c
+++ b/drivers/staging/comedi/drivers/ii_pci20kc.c
@@ -19,7 +19,7 @@
19 * - 16 bit 19 * - 16 bit
20 * 20 *
21 * only ONE PCI-20341 module possible 21 * only ONE PCI-20341 module possible
22 * only ONE PCI-20006 module possible 22 * only ONE PCI-20006 module possible
23 * no extern trigger implemented 23 * no extern trigger implemented
24 * 24 *
25 * NOT WORKING (but soon) only 4 on-board differential channels supported 25 * NOT WORKING (but soon) only 4 on-board differential channels supported
@@ -83,11 +83,11 @@ options for PCI-20341M:
83#include "../comedidev.h" 83#include "../comedidev.h"
84 84
85#define PCI20000_ID 0x1d 85#define PCI20000_ID 0x1d
86#define PCI20341_ID 0x77 86#define PCI20341_ID 0x77
87#define PCI20006_ID 0xe3 87#define PCI20006_ID 0xe3
88#define PCI20xxx_EMPTY_ID 0xff 88#define PCI20xxx_EMPTY_ID 0xff
89 89
90#define PCI20000_OFFSET 0x100 90#define PCI20000_OFFSET 0x100
91#define PCI20000_MODULES 3 91#define PCI20000_MODULES 3
92 92
93#define PCI20000_DIO_0 0x80 93#define PCI20000_DIO_0 0x80
@@ -246,7 +246,7 @@ static int pci20xxx_attach(struct comedi_device *dev,
246 pci20006_init(dev, s, it->options[2 * i + 2], 246 pci20006_init(dev, s, it->options[2 * i + 2],
247 it->options[2 * i + 3]); 247 it->options[2 * i + 3]);
248 printk(KERN_INFO "comedi%d: " 248 printk(KERN_INFO "comedi%d: "
249 "ii_pci20kc PCI-20006 module in slot %d \n", 249 "ii_pci20kc PCI-20006 module in slot %d\n",
250 dev->minor, i + 1); 250 dev->minor, i + 1);
251 break; 251 break;
252 case PCI20341_ID: 252 case PCI20341_ID:
@@ -255,7 +255,7 @@ static int pci20xxx_attach(struct comedi_device *dev,
255 pci20341_init(dev, s, it->options[2 * i + 2], 255 pci20341_init(dev, s, it->options[2 * i + 2],
256 it->options[2 * i + 3]); 256 it->options[2 * i + 3]);
257 printk(KERN_INFO "comedi%d: " 257 printk(KERN_INFO "comedi%d: "
258 "ii_pci20kc PCI-20341 module in slot %d \n", 258 "ii_pci20kc PCI-20341 module in slot %d\n",
259 dev->minor, i + 1); 259 dev->minor, i + 1);
260 break; 260 break;
261 default: 261 default:
@@ -376,9 +376,20 @@ static int pci20341_insn_read(struct comedi_device *dev,
376static const int pci20341_timebase[] = { 0x00, 0x00, 0x00, 0x04 }; 376static const int pci20341_timebase[] = { 0x00, 0x00, 0x00, 0x04 };
377static const int pci20341_settling_time[] = { 0x58, 0x58, 0x93, 0x99 }; 377static const int pci20341_settling_time[] = { 0x58, 0x58, 0x93, 0x99 };
378 378
379static const struct comedi_lrange range_bipolar0_5 = { 1, {BIP_RANGE(0.5)} }; 379static const struct comedi_lrange range_bipolar0_5 = {
380static const struct comedi_lrange range_bipolar0_05 = { 1, {BIP_RANGE(0.05)} }; 380 1,
381static const struct comedi_lrange range_bipolar0_025 = { 1, {BIP_RANGE(0.025)} }; 381 {BIP_RANGE(0.5)}
382};
383
384static const struct comedi_lrange range_bipolar0_05 = {
385 1,
386 {BIP_RANGE(0.05)}
387};
388
389static const struct comedi_lrange range_bipolar0_025 = {
390 1,
391 {BIP_RANGE(0.025)}
392};
382 393
383static const struct comedi_lrange *const pci20341_ranges[] = { 394static const struct comedi_lrange *const pci20341_ranges[] = {
384 &range_bipolar5, 395 &range_bipolar5,
@@ -408,12 +419,18 @@ static int pci20341_init(struct comedi_device *dev, struct comedi_subdevice *s,
408 s->maxdata = 0xffff; 419 s->maxdata = 0xffff;
409 s->range_table = pci20341_ranges[opt0]; 420 s->range_table = pci20341_ranges[opt0];
410 421
411 option = sdp->pci20341.timebase | PCI20341_REPMODE; /* depends on gain, trigger, repetition mode */ 422 /* depends on gain, trigger, repetition mode */
412 423 option = sdp->pci20341.timebase | PCI20341_REPMODE;
413 writeb(PCI20341_INIT, sdp->iobase + PCI20341_CONFIG_REG); /* initialize Module */ 424
414 writeb(PCI20341_PACER, sdp->iobase + PCI20341_MOD_STATUS); /* set Pacer */ 425 /* initialize Module */
415 writeb(option, sdp->iobase + PCI20341_OPT_REG); /* option register */ 426 writeb(PCI20341_INIT, sdp->iobase + PCI20341_CONFIG_REG);
416 writeb(sdp->pci20341.settling_time, sdp->iobase + PCI20341_SET_TIME_REG); /* settling time counter */ 427 /* set Pacer */
428 writeb(PCI20341_PACER, sdp->iobase + PCI20341_MOD_STATUS);
429 /* option register */
430 writeb(option, sdp->iobase + PCI20341_OPT_REG);
431 /* settling time counter */
432 writeb(sdp->pci20341.settling_time,
433 sdp->iobase + PCI20341_SET_TIME_REG);
417 /* trigger not implemented */ 434 /* trigger not implemented */
418 return 0; 435 return 0;
419} 436}
@@ -429,11 +446,15 @@ static int pci20341_insn_read(struct comedi_device *dev,
429 unsigned int clb; /* channel list byte */ 446 unsigned int clb; /* channel list byte */
430 unsigned int boarddata; 447 unsigned int boarddata;
431 448
432 writeb(1, sdp->iobase + PCI20341_LCHAN_ADDR_REG); /* write number of input channels */ 449 /* write number of input channels */
450 writeb(1, sdp->iobase + PCI20341_LCHAN_ADDR_REG);
433 clb = PCI20341_DAISY_CHAIN | PCI20341_MUX | (sdp->pci20341.ai_gain << 3) 451 clb = PCI20341_DAISY_CHAIN | PCI20341_MUX | (sdp->pci20341.ai_gain << 3)
434 | CR_CHAN(insn->chanspec); 452 | CR_CHAN(insn->chanspec);
435 writeb(clb, sdp->iobase + PCI20341_CHAN_LIST); 453 writeb(clb, sdp->iobase + PCI20341_CHAN_LIST);
436 writeb(0x00, sdp->iobase + PCI20341_CC_RESET); /* reset settling time counter and trigger delay counter */ 454
455 /* reset settling time counter and trigger delay counter */
456 writeb(0x00, sdp->iobase + PCI20341_CC_RESET);
457
437 writeb(0x00, sdp->iobase + PCI20341_CHAN_RESET); 458 writeb(0x00, sdp->iobase + PCI20341_CHAN_RESET);
438 459
439 /* generate Pacer */ 460 /* generate Pacer */
@@ -444,9 +465,12 @@ static int pci20341_insn_read(struct comedi_device *dev,
444 * the whole interrupt stuff 465 * the whole interrupt stuff
445 */ 466 */
446 j = 0; 467 j = 0;
447 readb(sdp->iobase + PCI20341_SOFT_PACER); /* generate Pacer */ 468 /* generate Pacer */
469 readb(sdp->iobase + PCI20341_SOFT_PACER);
470
448 eoc = readb(sdp->iobase + PCI20341_STATUS_REG); 471 eoc = readb(sdp->iobase + PCI20341_STATUS_REG);
449 while ((eoc < 0x80) && j < 100) { /* poll Interrupt Flag */ 472 /* poll Interrupt Flag */
473 while ((eoc < 0x80) && j < 100) {
450 j++; 474 j++;
451 eoc = readb(sdp->iobase + PCI20341_STATUS_REG); 475 eoc = readb(sdp->iobase + PCI20341_STATUS_REG);
452 } 476 }
@@ -460,7 +484,9 @@ static int pci20341_insn_read(struct comedi_device *dev,
460 lo = readb(sdp->iobase + PCI20341_LDATA); 484 lo = readb(sdp->iobase + PCI20341_LDATA);
461 hi = readb(sdp->iobase + PCI20341_LDATA + 1); 485 hi = readb(sdp->iobase + PCI20341_LDATA + 1);
462 boarddata = lo + 0x100 * hi; 486 boarddata = lo + 0x100 * hi;
463 data[i] = (short)((boarddata + 0x8000) & 0xffff); /* board-data -> comedi-data */ 487
488 /* board-data -> comedi-data */
489 data[i] = (short)((boarddata + 0x8000) & 0xffff);
464 } 490 }
465 491
466 return i; 492 return i;
diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c
index 8b383ee959b2..5c6c72744167 100644
--- a/drivers/staging/comedi/drivers/jr3_pci.c
+++ b/drivers/staging/comedi/drivers/jr3_pci.c
@@ -54,6 +54,7 @@ Devices: [JR3] PCI force sensor board (jr3_pci)
54 54
55#define PCI_VENDOR_ID_JR3 0x1762 55#define PCI_VENDOR_ID_JR3 0x1762
56#define PCI_DEVICE_ID_JR3_1_CHANNEL 0x3111 56#define PCI_DEVICE_ID_JR3_1_CHANNEL 0x3111
57#define PCI_DEVICE_ID_JR3_1_CHANNEL_NEW 0x1111
57#define PCI_DEVICE_ID_JR3_2_CHANNEL 0x3112 58#define PCI_DEVICE_ID_JR3_2_CHANNEL 0x3112
58#define PCI_DEVICE_ID_JR3_3_CHANNEL 0x3113 59#define PCI_DEVICE_ID_JR3_3_CHANNEL 0x3113
59#define PCI_DEVICE_ID_JR3_4_CHANNEL 0x3114 60#define PCI_DEVICE_ID_JR3_4_CHANNEL 0x3114
@@ -73,6 +74,8 @@ static DEFINE_PCI_DEVICE_TABLE(jr3_pci_pci_table) = {
73 { 74 {
74 PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL, 75 PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL,
75 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, { 76 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {
77 PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL_NEW,
78 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {
76 PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_2_CHANNEL, 79 PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_2_CHANNEL,
77 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, { 80 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, {
78 PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_3_CHANNEL, 81 PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_3_CHANNEL,
@@ -807,6 +810,10 @@ static int jr3_pci_attach(struct comedi_device *dev,
807 devpriv->n_channels = 1; 810 devpriv->n_channels = 1;
808 } 811 }
809 break; 812 break;
813 case PCI_DEVICE_ID_JR3_1_CHANNEL_NEW:{
814 devpriv->n_channels = 1;
815 }
816 break;
810 case PCI_DEVICE_ID_JR3_2_CHANNEL:{ 817 case PCI_DEVICE_ID_JR3_2_CHANNEL:{
811 devpriv->n_channels = 2; 818 devpriv->n_channels = 2;
812 } 819 }
diff --git a/drivers/staging/comedi/drivers/ni_tiocmd.c b/drivers/staging/comedi/drivers/ni_tiocmd.c
index b0d44b547a69..a9611587460a 100644
--- a/drivers/staging/comedi/drivers/ni_tiocmd.c
+++ b/drivers/staging/comedi/drivers/ni_tiocmd.c
@@ -62,11 +62,10 @@ static void ni_tio_configure_dma(struct ni_gpct *counter, short enable,
62 unsigned input_select_bits = 0; 62 unsigned input_select_bits = 0;
63 63
64 if (enable) { 64 if (enable) {
65 if (read_not_write) { 65 if (read_not_write)
66 input_select_bits |= Gi_Read_Acknowledges_Irq; 66 input_select_bits |= Gi_Read_Acknowledges_Irq;
67 } else { 67 else
68 input_select_bits |= Gi_Write_Acknowledges_Irq; 68 input_select_bits |= Gi_Write_Acknowledges_Irq;
69 }
70 } 69 }
71 ni_tio_set_bits(counter, 70 ni_tio_set_bits(counter,
72 NITIO_Gi_Input_Select_Reg(counter->counter_index), 71 NITIO_Gi_Input_Select_Reg(counter->counter_index),
@@ -84,9 +83,8 @@ static void ni_tio_configure_dma(struct ni_gpct *counter, short enable,
84 gi_dma_config_bits |= Gi_DMA_Enable_Bit; 83 gi_dma_config_bits |= Gi_DMA_Enable_Bit;
85 gi_dma_config_bits |= Gi_DMA_Int_Bit; 84 gi_dma_config_bits |= Gi_DMA_Int_Bit;
86 } 85 }
87 if (read_not_write == 0) { 86 if (read_not_write == 0)
88 gi_dma_config_bits |= Gi_DMA_Write_Bit; 87 gi_dma_config_bits |= Gi_DMA_Write_Bit;
89 }
90 ni_tio_set_bits(counter, 88 ni_tio_set_bits(counter,
91 NITIO_Gi_DMA_Config_Reg(counter-> 89 NITIO_Gi_DMA_Config_Reg(counter->
92 counter_index), 90 counter_index),
@@ -174,7 +172,7 @@ static int ni_tio_input_cmd(struct ni_gpct *counter, struct comedi_async *async)
174static int ni_tio_output_cmd(struct ni_gpct *counter, 172static int ni_tio_output_cmd(struct ni_gpct *counter,
175 struct comedi_async *async) 173 struct comedi_async *async)
176{ 174{
177 printk("ni_tio: output commands not yet implemented.\n"); 175 printk(KERN_ERR "ni_tio: output commands not yet implemented.\n");
178 return -ENOTSUPP; 176 return -ENOTSUPP;
179 177
180 counter->mite_chan->dir = COMEDI_OUTPUT; 178 counter->mite_chan->dir = COMEDI_OUTPUT;
@@ -198,9 +196,8 @@ static int ni_tio_cmd_setup(struct ni_gpct *counter, struct comedi_async *async)
198 set_gate_source = 1; 196 set_gate_source = 1;
199 gate_source = cmd->convert_arg; 197 gate_source = cmd->convert_arg;
200 } 198 }
201 if (set_gate_source) { 199 if (set_gate_source)
202 retval = ni_tio_set_gate_src(counter, 0, gate_source); 200 retval = ni_tio_set_gate_src(counter, 0, gate_source);
203 }
204 if (cmd->flags & TRIG_WAKE_EOS) { 201 if (cmd->flags & TRIG_WAKE_EOS) {
205 ni_tio_set_bits(counter, 202 ni_tio_set_bits(counter,
206 NITIO_Gi_Interrupt_Enable_Reg(counter-> 203 NITIO_Gi_Interrupt_Enable_Reg(counter->
@@ -221,22 +218,21 @@ int ni_tio_cmd(struct ni_gpct *counter, struct comedi_async *async)
221 218
222 spin_lock_irqsave(&counter->lock, flags); 219 spin_lock_irqsave(&counter->lock, flags);
223 if (counter->mite_chan == NULL) { 220 if (counter->mite_chan == NULL) {
224 printk 221 printk(KERN_ERR "ni_tio: commands only supported with DMA. Interrupt-driven commands not yet implemented.\n");
225 ("ni_tio: commands only supported with DMA. Interrupt-driven commands not yet implemented.\n");
226 retval = -EIO; 222 retval = -EIO;
227 } else { 223 } else {
228 retval = ni_tio_cmd_setup(counter, async); 224 retval = ni_tio_cmd_setup(counter, async);
229 if (retval == 0) { 225 if (retval == 0) {
230 if (cmd->flags & CMDF_WRITE) { 226 if (cmd->flags & CMDF_WRITE)
231 retval = ni_tio_output_cmd(counter, async); 227 retval = ni_tio_output_cmd(counter, async);
232 } else { 228 else
233 retval = ni_tio_input_cmd(counter, async); 229 retval = ni_tio_input_cmd(counter, async);
234 }
235 } 230 }
236 } 231 }
237 spin_unlock_irqrestore(&counter->lock, flags); 232 spin_unlock_irqrestore(&counter->lock, flags);
238 return retval; 233 return retval;
239} 234}
235EXPORT_SYMBOL_GPL(ni_tio_cmd);
240 236
241int ni_tio_cmdtest(struct ni_gpct *counter, struct comedi_cmd *cmd) 237int ni_tio_cmdtest(struct ni_gpct *counter, struct comedi_cmd *cmd)
242{ 238{
@@ -342,6 +338,7 @@ int ni_tio_cmdtest(struct ni_gpct *counter, struct comedi_cmd *cmd)
342 338
343 return 0; 339 return 0;
344} 340}
341EXPORT_SYMBOL_GPL(ni_tio_cmdtest);
345 342
346int ni_tio_cancel(struct ni_gpct *counter) 343int ni_tio_cancel(struct ni_gpct *counter)
347{ 344{
@@ -349,9 +346,8 @@ int ni_tio_cancel(struct ni_gpct *counter)
349 346
350 ni_tio_arm(counter, 0, 0); 347 ni_tio_arm(counter, 0, 0);
351 spin_lock_irqsave(&counter->lock, flags); 348 spin_lock_irqsave(&counter->lock, flags);
352 if (counter->mite_chan) { 349 if (counter->mite_chan)
353 mite_dma_disarm(counter->mite_chan); 350 mite_dma_disarm(counter->mite_chan);
354 }
355 spin_unlock_irqrestore(&counter->lock, flags); 351 spin_unlock_irqrestore(&counter->lock, flags);
356 ni_tio_configure_dma(counter, 0, 0); 352 ni_tio_configure_dma(counter, 0, 0);
357 353
@@ -361,10 +357,11 @@ int ni_tio_cancel(struct ni_gpct *counter)
361 0x0); 357 0x0);
362 return 0; 358 return 0;
363} 359}
360EXPORT_SYMBOL_GPL(ni_tio_cancel);
364 361
365 /* During buffered input counter operation for e-series, the gate interrupt is acked 362 /* During buffered input counter operation for e-series, the gate
366 automatically by the dma controller, due to the Gi_Read/Write_Acknowledges_IRQ bits 363 interrupt is acked automatically by the dma controller, due to the
367 in the input select register. */ 364 Gi_Read/Write_Acknowledges_IRQ bits in the input select register. */
368static int should_ack_gate(struct ni_gpct *counter) 365static int should_ack_gate(struct ni_gpct *counter)
369{ 366{
370 unsigned long flags; 367 unsigned long flags;
@@ -372,7 +369,10 @@ static int should_ack_gate(struct ni_gpct *counter)
372 369
373 switch (counter->counter_dev->variant) { 370 switch (counter->counter_dev->variant) {
374 case ni_gpct_variant_m_series: 371 case ni_gpct_variant_m_series:
375 case ni_gpct_variant_660x: /* not sure if 660x really supports gate interrupts (the bits are not listed in register-level manual) */ 372 /* not sure if 660x really supports gate
373 interrupts (the bits are not listed
374 in register-level manual) */
375 case ni_gpct_variant_660x:
376 return 1; 376 return 1;
377 break; 377 break;
378 case ni_gpct_variant_e_series: 378 case ni_gpct_variant_e_series:
@@ -416,7 +416,8 @@ void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter, int *gate_error,
416 if (gxx_status & Gi_Gate_Error_Bit(counter->counter_index)) { 416 if (gxx_status & Gi_Gate_Error_Bit(counter->counter_index)) {
417 ack |= Gi_Gate_Error_Confirm_Bit(counter->counter_index); 417 ack |= Gi_Gate_Error_Confirm_Bit(counter->counter_index);
418 if (gate_error) { 418 if (gate_error) {
419 /*660x don't support automatic acknowledgement of gate interrupt via dma read/write 419 /*660x don't support automatic acknowledgement
420 of gate interrupt via dma read/write
420 and report bogus gate errors */ 421 and report bogus gate errors */
421 if (counter->counter_dev->variant != 422 if (counter->counter_dev->variant !=
422 ni_gpct_variant_660x) { 423 ni_gpct_variant_660x) {
@@ -429,9 +430,8 @@ void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter, int *gate_error,
429 if (tc_error) 430 if (tc_error)
430 *tc_error = 1; 431 *tc_error = 1;
431 } 432 }
432 if (gi_status & Gi_TC_Bit) { 433 if (gi_status & Gi_TC_Bit)
433 ack |= Gi_TC_Interrupt_Ack_Bit; 434 ack |= Gi_TC_Interrupt_Ack_Bit;
434 }
435 if (gi_status & Gi_Gate_Interrupt_Bit) { 435 if (gi_status & Gi_Gate_Interrupt_Bit) {
436 if (should_ack_gate(counter)) 436 if (should_ack_gate(counter))
437 ack |= Gi_Gate_Interrupt_Ack_Bit; 437 ack |= Gi_Gate_Interrupt_Ack_Bit;
@@ -452,13 +452,14 @@ void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter, int *gate_error,
452 NITIO_Gxx_Joint_Status2_Reg 452 NITIO_Gxx_Joint_Status2_Reg
453 (counter->counter_index)) & 453 (counter->counter_index)) &
454 Gi_Permanent_Stale_Bit(counter->counter_index)) { 454 Gi_Permanent_Stale_Bit(counter->counter_index)) {
455 printk("%s: Gi_Permanent_Stale_Data detected.\n", 455 printk(KERN_INFO "%s: Gi_Permanent_Stale_Data detected.\n",
456 __FUNCTION__); 456 __func__);
457 if (perm_stale_data) 457 if (perm_stale_data)
458 *perm_stale_data = 1; 458 *perm_stale_data = 1;
459 } 459 }
460 } 460 }
461} 461}
462EXPORT_SYMBOL_GPL(ni_tio_acknowledge_and_confirm);
462 463
463void ni_tio_handle_interrupt(struct ni_gpct *counter, 464void ni_tio_handle_interrupt(struct ni_gpct *counter,
464 struct comedi_subdevice *s) 465 struct comedi_subdevice *s)
@@ -472,20 +473,19 @@ void ni_tio_handle_interrupt(struct ni_gpct *counter,
472 ni_tio_acknowledge_and_confirm(counter, &gate_error, &tc_error, 473 ni_tio_acknowledge_and_confirm(counter, &gate_error, &tc_error,
473 &perm_stale_data, NULL); 474 &perm_stale_data, NULL);
474 if (gate_error) { 475 if (gate_error) {
475 printk("%s: Gi_Gate_Error detected.\n", __FUNCTION__); 476 printk(KERN_NOTICE "%s: Gi_Gate_Error detected.\n", __func__);
476 s->async->events |= COMEDI_CB_OVERFLOW; 477 s->async->events |= COMEDI_CB_OVERFLOW;
477 } 478 }
478 if (perm_stale_data) { 479 if (perm_stale_data)
479 s->async->events |= COMEDI_CB_ERROR; 480 s->async->events |= COMEDI_CB_ERROR;
480 }
481 switch (counter->counter_dev->variant) { 481 switch (counter->counter_dev->variant) {
482 case ni_gpct_variant_m_series: 482 case ni_gpct_variant_m_series:
483 case ni_gpct_variant_660x: 483 case ni_gpct_variant_660x:
484 if (read_register(counter, 484 if (read_register(counter,
485 NITIO_Gi_DMA_Status_Reg 485 NITIO_Gi_DMA_Status_Reg
486 (counter->counter_index)) & Gi_DRQ_Error_Bit) 486 (counter->counter_index)) & Gi_DRQ_Error_Bit) {
487 { 487 printk(KERN_NOTICE "%s: Gi_DRQ_Error detected.\n",
488 printk("%s: Gi_DRQ_Error detected.\n", __FUNCTION__); 488 __func__);
489 s->async->events |= COMEDI_CB_OVERFLOW; 489 s->async->events |= COMEDI_CB_OVERFLOW;
490 } 490 }
491 break; 491 break;
@@ -506,6 +506,7 @@ void ni_tio_handle_interrupt(struct ni_gpct *counter,
506 mite_sync_input_dma(counter->mite_chan, s->async); 506 mite_sync_input_dma(counter->mite_chan, s->async);
507 spin_unlock_irqrestore(&counter->lock, flags); 507 spin_unlock_irqrestore(&counter->lock, flags);
508} 508}
509EXPORT_SYMBOL_GPL(ni_tio_handle_interrupt);
509 510
510void ni_tio_set_mite_channel(struct ni_gpct *counter, 511void ni_tio_set_mite_channel(struct ni_gpct *counter,
511 struct mite_channel *mite_chan) 512 struct mite_channel *mite_chan)
@@ -516,6 +517,7 @@ void ni_tio_set_mite_channel(struct ni_gpct *counter,
516 counter->mite_chan = mite_chan; 517 counter->mite_chan = mite_chan;
517 spin_unlock_irqrestore(&counter->lock, flags); 518 spin_unlock_irqrestore(&counter->lock, flags);
518} 519}
520EXPORT_SYMBOL_GPL(ni_tio_set_mite_channel);
519 521
520static int __init ni_tiocmd_init_module(void) 522static int __init ni_tiocmd_init_module(void)
521{ 523{
@@ -529,10 +531,3 @@ static void __exit ni_tiocmd_cleanup_module(void)
529} 531}
530 532
531module_exit(ni_tiocmd_cleanup_module); 533module_exit(ni_tiocmd_cleanup_module);
532
533EXPORT_SYMBOL_GPL(ni_tio_cmd);
534EXPORT_SYMBOL_GPL(ni_tio_cmdtest);
535EXPORT_SYMBOL_GPL(ni_tio_cancel);
536EXPORT_SYMBOL_GPL(ni_tio_handle_interrupt);
537EXPORT_SYMBOL_GPL(ni_tio_set_mite_channel);
538EXPORT_SYMBOL_GPL(ni_tio_acknowledge_and_confirm);
diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c
index 60ebfc3c75fd..aa8aeeee043f 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -753,7 +753,7 @@ static int rtd_attach(struct comedi_device *dev, struct comedi_devconfig *it)
753 struct comedi_subdevice *s; 753 struct comedi_subdevice *s;
754 struct pci_dev *pcidev; 754 struct pci_dev *pcidev;
755 int ret; 755 int ret;
756 resource_size_t physLas0; /* configuation */ 756 resource_size_t physLas0; /* configuration */
757 resource_size_t physLas1; /* data area */ 757 resource_size_t physLas1; /* data area */
758 resource_size_t physLcfg; /* PLX9080 */ 758 resource_size_t physLcfg; /* PLX9080 */
759#ifdef USE_DMA 759#ifdef USE_DMA
diff --git a/drivers/staging/comedi/drivers/s526.c b/drivers/staging/comedi/drivers/s526.c
index 3607aaee4af6..2b34daedc3d7 100644
--- a/drivers/staging/comedi/drivers/s526.c
+++ b/drivers/staging/comedi/drivers/s526.c
@@ -114,7 +114,7 @@ static const int s526_ports[] = {
114}; 114};
115 115
116struct counter_mode_register_t { 116struct counter_mode_register_t {
117#if defined (__LITTLE_ENDIAN_BITFIELD) 117#if defined(__LITTLE_ENDIAN_BITFIELD)
118 unsigned short coutSource:1; 118 unsigned short coutSource:1;
119 unsigned short coutPolarity:1; 119 unsigned short coutPolarity:1;
120 unsigned short autoLoadResetRcap:3; 120 unsigned short autoLoadResetRcap:3;
@@ -207,7 +207,9 @@ static const struct s526_board s526_boards[] = {
207 207
208/* this structure is for data unique to this hardware driver. If 208/* this structure is for data unique to this hardware driver. If
209 several hardware drivers keep similar information in this structure, 209 several hardware drivers keep similar information in this structure,
210 feel free to suggest moving the variable to the struct comedi_device struct. */ 210 feel free to suggest moving the variable to the struct comedi_device
211 struct.
212*/
211struct s526_private { 213struct s526_private {
212 214
213 int data; 215 int data;
@@ -304,7 +306,7 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
304/* int subdev_channel = 0; */ 306/* int subdev_channel = 0; */
305 union cmReg cmReg; 307 union cmReg cmReg;
306 308
307 printk("comedi%d: s526: ", dev->minor); 309 printk(KERN_INFO "comedi%d: s526: ", dev->minor);
308 310
309 iobase = it->options[0]; 311 iobase = it->options[0];
310 if (!iobase || !request_region(iobase, S526_IOSIZE, thisboard->name)) { 312 if (!iobase || !request_region(iobase, S526_IOSIZE, thisboard->name)) {
@@ -317,7 +319,8 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
317 319
318 /*** make it a little quieter, exw, 8/29/06 320 /*** make it a little quieter, exw, 8/29/06
319 for (i = 0; i < S526_NUM_PORTS; i++) { 321 for (i = 0; i < S526_NUM_PORTS; i++) {
320 printk("0x%02x: 0x%04x\n", ADDR_REG(s526_ports[i]), inw(ADDR_REG(s526_ports[i]))); 322 printk("0x%02x: 0x%04x\n", ADDR_REG(s526_ports[i]),
323 inw(ADDR_REG(s526_ports[i])));
321 } 324 }
322 ***/ 325 ***/
323 326
@@ -402,7 +405,7 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
402 s->type = COMEDI_SUBD_UNUSED; 405 s->type = COMEDI_SUBD_UNUSED;
403 } 406 }
404 407
405 printk("attached\n"); 408 printk(KERN_INFO "attached\n");
406 409
407 return 1; 410 return 1;
408 411
@@ -411,7 +414,7 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
411 /* One-shot (software trigger) */ 414 /* One-shot (software trigger) */
412 cmReg.reg.coutSource = 0; /* out RCAP */ 415 cmReg.reg.coutSource = 0; /* out RCAP */
413 cmReg.reg.coutPolarity = 1; /* Polarity inverted */ 416 cmReg.reg.coutPolarity = 1; /* Polarity inverted */
414 cmReg.reg.autoLoadResetRcap = 1; /* Auto load 0:disabled, 1:enabled */ 417 cmReg.reg.autoLoadResetRcap = 1;/* Auto load 0:disabled, 1:enabled */
415 cmReg.reg.hwCtEnableSource = 3; /* NOT RCAP */ 418 cmReg.reg.hwCtEnableSource = 3; /* NOT RCAP */
416 cmReg.reg.ctEnableCtrl = 2; /* Hardware */ 419 cmReg.reg.ctEnableCtrl = 2; /* Hardware */
417 cmReg.reg.clockSource = 2; /* Internal */ 420 cmReg.reg.clockSource = 2; /* Internal */
@@ -426,10 +429,12 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
426 outw(0x0001, ADDR_CHAN_REG(REG_C0H, subdev_channel)); 429 outw(0x0001, ADDR_CHAN_REG(REG_C0H, subdev_channel));
427 outw(0x3C68, ADDR_CHAN_REG(REG_C0L, subdev_channel)); 430 outw(0x3C68, ADDR_CHAN_REG(REG_C0L, subdev_channel));
428 431
429 outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); /* Reset the counter */ 432 /* Reset the counter */
430 outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); /* Load the counter from PR0 */ 433 outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
431 434 /* Load the counter from PR0 */
432 outw(0x0008, ADDR_CHAN_REG(REG_C0C, subdev_channel)); /* Reset RCAP (fires one-shot) */ 435 outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
436 /* Reset RCAP (fires one-shot) */
437 outw(0x0008, ADDR_CHAN_REG(REG_C0C, subdev_channel));
433 438
434#else 439#else
435 440
@@ -447,11 +452,12 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
447 cmReg.reg.reserved = 0; 452 cmReg.reg.reserved = 0;
448 453
449 n = 0; 454 n = 0;
450 printk("Mode reg=0x%04x, 0x%04lx\n", cmReg.value, ADDR_CHAN_REG(REG_C0M, 455 printk(KERN_INFO "Mode reg=0x%04x, 0x%04lx\n",
451 n)); 456 cmReg.value, ADDR_CHAN_REG(REG_C0M, n));
452 outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n)); 457 outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n));
453 udelay(1000); 458 udelay(1000);
454 printk("Read back mode reg=0x%04x\n", inw(ADDR_CHAN_REG(REG_C0M, n))); 459 printk(KERN_INFO "Read back mode reg=0x%04x\n",
460 inw(ADDR_CHAN_REG(REG_C0M, n)));
455 461
456 /* Load the pre-load register high word */ 462 /* Load the pre-load register high word */
457/* value = (short) (0x55); */ 463/* value = (short) (0x55); */
@@ -466,20 +472,23 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
466 472
467 /* Reset the counter if it is software preload */ 473 /* Reset the counter if it is software preload */
468 if (cmReg.reg.autoLoadResetRcap == 0) { 474 if (cmReg.reg.autoLoadResetRcap == 0) {
469 outw(0x8000, ADDR_CHAN_REG(REG_C0C, n)); /* Reset the counter */ 475 /* Reset the counter */
470 outw(0x4000, ADDR_CHAN_REG(REG_C0C, n)); /* Load the counter from PR0 */ 476 outw(0x8000, ADDR_CHAN_REG(REG_C0C, n));
477 /* Load the counter from PR0 */
478 outw(0x4000, ADDR_CHAN_REG(REG_C0C, n));
471 } 479 }
472 480
473 outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n)); 481 outw(cmReg.value, ADDR_CHAN_REG(REG_C0M, n));
474 udelay(1000); 482 udelay(1000);
475 printk("Read back mode reg=0x%04x\n", inw(ADDR_CHAN_REG(REG_C0M, n))); 483 printk(KERN_INFO "Read back mode reg=0x%04x\n",
484 inw(ADDR_CHAN_REG(REG_C0M, n)));
476 485
477#endif 486#endif
478 printk("Current registres:\n"); 487 printk(KERN_INFO "Current registres:\n");
479 488
480 for (i = 0; i < S526_NUM_PORTS; i++) { 489 for (i = 0; i < S526_NUM_PORTS; i++) {
481 printk("0x%02lx: 0x%04x\n", ADDR_REG(s526_ports[i]), 490 printk(KERN_INFO "0x%02lx: 0x%04x\n",
482 inw(ADDR_REG(s526_ports[i]))); 491 ADDR_REG(s526_ports[i]), inw(ADDR_REG(s526_ports[i])));
483 } 492 }
484 return 1; 493 return 1;
485} 494}
@@ -494,7 +503,7 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
494 */ 503 */
495static int s526_detach(struct comedi_device *dev) 504static int s526_detach(struct comedi_device *dev)
496{ 505{
497 printk("comedi%d: s526: remove\n", dev->minor); 506 printk(KERN_INFO "comedi%d: s526: remove\n", dev->minor);
498 507
499 if (dev->iobase > 0) 508 if (dev->iobase > 0)
500 release_region(dev->iobase, S526_IOSIZE); 509 release_region(dev->iobase, S526_IOSIZE);
@@ -513,7 +522,7 @@ static int s526_gpct_rinsn(struct comedi_device *dev,
513 522
514 /* Check if (n > 0) */ 523 /* Check if (n > 0) */
515 if (insn->n <= 0) { 524 if (insn->n <= 0) {
516 printk("s526: INSN_READ: n should be > 0\n"); 525 printk(KERN_ERR "s526: INSN_READ: n should be > 0\n");
517 return -EINVAL; 526 return -EINVAL;
518 } 527 }
519 /* Read the low word first */ 528 /* Read the low word first */
@@ -522,7 +531,8 @@ static int s526_gpct_rinsn(struct comedi_device *dev,
522 datahigh = inw(ADDR_CHAN_REG(REG_C0H, counter_channel)); 531 datahigh = inw(ADDR_CHAN_REG(REG_C0H, counter_channel));
523 data[i] = (int)(datahigh & 0x00FF); 532 data[i] = (int)(datahigh & 0x00FF);
524 data[i] = (data[i] << 16) | (datalow & 0xFFFF); 533 data[i] = (data[i] << 16) | (datalow & 0xFFFF);
525/* printk("s526 GPCT[%d]: %x(0x%04x, 0x%04x)\n", counter_channel, data[i], datahigh, datalow); */ 534 /* printk("s526 GPCT[%d]: %x(0x%04x, 0x%04x)\n",
535 counter_channel, data[i], datahigh, datalow); */
526 } 536 }
527 return i; 537 return i;
528} 538}
@@ -536,7 +546,8 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
536 short value; 546 short value;
537 union cmReg cmReg; 547 union cmReg cmReg;
538 548
539/* printk("s526: GPCT_INSN_CONFIG: Configuring Channel %d\n", subdev_channel); */ 549 /* printk("s526: GPCT_INSN_CONFIG: Configuring Channel %d\n",
550 subdev_channel); */
540 551
541 for (i = 0; i < MAX_GPCT_CONFIG_DATA; i++) { 552 for (i = 0; i < MAX_GPCT_CONFIG_DATA; i++) {
542 devpriv->s526_gpct_config[subdev_channel].data[i] = 553 devpriv->s526_gpct_config[subdev_channel].data[i] =
@@ -554,7 +565,7 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
554 data[2]: Pre-load Register Value 565 data[2]: Pre-load Register Value
555 data[3]: Conter Control Register 566 data[3]: Conter Control Register
556 */ 567 */
557 printk("s526: GPCT_INSN_CONFIG: Configuring Encoder\n"); 568 printk(KERN_INFO "s526: GPCT_INSN_CONFIG: Configuring Encoder\n");
558 devpriv->s526_gpct_config[subdev_channel].app = 569 devpriv->s526_gpct_config[subdev_channel].app =
559 PositionMeasurement; 570 PositionMeasurement;
560 571
@@ -563,7 +574,7 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
563 /* One-shot (software trigger) */ 574 /* One-shot (software trigger) */
564 cmReg.reg.coutSource = 0; /* out RCAP */ 575 cmReg.reg.coutSource = 0; /* out RCAP */
565 cmReg.reg.coutPolarity = 1; /* Polarity inverted */ 576 cmReg.reg.coutPolarity = 1; /* Polarity inverted */
566 cmReg.reg.autoLoadResetRcap = 0; /* Auto load disabled */ 577 cmReg.reg.autoLoadResetRcap = 0;/* Auto load disabled */
567 cmReg.reg.hwCtEnableSource = 3; /* NOT RCAP */ 578 cmReg.reg.hwCtEnableSource = 3; /* NOT RCAP */
568 cmReg.reg.ctEnableCtrl = 2; /* Hardware */ 579 cmReg.reg.ctEnableCtrl = 2; /* Hardware */
569 cmReg.reg.clockSource = 2; /* Internal */ 580 cmReg.reg.clockSource = 2; /* Internal */
@@ -578,10 +589,13 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
578 outw(0x0001, ADDR_CHAN_REG(REG_C0H, subdev_channel)); 589 outw(0x0001, ADDR_CHAN_REG(REG_C0H, subdev_channel));
579 outw(0x3C68, ADDR_CHAN_REG(REG_C0L, subdev_channel)); 590 outw(0x3C68, ADDR_CHAN_REG(REG_C0L, subdev_channel));
580 591
581 outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); /* Reset the counter */ 592 /* Reset the counter */
582 outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); /* Load the counter from PR0 */ 593 outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
594 /* Load the counter from PR0 */
595 outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
583 596
584 outw(0x0008, ADDR_CHAN_REG(REG_C0C, subdev_channel)); /* Reset RCAP (fires one-shot) */ 597 /* Reset RCAP (fires one-shot) */
598 outw(0x0008, ADDR_CHAN_REG(REG_C0C, subdev_channel));
585 599
586#endif 600#endif
587 601
@@ -594,30 +608,34 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
594 608
595 /* Reset the counter if it is software preload */ 609 /* Reset the counter if it is software preload */
596 if (cmReg.reg.autoLoadResetRcap == 0) { 610 if (cmReg.reg.autoLoadResetRcap == 0) {
597 outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); /* Reset the counter */ 611 /* Reset the counter */
598/* outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); Load the counter from PR0 */ 612 outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
613 /* Load the counter from PR0
614 * outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
615 */
599 } 616 }
600#else 617#else
601 cmReg.reg.countDirCtrl = 0; /* 0 quadrature, 1 software control */ 618 /* 0 quadrature, 1 software control */
619 cmReg.reg.countDirCtrl = 0;
602 620
603 /* data[1] contains GPCT_X1, GPCT_X2 or GPCT_X4 */ 621 /* data[1] contains GPCT_X1, GPCT_X2 or GPCT_X4 */
604 if (insn->data[1] == GPCT_X2) { 622 if (insn->data[1] == GPCT_X2)
605 cmReg.reg.clockSource = 1; 623 cmReg.reg.clockSource = 1;
606 } else if (insn->data[1] == GPCT_X4) { 624 else if (insn->data[1] == GPCT_X4)
607 cmReg.reg.clockSource = 2; 625 cmReg.reg.clockSource = 2;
608 } else { 626 else
609 cmReg.reg.clockSource = 0; 627 cmReg.reg.clockSource = 0;
610 }
611 628
612 /* When to take into account the indexpulse: */ 629 /* When to take into account the indexpulse: */
613 if (insn->data[2] == GPCT_IndexPhaseLowLow) { 630 /*if (insn->data[2] == GPCT_IndexPhaseLowLow) {
614 } else if (insn->data[2] == GPCT_IndexPhaseLowHigh) { 631 } else if (insn->data[2] == GPCT_IndexPhaseLowHigh) {
615 } else if (insn->data[2] == GPCT_IndexPhaseHighLow) { 632 } else if (insn->data[2] == GPCT_IndexPhaseHighLow) {
616 } else if (insn->data[2] == GPCT_IndexPhaseHighHigh) { 633 } else if (insn->data[2] == GPCT_IndexPhaseHighHigh) {
617 } 634 }*/
618 /* Take into account the index pulse? */ 635 /* Take into account the index pulse? */
619 if (insn->data[3] == GPCT_RESET_COUNTER_ON_INDEX) 636 if (insn->data[3] == GPCT_RESET_COUNTER_ON_INDEX)
620 cmReg.reg.autoLoadResetRcap = 4; /* Auto load with INDEX^ */ 637 /* Auto load with INDEX^ */
638 cmReg.reg.autoLoadResetRcap = 4;
621 639
622 /* Set Counter Mode Register */ 640 /* Set Counter Mode Register */
623 cmReg.value = (short)(insn->data[1] & 0xFFFF); 641 cmReg.value = (short)(insn->data[1] & 0xFFFF);
@@ -638,8 +656,10 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
638 } 656 }
639 /* Reset the counter if it is software preload */ 657 /* Reset the counter if it is software preload */
640 if (cmReg.reg.autoLoadResetRcap == 0) { 658 if (cmReg.reg.autoLoadResetRcap == 0) {
641 outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); /* Reset the counter */ 659 /* Reset the counter */
642 outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel)); /* Load the counter from PR0 */ 660 outw(0x8000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
661 /* Load the counter from PR0 */
662 outw(0x4000, ADDR_CHAN_REG(REG_C0C, subdev_channel));
643 } 663 }
644#endif 664#endif
645 break; 665 break;
@@ -652,7 +672,7 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
652 data[3]: Pre-load Register 1 Value 672 data[3]: Pre-load Register 1 Value
653 data[4]: Conter Control Register 673 data[4]: Conter Control Register
654 */ 674 */
655 printk("s526: GPCT_INSN_CONFIG: Configuring SPG\n"); 675 printk(KERN_INFO "s526: GPCT_INSN_CONFIG: Configuring SPG\n");
656 devpriv->s526_gpct_config[subdev_channel].app = 676 devpriv->s526_gpct_config[subdev_channel].app =
657 SinglePulseGeneration; 677 SinglePulseGeneration;
658 678
@@ -697,7 +717,7 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
697 data[3]: Pre-load Register 1 Value 717 data[3]: Pre-load Register 1 Value
698 data[4]: Conter Control Register 718 data[4]: Conter Control Register
699 */ 719 */
700 printk("s526: GPCT_INSN_CONFIG: Configuring PTG\n"); 720 printk(KERN_INFO "s526: GPCT_INSN_CONFIG: Configuring PTG\n");
701 devpriv->s526_gpct_config[subdev_channel].app = 721 devpriv->s526_gpct_config[subdev_channel].app =
702 PulseTrainGeneration; 722 PulseTrainGeneration;
703 723
@@ -735,7 +755,7 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
735 break; 755 break;
736 756
737 default: 757 default:
738 printk("s526: unsupported GPCT_insn_config\n"); 758 printk(KERN_ERR "s526: unsupported GPCT_insn_config\n");
739 return -EINVAL; 759 return -EINVAL;
740 break; 760 break;
741 } 761 }
@@ -751,20 +771,21 @@ static int s526_gpct_winsn(struct comedi_device *dev,
751 short value; 771 short value;
752 union cmReg cmReg; 772 union cmReg cmReg;
753 773
754 printk("s526: GPCT_INSN_WRITE on channel %d\n", subdev_channel); 774 printk(KERN_INFO "s526: GPCT_INSN_WRITE on channel %d\n",
775 subdev_channel);
755 cmReg.value = inw(ADDR_CHAN_REG(REG_C0M, subdev_channel)); 776 cmReg.value = inw(ADDR_CHAN_REG(REG_C0M, subdev_channel));
756 printk("s526: Counter Mode Register: %x\n", cmReg.value); 777 printk(KERN_INFO "s526: Counter Mode Register: %x\n", cmReg.value);
757 /* Check what Application of Counter this channel is configured for */ 778 /* Check what Application of Counter this channel is configured for */
758 switch (devpriv->s526_gpct_config[subdev_channel].app) { 779 switch (devpriv->s526_gpct_config[subdev_channel].app) {
759 case PositionMeasurement: 780 case PositionMeasurement:
760 printk("S526: INSN_WRITE: PM\n"); 781 printk(KERN_INFO "S526: INSN_WRITE: PM\n");
761 outw(0xFFFF & ((*data) >> 16), ADDR_CHAN_REG(REG_C0H, 782 outw(0xFFFF & ((*data) >> 16), ADDR_CHAN_REG(REG_C0H,
762 subdev_channel)); 783 subdev_channel));
763 outw(0xFFFF & (*data), ADDR_CHAN_REG(REG_C0L, subdev_channel)); 784 outw(0xFFFF & (*data), ADDR_CHAN_REG(REG_C0L, subdev_channel));
764 break; 785 break;
765 786
766 case SinglePulseGeneration: 787 case SinglePulseGeneration:
767 printk("S526: INSN_WRITE: SPG\n"); 788 printk(KERN_INFO "S526: INSN_WRITE: SPG\n");
768 outw(0xFFFF & ((*data) >> 16), ADDR_CHAN_REG(REG_C0H, 789 outw(0xFFFF & ((*data) >> 16), ADDR_CHAN_REG(REG_C0H,
769 subdev_channel)); 790 subdev_channel));
770 outw(0xFFFF & (*data), ADDR_CHAN_REG(REG_C0L, subdev_channel)); 791 outw(0xFFFF & (*data), ADDR_CHAN_REG(REG_C0L, subdev_channel));
@@ -777,14 +798,14 @@ static int s526_gpct_winsn(struct comedi_device *dev,
777 The above periods must be expressed as a multiple of the 798 The above periods must be expressed as a multiple of the
778 pulse frequency on the selected source 799 pulse frequency on the selected source
779 */ 800 */
780 printk("S526: INSN_WRITE: PTG\n"); 801 printk(KERN_INFO "S526: INSN_WRITE: PTG\n");
781 if ((insn->data[1] > insn->data[0]) && (insn->data[0] > 0)) { 802 if ((insn->data[1] > insn->data[0]) && (insn->data[0] > 0)) {
782 (devpriv->s526_gpct_config[subdev_channel]).data[0] = 803 (devpriv->s526_gpct_config[subdev_channel]).data[0] =
783 insn->data[0]; 804 insn->data[0];
784 (devpriv->s526_gpct_config[subdev_channel]).data[1] = 805 (devpriv->s526_gpct_config[subdev_channel]).data[1] =
785 insn->data[1]; 806 insn->data[1];
786 } else { 807 } else {
787 printk("s526: INSN_WRITE: PTG: Problem with Pulse params -> %d %d\n", 808 printk(KERN_ERR "s526: INSN_WRITE: PTG: Problem with Pulse params -> %d %d\n",
788 insn->data[0], insn->data[1]); 809 insn->data[0], insn->data[1]);
789 return -EINVAL; 810 return -EINVAL;
790 } 811 }
@@ -873,7 +894,7 @@ static int s526_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
873 if (i == TIMEOUT) { 894 if (i == TIMEOUT) {
874 /* printk() should be used instead of printk() 895 /* printk() should be used instead of printk()
875 * whenever the code can be called from real-time. */ 896 * whenever the code can be called from real-time. */
876 printk("s526: ADC(0x%04x) timeout\n", 897 printk(KERN_ERR "s526: ADC(0x%04x) timeout\n",
877 inw(ADDR_REG(REG_ISR))); 898 inw(ADDR_REG(REG_ISR)));
878 return -ETIMEDOUT; 899 return -ETIMEDOUT;
879 } 900 }
@@ -906,11 +927,14 @@ static int s526_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
906 * very useful, but that's how the interface is defined. */ 927 * very useful, but that's how the interface is defined. */
907 for (i = 0; i < insn->n; i++) { 928 for (i = 0; i < insn->n; i++) {
908 /* a typical programming sequence */ 929 /* a typical programming sequence */
909/* outw(data[i], dev->iobase + REG_ADD); write the data to preload register */ 930 /* write the data to preload register
910 outw(data[i], ADDR_REG(REG_ADD)); /* write the data to preload register */ 931 * outw(data[i], dev->iobase + REG_ADD);
932 */
933 /* write the data to preload register */
934 outw(data[i], ADDR_REG(REG_ADD));
911 devpriv->ao_readback[chan] = data[i]; 935 devpriv->ao_readback[chan] = data[i];
912/* outw(val + 1, dev->iobase + REG_DAC); starts the D/A conversion. */ 936/* outw(val + 1, dev->iobase + REG_DAC); starts the D/A conversion. */
913 outw(val + 1, ADDR_REG(REG_DAC)); /* starts the D/A conversion. */ 937 outw(val + 1, ADDR_REG(REG_DAC)); /*starts the D/A conversion.*/
914 } 938 }
915 939
916 /* return the number of samples read/written */ 940 /* return the number of samples read/written */
@@ -954,7 +978,7 @@ static int s526_dio_insn_bits(struct comedi_device *dev,
954 978
955 /* on return, data[1] contains the value of the digital 979 /* on return, data[1] contains the value of the digital
956 * input and output lines. */ 980 * input and output lines. */
957 data[1] = inw(ADDR_REG(REG_DIO)) & 0xFF; /* low 8 bits are the data */ 981 data[1] = inw(ADDR_REG(REG_DIO)) & 0xFF; /* low 8 bits are the data */
958 /* or we could just return the software copy of the output values if 982 /* or we could just return the software copy of the output values if
959 * it was a purely digital output subdevice */ 983 * it was a purely digital output subdevice */
960 /* data[1]=s->state & 0xFF; */ 984 /* data[1]=s->state & 0xFF; */
@@ -969,7 +993,7 @@ static int s526_dio_insn_config(struct comedi_device *dev,
969 int chan = CR_CHAN(insn->chanspec); 993 int chan = CR_CHAN(insn->chanspec);
970 int group, mask; 994 int group, mask;
971 995
972 printk("S526 DIO insn_config\n"); 996 printk(KERN_INFO "S526 DIO insn_config\n");
973 997
974 /* The input or output configuration of each digital line is 998 /* The input or output configuration of each digital line is
975 * configured by a special insn_config instruction. chanspec 999 * configured by a special insn_config instruction. chanspec
@@ -980,11 +1004,12 @@ static int s526_dio_insn_config(struct comedi_device *dev,
980 mask = 0xF << (group << 2); 1004 mask = 0xF << (group << 2);
981 switch (data[0]) { 1005 switch (data[0]) {
982 case INSN_CONFIG_DIO_OUTPUT: 1006 case INSN_CONFIG_DIO_OUTPUT:
983 s->state |= 1 << (group + 10); // bit 10/11 set the group 1/2's mode 1007 /* bit 10/11 set the group 1/2's mode */
1008 s->state |= 1 << (group + 10);
984 s->io_bits |= mask; 1009 s->io_bits |= mask;
985 break; 1010 break;
986 case INSN_CONFIG_DIO_INPUT: 1011 case INSN_CONFIG_DIO_INPUT:
987 s->state &= ~(1 << (group + 10));// 1 is output, 0 is input. 1012 s->state &= ~(1 << (group + 10)); /* 1 is output, 0 is input. */
988 s->io_bits &= ~mask; 1013 s->io_bits &= ~mask;
989 break; 1014 break;
990 case INSN_CONFIG_DIO_QUERY: 1015 case INSN_CONFIG_DIO_QUERY:
diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c
index de784ff08caa..696ee045e25f 100644
--- a/drivers/staging/comedi/drivers/usbdux.c
+++ b/drivers/staging/comedi/drivers/usbdux.c
@@ -2398,7 +2398,7 @@ static int usbduxsub_probe(struct usb_interface *uinterf,
2398 usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL); 2398 usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL);
2399 if (!usbduxsub[index].dux_commands) { 2399 if (!usbduxsub[index].dux_commands) {
2400 dev_err(dev, "comedi_: usbdux: " 2400 dev_err(dev, "comedi_: usbdux: "
2401 "error alloc space for dac commands\n"); 2401 "error alloc space for dux commands\n");
2402 tidy_up(&(usbduxsub[index])); 2402 tidy_up(&(usbduxsub[index]));
2403 up(&start_stop_sem); 2403 up(&start_stop_sem);
2404 return -ENOMEM; 2404 return -ENOMEM;
diff --git a/drivers/staging/cptm1217/Kconfig b/drivers/staging/cptm1217/Kconfig
new file mode 100644
index 000000000000..43b1cc0a50a5
--- /dev/null
+++ b/drivers/staging/cptm1217/Kconfig
@@ -0,0 +1,12 @@
1config TOUCHSCREEN_CLEARPAD_TM1217
2 tristate "Synaptics Clearpad TM1217"
3 depends on I2C
4 depends on GPIOLIB
5 depends on INPUT
6 help
7 Say Y here if you have a Synaptics Clearpad TM1217 Controller
8
9 If unsure, say N.
10
11 To compile this driver as a module, choose M here: the
12 module will be called clearpad_tm1217.
diff --git a/drivers/staging/cptm1217/Makefile b/drivers/staging/cptm1217/Makefile
new file mode 100644
index 000000000000..8961fafa80e7
--- /dev/null
+++ b/drivers/staging/cptm1217/Makefile
@@ -0,0 +1,2 @@
1obj-$(CONFIG_TOUCHSCREEN_CLEARPAD_TM1217) += clearpad_tm1217.o
2
diff --git a/drivers/staging/cptm1217/TODO b/drivers/staging/cptm1217/TODO
new file mode 100644
index 000000000000..303922465e4d
--- /dev/null
+++ b/drivers/staging/cptm1217/TODO
@@ -0,0 +1,5 @@
1- Wait for the official upstream general clearpad drivers as promised over
2 the past few months
3- Merge any device support needed from this driver into it
4- Delete this driver
5
diff --git a/drivers/staging/cptm1217/clearpad_tm1217.c b/drivers/staging/cptm1217/clearpad_tm1217.c
new file mode 100644
index 000000000000..76e4b782d2fb
--- /dev/null
+++ b/drivers/staging/cptm1217/clearpad_tm1217.c
@@ -0,0 +1,675 @@
1/*
2 * clearpad_tm1217.c - Touch Screen driver for Synaptics Clearpad
3 * TM1217 controller
4 *
5 * Copyright (C) 2008 Intel Corp
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; ifnot, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * Questions/Comments/Bug fixes to Ramesh Agarwal (ramesh.agarwal@intel.com)
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26#include <linux/module.h>
27#include <linux/kernel.h>
28#include <linux/input.h>
29#include <linux/interrupt.h>
30#include <linux/io.h>
31#include <linux/i2c.h>
32#include <linux/timer.h>
33#include <linux/gpio.h>
34#include <linux/hrtimer.h>
35#include <linux/kthread.h>
36#include <linux/delay.h>
37#include <linux/slab.h>
38#include "cp_tm1217.h"
39
40#define CPTM1217_DEVICE_NAME "cptm1217"
41#define CPTM1217_DRIVER_NAME CPTM1217_DEVICE_NAME
42
43#define MAX_TOUCH_SUPPORTED 2
44#define TOUCH_SUPPORTED 1
45#define SAMPLING_FREQ 80 /* Frequency in HZ */
46#define DELAY_BTWIN_SAMPLE (1000 / SAMPLING_FREQ)
47#define WAIT_FOR_RESPONSE 5 /* 5msec just works */
48#define MAX_RETRIES 5 /* As above */
49#define INCREMENTAL_DELAY 5 /* As above */
50
51/* Regster Definitions */
52#define TMA1217_DEV_STATUS 0x13 /* Device Status */
53#define TMA1217_INT_STATUS 0x14 /* Interrupt Status */
54
55/* Controller can detect upto 2 possible finger touches.
56 * Each finger touch provides 12 bit X Y co-ordinates, the values are split
57 * across 2 registers, and an 8 bit Z value */
58#define TMA1217_FINGER_STATE 0x18 /* Finger State */
59#define TMA1217_FINGER1_X_HIGHER8 0x19 /* Higher 8 bit of X coordinate */
60#define TMA1217_FINGER1_Y_HIGHER8 0x1A /* Higher 8 bit of Y coordinate */
61#define TMA1217_FINGER1_XY_LOWER4 0x1B /* Lower 4 bits of X and Y */
62#define TMA1217_FINGER1_Z_VALUE 0x1D /* 8 bit Z value for finger 1 */
63#define TMA1217_FINGER2_X_HIGHER8 0x1E /* Higher 8 bit of X coordinate */
64#define TMA1217_FINGER2_Y_HIGHER8 0x1F /* Higher 8 bit of Y coordinate */
65#define TMA1217_FINGER2_XY_LOWER4 0x20 /* Lower 4 bits of X and Y */
66#define TMA1217_FINGER2_Z_VALUE 0x22 /* 8 bit Z value for finger 2 */
67#define TMA1217_DEVICE_CTRL 0x23 /* Device Control */
68#define TMA1217_INTERRUPT_ENABLE 0x24 /* Interrupt Enable */
69#define TMA1217_REPORT_MODE 0x2B /* Reporting Mode */
70#define TMA1217_MAX_X_LOWER8 0x31 /* Bit 0-7 for Max X */
71#define TMA1217_MAX_X_HIGHER4 0x32 /* Bit 8-11 for Max X */
72#define TMA1217_MAX_Y_LOWER8 0x33 /* Bit 0-7 for Max Y */
73#define TMA1217_MAX_Y_HIGHER4 0x34 /* Bit 8-11 for Max Y */
74#define TMA1217_DEVICE_CMD_RESET 0x67 /* Device CMD reg for reset */
75#define TMA1217_DEVICE_CMD_REZERO 0x69 /* Device CMD reg for rezero */
76
77#define TMA1217_MANUFACTURER_ID 0x73 /* Manufacturer Id */
78#define TMA1217_PRODUCT_FAMILY 0x75 /* Product Family */
79#define TMA1217_FIRMWARE_REVISION 0x76 /* Firmware Revision */
80#define TMA1217_SERIAL_NO_HIGH 0x7C /* Bit 8-15 of device serial no. */
81#define TMA1217_SERIAL_NO_LOW 0x7D /* Bit 0-7 of device serial no. */
82#define TMA1217_PRODUCT_ID_START 0x7E /* Start address for 10 byte ID */
83#define TMA1217_DEVICE_CAPABILITY 0x8B /* Reporting capability */
84
85
86/*
87 * The touch position structure.
88 */
89struct touch_state {
90 int x;
91 int y;
92 bool button;
93};
94
95/* Device Specific info given by the controller */
96struct cp_dev_info {
97 u16 maxX;
98 u16 maxY;
99};
100
101/* Vendor related info given by the controller */
102struct cp_vendor_info {
103 u8 vendor_id;
104 u8 product_family;
105 u8 firmware_rev;
106 u16 serial_no;
107};
108
109/*
110 * Private structure to store the device details
111 */
112struct cp_tm1217_device {
113 struct i2c_client *client;
114 struct device *dev;
115 struct cp_vendor_info vinfo;
116 struct cp_dev_info dinfo;
117 struct input_dev_info {
118 char phys[32];
119 char name[128];
120 struct input_dev *input;
121 struct touch_state touch;
122 } cp_input_info[MAX_TOUCH_SUPPORTED];
123
124 int thread_running;
125 struct mutex thread_mutex;
126
127 int gpio;
128};
129
130
131/* The following functions are used to read/write registers on the device
132 * as per the RMI prorocol. Technically, a page select should be written
133 * before doing read/write but since the register offsets are below 0xFF
134 * we can use the default value of page which is 0x00
135 */
136static int cp_tm1217_read(struct cp_tm1217_device *ts,
137 u8 *req, int size)
138{
139 int i, retval;
140
141 /* Send the address */
142 retval = i2c_master_send(ts->client, &req[0], 1);
143 if (retval != 1) {
144 dev_err(ts->dev, "cp_tm1217: I2C send failed\n");
145 return retval;
146 }
147 msleep(WAIT_FOR_RESPONSE);
148 for (i = 0; i < MAX_RETRIES; i++) {
149 retval = i2c_master_recv(ts->client, &req[1], size);
150 if (retval == size) {
151 break;
152 } else {
153 msleep(INCREMENTAL_DELAY);
154 dev_dbg(ts->dev, "cp_tm1217: Retry count is %d\n", i);
155 }
156 }
157 if (retval != size)
158 dev_err(ts->dev, "cp_tm1217: Read from device failed\n");
159
160 return retval;
161}
162
163static int cp_tm1217_write(struct cp_tm1217_device *ts,
164 u8 *req, int size)
165{
166 int retval;
167
168 /* Send the address and the data to be written */
169 retval = i2c_master_send(ts->client, &req[0], size + 1);
170 if (retval != size + 1) {
171 dev_err(ts->dev, "cp_tm1217: I2C write failed: %d\n", retval);
172 return retval;
173 }
174 /* Wait for the write to complete. TBD why this is required */
175 msleep(WAIT_FOR_RESPONSE);
176
177 return size;
178}
179
180static int cp_tm1217_mask_interrupt(struct cp_tm1217_device *ts)
181{
182 u8 req[2];
183 int retval;
184
185 req[0] = TMA1217_INTERRUPT_ENABLE;
186 req[1] = 0x0;
187 retval = cp_tm1217_write(ts, req, 1);
188 if (retval != 1)
189 return -EIO;
190
191 return 0;
192}
193
194static int cp_tm1217_unmask_interrupt(struct cp_tm1217_device *ts)
195{
196 u8 req[2];
197 int retval;
198
199 req[0] = TMA1217_INTERRUPT_ENABLE;
200 req[1] = 0xa;
201 retval = cp_tm1217_write(ts, req, 1);
202 if (retval != 1)
203 return -EIO;
204
205 return 0;
206}
207
208static void process_touch(struct cp_tm1217_device *ts, int index)
209{
210 int retval;
211 struct input_dev_info *input_info =
212 (struct input_dev_info *)&ts->cp_input_info[index];
213 u8 xy_data[6];
214
215 if (index == 0)
216 xy_data[0] = TMA1217_FINGER1_X_HIGHER8;
217 else
218 xy_data[0] = TMA1217_FINGER2_X_HIGHER8;
219
220 retval = cp_tm1217_read(ts, xy_data, 5);
221 if (retval < 5) {
222 dev_err(ts->dev, "cp_tm1217: XY read from device failed\n");
223 return;
224 }
225
226 /* Note: Currently not using the Z values but may be requried in
227 the future. */
228 input_info->touch.x = (xy_data[1] << 4)
229 | (xy_data[3] & 0x0F);
230 input_info->touch.y = (xy_data[2] << 4)
231 | ((xy_data[3] & 0xF0) >> 4);
232 input_report_abs(input_info->input, ABS_X, input_info->touch.x);
233 input_report_abs(input_info->input, ABS_Y, input_info->touch.y);
234 input_sync(input_info->input);
235}
236
237static void cp_tm1217_get_data(struct cp_tm1217_device *ts)
238{
239 u8 req[2];
240 int retval, i, finger_touched = 0;
241
242 do {
243 req[0] = TMA1217_FINGER_STATE;
244 retval = cp_tm1217_read(ts, req, 1);
245 if (retval != 1) {
246 dev_err(ts->dev,
247 "cp_tm1217: Read from device failed\n");
248 continue;
249 }
250 finger_touched = 0;
251 /* Start sampling until the pressure is below
252 threshold */
253 for (i = 0; i < TOUCH_SUPPORTED; i++) {
254 if (req[1] & 0x3) {
255 finger_touched++;
256 if (ts->cp_input_info[i].touch.button == 0) {
257 /* send the button touch event */
258 input_report_key(
259 ts->cp_input_info[i].input,
260 BTN_TOUCH, 1);
261 ts->cp_input_info[i].touch.button = 1;
262 }
263 process_touch(ts, i);
264 } else {
265 if (ts->cp_input_info[i].touch.button == 1) {
266 /* send the button release event */
267 input_report_key(
268 ts->cp_input_info[i].input,
269 BTN_TOUCH, 0);
270 input_sync(ts->cp_input_info[i].input);
271 ts->cp_input_info[i].touch.button = 0;
272 }
273 }
274 req[1] = req[1] >> 2;
275 }
276 msleep(DELAY_BTWIN_SAMPLE);
277 } while (finger_touched > 0);
278}
279
280static irqreturn_t cp_tm1217_sample_thread(int irq, void *handle)
281{
282 struct cp_tm1217_device *ts = (struct cp_tm1217_device *) handle;
283 u8 req[2];
284 int retval;
285
286 /* Chedk if another thread is already running */
287 mutex_lock(&ts->thread_mutex);
288 if (ts->thread_running == 1) {
289 mutex_unlock(&ts->thread_mutex);
290 return IRQ_HANDLED;
291 } else {
292 ts->thread_running = 1;
293 mutex_unlock(&ts->thread_mutex);
294 }
295
296 /* Mask the interrupts */
297 retval = cp_tm1217_mask_interrupt(ts);
298
299 /* Read the Interrupt Status register to find the cause of the
300 Interrupt */
301 req[0] = TMA1217_INT_STATUS;
302 retval = cp_tm1217_read(ts, req, 1);
303 if (retval != 1)
304 goto exit_thread;
305
306 if (!(req[1] & 0x8))
307 goto exit_thread;
308
309 cp_tm1217_get_data(ts);
310
311exit_thread:
312 /* Unmask the interrupts before going to sleep */
313 retval = cp_tm1217_unmask_interrupt(ts);
314
315 mutex_lock(&ts->thread_mutex);
316 ts->thread_running = 0;
317 mutex_unlock(&ts->thread_mutex);
318
319 return IRQ_HANDLED;
320}
321
322static int cp_tm1217_init_data(struct cp_tm1217_device *ts)
323{
324 int retval;
325 u8 req[2];
326
327 /* Read the vendor id/ fw revision etc. Ignoring return check as this
328 is non critical info */
329 req[0] = TMA1217_MANUFACTURER_ID;
330 retval = cp_tm1217_read(ts, req, 1);
331 ts->vinfo.vendor_id = req[1];
332
333 req[0] = TMA1217_PRODUCT_FAMILY;
334 retval = cp_tm1217_read(ts, req, 1);
335 ts->vinfo.product_family = req[1];
336
337 req[0] = TMA1217_FIRMWARE_REVISION;
338 retval = cp_tm1217_read(ts, req, 1);
339 ts->vinfo.firmware_rev = req[1];
340
341 req[0] = TMA1217_SERIAL_NO_HIGH;
342 retval = cp_tm1217_read(ts, req, 1);
343 ts->vinfo.serial_no = (req[1] << 8);
344
345 req[0] = TMA1217_SERIAL_NO_LOW;
346 retval = cp_tm1217_read(ts, req, 1);
347 ts->vinfo.serial_no = ts->vinfo.serial_no | req[1];
348
349 req[0] = TMA1217_MAX_X_HIGHER4;
350 retval = cp_tm1217_read(ts, req, 1);
351 ts->dinfo.maxX = (req[1] & 0xF) << 8;
352
353 req[0] = TMA1217_MAX_X_LOWER8;
354 retval = cp_tm1217_read(ts, req, 1);
355 ts->dinfo.maxX = ts->dinfo.maxX | req[1];
356
357 req[0] = TMA1217_MAX_Y_HIGHER4;
358 retval = cp_tm1217_read(ts, req, 1);
359 ts->dinfo.maxY = (req[1] & 0xF) << 8;
360
361 req[0] = TMA1217_MAX_Y_LOWER8;
362 retval = cp_tm1217_read(ts, req, 1);
363 ts->dinfo.maxY = ts->dinfo.maxY | req[1];
364
365 return 0;
366
367}
368
369/*
370 * Set up a GPIO for use as the interrupt. We can't simply do this at
371 * boot time because the GPIO drivers themselves may not be around at
372 * boot/firmware set up time to do the work. Instead defer it to driver
373 * detection.
374 */
375
376static int cp_tm1217_setup_gpio_irq(struct cp_tm1217_device *ts)
377{
378 int retval;
379
380 /* Hook up the irq handler */
381 retval = gpio_request(ts->gpio, "cp_tm1217_touch");
382 if (retval < 0) {
383 dev_err(ts->dev, "cp_tm1217: GPIO request failed error %d\n",
384 retval);
385 return retval;
386 }
387
388 retval = gpio_direction_input(ts->gpio);
389 if (retval < 0) {
390 dev_err(ts->dev,
391 "cp_tm1217: GPIO direction configuration failed, error %d\n",
392 retval);
393 gpio_free(ts->gpio);
394 return retval;
395 }
396
397 retval = gpio_to_irq(ts->gpio);
398 if (retval < 0) {
399 dev_err(ts->dev, "cp_tm1217: GPIO to IRQ failedi,"
400 " error %d\n", retval);
401 gpio_free(ts->gpio);
402 }
403 dev_dbg(ts->dev,
404 "cp_tm1217: Got IRQ number is %d for GPIO %d\n",
405 retval, ts->gpio);
406 return retval;
407}
408
409static int cp_tm1217_probe(struct i2c_client *client,
410 const struct i2c_device_id *id)
411{
412 struct cp_tm1217_device *ts;
413 struct input_dev *input_dev;
414 struct input_dev_info *input_info;
415 struct cp_tm1217_platform_data *pdata;
416 u8 req[2];
417 int i, retval;
418
419 /* No pdata is fine - we then use "normal" IRQ mode */
420
421 pdata = client->dev.platform_data;
422
423 ts = kzalloc(sizeof(struct cp_tm1217_device), GFP_KERNEL);
424 if (!ts) {
425 dev_err(&client->dev,
426 "cp_tm1217: Private Device Struct alloc failed\n");
427 return -ENOMEM;
428 }
429
430 ts->client = client;
431 ts->dev = &client->dev;
432 i2c_set_clientdata(client, ts);
433
434 ts->thread_running = 0;
435 mutex_init(&ts->thread_mutex);
436
437 /* Reset the Controller */
438 req[0] = TMA1217_DEVICE_CMD_RESET;
439 req[1] = 0x1;
440 retval = cp_tm1217_write(ts, req, 1);
441 if (retval != 1) {
442 dev_err(ts->dev, "cp_tm1217: Controller reset failed\n");
443 kfree(ts);
444 return -EIO;
445 }
446
447 /* Clear up the interrupt status from reset. */
448 req[0] = TMA1217_INT_STATUS;
449 retval = cp_tm1217_read(ts, req, 1);
450
451 /* Mask all the interrupts */
452 retval = cp_tm1217_mask_interrupt(ts);
453
454 /* Read the controller information */
455 cp_tm1217_init_data(ts);
456
457 /* The following code will register multiple event devices when
458 multi-pointer is enabled, the code has not been tested
459 with MPX */
460 for (i = 0; i < TOUCH_SUPPORTED; i++) {
461 input_dev = input_allocate_device();
462 if (input_dev == NULL) {
463 dev_err(ts->dev,
464 "cp_tm1217:Input Device Struct alloc failed\n");
465 kfree(ts);
466 return -ENOMEM;
467 }
468 input_info = &ts->cp_input_info[i];
469 snprintf(input_info->name, sizeof(input_info->name),
470 "cp_tm1217_touchscreen_%d", i);
471 input_dev->name = input_info->name;
472 snprintf(input_info->phys, sizeof(input_info->phys),
473 "%s/input%d", dev_name(&client->dev), i);
474
475 input_dev->phys = input_info->phys;
476 input_dev->id.bustype = BUS_I2C;
477
478 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
479 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
480
481 input_set_abs_params(input_dev, ABS_X, 0, ts->dinfo.maxX, 0, 0);
482 input_set_abs_params(input_dev, ABS_Y, 0, ts->dinfo.maxY, 0, 0);
483
484 retval = input_register_device(input_dev);
485 if (retval) {
486 dev_err(ts->dev,
487 "Input dev registration failed for %s\n",
488 input_dev->name);
489 goto fail;
490 }
491 input_info->input = input_dev;
492 }
493
494 /* Setup the reporting mode to send an interrupt only when
495 finger arrives or departs. */
496 req[0] = TMA1217_REPORT_MODE;
497 req[1] = 0x02;
498 retval = cp_tm1217_write(ts, req, 1);
499
500 /* Setup the device to no sleep mode for now and make it configured */
501 req[0] = TMA1217_DEVICE_CTRL;
502 req[1] = 0x84;
503 retval = cp_tm1217_write(ts, req, 1);
504
505 /* Check for the status of the device */
506 req[0] = TMA1217_DEV_STATUS;
507 retval = cp_tm1217_read(ts, req, 1);
508 if (req[1] != 0) {
509 dev_err(ts->dev,
510 "cp_tm1217: Device Status 0x%x != 0: config failed\n",
511 req[1]);
512
513 retval = -EIO;
514 goto fail;
515 }
516
517 if (pdata && pdata->gpio) {
518 ts->gpio = pdata->gpio;
519 retval = cp_tm1217_setup_gpio_irq(ts);
520 } else
521 retval = client->irq;
522
523 if (retval < 0) {
524 dev_err(ts->dev, "cp_tm1217: GPIO request failed error %d\n",
525 retval);
526 goto fail;
527 }
528
529 client->irq = retval;
530
531
532 retval = request_threaded_irq(client->irq,
533 NULL, cp_tm1217_sample_thread,
534 IRQF_TRIGGER_FALLING, "cp_tm1217_touch", ts);
535 if (retval < 0) {
536 dev_err(ts->dev, "cp_tm1217: Request IRQ error %d\n", retval);
537 goto fail_gpio;
538 }
539
540 /* Unmask the interrupts */
541 retval = cp_tm1217_unmask_interrupt(ts);
542 if (retval == 0)
543 return 0;
544
545 free_irq(client->irq, ts);
546fail_gpio:
547 if (ts->gpio)
548 gpio_free(ts->gpio);
549fail:
550 /* Clean up before returning failure */
551 for (i = 0; i < TOUCH_SUPPORTED; i++) {
552 if (ts->cp_input_info[i].input) {
553 input_unregister_device(ts->cp_input_info[i].input);
554 input_free_device(ts->cp_input_info[i].input);
555 }
556 }
557 kfree(ts);
558 return retval;
559
560}
561
562/*
563 * cp_tm1217 suspend
564 *
565 */
566static int cp_tm1217_suspend(struct i2c_client *client, pm_message_t mesg)
567{
568 struct cp_tm1217_device *ts = i2c_get_clientdata(client);
569 u8 req[2];
570 int retval;
571
572 /* Put the controller to sleep */
573 req[0] = TMA1217_DEVICE_CTRL;
574 retval = cp_tm1217_read(ts, req, 1);
575 req[1] = (req[1] & 0xF8) | 0x1;
576 retval = cp_tm1217_write(ts, req, 1);
577
578 if (device_may_wakeup(&client->dev))
579 enable_irq_wake(client->irq);
580
581 return 0;
582}
583
584/*
585 * cp_tm1217_resume
586 *
587 */
588static int cp_tm1217_resume(struct i2c_client *client)
589{
590 struct cp_tm1217_device *ts = i2c_get_clientdata(client);
591 u8 req[2];
592 int retval;
593
594 /* Take the controller out of sleep */
595 req[0] = TMA1217_DEVICE_CTRL;
596 retval = cp_tm1217_read(ts, req, 1);
597 req[1] = (req[1] & 0xF8) | 0x4;
598 retval = cp_tm1217_write(ts, req, 1);
599
600 /* Restore the register settings sinc the power to the
601 could have been cut off */
602
603 /* Setup the reporting mode to send an interrupt only when
604 finger arrives or departs. */
605 req[0] = TMA1217_REPORT_MODE;
606 req[1] = 0x02;
607 retval = cp_tm1217_write(ts, req, 1);
608
609 /* Setup the device to no sleep mode for now and make it configured */
610 req[0] = TMA1217_DEVICE_CTRL;
611 req[1] = 0x84;
612 retval = cp_tm1217_write(ts, req, 1);
613
614 /* Setup the interrupt mask */
615 retval = cp_tm1217_unmask_interrupt(ts);
616
617 if (device_may_wakeup(&client->dev))
618 disable_irq_wake(client->irq);
619
620 return 0;
621}
622
623/*
624 * cp_tm1217_remove
625 *
626 */
627static int cp_tm1217_remove(struct i2c_client *client)
628{
629 struct cp_tm1217_device *ts = i2c_get_clientdata(client);
630 int i;
631
632 free_irq(client->irq, ts);
633 if (ts->gpio)
634 gpio_free(ts->gpio);
635 for (i = 0; i < TOUCH_SUPPORTED; i++)
636 input_unregister_device(ts->cp_input_info[i].input);
637 kfree(ts);
638 return 0;
639}
640
641static struct i2c_device_id cp_tm1217_idtable[] = {
642 { CPTM1217_DEVICE_NAME, 0 },
643 { }
644};
645
646MODULE_DEVICE_TABLE(i2c, cp_tm1217_idtable);
647
648static struct i2c_driver cp_tm1217_driver = {
649 .driver = {
650 .owner = THIS_MODULE,
651 .name = CPTM1217_DRIVER_NAME,
652 },
653 .id_table = cp_tm1217_idtable,
654 .probe = cp_tm1217_probe,
655 .remove = cp_tm1217_remove,
656 .suspend = cp_tm1217_suspend,
657 .resume = cp_tm1217_resume,
658};
659
660static int __init clearpad_tm1217_init(void)
661{
662 return i2c_add_driver(&cp_tm1217_driver);
663}
664
665static void __exit clearpad_tm1217_exit(void)
666{
667 i2c_del_driver(&cp_tm1217_driver);
668}
669
670module_init(clearpad_tm1217_init);
671module_exit(clearpad_tm1217_exit);
672
673MODULE_AUTHOR("Ramesh Agarwal <ramesh.agarwal@intel.com>");
674MODULE_DESCRIPTION("Synaptics TM1217 TouchScreen Driver");
675MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/cptm1217/cp_tm1217.h b/drivers/staging/cptm1217/cp_tm1217.h
new file mode 100644
index 000000000000..a0ce31db53f8
--- /dev/null
+++ b/drivers/staging/cptm1217/cp_tm1217.h
@@ -0,0 +1,9 @@
1#ifndef __LINUX_I2C_CP_TM1217_H
2#define __LINUX_I2C_CP_TM1217_H
3
4struct cp_tm1217_platform_data
5{
6 int gpio; /* If not set uses the IRQ resource 0 */
7};
8
9#endif
diff --git a/drivers/staging/crystalhd/crystalhd_hw.c b/drivers/staging/crystalhd/crystalhd_hw.c
index f63185790c48..153ddbf4247d 100644
--- a/drivers/staging/crystalhd/crystalhd_hw.c
+++ b/drivers/staging/crystalhd/crystalhd_hw.c
@@ -1711,7 +1711,7 @@ enum BC_STATUS crystalhd_download_fw(struct crystalhd_adp *adp, void *buffer, ui
1711 } 1711 }
1712 1712
1713 BCMLOG(BCMLOG_INFO, "Firmware Downloaded Successfully\n"); 1713 BCMLOG(BCMLOG_INFO, "Firmware Downloaded Successfully\n");
1714 return BC_STS_SUCCESS;; 1714 return BC_STS_SUCCESS;
1715} 1715}
1716 1716
1717enum BC_STATUS crystalhd_do_fw_cmd(struct crystalhd_hw *hw, 1717enum BC_STATUS crystalhd_do_fw_cmd(struct crystalhd_hw *hw,
diff --git a/drivers/staging/crystalhd/crystalhd_lnx.c b/drivers/staging/crystalhd/crystalhd_lnx.c
index 28c6b8ced424..719e70bc871e 100644
--- a/drivers/staging/crystalhd/crystalhd_lnx.c
+++ b/drivers/staging/crystalhd/crystalhd_lnx.c
@@ -516,7 +516,7 @@ static void __devexit chd_dec_pci_remove(struct pci_dev *pdev)
516 516
517 BCMLOG_ENTER; 517 BCMLOG_ENTER;
518 518
519 pinfo = (struct crystalhd_adp *) pci_get_drvdata(pdev); 519 pinfo = pci_get_drvdata(pdev);
520 if (!pinfo) { 520 if (!pinfo) {
521 BCMLOG_ERR("could not get adp\n"); 521 BCMLOG_ERR("could not get adp\n");
522 return; 522 return;
@@ -626,7 +626,7 @@ int chd_dec_pci_suspend(struct pci_dev *pdev, pm_message_t state)
626 struct crystalhd_ioctl_data *temp; 626 struct crystalhd_ioctl_data *temp;
627 enum BC_STATUS sts = BC_STS_SUCCESS; 627 enum BC_STATUS sts = BC_STS_SUCCESS;
628 628
629 adp = (struct crystalhd_adp *)pci_get_drvdata(pdev); 629 adp = pci_get_drvdata(pdev);
630 if (!adp) { 630 if (!adp) {
631 BCMLOG_ERR("could not get adp\n"); 631 BCMLOG_ERR("could not get adp\n");
632 return -ENODEV; 632 return -ENODEV;
@@ -660,7 +660,7 @@ int chd_dec_pci_resume(struct pci_dev *pdev)
660 enum BC_STATUS sts = BC_STS_SUCCESS; 660 enum BC_STATUS sts = BC_STS_SUCCESS;
661 int rc; 661 int rc;
662 662
663 adp = (struct crystalhd_adp *)pci_get_drvdata(pdev); 663 adp = pci_get_drvdata(pdev);
664 if (!adp) { 664 if (!adp) {
665 BCMLOG_ERR("could not get adp\n"); 665 BCMLOG_ERR("could not get adp\n");
666 return -ENODEV; 666 return -ENODEV;
diff --git a/drivers/staging/cx25821/cx25821-alsa.c b/drivers/staging/cx25821/cx25821-alsa.c
index 9a205a342c55..160f6693aa33 100644
--- a/drivers/staging/cx25821/cx25821-alsa.c
+++ b/drivers/staging/cx25821/cx25821-alsa.c
@@ -630,7 +630,7 @@ static int snd_cx25821_pcm(struct cx25821_audio_dev *chip, int device,
630 * Only boards with eeprom and byte 1 at eeprom=1 have it 630 * Only boards with eeprom and byte 1 at eeprom=1 have it
631 */ 631 */
632 632
633static const struct pci_device_id cx25821_audio_pci_tbl[] __devinitdata = { 633static DEFINE_PCI_DEVICE_TABLE(cx25821_audio_pci_tbl) = {
634 {0x14f1, 0x0920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 634 {0x14f1, 0x0920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
635 {0,} 635 {0,}
636}; 636};
diff --git a/drivers/staging/cxt1e1/comet.c b/drivers/staging/cxt1e1/comet.c
index dcbe6b628455..52224cdc967d 100644
--- a/drivers/staging/cxt1e1/comet.c
+++ b/drivers/staging/cxt1e1/comet.c
@@ -29,7 +29,7 @@
29#endif 29#endif
30 30
31 31
32extern int log_level; 32extern int cxt1e1_log_level;
33 33
34#define COMET_NUM_SAMPLES 24 /* Number of entries in the waveform table */ 34#define COMET_NUM_SAMPLES 24 /* Number of entries in the waveform table */
35#define COMET_NUM_UNITS 5 /* Number of points per entry in table */ 35#define COMET_NUM_UNITS 5 /* Number of points per entry in table */
@@ -292,12 +292,12 @@ init_comet (void *ci, comet_t * comet, u_int32_t port_mode, int clockmaster,
292 * i.e.FPMODE=0 (@0x20) */ 292 * i.e.FPMODE=0 (@0x20) */
293 if ((moreParams & CFG_CLK_PORT_MASK) == CFG_CLK_PORT_INTERNAL) 293 if ((moreParams & CFG_CLK_PORT_MASK) == CFG_CLK_PORT_INTERNAL)
294 { 294 {
295 if (log_level >= LOG_SBEBUG12) 295 if (cxt1e1_log_level >= LOG_SBEBUG12)
296 pr_info(">> %s: clockmaster internal clock\n", __func__); 296 pr_info(">> %s: clockmaster internal clock\n", __func__);
297 pci_write_32 ((u_int32_t *) &comet->tx_time, 0x0d); /* internal oscillator */ 297 pci_write_32 ((u_int32_t *) &comet->tx_time, 0x0d); /* internal oscillator */
298 } else /* external clock source */ 298 } else /* external clock source */
299 { 299 {
300 if (log_level >= LOG_SBEBUG12) 300 if (cxt1e1_log_level >= LOG_SBEBUG12)
301 pr_info(">> %s: clockmaster external clock\n", __func__); 301 pr_info(">> %s: clockmaster external clock\n", __func__);
302 pci_write_32 ((u_int32_t *) &comet->tx_time, 0x09); /* loop timing 302 pci_write_32 ((u_int32_t *) &comet->tx_time, 0x09); /* loop timing
303 * (external) */ 303 * (external) */
@@ -312,7 +312,7 @@ init_comet (void *ci, comet_t * comet, u_int32_t port_mode, int clockmaster,
312 pci_write_32 ((u_int32_t *) &comet->brif_cfg, 0x21); /* Slave Mode (CMODE=1) */ 312 pci_write_32 ((u_int32_t *) &comet->brif_cfg, 0x21); /* Slave Mode (CMODE=1) */
313 pci_write_32 ((u_int32_t *) &comet->brif_fpcfg, 0x20); /* Slave Mode i.e. 313 pci_write_32 ((u_int32_t *) &comet->brif_fpcfg, 0x20); /* Slave Mode i.e.
314 * FPMODE=1 (@0x20) */ 314 * FPMODE=1 (@0x20) */
315 if (log_level >= LOG_SBEBUG12) 315 if (cxt1e1_log_level >= LOG_SBEBUG12)
316 pr_info(">> %s: clockslave internal clock\n", __func__); 316 pr_info(">> %s: clockslave internal clock\n", __func__);
317 pci_write_32 ((u_int32_t *) &comet->tx_time, 0x0d); /* oscillator timing */ 317 pci_write_32 ((u_int32_t *) &comet->tx_time, 0x0d); /* oscillator timing */
318 } 318 }
diff --git a/drivers/staging/cxt1e1/functions.c b/drivers/staging/cxt1e1/functions.c
index ab399c2f7488..d9a9aa3571d9 100644
--- a/drivers/staging/cxt1e1/functions.c
+++ b/drivers/staging/cxt1e1/functions.c
@@ -54,7 +54,7 @@ static int dummy = 0;
54 54
55#endif 55#endif
56 56
57extern int log_level; 57extern int cxt1e1_log_level;
58extern int drvr_state; 58extern int drvr_state;
59 59
60 60
@@ -67,7 +67,7 @@ pci_read_32 (u_int32_t *p)
67 67
68 FLUSH_PCI_READ (); 68 FLUSH_PCI_READ ();
69 v = le32_to_cpu (*p); 69 v = le32_to_cpu (*p);
70 if (log_level >= LOG_DEBUG) 70 if (cxt1e1_log_level >= LOG_DEBUG)
71 pr_info("pci_read : %x = %x\n", (u_int32_t) p, v); 71 pr_info("pci_read : %x = %x\n", (u_int32_t) p, v);
72 return v; 72 return v;
73#else 73#else
@@ -80,7 +80,7 @@ void
80pci_write_32 (u_int32_t *p, u_int32_t v) 80pci_write_32 (u_int32_t *p, u_int32_t v)
81{ 81{
82#ifdef FLOW_DEBUG 82#ifdef FLOW_DEBUG
83 if (log_level >= LOG_DEBUG) 83 if (cxt1e1_log_level >= LOG_DEBUG)
84 pr_info("pci_write: %x = %x\n", (u_int32_t) p, v); 84 pr_info("pci_write: %x = %x\n", (u_int32_t) p, v);
85#endif 85#endif
86 *p = cpu_to_le32 (v); 86 *p = cpu_to_le32 (v);
@@ -118,7 +118,7 @@ watchdog_func (unsigned long arg)
118 118
119 if (drvr_state != SBE_DRVR_AVAILABLE) 119 if (drvr_state != SBE_DRVR_AVAILABLE)
120 { 120 {
121 if (log_level >= LOG_MONITOR) 121 if (cxt1e1_log_level >= LOG_MONITOR)
122 pr_warning("%s: drvr not available (%x)\n", __func__, drvr_state); 122 pr_warning("%s: drvr not available (%x)\n", __func__, drvr_state);
123 return; 123 return;
124 } 124 }
diff --git a/drivers/staging/cxt1e1/hwprobe.c b/drivers/staging/cxt1e1/hwprobe.c
index 89200e7af26c..c517cc22f391 100644
--- a/drivers/staging/cxt1e1/hwprobe.c
+++ b/drivers/staging/cxt1e1/hwprobe.c
@@ -37,7 +37,7 @@
37#define STATIC static 37#define STATIC static
38#endif 38#endif
39 39
40extern int log_level; 40extern int cxt1e1_log_level;
41extern int error_flag; 41extern int error_flag;
42extern int drvr_state; 42extern int drvr_state;
43 43
@@ -143,7 +143,7 @@ hdw_sn_get (hdw_info_t * hi, int brdno)
143 if ((hi->promfmt = pmc_verify_cksum (&hi->mfg_info.data)) == PROM_FORMAT_Unk) 143 if ((hi->promfmt = pmc_verify_cksum (&hi->mfg_info.data)) == PROM_FORMAT_Unk)
144 { 144 {
145 /* bad crc, data is suspect */ 145 /* bad crc, data is suspect */
146 if (log_level >= LOG_WARN) 146 if (cxt1e1_log_level >= LOG_WARN)
147 pr_info("%s: EEPROM cksum error\n", hi->devname); 147 pr_info("%s: EEPROM cksum error\n", hi->devname);
148 hi->mfg_info_sts = EEPROM_CRCERR; 148 hi->mfg_info_sts = EEPROM_CRCERR;
149 } else 149 } else
diff --git a/drivers/staging/cxt1e1/linux.c b/drivers/staging/cxt1e1/linux.c
index c7930287e3db..0f78f8962751 100644
--- a/drivers/staging/cxt1e1/linux.c
+++ b/drivers/staging/cxt1e1/linux.c
@@ -108,9 +108,9 @@ extern int unregister_hdlc_device_v7 (hdlc_device *);
108#endif 108#endif
109 109
110int error_flag; /* module load error reporting */ 110int error_flag; /* module load error reporting */
111int log_level = LOG_ERROR; 111int cxt1e1_log_level = LOG_ERROR;
112int log_level_default = LOG_ERROR; 112int log_level_default = LOG_ERROR;
113module_param(log_level, int, 0444); 113module_param(cxt1e1_log_level, int, 0444);
114 114
115int cxt1e1_max_mru = MUSYCC_MRU; 115int cxt1e1_max_mru = MUSYCC_MRU;
116int max_mru_default = MUSYCC_MRU; 116int max_mru_default = MUSYCC_MRU;
@@ -497,7 +497,7 @@ create_chan (struct net_device * ndev, ci_t * ci,
497 rtnl_lock (); /* needed due to Ioctl calling sequence */ 497 rtnl_lock (); /* needed due to Ioctl calling sequence */
498 if (ret) 498 if (ret)
499 { 499 {
500 if (log_level >= LOG_WARN) 500 if (cxt1e1_log_level >= LOG_WARN)
501 pr_info("%s: create_chan[%d] registration error = %d.\n", 501 pr_info("%s: create_chan[%d] registration error = %d.\n",
502 ci->devname, cp->channum, ret); 502 ci->devname, cp->channum, ret);
503 free_netdev (dev); /* cleanup */ 503 free_netdev (dev); /* cleanup */
@@ -722,11 +722,11 @@ do_get_chan_stats (struct net_device * ndev, void *data)
722STATIC status_t 722STATIC status_t
723do_set_loglevel (struct net_device * ndev, void *data) 723do_set_loglevel (struct net_device * ndev, void *data)
724{ 724{
725 unsigned int log_level; 725 unsigned int cxt1e1_log_level;
726 726
727 if (copy_from_user (&log_level, data, sizeof (int))) 727 if (copy_from_user (&cxt1e1_log_level, data, sizeof (int)))
728 return -EFAULT; 728 return -EFAULT;
729 sbecom_set_loglevel (log_level); 729 sbecom_set_loglevel (cxt1e1_log_level);
730 return 0; 730 return 0;
731} 731}
732 732
@@ -1115,9 +1115,9 @@ c4_mod_init (void)
1115 return -rtn; /* installation failure - see system log */ 1115 return -rtn; /* installation failure - see system log */
1116 1116
1117 /* housekeeping notifications */ 1117 /* housekeeping notifications */
1118 if (log_level != log_level_default) 1118 if (cxt1e1_log_level != log_level_default)
1119 pr_info("NOTE: driver parameter <log_level> changed from default %d to %d.\n", 1119 pr_info("NOTE: driver parameter <cxt1e1_log_level> changed from default %d to %d.\n",
1120 log_level_default, log_level); 1120 log_level_default, cxt1e1_log_level);
1121 if (cxt1e1_max_mru != max_mru_default) 1121 if (cxt1e1_max_mru != max_mru_default)
1122 pr_info("NOTE: driver parameter <cxt1e1_max_mru> changed from default %d to %d.\n", 1122 pr_info("NOTE: driver parameter <cxt1e1_max_mru> changed from default %d to %d.\n",
1123 max_mru_default, cxt1e1_max_mru); 1123 max_mru_default, cxt1e1_max_mru);
diff --git a/drivers/staging/cxt1e1/musycc.c b/drivers/staging/cxt1e1/musycc.c
index fc15610f6974..f274c77fb3fc 100644
--- a/drivers/staging/cxt1e1/musycc.c
+++ b/drivers/staging/cxt1e1/musycc.c
@@ -97,7 +97,7 @@ char SBEid_pmcc4_musyccc[] =
97/* global driver variables */ 97/* global driver variables */
98extern ci_t *c4_list; 98extern ci_t *c4_list;
99extern int drvr_state; 99extern int drvr_state;
100extern int log_level; 100extern int cxt1e1_log_level;
101 101
102extern int cxt1e1_max_mru; 102extern int cxt1e1_max_mru;
103extern int cxt1e1_max_mtu; 103extern int cxt1e1_max_mtu;
@@ -627,7 +627,7 @@ rewrite:
627 627
628 if ((r != req) && (req != SR_CHIP_RESET) && (++rcnt <= MUSYCC_SR_RETRY_CNT)) 628 if ((r != req) && (req != SR_CHIP_RESET) && (++rcnt <= MUSYCC_SR_RETRY_CNT))
629 { 629 {
630 if (log_level >= LOG_MONITOR) 630 if (cxt1e1_log_level >= LOG_MONITOR)
631 pr_info("%s: %d - reissue srv req/last %x/%x (hdw reads %x), Chan %d.\n", 631 pr_info("%s: %d - reissue srv req/last %x/%x (hdw reads %x), Chan %d.\n",
632 pi->up->devname, rcnt, req, pi->sr_last, r, 632 pi->up->devname, rcnt, req, pi->sr_last, r,
633 (pi->portnum * MUSYCC_NCHANS) + (req & 0x1f)); 633 (pi->portnum * MUSYCC_NCHANS) + (req & 0x1f));
@@ -951,7 +951,7 @@ musycc_bh_tx_eom (mpi_t * pi, int gchan)
951 ch = pi->chan[gchan]; 951 ch = pi->chan[gchan];
952 if (ch == 0 || ch->state != UP) 952 if (ch == 0 || ch->state != UP)
953 { 953 {
954 if (log_level >= LOG_ERROR) 954 if (cxt1e1_log_level >= LOG_ERROR)
955 pr_info("%s: intr: xmit EOM on uninitialized channel %d\n", 955 pr_info("%s: intr: xmit EOM on uninitialized channel %d\n",
956 pi->up->devname, gchan); 956 pi->up->devname, gchan);
957 } 957 }
@@ -1002,7 +1002,7 @@ musycc_bh_tx_eom (mpi_t * pi, int gchan)
1002 } 1002 }
1003 if (status & MUSYCC_TX_OWNED) 1003 if (status & MUSYCC_TX_OWNED)
1004 { 1004 {
1005 if (log_level >= LOG_MONITOR) 1005 if (cxt1e1_log_level >= LOG_MONITOR)
1006 { 1006 {
1007 pr_info("%s: Port %d Chan %2d - unexpected TX msg ownership intr (md %p sts %x)\n", 1007 pr_info("%s: Port %d Chan %2d - unexpected TX msg ownership intr (md %p sts %x)\n",
1008 pi->up->devname, pi->portnum, ch->channum, 1008 pi->up->devname, pi->portnum, ch->channum,
@@ -1016,7 +1016,7 @@ musycc_bh_tx_eom (mpi_t * pi, int gchan)
1016 break; /* Not our mdesc, done */ 1016 break; /* Not our mdesc, done */
1017 } else 1017 } else
1018 { 1018 {
1019 if (log_level >= LOG_MONITOR) 1019 if (cxt1e1_log_level >= LOG_MONITOR)
1020 pr_info("%s: Port %d Chan %2d - recovered TX msg ownership [%d] (md %p sts %x)\n", 1020 pr_info("%s: Port %d Chan %2d - recovered TX msg ownership [%d] (md %p sts %x)\n",
1021 pi->up->devname, pi->portnum, ch->channum, readCount, md, status); 1021 pi->up->devname, pi->portnum, ch->channum, readCount, md, status);
1022 } 1022 }
@@ -1054,7 +1054,7 @@ musycc_bh_tx_eom (mpi_t * pi, int gchan)
1054 } 1054 }
1055 md->status = 0; 1055 md->status = 0;
1056#ifdef RLD_TXFULL_DEBUG 1056#ifdef RLD_TXFULL_DEBUG
1057 if (log_level >= LOG_MONITOR2) 1057 if (cxt1e1_log_level >= LOG_MONITOR2)
1058 pr_info("~~ tx_eom: tx_full %x txd_free %d -> %d\n", 1058 pr_info("~~ tx_eom: tx_full %x txd_free %d -> %d\n",
1059 ch->tx_full, ch->txd_free, ch->txd_free + 1); 1059 ch->tx_full, ch->txd_free, ch->txd_free + 1);
1060#endif 1060#endif
@@ -1063,7 +1063,7 @@ musycc_bh_tx_eom (mpi_t * pi, int gchan)
1063 1063
1064 if ((ch->p.chan_mode != CFG_CH_PROTO_TRANS) && (status & EOBIRQ_ENABLE)) 1064 if ((ch->p.chan_mode != CFG_CH_PROTO_TRANS) && (status & EOBIRQ_ENABLE))
1065 { 1065 {
1066 if (log_level >= LOG_MONITOR) 1066 if (cxt1e1_log_level >= LOG_MONITOR)
1067 pr_info("%s: Mode (%x) incorrect EOB status (%x)\n", 1067 pr_info("%s: Mode (%x) incorrect EOB status (%x)\n",
1068 pi->up->devname, ch->p.chan_mode, status); 1068 pi->up->devname, ch->p.chan_mode, status);
1069 if ((status & EOMIRQ_ENABLE) == 0) 1069 if ((status & EOMIRQ_ENABLE) == 0)
@@ -1094,7 +1094,7 @@ musycc_bh_tx_eom (mpi_t * pi, int gchan)
1094 { 1094 {
1095 1095
1096#ifdef RLD_TXFULL_DEBUG 1096#ifdef RLD_TXFULL_DEBUG
1097 if (log_level >= LOG_MONITOR2) 1097 if (cxt1e1_log_level >= LOG_MONITOR2)
1098 pr_info("tx_eom[%d]: enable xmit tx_full no more, txd_free %d txd_num/2 %d\n", 1098 pr_info("tx_eom[%d]: enable xmit tx_full no more, txd_free %d txd_num/2 %d\n",
1099 ch->channum, 1099 ch->channum,
1100 ch->txd_free, ch->txd_num / 2); 1100 ch->txd_free, ch->txd_num / 2);
@@ -1108,7 +1108,7 @@ musycc_bh_tx_eom (mpi_t * pi, int gchan)
1108#ifdef RLD_TXFULL_DEBUG 1108#ifdef RLD_TXFULL_DEBUG
1109 else if (ch->tx_full) 1109 else if (ch->tx_full)
1110 { 1110 {
1111 if (log_level >= LOG_MONITOR2) 1111 if (cxt1e1_log_level >= LOG_MONITOR2)
1112 pr_info("tx_eom[%d]: bypass TX enable though room available? (txd_free %d txd_num/2 %d)\n", 1112 pr_info("tx_eom[%d]: bypass TX enable though room available? (txd_free %d txd_num/2 %d)\n",
1113 ch->channum, 1113 ch->channum,
1114 ch->txd_free, ch->txd_num / 2); 1114 ch->txd_free, ch->txd_num / 2);
@@ -1138,7 +1138,7 @@ musycc_bh_rx_eom (mpi_t * pi, int gchan)
1138 ch = pi->chan[gchan]; 1138 ch = pi->chan[gchan];
1139 if (ch == 0 || ch->state != UP) 1139 if (ch == 0 || ch->state != UP)
1140 { 1140 {
1141 if (log_level > LOG_ERROR) 1141 if (cxt1e1_log_level > LOG_ERROR)
1142 pr_info("%s: intr: receive EOM on uninitialized channel %d\n", 1142 pr_info("%s: intr: receive EOM on uninitialized channel %d\n",
1143 pi->up->devname, gchan); 1143 pi->up->devname, gchan);
1144 return; 1144 return;
@@ -1269,7 +1269,7 @@ musycc_intr_th_handler (void *devp)
1269 1269
1270 if (nextInt != INTRPTS_NEXTINT (ci->intlog.this_status_new)) 1270 if (nextInt != INTRPTS_NEXTINT (ci->intlog.this_status_new))
1271 { 1271 {
1272 if (log_level >= LOG_MONITOR) 1272 if (cxt1e1_log_level >= LOG_MONITOR)
1273 { 1273 {
1274 pr_info("%s: note - updated ISD from %08x to %08x\n", 1274 pr_info("%s: note - updated ISD from %08x to %08x\n",
1275 ci->devname, status, 1275 ci->devname, status,
@@ -1337,11 +1337,11 @@ musycc_intr_th_handler (void *devp)
1337 ci->intlog.last_status_new = ci->intlog.this_status_new; 1337 ci->intlog.last_status_new = ci->intlog.this_status_new;
1338 ci->intlog.this_status_new = currInt; 1338 ci->intlog.this_status_new = currInt;
1339 1339
1340 if ((log_level >= LOG_WARN) && (status & INTRPTS_INTFULL_M)) 1340 if ((cxt1e1_log_level >= LOG_WARN) && (status & INTRPTS_INTFULL_M))
1341 { 1341 {
1342 pr_info("%s: Interrupt queue full condition occurred\n", ci->devname); 1342 pr_info("%s: Interrupt queue full condition occurred\n", ci->devname);
1343 } 1343 }
1344 if (log_level >= LOG_DEBUG) 1344 if (cxt1e1_log_level >= LOG_DEBUG)
1345 pr_info("%s: interrupts pending, isd @ 0x%p: %x curr %d cnt %d NEXT %d\n", 1345 pr_info("%s: interrupts pending, isd @ 0x%p: %x curr %d cnt %d NEXT %d\n",
1346 ci->devname, &ci->reg->isd, 1346 ci->devname, &ci->reg->isd,
1347 status, nextInt, intCnt, (intCnt + nextInt) & (INT_QUEUE_SIZE - 1)); 1347 status, nextInt, intCnt, (intCnt + nextInt) & (INT_QUEUE_SIZE - 1));
@@ -1448,7 +1448,7 @@ musycc_intr_bh_tasklet (ci_t * ci)
1448 if ((currInt == badInt) || (currInt == badInt2)) /* catch failure of Bug 1448 if ((currInt == badInt) || (currInt == badInt2)) /* catch failure of Bug
1449 * Fix checking */ 1449 * Fix checking */
1450 { 1450 {
1451 if (log_level >= LOG_WARN) 1451 if (cxt1e1_log_level >= LOG_WARN)
1452 pr_info("%s: Illegal Interrupt Detected @ 0x%p, mod %d.)\n", 1452 pr_info("%s: Illegal Interrupt Detected @ 0x%p, mod %d.)\n",
1453 ci->devname, &ci->iqd_p[headx], headx); 1453 ci->devname, &ci->iqd_p[headx], headx);
1454 1454
@@ -1483,7 +1483,7 @@ musycc_intr_bh_tasklet (ci_t * ci)
1483 ci->iqd_p[headx] = __constant_cpu_to_le32 (INT_EMPTY_ENTRY); 1483 ci->iqd_p[headx] = __constant_cpu_to_le32 (INT_EMPTY_ENTRY);
1484 FLUSH_MEM_WRITE (); 1484 FLUSH_MEM_WRITE ();
1485 1485
1486 if (log_level >= LOG_DEBUG) 1486 if (cxt1e1_log_level >= LOG_DEBUG)
1487 { 1487 {
1488 if (err != 0) 1488 if (err != 0)
1489 pr_info(" %08x -> err: %2d,", currInt, err); 1489 pr_info(" %08x -> err: %2d,", currInt, err);
@@ -1497,7 +1497,7 @@ musycc_intr_bh_tasklet (ci_t * ci)
1497 switch (event) 1497 switch (event)
1498 { 1498 {
1499 case EVE_SACK: /* Service Request Acknowledge */ 1499 case EVE_SACK: /* Service Request Acknowledge */
1500 if (log_level >= LOG_DEBUG) 1500 if (cxt1e1_log_level >= LOG_DEBUG)
1501 { 1501 {
1502 volatile u_int32_t r; 1502 volatile u_int32_t r;
1503 1503
@@ -1534,7 +1534,7 @@ musycc_intr_bh_tasklet (ci_t * ci)
1534 } 1534 }
1535 break; 1535 break;
1536 default: 1536 default:
1537 if (log_level >= LOG_WARN) 1537 if (cxt1e1_log_level >= LOG_WARN)
1538 pr_info("%s: unexpected interrupt event: %d, iqd[%d]: %08x, port: %d\n", ci->devname, 1538 pr_info("%s: unexpected interrupt event: %d, iqd[%d]: %08x, port: %d\n", ci->devname,
1539 event, headx, currInt, group); 1539 event, headx, currInt, group);
1540 break; 1540 break;
@@ -1573,9 +1573,9 @@ musycc_intr_bh_tasklet (ci_t * ci)
1573 1573
1574 { 1574 {
1575#ifdef RLD_TRANS_DEBUG 1575#ifdef RLD_TRANS_DEBUG
1576 if (1 || log_level >= LOG_MONITOR) 1576 if (1 || cxt1e1_log_level >= LOG_MONITOR)
1577#else 1577#else
1578 if (log_level >= LOG_MONITOR) 1578 if (cxt1e1_log_level >= LOG_MONITOR)
1579#endif 1579#endif
1580 { 1580 {
1581 pr_info("%s: TX buffer underflow [ONR] on channel %d, mode %x QStopped %x free %d\n", 1581 pr_info("%s: TX buffer underflow [ONR] on channel %d, mode %x QStopped %x free %d\n",
@@ -1605,7 +1605,7 @@ musycc_intr_bh_tasklet (ci_t * ci)
1605 ch->s.rx_over_errors++; 1605 ch->s.rx_over_errors++;
1606 ch->ch_start_rx = CH_START_RX_ONR; 1606 ch->ch_start_rx = CH_START_RX_ONR;
1607 1607
1608 if (log_level >= LOG_WARN) 1608 if (cxt1e1_log_level >= LOG_WARN)
1609 { 1609 {
1610 pr_info("%s: RX buffer overflow [ONR] on channel %d, mode %x\n", 1610 pr_info("%s: RX buffer overflow [ONR] on channel %d, mode %x\n",
1611 ci->devname, ch->channum, ch->p.chan_mode); 1611 ci->devname, ch->channum, ch->p.chan_mode);
@@ -1623,7 +1623,7 @@ musycc_intr_bh_tasklet (ci_t * ci)
1623 * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors], 1623 * Per MUSYCC manual, Section 6.4.8.3 [Transmit Errors],
1624 * this BUFF error requires Transmit channel reactivation. 1624 * this BUFF error requires Transmit channel reactivation.
1625 */ 1625 */
1626 if (log_level >= LOG_MONITOR) 1626 if (cxt1e1_log_level >= LOG_MONITOR)
1627 pr_info("%s: TX buffer underrun [BUFF] on channel %d, mode %x\n", 1627 pr_info("%s: TX buffer underrun [BUFF] on channel %d, mode %x\n",
1628 ci->devname, ch->channum, ch->p.chan_mode); 1628 ci->devname, ch->channum, ch->p.chan_mode);
1629 } else /* RX buffer overrun */ 1629 } else /* RX buffer overrun */
@@ -1636,7 +1636,7 @@ musycc_intr_bh_tasklet (ci_t * ci)
1636 * space for this channel. Receive channel reactivation is 1636 * space for this channel. Receive channel reactivation is
1637 * not required, but data has been lost. 1637 * not required, but data has been lost.
1638 */ 1638 */
1639 if (log_level >= LOG_WARN) 1639 if (cxt1e1_log_level >= LOG_WARN)
1640 pr_info("%s: RX buffer overrun [BUFF] on channel %d, mode %x\n", 1640 pr_info("%s: RX buffer overrun [BUFF] on channel %d, mode %x\n",
1641 ci->devname, ch->channum, ch->p.chan_mode); 1641 ci->devname, ch->channum, ch->p.chan_mode);
1642 /* 1642 /*
@@ -1658,7 +1658,7 @@ musycc_intr_bh_tasklet (ci_t * ci)
1658 } /* switch on err */ 1658 } /* switch on err */
1659 1659
1660 /* Check for interrupt lost condition */ 1660 /* Check for interrupt lost condition */
1661 if ((currInt & INTRPT_ILOST_M) && (log_level >= LOG_ERROR)) 1661 if ((currInt & INTRPT_ILOST_M) && (cxt1e1_log_level >= LOG_ERROR))
1662 { 1662 {
1663 pr_info("%s: Interrupt queue overflow - ILOST asserted\n", 1663 pr_info("%s: Interrupt queue overflow - ILOST asserted\n",
1664 ci->devname); 1664 ci->devname);
@@ -1667,7 +1667,7 @@ musycc_intr_bh_tasklet (ci_t * ci)
1667 FLUSH_MEM_WRITE (); 1667 FLUSH_MEM_WRITE ();
1668 FLUSH_MEM_READ (); 1668 FLUSH_MEM_READ ();
1669 } /* while */ 1669 } /* while */
1670 if ((log_level >= LOG_MONITOR2) && (ci->iqp_headx != ci->iqp_tailx)) 1670 if ((cxt1e1_log_level >= LOG_MONITOR2) && (ci->iqp_headx != ci->iqp_tailx))
1671 { 1671 {
1672 int bh; 1672 int bh;
1673 1673
@@ -1821,9 +1821,9 @@ musycc_start_xmit (ci_t * ci, int channum, void *mem_token)
1821 return EROFS; /* how else to flag unwritable state ? */ 1821 return EROFS; /* how else to flag unwritable state ? */
1822 1822
1823#ifdef RLD_TRANS_DEBUGx 1823#ifdef RLD_TRANS_DEBUGx
1824 if (1 || log_level >= LOG_MONITOR2) 1824 if (1 || cxt1e1_log_level >= LOG_MONITOR2)
1825#else 1825#else
1826 if (log_level >= LOG_MONITOR2) 1826 if (cxt1e1_log_level >= LOG_MONITOR2)
1827#endif 1827#endif
1828 { 1828 {
1829 pr_info("++ start_xmt[%d]: state %x start %x full %d free %d required %d stopped %x\n", 1829 pr_info("++ start_xmt[%d]: state %x start %x full %d free %d required %d stopped %x\n",
@@ -1846,7 +1846,7 @@ musycc_start_xmit (ci_t * ci, int channum, void *mem_token)
1846 1846
1847 if (txd_need_cnt == 0) 1847 if (txd_need_cnt == 0)
1848 { 1848 {
1849 if (log_level >= LOG_MONITOR2) 1849 if (cxt1e1_log_level >= LOG_MONITOR2)
1850 pr_info("%s channel %d: no TX data in User buffer\n", ci->devname, channum); 1850 pr_info("%s channel %d: no TX data in User buffer\n", ci->devname, channum);
1851 OS_mem_token_free (mem_token); 1851 OS_mem_token_free (mem_token);
1852 return 0; /* no data to send */ 1852 return 0; /* no data to send */
@@ -1857,7 +1857,7 @@ musycc_start_xmit (ci_t * ci, int channum, void *mem_token)
1857 if (txd_need_cnt > ch->txd_num) /* never enough descriptors for this 1857 if (txd_need_cnt > ch->txd_num) /* never enough descriptors for this
1858 * large a buffer */ 1858 * large a buffer */
1859 { 1859 {
1860 if (log_level >= LOG_DEBUG) 1860 if (cxt1e1_log_level >= LOG_DEBUG)
1861 { 1861 {
1862 pr_info("start_xmit: discarding buffer, insufficient descriptor cnt %d, need %d.\n", 1862 pr_info("start_xmit: discarding buffer, insufficient descriptor cnt %d, need %d.\n",
1863 ch->txd_num, txd_need_cnt + 1); 1863 ch->txd_num, txd_need_cnt + 1);
@@ -1874,7 +1874,7 @@ musycc_start_xmit (ci_t * ci, int channum, void *mem_token)
1874 /************************************************************/ 1874 /************************************************************/
1875 if (txd_need_cnt > ch->txd_free) 1875 if (txd_need_cnt > ch->txd_free)
1876 { 1876 {
1877 if (log_level >= LOG_MONITOR2) 1877 if (cxt1e1_log_level >= LOG_MONITOR2)
1878 { 1878 {
1879 pr_info("start_xmit[%d]: EBUSY - need more descriptors, have %d of %d need %d\n", 1879 pr_info("start_xmit[%d]: EBUSY - need more descriptors, have %d of %d need %d\n",
1880 channum, ch->txd_free, ch->txd_num, txd_need_cnt); 1880 channum, ch->txd_free, ch->txd_num, txd_need_cnt);
diff --git a/drivers/staging/cxt1e1/pmcc4_drv.c b/drivers/staging/cxt1e1/pmcc4_drv.c
index 5c8a3eb0cfc3..341e7a92f099 100644
--- a/drivers/staging/cxt1e1/pmcc4_drv.c
+++ b/drivers/staging/cxt1e1/pmcc4_drv.c
@@ -135,7 +135,7 @@ void musycc_serv_req (mpi_t *, u_int32_t);
135void musycc_update_timeslots (mpi_t *); 135void musycc_update_timeslots (mpi_t *);
136 136
137extern void musycc_update_tx_thp (mch_t *); 137extern void musycc_update_tx_thp (mch_t *);
138extern int log_level; 138extern int cxt1e1_log_level;
139extern int cxt1e1_max_mru; 139extern int cxt1e1_max_mru;
140extern int cxt1e1_max_mtu; 140extern int cxt1e1_max_mtu;
141extern int max_rxdesc_used, max_rxdesc_default; 141extern int max_rxdesc_used, max_rxdesc_default;
@@ -168,12 +168,12 @@ sbecom_set_loglevel (int d)
168 * for card 0 only */ 168 * for card 0 only */
169 } else 169 } else
170 { 170 {
171 if (log_level != d) 171 if (cxt1e1_log_level != d)
172 { 172 {
173 pr_info("log level changed from %d to %d\n", log_level, d); 173 pr_info("log level changed from %d to %d\n", cxt1e1_log_level, d);
174 log_level = d; /* set new */ 174 cxt1e1_log_level = d; /* set new */
175 } else 175 } else
176 pr_info("log level is %d\n", log_level); 176 pr_info("log level is %d\n", cxt1e1_log_level);
177 } 177 }
178} 178}
179 179
@@ -513,7 +513,7 @@ checkPorts (ci_t * ci)
513 if ((value == 0x1c) || (value == 0x19) || (value == 0x12)) 513 if ((value == 0x1c) || (value == 0x19) || (value == 0x12))
514 c4_loop_port (ci, portnum, COMET_MDIAG_LBOFF); /* take port out of any 514 c4_loop_port (ci, portnum, COMET_MDIAG_LBOFF); /* take port out of any
515 * loopbk mode */ 515 * loopbk mode */
516 if (log_level >= LOG_DEBUG) 516 if (cxt1e1_log_level >= LOG_DEBUG)
517 if (value != 0x3f) 517 if (value != 0x3f)
518 pr_warning("%s: BOC value = %x on Port %d\n", 518 pr_warning("%s: BOC value = %x on Port %d\n",
519 ci->devname, value, portnum); 519 ci->devname, value, portnum);
@@ -533,7 +533,7 @@ c4_watchdog (ci_t * ci)
533{ 533{
534 if (drvr_state != SBE_DRVR_AVAILABLE) 534 if (drvr_state != SBE_DRVR_AVAILABLE)
535 { 535 {
536 if (log_level >= LOG_MONITOR) 536 if (cxt1e1_log_level >= LOG_MONITOR)
537 pr_info("drvr not available (%x)\n", drvr_state); 537 pr_info("drvr not available (%x)\n", drvr_state);
538 return; 538 return;
539 } 539 }
@@ -794,19 +794,19 @@ c4_loop_port (ci_t * ci, int portnum, u_int8_t cmd)
794 } 794 }
795 795
796 pci_write_32 ((u_int32_t *) &comet->mdiag, cmd); 796 pci_write_32 ((u_int32_t *) &comet->mdiag, cmd);
797 if (log_level >= LOG_WARN) 797 if (cxt1e1_log_level >= LOG_WARN)
798 pr_info("%s: loopback mode changed to %2x from %2x on Port %d\n", 798 pr_info("%s: loopback mode changed to %2x from %2x on Port %d\n",
799 ci->devname, cmd, loopValue, portnum); 799 ci->devname, cmd, loopValue, portnum);
800 loopValue = pci_read_32 ((u_int32_t *) &comet->mdiag) & COMET_MDIAG_LBMASK; 800 loopValue = pci_read_32 ((u_int32_t *) &comet->mdiag) & COMET_MDIAG_LBMASK;
801 if (loopValue != cmd) 801 if (loopValue != cmd)
802 { 802 {
803 if (log_level >= LOG_ERROR) 803 if (cxt1e1_log_level >= LOG_ERROR)
804 pr_info("%s: write to loop register failed, unknown state for Port %d\n", 804 pr_info("%s: write to loop register failed, unknown state for Port %d\n",
805 ci->devname, portnum); 805 ci->devname, portnum);
806 } 806 }
807 } else 807 } else
808 { 808 {
809 if (log_level >= LOG_WARN) 809 if (cxt1e1_log_level >= LOG_WARN)
810 pr_info("%s: loopback already in that mode (%2x)\n", 810 pr_info("%s: loopback already in that mode (%2x)\n",
811 ci->devname, loopValue); 811 ci->devname, loopValue);
812 } 812 }
@@ -997,7 +997,7 @@ c4_set_port (ci_t * ci, int portnum)
997 pi = &ci->port[portnum]; 997 pi = &ci->port[portnum];
998 pp = &ci->port[portnum].p; 998 pp = &ci->port[portnum].p;
999 e1mode = IS_FRAME_ANY_E1 (pp->port_mode); 999 e1mode = IS_FRAME_ANY_E1 (pp->port_mode);
1000 if (log_level >= LOG_MONITOR2) 1000 if (cxt1e1_log_level >= LOG_MONITOR2)
1001 { 1001 {
1002 pr_info("%s: c4_set_port[%d]: entered, e1mode = %x, openchans %d.\n", 1002 pr_info("%s: c4_set_port[%d]: entered, e1mode = %x, openchans %d.\n",
1003 ci->devname, 1003 ci->devname,
@@ -1278,12 +1278,12 @@ c4_fifo_alloc (mpi_t * pi, int chan, int *len)
1278 } 1278 }
1279 if (max != *len) 1279 if (max != *len)
1280 { 1280 {
1281 if (log_level >= LOG_WARN) 1281 if (cxt1e1_log_level >= LOG_WARN)
1282 pr_info("%s: wanted to allocate %d fifo space, but got only %d\n", 1282 pr_info("%s: wanted to allocate %d fifo space, but got only %d\n",
1283 pi->up->devname, *len, max); 1283 pi->up->devname, *len, max);
1284 *len = max; 1284 *len = max;
1285 } 1285 }
1286 if (log_level >= LOG_DEBUG) 1286 if (cxt1e1_log_level >= LOG_DEBUG)
1287 pr_info("%s: allocated %d fifo at %d for channel %d/%d\n", 1287 pr_info("%s: allocated %d fifo at %d for channel %d/%d\n",
1288 pi->up->devname, max, start, chan, pi->p.portnum); 1288 pi->up->devname, max, start, chan, pi->p.portnum);
1289 for (i = maxstart; i < (maxstart + max); i++) 1289 for (i = maxstart; i < (maxstart + max); i++)
@@ -1296,7 +1296,7 @@ c4_fifo_free (mpi_t * pi, int chan)
1296{ 1296{
1297 int i; 1297 int i;
1298 1298
1299 if (log_level >= LOG_DEBUG) 1299 if (cxt1e1_log_level >= LOG_DEBUG)
1300 pr_info("%s: deallocated fifo for channel %d/%d\n", 1300 pr_info("%s: deallocated fifo for channel %d/%d\n",
1301 pi->up->devname, chan, pi->p.portnum); 1301 pi->up->devname, chan, pi->p.portnum);
1302 for (i = 0; i < 32; i++) 1302 for (i = 0; i < 32; i++)
@@ -1321,7 +1321,7 @@ c4_chan_up (ci_t * ci, int channum)
1321 return ENOENT; 1321 return ENOENT;
1322 if (ch->state == UP) 1322 if (ch->state == UP)
1323 { 1323 {
1324 if (log_level >= LOG_MONITOR) 1324 if (cxt1e1_log_level >= LOG_MONITOR)
1325 pr_info("%s: channel already UP, graceful early exit\n", 1325 pr_info("%s: channel already UP, graceful early exit\n",
1326 ci->devname); 1326 ci->devname);
1327 return 0; 1327 return 0;
@@ -1334,7 +1334,7 @@ c4_chan_up (ci_t * ci, int channum)
1334 { 1334 {
1335 if (ch->p.bitmask[i] & pi->tsm[i]) 1335 if (ch->p.bitmask[i] & pi->tsm[i])
1336 { 1336 {
1337 if (1 || log_level >= LOG_WARN) 1337 if (1 || cxt1e1_log_level >= LOG_WARN)
1338 { 1338 {
1339 pr_info("%s: c4_chan_up[%d] EINVAL (attempt to cfg in-use or unavailable TimeSlot[%d])\n", 1339 pr_info("%s: c4_chan_up[%d] EINVAL (attempt to cfg in-use or unavailable TimeSlot[%d])\n",
1340 ci->devname, channum, i); 1340 ci->devname, channum, i);
@@ -1351,7 +1351,7 @@ c4_chan_up (ci_t * ci, int channum)
1351 nbuf = nts / 8 ? nts / 8 : 1; 1351 nbuf = nts / 8 ? nts / 8 : 1;
1352 if (!nbuf) 1352 if (!nbuf)
1353 { 1353 {
1354 /* if( log_level >= LOG_WARN) */ 1354 /* if( cxt1e1_log_level >= LOG_WARN) */
1355 pr_info("%s: c4_chan_up[%d] ENOBUFS (no TimeSlots assigned)\n", 1355 pr_info("%s: c4_chan_up[%d] ENOBUFS (no TimeSlots assigned)\n",
1356 ci->devname, channum); 1356 ci->devname, channum);
1357 return ENOBUFS; /* this should not happen */ 1357 return ENOBUFS; /* this should not happen */
@@ -1420,7 +1420,7 @@ c4_chan_up (ci_t * ci, int channum)
1420 1420
1421#if 0 1421#if 0
1422 /* DEBUG INFO */ 1422 /* DEBUG INFO */
1423 if (log_level >= LOG_MONITOR) 1423 if (cxt1e1_log_level >= LOG_MONITOR)
1424 pr_info("%s: mode %x rxnum %d (rxused %d def %d) txnum %d (txused %d def %d)\n", 1424 pr_info("%s: mode %x rxnum %d (rxused %d def %d) txnum %d (txused %d def %d)\n",
1425 ci->devname, ch->p.chan_mode, 1425 ci->devname, ch->p.chan_mode,
1426 rxnum, max_rxdesc_used, max_rxdesc_default, 1426 rxnum, max_rxdesc_used, max_rxdesc_default,
@@ -1451,7 +1451,7 @@ c4_chan_up (ci_t * ci, int channum)
1451 1451
1452 if (!(m = OS_mem_token_alloc (cxt1e1_max_mru))) 1452 if (!(m = OS_mem_token_alloc (cxt1e1_max_mru)))
1453 { 1453 {
1454 if (log_level >= LOG_MONITOR) 1454 if (cxt1e1_log_level >= LOG_MONITOR)
1455 pr_info("%s: c4_chan_up[%d] - token alloc failure, size = %d.\n", 1455 pr_info("%s: c4_chan_up[%d] - token alloc failure, size = %d.\n",
1456 ci->devname, channum, cxt1e1_max_mru); 1456 ci->devname, channum, cxt1e1_max_mru);
1457 goto errfree; 1457 goto errfree;
diff --git a/drivers/staging/cxt1e1/sbecom_inline_linux.h b/drivers/staging/cxt1e1/sbecom_inline_linux.h
index 5a72cb5cff42..501a331ded5b 100644
--- a/drivers/staging/cxt1e1/sbecom_inline_linux.h
+++ b/drivers/staging/cxt1e1/sbecom_inline_linux.h
@@ -86,7 +86,7 @@ pci_read_32 (u_int32_t *p)
86 86
87 FLUSH_PCI_READ (); 87 FLUSH_PCI_READ ();
88 v = le32_to_cpu (*p); 88 v = le32_to_cpu (*p);
89 if (log_level >= LOG_DEBUG) 89 if (cxt1e1_log_level >= LOG_DEBUG)
90 pr_info("pci_read : %x = %x\n", (u_int32_t) p, v); 90 pr_info("pci_read : %x = %x\n", (u_int32_t) p, v);
91 return v; 91 return v;
92#else 92#else
@@ -99,7 +99,7 @@ static inline void
99pci_write_32 (u_int32_t *p, u_int32_t v) 99pci_write_32 (u_int32_t *p, u_int32_t v)
100{ 100{
101#ifdef FLOW_DEBUG 101#ifdef FLOW_DEBUG
102 if (log_level >= LOG_DEBUG) 102 if (cxt1e1_log_level >= LOG_DEBUG)
103 pr_info("pci_write: %x = %x\n", (u_int32_t) p, v); 103 pr_info("pci_write: %x = %x\n", (u_int32_t) p, v);
104#endif 104#endif
105 *p = cpu_to_le32 (v); 105 *p = cpu_to_le32 (v);
diff --git a/drivers/staging/easycap/Kconfig b/drivers/staging/easycap/Kconfig
index 9d5fe4ddc30a..bd96f39f2735 100644
--- a/drivers/staging/easycap/Kconfig
+++ b/drivers/staging/easycap/Kconfig
@@ -1,7 +1,6 @@
1config EASYCAP 1config EASYCAP
2 tristate "EasyCAP USB ID 05e1:0408 support" 2 tristate "EasyCAP USB ID 05e1:0408 support"
3 depends on USB && VIDEO_DEV 3 depends on USB && VIDEO_DEV
4 depends on BKL # please fix
5 4
6 ---help--- 5 ---help---
7 This is an integrated audio/video driver for EasyCAP cards with 6 This is an integrated audio/video driver for EasyCAP cards with
diff --git a/drivers/staging/easycap/Makefile b/drivers/staging/easycap/Makefile
index 8a3d911aee5d..f1f2fbebf8f6 100644
--- a/drivers/staging/easycap/Makefile
+++ b/drivers/staging/easycap/Makefile
@@ -10,4 +10,5 @@ ccflags-y := -Wall
10ccflags-y += -DEASYCAP_IS_VIDEODEV_CLIENT 10ccflags-y += -DEASYCAP_IS_VIDEODEV_CLIENT
11ccflags-y += -DEASYCAP_NEEDS_V4L2_DEVICE_H 11ccflags-y += -DEASYCAP_NEEDS_V4L2_DEVICE_H
12ccflags-y += -DEASYCAP_NEEDS_V4L2_FOPS 12ccflags-y += -DEASYCAP_NEEDS_V4L2_FOPS
13ccflags-y += -DEASYCAP_NEEDS_UNLOCKED_IOCTL
13 14
diff --git a/drivers/staging/easycap/README b/drivers/staging/easycap/README
index 3775481f05e8..6b5ac0d34bd9 100644
--- a/drivers/staging/easycap/README
+++ b/drivers/staging/easycap/README
@@ -24,6 +24,9 @@ Two kinds of EasyCAP have this USB ID, namely:
24BUILD OPTIONS AND DEPENDENCIES 24BUILD OPTIONS AND DEPENDENCIES
25------------------------------ 25------------------------------
26 26
27Unless EASYCAP_DEBUG is defined during compilation it will not be possible
28to select a debug level at the time of module installation.
29
27If the parameter EASYCAP_IS_VIDEODEV_CLIENT is undefined during compilation 30If the parameter EASYCAP_IS_VIDEODEV_CLIENT is undefined during compilation
28the built module is entirely independent of the videodev module, and when 31the built module is entirely independent of the videodev module, and when
29the EasyCAP is physically plugged into a USB port the special files 32the EasyCAP is physically plugged into a USB port the special files
@@ -33,41 +36,54 @@ respectively.
33If the parameter EASYCAP_IS_VIDEODEV_CLIENT is defined during compilation 36If the parameter EASYCAP_IS_VIDEODEV_CLIENT is defined during compilation
34the built easycap module is configured to register with the videodev module, 37the built easycap module is configured to register with the videodev module,
35in which case the special files created when the EasyCAP is plugged in are 38in which case the special files created when the EasyCAP is plugged in are
36/dev/video0 and /dev/easysnd0. Use of the easycap module as a client of 39/dev/video0 and /dev/easysnd0.
37the videodev module has received very little testing as of June 2010. 40
41During in-tree builds the following should should be defined whenever the
42parameter EASYCAP_IS_VIDEODEV_CLIENT is defined:
43
44EASYCAP_NEEDS_V4L2_DEVICE_H
45EASYCAP_NEEDS_V4L2_FOPS
46EASYCAP_NEEDS_UNLOCKED_IOCTL
47
48If the build is performed out-of-tree against older kernels the parameters
49to be defined depend on the kernel version in a way which will not be
50discussed here.
38 51
39 52
40KNOWN BUILD PROBLEMS 53KNOWN RUNTIME ISSUES
41-------------------- 54--------------------
42 55
43(1) Recent gcc versions may generate the message: 56(1) Intentionally, this driver will not stream material which is unambiguously
57identified by the hardware as copy-protected. Normal video output will be
58present for about a minute but will then freeze when this situation arises.
44 59
45 warning: the frame size of .... bytes is larger than 1024 bytes 60(2) The controls for luminance, contrast, saturation, hue and volume may not
61always work properly.
46 62
47This warning can be suppressed by specifying in the Makefile: 63(3) Reduced-resolution S-Video seems to suffer from moire artefacts.
48 64
49 EXTRA_CFLAGS += -Wframe-larger-than=8192
50 65
51but it would be preferable to remove the cause of the warning. 66INPUT NUMBERING
67---------------
52 68
69For the EasyCAP with S-VIDEO input cable the driver regards a request for
70inputs numbered 0 or 1 as referring to CVBS and a request for input
71numbered 5 as referring to S-VIDEO.
53 72
54KNOWN RUNTIME ISSUES 73For the EasyCAP with four CVBS inputs the driver expects to be asked for
55-------------------- 74any one of inputs numbered 1,2,3,4. If input 0 is asked for, it is
75interpreted as input 1.
56 76
57(1) Randomly (maybe 5 to 10% of occasions) the driver fails to produce any
58output at start-up. Closing mplayer (or whatever the user program is) and
59restarting it restores normal performance without any other remedial action
60being necessary. The reason for this is not known.
61 77
62(2) Intentionally, this driver will not stream material which is unambiguously 78MODULE PARAMETERS
63identified by the hardware as copy-protected. The video output will freeze 79-----------------
64within about a minute when this situation arises.
65 80
66(3) The controls for luminance, contrast, saturation, hue and volume may not 81Three module parameters are defined:
67always work properly.
68 82
69(4) Reduced-resolution S-Video seems to suffer from moire artefacts. No 83debug the easycap module is configured at diagnostic level n (0 to 9)
70attempt has yet been made to rememdy this. 84gain audio gain level n (0 to 31, default is 16)
85bars 0 => testcard bars when incoming video signal is lost
86 1 => testcard bars when incoming video signal is lost (default)
71 87
72 88
73SUPPORTED TV STANDARDS AND RESOLUTIONS 89SUPPORTED TV STANDARDS AND RESOLUTIONS
@@ -82,18 +98,29 @@ usable as (for example) the "norm=" parameter in the mplayer command:
82 PAL_60, NTSC_443, 98 PAL_60, NTSC_443,
83 PAL_M. 99 PAL_M.
84 100
101In addition, the driver offers "custom" pseudo-standards with a framerate
102which is 20% of the usual framerate. These pseudo-standards are named:
103
104 PAL_BGHIN_SLOW, NTSC_N_443_SLOW,
105 PAL_Nc_SLOW, NTSC_N_SLOW,
106 SECAM_SLOW, NTSC_M_SLOW, NTSC_M_JP_SLOW,
107 PAL_60_SLOW, NTSC_443_SLOW,
108 PAL_M_SLOW.
109
110
85The available picture sizes are: 111The available picture sizes are:
86 112
87 at 25 frames per second: 720x576, 704x576, 640x480, 360x288, 320x240; 113 at 25 frames per second: 720x576, 704x576, 640x480, 360x288, 320x240;
88 at 30 frames per second: 720x480, 640x480, 360x240, 320x240; 114 at 30 frames per second: 720x480, 640x480, 360x240, 320x240.
89 115
90 116
91WHAT'S TESTED AND WHAT'S NOT 117WHAT'S TESTED AND WHAT'S NOT
92---------------------------- 118----------------------------
93 119
94This driver is known to work with mplayer, mencoder, tvtime and sufficiently 120This driver is known to work with mplayer, mencoder, tvtime, zoneminder,
95recent versions of vlc. An interface to ffmpeg is implemented, but serious 121xawtv, gstreamer and sufficiently recent versions of vlc. An interface
96audio-video synchronization problems remain. 122to ffmpeg is implemented, but serious audio-video synchronization problems
123remain.
97 124
98The driver is designed to support all the TV standards accepted by the 125The driver is designed to support all the TV standards accepted by the
99hardware, but as yet it has actually been tested on only a few of these. 126hardware, but as yet it has actually been tested on only a few of these.
@@ -101,10 +128,7 @@ hardware, but as yet it has actually been tested on only a few of these.
101I have been unable to test and calibrate the S-video input myself because I 128I have been unable to test and calibrate the S-video input myself because I
102do not possess any equipment with S-video output. 129do not possess any equipment with S-video output.
103 130
104This driver does not understand the V4L1 IOCTL commands, so programs such 131This driver does not understand the V4L1 IOCTL commands.
105as camorama are not compatible. There are reports that the driver does
106work with sufficiently recent (V4L2) versions of zoneminder, but I have not
107attempted to confirm this myself.
108 132
109 133
110UDEV RULES 134UDEV RULES
@@ -120,6 +144,17 @@ ATTRS{idVendor}=="05e1", ATTRS{idProduct}=="0408", \
120LABEL="easycap_rules_end" 144LABEL="easycap_rules_end"
121 145
122 146
147MODPROBE CONFIGURATION
148----------------------
149
150The easycap module is in competition with the module snd-usb-audio for the
151EasyCAP's audio channel, and its installation can be aided by providing a
152file in directory /etc/modprobe.d with content:
153
154options easycap gain=16 bars=1
155install easycap /sbin/rmmod snd-usb-audio; /sbin/modprobe --ignore-install easycap
156
157
123ACKNOWLEGEMENTS AND REFERENCES 158ACKNOWLEGEMENTS AND REFERENCES
124------------------------------ 159------------------------------
125This driver makes use of information contained in the Syntek Semicon DC-1125 160This driver makes use of information contained in the Syntek Semicon DC-1125
diff --git a/drivers/staging/easycap/easycap.h b/drivers/staging/easycap/easycap.h
index 884263b2775d..8ebf96f8a242 100644
--- a/drivers/staging/easycap/easycap.h
+++ b/drivers/staging/easycap/easycap.h
@@ -33,6 +33,7 @@
33 * EASYCAP_NEEDS_USBVIDEO_H 33 * EASYCAP_NEEDS_USBVIDEO_H
34 * EASYCAP_NEEDS_V4L2_DEVICE_H 34 * EASYCAP_NEEDS_V4L2_DEVICE_H
35 * EASYCAP_NEEDS_V4L2_FOPS 35 * EASYCAP_NEEDS_V4L2_FOPS
36 * EASYCAP_NEEDS_UNLOCKED_IOCTL
36 * 37 *
37 * IF REQUIRED THEY MUST BE EXTERNALLY DEFINED, FOR EXAMPLE AS COMPILER 38 * IF REQUIRED THEY MUST BE EXTERNALLY DEFINED, FOR EXAMPLE AS COMPILER
38 * OPTIONS. 39 * OPTIONS.
@@ -42,35 +43,24 @@
42#if (!defined(EASYCAP_H)) 43#if (!defined(EASYCAP_H))
43#define EASYCAP_H 44#define EASYCAP_H
44 45
45#if defined(EASYCAP_DEBUG) 46/*---------------------------------------------------------------------------*/
46#if (9 < EASYCAP_DEBUG) 47/*
47#error Debug levels 0 to 9 are okay.\ 48 * THESE ARE NORMALLY DEFINED
48 To achieve higher levels, remove this trap manually from easycap.h 49 */
49#endif 50/*---------------------------------------------------------------------------*/
50#endif /*EASYCAP_DEBUG*/ 51#define PATIENCE 500
52#undef PREFER_NTSC
53#define PERSEVERE
51/*---------------------------------------------------------------------------*/ 54/*---------------------------------------------------------------------------*/
52/* 55/*
53 * THESE ARE FOR MAINTENANCE ONLY - NORMALLY UNDEFINED: 56 * THESE ARE FOR MAINTENANCE ONLY - NORMALLY UNDEFINED:
54 */ 57 */
55/*---------------------------------------------------------------------------*/ 58/*---------------------------------------------------------------------------*/
56#undef PREFER_NTSC
57#undef EASYCAP_TESTCARD 59#undef EASYCAP_TESTCARD
58#undef EASYCAP_TESTTONE 60#undef EASYCAP_TESTTONE
59#undef LOCKFRAME
60#undef NOREADBACK 61#undef NOREADBACK
61#undef AUDIOTIME 62#undef AUDIOTIME
62/*---------------------------------------------------------------------------*/ 63/*---------------------------------------------------------------------------*/
63/*
64 *
65 * DEFINE BRIDGER TO ACTIVATE THE ROUTINE FOR BRIDGING VIDEOTAPE DROPOUTS.
66 *
67 * *** UNDER DEVELOPMENT/TESTING - NOT READY YET!***
68 *
69 */
70/*---------------------------------------------------------------------------*/
71#undef BRIDGER
72/*---------------------------------------------------------------------------*/
73
74#include <linux/kernel.h> 64#include <linux/kernel.h>
75#include <linux/errno.h> 65#include <linux/errno.h>
76#include <linux/init.h> 66#include <linux/init.h>
@@ -92,25 +82,14 @@
92 82
93/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 83/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
94#if defined(EASYCAP_IS_VIDEODEV_CLIENT) 84#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
95#if (!defined(__OLD_VIDIOC_))
96#define __OLD_VIDIOC_
97#endif /* !defined(__OLD_VIDIOC_) */
98
99#include <media/v4l2-dev.h> 85#include <media/v4l2-dev.h>
100
101#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H) 86#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
102#include <media/v4l2-device.h> 87#include <media/v4l2-device.h>
103#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/ 88#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
104#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 89#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
105/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ 90/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
106
107#if (!defined(__OLD_VIDIOC_))
108#define __OLD_VIDIOC_
109#endif /* !defined(__OLD_VIDIOC_) */
110#include <linux/videodev2.h> 91#include <linux/videodev2.h>
111
112#include <linux/soundcard.h> 92#include <linux/soundcard.h>
113
114#if defined(EASYCAP_NEEDS_USBVIDEO_H) 93#if defined(EASYCAP_NEEDS_USBVIDEO_H)
115#include <config/video/usbvideo.h> 94#include <config/video/usbvideo.h>
116#endif /*EASYCAP_NEEDS_USBVIDEO_H*/ 95#endif /*EASYCAP_NEEDS_USBVIDEO_H*/
@@ -121,7 +100,6 @@
121 100
122#define STRINGIZE_AGAIN(x) #x 101#define STRINGIZE_AGAIN(x) #x
123#define STRINGIZE(x) STRINGIZE_AGAIN(x) 102#define STRINGIZE(x) STRINGIZE_AGAIN(x)
124
125/*---------------------------------------------------------------------------*/ 103/*---------------------------------------------------------------------------*/
126/* VENDOR, PRODUCT: Syntek Semiconductor Co., Ltd 104/* VENDOR, PRODUCT: Syntek Semiconductor Co., Ltd
127 * 105 *
@@ -135,12 +113,12 @@
135#define USB_EASYCAP_VENDOR_ID 0x05e1 113#define USB_EASYCAP_VENDOR_ID 0x05e1
136#define USB_EASYCAP_PRODUCT_ID 0x0408 114#define USB_EASYCAP_PRODUCT_ID 0x0408
137 115
138#define EASYCAP_DRIVER_VERSION "0.8.21" 116#define EASYCAP_DRIVER_VERSION "0.8.41"
139#define EASYCAP_DRIVER_DESCRIPTION "easycapdc60" 117#define EASYCAP_DRIVER_DESCRIPTION "easycapdc60"
140 118
141#define USB_SKEL_MINOR_BASE 192 119#define USB_SKEL_MINOR_BASE 192
142#define VIDEO_DEVICE_MANY 8 120#define DONGLE_MANY 8
143 121#define INPUT_MANY 6
144/*---------------------------------------------------------------------------*/ 122/*---------------------------------------------------------------------------*/
145/* 123/*
146 * DEFAULT LUMINANCE, CONTRAST, SATURATION AND HUE 124 * DEFAULT LUMINANCE, CONTRAST, SATURATION AND HUE
@@ -164,6 +142,8 @@
164#if (USB_2_0_MAXPACKETSIZE > PAGE_SIZE) 142#if (USB_2_0_MAXPACKETSIZE > PAGE_SIZE)
165#error video_isoc_buffer[.] will not be big enough 143#error video_isoc_buffer[.] will not be big enough
166#endif 144#endif
145#define VIDEO_JUNK_TOLERATE VIDEO_ISOC_BUFFER_MANY
146#define VIDEO_LOST_TOLERATE 50
167/*---------------------------------------------------------------------------*/ 147/*---------------------------------------------------------------------------*/
168/* 148/*
169 * VIDEO BUFFERS 149 * VIDEO BUFFERS
@@ -210,7 +190,17 @@
210#define NTSC_M_JP 5 190#define NTSC_M_JP 5
211#define PAL_60 7 191#define PAL_60 7
212#define PAL_M 9 192#define PAL_M 9
213#define STANDARD_MANY 10 193#define PAL_BGHIN_SLOW 10
194#define PAL_Nc_SLOW 12
195#define SECAM_SLOW 14
196#define NTSC_N_SLOW 16
197#define NTSC_N_443_SLOW 18
198#define NTSC_M_SLOW 11
199#define NTSC_443_SLOW 13
200#define NTSC_M_JP_SLOW 15
201#define PAL_60_SLOW 17
202#define PAL_M_SLOW 19
203#define STANDARD_MANY 20
214/*---------------------------------------------------------------------------*/ 204/*---------------------------------------------------------------------------*/
215/* 205/*
216 * ENUMS 206 * ENUMS
@@ -238,7 +228,6 @@ PIXELFORMAT_MANY
238enum { 228enum {
239FIELD_NONE, 229FIELD_NONE,
240FIELD_INTERLACED, 230FIELD_INTERLACED,
241FIELD_ALTERNATE,
242INTERLACE_MANY 231INTERLACE_MANY
243}; 232};
244#define SETTINGS_MANY (STANDARD_MANY * \ 233#define SETTINGS_MANY (STANDARD_MANY * \
@@ -251,11 +240,18 @@ INTERLACE_MANY
251 * STRUCTURE DEFINITIONS 240 * STRUCTURE DEFINITIONS
252 */ 241 */
253/*---------------------------------------------------------------------------*/ 242/*---------------------------------------------------------------------------*/
243struct easycap_dongle {
244struct easycap *peasycap;
245struct mutex mutex_video;
246struct mutex mutex_audio;
247};
248/*---------------------------------------------------------------------------*/
254struct data_buffer { 249struct data_buffer {
255struct list_head list_head; 250struct list_head list_head;
256void *pgo; 251void *pgo;
257void *pto; 252void *pto;
258__u16 kount; 253__u16 kount;
254__u16 input;
259}; 255};
260/*---------------------------------------------------------------------------*/ 256/*---------------------------------------------------------------------------*/
261struct data_urb { 257struct data_urb {
@@ -274,6 +270,22 @@ __u16 mask;
274char name[128]; 270char name[128];
275struct v4l2_format v4l2_format; 271struct v4l2_format v4l2_format;
276}; 272};
273struct inputset {
274int input;
275int input_ok;
276int standard_offset;
277int standard_offset_ok;
278int format_offset;
279int format_offset_ok;
280int brightness;
281int brightness_ok;
282int contrast;
283int contrast_ok;
284int saturation;
285int saturation_ok;
286int hue;
287int hue_ok;
288};
277/*---------------------------------------------------------------------------*/ 289/*---------------------------------------------------------------------------*/
278/* 290/*
279 * easycap.ilk == 0 => CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=256 291 * easycap.ilk == 0 => CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=256
@@ -282,6 +294,19 @@ struct v4l2_format v4l2_format;
282 */ 294 */
283/*---------------------------------------------------------------------------*/ 295/*---------------------------------------------------------------------------*/
284struct easycap { 296struct easycap {
297#define TELLTALE "expectedstring"
298char telltale[16];
299int isdongle;
300
301/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
302#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
303struct video_device video_device;
304#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
305struct v4l2_device v4l2_device;
306#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
307#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
308/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
309int status;
285unsigned int audio_pages_per_fragment; 310unsigned int audio_pages_per_fragment;
286unsigned int audio_bytes_per_fragment; 311unsigned int audio_bytes_per_fragment;
287unsigned int audio_buffer_page_many; 312unsigned int audio_buffer_page_many;
@@ -291,26 +316,14 @@ unsigned int audio_buffer_page_many;
291__s16 oldaudio; 316__s16 oldaudio;
292#endif /*UPSAMPLE*/ 317#endif /*UPSAMPLE*/
293 318
294struct easycap_format easycap_format[1 + SETTINGS_MANY];
295
296int ilk; 319int ilk;
297bool microphone; 320bool microphone;
298 321
299/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
300#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
301struct video_device *pvideo_device;
302#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
303/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
304
305struct usb_device *pusb_device; 322struct usb_device *pusb_device;
306struct usb_interface *pusb_interface; 323struct usb_interface *pusb_interface;
307 324
308struct kref kref; 325struct kref kref;
309 326
310struct mutex mutex_mmap_video[FRAME_BUFFER_MANY];
311struct mutex mutex_timeval0;
312struct mutex mutex_timeval1;
313
314int queued[FRAME_BUFFER_MANY]; 327int queued[FRAME_BUFFER_MANY];
315int done[FRAME_BUFFER_MANY]; 328int done[FRAME_BUFFER_MANY];
316 329
@@ -321,16 +334,24 @@ int input;
321int polled; 334int polled;
322int standard_offset; 335int standard_offset;
323int format_offset; 336int format_offset;
337struct inputset inputset[INPUT_MANY];
324 338
339bool ntsc;
325int fps; 340int fps;
326int usec; 341int usec;
327int tolerate; 342int tolerate;
343int skip;
344int skipped;
345int lost[INPUT_MANY];
328int merit[180]; 346int merit[180];
329 347
330struct timeval timeval0; 348struct timeval timeval0;
331struct timeval timeval1; 349struct timeval timeval1;
332struct timeval timeval2; 350struct timeval timeval2;
351struct timeval timeval3;
352struct timeval timeval6;
333struct timeval timeval7; 353struct timeval timeval7;
354struct timeval timeval8;
334long long int dnbydt; 355long long int dnbydt;
335 356
336int video_interface; 357int video_interface;
@@ -347,8 +368,6 @@ int video_idle;
347int video_eof; 368int video_eof;
348int video_junk; 369int video_junk;
349 370
350int fudge;
351
352struct data_buffer video_isoc_buffer[VIDEO_ISOC_BUFFER_MANY]; 371struct data_buffer video_isoc_buffer[VIDEO_ISOC_BUFFER_MANY];
353struct data_buffer \ 372struct data_buffer \
354 field_buffer[FIELD_BUFFER_MANY][(FIELD_BUFFER_SIZE/PAGE_SIZE)]; 373 field_buffer[FIELD_BUFFER_MANY][(FIELD_BUFFER_SIZE/PAGE_SIZE)];
@@ -358,6 +377,13 @@ struct data_buffer \
358struct list_head urb_video_head; 377struct list_head urb_video_head;
359struct list_head *purb_video_head; 378struct list_head *purb_video_head;
360 379
380__u8 cache[8];
381__u8 *pcache;
382int video_mt;
383int audio_mt;
384long long audio_bytes;
385__u32 isequence;
386
361int vma_many; 387int vma_many;
362 388
363/*---------------------------------------------------------------------------*/ 389/*---------------------------------------------------------------------------*/
@@ -383,7 +409,6 @@ int frame_lock; /* Flag set to 1 by DQBUF and cleared by QBUF */
383 */ 409 */
384/*---------------------------------------------------------------------------*/ 410/*---------------------------------------------------------------------------*/
385__u32 pixelformat; 411__u32 pixelformat;
386__u32 field;
387int width; 412int width;
388int height; 413int height;
389int bytesperpixel; 414int bytesperpixel;
@@ -463,8 +488,10 @@ struct data_buffer audio_buffer[];
463void easycap_complete(struct urb *); 488void easycap_complete(struct urb *);
464int easycap_open(struct inode *, struct file *); 489int easycap_open(struct inode *, struct file *);
465int easycap_release(struct inode *, struct file *); 490int easycap_release(struct inode *, struct file *);
466long easycap_ioctl(struct file *, unsigned int, unsigned long); 491long easycap_ioctl_noinode(struct file *, unsigned int, \
467 492 unsigned long);
493int easycap_ioctl(struct inode *, struct file *, unsigned int, \
494 unsigned long);
468/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 495/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
469#if defined(EASYCAP_IS_VIDEODEV_CLIENT) 496#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
470int easycap_open_noinode(struct file *); 497int easycap_open_noinode(struct file *);
@@ -489,12 +516,10 @@ int kill_video_urbs(struct easycap *);
489int field2frame(struct easycap *); 516int field2frame(struct easycap *);
490int redaub(struct easycap *, void *, void *, \ 517int redaub(struct easycap *, void *, void *, \
491 int, int, __u8, __u8, bool); 518 int, int, __u8, __u8, bool);
492void debrief(struct easycap *);
493void sayreadonly(struct easycap *);
494void easycap_testcard(struct easycap *, int); 519void easycap_testcard(struct easycap *, int);
495int explain_ioctl(__u32);
496int explain_cid(__u32);
497int fillin_formats(void); 520int fillin_formats(void);
521int reset(struct easycap *);
522int newinput(struct easycap *, int);
498int adjust_standard(struct easycap *, v4l2_std_id); 523int adjust_standard(struct easycap *, v4l2_std_id);
499int adjust_format(struct easycap *, __u32, __u32, __u32, \ 524int adjust_format(struct easycap *, __u32, __u32, __u32, \
500 int, bool); 525 int, bool);
@@ -512,7 +537,10 @@ void easysnd_complete(struct urb *);
512ssize_t easysnd_read(struct file *, char __user *, size_t, loff_t *); 537ssize_t easysnd_read(struct file *, char __user *, size_t, loff_t *);
513int easysnd_open(struct inode *, struct file *); 538int easysnd_open(struct inode *, struct file *);
514int easysnd_release(struct inode *, struct file *); 539int easysnd_release(struct inode *, struct file *);
515long easysnd_ioctl(struct file *, unsigned int, unsigned long); 540long easysnd_ioctl_noinode(struct file *, unsigned int, \
541 unsigned long);
542int easysnd_ioctl(struct inode *, struct file *, unsigned int, \
543 unsigned long);
516unsigned int easysnd_poll(struct file *, poll_table *); 544unsigned int easysnd_poll(struct file *, poll_table *);
517void easysnd_delete(struct kref *); 545void easysnd_delete(struct kref *);
518int submit_audio_urbs(struct easycap *); 546int submit_audio_urbs(struct easycap *);
@@ -532,11 +560,11 @@ int wakeup_device(struct usb_device *);
532int confirm_resolution(struct usb_device *); 560int confirm_resolution(struct usb_device *);
533int confirm_stream(struct usb_device *); 561int confirm_stream(struct usb_device *);
534 562
535int setup_stk(struct usb_device *); 563int setup_stk(struct usb_device *, bool);
536int setup_saa(struct usb_device *); 564int setup_saa(struct usb_device *, bool);
537int setup_vt(struct usb_device *); 565int setup_vt(struct usb_device *);
538int check_stk(struct usb_device *); 566int check_stk(struct usb_device *, bool);
539int check_saa(struct usb_device *); 567int check_saa(struct usb_device *, bool);
540int ready_saa(struct usb_device *); 568int ready_saa(struct usb_device *);
541int merit_saa(struct usb_device *); 569int merit_saa(struct usb_device *);
542int check_vt(struct usb_device *); 570int check_vt(struct usb_device *);
@@ -554,12 +582,9 @@ int stop_100(struct usb_device *);
554int write_300(struct usb_device *); 582int write_300(struct usb_device *);
555int read_vt(struct usb_device *, __u16); 583int read_vt(struct usb_device *, __u16);
556int write_vt(struct usb_device *, __u16, __u16); 584int write_vt(struct usb_device *, __u16, __u16);
557
558int set2to78(struct usb_device *);
559int set2to93(struct usb_device *);
560
561int regset(struct usb_device *, __u16, __u16); 585int regset(struct usb_device *, __u16, __u16);
562int regget(struct usb_device *, __u16, void *); 586int regget(struct usb_device *, __u16, void *);
587int isdongle(struct easycap *);
563/*---------------------------------------------------------------------------*/ 588/*---------------------------------------------------------------------------*/
564struct signed_div_result { 589struct signed_div_result {
565long long int quotient; 590long long int quotient;
@@ -587,24 +612,41 @@ unsigned long long int remainder;
587 } \ 612 } \
588} while (0) 613} while (0)
589/*---------------------------------------------------------------------------*/ 614/*---------------------------------------------------------------------------*/
590 615/*
616 * MACROS SAM(...) AND JOM(...) ALLOW DIAGNOSTIC OUTPUT TO BE TAGGED WITH
617 * THE IDENTITY OF THE DONGLE TO WHICH IT APPLIES, BUT IF INVOKED WHEN THE
618 * POINTER peasycap IS INVALID AN Oops IS LIKELY, AND ITS CAUSE MAY NOT BE
619 * IMMEDIATELY OBVIOUS FROM A CASUAL READING OF THE SOURCE CODE. BEWARE.
620*/
621/*---------------------------------------------------------------------------*/
591#define SAY(format, args...) do { \ 622#define SAY(format, args...) do { \
592 printk(KERN_DEBUG "easycap: %s: " format, __func__, ##args); \ 623 printk(KERN_DEBUG "easycap:: %s: " \
624 format, __func__, ##args); \
625} while (0)
626#define SAM(format, args...) do { \
627 printk(KERN_DEBUG "easycap::%i%s: " \
628 format, peasycap->isdongle, __func__, ##args);\
593} while (0) 629} while (0)
594
595 630
596#if defined(EASYCAP_DEBUG) 631#if defined(EASYCAP_DEBUG)
597#define JOT(n, format, args...) do { \ 632#define JOT(n, format, args...) do { \
598 if (n <= easycap_debug) { \ 633 if (n <= easycap_debug) { \
599 printk(KERN_DEBUG "easycap: %s: " format, __func__, ##args); \ 634 printk(KERN_DEBUG "easycap:: %s: " \
635 format, __func__, ##args);\
600 } \ 636 } \
601} while (0) 637} while (0)
638#define JOM(n, format, args...) do { \
639 if (n <= easycap_debug) { \
640 printk(KERN_DEBUG "easycap::%i%s: " \
641 format, peasycap->isdongle, __func__, ##args);\
642 } \
643} while (0)
644
602#else 645#else
603#define JOT(n, format, args...) do {} while (0) 646#define JOT(n, format, args...) do {} while (0)
647#define JOM(n, format, args...) do {} while (0)
604#endif /*EASYCAP_DEBUG*/ 648#endif /*EASYCAP_DEBUG*/
605 649
606#define POUT JOT(8, ":-(in file %s line %4i\n", __FILE__, __LINE__)
607
608#define MICROSECONDS(X, Y) \ 650#define MICROSECONDS(X, Y) \
609 ((1000000*((long long int)(X.tv_sec - Y.tv_sec))) + \ 651 ((1000000*((long long int)(X.tv_sec - Y.tv_sec))) + \
610 (long long int)(X.tv_usec - Y.tv_usec)) 652 (long long int)(X.tv_usec - Y.tv_usec))
diff --git a/drivers/staging/easycap/easycap_debug.h b/drivers/staging/easycap/easycap_debug.h
index 1d10d7ea7d68..b6b571843125 100644
--- a/drivers/staging/easycap/easycap_debug.h
+++ b/drivers/staging/easycap/easycap_debug.h
@@ -25,3 +25,5 @@
25*/ 25*/
26/*****************************************************************************/ 26/*****************************************************************************/
27extern int easycap_debug; 27extern int easycap_debug;
28extern int easycap_gain;
29extern struct easycap_dongle easycap_dongle[];
diff --git a/drivers/staging/easycap/easycap_ioctl.c b/drivers/staging/easycap/easycap_ioctl.c
index 9a42ae02cd5d..447953a4e80c 100644
--- a/drivers/staging/easycap/easycap_ioctl.c
+++ b/drivers/staging/easycap/easycap_ioctl.c
@@ -36,53 +36,101 @@
36 * UNLESS THERE IS A PREMATURE ERROR RETURN THIS ROUTINE UPDATES THE 36 * UNLESS THERE IS A PREMATURE ERROR RETURN THIS ROUTINE UPDATES THE
37 * FOLLOWING: 37 * FOLLOWING:
38 * peasycap->standard_offset 38 * peasycap->standard_offset
39 * peasycap->inputset[peasycap->input].standard_offset
39 * peasycap->fps 40 * peasycap->fps
40 * peasycap->usec 41 * peasycap->usec
41 * peasycap->tolerate 42 * peasycap->tolerate
43 * peasycap->skip
42 */ 44 */
43/*---------------------------------------------------------------------------*/ 45/*---------------------------------------------------------------------------*/
44int adjust_standard(struct easycap *peasycap, v4l2_std_id std_id) 46int adjust_standard(struct easycap *peasycap, v4l2_std_id std_id)
45{ 47{
46struct easycap_standard const *peasycap_standard; 48struct easycap_standard const *peasycap_standard;
47__u16 reg, set; 49__u16 reg, set;
48int ir, rc, need; 50int ir, rc, need, k;
49unsigned int itwas, isnow; 51unsigned int itwas, isnow;
52bool resubmit;
50 53
54if (NULL == peasycap) {
55 SAY("ERROR: peasycap is NULL\n");
56 return -EFAULT;
57}
51if ((struct usb_device *)NULL == peasycap->pusb_device) { 58if ((struct usb_device *)NULL == peasycap->pusb_device) {
52 SAY("ERROR: peasycap->pusb_device is NULL\n"); 59 SAM("ERROR: peasycap->pusb_device is NULL\n");
53 return -EFAULT; 60 return -EFAULT;
54} 61}
55peasycap_standard = &easycap_standard[0]; 62peasycap_standard = &easycap_standard[0];
56while (0xFFFF != peasycap_standard->mask) { 63while (0xFFFF != peasycap_standard->mask) {
57 if (std_id & peasycap_standard->v4l2_standard.id) 64 if (std_id == peasycap_standard->v4l2_standard.id)
58 break; 65 break;
59 peasycap_standard++; 66 peasycap_standard++;
60} 67}
61if (0xFFFF == peasycap_standard->mask) { 68if (0xFFFF == peasycap_standard->mask) {
62 SAY("ERROR: 0x%08X=std_id: standard not found\n", \ 69 peasycap_standard = &easycap_standard[0];
70 while (0xFFFF != peasycap_standard->mask) {
71 if (std_id & peasycap_standard->v4l2_standard.id)
72 break;
73 peasycap_standard++;
74 }
75}
76if (0xFFFF == peasycap_standard->mask) {
77 SAM("ERROR: 0x%08X=std_id: standard not found\n", \
63 (unsigned int)std_id); 78 (unsigned int)std_id);
64 return -EINVAL; 79 return -EINVAL;
65} 80}
66SAY("user requests standard: %s\n", \ 81SAM("selected standard: %s\n", \
67 &(peasycap_standard->v4l2_standard.name[0])); 82 &(peasycap_standard->v4l2_standard.name[0]));
68if (peasycap->standard_offset == \ 83if (peasycap->standard_offset == \
69 (int)(peasycap_standard - &easycap_standard[0])) { 84 (int)(peasycap_standard - &easycap_standard[0])) {
70 SAY("requested standard already in effect\n"); 85 SAM("requested standard already in effect\n");
71 return 0; 86 return 0;
72} 87}
73peasycap->standard_offset = (int)(peasycap_standard - &easycap_standard[0]); 88peasycap->standard_offset = (int)(peasycap_standard - &easycap_standard[0]);
89for (k = 0; k < INPUT_MANY; k++) {
90 if (!peasycap->inputset[k].standard_offset_ok) {
91 peasycap->inputset[k].standard_offset = \
92 peasycap->standard_offset;
93 }
94}
95if ((0 <= peasycap->input) && (INPUT_MANY > peasycap->input)) {
96 peasycap->inputset[peasycap->input].standard_offset = \
97 peasycap->standard_offset;
98 peasycap->inputset[peasycap->input].standard_offset_ok = 1;
99} else
100 JOM(8, "%i=peasycap->input\n", peasycap->input);
74peasycap->fps = peasycap_standard->v4l2_standard.frameperiod.denominator / \ 101peasycap->fps = peasycap_standard->v4l2_standard.frameperiod.denominator / \
75 peasycap_standard->v4l2_standard.frameperiod.numerator; 102 peasycap_standard->v4l2_standard.frameperiod.numerator;
76if (!peasycap->fps) { 103switch (peasycap->fps) {
77 SAY("MISTAKE: frames-per-second is zero\n"); 104case 6:
78 return -EFAULT; 105case 30: {
106 peasycap->ntsc = true;
107 break;
79} 108}
80JOT(8, "%i frames-per-second\n", peasycap->fps); 109case 5:
81peasycap->usec = 1000000 / (2 * peasycap->fps); 110case 25: {
82peasycap->tolerate = 1000 * (25 / peasycap->fps); 111 peasycap->ntsc = false;
83 112 break;
84kill_video_urbs(peasycap); 113}
85 114default: {
115 SAM("MISTAKE: %i=frames-per-second\n", peasycap->fps);
116 return -ENOENT;
117}
118}
119JOM(8, "%i frames-per-second\n", peasycap->fps);
120if (0x8000 & peasycap_standard->mask) {
121 peasycap->skip = 5;
122 peasycap->usec = 1000000 / (2 * (5 * peasycap->fps));
123 peasycap->tolerate = 1000 * (25 / (5 * peasycap->fps));
124} else {
125 peasycap->skip = 0;
126 peasycap->usec = 1000000 / (2 * peasycap->fps);
127 peasycap->tolerate = 1000 * (25 / peasycap->fps);
128}
129if (peasycap->video_isoc_streaming) {
130 resubmit = true;
131 kill_video_urbs(peasycap);
132} else
133 resubmit = false;
86/*--------------------------------------------------------------------------*/ 134/*--------------------------------------------------------------------------*/
87/* 135/*
88 * SAA7113H DATASHEET PAGE 44, TABLE 42 136 * SAA7113H DATASHEET PAGE 44, TABLE 42
@@ -94,55 +142,41 @@ case NTSC_M_JP: {
94 reg = 0x0A; set = 0x95; 142 reg = 0x0A; set = 0x95;
95 ir = read_saa(peasycap->pusb_device, reg); 143 ir = read_saa(peasycap->pusb_device, reg);
96 if (0 > ir) 144 if (0 > ir)
97 SAY("ERROR: cannot read SAA register 0x%02X\n", reg); 145 SAM("ERROR: cannot read SAA register 0x%02X\n", reg);
98 else 146 else
99 itwas = (unsigned int)ir; 147 itwas = (unsigned int)ir;
100
101
102 set2to78(peasycap->pusb_device);
103
104
105 rc = write_saa(peasycap->pusb_device, reg, set); 148 rc = write_saa(peasycap->pusb_device, reg, set);
106 if (0 != rc) 149 if (0 != rc)
107 SAY("ERROR: failed to set SAA register " \ 150 SAM("ERROR: failed to set SAA register " \
108 "0x%02X to 0x%02X for JP standard\n", reg, set); 151 "0x%02X to 0x%02X for JP standard\n", reg, set);
109 else { 152 else {
110 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg); 153 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg);
111 if (0 > ir) 154 if (0 > ir)
112 JOT(8, "SAA register 0x%02X changed " \ 155 JOM(8, "SAA register 0x%02X changed " \
113 "to 0x%02X\n", reg, isnow); 156 "to 0x%02X\n", reg, isnow);
114 else 157 else
115 JOT(8, "SAA register 0x%02X changed " \ 158 JOM(8, "SAA register 0x%02X changed " \
116 "from 0x%02X to 0x%02X\n", reg, itwas, isnow); 159 "from 0x%02X to 0x%02X\n", reg, itwas, isnow);
117
118 set2to78(peasycap->pusb_device);
119
120 } 160 }
121 161
122 reg = 0x0B; set = 0x48; 162 reg = 0x0B; set = 0x48;
123 ir = read_saa(peasycap->pusb_device, reg); 163 ir = read_saa(peasycap->pusb_device, reg);
124 if (0 > ir) 164 if (0 > ir)
125 SAY("ERROR: cannot read SAA register 0x%02X\n", reg); 165 SAM("ERROR: cannot read SAA register 0x%02X\n", reg);
126 else 166 else
127 itwas = (unsigned int)ir; 167 itwas = (unsigned int)ir;
128
129 set2to78(peasycap->pusb_device);
130
131 rc = write_saa(peasycap->pusb_device, reg, set); 168 rc = write_saa(peasycap->pusb_device, reg, set);
132 if (0 != rc) 169 if (0 != rc)
133 SAY("ERROR: failed to set SAA register 0x%02X to 0x%02X " \ 170 SAM("ERROR: failed to set SAA register 0x%02X to 0x%02X " \
134 "for JP standard\n", reg, set); 171 "for JP standard\n", reg, set);
135 else { 172 else {
136 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg); 173 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg);
137 if (0 > ir) 174 if (0 > ir)
138 JOT(8, "SAA register 0x%02X changed " \ 175 JOM(8, "SAA register 0x%02X changed " \
139 "to 0x%02X\n", reg, isnow); 176 "to 0x%02X\n", reg, isnow);
140 else 177 else
141 JOT(8, "SAA register 0x%02X changed " \ 178 JOM(8, "SAA register 0x%02X changed " \
142 "from 0x%02X to 0x%02X\n", reg, itwas, isnow); 179 "from 0x%02X to 0x%02X\n", reg, itwas, isnow);
143
144 set2to78(peasycap->pusb_device);
145
146 } 180 }
147/*--------------------------------------------------------------------------*/ 181/*--------------------------------------------------------------------------*/
148/* 182/*
@@ -176,23 +210,20 @@ default:
176if (need) { 210if (need) {
177 ir = read_saa(peasycap->pusb_device, reg); 211 ir = read_saa(peasycap->pusb_device, reg);
178 if (0 > ir) 212 if (0 > ir)
179 SAY("ERROR: failed to read SAA register 0x%02X\n", reg); 213 SAM("ERROR: failed to read SAA register 0x%02X\n", reg);
180 else 214 else
181 itwas = (unsigned int)ir; 215 itwas = (unsigned int)ir;
182
183 set2to78(peasycap->pusb_device);
184
185 rc = write_saa(peasycap->pusb_device, reg, set); 216 rc = write_saa(peasycap->pusb_device, reg, set);
186 if (0 != write_saa(peasycap->pusb_device, reg, set)) { 217 if (0 != write_saa(peasycap->pusb_device, reg, set)) {
187 SAY("ERROR: failed to set SAA register " \ 218 SAM("ERROR: failed to set SAA register " \
188 "0x%02X to 0x%02X for table 42\n", reg, set); 219 "0x%02X to 0x%02X for table 42\n", reg, set);
189 } else { 220 } else {
190 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg); 221 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg);
191 if (0 > ir) 222 if (0 > ir)
192 JOT(8, "SAA register 0x%02X changed " \ 223 JOM(8, "SAA register 0x%02X changed " \
193 "to 0x%02X\n", reg, isnow); 224 "to 0x%02X\n", reg, isnow);
194 else 225 else
195 JOT(8, "SAA register 0x%02X changed " \ 226 JOM(8, "SAA register 0x%02X changed " \
196 "from 0x%02X to 0x%02X\n", reg, itwas, isnow); 227 "from 0x%02X to 0x%02X\n", reg, itwas, isnow);
197 } 228 }
198} 229}
@@ -204,7 +235,7 @@ if (need) {
204reg = 0x08; 235reg = 0x08;
205ir = read_saa(peasycap->pusb_device, reg); 236ir = read_saa(peasycap->pusb_device, reg);
206if (0 > ir) 237if (0 > ir)
207 SAY("ERROR: failed to read SAA register 0x%02X " \ 238 SAM("ERROR: failed to read SAA register 0x%02X " \
208 "so cannot reset\n", reg); 239 "so cannot reset\n", reg);
209else { 240else {
210 itwas = (unsigned int)ir; 241 itwas = (unsigned int)ir;
@@ -212,19 +243,18 @@ else {
212 set = itwas | 0x40 ; 243 set = itwas | 0x40 ;
213 else 244 else
214 set = itwas & ~0x40 ; 245 set = itwas & ~0x40 ;
215 246 rc = write_saa(peasycap->pusb_device, reg, set);
216set2to78(peasycap->pusb_device); 247 if (0 != rc)
217 248 SAM("ERROR: failed to set SAA register 0x%02X to 0x%02X\n", \
218rc = write_saa(peasycap->pusb_device, reg, set); 249 reg, set);
219if (0 != rc) 250 else {
220 SAY("ERROR: failed to set SAA register 0x%02X to 0x%02X\n", reg, set); 251 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg);
221else { 252 if (0 > ir)
222 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg); 253 JOM(8, "SAA register 0x%02X changed to 0x%02X\n", \
223 if (0 > ir) 254 reg, isnow);
224 JOT(8, "SAA register 0x%02X changed to 0x%02X\n", reg, isnow); 255 else
225 else 256 JOM(8, "SAA register 0x%02X changed " \
226 JOT(8, "SAA register 0x%02X changed " \ 257 "from 0x%02X to 0x%02X\n", reg, itwas, isnow);
227 "from 0x%02X to 0x%02X\n", reg, itwas, isnow);
228 } 258 }
229} 259}
230/*--------------------------------------------------------------------------*/ 260/*--------------------------------------------------------------------------*/
@@ -235,7 +265,7 @@ else {
235reg = 0x40; 265reg = 0x40;
236ir = read_saa(peasycap->pusb_device, reg); 266ir = read_saa(peasycap->pusb_device, reg);
237if (0 > ir) 267if (0 > ir)
238 SAY("ERROR: failed to read SAA register 0x%02X " \ 268 SAM("ERROR: failed to read SAA register 0x%02X " \
239 "so cannot reset\n", reg); 269 "so cannot reset\n", reg);
240else { 270else {
241 itwas = (unsigned int)ir; 271 itwas = (unsigned int)ir;
@@ -243,19 +273,18 @@ else {
243 set = itwas | 0x80 ; 273 set = itwas | 0x80 ;
244 else 274 else
245 set = itwas & ~0x80 ; 275 set = itwas & ~0x80 ;
246 276 rc = write_saa(peasycap->pusb_device, reg, set);
247set2to78(peasycap->pusb_device); 277 if (0 != rc)
248 278 SAM("ERROR: failed to set SAA register 0x%02X to 0x%02X\n", \
249rc = write_saa(peasycap->pusb_device, reg, set); 279 reg, set);
250if (0 != rc) 280 else {
251 SAY("ERROR: failed to set SAA register 0x%02X to 0x%02X\n", reg, set); 281 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg);
252else { 282 if (0 > ir)
253 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg); 283 JOM(8, "SAA register 0x%02X changed to 0x%02X\n", \
254 if (0 > ir) 284 reg, isnow);
255 JOT(8, "SAA register 0x%02X changed to 0x%02X\n", reg, isnow); 285 else
256 else 286 JOM(8, "SAA register 0x%02X changed " \
257 JOT(8, "SAA register 0x%02X changed " \ 287 "from 0x%02X to 0x%02X\n", reg, itwas, isnow);
258 "from 0x%02X to 0x%02X\n", reg, itwas, isnow);
259 } 288 }
260} 289}
261/*--------------------------------------------------------------------------*/ 290/*--------------------------------------------------------------------------*/
@@ -266,41 +295,39 @@ else {
266reg = 0x5A; 295reg = 0x5A;
267ir = read_saa(peasycap->pusb_device, reg); 296ir = read_saa(peasycap->pusb_device, reg);
268if (0 > ir) 297if (0 > ir)
269 SAY("ERROR: failed to read SAA register 0x%02X but continuing\n", reg); 298 SAM("ERROR: failed to read SAA register 0x%02X but continuing\n", reg);
270 itwas = (unsigned int)ir; 299 itwas = (unsigned int)ir;
271 if (peasycap_standard->mask & 0x0001) 300 if (peasycap_standard->mask & 0x0001)
272 set = 0x0A ; 301 set = 0x0A ;
273 else 302 else
274 set = 0x07 ; 303 set = 0x07 ;
275
276 set2to78(peasycap->pusb_device);
277
278 if (0 != write_saa(peasycap->pusb_device, reg, set)) 304 if (0 != write_saa(peasycap->pusb_device, reg, set))
279 SAY("ERROR: failed to set SAA register 0x%02X to 0x%02X\n", \ 305 SAM("ERROR: failed to set SAA register 0x%02X to 0x%02X\n", \
280 reg, set); 306 reg, set);
281 else { 307 else {
282 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg); 308 isnow = (unsigned int)read_saa(peasycap->pusb_device, reg);
283 if (0 > ir) 309 if (0 > ir)
284 JOT(8, "SAA register 0x%02X changed " 310 JOM(8, "SAA register 0x%02X changed "
285 "to 0x%02X\n", reg, isnow); 311 "to 0x%02X\n", reg, isnow);
286 else 312 else
287 JOT(8, "SAA register 0x%02X changed " 313 JOM(8, "SAA register 0x%02X changed "
288 "from 0x%02X to 0x%02X\n", reg, itwas, isnow); 314 "from 0x%02X to 0x%02X\n", reg, itwas, isnow);
289 } 315 }
290 if (0 != check_saa(peasycap->pusb_device)) 316if (true == resubmit)
291 SAY("ERROR: check_saa() failed\n"); 317 submit_video_urbs(peasycap);
292return 0; 318return 0;
293} 319}
294/*****************************************************************************/ 320/*****************************************************************************/
295/*--------------------------------------------------------------------------*/ 321/*--------------------------------------------------------------------------*/
296/* 322/*
297 * THE ALGORITHM FOR RESPONDING TO THE VIDIO_S_FMT IOCTL DEPENDS ON THE 323 * THE ALGORITHM FOR RESPONDING TO THE VIDIO_S_FMT IOCTL REQUIRES
298 * CURRENT VALUE OF peasycap->standard_offset. 324 * A VALID VALUE OF peasycap->standard_offset, OTHERWISE -EBUSY IS RETURNED.
325 *
299 * PROVIDED THE ARGUMENT try IS false AND THERE IS NO PREMATURE ERROR RETURN 326 * PROVIDED THE ARGUMENT try IS false AND THERE IS NO PREMATURE ERROR RETURN
300 * THIS ROUTINE UPDATES THE FOLLOWING: 327 * THIS ROUTINE UPDATES THE FOLLOWING:
301 * peasycap->format_offset 328 * peasycap->format_offset
329 * peasycap->inputset[peasycap->input].format_offset
302 * peasycap->pixelformat 330 * peasycap->pixelformat
303 * peasycap->field
304 * peasycap->height 331 * peasycap->height
305 * peasycap->width 332 * peasycap->width
306 * peasycap->bytesperpixel 333 * peasycap->bytesperpixel
@@ -321,39 +348,93 @@ int adjust_format(struct easycap *peasycap, \
321struct easycap_format *peasycap_format, *peasycap_best_format; 348struct easycap_format *peasycap_format, *peasycap_best_format;
322__u16 mask; 349__u16 mask;
323struct usb_device *p; 350struct usb_device *p;
324int miss, multiplier, best; 351int miss, multiplier, best, k;
325char bf[5], *pc; 352char bf[5], fo[32], *pc;
326__u32 uc; 353__u32 uc;
354bool resubmit;
327 355
328if ((struct easycap *)NULL == peasycap) { 356if (NULL == peasycap) {
329 SAY("ERROR: peasycap is NULL\n"); 357 SAY("ERROR: peasycap is NULL\n");
330 return -EFAULT; 358 return -EFAULT;
331} 359}
360if (0 > peasycap->standard_offset) {
361 JOM(8, "%i=peasycap->standard_offset\n", peasycap->standard_offset);
362 return -EBUSY;
363}
332p = peasycap->pusb_device; 364p = peasycap->pusb_device;
333if ((struct usb_device *)NULL == p) { 365if ((struct usb_device *)NULL == p) {
334 SAY("ERROR: peaycap->pusb_device is NULL\n"); 366 SAM("ERROR: peaycap->pusb_device is NULL\n");
335 return -EFAULT; 367 return -EFAULT;
336} 368}
337pc = &bf[0]; 369pc = &bf[0];
338uc = pixelformat; memcpy((void *)pc, (void *)(&uc), 4); bf[4] = 0; 370uc = pixelformat;
339mask = easycap_standard[peasycap->standard_offset].mask; 371memcpy((void *)pc, (void *)(&uc), 4);
340SAY("sought: %ix%i,%s(0x%08X),%i=field,0x%02X=std mask\n", \ 372bf[4] = 0;
373mask = 0xFF & easycap_standard[peasycap->standard_offset].mask;
374SAM("sought: %ix%i,%s(0x%08X),%i=field,0x%02X=std mask\n", \
341 width, height, pc, pixelformat, field, mask); 375 width, height, pc, pixelformat, field, mask);
376switch (field) {
377case V4L2_FIELD_ANY: {
378 strcpy(&fo[0], "V4L2_FIELD_ANY ");
379 break;
380}
381case V4L2_FIELD_NONE: {
382 strcpy(&fo[0], "V4L2_FIELD_NONE");
383 break;
384}
385case V4L2_FIELD_TOP: {
386 strcpy(&fo[0], "V4L2_FIELD_TOP");
387 break;
388}
389case V4L2_FIELD_BOTTOM: {
390 strcpy(&fo[0], "V4L2_FIELD_BOTTOM");
391 break;
392}
393case V4L2_FIELD_INTERLACED: {
394 strcpy(&fo[0], "V4L2_FIELD_INTERLACED");
395 break;
396}
397case V4L2_FIELD_SEQ_TB: {
398 strcpy(&fo[0], "V4L2_FIELD_SEQ_TB");
399 break;
400}
401case V4L2_FIELD_SEQ_BT: {
402 strcpy(&fo[0], "V4L2_FIELD_SEQ_BT");
403 break;
404}
405case V4L2_FIELD_ALTERNATE: {
406 strcpy(&fo[0], "V4L2_FIELD_ALTERNATE");
407 break;
408}
409case V4L2_FIELD_INTERLACED_TB: {
410 strcpy(&fo[0], "V4L2_FIELD_INTERLACED_TB");
411 break;
412}
413case V4L2_FIELD_INTERLACED_BT: {
414 strcpy(&fo[0], "V4L2_FIELD_INTERLACED_BT");
415 break;
416}
417default: {
418 strcpy(&fo[0], "V4L2_FIELD_... UNKNOWN ");
419 break;
420}
421}
422SAM("sought: %s\n", &fo[0]);
342if (V4L2_FIELD_ANY == field) { 423if (V4L2_FIELD_ANY == field) {
343 field = V4L2_FIELD_INTERLACED; 424 field = V4L2_FIELD_NONE;
344 SAY("prefer: V4L2_FIELD_INTERLACED=field, was V4L2_FIELD_ANY\n"); 425 SAM("prefer: V4L2_FIELD_NONE=field, was V4L2_FIELD_ANY\n");
345} 426}
346peasycap_best_format = (struct easycap_format *)NULL; 427peasycap_best_format = (struct easycap_format *)NULL;
347peasycap_format = &easycap_format[0]; 428peasycap_format = &easycap_format[0];
348while (0 != peasycap_format->v4l2_format.fmt.pix.width) { 429while (0 != peasycap_format->v4l2_format.fmt.pix.width) {
349 JOT(16, ".> %i %i 0x%08X %ix%i\n", \ 430 JOM(16, ".> %i %i 0x%08X %ix%i\n", \
350 peasycap_format->mask & 0x01, 431 peasycap_format->mask & 0x01,
351 peasycap_format->v4l2_format.fmt.pix.field, 432 peasycap_format->v4l2_format.fmt.pix.field,
352 peasycap_format->v4l2_format.fmt.pix.pixelformat, 433 peasycap_format->v4l2_format.fmt.pix.pixelformat,
353 peasycap_format->v4l2_format.fmt.pix.width, 434 peasycap_format->v4l2_format.fmt.pix.width,
354 peasycap_format->v4l2_format.fmt.pix.height); 435 peasycap_format->v4l2_format.fmt.pix.height);
355 436
356 if (((peasycap_format->mask & 0x0F) == (mask & 0x0F)) && \ 437 if (((peasycap_format->mask & 0x1F) == (mask & 0x1F)) && \
357 (peasycap_format->v4l2_format.fmt.pix.field == field) && \ 438 (peasycap_format->v4l2_format.fmt.pix.field == field) && \
358 (peasycap_format->v4l2_format.fmt.pix.pixelformat == \ 439 (peasycap_format->v4l2_format.fmt.pix.pixelformat == \
359 pixelformat) && \ 440 pixelformat) && \
@@ -365,11 +446,11 @@ while (0 != peasycap_format->v4l2_format.fmt.pix.width) {
365 peasycap_format++; 446 peasycap_format++;
366} 447}
367if (0 == peasycap_format->v4l2_format.fmt.pix.width) { 448if (0 == peasycap_format->v4l2_format.fmt.pix.width) {
368 SAY("cannot do: %ix%i with standard mask 0x%02X\n", \ 449 SAM("cannot do: %ix%i with standard mask 0x%02X\n", \
369 width, height, mask); 450 width, height, mask);
370 peasycap_format = &easycap_format[0]; best = -1; 451 peasycap_format = &easycap_format[0]; best = -1;
371 while (0 != peasycap_format->v4l2_format.fmt.pix.width) { 452 while (0 != peasycap_format->v4l2_format.fmt.pix.width) {
372 if (((peasycap_format->mask & 0x0F) == (mask & 0x0F)) && \ 453 if (((peasycap_format->mask & 0x1F) == (mask & 0x1F)) && \
373 (peasycap_format->v4l2_format.fmt.pix\ 454 (peasycap_format->v4l2_format.fmt.pix\
374 .field == field) && \ 455 .field == field) && \
375 (peasycap_format->v4l2_format.fmt.pix\ 456 (peasycap_format->v4l2_format.fmt.pix\
@@ -386,16 +467,16 @@ if (0 == peasycap_format->v4l2_format.fmt.pix.width) {
386 peasycap_format++; 467 peasycap_format++;
387 } 468 }
388 if (-1 == best) { 469 if (-1 == best) {
389 SAY("cannot do %ix... with standard mask 0x%02X\n", \ 470 SAM("cannot do %ix... with standard mask 0x%02X\n", \
390 width, mask); 471 width, mask);
391 SAY("cannot do ...x%i with standard mask 0x%02X\n", \ 472 SAM("cannot do ...x%i with standard mask 0x%02X\n", \
392 height, mask); 473 height, mask);
393 SAY(" %ix%i unmatched\n", width, height); 474 SAM(" %ix%i unmatched\n", width, height);
394 return peasycap->format_offset; 475 return peasycap->format_offset;
395 } 476 }
396} 477}
397if ((struct easycap_format *)NULL == peasycap_best_format) { 478if ((struct easycap_format *)NULL == peasycap_best_format) {
398 SAY("MISTAKE: peasycap_best_format is NULL"); 479 SAM("MISTAKE: peasycap_best_format is NULL");
399 return -EINVAL; 480 return -EINVAL;
400} 481}
401peasycap_format = peasycap_best_format; 482peasycap_format = peasycap_best_format;
@@ -406,23 +487,43 @@ if (true == try)
406/*...........................................................................*/ 487/*...........................................................................*/
407 488
408if (false != try) { 489if (false != try) {
409 SAY("MISTAKE: true==try where is should be false\n"); 490 SAM("MISTAKE: true==try where is should be false\n");
410 return -EINVAL; 491 return -EINVAL;
411} 492}
412SAY("actioning: %ix%i %s\n", \ 493SAM("actioning: %ix%i %s\n", \
413 peasycap_format->v4l2_format.fmt.pix.width, \ 494 peasycap_format->v4l2_format.fmt.pix.width, \
414 peasycap_format->v4l2_format.fmt.pix.height, 495 peasycap_format->v4l2_format.fmt.pix.height,
415 &peasycap_format->name[0]); 496 &peasycap_format->name[0]);
416peasycap->height = peasycap_format->v4l2_format.fmt.pix.height; 497peasycap->height = peasycap_format->v4l2_format.fmt.pix.height;
417peasycap->width = peasycap_format->v4l2_format.fmt.pix.width; 498peasycap->width = peasycap_format->v4l2_format.fmt.pix.width;
418peasycap->pixelformat = peasycap_format->v4l2_format.fmt.pix.pixelformat; 499peasycap->pixelformat = peasycap_format->v4l2_format.fmt.pix.pixelformat;
419peasycap->field = peasycap_format->v4l2_format.fmt.pix.field;
420peasycap->format_offset = (int)(peasycap_format - &easycap_format[0]); 500peasycap->format_offset = (int)(peasycap_format - &easycap_format[0]);
421peasycap->bytesperpixel = (0x00F0 & peasycap_format->mask) >> 4 ; 501
502
503for (k = 0; k < INPUT_MANY; k++) {
504 if (!peasycap->inputset[k].format_offset_ok) {
505 peasycap->inputset[k].format_offset = \
506 peasycap->format_offset;
507 }
508}
509if ((0 <= peasycap->input) && (INPUT_MANY > peasycap->input)) {
510 peasycap->inputset[peasycap->input].format_offset = \
511 peasycap->format_offset;
512 peasycap->inputset[peasycap->input].format_offset_ok = 1;
513} else
514 JOM(8, "%i=peasycap->input\n", peasycap->input);
515
516
517
518peasycap->bytesperpixel = (0x00E0 & peasycap_format->mask) >> 5 ;
422if (0x0100 & peasycap_format->mask) 519if (0x0100 & peasycap_format->mask)
423 peasycap->byteswaporder = true; 520 peasycap->byteswaporder = true;
424else 521else
425 peasycap->byteswaporder = false; 522 peasycap->byteswaporder = false;
523if (0x0200 & peasycap_format->mask)
524 peasycap->skip = 5;
525else
526 peasycap->skip = 0;
426if (0x0800 & peasycap_format->mask) 527if (0x0800 & peasycap_format->mask)
427 peasycap->decimatepixel = true; 528 peasycap->decimatepixel = true;
428else 529else
@@ -439,27 +540,11 @@ peasycap->videofieldamount = multiplier * peasycap->width * \
439 multiplier * peasycap->height; 540 multiplier * peasycap->height;
440peasycap->frame_buffer_used = peasycap->bytesperpixel * \ 541peasycap->frame_buffer_used = peasycap->bytesperpixel * \
441 peasycap->width * peasycap->height; 542 peasycap->width * peasycap->height;
442 543if (peasycap->video_isoc_streaming) {
443if (true == peasycap->offerfields) { 544 resubmit = true;
444 SAY("WARNING: %i=peasycap->field is untested: " \ 545 kill_video_urbs(peasycap);
445 "please report problems\n", peasycap->field); 546} else
446 547 resubmit = false;
447
448/*
449 * FIXME ---- THIS IS UNTESTED, MAY BE (AND PROBABLY IS) INCORRECT:
450 *
451 * peasycap->frame_buffer_used = peasycap->frame_buffer_used / 2;
452 *
453 * SO DO NOT RISK IT YET.
454 *
455 */
456
457
458
459}
460
461kill_video_urbs(peasycap);
462
463/*---------------------------------------------------------------------------*/ 548/*---------------------------------------------------------------------------*/
464/* 549/*
465 * PAL 550 * PAL
@@ -474,13 +559,13 @@ if (0 == (0x01 & peasycap_format->mask)) {
474 (288 == \ 559 (288 == \
475 peasycap_format->v4l2_format.fmt.pix.height))) { 560 peasycap_format->v4l2_format.fmt.pix.height))) {
476 if (0 != set_resolution(p, 0x0000, 0x0001, 0x05A0, 0x0121)) { 561 if (0 != set_resolution(p, 0x0000, 0x0001, 0x05A0, 0x0121)) {
477 SAY("ERROR: set_resolution() failed\n"); 562 SAM("ERROR: set_resolution() failed\n");
478 return -EINVAL; 563 return -EINVAL;
479 } 564 }
480 } else if ((704 == peasycap_format->v4l2_format.fmt.pix.width) && \ 565 } else if ((704 == peasycap_format->v4l2_format.fmt.pix.width) && \
481 (576 == peasycap_format->v4l2_format.fmt.pix.height)) { 566 (576 == peasycap_format->v4l2_format.fmt.pix.height)) {
482 if (0 != set_resolution(p, 0x0004, 0x0001, 0x0584, 0x0121)) { 567 if (0 != set_resolution(p, 0x0004, 0x0001, 0x0584, 0x0121)) {
483 SAY("ERROR: set_resolution() failed\n"); 568 SAM("ERROR: set_resolution() failed\n");
484 return -EINVAL; 569 return -EINVAL;
485 } 570 }
486 } else if (((640 == peasycap_format->v4l2_format.fmt.pix.width) && \ 571 } else if (((640 == peasycap_format->v4l2_format.fmt.pix.width) && \
@@ -491,11 +576,11 @@ if (0 == (0x01 & peasycap_format->mask)) {
491 (240 == \ 576 (240 == \
492 peasycap_format->v4l2_format.fmt.pix.height))) { 577 peasycap_format->v4l2_format.fmt.pix.height))) {
493 if (0 != set_resolution(p, 0x0014, 0x0020, 0x0514, 0x0110)) { 578 if (0 != set_resolution(p, 0x0014, 0x0020, 0x0514, 0x0110)) {
494 SAY("ERROR: set_resolution() failed\n"); 579 SAM("ERROR: set_resolution() failed\n");
495 return -EINVAL; 580 return -EINVAL;
496 } 581 }
497 } else { 582 } else {
498 SAY("MISTAKE: bad format, cannot set resolution\n"); 583 SAM("MISTAKE: bad format, cannot set resolution\n");
499 return -EINVAL; 584 return -EINVAL;
500 } 585 }
501/*---------------------------------------------------------------------------*/ 586/*---------------------------------------------------------------------------*/
@@ -512,7 +597,7 @@ if (0 == (0x01 & peasycap_format->mask)) {
512 (240 == \ 597 (240 == \
513 peasycap_format->v4l2_format.fmt.pix.height))) { 598 peasycap_format->v4l2_format.fmt.pix.height))) {
514 if (0 != set_resolution(p, 0x0000, 0x0003, 0x05A0, 0x00F3)) { 599 if (0 != set_resolution(p, 0x0000, 0x0003, 0x05A0, 0x00F3)) {
515 SAY("ERROR: set_resolution() failed\n"); 600 SAM("ERROR: set_resolution() failed\n");
516 return -EINVAL; 601 return -EINVAL;
517 } 602 }
518 } else if (((640 == peasycap_format->v4l2_format.fmt.pix.width) && \ 603 } else if (((640 == peasycap_format->v4l2_format.fmt.pix.width) && \
@@ -523,28 +608,31 @@ if (0 == (0x01 & peasycap_format->mask)) {
523 (240 == \ 608 (240 == \
524 peasycap_format->v4l2_format.fmt.pix.height))) { 609 peasycap_format->v4l2_format.fmt.pix.height))) {
525 if (0 != set_resolution(p, 0x0014, 0x0003, 0x0514, 0x00F3)) { 610 if (0 != set_resolution(p, 0x0014, 0x0003, 0x0514, 0x00F3)) {
526 SAY("ERROR: set_resolution() failed\n"); 611 SAM("ERROR: set_resolution() failed\n");
527 return -EINVAL; 612 return -EINVAL;
528 } 613 }
529 } else { 614 } else {
530 SAY("MISTAKE: bad format, cannot set resolution\n"); 615 SAM("MISTAKE: bad format, cannot set resolution\n");
531 return -EINVAL; 616 return -EINVAL;
532 } 617 }
533} 618}
534/*---------------------------------------------------------------------------*/ 619/*---------------------------------------------------------------------------*/
535 620if (true == resubmit)
536check_stk(peasycap->pusb_device); 621 submit_video_urbs(peasycap);
537
538return (int)(peasycap_best_format - &easycap_format[0]); 622return (int)(peasycap_best_format - &easycap_format[0]);
539} 623}
540/*****************************************************************************/ 624/*****************************************************************************/
541int adjust_brightness(struct easycap *peasycap, int value) 625int adjust_brightness(struct easycap *peasycap, int value)
542{ 626{
543unsigned int mood; 627unsigned int mood;
544int i1; 628int i1, k;
545 629
630if (NULL == peasycap) {
631 SAY("ERROR: peasycap is NULL\n");
632 return -EFAULT;
633}
546if ((struct usb_device *)NULL == peasycap->pusb_device) { 634if ((struct usb_device *)NULL == peasycap->pusb_device) {
547 SAY("ERROR: peasycap->pusb_device is NULL\n"); 635 SAM("ERROR: peasycap->pusb_device is NULL\n");
548 return -EFAULT; 636 return -EFAULT;
549} 637}
550i1 = 0; 638i1 = 0;
@@ -553,37 +641,56 @@ while (0xFFFFFFFF != easycap_control[i1].id) {
553 if ((easycap_control[i1].minimum > value) || \ 641 if ((easycap_control[i1].minimum > value) || \
554 (easycap_control[i1].maximum < value)) 642 (easycap_control[i1].maximum < value))
555 value = easycap_control[i1].default_value; 643 value = easycap_control[i1].default_value;
644
645 if ((easycap_control[i1].minimum <= peasycap->brightness) && \
646 (easycap_control[i1].maximum >= \
647 peasycap->brightness)) {
648 if (peasycap->brightness == value) {
649 SAM("unchanged brightness at 0x%02X\n", \
650 value);
651 return 0;
652 }
653 }
556 peasycap->brightness = value; 654 peasycap->brightness = value;
655 for (k = 0; k < INPUT_MANY; k++) {
656 if (!peasycap->inputset[k].brightness_ok)
657 peasycap->inputset[k].brightness = \
658 peasycap->brightness;
659 }
660 if ((0 <= peasycap->input) && (INPUT_MANY > peasycap->input)) {
661 peasycap->inputset[peasycap->input].brightness = \
662 peasycap->brightness;
663 peasycap->inputset[peasycap->input].brightness_ok = 1;
664 } else
665 JOM(8, "%i=peasycap->input\n", peasycap->input);
557 mood = 0x00FF & (unsigned int)peasycap->brightness; 666 mood = 0x00FF & (unsigned int)peasycap->brightness;
558
559 set2to78(peasycap->pusb_device);
560
561 if (!write_saa(peasycap->pusb_device, 0x0A, mood)) { 667 if (!write_saa(peasycap->pusb_device, 0x0A, mood)) {
562 SAY("adjusting brightness to 0x%02X\n", mood); 668 SAM("adjusting brightness to 0x%02X\n", mood);
563 return 0; 669 return 0;
564 } else { 670 } else {
565 SAY("WARNING: failed to adjust brightness " \ 671 SAM("WARNING: failed to adjust brightness " \
566 "to 0x%02X\n", mood); 672 "to 0x%02X\n", mood);
567 return -ENOENT; 673 return -ENOENT;
568 } 674 }
569
570 set2to78(peasycap->pusb_device);
571
572 break; 675 break;
573 } 676 }
574 i1++; 677 i1++;
575} 678}
576SAY("WARNING: failed to adjust brightness: control not found\n"); 679SAM("WARNING: failed to adjust brightness: control not found\n");
577return -ENOENT; 680return -ENOENT;
578} 681}
579/*****************************************************************************/ 682/*****************************************************************************/
580int adjust_contrast(struct easycap *peasycap, int value) 683int adjust_contrast(struct easycap *peasycap, int value)
581{ 684{
582unsigned int mood; 685unsigned int mood;
583int i1; 686int i1, k;
584 687
688if (NULL == peasycap) {
689 SAY("ERROR: peasycap is NULL\n");
690 return -EFAULT;
691}
585if ((struct usb_device *)NULL == peasycap->pusb_device) { 692if ((struct usb_device *)NULL == peasycap->pusb_device) {
586 SAY("ERROR: peasycap->pusb_device is NULL\n"); 693 SAM("ERROR: peasycap->pusb_device is NULL\n");
587 return -EFAULT; 694 return -EFAULT;
588} 695}
589i1 = 0; 696i1 = 0;
@@ -592,37 +699,58 @@ while (0xFFFFFFFF != easycap_control[i1].id) {
592 if ((easycap_control[i1].minimum > value) || \ 699 if ((easycap_control[i1].minimum > value) || \
593 (easycap_control[i1].maximum < value)) 700 (easycap_control[i1].maximum < value))
594 value = easycap_control[i1].default_value; 701 value = easycap_control[i1].default_value;
595 peasycap->contrast = value;
596 mood = 0x00FF & (unsigned int) (peasycap->contrast - 128);
597 702
598 set2to78(peasycap->pusb_device);
599 703
704
705 if ((easycap_control[i1].minimum <= peasycap->contrast) && \
706 (easycap_control[i1].maximum >= \
707 peasycap->contrast)) {
708 if (peasycap->contrast == value) {
709 SAM("unchanged contrast at 0x%02X\n", value);
710 return 0;
711 }
712 }
713 peasycap->contrast = value;
714 for (k = 0; k < INPUT_MANY; k++) {
715 if (!peasycap->inputset[k].contrast_ok) {
716 peasycap->inputset[k].contrast = \
717 peasycap->contrast;
718 }
719 }
720 if ((0 <= peasycap->input) && (INPUT_MANY > peasycap->input)) {
721 peasycap->inputset[peasycap->input].contrast = \
722 peasycap->contrast;
723 peasycap->inputset[peasycap->input].contrast_ok = 1;
724 } else
725 JOM(8, "%i=peasycap->input\n", peasycap->input);
726 mood = 0x00FF & (unsigned int) (peasycap->contrast - 128);
600 if (!write_saa(peasycap->pusb_device, 0x0B, mood)) { 727 if (!write_saa(peasycap->pusb_device, 0x0B, mood)) {
601 SAY("adjusting contrast to 0x%02X\n", mood); 728 SAM("adjusting contrast to 0x%02X\n", mood);
602 return 0; 729 return 0;
603 } else { 730 } else {
604 SAY("WARNING: failed to adjust contrast to " \ 731 SAM("WARNING: failed to adjust contrast to " \
605 "0x%02X\n", mood); 732 "0x%02X\n", mood);
606 return -ENOENT; 733 return -ENOENT;
607 } 734 }
608
609 set2to78(peasycap->pusb_device);
610
611 break; 735 break;
612 } 736 }
613 i1++; 737 i1++;
614} 738}
615SAY("WARNING: failed to adjust contrast: control not found\n"); 739SAM("WARNING: failed to adjust contrast: control not found\n");
616return -ENOENT; 740return -ENOENT;
617} 741}
618/*****************************************************************************/ 742/*****************************************************************************/
619int adjust_saturation(struct easycap *peasycap, int value) 743int adjust_saturation(struct easycap *peasycap, int value)
620{ 744{
621unsigned int mood; 745unsigned int mood;
622int i1; 746int i1, k;
623 747
748if (NULL == peasycap) {
749 SAY("ERROR: peasycap is NULL\n");
750 return -EFAULT;
751}
624if ((struct usb_device *)NULL == peasycap->pusb_device) { 752if ((struct usb_device *)NULL == peasycap->pusb_device) {
625 SAY("ERROR: peasycap->pusb_device is NULL\n"); 753 SAM("ERROR: peasycap->pusb_device is NULL\n");
626 return -EFAULT; 754 return -EFAULT;
627} 755}
628i1 = 0; 756i1 = 0;
@@ -631,37 +759,58 @@ while (0xFFFFFFFF != easycap_control[i1].id) {
631 if ((easycap_control[i1].minimum > value) || \ 759 if ((easycap_control[i1].minimum > value) || \
632 (easycap_control[i1].maximum < value)) 760 (easycap_control[i1].maximum < value))
633 value = easycap_control[i1].default_value; 761 value = easycap_control[i1].default_value;
634 peasycap->saturation = value;
635 mood = 0x00FF & (unsigned int) (peasycap->saturation - 128);
636 762
637 set2to78(peasycap->pusb_device);
638 763
764 if ((easycap_control[i1].minimum <= peasycap->saturation) && \
765 (easycap_control[i1].maximum >= \
766 peasycap->saturation)) {
767 if (peasycap->saturation == value) {
768 SAM("unchanged saturation at 0x%02X\n", \
769 value);
770 return 0;
771 }
772 }
773 peasycap->saturation = value;
774 for (k = 0; k < INPUT_MANY; k++) {
775 if (!peasycap->inputset[k].saturation_ok) {
776 peasycap->inputset[k].saturation = \
777 peasycap->saturation;
778 }
779 }
780 if ((0 <= peasycap->input) && (INPUT_MANY > peasycap->input)) {
781 peasycap->inputset[peasycap->input].saturation = \
782 peasycap->saturation;
783 peasycap->inputset[peasycap->input].saturation_ok = 1;
784 } else
785 JOM(8, "%i=peasycap->input\n", peasycap->input);
786 mood = 0x00FF & (unsigned int) (peasycap->saturation - 128);
639 if (!write_saa(peasycap->pusb_device, 0x0C, mood)) { 787 if (!write_saa(peasycap->pusb_device, 0x0C, mood)) {
640 SAY("adjusting saturation to 0x%02X\n", mood); 788 SAM("adjusting saturation to 0x%02X\n", mood);
641 return 0; 789 return 0;
642 } else { 790 } else {
643 SAY("WARNING: failed to adjust saturation to " \ 791 SAM("WARNING: failed to adjust saturation to " \
644 "0x%02X\n", mood); 792 "0x%02X\n", mood);
645 return -ENOENT; 793 return -ENOENT;
646 } 794 }
647 break; 795 break;
648
649 set2to78(peasycap->pusb_device);
650
651 } 796 }
652 i1++; 797 i1++;
653} 798}
654SAY("WARNING: failed to adjust saturation: control not found\n"); 799SAM("WARNING: failed to adjust saturation: control not found\n");
655return -ENOENT; 800return -ENOENT;
656} 801}
657/*****************************************************************************/ 802/*****************************************************************************/
658int adjust_hue(struct easycap *peasycap, int value) 803int adjust_hue(struct easycap *peasycap, int value)
659{ 804{
660unsigned int mood; 805unsigned int mood;
661int i1, i2; 806int i1, i2, k;
662 807
808if (NULL == peasycap) {
809 SAY("ERROR: peasycap is NULL\n");
810 return -EFAULT;
811}
663if ((struct usb_device *)NULL == peasycap->pusb_device) { 812if ((struct usb_device *)NULL == peasycap->pusb_device) {
664 SAY("ERROR: peasycap->pusb_device is NULL\n"); 813 SAM("ERROR: peasycap->pusb_device is NULL\n");
665 return -EFAULT; 814 return -EFAULT;
666} 815}
667i1 = 0; 816i1 = 0;
@@ -670,27 +819,40 @@ while (0xFFFFFFFF != easycap_control[i1].id) {
670 if ((easycap_control[i1].minimum > value) || \ 819 if ((easycap_control[i1].minimum > value) || \
671 (easycap_control[i1].maximum < value)) 820 (easycap_control[i1].maximum < value))
672 value = easycap_control[i1].default_value; 821 value = easycap_control[i1].default_value;
822
823 if ((easycap_control[i1].minimum <= peasycap->hue) && \
824 (easycap_control[i1].maximum >= \
825 peasycap->hue)) {
826 if (peasycap->hue == value) {
827 SAM("unchanged hue at 0x%02X\n", value);
828 return 0;
829 }
830 }
673 peasycap->hue = value; 831 peasycap->hue = value;
832 for (k = 0; k < INPUT_MANY; k++) {
833 if (!peasycap->inputset[k].hue_ok)
834 peasycap->inputset[k].hue = peasycap->hue;
835 }
836 if ((0 <= peasycap->input) && (INPUT_MANY > peasycap->input)) {
837 peasycap->inputset[peasycap->input].hue = \
838 peasycap->hue;
839 peasycap->inputset[peasycap->input].hue_ok = 1;
840 } else
841 JOM(8, "%i=peasycap->input\n", peasycap->input);
674 i2 = peasycap->hue - 128; 842 i2 = peasycap->hue - 128;
675 mood = 0x00FF & ((int) i2); 843 mood = 0x00FF & ((int) i2);
676
677 set2to78(peasycap->pusb_device);
678
679 if (!write_saa(peasycap->pusb_device, 0x0D, mood)) { 844 if (!write_saa(peasycap->pusb_device, 0x0D, mood)) {
680 SAY("adjusting hue to 0x%02X\n", mood); 845 SAM("adjusting hue to 0x%02X\n", mood);
681 return 0; 846 return 0;
682 } else { 847 } else {
683 SAY("WARNING: failed to adjust hue to 0x%02X\n", mood); 848 SAM("WARNING: failed to adjust hue to 0x%02X\n", mood);
684 return -ENOENT; 849 return -ENOENT;
685 } 850 }
686
687 set2to78(peasycap->pusb_device);
688
689 break; 851 break;
690 } 852 }
691 i1++; 853 i1++;
692} 854}
693SAY("WARNING: failed to adjust hue: control not found\n"); 855SAM("WARNING: failed to adjust hue: control not found\n");
694return -ENOENT; 856return -ENOENT;
695} 857}
696/*****************************************************************************/ 858/*****************************************************************************/
@@ -699,33 +861,45 @@ int adjust_volume(struct easycap *peasycap, int value)
699__s8 mood; 861__s8 mood;
700int i1; 862int i1;
701 863
864if (NULL == peasycap) {
865 SAY("ERROR: peasycap is NULL\n");
866 return -EFAULT;
867}
702if ((struct usb_device *)NULL == peasycap->pusb_device) { 868if ((struct usb_device *)NULL == peasycap->pusb_device) {
703 SAY("ERROR: peasycap->pusb_device is NULL\n"); 869 SAM("ERROR: peasycap->pusb_device is NULL\n");
704 return -EFAULT; 870 return -EFAULT;
705} 871}
706i1 = 0; 872i1 = 0;
707while (0xFFFFFFFF != easycap_control[i1].id) { 873while (0xFFFFFFFF != easycap_control[i1].id) {
708 if (V4L2_CID_AUDIO_VOLUME == easycap_control[i1].id) { 874 if (V4L2_CID_AUDIO_VOLUME == easycap_control[i1].id) {
709 if ((easycap_control[i1].minimum > value) || \ 875 if ((easycap_control[i1].minimum > value) || \
710 (easycap_control[i1].maximum < value)) 876 (easycap_control[i1].maximum < value))
711 value = easycap_control[i1].default_value; 877 value = easycap_control[i1].default_value;
878 if ((easycap_control[i1].minimum <= peasycap->volume) && \
879 (easycap_control[i1].maximum >= \
880 peasycap->volume)) {
881 if (peasycap->volume == value) {
882 SAM("unchanged volume at 0x%02X\n", value);
883 return 0;
884 }
885 }
712 peasycap->volume = value; 886 peasycap->volume = value;
713 mood = (16 > peasycap->volume) ? 16 : \ 887 mood = (16 > peasycap->volume) ? 16 : \
714 ((31 < peasycap->volume) ? 31 : \ 888 ((31 < peasycap->volume) ? 31 : \
715 (__s8) peasycap->volume); 889 (__s8) peasycap->volume);
716 if (!audio_gainset(peasycap->pusb_device, mood)) { 890 if (!audio_gainset(peasycap->pusb_device, mood)) {
717 SAY("adjusting volume to 0x%01X\n", mood); 891 SAM("adjusting volume to 0x%02X\n", mood);
718 return 0; 892 return 0;
719 } else { 893 } else {
720 SAY("WARNING: failed to adjust volume to " \ 894 SAM("WARNING: failed to adjust volume to " \
721 "0x%1X\n", mood); 895 "0x%2X\n", mood);
722 return -ENOENT; 896 return -ENOENT;
723 } 897 }
724 break; 898 break;
725 } 899 }
726i1++; 900i1++;
727} 901}
728SAY("WARNING: failed to adjust volume: control not found\n"); 902SAM("WARNING: failed to adjust volume: control not found\n");
729return -ENOENT; 903return -ENOENT;
730} 904}
731/*****************************************************************************/ 905/*****************************************************************************/
@@ -744,8 +918,12 @@ int adjust_mute(struct easycap *peasycap, int value)
744{ 918{
745int i1; 919int i1;
746 920
921if (NULL == peasycap) {
922 SAY("ERROR: peasycap is NULL\n");
923 return -EFAULT;
924}
747if ((struct usb_device *)NULL == peasycap->pusb_device) { 925if ((struct usb_device *)NULL == peasycap->pusb_device) {
748 SAY("ERROR: peasycap->pusb_device is NULL\n"); 926 SAM("ERROR: peasycap->pusb_device is NULL\n");
749 return -EFAULT; 927 return -EFAULT;
750} 928}
751i1 = 0; 929i1 = 0;
@@ -756,13 +934,13 @@ while (0xFFFFFFFF != easycap_control[i1].id) {
756 case 1: { 934 case 1: {
757 peasycap->audio_idle = 1; 935 peasycap->audio_idle = 1;
758 peasycap->timeval0.tv_sec = 0; 936 peasycap->timeval0.tv_sec = 0;
759 SAY("adjusting mute: %i=peasycap->audio_idle\n", \ 937 SAM("adjusting mute: %i=peasycap->audio_idle\n", \
760 peasycap->audio_idle); 938 peasycap->audio_idle);
761 return 0; 939 return 0;
762 } 940 }
763 default: { 941 default: {
764 peasycap->audio_idle = 0; 942 peasycap->audio_idle = 0;
765 SAY("adjusting mute: %i=peasycap->audio_idle\n", \ 943 SAM("adjusting mute: %i=peasycap->audio_idle\n", \
766 peasycap->audio_idle); 944 peasycap->audio_idle);
767 return 0; 945 return 0;
768 } 946 }
@@ -771,47 +949,107 @@ while (0xFFFFFFFF != easycap_control[i1].id) {
771 } 949 }
772 i1++; 950 i1++;
773} 951}
774SAY("WARNING: failed to adjust mute: control not found\n"); 952SAM("WARNING: failed to adjust mute: control not found\n");
775return -ENOENT; 953return -ENOENT;
776} 954}
777 955/*****************************************************************************/
778/*--------------------------------------------------------------------------*/ 956/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
779static int easycap_ioctl_bkl(struct inode *inode, struct file *file, 957#if ((defined(EASYCAP_IS_VIDEODEV_CLIENT)) || \
780 unsigned int cmd, unsigned long arg) 958 (defined(EASYCAP_NEEDS_UNLOCKED_IOCTL)))
959long
960easycap_ioctl_noinode(struct file *file, unsigned int cmd, unsigned long arg) {
961 return (long)easycap_ioctl((struct inode *)NULL, file, cmd, arg);
962}
963#endif /*EASYCAP_IS_VIDEODEV_CLIENT||EASYCAP_NEEDS_UNLOCKED_IOCTL*/
964/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
965/*---------------------------------------------------------------------------*/
966int
967easycap_ioctl(struct inode *inode, struct file *file,
968 unsigned int cmd, unsigned long arg)
781{ 969{
782static struct easycap *peasycap; 970struct easycap *peasycap;
783static struct usb_device *p; 971struct usb_device *p;
784static __u32 isequence; 972int kd;
785 973
974if (NULL == file) {
975 SAY("ERROR: file is NULL\n");
976 return -ERESTARTSYS;
977}
786peasycap = file->private_data; 978peasycap = file->private_data;
787if (NULL == peasycap) { 979if (NULL == peasycap) {
788 SAY("ERROR: peasycap is NULL\n"); 980 SAY("ERROR: peasycap is NULL\n");
789 return -1; 981 return -1;
790} 982}
983if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
984 SAY("ERROR: bad peasycap\n");
985 return -EFAULT;
986}
791p = peasycap->pusb_device; 987p = peasycap->pusb_device;
792if ((struct usb_device *)NULL == p) { 988if (NULL == p) {
793 SAY("ERROR: peasycap->pusb_device is NULL\n"); 989 SAM("ERROR: peasycap->pusb_device is NULL\n");
794 return -EFAULT; 990 return -EFAULT;
795} 991}
992kd = isdongle(peasycap);
993if (0 <= kd && DONGLE_MANY > kd) {
994 if (mutex_lock_interruptible(&easycap_dongle[kd].mutex_video)) {
995 SAY("ERROR: cannot lock easycap_dongle[%i].mutex_video\n", kd);
996 return -ERESTARTSYS;
997 }
998 JOM(4, "locked easycap_dongle[%i].mutex_video\n", kd);
796/*---------------------------------------------------------------------------*/ 999/*---------------------------------------------------------------------------*/
797/* 1000/*
798 * MOST OF THE VARIABLES DECLARED static IN THE case{} BLOCKS BELOW ARE SO 1001 * MEANWHILE, easycap_usb_disconnect() MAY HAVE FREED POINTER peasycap,
799 * DECLARED SIMPLY TO AVOID A COMPILER WARNING OF THE KIND: 1002 * IN WHICH CASE A REPEAT CALL TO isdongle() WILL FAIL.
800 * easycap_ioctl.c: warning: 1003 * IF NECESSARY, BAIL OUT.
801 * the frame size of ... bytes is larger than 1024 bytes 1004*/
802 */ 1005/*---------------------------------------------------------------------------*/
1006 if (kd != isdongle(peasycap))
1007 return -ERESTARTSYS;
1008 if (NULL == file) {
1009 SAY("ERROR: file is NULL\n");
1010 mutex_unlock(&easycap_dongle[kd].mutex_video);
1011 return -ERESTARTSYS;
1012 }
1013 peasycap = file->private_data;
1014 if (NULL == peasycap) {
1015 SAY("ERROR: peasycap is NULL\n");
1016 mutex_unlock(&easycap_dongle[kd].mutex_video);
1017 return -ERESTARTSYS;
1018 }
1019 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
1020 SAY("ERROR: bad peasycap\n");
1021 mutex_unlock(&easycap_dongle[kd].mutex_video);
1022 return -EFAULT;
1023 }
1024 p = peasycap->pusb_device;
1025 if (NULL == peasycap->pusb_device) {
1026 SAM("ERROR: peasycap->pusb_device is NULL\n");
1027 mutex_unlock(&easycap_dongle[kd].mutex_video);
1028 return -ERESTARTSYS;
1029 }
1030} else {
1031/*---------------------------------------------------------------------------*/
1032/*
1033 * IF easycap_usb_disconnect() HAS ALREADY FREED POINTER peasycap BEFORE THE
1034 * ATTEMPT TO ACQUIRE THE SEMAPHORE, isdongle() WILL HAVE FAILED. BAIL OUT.
1035*/
1036/*---------------------------------------------------------------------------*/
1037 return -ERESTARTSYS;
1038}
803/*---------------------------------------------------------------------------*/ 1039/*---------------------------------------------------------------------------*/
804switch (cmd) { 1040switch (cmd) {
805case VIDIOC_QUERYCAP: { 1041case VIDIOC_QUERYCAP: {
806 static struct v4l2_capability v4l2_capability; 1042 struct v4l2_capability v4l2_capability;
807 static char version[16], *p1, *p2; 1043 char version[16], *p1, *p2;
808 static int i, rc, k[3]; 1044 int i, rc, k[3];
809 static long lng; 1045 long lng;
810 1046
811 JOT(8, "VIDIOC_QUERYCAP\n"); 1047 JOM(8, "VIDIOC_QUERYCAP\n");
812 1048
813 if (16 <= strlen(EASYCAP_DRIVER_VERSION)) { 1049 if (16 <= strlen(EASYCAP_DRIVER_VERSION)) {
814 SAY("ERROR: bad driver version string\n"); return -EINVAL; 1050 SAM("ERROR: bad driver version string\n");
1051 mutex_unlock(&easycap_dongle[kd].mutex_video);
1052 return -EINVAL;
815 } 1053 }
816 strcpy(&version[0], EASYCAP_DRIVER_VERSION); 1054 strcpy(&version[0], EASYCAP_DRIVER_VERSION);
817 for (i = 0; i < 3; i++) 1055 for (i = 0; i < 3; i++)
@@ -826,8 +1064,9 @@ case VIDIOC_QUERYCAP: {
826 if (3 > i) { 1064 if (3 > i) {
827 rc = (int) strict_strtol(p1, 10, &lng); 1065 rc = (int) strict_strtol(p1, 10, &lng);
828 if (0 != rc) { 1066 if (0 != rc) {
829 SAY("ERROR: %i=strict_strtol(%s,.,,)\n", \ 1067 SAM("ERROR: %i=strict_strtol(%s,.,,)\n", \
830 rc, p1); 1068 rc, p1);
1069 mutex_unlock(&easycap_dongle[kd].mutex_video);
831 return -EINVAL; 1070 return -EINVAL;
832 } 1071 }
833 k[i] = (int)lng; 1072 k[i] = (int)lng;
@@ -844,7 +1083,7 @@ case VIDIOC_QUERYCAP: {
844 V4L2_CAP_AUDIO | V4L2_CAP_READWRITE; 1083 V4L2_CAP_AUDIO | V4L2_CAP_READWRITE;
845 1084
846 v4l2_capability.version = KERNEL_VERSION(k[0], k[1], k[2]); 1085 v4l2_capability.version = KERNEL_VERSION(k[0], k[1], k[2]);
847 JOT(8, "v4l2_capability.version=(%i,%i,%i)\n", k[0], k[1], k[2]); 1086 JOM(8, "v4l2_capability.version=(%i,%i,%i)\n", k[0], k[1], k[2]);
848 1087
849 strlcpy(&v4l2_capability.card[0], "EasyCAP DC60", \ 1088 strlcpy(&v4l2_capability.card[0], "EasyCAP DC60", \
850 sizeof(v4l2_capability.card)); 1089 sizeof(v4l2_capability.card));
@@ -853,26 +1092,26 @@ case VIDIOC_QUERYCAP: {
853 sizeof(v4l2_capability.bus_info)) < 0) { 1092 sizeof(v4l2_capability.bus_info)) < 0) {
854 strlcpy(&v4l2_capability.bus_info[0], "EasyCAP bus_info", \ 1093 strlcpy(&v4l2_capability.bus_info[0], "EasyCAP bus_info", \
855 sizeof(v4l2_capability.bus_info)); 1094 sizeof(v4l2_capability.bus_info));
856 JOT(8, "%s=v4l2_capability.bus_info\n", \ 1095 JOM(8, "%s=v4l2_capability.bus_info\n", \
857 &v4l2_capability.bus_info[0]); 1096 &v4l2_capability.bus_info[0]);
858 } 1097 }
859 if (0 != copy_to_user((void __user *)arg, &v4l2_capability, \ 1098 if (0 != copy_to_user((void __user *)arg, &v4l2_capability, \
860 sizeof(struct v4l2_capability))) { 1099 sizeof(struct v4l2_capability))) {
861 POUT; 1100 mutex_unlock(&easycap_dongle[kd].mutex_video);
862 return -EFAULT; 1101 return -EFAULT;
863 } 1102 }
864 break; 1103 break;
865} 1104}
866/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1105/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
867case VIDIOC_ENUMINPUT: { 1106case VIDIOC_ENUMINPUT: {
868 static struct v4l2_input v4l2_input; 1107 struct v4l2_input v4l2_input;
869 static __u32 index; 1108 __u32 index;
870 1109
871 JOT(8, "VIDIOC_ENUMINPUT\n"); 1110 JOM(8, "VIDIOC_ENUMINPUT\n");
872 1111
873 if (0 != copy_from_user(&v4l2_input, (void __user *)arg, \ 1112 if (0 != copy_from_user(&v4l2_input, (void __user *)arg, \
874 sizeof(struct v4l2_input))) { 1113 sizeof(struct v4l2_input))) {
875 POUT; 1114 mutex_unlock(&easycap_dongle[kd].mutex_video);
876 return -EFAULT; 1115 return -EFAULT;
877 } 1116 }
878 1117
@@ -889,7 +1128,7 @@ case VIDIOC_ENUMINPUT: {
889 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \ 1128 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \
890 V4L2_STD_NTSC ; 1129 V4L2_STD_NTSC ;
891 v4l2_input.status = 0; 1130 v4l2_input.status = 0;
892 JOT(8, "%i=index: %s\n", index, &v4l2_input.name[0]); 1131 JOM(8, "%i=index: %s\n", index, &v4l2_input.name[0]);
893 break; 1132 break;
894 } 1133 }
895 case 1: { 1134 case 1: {
@@ -901,7 +1140,7 @@ case VIDIOC_ENUMINPUT: {
901 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \ 1140 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \
902 V4L2_STD_NTSC ; 1141 V4L2_STD_NTSC ;
903 v4l2_input.status = 0; 1142 v4l2_input.status = 0;
904 JOT(8, "%i=index: %s\n", index, &v4l2_input.name[0]); 1143 JOM(8, "%i=index: %s\n", index, &v4l2_input.name[0]);
905 break; 1144 break;
906 } 1145 }
907 case 2: { 1146 case 2: {
@@ -913,7 +1152,7 @@ case VIDIOC_ENUMINPUT: {
913 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \ 1152 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \
914 V4L2_STD_NTSC ; 1153 V4L2_STD_NTSC ;
915 v4l2_input.status = 0; 1154 v4l2_input.status = 0;
916 JOT(8, "%i=index: %s\n", index, &v4l2_input.name[0]); 1155 JOM(8, "%i=index: %s\n", index, &v4l2_input.name[0]);
917 break; 1156 break;
918 } 1157 }
919 case 3: { 1158 case 3: {
@@ -925,7 +1164,7 @@ case VIDIOC_ENUMINPUT: {
925 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \ 1164 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \
926 V4L2_STD_NTSC ; 1165 V4L2_STD_NTSC ;
927 v4l2_input.status = 0; 1166 v4l2_input.status = 0;
928 JOT(8, "%i=index: %s\n", index, &v4l2_input.name[0]); 1167 JOM(8, "%i=index: %s\n", index, &v4l2_input.name[0]);
929 break; 1168 break;
930 } 1169 }
931 case 4: { 1170 case 4: {
@@ -937,7 +1176,7 @@ case VIDIOC_ENUMINPUT: {
937 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \ 1176 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \
938 V4L2_STD_NTSC ; 1177 V4L2_STD_NTSC ;
939 v4l2_input.status = 0; 1178 v4l2_input.status = 0;
940 JOT(8, "%i=index: %s\n", index, &v4l2_input.name[0]); 1179 JOM(8, "%i=index: %s\n", index, &v4l2_input.name[0]);
941 break; 1180 break;
942 } 1181 }
943 case 5: { 1182 case 5: {
@@ -949,31 +1188,32 @@ case VIDIOC_ENUMINPUT: {
949 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \ 1188 v4l2_input.std = V4L2_STD_PAL | V4L2_STD_SECAM | \
950 V4L2_STD_NTSC ; 1189 V4L2_STD_NTSC ;
951 v4l2_input.status = 0; 1190 v4l2_input.status = 0;
952 JOT(8, "%i=index: %s\n", index, &v4l2_input.name[0]); 1191 JOM(8, "%i=index: %s\n", index, &v4l2_input.name[0]);
953 break; 1192 break;
954 } 1193 }
955 default: { 1194 default: {
956 JOT(8, "%i=index: exhausts inputs\n", index); 1195 JOM(8, "%i=index: exhausts inputs\n", index);
1196 mutex_unlock(&easycap_dongle[kd].mutex_video);
957 return -EINVAL; 1197 return -EINVAL;
958 } 1198 }
959 } 1199 }
960 1200
961 if (0 != copy_to_user((void __user *)arg, &v4l2_input, \ 1201 if (0 != copy_to_user((void __user *)arg, &v4l2_input, \
962 sizeof(struct v4l2_input))) { 1202 sizeof(struct v4l2_input))) {
963 POUT; 1203 mutex_unlock(&easycap_dongle[kd].mutex_video);
964 return -EFAULT; 1204 return -EFAULT;
965 } 1205 }
966 break; 1206 break;
967} 1207}
968/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1208/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
969case VIDIOC_G_INPUT: { 1209case VIDIOC_G_INPUT: {
970 static __u32 index; 1210 __u32 index;
971 1211
972 JOT(8, "VIDIOC_G_INPUT\n"); 1212 JOM(8, "VIDIOC_G_INPUT\n");
973 index = (__u32)peasycap->input; 1213 index = (__u32)peasycap->input;
974 JOT(8, "user is told: %i\n", index); 1214 JOM(8, "user is told: %i\n", index);
975 if (0 != copy_to_user((void __user *)arg, &index, sizeof(__u32))) { 1215 if (0 != copy_to_user((void __user *)arg, &index, sizeof(__u32))) {
976 POUT; 1216 mutex_unlock(&easycap_dongle[kd].mutex_video);
977 return -EFAULT; 1217 return -EFAULT;
978 } 1218 }
979 break; 1219 break;
@@ -981,79 +1221,89 @@ case VIDIOC_G_INPUT: {
981/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1221/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
982case VIDIOC_S_INPUT: 1222case VIDIOC_S_INPUT:
983 { 1223 {
984 static __u32 index; 1224 __u32 index;
1225 int rc;
985 1226
986 JOT(8, "VIDIOC_S_INPUT\n"); 1227 JOM(8, "VIDIOC_S_INPUT\n");
987 1228
988 if (0 != copy_from_user(&index, (void __user *)arg, sizeof(__u32))) { 1229 if (0 != copy_from_user(&index, (void __user *)arg, sizeof(__u32))) {
989 POUT; 1230 mutex_unlock(&easycap_dongle[kd].mutex_video);
990 return -EFAULT; 1231 return -EFAULT;
991 } 1232 }
992 1233
993 JOT(8, "user requests input %i\n", index); 1234 JOM(8, "user requests input %i\n", index);
994 1235
995 if ((int)index == peasycap->input) { 1236 if ((int)index == peasycap->input) {
996 SAY("requested input already in effect\n"); 1237 SAM("requested input already in effect\n");
997 break; 1238 break;
998 } 1239 }
999 1240
1000 if ((0 > index) || (5 < index)) { 1241 if ((0 > index) || (INPUT_MANY <= index)) {
1001 JOT(8, "ERROR: bad requested input: %i\n", index); 1242 JOM(8, "ERROR: bad requested input: %i\n", index);
1243 mutex_unlock(&easycap_dongle[kd].mutex_video);
1002 return -EINVAL; 1244 return -EINVAL;
1003 } 1245 }
1004 peasycap->input = (int)index;
1005
1006 select_input(peasycap->pusb_device, peasycap->input, 9);
1007 1246
1247 rc = newinput(peasycap, (int)index);
1248 if (0 == rc) {
1249 JOM(8, "newinput(.,%i) OK\n", (int)index);
1250 } else {
1251 SAM("ERROR: newinput(.,%i) returned %i\n", (int)index, rc);
1252 mutex_unlock(&easycap_dongle[kd].mutex_video);
1253 return -EFAULT;
1254 }
1008 break; 1255 break;
1009} 1256}
1010/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1257/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1011case VIDIOC_ENUMAUDIO: { 1258case VIDIOC_ENUMAUDIO: {
1012 JOT(8, "VIDIOC_ENUMAUDIO\n"); 1259 JOM(8, "VIDIOC_ENUMAUDIO\n");
1260 mutex_unlock(&easycap_dongle[kd].mutex_video);
1013 return -EINVAL; 1261 return -EINVAL;
1014} 1262}
1015/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1263/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1016case VIDIOC_ENUMAUDOUT: { 1264case VIDIOC_ENUMAUDOUT: {
1017 static struct v4l2_audioout v4l2_audioout; 1265 struct v4l2_audioout v4l2_audioout;
1018 1266
1019 JOT(8, "VIDIOC_ENUMAUDOUT\n"); 1267 JOM(8, "VIDIOC_ENUMAUDOUT\n");
1020 1268
1021 if (0 != copy_from_user(&v4l2_audioout, (void __user *)arg, \ 1269 if (0 != copy_from_user(&v4l2_audioout, (void __user *)arg, \
1022 sizeof(struct v4l2_audioout))) { 1270 sizeof(struct v4l2_audioout))) {
1023 POUT; 1271 mutex_unlock(&easycap_dongle[kd].mutex_video);
1024 return -EFAULT; 1272 return -EFAULT;
1025 } 1273 }
1026 1274
1027 if (0 != v4l2_audioout.index) 1275 if (0 != v4l2_audioout.index) {
1276 mutex_unlock(&easycap_dongle[kd].mutex_video);
1028 return -EINVAL; 1277 return -EINVAL;
1278 }
1029 memset(&v4l2_audioout, 0, sizeof(struct v4l2_audioout)); 1279 memset(&v4l2_audioout, 0, sizeof(struct v4l2_audioout));
1030 v4l2_audioout.index = 0; 1280 v4l2_audioout.index = 0;
1031 strcpy(&v4l2_audioout.name[0], "Soundtrack"); 1281 strcpy(&v4l2_audioout.name[0], "Soundtrack");
1032 1282
1033 if (0 != copy_to_user((void __user *)arg, &v4l2_audioout, \ 1283 if (0 != copy_to_user((void __user *)arg, &v4l2_audioout, \
1034 sizeof(struct v4l2_audioout))) { 1284 sizeof(struct v4l2_audioout))) {
1035 POUT; 1285 mutex_unlock(&easycap_dongle[kd].mutex_video);
1036 return -EFAULT; 1286 return -EFAULT;
1037 } 1287 }
1038 break; 1288 break;
1039} 1289}
1040/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1290/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1041case VIDIOC_QUERYCTRL: { 1291case VIDIOC_QUERYCTRL: {
1042 static int i1; 1292 int i1;
1043 static struct v4l2_queryctrl v4l2_queryctrl; 1293 struct v4l2_queryctrl v4l2_queryctrl;
1044 1294
1045 JOT(8, "VIDIOC_QUERYCTRL\n"); 1295 JOM(8, "VIDIOC_QUERYCTRL\n");
1046 1296
1047 if (0 != copy_from_user(&v4l2_queryctrl, (void __user *)arg, \ 1297 if (0 != copy_from_user(&v4l2_queryctrl, (void __user *)arg, \
1048 sizeof(struct v4l2_queryctrl))) { 1298 sizeof(struct v4l2_queryctrl))) {
1049 POUT; 1299 mutex_unlock(&easycap_dongle[kd].mutex_video);
1050 return -EFAULT; 1300 return -EFAULT;
1051 } 1301 }
1052 1302
1053 i1 = 0; 1303 i1 = 0;
1054 while (0xFFFFFFFF != easycap_control[i1].id) { 1304 while (0xFFFFFFFF != easycap_control[i1].id) {
1055 if (easycap_control[i1].id == v4l2_queryctrl.id) { 1305 if (easycap_control[i1].id == v4l2_queryctrl.id) {
1056 JOT(8, "VIDIOC_QUERYCTRL %s=easycap_control[%i]" \ 1306 JOM(8, "VIDIOC_QUERYCTRL %s=easycap_control[%i]" \
1057 ".name\n", &easycap_control[i1].name[0], i1); 1307 ".name\n", &easycap_control[i1].name[0], i1);
1058 memcpy(&v4l2_queryctrl, &easycap_control[i1], \ 1308 memcpy(&v4l2_queryctrl, &easycap_control[i1], \
1059 sizeof(struct v4l2_queryctrl)); 1309 sizeof(struct v4l2_queryctrl));
@@ -1062,127 +1312,137 @@ case VIDIOC_QUERYCTRL: {
1062 i1++; 1312 i1++;
1063 } 1313 }
1064 if (0xFFFFFFFF == easycap_control[i1].id) { 1314 if (0xFFFFFFFF == easycap_control[i1].id) {
1065 JOT(8, "%i=index: exhausts controls\n", i1); 1315 JOM(8, "%i=index: exhausts controls\n", i1);
1316 mutex_unlock(&easycap_dongle[kd].mutex_video);
1066 return -EINVAL; 1317 return -EINVAL;
1067 } 1318 }
1068 if (0 != copy_to_user((void __user *)arg, &v4l2_queryctrl, \ 1319 if (0 != copy_to_user((void __user *)arg, &v4l2_queryctrl, \
1069 sizeof(struct v4l2_queryctrl))) { 1320 sizeof(struct v4l2_queryctrl))) {
1070 POUT; 1321 mutex_unlock(&easycap_dongle[kd].mutex_video);
1071 return -EFAULT; 1322 return -EFAULT;
1072 } 1323 }
1073 break; 1324 break;
1074} 1325}
1075/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1326/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1076case VIDIOC_QUERYMENU: { 1327case VIDIOC_QUERYMENU: {
1077 JOT(8, "VIDIOC_QUERYMENU unsupported\n"); 1328 JOM(8, "VIDIOC_QUERYMENU unsupported\n");
1329 mutex_unlock(&easycap_dongle[kd].mutex_video);
1078 return -EINVAL; 1330 return -EINVAL;
1079 break;
1080} 1331}
1081/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1332/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1082case VIDIOC_G_CTRL: { 1333case VIDIOC_G_CTRL: {
1083 static struct v4l2_control v4l2_control; 1334 struct v4l2_control *pv4l2_control;
1084 1335
1085 JOT(8, "VIDIOC_G_CTRL\n"); 1336 JOM(8, "VIDIOC_G_CTRL\n");
1086 1337 pv4l2_control = kzalloc(sizeof(struct v4l2_control), GFP_KERNEL);
1087 if (0 != copy_from_user(&v4l2_control, (void __user *)arg, \ 1338 if (!pv4l2_control) {
1339 SAM("ERROR: out of memory\n");
1340 mutex_unlock(&easycap_dongle[kd].mutex_video);
1341 return -ENOMEM;
1342 }
1343 if (0 != copy_from_user(pv4l2_control, (void __user *)arg, \
1088 sizeof(struct v4l2_control))) { 1344 sizeof(struct v4l2_control))) {
1089 POUT; 1345 kfree(pv4l2_control);
1346 mutex_unlock(&easycap_dongle[kd].mutex_video);
1090 return -EFAULT; 1347 return -EFAULT;
1091 } 1348 }
1092 1349
1093 switch (v4l2_control.id) { 1350 switch (pv4l2_control->id) {
1094 case V4L2_CID_BRIGHTNESS: { 1351 case V4L2_CID_BRIGHTNESS: {
1095 v4l2_control.value = peasycap->brightness; 1352 pv4l2_control->value = peasycap->brightness;
1096 JOT(8, "user enquires brightness: %i\n", v4l2_control.value); 1353 JOM(8, "user enquires brightness: %i\n", pv4l2_control->value);
1097 break; 1354 break;
1098 } 1355 }
1099 case V4L2_CID_CONTRAST: { 1356 case V4L2_CID_CONTRAST: {
1100 v4l2_control.value = peasycap->contrast; 1357 pv4l2_control->value = peasycap->contrast;
1101 JOT(8, "user enquires contrast: %i\n", v4l2_control.value); 1358 JOM(8, "user enquires contrast: %i\n", pv4l2_control->value);
1102 break; 1359 break;
1103 } 1360 }
1104 case V4L2_CID_SATURATION: { 1361 case V4L2_CID_SATURATION: {
1105 v4l2_control.value = peasycap->saturation; 1362 pv4l2_control->value = peasycap->saturation;
1106 JOT(8, "user enquires saturation: %i\n", v4l2_control.value); 1363 JOM(8, "user enquires saturation: %i\n", pv4l2_control->value);
1107 break; 1364 break;
1108 } 1365 }
1109 case V4L2_CID_HUE: { 1366 case V4L2_CID_HUE: {
1110 v4l2_control.value = peasycap->hue; 1367 pv4l2_control->value = peasycap->hue;
1111 JOT(8, "user enquires hue: %i\n", v4l2_control.value); 1368 JOM(8, "user enquires hue: %i\n", pv4l2_control->value);
1112 break; 1369 break;
1113 } 1370 }
1114 case V4L2_CID_AUDIO_VOLUME: { 1371 case V4L2_CID_AUDIO_VOLUME: {
1115 v4l2_control.value = peasycap->volume; 1372 pv4l2_control->value = peasycap->volume;
1116 JOT(8, "user enquires volume: %i\n", v4l2_control.value); 1373 JOM(8, "user enquires volume: %i\n", pv4l2_control->value);
1117 break; 1374 break;
1118 } 1375 }
1119 case V4L2_CID_AUDIO_MUTE: { 1376 case V4L2_CID_AUDIO_MUTE: {
1120 if (1 == peasycap->mute) 1377 if (1 == peasycap->mute)
1121 v4l2_control.value = true; 1378 pv4l2_control->value = true;
1122 else 1379 else
1123 v4l2_control.value = false; 1380 pv4l2_control->value = false;
1124 JOT(8, "user enquires mute: %i\n", v4l2_control.value); 1381 JOM(8, "user enquires mute: %i\n", pv4l2_control->value);
1125 break; 1382 break;
1126 } 1383 }
1127 default: { 1384 default: {
1128 SAY("ERROR: unknown V4L2 control: 0x%08X=id\n", \ 1385 SAM("ERROR: unknown V4L2 control: 0x%08X=id\n", \
1129 v4l2_control.id); 1386 pv4l2_control->id);
1130 explain_cid(v4l2_control.id); 1387 kfree(pv4l2_control);
1388 mutex_unlock(&easycap_dongle[kd].mutex_video);
1131 return -EINVAL; 1389 return -EINVAL;
1132 } 1390 }
1133 } 1391 }
1134 if (0 != copy_to_user((void __user *)arg, &v4l2_control, \ 1392 if (0 != copy_to_user((void __user *)arg, pv4l2_control, \
1135 sizeof(struct v4l2_control))) { 1393 sizeof(struct v4l2_control))) {
1136 POUT; 1394 kfree(pv4l2_control);
1395 mutex_unlock(&easycap_dongle[kd].mutex_video);
1137 return -EFAULT; 1396 return -EFAULT;
1138 } 1397 }
1398 kfree(pv4l2_control);
1139 break; 1399 break;
1140} 1400}
1141/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1401/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1142#if defined(VIDIOC_S_CTRL_OLD) 1402#if defined(VIDIOC_S_CTRL_OLD)
1143case VIDIOC_S_CTRL_OLD: { 1403case VIDIOC_S_CTRL_OLD: {
1144 JOT(8, "VIDIOC_S_CTRL_OLD required at least for xawtv\n"); 1404 JOM(8, "VIDIOC_S_CTRL_OLD required at least for xawtv\n");
1145} 1405}
1146#endif /*VIDIOC_S_CTRL_OLD*/ 1406#endif /*VIDIOC_S_CTRL_OLD*/
1147case VIDIOC_S_CTRL: 1407case VIDIOC_S_CTRL:
1148 { 1408 {
1149 static struct v4l2_control v4l2_control; 1409 struct v4l2_control v4l2_control;
1150 1410
1151 JOT(8, "VIDIOC_S_CTRL\n"); 1411 JOM(8, "VIDIOC_S_CTRL\n");
1152 1412
1153 if (0 != copy_from_user(&v4l2_control, (void __user *)arg, \ 1413 if (0 != copy_from_user(&v4l2_control, (void __user *)arg, \
1154 sizeof(struct v4l2_control))) { 1414 sizeof(struct v4l2_control))) {
1155 POUT; 1415 mutex_unlock(&easycap_dongle[kd].mutex_video);
1156 return -EFAULT; 1416 return -EFAULT;
1157 } 1417 }
1158 1418
1159 switch (v4l2_control.id) { 1419 switch (v4l2_control.id) {
1160 case V4L2_CID_BRIGHTNESS: { 1420 case V4L2_CID_BRIGHTNESS: {
1161 JOT(8, "user requests brightness %i\n", v4l2_control.value); 1421 JOM(8, "user requests brightness %i\n", v4l2_control.value);
1162 if (0 != adjust_brightness(peasycap, v4l2_control.value)) 1422 if (0 != adjust_brightness(peasycap, v4l2_control.value))
1163 ; 1423 ;
1164 break; 1424 break;
1165 } 1425 }
1166 case V4L2_CID_CONTRAST: { 1426 case V4L2_CID_CONTRAST: {
1167 JOT(8, "user requests contrast %i\n", v4l2_control.value); 1427 JOM(8, "user requests contrast %i\n", v4l2_control.value);
1168 if (0 != adjust_contrast(peasycap, v4l2_control.value)) 1428 if (0 != adjust_contrast(peasycap, v4l2_control.value))
1169 ; 1429 ;
1170 break; 1430 break;
1171 } 1431 }
1172 case V4L2_CID_SATURATION: { 1432 case V4L2_CID_SATURATION: {
1173 JOT(8, "user requests saturation %i\n", v4l2_control.value); 1433 JOM(8, "user requests saturation %i\n", v4l2_control.value);
1174 if (0 != adjust_saturation(peasycap, v4l2_control.value)) 1434 if (0 != adjust_saturation(peasycap, v4l2_control.value))
1175 ; 1435 ;
1176 break; 1436 break;
1177 } 1437 }
1178 case V4L2_CID_HUE: { 1438 case V4L2_CID_HUE: {
1179 JOT(8, "user requests hue %i\n", v4l2_control.value); 1439 JOM(8, "user requests hue %i\n", v4l2_control.value);
1180 if (0 != adjust_hue(peasycap, v4l2_control.value)) 1440 if (0 != adjust_hue(peasycap, v4l2_control.value))
1181 ; 1441 ;
1182 break; 1442 break;
1183 } 1443 }
1184 case V4L2_CID_AUDIO_VOLUME: { 1444 case V4L2_CID_AUDIO_VOLUME: {
1185 JOT(8, "user requests volume %i\n", v4l2_control.value); 1445 JOM(8, "user requests volume %i\n", v4l2_control.value);
1186 if (0 != adjust_volume(peasycap, v4l2_control.value)) 1446 if (0 != adjust_volume(peasycap, v4l2_control.value))
1187 ; 1447 ;
1188 break; 1448 break;
@@ -1190,40 +1450,41 @@ case VIDIOC_S_CTRL:
1190 case V4L2_CID_AUDIO_MUTE: { 1450 case V4L2_CID_AUDIO_MUTE: {
1191 int mute; 1451 int mute;
1192 1452
1193 JOT(8, "user requests mute %i\n", v4l2_control.value); 1453 JOM(8, "user requests mute %i\n", v4l2_control.value);
1194 if (true == v4l2_control.value) 1454 if (true == v4l2_control.value)
1195 mute = 1; 1455 mute = 1;
1196 else 1456 else
1197 mute = 0; 1457 mute = 0;
1198 1458
1199 if (0 != adjust_mute(peasycap, mute)) 1459 if (0 != adjust_mute(peasycap, mute))
1200 SAY("WARNING: failed to adjust mute to %i\n", mute); 1460 SAM("WARNING: failed to adjust mute to %i\n", mute);
1201 break; 1461 break;
1202 } 1462 }
1203 default: { 1463 default: {
1204 SAY("ERROR: unknown V4L2 control: 0x%08X=id\n", \ 1464 SAM("ERROR: unknown V4L2 control: 0x%08X=id\n", \
1205 v4l2_control.id); 1465 v4l2_control.id);
1206 explain_cid(v4l2_control.id); 1466 mutex_unlock(&easycap_dongle[kd].mutex_video);
1207 return -EINVAL; 1467 return -EINVAL;
1208 } 1468 }
1209 } 1469 }
1210 break; 1470 break;
1211} 1471}
1212/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1472/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1213case VIDIOC_S_EXT_CTRLS: { 1473case VIDIOC_S_EXT_CTRLS: {
1214 JOT(8, "VIDIOC_S_EXT_CTRLS unsupported\n"); 1474 JOM(8, "VIDIOC_S_EXT_CTRLS unsupported\n");
1475 mutex_unlock(&easycap_dongle[kd].mutex_video);
1215 return -EINVAL; 1476 return -EINVAL;
1216} 1477}
1217/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1478/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1218case VIDIOC_ENUM_FMT: { 1479case VIDIOC_ENUM_FMT: {
1219 static __u32 index; 1480 __u32 index;
1220 static struct v4l2_fmtdesc v4l2_fmtdesc; 1481 struct v4l2_fmtdesc v4l2_fmtdesc;
1221 1482
1222 JOT(8, "VIDIOC_ENUM_FMT\n"); 1483 JOM(8, "VIDIOC_ENUM_FMT\n");
1223 1484
1224 if (0 != copy_from_user(&v4l2_fmtdesc, (void __user *)arg, \ 1485 if (0 != copy_from_user(&v4l2_fmtdesc, (void __user *)arg, \
1225 sizeof(struct v4l2_fmtdesc))) { 1486 sizeof(struct v4l2_fmtdesc))) {
1226 POUT; 1487 mutex_unlock(&easycap_dongle[kd].mutex_video);
1227 return -EFAULT; 1488 return -EFAULT;
1228 } 1489 }
1229 1490
@@ -1238,117 +1499,327 @@ case VIDIOC_ENUM_FMT: {
1238 v4l2_fmtdesc.flags = 0; 1499 v4l2_fmtdesc.flags = 0;
1239 strcpy(&v4l2_fmtdesc.description[0], "uyvy"); 1500 strcpy(&v4l2_fmtdesc.description[0], "uyvy");
1240 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_UYVY; 1501 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_UYVY;
1241 JOT(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]); 1502 JOM(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]);
1242 break; 1503 break;
1243 } 1504 }
1244 case 1: { 1505 case 1: {
1245 v4l2_fmtdesc.flags = 0; 1506 v4l2_fmtdesc.flags = 0;
1246 strcpy(&v4l2_fmtdesc.description[0], "yuy2"); 1507 strcpy(&v4l2_fmtdesc.description[0], "yuy2");
1247 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_YUYV; 1508 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_YUYV;
1248 JOT(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]); 1509 JOM(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]);
1249 break; 1510 break;
1250 } 1511 }
1251 case 2: { 1512 case 2: {
1252 v4l2_fmtdesc.flags = 0; 1513 v4l2_fmtdesc.flags = 0;
1253 strcpy(&v4l2_fmtdesc.description[0], "rgb24"); 1514 strcpy(&v4l2_fmtdesc.description[0], "rgb24");
1254 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_RGB24; 1515 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_RGB24;
1255 JOT(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]); 1516 JOM(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]);
1256 break; 1517 break;
1257 } 1518 }
1258 case 3: { 1519 case 3: {
1259 v4l2_fmtdesc.flags = 0; 1520 v4l2_fmtdesc.flags = 0;
1260 strcpy(&v4l2_fmtdesc.description[0], "rgb32"); 1521 strcpy(&v4l2_fmtdesc.description[0], "rgb32");
1261 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_RGB32; 1522 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_RGB32;
1262 JOT(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]); 1523 JOM(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]);
1263 break; 1524 break;
1264 } 1525 }
1265 case 4: { 1526 case 4: {
1266 v4l2_fmtdesc.flags = 0; 1527 v4l2_fmtdesc.flags = 0;
1267 strcpy(&v4l2_fmtdesc.description[0], "bgr24"); 1528 strcpy(&v4l2_fmtdesc.description[0], "bgr24");
1268 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_BGR24; 1529 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_BGR24;
1269 JOT(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]); 1530 JOM(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]);
1270 break; 1531 break;
1271 } 1532 }
1272 case 5: { 1533 case 5: {
1273 v4l2_fmtdesc.flags = 0; 1534 v4l2_fmtdesc.flags = 0;
1274 strcpy(&v4l2_fmtdesc.description[0], "bgr32"); 1535 strcpy(&v4l2_fmtdesc.description[0], "bgr32");
1275 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_BGR32; 1536 v4l2_fmtdesc.pixelformat = V4L2_PIX_FMT_BGR32;
1276 JOT(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]); 1537 JOM(8, "%i=index: %s\n", index, &v4l2_fmtdesc.description[0]);
1277 break; 1538 break;
1278 } 1539 }
1279 default: { 1540 default: {
1280 JOT(8, "%i=index: exhausts formats\n", index); 1541 JOM(8, "%i=index: exhausts formats\n", index);
1542 mutex_unlock(&easycap_dongle[kd].mutex_video);
1281 return -EINVAL; 1543 return -EINVAL;
1282 } 1544 }
1283 } 1545 }
1284 if (0 != copy_to_user((void __user *)arg, &v4l2_fmtdesc, \ 1546 if (0 != copy_to_user((void __user *)arg, &v4l2_fmtdesc, \
1285 sizeof(struct v4l2_fmtdesc))) { 1547 sizeof(struct v4l2_fmtdesc))) {
1286 POUT; 1548 mutex_unlock(&easycap_dongle[kd].mutex_video);
1287 return -EFAULT; 1549 return -EFAULT;
1288 } 1550 }
1289 break; 1551 break;
1290} 1552}
1291/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1553/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1554/*
1555 * THE RESPONSE TO VIDIOC_ENUM_FRAMESIZES MUST BE CONDITIONED ON THE
1556 * THE CURRENT STANDARD, BECAUSE THAT IS WHAT gstreamer EXPECTS. BEWARE.
1557*/
1558/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1292case VIDIOC_ENUM_FRAMESIZES: { 1559case VIDIOC_ENUM_FRAMESIZES: {
1293 JOT(8, "VIDIOC_ENUM_FRAMESIZES unsupported\n"); 1560 __u32 index;
1294 return -EINVAL; 1561 struct v4l2_frmsizeenum v4l2_frmsizeenum;
1562
1563 JOM(8, "VIDIOC_ENUM_FRAMESIZES\n");
1564
1565 if (0 != copy_from_user(&v4l2_frmsizeenum, (void __user *)arg, \
1566 sizeof(struct v4l2_frmsizeenum))) {
1567 mutex_unlock(&easycap_dongle[kd].mutex_video);
1568 return -EFAULT;
1569 }
1570
1571 index = v4l2_frmsizeenum.index;
1572
1573 v4l2_frmsizeenum.type = (__u32) V4L2_FRMSIZE_TYPE_DISCRETE;
1574
1575 if (true == peasycap->ntsc) {
1576 switch (index) {
1577 case 0: {
1578 v4l2_frmsizeenum.discrete.width = 640;
1579 v4l2_frmsizeenum.discrete.height = 480;
1580 JOM(8, "%i=index: %ix%i\n", index, \
1581 (int)(v4l2_frmsizeenum.\
1582 discrete.width), \
1583 (int)(v4l2_frmsizeenum.\
1584 discrete.height));
1585 break;
1586 }
1587 case 1: {
1588 v4l2_frmsizeenum.discrete.width = 320;
1589 v4l2_frmsizeenum.discrete.height = 240;
1590 JOM(8, "%i=index: %ix%i\n", index, \
1591 (int)(v4l2_frmsizeenum.\
1592 discrete.width), \
1593 (int)(v4l2_frmsizeenum.\
1594 discrete.height));
1595 break;
1596 }
1597 case 2: {
1598 v4l2_frmsizeenum.discrete.width = 720;
1599 v4l2_frmsizeenum.discrete.height = 480;
1600 JOM(8, "%i=index: %ix%i\n", index, \
1601 (int)(v4l2_frmsizeenum.\
1602 discrete.width), \
1603 (int)(v4l2_frmsizeenum.\
1604 discrete.height));
1605 break;
1606 }
1607 case 3: {
1608 v4l2_frmsizeenum.discrete.width = 360;
1609 v4l2_frmsizeenum.discrete.height = 240;
1610 JOM(8, "%i=index: %ix%i\n", index, \
1611 (int)(v4l2_frmsizeenum.\
1612 discrete.width), \
1613 (int)(v4l2_frmsizeenum.\
1614 discrete.height));
1615 break;
1616 }
1617 default: {
1618 JOM(8, "%i=index: exhausts framesizes\n", index);
1619 mutex_unlock(&easycap_dongle[kd].mutex_video);
1620 return -EINVAL;
1621 }
1622 }
1623 } else {
1624 switch (index) {
1625 case 0: {
1626 v4l2_frmsizeenum.discrete.width = 640;
1627 v4l2_frmsizeenum.discrete.height = 480;
1628 JOM(8, "%i=index: %ix%i\n", index, \
1629 (int)(v4l2_frmsizeenum.\
1630 discrete.width), \
1631 (int)(v4l2_frmsizeenum.\
1632 discrete.height));
1633 break;
1634 }
1635 case 1: {
1636 v4l2_frmsizeenum.discrete.width = 320;
1637 v4l2_frmsizeenum.discrete.height = 240;
1638 JOM(8, "%i=index: %ix%i\n", index, \
1639 (int)(v4l2_frmsizeenum.\
1640 discrete.width), \
1641 (int)(v4l2_frmsizeenum.\
1642 discrete.height));
1643 break;
1644 }
1645 case 2: {
1646 v4l2_frmsizeenum.discrete.width = 704;
1647 v4l2_frmsizeenum.discrete.height = 576;
1648 JOM(8, "%i=index: %ix%i\n", index, \
1649 (int)(v4l2_frmsizeenum.\
1650 discrete.width), \
1651 (int)(v4l2_frmsizeenum.\
1652 discrete.height));
1653 break;
1654 }
1655 case 3: {
1656 v4l2_frmsizeenum.discrete.width = 720;
1657 v4l2_frmsizeenum.discrete.height = 576;
1658 JOM(8, "%i=index: %ix%i\n", index, \
1659 (int)(v4l2_frmsizeenum.\
1660 discrete.width), \
1661 (int)(v4l2_frmsizeenum.\
1662 discrete.height));
1663 break;
1664 }
1665 case 4: {
1666 v4l2_frmsizeenum.discrete.width = 360;
1667 v4l2_frmsizeenum.discrete.height = 288;
1668 JOM(8, "%i=index: %ix%i\n", index, \
1669 (int)(v4l2_frmsizeenum.\
1670 discrete.width), \
1671 (int)(v4l2_frmsizeenum.\
1672 discrete.height));
1673 break;
1674 }
1675 default: {
1676 JOM(8, "%i=index: exhausts framesizes\n", index);
1677 mutex_unlock(&easycap_dongle[kd].mutex_video);
1678 return -EINVAL;
1679 }
1680 }
1681 }
1682 if (0 != copy_to_user((void __user *)arg, &v4l2_frmsizeenum, \
1683 sizeof(struct v4l2_frmsizeenum))) {
1684 mutex_unlock(&easycap_dongle[kd].mutex_video);
1685 return -EFAULT;
1686 }
1687 break;
1295} 1688}
1689/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1690/*
1691 * THE RESPONSE TO VIDIOC_ENUM_FRAMEINTERVALS MUST BE CONDITIONED ON THE
1692 * THE CURRENT STANDARD, BECAUSE THAT IS WHAT gstreamer EXPECTS. BEWARE.
1693*/
1694/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1296case VIDIOC_ENUM_FRAMEINTERVALS: { 1695case VIDIOC_ENUM_FRAMEINTERVALS: {
1297 JOT(8, "VIDIOC_ENUM_FRAME_INTERVALS unsupported\n"); 1696 __u32 index;
1298 return -EINVAL; 1697 int denominator;
1698 struct v4l2_frmivalenum v4l2_frmivalenum;
1699
1700 JOM(8, "VIDIOC_ENUM_FRAMEINTERVALS\n");
1701
1702 if (peasycap->fps)
1703 denominator = peasycap->fps;
1704 else {
1705 if (true == peasycap->ntsc)
1706 denominator = 30;
1707 else
1708 denominator = 25;
1709 }
1710
1711 if (0 != copy_from_user(&v4l2_frmivalenum, (void __user *)arg, \
1712 sizeof(struct v4l2_frmivalenum))) {
1713 mutex_unlock(&easycap_dongle[kd].mutex_video);
1714 return -EFAULT;
1715 }
1716
1717 index = v4l2_frmivalenum.index;
1718
1719 v4l2_frmivalenum.type = (__u32) V4L2_FRMIVAL_TYPE_DISCRETE;
1720
1721 switch (index) {
1722 case 0: {
1723 v4l2_frmivalenum.discrete.numerator = 1;
1724 v4l2_frmivalenum.discrete.denominator = denominator;
1725 JOM(8, "%i=index: %i/%i\n", index, \
1726 (int)(v4l2_frmivalenum.discrete.numerator), \
1727 (int)(v4l2_frmivalenum.discrete.denominator));
1728 break;
1729 }
1730 case 1: {
1731 v4l2_frmivalenum.discrete.numerator = 1;
1732 v4l2_frmivalenum.discrete.denominator = denominator/5;
1733 JOM(8, "%i=index: %i/%i\n", index, \
1734 (int)(v4l2_frmivalenum.discrete.numerator), \
1735 (int)(v4l2_frmivalenum.discrete.denominator));
1736 break;
1737 }
1738 default: {
1739 JOM(8, "%i=index: exhausts frameintervals\n", index);
1740 mutex_unlock(&easycap_dongle[kd].mutex_video);
1741 return -EINVAL;
1742 }
1743 }
1744 if (0 != copy_to_user((void __user *)arg, &v4l2_frmivalenum, \
1745 sizeof(struct v4l2_frmivalenum))) {
1746 mutex_unlock(&easycap_dongle[kd].mutex_video);
1747 return -EFAULT;
1748 }
1749 break;
1299} 1750}
1300/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1751/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1301case VIDIOC_G_FMT: { 1752case VIDIOC_G_FMT: {
1302 static struct v4l2_format v4l2_format; 1753 struct v4l2_format *pv4l2_format;
1303 static struct v4l2_pix_format v4l2_pix_format; 1754 struct v4l2_pix_format *pv4l2_pix_format;
1304 1755
1305 JOT(8, "VIDIOC_G_FMT\n"); 1756 JOM(8, "VIDIOC_G_FMT\n");
1306 1757 pv4l2_format = kzalloc(sizeof(struct v4l2_format), GFP_KERNEL);
1307 if (0 != copy_from_user(&v4l2_format, (void __user *)arg, \ 1758 if (!pv4l2_format) {
1759 SAM("ERROR: out of memory\n");
1760 mutex_unlock(&easycap_dongle[kd].mutex_video);
1761 return -ENOMEM;
1762 }
1763 pv4l2_pix_format = kzalloc(sizeof(struct v4l2_pix_format), GFP_KERNEL);
1764 if (!pv4l2_pix_format) {
1765 SAM("ERROR: out of memory\n");
1766 kfree(pv4l2_format);
1767 mutex_unlock(&easycap_dongle[kd].mutex_video);
1768 return -ENOMEM;
1769 }
1770 if (0 != copy_from_user(pv4l2_format, (void __user *)arg, \
1308 sizeof(struct v4l2_format))) { 1771 sizeof(struct v4l2_format))) {
1309 POUT; 1772 kfree(pv4l2_format);
1773 kfree(pv4l2_pix_format);
1774 mutex_unlock(&easycap_dongle[kd].mutex_video);
1310 return -EFAULT; 1775 return -EFAULT;
1311 } 1776 }
1312 1777
1313 if (v4l2_format.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1778 if (pv4l2_format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1314 POUT; 1779 kfree(pv4l2_format);
1780 kfree(pv4l2_pix_format);
1781 mutex_unlock(&easycap_dongle[kd].mutex_video);
1315 return -EINVAL; 1782 return -EINVAL;
1316 } 1783 }
1317 1784
1318 memset(&v4l2_pix_format, 0, sizeof(struct v4l2_pix_format)); 1785 memset(pv4l2_pix_format, 0, sizeof(struct v4l2_pix_format));
1319 v4l2_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1786 pv4l2_format->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1320 memcpy(&(v4l2_format.fmt.pix), \ 1787 memcpy(&pv4l2_format->fmt.pix, \
1321 &(easycap_format[peasycap->format_offset]\ 1788 &easycap_format[peasycap->format_offset]\
1322 .v4l2_format.fmt.pix), sizeof(v4l2_pix_format)); 1789 .v4l2_format.fmt.pix, sizeof(struct v4l2_pix_format));
1323 JOT(8, "user is told: %s\n", \ 1790 JOM(8, "user is told: %s\n", \
1324 &easycap_format[peasycap->format_offset].name[0]); 1791 &easycap_format[peasycap->format_offset].name[0]);
1325 1792
1326 if (0 != copy_to_user((void __user *)arg, &v4l2_format, \ 1793 if (0 != copy_to_user((void __user *)arg, pv4l2_format, \
1327 sizeof(struct v4l2_format))) { 1794 sizeof(struct v4l2_format))) {
1328 POUT; 1795 kfree(pv4l2_format);
1796 kfree(pv4l2_pix_format);
1797 mutex_unlock(&easycap_dongle[kd].mutex_video);
1329 return -EFAULT; 1798 return -EFAULT;
1330 } 1799 }
1800 kfree(pv4l2_format);
1801 kfree(pv4l2_pix_format);
1331 break; 1802 break;
1332} 1803}
1333/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1804/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1334case VIDIOC_TRY_FMT: 1805case VIDIOC_TRY_FMT:
1335case VIDIOC_S_FMT: { 1806case VIDIOC_S_FMT: {
1336 static struct v4l2_format v4l2_format; 1807 struct v4l2_format v4l2_format;
1337 static struct v4l2_pix_format v4l2_pix_format; 1808 struct v4l2_pix_format v4l2_pix_format;
1338 static bool try; 1809 bool try;
1339 static int best_format; 1810 int best_format;
1340 1811
1341 if (VIDIOC_TRY_FMT == cmd) { 1812 if (VIDIOC_TRY_FMT == cmd) {
1342 JOT(8, "VIDIOC_TRY_FMT\n"); 1813 JOM(8, "VIDIOC_TRY_FMT\n");
1343 try = true; 1814 try = true;
1344 } else { 1815 } else {
1345 JOT(8, "VIDIOC_S_FMT\n"); 1816 JOM(8, "VIDIOC_S_FMT\n");
1346 try = false; 1817 try = false;
1347 } 1818 }
1348 1819
1349 if (0 != copy_from_user(&v4l2_format, (void __user *)arg, \ 1820 if (0 != copy_from_user(&v4l2_format, (void __user *)arg, \
1350 sizeof(struct v4l2_format))) { 1821 sizeof(struct v4l2_format))) {
1351 POUT; 1822 mutex_unlock(&easycap_dongle[kd].mutex_video);
1352 return -EFAULT; 1823 return -EFAULT;
1353 } 1824 }
1354 1825
@@ -1359,7 +1830,12 @@ case VIDIOC_S_FMT: {
1359 v4l2_format.fmt.pix.field, \ 1830 v4l2_format.fmt.pix.field, \
1360 try); 1831 try);
1361 if (0 > best_format) { 1832 if (0 > best_format) {
1362 JOT(8, "WARNING: adjust_format() returned %i\n", best_format); 1833 if (-EBUSY == best_format) {
1834 mutex_unlock(&easycap_dongle[kd].mutex_video);
1835 return -EBUSY;
1836 }
1837 JOM(8, "WARNING: adjust_format() returned %i\n", best_format);
1838 mutex_unlock(&easycap_dongle[kd].mutex_video);
1363 return -ENOENT; 1839 return -ENOENT;
1364 } 1840 }
1365/*...........................................................................*/ 1841/*...........................................................................*/
@@ -1368,29 +1844,29 @@ case VIDIOC_S_FMT: {
1368 1844
1369 memcpy(&(v4l2_format.fmt.pix), &(easycap_format[best_format]\ 1845 memcpy(&(v4l2_format.fmt.pix), &(easycap_format[best_format]\
1370 .v4l2_format.fmt.pix), sizeof(v4l2_pix_format)); 1846 .v4l2_format.fmt.pix), sizeof(v4l2_pix_format));
1371 JOT(8, "user is told: %s\n", &easycap_format[best_format].name[0]); 1847 JOM(8, "user is told: %s\n", &easycap_format[best_format].name[0]);
1372 1848
1373 if (0 != copy_to_user((void __user *)arg, &v4l2_format, \ 1849 if (0 != copy_to_user((void __user *)arg, &v4l2_format, \
1374 sizeof(struct v4l2_format))) { 1850 sizeof(struct v4l2_format))) {
1375 POUT; 1851 mutex_unlock(&easycap_dongle[kd].mutex_video);
1376 return -EFAULT; 1852 return -EFAULT;
1377 } 1853 }
1378 break; 1854 break;
1379} 1855}
1380/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1856/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1381case VIDIOC_CROPCAP: { 1857case VIDIOC_CROPCAP: {
1382 static struct v4l2_cropcap v4l2_cropcap; 1858 struct v4l2_cropcap v4l2_cropcap;
1383 1859
1384 JOT(8, "VIDIOC_CROPCAP\n"); 1860 JOM(8, "VIDIOC_CROPCAP\n");
1385 1861
1386 if (0 != copy_from_user(&v4l2_cropcap, (void __user *)arg, \ 1862 if (0 != copy_from_user(&v4l2_cropcap, (void __user *)arg, \
1387 sizeof(struct v4l2_cropcap))) { 1863 sizeof(struct v4l2_cropcap))) {
1388 POUT; 1864 mutex_unlock(&easycap_dongle[kd].mutex_video);
1389 return -EFAULT; 1865 return -EFAULT;
1390 } 1866 }
1391 1867
1392 if (v4l2_cropcap.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1868 if (v4l2_cropcap.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1393 JOT(8, "v4l2_cropcap.type != V4L2_BUF_TYPE_VIDEO_CAPTURE\n"); 1869 JOM(8, "v4l2_cropcap.type != V4L2_BUF_TYPE_VIDEO_CAPTURE\n");
1394 1870
1395 memset(&v4l2_cropcap, 0, sizeof(struct v4l2_cropcap)); 1871 memset(&v4l2_cropcap, 0, sizeof(struct v4l2_cropcap));
1396 v4l2_cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1872 v4l2_cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -1405,11 +1881,11 @@ case VIDIOC_CROPCAP: {
1405 v4l2_cropcap.pixelaspect.numerator = 1; 1881 v4l2_cropcap.pixelaspect.numerator = 1;
1406 v4l2_cropcap.pixelaspect.denominator = 1; 1882 v4l2_cropcap.pixelaspect.denominator = 1;
1407 1883
1408 JOT(8, "user is told: %ix%i\n", peasycap->width, peasycap->height); 1884 JOM(8, "user is told: %ix%i\n", peasycap->width, peasycap->height);
1409 1885
1410 if (0 != copy_to_user((void __user *)arg, &v4l2_cropcap, \ 1886 if (0 != copy_to_user((void __user *)arg, &v4l2_cropcap, \
1411 sizeof(struct v4l2_cropcap))) { 1887 sizeof(struct v4l2_cropcap))) {
1412 POUT; 1888 mutex_unlock(&easycap_dongle[kd].mutex_video);
1413 return -EFAULT; 1889 return -EFAULT;
1414 } 1890 }
1415 break; 1891 break;
@@ -1417,13 +1893,15 @@ case VIDIOC_CROPCAP: {
1417/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1893/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1418case VIDIOC_G_CROP: 1894case VIDIOC_G_CROP:
1419case VIDIOC_S_CROP: { 1895case VIDIOC_S_CROP: {
1420 JOT(8, "VIDIOC_G_CROP|VIDIOC_S_CROP unsupported\n"); 1896 JOM(8, "VIDIOC_G_CROP|VIDIOC_S_CROP unsupported\n");
1897 mutex_unlock(&easycap_dongle[kd].mutex_video);
1421 return -EINVAL; 1898 return -EINVAL;
1422} 1899}
1423/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1900/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1424case VIDIOC_QUERYSTD: { 1901case VIDIOC_QUERYSTD: {
1425 JOT(8, "VIDIOC_QUERYSTD: " \ 1902 JOM(8, "VIDIOC_QUERYSTD: " \
1426 "EasyCAP is incapable of detecting standard\n"); 1903 "EasyCAP is incapable of detecting standard\n");
1904 mutex_unlock(&easycap_dongle[kd].mutex_video);
1427 return -EINVAL; 1905 return -EINVAL;
1428 break; 1906 break;
1429} 1907}
@@ -1436,16 +1914,16 @@ case VIDIOC_QUERYSTD: {
1436 */ 1914 */
1437/*---------------------------------------------------------------------------*/ 1915/*---------------------------------------------------------------------------*/
1438case VIDIOC_ENUMSTD: { 1916case VIDIOC_ENUMSTD: {
1439 static int last0 = -1, last1 = -1, last2 = -1, last3 = -1; 1917 int last0 = -1, last1 = -1, last2 = -1, last3 = -1;
1440 static struct v4l2_standard v4l2_standard; 1918 struct v4l2_standard v4l2_standard;
1441 static __u32 index; 1919 __u32 index;
1442 static struct easycap_standard const *peasycap_standard; 1920 struct easycap_standard const *peasycap_standard;
1443 1921
1444 JOT(8, "VIDIOC_ENUMSTD\n"); 1922 JOM(8, "VIDIOC_ENUMSTD\n");
1445 1923
1446 if (0 != copy_from_user(&v4l2_standard, (void __user *)arg, \ 1924 if (0 != copy_from_user(&v4l2_standard, (void __user *)arg, \
1447 sizeof(struct v4l2_standard))) { 1925 sizeof(struct v4l2_standard))) {
1448 POUT; 1926 mutex_unlock(&easycap_dongle[kd].mutex_video);
1449 return -EFAULT; 1927 return -EFAULT;
1450 } 1928 }
1451 index = v4l2_standard.index; 1929 index = v4l2_standard.index;
@@ -1466,10 +1944,11 @@ case VIDIOC_ENUMSTD: {
1466 peasycap_standard++; 1944 peasycap_standard++;
1467 } 1945 }
1468 if (0xFFFF == peasycap_standard->mask) { 1946 if (0xFFFF == peasycap_standard->mask) {
1469 JOT(8, "%i=index: exhausts standards\n", index); 1947 JOM(8, "%i=index: exhausts standards\n", index);
1948 mutex_unlock(&easycap_dongle[kd].mutex_video);
1470 return -EINVAL; 1949 return -EINVAL;
1471 } 1950 }
1472 JOT(8, "%i=index: %s\n", index, \ 1951 JOM(8, "%i=index: %s\n", index, \
1473 &(peasycap_standard->v4l2_standard.name[0])); 1952 &(peasycap_standard->v4l2_standard.name[0]));
1474 memcpy(&v4l2_standard, &(peasycap_standard->v4l2_standard), \ 1953 memcpy(&v4l2_standard, &(peasycap_standard->v4l2_standard), \
1475 sizeof(struct v4l2_standard)); 1954 sizeof(struct v4l2_standard));
@@ -1478,87 +1957,101 @@ case VIDIOC_ENUMSTD: {
1478 1957
1479 if (0 != copy_to_user((void __user *)arg, &v4l2_standard, \ 1958 if (0 != copy_to_user((void __user *)arg, &v4l2_standard, \
1480 sizeof(struct v4l2_standard))) { 1959 sizeof(struct v4l2_standard))) {
1481 POUT; 1960 mutex_unlock(&easycap_dongle[kd].mutex_video);
1482 return -EFAULT; 1961 return -EFAULT;
1483 } 1962 }
1484 break; 1963 break;
1485} 1964}
1486/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1965/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1487case VIDIOC_G_STD: { 1966case VIDIOC_G_STD: {
1488 static v4l2_std_id std_id; 1967 v4l2_std_id std_id;
1489 static struct easycap_standard const *peasycap_standard; 1968 struct easycap_standard const *peasycap_standard;
1969
1970 JOM(8, "VIDIOC_G_STD\n");
1490 1971
1491 JOT(8, "VIDIOC_G_STD\n"); 1972 if (0 > peasycap->standard_offset) {
1973 JOM(8, "%i=peasycap->standard_offset\n", \
1974 peasycap->standard_offset);
1975 mutex_unlock(&easycap_dongle[kd].mutex_video);
1976 return -EBUSY;
1977 }
1492 1978
1493 if (0 != copy_from_user(&std_id, (void __user *)arg, \ 1979 if (0 != copy_from_user(&std_id, (void __user *)arg, \
1494 sizeof(v4l2_std_id))) { 1980 sizeof(v4l2_std_id))) {
1495 POUT; 1981 mutex_unlock(&easycap_dongle[kd].mutex_video);
1496 return -EFAULT; 1982 return -EFAULT;
1497 } 1983 }
1498 1984
1499 peasycap_standard = &easycap_standard[peasycap->standard_offset]; 1985 peasycap_standard = &easycap_standard[peasycap->standard_offset];
1500 std_id = peasycap_standard->v4l2_standard.id; 1986 std_id = peasycap_standard->v4l2_standard.id;
1501 1987
1502 JOT(8, "user is told: %s\n", \ 1988 JOM(8, "user is told: %s\n", \
1503 &peasycap_standard->v4l2_standard.name[0]); 1989 &peasycap_standard->v4l2_standard.name[0]);
1504 1990
1505 if (0 != copy_to_user((void __user *)arg, &std_id, \ 1991 if (0 != copy_to_user((void __user *)arg, &std_id, \
1506 sizeof(v4l2_std_id))) { 1992 sizeof(v4l2_std_id))) {
1507 POUT; 1993 mutex_unlock(&easycap_dongle[kd].mutex_video);
1508 return -EFAULT; 1994 return -EFAULT;
1509 } 1995 }
1510 break; 1996 break;
1511} 1997}
1512/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1998/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1513case VIDIOC_S_STD: { 1999case VIDIOC_S_STD: {
1514 static v4l2_std_id std_id; 2000 v4l2_std_id std_id;
1515 static int rc; 2001 int rc;
1516 2002
1517 JOT(8, "VIDIOC_S_STD\n"); 2003 JOM(8, "VIDIOC_S_STD\n");
1518 2004
1519 if (0 != copy_from_user(&std_id, (void __user *)arg, \ 2005 if (0 != copy_from_user(&std_id, (void __user *)arg, \
1520 sizeof(v4l2_std_id))) { 2006 sizeof(v4l2_std_id))) {
1521 POUT; 2007 mutex_unlock(&easycap_dongle[kd].mutex_video);
1522 return -EFAULT; 2008 return -EFAULT;
1523 } 2009 }
1524 2010
2011 JOM(8, "User requests standard: 0x%08X%08X\n", \
2012 (int)((std_id & (((v4l2_std_id)0xFFFFFFFF) << 32)) >> 32), \
2013 (int)(std_id & ((v4l2_std_id)0xFFFFFFFF)));
2014
1525 rc = adjust_standard(peasycap, std_id); 2015 rc = adjust_standard(peasycap, std_id);
1526 if (0 > rc) { 2016 if (0 > rc) {
1527 JOT(8, "WARNING: adjust_standard() returned %i\n", rc); 2017 JOM(8, "WARNING: adjust_standard() returned %i\n", rc);
2018 mutex_unlock(&easycap_dongle[kd].mutex_video);
1528 return -ENOENT; 2019 return -ENOENT;
1529 } 2020 }
1530 break; 2021 break;
1531} 2022}
1532/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2023/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1533case VIDIOC_REQBUFS: { 2024case VIDIOC_REQBUFS: {
1534 static int nbuffers; 2025 int nbuffers;
1535 static struct v4l2_requestbuffers v4l2_requestbuffers; 2026 struct v4l2_requestbuffers v4l2_requestbuffers;
1536 2027
1537 JOT(8, "VIDIOC_REQBUFS\n"); 2028 JOM(8, "VIDIOC_REQBUFS\n");
1538 2029
1539 if (0 != copy_from_user(&v4l2_requestbuffers, (void __user *)arg, \ 2030 if (0 != copy_from_user(&v4l2_requestbuffers, (void __user *)arg, \
1540 sizeof(struct v4l2_requestbuffers))) { 2031 sizeof(struct v4l2_requestbuffers))) {
1541 POUT; 2032 mutex_unlock(&easycap_dongle[kd].mutex_video);
1542 return -EFAULT; 2033 return -EFAULT;
1543 } 2034 }
1544 2035
1545 if (v4l2_requestbuffers.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 2036 if (v4l2_requestbuffers.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2037 mutex_unlock(&easycap_dongle[kd].mutex_video);
1546 return -EINVAL; 2038 return -EINVAL;
2039 }
1547 if (v4l2_requestbuffers.memory != V4L2_MEMORY_MMAP) { 2040 if (v4l2_requestbuffers.memory != V4L2_MEMORY_MMAP) {
1548 POUT; 2041 mutex_unlock(&easycap_dongle[kd].mutex_video);
1549 return -EINVAL; 2042 return -EINVAL;
1550 } 2043 }
1551 nbuffers = v4l2_requestbuffers.count; 2044 nbuffers = v4l2_requestbuffers.count;
1552 JOT(8, " User requests %i buffers ...\n", nbuffers); 2045 JOM(8, " User requests %i buffers ...\n", nbuffers);
1553 if (nbuffers < 2) 2046 if (nbuffers < 2)
1554 nbuffers = 2; 2047 nbuffers = 2;
1555 if (nbuffers > FRAME_BUFFER_MANY) 2048 if (nbuffers > FRAME_BUFFER_MANY)
1556 nbuffers = FRAME_BUFFER_MANY; 2049 nbuffers = FRAME_BUFFER_MANY;
1557 if (v4l2_requestbuffers.count == nbuffers) { 2050 if (v4l2_requestbuffers.count == nbuffers) {
1558 JOT(8, " ... agree to %i buffers\n", \ 2051 JOM(8, " ... agree to %i buffers\n", \
1559 nbuffers); 2052 nbuffers);
1560 } else { 2053 } else {
1561 JOT(8, " ... insist on %i buffers\n", \ 2054 JOM(8, " ... insist on %i buffers\n", \
1562 nbuffers); 2055 nbuffers);
1563 v4l2_requestbuffers.count = nbuffers; 2056 v4l2_requestbuffers.count = nbuffers;
1564 } 2057 }
@@ -1566,32 +2059,35 @@ case VIDIOC_REQBUFS: {
1566 2059
1567 if (0 != copy_to_user((void __user *)arg, &v4l2_requestbuffers, \ 2060 if (0 != copy_to_user((void __user *)arg, &v4l2_requestbuffers, \
1568 sizeof(struct v4l2_requestbuffers))) { 2061 sizeof(struct v4l2_requestbuffers))) {
1569 POUT; 2062 mutex_unlock(&easycap_dongle[kd].mutex_video);
1570 return -EFAULT; 2063 return -EFAULT;
1571 } 2064 }
1572 break; 2065 break;
1573} 2066}
1574/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2067/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1575case VIDIOC_QUERYBUF: { 2068case VIDIOC_QUERYBUF: {
1576 static __u32 index; 2069 __u32 index;
1577 static struct v4l2_buffer v4l2_buffer; 2070 struct v4l2_buffer v4l2_buffer;
1578 2071
1579 JOT(8, "VIDIOC_QUERYBUF\n"); 2072 JOM(8, "VIDIOC_QUERYBUF\n");
1580 2073
1581 if (peasycap->video_eof) { 2074 if (peasycap->video_eof) {
1582 JOT(8, "returning -1 because %i=video_eof\n", \ 2075 JOM(8, "returning -EIO because %i=video_eof\n", \
1583 peasycap->video_eof); 2076 peasycap->video_eof);
1584 return -1; 2077 mutex_unlock(&easycap_dongle[kd].mutex_video);
2078 return -EIO;
1585 } 2079 }
1586 2080
1587 if (0 != copy_from_user(&v4l2_buffer, (void __user *)arg, \ 2081 if (0 != copy_from_user(&v4l2_buffer, (void __user *)arg, \
1588 sizeof(struct v4l2_buffer))) { 2082 sizeof(struct v4l2_buffer))) {
1589 POUT; 2083 mutex_unlock(&easycap_dongle[kd].mutex_video);
1590 return -EFAULT; 2084 return -EFAULT;
1591 } 2085 }
1592 2086
1593 if (v4l2_buffer.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 2087 if (v4l2_buffer.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2088 mutex_unlock(&easycap_dongle[kd].mutex_video);
1594 return -EINVAL; 2089 return -EINVAL;
2090 }
1595 index = v4l2_buffer.index; 2091 index = v4l2_buffer.index;
1596 if (index < 0 || index >= peasycap->frame_buffer_many) 2092 if (index < 0 || index >= peasycap->frame_buffer_many)
1597 return -EINVAL; 2093 return -EINVAL;
@@ -1602,49 +2098,55 @@ case VIDIOC_QUERYBUF: {
1602 v4l2_buffer.flags = V4L2_BUF_FLAG_MAPPED | \ 2098 v4l2_buffer.flags = V4L2_BUF_FLAG_MAPPED | \
1603 peasycap->done[index] | \ 2099 peasycap->done[index] | \
1604 peasycap->queued[index]; 2100 peasycap->queued[index];
1605 v4l2_buffer.field = peasycap->field; 2101 v4l2_buffer.field = V4L2_FIELD_NONE;
1606 v4l2_buffer.memory = V4L2_MEMORY_MMAP; 2102 v4l2_buffer.memory = V4L2_MEMORY_MMAP;
1607 v4l2_buffer.m.offset = index * FRAME_BUFFER_SIZE; 2103 v4l2_buffer.m.offset = index * FRAME_BUFFER_SIZE;
1608 v4l2_buffer.length = FRAME_BUFFER_SIZE; 2104 v4l2_buffer.length = FRAME_BUFFER_SIZE;
1609 2105
1610 JOT(16, " %10i=index\n", v4l2_buffer.index); 2106 JOM(16, " %10i=index\n", v4l2_buffer.index);
1611 JOT(16, " 0x%08X=type\n", v4l2_buffer.type); 2107 JOM(16, " 0x%08X=type\n", v4l2_buffer.type);
1612 JOT(16, " %10i=bytesused\n", v4l2_buffer.bytesused); 2108 JOM(16, " %10i=bytesused\n", v4l2_buffer.bytesused);
1613 JOT(16, " 0x%08X=flags\n", v4l2_buffer.flags); 2109 JOM(16, " 0x%08X=flags\n", v4l2_buffer.flags);
1614 JOT(16, " %10i=field\n", v4l2_buffer.field); 2110 JOM(16, " %10i=field\n", v4l2_buffer.field);
1615 JOT(16, " %10li=timestamp.tv_usec\n", \ 2111 JOM(16, " %10li=timestamp.tv_usec\n", \
1616 (long)v4l2_buffer.timestamp.tv_usec); 2112 (long)v4l2_buffer.timestamp.tv_usec);
1617 JOT(16, " %10i=sequence\n", v4l2_buffer.sequence); 2113 JOM(16, " %10i=sequence\n", v4l2_buffer.sequence);
1618 JOT(16, " 0x%08X=memory\n", v4l2_buffer.memory); 2114 JOM(16, " 0x%08X=memory\n", v4l2_buffer.memory);
1619 JOT(16, " %10i=m.offset\n", v4l2_buffer.m.offset); 2115 JOM(16, " %10i=m.offset\n", v4l2_buffer.m.offset);
1620 JOT(16, " %10i=length\n", v4l2_buffer.length); 2116 JOM(16, " %10i=length\n", v4l2_buffer.length);
1621 2117
1622 if (0 != copy_to_user((void __user *)arg, &v4l2_buffer, \ 2118 if (0 != copy_to_user((void __user *)arg, &v4l2_buffer, \
1623 sizeof(struct v4l2_buffer))) { 2119 sizeof(struct v4l2_buffer))) {
1624 POUT; 2120 mutex_unlock(&easycap_dongle[kd].mutex_video);
1625 return -EFAULT; 2121 return -EFAULT;
1626 } 2122 }
1627 break; 2123 break;
1628} 2124}
1629/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2125/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1630case VIDIOC_QBUF: { 2126case VIDIOC_QBUF: {
1631 static struct v4l2_buffer v4l2_buffer; 2127 struct v4l2_buffer v4l2_buffer;
1632 2128
1633 JOT(8, "VIDIOC_QBUF\n"); 2129 JOM(8, "VIDIOC_QBUF\n");
1634 2130
1635 if (0 != copy_from_user(&v4l2_buffer, (void __user *)arg, \ 2131 if (0 != copy_from_user(&v4l2_buffer, (void __user *)arg, \
1636 sizeof(struct v4l2_buffer))) { 2132 sizeof(struct v4l2_buffer))) {
1637 POUT; 2133 mutex_unlock(&easycap_dongle[kd].mutex_video);
1638 return -EFAULT; 2134 return -EFAULT;
1639 } 2135 }
1640 2136
1641 if (v4l2_buffer.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 2137 if (v4l2_buffer.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2138 mutex_unlock(&easycap_dongle[kd].mutex_video);
1642 return -EINVAL; 2139 return -EINVAL;
1643 if (v4l2_buffer.memory != V4L2_MEMORY_MMAP) 2140 }
2141 if (v4l2_buffer.memory != V4L2_MEMORY_MMAP) {
2142 mutex_unlock(&easycap_dongle[kd].mutex_video);
1644 return -EINVAL; 2143 return -EINVAL;
2144 }
1645 if (v4l2_buffer.index < 0 || \ 2145 if (v4l2_buffer.index < 0 || \
1646 (v4l2_buffer.index >= peasycap->frame_buffer_many)) 2146 (v4l2_buffer.index >= peasycap->frame_buffer_many)) {
2147 mutex_unlock(&easycap_dongle[kd].mutex_video);
1647 return -EINVAL; 2148 return -EINVAL;
2149 }
1648 v4l2_buffer.flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED; 2150 v4l2_buffer.flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED;
1649 2151
1650 peasycap->done[v4l2_buffer.index] = 0; 2152 peasycap->done[v4l2_buffer.index] = 0;
@@ -1652,11 +2154,11 @@ case VIDIOC_QBUF: {
1652 2154
1653 if (0 != copy_to_user((void __user *)arg, &v4l2_buffer, \ 2155 if (0 != copy_to_user((void __user *)arg, &v4l2_buffer, \
1654 sizeof(struct v4l2_buffer))) { 2156 sizeof(struct v4l2_buffer))) {
1655 POUT; 2157 mutex_unlock(&easycap_dongle[kd].mutex_video);
1656 return -EFAULT; 2158 return -EFAULT;
1657 } 2159 }
1658 2160
1659 JOT(8, "..... user queueing frame buffer %i\n", \ 2161 JOM(8, "..... user queueing frame buffer %i\n", \
1660 (int)v4l2_buffer.index); 2162 (int)v4l2_buffer.index);
1661 2163
1662 peasycap->frame_lock = 0; 2164 peasycap->frame_lock = 0;
@@ -1667,36 +2169,60 @@ case VIDIOC_QBUF: {
1667case VIDIOC_DQBUF: 2169case VIDIOC_DQBUF:
1668 { 2170 {
1669#if defined(AUDIOTIME) 2171#if defined(AUDIOTIME)
1670 static struct signed_div_result sdr; 2172 struct signed_div_result sdr;
1671 static long long int above, below, dnbydt, fudge, sll; 2173 long long int above, below, dnbydt, fudge, sll;
1672 static unsigned long long int ull; 2174 unsigned long long int ull;
1673 static struct timeval timeval0; 2175 struct timeval timeval8;
1674 struct timeval timeval1; 2176 struct timeval timeval1;
1675#endif /*AUDIOTIME*/ 2177#endif /*AUDIOTIME*/
1676 static struct timeval timeval, timeval2; 2178 struct timeval timeval, timeval2;
1677 static int i, j; 2179 int i, j;
1678 static struct v4l2_buffer v4l2_buffer; 2180 struct v4l2_buffer v4l2_buffer;
2181 int rcdq;
2182 __u16 input;
1679 2183
1680 JOT(8, "VIDIOC_DQBUF\n"); 2184 JOM(8, "VIDIOC_DQBUF\n");
1681 2185
1682 if ((peasycap->video_idle) || (peasycap->video_eof)) { 2186 if ((peasycap->video_idle) || (peasycap->video_eof)) {
1683 JOT(8, "returning -EIO because " \ 2187 JOM(8, "returning -EIO because " \
1684 "%i=video_idle %i=video_eof\n", \ 2188 "%i=video_idle %i=video_eof\n", \
1685 peasycap->video_idle, peasycap->video_eof); 2189 peasycap->video_idle, peasycap->video_eof);
2190 mutex_unlock(&easycap_dongle[kd].mutex_video);
1686 return -EIO; 2191 return -EIO;
1687 } 2192 }
1688 2193
1689 if (0 != copy_from_user(&v4l2_buffer, (void __user *)arg, \ 2194 if (0 != copy_from_user(&v4l2_buffer, (void __user *)arg, \
1690 sizeof(struct v4l2_buffer))) { 2195 sizeof(struct v4l2_buffer))) {
1691 POUT; 2196 mutex_unlock(&easycap_dongle[kd].mutex_video);
1692 return -EFAULT; 2197 return -EFAULT;
1693 } 2198 }
1694 2199
1695 if (v4l2_buffer.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 2200 if (v4l2_buffer.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2201 mutex_unlock(&easycap_dongle[kd].mutex_video);
1696 return -EINVAL; 2202 return -EINVAL;
2203 }
2204
2205 if (true == peasycap->offerfields) {
2206 /*-----------------------------------------------------------*/
2207 /*
2208 * IN ITS 50 "fps" MODE tvtime SEEMS ALWAYS TO REQUEST
2209 * V4L2_FIELD_BOTTOM
2210 */
2211 /*-----------------------------------------------------------*/
2212 if (V4L2_FIELD_TOP == v4l2_buffer.field)
2213 JOM(8, "user wants V4L2_FIELD_TOP\n");
2214 else if (V4L2_FIELD_BOTTOM == v4l2_buffer.field)
2215 JOM(8, "user wants V4L2_FIELD_BOTTOM\n");
2216 else if (V4L2_FIELD_ANY == v4l2_buffer.field)
2217 JOM(8, "user wants V4L2_FIELD_ANY\n");
2218 else
2219 JOM(8, "user wants V4L2_FIELD_...UNKNOWN: %i\n", \
2220 v4l2_buffer.field);
2221 }
1697 2222
1698 if (!peasycap->video_isoc_streaming) { 2223 if (!peasycap->video_isoc_streaming) {
1699 JOT(16, "returning -EIO because video urbs not streaming\n"); 2224 JOM(16, "returning -EIO because video urbs not streaming\n");
2225 mutex_unlock(&easycap_dongle[kd].mutex_video);
1700 return -EIO; 2226 return -EIO;
1701 } 2227 }
1702/*---------------------------------------------------------------------------*/ 2228/*---------------------------------------------------------------------------*/
@@ -1708,19 +2234,28 @@ case VIDIOC_DQBUF:
1708/*---------------------------------------------------------------------------*/ 2234/*---------------------------------------------------------------------------*/
1709 2235
1710 if (!peasycap->polled) { 2236 if (!peasycap->polled) {
1711 if (-EIO == easycap_dqbuf(peasycap, 0)) 2237 do {
1712 return -EIO; 2238 rcdq = easycap_dqbuf(peasycap, 0);
2239 if (-EIO == rcdq) {
2240 JOM(8, "returning -EIO because " \
2241 "dqbuf() returned -EIO\n");
2242 mutex_unlock(&easycap_dongle[kd].mutex_video);
2243 return -EIO;
2244 }
2245 } while (0 != rcdq);
1713 } else { 2246 } else {
1714 if (peasycap->video_eof) 2247 if (peasycap->video_eof) {
2248 mutex_unlock(&easycap_dongle[kd].mutex_video);
1715 return -EIO; 2249 return -EIO;
2250 }
1716 } 2251 }
1717 if (V4L2_BUF_FLAG_DONE != peasycap->done[peasycap->frame_read]) { 2252 if (V4L2_BUF_FLAG_DONE != peasycap->done[peasycap->frame_read]) {
1718 SAY("ERROR: V4L2_BUF_FLAG_DONE != 0x%08X\n", \ 2253 SAM("ERROR: V4L2_BUF_FLAG_DONE != 0x%08X\n", \
1719 peasycap->done[peasycap->frame_read]); 2254 peasycap->done[peasycap->frame_read]);
1720 } 2255 }
1721 peasycap->polled = 0; 2256 peasycap->polled = 0;
1722 2257
1723 if (!(isequence % 10)) { 2258 if (!(peasycap->isequence % 10)) {
1724 for (i = 0; i < 179; i++) 2259 for (i = 0; i < 179; i++)
1725 peasycap->merit[i] = peasycap->merit[i+1]; 2260 peasycap->merit[i] = peasycap->merit[i+1];
1726 peasycap->merit[179] = merit_saa(peasycap->pusb_device); 2261 peasycap->merit[179] = merit_saa(peasycap->pusb_device);
@@ -1728,7 +2263,7 @@ case VIDIOC_DQBUF:
1728 for (i = 0; i < 180; i++) 2263 for (i = 0; i < 180; i++)
1729 j += peasycap->merit[i]; 2264 j += peasycap->merit[i];
1730 if (90 < j) { 2265 if (90 < j) {
1731 SAY("easycap driver shutting down " \ 2266 SAM("easycap driver shutting down " \
1732 "on condition blue\n"); 2267 "on condition blue\n");
1733 peasycap->video_eof = 1; peasycap->audio_eof = 1; 2268 peasycap->video_eof = 1; peasycap->audio_eof = 1;
1734 } 2269 }
@@ -1738,31 +2273,23 @@ case VIDIOC_DQBUF:
1738 v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 2273 v4l2_buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1739 v4l2_buffer.bytesused = peasycap->frame_buffer_used; 2274 v4l2_buffer.bytesused = peasycap->frame_buffer_used;
1740 v4l2_buffer.flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE; 2275 v4l2_buffer.flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE;
1741 v4l2_buffer.field = peasycap->field; 2276 if (true == peasycap->offerfields)
1742 if (V4L2_FIELD_ALTERNATE == v4l2_buffer.field) 2277 v4l2_buffer.field = V4L2_FIELD_BOTTOM;
1743 v4l2_buffer.field = \ 2278 else
1744 0x000F & (peasycap->\ 2279 v4l2_buffer.field = V4L2_FIELD_NONE;
1745 frame_buffer[peasycap->frame_read][0].kount);
1746 do_gettimeofday(&timeval); 2280 do_gettimeofday(&timeval);
1747 timeval2 = timeval; 2281 timeval2 = timeval;
1748 2282
1749#if defined(AUDIOTIME) 2283#if defined(AUDIOTIME)
1750 if (!peasycap->timeval0.tv_sec) { 2284 if (!peasycap->timeval0.tv_sec) {
1751 timeval0 = timeval; 2285 timeval8 = timeval;
1752 timeval1 = timeval; 2286 timeval1 = timeval;
1753 timeval2 = timeval; 2287 timeval2 = timeval;
1754 dnbydt = 192000; 2288 dnbydt = 192000;
1755 2289 peasycap->timeval0 = timeval8;
1756 if (mutex_lock_interruptible(&(peasycap->mutex_timeval0)))
1757 return -ERESTARTSYS;
1758 peasycap->timeval0 = timeval0;
1759 mutex_unlock(&(peasycap->mutex_timeval0));
1760 } else { 2290 } else {
1761 if (mutex_lock_interruptible(&(peasycap->mutex_timeval1)))
1762 return -ERESTARTSYS;
1763 dnbydt = peasycap->dnbydt; 2291 dnbydt = peasycap->dnbydt;
1764 timeval1 = peasycap->timeval1; 2292 timeval1 = peasycap->timeval1;
1765 mutex_unlock(&(peasycap->mutex_timeval1));
1766 above = dnbydt * MICROSECONDS(timeval, timeval1); 2293 above = dnbydt * MICROSECONDS(timeval, timeval1);
1767 below = 192000; 2294 below = 192000;
1768 sdr = signed_div(above, below); 2295 sdr = signed_div(above, below);
@@ -1774,72 +2301,76 @@ case VIDIOC_DQBUF:
1774 timeval2.tv_usec = sdr.remainder; 2301 timeval2.tv_usec = sdr.remainder;
1775 timeval2.tv_sec = timeval1.tv_sec + sdr.quotient; 2302 timeval2.tv_sec = timeval1.tv_sec + sdr.quotient;
1776 } 2303 }
1777 if (!(isequence % 500)) { 2304 if (!(peasycap->isequence % 500)) {
1778 fudge = ((long long int)(1000000)) * \ 2305 fudge = ((long long int)(1000000)) * \
1779 ((long long int)(timeval.tv_sec - \ 2306 ((long long int)(timeval.tv_sec - \
1780 timeval2.tv_sec)) + \ 2307 timeval2.tv_sec)) + \
1781 (long long int)(timeval.tv_usec - \ 2308 (long long int)(timeval.tv_usec - \
1782 timeval2.tv_usec); 2309 timeval2.tv_usec);
1783 sdr = signed_div(fudge, 1000); 2310 sdr = signed_div(fudge, 1000);
1784 sll = sdr.quotient; 2311 sll = sdr.quotient;
1785 ull = sdr.remainder; 2312 ull = sdr.remainder;
1786 2313
1787 SAY("%5lli.%-3lli=ms timestamp fudge\n", sll, ull); 2314 SAM("%5lli.%-3lli=ms timestamp fudge\n", sll, ull);
1788 } 2315 }
1789#endif /*AUDIOTIME*/ 2316#endif /*AUDIOTIME*/
1790 2317
1791 v4l2_buffer.timestamp = timeval2; 2318 v4l2_buffer.timestamp = timeval2;
1792 v4l2_buffer.sequence = isequence++; 2319 v4l2_buffer.sequence = peasycap->isequence++;
1793 v4l2_buffer.memory = V4L2_MEMORY_MMAP; 2320 v4l2_buffer.memory = V4L2_MEMORY_MMAP;
1794 v4l2_buffer.m.offset = v4l2_buffer.index * FRAME_BUFFER_SIZE; 2321 v4l2_buffer.m.offset = v4l2_buffer.index * FRAME_BUFFER_SIZE;
1795 v4l2_buffer.length = FRAME_BUFFER_SIZE; 2322 v4l2_buffer.length = FRAME_BUFFER_SIZE;
1796 2323
1797 JOT(16, " %10i=index\n", v4l2_buffer.index); 2324 JOM(16, " %10i=index\n", v4l2_buffer.index);
1798 JOT(16, " 0x%08X=type\n", v4l2_buffer.type); 2325 JOM(16, " 0x%08X=type\n", v4l2_buffer.type);
1799 JOT(16, " %10i=bytesused\n", v4l2_buffer.bytesused); 2326 JOM(16, " %10i=bytesused\n", v4l2_buffer.bytesused);
1800 JOT(16, " 0x%08X=flags\n", v4l2_buffer.flags); 2327 JOM(16, " 0x%08X=flags\n", v4l2_buffer.flags);
1801 JOT(16, " %10i=field\n", v4l2_buffer.field); 2328 JOM(16, " %10i=field\n", v4l2_buffer.field);
1802 JOT(16, " %10li=timestamp.tv_usec\n", \ 2329 JOM(16, " %10li=timestamp.tv_sec\n", \
2330 (long)v4l2_buffer.timestamp.tv_sec);
2331 JOM(16, " %10li=timestamp.tv_usec\n", \
1803 (long)v4l2_buffer.timestamp.tv_usec); 2332 (long)v4l2_buffer.timestamp.tv_usec);
1804 JOT(16, " %10i=sequence\n", v4l2_buffer.sequence); 2333 JOM(16, " %10i=sequence\n", v4l2_buffer.sequence);
1805 JOT(16, " 0x%08X=memory\n", v4l2_buffer.memory); 2334 JOM(16, " 0x%08X=memory\n", v4l2_buffer.memory);
1806 JOT(16, " %10i=m.offset\n", v4l2_buffer.m.offset); 2335 JOM(16, " %10i=m.offset\n", v4l2_buffer.m.offset);
1807 JOT(16, " %10i=length\n", v4l2_buffer.length); 2336 JOM(16, " %10i=length\n", v4l2_buffer.length);
1808 2337
1809 if (0 != copy_to_user((void __user *)arg, &v4l2_buffer, \ 2338 if (0 != copy_to_user((void __user *)arg, &v4l2_buffer, \
1810 sizeof(struct v4l2_buffer))) { 2339 sizeof(struct v4l2_buffer))) {
1811 POUT; 2340 mutex_unlock(&easycap_dongle[kd].mutex_video);
1812 return -EFAULT; 2341 return -EFAULT;
1813 } 2342 }
1814 2343
1815 JOT(8, "..... user is offered frame buffer %i\n", \ 2344 input = peasycap->frame_buffer[peasycap->frame_read][0].input;
2345 if (0x08 & input) {
2346 JOM(8, "user is offered frame buffer %i, input %i\n", \
2347 peasycap->frame_read, (0x07 & input));
2348 } else {
2349 JOM(8, "user is offered frame buffer %i\n", \
1816 peasycap->frame_read); 2350 peasycap->frame_read);
2351 }
1817 peasycap->frame_lock = 1; 2352 peasycap->frame_lock = 1;
2353 JOM(8, "%i=peasycap->frame_fill\n", peasycap->frame_fill);
1818 if (peasycap->frame_read == peasycap->frame_fill) { 2354 if (peasycap->frame_read == peasycap->frame_fill) {
1819 if (peasycap->frame_lock) { 2355 if (peasycap->frame_lock) {
1820 JOT(8, "ERROR: filling frame buffer " \ 2356 JOM(8, "WORRY: filling frame buffer " \
1821 "while offered to user\n"); 2357 "while offered to user\n");
1822 } 2358 }
1823 } 2359 }
1824 break; 2360 break;
1825} 2361}
1826/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2362/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1827/*---------------------------------------------------------------------------*/
1828/*
1829 * AUDIO URBS HAVE ALREADY BEEN SUBMITTED WHEN THIS COMMAND IS RECEIVED;
1830 * VIDEO URBS HAVE NOT.
1831 */
1832/*---------------------------------------------------------------------------*/
1833case VIDIOC_STREAMON: { 2363case VIDIOC_STREAMON: {
1834 static int i; 2364 int i;
1835 2365
1836 JOT(8, "VIDIOC_STREAMON\n"); 2366 JOM(8, "VIDIOC_STREAMON\n");
1837 2367
1838 isequence = 0; 2368 peasycap->isequence = 0;
1839 for (i = 0; i < 180; i++) 2369 for (i = 0; i < 180; i++)
1840 peasycap->merit[i] = 0; 2370 peasycap->merit[i] = 0;
1841 if ((struct usb_device *)NULL == peasycap->pusb_device) { 2371 if ((struct usb_device *)NULL == peasycap->pusb_device) {
1842 SAY("ERROR: peasycap->pusb_device is NULL\n"); 2372 SAM("ERROR: peasycap->pusb_device is NULL\n");
2373 mutex_unlock(&easycap_dongle[kd].mutex_video);
1843 return -EFAULT; 2374 return -EFAULT;
1844 } 2375 }
1845 submit_video_urbs(peasycap); 2376 submit_video_urbs(peasycap);
@@ -1851,10 +2382,11 @@ case VIDIOC_STREAMON: {
1851} 2382}
1852/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2383/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1853case VIDIOC_STREAMOFF: { 2384case VIDIOC_STREAMOFF: {
1854 JOT(8, "VIDIOC_STREAMOFF\n"); 2385 JOM(8, "VIDIOC_STREAMOFF\n");
1855 2386
1856 if ((struct usb_device *)NULL == peasycap->pusb_device) { 2387 if ((struct usb_device *)NULL == peasycap->pusb_device) {
1857 SAY("ERROR: peasycap->pusb_device is NULL\n"); 2388 SAM("ERROR: peasycap->pusb_device is NULL\n");
2389 mutex_unlock(&easycap_dongle[kd].mutex_video);
1858 return -EFAULT; 2390 return -EFAULT;
1859 } 2391 }
1860 2392
@@ -1866,7 +2398,7 @@ case VIDIOC_STREAMOFF: {
1866 * THE USERSPACE PROGRAM, E.G. mplayer, MAY HANG ON EXIT. BEWARE. 2398 * THE USERSPACE PROGRAM, E.G. mplayer, MAY HANG ON EXIT. BEWARE.
1867 */ 2399 */
1868/*---------------------------------------------------------------------------*/ 2400/*---------------------------------------------------------------------------*/
1869 JOT(8, "calling wake_up on wq_video and wq_audio\n"); 2401 JOM(8, "calling wake_up on wq_video and wq_audio\n");
1870 wake_up_interruptible(&(peasycap->wq_video)); 2402 wake_up_interruptible(&(peasycap->wq_video));
1871 wake_up_interruptible(&(peasycap->wq_audio)); 2403 wake_up_interruptible(&(peasycap->wq_audio));
1872/*---------------------------------------------------------------------------*/ 2404/*---------------------------------------------------------------------------*/
@@ -1874,111 +2406,200 @@ case VIDIOC_STREAMOFF: {
1874} 2406}
1875/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2407/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1876case VIDIOC_G_PARM: { 2408case VIDIOC_G_PARM: {
1877 static struct v4l2_streamparm v4l2_streamparm; 2409 struct v4l2_streamparm *pv4l2_streamparm;
1878 2410
1879 JOT(8, "VIDIOC_G_PARM\n"); 2411 JOM(8, "VIDIOC_G_PARM\n");
1880 2412 pv4l2_streamparm = kzalloc(sizeof(struct v4l2_streamparm), GFP_KERNEL);
1881 if (0 != copy_from_user(&v4l2_streamparm, (void __user *)arg, \ 2413 if (!pv4l2_streamparm) {
2414 SAM("ERROR: out of memory\n");
2415 mutex_unlock(&easycap_dongle[kd].mutex_video);
2416 return -ENOMEM;
2417 }
2418 if (0 != copy_from_user(pv4l2_streamparm, (void __user *)arg, \
1882 sizeof(struct v4l2_streamparm))) { 2419 sizeof(struct v4l2_streamparm))) {
1883 POUT; 2420 kfree(pv4l2_streamparm);
2421 mutex_unlock(&easycap_dongle[kd].mutex_video);
1884 return -EFAULT; 2422 return -EFAULT;
1885 } 2423 }
1886 2424
1887 if (v4l2_streamparm.type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { 2425 if (pv4l2_streamparm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1888 POUT; 2426 kfree(pv4l2_streamparm);
2427 mutex_unlock(&easycap_dongle[kd].mutex_video);
1889 return -EINVAL; 2428 return -EINVAL;
1890 } 2429 }
1891 v4l2_streamparm.parm.capture.capability = 0; 2430 pv4l2_streamparm->parm.capture.capability = 0;
1892 v4l2_streamparm.parm.capture.capturemode = 0; 2431 pv4l2_streamparm->parm.capture.capturemode = 0;
1893 v4l2_streamparm.parm.capture.timeperframe.numerator = 1; 2432 pv4l2_streamparm->parm.capture.timeperframe.numerator = 1;
1894 v4l2_streamparm.parm.capture.timeperframe.denominator = 30; 2433
1895 v4l2_streamparm.parm.capture.readbuffers = peasycap->frame_buffer_many; 2434 if (peasycap->fps) {
1896 v4l2_streamparm.parm.capture.extendedmode = 0; 2435 pv4l2_streamparm->parm.capture.timeperframe.\
1897 if (0 != copy_to_user((void __user *)arg, &v4l2_streamparm, \ 2436 denominator = peasycap->fps;
2437 } else {
2438 if (true == peasycap->ntsc) {
2439 pv4l2_streamparm->parm.capture.timeperframe.\
2440 denominator = 30;
2441 } else {
2442 pv4l2_streamparm->parm.capture.timeperframe.\
2443 denominator = 25;
2444 }
2445 }
2446
2447 pv4l2_streamparm->parm.capture.readbuffers = \
2448 peasycap->frame_buffer_many;
2449 pv4l2_streamparm->parm.capture.extendedmode = 0;
2450 if (0 != copy_to_user((void __user *)arg, pv4l2_streamparm, \
1898 sizeof(struct v4l2_streamparm))) { 2451 sizeof(struct v4l2_streamparm))) {
1899 POUT; 2452 kfree(pv4l2_streamparm);
2453 mutex_unlock(&easycap_dongle[kd].mutex_video);
1900 return -EFAULT; 2454 return -EFAULT;
1901 } 2455 }
2456 kfree(pv4l2_streamparm);
1902 break; 2457 break;
1903} 2458}
1904/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2459/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1905case VIDIOC_S_PARM: { 2460case VIDIOC_S_PARM: {
1906 JOT(8, "VIDIOC_S_PARM unsupported\n"); 2461 JOM(8, "VIDIOC_S_PARM unsupported\n");
2462 mutex_unlock(&easycap_dongle[kd].mutex_video);
1907 return -EINVAL; 2463 return -EINVAL;
1908} 2464}
1909/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2465/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1910case VIDIOC_G_AUDIO: { 2466case VIDIOC_G_AUDIO: {
1911 JOT(8, "VIDIOC_G_AUDIO unsupported\n"); 2467 JOM(8, "VIDIOC_G_AUDIO unsupported\n");
2468 mutex_unlock(&easycap_dongle[kd].mutex_video);
1912 return -EINVAL; 2469 return -EINVAL;
1913} 2470}
1914/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2471/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1915case VIDIOC_S_AUDIO: { 2472case VIDIOC_S_AUDIO: {
1916 JOT(8, "VIDIOC_S_AUDIO unsupported\n"); 2473 JOM(8, "VIDIOC_S_AUDIO unsupported\n");
2474 mutex_unlock(&easycap_dongle[kd].mutex_video);
1917 return -EINVAL; 2475 return -EINVAL;
1918} 2476}
1919/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2477/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1920case VIDIOC_S_TUNER: { 2478case VIDIOC_S_TUNER: {
1921 JOT(8, "VIDIOC_S_TUNER unsupported\n"); 2479 JOM(8, "VIDIOC_S_TUNER unsupported\n");
2480 mutex_unlock(&easycap_dongle[kd].mutex_video);
1922 return -EINVAL; 2481 return -EINVAL;
1923} 2482}
1924/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2483/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1925case VIDIOC_G_FBUF: 2484case VIDIOC_G_FBUF:
1926case VIDIOC_S_FBUF: 2485case VIDIOC_S_FBUF:
1927case VIDIOC_OVERLAY: { 2486case VIDIOC_OVERLAY: {
1928 JOT(8, "VIDIOC_G_FBUF|VIDIOC_S_FBUF|VIDIOC_OVERLAY unsupported\n"); 2487 JOM(8, "VIDIOC_G_FBUF|VIDIOC_S_FBUF|VIDIOC_OVERLAY unsupported\n");
2488 mutex_unlock(&easycap_dongle[kd].mutex_video);
1929 return -EINVAL; 2489 return -EINVAL;
1930} 2490}
1931/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2491/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1932case VIDIOC_G_TUNER: { 2492case VIDIOC_G_TUNER: {
1933 JOT(8, "VIDIOC_G_TUNER unsupported\n"); 2493 JOM(8, "VIDIOC_G_TUNER unsupported\n");
2494 mutex_unlock(&easycap_dongle[kd].mutex_video);
1934 return -EINVAL; 2495 return -EINVAL;
1935} 2496}
1936case VIDIOC_G_FREQUENCY: 2497case VIDIOC_G_FREQUENCY:
1937case VIDIOC_S_FREQUENCY: { 2498case VIDIOC_S_FREQUENCY: {
1938 JOT(8, "VIDIOC_G_FREQUENCY|VIDIOC_S_FREQUENCY unsupported\n"); 2499 JOM(8, "VIDIOC_G_FREQUENCY|VIDIOC_S_FREQUENCY unsupported\n");
2500 mutex_unlock(&easycap_dongle[kd].mutex_video);
1939 return -EINVAL; 2501 return -EINVAL;
1940} 2502}
1941/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2503/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1942default: { 2504default: {
1943 JOT(8, "ERROR: unrecognized V4L2 IOCTL command: 0x%08X\n", cmd); 2505 JOM(8, "ERROR: unrecognized V4L2 IOCTL command: 0x%08X\n", cmd);
1944 explain_ioctl(cmd); 2506 mutex_unlock(&easycap_dongle[kd].mutex_video);
1945 POUT;
1946 return -ENOIOCTLCMD; 2507 return -ENOIOCTLCMD;
1947} 2508}
1948} 2509}
2510mutex_unlock(&easycap_dongle[kd].mutex_video);
2511JOM(4, "unlocked easycap_dongle[%i].mutex_video\n", kd);
1949return 0; 2512return 0;
1950} 2513}
1951 2514/*****************************************************************************/
1952long easycap_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 2515/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
1953{ 2516#if ((defined(EASYCAP_IS_VIDEODEV_CLIENT)) || \
1954 struct inode *inode = file->f_dentry->d_inode; 2517 (defined(EASYCAP_NEEDS_UNLOCKED_IOCTL)))
1955 long ret; 2518long
1956 2519easysnd_ioctl_noinode(struct file *file, unsigned int cmd, unsigned long arg) {
1957 lock_kernel(); 2520 return (long)easysnd_ioctl((struct inode *)NULL, file, cmd, arg);
1958 ret = easycap_ioctl_bkl(inode, file, cmd, arg); 2521}
1959 unlock_kernel(); 2522#endif /*EASYCAP_IS_VIDEODEV_CLIENT||EASYCAP_NEEDS_UNLOCKED_IOCTL*/
1960 2523/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
1961 return ret; 2524/*---------------------------------------------------------------------------*/
1962} 2525int
1963 2526easysnd_ioctl(struct inode *inode, struct file *file,
1964/*--------------------------------------------------------------------------*/ 2527 unsigned int cmd, unsigned long arg)
1965static int easysnd_ioctl_bkl(struct inode *inode, struct file *file,
1966 unsigned int cmd, unsigned long arg)
1967{ 2528{
1968struct easycap *peasycap; 2529struct easycap *peasycap;
1969struct usb_device *p; 2530struct usb_device *p;
2531int kd;
1970 2532
2533if (NULL == file) {
2534 SAY("ERROR: file is NULL\n");
2535 return -ERESTARTSYS;
2536}
1971peasycap = file->private_data; 2537peasycap = file->private_data;
1972if (NULL == peasycap) { 2538if (NULL == peasycap) {
1973 SAY("ERROR: peasycap is NULL.\n"); 2539 SAY("ERROR: peasycap is NULL.\n");
1974 return -1; 2540 return -EFAULT;
2541}
2542if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
2543 SAY("ERROR: bad peasycap\n");
2544 return -EFAULT;
1975} 2545}
1976p = peasycap->pusb_device; 2546p = peasycap->pusb_device;
2547if (NULL == p) {
2548 SAM("ERROR: peasycap->pusb_device is NULL\n");
2549 return -EFAULT;
2550}
2551kd = isdongle(peasycap);
2552if (0 <= kd && DONGLE_MANY > kd) {
2553 if (mutex_lock_interruptible(&easycap_dongle[kd].mutex_audio)) {
2554 SAY("ERROR: cannot lock easycap_dongle[%i].mutex_audio\n", kd);
2555 return -ERESTARTSYS;
2556 }
2557 JOM(4, "locked easycap_dongle[%i].mutex_audio\n", kd);
2558/*---------------------------------------------------------------------------*/
2559/*
2560 * MEANWHILE, easycap_usb_disconnect() MAY HAVE FREED POINTER peasycap,
2561 * IN WHICH CASE A REPEAT CALL TO isdongle() WILL FAIL.
2562 * IF NECESSARY, BAIL OUT.
2563*/
2564/*---------------------------------------------------------------------------*/
2565 if (kd != isdongle(peasycap))
2566 return -ERESTARTSYS;
2567 if (NULL == file) {
2568 SAY("ERROR: file is NULL\n");
2569 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2570 return -ERESTARTSYS;
2571 }
2572 peasycap = file->private_data;
2573 if (NULL == peasycap) {
2574 SAY("ERROR: peasycap is NULL\n");
2575 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2576 return -ERESTARTSYS;
2577 }
2578 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
2579 SAY("ERROR: bad peasycap\n");
2580 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2581 return -EFAULT;
2582 }
2583 p = peasycap->pusb_device;
2584 if (NULL == peasycap->pusb_device) {
2585 SAM("ERROR: peasycap->pusb_device is NULL\n");
2586 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2587 return -ERESTARTSYS;
2588 }
2589} else {
2590/*---------------------------------------------------------------------------*/
2591/*
2592 * IF easycap_usb_disconnect() HAS ALREADY FREED POINTER peasycap BEFORE THE
2593 * ATTEMPT TO ACQUIRE THE SEMAPHORE, isdongle() WILL HAVE FAILED. BAIL OUT.
2594*/
2595/*---------------------------------------------------------------------------*/
2596 return -ERESTARTSYS;
2597}
1977/*---------------------------------------------------------------------------*/ 2598/*---------------------------------------------------------------------------*/
1978switch (cmd) { 2599switch (cmd) {
1979case SNDCTL_DSP_GETCAPS: { 2600case SNDCTL_DSP_GETCAPS: {
1980 int caps; 2601 int caps;
1981 JOT(8, "SNDCTL_DSP_GETCAPS\n"); 2602 JOM(8, "SNDCTL_DSP_GETCAPS\n");
1982 2603
1983#if defined(UPSAMPLE) 2604#if defined(UPSAMPLE)
1984 if (true == peasycap->microphone) 2605 if (true == peasycap->microphone)
@@ -1992,13 +2613,15 @@ case SNDCTL_DSP_GETCAPS: {
1992 caps = 0x04400000; 2613 caps = 0x04400000;
1993#endif /*UPSAMPLE*/ 2614#endif /*UPSAMPLE*/
1994 2615
1995 if (0 != copy_to_user((void __user *)arg, &caps, sizeof(int))) 2616 if (0 != copy_to_user((void __user *)arg, &caps, sizeof(int))) {
2617 mutex_unlock(&easycap_dongle[kd].mutex_audio);
1996 return -EFAULT; 2618 return -EFAULT;
2619 }
1997 break; 2620 break;
1998} 2621}
1999case SNDCTL_DSP_GETFMTS: { 2622case SNDCTL_DSP_GETFMTS: {
2000 int incoming; 2623 int incoming;
2001 JOT(8, "SNDCTL_DSP_GETFMTS\n"); 2624 JOM(8, "SNDCTL_DSP_GETFMTS\n");
2002 2625
2003#if defined(UPSAMPLE) 2626#if defined(UPSAMPLE)
2004 if (true == peasycap->microphone) 2627 if (true == peasycap->microphone)
@@ -2012,16 +2635,20 @@ case SNDCTL_DSP_GETFMTS: {
2012 incoming = AFMT_S16_LE; 2635 incoming = AFMT_S16_LE;
2013#endif /*UPSAMPLE*/ 2636#endif /*UPSAMPLE*/
2014 2637
2015 if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int))) 2638 if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int))) {
2639 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2016 return -EFAULT; 2640 return -EFAULT;
2641 }
2017 break; 2642 break;
2018} 2643}
2019case SNDCTL_DSP_SETFMT: { 2644case SNDCTL_DSP_SETFMT: {
2020 int incoming, outgoing; 2645 int incoming, outgoing;
2021 JOT(8, "SNDCTL_DSP_SETFMT\n"); 2646 JOM(8, "SNDCTL_DSP_SETFMT\n");
2022 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) 2647 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) {
2648 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2023 return -EFAULT; 2649 return -EFAULT;
2024 JOT(8, "........... %i=incoming\n", incoming); 2650 }
2651 JOM(8, "........... %i=incoming\n", incoming);
2025 2652
2026#if defined(UPSAMPLE) 2653#if defined(UPSAMPLE)
2027 if (true == peasycap->microphone) 2654 if (true == peasycap->microphone)
@@ -2036,22 +2663,27 @@ case SNDCTL_DSP_SETFMT: {
2036#endif /*UPSAMPLE*/ 2663#endif /*UPSAMPLE*/
2037 2664
2038 if (incoming != outgoing) { 2665 if (incoming != outgoing) {
2039 JOT(8, "........... %i=outgoing\n", outgoing); 2666 JOM(8, "........... %i=outgoing\n", outgoing);
2040 JOT(8, " cf. %i=AFMT_S16_LE\n", AFMT_S16_LE); 2667 JOM(8, " cf. %i=AFMT_S16_LE\n", AFMT_S16_LE);
2041 JOT(8, " cf. %i=AFMT_U8\n", AFMT_U8); 2668 JOM(8, " cf. %i=AFMT_U8\n", AFMT_U8);
2042 if (0 != copy_to_user((void __user *)arg, &outgoing, \ 2669 if (0 != copy_to_user((void __user *)arg, &outgoing, \
2043 sizeof(int))) 2670 sizeof(int))) {
2671 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2044 return -EFAULT; 2672 return -EFAULT;
2673 }
2674 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2045 return -EINVAL ; 2675 return -EINVAL ;
2046 } 2676 }
2047 break; 2677 break;
2048} 2678}
2049case SNDCTL_DSP_STEREO: { 2679case SNDCTL_DSP_STEREO: {
2050 int incoming; 2680 int incoming;
2051 JOT(8, "SNDCTL_DSP_STEREO\n"); 2681 JOM(8, "SNDCTL_DSP_STEREO\n");
2052 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) 2682 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) {
2683 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2053 return -EFAULT; 2684 return -EFAULT;
2054 JOT(8, "........... %i=incoming\n", incoming); 2685 }
2686 JOM(8, "........... %i=incoming\n", incoming);
2055 2687
2056#if defined(UPSAMPLE) 2688#if defined(UPSAMPLE)
2057 if (true == peasycap->microphone) 2689 if (true == peasycap->microphone)
@@ -2065,16 +2697,20 @@ case SNDCTL_DSP_STEREO: {
2065 incoming = 1; 2697 incoming = 1;
2066#endif /*UPSAMPLE*/ 2698#endif /*UPSAMPLE*/
2067 2699
2068 if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int))) 2700 if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int))) {
2701 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2069 return -EFAULT; 2702 return -EFAULT;
2703 }
2070 break; 2704 break;
2071} 2705}
2072case SNDCTL_DSP_SPEED: { 2706case SNDCTL_DSP_SPEED: {
2073 int incoming; 2707 int incoming;
2074 JOT(8, "SNDCTL_DSP_SPEED\n"); 2708 JOM(8, "SNDCTL_DSP_SPEED\n");
2075 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) 2709 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) {
2710 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2076 return -EFAULT; 2711 return -EFAULT;
2077 JOT(8, "........... %i=incoming\n", incoming); 2712 }
2713 JOM(8, "........... %i=incoming\n", incoming);
2078 2714
2079#if defined(UPSAMPLE) 2715#if defined(UPSAMPLE)
2080 if (true == peasycap->microphone) 2716 if (true == peasycap->microphone)
@@ -2088,29 +2724,37 @@ case SNDCTL_DSP_SPEED: {
2088 incoming = 48000; 2724 incoming = 48000;
2089#endif /*UPSAMPLE*/ 2725#endif /*UPSAMPLE*/
2090 2726
2091 if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int))) 2727 if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int))) {
2728 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2092 return -EFAULT; 2729 return -EFAULT;
2730 }
2093 break; 2731 break;
2094} 2732}
2095case SNDCTL_DSP_GETTRIGGER: { 2733case SNDCTL_DSP_GETTRIGGER: {
2096 int incoming; 2734 int incoming;
2097 JOT(8, "SNDCTL_DSP_GETTRIGGER\n"); 2735 JOM(8, "SNDCTL_DSP_GETTRIGGER\n");
2098 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) 2736 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) {
2737 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2099 return -EFAULT; 2738 return -EFAULT;
2100 JOT(8, "........... %i=incoming\n", incoming); 2739 }
2740 JOM(8, "........... %i=incoming\n", incoming);
2101 2741
2102 incoming = PCM_ENABLE_INPUT; 2742 incoming = PCM_ENABLE_INPUT;
2103 if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int))) 2743 if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int))) {
2744 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2104 return -EFAULT; 2745 return -EFAULT;
2746 }
2105 break; 2747 break;
2106} 2748}
2107case SNDCTL_DSP_SETTRIGGER: { 2749case SNDCTL_DSP_SETTRIGGER: {
2108 int incoming; 2750 int incoming;
2109 JOT(8, "SNDCTL_DSP_SETTRIGGER\n"); 2751 JOM(8, "SNDCTL_DSP_SETTRIGGER\n");
2110 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) 2752 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) {
2753 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2111 return -EFAULT; 2754 return -EFAULT;
2112 JOT(8, "........... %i=incoming\n", incoming); 2755 }
2113 JOT(8, "........... cf 0x%x=PCM_ENABLE_INPUT " \ 2756 JOM(8, "........... %i=incoming\n", incoming);
2757 JOM(8, "........... cf 0x%x=PCM_ENABLE_INPUT " \
2114 "0x%x=PCM_ENABLE_OUTPUT\n", \ 2758 "0x%x=PCM_ENABLE_OUTPUT\n", \
2115 PCM_ENABLE_INPUT, PCM_ENABLE_OUTPUT); 2759 PCM_ENABLE_INPUT, PCM_ENABLE_OUTPUT);
2116 ; 2760 ;
@@ -2121,19 +2765,23 @@ case SNDCTL_DSP_SETTRIGGER: {
2121} 2765}
2122case SNDCTL_DSP_GETBLKSIZE: { 2766case SNDCTL_DSP_GETBLKSIZE: {
2123 int incoming; 2767 int incoming;
2124 JOT(8, "SNDCTL_DSP_GETBLKSIZE\n"); 2768 JOM(8, "SNDCTL_DSP_GETBLKSIZE\n");
2125 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) 2769 if (0 != copy_from_user(&incoming, (void __user *)arg, sizeof(int))) {
2770 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2126 return -EFAULT; 2771 return -EFAULT;
2127 JOT(8, "........... %i=incoming\n", incoming); 2772 }
2773 JOM(8, "........... %i=incoming\n", incoming);
2128 incoming = peasycap->audio_bytes_per_fragment; 2774 incoming = peasycap->audio_bytes_per_fragment;
2129 if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int))) 2775 if (0 != copy_to_user((void __user *)arg, &incoming, sizeof(int))) {
2776 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2130 return -EFAULT; 2777 return -EFAULT;
2778 }
2131 break; 2779 break;
2132} 2780}
2133case SNDCTL_DSP_GETISPACE: { 2781case SNDCTL_DSP_GETISPACE: {
2134 struct audio_buf_info audio_buf_info; 2782 struct audio_buf_info audio_buf_info;
2135 2783
2136 JOT(8, "SNDCTL_DSP_GETISPACE\n"); 2784 JOM(8, "SNDCTL_DSP_GETISPACE\n");
2137 2785
2138 audio_buf_info.bytes = peasycap->audio_bytes_per_fragment; 2786 audio_buf_info.bytes = peasycap->audio_bytes_per_fragment;
2139 audio_buf_info.fragments = 1; 2787 audio_buf_info.fragments = 1;
@@ -2141,555 +2789,31 @@ case SNDCTL_DSP_GETISPACE: {
2141 audio_buf_info.fragstotal = 0; 2789 audio_buf_info.fragstotal = 0;
2142 2790
2143 if (0 != copy_to_user((void __user *)arg, &audio_buf_info, \ 2791 if (0 != copy_to_user((void __user *)arg, &audio_buf_info, \
2144 sizeof(int))) 2792 sizeof(int))) {
2793 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2145 return -EFAULT; 2794 return -EFAULT;
2795 }
2146 break; 2796 break;
2147} 2797}
2798case 0x00005401:
2799case 0x00005402:
2800case 0x00005403:
2801case 0x00005404:
2802case 0x00005405:
2803case 0x00005406: {
2804 JOM(8, "SNDCTL_TMR_...: 0x%08X unsupported\n", cmd);
2805 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2806 return -ENOIOCTLCMD;
2807}
2148default: { 2808default: {
2149 JOT(8, "ERROR: unrecognized DSP IOCTL command: 0x%08X\n", cmd); 2809 JOM(8, "ERROR: unrecognized DSP IOCTL command: 0x%08X\n", cmd);
2150 POUT; 2810 mutex_unlock(&easycap_dongle[kd].mutex_audio);
2151 return -ENOIOCTLCMD; 2811 return -ENOIOCTLCMD;
2152} 2812}
2153} 2813}
2814mutex_unlock(&easycap_dongle[kd].mutex_audio);
2154return 0; 2815return 0;
2155} 2816}
2817/*****************************************************************************/
2156 2818
2157long easysnd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2158{
2159 struct inode *inode = file->f_dentry->d_inode;
2160 long ret;
2161
2162 lock_kernel();
2163 ret = easysnd_ioctl_bkl(inode, file, cmd, arg);
2164 unlock_kernel();
2165
2166 return ret;
2167}
2168 2819
2169/*****************************************************************************/
2170int explain_ioctl(__u32 wot)
2171{
2172int k;
2173/*---------------------------------------------------------------------------*/
2174/*
2175 * THE DATA FOR THE ARRAY mess BELOW WERE CONSTRUCTED BY RUNNING THE FOLLOWING
2176 * SHELL SCRIPT:
2177 * #
2178 * cat /usr/src/linux-headers-`uname -r`/include/linux/videodev2.h | \
2179 * grep "^#define VIDIOC_" - | grep -v "_OLD" - | \
2180 * sed -e "s,_IO.*$,,;p" | sed -e "N;s,\n,, " | \
2181 * sed -e "s/^#define / {/;s/#define /, \"/;s/$/\"},/" | \
2182 * sed -e "s, ,,g;s, ,,g" >ioctl.tmp
2183 * echo "{0xFFFFFFFF,\"\"}" >>ioctl.tmp
2184 * exit 0
2185 * #
2186 * AND REINSTATING THE EXCISED "_OLD" CASES WERE LATER MANUALLY.
2187 *
2188 * THE DATA FOR THE ARRAY mess1 BELOW WERE CONSTRUCTED BY RUNNING THE FOLLOWING
2189 * SHELL SCRIPT:
2190 * cat /usr/src/linux-headers-`uname -r`/include/linux/videodev.h | \
2191 * grep "^#define VIDIOC" - | grep -v "_OLD" - | \
2192 * sed -e "s,_IO.*$,,;p" | sed -e "N;s,\n,, " | \
2193 * sed -e "s/^#define / {/;s/#define /, \"/;s/$/\"},/" | \
2194 * sed -e "s, ,,g;s, ,,g" >ioctl.tmp
2195 * echo "{0xFFFFFFFF,\"\"}" >>ioctl.tmp
2196 * exit 0
2197 * #
2198 */
2199/*---------------------------------------------------------------------------*/
2200static struct mess {
2201 __u32 command;
2202 char name[64];
2203} mess[] = {
2204#if defined(VIDIOC_QUERYCAP)
2205{VIDIOC_QUERYCAP, "VIDIOC_QUERYCAP"},
2206#endif
2207#if defined(VIDIOC_RESERVED)
2208{VIDIOC_RESERVED, "VIDIOC_RESERVED"},
2209#endif
2210#if defined(VIDIOC_ENUM_FMT)
2211{VIDIOC_ENUM_FMT, "VIDIOC_ENUM_FMT"},
2212#endif
2213#if defined(VIDIOC_G_FMT)
2214{VIDIOC_G_FMT, "VIDIOC_G_FMT"},
2215#endif
2216#if defined(VIDIOC_S_FMT)
2217{VIDIOC_S_FMT, "VIDIOC_S_FMT"},
2218#endif
2219#if defined(VIDIOC_REQBUFS)
2220{VIDIOC_REQBUFS, "VIDIOC_REQBUFS"},
2221#endif
2222#if defined(VIDIOC_QUERYBUF)
2223{VIDIOC_QUERYBUF, "VIDIOC_QUERYBUF"},
2224#endif
2225#if defined(VIDIOC_G_FBUF)
2226{VIDIOC_G_FBUF, "VIDIOC_G_FBUF"},
2227#endif
2228#if defined(VIDIOC_S_FBUF)
2229{VIDIOC_S_FBUF, "VIDIOC_S_FBUF"},
2230#endif
2231#if defined(VIDIOC_OVERLAY)
2232{VIDIOC_OVERLAY, "VIDIOC_OVERLAY"},
2233#endif
2234#if defined(VIDIOC_QBUF)
2235{VIDIOC_QBUF, "VIDIOC_QBUF"},
2236#endif
2237#if defined(VIDIOC_DQBUF)
2238{VIDIOC_DQBUF, "VIDIOC_DQBUF"},
2239#endif
2240#if defined(VIDIOC_STREAMON)
2241{VIDIOC_STREAMON, "VIDIOC_STREAMON"},
2242#endif
2243#if defined(VIDIOC_STREAMOFF)
2244{VIDIOC_STREAMOFF, "VIDIOC_STREAMOFF"},
2245#endif
2246#if defined(VIDIOC_G_PARM)
2247{VIDIOC_G_PARM, "VIDIOC_G_PARM"},
2248#endif
2249#if defined(VIDIOC_S_PARM)
2250{VIDIOC_S_PARM, "VIDIOC_S_PARM"},
2251#endif
2252#if defined(VIDIOC_G_STD)
2253{VIDIOC_G_STD, "VIDIOC_G_STD"},
2254#endif
2255#if defined(VIDIOC_S_STD)
2256{VIDIOC_S_STD, "VIDIOC_S_STD"},
2257#endif
2258#if defined(VIDIOC_ENUMSTD)
2259{VIDIOC_ENUMSTD, "VIDIOC_ENUMSTD"},
2260#endif
2261#if defined(VIDIOC_ENUMINPUT)
2262{VIDIOC_ENUMINPUT, "VIDIOC_ENUMINPUT"},
2263#endif
2264#if defined(VIDIOC_G_CTRL)
2265{VIDIOC_G_CTRL, "VIDIOC_G_CTRL"},
2266#endif
2267#if defined(VIDIOC_S_CTRL)
2268{VIDIOC_S_CTRL, "VIDIOC_S_CTRL"},
2269#endif
2270#if defined(VIDIOC_G_TUNER)
2271{VIDIOC_G_TUNER, "VIDIOC_G_TUNER"},
2272#endif
2273#if defined(VIDIOC_S_TUNER)
2274{VIDIOC_S_TUNER, "VIDIOC_S_TUNER"},
2275#endif
2276#if defined(VIDIOC_G_AUDIO)
2277{VIDIOC_G_AUDIO, "VIDIOC_G_AUDIO"},
2278#endif
2279#if defined(VIDIOC_S_AUDIO)
2280{VIDIOC_S_AUDIO, "VIDIOC_S_AUDIO"},
2281#endif
2282#if defined(VIDIOC_QUERYCTRL)
2283{VIDIOC_QUERYCTRL, "VIDIOC_QUERYCTRL"},
2284#endif
2285#if defined(VIDIOC_QUERYMENU)
2286{VIDIOC_QUERYMENU, "VIDIOC_QUERYMENU"},
2287#endif
2288#if defined(VIDIOC_G_INPUT)
2289{VIDIOC_G_INPUT, "VIDIOC_G_INPUT"},
2290#endif
2291#if defined(VIDIOC_S_INPUT)
2292{VIDIOC_S_INPUT, "VIDIOC_S_INPUT"},
2293#endif
2294#if defined(VIDIOC_G_OUTPUT)
2295{VIDIOC_G_OUTPUT, "VIDIOC_G_OUTPUT"},
2296#endif
2297#if defined(VIDIOC_S_OUTPUT)
2298{VIDIOC_S_OUTPUT, "VIDIOC_S_OUTPUT"},
2299#endif
2300#if defined(VIDIOC_ENUMOUTPUT)
2301{VIDIOC_ENUMOUTPUT, "VIDIOC_ENUMOUTPUT"},
2302#endif
2303#if defined(VIDIOC_G_AUDOUT)
2304{VIDIOC_G_AUDOUT, "VIDIOC_G_AUDOUT"},
2305#endif
2306#if defined(VIDIOC_S_AUDOUT)
2307{VIDIOC_S_AUDOUT, "VIDIOC_S_AUDOUT"},
2308#endif
2309#if defined(VIDIOC_G_MODULATOR)
2310{VIDIOC_G_MODULATOR, "VIDIOC_G_MODULATOR"},
2311#endif
2312#if defined(VIDIOC_S_MODULATOR)
2313{VIDIOC_S_MODULATOR, "VIDIOC_S_MODULATOR"},
2314#endif
2315#if defined(VIDIOC_G_FREQUENCY)
2316{VIDIOC_G_FREQUENCY, "VIDIOC_G_FREQUENCY"},
2317#endif
2318#if defined(VIDIOC_S_FREQUENCY)
2319{VIDIOC_S_FREQUENCY, "VIDIOC_S_FREQUENCY"},
2320#endif
2321#if defined(VIDIOC_CROPCAP)
2322{VIDIOC_CROPCAP, "VIDIOC_CROPCAP"},
2323#endif
2324#if defined(VIDIOC_G_CROP)
2325{VIDIOC_G_CROP, "VIDIOC_G_CROP"},
2326#endif
2327#if defined(VIDIOC_S_CROP)
2328{VIDIOC_S_CROP, "VIDIOC_S_CROP"},
2329#endif
2330#if defined(VIDIOC_G_JPEGCOMP)
2331{VIDIOC_G_JPEGCOMP, "VIDIOC_G_JPEGCOMP"},
2332#endif
2333#if defined(VIDIOC_S_JPEGCOMP)
2334{VIDIOC_S_JPEGCOMP, "VIDIOC_S_JPEGCOMP"},
2335#endif
2336#if defined(VIDIOC_QUERYSTD)
2337{VIDIOC_QUERYSTD, "VIDIOC_QUERYSTD"},
2338#endif
2339#if defined(VIDIOC_TRY_FMT)
2340{VIDIOC_TRY_FMT, "VIDIOC_TRY_FMT"},
2341#endif
2342#if defined(VIDIOC_ENUMAUDIO)
2343{VIDIOC_ENUMAUDIO, "VIDIOC_ENUMAUDIO"},
2344#endif
2345#if defined(VIDIOC_ENUMAUDOUT)
2346{VIDIOC_ENUMAUDOUT, "VIDIOC_ENUMAUDOUT"},
2347#endif
2348#if defined(VIDIOC_G_PRIORITY)
2349{VIDIOC_G_PRIORITY, "VIDIOC_G_PRIORITY"},
2350#endif
2351#if defined(VIDIOC_S_PRIORITY)
2352{VIDIOC_S_PRIORITY, "VIDIOC_S_PRIORITY"},
2353#endif
2354#if defined(VIDIOC_G_SLICED_VBI_CAP)
2355{VIDIOC_G_SLICED_VBI_CAP, "VIDIOC_G_SLICED_VBI_CAP"},
2356#endif
2357#if defined(VIDIOC_LOG_STATUS)
2358{VIDIOC_LOG_STATUS, "VIDIOC_LOG_STATUS"},
2359#endif
2360#if defined(VIDIOC_G_EXT_CTRLS)
2361{VIDIOC_G_EXT_CTRLS, "VIDIOC_G_EXT_CTRLS"},
2362#endif
2363#if defined(VIDIOC_S_EXT_CTRLS)
2364{VIDIOC_S_EXT_CTRLS, "VIDIOC_S_EXT_CTRLS"},
2365#endif
2366#if defined(VIDIOC_TRY_EXT_CTRLS)
2367{VIDIOC_TRY_EXT_CTRLS, "VIDIOC_TRY_EXT_CTRLS"},
2368#endif
2369#if defined(VIDIOC_ENUM_FRAMESIZES)
2370{VIDIOC_ENUM_FRAMESIZES, "VIDIOC_ENUM_FRAMESIZES"},
2371#endif
2372#if defined(VIDIOC_ENUM_FRAMEINTERVALS)
2373{VIDIOC_ENUM_FRAMEINTERVALS, "VIDIOC_ENUM_FRAMEINTERVALS"},
2374#endif
2375#if defined(VIDIOC_G_ENC_INDEX)
2376{VIDIOC_G_ENC_INDEX, "VIDIOC_G_ENC_INDEX"},
2377#endif
2378#if defined(VIDIOC_ENCODER_CMD)
2379{VIDIOC_ENCODER_CMD, "VIDIOC_ENCODER_CMD"},
2380#endif
2381#if defined(VIDIOC_TRY_ENCODER_CMD)
2382{VIDIOC_TRY_ENCODER_CMD, "VIDIOC_TRY_ENCODER_CMD"},
2383#endif
2384#if defined(VIDIOC_G_CHIP_IDENT)
2385{VIDIOC_G_CHIP_IDENT, "VIDIOC_G_CHIP_IDENT"},
2386#endif
2387
2388#if defined(VIDIOC_OVERLAY_OLD)
2389{VIDIOC_OVERLAY_OLD, "VIDIOC_OVERLAY_OLD"},
2390#endif
2391#if defined(VIDIOC_S_PARM_OLD)
2392{VIDIOC_S_PARM_OLD, "VIDIOC_S_PARM_OLD"},
2393#endif
2394#if defined(VIDIOC_S_CTRL_OLD)
2395{VIDIOC_S_CTRL_OLD, "VIDIOC_S_CTRL_OLD"},
2396#endif
2397#if defined(VIDIOC_G_AUDIO_OLD)
2398{VIDIOC_G_AUDIO_OLD, "VIDIOC_G_AUDIO_OLD"},
2399#endif
2400#if defined(VIDIOC_G_AUDOUT_OLD)
2401{VIDIOC_G_AUDOUT_OLD, "VIDIOC_G_AUDOUT_OLD"},
2402#endif
2403#if defined(VIDIOC_CROPCAP_OLD)
2404{VIDIOC_CROPCAP_OLD, "VIDIOC_CROPCAP_OLD"},
2405#endif
2406{0xFFFFFFFF, ""}
2407};
2408
2409static struct mess mess1[] = \
2410{
2411#if defined(VIDIOCGCAP)
2412{VIDIOCGCAP, "VIDIOCGCAP"},
2413#endif
2414#if defined(VIDIOCGCHAN)
2415{VIDIOCGCHAN, "VIDIOCGCHAN"},
2416#endif
2417#if defined(VIDIOCSCHAN)
2418{VIDIOCSCHAN, "VIDIOCSCHAN"},
2419#endif
2420#if defined(VIDIOCGTUNER)
2421{VIDIOCGTUNER, "VIDIOCGTUNER"},
2422#endif
2423#if defined(VIDIOCSTUNER)
2424{VIDIOCSTUNER, "VIDIOCSTUNER"},
2425#endif
2426#if defined(VIDIOCGPICT)
2427{VIDIOCGPICT, "VIDIOCGPICT"},
2428#endif
2429#if defined(VIDIOCSPICT)
2430{VIDIOCSPICT, "VIDIOCSPICT"},
2431#endif
2432#if defined(VIDIOCCAPTURE)
2433{VIDIOCCAPTURE, "VIDIOCCAPTURE"},
2434#endif
2435#if defined(VIDIOCGWIN)
2436{VIDIOCGWIN, "VIDIOCGWIN"},
2437#endif
2438#if defined(VIDIOCSWIN)
2439{VIDIOCSWIN, "VIDIOCSWIN"},
2440#endif
2441#if defined(VIDIOCGFBUF)
2442{VIDIOCGFBUF, "VIDIOCGFBUF"},
2443#endif
2444#if defined(VIDIOCSFBUF)
2445{VIDIOCSFBUF, "VIDIOCSFBUF"},
2446#endif
2447#if defined(VIDIOCKEY)
2448{VIDIOCKEY, "VIDIOCKEY"},
2449#endif
2450#if defined(VIDIOCGFREQ)
2451{VIDIOCGFREQ, "VIDIOCGFREQ"},
2452#endif
2453#if defined(VIDIOCSFREQ)
2454{VIDIOCSFREQ, "VIDIOCSFREQ"},
2455#endif
2456#if defined(VIDIOCGAUDIO)
2457{VIDIOCGAUDIO, "VIDIOCGAUDIO"},
2458#endif
2459#if defined(VIDIOCSAUDIO)
2460{VIDIOCSAUDIO, "VIDIOCSAUDIO"},
2461#endif
2462#if defined(VIDIOCSYNC)
2463{VIDIOCSYNC, "VIDIOCSYNC"},
2464#endif
2465#if defined(VIDIOCMCAPTURE)
2466{VIDIOCMCAPTURE, "VIDIOCMCAPTURE"},
2467#endif
2468#if defined(VIDIOCGMBUF)
2469{VIDIOCGMBUF, "VIDIOCGMBUF"},
2470#endif
2471#if defined(VIDIOCGUNIT)
2472{VIDIOCGUNIT, "VIDIOCGUNIT"},
2473#endif
2474#if defined(VIDIOCGCAPTURE)
2475{VIDIOCGCAPTURE, "VIDIOCGCAPTURE"},
2476#endif
2477#if defined(VIDIOCSCAPTURE)
2478{VIDIOCSCAPTURE, "VIDIOCSCAPTURE"},
2479#endif
2480#if defined(VIDIOCSPLAYMODE)
2481{VIDIOCSPLAYMODE, "VIDIOCSPLAYMODE"},
2482#endif
2483#if defined(VIDIOCSWRITEMODE)
2484{VIDIOCSWRITEMODE, "VIDIOCSWRITEMODE"},
2485#endif
2486#if defined(VIDIOCGPLAYINFO)
2487{VIDIOCGPLAYINFO, "VIDIOCGPLAYINFO"},
2488#endif
2489#if defined(VIDIOCSMICROCODE)
2490{VIDIOCSMICROCODE, "VIDIOCSMICROCODE"},
2491#endif
2492{0xFFFFFFFF, ""}
2493};
2494
2495k = 0;
2496while (mess[k].name[0]) {
2497 if (wot == mess[k].command) {
2498 JOT(8, "ioctl 0x%08X is %s\n", \
2499 mess[k].command, &mess[k].name[0]);
2500 return 0;
2501 }
2502 k++;
2503}
2504JOT(8, "ioctl 0x%08X is not in videodev2.h\n", wot);
2505
2506k = 0;
2507while (mess1[k].name[0]) {
2508 if (wot == mess1[k].command) {
2509 JOT(8, "ioctl 0x%08X is %s (V4L1)\n", \
2510 mess1[k].command, &mess1[k].name[0]);
2511 return 0;
2512 }
2513 k++;
2514}
2515JOT(8, "ioctl 0x%08X is not in videodev.h\n", wot);
2516return -1;
2517}
2518/*****************************************************************************/
2519int explain_cid(__u32 wot)
2520{
2521int k;
2522/*---------------------------------------------------------------------------*/
2523/*
2524 * THE DATA FOR THE ARRAY mess BELOW WERE CONSTRUCTED BY RUNNING THE FOLLOWING
2525 * SHELL SCRIPT:
2526 * #
2527 * cat /usr/src/linux-headers-`uname -r`/include/linux/videodev2.h | \
2528 * grep "^#define V4L2_CID_" | \
2529 * sed -e "s,(.*$,,;p" | sed -e "N;s,\n,, " | \
2530 * sed -e "s/^#define / {/;s/#define /, \"/;s/$/\"},/" | \
2531 * sed -e "s, ,,g;s, ,,g" | grep -v "_BASE" | grep -v "MPEG" >cid.tmp
2532 * echo "{0xFFFFFFFF,\"\"}" >>cid.tmp
2533 * exit 0
2534 * #
2535 */
2536/*---------------------------------------------------------------------------*/
2537static struct mess
2538{
2539__u32 command;
2540char name[64];
2541} mess[] = {
2542#if defined(V4L2_CID_USER_CLASS)
2543{V4L2_CID_USER_CLASS, "V4L2_CID_USER_CLASS"},
2544#endif
2545#if defined(V4L2_CID_BRIGHTNESS)
2546{V4L2_CID_BRIGHTNESS, "V4L2_CID_BRIGHTNESS"},
2547#endif
2548#if defined(V4L2_CID_CONTRAST)
2549{V4L2_CID_CONTRAST, "V4L2_CID_CONTRAST"},
2550#endif
2551#if defined(V4L2_CID_SATURATION)
2552{V4L2_CID_SATURATION, "V4L2_CID_SATURATION"},
2553#endif
2554#if defined(V4L2_CID_HUE)
2555{V4L2_CID_HUE, "V4L2_CID_HUE"},
2556#endif
2557#if defined(V4L2_CID_AUDIO_VOLUME)
2558{V4L2_CID_AUDIO_VOLUME, "V4L2_CID_AUDIO_VOLUME"},
2559#endif
2560#if defined(V4L2_CID_AUDIO_BALANCE)
2561{V4L2_CID_AUDIO_BALANCE, "V4L2_CID_AUDIO_BALANCE"},
2562#endif
2563#if defined(V4L2_CID_AUDIO_BASS)
2564{V4L2_CID_AUDIO_BASS, "V4L2_CID_AUDIO_BASS"},
2565#endif
2566#if defined(V4L2_CID_AUDIO_TREBLE)
2567{V4L2_CID_AUDIO_TREBLE, "V4L2_CID_AUDIO_TREBLE"},
2568#endif
2569#if defined(V4L2_CID_AUDIO_MUTE)
2570{V4L2_CID_AUDIO_MUTE, "V4L2_CID_AUDIO_MUTE"},
2571#endif
2572#if defined(V4L2_CID_AUDIO_LOUDNESS)
2573{V4L2_CID_AUDIO_LOUDNESS, "V4L2_CID_AUDIO_LOUDNESS"},
2574#endif
2575#if defined(V4L2_CID_BLACK_LEVEL)
2576{V4L2_CID_BLACK_LEVEL, "V4L2_CID_BLACK_LEVEL"},
2577#endif
2578#if defined(V4L2_CID_AUTO_WHITE_BALANCE)
2579{V4L2_CID_AUTO_WHITE_BALANCE, "V4L2_CID_AUTO_WHITE_BALANCE"},
2580#endif
2581#if defined(V4L2_CID_DO_WHITE_BALANCE)
2582{V4L2_CID_DO_WHITE_BALANCE, "V4L2_CID_DO_WHITE_BALANCE"},
2583#endif
2584#if defined(V4L2_CID_RED_BALANCE)
2585{V4L2_CID_RED_BALANCE, "V4L2_CID_RED_BALANCE"},
2586#endif
2587#if defined(V4L2_CID_BLUE_BALANCE)
2588{V4L2_CID_BLUE_BALANCE, "V4L2_CID_BLUE_BALANCE"},
2589#endif
2590#if defined(V4L2_CID_GAMMA)
2591{V4L2_CID_GAMMA, "V4L2_CID_GAMMA"},
2592#endif
2593#if defined(V4L2_CID_WHITENESS)
2594{V4L2_CID_WHITENESS, "V4L2_CID_WHITENESS"},
2595#endif
2596#if defined(V4L2_CID_EXPOSURE)
2597{V4L2_CID_EXPOSURE, "V4L2_CID_EXPOSURE"},
2598#endif
2599#if defined(V4L2_CID_AUTOGAIN)
2600{V4L2_CID_AUTOGAIN, "V4L2_CID_AUTOGAIN"},
2601#endif
2602#if defined(V4L2_CID_GAIN)
2603{V4L2_CID_GAIN, "V4L2_CID_GAIN"},
2604#endif
2605#if defined(V4L2_CID_HFLIP)
2606{V4L2_CID_HFLIP, "V4L2_CID_HFLIP"},
2607#endif
2608#if defined(V4L2_CID_VFLIP)
2609{V4L2_CID_VFLIP, "V4L2_CID_VFLIP"},
2610#endif
2611#if defined(V4L2_CID_HCENTER)
2612{V4L2_CID_HCENTER, "V4L2_CID_HCENTER"},
2613#endif
2614#if defined(V4L2_CID_VCENTER)
2615{V4L2_CID_VCENTER, "V4L2_CID_VCENTER"},
2616#endif
2617#if defined(V4L2_CID_POWER_LINE_FREQUENCY)
2618{V4L2_CID_POWER_LINE_FREQUENCY, "V4L2_CID_POWER_LINE_FREQUENCY"},
2619#endif
2620#if defined(V4L2_CID_HUE_AUTO)
2621{V4L2_CID_HUE_AUTO, "V4L2_CID_HUE_AUTO"},
2622#endif
2623#if defined(V4L2_CID_WHITE_BALANCE_TEMPERATURE)
2624{V4L2_CID_WHITE_BALANCE_TEMPERATURE, "V4L2_CID_WHITE_BALANCE_TEMPERATURE"},
2625#endif
2626#if defined(V4L2_CID_SHARPNESS)
2627{V4L2_CID_SHARPNESS, "V4L2_CID_SHARPNESS"},
2628#endif
2629#if defined(V4L2_CID_BACKLIGHT_COMPENSATION)
2630{V4L2_CID_BACKLIGHT_COMPENSATION, "V4L2_CID_BACKLIGHT_COMPENSATION"},
2631#endif
2632#if defined(V4L2_CID_CHROMA_AGC)
2633{V4L2_CID_CHROMA_AGC, "V4L2_CID_CHROMA_AGC"},
2634#endif
2635#if defined(V4L2_CID_COLOR_KILLER)
2636{V4L2_CID_COLOR_KILLER, "V4L2_CID_COLOR_KILLER"},
2637#endif
2638#if defined(V4L2_CID_LASTP1)
2639{V4L2_CID_LASTP1, "V4L2_CID_LASTP1"},
2640#endif
2641#if defined(V4L2_CID_CAMERA_CLASS)
2642{V4L2_CID_CAMERA_CLASS, "V4L2_CID_CAMERA_CLASS"},
2643#endif
2644#if defined(V4L2_CID_EXPOSURE_AUTO)
2645{V4L2_CID_EXPOSURE_AUTO, "V4L2_CID_EXPOSURE_AUTO"},
2646#endif
2647#if defined(V4L2_CID_EXPOSURE_ABSOLUTE)
2648{V4L2_CID_EXPOSURE_ABSOLUTE, "V4L2_CID_EXPOSURE_ABSOLUTE"},
2649#endif
2650#if defined(V4L2_CID_EXPOSURE_AUTO_PRIORITY)
2651{V4L2_CID_EXPOSURE_AUTO_PRIORITY, "V4L2_CID_EXPOSURE_AUTO_PRIORITY"},
2652#endif
2653#if defined(V4L2_CID_PAN_RELATIVE)
2654{V4L2_CID_PAN_RELATIVE, "V4L2_CID_PAN_RELATIVE"},
2655#endif
2656#if defined(V4L2_CID_TILT_RELATIVE)
2657{V4L2_CID_TILT_RELATIVE, "V4L2_CID_TILT_RELATIVE"},
2658#endif
2659#if defined(V4L2_CID_PAN_RESET)
2660{V4L2_CID_PAN_RESET, "V4L2_CID_PAN_RESET"},
2661#endif
2662#if defined(V4L2_CID_TILT_RESET)
2663{V4L2_CID_TILT_RESET, "V4L2_CID_TILT_RESET"},
2664#endif
2665#if defined(V4L2_CID_PAN_ABSOLUTE)
2666{V4L2_CID_PAN_ABSOLUTE, "V4L2_CID_PAN_ABSOLUTE"},
2667#endif
2668#if defined(V4L2_CID_TILT_ABSOLUTE)
2669{V4L2_CID_TILT_ABSOLUTE, "V4L2_CID_TILT_ABSOLUTE"},
2670#endif
2671#if defined(V4L2_CID_FOCUS_ABSOLUTE)
2672{V4L2_CID_FOCUS_ABSOLUTE, "V4L2_CID_FOCUS_ABSOLUTE"},
2673#endif
2674#if defined(V4L2_CID_FOCUS_RELATIVE)
2675{V4L2_CID_FOCUS_RELATIVE, "V4L2_CID_FOCUS_RELATIVE"},
2676#endif
2677#if defined(V4L2_CID_FOCUS_AUTO)
2678{V4L2_CID_FOCUS_AUTO, "V4L2_CID_FOCUS_AUTO"},
2679#endif
2680{0xFFFFFFFF, ""}
2681};
2682
2683k = 0;
2684while (mess[k].name[0]) {
2685 if (wot == mess[k].command) {
2686 JOT(8, "ioctl 0x%08X is %s\n", \
2687 mess[k].command, &mess[k].name[0]);
2688 return 0;
2689 }
2690 k++;
2691}
2692JOT(8, "cid 0x%08X is not in videodev2.h\n", wot);
2693return -1;
2694}
2695/*****************************************************************************/
diff --git a/drivers/staging/easycap/easycap_low.c b/drivers/staging/easycap/easycap_low.c
index ad1fc4cc471a..28c4d1e3c02f 100644
--- a/drivers/staging/easycap/easycap_low.c
+++ b/drivers/staging/easycap/easycap_low.c
@@ -38,148 +38,209 @@
38*/ 38*/
39/****************************************************************************/ 39/****************************************************************************/
40 40
41#include "easycap_debug.h"
42#include "easycap.h" 41#include "easycap.h"
42#include "easycap_debug.h"
43 43
44/*--------------------------------------------------------------------------*/ 44/*--------------------------------------------------------------------------*/
45const struct stk1160config { int reg; int set; } stk1160config[256] = { 45const struct stk1160config { int reg; int set; } stk1160configPAL[256] = {
46 {0x000, 0x0098}, 46 {0x000, 0x0098},
47 {0x002, 0x0093}, 47 {0x002, 0x0093},
48 48
49 {0x001, 0x0003}, 49 {0x001, 0x0003},
50 {0x003, 0x0080}, 50 {0x003, 0x0080},
51 {0x00D, 0x0000}, 51 {0x00D, 0x0000},
52 {0x00F, 0x0002}, 52 {0x00F, 0x0002},
53 {0x018, 0x0010}, 53 {0x018, 0x0010},
54 {0x019, 0x0000}, 54 {0x019, 0x0000},
55 {0x01A, 0x0014}, 55 {0x01A, 0x0014},
56 {0x01B, 0x000E}, 56 {0x01B, 0x000E},
57 {0x01C, 0x0046}, 57 {0x01C, 0x0046},
58 58
59 {0x100, 0x0033}, 59 {0x100, 0x0033},
60 {0x103, 0x0000}, 60 {0x103, 0x0000},
61 {0x104, 0x0000}, 61 {0x104, 0x0000},
62 {0x105, 0x0000}, 62 {0x105, 0x0000},
63 {0x106, 0x0000}, 63 {0x106, 0x0000},
64 64
65#if defined(PREFER_NTSC) 65/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
66 66/*
67#undef OLDMARGIN 67 * RESOLUTION 640x480
68#if defined(OLDMARGIN) 68*/
69 {0x110, 0x0008}, 69/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
70#else 70 {0x110, 0x0008},
71 {0x110, 0x0014}, 71 {0x111, 0x0000},
72#endif /*OLDMARGIN*/ 72 {0x112, 0x0020},
73 73 {0x113, 0x0000},
74 {0x111, 0x0000}, 74 {0x114, 0x0508},
75 {0x112, 0x0003}, 75 {0x115, 0x0005},
76 {0x113, 0x0000}, 76 {0x116, 0x0110},
77 77 {0x117, 0x0001},
78#if defined(OLDMARGIN) 78/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
79 {0x114, 0x0508}, 79
80#else 80 {0x202, 0x000F},
81 {0x114, 0x0514}, 81 {0x203, 0x004A},
82#endif /*OLDMARGIN*/ 82 {0x2FF, 0x0000},
83 83
84 {0x115, 0x0005}, 84 {0xFFF, 0xFFFF}
85 {0x116, 0x00F3}, 85};
86 {0x117, 0x0000},
87
88#else /* ! PREFER_NTSC*/
89
90#if defined(OLDMARGIN)
91 {0x110, 0x0008},
92#else
93 {0x110, 0x0014},
94#endif /*OLDMARGIN*/
95
96 {0x111, 0x0000},
97 {0x112, 0x0020},
98 {0x113, 0x0000},
99
100#if defined(OLDMARGIN)
101 {0x114, 0x0508},
102#else
103 {0x114, 0x0514},
104#endif /*OLDMARGIN*/
105
106 {0x115, 0x0005},
107 {0x116, 0x0110},
108 {0x117, 0x0001},
109
110#endif /* ! PREFER_NTSC*/
111
112 {0x202, 0x000F},
113 {0x203, 0x004A},
114 {0x2FF, 0x0000},
115/*---------------------------------------------------------------------------*/
116 {0xFFF, 0xFFFF}
117 };
118/*--------------------------------------------------------------------------*/ 86/*--------------------------------------------------------------------------*/
119const struct saa7113config { int reg; int set; } saa7113config[256] = { 87const struct stk1160config stk1160configNTSC[256] = {
120 {0x01, 0x08}, 88 {0x000, 0x0098},
121 {0x02, 0x80}, 89 {0x002, 0x0093},
122 {0x03, 0x33}, 90
123 {0x04, 0x00}, 91 {0x001, 0x0003},
124 {0x05, 0x00}, 92 {0x003, 0x0080},
125 {0x06, 0xE9}, 93 {0x00D, 0x0000},
126 {0x07, 0x0D}, 94 {0x00F, 0x0002},
127#if defined(PREFER_NTSC) 95 {0x018, 0x0010},
128 {0x08, 0x78}, 96 {0x019, 0x0000},
129#else 97 {0x01A, 0x0014},
130 {0x08, 0x38}, 98 {0x01B, 0x000E},
131#endif /* ! PREFER_NTSC*/ 99 {0x01C, 0x0046},
132 {0x09, 0x00}, 100
133 {0x0A, SAA_0A_DEFAULT}, 101 {0x100, 0x0033},
134 {0x0B, SAA_0B_DEFAULT}, 102 {0x103, 0x0000},
135 {0x0C, SAA_0C_DEFAULT}, 103 {0x104, 0x0000},
136 {0x0D, SAA_0D_DEFAULT}, 104 {0x105, 0x0000},
137 {0x0E, 0x01}, 105 {0x106, 0x0000},
138 {0x0F, 0x36}, 106
139 {0x10, 0x00}, 107/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
140 {0x11, 0x0C}, 108/*
141 {0x12, 0xE7}, 109 * RESOLUTION 640x480
142 {0x13, 0x00}, 110*/
143 {0x15, 0x00}, 111/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
144 {0x16, 0x00}, 112 {0x110, 0x0008},
145#if defined(PREFER_NTSC) 113 {0x111, 0x0000},
146 {0x40, 0x82}, 114 {0x112, 0x0003},
115 {0x113, 0x0000},
116 {0x114, 0x0508},
117 {0x115, 0x0005},
118 {0x116, 0x00F3},
119 {0x117, 0x0000},
120/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
121
122 {0x202, 0x000F},
123 {0x203, 0x004A},
124 {0x2FF, 0x0000},
125
126 {0xFFF, 0xFFFF}
127};
128/*--------------------------------------------------------------------------*/
129const struct saa7113config { int reg; int set; } saa7113configPAL[256] = {
130 {0x01, 0x08},
131#if defined(ANTIALIAS)
132 {0x02, 0xC0},
147#else 133#else
148 {0x40, 0x02}, 134 {0x02, 0x80},
149#endif /* ! PREFER_NTSC*/ 135#endif /*ANTIALIAS*/
150 {0x41, 0xFF}, 136 {0x03, 0x33},
151 {0x42, 0xFF}, 137 {0x04, 0x00},
152 {0x43, 0xFF}, 138 {0x05, 0x00},
153 {0x44, 0xFF}, 139 {0x06, 0xE9},
154 {0x45, 0xFF}, 140 {0x07, 0x0D},
155 {0x46, 0xFF}, 141 {0x08, 0x38},
156 {0x47, 0xFF}, 142 {0x09, 0x00},
157 {0x48, 0xFF}, 143 {0x0A, SAA_0A_DEFAULT},
158 {0x49, 0xFF}, 144 {0x0B, SAA_0B_DEFAULT},
159 {0x4A, 0xFF}, 145 {0x0C, SAA_0C_DEFAULT},
160 {0x4B, 0xFF}, 146 {0x0D, SAA_0D_DEFAULT},
161 {0x4C, 0xFF}, 147 {0x0E, 0x01},
162 {0x4D, 0xFF}, 148 {0x0F, 0x36},
163 {0x4E, 0xFF}, 149 {0x10, 0x00},
164 {0x4F, 0xFF}, 150 {0x11, 0x0C},
165 {0x50, 0xFF}, 151 {0x12, 0xE7},
166 {0x51, 0xFF}, 152 {0x13, 0x00},
167 {0x52, 0xFF}, 153 {0x15, 0x00},
168 {0x53, 0xFF}, 154 {0x16, 0x00},
169 {0x54, 0xFF}, 155 {0x40, 0x02},
170 {0x55, 0xFF}, 156 {0x41, 0xFF},
171 {0x56, 0xFF}, 157 {0x42, 0xFF},
172 {0x57, 0xFF}, 158 {0x43, 0xFF},
173 {0x58, 0x40}, 159 {0x44, 0xFF},
174 {0x59, 0x54}, 160 {0x45, 0xFF},
175#if defined(PREFER_NTSC) 161 {0x46, 0xFF},
176 {0x5A, 0x0A}, 162 {0x47, 0xFF},
163 {0x48, 0xFF},
164 {0x49, 0xFF},
165 {0x4A, 0xFF},
166 {0x4B, 0xFF},
167 {0x4C, 0xFF},
168 {0x4D, 0xFF},
169 {0x4E, 0xFF},
170 {0x4F, 0xFF},
171 {0x50, 0xFF},
172 {0x51, 0xFF},
173 {0x52, 0xFF},
174 {0x53, 0xFF},
175 {0x54, 0xFF},
176 {0x55, 0xFF},
177 {0x56, 0xFF},
178 {0x57, 0xFF},
179 {0x58, 0x40},
180 {0x59, 0x54},
181 {0x5A, 0x07},
182 {0x5B, 0x83},
183
184 {0xFF, 0xFF}
185};
186/*--------------------------------------------------------------------------*/
187const struct saa7113config saa7113configNTSC[256] = {
188 {0x01, 0x08},
189#if defined(ANTIALIAS)
190 {0x02, 0xC0},
177#else 191#else
178 {0x5A, 0x07}, 192 {0x02, 0x80},
179#endif /* ! PREFER_NTSC*/ 193#endif /*ANTIALIAS*/
180 {0x5B, 0x83}, 194 {0x03, 0x33},
181 {0xFF, 0xFF} 195 {0x04, 0x00},
182 }; 196 {0x05, 0x00},
197 {0x06, 0xE9},
198 {0x07, 0x0D},
199 {0x08, 0x78},
200 {0x09, 0x00},
201 {0x0A, SAA_0A_DEFAULT},
202 {0x0B, SAA_0B_DEFAULT},
203 {0x0C, SAA_0C_DEFAULT},
204 {0x0D, SAA_0D_DEFAULT},
205 {0x0E, 0x01},
206 {0x0F, 0x36},
207 {0x10, 0x00},
208 {0x11, 0x0C},
209 {0x12, 0xE7},
210 {0x13, 0x00},
211 {0x15, 0x00},
212 {0x16, 0x00},
213 {0x40, 0x82},
214 {0x41, 0xFF},
215 {0x42, 0xFF},
216 {0x43, 0xFF},
217 {0x44, 0xFF},
218 {0x45, 0xFF},
219 {0x46, 0xFF},
220 {0x47, 0xFF},
221 {0x48, 0xFF},
222 {0x49, 0xFF},
223 {0x4A, 0xFF},
224 {0x4B, 0xFF},
225 {0x4C, 0xFF},
226 {0x4D, 0xFF},
227 {0x4E, 0xFF},
228 {0x4F, 0xFF},
229 {0x50, 0xFF},
230 {0x51, 0xFF},
231 {0x52, 0xFF},
232 {0x53, 0xFF},
233 {0x54, 0xFF},
234 {0x55, 0xFF},
235 {0x56, 0xFF},
236 {0x57, 0xFF},
237 {0x58, 0x40},
238 {0x59, 0x54},
239 {0x5A, 0x0A},
240 {0x5B, 0x83},
241
242 {0xFF, 0xFF}
243};
183/*--------------------------------------------------------------------------*/ 244/*--------------------------------------------------------------------------*/
184 245
185/****************************************************************************/ 246/****************************************************************************/
@@ -187,6 +248,9 @@ int
187confirm_resolution(struct usb_device *p) 248confirm_resolution(struct usb_device *p)
188{ 249{
189__u8 get0, get1, get2, get3, get4, get5, get6, get7; 250__u8 get0, get1, get2, get3, get4, get5, get6, get7;
251
252if (NULL == p)
253 return -ENODEV;
190GET(p, 0x0110, &get0); 254GET(p, 0x0110, &get0);
191GET(p, 0x0111, &get1); 255GET(p, 0x0111, &get1);
192GET(p, 0x0112, &get2); 256GET(p, 0x0112, &get2);
@@ -227,6 +291,8 @@ confirm_stream(struct usb_device *p)
227__u16 get2; 291__u16 get2;
228__u8 igot; 292__u8 igot;
229 293
294if (NULL == p)
295 return -ENODEV;
230GET(p, 0x0100, &igot); get2 = 0x80 & igot; 296GET(p, 0x0100, &igot); get2 = 0x80 & igot;
231if (0x80 == get2) 297if (0x80 == get2)
232 JOT(8, "confirm_stream: OK\n"); 298 JOT(8, "confirm_stream: OK\n");
@@ -236,15 +302,24 @@ return 0;
236} 302}
237/****************************************************************************/ 303/****************************************************************************/
238int 304int
239setup_stk(struct usb_device *p) 305setup_stk(struct usb_device *p, bool ntsc)
240{ 306{
241int i0; 307int i0;
242 308
309if (NULL == p)
310 return -ENODEV;
243i0 = 0; 311i0 = 0;
244while (0xFFF != stk1160config[i0].reg) { 312if (true == ntsc) {
245 SET(p, stk1160config[i0].reg, stk1160config[i0].set); 313 while (0xFFF != stk1160configNTSC[i0].reg) {
246 i0++; 314 SET(p, stk1160configNTSC[i0].reg, stk1160configNTSC[i0].set);
315 i0++;
316 }
317} else {
318 while (0xFFF != stk1160configPAL[i0].reg) {
319 SET(p, stk1160configPAL[i0].reg, stk1160configPAL[i0].set);
320 i0++;
247 } 321 }
322}
248 323
249write_300(p); 324write_300(p);
250 325
@@ -252,19 +327,26 @@ return 0;
252} 327}
253/****************************************************************************/ 328/****************************************************************************/
254int 329int
255setup_saa(struct usb_device *p) 330setup_saa(struct usb_device *p, bool ntsc)
256{ 331{
257int i0, ir; 332int i0, ir;
258 333
259 334if (NULL == p)
260set2to78(p); 335 return -ENODEV;
261
262
263i0 = 0; 336i0 = 0;
264while (0xFF != saa7113config[i0].reg) { 337if (true == ntsc) {
265 ir = write_saa(p, saa7113config[i0].reg, saa7113config[i0].set); 338 while (0xFF != saa7113configNTSC[i0].reg) {
266 i0++; 339 ir = write_saa(p, saa7113configNTSC[i0].reg, \
340 saa7113configNTSC[i0].set);
341 i0++;
267 } 342 }
343} else {
344 while (0xFF != saa7113configPAL[i0].reg) {
345 ir = write_saa(p, saa7113configPAL[i0].reg, \
346 saa7113configPAL[i0].set);
347 i0++;
348 }
349}
268return 0; 350return 0;
269} 351}
270/****************************************************************************/ 352/****************************************************************************/
@@ -273,6 +355,8 @@ write_000(struct usb_device *p, __u16 set2, __u16 set0)
273{ 355{
274__u8 igot0, igot2; 356__u8 igot0, igot2;
275 357
358if (NULL == p)
359 return -ENODEV;
276GET(p, 0x0002, &igot2); 360GET(p, 0x0002, &igot2);
277GET(p, 0x0000, &igot0); 361GET(p, 0x0000, &igot0);
278SET(p, 0x0002, set2); 362SET(p, 0x0002, set2);
@@ -283,6 +367,8 @@ return 0;
283int 367int
284write_saa(struct usb_device *p, __u16 reg0, __u16 set0) 368write_saa(struct usb_device *p, __u16 reg0, __u16 set0)
285{ 369{
370if (NULL == p)
371 return -ENODEV;
286SET(p, 0x200, 0x00); 372SET(p, 0x200, 0x00);
287SET(p, 0x204, reg0); 373SET(p, 0x204, reg0);
288SET(p, 0x205, set0); 374SET(p, 0x205, set0);
@@ -306,6 +392,8 @@ __u8 igot;
306__u16 got502, got503; 392__u16 got502, got503;
307__u16 set502, set503; 393__u16 set502, set503;
308 394
395if (NULL == p)
396 return -ENODEV;
309SET(p, 0x0504, reg0); 397SET(p, 0x0504, reg0);
310SET(p, 0x0500, 0x008B); 398SET(p, 0x0500, 0x008B);
311 399
@@ -341,6 +429,8 @@ read_vt(struct usb_device *p, __u16 reg0)
341__u8 igot; 429__u8 igot;
342__u16 got502, got503; 430__u16 got502, got503;
343 431
432if (NULL == p)
433 return -ENODEV;
344SET(p, 0x0504, reg0); 434SET(p, 0x0504, reg0);
345SET(p, 0x0500, 0x008B); 435SET(p, 0x0500, 0x008B);
346 436
@@ -360,6 +450,8 @@ return (got503 << 8) | got502;
360int 450int
361write_300(struct usb_device *p) 451write_300(struct usb_device *p)
362{ 452{
453if (NULL == p)
454 return -ENODEV;
363SET(p, 0x300, 0x0012); 455SET(p, 0x300, 0x0012);
364SET(p, 0x350, 0x002D); 456SET(p, 0x350, 0x002D);
365SET(p, 0x351, 0x0001); 457SET(p, 0x351, 0x0001);
@@ -376,24 +468,48 @@ return 0;
376 */ 468 */
377/*--------------------------------------------------------------------------*/ 469/*--------------------------------------------------------------------------*/
378int 470int
379check_saa(struct usb_device *p) 471check_saa(struct usb_device *p, bool ntsc)
380{ 472{
381int i0, ir, rc; 473int i0, ir, rc;
382i0 = 0;
383 474
475if (NULL == p)
476 return -ENODEV;
477i0 = 0;
384rc = 0; 478rc = 0;
385while (0xFF != saa7113config[i0].reg) { 479if (true == ntsc) {
386 if (0x0F == saa7113config[i0].reg) { 480 while (0xFF != saa7113configNTSC[i0].reg) {
387 i0++; continue; 481 if (0x0F == saa7113configNTSC[i0].reg) {
482 i0++;
483 continue;
484 }
485
486 ir = read_saa(p, saa7113configNTSC[i0].reg);
487 if (ir != saa7113configNTSC[i0].set) {
488 SAY("SAA register 0x%02X has 0x%02X, " \
489 "expected 0x%02X\n", \
490 saa7113configNTSC[i0].reg, \
491 ir, saa7113configNTSC[i0].set);
492 rc--;
493 }
494 i0++;
388 } 495 }
496} else {
497 while (0xFF != saa7113configPAL[i0].reg) {
498 if (0x0F == saa7113configPAL[i0].reg) {
499 i0++;
500 continue;
501 }
389 502
390 ir = read_saa(p, saa7113config[i0].reg); 503 ir = read_saa(p, saa7113configPAL[i0].reg);
391 if (ir != saa7113config[i0].set) { 504 if (ir != saa7113configPAL[i0].set) {
392 SAY("SAA register 0x%02X has 0x%02X, expected 0x%02X\n", \ 505 SAY("SAA register 0x%02X has 0x%02X, " \
393 saa7113config[i0].reg, ir, saa7113config[i0].set); 506 "expected 0x%02X\n", \
394 rc--; 507 saa7113configPAL[i0].reg, \
508 ir, saa7113configPAL[i0].set);
509 rc--;
510 }
511 i0++;
395 } 512 }
396 i0++;
397} 513}
398if (-8 > rc) 514if (-8 > rc)
399 return rc; 515 return rc;
@@ -406,6 +522,8 @@ merit_saa(struct usb_device *p)
406{ 522{
407int rc; 523int rc;
408 524
525if (NULL == p)
526 return -ENODEV;
409rc = read_saa(p, 0x1F); 527rc = read_saa(p, 0x1F);
410if ((0 > rc) || (0x02 & rc)) 528if ((0 > rc) || (0x02 & rc))
411 return 1 ; 529 return 1 ;
@@ -416,29 +534,46 @@ else
416int 534int
417ready_saa(struct usb_device *p) 535ready_saa(struct usb_device *p)
418{ 536{
419int j, rc; 537int j, rc, rate;
420static int max = 10; 538const int max = 5, marktime = PATIENCE/5;
421 539/*--------------------------------------------------------------------------*/
540/*
541 * RETURNS 0 FOR INTERLACED 50 Hz
542 * 1 FOR NON-INTERLACED 50 Hz
543 * 2 FOR INTERLACED 60 Hz
544 * 3 FOR NON-INTERLACED 60 Hz
545*/
546/*--------------------------------------------------------------------------*/
547if (NULL == p)
548 return -ENODEV;
422j = 0; 549j = 0;
423while (max > j) { 550while (max > j) {
424 rc = read_saa(p, 0x1F); 551 rc = read_saa(p, 0x1F);
425 if (0 <= rc) { 552 if (0 <= rc) {
426 if ((1 == (0x01 & rc))&&(0 == (0x40 & rc))) 553 if (0 == (0x40 & rc))
554 break;
555 if (1 == (0x01 & rc))
427 break; 556 break;
428 } 557 }
429 msleep(100); j++; 558 msleep(marktime);
559 j++;
430} 560}
431if (max == j) 561if (max == j)
432 return -1; 562 return -1;
433else { 563else {
434 if (0x20 & rc) 564 if (0x20 & rc) {
565 rate = 2;
435 JOT(8, "hardware detects 60 Hz\n"); 566 JOT(8, "hardware detects 60 Hz\n");
436 else 567 } else {
568 rate = 0;
437 JOT(8, "hardware detects 50 Hz\n"); 569 JOT(8, "hardware detects 50 Hz\n");
570 }
438 if (0x80 & rc) 571 if (0x80 & rc)
439 JOT(8, "hardware detects interlacing\n"); 572 JOT(8, "hardware detects interlacing\n");
440 else 573 else {
574 rate++;
441 JOT(8, "hardware detects no interlacing\n"); 575 JOT(8, "hardware detects no interlacing\n");
576 }
442} 577}
443return 0; 578return 0;
444} 579}
@@ -447,45 +582,80 @@ return 0;
447/* 582/*
448 * NOTE: THE FOLLOWING ARE NOT CHECKED: 583 * NOTE: THE FOLLOWING ARE NOT CHECKED:
449 * REGISTERS 0x000, 0x002: FUNCTIONALITY IS NOT KNOWN 584 * REGISTERS 0x000, 0x002: FUNCTIONALITY IS NOT KNOWN
450 * REGISTER 0x100: ACCEPT ALSO (0x80 | stk1160config[.].set) 585 * REGISTER 0x100: ACCEPT ALSO (0x80 | stk1160config....[.].set)
451 */ 586 */
452/*--------------------------------------------------------------------------*/ 587/*--------------------------------------------------------------------------*/
453int 588int
454check_stk(struct usb_device *p) 589check_stk(struct usb_device *p, bool ntsc)
455{ 590{
456int i0, ir; 591int i0, ir;
457i0 = 0;
458while (0xFFF != stk1160config[i0].reg) {
459 if (0x000 == stk1160config[i0].reg) {
460 i0++; continue;
461 }
462 if (0x002 == stk1160config[i0].reg) {
463 i0++; continue;
464 }
465
466 ir = read_stk(p, stk1160config[i0].reg);
467 592
468 if (0x100 == stk1160config[i0].reg) { 593if (NULL == p)
469 if ((ir != (0xFF & stk1160config[i0].set)) && \ 594 return -ENODEV;
470 (ir != (0x80 | (0xFF & stk1160config[i0].set))) && \ 595i0 = 0;
471 (0xFFFF != stk1160config[i0].set)) { 596if (true == ntsc) {
472 SAY("STK register 0x%03X has 0x%02X, " \ 597 while (0xFFF != stk1160configNTSC[i0].reg) {
473 "expected 0x%02X\n", \ 598 if (0x000 == stk1160configNTSC[i0].reg) {
474 stk1160config[i0].reg, ir, \ 599 i0++; continue;
475 stk1160config[i0].set); 600 }
601 if (0x002 == stk1160configNTSC[i0].reg) {
602 i0++; continue;
603 }
604 ir = read_stk(p, stk1160configNTSC[i0].reg);
605 if (0x100 == stk1160configNTSC[i0].reg) {
606 if ((ir != (0xFF & stk1160configNTSC[i0].set)) && \
607 (ir != (0x80 | (0xFF & \
608 stk1160configNTSC[i0].set))) && \
609 (0xFFFF != \
610 stk1160configNTSC[i0].set)) {
611 SAY("STK register 0x%03X has 0x%02X, " \
612 "expected 0x%02X\n", \
613 stk1160configNTSC[i0].reg, \
614 ir, stk1160configNTSC[i0].set);
615 }
616 i0++; continue;
476 } 617 }
477 i0++; continue; 618 if ((ir != (0xFF & stk1160configNTSC[i0].set)) && \
619 (0xFFFF != stk1160configNTSC[i0].set)) {
620 SAY("STK register 0x%03X has 0x%02X, " \
621 "expected 0x%02X\n", \
622 stk1160configNTSC[i0].reg, \
623 ir, stk1160configNTSC[i0].set);
478 } 624 }
479 625 i0++;
480 if ((ir != (0xFF & stk1160config[i0].set)) && \ 626 }
481 (0xFFFF != stk1160config[i0].set)) { 627} else {
482 SAY("STK register 0x%03X has 0x%02X, " \ 628 while (0xFFF != stk1160configPAL[i0].reg) {
483 "expected 0x%02X\n", \ 629 if (0x000 == stk1160configPAL[i0].reg) {
484 stk1160config[i0].reg, ir, \ 630 i0++; continue;
485 stk1160config[i0].set);
486 } 631 }
487 i0++; 632 if (0x002 == stk1160configPAL[i0].reg) {
633 i0++; continue;
634 }
635 ir = read_stk(p, stk1160configPAL[i0].reg);
636 if (0x100 == stk1160configPAL[i0].reg) {
637 if ((ir != (0xFF & stk1160configPAL[i0].set)) && \
638 (ir != (0x80 | (0xFF & \
639 stk1160configPAL[i0].set))) && \
640 (0xFFFF != \
641 stk1160configPAL[i0].set)) {
642 SAY("STK register 0x%03X has 0x%02X, " \
643 "expected 0x%02X\n", \
644 stk1160configPAL[i0].reg, \
645 ir, stk1160configPAL[i0].set);
646 }
647 i0++; continue;
648 }
649 if ((ir != (0xFF & stk1160configPAL[i0].set)) && \
650 (0xFFFF != stk1160configPAL[i0].set)) {
651 SAY("STK register 0x%03X has 0x%02X, " \
652 "expected 0x%02X\n", \
653 stk1160configPAL[i0].reg, \
654 ir, stk1160configPAL[i0].set);
655 }
656 i0++;
488 } 657 }
658}
489return 0; 659return 0;
490} 660}
491/****************************************************************************/ 661/****************************************************************************/
@@ -494,6 +664,8 @@ read_saa(struct usb_device *p, __u16 reg0)
494{ 664{
495__u8 igot; 665__u8 igot;
496 666
667if (NULL == p)
668 return -ENODEV;
497SET(p, 0x208, reg0); 669SET(p, 0x208, reg0);
498SET(p, 0x200, 0x20); 670SET(p, 0x200, 0x20);
499if (0 != wait_i2c(p)) 671if (0 != wait_i2c(p))
@@ -508,12 +680,14 @@ read_stk(struct usb_device *p, __u32 reg0)
508{ 680{
509__u8 igot; 681__u8 igot;
510 682
683if (NULL == p)
684 return -ENODEV;
511igot = 0; 685igot = 0;
512GET(p, reg0, &igot); 686GET(p, reg0, &igot);
513return igot; 687return igot;
514} 688}
515/*****************************************************************************/ 689/****************************************************************************/
516/*---------------------------------------------------------------------------*/ 690/*--------------------------------------------------------------------------*/
517/* 691/*
518 * HARDWARE USERSPACE INPUT NUMBER PHYSICAL INPUT DRIVER input VALUE 692 * HARDWARE USERSPACE INPUT NUMBER PHYSICAL INPUT DRIVER input VALUE
519 * 693 *
@@ -534,81 +708,100 @@ return igot;
534int 708int
535select_input(struct usb_device *p, int input, int mode) 709select_input(struct usb_device *p, int input, int mode)
536{ 710{
711int ir;
537 712
713if (NULL == p)
714 return -ENODEV;
538stop_100(p); 715stop_100(p);
539
540msleep(20);
541switch (input) { 716switch (input) {
542case 0: 717case 0:
543case 1: { 718case 1: {
544 SET(p, 0x0000, 0x0098); break; 719 if (0 != write_saa(p, 0x02, 0x80)) {
720 SAY("ERROR: failed to set SAA register 0x02 for input %i\n", \
721 input);
722 }
723 SET(p, 0x0000, 0x0098);
724 SET(p, 0x0002, 0x0078);
725 break;
545} 726}
546case 2: { 727case 2: {
547 SET(p, 0x0000, 0x0090); break; 728 if (0 != write_saa(p, 0x02, 0x80)) {
729 SAY("ERROR: failed to set SAA register 0x02 for input %i\n", \
730 input);
731 }
732 SET(p, 0x0000, 0x0090);
733 SET(p, 0x0002, 0x0078);
734 break;
548} 735}
549case 3: { 736case 3: {
550 SET(p, 0x0000, 0x0088); break; 737 if (0 != write_saa(p, 0x02, 0x80)) {
738 SAY("ERROR: failed to set SAA register 0x02 for input %i\n", \
739 input);
740 }
741 SET(p, 0x0000, 0x0088);
742 SET(p, 0x0002, 0x0078);
743 break;
551} 744}
552case 4: { 745case 4: {
553 SET(p, 0x0000, 0x0080); break; 746 if (0 != write_saa(p, 0x02, 0x80)) {
747 SAY("ERROR: failed to set SAA register 0x02 for input %i\n", \
748 input);
749 }
750 SET(p, 0x0000, 0x0080);
751 SET(p, 0x0002, 0x0078);
752 break;
554} 753}
555case 5: { 754case 5: {
556 if (9 != mode) 755 if (9 != mode)
557 mode = 7; 756 mode = 7;
558 switch (mode) { 757 switch (mode) {
559 case 7: 758 case 7: {
560 {
561 if (0 != write_saa(p, 0x02, 0x87)) { 759 if (0 != write_saa(p, 0x02, 0x87)) {
562 SAY("ERROR: failed to set SAA " \ 760 SAY("ERROR: failed to set SAA register 0x02 " \
563 "register 0x02 for input " \ 761 "for input %i\n", input);
564 "%i\n", input);
565 } 762 }
566 if (0 != write_saa(p, 0x05, 0xFF)) { 763 if (0 != write_saa(p, 0x05, 0xFF)) {
567 SAY("ERROR: failed to set SAA " \ 764 SAY("ERROR: failed to set SAA register 0x05 " \
568 "register 0x05 for input " \ 765 "for input %i\n", input);
569 "%i\n", input);
570 } 766 }
571 break; 767 break;
572 } 768 }
573 case 9: 769 case 9: {
574 {
575 if (0 != write_saa(p, 0x02, 0x89)) { 770 if (0 != write_saa(p, 0x02, 0x89)) {
576 SAY("ERROR: failed to set SAA " \ 771 SAY("ERROR: failed to set SAA register 0x02 " \
577 "register 0x02 for input " \ 772 "for input %i\n", input);
578 "%i\n", input);
579 } 773 }
580 if (0 != write_saa(p, 0x05, 0x00)) { 774 if (0 != write_saa(p, 0x05, 0x00)) {
581 SAY("ERROR: failed to set SAA " \ 775 SAY("ERROR: failed to set SAA register 0x05 " \
582 "register 0x05 for input " \ 776 "for input %i\n", input);
583 "%i\n", input);
584 } 777 }
585 break; 778 break;
586 } 779 }
587 default: 780 default: {
588 {
589 SAY("MISTAKE: bad mode: %i\n", mode); 781 SAY("MISTAKE: bad mode: %i\n", mode);
590 return -1; 782 return -1;
591 } 783 }
592 } 784 }
593 if (0 != write_saa(p, 0x04, 0x00)) { 785 if (0 != write_saa(p, 0x04, 0x00)) {
594 SAY("ERROR: failed to set SAA register 0x04 " \ 786 SAY("ERROR: failed to set SAA register 0x04 for input %i\n", \
595 "for input %i\n", input); 787 input);
596 } 788 }
597 if (0 != write_saa(p, 0x09, 0x80)) { 789 if (0 != write_saa(p, 0x09, 0x80)) {
598 SAY("ERROR: failed to set SAA register 0x09 " \ 790 SAY("ERROR: failed to set SAA register 0x09 for input %i\n", \
599 "for input %i\n", input); 791 input);
600 } 792 }
793 SET(p, 0x0002, 0x0093);
601 break; 794 break;
602} 795}
603default: 796default: {
604 {
605 SAY("ERROR: bad input: %i\n", input); 797 SAY("ERROR: bad input: %i\n", input);
606 return -1; 798 return -1;
607} 799}
608} 800}
609msleep(20); 801ir = read_stk(p, 0x00);
610SET(p, 0x0002, 0x0093); 802JOT(8, "STK register 0x00 has 0x%02X\n", ir);
611msleep(20); 803ir = read_saa(p, 0x02);
804JOT(8, "SAA register 0x02 has 0x%02X\n", ir);
612 805
613start_100(p); 806start_100(p);
614 807
@@ -621,6 +814,8 @@ set_resolution(struct usb_device *p, \
621{ 814{
622__u16 u0x0111, u0x0113, u0x0115, u0x0117; 815__u16 u0x0111, u0x0113, u0x0115, u0x0117;
623 816
817if (NULL == p)
818 return -ENODEV;
624u0x0111 = ((0xFF00 & set0) >> 8); 819u0x0111 = ((0xFF00 & set0) >> 8);
625u0x0113 = ((0xFF00 & set1) >> 8); 820u0x0113 = ((0xFF00 & set1) >> 8);
626u0x0115 = ((0xFF00 & set2) >> 8); 821u0x0115 = ((0xFF00 & set2) >> 8);
@@ -641,13 +836,25 @@ return 0;
641int 836int
642start_100(struct usb_device *p) 837start_100(struct usb_device *p)
643{ 838{
644__u16 get0; 839__u16 get116, get117, get0;
645__u8 igot; 840__u8 igot116, igot117, igot;
646 841
647GET(p, 0x0100, &igot); get0 = igot; 842if (NULL == p)
648msleep(0x1f4); 843 return -ENODEV;
844GET(p, 0x0116, &igot116);
845get116 = igot116;
846GET(p, 0x0117, &igot117);
847get117 = igot117;
848SET(p, 0x0116, 0x0000);
849SET(p, 0x0117, 0x0000);
850
851GET(p, 0x0100, &igot);
852get0 = igot;
649SET(p, 0x0100, (0x80 | get0)); 853SET(p, 0x0100, (0x80 | get0));
650msleep(0x1f4); 854
855SET(p, 0x0116, get116);
856SET(p, 0x0117, get117);
857
651return 0; 858return 0;
652} 859}
653/****************************************************************************/ 860/****************************************************************************/
@@ -657,10 +864,11 @@ stop_100(struct usb_device *p)
657__u16 get0; 864__u16 get0;
658__u8 igot; 865__u8 igot;
659 866
660GET(p, 0x0100, &igot); get0 = igot; 867if (NULL == p)
661msleep(0x1f4); 868 return -ENODEV;
869GET(p, 0x0100, &igot);
870get0 = igot;
662SET(p, 0x0100, (0x7F & get0)); 871SET(p, 0x0100, (0x7F & get0));
663msleep(0x1f4);
664return 0; 872return 0;
665} 873}
666/****************************************************************************/ 874/****************************************************************************/
@@ -674,9 +882,11 @@ wait_i2c(struct usb_device *p)
674{ 882{
675__u16 get0; 883__u16 get0;
676__u8 igot; 884__u8 igot;
677const int max = 4; 885const int max = 2;
678int k; 886int k;
679 887
888if (NULL == p)
889 return -ENODEV;
680for (k = 0; k < max; k++) { 890for (k = 0; k < max; k++) {
681 GET(p, 0x0201, &igot); get0 = igot; 891 GET(p, 0x0201, &igot); get0 = igot;
682 switch (get0) { 892 switch (get0) {
@@ -685,7 +895,7 @@ for (k = 0; k < max; k++) {
685 return 0; 895 return 0;
686 } 896 }
687 case 0x00: { 897 case 0x00: {
688 msleep(10); 898 msleep(20);
689 continue; 899 continue;
690 } 900 }
691 default: { 901 default: {
@@ -703,8 +913,7 @@ __u16 igot;
703int rc0, rc1; 913int rc0, rc1;
704 914
705if (!pusb_device) 915if (!pusb_device)
706 return -EFAULT; 916 return -ENODEV;
707
708rc1 = 0; igot = 0; 917rc1 = 0; igot = 0;
709rc0 = usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \ 918rc0 = usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \
710 (__u8)0x01, \ 919 (__u8)0x01, \
@@ -741,27 +950,14 @@ case 0x204:
741case 0x205: 950case 0x205:
742case 0x350: 951case 0x350:
743case 0x351: { 952case 0x351: {
744 if (0 != igot) { 953 if (0 != (0xFF & igot)) {
745 JOT(8, "unexpected 0x%02X for STK register 0x%03X\n", \ 954 JOT(8, "unexpected 0x%02X for STK register 0x%03X\n", \
746 igot, index); 955 igot, index);
747 } 956 }
748break; 957break;
749} 958}
750case 0x114:
751case 0x116: {
752 if ((0xFF & value) != igot) {
753 JOT(8, "unexpected 0x%02X != 0x%02X " \
754 "for STK register 0x%03X\n", \
755 igot, value, index);
756 }
757break;
758}
759case 0x200: {
760 if (0 == igot)
761 break;
762}
763default: { 959default: {
764 if (value != igot) { 960 if ((0xFF & value) != (0xFF & igot)) {
765 JOT(8, "unexpected 0x%02X != 0x%02X " \ 961 JOT(8, "unexpected 0x%02X != 0x%02X " \
766 "for STK register 0x%03X\n", \ 962 "for STK register 0x%03X\n", \
767 igot, value, index); 963 igot, value, index);
@@ -780,8 +976,7 @@ regget(struct usb_device *pusb_device, __u16 index, void *pvoid)
780int ir; 976int ir;
781 977
782if (!pusb_device) 978if (!pusb_device)
783 return -EFAULT; 979 return -ENODEV;
784
785ir = usb_control_msg(pusb_device, usb_rcvctrlpipe(pusb_device, 0), \ 980ir = usb_control_msg(pusb_device, usb_rcvctrlpipe(pusb_device, 0), \
786 (__u8)0x00, \ 981 (__u8)0x00, \
787 (__u8)(USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE), \ 982 (__u8)(USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE), \
@@ -796,6 +991,8 @@ return 0xFF & ir;
796int 991int
797wakeup_device(struct usb_device *pusb_device) 992wakeup_device(struct usb_device *pusb_device)
798{ 993{
994if (!pusb_device)
995 return -ENODEV;
799return usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \ 996return usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \
800 (__u8)USB_REQ_SET_FEATURE, \ 997 (__u8)USB_REQ_SET_FEATURE, \
801 (__u8)(USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE), \ 998 (__u8)(USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE), \
@@ -806,6 +1003,12 @@ return usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \
806 (int)50000); 1003 (int)50000);
807} 1004}
808/*****************************************************************************/ 1005/*****************************************************************************/
1006int
1007audio_setup(struct easycap *peasycap)
1008{
1009struct usb_device *pusb_device;
1010unsigned char buffer[1];
1011int rc, id1, id2;
809/*---------------------------------------------------------------------------*/ 1012/*---------------------------------------------------------------------------*/
810/* 1013/*
811 * IMPORTANT: 1014 * IMPORTANT:
@@ -814,29 +1017,21 @@ return usb_control_msg(pusb_device, usb_sndctrlpipe(pusb_device, 0), \
814 * TO ENABLE AUDIO THE VALUE 0x0200 MUST BE SENT. 1017 * TO ENABLE AUDIO THE VALUE 0x0200 MUST BE SENT.
815 */ 1018 */
816/*---------------------------------------------------------------------------*/ 1019/*---------------------------------------------------------------------------*/
817int 1020const __u8 request = 0x01;
818audio_setup(struct easycap *peasycap) 1021const __u8 requesttype = \
819{
820struct usb_device *pusb_device;
821static __u8 request = 0x01;
822static __u8 requesttype = \
823 (__u8)(USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE); 1022 (__u8)(USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE);
824 1023const __u16 value_unmute = 0x0200;
825static __u16 value_unmute = 0x0200; 1024const __u16 index = 0x0301;
826static __u16 index = 0x0301; 1025const __u16 length = 1;
827
828static unsigned char buffer[1];
829static __u16 length = 1;
830int rc, id1, id2;
831 1026
832if (NULL == peasycap) 1027if (NULL == peasycap)
833 return -EFAULT; 1028 return -EFAULT;
834 1029
835pusb_device = peasycap->pusb_device; 1030pusb_device = peasycap->pusb_device;
836if (NULL == pusb_device) 1031if (NULL == pusb_device)
837 return -EFAULT; 1032 return -ENODEV;
838 1033
839JOT(8, "%02X %02X %02X %02X %02X %02X %02X %02X\n", \ 1034JOM(8, "%02X %02X %02X %02X %02X %02X %02X %02X\n", \
840 requesttype, request, \ 1035 requesttype, request, \
841 (0x00FF & value_unmute), \ 1036 (0x00FF & value_unmute), \
842 (0xFF00 & value_unmute) >> 8, \ 1037 (0xFF00 & value_unmute) >> 8, \
@@ -875,41 +1070,25 @@ if (rc != (int)length)
875 * THE UPPER BYTE SEEMS TO HAVE NO EFFECT. 1070 * THE UPPER BYTE SEEMS TO HAVE NO EFFECT.
876 */ 1071 */
877/*--------------------------------------------------------------------------*/ 1072/*--------------------------------------------------------------------------*/
878
879SET(pusb_device, 0x0500, 0x0094); 1073SET(pusb_device, 0x0500, 0x0094);
880
881SET(pusb_device, 0x0500, 0x008C); 1074SET(pusb_device, 0x0500, 0x008C);
882
883SET(pusb_device, 0x0506, 0x0001); 1075SET(pusb_device, 0x0506, 0x0001);
884SET(pusb_device, 0x0507, 0x0000); 1076SET(pusb_device, 0x0507, 0x0000);
885
886id1 = read_vt(pusb_device, 0x007C); 1077id1 = read_vt(pusb_device, 0x007C);
887id2 = read_vt(pusb_device, 0x007E); 1078id2 = read_vt(pusb_device, 0x007E);
888SAY("0x%04X:0x%04X is audio vendor id\n", id1, id2); 1079SAM("0x%04X:0x%04X is audio vendor id\n", id1, id2);
889
890/*---------------------------------------------------------------------------*/ 1080/*---------------------------------------------------------------------------*/
891/* 1081/*
892* SELECT AUDIO SOURCE "LINE IN" AND SET DEFAULT GAIN TO 0 dB. 1082 * SELECT AUDIO SOURCE "LINE IN" AND SET THE AUDIO GAIN.
893*
894* THESE COMMANDS SEEM TO BE ACCEPTED (THOUGH POSSIBLY IGNORED) EVEN WHEN
895* THERE IS NO SEPARATE AUDIO CHIP PRESENT.
896*/ 1083*/
897/*---------------------------------------------------------------------------*/ 1084/*---------------------------------------------------------------------------*/
898 1085if (31 < easycap_gain)
899write_vt(pusb_device, 0x0002, 0x8000); 1086 easycap_gain = 31;
900write_vt(pusb_device, 0x001C, 0x8000); 1087if (0 > easycap_gain)
901 1088 easycap_gain = 0;
902write_vt(pusb_device, 0x000E, 0x0000); 1089if (0 != audio_gainset(pusb_device, (__s8)easycap_gain))
903write_vt(pusb_device, 0x0010, 0x0000); 1090 SAY("ERROR: audio_gainset() failed\n");
904write_vt(pusb_device, 0x0012, 0x8000);
905write_vt(pusb_device, 0x0016, 0x0000);
906
907write_vt(pusb_device, 0x001A, 0x0404);
908write_vt(pusb_device, 0x0002, 0x0000);
909write_vt(pusb_device, 0x001C, 0x0000);
910
911check_vt(pusb_device); 1091check_vt(pusb_device);
912
913return 0; 1092return 0;
914} 1093}
915/*****************************************************************************/ 1094/*****************************************************************************/
@@ -918,6 +1097,8 @@ check_vt(struct usb_device *pusb_device)
918{ 1097{
919int igot; 1098int igot;
920 1099
1100if (!pusb_device)
1101 return -ENODEV;
921igot = read_vt(pusb_device, 0x0002); 1102igot = read_vt(pusb_device, 0x0002);
922if (0 > igot) 1103if (0 > igot)
923 SAY("ERROR: failed to read VT1612A register 0x02\n"); 1104 SAY("ERROR: failed to read VT1612A register 0x02\n");
@@ -942,17 +1123,23 @@ if (0 > igot)
942if (0x8000 & igot) 1123if (0x8000 & igot)
943 SAY("register 0x%02X muted\n", 0x12); 1124 SAY("register 0x%02X muted\n", 0x12);
944 1125
1126igot = read_vt(pusb_device, 0x0014);
1127if (0 > igot)
1128 SAY("ERROR: failed to read VT1612A register 0x14\n");
1129if (0x8000 & igot)
1130 SAY("register 0x%02X muted\n", 0x14);
1131
945igot = read_vt(pusb_device, 0x0016); 1132igot = read_vt(pusb_device, 0x0016);
946if (0 > igot) 1133if (0 > igot)
947 SAY("ERROR: failed to read VT1612A register 0x16\n"); 1134 SAY("ERROR: failed to read VT1612A register 0x16\n");
948if (0x8000 & igot) 1135if (0x8000 & igot)
949 SAY("register 0x%02X muted\n", 0x16); 1136 SAY("register 0x%02X muted\n", 0x16);
950 1137
951igot = read_vt(pusb_device, 0x001A); 1138igot = read_vt(pusb_device, 0x0018);
952if (0 > igot) 1139if (0 > igot)
953 SAY("ERROR: failed to read VT1612A register 0x1A\n"); 1140 SAY("ERROR: failed to read VT1612A register 0x18\n");
954if (0x8000 & igot) 1141if (0x8000 & igot)
955 SAY("register 0x%02X muted\n", 0x1A); 1142 SAY("register 0x%02X muted\n", 0x18);
956 1143
957igot = read_vt(pusb_device, 0x001C); 1144igot = read_vt(pusb_device, 0x001C);
958if (0 > igot) 1145if (0 > igot)
@@ -964,14 +1151,18 @@ return 0;
964} 1151}
965/*****************************************************************************/ 1152/*****************************************************************************/
966/*---------------------------------------------------------------------------*/ 1153/*---------------------------------------------------------------------------*/
967/* 1154/* NOTE: THIS DOES INCREASE THE VOLUME DRAMATICALLY:
968 * NOTE: THIS DOES INCREASE THE VOLUME DRAMATICALLY: 1155 * audio_gainset(pusb_device, 0x000F);
969 * audio_gainset(pusb_device, 0x000F);
970 * 1156 *
971 * IF 16<loud<31 VT1621A REGISTER 0x1C IS SET FOR POSITIVE GAIN. 1157 * loud dB register 0x10 dB register 0x1C dB total
972 * IF loud<=16 VT1621A REGISTER 0x1C IS SET FOR ZERO GAIN. 1158 * 0 -34.5 0 -34.5
973 * THERE IS NEVER ANY (ADDITIONAL) ATTENUATION. 1159 * .. .... . ....
974 */ 1160 * 15 10.5 0 10.5
1161 * 16 12.0 0 12.0
1162 * 17 12.0 1.5 13.5
1163 * .. .... .... ....
1164 * 31 12.0 22.5 34.5
1165*/
975/*---------------------------------------------------------------------------*/ 1166/*---------------------------------------------------------------------------*/
976int 1167int
977audio_gainset(struct usb_device *pusb_device, __s8 loud) 1168audio_gainset(struct usb_device *pusb_device, __s8 loud)
@@ -980,25 +1171,65 @@ int igot;
980__u8 u8; 1171__u8 u8;
981__u16 mute; 1172__u16 mute;
982 1173
983if (16 > loud) 1174if (NULL == pusb_device)
984 loud = 16; 1175 return -ENODEV;
985u8 = 0x000F & (__u8)(loud - 16); 1176if (0 > loud)
1177 loud = 0;
1178if (31 < loud)
1179 loud = 31;
986 1180
987write_vt(pusb_device, 0x0002, 0x8000); 1181write_vt(pusb_device, 0x0002, 0x8000);
1182/*---------------------------------------------------------------------------*/
1183igot = read_vt(pusb_device, 0x000E);
1184if (0 > igot) {
1185 SAY("ERROR: failed to read VT1612A register 0x0E\n");
1186 mute = 0x0000;
1187} else
1188 mute = 0x8000 & ((unsigned int)igot);
1189mute = 0;
1190
1191if (16 > loud)
1192 u8 = 0x01 | (0x001F & (((__u8)(15 - loud)) << 1));
1193else
1194 u8 = 0;
988 1195
1196JOT(8, "0x%04X=(mute|u8) for VT1612A register 0x0E\n", mute | u8);
1197write_vt(pusb_device, 0x000E, (mute | u8));
1198/*---------------------------------------------------------------------------*/
1199igot = read_vt(pusb_device, 0x0010);
1200if (0 > igot) {
1201 SAY("ERROR: failed to read VT1612A register 0x10\n");
1202 mute = 0x0000;
1203} else
1204 mute = 0x8000 & ((unsigned int)igot);
1205mute = 0;
1206
1207JOT(8, "0x%04X=(mute|u8|(u8<<8)) for VT1612A register 0x10,...0x18\n", \
1208 mute | u8 | (u8 << 8));
1209write_vt(pusb_device, 0x0010, (mute | u8 | (u8 << 8)));
1210write_vt(pusb_device, 0x0012, (mute | u8 | (u8 << 8)));
1211write_vt(pusb_device, 0x0014, (mute | u8 | (u8 << 8)));
1212write_vt(pusb_device, 0x0016, (mute | u8 | (u8 << 8)));
1213write_vt(pusb_device, 0x0018, (mute | u8 | (u8 << 8)));
1214/*---------------------------------------------------------------------------*/
989igot = read_vt(pusb_device, 0x001C); 1215igot = read_vt(pusb_device, 0x001C);
990if (0 > igot) { 1216if (0 > igot) {
991 SAY("ERROR: failed to read VT1612A register 0x1C\n"); 1217 SAY("ERROR: failed to read VT1612A register 0x1C\n");
992 mute = 0x0000; 1218 mute = 0x0000;
993} else 1219} else
994 mute = 0x8000 & ((unsigned int)igot); 1220 mute = 0x8000 & ((unsigned int)igot);
1221mute = 0;
995 1222
996JOT(8, "0x%04X=(mute|u8|(u8<<8))\n", mute | u8 | (u8 << 8)); 1223if (16 <= loud)
1224 u8 = 0x000F & (__u8)(loud - 16);
1225else
1226 u8 = 0;
997 1227
998write_vt(pusb_device, 0x001C, 0x8000); 1228JOT(8, "0x%04X=(mute|u8|(u8<<8)) for VT1612A register 0x1C\n", \
1229 mute | u8 | (u8 << 8));
999write_vt(pusb_device, 0x001C, (mute | u8 | (u8 << 8))); 1230write_vt(pusb_device, 0x001C, (mute | u8 | (u8 << 8)));
1231write_vt(pusb_device, 0x001A, 0x0404);
1000write_vt(pusb_device, 0x0002, 0x0000); 1232write_vt(pusb_device, 0x0002, 0x0000);
1001
1002return 0; 1233return 0;
1003} 1234}
1004/*****************************************************************************/ 1235/*****************************************************************************/
@@ -1007,35 +1238,11 @@ audio_gainget(struct usb_device *pusb_device)
1007{ 1238{
1008int igot; 1239int igot;
1009 1240
1241if (NULL == pusb_device)
1242 return -ENODEV;
1010igot = read_vt(pusb_device, 0x001C); 1243igot = read_vt(pusb_device, 0x001C);
1011if (0 > igot) 1244if (0 > igot)
1012 SAY("ERROR: failed to read VT1612A register 0x1C\n"); 1245 SAY("ERROR: failed to read VT1612A register 0x1C\n");
1013return igot; 1246return igot;
1014} 1247}
1015/*****************************************************************************/ 1248/*****************************************************************************/
1016int
1017set2to78(struct usb_device *p)
1018{
1019int ir;
1020
1021msleep(20);
1022ir = regset(p, 0x0002, 0x0078);
1023if (0 > ir)
1024 SAY("ERROR: failed to set register 0x0002 to 0x0078\n");
1025msleep(20);
1026return ir;
1027}
1028/*****************************************************************************/
1029int
1030set2to93(struct usb_device *p)
1031{
1032int ir;
1033
1034msleep(20);
1035ir = regset(p, 0x0002, 0x0093);
1036if (0 > ir)
1037 SAY("ERROR: failed to set register 0x0002 to 0x0078\n");
1038msleep(20);
1039return ir;
1040}
1041/*****************************************************************************/
diff --git a/drivers/staging/easycap/easycap_main.c b/drivers/staging/easycap/easycap_main.c
index 5a4bbd9b453f..acc1f56e6f29 100644
--- a/drivers/staging/easycap/easycap_main.c
+++ b/drivers/staging/easycap/easycap_main.c
@@ -30,9 +30,29 @@
30 30
31#include "easycap.h" 31#include "easycap.h"
32#include "easycap_standard.h" 32#include "easycap_standard.h"
33#include "easycap_ioctl.h"
33 34
34int easycap_debug; 35static int easycap_debug;
35module_param(easycap_debug, int, S_IRUGO | S_IWUSR); 36static int easycap_bars;
37int easycap_gain = 16;
38module_param_named(debug, easycap_debug, int, S_IRUGO | S_IWUSR);
39module_param_named(bars, easycap_bars, int, S_IRUGO | S_IWUSR);
40module_param_named(gain, easycap_gain, int, S_IRUGO | S_IWUSR);
41
42/*---------------------------------------------------------------------------*/
43/*
44 * dongle_this IS INDISPENSIBLY static BECAUSE FUNCTION easycap_usb_probe()
45 * IS CALLED SUCCESSIVELY FOR INTERFACES 0, 1, 2 AND THE POINTER peasycap
46 * ALLOCATED DURING THE PROBING OF INTERFACE 0 MUST BE REMEMBERED WHEN
47 * PROBING INTERFACES 1 AND 2.
48 *
49 * IOCTL LOCKING IS DONE AT MODULE LEVEL, NOT DEVICE LEVEL.
50*/
51/*---------------------------------------------------------------------------*/
52
53struct easycap_dongle easycap_dongle[DONGLE_MANY];
54static int dongle_this;
55static int dongle_done;
36 56
37/*---------------------------------------------------------------------------*/ 57/*---------------------------------------------------------------------------*/
38/* 58/*
@@ -63,22 +83,25 @@ const struct file_operations easycap_fops = {
63 .owner = THIS_MODULE, 83 .owner = THIS_MODULE,
64 .open = easycap_open, 84 .open = easycap_open,
65 .release = easycap_release, 85 .release = easycap_release,
66 .unlocked_ioctl = easycap_ioctl, 86#if defined(EASYCAP_NEEDS_UNLOCKED_IOCTL)
87 .unlocked_ioctl = easycap_ioctl_noinode,
88#else
89 .ioctl = easycap_ioctl,
90#endif /*EASYCAP_NEEDS_UNLOCKED_IOCTL*/
67 .poll = easycap_poll, 91 .poll = easycap_poll,
68 .mmap = easycap_mmap, 92 .mmap = easycap_mmap,
69 .llseek = no_llseek, 93 .llseek = no_llseek,
70}; 94};
71struct vm_operations_struct easycap_vm_ops = { 95struct vm_operations_struct easycap_vm_ops = {
72.open = easycap_vma_open, 96 .open = easycap_vma_open,
73.close = easycap_vma_close, 97 .close = easycap_vma_close,
74.fault = easycap_vma_fault, 98 .fault = easycap_vma_fault,
75}; 99};
76struct usb_class_driver easycap_class = { 100struct usb_class_driver easycap_class = {
77.name = "usb/easycap%d", 101 .name = "usb/easycap%d",
78.fops = &easycap_fops, 102 .fops = &easycap_fops,
79.minor_base = USB_SKEL_MINOR_BASE, 103 .minor_base = USB_SKEL_MINOR_BASE,
80}; 104};
81
82/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 105/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
83#if defined(EASYCAP_IS_VIDEODEV_CLIENT) 106#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
84#if defined(EASYCAP_NEEDS_V4L2_FOPS) 107#if defined(EASYCAP_NEEDS_V4L2_FOPS)
@@ -86,16 +109,17 @@ const struct v4l2_file_operations v4l2_fops = {
86 .owner = THIS_MODULE, 109 .owner = THIS_MODULE,
87 .open = easycap_open_noinode, 110 .open = easycap_open_noinode,
88 .release = easycap_release_noinode, 111 .release = easycap_release_noinode,
89 .unlocked_ioctl = easycap_ioctl, 112#if defined(EASYCAP_NEEDS_UNLOCKED_IOCTL)
113 .unlocked_ioctl = easycap_ioctl_noinode,
114#else
115 .ioctl = easycap_ioctl,
116#endif /*EASYCAP_NEEDS_UNLOCKED_IOCTL*/
90 .poll = easycap_poll, 117 .poll = easycap_poll,
91 .mmap = easycap_mmap, 118 .mmap = easycap_mmap,
92}; 119};
93#endif /*EASYCAP_NEEDS_V4L2_FOPS*/ 120#endif /*EASYCAP_NEEDS_V4L2_FOPS*/
94int video_device_many /*=0*/;
95struct video_device *pvideo_array[VIDEO_DEVICE_MANY], *pvideo_device;
96#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 121#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
97/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ 122/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
98
99/*--------------------------------------------------------------------------*/ 123/*--------------------------------------------------------------------------*/
100/* 124/*
101 * PARAMETERS USED WHEN REGISTERING THE AUDIO INTERFACE 125 * PARAMETERS USED WHEN REGISTERING THE AUDIO INTERFACE
@@ -105,7 +129,11 @@ const struct file_operations easysnd_fops = {
105 .owner = THIS_MODULE, 129 .owner = THIS_MODULE,
106 .open = easysnd_open, 130 .open = easysnd_open,
107 .release = easysnd_release, 131 .release = easysnd_release,
108 .unlocked_ioctl = easysnd_ioctl, 132#if defined(EASYCAP_NEEDS_UNLOCKED_IOCTL)
133 .unlocked_ioctl = easysnd_ioctl_noinode,
134#else
135 .ioctl = easysnd_ioctl,
136#endif /*EASYCAP_NEEDS_UNLOCKED_IOCTL*/
109 .read = easysnd_read, 137 .read = easysnd_read,
110 .llseek = no_llseek, 138 .llseek = no_llseek,
111}; 139};
@@ -115,17 +143,26 @@ struct usb_class_driver easysnd_class = {
115.minor_base = USB_SKEL_MINOR_BASE, 143.minor_base = USB_SKEL_MINOR_BASE,
116}; 144};
117/****************************************************************************/ 145/****************************************************************************/
118/*--------------------------------------------------------------------------*/ 146/*---------------------------------------------------------------------------*/
119/* 147/*
120 * IT IS NOT APPROPRIATE FOR easycap_open() TO SUBMIT THE VIDEO URBS HERE, 148 * THIS ROUTINE DOES NOT DETECT DUPLICATE OCCURRENCES OF POINTER peasycap
121 * BECAUSE THERE WILL ALWAYS BE SUBSEQUENT NEGOTIATION OF TV STANDARD AND 149*/
122 * FORMAT BY IOCTL AND IT IS INADVISABLE TO HAVE THE URBS RUNNING WHILE 150/*---------------------------------------------------------------------------*/
123 * REGISTERS OF THE SA7113H ARE BEING MANIPULATED. 151int
124 * 152isdongle(struct easycap *peasycap)
125 * THE SUBMISSION OF VIDEO URBS IS THEREFORE DELAYED UNTIL THE IOCTL COMMAND 153{
126 * STREAMON IS RECEIVED. 154int k;
127 */ 155if (NULL == peasycap)
128/*--------------------------------------------------------------------------*/ 156 return -2;
157for (k = 0; k < DONGLE_MANY; k++) {
158 if (easycap_dongle[k].peasycap == peasycap) {
159 peasycap->isdongle = k;
160 return k;
161 }
162}
163return -1;
164}
165/*****************************************************************************/
129/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 166/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
130#if defined(EASYCAP_IS_VIDEODEV_CLIENT) 167#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
131int 168int
@@ -140,15 +177,17 @@ easycap_open(struct inode *inode, struct file *file)
140{ 177{
141#if (!defined(EASYCAP_IS_VIDEODEV_CLIENT)) 178#if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
142struct usb_interface *pusb_interface; 179struct usb_interface *pusb_interface;
180#else
181struct video_device *pvideo_device;
143#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 182#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
144struct usb_device *p;
145struct easycap *peasycap; 183struct easycap *peasycap;
146int i, k, m, rc; 184int rc;
147 185
148JOT(4, "\n"); 186JOT(4, "\n");
149SAY("==========OPEN=========\n"); 187SAY("==========OPEN=========\n");
150 188
151peasycap = (struct easycap *)NULL; 189peasycap = (struct easycap *)NULL;
190/*---------------------------------------------------------------------------*/
152#if (!defined(EASYCAP_IS_VIDEODEV_CLIENT)) 191#if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
153if ((struct inode *)NULL == inode) { 192if ((struct inode *)NULL == inode) {
154 SAY("ERROR: inode is NULL.\n"); 193 SAY("ERROR: inode is NULL.\n");
@@ -162,161 +201,427 @@ if (!pusb_interface) {
162peasycap = usb_get_intfdata(pusb_interface); 201peasycap = usb_get_intfdata(pusb_interface);
163/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 202/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
164#else 203#else
165for (i = 0; i < video_device_many; i++) { 204pvideo_device = video_devdata(file);
166 pvideo_device = pvideo_array[i]; 205if ((struct video_device *)NULL == pvideo_device) {
167 if ((struct video_device *)NULL != pvideo_device) { 206 SAY("ERROR: pvideo_device is NULL.\n");
168 peasycap = (struct easycap *)video_get_drvdata(pvideo_device); 207 return -EFAULT;
169 break;
170 }
171} 208}
172/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ 209peasycap = (struct easycap *)video_get_drvdata(pvideo_device);
173#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 210#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
174if ((struct easycap *)NULL == peasycap) { 211/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
175 SAY("MISTAKE: peasycap is NULL\n"); 212if (NULL == peasycap) {
213 SAY("ERROR: peasycap is NULL\n");
176 return -EFAULT; 214 return -EFAULT;
177} 215}
178file->private_data = peasycap; 216if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
179/*---------------------------------------------------------------------------*/ 217 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
180/* 218 return -EFAULT;
181 * INITIALIZATION
182 */
183/*---------------------------------------------------------------------------*/
184JOT(4, "starting initialization\n");
185
186for (k = 0; k < FRAME_BUFFER_MANY; k++) {
187 for (m = 0; m < FRAME_BUFFER_SIZE/PAGE_SIZE; m++)
188 memset(peasycap->frame_buffer[k][m].pgo, 0, PAGE_SIZE);
189} 219}
190p = peasycap->pusb_device; 220if (NULL == peasycap->pusb_device) {
191if ((struct usb_device *)NULL == p) { 221 SAM("ERROR: peasycap->pusb_device is NULL\n");
192 SAY("ERROR: peasycap->pusb_device is NULL\n");
193 return -EFAULT; 222 return -EFAULT;
194} else { 223} else {
195 JOT(16, "0x%08lX=peasycap->pusb_device\n", \ 224 JOM(16, "0x%08lX=peasycap->pusb_device\n", \
196 (long int)peasycap->pusb_device); 225 (long int)peasycap->pusb_device);
197} 226}
227file->private_data = peasycap;
198rc = wakeup_device(peasycap->pusb_device); 228rc = wakeup_device(peasycap->pusb_device);
199if (0 == rc) 229if (0 == rc)
200 JOT(8, "wakeup_device() OK\n"); 230 JOM(8, "wakeup_device() OK\n");
201else { 231else {
202 SAY("ERROR: wakeup_device() returned %i\n", rc); 232 SAM("ERROR: wakeup_device() returned %i\n", rc);
233 if (-ENODEV == rc)
234 SAM("ERROR: wakeup_device() returned -ENODEV\n");
235 else
236 SAM("ERROR: wakeup_device() returned %i\n", rc);
237 return rc;
238}
239peasycap->input = 0;
240rc = reset(peasycap);
241if (0 != rc) {
242 SAM("ERROR: reset() returned %i\n", rc);
203 return -EFAULT; 243 return -EFAULT;
204} 244}
205rc = setup_stk(p); peasycap->input = 0; 245return 0;
206if (0 == rc) 246}
207 JOT(8, "setup_stk() OK\n"); 247/*****************************************************************************/
208else { 248/*---------------------------------------------------------------------------*/
209 SAY("ERROR: setup_stk() returned %i\n", rc); 249/*
250 * RESET THE HARDWARE TO ITS REFERENCE STATE.
251 *
252 * THIS ROUTINE MAY BE CALLED REPEATEDLY IF easycap_complete() DETECTS
253 * A BAD VIDEO FRAME SIZE.
254*/
255/*---------------------------------------------------------------------------*/
256int
257reset(struct easycap *peasycap)
258{
259struct easycap_standard const *peasycap_standard;
260int i, rc, input, rate;
261bool ntsc, other;
262
263if (NULL == peasycap) {
264 SAY("ERROR: peasycap is NULL\n");
210 return -EFAULT; 265 return -EFAULT;
211} 266}
212rc = setup_saa(p); 267input = peasycap->input;
268
269/*---------------------------------------------------------------------------*/
270/*
271 * IF THE SAA7113H HAS ALREADY ACQUIRED SYNC, USE ITS HARDWARE-DETECTED
272 * FIELD FREQUENCY TO DISTINGUISH NTSC FROM PAL. THIS IS ESSENTIAL FOR
273 * gstreamer AND OTHER USERSPACE PROGRAMS WHICH MAY NOT ATTEMPT TO INITIATE
274 * A SWITCH BETWEEN PAL AND NTSC.
275 *
276 * FUNCTION ready_saa() MAY REQUIRE A SUBSTANTIAL FRACTION OF A SECOND TO
277 * COMPLETE, SO SHOULD NOT BE INVOKED WITHOUT GOOD REASON.
278*/
279/*---------------------------------------------------------------------------*/
280other = false;
281if (true == peasycap->ntsc)
282 JOM(8, "true=peasycap->ntsc\n");
283else
284 JOM(8, "false=peasycap->ntsc\n");
285rate = ready_saa(peasycap->pusb_device);
286if (0 > rate) {
287 JOM(8, "not ready to capture after %i ms ...\n", PATIENCE);
288 if (true == peasycap->ntsc) {
289 JOM(8, "... trying PAL ...\n"); ntsc = false;
290 } else {
291 JOM(8, "... trying NTSC ...\n"); ntsc = true;
292}
293rc = setup_stk(peasycap->pusb_device, ntsc);
213if (0 == rc) 294if (0 == rc)
214 JOT(8, "setup_saa() OK\n"); 295 JOM(4, "setup_stk() OK\n");
215else { 296else {
216 SAY("ERROR: setup_saa() returned %i\n", rc); 297 SAM("ERROR: setup_stk() returned %i\n", rc);
217 return -EFAULT; 298 return -EFAULT;
218} 299}
219rc = check_saa(p); 300rc = setup_saa(peasycap->pusb_device, ntsc);
220if (0 == rc) 301if (0 == rc)
221 JOT(8, "check_saa() OK\n"); 302 JOM(4, "setup_saa() OK\n");
222else if (-8 < rc)
223 SAY("check_saa() returned %i\n", rc);
224else { 303else {
225 SAY("ERROR: check_saa() returned %i\n", rc); 304 SAM("ERROR: setup_saa() returned %i\n", rc);
226 return -EFAULT; 305 return -EFAULT;
227} 306}
228peasycap->standard_offset = -1; 307rate = ready_saa(peasycap->pusb_device);
308if (0 > rate) {
309 JOM(8, "not ready to capture after %i ms ...\n", PATIENCE);
310 JOM(8, "... saa register 0x1F has 0x%02X\n", \
311 read_saa(peasycap->pusb_device, 0x1F));
312 ntsc = peasycap->ntsc;
313 } else {
314 JOM(8, "... success at second try: %i=rate\n", rate);
315 ntsc = (0 < (rate/2)) ? true : false ;
316 other = true;
317 }
318} else {
319 JOM(8, "... success at first try: %i=rate\n", rate);
320 ntsc = (0 < rate/2) ? true : false ;
321}
322if (true == ntsc)
323 JOM(8, "true=ntsc\n");
324else
325 JOM(8, "false=ntsc\n");
229/*---------------------------------------------------------------------------*/ 326/*---------------------------------------------------------------------------*/
230#if defined(PREFER_NTSC)
231 327
232rc = adjust_standard(peasycap, V4L2_STD_NTSC_M); 328rc = setup_stk(peasycap->pusb_device, ntsc);
233if (0 == rc) 329if (0 == rc)
234 JOT(8, "adjust_standard(.,NTSC_M) OK\n"); 330 JOM(4, "setup_stk() OK\n");
235else { 331else {
236 SAY("ERROR: adjust_standard(.,NTSC_M) returned %i\n", rc); 332 SAM("ERROR: setup_stk() returned %i\n", rc);
237 return -EFAULT; 333 return -EFAULT;
238} 334}
239rc = adjust_format(peasycap, 640, 480, V4L2_PIX_FMT_UYVY, V4L2_FIELD_NONE, \ 335rc = setup_saa(peasycap->pusb_device, ntsc);
240 false); 336if (0 == rc)
241if (0 <= rc) 337 JOM(4, "setup_saa() OK\n");
242 JOT(8, "adjust_format(.,640,480,UYVY) OK\n");
243else { 338else {
244 SAY("ERROR: adjust_format(.,640,480,UYVY) returned %i\n", rc); 339 SAM("ERROR: setup_saa() returned %i\n", rc);
245 return -EFAULT; 340 return -EFAULT;
246} 341}
247 342
248#else 343for (i = 0; i < 180; i++)
344 peasycap->merit[i] = 0;
345peasycap->video_eof = 0;
346peasycap->audio_eof = 0;
347do_gettimeofday(&peasycap->timeval7);
348/*---------------------------------------------------------------------------*/
349/*
350 * RESTORE INPUT AND FORCE REFRESH OF STANDARD, FORMAT, ETC.
351 *
352 * WHILE THIS PROCEDURE IS IN PROGRESS, SOME IOCTL COMMANDS WILL RETURN -EBUSY.
353*/
354/*---------------------------------------------------------------------------*/
355peasycap->input = -8192;
356peasycap->standard_offset = -8192;
357if (true == other) {
358 peasycap_standard = &easycap_standard[0];
359 while (0xFFFF != peasycap_standard->mask) {
360 if (true == ntsc) {
361 if (NTSC_M == \
362 peasycap_standard->v4l2_standard.index) {
363 peasycap->inputset[input].standard_offset = \
364 peasycap_standard - \
365 &easycap_standard[0];
366 break;
367 }
368 } else {
369 if (PAL_BGHIN == \
370 peasycap_standard->v4l2_standard.index) {
371 peasycap->inputset[input].standard_offset = \
372 peasycap_standard -
373 &easycap_standard[0];
374 break;
375 }
376 }
377 peasycap_standard++;
378 }
379 if (0xFFFF == peasycap_standard->mask) {
380 SAM("ERROR: standard not found\n");
381 return -EINVAL;
382 }
383JOM(8, "%i=peasycap->inputset[%i].standard_offset\n", \
384 peasycap->inputset[input].standard_offset, input);
385}
386peasycap->format_offset = -8192;
387peasycap->brightness = -8192;
388peasycap->contrast = -8192;
389peasycap->saturation = -8192;
390peasycap->hue = -8192;
391
392rc = newinput(peasycap, input);
249 393
250rc = adjust_standard(peasycap, \
251 (V4L2_STD_PAL_B | V4L2_STD_PAL_G | V4L2_STD_PAL_H | \
252 V4L2_STD_PAL_I | V4L2_STD_PAL_N));
253if (0 == rc) 394if (0 == rc)
254 JOT(8, "adjust_standard(.,PAL_BGHIN) OK\n"); 395 JOM(4, "restored input, standard and format\n");
255else { 396else {
256 SAY("ERROR: adjust_standard(.,PAL_BGHIN) returned %i\n", rc); 397 SAM("ERROR: newinput(.,%i) returned %i\n", rc, input);
257 return -EFAULT; 398 return -EFAULT;
258} 399}
259rc = adjust_format(peasycap, 640, 480, V4L2_PIX_FMT_UYVY, V4L2_FIELD_NONE, \ 400if (true == peasycap->ntsc)
260 false); 401 JOM(8, "true=peasycap->ntsc\n");
261if (0 <= rc) 402else
262 JOT(8, "adjust_format(.,640,480,uyvy,false) OK\n"); 403 JOM(8, "false=peasycap->ntsc\n");
263else { 404
264 SAY("ERROR: adjust_format(.,640,480,uyvy,false) returned %i\n", rc); 405if (0 > peasycap->input) {
406 SAM("MISTAKE: %i=peasycap->input\n", peasycap->input);
407 return -ENOENT;
408}
409if (0 > peasycap->standard_offset) {
410 SAM("MISTAKE: %i=peasycap->standard_offset\n", \
411 peasycap->standard_offset);
412 return -ENOENT;
413}
414if (0 > peasycap->format_offset) {
415 SAM("MISTAKE: %i=peasycap->format_offset\n", \
416 peasycap->format_offset);
417 return -ENOENT;
418}
419if (0 > peasycap->brightness) {
420 SAM("MISTAKE: %i=peasycap->brightness\n", peasycap->brightness);
421 return -ENOENT;
422}
423if (0 > peasycap->contrast) {
424 SAM("MISTAKE: %i=peasycap->contrast\n", peasycap->contrast);
425 return -ENOENT;
426}
427if (0 > peasycap->saturation) {
428 SAM("MISTAKE: %i=peasycap->saturation\n", peasycap->saturation);
429 return -ENOENT;
430}
431if (0 > peasycap->hue) {
432 SAM("MISTAKE: %i=peasycap->hue\n", peasycap->hue);
433 return -ENOENT;
434}
435return 0;
436}
437/*****************************************************************************/
438/*---------------------------------------------------------------------------*/
439/*
440 * IF THE REQUESTED INPUT IS THE SAME AS THE EXISTING INPUT, DO NOTHING.
441 * OTHERWISE:
442 * KILL URBS, CLEAR FIELD AND FRAME BUFFERS AND RESET THEIR
443 * _read AND _fill POINTERS.
444 * SELECT THE NEW INPUT.
445 * ADJUST THE STANDARD, FORMAT, BRIGHTNESS, CONTRAST, SATURATION AND HUE
446 * ON THE BASIS OF INFORMATION IN STRUCTURE easycap.inputset[input].
447 * RESUBMIT THE URBS IF STREAMING WAS ALREADY IN PROGRESS.
448 *
449 * NOTE:
450 * THIS ROUTINE MAY BE CALLED FREQUENTLY BY ZONEMINDER VIA IOCTL,
451 * SO IT SHOULD WRITE ONLY SPARINGLY TO THE LOGFILE.
452*/
453/*---------------------------------------------------------------------------*/
454int
455newinput(struct easycap *peasycap, int input)
456{
457int rc, k, m, mood, off;
458int inputnow, video_idlenow, audio_idlenow;
459bool resubmit;
460
461if (NULL == peasycap) {
462 SAY("ERROR: peasycap is NULL\n");
265 return -EFAULT; 463 return -EFAULT;
266} 464}
465JOM(8, "%i=input sought\n", input);
267 466
268#endif /* !PREFER_NTSC*/ 467if (0 > input && INPUT_MANY <= input)
468 return -ENOENT;
469inputnow = peasycap->input;
470if (input == inputnow)
471 return 0;
269/*---------------------------------------------------------------------------*/ 472/*---------------------------------------------------------------------------*/
270rc = adjust_brightness(peasycap, -8192); 473/*
474 * IF STREAMING IS IN PROGRESS THE URBS ARE KILLED AT THIS
475 * STAGE AND WILL BE RESUBMITTED PRIOR TO EXIT FROM THE ROUTINE.
476 * IF NO STREAMING IS IN PROGRESS NO URBS WILL BE SUBMITTED BY THE
477 * ROUTINE.
478*/
479/*---------------------------------------------------------------------------*/
480video_idlenow = peasycap->video_idle;
481audio_idlenow = peasycap->audio_idle;
482
483peasycap->video_idle = 1;
484peasycap->audio_idle = 1;
485if (peasycap->video_isoc_streaming) {
486 resubmit = true;
487 kill_video_urbs(peasycap);
488} else
489 resubmit = false;
490/*---------------------------------------------------------------------------*/
491if (NULL == peasycap->pusb_device) {
492 SAM("ERROR: peasycap->pusb_device is NULL\n");
493 return -ENODEV;
494}
495rc = usb_set_interface(peasycap->pusb_device,
496 peasycap->video_interface, \
497 peasycap->video_altsetting_off);
271if (0 != rc) { 498if (0 != rc) {
272 SAY("ERROR: adjust_brightness(default) returned %i\n", rc); 499 SAM("ERROR: usb_set_interface() returned %i\n", rc);
273 return -EFAULT; 500 return -EFAULT;
274} 501}
275rc = adjust_contrast(peasycap, -8192); 502rc = stop_100(peasycap->pusb_device);
276if (0 != rc) { 503if (0 != rc) {
277 SAY("ERROR: adjust_contrast(default) returned %i\n", rc); 504 SAM("ERROR: stop_100() returned %i\n", rc);
278 return -EFAULT; 505 return -EFAULT;
279} 506}
280rc = adjust_saturation(peasycap, -8192); 507for (k = 0; k < FIELD_BUFFER_MANY; k++) {
281if (0 != rc) { 508 for (m = 0; m < FIELD_BUFFER_SIZE/PAGE_SIZE; m++)
282 SAY("ERROR: adjust_saturation(default) returned %i\n", rc); 509 memset(peasycap->field_buffer[k][m].pgo, 0, PAGE_SIZE);
283 return -EFAULT;
284} 510}
285rc = adjust_hue(peasycap, -8192); 511for (k = 0; k < FRAME_BUFFER_MANY; k++) {
286if (0 != rc) { 512 for (m = 0; m < FRAME_BUFFER_SIZE/PAGE_SIZE; m++)
287 SAY("ERROR: adjust_hue(default) returned %i\n", rc); 513 memset(peasycap->frame_buffer[k][m].pgo, 0, PAGE_SIZE);
288 return -EFAULT; 514}
515peasycap->field_page = 0;
516peasycap->field_read = 0;
517peasycap->field_fill = 0;
518
519peasycap->frame_read = 0;
520peasycap->frame_fill = 0;
521for (k = 0; k < peasycap->input; k++) {
522 (peasycap->frame_fill)++;
523 if (peasycap->frame_buffer_many <= peasycap->frame_fill)
524 peasycap->frame_fill = 0;
289} 525}
526peasycap->input = input;
527select_input(peasycap->pusb_device, peasycap->input, 9);
290/*---------------------------------------------------------------------------*/ 528/*---------------------------------------------------------------------------*/
291rc = usb_set_interface(peasycap->pusb_device, peasycap->video_interface, \ 529if (input == peasycap->inputset[input].input) {
292 peasycap->video_altsetting_on); 530 off = peasycap->inputset[input].standard_offset;
293if (0 == rc) 531 if (off != peasycap->standard_offset) {
294 JOT(8, "usb_set_interface(.,%i,%i) OK\n", peasycap->video_interface, \ 532 rc = adjust_standard(peasycap, \
295 peasycap->video_altsetting_on); 533 easycap_standard[off].v4l2_standard.id);
296else { 534 if (0 != rc) {
297 SAY("ERROR: usb_set_interface() returned %i\n", rc); 535 SAM("ERROR: adjust_standard() returned %i\n", rc);
536 return -EFAULT;
537 }
538 JOM(8, "%i=peasycap->standard_offset\n", \
539 peasycap->standard_offset);
540 } else {
541 JOM(8, "%i=peasycap->standard_offset unchanged\n", \
542 peasycap->standard_offset);
543 }
544 off = peasycap->inputset[input].format_offset;
545 if (off != peasycap->format_offset) {
546 rc = adjust_format(peasycap, \
547 easycap_format[off].v4l2_format.fmt.pix.width, \
548 easycap_format[off].v4l2_format.fmt.pix.height, \
549 easycap_format[off].v4l2_format.fmt.pix.pixelformat, \
550 easycap_format[off].v4l2_format.fmt.pix.field, false);
551 if (0 > rc) {
552 SAM("ERROR: adjust_format() returned %i\n", rc);
553 return -EFAULT;
554 }
555 JOM(8, "%i=peasycap->format_offset\n", peasycap->format_offset);
556 } else {
557 JOM(8, "%i=peasycap->format_offset unchanged\n", \
558 peasycap->format_offset);
559 }
560 mood = peasycap->inputset[input].brightness;
561 if (mood != peasycap->brightness) {
562 rc = adjust_brightness(peasycap, mood);
563 if (0 != rc) {
564 SAM("ERROR: adjust_brightness returned %i\n", rc);
565 return -EFAULT;
566 }
567 JOM(8, "%i=peasycap->brightness\n", peasycap->brightness);
568 }
569 mood = peasycap->inputset[input].contrast;
570 if (mood != peasycap->contrast) {
571 rc = adjust_contrast(peasycap, mood);
572 if (0 != rc) {
573 SAM("ERROR: adjust_contrast returned %i\n", rc);
574 return -EFAULT;
575 }
576 JOM(8, "%i=peasycap->contrast\n", peasycap->contrast);
577 }
578 mood = peasycap->inputset[input].saturation;
579 if (mood != peasycap->saturation) {
580 rc = adjust_saturation(peasycap, mood);
581 if (0 != rc) {
582 SAM("ERROR: adjust_saturation returned %i\n", rc);
583 return -EFAULT;
584 }
585 JOM(8, "%i=peasycap->saturation\n", peasycap->saturation);
586 }
587 mood = peasycap->inputset[input].hue;
588 if (mood != peasycap->hue) {
589 rc = adjust_hue(peasycap, mood);
590 if (0 != rc) {
591 SAM("ERROR: adjust_hue returned %i\n", rc);
592 return -EFAULT;
593 }
594 JOM(8, "%i=peasycap->hue\n", peasycap->hue);
595 }
596} else {
597 SAM("MISTAKE: easycap.inputset[%i] unpopulated\n", input);
598 return -ENOENT;
599}
600/*---------------------------------------------------------------------------*/
601if (NULL == peasycap->pusb_device) {
602 SAM("ERROR: peasycap->pusb_device is NULL\n");
603 return -ENODEV;
604}
605rc = usb_set_interface(peasycap->pusb_device,
606 peasycap->video_interface, \
607 peasycap->video_altsetting_on);
608if (0 != rc) {
609 SAM("ERROR: usb_set_interface() returned %i\n", rc);
298 return -EFAULT; 610 return -EFAULT;
299} 611}
300rc = start_100(p); 612rc = start_100(peasycap->pusb_device);
301if (0 == rc) 613if (0 != rc) {
302 JOT(8, "start_100() OK\n"); 614 SAM("ERROR: start_100() returned %i\n", rc);
303else {
304 SAY("ERROR: start_100() returned %i\n", rc);
305 return -EFAULT; 615 return -EFAULT;
306} 616}
617if (true == resubmit)
618 submit_video_urbs(peasycap);
619
307peasycap->video_isoc_sequence = VIDEO_ISOC_BUFFER_MANY - 1; 620peasycap->video_isoc_sequence = VIDEO_ISOC_BUFFER_MANY - 1;
308peasycap->video_idle = 0; 621peasycap->video_idle = video_idlenow;
622peasycap->audio_idle = audio_idlenow;
309peasycap->video_junk = 0; 623peasycap->video_junk = 0;
310for (i = 0; i < 180; i++)
311 peasycap->merit[i] = 0;
312peasycap->video_eof = 0;
313peasycap->audio_eof = 0;
314 624
315do_gettimeofday(&peasycap->timeval7);
316
317peasycap->fudge = 0;
318
319JOT(4, "finished initialization\n");
320return 0; 625return 0;
321} 626}
322/*****************************************************************************/ 627/*****************************************************************************/
@@ -326,33 +631,25 @@ submit_video_urbs(struct easycap *peasycap)
326struct data_urb *pdata_urb; 631struct data_urb *pdata_urb;
327struct urb *purb; 632struct urb *purb;
328struct list_head *plist_head; 633struct list_head *plist_head;
329int j, isbad, m, rc; 634int j, isbad, nospc, m, rc;
330int isbuf; 635int isbuf;
331 636
332if ((struct list_head *)NULL == peasycap->purb_video_head) { 637if (NULL == peasycap) {
638 SAY("ERROR: peasycap is NULL\n");
639 return -EFAULT;
640}
641
642if (NULL == peasycap->purb_video_head) {
333 SAY("ERROR: peasycap->urb_video_head uninitialized\n"); 643 SAY("ERROR: peasycap->urb_video_head uninitialized\n");
334 return -EFAULT; 644 return -EFAULT;
335} 645}
336if ((struct usb_device *)NULL == peasycap->pusb_device) { 646if (NULL == peasycap->pusb_device) {
337 SAY("ERROR: peasycap->pusb_device is NULL\n"); 647 SAY("ERROR: peasycap->pusb_device is NULL\n");
338 return -EFAULT; 648 return -ENODEV;
339} 649}
340if (!peasycap->video_isoc_streaming) { 650if (!peasycap->video_isoc_streaming) {
341 651 JOM(4, "submission of all video urbs\n");
342 652 isbad = 0; nospc = 0; m = 0;
343
344
345
346
347
348
349 JOT(4, "submission of all video urbs\n");
350 if (0 != ready_saa(peasycap->pusb_device)) {
351 SAY("ERROR: not ready to capture after waiting " \
352 "one second\n");
353 SAY("..... continuing anyway\n");
354 }
355 isbad = 0; m = 0;
356 list_for_each(plist_head, (peasycap->purb_video_head)) { 653 list_for_each(plist_head, (peasycap->purb_video_head)) {
357 pdata_urb = list_entry(plist_head, struct data_urb, list_head); 654 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
358 if (NULL != pdata_urb) { 655 if (NULL != pdata_urb) {
@@ -389,44 +686,57 @@ if (!peasycap->video_isoc_streaming) {
389 rc = usb_submit_urb(purb, GFP_KERNEL); 686 rc = usb_submit_urb(purb, GFP_KERNEL);
390 if (0 != rc) { 687 if (0 != rc) {
391 isbad++; 688 isbad++;
392 SAY("ERROR: usb_submit_urb() failed " \ 689 SAM("ERROR: usb_submit_urb() failed " \
393 "for urb with rc:\n"); 690 "for urb with rc:\n");
394 switch (rc) { 691 switch (rc) {
395 case -ENOMEM: { 692 case -ENOMEM: {
396 SAY("ENOMEM\n"); 693 SAM("ERROR: -ENOMEM=" \
694 "usb_submit_urb()\n");
397 break; 695 break;
398 } 696 }
399 case -ENODEV: { 697 case -ENODEV: {
400 SAY("ENODEV\n"); 698 SAM("ERROR: -ENODEV=" \
699 "usb_submit_urb()\n");
401 break; 700 break;
402 } 701 }
403 case -ENXIO: { 702 case -ENXIO: {
404 SAY("ENXIO\n"); 703 SAM("ERROR: -ENXIO=" \
704 "usb_submit_urb()\n");
405 break; 705 break;
406 } 706 }
407 case -EINVAL: { 707 case -EINVAL: {
408 SAY("EINVAL\n"); 708 SAM("ERROR: -EINVAL=" \
709 "usb_submit_urb()\n");
409 break; 710 break;
410 } 711 }
411 case -EAGAIN: { 712 case -EAGAIN: {
412 SAY("EAGAIN\n"); 713 SAM("ERROR: -EAGAIN=" \
714 "usb_submit_urb()\n");
413 break; 715 break;
414 } 716 }
415 case -EFBIG: { 717 case -EFBIG: {
416 SAY("EFBIG\n"); 718 SAM("ERROR: -EFBIG=" \
719 "usb_submit_urb()\n");
417 break; 720 break;
418 } 721 }
419 case -EPIPE: { 722 case -EPIPE: {
420 SAY("EPIPE\n"); 723 SAM("ERROR: -EPIPE=" \
724 "usb_submit_urb()\n");
421 break; 725 break;
422 } 726 }
423 case -EMSGSIZE: { 727 case -EMSGSIZE: {
424 SAY("EMSGSIZE\n"); 728 SAM("ERROR: -EMSGSIZE=" \
729 "usb_submit_urb()\n");
730 break;
731 }
732 case -ENOSPC: {
733 nospc++;
425 break; 734 break;
426 } 735 }
427 default: { 736 default: {
428 SAY("unknown error code %i\n",\ 737 SAM("ERROR: %i=" \
429 rc); 738 "usb_submit_urb()\n",\
739 rc);
430 break; 740 break;
431 } 741 }
432 } 742 }
@@ -434,14 +744,20 @@ if (!peasycap->video_isoc_streaming) {
434 m++; 744 m++;
435 } 745 }
436 } else { 746 } else {
437 isbad++; 747 isbad++;
438 } 748 }
439 } else { 749 } else {
440 isbad++; 750 isbad++;
441 } 751 }
442 } 752 }
753 if (nospc) {
754 SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc);
755 SAM("..... possibly inadequate USB bandwidth\n");
756 peasycap->video_eof = 1;
757 }
758
443 if (isbad) { 759 if (isbad) {
444 JOT(4, "attempting cleanup instead of submitting\n"); 760 JOM(4, "attempting cleanup instead of submitting\n");
445 list_for_each(plist_head, (peasycap->purb_video_head)) { 761 list_for_each(plist_head, (peasycap->purb_video_head)) {
446 pdata_urb = list_entry(plist_head, struct data_urb, \ 762 pdata_urb = list_entry(plist_head, struct data_urb, \
447 list_head); 763 list_head);
@@ -454,16 +770,10 @@ if (!peasycap->video_isoc_streaming) {
454 peasycap->video_isoc_streaming = 0; 770 peasycap->video_isoc_streaming = 0;
455 } else { 771 } else {
456 peasycap->video_isoc_streaming = 1; 772 peasycap->video_isoc_streaming = 1;
457 JOT(4, "submitted %i video urbs\n", m); 773 JOM(4, "submitted %i video urbs\n", m);
458 } 774 }
459
460
461
462
463
464
465} else { 775} else {
466 JOT(4, "already streaming video urbs\n"); 776 JOM(4, "already streaming video urbs\n");
467} 777}
468return 0; 778return 0;
469} 779}
@@ -475,35 +785,32 @@ int m;
475struct list_head *plist_head; 785struct list_head *plist_head;
476struct data_urb *pdata_urb; 786struct data_urb *pdata_urb;
477 787
478if ((struct easycap *)NULL == peasycap) { 788if (NULL == peasycap) {
479 SAY("ERROR: peasycap is NULL\n"); 789 SAY("ERROR: peasycap is NULL\n");
480 return -EFAULT; 790 return -EFAULT;
481} 791}
482if (peasycap->video_isoc_streaming) { 792if (peasycap->video_isoc_streaming) {
483
484
485
486 if ((struct list_head *)NULL != peasycap->purb_video_head) { 793 if ((struct list_head *)NULL != peasycap->purb_video_head) {
487 peasycap->video_isoc_streaming = 0; 794 peasycap->video_isoc_streaming = 0;
488 JOT(4, "killing video urbs\n"); 795 JOM(4, "killing video urbs\n");
489 m = 0; 796 m = 0;
490 list_for_each(plist_head, (peasycap->purb_video_head)) { 797 list_for_each(plist_head, (peasycap->purb_video_head)) {
491 pdata_urb = list_entry(plist_head, struct data_urb, \ 798 pdata_urb = list_entry(plist_head, struct data_urb, \
492 list_head); 799 list_head);
493 if ((struct data_urb *)NULL != pdata_urb) { 800 if (NULL != pdata_urb) {
494 if ((struct urb *)NULL != pdata_urb->purb) { 801 if (NULL != pdata_urb->purb) {
495 usb_kill_urb(pdata_urb->purb); 802 usb_kill_urb(pdata_urb->purb);
496 m++; 803 m++;
497 } 804 }
498 } 805 }
499 } 806 }
500 JOT(4, "%i video urbs killed\n", m); 807 JOM(4, "%i video urbs killed\n", m);
501 } else { 808 } else {
502 SAY("ERROR: peasycap->purb_video_head is NULL\n"); 809 SAM("ERROR: peasycap->purb_video_head is NULL\n");
503 return -EFAULT; 810 return -EFAULT;
504 } 811 }
505} else { 812} else {
506 JOT(8, "%i=video_isoc_streaming, no video urbs killed\n", \ 813 JOM(8, "%i=video_isoc_streaming, no video urbs killed\n", \
507 peasycap->video_isoc_streaming); 814 peasycap->video_isoc_streaming);
508} 815}
509return 0; 816return 0;
@@ -533,11 +840,15 @@ if (NULL == peasycap) {
533 SAY("ending unsuccessfully\n"); 840 SAY("ending unsuccessfully\n");
534 return -EFAULT; 841 return -EFAULT;
535} 842}
843if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
844 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
845 return -EFAULT;
846}
536if (0 != kill_video_urbs(peasycap)) { 847if (0 != kill_video_urbs(peasycap)) {
537 SAY("ERROR: kill_video_urbs() failed\n"); 848 SAM("ERROR: kill_video_urbs() failed\n");
538 return -EFAULT; 849 return -EFAULT;
539} 850}
540JOT(4, "ending successfully\n"); 851JOM(4, "ending successfully\n");
541/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 852/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
542#else 853#else
543# 854#
@@ -550,63 +861,45 @@ return 0;
550/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 861/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
551#if defined(EASYCAP_IS_VIDEODEV_CLIENT) 862#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
552int 863int
553videodev_release(struct video_device *pvd) 864videodev_release(struct video_device *pvideo_device)
554{ 865{
555struct easycap *peasycap; 866struct easycap *peasycap;
556int i, j, k;
557 867
558JOT(4, "\n"); 868JOT(4, "\n");
559 869
560k = 0; 870peasycap = video_get_drvdata(pvideo_device);
561for (i = 0; i < video_device_many; i++) { 871if (NULL == peasycap) {
562 pvideo_device = pvideo_array[i]; 872 SAY("ERROR: peasycap is NULL\n");
563 if ((struct video_device *)NULL != pvideo_device) {
564 if (pvd->minor == pvideo_device->minor) {
565 peasycap = (struct easycap *)\
566 video_get_drvdata(pvideo_device);
567 if ((struct easycap *)NULL == peasycap) {
568 SAY("ERROR: peasycap is NULL\n");
569 SAY("ending unsuccessfully\n");
570 return -EFAULT;
571 }
572 if (0 != kill_video_urbs(peasycap)) {
573 SAY("ERROR: kill_video_urbs() failed\n");
574 return -EFAULT;
575 }
576 JOT(4, "freeing video_device structure: " \
577 "/dev/video%i\n", i);
578 kfree((void *)pvideo_device);
579 for (j = i; j < (VIDEO_DEVICE_MANY - 1); j++)
580 pvideo_array[j] = pvideo_array[j + 1];
581 video_device_many--; k++;
582 break;
583 }
584 }
585}
586if (!k) {
587 SAY("ERROR: lost video_device structure for %i=minor\n", pvd->minor);
588 SAY("cannot free: may cause memory leak\n");
589 SAY("ending unsuccessfully\n"); 873 SAY("ending unsuccessfully\n");
590 return -EFAULT; 874 return -EFAULT;
591} 875}
592 876if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
593JOT(4, "ending successfully\n"); 877 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
878 return -EFAULT;
879}
880if (0 != kill_video_urbs(peasycap)) {
881 SAM("ERROR: kill_video_urbs() failed\n");
882 return -EFAULT;
883}
884JOM(4, "ending successfully\n");
594return 0; 885return 0;
595} 886}
596#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 887#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
597/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ 888/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
598/****************************************************************************/ 889/*****************************************************************************/
599/*--------------------------------------------------------------------------*/ 890/*--------------------------------------------------------------------------*/
600/* 891/*
601 * THIS FUNCTION IS CALLED FROM WITHIN easycap_usb_disconnect(). 892 * THIS FUNCTION IS CALLED FROM WITHIN easycap_usb_disconnect() AND IS
602 * BY THIS STAGE THE DEVICE HAS ALREADY BEEN PHYSICALLY UNPLUGGED. 893 * PROTECTED BY SEMAPHORES SET AND CLEARED BY easycap_usb_disconnect().
603 * peasycap->pusb_device IS NO LONGER VALID AND SHOULD HAVE BEEN SET TO NULL. 894 *
895 * BY THIS STAGE THE DEVICE HAS ALREADY BEEN PHYSICALLY UNPLUGGED, SO
896 * peasycap->pusb_device IS NO LONGER VALID.
604 */ 897 */
605/*---------------------------------------------------------------------------*/ 898/*---------------------------------------------------------------------------*/
606void 899void
607easycap_delete(struct kref *pkref) 900easycap_delete(struct kref *pkref)
608{ 901{
609int k, m, lost; 902int k, m, gone, kd;
610int allocation_video_urb, allocation_video_page, allocation_video_struct; 903int allocation_video_urb, allocation_video_page, allocation_video_struct;
611int allocation_audio_urb, allocation_audio_page, allocation_audio_struct; 904int allocation_audio_urb, allocation_audio_page, allocation_audio_struct;
612int registered_video, registered_audio; 905int registered_video, registered_audio;
@@ -617,22 +910,27 @@ struct list_head *plist_head, *plist_next;
617JOT(4, "\n"); 910JOT(4, "\n");
618 911
619peasycap = container_of(pkref, struct easycap, kref); 912peasycap = container_of(pkref, struct easycap, kref);
620if ((struct easycap *)NULL == peasycap) { 913if (NULL == peasycap) {
621 SAY("ERROR: peasycap is NULL: cannot perform deletions\n"); 914 SAM("ERROR: peasycap is NULL: cannot perform deletions\n");
915 return;
916}
917if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
918 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
622 return; 919 return;
623} 920}
921kd = isdongle(peasycap);
624/*---------------------------------------------------------------------------*/ 922/*---------------------------------------------------------------------------*/
625/* 923/*
626 * FREE VIDEO. 924 * FREE VIDEO.
627 */ 925 */
628/*---------------------------------------------------------------------------*/ 926/*---------------------------------------------------------------------------*/
629if ((struct list_head *)NULL != peasycap->purb_video_head) { 927if ((struct list_head *)NULL != peasycap->purb_video_head) {
630 JOT(4, "freeing video urbs\n"); 928 JOM(4, "freeing video urbs\n");
631 m = 0; 929 m = 0;
632 list_for_each(plist_head, (peasycap->purb_video_head)) { 930 list_for_each(plist_head, (peasycap->purb_video_head)) {
633 pdata_urb = list_entry(plist_head, struct data_urb, list_head); 931 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
634 if (NULL == pdata_urb) 932 if (NULL == pdata_urb)
635 JOT(4, "ERROR: pdata_urb is NULL\n"); 933 JOM(4, "ERROR: pdata_urb is NULL\n");
636 else { 934 else {
637 if ((struct urb *)NULL != pdata_urb->purb) { 935 if ((struct urb *)NULL != pdata_urb->purb) {
638 usb_free_urb(pdata_urb->purb); 936 usb_free_urb(pdata_urb->purb);
@@ -643,9 +941,9 @@ if ((struct list_head *)NULL != peasycap->purb_video_head) {
643 } 941 }
644 } 942 }
645 943
646 JOT(4, "%i video urbs freed\n", m); 944 JOM(4, "%i video urbs freed\n", m);
647/*---------------------------------------------------------------------------*/ 945/*---------------------------------------------------------------------------*/
648 JOT(4, "freeing video data_urb structures.\n"); 946 JOM(4, "freeing video data_urb structures.\n");
649 m = 0; 947 m = 0;
650 list_for_each_safe(plist_head, plist_next, peasycap->purb_video_head) { 948 list_for_each_safe(plist_head, plist_next, peasycap->purb_video_head) {
651 pdata_urb = list_entry(plist_head, struct data_urb, list_head); 949 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
@@ -656,14 +954,12 @@ if ((struct list_head *)NULL != peasycap->purb_video_head) {
656 m++; 954 m++;
657 } 955 }
658 } 956 }
659 JOT(4, "%i video data_urb structures freed\n", m); 957 JOM(4, "%i video data_urb structures freed\n", m);
660 JOT(4, "setting peasycap->purb_video_head=NULL\n"); 958 JOM(4, "setting peasycap->purb_video_head=NULL\n");
661 peasycap->purb_video_head = (struct list_head *)NULL; 959 peasycap->purb_video_head = (struct list_head *)NULL;
662 } else {
663JOT(4, "peasycap->purb_video_head is NULL\n");
664} 960}
665/*---------------------------------------------------------------------------*/ 961/*---------------------------------------------------------------------------*/
666JOT(4, "freeing video isoc buffers.\n"); 962JOM(4, "freeing video isoc buffers.\n");
667m = 0; 963m = 0;
668for (k = 0; k < VIDEO_ISOC_BUFFER_MANY; k++) { 964for (k = 0; k < VIDEO_ISOC_BUFFER_MANY; k++) {
669 if ((void *)NULL != peasycap->video_isoc_buffer[k].pgo) { 965 if ((void *)NULL != peasycap->video_isoc_buffer[k].pgo) {
@@ -676,10 +972,10 @@ for (k = 0; k < VIDEO_ISOC_BUFFER_MANY; k++) {
676 m++; 972 m++;
677 } 973 }
678} 974}
679JOT(4, "isoc video buffers freed: %i pages\n", m * (0x01 << VIDEO_ISOC_ORDER)); 975JOM(4, "isoc video buffers freed: %i pages\n", m * (0x01 << VIDEO_ISOC_ORDER));
680/*---------------------------------------------------------------------------*/ 976/*---------------------------------------------------------------------------*/
681JOT(4, "freeing video field buffers.\n"); 977JOM(4, "freeing video field buffers.\n");
682lost = 0; 978gone = 0;
683for (k = 0; k < FIELD_BUFFER_MANY; k++) { 979for (k = 0; k < FIELD_BUFFER_MANY; k++) {
684 for (m = 0; m < FIELD_BUFFER_SIZE/PAGE_SIZE; m++) { 980 for (m = 0; m < FIELD_BUFFER_SIZE/PAGE_SIZE; m++) {
685 if ((void *)NULL != peasycap->field_buffer[k][m].pgo) { 981 if ((void *)NULL != peasycap->field_buffer[k][m].pgo) {
@@ -687,14 +983,14 @@ for (k = 0; k < FIELD_BUFFER_MANY; k++) {
687 (peasycap->field_buffer[k][m].pgo)); 983 (peasycap->field_buffer[k][m].pgo));
688 peasycap->field_buffer[k][m].pgo = (void *)NULL; 984 peasycap->field_buffer[k][m].pgo = (void *)NULL;
689 peasycap->allocation_video_page -= 1; 985 peasycap->allocation_video_page -= 1;
690 lost++; 986 gone++;
691 } 987 }
692 } 988 }
693} 989}
694JOT(4, "video field buffers freed: %i pages\n", lost); 990JOM(4, "video field buffers freed: %i pages\n", gone);
695/*---------------------------------------------------------------------------*/ 991/*---------------------------------------------------------------------------*/
696JOT(4, "freeing video frame buffers.\n"); 992JOM(4, "freeing video frame buffers.\n");
697lost = 0; 993gone = 0;
698for (k = 0; k < FRAME_BUFFER_MANY; k++) { 994for (k = 0; k < FRAME_BUFFER_MANY; k++) {
699 for (m = 0; m < FRAME_BUFFER_SIZE/PAGE_SIZE; m++) { 995 for (m = 0; m < FRAME_BUFFER_SIZE/PAGE_SIZE; m++) {
700 if ((void *)NULL != peasycap->frame_buffer[k][m].pgo) { 996 if ((void *)NULL != peasycap->frame_buffer[k][m].pgo) {
@@ -702,23 +998,23 @@ for (k = 0; k < FRAME_BUFFER_MANY; k++) {
702 (peasycap->frame_buffer[k][m].pgo)); 998 (peasycap->frame_buffer[k][m].pgo));
703 peasycap->frame_buffer[k][m].pgo = (void *)NULL; 999 peasycap->frame_buffer[k][m].pgo = (void *)NULL;
704 peasycap->allocation_video_page -= 1; 1000 peasycap->allocation_video_page -= 1;
705 lost++; 1001 gone++;
706 } 1002 }
707 } 1003 }
708} 1004}
709JOT(4, "video frame buffers freed: %i pages\n", lost); 1005JOM(4, "video frame buffers freed: %i pages\n", gone);
710/*---------------------------------------------------------------------------*/ 1006/*---------------------------------------------------------------------------*/
711/* 1007/*
712 * FREE AUDIO. 1008 * FREE AUDIO.
713 */ 1009 */
714/*---------------------------------------------------------------------------*/ 1010/*---------------------------------------------------------------------------*/
715if ((struct list_head *)NULL != peasycap->purb_audio_head) { 1011if ((struct list_head *)NULL != peasycap->purb_audio_head) {
716 JOT(4, "freeing audio urbs\n"); 1012 JOM(4, "freeing audio urbs\n");
717 m = 0; 1013 m = 0;
718 list_for_each(plist_head, (peasycap->purb_audio_head)) { 1014 list_for_each(plist_head, (peasycap->purb_audio_head)) {
719 pdata_urb = list_entry(plist_head, struct data_urb, list_head); 1015 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
720 if (NULL == pdata_urb) 1016 if (NULL == pdata_urb)
721 JOT(4, "ERROR: pdata_urb is NULL\n"); 1017 JOM(4, "ERROR: pdata_urb is NULL\n");
722 else { 1018 else {
723 if ((struct urb *)NULL != pdata_urb->purb) { 1019 if ((struct urb *)NULL != pdata_urb->purb) {
724 usb_free_urb(pdata_urb->purb); 1020 usb_free_urb(pdata_urb->purb);
@@ -728,9 +1024,9 @@ if ((struct list_head *)NULL != peasycap->purb_audio_head) {
728 } 1024 }
729 } 1025 }
730 } 1026 }
731 JOT(4, "%i audio urbs freed\n", m); 1027 JOM(4, "%i audio urbs freed\n", m);
732/*---------------------------------------------------------------------------*/ 1028/*---------------------------------------------------------------------------*/
733 JOT(4, "freeing audio data_urb structures.\n"); 1029 JOM(4, "freeing audio data_urb structures.\n");
734 m = 0; 1030 m = 0;
735 list_for_each_safe(plist_head, plist_next, peasycap->purb_audio_head) { 1031 list_for_each_safe(plist_head, plist_next, peasycap->purb_audio_head) {
736 pdata_urb = list_entry(plist_head, struct data_urb, list_head); 1032 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
@@ -741,14 +1037,12 @@ if ((struct list_head *)NULL != peasycap->purb_audio_head) {
741 m++; 1037 m++;
742 } 1038 }
743 } 1039 }
744JOT(4, "%i audio data_urb structures freed\n", m); 1040JOM(4, "%i audio data_urb structures freed\n", m);
745JOT(4, "setting peasycap->purb_audio_head=NULL\n"); 1041JOM(4, "setting peasycap->purb_audio_head=NULL\n");
746peasycap->purb_audio_head = (struct list_head *)NULL; 1042peasycap->purb_audio_head = (struct list_head *)NULL;
747} else {
748JOT(4, "peasycap->purb_audio_head is NULL\n");
749} 1043}
750/*---------------------------------------------------------------------------*/ 1044/*---------------------------------------------------------------------------*/
751JOT(4, "freeing audio isoc buffers.\n"); 1045JOM(4, "freeing audio isoc buffers.\n");
752m = 0; 1046m = 0;
753for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) { 1047for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) {
754 if ((void *)NULL != peasycap->audio_isoc_buffer[k].pgo) { 1048 if ((void *)NULL != peasycap->audio_isoc_buffer[k].pgo) {
@@ -761,22 +1055,22 @@ for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) {
761 m++; 1055 m++;
762 } 1056 }
763} 1057}
764JOT(4, "easysnd_delete(): isoc audio buffers freed: %i pages\n", \ 1058JOM(4, "easysnd_delete(): isoc audio buffers freed: %i pages\n", \
765 m * (0x01 << AUDIO_ISOC_ORDER)); 1059 m * (0x01 << AUDIO_ISOC_ORDER));
766/*---------------------------------------------------------------------------*/ 1060/*---------------------------------------------------------------------------*/
767JOT(4, "freeing audio buffers.\n"); 1061JOM(4, "freeing audio buffers.\n");
768lost = 0; 1062gone = 0;
769for (k = 0; k < peasycap->audio_buffer_page_many; k++) { 1063for (k = 0; k < peasycap->audio_buffer_page_many; k++) {
770 if ((void *)NULL != peasycap->audio_buffer[k].pgo) { 1064 if ((void *)NULL != peasycap->audio_buffer[k].pgo) {
771 free_page((unsigned long)(peasycap->audio_buffer[k].pgo)); 1065 free_page((unsigned long)(peasycap->audio_buffer[k].pgo));
772 peasycap->audio_buffer[k].pgo = (void *)NULL; 1066 peasycap->audio_buffer[k].pgo = (void *)NULL;
773 peasycap->allocation_audio_page -= 1; 1067 peasycap->allocation_audio_page -= 1;
774 lost++; 1068 gone++;
775 } 1069 }
776} 1070}
777JOT(4, "easysnd_delete(): audio buffers freed: %i pages\n", lost); 1071JOM(4, "easysnd_delete(): audio buffers freed: %i pages\n", gone);
778/*---------------------------------------------------------------------------*/ 1072/*---------------------------------------------------------------------------*/
779JOT(4, "freeing easycap structure.\n"); 1073JOM(4, "freeing easycap structure.\n");
780allocation_video_urb = peasycap->allocation_video_urb; 1074allocation_video_urb = peasycap->allocation_video_urb;
781allocation_video_page = peasycap->allocation_video_page; 1075allocation_video_page = peasycap->allocation_video_page;
782allocation_video_struct = peasycap->allocation_video_struct; 1076allocation_video_struct = peasycap->allocation_video_struct;
@@ -785,15 +1079,16 @@ allocation_audio_urb = peasycap->allocation_audio_urb;
785allocation_audio_page = peasycap->allocation_audio_page; 1079allocation_audio_page = peasycap->allocation_audio_page;
786allocation_audio_struct = peasycap->allocation_audio_struct; 1080allocation_audio_struct = peasycap->allocation_audio_struct;
787registered_audio = peasycap->registered_audio; 1081registered_audio = peasycap->registered_audio;
788m = 0; 1082
789if ((struct easycap *)NULL != peasycap) { 1083kfree(peasycap);
790 kfree(peasycap); peasycap = (struct easycap *)NULL; 1084if (0 <= kd && DONGLE_MANY > kd) {
1085 easycap_dongle[kd].peasycap = (struct easycap *)NULL;
1086 JOT(4, " null-->easycap_dongle[%i].peasycap\n", kd);
791 allocation_video_struct -= sizeof(struct easycap); 1087 allocation_video_struct -= sizeof(struct easycap);
792 m++; 1088} else {
1089 SAY("ERROR: cannot purge easycap_dongle[].peasycap");
793} 1090}
794JOT(4, "%i easycap structure freed\n", m);
795/*---------------------------------------------------------------------------*/ 1091/*---------------------------------------------------------------------------*/
796
797SAY("%8i= video urbs after all deletions\n", allocation_video_urb); 1092SAY("%8i= video urbs after all deletions\n", allocation_video_urb);
798SAY("%8i= video pages after all deletions\n", allocation_video_page); 1093SAY("%8i= video pages after all deletions\n", allocation_video_page);
799SAY("%8i= video structs after all deletions\n", allocation_video_struct); 1094SAY("%8i= video structs after all deletions\n", allocation_video_struct);
@@ -810,27 +1105,85 @@ return;
810unsigned int easycap_poll(struct file *file, poll_table *wait) 1105unsigned int easycap_poll(struct file *file, poll_table *wait)
811{ 1106{
812struct easycap *peasycap; 1107struct easycap *peasycap;
1108int rc, kd;
813 1109
814JOT(8, "\n"); 1110JOT(8, "\n");
815 1111
816if (NULL == ((poll_table *)wait)) 1112if (NULL == ((poll_table *)wait))
817 JOT(8, "WARNING: poll table pointer is NULL ... continuing\n"); 1113 JOT(8, "WARNING: poll table pointer is NULL ... continuing\n");
818if (NULL == ((struct file *)file)) { 1114if ((struct file *)NULL == file) {
819 SAY("ERROR: file pointer is NULL\n"); 1115 SAY("ERROR: file pointer is NULL\n");
820 return -EFAULT; 1116 return -ERESTARTSYS;
821} 1117}
822peasycap = file->private_data; 1118peasycap = file->private_data;
823if (NULL == peasycap) { 1119if (NULL == peasycap) {
824 SAY("ERROR: peasycap is NULL\n"); 1120 SAY("ERROR: peasycap is NULL\n");
825 return -EFAULT; 1121 return -EFAULT;
826} 1122}
1123if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
1124 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
1125 return -EFAULT;
1126}
1127if (NULL == peasycap->pusb_device) {
1128 SAY("ERROR: peasycap->pusb_device is NULL\n");
1129 return -EFAULT;
1130}
1131/*---------------------------------------------------------------------------*/
1132kd = isdongle(peasycap);
1133if (0 <= kd && DONGLE_MANY > kd) {
1134 if (mutex_lock_interruptible(&easycap_dongle[kd].mutex_video)) {
1135 SAY("ERROR: cannot down easycap_dongle[%i].mutex_video\n", kd);
1136 return -ERESTARTSYS;
1137 }
1138 JOM(4, "locked easycap_dongle[%i].mutex_video\n", kd);
1139 /*-------------------------------------------------------------------*/
1140 /*
1141 * MEANWHILE, easycap_usb_disconnect() MAY HAVE FREED POINTER
1142 * peasycap, IN WHICH CASE A REPEAT CALL TO isdongle() WILL FAIL.
1143 * IF NECESSARY, BAIL OUT.
1144 */
1145 /*-------------------------------------------------------------------*/
1146 if (kd != isdongle(peasycap))
1147 return -ERESTARTSYS;
1148 if (NULL == file) {
1149 SAY("ERROR: file is NULL\n");
1150 mutex_unlock(&easycap_dongle[kd].mutex_video);
1151 return -ERESTARTSYS;
1152 }
1153 peasycap = file->private_data;
1154 if (NULL == peasycap) {
1155 SAY("ERROR: peasycap is NULL\n");
1156 mutex_unlock(&easycap_dongle[kd].mutex_video);
1157 return -ERESTARTSYS;
1158 }
1159 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
1160 SAY("ERROR: bad peasycap: 0x%08lX\n", \
1161 (unsigned long int) peasycap);
1162 mutex_unlock(&easycap_dongle[kd].mutex_video);
1163 return -ERESTARTSYS;
1164 }
1165 if (NULL == peasycap->pusb_device) {
1166 SAM("ERROR: peasycap->pusb_device is NULL\n");
1167 mutex_unlock(&easycap_dongle[kd].mutex_video);
1168 return -ERESTARTSYS;
1169 }
1170} else
1171 /*-------------------------------------------------------------------*/
1172 /*
1173 * IF easycap_usb_disconnect() HAS ALREADY FREED POINTER peasycap
1174 * BEFORE THE ATTEMPT TO ACQUIRE THE SEMAPHORE, isdongle() WILL
1175 * HAVE FAILED. BAIL OUT.
1176 */
1177 /*-------------------------------------------------------------------*/
1178 return -ERESTARTSYS;
1179/*---------------------------------------------------------------------------*/
1180rc = easycap_dqbuf(peasycap, 0);
827peasycap->polled = 1; 1181peasycap->polled = 1;
828 1182mutex_unlock(&easycap_dongle[kd].mutex_video);
829if (0 == easycap_dqbuf(peasycap, 0)) 1183if (0 == rc)
830 return POLLIN | POLLRDNORM; 1184 return POLLIN | POLLRDNORM;
831else 1185else
832 return POLLERR; 1186 return POLLERR;
833
834} 1187}
835/*****************************************************************************/ 1188/*****************************************************************************/
836/*---------------------------------------------------------------------------*/ 1189/*---------------------------------------------------------------------------*/
@@ -841,7 +1194,7 @@ else
841int 1194int
842easycap_dqbuf(struct easycap *peasycap, int mode) 1195easycap_dqbuf(struct easycap *peasycap, int mode)
843{ 1196{
844int miss, rc; 1197int input, ifield, miss, rc;
845 1198
846JOT(8, "\n"); 1199JOT(8, "\n");
847 1200
@@ -849,129 +1202,188 @@ if (NULL == peasycap) {
849 SAY("ERROR: peasycap is NULL\n"); 1202 SAY("ERROR: peasycap is NULL\n");
850 return -EFAULT; 1203 return -EFAULT;
851} 1204}
1205if (NULL == peasycap->pusb_device) {
1206 SAY("ERROR: peasycap->pusb_device is NULL\n");
1207 return -EFAULT;
1208}
1209ifield = 0;
1210JOM(8, "%i=ifield\n", ifield);
1211/*---------------------------------------------------------------------------*/
1212/*
1213 * CHECK FOR LOST INPUT SIGNAL.
1214 *
1215 * FOR THE FOUR-CVBS EasyCAP, THIS DOES NOT WORK AS EXPECTED.
1216 * IF INPUT 0 IS PRESENT AND SYNC ACQUIRED, UNPLUGGING INPUT 4 DOES NOT
1217 * RESULT IN SETTING BIT 0x40 ON REGISTER 0x1F, PRESUMABLY BECAUSE THERE
1218 * IS FLYWHEELING ON INPUT 0. THE UPSHOT IS:
1219 *
1220 * INPUT 0 PLUGGED, INPUT 4 PLUGGED => SCREEN 0 OK, SCREEN 4 OK
1221 * INPUT 0 PLUGGED, INPUT 4 UNPLUGGED => SCREEN 0 OK, SCREEN 4 BLACK
1222 * INPUT 0 UNPLUGGED, INPUT 4 PLUGGED => SCREEN 0 BARS, SCREEN 4 OK
1223 * INPUT 0 UNPLUGGED, INPUT 4 UNPLUGGED => SCREEN 0 BARS, SCREEN 4 BARS
1224*/
1225/*---------------------------------------------------------------------------*/
1226input = peasycap->input;
1227if (0 <= input && INPUT_MANY > input) {
1228 rc = read_saa(peasycap->pusb_device, 0x1F);
1229 if (0 <= rc) {
1230 if (rc & 0x40)
1231 peasycap->lost[input] += 1;
1232 else
1233 peasycap->lost[input] -= 2;
1234
1235 if (0 > peasycap->lost[input])
1236 peasycap->lost[input] = 0;
1237 else if ((2 * VIDEO_LOST_TOLERATE) < peasycap->lost[input])
1238 peasycap->lost[input] = (2 * VIDEO_LOST_TOLERATE);
1239 }
1240}
852/*---------------------------------------------------------------------------*/ 1241/*---------------------------------------------------------------------------*/
853/* 1242/*
854 * WAIT FOR FIELD 0 1243 * WAIT FOR FIELD ifield (0 => TOP, 1 => BOTTOM)
855 */ 1244 */
856/*---------------------------------------------------------------------------*/ 1245/*---------------------------------------------------------------------------*/
857miss = 0; 1246miss = 0;
858if (mutex_lock_interruptible(&(peasycap->mutex_mmap_video[0])))
859 return -ERESTARTSYS;
860while ((peasycap->field_read == peasycap->field_fill) || \ 1247while ((peasycap->field_read == peasycap->field_fill) || \
861 (0 != (0xFF00 & peasycap->field_buffer\ 1248 (0 != (0xFF00 & peasycap->field_buffer\
862 [peasycap->field_read][0].kount)) || \ 1249 [peasycap->field_read][0].kount)) || \
863 (0 != (0x00FF & peasycap->field_buffer\ 1250 (ifield != (0x00FF & peasycap->field_buffer\
864 [peasycap->field_read][0].kount))) { 1251 [peasycap->field_read][0].kount))) {
865 mutex_unlock(&(peasycap->mutex_mmap_video[0]));
866
867 if (mode) 1252 if (mode)
868 return -EAGAIN; 1253 return -EAGAIN;
869 1254
870 JOT(8, "first wait on wq_video, " \ 1255 JOM(8, "first wait on wq_video, " \
871 "%i=field_read %i=field_fill\n", \ 1256 "%i=field_read %i=field_fill\n", \
872 peasycap->field_read, peasycap->field_fill); 1257 peasycap->field_read, peasycap->field_fill);
873 1258
874 msleep(1);
875 if (0 != (wait_event_interruptible(peasycap->wq_video, \ 1259 if (0 != (wait_event_interruptible(peasycap->wq_video, \
876 (peasycap->video_idle || peasycap->video_eof || \ 1260 (peasycap->video_idle || peasycap->video_eof || \
877 ((peasycap->field_read != peasycap->field_fill) && \ 1261 ((peasycap->field_read != peasycap->field_fill) && \
878 (0 == (0xFF00 & peasycap->field_buffer\ 1262 (0 == (0xFF00 & peasycap->field_buffer\
879 [peasycap->field_read][0].kount)) && \ 1263 [peasycap->field_read][0].kount)) && \
880 (0 == (0x00FF & peasycap->field_buffer\ 1264 (ifield == (0x00FF & peasycap->field_buffer\
881 [peasycap->field_read][0].kount))))))){ 1265 [peasycap->field_read][0].kount))))))) {
882 SAY("aborted by signal\n"); 1266 SAM("aborted by signal\n");
883 return -EIO; 1267 return -EIO;
884 } 1268 }
885 if (peasycap->video_idle) { 1269 if (peasycap->video_idle) {
886 JOT(8, "%i=peasycap->video_idle\n", peasycap->video_idle); 1270 JOM(8, "%i=peasycap->video_idle ... returning -EAGAIN\n", \
887 return -EIO; 1271 peasycap->video_idle);
1272 return -EAGAIN;
888 } 1273 }
889 if (peasycap->video_eof) { 1274 if (peasycap->video_eof) {
890 JOT(8, "%i=peasycap->video_eof\n", peasycap->video_eof); 1275 JOM(8, "%i=peasycap->video_eof\n", peasycap->video_eof);
891 debrief(peasycap); 1276 #if defined(PERSEVERE)
1277 if (1 == peasycap->status) {
1278 JOM(8, "persevering ...\n");
1279 peasycap->video_eof = 0;
1280 peasycap->audio_eof = 0;
1281 if (0 != reset(peasycap)) {
1282 JOM(8, " ... failed ... returning -EIO\n");
1283 peasycap->video_eof = 1;
1284 peasycap->audio_eof = 1;
1285 kill_video_urbs(peasycap);
1286 return -EIO;
1287 }
1288 peasycap->status = 0;
1289 JOM(8, " ... OK ... returning -EAGAIN\n");
1290 return -EAGAIN;
1291 }
1292 #endif /*PERSEVERE*/
1293 peasycap->video_eof = 1;
1294 peasycap->audio_eof = 1;
892 kill_video_urbs(peasycap); 1295 kill_video_urbs(peasycap);
1296 JOM(8, "returning -EIO\n");
893 return -EIO; 1297 return -EIO;
894 } 1298 }
895miss++; 1299miss++;
896if (mutex_lock_interruptible(&(peasycap->mutex_mmap_video[0])))
897 return -ERESTARTSYS;
898} 1300}
899mutex_unlock(&(peasycap->mutex_mmap_video[0])); 1301JOM(8, "first awakening on wq_video after %i waits\n", miss);
900JOT(8, "first awakening on wq_video after %i waits\n", miss);
901 1302
902rc = field2frame(peasycap); 1303rc = field2frame(peasycap);
903if (0 != rc) 1304if (0 != rc)
904 SAY("ERROR: field2frame() returned %i\n", rc); 1305 SAM("ERROR: field2frame() returned %i\n", rc);
905
906if (true == peasycap->offerfields) {
907 peasycap->frame_read = peasycap->frame_fill;
908 (peasycap->frame_fill)++;
909 if (peasycap->frame_buffer_many <= peasycap->frame_fill)
910 peasycap->frame_fill = 0;
911
912 if (0x01 & easycap_standard[peasycap->standard_offset].mask) {
913 peasycap->frame_buffer[peasycap->frame_read][0].kount = \
914 V4L2_FIELD_BOTTOM;
915 } else {
916 peasycap->frame_buffer[peasycap->frame_read][0].kount = \
917 V4L2_FIELD_TOP;
918 }
919JOT(8, "setting: %i=peasycap->frame_read\n", peasycap->frame_read);
920JOT(8, "bumped to: %i=peasycap->frame_fill\n", peasycap->frame_fill);
921}
922/*---------------------------------------------------------------------------*/ 1306/*---------------------------------------------------------------------------*/
923/* 1307/*
924 * WAIT FOR FIELD 1 1308 * WAIT FOR THE OTHER FIELD
925 */ 1309 */
926/*---------------------------------------------------------------------------*/ 1310/*---------------------------------------------------------------------------*/
1311if (ifield)
1312 ifield = 0;
1313else
1314 ifield = 1;
927miss = 0; 1315miss = 0;
928if (mutex_lock_interruptible(&(peasycap->mutex_mmap_video[0])))
929 return -ERESTARTSYS;
930while ((peasycap->field_read == peasycap->field_fill) || \ 1316while ((peasycap->field_read == peasycap->field_fill) || \
931 (0 != (0xFF00 & peasycap->field_buffer\ 1317 (0 != (0xFF00 & peasycap->field_buffer\
932 [peasycap->field_read][0].kount)) || \ 1318 [peasycap->field_read][0].kount)) || \
933 (0 == (0x00FF & peasycap->field_buffer\ 1319 (ifield != (0x00FF & peasycap->field_buffer\
934 [peasycap->field_read][0].kount))) { 1320 [peasycap->field_read][0].kount))) {
935 mutex_unlock(&(peasycap->mutex_mmap_video[0]));
936
937 if (mode) 1321 if (mode)
938 return -EAGAIN; 1322 return -EAGAIN;
939 1323
940 JOT(8, "second wait on wq_video, " \ 1324 JOM(8, "second wait on wq_video, " \
941 "%i=field_read %i=field_fill\n", \ 1325 "%i=field_read %i=field_fill\n", \
942 peasycap->field_read, peasycap->field_fill); 1326 peasycap->field_read, peasycap->field_fill);
943 msleep(1);
944 if (0 != (wait_event_interruptible(peasycap->wq_video, \ 1327 if (0 != (wait_event_interruptible(peasycap->wq_video, \
945 (peasycap->video_idle || peasycap->video_eof || \ 1328 (peasycap->video_idle || peasycap->video_eof || \
946 ((peasycap->field_read != peasycap->field_fill) && \ 1329 ((peasycap->field_read != peasycap->field_fill) && \
947 (0 == (0xFF00 & peasycap->field_buffer\ 1330 (0 == (0xFF00 & peasycap->field_buffer\
948 [peasycap->field_read][0].kount)) && \ 1331 [peasycap->field_read][0].kount)) && \
949 (0 != (0x00FF & peasycap->field_buffer\ 1332 (ifield == (0x00FF & peasycap->field_buffer\
950 [peasycap->field_read][0].kount))))))){ 1333 [peasycap->field_read][0].\
951 SAY("aborted by signal\n"); 1334 kount))))))) {
1335 SAM("aborted by signal\n");
952 return -EIO; 1336 return -EIO;
953 } 1337 }
954 if (peasycap->video_idle) { 1338 if (peasycap->video_idle) {
955 JOT(8, "%i=peasycap->video_idle\n", peasycap->video_idle); 1339 JOM(8, "%i=peasycap->video_idle ... returning -EAGAIN\n", \
956 return -EIO; 1340 peasycap->video_idle);
1341 return -EAGAIN;
957 } 1342 }
958 if (peasycap->video_eof) { 1343 if (peasycap->video_eof) {
959 JOT(8, "%i=peasycap->video_eof\n", peasycap->video_eof); 1344 JOM(8, "%i=peasycap->video_eof\n", peasycap->video_eof);
960 debrief(peasycap); 1345 #if defined(PERSEVERE)
1346 if (1 == peasycap->status) {
1347 JOM(8, "persevering ...\n");
1348 peasycap->video_eof = 0;
1349 peasycap->audio_eof = 0;
1350 if (0 != reset(peasycap)) {
1351 JOM(8, " ... failed ... returning -EIO\n");
1352 peasycap->video_eof = 1;
1353 peasycap->audio_eof = 1;
1354 kill_video_urbs(peasycap);
1355 return -EIO;
1356 }
1357 peasycap->status = 0;
1358 JOM(8, " ... OK ... returning -EAGAIN\n");
1359 return -EAGAIN;
1360 }
1361 #endif /*PERSEVERE*/
1362 peasycap->video_eof = 1;
1363 peasycap->audio_eof = 1;
961 kill_video_urbs(peasycap); 1364 kill_video_urbs(peasycap);
1365 JOM(8, "returning -EIO\n");
962 return -EIO; 1366 return -EIO;
963 } 1367 }
964miss++; 1368miss++;
965if (mutex_lock_interruptible(&(peasycap->mutex_mmap_video[0])))
966 return -ERESTARTSYS;
967} 1369}
968mutex_unlock(&(peasycap->mutex_mmap_video[0])); 1370JOM(8, "second awakening on wq_video after %i waits\n", miss);
969JOT(8, "second awakening on wq_video after %i waits\n", miss);
970 1371
971rc = field2frame(peasycap); 1372rc = field2frame(peasycap);
972if (0 != rc) 1373if (0 != rc)
973 SAY("ERROR: field2frame() returned %i\n", rc); 1374 SAM("ERROR: field2frame() returned %i\n", rc);
974 1375/*---------------------------------------------------------------------------*/
1376/*
1377 * WASTE THIS FRAME
1378*/
1379/*---------------------------------------------------------------------------*/
1380if (0 != peasycap->skip) {
1381 peasycap->skipped++;
1382 if (peasycap->skip != peasycap->skipped)
1383 return peasycap->skip - peasycap->skipped;
1384 peasycap->skipped = 0;
1385}
1386/*---------------------------------------------------------------------------*/
975peasycap->frame_read = peasycap->frame_fill; 1387peasycap->frame_read = peasycap->frame_fill;
976peasycap->queued[peasycap->frame_read] = 0; 1388peasycap->queued[peasycap->frame_read] = 0;
977peasycap->done[peasycap->frame_read] = V4L2_BUF_FLAG_DONE; 1389peasycap->done[peasycap->frame_read] = V4L2_BUF_FLAG_DONE;
@@ -988,8 +1400,8 @@ if (0x01 & easycap_standard[peasycap->standard_offset].mask) {
988 V4L2_FIELD_BOTTOM; 1400 V4L2_FIELD_BOTTOM;
989} 1401}
990 1402
991JOT(8, "setting: %i=peasycap->frame_read\n", peasycap->frame_read); 1403JOM(8, "setting: %i=peasycap->frame_read\n", peasycap->frame_read);
992JOT(8, "bumped to: %i=peasycap->frame_fill\n", peasycap->frame_fill); 1404JOM(8, "bumped to: %i=peasycap->frame_fill\n", peasycap->frame_fill);
993 1405
994return 0; 1406return 0;
995} 1407}
@@ -1003,14 +1415,12 @@ return 0;
1003 * odd==false IS TRANSFERRED TO THE FRAME BUFFER. 1415 * odd==false IS TRANSFERRED TO THE FRAME BUFFER.
1004 * 1416 *
1005 * THE BOOLEAN PARAMETER offerfields IS true ONLY WHEN THE USER PROGRAM 1417 * THE BOOLEAN PARAMETER offerfields IS true ONLY WHEN THE USER PROGRAM
1006 * CHOOSES THE OPTION V4L2_FIELD_ALTERNATE. NO USERSPACE PROGRAM TESTED 1418 * CHOOSES THE OPTION V4L2_FIELD_INTERLACED.
1007 * TO DATE HAS DONE THIS. BUGS ARE LIKELY.
1008 */ 1419 */
1009/*---------------------------------------------------------------------------*/ 1420/*---------------------------------------------------------------------------*/
1010int 1421int
1011field2frame(struct easycap *peasycap) 1422field2frame(struct easycap *peasycap)
1012{ 1423{
1013static struct timeval timeval0;
1014struct timeval timeval; 1424struct timeval timeval;
1015long long int above, below; 1425long long int above, below;
1016__u32 remainder; 1426__u32 remainder;
@@ -1019,16 +1429,26 @@ struct signed_div_result sdr;
1019void *pex, *pad; 1429void *pex, *pad;
1020int kex, kad, mex, mad, rex, rad, rad2; 1430int kex, kad, mex, mad, rex, rad, rad2;
1021int c2, c3, w2, w3, cz, wz; 1431int c2, c3, w2, w3, cz, wz;
1022int rc, bytesperpixel, multiplier, much, more, over, rump, caches; 1432int rc, bytesperpixel, multiplier, much, more, over, rump, caches, input;
1023__u8 mask, margin; 1433__u8 mask, margin;
1024bool odd, isuy, decimatepixel, offerfields; 1434bool odd, isuy, decimatepixel, offerfields, badinput;
1435
1436if (NULL == peasycap) {
1437 SAY("ERROR: peasycap is NULL\n");
1438 return -EFAULT;
1439}
1025 1440
1026JOT(8, "===== parity %i, field buffer %i --> frame buffer %i\n", \ 1441badinput = false;
1442input = 0x07 & peasycap->field_buffer[peasycap->field_read][0].input;
1443
1444JOM(8, "===== parity %i, input 0x%02X, field buffer %i --> " \
1445 "frame buffer %i\n", \
1027 peasycap->field_buffer[peasycap->field_read][0].kount,\ 1446 peasycap->field_buffer[peasycap->field_read][0].kount,\
1447 peasycap->field_buffer[peasycap->field_read][0].input,\
1028 peasycap->field_read, peasycap->frame_fill); 1448 peasycap->field_read, peasycap->frame_fill);
1029JOT(8, "===== %i=bytesperpixel\n", peasycap->bytesperpixel); 1449JOM(8, "===== %i=bytesperpixel\n", peasycap->bytesperpixel);
1030if (true == peasycap->offerfields) 1450if (true == peasycap->offerfields)
1031 JOT(8, "===== offerfields\n"); 1451 JOM(8, "===== offerfields\n");
1032 1452
1033/*---------------------------------------------------------------------------*/ 1453/*---------------------------------------------------------------------------*/
1034/* 1454/*
@@ -1036,15 +1456,17 @@ if (true == peasycap->offerfields)
1036 */ 1456 */
1037/*---------------------------------------------------------------------------*/ 1457/*---------------------------------------------------------------------------*/
1038if (peasycap->field_read == peasycap->field_fill) { 1458if (peasycap->field_read == peasycap->field_fill) {
1039 SAY("ERROR: on entry, still filling field buffer %i\n", \ 1459 SAM("ERROR: on entry, still filling field buffer %i\n", \
1040 peasycap->field_read); 1460 peasycap->field_read);
1041 return 0; 1461 return 0;
1042} 1462}
1043#if defined(EASYCAP_TESTCARD) 1463#if defined(EASYCAP_TESTCARD)
1044easycap_testcard(peasycap, peasycap->field_read); 1464easycap_testcard(peasycap, peasycap->field_read);
1045#else 1465#else
1046if (0 != (0x0400 & peasycap->field_buffer[peasycap->field_read][0].kount)) 1466if (0 <= input && INPUT_MANY > input) {
1047 easycap_testcard(peasycap, peasycap->field_read); 1467 if (easycap_bars && VIDEO_LOST_TOLERATE <= peasycap->lost[input])
1468 easycap_testcard(peasycap, peasycap->field_read);
1469}
1048#endif /*EASYCAP_TESTCARD*/ 1470#endif /*EASYCAP_TESTCARD*/
1049/*---------------------------------------------------------------------------*/ 1471/*---------------------------------------------------------------------------*/
1050 1472
@@ -1055,7 +1477,7 @@ decimatepixel = peasycap->decimatepixel;
1055if ((2 != bytesperpixel) && \ 1477if ((2 != bytesperpixel) && \
1056 (3 != bytesperpixel) && \ 1478 (3 != bytesperpixel) && \
1057 (4 != bytesperpixel)) { 1479 (4 != bytesperpixel)) {
1058 SAY("MISTAKE: %i=bytesperpixel\n", bytesperpixel); 1480 SAM("MISTAKE: %i=bytesperpixel\n", bytesperpixel);
1059 return -EFAULT; 1481 return -EFAULT;
1060} 1482}
1061if (true == decimatepixel) 1483if (true == decimatepixel)
@@ -1082,8 +1504,8 @@ if (peasycap->field_buffer[kex][0].kount)
1082else 1504else
1083 odd = false; 1505 odd = false;
1084 1506
1085if ((true == odd) && (false == offerfields) &&(false == decimatepixel)) { 1507if ((true == odd) && (false == decimatepixel)) {
1086 JOT(8, " initial skipping %4i bytes p.%4i\n", \ 1508 JOM(8, " initial skipping %4i bytes p.%4i\n", \
1087 w3/multiplier, mad); 1509 w3/multiplier, mad);
1088 pad += (w3 / multiplier); rad -= (w3 / multiplier); 1510 pad += (w3 / multiplier); rad -= (w3 / multiplier);
1089} 1511}
@@ -1108,7 +1530,7 @@ while (cz < wz) {
1108 rump = 0; 1530 rump = 0;
1109 1531
1110 if (much % 2) { 1532 if (much % 2) {
1111 SAY("MISTAKE: much is odd\n"); 1533 SAM("MISTAKE: much is odd\n");
1112 return -EFAULT; 1534 return -EFAULT;
1113 } 1535 }
1114 1536
@@ -1116,13 +1538,11 @@ while (cz < wz) {
1116 much) / 2; 1538 much) / 2;
1117/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1539/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1118 if (1 < bytesperpixel) { 1540 if (1 < bytesperpixel) {
1119 if ((rad * \ 1541 if (rad * 2 < much * bytesperpixel) {
1120 2) < (much * \
1121 bytesperpixel)) {
1122 /* 1542 /*
1123 ** INJUDICIOUS ALTERATION OF THIS 1543 ** INJUDICIOUS ALTERATION OF THIS
1124 ** BLOCK WILL CAUSE BREAKAGE. 1544 ** STATEMENT BLOCK WILL CAUSE
1125 ** BEWARE. 1545 ** BREAKAGE. BEWARE.
1126 **/ 1546 **/
1127 rad2 = rad + bytesperpixel - 1; 1547 rad2 = rad + bytesperpixel - 1;
1128 much = ((((2 * \ 1548 much = ((((2 * \
@@ -1145,18 +1565,25 @@ while (cz < wz) {
1145 } 1565 }
1146/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1566/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1147 } else { 1567 } else {
1148 SAY("MISTAKE: %i=bytesperpixel\n", \ 1568 SAM("MISTAKE: %i=bytesperpixel\n", \
1149 bytesperpixel); 1569 bytesperpixel);
1150 return -EFAULT; 1570 return -EFAULT;
1151 } 1571 }
1152/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1572/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1153 if (rump) 1573 if (rump)
1154 caches++; 1574 caches++;
1155 1575 if (true == badinput) {
1576 JOM(8, "ERROR: 0x%02X=->field_buffer" \
1577 "[%i][%i].input, " \
1578 "0x%02X=(0x08|->input)\n", \
1579 peasycap->field_buffer\
1580 [kex][mex].input, kex, mex, \
1581 (0x08|peasycap->input));
1582 }
1156 rc = redaub(peasycap, pad, pex, much, more, \ 1583 rc = redaub(peasycap, pad, pex, much, more, \
1157 mask, margin, isuy); 1584 mask, margin, isuy);
1158 if (0 > rc) { 1585 if (0 > rc) {
1159 SAY("ERROR: redaub() failed\n"); 1586 SAM("ERROR: redaub() failed\n");
1160 return -EFAULT; 1587 return -EFAULT;
1161 } 1588 }
1162 if (much % 4) { 1589 if (much % 4) {
@@ -1171,6 +1598,9 @@ while (cz < wz) {
1171 mex++; 1598 mex++;
1172 pex = peasycap->field_buffer[kex][mex].pgo; 1599 pex = peasycap->field_buffer[kex][mex].pgo;
1173 rex = PAGE_SIZE; 1600 rex = PAGE_SIZE;
1601 if (peasycap->field_buffer[kex][mex].input != \
1602 (0x08|peasycap->input))
1603 badinput = true;
1174 } 1604 }
1175 pad += more; 1605 pad += more;
1176 rad -= more; 1606 rad -= more;
@@ -1190,7 +1620,7 @@ while (cz < wz) {
1190 * UNLESS IT IS THE LAST LINE OF AN ODD FRAME 1620 * UNLESS IT IS THE LAST LINE OF AN ODD FRAME
1191 */ 1621 */
1192/*---------------------------------------------------------------------------*/ 1622/*---------------------------------------------------------------------------*/
1193 if (((false == odd) || (cz != wz))&&(false == offerfields)) { 1623 if ((false == odd) || (cz != wz)) {
1194 over = w3; 1624 over = w3;
1195 do { 1625 do {
1196 if (!rad) { 1626 if (!rad) {
@@ -1224,7 +1654,7 @@ while (cz < wz) {
1224 rump = 0; 1654 rump = 0;
1225 1655
1226 if (much % 2) { 1656 if (much % 2) {
1227 SAY("MISTAKE: much is odd\n"); 1657 SAM("MISTAKE: much is odd\n");
1228 return -EFAULT; 1658 return -EFAULT;
1229 } 1659 }
1230 1660
@@ -1232,12 +1662,11 @@ while (cz < wz) {
1232 much) / 4; 1662 much) / 4;
1233/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1663/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1234 if (1 < bytesperpixel) { 1664 if (1 < bytesperpixel) {
1235 if ((rad * 4) < (much * \ 1665 if (rad * 4 < much * bytesperpixel) {
1236 bytesperpixel)) {
1237 /* 1666 /*
1238 ** INJUDICIOUS ALTERATION OF THIS 1667 ** INJUDICIOUS ALTERATION OF THIS
1239 ** BLOCK WILL CAUSE BREAKAGE. 1668 ** STATEMENT BLOCK WILL CAUSE
1240 ** BEWARE. 1669 ** BREAKAGE. BEWARE.
1241 **/ 1670 **/
1242 rad2 = rad + bytesperpixel - 1; 1671 rad2 = rad + bytesperpixel - 1;
1243 much = ((((2 * rad2)/bytesperpixel)/2)\ 1672 much = ((((2 * rad2)/bytesperpixel)/2)\
@@ -1261,7 +1690,7 @@ while (cz < wz) {
1261 } 1690 }
1262/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 1691/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1263 } else { 1692 } else {
1264 SAY("MISTAKE: %i=bytesperpixel\n", \ 1693 SAM("MISTAKE: %i=bytesperpixel\n", \
1265 bytesperpixel); 1694 bytesperpixel);
1266 return -EFAULT; 1695 return -EFAULT;
1267 } 1696 }
@@ -1269,10 +1698,18 @@ while (cz < wz) {
1269 if (rump) 1698 if (rump)
1270 caches++; 1699 caches++;
1271 1700
1701 if (true == badinput) {
1702 JOM(8, "ERROR: 0x%02X=->field_buffer" \
1703 "[%i][%i].input, " \
1704 "0x%02X=(0x08|->input)\n", \
1705 peasycap->field_buffer\
1706 [kex][mex].input, kex, mex, \
1707 (0x08|peasycap->input));
1708 }
1272 rc = redaub(peasycap, pad, pex, much, more, \ 1709 rc = redaub(peasycap, pad, pex, much, more, \
1273 mask, margin, isuy); 1710 mask, margin, isuy);
1274 if (0 > rc) { 1711 if (0 > rc) {
1275 SAY("ERROR: redaub() failed\n"); 1712 SAM("ERROR: redaub() failed\n");
1276 return -EFAULT; 1713 return -EFAULT;
1277 } 1714 }
1278 over -= much; cz += much; 1715 over -= much; cz += much;
@@ -1281,6 +1718,9 @@ while (cz < wz) {
1281 mex++; 1718 mex++;
1282 pex = peasycap->field_buffer[kex][mex].pgo; 1719 pex = peasycap->field_buffer[kex][mex].pgo;
1283 rex = PAGE_SIZE; 1720 rex = PAGE_SIZE;
1721 if (peasycap->field_buffer[kex][mex].input != \
1722 (0x08|peasycap->input))
1723 badinput = true;
1284 } 1724 }
1285 pad += more; 1725 pad += more;
1286 rad -= more; 1726 rad -= more;
@@ -1307,6 +1747,16 @@ while (cz < wz) {
1307 mex++; 1747 mex++;
1308 pex = peasycap->field_buffer[kex][mex].pgo; 1748 pex = peasycap->field_buffer[kex][mex].pgo;
1309 rex = PAGE_SIZE; 1749 rex = PAGE_SIZE;
1750 if (peasycap->field_buffer[kex][mex].input != \
1751 (0x08|peasycap->input)) {
1752 JOM(8, "ERROR: 0x%02X=->field_buffer"\
1753 "[%i][%i].input, " \
1754 "0x%02X=(0x08|->input)\n", \
1755 peasycap->field_buffer\
1756 [kex][mex].input, kex, mex, \
1757 (0x08|peasycap->input));
1758 badinput = true;
1759 }
1310 } 1760 }
1311 much = over; 1761 much = over;
1312 if (rex < much) 1762 if (rex < much)
@@ -1325,39 +1775,39 @@ while (cz < wz) {
1325/*---------------------------------------------------------------------------*/ 1775/*---------------------------------------------------------------------------*/
1326c2 = (mex + 1)*PAGE_SIZE - rex; 1776c2 = (mex + 1)*PAGE_SIZE - rex;
1327if (cz != c2) 1777if (cz != c2)
1328 SAY("ERROR: discrepancy %i in bytes read\n", c2 - cz); 1778 SAM("ERROR: discrepancy %i in bytes read\n", c2 - cz);
1329c3 = (mad + 1)*PAGE_SIZE - rad; 1779c3 = (mad + 1)*PAGE_SIZE - rad;
1330 1780
1331if (false == decimatepixel) { 1781if (false == decimatepixel) {
1332 if (bytesperpixel * \ 1782 if (bytesperpixel * \
1333 cz != c3) \ 1783 cz != c3) \
1334 SAY("ERROR: discrepancy %i in bytes written\n", \ 1784 SAM("ERROR: discrepancy %i in bytes written\n", \
1335 c3 - (bytesperpixel * \ 1785 c3 - (bytesperpixel * \
1336 cz)); 1786 cz));
1337} else { 1787} else {
1338 if (false == odd) { 1788 if (false == odd) {
1339 if (bytesperpixel * \ 1789 if (bytesperpixel * \
1340 cz != (4 * c3)) 1790 cz != (4 * c3))
1341 SAY("ERROR: discrepancy %i in bytes written\n", \ 1791 SAM("ERROR: discrepancy %i in bytes written\n", \
1342 (2*c3)-(bytesperpixel * \ 1792 (2*c3)-(bytesperpixel * \
1343 cz)); 1793 cz));
1344 } else { 1794 } else {
1345 if (0 != c3) 1795 if (0 != c3)
1346 SAY("ERROR: discrepancy %i " \ 1796 SAM("ERROR: discrepancy %i " \
1347 "in bytes written\n", c3); 1797 "in bytes written\n", c3);
1348 } 1798 }
1349} 1799}
1350if (rump) 1800if (rump)
1351 SAY("ERROR: undischarged cache at end of line in frame buffer\n"); 1801 SAM("WORRY: undischarged cache at end of line in frame buffer\n");
1352 1802
1353JOT(8, "===== field2frame(): %i bytes --> %i bytes (incl skip)\n", c2, c3); 1803JOM(8, "===== field2frame(): %i bytes --> %i bytes (incl skip)\n", c2, c3);
1354JOT(8, "===== field2frame(): %i=mad %i=rad\n", mad, rad); 1804JOM(8, "===== field2frame(): %i=mad %i=rad\n", mad, rad);
1355 1805
1356if (true == odd) 1806if (true == odd)
1357 JOT(8, "+++++ field2frame(): frame buffer %i is full\n", kad); 1807 JOM(8, "+++++ field2frame(): frame buffer %i is full\n", kad);
1358 1808
1359if (peasycap->field_read == peasycap->field_fill) 1809if (peasycap->field_read == peasycap->field_fill)
1360 SAY("WARNING: on exit, filling field buffer %i\n", \ 1810 SAM("WARNING: on exit, filling field buffer %i\n", \
1361 peasycap->field_read); 1811 peasycap->field_read);
1362/*---------------------------------------------------------------------------*/ 1812/*---------------------------------------------------------------------------*/
1363/* 1813/*
@@ -1365,23 +1815,24 @@ if (peasycap->field_read == peasycap->field_fill)
1365 */ 1815 */
1366/*---------------------------------------------------------------------------*/ 1816/*---------------------------------------------------------------------------*/
1367do_gettimeofday(&timeval); 1817do_gettimeofday(&timeval);
1368if (timeval0.tv_sec) { 1818if (peasycap->timeval6.tv_sec) {
1369 below = ((long long int)(1000000)) * \ 1819 below = ((long long int)(1000000)) * \
1370 ((long long int)(timeval.tv_sec - timeval0.tv_sec)) + \ 1820 ((long long int)(timeval.tv_sec - \
1371 (long long int)(timeval.tv_usec - timeval0.tv_usec); 1821 peasycap->timeval6.tv_sec)) + \
1822 (long long int)(timeval.tv_usec - peasycap->timeval6.tv_usec);
1372 above = (long long int)1000000; 1823 above = (long long int)1000000;
1373 1824
1374 sdr = signed_div(above, below); 1825 sdr = signed_div(above, below);
1375 above = sdr.quotient; 1826 above = sdr.quotient;
1376 remainder = (__u32)sdr.remainder; 1827 remainder = (__u32)sdr.remainder;
1377 1828
1378 JOT(8, "video streaming at %3lli.%03i fields per second\n", above, \ 1829 JOM(8, "video streaming at %3lli.%03i fields per second\n", above, \
1379 (remainder/1000)); 1830 (remainder/1000));
1380} 1831}
1381timeval0 = timeval; 1832peasycap->timeval6 = timeval;
1382 1833
1383if (caches) 1834if (caches)
1384 JOT(8, "%i=caches\n", caches); 1835 JOM(8, "%i=caches\n", caches);
1385return 0; 1836return 0;
1386} 1837}
1387/*****************************************************************************/ 1838/*****************************************************************************/
@@ -1434,7 +1885,7 @@ redaub(struct easycap *peasycap, void *pad, void *pex, int much, int more, \
1434 __u8 mask, __u8 margin, bool isuy) 1885 __u8 mask, __u8 margin, bool isuy)
1435{ 1886{
1436static __s32 ay[256], bu[256], rv[256], gu[256], gv[256]; 1887static __s32 ay[256], bu[256], rv[256], gu[256], gv[256];
1437static __u8 cache[8], *pcache; 1888__u8 *pcache;
1438__u8 r, g, b, y, u, v, c, *p2, *p3, *pz, *pr; 1889__u8 r, g, b, y, u, v, c, *p2, *p3, *pz, *pr;
1439int bytesperpixel; 1890int bytesperpixel;
1440bool byteswaporder, decimatepixel, last; 1891bool byteswaporder, decimatepixel, last;
@@ -1442,7 +1893,7 @@ int j, rump;
1442__s32 s32; 1893__s32 s32;
1443 1894
1444if (much % 2) { 1895if (much % 2) {
1445 SAY("MISTAKE: much is odd\n"); 1896 SAM("MISTAKE: much is odd\n");
1446 return -EFAULT; 1897 return -EFAULT;
1447} 1898}
1448bytesperpixel = peasycap->bytesperpixel; 1899bytesperpixel = peasycap->bytesperpixel;
@@ -1475,30 +1926,31 @@ if (!bu[255]) {
1475 ay[j] = ay[16]; 1926 ay[j] = ay[16];
1476 for (j = 236; j < 256; j++) 1927 for (j = 236; j < 256; j++)
1477 ay[j] = ay[235]; 1928 ay[j] = ay[235];
1478 JOT(8, "lookup tables are prepared\n"); 1929 JOM(8, "lookup tables are prepared\n");
1479} 1930}
1480if ((__u8 *)NULL == pcache) 1931pcache = peasycap->pcache;
1481 pcache = &cache[0]; 1932if (NULL == pcache)
1933 pcache = &peasycap->cache[0];
1482/*---------------------------------------------------------------------------*/ 1934/*---------------------------------------------------------------------------*/
1483/* 1935/*
1484 * TRANSFER CONTENTS OF CACHE TO THE FRAME BUFFER 1936 * TRANSFER CONTENTS OF CACHE TO THE FRAME BUFFER
1485 */ 1937 */
1486/*---------------------------------------------------------------------------*/ 1938/*---------------------------------------------------------------------------*/
1487if (!pcache) { 1939if (!pcache) {
1488 SAY("MISTAKE: pcache is NULL\n"); 1940 SAM("MISTAKE: pcache is NULL\n");
1489 return -EFAULT; 1941 return -EFAULT;
1490} 1942}
1491 1943
1492if (pcache != &cache[0]) 1944if (pcache != &peasycap->cache[0])
1493 JOT(16, "cache has %i bytes\n", (int)(pcache - &cache[0])); 1945 JOM(16, "cache has %i bytes\n", (int)(pcache - &peasycap->cache[0]));
1494p2 = &cache[0]; 1946p2 = &peasycap->cache[0];
1495p3 = (__u8 *)pad - (int)(pcache - &cache[0]); 1947p3 = (__u8 *)pad - (int)(pcache - &peasycap->cache[0]);
1496while (p2 < pcache) { 1948while (p2 < pcache) {
1497 *p3++ = *p2; p2++; 1949 *p3++ = *p2; p2++;
1498} 1950}
1499pcache = &cache[0]; 1951pcache = &peasycap->cache[0];
1500if (p3 != pad) { 1952if (p3 != pad) {
1501 SAY("MISTAKE: pointer misalignment\n"); 1953 SAM("MISTAKE: pointer misalignment\n");
1502 return -EFAULT; 1954 return -EFAULT;
1503} 1955}
1504/*---------------------------------------------------------------------------*/ 1956/*---------------------------------------------------------------------------*/
@@ -1513,7 +1965,7 @@ else
1513 v = *(p2 - 1); 1965 v = *(p2 - 1);
1514 1966
1515if (rump) 1967if (rump)
1516 JOT(16, "%4i=much %4i=more %i=rump\n", much, more, rump); 1968 JOM(16, "%4i=much %4i=more %i=rump\n", much, more, rump);
1517 1969
1518/*---------------------------------------------------------------------------*/ 1970/*---------------------------------------------------------------------------*/
1519switch (bytesperpixel) { 1971switch (bytesperpixel) {
@@ -1619,7 +2071,7 @@ case 3:
1619 0 : (__u8)s32); 2071 0 : (__u8)s32);
1620 2072
1621 if ((true == last) && rump) { 2073 if ((true == last) && rump) {
1622 pcache = &cache[0]; 2074 pcache = &peasycap->cache[0];
1623 switch (bytesperpixel - rump) { 2075 switch (bytesperpixel - rump) {
1624 case 1: { 2076 case 1: {
1625 *p3 = r; 2077 *p3 = r;
@@ -1634,7 +2086,7 @@ case 3:
1634 break; 2086 break;
1635 } 2087 }
1636 default: { 2088 default: {
1637 SAY("MISTAKE: %i=rump\n", \ 2089 SAM("MISTAKE: %i=rump\n", \
1638 bytesperpixel - rump); 2090 bytesperpixel - rump);
1639 return -EFAULT; 2091 return -EFAULT;
1640 } 2092 }
@@ -1692,7 +2144,7 @@ case 3:
1692 0 : (__u8)s32); 2144 0 : (__u8)s32);
1693 2145
1694 if ((true == last) && rump) { 2146 if ((true == last) && rump) {
1695 pcache = &cache[0]; 2147 pcache = &peasycap->cache[0];
1696 switch (bytesperpixel - rump) { 2148 switch (bytesperpixel - rump) {
1697 case 1: { 2149 case 1: {
1698 *p3 = b; 2150 *p3 = b;
@@ -1707,7 +2159,7 @@ case 3:
1707 break; 2159 break;
1708 } 2160 }
1709 default: { 2161 default: {
1710 SAY("MISTAKE: %i=rump\n", \ 2162 SAM("MISTAKE: %i=rump\n", \
1711 bytesperpixel - rump); 2163 bytesperpixel - rump);
1712 return -EFAULT; 2164 return -EFAULT;
1713 } 2165 }
@@ -1768,7 +2220,7 @@ case 3:
1768 0 : (__u8)s32); 2220 0 : (__u8)s32);
1769 2221
1770 if ((true == last) && rump) { 2222 if ((true == last) && rump) {
1771 pcache = &cache[0]; 2223 pcache = &peasycap->cache[0];
1772 switch (bytesperpixel - rump) { 2224 switch (bytesperpixel - rump) {
1773 case 1: { 2225 case 1: {
1774 *p3 = r; 2226 *p3 = r;
@@ -1783,7 +2235,7 @@ case 3:
1783 break; 2235 break;
1784 } 2236 }
1785 default: { 2237 default: {
1786 SAY("MISTAKE: " \ 2238 SAM("MISTAKE: " \
1787 "%i=rump\n", \ 2239 "%i=rump\n", \
1788 bytesperpixel - rump); 2240 bytesperpixel - rump);
1789 return -EFAULT; 2241 return -EFAULT;
@@ -1844,7 +2296,7 @@ case 3:
1844 0 : (__u8)s32); 2296 0 : (__u8)s32);
1845 2297
1846 if ((true == last) && rump) { 2298 if ((true == last) && rump) {
1847 pcache = &cache[0]; 2299 pcache = &peasycap->cache[0];
1848 switch (bytesperpixel - rump) { 2300 switch (bytesperpixel - rump) {
1849 case 1: { 2301 case 1: {
1850 *p3 = b; 2302 *p3 = b;
@@ -1859,7 +2311,7 @@ case 3:
1859 break; 2311 break;
1860 } 2312 }
1861 default: { 2313 default: {
1862 SAY("MISTAKE: " \ 2314 SAM("MISTAKE: " \
1863 "%i=rump\n", \ 2315 "%i=rump\n", \
1864 bytesperpixel - rump); 2316 bytesperpixel - rump);
1865 return -EFAULT; 2317 return -EFAULT;
@@ -1924,7 +2376,7 @@ case 4:
1924 0 : (__u8)s32); 2376 0 : (__u8)s32);
1925 2377
1926 if ((true == last) && rump) { 2378 if ((true == last) && rump) {
1927 pcache = &cache[0]; 2379 pcache = &peasycap->cache[0];
1928 switch (bytesperpixel - rump) { 2380 switch (bytesperpixel - rump) {
1929 case 1: { 2381 case 1: {
1930 *p3 = r; 2382 *p3 = r;
@@ -1948,7 +2400,7 @@ case 4:
1948 break; 2400 break;
1949 } 2401 }
1950 default: { 2402 default: {
1951 SAY("MISTAKE: %i=rump\n", \ 2403 SAM("MISTAKE: %i=rump\n", \
1952 bytesperpixel - rump); 2404 bytesperpixel - rump);
1953 return -EFAULT; 2405 return -EFAULT;
1954 } 2406 }
@@ -2006,7 +2458,7 @@ case 4:
2006 0 : (__u8)s32); 2458 0 : (__u8)s32);
2007 2459
2008 if ((true == last) && rump) { 2460 if ((true == last) && rump) {
2009 pcache = &cache[0]; 2461 pcache = &peasycap->cache[0];
2010 switch (bytesperpixel - rump) { 2462 switch (bytesperpixel - rump) {
2011 case 1: { 2463 case 1: {
2012 *p3 = b; 2464 *p3 = b;
@@ -2030,7 +2482,7 @@ case 4:
2030 break; 2482 break;
2031 } 2483 }
2032 default: { 2484 default: {
2033 SAY("MISTAKE: %i=rump\n", \ 2485 SAM("MISTAKE: %i=rump\n", \
2034 bytesperpixel - rump); 2486 bytesperpixel - rump);
2035 return -EFAULT; 2487 return -EFAULT;
2036 } 2488 }
@@ -2093,7 +2545,7 @@ case 4:
2093 0 : (__u8)s32); 2545 0 : (__u8)s32);
2094 2546
2095 if ((true == last) && rump) { 2547 if ((true == last) && rump) {
2096 pcache = &cache[0]; 2548 pcache = &peasycap->cache[0];
2097 switch (bytesperpixel - rump) { 2549 switch (bytesperpixel - rump) {
2098 case 1: { 2550 case 1: {
2099 *p3 = r; 2551 *p3 = r;
@@ -2117,7 +2569,7 @@ case 4:
2117 break; 2569 break;
2118 } 2570 }
2119 default: { 2571 default: {
2120 SAY("MISTAKE: " \ 2572 SAM("MISTAKE: " \
2121 "%i=rump\n", \ 2573 "%i=rump\n", \
2122 bytesperpixel - \ 2574 bytesperpixel - \
2123 rump); 2575 rump);
@@ -2178,7 +2630,7 @@ case 4:
2178 0 : (__u8)s32); 2630 0 : (__u8)s32);
2179 2631
2180 if ((true == last) && rump) { 2632 if ((true == last) && rump) {
2181 pcache = &cache[0]; 2633 pcache = &peasycap->cache[0];
2182 switch (bytesperpixel - rump) { 2634 switch (bytesperpixel - rump) {
2183 case 1: { 2635 case 1: {
2184 *p3 = b; 2636 *p3 = b;
@@ -2202,7 +2654,7 @@ case 4:
2202 break; 2654 break;
2203 } 2655 }
2204 default: { 2656 default: {
2205 SAY("MISTAKE: " \ 2657 SAM("MISTAKE: " \
2206 "%i=rump\n", \ 2658 "%i=rump\n", \
2207 bytesperpixel - rump); 2659 bytesperpixel - rump);
2208 return -EFAULT; 2660 return -EFAULT;
@@ -2226,48 +2678,13 @@ case 4:
2226 break; 2678 break;
2227 } 2679 }
2228default: { 2680default: {
2229 SAY("MISTAKE: %i=bytesperpixel\n", bytesperpixel); 2681 SAM("MISTAKE: %i=bytesperpixel\n", bytesperpixel);
2230 return -EFAULT; 2682 return -EFAULT;
2231 } 2683 }
2232} 2684}
2233return 0; 2685return 0;
2234} 2686}
2235/*****************************************************************************/ 2687/*****************************************************************************/
2236void
2237debrief(struct easycap *peasycap)
2238{
2239if ((struct usb_device *)NULL != peasycap->pusb_device) {
2240 check_stk(peasycap->pusb_device);
2241 check_saa(peasycap->pusb_device);
2242 sayreadonly(peasycap);
2243 SAY("%i=peasycap->field_fill\n", peasycap->field_fill);
2244 SAY("%i=peasycap->field_read\n", peasycap->field_read);
2245 SAY("%i=peasycap->frame_fill\n", peasycap->frame_fill);
2246 SAY("%i=peasycap->frame_read\n", peasycap->frame_read);
2247}
2248return;
2249}
2250/*****************************************************************************/
2251void
2252sayreadonly(struct easycap *peasycap)
2253{
2254static int done;
2255int got00, got1F, got60, got61, got62;
2256
2257if ((!done) && ((struct usb_device *)NULL != peasycap->pusb_device)) {
2258 done = 1;
2259 got00 = read_saa(peasycap->pusb_device, 0x00);
2260 got1F = read_saa(peasycap->pusb_device, 0x1F);
2261 got60 = read_saa(peasycap->pusb_device, 0x60);
2262 got61 = read_saa(peasycap->pusb_device, 0x61);
2263 got62 = read_saa(peasycap->pusb_device, 0x62);
2264 SAY("0x%02X=reg0x00 0x%02X=reg0x1F\n", got00, got1F);
2265 SAY("0x%02X=reg0x60 0x%02X=reg0x61 0x%02X=reg0x62\n", \
2266 got60, got61, got62);
2267}
2268return;
2269}
2270/*****************************************************************************/
2271/*---------------------------------------------------------------------------*/ 2688/*---------------------------------------------------------------------------*/
2272/* 2689/*
2273 * SEE CORBET ET AL. "LINUX DEVICE DRIVERS", 3rd EDITION, PAGES 430-434 2690 * SEE CORBET ET AL. "LINUX DEVICE DRIVERS", 3rd EDITION, PAGES 430-434
@@ -2292,11 +2709,16 @@ easycap_vma_open(struct vm_area_struct *pvma)
2292struct easycap *peasycap; 2709struct easycap *peasycap;
2293 2710
2294peasycap = pvma->vm_private_data; 2711peasycap = pvma->vm_private_data;
2295if (NULL != peasycap) 2712if (NULL == peasycap) {
2296 peasycap->vma_many++; 2713 SAY("ERROR: peasycap is NULL\n");
2297 2714 return;
2715}
2716if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
2717 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
2718 return;
2719}
2720peasycap->vma_many++;
2298JOT(8, "%i=peasycap->vma_many\n", peasycap->vma_many); 2721JOT(8, "%i=peasycap->vma_many\n", peasycap->vma_many);
2299
2300return; 2722return;
2301} 2723}
2302/*****************************************************************************/ 2724/*****************************************************************************/
@@ -2306,10 +2728,16 @@ easycap_vma_close(struct vm_area_struct *pvma)
2306struct easycap *peasycap; 2728struct easycap *peasycap;
2307 2729
2308peasycap = pvma->vm_private_data; 2730peasycap = pvma->vm_private_data;
2309if (NULL != peasycap) { 2731if (NULL == peasycap) {
2310 peasycap->vma_many--; 2732 SAY("ERROR: peasycap is NULL\n");
2311 JOT(8, "%i=peasycap->vma_many\n", peasycap->vma_many); 2733 return;
2734}
2735if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
2736 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
2737 return;
2312} 2738}
2739peasycap->vma_many--;
2740JOT(8, "%i=peasycap->vma_many\n", peasycap->vma_many);
2313return; 2741return;
2314} 2742}
2315/*****************************************************************************/ 2743/*****************************************************************************/
@@ -2355,24 +2783,22 @@ if (NULL == peasycap) {
2355 SAY("ERROR: peasycap is NULL\n"); 2783 SAY("ERROR: peasycap is NULL\n");
2356 return retcode; 2784 return retcode;
2357} 2785}
2358mutex_lock(&(peasycap->mutex_mmap_video[0]));
2359/*---------------------------------------------------------------------------*/ 2786/*---------------------------------------------------------------------------*/
2360pbuf = peasycap->frame_buffer[k][m].pgo; 2787pbuf = peasycap->frame_buffer[k][m].pgo;
2361if (NULL == pbuf) { 2788if (NULL == pbuf) {
2362 SAY("ERROR: pbuf is NULL\n"); 2789 SAM("ERROR: pbuf is NULL\n");
2363 goto finish; 2790 goto finish;
2364} 2791}
2365page = virt_to_page(pbuf); 2792page = virt_to_page(pbuf);
2366if (NULL == page) { 2793if (NULL == page) {
2367 SAY("ERROR: page is NULL\n"); 2794 SAM("ERROR: page is NULL\n");
2368 goto finish; 2795 goto finish;
2369} 2796}
2370get_page(page); 2797get_page(page);
2371/*---------------------------------------------------------------------------*/ 2798/*---------------------------------------------------------------------------*/
2372finish: 2799finish:
2373mutex_unlock(&(peasycap->mutex_mmap_video[0]));
2374if (NULL == page) { 2800if (NULL == page) {
2375 SAY("ERROR: page is NULL after get_page(page)\n"); 2801 SAM("ERROR: page is NULL after get_page(page)\n");
2376} else { 2802} else {
2377 pvmf->page = page; 2803 pvmf->page = page;
2378 retcode = VM_FAULT_MINOR; 2804 retcode = VM_FAULT_MINOR;
@@ -2383,7 +2809,7 @@ return retcode;
2383/*---------------------------------------------------------------------------*/ 2809/*---------------------------------------------------------------------------*/
2384/* 2810/*
2385 * ON COMPLETION OF A VIDEO URB ITS DATA IS COPIED TO THE FIELD BUFFERS 2811 * ON COMPLETION OF A VIDEO URB ITS DATA IS COPIED TO THE FIELD BUFFERS
2386 * PROVIDED peasycap->video_idle IS ZER0. REGARDLESS OF THIS BEING TRUE, 2812 * PROVIDED peasycap->video_idle IS ZERO. REGARDLESS OF THIS BEING TRUE,
2387 * IT IS RESUBMITTED PROVIDED peasycap->video_isoc_streaming IS NOT ZERO. 2813 * IT IS RESUBMITTED PROVIDED peasycap->video_isoc_streaming IS NOT ZERO.
2388 * 2814 *
2389 * THIS FUNCTION IS AN INTERRUPT SERVICE ROUTINE AND MUST NOT SLEEP. 2815 * THIS FUNCTION IS AN INTERRUPT SERVICE ROUTINE AND MUST NOT SLEEP.
@@ -2400,7 +2826,8 @@ return retcode;
2400 * 0 != (kount & 0x8000) => AT LEAST ONE URB COMPLETED WITH ERRORS 2826 * 0 != (kount & 0x8000) => AT LEAST ONE URB COMPLETED WITH ERRORS
2401 * 0 != (kount & 0x4000) => BUFFER HAS TOO MUCH DATA 2827 * 0 != (kount & 0x4000) => BUFFER HAS TOO MUCH DATA
2402 * 0 != (kount & 0x2000) => BUFFER HAS NOT ENOUGH DATA 2828 * 0 != (kount & 0x2000) => BUFFER HAS NOT ENOUGH DATA
2403 * 0 != (kount & 0x0400) => FIELD WAS SUBMITTED BY BRIDGER ROUTINE 2829 * 0 != (kount & 0x1000) => BUFFER HAS DATA FROM DISPARATE INPUTS
2830 * 0 != (kount & 0x0400) => RESERVED
2404 * 0 != (kount & 0x0200) => FIELD BUFFER NOT YET CHECKED 2831 * 0 != (kount & 0x0200) => FIELD BUFFER NOT YET CHECKED
2405 * 0 != (kount & 0x0100) => BUFFER HAS TWO EXTRA BYTES - WHY? 2832 * 0 != (kount & 0x0100) => BUFFER HAS TWO EXTRA BYTES - WHY?
2406 */ 2833 */
@@ -2408,19 +2835,14 @@ return retcode;
2408void 2835void
2409easycap_complete(struct urb *purb) 2836easycap_complete(struct urb *purb)
2410{ 2837{
2411static int mt;
2412struct easycap *peasycap; 2838struct easycap *peasycap;
2413struct data_buffer *pfield_buffer; 2839struct data_buffer *pfield_buffer;
2414char errbuf[16]; 2840char errbuf[16];
2415int i, more, much, leap, rc, last; 2841int i, more, much, leap, rc, last;
2416int videofieldamount; 2842int videofieldamount;
2417unsigned int override; 2843unsigned int override, bad;
2418int framestatus, framelength, frameactual, frameoffset; 2844int framestatus, framelength, frameactual, frameoffset;
2419__u8 *pu; 2845__u8 *pu;
2420#if defined(BRIDGER)
2421struct timeval timeval;
2422long long usec;
2423#endif /*BRIDGER*/
2424 2846
2425if (NULL == purb) { 2847if (NULL == purb) {
2426 SAY("ERROR: easycap_complete(): purb is NULL\n"); 2848 SAY("ERROR: easycap_complete(): purb is NULL\n");
@@ -2431,74 +2853,78 @@ if (NULL == peasycap) {
2431 SAY("ERROR: easycap_complete(): peasycap is NULL\n"); 2853 SAY("ERROR: easycap_complete(): peasycap is NULL\n");
2432 return; 2854 return;
2433} 2855}
2434 2856if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
2857 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
2858 return;
2859}
2435if (peasycap->video_eof) 2860if (peasycap->video_eof)
2436 return; 2861 return;
2437
2438for (i = 0; i < VIDEO_ISOC_BUFFER_MANY; i++) 2862for (i = 0; i < VIDEO_ISOC_BUFFER_MANY; i++)
2439 if (purb->transfer_buffer == peasycap->video_isoc_buffer[i].pgo) 2863 if (purb->transfer_buffer == peasycap->video_isoc_buffer[i].pgo)
2440 break; 2864 break;
2441JOT(16, "%2i=urb\n", i); 2865JOM(16, "%2i=urb\n", i);
2442last = peasycap->video_isoc_sequence; 2866last = peasycap->video_isoc_sequence;
2443if ((((VIDEO_ISOC_BUFFER_MANY - 1) == last) && \ 2867if ((((VIDEO_ISOC_BUFFER_MANY - 1) == last) && \
2444 (0 != i)) || \ 2868 (0 != i)) || \
2445 (((VIDEO_ISOC_BUFFER_MANY - 1) != last) && \ 2869 (((VIDEO_ISOC_BUFFER_MANY - 1) != last) && \
2446 ((last + 1) != i))) { 2870 ((last + 1) != i))) {
2447 SAY("ERROR: out-of-order urbs %i,%i ... continuing\n", last, i); 2871 JOM(16, "ERROR: out-of-order urbs %i,%i ... continuing\n", last, i);
2448} 2872}
2449peasycap->video_isoc_sequence = i; 2873peasycap->video_isoc_sequence = i;
2450 2874
2451if (peasycap->video_idle) { 2875if (peasycap->video_idle) {
2452 JOT(16, "%i=video_idle %i=video_isoc_streaming\n", \ 2876 JOM(16, "%i=video_idle %i=video_isoc_streaming\n", \
2453 peasycap->video_idle, peasycap->video_isoc_streaming); 2877 peasycap->video_idle, peasycap->video_isoc_streaming);
2454 if (peasycap->video_isoc_streaming) { 2878 if (peasycap->video_isoc_streaming) {
2455 rc = usb_submit_urb(purb, GFP_ATOMIC); 2879 rc = usb_submit_urb(purb, GFP_ATOMIC);
2456 if (0 != rc) { 2880 if (0 != rc) {
2457 SAY("ERROR: while %i=video_idle, " \
2458 "usb_submit_urb() failed with rc:\n", \
2459 peasycap->video_idle);
2460 switch (rc) { 2881 switch (rc) {
2461 case -ENOMEM: { 2882 case -ENOMEM: {
2462 SAY("ENOMEM\n"); 2883 SAM("ENOMEM\n");
2463 break; 2884 break;
2464 } 2885 }
2465 case -ENODEV: { 2886 case -ENODEV: {
2466 SAY("ENODEV\n"); 2887 SAM("ENODEV\n");
2467 break; 2888 break;
2468 } 2889 }
2469 case -ENXIO: { 2890 case -ENXIO: {
2470 SAY("ENXIO\n"); 2891 SAM("ENXIO\n");
2471 break; 2892 break;
2472 } 2893 }
2473 case -EINVAL: { 2894 case -EINVAL: {
2474 SAY("EINVAL\n"); 2895 SAM("EINVAL\n");
2475 break; 2896 break;
2476 } 2897 }
2477 case -EAGAIN: { 2898 case -EAGAIN: {
2478 SAY("EAGAIN\n"); 2899 SAM("EAGAIN\n");
2479 break; 2900 break;
2480 } 2901 }
2481 case -EFBIG: { 2902 case -EFBIG: {
2482 SAY("EFBIG\n"); 2903 SAM("EFBIG\n");
2483 break; 2904 break;
2484 } 2905 }
2485 case -EPIPE: { 2906 case -EPIPE: {
2486 SAY("EPIPE\n"); 2907 SAM("EPIPE\n");
2487 break; 2908 break;
2488 } 2909 }
2489 case -EMSGSIZE: { 2910 case -EMSGSIZE: {
2490 SAY("EMSGSIZE\n"); 2911 SAM("EMSGSIZE\n");
2491 break; 2912 break;
2492 } 2913 }
2493 case -ENOSPC: { 2914 case -ENOSPC: {
2494 SAY("ENOSPC\n"); 2915 SAM("ENOSPC\n");
2495 break; 2916 break;
2496 } 2917 }
2497 default: { 2918 default: {
2498 SAY("0x%08X\n", rc); 2919 SAM("0x%08X\n", rc);
2499 break; 2920 break;
2500 } 2921 }
2501 } 2922 }
2923 if (-ENODEV != rc) \
2924 SAM("ERROR: while %i=video_idle, " \
2925 "usb_submit_urb() " \
2926 "failed with rc:\n", \
2927 peasycap->video_idle);
2502 } 2928 }
2503 } 2929 }
2504return; 2930return;
@@ -2506,80 +2932,80 @@ return;
2506override = 0; 2932override = 0;
2507/*---------------------------------------------------------------------------*/ 2933/*---------------------------------------------------------------------------*/
2508if (FIELD_BUFFER_MANY <= peasycap->field_fill) { 2934if (FIELD_BUFFER_MANY <= peasycap->field_fill) {
2509 SAY("ERROR: bad peasycap->field_fill\n"); 2935 SAM("ERROR: bad peasycap->field_fill\n");
2510 return; 2936 return;
2511} 2937}
2512if (purb->status) { 2938if (purb->status) {
2513 if ((-ESHUTDOWN == purb->status) || (-ENOENT == purb->status)) { 2939 if ((-ESHUTDOWN == purb->status) || (-ENOENT == purb->status)) {
2514 JOT(8, "urb status -ESHUTDOWN or -ENOENT\n"); 2940 JOM(8, "urb status -ESHUTDOWN or -ENOENT\n");
2515 return; 2941 return;
2516 } 2942 }
2517 2943
2518 (peasycap->field_buffer[peasycap->field_fill][0].kount) |= 0x8000 ; 2944 (peasycap->field_buffer[peasycap->field_fill][0].kount) |= 0x8000 ;
2519 SAY("ERROR: bad urb status:\n"); 2945 SAM("ERROR: bad urb status:\n");
2520 switch (purb->status) { 2946 switch (purb->status) {
2521 case -EINPROGRESS: { 2947 case -EINPROGRESS: {
2522 SAY("-EINPROGRESS\n"); break; 2948 SAM("-EINPROGRESS\n"); break;
2523 } 2949 }
2524 case -ENOSR: { 2950 case -ENOSR: {
2525 SAY("-ENOSR\n"); break; 2951 SAM("-ENOSR\n"); break;
2526 } 2952 }
2527 case -EPIPE: { 2953 case -EPIPE: {
2528 SAY("-EPIPE\n"); break; 2954 SAM("-EPIPE\n"); break;
2529 } 2955 }
2530 case -EOVERFLOW: { 2956 case -EOVERFLOW: {
2531 SAY("-EOVERFLOW\n"); break; 2957 SAM("-EOVERFLOW\n"); break;
2532 } 2958 }
2533 case -EPROTO: { 2959 case -EPROTO: {
2534 SAY("-EPROTO\n"); break; 2960 SAM("-EPROTO\n"); break;
2535 } 2961 }
2536 case -EILSEQ: { 2962 case -EILSEQ: {
2537 SAY("-EILSEQ\n"); break; 2963 SAM("-EILSEQ\n"); break;
2538 } 2964 }
2539 case -ETIMEDOUT: { 2965 case -ETIMEDOUT: {
2540 SAY("-ETIMEDOUT\n"); break; 2966 SAM("-ETIMEDOUT\n"); break;
2541 } 2967 }
2542 case -EMSGSIZE: { 2968 case -EMSGSIZE: {
2543 SAY("-EMSGSIZE\n"); break; 2969 SAM("-EMSGSIZE\n"); break;
2544 } 2970 }
2545 case -EOPNOTSUPP: { 2971 case -EOPNOTSUPP: {
2546 SAY("-EOPNOTSUPP\n"); break; 2972 SAM("-EOPNOTSUPP\n"); break;
2547 } 2973 }
2548 case -EPFNOSUPPORT: { 2974 case -EPFNOSUPPORT: {
2549 SAY("-EPFNOSUPPORT\n"); break; 2975 SAM("-EPFNOSUPPORT\n"); break;
2550 } 2976 }
2551 case -EAFNOSUPPORT: { 2977 case -EAFNOSUPPORT: {
2552 SAY("-EAFNOSUPPORT\n"); break; 2978 SAM("-EAFNOSUPPORT\n"); break;
2553 } 2979 }
2554 case -EADDRINUSE: { 2980 case -EADDRINUSE: {
2555 SAY("-EADDRINUSE\n"); break; 2981 SAM("-EADDRINUSE\n"); break;
2556 } 2982 }
2557 case -EADDRNOTAVAIL: { 2983 case -EADDRNOTAVAIL: {
2558 SAY("-EADDRNOTAVAIL\n"); break; 2984 SAM("-EADDRNOTAVAIL\n"); break;
2559 } 2985 }
2560 case -ENOBUFS: { 2986 case -ENOBUFS: {
2561 SAY("-ENOBUFS\n"); break; 2987 SAM("-ENOBUFS\n"); break;
2562 } 2988 }
2563 case -EISCONN: { 2989 case -EISCONN: {
2564 SAY("-EISCONN\n"); break; 2990 SAM("-EISCONN\n"); break;
2565 } 2991 }
2566 case -ENOTCONN: { 2992 case -ENOTCONN: {
2567 SAY("-ENOTCONN\n"); break; 2993 SAM("-ENOTCONN\n"); break;
2568 } 2994 }
2569 case -ESHUTDOWN: { 2995 case -ESHUTDOWN: {
2570 SAY("-ESHUTDOWN\n"); break; 2996 SAM("-ESHUTDOWN\n"); break;
2571 } 2997 }
2572 case -ENOENT: { 2998 case -ENOENT: {
2573 SAY("-ENOENT\n"); break; 2999 SAM("-ENOENT\n"); break;
2574 } 3000 }
2575 case -ECONNRESET: { 3001 case -ECONNRESET: {
2576 SAY("-ECONNRESET\n"); break; 3002 SAM("-ECONNRESET\n"); break;
2577 } 3003 }
2578 case -ENOSPC: { 3004 case -ENOSPC: {
2579 SAY("ENOSPC\n"); break; 3005 SAM("ENOSPC\n"); break;
2580 } 3006 }
2581 default: { 3007 default: {
2582 SAY("unknown error code 0x%08X\n", purb->status); break; 3008 SAM("unknown error code 0x%08X\n", purb->status); break;
2583 } 3009 }
2584 } 3010 }
2585/*---------------------------------------------------------------------------*/ 3011/*---------------------------------------------------------------------------*/
@@ -2638,7 +3064,7 @@ if (purb->status) {
2638 strcpy(&errbuf[0], "-ECONNRESET"); break; 3064 strcpy(&errbuf[0], "-ECONNRESET"); break;
2639 } 3065 }
2640 case -ENOSPC: { 3066 case -ENOSPC: {
2641 SAY("ENOSPC\n"); break; 3067 SAM("ENOSPC\n"); break;
2642 } 3068 }
2643 case -ESHUTDOWN: { 3069 case -ESHUTDOWN: {
2644 strcpy(&errbuf[0], "-ESHUTDOWN"); break; 3070 strcpy(&errbuf[0], "-ESHUTDOWN"); break;
@@ -2653,7 +3079,7 @@ if (purb->status) {
2653 frameactual = purb->iso_frame_desc[i].actual_length; 3079 frameactual = purb->iso_frame_desc[i].actual_length;
2654 frameoffset = purb->iso_frame_desc[i].offset; 3080 frameoffset = purb->iso_frame_desc[i].offset;
2655 3081
2656 JOT(16, "frame[%2i]:" \ 3082 JOM(16, "frame[%2i]:" \
2657 "%4i=status " \ 3083 "%4i=status " \
2658 "%4i=actual " \ 3084 "%4i=actual " \
2659 "%4i=length " \ 3085 "%4i=length " \
@@ -2667,19 +3093,20 @@ if (purb->status) {
2667 PAGE_SIZE) + \ 3093 PAGE_SIZE) + \
2668 (int)(pfield_buffer->pto - pfield_buffer->pgo); 3094 (int)(pfield_buffer->pto - pfield_buffer->pgo);
2669 if (4 == more) 3095 if (4 == more)
2670 mt++; 3096 peasycap->video_mt++;
2671 if (4 < more) { 3097 if (4 < more) {
2672 if (mt) { 3098 if (peasycap->video_mt) {
2673 JOT(8, "%4i empty video urb frames\n", mt); 3099 JOM(8, "%4i empty video urb frames\n", \
2674 mt = 0; 3100 peasycap->video_mt);
3101 peasycap->video_mt = 0;
2675 } 3102 }
2676 if (FIELD_BUFFER_MANY <= peasycap->field_fill) { 3103 if (FIELD_BUFFER_MANY <= peasycap->field_fill) {
2677 SAY("ERROR: bad peasycap->field_fill\n"); 3104 SAM("ERROR: bad peasycap->field_fill\n");
2678 return; 3105 return;
2679 } 3106 }
2680 if (FIELD_BUFFER_SIZE/PAGE_SIZE <= \ 3107 if (FIELD_BUFFER_SIZE/PAGE_SIZE <= \
2681 peasycap->field_page) { 3108 peasycap->field_page) {
2682 SAY("ERROR: bad peasycap->field_page\n"); 3109 SAM("ERROR: bad peasycap->field_page\n");
2683 return; 3110 return;
2684 } 3111 }
2685 pfield_buffer = &peasycap->field_buffer\ 3112 pfield_buffer = &peasycap->field_buffer\
@@ -2712,11 +3139,13 @@ if (purb->status) {
2712 peasycap->videofieldamount) { 3139 peasycap->videofieldamount) {
2713 if (2 == videofieldamount - \ 3140 if (2 == videofieldamount - \
2714 peasycap->\ 3141 peasycap->\
2715 videofieldamount) 3142 videofieldamount) {
2716 (peasycap->field_buffer\ 3143 (peasycap->field_buffer\
2717 [peasycap->field_fill]\ 3144 [peasycap->field_fill]\
2718 [0].kount) |= 0x0100; 3145 [0].kount) |= 0x0100;
2719 else 3146 peasycap->video_junk += (1 + \
3147 VIDEO_JUNK_TOLERATE);
3148 } else
2720 (peasycap->field_buffer\ 3149 (peasycap->field_buffer\
2721 [peasycap->field_fill]\ 3150 [peasycap->field_fill]\
2722 [0].kount) |= 0x4000; 3151 [0].kount) |= 0x4000;
@@ -2727,53 +3156,74 @@ if (purb->status) {
2727 [peasycap->field_fill]\ 3156 [peasycap->field_fill]\
2728 [0].kount) |= 0x2000; 3157 [0].kount) |= 0x2000;
2729 } 3158 }
2730 if (!(0xFF00 & peasycap->field_buffer\ 3159 bad = 0xFF00 & peasycap->field_buffer\
2731 [peasycap->field_fill]\ 3160 [peasycap->field_fill]\
2732 [0].kount)) { 3161 [0].kount;
2733 (peasycap->video_junk)--; 3162 if (!bad) {
2734 if (-16 > peasycap->video_junk) 3163 (peasycap->video_junk)--;
2735 peasycap->video_junk = -16; 3164 if (-VIDEO_JUNK_TOLERATE > \
2736 peasycap->field_read = \ 3165 peasycap->video_junk) \
3166 peasycap->video_junk =\
3167 -VIDEO_JUNK_TOLERATE;
3168 peasycap->field_read = \
2737 (peasycap->\ 3169 (peasycap->\
2738 field_fill)++; 3170 field_fill)++;
2739 3171 if (FIELD_BUFFER_MANY <= \
2740 if (FIELD_BUFFER_MANY <= \ 3172 peasycap->\
2741 peasycap->field_fill) 3173 field_fill)
2742 peasycap->field_fill = 0; 3174 peasycap->\
2743 peasycap->field_page = 0; 3175 field_fill = 0;
2744 pfield_buffer = &peasycap->\ 3176 peasycap->field_page = 0;
2745 field_buffer\ 3177 pfield_buffer = &peasycap->\
2746 [peasycap->field_fill]\ 3178 field_buffer\
2747 [peasycap->field_page]; 3179 [peasycap->\
2748 pfield_buffer->pto = \ 3180 field_fill]\
3181 [peasycap->\
3182 field_page];
3183 pfield_buffer->pto = \
2749 pfield_buffer->pgo; 3184 pfield_buffer->pgo;
2750 3185 JOM(8, "bumped to: %i="\
2751 JOT(8, "bumped to: %i=peasycap->" \ 3186 "peasycap->" \
2752 "field_fill %i=parity\n", \ 3187 "field_fill %i="\
2753 peasycap->field_fill, \ 3188 "parity\n", \
2754 0x00FF & pfield_buffer->kount); 3189 peasycap->field_fill, \
2755 JOT(8, "field buffer %i has %i " \ 3190 0x00FF & \
2756 "bytes fit to be read\n", \ 3191 pfield_buffer->kount);
2757 peasycap->field_read, \ 3192 JOM(8, "field buffer %i has "\
2758 videofieldamount); 3193 "%i bytes fit to be "\
2759 JOT(8, "wakeup call to wq_video, " \ 3194 "read\n", \
2760 "%i=field_read %i=field_fill "\ 3195 peasycap->field_read, \
2761 "%i=parity\n", \ 3196 videofieldamount);
2762 peasycap->field_read, \ 3197 JOM(8, "wakeup call to "\
2763 peasycap->field_fill, \ 3198 "wq_video, " \
2764 0x00FF & peasycap->\ 3199 "%i=field_read "\
2765 field_buffer[peasycap->\ 3200 "%i=field_fill "\
2766 field_read][0].kount); 3201 "%i=parity\n", \
2767 wake_up_interruptible(&(peasycap->\ 3202 peasycap->field_read, \
2768 wq_video)); 3203 peasycap->field_fill, \
2769 do_gettimeofday(&peasycap->timeval7); 3204 0x00FF & peasycap->\
3205 field_buffer\
3206 [peasycap->\
3207 field_read][0].kount);
3208 wake_up_interruptible\
3209 (&(peasycap->\
3210 wq_video));
3211 do_gettimeofday\
3212 (&peasycap->timeval7);
2770 } else { 3213 } else {
2771 peasycap->video_junk++; 3214 peasycap->video_junk++;
2772 JOT(8, "field buffer %i had %i " \ 3215 if (bad & 0x0010) \
2773 "bytes, now discarded\n", \ 3216 peasycap->video_junk += \
3217 (1 + VIDEO_JUNK_TOLERATE/2);
3218 JOM(8, "field buffer %i had %i " \
3219 "bytes, now discarded: "\
3220 "0x%04X\n", \
2774 peasycap->field_fill, \ 3221 peasycap->field_fill, \
2775 videofieldamount); 3222 videofieldamount,\
2776 3223 (0xFF00 & \
3224 peasycap->field_buffer\
3225 [peasycap->field_fill][0].\
3226 kount));
2777 (peasycap->field_fill)++; 3227 (peasycap->field_fill)++;
2778 3228
2779 if (FIELD_BUFFER_MANY <= \ 3229 if (FIELD_BUFFER_MANY <= \
@@ -2787,20 +3237,22 @@ if (purb->status) {
2787 pfield_buffer->pto = \ 3237 pfield_buffer->pto = \
2788 pfield_buffer->pgo; 3238 pfield_buffer->pgo;
2789 3239
2790 JOT(8, "bumped to: %i=peasycap->" \ 3240 JOM(8, "bumped to: %i=peasycap->" \
2791 "field_fill %i=parity\n", \ 3241 "field_fill %i=parity\n", \
2792 peasycap->field_fill, \ 3242 peasycap->field_fill, \
2793 0x00FF & pfield_buffer->kount); 3243 0x00FF & pfield_buffer->kount);
2794 } 3244 }
2795 if (8 == more) { 3245 if (8 == more) {
2796 JOT(8, "end-of-field: received " \ 3246 JOM(8, "end-of-field: received " \
2797 "parity byte 0x%02X\n", \ 3247 "parity byte 0x%02X\n", \
2798 (0xFF & *pu)); 3248 (0xFF & *pu));
2799 if (0x40 & *pu) 3249 if (0x40 & *pu)
2800 pfield_buffer->kount = 0x0000; 3250 pfield_buffer->kount = 0x0000;
2801 else 3251 else
2802 pfield_buffer->kount = 0x0001; 3252 pfield_buffer->kount = 0x0001;
2803 JOT(8, "end-of-field: 0x%02X=kount\n",\ 3253 pfield_buffer->input = 0x08 | \
3254 (0x07 & peasycap->input);
3255 JOM(8, "end-of-field: 0x%02X=kount\n",\
2804 0xFF & pfield_buffer->kount); 3256 0xFF & pfield_buffer->kount);
2805 } 3257 }
2806 } 3258 }
@@ -2813,12 +3265,12 @@ if (purb->status) {
2813 more -= leap; 3265 more -= leap;
2814 3266
2815 if (FIELD_BUFFER_MANY <= peasycap->field_fill) { 3267 if (FIELD_BUFFER_MANY <= peasycap->field_fill) {
2816 SAY("ERROR: bad peasycap->field_fill\n"); 3268 SAM("ERROR: bad peasycap->field_fill\n");
2817 return; 3269 return;
2818 } 3270 }
2819 if (FIELD_BUFFER_SIZE/PAGE_SIZE <= \ 3271 if (FIELD_BUFFER_SIZE/PAGE_SIZE <= \
2820 peasycap->field_page) { 3272 peasycap->field_page) {
2821 SAY("ERROR: bad peasycap->field_page\n"); 3273 SAM("ERROR: bad peasycap->field_page\n");
2822 return; 3274 return;
2823 } 3275 }
2824 pfield_buffer = &peasycap->field_buffer\ 3276 pfield_buffer = &peasycap->field_buffer\
@@ -2829,7 +3281,7 @@ if (purb->status) {
2829 [peasycap->field_page]; 3281 [peasycap->field_page];
2830 if (PAGE_SIZE < (pfield_buffer->pto - \ 3282 if (PAGE_SIZE < (pfield_buffer->pto - \
2831 pfield_buffer->pgo)) { 3283 pfield_buffer->pgo)) {
2832 SAY("ERROR: bad pfield_buffer->pto\n"); 3284 SAM("ERROR: bad pfield_buffer->pto\n");
2833 return; 3285 return;
2834 } 3286 }
2835 if (PAGE_SIZE == (pfield_buffer->pto - \ 3287 if (PAGE_SIZE == (pfield_buffer->pto - \
@@ -2837,7 +3289,7 @@ if (purb->status) {
2837 (peasycap->field_page)++; 3289 (peasycap->field_page)++;
2838 if (FIELD_BUFFER_SIZE/PAGE_SIZE <= \ 3290 if (FIELD_BUFFER_SIZE/PAGE_SIZE <= \
2839 peasycap->field_page) { 3291 peasycap->field_page) {
2840 JOT(16, "wrapping peasycap->" \ 3292 JOM(16, "wrapping peasycap->" \
2841 "field_page\n"); 3293 "field_page\n");
2842 peasycap->field_page = 0; 3294 peasycap->field_page = 0;
2843 } 3295 }
@@ -2847,6 +3299,15 @@ if (purb->status) {
2847 [peasycap->field_page]; 3299 [peasycap->field_page];
2848 pfield_buffer->pto = \ 3300 pfield_buffer->pto = \
2849 pfield_buffer->pgo; 3301 pfield_buffer->pgo;
3302 pfield_buffer->input = 0x08 | \
3303 (0x07 & peasycap->input);
3304 if ((peasycap->field_buffer[peasycap->\
3305 field_fill][0]).\
3306 input != \
3307 pfield_buffer->input)
3308 (peasycap->field_buffer\
3309 [peasycap->field_fill]\
3310 [0]).kount |= 0x1000;
2850 } 3311 }
2851 3312
2852 much = PAGE_SIZE - (int)(pfield_buffer->pto - \ 3313 much = PAGE_SIZE - (int)(pfield_buffer->pto - \
@@ -2865,55 +3326,6 @@ if (purb->status) {
2865} 3326}
2866/*---------------------------------------------------------------------------*/ 3327/*---------------------------------------------------------------------------*/
2867/* 3328/*
2868 *
2869 *
2870 * *** UNDER DEVELOPMENT/TESTING - NOT READY YET! ***
2871 *
2872 *
2873 *
2874 * VIDEOTAPES MAY HAVE BEEN MANUALLY PAUSED AND RESTARTED DURING RECORDING.
2875 * THIS CAUSES LOSS OF SYNC, CONFUSING DOWNSTREAM USERSPACE PROGRAMS WHICH
2876 * MAY INTERPRET THE INTERRUPTION AS A SYMPTOM OF LATENCY. TO OVERCOME THIS
2877 * THE DRIVER BRIDGES THE HIATUS BY SENDING DUMMY VIDEO FRAMES AT ROUGHLY
2878 * THE RIGHT TIME INTERVALS IN THE HOPE OF PERSUADING THE DOWNSTREAM USERSPACE
2879 * PROGRAM TO RESUME NORMAL SERVICE WHEN THE INTERRUPTION IS OVER.
2880 */
2881/*---------------------------------------------------------------------------*/
2882#if defined(BRIDGER)
2883do_gettimeofday(&timeval);
2884if (peasycap->timeval7.tv_sec) {
2885 usec = 1000000*(timeval.tv_sec - peasycap->timeval7.tv_sec) + \
2886 (timeval.tv_usec - peasycap->timeval7.tv_usec);
2887 if (usec > (peasycap->usec + peasycap->tolerate)) {
2888 JOT(8, "bridging hiatus\n");
2889 peasycap->video_junk = 0;
2890 peasycap->field_buffer[peasycap->field_fill][0].kount |= 0x0400;
2891
2892 peasycap->field_read = (peasycap->field_fill)++;
2893
2894 if (FIELD_BUFFER_MANY <= peasycap->field_fill) \
2895 peasycap->field_fill = 0;
2896 peasycap->field_page = 0;
2897 pfield_buffer = &peasycap->field_buffer\
2898 [peasycap->field_fill][peasycap->field_page];
2899 pfield_buffer->pto = pfield_buffer->pgo;
2900
2901 JOT(8, "bumped to: %i=peasycap->field_fill %i=parity\n", \
2902 peasycap->field_fill, 0x00FF & pfield_buffer->kount);
2903 JOT(8, "field buffer %i has %i bytes to be overwritten\n", \
2904 peasycap->field_read, videofieldamount);
2905 JOT(8, "wakeup call to wq_video, " \
2906 "%i=field_read %i=field_fill %i=parity\n", \
2907 peasycap->field_read, peasycap->field_fill, \
2908 0x00FF & \
2909 peasycap->field_buffer[peasycap->field_read][0].kount);
2910 wake_up_interruptible(&(peasycap->wq_video));
2911 do_gettimeofday(&peasycap->timeval7);
2912 }
2913}
2914#endif /*BRIDGER*/
2915/*---------------------------------------------------------------------------*/
2916/*
2917 * RESUBMIT THIS URB, UNLESS A SEVERE PERSISTENT ERROR CONDITION EXISTS. 3329 * RESUBMIT THIS URB, UNLESS A SEVERE PERSISTENT ERROR CONDITION EXISTS.
2918 * 3330 *
2919 * IF THE WAIT QUEUES ARE NOT CLEARED IN RESPONSE TO AN ERROR CONDITION 3331 * IF THE WAIT QUEUES ARE NOT CLEARED IN RESPONSE TO AN ERROR CONDITION
@@ -2921,51 +3333,57 @@ if (peasycap->timeval7.tv_sec) {
2921 */ 3333 */
2922/*---------------------------------------------------------------------------*/ 3334/*---------------------------------------------------------------------------*/
2923if (VIDEO_ISOC_BUFFER_MANY <= peasycap->video_junk) { 3335if (VIDEO_ISOC_BUFFER_MANY <= peasycap->video_junk) {
2924 SAY("easycap driver shutting down on condition green\n"); 3336 SAM("easycap driver shutting down on condition green\n");
3337 peasycap->status = 1;
2925 peasycap->video_eof = 1; 3338 peasycap->video_eof = 1;
3339 peasycap->video_junk = 0;
3340 wake_up_interruptible(&peasycap->wq_video);
3341#if !defined(PERSEVERE)
2926 peasycap->audio_eof = 1; 3342 peasycap->audio_eof = 1;
2927 peasycap->video_junk = -VIDEO_ISOC_BUFFER_MANY; 3343 wake_up_interruptible(&peasycap->wq_audio);
2928 wake_up_interruptible(&(peasycap->wq_video)); 3344#endif /*PERSEVERE*/
2929 wake_up_interruptible(&(peasycap->wq_audio));
2930 return; 3345 return;
2931} 3346}
2932if (peasycap->video_isoc_streaming) { 3347if (peasycap->video_isoc_streaming) {
2933 rc = usb_submit_urb(purb, GFP_ATOMIC); 3348 rc = usb_submit_urb(purb, GFP_ATOMIC);
2934 if (0 != rc) { 3349 if (0 != rc) {
2935 SAY("ERROR: while %i=video_idle, usb_submit_urb() failed " \
2936 "with rc:\n", peasycap->video_idle);
2937 switch (rc) { 3350 switch (rc) {
2938 case -ENOMEM: { 3351 case -ENOMEM: {
2939 SAY("ENOMEM\n"); break; 3352 SAM("ENOMEM\n"); break;
2940 } 3353 }
2941 case -ENODEV: { 3354 case -ENODEV: {
2942 SAY("ENODEV\n"); break; 3355 SAM("ENODEV\n"); break;
2943 } 3356 }
2944 case -ENXIO: { 3357 case -ENXIO: {
2945 SAY("ENXIO\n"); break; 3358 SAM("ENXIO\n"); break;
2946 } 3359 }
2947 case -EINVAL: { 3360 case -EINVAL: {
2948 SAY("EINVAL\n"); break; 3361 SAM("EINVAL\n"); break;
2949 } 3362 }
2950 case -EAGAIN: { 3363 case -EAGAIN: {
2951 SAY("EAGAIN\n"); break; 3364 SAM("EAGAIN\n"); break;
2952 } 3365 }
2953 case -EFBIG: { 3366 case -EFBIG: {
2954 SAY("EFBIG\n"); break; 3367 SAM("EFBIG\n"); break;
2955 } 3368 }
2956 case -EPIPE: { 3369 case -EPIPE: {
2957 SAY("EPIPE\n"); break; 3370 SAM("EPIPE\n"); break;
2958 } 3371 }
2959 case -EMSGSIZE: { 3372 case -EMSGSIZE: {
2960 SAY("EMSGSIZE\n"); break; 3373 SAM("EMSGSIZE\n"); break;
2961 } 3374 }
2962 case -ENOSPC: { 3375 case -ENOSPC: {
2963 SAY("ENOSPC\n"); break; 3376 SAM("ENOSPC\n"); break;
2964 } 3377 }
2965 default: { 3378 default: {
2966 SAY("0x%08X\n", rc); break; 3379 SAM("0x%08X\n", rc); break;
2967 } 3380 }
2968 } 3381 }
3382 if (-ENODEV != rc) \
3383 SAM("ERROR: while %i=video_idle, " \
3384 "usb_submit_urb() " \
3385 "failed with rc:\n", \
3386 peasycap->video_idle);
2969 } 3387 }
2970} 3388}
2971return; 3389return;
@@ -2977,8 +3395,8 @@ return;
2977 * FIXME 3395 * FIXME
2978 * 3396 *
2979 * 3397 *
2980 * THIS FUNCTION ASSUMES THAT, ON EACH AND EVERY OCCASION THAT THE DEVICE IS 3398 * THIS FUNCTION ASSUMES THAT, ON EACH AND EVERY OCCASION THAT THE EasyCAP
2981 * PHYSICALLY PLUGGED IN, INTERFACE 0 IS PROBED FIRST. 3399 * IS PHYSICALLY PLUGGED IN, INTERFACE 0 IS PROBED FIRST.
2982 * IF THIS IS NOT TRUE, THERE IS THE POSSIBILITY OF AN Oops. 3400 * IF THIS IS NOT TRUE, THERE IS THE POSSIBILITY OF AN Oops.
2983 * 3401 *
2984 * THIS HAS NEVER BEEN A PROBLEM IN PRACTICE, BUT SOMETHING SEEMS WRONG HERE. 3402 * THIS HAS NEVER BEEN A PROBLEM IN PRACTICE, BUT SOMETHING SEEMS WRONG HERE.
@@ -2994,7 +3412,7 @@ struct usb_endpoint_descriptor *pepd;
2994struct usb_interface_descriptor *pusb_interface_descriptor; 3412struct usb_interface_descriptor *pusb_interface_descriptor;
2995struct usb_interface_assoc_descriptor *pusb_interface_assoc_descriptor; 3413struct usb_interface_assoc_descriptor *pusb_interface_assoc_descriptor;
2996struct urb *purb; 3414struct urb *purb;
2997static struct easycap *peasycap /*=NULL*/; 3415struct easycap *peasycap;
2998struct data_urb *pdata_urb; 3416struct data_urb *pdata_urb;
2999size_t wMaxPacketSize; 3417size_t wMaxPacketSize;
3000int ISOCwMaxPacketSize; 3418int ISOCwMaxPacketSize;
@@ -3004,19 +3422,32 @@ int CTRLwMaxPacketSize;
3004__u8 bEndpointAddress; 3422__u8 bEndpointAddress;
3005__u8 ISOCbEndpointAddress; 3423__u8 ISOCbEndpointAddress;
3006__u8 INTbEndpointAddress; 3424__u8 INTbEndpointAddress;
3007int isin, i, j, k, m; 3425int isin, i, j, k, m, rc;
3008__u8 bInterfaceNumber; 3426__u8 bInterfaceNumber;
3009__u8 bInterfaceClass; 3427__u8 bInterfaceClass;
3010__u8 bInterfaceSubClass; 3428__u8 bInterfaceSubClass;
3011void *pbuf; 3429void *pbuf;
3012int okalt[8], isokalt; 3430int okalt[8], isokalt;
3013int okepn[8], isokepn; 3431int okepn[8];
3014int okmps[8], isokmps; 3432int okmps[8];
3015int maxpacketsize; 3433int maxpacketsize;
3016int rc; 3434__u16 mask;
3435__s32 value;
3436struct easycap_format *peasycap_format;
3017 3437
3018JOT(4, "\n"); 3438JOT(4, "\n");
3019 3439
3440if (!dongle_done) {
3441 dongle_done = 1;
3442 for (k = 0; k < DONGLE_MANY; k++) {
3443 easycap_dongle[k].peasycap = (struct easycap *)NULL;
3444 mutex_init(&easycap_dongle[k].mutex_video);
3445 mutex_init(&easycap_dongle[k].mutex_audio);
3446 }
3447}
3448
3449peasycap = (struct easycap *)NULL;
3450
3020if ((struct usb_interface *)NULL == pusb_interface) { 3451if ((struct usb_interface *)NULL == pusb_interface) {
3021 SAY("ERROR: pusb_interface is NULL\n"); 3452 SAY("ERROR: pusb_interface is NULL\n");
3022 return -EFAULT; 3453 return -EFAULT;
@@ -3117,46 +3548,83 @@ JOT(4, "intf[%i]: pusb_interface_assoc_descriptor is NULL\n", \
3117/* 3548/*
3118 * A NEW struct easycap IS ALWAYS ALLOCATED WHEN INTERFACE 0 IS PROBED. 3549 * A NEW struct easycap IS ALWAYS ALLOCATED WHEN INTERFACE 0 IS PROBED.
3119 * IT IS NOT POSSIBLE HERE TO FREE ANY EXISTING struct easycap. THIS 3550 * IT IS NOT POSSIBLE HERE TO FREE ANY EXISTING struct easycap. THIS
3120 * SHOULD HAVE BEEN DONE BY easycap_delete() WHEN THE DEVICE WAS PHYSICALLY 3551 * SHOULD HAVE BEEN DONE BY easycap_delete() WHEN THE EasyCAP WAS
3121 * UNPLUGGED. 3552 * PHYSICALLY UNPLUGGED.
3122 */ 3553 *
3554 * THE POINTER peasycap TO THE struct easycap IS REMEMBERED WHEN
3555 * INTERFACES 1 AND 2 ARE PROBED.
3556 *
3557 * IF TWO EasyCAPs ARE PLUGGED IN NEARLY SIMULTANEOUSLY THERE WILL
3558 * BE TROUBLE. BEWARE.
3559*/
3123/*---------------------------------------------------------------------------*/ 3560/*---------------------------------------------------------------------------*/
3124if (0 == bInterfaceNumber) { 3561if (0 == bInterfaceNumber) {
3125 peasycap = kzalloc(sizeof(struct easycap), GFP_KERNEL); 3562 peasycap = kzalloc(sizeof(struct easycap), GFP_KERNEL);
3126 if (NULL == peasycap) { 3563 if (NULL == peasycap) {
3127 SAY("ERROR: Could not allocate peasycap\n"); 3564 SAY("ERROR: Could not allocate peasycap\n");
3128 return -ENOMEM; 3565 return -ENOMEM;
3129 } else {
3130 peasycap->allocation_video_struct = sizeof(struct easycap);
3131 peasycap->allocation_video_page = 0;
3132 peasycap->allocation_video_urb = 0;
3133 peasycap->allocation_audio_struct = 0;
3134 peasycap->allocation_audio_page = 0;
3135 peasycap->allocation_audio_urb = 0;
3136 } 3566 }
3567 SAM("allocated 0x%08lX=peasycap\n", (unsigned long int) peasycap);
3568/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
3569#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
3570 SAM("where 0x%08lX=&peasycap->video_device\n", \
3571 (unsigned long int) &peasycap->video_device);
3572#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
3573 SAM("and 0x%08lX=&peasycap->v4l2_device\n", \
3574 (unsigned long int) &peasycap->v4l2_device);
3575#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
3576#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
3577/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
3137/*---------------------------------------------------------------------------*/ 3578/*---------------------------------------------------------------------------*/
3138/* 3579/*
3139 * INITIALIZE THE NEW easycap STRUCTURE. 3580 * PERFORM URGENT INTIALIZATIONS ...
3140 * NO PARAMETERS ARE SPECIFIED HERE REQUIRING THE SETTING OF REGISTERS. 3581*/
3141 * THAT IS DONE FIRST BY easycap_open() AND LATER BY easycap_ioctl().
3142 */
3143/*---------------------------------------------------------------------------*/ 3582/*---------------------------------------------------------------------------*/
3144 peasycap->pusb_device = pusb_device; 3583 strcpy(&peasycap->telltale[0], TELLTALE);
3145 peasycap->pusb_interface = pusb_interface;
3146
3147 kref_init(&peasycap->kref); 3584 kref_init(&peasycap->kref);
3148 JOT(8, "intf[%i]: after kref_init(..._video) " \ 3585 JOM(8, "intf[%i]: after kref_init(..._video) " \
3149 "%i=peasycap->kref.refcount.counter\n", \ 3586 "%i=peasycap->kref.refcount.counter\n", \
3150 bInterfaceNumber, peasycap->kref.refcount.counter); 3587 bInterfaceNumber, peasycap->kref.refcount.counter);
3151 3588
3152 init_waitqueue_head(&(peasycap->wq_video)); 3589 init_waitqueue_head(&peasycap->wq_video);
3153 init_waitqueue_head(&(peasycap->wq_audio)); 3590 init_waitqueue_head(&peasycap->wq_audio);
3591
3592 for (dongle_this = 0; dongle_this < DONGLE_MANY; dongle_this++) {
3593 if (NULL == easycap_dongle[dongle_this].peasycap) {
3594 if (0 == mutex_is_locked(&easycap_dongle\
3595 [dongle_this].mutex_video)) {
3596 if (0 == mutex_is_locked(&easycap_dongle\
3597 [dongle_this].mutex_audio)) {
3598 easycap_dongle\
3599 [dongle_this].peasycap = \
3600 peasycap;
3601 JOM(8, "intf[%i]: peasycap-->easycap" \
3602 "_dongle[%i].peasycap\n", \
3603 bInterfaceNumber, dongle_this);
3604 break;
3605 }
3606 }
3607 }
3608 }
3609 if (DONGLE_MANY <= dongle_this) {
3610 SAM("ERROR: too many dongles\n");
3611 return -ENOMEM;
3612 }
3154 3613
3155 mutex_init(&(peasycap->mutex_timeval0)); 3614 peasycap->allocation_video_struct = sizeof(struct easycap);
3156 mutex_init(&(peasycap->mutex_timeval1)); 3615 peasycap->allocation_video_page = 0;
3616 peasycap->allocation_video_urb = 0;
3617 peasycap->allocation_audio_struct = 0;
3618 peasycap->allocation_audio_page = 0;
3619 peasycap->allocation_audio_urb = 0;
3157 3620
3158 for (k = 0; k < FRAME_BUFFER_MANY; k++) 3621/*---------------------------------------------------------------------------*/
3159 mutex_init(&(peasycap->mutex_mmap_video[k])); 3622/*
3623 * ... AND FURTHER INITIALIZE THE STRUCTURE
3624*/
3625/*---------------------------------------------------------------------------*/
3626 peasycap->pusb_device = pusb_device;
3627 peasycap->pusb_interface = pusb_interface;
3160 3628
3161 peasycap->ilk = 0; 3629 peasycap->ilk = 0;
3162 peasycap->microphone = false; 3630 peasycap->microphone = false;
@@ -3177,46 +3645,172 @@ if (0 == bInterfaceNumber) {
3177 3645
3178 peasycap->frame_buffer_many = FRAME_BUFFER_MANY; 3646 peasycap->frame_buffer_many = FRAME_BUFFER_MANY;
3179 3647
3180 if ((struct mutex *)NULL == &(peasycap->mutex_mmap_video[0])) { 3648 for (k = 0; k < INPUT_MANY; k++)
3181 SAY("ERROR: &(peasycap->mutex_mmap_video[%i]) is NULL\n", 0); 3649 peasycap->lost[k] = 0;
3182 return -EFAULT; 3650 peasycap->skip = 0;
3183 } 3651 peasycap->skipped = 0;
3652 peasycap->offerfields = 0;
3184/*---------------------------------------------------------------------------*/ 3653/*---------------------------------------------------------------------------*/
3185/* 3654/*
3186 * DYNAMICALLY FILL IN THE AVAILABLE FORMATS. 3655 * DYNAMICALLY FILL IN THE AVAILABLE FORMATS ...
3187 */ 3656 */
3188/*---------------------------------------------------------------------------*/ 3657/*---------------------------------------------------------------------------*/
3189 rc = fillin_formats(); 3658 rc = fillin_formats();
3190 if (0 > rc) { 3659 if (0 > rc) {
3191 SAY("ERROR: fillin_formats() returned %i\n", rc); 3660 SAM("ERROR: fillin_formats() returned %i\n", rc);
3192 return -EFAULT; 3661 return -EFAULT;
3193 } 3662 }
3194 JOT(4, "%i formats available\n", rc); 3663 JOM(4, "%i formats available\n", rc);
3195 } else {
3196/*---------------------------------------------------------------------------*/ 3664/*---------------------------------------------------------------------------*/
3197 if ((struct easycap *)NULL == peasycap) { 3665/*
3198 SAY("ERROR: peasycap is NULL " \ 3666 * ... AND POPULATE easycap.inputset[]
3199 "when probing interface %i\n", \ 3667*/
3200 bInterfaceNumber); 3668/*---------------------------------------------------------------------------*/
3201 return -EFAULT; 3669 for (k = 0; k < INPUT_MANY; k++) {
3670 peasycap->inputset[k].input_ok = 0;
3671 peasycap->inputset[k].standard_offset_ok = 0;
3672 peasycap->inputset[k].format_offset_ok = 0;
3673 peasycap->inputset[k].brightness_ok = 0;
3674 peasycap->inputset[k].contrast_ok = 0;
3675 peasycap->inputset[k].saturation_ok = 0;
3676 peasycap->inputset[k].hue_ok = 0;
3677 }
3678 if (true == peasycap->ntsc) {
3679 i = 0;
3680 m = 0;
3681 mask = 0;
3682 while (0xFFFF != easycap_standard[i].mask) {
3683 if (NTSC_M == easycap_standard[i].\
3684 v4l2_standard.index) {
3685 m++;
3686 for (k = 0; k < INPUT_MANY; k++) {
3687 peasycap->inputset[k].\
3688 standard_offset = i;
3689 }
3690 mask = easycap_standard[i].mask;
3691 }
3692 i++;
3202 } 3693 }
3694 } else {
3695 i = 0;
3696 m = 0;
3697 mask = 0;
3698 while (0xFFFF != easycap_standard[i].mask) {
3699 if (PAL_BGHIN == easycap_standard[i].\
3700 v4l2_standard.index) {
3701 m++;
3702 for (k = 0; k < INPUT_MANY; k++) {
3703 peasycap->inputset[k].\
3704 standard_offset = i;
3705 }
3706 mask = easycap_standard[i].mask;
3707 }
3708 i++;
3709 }
3710 }
3203 3711
3204 JOT(8, "kref_get() with %i=peasycap->kref.refcount.counter\n", \ 3712 if (1 != m) {
3205 (int)peasycap->kref.refcount.counter); 3713 SAM("MISTAKE: easycap.inputset[].standard_offset " \
3206 kref_get(&peasycap->kref); 3714 "unpopulated, %i=m\n", m);
3715 return -ENOENT;
3716 }
3717
3718 peasycap_format = &easycap_format[0];
3719 i = 0;
3720 m = 0;
3721 while (0 != peasycap_format->v4l2_format.fmt.pix.width) {
3722 if (((peasycap_format->mask & 0x0F) == (mask & 0x0F)) && \
3723 (peasycap_format->\
3724 v4l2_format.fmt.pix.field == \
3725 V4L2_FIELD_NONE) && \
3726 (peasycap_format->\
3727 v4l2_format.fmt.pix.pixelformat == \
3728 V4L2_PIX_FMT_UYVY) && \
3729 (peasycap_format->\
3730 v4l2_format.fmt.pix.width == \
3731 640) && \
3732 (peasycap_format->\
3733 v4l2_format.fmt.pix.height == 480)) {
3734 m++;
3735 for (k = 0; k < INPUT_MANY; k++)
3736 peasycap->inputset[k].format_offset = i;
3737 break;
3738 }
3739 peasycap_format++;
3740 i++;
3741 }
3742 if (1 != m) {
3743 SAM("MISTAKE: easycap.inputset[].format_offset unpopulated\n");
3744 return -ENOENT;
3745 }
3746
3747 i = 0;
3748 m = 0;
3749 while (0xFFFFFFFF != easycap_control[i].id) {
3750 value = easycap_control[i].default_value;
3751 if (V4L2_CID_BRIGHTNESS == easycap_control[i].id) {
3752 m++;
3753 for (k = 0; k < INPUT_MANY; k++)
3754 peasycap->inputset[k].brightness = value;
3755 } else if (V4L2_CID_CONTRAST == easycap_control[i].id) {
3756 m++;
3757 for (k = 0; k < INPUT_MANY; k++)
3758 peasycap->inputset[k].contrast = value;
3759 } else if (V4L2_CID_SATURATION == easycap_control[i].id) {
3760 m++;
3761 for (k = 0; k < INPUT_MANY; k++)
3762 peasycap->inputset[k].saturation = value;
3763 } else if (V4L2_CID_HUE == easycap_control[i].id) {
3764 m++;
3765 for (k = 0; k < INPUT_MANY; k++)
3766 peasycap->inputset[k].hue = value;
3767 }
3768 i++;
3769 }
3770 if (4 != m) {
3771 SAM("MISTAKE: easycap.inputset[].brightness,... " \
3772 "underpopulated\n");
3773 return -ENOENT;
3774 }
3775 for (k = 0; k < INPUT_MANY; k++)
3776 peasycap->inputset[k].input = k;
3777 JOM(4, "populated easycap.inputset[]\n");
3778 JOM(4, "finished initialization\n");
3779} else {
3780/*---------------------------------------------------------------------------*/
3781 /*
3782 * FOR INTERFACES 1 AND 2 THE POINTER peasycap IS OBTAINED BY ASSUMING
3783 * THAT dongle_this HAS NOT CHANGED SINCE INTERFACE 0 WAS PROBED. IF
3784 * THIS IS NOT THE CASE, FOR EXAMPLE WHEN TWO EASYCAPs ARE PLUGGED IN
3785 * SIMULTANEOUSLY, THERE WILL BE SERIOUS TROUBLE.
3786 */
3787/*---------------------------------------------------------------------------*/
3788 if ((0 > dongle_this) || (DONGLE_MANY <= dongle_this)) {
3789 SAY("ERROR: bad dongle count\n");
3790 return -EFAULT;
3791 }
3792 peasycap = easycap_dongle[dongle_this].peasycap;
3793 JOT(8, "intf[%i]: easycap_dongle[%i].peasycap-->peasycap\n", \
3794 bInterfaceNumber, dongle_this);
3795
3796 if ((struct easycap *)NULL == peasycap) {
3797 SAY("ERROR: peasycap is NULL when probing interface %i\n", \
3798 bInterfaceNumber);
3799 return -EFAULT;
3800 }
3207} 3801}
3208/*---------------------------------------------------------------------------*/ 3802/*---------------------------------------------------------------------------*/
3209if ((USB_CLASS_VIDEO == bInterfaceClass) || \ 3803if ((USB_CLASS_VIDEO == bInterfaceClass) || \
3210 (USB_CLASS_VENDOR_SPEC == bInterfaceClass)) { 3804 (USB_CLASS_VENDOR_SPEC == bInterfaceClass)) {
3211 if (-1 == peasycap->video_interface) { 3805 if (-1 == peasycap->video_interface) {
3212 peasycap->video_interface = bInterfaceNumber; 3806 peasycap->video_interface = bInterfaceNumber;
3213 JOT(4, "setting peasycap->video_interface=%i\n", \ 3807 JOM(4, "setting peasycap->video_interface=%i\n", \
3214 peasycap->video_interface); 3808 peasycap->video_interface);
3215 } else { 3809 } else {
3216 if (peasycap->video_interface != bInterfaceNumber) { 3810 if (peasycap->video_interface != bInterfaceNumber) {
3217 SAY("ERROR: attempting to reset " \ 3811 SAM("ERROR: attempting to reset " \
3218 "peasycap->video_interface\n"); 3812 "peasycap->video_interface\n");
3219 SAY("...... continuing with " \ 3813 SAM("...... continuing with " \
3220 "%i=peasycap->video_interface\n", \ 3814 "%i=peasycap->video_interface\n", \
3221 peasycap->video_interface); 3815 peasycap->video_interface);
3222 } 3816 }
@@ -3225,13 +3819,13 @@ if ((USB_CLASS_VIDEO == bInterfaceClass) || \
3225 (0x02 == bInterfaceSubClass)) { 3819 (0x02 == bInterfaceSubClass)) {
3226 if (-1 == peasycap->audio_interface) { 3820 if (-1 == peasycap->audio_interface) {
3227 peasycap->audio_interface = bInterfaceNumber; 3821 peasycap->audio_interface = bInterfaceNumber;
3228 JOT(4, "setting peasycap->audio_interface=%i\n", \ 3822 JOM(4, "setting peasycap->audio_interface=%i\n", \
3229 peasycap->audio_interface); 3823 peasycap->audio_interface);
3230 } else { 3824 } else {
3231 if (peasycap->audio_interface != bInterfaceNumber) { 3825 if (peasycap->audio_interface != bInterfaceNumber) {
3232 SAY("ERROR: attempting to reset " \ 3826 SAM("ERROR: attempting to reset " \
3233 "peasycap->audio_interface\n"); 3827 "peasycap->audio_interface\n");
3234 SAY("...... continuing with " \ 3828 SAM("...... continuing with " \
3235 "%i=peasycap->audio_interface\n", \ 3829 "%i=peasycap->audio_interface\n", \
3236 peasycap->audio_interface); 3830 peasycap->audio_interface);
3237 } 3831 }
@@ -3244,37 +3838,35 @@ if ((USB_CLASS_VIDEO == bInterfaceClass) || \
3244 */ 3838 */
3245/*---------------------------------------------------------------------------*/ 3839/*---------------------------------------------------------------------------*/
3246isokalt = 0; 3840isokalt = 0;
3247isokepn = 0;
3248isokmps = 0;
3249 3841
3250for (i = 0; i < pusb_interface->num_altsetting; i++) { 3842for (i = 0; i < pusb_interface->num_altsetting; i++) {
3251 pusb_host_interface = &(pusb_interface->altsetting[i]); 3843 pusb_host_interface = &(pusb_interface->altsetting[i]);
3252 if ((struct usb_host_interface *)NULL == pusb_host_interface) { 3844 if ((struct usb_host_interface *)NULL == pusb_host_interface) {
3253 SAY("ERROR: pusb_host_interface is NULL\n"); 3845 SAM("ERROR: pusb_host_interface is NULL\n");
3254 return -EFAULT; 3846 return -EFAULT;
3255 } 3847 }
3256 pusb_interface_descriptor = &(pusb_host_interface->desc); 3848 pusb_interface_descriptor = &(pusb_host_interface->desc);
3257 if ((struct usb_interface_descriptor *)NULL == \ 3849 if ((struct usb_interface_descriptor *)NULL == \
3258 pusb_interface_descriptor) { 3850 pusb_interface_descriptor) {
3259 SAY("ERROR: pusb_interface_descriptor is NULL\n"); 3851 SAM("ERROR: pusb_interface_descriptor is NULL\n");
3260 return -EFAULT; 3852 return -EFAULT;
3261 } 3853 }
3262 3854
3263 JOT(4, "intf[%i]alt[%i]: desc.bDescriptorType=0x%02X\n", \ 3855 JOM(4, "intf[%i]alt[%i]: desc.bDescriptorType=0x%02X\n", \
3264 bInterfaceNumber, i, pusb_interface_descriptor->bDescriptorType); 3856 bInterfaceNumber, i, pusb_interface_descriptor->bDescriptorType);
3265 JOT(4, "intf[%i]alt[%i]: desc.bInterfaceNumber=0x%02X\n", \ 3857 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceNumber=0x%02X\n", \
3266 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceNumber); 3858 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceNumber);
3267 JOT(4, "intf[%i]alt[%i]: desc.bAlternateSetting=0x%02X\n", \ 3859 JOM(4, "intf[%i]alt[%i]: desc.bAlternateSetting=0x%02X\n", \
3268 bInterfaceNumber, i, pusb_interface_descriptor->bAlternateSetting); 3860 bInterfaceNumber, i, pusb_interface_descriptor->bAlternateSetting);
3269 JOT(4, "intf[%i]alt[%i]: desc.bNumEndpoints=0x%02X\n", \ 3861 JOM(4, "intf[%i]alt[%i]: desc.bNumEndpoints=0x%02X\n", \
3270 bInterfaceNumber, i, pusb_interface_descriptor->bNumEndpoints); 3862 bInterfaceNumber, i, pusb_interface_descriptor->bNumEndpoints);
3271 JOT(4, "intf[%i]alt[%i]: desc.bInterfaceClass=0x%02X\n", \ 3863 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceClass=0x%02X\n", \
3272 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceClass); 3864 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceClass);
3273 JOT(4, "intf[%i]alt[%i]: desc.bInterfaceSubClass=0x%02X\n", \ 3865 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceSubClass=0x%02X\n", \
3274 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceSubClass); 3866 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceSubClass);
3275 JOT(4, "intf[%i]alt[%i]: desc.bInterfaceProtocol=0x%02X\n", \ 3867 JOM(4, "intf[%i]alt[%i]: desc.bInterfaceProtocol=0x%02X\n", \
3276 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceProtocol); 3868 bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceProtocol);
3277 JOT(4, "intf[%i]alt[%i]: desc.iInterface=0x%02X\n", \ 3869 JOM(4, "intf[%i]alt[%i]: desc.iInterface=0x%02X\n", \
3278 bInterfaceNumber, i, pusb_interface_descriptor->iInterface); 3870 bInterfaceNumber, i, pusb_interface_descriptor->iInterface);
3279 3871
3280 ISOCwMaxPacketSize = -1; 3872 ISOCwMaxPacketSize = -1;
@@ -3285,86 +3877,80 @@ for (i = 0; i < pusb_interface->num_altsetting; i++) {
3285 INTbEndpointAddress = 0; 3877 INTbEndpointAddress = 0;
3286 3878
3287 if (0 == pusb_interface_descriptor->bNumEndpoints) 3879 if (0 == pusb_interface_descriptor->bNumEndpoints)
3288 JOT(4, "intf[%i]alt[%i] has no endpoints\n", \ 3880 JOM(4, "intf[%i]alt[%i] has no endpoints\n", \
3289 bInterfaceNumber, i); 3881 bInterfaceNumber, i);
3290/*---------------------------------------------------------------------------*/ 3882/*---------------------------------------------------------------------------*/
3291 for (j = 0; j < pusb_interface_descriptor->bNumEndpoints; j++) { 3883 for (j = 0; j < pusb_interface_descriptor->bNumEndpoints; j++) {
3292 pepd = &(pusb_host_interface->endpoint[j].desc); 3884 pepd = &(pusb_host_interface->endpoint[j].desc);
3293 if ((struct usb_endpoint_descriptor *)NULL == pepd) { 3885 if ((struct usb_endpoint_descriptor *)NULL == pepd) {
3294 SAY("ERROR: pepd is NULL.\n"); 3886 SAM("ERROR: pepd is NULL.\n");
3295 SAY("...... skipping\n"); 3887 SAM("...... skipping\n");
3296 continue; 3888 continue;
3297 } 3889 }
3298 wMaxPacketSize = le16_to_cpu(pepd->wMaxPacketSize); 3890 wMaxPacketSize = le16_to_cpu(pepd->wMaxPacketSize);
3299 bEndpointAddress = pepd->bEndpointAddress; 3891 bEndpointAddress = pepd->bEndpointAddress;
3300 3892
3301 JOT(4, "intf[%i]alt[%i]end[%i]: bEndpointAddress=0x%X\n", \ 3893 JOM(4, "intf[%i]alt[%i]end[%i]: bEndpointAddress=0x%X\n", \
3302 bInterfaceNumber, i, j, \ 3894 bInterfaceNumber, i, j, \
3303 pepd->bEndpointAddress); 3895 pepd->bEndpointAddress);
3304 JOT(4, "intf[%i]alt[%i]end[%i]: bmAttributes=0x%X\n", \ 3896 JOM(4, "intf[%i]alt[%i]end[%i]: bmAttributes=0x%X\n", \
3305 bInterfaceNumber, i, j, \ 3897 bInterfaceNumber, i, j, \
3306 pepd->bmAttributes); 3898 pepd->bmAttributes);
3307 JOT(4, "intf[%i]alt[%i]end[%i]: wMaxPacketSize=%i\n", \ 3899 JOM(4, "intf[%i]alt[%i]end[%i]: wMaxPacketSize=%i\n", \
3308 bInterfaceNumber, i, j, \ 3900 bInterfaceNumber, i, j, \
3309 pepd->wMaxPacketSize); 3901 pepd->wMaxPacketSize);
3310 JOT(4, "intf[%i]alt[%i]end[%i]: bInterval=%i\n", 3902 JOM(4, "intf[%i]alt[%i]end[%i]: bInterval=%i\n",
3311 bInterfaceNumber, i, j, \ 3903 bInterfaceNumber, i, j, \
3312 pepd->bInterval); 3904 pepd->bInterval);
3313 3905
3314 if (pepd->bEndpointAddress & USB_DIR_IN) { 3906 if (pepd->bEndpointAddress & USB_DIR_IN) {
3315 JOT(4, "intf[%i]alt[%i]end[%i] is an IN endpoint\n",\ 3907 JOM(4, "intf[%i]alt[%i]end[%i] is an IN endpoint\n",\
3316 bInterfaceNumber, i, j); 3908 bInterfaceNumber, i, j);
3317 isin = 1; 3909 isin = 1;
3318 } else { 3910 } else {
3319 JOT(4, "intf[%i]alt[%i]end[%i] is an OUT endpoint\n",\ 3911 JOM(4, "intf[%i]alt[%i]end[%i] is an OUT endpoint\n",\
3320 bInterfaceNumber, i, j); 3912 bInterfaceNumber, i, j);
3321 SAY("ERROR: OUT endpoint unexpected\n"); 3913 SAM("ERROR: OUT endpoint unexpected\n");
3322 SAY("...... continuing\n"); 3914 SAM("...... continuing\n");
3323 isin = 0; 3915 isin = 0;
3324 } 3916 }
3325 if ((pepd->bmAttributes & \ 3917 if ((pepd->bmAttributes & \
3326 USB_ENDPOINT_XFERTYPE_MASK) == \ 3918 USB_ENDPOINT_XFERTYPE_MASK) == \
3327 USB_ENDPOINT_XFER_ISOC) { 3919 USB_ENDPOINT_XFER_ISOC) {
3328 JOT(4, "intf[%i]alt[%i]end[%i] is an ISOC endpoint\n",\ 3920 JOM(4, "intf[%i]alt[%i]end[%i] is an ISOC endpoint\n",\
3329 bInterfaceNumber, i, j); 3921 bInterfaceNumber, i, j);
3330 if (isin) { 3922 if (isin) {
3331 switch (bInterfaceClass) { 3923 switch (bInterfaceClass) {
3332 case USB_CLASS_VIDEO: 3924 case USB_CLASS_VIDEO:
3333 case USB_CLASS_VENDOR_SPEC: { 3925 case USB_CLASS_VENDOR_SPEC: {
3334 if (!peasycap) { 3926 if (!peasycap) {
3335 SAY("MISTAKE: " \ 3927 SAM("MISTAKE: " \
3336 "peasycap is NULL\n"); 3928 "peasycap is NULL\n");
3337 return -EFAULT; 3929 return -EFAULT;
3338 } 3930 }
3339 if (pepd->wMaxPacketSize) { 3931 if (pepd->wMaxPacketSize) {
3340 if (8 > isokalt) { 3932 if (8 > isokalt) {
3341 okalt[isokalt] = i; 3933 okalt[isokalt] = i;
3342 JOT(4,\ 3934 JOM(4,\
3343 "%i=okalt[%i]\n", \ 3935 "%i=okalt[%i]\n", \
3344 okalt[isokalt], \ 3936 okalt[isokalt], \
3345 isokalt); 3937 isokalt);
3346 isokalt++; 3938 okepn[isokalt] = \
3347 }
3348 if (8 > isokepn) {
3349 okepn[isokepn] = \
3350 pepd->\ 3939 pepd->\
3351 bEndpointAddress & \ 3940 bEndpointAddress & \
3352 0x0F; 3941 0x0F;
3353 JOT(4,\ 3942 JOM(4,\
3354 "%i=okepn[%i]\n", \ 3943 "%i=okepn[%i]\n", \
3355 okepn[isokepn], \ 3944 okepn[isokalt], \
3356 isokepn); 3945 isokalt);
3357 isokepn++; 3946 okmps[isokalt] = \
3358 }
3359 if (8 > isokmps) {
3360 okmps[isokmps] = \
3361 le16_to_cpu(pepd->\ 3947 le16_to_cpu(pepd->\
3362 wMaxPacketSize); 3948 wMaxPacketSize);
3363 JOT(4,\ 3949 JOM(4,\
3364 "%i=okmps[%i]\n", \ 3950 "%i=okmps[%i]\n", \
3365 okmps[isokmps], \ 3951 okmps[isokalt], \
3366 isokmps); 3952 isokalt);
3367 isokmps++; 3953 isokalt++;
3368 } 3954 }
3369 } else { 3955 } else {
3370 if (-1 == peasycap->\ 3956 if (-1 == peasycap->\
@@ -3372,16 +3958,16 @@ for (i = 0; i < pusb_interface->num_altsetting; i++) {
3372 peasycap->\ 3958 peasycap->\
3373 video_altsetting_off =\ 3959 video_altsetting_off =\
3374 i; 3960 i;
3375 JOT(4, "%i=video_" \ 3961 JOM(4, "%i=video_" \
3376 "altsetting_off " \ 3962 "altsetting_off " \
3377 "<====\n", \ 3963 "<====\n", \
3378 peasycap->\ 3964 peasycap->\
3379 video_altsetting_off); 3965 video_altsetting_off);
3380 } else { 3966 } else {
3381 SAY("ERROR: peasycap" \ 3967 SAM("ERROR: peasycap" \
3382 "->video_altsetting_" \ 3968 "->video_altsetting_" \
3383 "off already set\n"); 3969 "off already set\n");
3384 SAY("...... " \ 3970 SAM("...... " \
3385 "continuing with " \ 3971 "continuing with " \
3386 "%i=peasycap->video_" \ 3972 "%i=peasycap->video_" \
3387 "altsetting_off\n", \ 3973 "altsetting_off\n", \
@@ -3395,39 +3981,33 @@ for (i = 0; i < pusb_interface->num_altsetting; i++) {
3395 if (0x02 != bInterfaceSubClass) 3981 if (0x02 != bInterfaceSubClass)
3396 break; 3982 break;
3397 if (!peasycap) { 3983 if (!peasycap) {
3398 SAY("MISTAKE: " \ 3984 SAM("MISTAKE: " \
3399 "peasycap is NULL\n"); 3985 "peasycap is NULL\n");
3400 return -EFAULT; 3986 return -EFAULT;
3401 } 3987 }
3402 if (pepd->wMaxPacketSize) { 3988 if (pepd->wMaxPacketSize) {
3403 if (8 > isokalt) { 3989 if (8 > isokalt) {
3404 okalt[isokalt] = i ; 3990 okalt[isokalt] = i ;
3405 JOT(4,\ 3991 JOM(4,\
3406 "%i=okalt[%i]\n", \ 3992 "%i=okalt[%i]\n", \
3407 okalt[isokalt], \ 3993 okalt[isokalt], \
3408 isokalt); 3994 isokalt);
3409 isokalt++; 3995 okepn[isokalt] = \
3410 }
3411 if (8 > isokepn) {
3412 okepn[isokepn] = \
3413 pepd->\ 3996 pepd->\
3414 bEndpointAddress & \ 3997 bEndpointAddress & \
3415 0x0F; 3998 0x0F;
3416 JOT(4,\ 3999 JOM(4,\
3417 "%i=okepn[%i]\n", \ 4000 "%i=okepn[%i]\n", \
3418 okepn[isokepn], \ 4001 okepn[isokalt], \
3419 isokepn); 4002 isokalt);
3420 isokepn++; 4003 okmps[isokalt] = \
3421 }
3422 if (8 > isokmps) {
3423 okmps[isokmps] = \
3424 le16_to_cpu(pepd->\ 4004 le16_to_cpu(pepd->\
3425 wMaxPacketSize); 4005 wMaxPacketSize);
3426 JOT(4,\ 4006 JOM(4,\
3427 "%i=okmps[%i]\n",\ 4007 "%i=okmps[%i]\n",\
3428 okmps[isokmps], \ 4008 okmps[isokalt], \
3429 isokmps); 4009 isokalt);
3430 isokmps++; 4010 isokalt++;
3431 } 4011 }
3432 } else { 4012 } else {
3433 if (-1 == peasycap->\ 4013 if (-1 == peasycap->\
@@ -3435,16 +4015,16 @@ for (i = 0; i < pusb_interface->num_altsetting; i++) {
3435 peasycap->\ 4015 peasycap->\
3436 audio_altsetting_off =\ 4016 audio_altsetting_off =\
3437 i; 4017 i;
3438 JOT(4, "%i=audio_" \ 4018 JOM(4, "%i=audio_" \
3439 "altsetting_off " \ 4019 "altsetting_off " \
3440 "<====\n", \ 4020 "<====\n", \
3441 peasycap->\ 4021 peasycap->\
3442 audio_altsetting_off); 4022 audio_altsetting_off);
3443 } else { 4023 } else {
3444 SAY("ERROR: peasycap" \ 4024 SAM("ERROR: peasycap" \
3445 "->audio_altsetting_" \ 4025 "->audio_altsetting_" \
3446 "off already set\n"); 4026 "off already set\n");
3447 SAY("...... " \ 4027 SAM("...... " \
3448 "continuing with " \ 4028 "continuing with " \
3449 "%i=peasycap->\ 4029 "%i=peasycap->\
3450 audio_altsetting_" \ 4030 audio_altsetting_" \
@@ -3462,19 +4042,19 @@ for (i = 0; i < pusb_interface->num_altsetting; i++) {
3462 } else if ((pepd->bmAttributes & \ 4042 } else if ((pepd->bmAttributes & \
3463 USB_ENDPOINT_XFERTYPE_MASK) ==\ 4043 USB_ENDPOINT_XFERTYPE_MASK) ==\
3464 USB_ENDPOINT_XFER_BULK) { 4044 USB_ENDPOINT_XFER_BULK) {
3465 JOT(4, "intf[%i]alt[%i]end[%i] is a BULK endpoint\n",\ 4045 JOM(4, "intf[%i]alt[%i]end[%i] is a BULK endpoint\n",\
3466 bInterfaceNumber, i, j); 4046 bInterfaceNumber, i, j);
3467 } else if ((pepd->bmAttributes & \ 4047 } else if ((pepd->bmAttributes & \
3468 USB_ENDPOINT_XFERTYPE_MASK) ==\ 4048 USB_ENDPOINT_XFERTYPE_MASK) ==\
3469 USB_ENDPOINT_XFER_INT) { 4049 USB_ENDPOINT_XFER_INT) {
3470 JOT(4, "intf[%i]alt[%i]end[%i] is an INT endpoint\n",\ 4050 JOM(4, "intf[%i]alt[%i]end[%i] is an INT endpoint\n",\
3471 bInterfaceNumber, i, j); 4051 bInterfaceNumber, i, j);
3472 } else { 4052 } else {
3473 JOT(4, "intf[%i]alt[%i]end[%i] is a CTRL endpoint\n",\ 4053 JOM(4, "intf[%i]alt[%i]end[%i] is a CTRL endpoint\n",\
3474 bInterfaceNumber, i, j); 4054 bInterfaceNumber, i, j);
3475 } 4055 }
3476 if (0 == pepd->wMaxPacketSize) { 4056 if (0 == pepd->wMaxPacketSize) {
3477 JOT(4, "intf[%i]alt[%i]end[%i] " \ 4057 JOM(4, "intf[%i]alt[%i]end[%i] " \
3478 "has zero packet size\n", \ 4058 "has zero packet size\n", \
3479 bInterfaceNumber, i, j); 4059 bInterfaceNumber, i, j);
3480 } 4060 }
@@ -3485,7 +4065,7 @@ for (i = 0; i < pusb_interface->num_altsetting; i++) {
3485 * PERFORM INITIALIZATION OF THE PROBED INTERFACE 4065 * PERFORM INITIALIZATION OF THE PROBED INTERFACE
3486 */ 4066 */
3487/*---------------------------------------------------------------------------*/ 4067/*---------------------------------------------------------------------------*/
3488JOT(4, "initialization begins for interface %i\n", \ 4068JOM(4, "initialization begins for interface %i\n", \
3489 pusb_interface_descriptor->bInterfaceNumber); 4069 pusb_interface_descriptor->bInterfaceNumber);
3490switch (bInterfaceNumber) { 4070switch (bInterfaceNumber) {
3491/*---------------------------------------------------------------------------*/ 4071/*---------------------------------------------------------------------------*/
@@ -3495,89 +4075,78 @@ switch (bInterfaceNumber) {
3495/*---------------------------------------------------------------------------*/ 4075/*---------------------------------------------------------------------------*/
3496case 0: { 4076case 0: {
3497 if (!peasycap) { 4077 if (!peasycap) {
3498 SAY("MISTAKE: peasycap is NULL\n"); 4078 SAM("MISTAKE: peasycap is NULL\n");
3499 return -EFAULT; 4079 return -EFAULT;
3500 } 4080 }
3501 if (!isokalt) { 4081 if (!isokalt) {
3502 SAY("ERROR: no viable video_altsetting_on\n"); 4082 SAM("ERROR: no viable video_altsetting_on\n");
3503 return -ENOENT; 4083 return -ENOENT;
3504 } else { 4084 } else {
3505 peasycap->video_altsetting_on = okalt[isokalt - 1]; 4085 peasycap->video_altsetting_on = okalt[isokalt - 1];
3506 JOT(4, "%i=video_altsetting_on <====\n", \ 4086 JOM(4, "%i=video_altsetting_on <====\n", \
3507 peasycap->video_altsetting_on); 4087 peasycap->video_altsetting_on);
3508 } 4088 }
3509 if (!isokepn) {
3510 SAY("ERROR: no viable video_endpointnumber\n");
3511 return -ENOENT;
3512 } else {
3513 peasycap->video_endpointnumber = okepn[isokepn - 1];
3514 JOT(4, "%i=video_endpointnumber\n", \
3515 peasycap->video_endpointnumber);
3516 }
3517 if (!isokmps) {
3518 SAY("ERROR: no viable video_maxpacketsize\n");
3519 return -ENOENT;
3520/*---------------------------------------------------------------------------*/ 4089/*---------------------------------------------------------------------------*/
3521/* 4090/*
3522 * DECIDE THE VIDEO STREAMING PARAMETERS 4091 * DECIDE THE VIDEO STREAMING PARAMETERS
3523 */ 4092 */
3524/*---------------------------------------------------------------------------*/ 4093/*---------------------------------------------------------------------------*/
4094 peasycap->video_endpointnumber = okepn[isokalt - 1];
4095 JOM(4, "%i=video_endpointnumber\n", peasycap->video_endpointnumber);
4096 maxpacketsize = okmps[isokalt - 1];
4097 if (USB_2_0_MAXPACKETSIZE > maxpacketsize) {
4098 peasycap->video_isoc_maxframesize = maxpacketsize;
3525 } else { 4099 } else {
3526 maxpacketsize = okmps[isokmps - 1] - 1024; 4100 peasycap->video_isoc_maxframesize = \
3527 if (USB_2_0_MAXPACKETSIZE > maxpacketsize) { 4101 USB_2_0_MAXPACKETSIZE;
3528 peasycap->video_isoc_maxframesize = maxpacketsize; 4102 }
3529 } else { 4103 JOM(4, "%i=video_isoc_maxframesize\n", \
3530 peasycap->video_isoc_maxframesize = \ 4104 peasycap->video_isoc_maxframesize);
3531 USB_2_0_MAXPACKETSIZE; 4105 if (0 >= peasycap->video_isoc_maxframesize) {
3532 } 4106 SAM("ERROR: bad video_isoc_maxframesize\n");
3533 JOT(4, "%i=video_isoc_maxframesize\n", \ 4107 SAM(" possibly because port is USB 1.1\n");
3534 peasycap->video_isoc_maxframesize); 4108 return -ENOENT;
3535 if (0 >= peasycap->video_isoc_maxframesize) { 4109 }
3536 SAY("ERROR: bad video_isoc_maxframesize\n"); 4110 peasycap->video_isoc_framesperdesc = VIDEO_ISOC_FRAMESPERDESC;
3537 return -ENOENT; 4111 JOM(4, "%i=video_isoc_framesperdesc\n", \
3538 } 4112 peasycap->video_isoc_framesperdesc);
3539 peasycap->video_isoc_framesperdesc = VIDEO_ISOC_FRAMESPERDESC; 4113 if (0 >= peasycap->video_isoc_framesperdesc) {
3540 JOT(4, "%i=video_isoc_framesperdesc\n", \ 4114 SAM("ERROR: bad video_isoc_framesperdesc\n");
3541 peasycap->video_isoc_framesperdesc); 4115 return -ENOENT;
3542 if (0 >= peasycap->video_isoc_framesperdesc) { 4116 }
3543 SAY("ERROR: bad video_isoc_framesperdesc\n"); 4117 peasycap->video_isoc_buffer_size = \
3544 return -ENOENT; 4118 peasycap->video_isoc_maxframesize * \
3545 } 4119 peasycap->video_isoc_framesperdesc;
3546 peasycap->video_isoc_buffer_size = \ 4120 JOM(4, "%i=video_isoc_buffer_size\n", \
3547 peasycap->video_isoc_maxframesize * \ 4121 peasycap->video_isoc_buffer_size);
3548 peasycap->video_isoc_framesperdesc; 4122 if ((PAGE_SIZE << VIDEO_ISOC_ORDER) < \
3549 JOT(4, "%i=video_isoc_buffer_size\n", \ 4123 peasycap->video_isoc_buffer_size) {
3550 peasycap->video_isoc_buffer_size); 4124 SAM("MISTAKE: peasycap->video_isoc_buffer_size too big\n");
3551 if ((PAGE_SIZE << VIDEO_ISOC_ORDER) < \ 4125 return -EFAULT;
3552 peasycap->video_isoc_buffer_size) {
3553 SAY("MISTAKE: " \
3554 "peasycap->video_isoc_buffer_size too big\n");
3555 return -EFAULT;
3556 }
3557 } 4126 }
3558/*---------------------------------------------------------------------------*/ 4127/*---------------------------------------------------------------------------*/
3559 if (-1 == peasycap->video_interface) { 4128 if (-1 == peasycap->video_interface) {
3560 SAY("MISTAKE: video_interface is unset\n"); 4129 SAM("MISTAKE: video_interface is unset\n");
3561 return -EFAULT; 4130 return -EFAULT;
3562 } 4131 }
3563 if (-1 == peasycap->video_altsetting_on) { 4132 if (-1 == peasycap->video_altsetting_on) {
3564 SAY("MISTAKE: video_altsetting_on is unset\n"); 4133 SAM("MISTAKE: video_altsetting_on is unset\n");
3565 return -EFAULT; 4134 return -EFAULT;
3566 } 4135 }
3567 if (-1 == peasycap->video_altsetting_off) { 4136 if (-1 == peasycap->video_altsetting_off) {
3568 SAY("MISTAKE: video_interface_off is unset\n"); 4137 SAM("MISTAKE: video_interface_off is unset\n");
3569 return -EFAULT; 4138 return -EFAULT;
3570 } 4139 }
3571 if (-1 == peasycap->video_endpointnumber) { 4140 if (-1 == peasycap->video_endpointnumber) {
3572 SAY("MISTAKE: video_endpointnumber is unset\n"); 4141 SAM("MISTAKE: video_endpointnumber is unset\n");
3573 return -EFAULT; 4142 return -EFAULT;
3574 } 4143 }
3575 if (-1 == peasycap->video_isoc_maxframesize) { 4144 if (-1 == peasycap->video_isoc_maxframesize) {
3576 SAY("MISTAKE: video_isoc_maxframesize is unset\n"); 4145 SAM("MISTAKE: video_isoc_maxframesize is unset\n");
3577 return -EFAULT; 4146 return -EFAULT;
3578 } 4147 }
3579 if (-1 == peasycap->video_isoc_buffer_size) { 4148 if (-1 == peasycap->video_isoc_buffer_size) {
3580 SAY("MISTAKE: video_isoc_buffer_size is unset\n"); 4149 SAM("MISTAKE: video_isoc_buffer_size is unset\n");
3581 return -EFAULT; 4150 return -EFAULT;
3582 } 4151 }
3583/*---------------------------------------------------------------------------*/ 4152/*---------------------------------------------------------------------------*/
@@ -3588,20 +4157,20 @@ case 0: {
3588 INIT_LIST_HEAD(&(peasycap->urb_video_head)); 4157 INIT_LIST_HEAD(&(peasycap->urb_video_head));
3589 peasycap->purb_video_head = &(peasycap->urb_video_head); 4158 peasycap->purb_video_head = &(peasycap->urb_video_head);
3590/*---------------------------------------------------------------------------*/ 4159/*---------------------------------------------------------------------------*/
3591 JOT(4, "allocating %i frame buffers of size %li\n", \ 4160 JOM(4, "allocating %i frame buffers of size %li\n", \
3592 FRAME_BUFFER_MANY, (long int)FRAME_BUFFER_SIZE); 4161 FRAME_BUFFER_MANY, (long int)FRAME_BUFFER_SIZE);
3593 JOT(4, ".... each scattered over %li pages\n", \ 4162 JOM(4, ".... each scattered over %li pages\n", \
3594 FRAME_BUFFER_SIZE/PAGE_SIZE); 4163 FRAME_BUFFER_SIZE/PAGE_SIZE);
3595 4164
3596 for (k = 0; k < FRAME_BUFFER_MANY; k++) { 4165 for (k = 0; k < FRAME_BUFFER_MANY; k++) {
3597 for (m = 0; m < FRAME_BUFFER_SIZE/PAGE_SIZE; m++) { 4166 for (m = 0; m < FRAME_BUFFER_SIZE/PAGE_SIZE; m++) {
3598 if ((void *)NULL != peasycap->frame_buffer[k][m].pgo) 4167 if ((void *)NULL != peasycap->frame_buffer[k][m].pgo)
3599 SAY("attempting to reallocate frame " \ 4168 SAM("attempting to reallocate frame " \
3600 " buffers\n"); 4169 " buffers\n");
3601 else { 4170 else {
3602 pbuf = (void *)__get_free_page(GFP_KERNEL); 4171 pbuf = (void *)__get_free_page(GFP_KERNEL);
3603 if ((void *)NULL == pbuf) { 4172 if ((void *)NULL == pbuf) {
3604 SAY("ERROR: Could not allocate frame "\ 4173 SAM("ERROR: Could not allocate frame "\
3605 "buffer %i page %i\n", k, m); 4174 "buffer %i page %i\n", k, m);
3606 return -ENOMEM; 4175 return -ENOMEM;
3607 } else 4176 } else
@@ -3615,23 +4184,23 @@ case 0: {
3615 4184
3616 peasycap->frame_fill = 0; 4185 peasycap->frame_fill = 0;
3617 peasycap->frame_read = 0; 4186 peasycap->frame_read = 0;
3618 JOT(4, "allocation of frame buffers done: %i pages\n", k * \ 4187 JOM(4, "allocation of frame buffers done: %i pages\n", k * \
3619 m); 4188 m);
3620/*---------------------------------------------------------------------------*/ 4189/*---------------------------------------------------------------------------*/
3621 JOT(4, "allocating %i field buffers of size %li\n", \ 4190 JOM(4, "allocating %i field buffers of size %li\n", \
3622 FIELD_BUFFER_MANY, (long int)FIELD_BUFFER_SIZE); 4191 FIELD_BUFFER_MANY, (long int)FIELD_BUFFER_SIZE);
3623 JOT(4, ".... each scattered over %li pages\n", \ 4192 JOM(4, ".... each scattered over %li pages\n", \
3624 FIELD_BUFFER_SIZE/PAGE_SIZE); 4193 FIELD_BUFFER_SIZE/PAGE_SIZE);
3625 4194
3626 for (k = 0; k < FIELD_BUFFER_MANY; k++) { 4195 for (k = 0; k < FIELD_BUFFER_MANY; k++) {
3627 for (m = 0; m < FIELD_BUFFER_SIZE/PAGE_SIZE; m++) { 4196 for (m = 0; m < FIELD_BUFFER_SIZE/PAGE_SIZE; m++) {
3628 if ((void *)NULL != peasycap->field_buffer[k][m].pgo) { 4197 if ((void *)NULL != peasycap->field_buffer[k][m].pgo) {
3629 SAY("ERROR: attempting to reallocate " \ 4198 SAM("ERROR: attempting to reallocate " \
3630 "field buffers\n"); 4199 "field buffers\n");
3631 } else { 4200 } else {
3632 pbuf = (void *) __get_free_page(GFP_KERNEL); 4201 pbuf = (void *) __get_free_page(GFP_KERNEL);
3633 if ((void *)NULL == pbuf) { 4202 if ((void *)NULL == pbuf) {
3634 SAY("ERROR: Could not allocate field" \ 4203 SAM("ERROR: Could not allocate field" \
3635 " buffer %i page %i\n", k, m); 4204 " buffer %i page %i\n", k, m);
3636 return -ENOMEM; 4205 return -ENOMEM;
3637 } 4206 }
@@ -3647,18 +4216,18 @@ case 0: {
3647 peasycap->field_fill = 0; 4216 peasycap->field_fill = 0;
3648 peasycap->field_page = 0; 4217 peasycap->field_page = 0;
3649 peasycap->field_read = 0; 4218 peasycap->field_read = 0;
3650 JOT(4, "allocation of field buffers done: %i pages\n", k * \ 4219 JOM(4, "allocation of field buffers done: %i pages\n", k * \
3651 m); 4220 m);
3652/*---------------------------------------------------------------------------*/ 4221/*---------------------------------------------------------------------------*/
3653 JOT(4, "allocating %i isoc video buffers of size %i\n", \ 4222 JOM(4, "allocating %i isoc video buffers of size %i\n", \
3654 VIDEO_ISOC_BUFFER_MANY, \ 4223 VIDEO_ISOC_BUFFER_MANY, \
3655 peasycap->video_isoc_buffer_size); 4224 peasycap->video_isoc_buffer_size);
3656 JOT(4, ".... each occupying contiguous memory pages\n"); 4225 JOM(4, ".... each occupying contiguous memory pages\n");
3657 4226
3658 for (k = 0; k < VIDEO_ISOC_BUFFER_MANY; k++) { 4227 for (k = 0; k < VIDEO_ISOC_BUFFER_MANY; k++) {
3659 pbuf = (void *)__get_free_pages(GFP_KERNEL, VIDEO_ISOC_ORDER); 4228 pbuf = (void *)__get_free_pages(GFP_KERNEL, VIDEO_ISOC_ORDER);
3660 if (NULL == pbuf) { 4229 if (NULL == pbuf) {
3661 SAY("ERROR: Could not allocate isoc video buffer " \ 4230 SAM("ERROR: Could not allocate isoc video buffer " \
3662 "%i\n", k); 4231 "%i\n", k);
3663 return -ENOMEM; 4232 return -ENOMEM;
3664 } else 4233 } else
@@ -3670,26 +4239,26 @@ case 0: {
3670 peasycap->video_isoc_buffer_size; 4239 peasycap->video_isoc_buffer_size;
3671 peasycap->video_isoc_buffer[k].kount = k; 4240 peasycap->video_isoc_buffer[k].kount = k;
3672 } 4241 }
3673 JOT(4, "allocation of isoc video buffers done: %i pages\n", \ 4242 JOM(4, "allocation of isoc video buffers done: %i pages\n", \
3674 k * (0x01 << VIDEO_ISOC_ORDER)); 4243 k * (0x01 << VIDEO_ISOC_ORDER));
3675/*---------------------------------------------------------------------------*/ 4244/*---------------------------------------------------------------------------*/
3676/* 4245/*
3677 * ALLOCATE AND INITIALIZE MULTIPLE struct urb ... 4246 * ALLOCATE AND INITIALIZE MULTIPLE struct urb ...
3678 */ 4247 */
3679/*---------------------------------------------------------------------------*/ 4248/*---------------------------------------------------------------------------*/
3680 JOT(4, "allocating %i struct urb.\n", VIDEO_ISOC_BUFFER_MANY); 4249 JOM(4, "allocating %i struct urb.\n", VIDEO_ISOC_BUFFER_MANY);
3681 JOT(4, "using %i=peasycap->video_isoc_framesperdesc\n", \ 4250 JOM(4, "using %i=peasycap->video_isoc_framesperdesc\n", \
3682 peasycap->video_isoc_framesperdesc); 4251 peasycap->video_isoc_framesperdesc);
3683 JOT(4, "using %i=peasycap->video_isoc_maxframesize\n", \ 4252 JOM(4, "using %i=peasycap->video_isoc_maxframesize\n", \
3684 peasycap->video_isoc_maxframesize); 4253 peasycap->video_isoc_maxframesize);
3685 JOT(4, "using %i=peasycap->video_isoc_buffer_sizen", \ 4254 JOM(4, "using %i=peasycap->video_isoc_buffer_sizen", \
3686 peasycap->video_isoc_buffer_size); 4255 peasycap->video_isoc_buffer_size);
3687 4256
3688 for (k = 0; k < VIDEO_ISOC_BUFFER_MANY; k++) { 4257 for (k = 0; k < VIDEO_ISOC_BUFFER_MANY; k++) {
3689 purb = usb_alloc_urb(peasycap->video_isoc_framesperdesc, \ 4258 purb = usb_alloc_urb(peasycap->video_isoc_framesperdesc, \
3690 GFP_KERNEL); 4259 GFP_KERNEL);
3691 if (NULL == purb) { 4260 if (NULL == purb) {
3692 SAY("ERROR: usb_alloc_urb returned NULL for buffer " \ 4261 SAM("ERROR: usb_alloc_urb returned NULL for buffer " \
3693 "%i\n", k); 4262 "%i\n", k);
3694 return -ENOMEM; 4263 return -ENOMEM;
3695 } else 4264 } else
@@ -3697,7 +4266,7 @@ case 0: {
3697/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 4266/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
3698 pdata_urb = kzalloc(sizeof(struct data_urb), GFP_KERNEL); 4267 pdata_urb = kzalloc(sizeof(struct data_urb), GFP_KERNEL);
3699 if (NULL == pdata_urb) { 4268 if (NULL == pdata_urb) {
3700 SAY("ERROR: Could not allocate struct data_urb.\n"); 4269 SAM("ERROR: Could not allocate struct data_urb.\n");
3701 return -ENOMEM; 4270 return -ENOMEM;
3702 } else 4271 } else
3703 peasycap->allocation_video_struct += \ 4272 peasycap->allocation_video_struct += \
@@ -3714,30 +4283,30 @@ case 0: {
3714 */ 4283 */
3715/*---------------------------------------------------------------------------*/ 4284/*---------------------------------------------------------------------------*/
3716 if (!k) { 4285 if (!k) {
3717 JOT(4, "initializing video urbs thus:\n"); 4286 JOM(4, "initializing video urbs thus:\n");
3718 JOT(4, " purb->interval = 1;\n"); 4287 JOM(4, " purb->interval = 1;\n");
3719 JOT(4, " purb->dev = peasycap->pusb_device;\n"); 4288 JOM(4, " purb->dev = peasycap->pusb_device;\n");
3720 JOT(4, " purb->pipe = usb_rcvisocpipe" \ 4289 JOM(4, " purb->pipe = usb_rcvisocpipe" \
3721 "(peasycap->pusb_device,%i);\n", \ 4290 "(peasycap->pusb_device,%i);\n", \
3722 peasycap->video_endpointnumber); 4291 peasycap->video_endpointnumber);
3723 JOT(4, " purb->transfer_flags = URB_ISO_ASAP;\n"); 4292 JOM(4, " purb->transfer_flags = URB_ISO_ASAP;\n");
3724 JOT(4, " purb->transfer_buffer = peasycap->" \ 4293 JOM(4, " purb->transfer_buffer = peasycap->" \
3725 "video_isoc_buffer[.].pgo;\n"); 4294 "video_isoc_buffer[.].pgo;\n");
3726 JOT(4, " purb->transfer_buffer_length = %i;\n", \ 4295 JOM(4, " purb->transfer_buffer_length = %i;\n", \
3727 peasycap->video_isoc_buffer_size); 4296 peasycap->video_isoc_buffer_size);
3728 JOT(4, " purb->complete = easycap_complete;\n"); 4297 JOM(4, " purb->complete = easycap_complete;\n");
3729 JOT(4, " purb->context = peasycap;\n"); 4298 JOM(4, " purb->context = peasycap;\n");
3730 JOT(4, " purb->start_frame = 0;\n"); 4299 JOM(4, " purb->start_frame = 0;\n");
3731 JOT(4, " purb->number_of_packets = %i;\n", \ 4300 JOM(4, " purb->number_of_packets = %i;\n", \
3732 peasycap->video_isoc_framesperdesc); 4301 peasycap->video_isoc_framesperdesc);
3733 JOT(4, " for (j = 0; j < %i; j++)\n", \ 4302 JOM(4, " for (j = 0; j < %i; j++)\n", \
3734 peasycap->video_isoc_framesperdesc); 4303 peasycap->video_isoc_framesperdesc);
3735 JOT(4, " {\n"); 4304 JOM(4, " {\n");
3736 JOT(4, " purb->iso_frame_desc[j].offset = j*%i;\n",\ 4305 JOM(4, " purb->iso_frame_desc[j].offset = j*%i;\n",\
3737 peasycap->video_isoc_maxframesize); 4306 peasycap->video_isoc_maxframesize);
3738 JOT(4, " purb->iso_frame_desc[j].length = %i;\n", \ 4307 JOM(4, " purb->iso_frame_desc[j].length = %i;\n", \
3739 peasycap->video_isoc_maxframesize); 4308 peasycap->video_isoc_maxframesize);
3740 JOT(4, " }\n"); 4309 JOM(4, " }\n");
3741 } 4310 }
3742 4311
3743 purb->interval = 1; 4312 purb->interval = 1;
@@ -3759,13 +4328,33 @@ case 0: {
3759 peasycap->video_isoc_maxframesize; 4328 peasycap->video_isoc_maxframesize;
3760 } 4329 }
3761 } 4330 }
3762 JOT(4, "allocation of %i struct urb done.\n", k); 4331 JOM(4, "allocation of %i struct urb done.\n", k);
3763/*--------------------------------------------------------------------------*/ 4332/*--------------------------------------------------------------------------*/
3764/* 4333/*
3765 * SAVE POINTER peasycap IN THIS INTERFACE. 4334 * SAVE POINTER peasycap IN THIS INTERFACE.
3766 */ 4335 */
3767/*--------------------------------------------------------------------------*/ 4336/*--------------------------------------------------------------------------*/
3768 usb_set_intfdata(pusb_interface, peasycap); 4337 usb_set_intfdata(pusb_interface, peasycap);
4338/*---------------------------------------------------------------------------*/
4339/*
4340 * IT IS ESSENTIAL TO INITIALIZE THE HARDWARE BEFORE, RATHER THAN AFTER,
4341 * THE DEVICE IS REGISTERED, BECAUSE SOME VERSIONS OF THE videodev MODULE
4342 * CALL easycap_open() IMMEDIATELY AFTER REGISTRATION, CAUSING A CLASH.
4343 * BEWARE.
4344*/
4345/*---------------------------------------------------------------------------*/
4346#if defined(PREFER_NTSC)
4347 peasycap->ntsc = true;
4348 JOM(8, "defaulting initially to NTSC\n");
4349#else
4350 peasycap->ntsc = false;
4351 JOM(8, "defaulting initially to PAL\n");
4352#endif /*PREFER_NTSC*/
4353 rc = reset(peasycap);
4354 if (0 != rc) {
4355 SAM("ERROR: reset() returned %i\n", rc);
4356 return -EFAULT;
4357 }
3769/*--------------------------------------------------------------------------*/ 4358/*--------------------------------------------------------------------------*/
3770/* 4359/*
3771 * THE VIDEO DEVICE CAN BE REGISTERED NOW, AS IT IS READY. 4360 * THE VIDEO DEVICE CAN BE REGISTERED NOW, AS IT IS READY.
@@ -3776,48 +4365,58 @@ case 0: {
3776 err("Not able to get a minor for this device"); 4365 err("Not able to get a minor for this device");
3777 usb_set_intfdata(pusb_interface, NULL); 4366 usb_set_intfdata(pusb_interface, NULL);
3778 return -ENODEV; 4367 return -ENODEV;
3779 } else 4368 } else {
3780 (peasycap->registered_video)++; 4369 (peasycap->registered_video)++;
3781 SAY("easycap attached to minor #%d\n", pusb_interface->minor); 4370 SAM("easycap attached to minor #%d\n", pusb_interface->minor);
3782 break; 4371 break;
3783/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
3784#else
3785 pvideo_device = (struct video_device *)\
3786 kzalloc(sizeof(struct video_device), GFP_KERNEL);
3787 if ((struct video_device *)NULL == pvideo_device) {
3788 SAY("ERROR: Could not allocate structure video_device\n");
3789 return -ENOMEM;
3790 } 4372 }
3791 if (VIDEO_DEVICE_MANY <= video_device_many) { 4373/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
3792 SAY("ERROR: Too many /dev/videos\n"); 4374#else
3793 return -ENOMEM; 4375#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
4376 if (0 != (v4l2_device_register(&(pusb_interface->dev), \
4377 &(peasycap->v4l2_device)))) {
4378 SAM("v4l2_device_register() failed\n");
4379 return -ENODEV;
4380 } else {
4381 JOM(4, "registered device instance: %s\n", \
4382 &(peasycap->v4l2_device.name[0]));
3794 } 4383 }
3795 pvideo_array[video_device_many] = pvideo_device; video_device_many++; 4384/*---------------------------------------------------------------------------*/
4385/*
4386 * FIXME
4387 *
4388 *
4389 * THIS IS BELIEVED TO BE HARMLESS, BUT MAY WELL BE UNNECESSARY OR WRONG:
4390*/
4391/*---------------------------------------------------------------------------*/
4392 peasycap->video_device.v4l2_dev = (struct v4l2_device *)NULL;
4393/*---------------------------------------------------------------------------*/
4394
4395#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
3796 4396
3797 strcpy(&pvideo_device->name[0], "easycapdc60"); 4397 strcpy(&peasycap->video_device.name[0], "easycapdc60");
3798#if defined(EASYCAP_NEEDS_V4L2_FOPS) 4398#if defined(EASYCAP_NEEDS_V4L2_FOPS)
3799 pvideo_device->fops = &v4l2_fops; 4399 peasycap->video_device.fops = &v4l2_fops;
3800#else 4400#else
3801 pvideo_device->fops = &easycap_fops; 4401 peasycap->video_device.fops = &easycap_fops;
3802#endif /*EASYCAP_NEEDS_V4L2_FOPS*/ 4402#endif /*EASYCAP_NEEDS_V4L2_FOPS*/
3803 pvideo_device->minor = -1; 4403 peasycap->video_device.minor = -1;
3804 pvideo_device->release = (void *)(&videodev_release); 4404 peasycap->video_device.release = (void *)(&videodev_release);
3805 4405
3806 video_set_drvdata(pvideo_device, (void *)peasycap); 4406 video_set_drvdata(&(peasycap->video_device), (void *)peasycap);
3807 4407
3808 rc = video_register_device(pvideo_device, VFL_TYPE_GRABBER, -1); 4408 if (0 != (video_register_device(&(peasycap->video_device), \
3809 if (0 != rc) { 4409 VFL_TYPE_GRABBER, -1))) {
3810 err("Not able to register with videodev"); 4410 err("Not able to register with videodev");
3811 videodev_release(pvideo_device); 4411 videodev_release(&(peasycap->video_device));
3812 return -ENODEV; 4412 return -ENODEV;
3813 } else { 4413 } else {
3814 peasycap->pvideo_device = pvideo_device;
3815 (peasycap->registered_video)++; 4414 (peasycap->registered_video)++;
3816 JOT(4, "registered with videodev: %i=minor\n", \ 4415 SAM("registered with videodev: %i=minor\n", \
3817 pvideo_device->minor); 4416 peasycap->video_device.minor);
3818 } 4417 }
3819/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
3820#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 4418#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
4419/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
3821 break; 4420 break;
3822} 4421}
3823/*--------------------------------------------------------------------------*/ 4422/*--------------------------------------------------------------------------*/
@@ -3827,125 +4426,118 @@ case 0: {
3827 */ 4426 */
3828/*--------------------------------------------------------------------------*/ 4427/*--------------------------------------------------------------------------*/
3829case 1: { 4428case 1: {
4429 if (!peasycap) {
4430 SAM("ERROR: peasycap is NULL\n");
4431 return -EFAULT;
4432 }
3830/*--------------------------------------------------------------------------*/ 4433/*--------------------------------------------------------------------------*/
3831/* 4434/*
3832 * SAVE POINTER peasycap IN INTERFACE 1 4435 * SAVE POINTER peasycap IN INTERFACE 1
3833 */ 4436 */
3834/*--------------------------------------------------------------------------*/ 4437/*--------------------------------------------------------------------------*/
3835 usb_set_intfdata(pusb_interface, peasycap); 4438 usb_set_intfdata(pusb_interface, peasycap);
3836 JOT(4, "no initialization required for interface %i\n", \ 4439 JOM(4, "no initialization required for interface %i\n", \
3837 pusb_interface_descriptor->bInterfaceNumber); 4440 pusb_interface_descriptor->bInterfaceNumber);
3838 break; 4441 break;
3839} 4442}
3840/*--------------------------------------------------------------------------*/ 4443/*--------------------------------------------------------------------------*/
3841case 2: { 4444case 2: {
3842 if (!peasycap) { 4445 if (!peasycap) {
3843 SAY("MISTAKE: peasycap is NULL\n"); 4446 SAM("MISTAKE: peasycap is NULL\n");
3844 return -EFAULT; 4447 return -EFAULT;
3845 } 4448 }
3846 if (!isokalt) { 4449 if (!isokalt) {
3847 SAY("ERROR: no viable audio_altsetting_on\n"); 4450 SAM("ERROR: no viable audio_altsetting_on\n");
3848 return -ENOENT; 4451 return -ENOENT;
3849 } else { 4452 } else {
3850 peasycap->audio_altsetting_on = okalt[isokalt - 1]; 4453 peasycap->audio_altsetting_on = okalt[isokalt - 1];
3851 JOT(4, "%i=audio_altsetting_on <====\n", \ 4454 JOM(4, "%i=audio_altsetting_on <====\n", \
3852 peasycap->audio_altsetting_on); 4455 peasycap->audio_altsetting_on);
3853 } 4456 }
3854 if (!isokepn) { 4457
3855 SAY("ERROR: no viable audio_endpointnumber\n"); 4458 peasycap->audio_endpointnumber = okepn[isokalt - 1];
4459 JOM(4, "%i=audio_endpointnumber\n", peasycap->audio_endpointnumber);
4460
4461 peasycap->audio_isoc_maxframesize = okmps[isokalt - 1];
4462 JOM(4, "%i=audio_isoc_maxframesize\n", \
4463 peasycap->audio_isoc_maxframesize);
4464 if (0 >= peasycap->audio_isoc_maxframesize) {
4465 SAM("ERROR: bad audio_isoc_maxframesize\n");
3856 return -ENOENT; 4466 return -ENOENT;
3857 } else {
3858 peasycap->audio_endpointnumber = okepn[isokepn - 1];
3859 JOT(4, "%i=audio_endpointnumber\n", \
3860 peasycap->audio_endpointnumber);
3861 } 4467 }
3862 if (!isokmps) { 4468 if (9 == peasycap->audio_isoc_maxframesize) {
3863 SAY("ERROR: no viable audio_maxpacketsize\n"); 4469 peasycap->ilk |= 0x02;
3864 return -ENOENT; 4470 SAM("hardware is FOUR-CVBS\n");
4471 peasycap->microphone = true;
4472 peasycap->audio_pages_per_fragment = 4;
4473 } else if (256 == peasycap->audio_isoc_maxframesize) {
4474 peasycap->ilk &= ~0x02;
4475 SAM("hardware is CVBS+S-VIDEO\n");
4476 peasycap->microphone = false;
4477 peasycap->audio_pages_per_fragment = 4;
3865 } else { 4478 } else {
3866 peasycap->audio_isoc_maxframesize = okmps[isokmps - 1]; 4479 SAM("hardware is unidentified:\n");
3867 JOT(4, "%i=audio_isoc_maxframesize\n", \ 4480 SAM("%i=audio_isoc_maxframesize\n", \
3868 peasycap->audio_isoc_maxframesize);
3869 if (0 >= peasycap->audio_isoc_maxframesize) {
3870 SAY("ERROR: bad audio_isoc_maxframesize\n");
3871 return -ENOENT;
3872 }
3873 if (9 == peasycap->audio_isoc_maxframesize) {
3874 peasycap->ilk |= 0x02;
3875 SAY("hardware is FOUR-CVBS\n");
3876 peasycap->microphone = true;
3877 peasycap->audio_pages_per_fragment = 4;
3878 } else if (256 == peasycap->audio_isoc_maxframesize) {
3879 peasycap->ilk &= ~0x02;
3880 SAY("hardware is CVBS+S-VIDEO\n");
3881 peasycap->microphone = false;
3882 peasycap->audio_pages_per_fragment = 4;
3883 } else {
3884 SAY("hardware is unidentified:\n");
3885 SAY("%i=audio_isoc_maxframesize\n", \
3886 peasycap->audio_isoc_maxframesize); 4481 peasycap->audio_isoc_maxframesize);
3887 return -ENOENT; 4482 return -ENOENT;
3888 } 4483 }
3889 4484
3890 peasycap->audio_bytes_per_fragment = \ 4485 peasycap->audio_bytes_per_fragment = \
3891 peasycap->audio_pages_per_fragment * \ 4486 peasycap->audio_pages_per_fragment * \
3892 PAGE_SIZE ; 4487 PAGE_SIZE ;
3893 peasycap->audio_buffer_page_many = (AUDIO_FRAGMENT_MANY * \ 4488 peasycap->audio_buffer_page_many = (AUDIO_FRAGMENT_MANY * \
3894 peasycap->audio_pages_per_fragment); 4489 peasycap->audio_pages_per_fragment);
3895 4490
3896 JOT(4, "%6i=AUDIO_FRAGMENT_MANY\n", AUDIO_FRAGMENT_MANY); 4491 JOM(4, "%6i=AUDIO_FRAGMENT_MANY\n", AUDIO_FRAGMENT_MANY);
3897 JOT(4, "%6i=audio_pages_per_fragment\n", \ 4492 JOM(4, "%6i=audio_pages_per_fragment\n", \
3898 peasycap->audio_pages_per_fragment); 4493 peasycap->audio_pages_per_fragment);
3899 JOT(4, "%6i=audio_bytes_per_fragment\n", \ 4494 JOM(4, "%6i=audio_bytes_per_fragment\n", \
3900 peasycap->audio_bytes_per_fragment); 4495 peasycap->audio_bytes_per_fragment);
3901 JOT(4, "%6i=audio_buffer_page_many\n", \ 4496 JOM(4, "%6i=audio_buffer_page_many\n", \
3902 peasycap->audio_buffer_page_many); 4497 peasycap->audio_buffer_page_many);
3903 4498
3904 peasycap->audio_isoc_framesperdesc = 128; 4499 peasycap->audio_isoc_framesperdesc = 128;
3905 4500
3906 JOT(4, "%i=audio_isoc_framesperdesc\n", \ 4501 JOM(4, "%i=audio_isoc_framesperdesc\n", \
3907 peasycap->audio_isoc_framesperdesc); 4502 peasycap->audio_isoc_framesperdesc);
3908 if (0 >= peasycap->audio_isoc_framesperdesc) { 4503 if (0 >= peasycap->audio_isoc_framesperdesc) {
3909 SAY("ERROR: bad audio_isoc_framesperdesc\n"); 4504 SAM("ERROR: bad audio_isoc_framesperdesc\n");
3910 return -ENOENT; 4505 return -ENOENT;
3911 } 4506 }
3912 4507
3913 peasycap->audio_isoc_buffer_size = \ 4508 peasycap->audio_isoc_buffer_size = \
3914 peasycap->audio_isoc_maxframesize * \ 4509 peasycap->audio_isoc_maxframesize * \
3915 peasycap->audio_isoc_framesperdesc; 4510 peasycap->audio_isoc_framesperdesc;
3916 JOT(4, "%i=audio_isoc_buffer_size\n", \ 4511 JOM(4, "%i=audio_isoc_buffer_size\n", \
3917 peasycap->audio_isoc_buffer_size); 4512 peasycap->audio_isoc_buffer_size);
3918 if (AUDIO_ISOC_BUFFER_SIZE < \ 4513 if (AUDIO_ISOC_BUFFER_SIZE < peasycap->audio_isoc_buffer_size) {
3919 peasycap->audio_isoc_buffer_size) { 4514 SAM("MISTAKE: audio_isoc_buffer_size bigger "
3920 SAY("MISTAKE: audio_isoc_buffer_size bigger "
3921 "than %li=AUDIO_ISOC_BUFFER_SIZE\n", \ 4515 "than %li=AUDIO_ISOC_BUFFER_SIZE\n", \
3922 AUDIO_ISOC_BUFFER_SIZE); 4516 AUDIO_ISOC_BUFFER_SIZE);
3923 return -EFAULT; 4517 return -EFAULT;
3924 }
3925 } 4518 }
3926
3927 if (-1 == peasycap->audio_interface) { 4519 if (-1 == peasycap->audio_interface) {
3928 SAY("MISTAKE: audio_interface is unset\n"); 4520 SAM("MISTAKE: audio_interface is unset\n");
3929 return -EFAULT; 4521 return -EFAULT;
3930 } 4522 }
3931 if (-1 == peasycap->audio_altsetting_on) { 4523 if (-1 == peasycap->audio_altsetting_on) {
3932 SAY("MISTAKE: audio_altsetting_on is unset\n"); 4524 SAM("MISTAKE: audio_altsetting_on is unset\n");
3933 return -EFAULT; 4525 return -EFAULT;
3934 } 4526 }
3935 if (-1 == peasycap->audio_altsetting_off) { 4527 if (-1 == peasycap->audio_altsetting_off) {
3936 SAY("MISTAKE: audio_interface_off is unset\n"); 4528 SAM("MISTAKE: audio_interface_off is unset\n");
3937 return -EFAULT; 4529 return -EFAULT;
3938 } 4530 }
3939 if (-1 == peasycap->audio_endpointnumber) { 4531 if (-1 == peasycap->audio_endpointnumber) {
3940 SAY("MISTAKE: audio_endpointnumber is unset\n"); 4532 SAM("MISTAKE: audio_endpointnumber is unset\n");
3941 return -EFAULT; 4533 return -EFAULT;
3942 } 4534 }
3943 if (-1 == peasycap->audio_isoc_maxframesize) { 4535 if (-1 == peasycap->audio_isoc_maxframesize) {
3944 SAY("MISTAKE: audio_isoc_maxframesize is unset\n"); 4536 SAM("MISTAKE: audio_isoc_maxframesize is unset\n");
3945 return -EFAULT; 4537 return -EFAULT;
3946 } 4538 }
3947 if (-1 == peasycap->audio_isoc_buffer_size) { 4539 if (-1 == peasycap->audio_isoc_buffer_size) {
3948 SAY("MISTAKE: audio_isoc_buffer_size is unset\n"); 4540 SAM("MISTAKE: audio_isoc_buffer_size is unset\n");
3949 return -EFAULT; 4541 return -EFAULT;
3950 } 4542 }
3951/*---------------------------------------------------------------------------*/ 4543/*---------------------------------------------------------------------------*/
@@ -3956,17 +4548,17 @@ case 2: {
3956 INIT_LIST_HEAD(&(peasycap->urb_audio_head)); 4548 INIT_LIST_HEAD(&(peasycap->urb_audio_head));
3957 peasycap->purb_audio_head = &(peasycap->urb_audio_head); 4549 peasycap->purb_audio_head = &(peasycap->urb_audio_head);
3958 4550
3959 JOT(4, "allocating an audio buffer\n"); 4551 JOM(4, "allocating an audio buffer\n");
3960 JOT(4, ".... scattered over %i pages\n", \ 4552 JOM(4, ".... scattered over %i pages\n", \
3961 peasycap->audio_buffer_page_many); 4553 peasycap->audio_buffer_page_many);
3962 4554
3963 for (k = 0; k < peasycap->audio_buffer_page_many; k++) { 4555 for (k = 0; k < peasycap->audio_buffer_page_many; k++) {
3964 if ((void *)NULL != peasycap->audio_buffer[k].pgo) { 4556 if ((void *)NULL != peasycap->audio_buffer[k].pgo) {
3965 SAY("ERROR: attempting to reallocate audio buffers\n"); 4557 SAM("ERROR: attempting to reallocate audio buffers\n");
3966 } else { 4558 } else {
3967 pbuf = (void *) __get_free_page(GFP_KERNEL); 4559 pbuf = (void *) __get_free_page(GFP_KERNEL);
3968 if ((void *)NULL == pbuf) { 4560 if ((void *)NULL == pbuf) {
3969 SAY("ERROR: Could not allocate audio " \ 4561 SAM("ERROR: Could not allocate audio " \
3970 "buffer page %i\n", k); 4562 "buffer page %i\n", k);
3971 return -ENOMEM; 4563 return -ENOMEM;
3972 } else 4564 } else
@@ -3979,16 +4571,16 @@ case 2: {
3979 4571
3980 peasycap->audio_fill = 0; 4572 peasycap->audio_fill = 0;
3981 peasycap->audio_read = 0; 4573 peasycap->audio_read = 0;
3982 JOT(4, "allocation of audio buffer done: %i pages\n", k); 4574 JOM(4, "allocation of audio buffer done: %i pages\n", k);
3983/*---------------------------------------------------------------------------*/ 4575/*---------------------------------------------------------------------------*/
3984 JOT(4, "allocating %i isoc audio buffers of size %i\n", \ 4576 JOM(4, "allocating %i isoc audio buffers of size %i\n", \
3985 AUDIO_ISOC_BUFFER_MANY, peasycap->audio_isoc_buffer_size); 4577 AUDIO_ISOC_BUFFER_MANY, peasycap->audio_isoc_buffer_size);
3986 JOT(4, ".... each occupying contiguous memory pages\n"); 4578 JOM(4, ".... each occupying contiguous memory pages\n");
3987 4579
3988 for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) { 4580 for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) {
3989 pbuf = (void *)__get_free_pages(GFP_KERNEL, AUDIO_ISOC_ORDER); 4581 pbuf = (void *)__get_free_pages(GFP_KERNEL, AUDIO_ISOC_ORDER);
3990 if (NULL == pbuf) { 4582 if (NULL == pbuf) {
3991 SAY("ERROR: Could not allocate isoc audio buffer " \ 4583 SAM("ERROR: Could not allocate isoc audio buffer " \
3992 "%i\n", k); 4584 "%i\n", k);
3993 return -ENOMEM; 4585 return -ENOMEM;
3994 } else 4586 } else
@@ -4000,25 +4592,25 @@ case 2: {
4000 peasycap->audio_isoc_buffer_size; 4592 peasycap->audio_isoc_buffer_size;
4001 peasycap->audio_isoc_buffer[k].kount = k; 4593 peasycap->audio_isoc_buffer[k].kount = k;
4002 } 4594 }
4003 JOT(4, "allocation of isoc audio buffers done.\n"); 4595 JOM(4, "allocation of isoc audio buffers done.\n");
4004/*---------------------------------------------------------------------------*/ 4596/*---------------------------------------------------------------------------*/
4005/* 4597/*
4006 * ALLOCATE AND INITIALIZE MULTIPLE struct urb ... 4598 * ALLOCATE AND INITIALIZE MULTIPLE struct urb ...
4007 */ 4599 */
4008/*---------------------------------------------------------------------------*/ 4600/*---------------------------------------------------------------------------*/
4009 JOT(4, "allocating %i struct urb.\n", AUDIO_ISOC_BUFFER_MANY); 4601 JOM(4, "allocating %i struct urb.\n", AUDIO_ISOC_BUFFER_MANY);
4010 JOT(4, "using %i=peasycap->audio_isoc_framesperdesc\n", \ 4602 JOM(4, "using %i=peasycap->audio_isoc_framesperdesc\n", \
4011 peasycap->audio_isoc_framesperdesc); 4603 peasycap->audio_isoc_framesperdesc);
4012 JOT(4, "using %i=peasycap->audio_isoc_maxframesize\n", \ 4604 JOM(4, "using %i=peasycap->audio_isoc_maxframesize\n", \
4013 peasycap->audio_isoc_maxframesize); 4605 peasycap->audio_isoc_maxframesize);
4014 JOT(4, "using %i=peasycap->audio_isoc_buffer_size\n", \ 4606 JOM(4, "using %i=peasycap->audio_isoc_buffer_size\n", \
4015 peasycap->audio_isoc_buffer_size); 4607 peasycap->audio_isoc_buffer_size);
4016 4608
4017 for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) { 4609 for (k = 0; k < AUDIO_ISOC_BUFFER_MANY; k++) {
4018 purb = usb_alloc_urb(peasycap->audio_isoc_framesperdesc, \ 4610 purb = usb_alloc_urb(peasycap->audio_isoc_framesperdesc, \
4019 GFP_KERNEL); 4611 GFP_KERNEL);
4020 if (NULL == purb) { 4612 if (NULL == purb) {
4021 SAY("ERROR: usb_alloc_urb returned NULL for buffer " \ 4613 SAM("ERROR: usb_alloc_urb returned NULL for buffer " \
4022 "%i\n", k); 4614 "%i\n", k);
4023 return -ENOMEM; 4615 return -ENOMEM;
4024 } else 4616 } else
@@ -4026,7 +4618,7 @@ case 2: {
4026/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 4618/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
4027 pdata_urb = kzalloc(sizeof(struct data_urb), GFP_KERNEL); 4619 pdata_urb = kzalloc(sizeof(struct data_urb), GFP_KERNEL);
4028 if (NULL == pdata_urb) { 4620 if (NULL == pdata_urb) {
4029 SAY("ERROR: Could not allocate struct data_urb.\n"); 4621 SAM("ERROR: Could not allocate struct data_urb.\n");
4030 return -ENOMEM; 4622 return -ENOMEM;
4031 } else 4623 } else
4032 peasycap->allocation_audio_struct += \ 4624 peasycap->allocation_audio_struct += \
@@ -4043,30 +4635,30 @@ case 2: {
4043 */ 4635 */
4044/*---------------------------------------------------------------------------*/ 4636/*---------------------------------------------------------------------------*/
4045 if (!k) { 4637 if (!k) {
4046 JOT(4, "initializing audio urbs thus:\n"); 4638 JOM(4, "initializing audio urbs thus:\n");
4047 JOT(4, " purb->interval = 1;\n"); 4639 JOM(4, " purb->interval = 1;\n");
4048 JOT(4, " purb->dev = peasycap->pusb_device;\n"); 4640 JOM(4, " purb->dev = peasycap->pusb_device;\n");
4049 JOT(4, " purb->pipe = usb_rcvisocpipe(peasycap->" \ 4641 JOM(4, " purb->pipe = usb_rcvisocpipe(peasycap->" \
4050 "pusb_device,%i);\n", \ 4642 "pusb_device,%i);\n", \
4051 peasycap->audio_endpointnumber); 4643 peasycap->audio_endpointnumber);
4052 JOT(4, " purb->transfer_flags = URB_ISO_ASAP;\n"); 4644 JOM(4, " purb->transfer_flags = URB_ISO_ASAP;\n");
4053 JOT(4, " purb->transfer_buffer = " \ 4645 JOM(4, " purb->transfer_buffer = " \
4054 "peasycap->audio_isoc_buffer[.].pgo;\n"); 4646 "peasycap->audio_isoc_buffer[.].pgo;\n");
4055 JOT(4, " purb->transfer_buffer_length = %i;\n", \ 4647 JOM(4, " purb->transfer_buffer_length = %i;\n", \
4056 peasycap->audio_isoc_buffer_size); 4648 peasycap->audio_isoc_buffer_size);
4057 JOT(4, " purb->complete = easysnd_complete;\n"); 4649 JOM(4, " purb->complete = easysnd_complete;\n");
4058 JOT(4, " purb->context = peasycap;\n"); 4650 JOM(4, " purb->context = peasycap;\n");
4059 JOT(4, " purb->start_frame = 0;\n"); 4651 JOM(4, " purb->start_frame = 0;\n");
4060 JOT(4, " purb->number_of_packets = %i;\n", \ 4652 JOM(4, " purb->number_of_packets = %i;\n", \
4061 peasycap->audio_isoc_framesperdesc); 4653 peasycap->audio_isoc_framesperdesc);
4062 JOT(4, " for (j = 0; j < %i; j++)\n", \ 4654 JOM(4, " for (j = 0; j < %i; j++)\n", \
4063 peasycap->audio_isoc_framesperdesc); 4655 peasycap->audio_isoc_framesperdesc);
4064 JOT(4, " {\n"); 4656 JOM(4, " {\n");
4065 JOT(4, " purb->iso_frame_desc[j].offset = j*%i;\n",\ 4657 JOM(4, " purb->iso_frame_desc[j].offset = j*%i;\n",\
4066 peasycap->audio_isoc_maxframesize); 4658 peasycap->audio_isoc_maxframesize);
4067 JOT(4, " purb->iso_frame_desc[j].length = %i;\n", \ 4659 JOM(4, " purb->iso_frame_desc[j].length = %i;\n", \
4068 peasycap->audio_isoc_maxframesize); 4660 peasycap->audio_isoc_maxframesize);
4069 JOT(4, " }\n"); 4661 JOM(4, " }\n");
4070 } 4662 }
4071 4663
4072 purb->interval = 1; 4664 purb->interval = 1;
@@ -4088,7 +4680,7 @@ case 2: {
4088 peasycap->audio_isoc_maxframesize; 4680 peasycap->audio_isoc_maxframesize;
4089 } 4681 }
4090 } 4682 }
4091 JOT(4, "allocation of %i struct urb done.\n", k); 4683 JOM(4, "allocation of %i struct urb done.\n", k);
4092/*---------------------------------------------------------------------------*/ 4684/*---------------------------------------------------------------------------*/
4093/* 4685/*
4094 * SAVE POINTER peasycap IN THIS INTERFACE. 4686 * SAVE POINTER peasycap IN THIS INTERFACE.
@@ -4105,14 +4697,18 @@ case 2: {
4105 err("Not able to get a minor for this device."); 4697 err("Not able to get a minor for this device.");
4106 usb_set_intfdata(pusb_interface, NULL); 4698 usb_set_intfdata(pusb_interface, NULL);
4107 return -ENODEV; 4699 return -ENODEV;
4108 } else 4700 } else {
4701 JOM(8, "kref_get() with %i=peasycap->kref.refcount.counter\n",\
4702 (int)peasycap->kref.refcount.counter);
4703 kref_get(&peasycap->kref);
4109 (peasycap->registered_audio)++; 4704 (peasycap->registered_audio)++;
4705 }
4110/*---------------------------------------------------------------------------*/ 4706/*---------------------------------------------------------------------------*/
4111/* 4707/*
4112 * LET THE USER KNOW WHAT NODE THE AUDIO DEVICE IS ATTACHED TO. 4708 * LET THE USER KNOW WHAT NODE THE AUDIO DEVICE IS ATTACHED TO.
4113 */ 4709 */
4114/*---------------------------------------------------------------------------*/ 4710/*---------------------------------------------------------------------------*/
4115 SAY("easysnd attached to minor #%d\n", pusb_interface->minor); 4711 SAM("easysnd attached to minor #%d\n", pusb_interface->minor);
4116 break; 4712 break;
4117} 4713}
4118/*---------------------------------------------------------------------------*/ 4714/*---------------------------------------------------------------------------*/
@@ -4121,20 +4717,19 @@ case 2: {
4121 */ 4717 */
4122/*---------------------------------------------------------------------------*/ 4718/*---------------------------------------------------------------------------*/
4123default: { 4719default: {
4124 JOT(4, "ERROR: unexpected interface %i\n", bInterfaceNumber); 4720 JOM(4, "ERROR: unexpected interface %i\n", bInterfaceNumber);
4125 return -EINVAL; 4721 return -EINVAL;
4126} 4722}
4127} 4723}
4128JOT(4, "ends successfully for interface %i\n", \ 4724JOM(4, "ends successfully for interface %i\n", \
4129 pusb_interface_descriptor->bInterfaceNumber); 4725 pusb_interface_descriptor->bInterfaceNumber);
4130return 0; 4726return 0;
4131} 4727}
4132/*****************************************************************************/ 4728/*****************************************************************************/
4133/*---------------------------------------------------------------------------*/ 4729/*---------------------------------------------------------------------------*/
4134/* 4730/*
4135 * WHEN THIS FUNCTION IS CALLED THE DEVICE HAS ALREADY BEEN PHYSICALLY 4731 * WHEN THIS FUNCTION IS CALLED THE EasyCAP HAS ALREADY BEEN PHYSICALLY
4136 * UNPLUGGED. 4732 * UNPLUGGED. HENCE peasycap->pusb_device IS NO LONGER VALID.
4137 * HENCE peasycap->pusb_device IS NO LONGER VALID AND MUST BE SET TO NULL.
4138 */ 4733 */
4139/*---------------------------------------------------------------------------*/ 4734/*---------------------------------------------------------------------------*/
4140void 4735void
@@ -4147,7 +4742,14 @@ struct easycap *peasycap;
4147 4742
4148struct list_head *plist_head; 4743struct list_head *plist_head;
4149struct data_urb *pdata_urb; 4744struct data_urb *pdata_urb;
4150int minor, m; 4745int minor, m, kd;
4746/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
4747#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
4748#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
4749struct v4l2_device *pv4l2_device;
4750#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
4751#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
4752/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
4151 4753
4152JOT(4, "\n"); 4754JOT(4, "\n");
4153 4755
@@ -4169,107 +4771,188 @@ bInterfaceNumber = pusb_interface_descriptor->bInterfaceNumber;
4169minor = pusb_interface->minor; 4771minor = pusb_interface->minor;
4170JOT(4, "intf[%i]: minor=%i\n", bInterfaceNumber, minor); 4772JOT(4, "intf[%i]: minor=%i\n", bInterfaceNumber, minor);
4171 4773
4774if (1 == bInterfaceNumber)
4775 return;
4776
4172peasycap = usb_get_intfdata(pusb_interface); 4777peasycap = usb_get_intfdata(pusb_interface);
4173if ((struct easycap *)NULL == peasycap) 4778if (NULL == peasycap) {
4174 SAY("ERROR: peasycap is NULL\n"); 4779 SAY("ERROR: peasycap is NULL\n");
4175else { 4780 return;
4176 peasycap->pusb_device = (struct usb_device *)NULL; 4781}
4177 switch (bInterfaceNumber) { 4782/*---------------------------------------------------------------------------*/
4178/*---------------------------------------------------------------------------*/ 4783#if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
4179 case 0: { 4784#
4180 if ((struct list_head *)NULL != peasycap->purb_video_head) { 4785/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
4181 JOT(4, "killing video urbs\n"); 4786#else
4182 m = 0; 4787#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
4183 list_for_each(plist_head, (peasycap->purb_video_head)) 4788/*---------------------------------------------------------------------------*/
4184 { 4789/*
4185 pdata_urb = list_entry(plist_head, \ 4790 * SOME VERSIONS OF THE videodev MODULE OVERWRITE THE DATA WHICH HAS
4186 struct data_urb, list_head); 4791 * BEEN WRITTEN BY THE CALL TO usb_set_intfdata() IN easycap_usb_probe(),
4187 if ((struct data_urb *)NULL != pdata_urb) { 4792 * REPLACING IT WITH A POINTER TO THE EMBEDDED v4l2_device STRUCTURE.
4188 if ((struct urb *)NULL != \ 4793 * TO DETECT THIS, THE STRING IN THE easycap.telltale[] BUFFER IS CHECKED.
4189 pdata_urb->purb) { 4794*/
4190 usb_kill_urb(pdata_urb->purb); 4795/*---------------------------------------------------------------------------*/
4191 m++; 4796if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
4192 } 4797 pv4l2_device = usb_get_intfdata(pusb_interface);
4798 if ((struct v4l2_device *)NULL == pv4l2_device) {
4799 SAY("ERROR: pv4l2_device is NULL\n");
4800 return;
4801 }
4802 peasycap = (struct easycap *) \
4803 container_of(pv4l2_device, struct easycap, v4l2_device);
4804}
4805#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
4806#
4807#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
4808/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
4809/*---------------------------------------------------------------------------*/
4810if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
4811 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
4812 return;
4813}
4814/*---------------------------------------------------------------------------*/
4815/*
4816 * IF THE WAIT QUEUES ARE NOT CLEARED A DEADLOCK IS POSSIBLE. BEWARE.
4817*/
4818/*---------------------------------------------------------------------------*/
4819peasycap->video_eof = 1;
4820peasycap->audio_eof = 1;
4821wake_up_interruptible(&(peasycap->wq_video));
4822wake_up_interruptible(&(peasycap->wq_audio));
4823/*---------------------------------------------------------------------------*/
4824switch (bInterfaceNumber) {
4825case 0: {
4826 if ((struct list_head *)NULL != peasycap->purb_video_head) {
4827 JOM(4, "killing video urbs\n");
4828 m = 0;
4829 list_for_each(plist_head, (peasycap->purb_video_head))
4830 {
4831 pdata_urb = list_entry(plist_head, \
4832 struct data_urb, list_head);
4833 if ((struct data_urb *)NULL != pdata_urb) {
4834 if ((struct urb *)NULL != \
4835 pdata_urb->purb) {
4836 usb_kill_urb(pdata_urb->purb);
4837 m++;
4193 } 4838 }
4194 } 4839 }
4195 JOT(4, "%i video urbs killed\n", m); 4840 }
4196 } else 4841 JOM(4, "%i video urbs killed\n", m);
4197 SAY("ERROR: peasycap->purb_video_head is NULL\n");
4198 break;
4199 } 4842 }
4843 break;
4844}
4200/*---------------------------------------------------------------------------*/ 4845/*---------------------------------------------------------------------------*/
4201 case 2: { 4846case 2: {
4202 if ((struct list_head *)NULL != peasycap->purb_audio_head) { 4847 if ((struct list_head *)NULL != peasycap->purb_audio_head) {
4203 JOT(4, "killing audio urbs\n"); 4848 JOM(4, "killing audio urbs\n");
4204 m = 0; 4849 m = 0;
4205 list_for_each(plist_head, \ 4850 list_for_each(plist_head, \
4206 (peasycap->purb_audio_head)) { 4851 (peasycap->purb_audio_head)) {
4207 pdata_urb = list_entry(plist_head, \ 4852 pdata_urb = list_entry(plist_head, \
4208 struct data_urb, list_head); 4853 struct data_urb, list_head);
4209 if ((struct data_urb *)NULL != pdata_urb) { 4854 if ((struct data_urb *)NULL != pdata_urb) {
4210 if ((struct urb *)NULL != \ 4855 if ((struct urb *)NULL != \
4211 pdata_urb->purb) { 4856 pdata_urb->purb) {
4212 usb_kill_urb(pdata_urb->purb); 4857 usb_kill_urb(pdata_urb->purb);
4213 m++; 4858 m++;
4214 }
4215 } 4859 }
4216 } 4860 }
4217 JOT(4, "%i audio urbs killed\n", m); 4861 }
4218 } else 4862 JOM(4, "%i audio urbs killed\n", m);
4219 SAY("ERROR: peasycap->purb_audio_head is NULL\n");
4220 break;
4221 } 4863 }
4864 break;
4865}
4222/*---------------------------------------------------------------------------*/ 4866/*---------------------------------------------------------------------------*/
4223 default: 4867default:
4224 break; 4868 break;
4225 }
4226} 4869}
4227/*--------------------------------------------------------------------------*/ 4870/*--------------------------------------------------------------------------*/
4228/* 4871/*
4229 * DEREGISTER 4872 * DEREGISTER
4873 *
4874 * THIS PROCEDURE WILL BLOCK UNTIL easycap_poll(), VIDEO IOCTL AND AUDIO
4875 * IOCTL ARE ALL UNLOCKED. IF THIS IS NOT DONE AN Oops CAN OCCUR WHEN
4876 * AN EasyCAP IS UNPLUGGED WHILE THE URBS ARE RUNNING. BEWARE.
4230 */ 4877 */
4231/*--------------------------------------------------------------------------*/ 4878/*--------------------------------------------------------------------------*/
4879kd = isdongle(peasycap);
4232switch (bInterfaceNumber) { 4880switch (bInterfaceNumber) {
4233case 0: { 4881case 0: {
4882 if (0 <= kd && DONGLE_MANY > kd) {
4883 wake_up_interruptible(&peasycap->wq_video);
4884 JOM(4, "about to lock easycap_dongle[%i].mutex_video\n", kd);
4885 if (mutex_lock_interruptible(&easycap_dongle[kd].\
4886 mutex_video)) {
4887 SAY("ERROR: cannot lock easycap_dongle[%i]." \
4888 "mutex_video\n", kd);
4889 return;
4890 }
4891 JOM(4, "locked easycap_dongle[%i].mutex_video\n", kd);
4892 } else
4893 SAY("ERROR: %i=kd is bad: cannot lock dongle\n", kd);
4894/*---------------------------------------------------------------------------*/
4234#if (!defined(EASYCAP_IS_VIDEODEV_CLIENT)) 4895#if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
4235 if ((struct easycap *)NULL == peasycap) { 4896 if ((struct easycap *)NULL == peasycap) {
4236 SAY("ERROR: peasycap has become NULL\n"); 4897 SAM("ERROR: peasycap has become NULL\n");
4237 } else { 4898 } else {
4238 lock_kernel();
4239 usb_deregister_dev(pusb_interface, &easycap_class); 4899 usb_deregister_dev(pusb_interface, &easycap_class);
4240 (peasycap->registered_video)--; 4900 (peasycap->registered_video)--;
4241 4901 JOM(4, "intf[%i]: usb_deregister_dev()\n", bInterfaceNumber);
4242 JOT(4, "intf[%i]: usb_deregister_dev()\n", bInterfaceNumber); 4902 SAM("easycap detached from minor #%d\n", minor);
4243 unlock_kernel();
4244 SAY("easycap detached from minor #%d\n", minor);
4245 } 4903 }
4246/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ 4904/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
4247#else 4905#else
4248 if ((struct easycap *)NULL == peasycap) 4906#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
4249 SAY("ERROR: peasycap has become NULL\n"); 4907 if (!peasycap->v4l2_device.name[0]) {
4250 else { 4908 SAM("ERROR: peasycap->v4l2_device.name is empty\n");
4251 lock_kernel(); 4909 if (0 <= kd && DONGLE_MANY > kd)
4252 video_unregister_device(peasycap->pvideo_device); 4910 mutex_unlock(&easycap_dongle[kd].mutex_video);
4253 (peasycap->registered_video)--; 4911 return;
4254 unlock_kernel();
4255 JOT(4, "unregistered with videodev: %i=minor\n", \
4256 pvideo_device->minor);
4257 } 4912 }
4258/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ 4913 v4l2_device_disconnect(&peasycap->v4l2_device);
4914 JOM(4, "v4l2_device_disconnect() OK\n");
4915 v4l2_device_unregister(&peasycap->v4l2_device);
4916 JOM(4, "v4l2_device_unregister() OK\n");
4917#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
4918
4919 video_unregister_device(&peasycap->video_device);
4920 JOM(4, "intf[%i]: video_unregister_device() OK\n", bInterfaceNumber);
4921 (peasycap->registered_video)--;
4922 JOM(4, "unregistered with videodev: %i=minor\n", minor);
4259#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/ 4923#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
4924/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
4925
4926 if (0 <= kd && DONGLE_MANY > kd) {
4927 mutex_unlock(&easycap_dongle[kd].mutex_video);
4928 JOM(4, "unlocked easycap_dongle[%i].mutex_video\n", kd);
4929 }
4260 break; 4930 break;
4261} 4931}
4262case 2: { 4932case 2: {
4263 lock_kernel(); 4933 if (0 <= kd && DONGLE_MANY > kd) {
4934 wake_up_interruptible(&peasycap->wq_audio);
4935 JOM(4, "about to lock easycap_dongle[%i].mutex_audio\n", kd);
4936 if (mutex_lock_interruptible(&easycap_dongle[kd].\
4937 mutex_audio)) {
4938 SAY("ERROR: cannot lock easycap_dongle[%i]." \
4939 "mutex_audio\n", kd);
4940 return;
4941 }
4942 JOM(4, "locked easycap_dongle[%i].mutex_audio\n", kd);
4943 } else
4944 SAY("ERROR: %i=kd is bad: cannot lock dongle\n", kd);
4264 4945
4265 usb_deregister_dev(pusb_interface, &easysnd_class); 4946 usb_deregister_dev(pusb_interface, &easysnd_class);
4266 if ((struct easycap *)NULL != peasycap) 4947 (peasycap->registered_audio)--;
4267 (peasycap->registered_audio)--;
4268 4948
4269 JOT(4, "intf[%i]: usb_deregister_dev()\n", bInterfaceNumber); 4949 JOM(4, "intf[%i]: usb_deregister_dev()\n", bInterfaceNumber);
4270 unlock_kernel(); 4950 SAM("easysnd detached from minor #%d\n", minor);
4271 4951
4272 SAY("easysnd detached from minor #%d\n", minor); 4952 if (0 <= kd && DONGLE_MANY > kd) {
4953 mutex_unlock(&easycap_dongle[kd].mutex_audio);
4954 JOM(4, "unlocked easycap_dongle[%i].mutex_audio\n", kd);
4955 }
4273 break; 4956 break;
4274} 4957}
4275default: 4958default:
@@ -4280,25 +4963,42 @@ default:
4280 * CALL easycap_delete() IF NO REMAINING REFERENCES TO peasycap 4963 * CALL easycap_delete() IF NO REMAINING REFERENCES TO peasycap
4281 */ 4964 */
4282/*---------------------------------------------------------------------------*/ 4965/*---------------------------------------------------------------------------*/
4283if ((struct easycap *)NULL == peasycap) {
4284 SAY("ERROR: peasycap has become NULL\n");
4285 SAY("cannot call kref_put()\n");
4286 SAY("ending unsuccessfully: may cause memory leak\n");
4287 return;
4288}
4289if (!peasycap->kref.refcount.counter) { 4966if (!peasycap->kref.refcount.counter) {
4290 SAY("ERROR: peasycap->kref.refcount.counter is zero " \ 4967 SAM("ERROR: peasycap->kref.refcount.counter is zero "
4291 "so cannot call kref_put()\n"); 4968 "so cannot call kref_put()\n");
4292 SAY("ending unsuccessfully: may cause memory leak\n"); 4969 SAM("ending unsuccessfully: may cause memory leak\n");
4293 return; 4970 return;
4294} 4971}
4295JOT(4, "intf[%i]: kref_put() with %i=peasycap->kref.refcount.counter\n", \ 4972if (0 <= kd && DONGLE_MANY > kd) {
4973 JOM(4, "about to lock easycap_dongle[%i].mutex_video\n", kd);
4974 if (mutex_lock_interruptible(&easycap_dongle[kd].mutex_video)) {
4975 SAY("ERROR: cannot down easycap_dongle[%i].mutex_video\n", kd);
4976 SAM("ending unsuccessfully: may cause memory leak\n");
4977 return;
4978 }
4979 JOM(4, "locked easycap_dongle[%i].mutex_video\n", kd);
4980 JOM(4, "about to lock easycap_dongle[%i].mutex_audio\n", kd);
4981 if (mutex_lock_interruptible(&easycap_dongle[kd].mutex_audio)) {
4982 SAY("ERROR: cannot down easycap_dongle[%i].mutex_audio\n", kd);
4983 mutex_unlock(&(easycap_dongle[kd].mutex_video));
4984 JOM(4, "unlocked easycap_dongle[%i].mutex_video\n", kd);
4985 SAM("ending unsuccessfully: may cause memory leak\n");
4986 return;
4987 }
4988 JOM(4, "locked easycap_dongle[%i].mutex_audio\n", kd);
4989}
4990JOM(4, "intf[%i]: %i=peasycap->kref.refcount.counter\n", \
4296 bInterfaceNumber, (int)peasycap->kref.refcount.counter); 4991 bInterfaceNumber, (int)peasycap->kref.refcount.counter);
4297kref_put(&peasycap->kref, easycap_delete); 4992kref_put(&peasycap->kref, easycap_delete);
4298JOT(4, "intf[%i]: kref_put() done.\n", bInterfaceNumber); 4993JOT(4, "intf[%i]: kref_put() done.\n", bInterfaceNumber);
4994if (0 <= kd && DONGLE_MANY > kd) {
4995 mutex_unlock(&(easycap_dongle[kd].mutex_audio));
4996 JOT(4, "unlocked easycap_dongle[%i].mutex_audio\n", kd);
4997 mutex_unlock(&easycap_dongle[kd].mutex_video);
4998 JOT(4, "unlocked easycap_dongle[%i].mutex_video\n", kd);
4999}
4299/*---------------------------------------------------------------------------*/ 5000/*---------------------------------------------------------------------------*/
4300 5001JOM(4, "ends\n");
4301JOT(4, "ends\n");
4302return; 5002return;
4303} 5003}
4304/*****************************************************************************/ 5004/*****************************************************************************/
@@ -4308,7 +5008,8 @@ easycap_module_init(void)
4308int result; 5008int result;
4309 5009
4310SAY("========easycap=======\n"); 5010SAY("========easycap=======\n");
4311JOT(4, "begins. %i=debug\n", easycap_debug); 5011JOT(4, "begins. %i=debug %i=bars %i=gain\n", easycap_debug, easycap_bars, \
5012 easycap_gain);
4312SAY("version: " EASYCAP_DRIVER_VERSION "\n"); 5013SAY("version: " EASYCAP_DRIVER_VERSION "\n");
4313/*---------------------------------------------------------------------------*/ 5014/*---------------------------------------------------------------------------*/
4314/* 5015/*
@@ -4349,6 +5050,9 @@ MODULE_AUTHOR("R.M. Thomas <rmthomas@sciolus.org>");
4349MODULE_DESCRIPTION(EASYCAP_DRIVER_DESCRIPTION); 5050MODULE_DESCRIPTION(EASYCAP_DRIVER_DESCRIPTION);
4350MODULE_VERSION(EASYCAP_DRIVER_VERSION); 5051MODULE_VERSION(EASYCAP_DRIVER_VERSION);
4351#if defined(EASYCAP_DEBUG) 5052#if defined(EASYCAP_DEBUG)
4352MODULE_PARM_DESC(easycap_debug, "debug: 0 (default), 1, 2,..."); 5053MODULE_PARM_DESC(debug, "Debug level: 0(default),1,2,...,9");
4353#endif /*EASYCAP_DEBUG*/ 5054#endif /*EASYCAP_DEBUG*/
5055MODULE_PARM_DESC(bars, \
5056 "Testcard bars on input signal failure: 0=>no, 1=>yes(default)");
5057MODULE_PARM_DESC(gain, "Audio gain: 0,...,16(default),...31");
4354/*****************************************************************************/ 5058/*****************************************************************************/
diff --git a/drivers/staging/easycap/easycap_settings.c b/drivers/staging/easycap/easycap_settings.c
index 38d94051241d..df3f17d361b1 100644
--- a/drivers/staging/easycap/easycap_settings.c
+++ b/drivers/staging/easycap/easycap_settings.c
@@ -33,11 +33,15 @@
33 * THE LEAST SIGNIFICANT BIT OF easycap_standard.mask HAS MEANING: 33 * THE LEAST SIGNIFICANT BIT OF easycap_standard.mask HAS MEANING:
34 * 0 => 25 fps 34 * 0 => 25 fps
35 * 1 => 30 fps 35 * 1 => 30 fps
36 *
37 * THE MOST SIGNIFICANT BIT OF easycap_standard.mask HAS MEANING:
38 * 0 => full framerate
39 * 1 => 20% framerate
36 */ 40 */
37/*---------------------------------------------------------------------------*/ 41/*---------------------------------------------------------------------------*/
38const struct easycap_standard easycap_standard[] = { 42const struct easycap_standard easycap_standard[] = {
39{ 43{
40.mask = 0x000F & PAL_BGHIN , 44.mask = 0x00FF & PAL_BGHIN ,
41.v4l2_standard = { 45.v4l2_standard = {
42 .index = PAL_BGHIN, 46 .index = PAL_BGHIN,
43 .id = (V4L2_STD_PAL_B | V4L2_STD_PAL_G | V4L2_STD_PAL_H | \ 47 .id = (V4L2_STD_PAL_B | V4L2_STD_PAL_G | V4L2_STD_PAL_H | \
@@ -50,7 +54,7 @@ const struct easycap_standard easycap_standard[] = {
50}, 54},
51/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 55/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
52{ 56{
53.mask = 0x000F & NTSC_N_443 , 57.mask = 0x00FF & NTSC_N_443 ,
54.v4l2_standard = { 58.v4l2_standard = {
55 .index = NTSC_N_443, 59 .index = NTSC_N_443,
56 .id = V4L2_STD_UNKNOWN, 60 .id = V4L2_STD_UNKNOWN,
@@ -62,7 +66,7 @@ const struct easycap_standard easycap_standard[] = {
62}, 66},
63/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 67/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
64{ 68{
65.mask = 0x000F & PAL_Nc , 69.mask = 0x00FF & PAL_Nc ,
66.v4l2_standard = { 70.v4l2_standard = {
67 .index = PAL_Nc, 71 .index = PAL_Nc,
68 .id = V4L2_STD_PAL_Nc, 72 .id = V4L2_STD_PAL_Nc,
@@ -74,7 +78,7 @@ const struct easycap_standard easycap_standard[] = {
74}, 78},
75/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 79/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
76{ 80{
77.mask = 0x000F & NTSC_N , 81.mask = 0x00FF & NTSC_N ,
78.v4l2_standard = { 82.v4l2_standard = {
79 .index = NTSC_N, 83 .index = NTSC_N,
80 .id = V4L2_STD_UNKNOWN, 84 .id = V4L2_STD_UNKNOWN,
@@ -86,7 +90,7 @@ const struct easycap_standard easycap_standard[] = {
86}, 90},
87/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 91/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
88{ 92{
89.mask = 0x000F & SECAM , 93.mask = 0x00FF & SECAM ,
90.v4l2_standard = { 94.v4l2_standard = {
91 .index = SECAM, 95 .index = SECAM,
92 .id = V4L2_STD_SECAM, 96 .id = V4L2_STD_SECAM,
@@ -98,7 +102,7 @@ const struct easycap_standard easycap_standard[] = {
98}, 102},
99/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 103/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
100{ 104{
101.mask = 0x000F & NTSC_M , 105.mask = 0x00FF & NTSC_M ,
102.v4l2_standard = { 106.v4l2_standard = {
103 .index = NTSC_M, 107 .index = NTSC_M,
104 .id = V4L2_STD_NTSC_M, 108 .id = V4L2_STD_NTSC_M,
@@ -110,7 +114,7 @@ const struct easycap_standard easycap_standard[] = {
110}, 114},
111/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 115/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
112{ 116{
113.mask = 0x000F & NTSC_M_JP , 117.mask = 0x00FF & NTSC_M_JP ,
114.v4l2_standard = { 118.v4l2_standard = {
115 .index = NTSC_M_JP, 119 .index = NTSC_M_JP,
116 .id = V4L2_STD_NTSC_M_JP, 120 .id = V4L2_STD_NTSC_M_JP,
@@ -122,7 +126,7 @@ const struct easycap_standard easycap_standard[] = {
122}, 126},
123/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 127/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
124{ 128{
125.mask = 0x000F & PAL_60 , 129.mask = 0x00FF & PAL_60 ,
126.v4l2_standard = { 130.v4l2_standard = {
127 .index = PAL_60, 131 .index = PAL_60,
128 .id = V4L2_STD_PAL_60, 132 .id = V4L2_STD_PAL_60,
@@ -134,7 +138,7 @@ const struct easycap_standard easycap_standard[] = {
134}, 138},
135/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 139/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
136{ 140{
137.mask = 0x000F & NTSC_443 , 141.mask = 0x00FF & NTSC_443 ,
138.v4l2_standard = { 142.v4l2_standard = {
139 .index = NTSC_443, 143 .index = NTSC_443,
140 .id = V4L2_STD_NTSC_443, 144 .id = V4L2_STD_NTSC_443,
@@ -146,7 +150,7 @@ const struct easycap_standard easycap_standard[] = {
146}, 150},
147/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 151/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
148{ 152{
149.mask = 0x000F & PAL_M , 153.mask = 0x00FF & PAL_M ,
150.v4l2_standard = { 154.v4l2_standard = {
151 .index = PAL_M, 155 .index = PAL_M,
152 .id = V4L2_STD_PAL_M, 156 .id = V4L2_STD_PAL_M,
@@ -158,6 +162,128 @@ const struct easycap_standard easycap_standard[] = {
158}, 162},
159/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 163/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
160{ 164{
165.mask = 0x8000 | (0x00FF & PAL_BGHIN_SLOW),
166.v4l2_standard = {
167 .index = PAL_BGHIN_SLOW,
168 .id = (V4L2_STD_PAL_B | V4L2_STD_PAL_G | V4L2_STD_PAL_H | \
169 V4L2_STD_PAL_I | V4L2_STD_PAL_N | \
170 (((v4l2_std_id)0x01) << 32)),
171 .name = "PAL_BGHIN_SLOW",
172 .frameperiod = {1, 5},
173 .framelines = 625,
174 .reserved = {0, 0, 0, 0}
175}
176},
177/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
178{
179.mask = 0x8000 | (0x00FF & NTSC_N_443_SLOW),
180.v4l2_standard = {
181 .index = NTSC_N_443_SLOW,
182 .id = (V4L2_STD_UNKNOWN | (((v4l2_std_id)0x11) << 32)),
183 .name = "NTSC_N_443_SLOW",
184 .frameperiod = {1, 5},
185 .framelines = 480,
186 .reserved = {0, 0, 0, 0}
187}
188},
189/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
190{
191.mask = 0x8000 | (0x00FF & PAL_Nc_SLOW),
192.v4l2_standard = {
193 .index = PAL_Nc_SLOW,
194 .id = (V4L2_STD_PAL_Nc | (((v4l2_std_id)0x01) << 32)),
195 .name = "PAL_Nc_SLOW",
196 .frameperiod = {1, 5},
197 .framelines = 625,
198 .reserved = {0, 0, 0, 0}
199}
200},
201/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
202{
203.mask = 0x8000 | (0x00FF & NTSC_N_SLOW),
204.v4l2_standard = {
205 .index = NTSC_N_SLOW,
206 .id = (V4L2_STD_UNKNOWN | (((v4l2_std_id)0x21) << 32)),
207 .name = "NTSC_N_SLOW",
208 .frameperiod = {1, 5},
209 .framelines = 525,
210 .reserved = {0, 0, 0, 0}
211}
212},
213/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
214{
215.mask = 0x8000 | (0x00FF & SECAM_SLOW),
216.v4l2_standard = {
217 .index = SECAM_SLOW,
218 .id = (V4L2_STD_SECAM | (((v4l2_std_id)0x01) << 32)),
219 .name = "SECAM_SLOW",
220 .frameperiod = {1, 5},
221 .framelines = 625,
222 .reserved = {0, 0, 0, 0}
223}
224},
225/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
226{
227.mask = 0x8000 | (0x00FF & NTSC_M_SLOW),
228.v4l2_standard = {
229 .index = NTSC_M_SLOW,
230 .id = (V4L2_STD_NTSC_M | (((v4l2_std_id)0x01) << 32)),
231 .name = "NTSC_M_SLOW",
232 .frameperiod = {1, 6},
233 .framelines = 525,
234 .reserved = {0, 0, 0, 0}
235}
236},
237/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
238{
239.mask = 0x8000 | (0x00FF & NTSC_M_JP_SLOW),
240.v4l2_standard = {
241 .index = NTSC_M_JP_SLOW,
242 .id = (V4L2_STD_NTSC_M_JP | (((v4l2_std_id)0x01) << 32)),
243 .name = "NTSC_M_JP_SLOW",
244 .frameperiod = {1, 6},
245 .framelines = 525,
246 .reserved = {0, 0, 0, 0}
247}
248},
249/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
250{
251.mask = 0x8000 | (0x00FF & PAL_60_SLOW),
252.v4l2_standard = {
253 .index = PAL_60_SLOW,
254 .id = (V4L2_STD_PAL_60 | (((v4l2_std_id)0x01) << 32)),
255 .name = "PAL_60_SLOW",
256 .frameperiod = {1, 6},
257 .framelines = 525,
258 .reserved = {0, 0, 0, 0}
259}
260},
261/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
262{
263.mask = 0x8000 | (0x00FF & NTSC_443_SLOW),
264.v4l2_standard = {
265 .index = NTSC_443_SLOW,
266 .id = (V4L2_STD_NTSC_443 | (((v4l2_std_id)0x01) << 32)),
267 .name = "NTSC_443_SLOW",
268 .frameperiod = {1, 6},
269 .framelines = 525,
270 .reserved = {0, 0, 0, 0}
271}
272},
273/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
274{
275.mask = 0x8000 | (0x00FF & PAL_M_SLOW),
276.v4l2_standard = {
277 .index = PAL_M_SLOW,
278 .id = (V4L2_STD_PAL_M | (((v4l2_std_id)0x01) << 32)),
279 .name = "PAL_M_SLOW",
280 .frameperiod = {1, 6},
281 .framelines = 525,
282 .reserved = {0, 0, 0, 0}
283}
284},
285/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
286{
161.mask = 0xFFFF 287.mask = 0xFFFF
162} 288}
163}; 289};
@@ -165,15 +291,16 @@ const struct easycap_standard easycap_standard[] = {
165/* 291/*
166 * THE 16-BIT easycap_format.mask HAS MEANING: 292 * THE 16-BIT easycap_format.mask HAS MEANING:
167 * (least significant) BIT 0: 0 => PAL, 25 FPS; 1 => NTSC, 30 FPS 293 * (least significant) BIT 0: 0 => PAL, 25 FPS; 1 => NTSC, 30 FPS
168 * BITS 1-3: RESERVED FOR DIFFERENTIATING STANDARDS 294 * BITS 2-4: RESERVED FOR DIFFERENTIATING STANDARDS
169 * BITS 4-7: NUMBER OF BYTES PER PIXEL 295 * BITS 5-7: NUMBER OF BYTES PER PIXEL
170 * BIT 8: 0 => NATIVE BYTE ORDER; 1 => SWAPPED 296 * BIT 8: 0 => NATIVE BYTE ORDER; 1 => SWAPPED
171 * BITS 9-10: RESERVED FOR OTHER BYTE PERMUTATIONS 297 * BITS 9-10: RESERVED FOR OTHER BYTE PERMUTATIONS
172 * BIT 11: 0 => UNDECIMATED; 1 => DECIMATED 298 * BIT 11: 0 => UNDECIMATED; 1 => DECIMATED
173 * BIT 12: 0 => OFFER FRAMES; 1 => OFFER FIELDS 299 * BIT 12: 0 => OFFER FRAMES; 1 => OFFER FIELDS
174 * (most significant) BITS 13-15: RESERVED FOR OTHER FIELD ORDER OPTIONS 300 * BIT 13: 0 => FULL FRAMERATE; 1 => REDUCED
301 * (most significant) BITS 14-15: RESERVED FOR OTHER FIELD/FRAME OPTIONS
175 * IT FOLLOWS THAT: 302 * IT FOLLOWS THAT:
176 * bytesperpixel IS ((0x00F0 & easycap_format.mask) >> 4) 303 * bytesperpixel IS ((0x00E0 & easycap_format.mask) >> 5)
177 * byteswaporder IS true IF (0 != (0x0100 & easycap_format.mask)) 304 * byteswaporder IS true IF (0 != (0x0100 & easycap_format.mask))
178 * 305 *
179 * decimatepixel IS true IF (0 != (0x0800 & easycap_format.mask)) 306 * decimatepixel IS true IF (0 != (0x0800 & easycap_format.mask))
@@ -197,65 +324,135 @@ for (i = 0, n = 0; i < STANDARD_MANY; i++) {
197 mask1 = 0x0000; 324 mask1 = 0x0000;
198 switch (i) { 325 switch (i) {
199 case PAL_BGHIN: { 326 case PAL_BGHIN: {
200 mask1 = PAL_BGHIN; 327 mask1 = 0x1F & PAL_BGHIN;
201 strcpy(&name1[0], "PAL_BGHIN"); 328 strcpy(&name1[0], "PAL_BGHIN");
202 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG; 329 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
203 break; 330 break;
204 } 331 }
205 case SECAM: { 332 case SECAM: {
206 mask1 = SECAM; 333 mask1 = 0x1F & SECAM;
207 strcpy(&name1[0], "SECAM"); 334 strcpy(&name1[0], "SECAM");
208 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG; 335 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
209 break; 336 break;
210 } 337 }
211 case PAL_Nc: { 338 case PAL_Nc: {
212 mask1 = PAL_Nc; 339 mask1 = 0x1F & PAL_Nc;
213 strcpy(&name1[0], "PAL_Nc"); 340 strcpy(&name1[0], "PAL_Nc");
214 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG; 341 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
215 break; 342 break;
216 } 343 }
217 case PAL_60: { 344 case PAL_60: {
218 mask1 = PAL_60; 345 mask1 = 0x1F & PAL_60;
219 strcpy(&name1[0], "PAL_60"); 346 strcpy(&name1[0], "PAL_60");
220 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG; 347 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
221 break; 348 break;
222 } 349 }
223 case PAL_M: { 350 case PAL_M: {
224 mask1 = PAL_M; 351 mask1 = 0x1F & PAL_M;
225 strcpy(&name1[0], "PAL_M"); 352 strcpy(&name1[0], "PAL_M");
226 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG; 353 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
227 break; 354 break;
228 } 355 }
229 case NTSC_M: { 356 case NTSC_M: {
230 mask1 = NTSC_M; 357 mask1 = 0x1F & NTSC_M;
231 strcpy(&name1[0], "NTSC_M"); 358 strcpy(&name1[0], "NTSC_M");
232 colorspace = V4L2_COLORSPACE_470_SYSTEM_M; 359 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
233 break; 360 break;
234 } 361 }
235 case NTSC_443: { 362 case NTSC_443: {
236 mask1 = NTSC_443; 363 mask1 = 0x1F & NTSC_443;
237 strcpy(&name1[0], "NTSC_443"); 364 strcpy(&name1[0], "NTSC_443");
238 colorspace = V4L2_COLORSPACE_470_SYSTEM_M; 365 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
239 break; 366 break;
240 } 367 }
241 case NTSC_M_JP: { 368 case NTSC_M_JP: {
242 mask1 = NTSC_M_JP; 369 mask1 = 0x1F & NTSC_M_JP;
243 strcpy(&name1[0], "NTSC_M_JP"); 370 strcpy(&name1[0], "NTSC_M_JP");
244 colorspace = V4L2_COLORSPACE_470_SYSTEM_M; 371 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
245 break; 372 break;
246 } 373 }
247 case NTSC_N: { 374 case NTSC_N: {
248 mask1 = NTSC_M; 375 mask1 = 0x1F & NTSC_M;
249 strcpy(&name1[0], "NTSC_N"); 376 strcpy(&name1[0], "NTSC_N");
250 colorspace = V4L2_COLORSPACE_470_SYSTEM_M; 377 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
251 break; 378 break;
252 } 379 }
253 case NTSC_N_443: { 380 case NTSC_N_443: {
254 mask1 = NTSC_N_443; 381 mask1 = 0x1F & NTSC_N_443;
255 strcpy(&name1[0], "NTSC_N_443"); 382 strcpy(&name1[0], "NTSC_N_443");
256 colorspace = V4L2_COLORSPACE_470_SYSTEM_M; 383 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
257 break; 384 break;
258 } 385 }
386 case PAL_BGHIN_SLOW: {
387 mask1 = 0x001F & PAL_BGHIN_SLOW;
388 mask1 |= 0x0200;
389 strcpy(&name1[0], "PAL_BGHIN_SLOW");
390 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
391 break;
392 }
393 case SECAM_SLOW: {
394 mask1 = 0x001F & SECAM_SLOW;
395 mask1 |= 0x0200;
396 strcpy(&name1[0], "SECAM_SLOW");
397 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
398 break;
399 }
400 case PAL_Nc_SLOW: {
401 mask1 = 0x001F & PAL_Nc_SLOW;
402 mask1 |= 0x0200;
403 strcpy(&name1[0], "PAL_Nc_SLOW");
404 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
405 break;
406 }
407 case PAL_60_SLOW: {
408 mask1 = 0x001F & PAL_60_SLOW;
409 mask1 |= 0x0200;
410 strcpy(&name1[0], "PAL_60_SLOW");
411 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
412 break;
413 }
414 case PAL_M_SLOW: {
415 mask1 = 0x001F & PAL_M_SLOW;
416 mask1 |= 0x0200;
417 strcpy(&name1[0], "PAL_M_SLOW");
418 colorspace = V4L2_COLORSPACE_470_SYSTEM_BG;
419 break;
420 }
421 case NTSC_M_SLOW: {
422 mask1 = 0x001F & NTSC_M_SLOW;
423 mask1 |= 0x0200;
424 strcpy(&name1[0], "NTSC_M_SLOW");
425 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
426 break;
427 }
428 case NTSC_443_SLOW: {
429 mask1 = 0x001F & NTSC_443_SLOW;
430 mask1 |= 0x0200;
431 strcpy(&name1[0], "NTSC_443_SLOW");
432 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
433 break;
434 }
435 case NTSC_M_JP_SLOW: {
436 mask1 = 0x001F & NTSC_M_JP_SLOW;
437 mask1 |= 0x0200;
438 strcpy(&name1[0], "NTSC_M_JP_SLOW");
439 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
440 break;
441 }
442 case NTSC_N_SLOW: {
443 mask1 = 0x001F & NTSC_N_SLOW;
444 mask1 |= 0x0200;
445 strcpy(&name1[0], "NTSC_N_SLOW");
446 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
447 break;
448 }
449 case NTSC_N_443_SLOW: {
450 mask1 = 0x001F & NTSC_N_443_SLOW;
451 mask1 |= 0x0200;
452 strcpy(&name1[0], "NTSC_N_443_SLOW");
453 colorspace = V4L2_COLORSPACE_470_SYSTEM_M;
454 break;
455 }
259 default: 456 default:
260 return -1; 457 return -1;
261 } 458 }
@@ -311,39 +508,39 @@ for (i = 0, n = 0; i < STANDARD_MANY; i++) {
311 case FMT_UYVY: { 508 case FMT_UYVY: {
312 strcpy(&name3[0], "_" STRINGIZE(FMT_UYVY)); 509 strcpy(&name3[0], "_" STRINGIZE(FMT_UYVY));
313 pixelformat = V4L2_PIX_FMT_UYVY; 510 pixelformat = V4L2_PIX_FMT_UYVY;
314 mask3 |= (0x02 << 4); 511 mask3 |= (0x02 << 5);
315 break; 512 break;
316 } 513 }
317 case FMT_YUY2: { 514 case FMT_YUY2: {
318 strcpy(&name3[0], "_" STRINGIZE(FMT_YUY2)); 515 strcpy(&name3[0], "_" STRINGIZE(FMT_YUY2));
319 pixelformat = V4L2_PIX_FMT_YUYV; 516 pixelformat = V4L2_PIX_FMT_YUYV;
320 mask3 |= (0x02 << 4); 517 mask3 |= (0x02 << 5);
321 mask3 |= 0x0100; 518 mask3 |= 0x0100;
322 break; 519 break;
323 } 520 }
324 case FMT_RGB24: { 521 case FMT_RGB24: {
325 strcpy(&name3[0], "_" STRINGIZE(FMT_RGB24)); 522 strcpy(&name3[0], "_" STRINGIZE(FMT_RGB24));
326 pixelformat = V4L2_PIX_FMT_RGB24; 523 pixelformat = V4L2_PIX_FMT_RGB24;
327 mask3 |= (0x03 << 4); 524 mask3 |= (0x03 << 5);
328 break; 525 break;
329 } 526 }
330 case FMT_RGB32: { 527 case FMT_RGB32: {
331 strcpy(&name3[0], "_" STRINGIZE(FMT_RGB32)); 528 strcpy(&name3[0], "_" STRINGIZE(FMT_RGB32));
332 pixelformat = V4L2_PIX_FMT_RGB32; 529 pixelformat = V4L2_PIX_FMT_RGB32;
333 mask3 |= (0x04 << 4); 530 mask3 |= (0x04 << 5);
334 break; 531 break;
335 } 532 }
336 case FMT_BGR24: { 533 case FMT_BGR24: {
337 strcpy(&name3[0], "_" STRINGIZE(FMT_BGR24)); 534 strcpy(&name3[0], "_" STRINGIZE(FMT_BGR24));
338 pixelformat = V4L2_PIX_FMT_BGR24; 535 pixelformat = V4L2_PIX_FMT_BGR24;
339 mask3 |= (0x03 << 4); 536 mask3 |= (0x03 << 5);
340 mask3 |= 0x0100; 537 mask3 |= 0x0100;
341 break; 538 break;
342 } 539 }
343 case FMT_BGR32: { 540 case FMT_BGR32: {
344 strcpy(&name3[0], "_" STRINGIZE(FMT_BGR32)); 541 strcpy(&name3[0], "_" STRINGIZE(FMT_BGR32));
345 pixelformat = V4L2_PIX_FMT_BGR32; 542 pixelformat = V4L2_PIX_FMT_BGR32;
346 mask3 |= (0x04 << 4); 543 mask3 |= (0x04 << 5);
347 mask3 |= 0x0100; 544 mask3 |= 0x0100;
348 break; 545 break;
349 } 546 }
@@ -363,13 +560,8 @@ for (i = 0, n = 0; i < STANDARD_MANY; i++) {
363 } 560 }
364 case FIELD_INTERLACED: { 561 case FIELD_INTERLACED: {
365 strcpy(&name4[0], "-i"); 562 strcpy(&name4[0], "-i");
366 field = V4L2_FIELD_INTERLACED;
367 break;
368 }
369 case FIELD_ALTERNATE: {
370 strcpy(&name4[0], "-a");
371 mask4 |= 0x1000; 563 mask4 |= 0x1000;
372 field = V4L2_FIELD_ALTERNATE; 564 field = V4L2_FIELD_INTERLACED;
373 break; 565 break;
374 } 566 }
375 default: 567 default:
@@ -413,7 +605,7 @@ return n;
413} 605}
414/*---------------------------------------------------------------------------*/ 606/*---------------------------------------------------------------------------*/
415struct v4l2_queryctrl easycap_control[] = \ 607struct v4l2_queryctrl easycap_control[] = \
416 {{ 608{{
417.id = V4L2_CID_BRIGHTNESS, 609.id = V4L2_CID_BRIGHTNESS,
418.type = V4L2_CTRL_TYPE_INTEGER, 610.type = V4L2_CTRL_TYPE_INTEGER,
419.name = "Brightness", 611.name = "Brightness",
@@ -485,5 +677,5 @@ struct v4l2_queryctrl easycap_control[] = \
485{ 677{
486.id = 0xFFFFFFFF 678.id = 0xFFFFFFFF
487} 679}
488 }; 680};
489/*****************************************************************************/ 681/*****************************************************************************/
diff --git a/drivers/staging/easycap/easycap_sound.c b/drivers/staging/easycap/easycap_sound.c
index 63562bda738e..24d8bb4e449e 100644
--- a/drivers/staging/easycap/easycap_sound.c
+++ b/drivers/staging/easycap/easycap_sound.c
@@ -36,17 +36,15 @@
36/*---------------------------------------------------------------------------*/ 36/*---------------------------------------------------------------------------*/
37/* 37/*
38 * ON COMPLETION OF AN AUDIO URB ITS DATA IS COPIED TO THE AUDIO BUFFERS 38 * ON COMPLETION OF AN AUDIO URB ITS DATA IS COPIED TO THE AUDIO BUFFERS
39 * PROVIDED peasycap->audio_idle IS ZER0. REGARDLESS OF THIS BEING TRUE, 39 * PROVIDED peasycap->audio_idle IS ZERO. REGARDLESS OF THIS BEING TRUE,
40 * IT IS RESUBMITTED PROVIDED peasycap->audio_isoc_streaming IS NOT ZERO. 40 * IT IS RESUBMITTED PROVIDED peasycap->audio_isoc_streaming IS NOT ZERO.
41 */ 41 */
42/*---------------------------------------------------------------------------*/ 42/*---------------------------------------------------------------------------*/
43void 43void
44easysnd_complete(struct urb *purb) 44easysnd_complete(struct urb *purb)
45{ 45{
46static int mt;
47struct easycap *peasycap; 46struct easycap *peasycap;
48struct data_buffer *paudio_buffer; 47struct data_buffer *paudio_buffer;
49char errbuf[16];
50__u8 *p1, *p2; 48__u8 *p1, *p2;
51__s16 s16; 49__s16 s16;
52int i, j, more, much, leap, rc; 50int i, j, more, much, leap, rc;
@@ -66,48 +64,62 @@ if (NULL == peasycap) {
66 SAY("ERROR: peasycap is NULL\n"); 64 SAY("ERROR: peasycap is NULL\n");
67 return; 65 return;
68} 66}
69much = 0; 67if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
68 SAY("ERROR: bad peasycap\n");
69 return;
70}
70 71
72much = 0;
71 73
72if (peasycap->audio_idle) { 74if (peasycap->audio_idle) {
73 JOT(16, "%i=audio_idle %i=audio_isoc_streaming\n", \ 75 JOM(16, "%i=audio_idle %i=audio_isoc_streaming\n", \
74 peasycap->audio_idle, peasycap->audio_isoc_streaming); 76 peasycap->audio_idle, peasycap->audio_isoc_streaming);
75 if (peasycap->audio_isoc_streaming) { 77 if (peasycap->audio_isoc_streaming) {
76 rc = usb_submit_urb(purb, GFP_ATOMIC); 78 rc = usb_submit_urb(purb, GFP_ATOMIC);
77 if (0 != rc) { 79 if (0 != rc) {
78 SAY("ERROR: while %i=audio_idle, " \ 80 if (-ENODEV != rc)
81 SAM("ERROR: while %i=audio_idle, " \
79 "usb_submit_urb() failed with rc:\n", \ 82 "usb_submit_urb() failed with rc:\n", \
80 peasycap->audio_idle); 83 peasycap->audio_idle);
81 switch (rc) { 84 switch (rc) {
82 case -ENOMEM: { 85 case -ENOMEM: {
83 SAY("ENOMEM\n"); break; 86 SAM("-ENOMEM\n");
87 break;
84 } 88 }
85 case -ENODEV: { 89 case -ENODEV: {
86 SAY("ENODEV\n"); break; 90 break;
87 } 91 }
88 case -ENXIO: { 92 case -ENXIO: {
89 SAY("ENXIO\n"); break; 93 SAM("-ENXIO\n");
94 break;
90 } 95 }
91 case -EINVAL: { 96 case -EINVAL: {
92 SAY("EINVAL\n"); break; 97 SAM("-EINVAL\n");
98 break;
93 } 99 }
94 case -EAGAIN: { 100 case -EAGAIN: {
95 SAY("EAGAIN\n"); break; 101 SAM("-EAGAIN\n");
102 break;
96 } 103 }
97 case -EFBIG: { 104 case -EFBIG: {
98 SAY("EFBIG\n"); break; 105 SAM("-EFBIG\n");
106 break;
99 } 107 }
100 case -EPIPE: { 108 case -EPIPE: {
101 SAY("EPIPE\n"); break; 109 SAM("-EPIPE\n");
110 break;
102 } 111 }
103 case -EMSGSIZE: { 112 case -EMSGSIZE: {
104 SAY("EMSGSIZE\n"); break; 113 SAM("-EMSGSIZE\n");
114 break;
105 } 115 }
106 case -ENOSPC: { 116 case -ENOSPC: {
107 SAY("ENOSPC\n"); break; 117 SAM("-ENOSPC\n");
118 break;
108 } 119 }
109 default: { 120 default: {
110 SAY("0x%08X\n", rc); break; 121 SAM("unknown error: 0x%08X\n", rc);
122 break;
111 } 123 }
112 } 124 }
113 } 125 }
@@ -116,74 +128,95 @@ return;
116} 128}
117/*---------------------------------------------------------------------------*/ 129/*---------------------------------------------------------------------------*/
118if (purb->status) { 130if (purb->status) {
119 if (-ESHUTDOWN == purb->status) { 131 if ((-ESHUTDOWN == purb->status) || (-ENOENT == purb->status)) {
120 JOT(16, "immediate return because -ESHUTDOWN=purb->status\n"); 132 JOM(16, "urb status -ESHUTDOWN or -ENOENT\n");
121 return; 133 return;
122 } 134 }
123 SAY("ERROR: non-zero urb status:\n"); 135 SAM("ERROR: non-zero urb status:\n");
124 switch (purb->status) { 136 switch (purb->status) {
125 case -EINPROGRESS: { 137 case -EINPROGRESS: {
126 SAY("-EINPROGRESS\n"); break; 138 SAM("-EINPROGRESS\n");
139 break;
127 } 140 }
128 case -ENOSR: { 141 case -ENOSR: {
129 SAY("-ENOSR\n"); break; 142 SAM("-ENOSR\n");
143 break;
130 } 144 }
131 case -EPIPE: { 145 case -EPIPE: {
132 SAY("-EPIPE\n"); break; 146 SAM("-EPIPE\n");
147 break;
133 } 148 }
134 case -EOVERFLOW: { 149 case -EOVERFLOW: {
135 SAY("-EOVERFLOW\n"); break; 150 SAM("-EOVERFLOW\n");
151 break;
136 } 152 }
137 case -EPROTO: { 153 case -EPROTO: {
138 SAY("-EPROTO\n"); break; 154 SAM("-EPROTO\n");
155 break;
139 } 156 }
140 case -EILSEQ: { 157 case -EILSEQ: {
141 SAY("-EILSEQ\n"); break; 158 SAM("-EILSEQ\n");
159 break;
142 } 160 }
143 case -ETIMEDOUT: { 161 case -ETIMEDOUT: {
144 SAY("-ETIMEDOUT\n"); break; 162 SAM("-ETIMEDOUT\n");
163 break;
145 } 164 }
146 case -EMSGSIZE: { 165 case -EMSGSIZE: {
147 SAY("-EMSGSIZE\n"); break; 166 SAM("-EMSGSIZE\n");
167 break;
148 } 168 }
149 case -EOPNOTSUPP: { 169 case -EOPNOTSUPP: {
150 SAY("-EOPNOTSUPP\n"); break; 170 SAM("-EOPNOTSUPP\n");
171 break;
151 } 172 }
152 case -EPFNOSUPPORT: { 173 case -EPFNOSUPPORT: {
153 SAY("-EPFNOSUPPORT\n"); break; 174 SAM("-EPFNOSUPPORT\n");
175 break;
154 } 176 }
155 case -EAFNOSUPPORT: { 177 case -EAFNOSUPPORT: {
156 SAY("-EAFNOSUPPORT\n"); break; 178 SAM("-EAFNOSUPPORT\n");
179 break;
157 } 180 }
158 case -EADDRINUSE: { 181 case -EADDRINUSE: {
159 SAY("-EADDRINUSE\n"); break; 182 SAM("-EADDRINUSE\n");
183 break;
160 } 184 }
161 case -EADDRNOTAVAIL: { 185 case -EADDRNOTAVAIL: {
162 SAY("-EADDRNOTAVAIL\n"); break; 186 SAM("-EADDRNOTAVAIL\n");
187 break;
163 } 188 }
164 case -ENOBUFS: { 189 case -ENOBUFS: {
165 SAY("-ENOBUFS\n"); break; 190 SAM("-ENOBUFS\n");
191 break;
166 } 192 }
167 case -EISCONN: { 193 case -EISCONN: {
168 SAY("-EISCONN\n"); break; 194 SAM("-EISCONN\n");
195 break;
169 } 196 }
170 case -ENOTCONN: { 197 case -ENOTCONN: {
171 SAY("-ENOTCONN\n"); break; 198 SAM("-ENOTCONN\n");
199 break;
172 } 200 }
173 case -ESHUTDOWN: { 201 case -ESHUTDOWN: {
174 SAY("-ESHUTDOWN\n"); break; 202 SAM("-ESHUTDOWN\n");
203 break;
175 } 204 }
176 case -ENOENT: { 205 case -ENOENT: {
177 SAY("-ENOENT\n"); break; 206 SAM("-ENOENT\n");
207 break;
178 } 208 }
179 case -ECONNRESET: { 209 case -ECONNRESET: {
180 SAY("-ECONNRESET\n"); break; 210 SAM("-ECONNRESET\n");
211 break;
181 } 212 }
182 case -ENOSPC: { 213 case -ENOSPC: {
183 SAY("ENOSPC\n"); break; 214 SAM("ENOSPC\n");
215 break;
184 } 216 }
185 default: { 217 default: {
186 SAY("unknown error code 0x%08X\n", purb->status); break; 218 SAM("unknown error code 0x%08X\n", purb->status);
219 break;
187 } 220 }
188 } 221 }
189/*---------------------------------------------------------------------------*/ 222/*---------------------------------------------------------------------------*/
@@ -196,35 +229,43 @@ if (purb->status) {
196 if (peasycap->audio_isoc_streaming) { 229 if (peasycap->audio_isoc_streaming) {
197 rc = usb_submit_urb(purb, GFP_ATOMIC); 230 rc = usb_submit_urb(purb, GFP_ATOMIC);
198 if (0 != rc) { 231 if (0 != rc) {
199 SAY("ERROR: while %i=audio_idle, usb_submit_urb() " 232 SAM("ERROR: while %i=audio_idle, usb_submit_urb() "
200 "failed with rc:\n", peasycap->audio_idle); 233 "failed with rc:\n", peasycap->audio_idle);
201 switch (rc) { 234 switch (rc) {
202 case -ENOMEM: { 235 case -ENOMEM: {
203 SAY("ENOMEM\n"); break; 236 SAM("-ENOMEM\n");
237 break;
204 } 238 }
205 case -ENODEV: { 239 case -ENODEV: {
206 SAY("ENODEV\n"); break; 240 SAM("-ENODEV\n");
241 break;
207 } 242 }
208 case -ENXIO: { 243 case -ENXIO: {
209 SAY("ENXIO\n"); break; 244 SAM("-ENXIO\n");
245 break;
210 } 246 }
211 case -EINVAL: { 247 case -EINVAL: {
212 SAY("EINVAL\n"); break; 248 SAM("-EINVAL\n");
249 break;
213 } 250 }
214 case -EAGAIN: { 251 case -EAGAIN: {
215 SAY("EAGAIN\n"); break; 252 SAM("-EAGAIN\n");
253 break;
216 } 254 }
217 case -EFBIG: { 255 case -EFBIG: {
218 SAY("EFBIG\n"); break; 256 SAM("-EFBIG\n");
257 break;
219 } 258 }
220 case -EPIPE: { 259 case -EPIPE: {
221 SAY("EPIPE\n"); break; 260 SAM("-EPIPE\n");
261 break;
222 } 262 }
223 case -EMSGSIZE: { 263 case -EMSGSIZE: {
224 SAY("EMSGSIZE\n"); break; 264 SAM("-EMSGSIZE\n");
265 break;
225 } 266 }
226 default: { 267 default: {
227 SAY("0x%08X\n", rc); break; 268 SAM("0x%08X\n", rc); break;
228 } 269 }
229 } 270 }
230 } 271 }
@@ -243,72 +284,80 @@ oldaudio = peasycap->oldaudio;
243for (i = 0; i < purb->number_of_packets; i++) { 284for (i = 0; i < purb->number_of_packets; i++) {
244 switch (purb->iso_frame_desc[i].status) { 285 switch (purb->iso_frame_desc[i].status) {
245 case 0: { 286 case 0: {
246 strcpy(&errbuf[0], "OK"); break; 287 break;
247 } 288 }
248 case -ENOENT: { 289 case -ENOENT: {
249 strcpy(&errbuf[0], "-ENOENT"); break; 290 SAM("-ENOENT\n");
291 break;
250 } 292 }
251 case -EINPROGRESS: { 293 case -EINPROGRESS: {
252 strcpy(&errbuf[0], "-EINPROGRESS"); break; 294 SAM("-EINPROGRESS\n");
295 break;
253 } 296 }
254 case -EPROTO: { 297 case -EPROTO: {
255 strcpy(&errbuf[0], "-EPROTO"); break; 298 SAM("-EPROTO\n");
299 break;
256 } 300 }
257 case -EILSEQ: { 301 case -EILSEQ: {
258 strcpy(&errbuf[0], "-EILSEQ"); break; 302 SAM("-EILSEQ\n");
303 break;
259 } 304 }
260 case -ETIME: { 305 case -ETIME: {
261 strcpy(&errbuf[0], "-ETIME"); break; 306 SAM("-ETIME\n");
307 break;
262 } 308 }
263 case -ETIMEDOUT: { 309 case -ETIMEDOUT: {
264 strcpy(&errbuf[0], "-ETIMEDOUT"); break; 310 SAM("-ETIMEDOUT\n");
311 break;
265 } 312 }
266 case -EPIPE: { 313 case -EPIPE: {
267 strcpy(&errbuf[0], "-EPIPE"); break; 314 SAM("-EPIPE\n");
315 break;
268 } 316 }
269 case -ECOMM: { 317 case -ECOMM: {
270 strcpy(&errbuf[0], "-ECOMM"); break; 318 SAM("-ECOMM\n");
319 break;
271 } 320 }
272 case -ENOSR: { 321 case -ENOSR: {
273 strcpy(&errbuf[0], "-ENOSR"); break; 322 SAM("-ENOSR\n");
323 break;
274 } 324 }
275 case -EOVERFLOW: { 325 case -EOVERFLOW: {
276 strcpy(&errbuf[0], "-EOVERFLOW"); break; 326 SAM("-EOVERFLOW\n");
327 break;
277 } 328 }
278 case -EREMOTEIO: { 329 case -EREMOTEIO: {
279 strcpy(&errbuf[0], "-EREMOTEIO"); break; 330 SAM("-EREMOTEIO\n");
331 break;
280 } 332 }
281 case -ENODEV: { 333 case -ENODEV: {
282 strcpy(&errbuf[0], "-ENODEV"); break; 334 SAM("-ENODEV\n");
335 break;
283 } 336 }
284 case -EXDEV: { 337 case -EXDEV: {
285 strcpy(&errbuf[0], "-EXDEV"); break; 338 SAM("-EXDEV\n");
339 break;
286 } 340 }
287 case -EINVAL: { 341 case -EINVAL: {
288 strcpy(&errbuf[0], "-EINVAL"); break; 342 SAM("-EINVAL\n");
343 break;
289 } 344 }
290 case -ECONNRESET: { 345 case -ECONNRESET: {
291 strcpy(&errbuf[0], "-ECONNRESET"); break; 346 SAM("-ECONNRESET\n");
347 break;
292 } 348 }
293 case -ENOSPC: { 349 case -ENOSPC: {
294 strcpy(&errbuf[0], "-ENOSPC"); break; 350 SAM("-ENOSPC\n");
351 break;
295 } 352 }
296 case -ESHUTDOWN: { 353 case -ESHUTDOWN: {
297 strcpy(&errbuf[0], "-ESHUTDOWN"); break; 354 SAM("-ESHUTDOWN\n");
355 break;
298 } 356 }
299 default: { 357 default: {
300 strcpy(&errbuf[0], "UNKNOWN"); break; 358 SAM("unknown error:0x%08X\n", purb->iso_frame_desc[i].status);
301 } 359 break;
302 } 360 }
303 if ((!purb->iso_frame_desc[i].status) && 0) {
304 JOT(16, "frame[%2i]: %i=status{=%16s} " \
305 "%5i=actual " \
306 "%5i=length " \
307 "%3i=offset\n", \
308 i, purb->iso_frame_desc[i].status, &errbuf[0],
309 purb->iso_frame_desc[i].actual_length,
310 purb->iso_frame_desc[i].length,
311 purb->iso_frame_desc[i].offset);
312 } 361 }
313 if (!purb->iso_frame_desc[i].status) { 362 if (!purb->iso_frame_desc[i].status) {
314 more = purb->iso_frame_desc[i].actual_length; 363 more = purb->iso_frame_desc[i].actual_length;
@@ -319,11 +368,12 @@ for (i = 0; i < purb->number_of_packets; i++) {
319#endif 368#endif
320 369
321 if (!more) 370 if (!more)
322 mt++; 371 peasycap->audio_mt++;
323 else { 372 else {
324 if (mt) { 373 if (peasycap->audio_mt) {
325 JOT(16, "%4i empty audio urb frames\n", mt); 374 JOM(16, "%4i empty audio urb frames\n", \
326 mt = 0; 375 peasycap->audio_mt);
376 peasycap->audio_mt = 0;
327 } 377 }
328 378
329 p1 = (__u8 *)(purb->transfer_buffer + \ 379 p1 = (__u8 *)(purb->transfer_buffer + \
@@ -340,13 +390,13 @@ for (i = 0; i < purb->number_of_packets; i++) {
340/*---------------------------------------------------------------------------*/ 390/*---------------------------------------------------------------------------*/
341 while (more) { 391 while (more) {
342 if (0 > more) { 392 if (0 > more) {
343 SAY("easysnd_complete: MISTAKE: " \ 393 SAM("easysnd_complete: MISTAKE: " \
344 "more is negative\n"); 394 "more is negative\n");
345 return; 395 return;
346 } 396 }
347 if (peasycap->audio_buffer_page_many <= \ 397 if (peasycap->audio_buffer_page_many <= \
348 peasycap->audio_fill) { 398 peasycap->audio_fill) {
349 SAY("ERROR: bad " \ 399 SAM("ERROR: bad " \
350 "peasycap->audio_fill\n"); 400 "peasycap->audio_fill\n");
351 return; 401 return;
352 } 402 }
@@ -355,7 +405,7 @@ for (i = 0; i < purb->number_of_packets; i++) {
355 [peasycap->audio_fill]; 405 [peasycap->audio_fill];
356 if (PAGE_SIZE < (paudio_buffer->pto - \ 406 if (PAGE_SIZE < (paudio_buffer->pto - \
357 paudio_buffer->pgo)) { 407 paudio_buffer->pgo)) {
358 SAY("ERROR: bad paudio_buffer->pto\n"); 408 SAM("ERROR: bad paudio_buffer->pto\n");
359 return; 409 return;
360 } 410 }
361 if (PAGE_SIZE == (paudio_buffer->pto - \ 411 if (PAGE_SIZE == (paudio_buffer->pto - \
@@ -374,7 +424,7 @@ for (i = 0; i < purb->number_of_packets; i++) {
374 peasycap->audio_fill) 424 peasycap->audio_fill)
375 peasycap->audio_fill = 0; 425 peasycap->audio_fill = 0;
376 426
377 JOT(12, "bumped peasycap->" \ 427 JOM(12, "bumped peasycap->" \
378 "audio_fill to %i\n", \ 428 "audio_fill to %i\n", \
379 peasycap->audio_fill); 429 peasycap->audio_fill);
380 430
@@ -387,7 +437,7 @@ for (i = 0; i < purb->number_of_packets; i++) {
387 if (!(peasycap->audio_fill % \ 437 if (!(peasycap->audio_fill % \
388 peasycap->\ 438 peasycap->\
389 audio_pages_per_fragment)) { 439 audio_pages_per_fragment)) {
390 JOT(12, "wakeup call on wq_" \ 440 JOM(12, "wakeup call on wq_" \
391 "audio, %i=frag reading %i" \ 441 "audio, %i=frag reading %i" \
392 "=fragment fill\n", \ 442 "=fragment fill\n", \
393 (peasycap->audio_read / \ 443 (peasycap->audio_read / \
@@ -414,7 +464,7 @@ for (i = 0; i < purb->number_of_packets; i++) {
414 } else { 464 } else {
415#if defined(UPSAMPLE) 465#if defined(UPSAMPLE)
416 if (much % 16) 466 if (much % 16)
417 JOT(8, "MISTAKE? much" \ 467 JOM(8, "MISTAKE? much" \
418 " is not divisible by 16\n"); 468 " is not divisible by 16\n");
419 if (much > (16 * \ 469 if (much > (16 * \
420 more)) 470 more))
@@ -468,7 +518,7 @@ for (i = 0; i < purb->number_of_packets; i++) {
468 } 518 }
469 } 519 }
470 } else { 520 } else {
471 JOT(12, "discarding audio samples because " \ 521 JOM(12, "discarding audio samples because " \
472 "%i=purb->iso_frame_desc[i].status\n", \ 522 "%i=purb->iso_frame_desc[i].status\n", \
473 purb->iso_frame_desc[i].status); 523 purb->iso_frame_desc[i].status);
474 } 524 }
@@ -486,38 +536,50 @@ peasycap->oldaudio = oldaudio;
486if (peasycap->audio_isoc_streaming) { 536if (peasycap->audio_isoc_streaming) {
487 rc = usb_submit_urb(purb, GFP_ATOMIC); 537 rc = usb_submit_urb(purb, GFP_ATOMIC);
488 if (0 != rc) { 538 if (0 != rc) {
489 SAY("ERROR: while %i=audio_idle, usb_submit_urb() failed " \ 539 if (-ENODEV != rc) {
540 SAM("ERROR: while %i=audio_idle, " \
541 "usb_submit_urb() failed " \
490 "with rc:\n", peasycap->audio_idle); 542 "with rc:\n", peasycap->audio_idle);
543 }
491 switch (rc) { 544 switch (rc) {
492 case -ENOMEM: { 545 case -ENOMEM: {
493 SAY("ENOMEM\n"); break; 546 SAM("-ENOMEM\n");
547 break;
494 } 548 }
495 case -ENODEV: { 549 case -ENODEV: {
496 SAY("ENODEV\n"); break; 550 break;
497 } 551 }
498 case -ENXIO: { 552 case -ENXIO: {
499 SAY("ENXIO\n"); break; 553 SAM("-ENXIO\n");
554 break;
500 } 555 }
501 case -EINVAL: { 556 case -EINVAL: {
502 SAY("EINVAL\n"); break; 557 SAM("-EINVAL\n");
558 break;
503 } 559 }
504 case -EAGAIN: { 560 case -EAGAIN: {
505 SAY("EAGAIN\n"); break; 561 SAM("-EAGAIN\n");
562 break;
506 } 563 }
507 case -EFBIG: { 564 case -EFBIG: {
508 SAY("EFBIG\n"); break; 565 SAM("-EFBIG\n");
566 break;
509 } 567 }
510 case -EPIPE: { 568 case -EPIPE: {
511 SAY("EPIPE\n"); break; 569 SAM("-EPIPE\n");
570 break;
512 } 571 }
513 case -EMSGSIZE: { 572 case -EMSGSIZE: {
514 SAY("EMSGSIZE\n"); break; 573 SAM("-EMSGSIZE\n");
574 break;
515 } 575 }
516 case -ENOSPC: { 576 case -ENOSPC: {
517 SAY("ENOSPC\n"); break; 577 SAM("-ENOSPC\n");
578 break;
518 } 579 }
519 default: { 580 default: {
520 SAY("0x%08X\n", rc); break; 581 SAM("unknown error: 0x%08X\n", rc);
582 break;
521 } 583 }
522 } 584 }
523 } 585 }
@@ -529,8 +591,7 @@ return;
529/* 591/*
530 * THE AUDIO URBS ARE SUBMITTED AT THIS EARLY STAGE SO THAT IT IS POSSIBLE TO 592 * THE AUDIO URBS ARE SUBMITTED AT THIS EARLY STAGE SO THAT IT IS POSSIBLE TO
531 * STREAM FROM /dev/easysnd1 WITH SIMPLE PROGRAMS SUCH AS cat WHICH DO NOT 593 * STREAM FROM /dev/easysnd1 WITH SIMPLE PROGRAMS SUCH AS cat WHICH DO NOT
532 * HAVE AN IOCTL INTERFACE. THE VIDEO URBS, BY CONTRAST, MUST BE SUBMITTED 594 * HAVE AN IOCTL INTERFACE.
533 * MUCH LATER: SEE COMMENTS IN FILE easycap_main.c.
534 */ 595 */
535/*---------------------------------------------------------------------------*/ 596/*---------------------------------------------------------------------------*/
536int 597int
@@ -539,8 +600,15 @@ easysnd_open(struct inode *inode, struct file *file)
539struct usb_interface *pusb_interface; 600struct usb_interface *pusb_interface;
540struct easycap *peasycap; 601struct easycap *peasycap;
541int subminor, rc; 602int subminor, rc;
603/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
604#if defined(EASYCAP_IS_VIDEODEV_CLIENT)
605#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
606struct v4l2_device *pv4l2_device;
607#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
608#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
609/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
542 610
543JOT(4, "begins.\n"); 611JOT(4, "begins\n");
544 612
545subminor = iminor(inode); 613subminor = iminor(inode);
546 614
@@ -556,70 +624,90 @@ if (NULL == peasycap) {
556 SAY("ending unsuccessfully\n"); 624 SAY("ending unsuccessfully\n");
557 return -1; 625 return -1;
558} 626}
627/*---------------------------------------------------------------------------*/
628#if (!defined(EASYCAP_IS_VIDEODEV_CLIENT))
629#
630/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
631#else
632#if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
633/*---------------------------------------------------------------------------*/
634/*
635 * SOME VERSIONS OF THE videodev MODULE OVERWRITE THE DATA WHICH HAS
636 * BEEN WRITTEN BY THE CALL TO usb_set_intfdata() IN easycap_usb_probe(),
637 * REPLACING IT WITH A POINTER TO THE EMBEDDED v4l2_device STRUCTURE.
638 * TO DETECT THIS, THE STRING IN THE easycap.telltale[] BUFFER IS CHECKED.
639*/
640/*---------------------------------------------------------------------------*/
641if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
642 pv4l2_device = usb_get_intfdata(pusb_interface);
643 if ((struct v4l2_device *)NULL == pv4l2_device) {
644 SAY("ERROR: pv4l2_device is NULL\n");
645 return -EFAULT;
646 }
647 peasycap = (struct easycap *) \
648 container_of(pv4l2_device, struct easycap, v4l2_device);
649}
650#endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
651#
652#endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
653/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
654/*---------------------------------------------------------------------------*/
655if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
656 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
657 return -EFAULT;
658}
659/*---------------------------------------------------------------------------*/
559 660
560file->private_data = peasycap; 661file->private_data = peasycap;
561 662
562/*---------------------------------------------------------------------------*/ 663/*---------------------------------------------------------------------------*/
563/* 664/*
564 * INITIALIZATION. 665 * INITIALIZATION
565 */ 666 */
566/*---------------------------------------------------------------------------*/ 667/*---------------------------------------------------------------------------*/
567JOT(4, "starting initialization\n"); 668JOM(4, "starting initialization\n");
568 669
569if ((struct usb_device *)NULL == peasycap->pusb_device) { 670if ((struct usb_device *)NULL == peasycap->pusb_device) {
570 SAY("ERROR: peasycap->pusb_device is NULL\n"); 671 SAM("ERROR: peasycap->pusb_device is NULL\n");
571 return -EFAULT; 672 return -ENODEV;
572} else {
573 JOT(16, "0x%08lX=peasycap->pusb_device\n", \
574 (long int)peasycap->pusb_device);
575} 673}
674JOM(16, "0x%08lX=peasycap->pusb_device\n", (long int)peasycap->pusb_device);
576 675
577rc = audio_setup(peasycap); 676rc = audio_setup(peasycap);
578if (0 <= rc) 677if (0 <= rc)
579 JOT(8, "audio_setup() returned %i\n", rc); 678 JOM(8, "audio_setup() returned %i\n", rc);
580else 679else
581 JOT(8, "easysnd open(): ERROR: audio_setup() returned %i\n", rc); 680 JOM(8, "easysnd open(): ERROR: audio_setup() returned %i\n", rc);
582 681
583if ((struct usb_device *)NULL == peasycap->pusb_device) { 682if ((struct usb_device *)NULL == peasycap->pusb_device) {
584 SAY("ERROR: peasycap->pusb_device has become NULL\n"); 683 SAM("ERROR: peasycap->pusb_device has become NULL\n");
585 return -EFAULT; 684 return -ENODEV;
586}
587rc = adjust_volume(peasycap, -8192);
588if (0 != rc) {
589 SAY("ERROR: adjust_volume(default) returned %i\n", rc);
590 return -EFAULT;
591} 685}
592/*---------------------------------------------------------------------------*/ 686/*---------------------------------------------------------------------------*/
593if ((struct usb_device *)NULL == peasycap->pusb_device) { 687if ((struct usb_device *)NULL == peasycap->pusb_device) {
594 SAY("ERROR: peasycap->pusb_device has become NULL\n"); 688 SAM("ERROR: peasycap->pusb_device has become NULL\n");
595 return -EFAULT; 689 return -ENODEV;
596} 690}
597rc = usb_set_interface(peasycap->pusb_device, peasycap->audio_interface, \ 691rc = usb_set_interface(peasycap->pusb_device, peasycap->audio_interface, \
598 peasycap->audio_altsetting_on); 692 peasycap->audio_altsetting_on);
599JOT(8, "usb_set_interface(.,%i,%i) returned %i\n", peasycap->audio_interface, \ 693JOM(8, "usb_set_interface(.,%i,%i) returned %i\n", peasycap->audio_interface, \
600 peasycap->audio_altsetting_on, rc); 694 peasycap->audio_altsetting_on, rc);
601 695
602if ((struct usb_device *)NULL == peasycap->pusb_device) {
603 SAY("ERROR: peasycap->pusb_device has become NULL\n");
604 return -EFAULT;
605}
606rc = wakeup_device(peasycap->pusb_device); 696rc = wakeup_device(peasycap->pusb_device);
607if (0 == rc) 697if (0 == rc)
608 JOT(8, "wakeup_device() returned %i\n", rc); 698 JOM(8, "wakeup_device() returned %i\n", rc);
609else 699else
610 JOT(8, "easysnd open(): ERROR: wakeup_device() returned %i\n", rc); 700 JOM(8, "ERROR: wakeup_device() returned %i\n", rc);
611 701
612if ((struct usb_device *)NULL == peasycap->pusb_device) { 702peasycap->audio_eof = 0;
613 SAY("ERROR: peasycap->pusb_device has become NULL\n");
614 return -EFAULT;
615}
616submit_audio_urbs(peasycap);
617peasycap->audio_idle = 0; 703peasycap->audio_idle = 0;
618 704
619peasycap->timeval1.tv_sec = 0; 705peasycap->timeval1.tv_sec = 0;
620peasycap->timeval1.tv_usec = 0; 706peasycap->timeval1.tv_usec = 0;
621 707
622JOT(4, "finished initialization\n"); 708submit_audio_urbs(peasycap);
709
710JOM(4, "finished initialization\n");
623return 0; 711return 0;
624} 712}
625/*****************************************************************************/ 713/*****************************************************************************/
@@ -635,11 +723,15 @@ if (NULL == peasycap) {
635 SAY("ERROR: peasycap is NULL.\n"); 723 SAY("ERROR: peasycap is NULL.\n");
636 return -EFAULT; 724 return -EFAULT;
637} 725}
726if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
727 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
728 return -EFAULT;
729}
638if (0 != kill_audio_urbs(peasycap)) { 730if (0 != kill_audio_urbs(peasycap)) {
639 SAY("ERROR: kill_audio_urbs() failed\n"); 731 SAM("ERROR: kill_audio_urbs() failed\n");
640 return -EFAULT; 732 return -EFAULT;
641} 733}
642JOT(4, "ending successfully\n"); 734JOM(4, "ending successfully\n");
643return 0; 735return 0;
644} 736}
645/*****************************************************************************/ 737/*****************************************************************************/
@@ -648,12 +740,11 @@ easysnd_read(struct file *file, char __user *puserspacebuffer, \
648 size_t kount, loff_t *poff) 740 size_t kount, loff_t *poff)
649{ 741{
650struct timeval timeval; 742struct timeval timeval;
651static struct timeval timeval1; 743long long int above, below, mean;
652static long long int audio_bytes, above, below, mean;
653struct signed_div_result sdr; 744struct signed_div_result sdr;
654unsigned char *p0; 745unsigned char *p0;
655long int kount1, more, rc, l0, lm; 746long int kount1, more, rc, l0, lm;
656int fragment; 747int fragment, kd;
657struct easycap *peasycap; 748struct easycap *peasycap;
658struct data_buffer *pdata_buffer; 749struct data_buffer *pdata_buffer;
659size_t szret; 750size_t szret;
@@ -671,23 +762,89 @@ size_t szret;
671 762
672JOT(8, "===== easysnd_read(): kount=%i, *poff=%i\n", (int)kount, (int)(*poff)); 763JOT(8, "===== easysnd_read(): kount=%i, *poff=%i\n", (int)kount, (int)(*poff));
673 764
674peasycap = (struct easycap *)(file->private_data); 765if (NULL == file) {
766 SAY("ERROR: file is NULL\n");
767 return -ERESTARTSYS;
768}
769peasycap = file->private_data;
675if (NULL == peasycap) { 770if (NULL == peasycap) {
676 SAY("ERROR in easysnd_read(): peasycap is NULL\n"); 771 SAY("ERROR in easysnd_read(): peasycap is NULL\n");
677 return -EFAULT; 772 return -EFAULT;
678} 773}
774if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
775 SAY("ERROR: bad peasycap: 0x%08lX\n", (unsigned long int) peasycap);
776 return -EFAULT;
777}
778if (NULL == peasycap->pusb_device) {
779 SAY("ERROR in easysnd_read(): peasycap->pusb_device is NULL\n");
780 return -EFAULT;
781}
782kd = isdongle(peasycap);
783if (0 <= kd && DONGLE_MANY > kd) {
784 if (mutex_lock_interruptible(&(easycap_dongle[kd].mutex_audio))) {
785 SAY("ERROR: cannot lock easycap_dongle[%i].mutex_audio\n", kd);
786 return -ERESTARTSYS;
787 }
788 JOM(4, "locked easycap_dongle[%i].mutex_audio\n", kd);
679/*---------------------------------------------------------------------------*/ 789/*---------------------------------------------------------------------------*/
790/*
791 * MEANWHILE, easycap_usb_disconnect() MAY HAVE FREED POINTER peasycap,
792 * IN WHICH CASE A REPEAT CALL TO isdongle() WILL FAIL.
793 * IF NECESSARY, BAIL OUT.
794*/
795/*---------------------------------------------------------------------------*/
796 if (kd != isdongle(peasycap))
797 return -ERESTARTSYS;
798 if (NULL == file) {
799 SAY("ERROR: file is NULL\n");
800 mutex_unlock(&easycap_dongle[kd].mutex_audio);
801 return -ERESTARTSYS;
802 }
803 peasycap = file->private_data;
804 if (NULL == peasycap) {
805 SAY("ERROR: peasycap is NULL\n");
806 mutex_unlock(&easycap_dongle[kd].mutex_audio);
807 return -ERESTARTSYS;
808 }
809 if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) {
810 SAY("ERROR: bad peasycap: 0x%08lX\n", \
811 (unsigned long int) peasycap);
812 mutex_unlock(&easycap_dongle[kd].mutex_audio);
813 return -ERESTARTSYS;
814 }
815 if (NULL == peasycap->pusb_device) {
816 SAM("ERROR: peasycap->pusb_device is NULL\n");
817 mutex_unlock(&easycap_dongle[kd].mutex_audio);
818 return -ERESTARTSYS;
819 }
820} else {
821/*---------------------------------------------------------------------------*/
822/*
823 * IF easycap_usb_disconnect() HAS ALREADY FREED POINTER peasycap BEFORE THE
824 * ATTEMPT TO ACQUIRE THE SEMAPHORE, isdongle() WILL HAVE FAILED. BAIL OUT.
825*/
826/*---------------------------------------------------------------------------*/
827 return -ERESTARTSYS;
828}
829/*---------------------------------------------------------------------------*/
830if (file->f_flags & O_NONBLOCK)
831 JOT(16, "NONBLOCK kount=%i, *poff=%i\n", (int)kount, (int)(*poff));
832else
833 JOT(8, "BLOCKING kount=%i, *poff=%i\n", (int)kount, (int)(*poff));
834
680if ((0 > peasycap->audio_read) || \ 835if ((0 > peasycap->audio_read) || \
681 (peasycap->audio_buffer_page_many <= peasycap->audio_read)) { 836 (peasycap->audio_buffer_page_many <= peasycap->audio_read)) {
682 SAY("ERROR: peasycap->audio_read out of range\n"); 837 SAM("ERROR: peasycap->audio_read out of range\n");
838 mutex_unlock(&easycap_dongle[kd].mutex_audio);
683 return -EFAULT; 839 return -EFAULT;
684} 840}
685pdata_buffer = &peasycap->audio_buffer[peasycap->audio_read]; 841pdata_buffer = &peasycap->audio_buffer[peasycap->audio_read];
686if ((struct data_buffer *)NULL == pdata_buffer) { 842if ((struct data_buffer *)NULL == pdata_buffer) {
687 SAY("ERROR: pdata_buffer is NULL\n"); 843 SAM("ERROR: pdata_buffer is NULL\n");
844 mutex_unlock(&easycap_dongle[kd].mutex_audio);
688 return -EFAULT; 845 return -EFAULT;
689} 846}
690JOT(12, "before wait, %i=frag read %i=frag fill\n", \ 847JOM(12, "before wait, %i=frag read %i=frag fill\n", \
691 (peasycap->audio_read / peasycap->audio_pages_per_fragment), \ 848 (peasycap->audio_read / peasycap->audio_pages_per_fragment), \
692 (peasycap->audio_fill / peasycap->audio_pages_per_fragment)); 849 (peasycap->audio_fill / peasycap->audio_pages_per_fragment));
693fragment = (peasycap->audio_read / peasycap->audio_pages_per_fragment); 850fragment = (peasycap->audio_read / peasycap->audio_pages_per_fragment);
@@ -695,7 +852,8 @@ while ((fragment == (peasycap->audio_fill / \
695 peasycap->audio_pages_per_fragment)) || \ 852 peasycap->audio_pages_per_fragment)) || \
696 (0 == (PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo)))) { 853 (0 == (PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo)))) {
697 if (file->f_flags & O_NONBLOCK) { 854 if (file->f_flags & O_NONBLOCK) {
698 JOT(16, "returning -EAGAIN as instructed\n"); 855 JOM(16, "returning -EAGAIN as instructed\n");
856 mutex_unlock(&easycap_dongle[kd].mutex_audio);
699 return -EAGAIN; 857 return -EAGAIN;
700 } 858 }
701 rc = wait_event_interruptible(peasycap->wq_audio, \ 859 rc = wait_event_interruptible(peasycap->wq_audio, \
@@ -704,50 +862,56 @@ while ((fragment == (peasycap->audio_fill / \
704 peasycap->audio_pages_per_fragment)) && \ 862 peasycap->audio_pages_per_fragment)) && \
705 (0 < (PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo)))))); 863 (0 < (PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo))))));
706 if (0 != rc) { 864 if (0 != rc) {
707 SAY("aborted by signal\n"); 865 SAM("aborted by signal\n");
866 mutex_unlock(&easycap_dongle[kd].mutex_audio);
708 return -ERESTARTSYS; 867 return -ERESTARTSYS;
709 } 868 }
710 if (peasycap->audio_eof) { 869 if (peasycap->audio_eof) {
711 JOT(8, "returning 0 because %i=audio_eof\n", \ 870 JOM(8, "returning 0 because %i=audio_eof\n", \
712 peasycap->audio_eof); 871 peasycap->audio_eof);
713 kill_audio_urbs(peasycap); 872 kill_audio_urbs(peasycap);
714 msleep(500); 873 mutex_unlock(&easycap_dongle[kd].mutex_audio);
715 return 0; 874 return 0;
716 } 875 }
717 if (peasycap->audio_idle) { 876 if (peasycap->audio_idle) {
718 JOT(16, "returning 0 because %i=audio_idle\n", \ 877 JOM(16, "returning 0 because %i=audio_idle\n", \
719 peasycap->audio_idle); 878 peasycap->audio_idle);
879 mutex_unlock(&easycap_dongle[kd].mutex_audio);
720 return 0; 880 return 0;
721 } 881 }
722 if (!peasycap->audio_isoc_streaming) { 882 if (!peasycap->audio_isoc_streaming) {
723 JOT(16, "returning 0 because audio urbs not streaming\n"); 883 JOM(16, "returning 0 because audio urbs not streaming\n");
884 mutex_unlock(&easycap_dongle[kd].mutex_audio);
724 return 0; 885 return 0;
725 } 886 }
726} 887}
727JOT(12, "after wait, %i=frag read %i=frag fill\n", \ 888JOM(12, "after wait, %i=frag read %i=frag fill\n", \
728 (peasycap->audio_read / peasycap->audio_pages_per_fragment), \ 889 (peasycap->audio_read / peasycap->audio_pages_per_fragment), \
729 (peasycap->audio_fill / peasycap->audio_pages_per_fragment)); 890 (peasycap->audio_fill / peasycap->audio_pages_per_fragment));
730szret = (size_t)0; 891szret = (size_t)0;
731while (fragment == (peasycap->audio_read / \ 892while (fragment == (peasycap->audio_read / \
732 peasycap->audio_pages_per_fragment)) { 893 peasycap->audio_pages_per_fragment)) {
733 if (NULL == pdata_buffer->pgo) { 894 if (NULL == pdata_buffer->pgo) {
734 SAY("ERROR: pdata_buffer->pgo is NULL\n"); 895 SAM("ERROR: pdata_buffer->pgo is NULL\n");
896 mutex_unlock(&easycap_dongle[kd].mutex_audio);
735 return -EFAULT; 897 return -EFAULT;
736 } 898 }
737 if (NULL == pdata_buffer->pto) { 899 if (NULL == pdata_buffer->pto) {
738 SAY("ERROR: pdata_buffer->pto is NULL\n"); 900 SAM("ERROR: pdata_buffer->pto is NULL\n");
901 mutex_unlock(&easycap_dongle[kd].mutex_audio);
739 return -EFAULT; 902 return -EFAULT;
740 } 903 }
741 kount1 = PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo); 904 kount1 = PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo);
742 if (0 > kount1) { 905 if (0 > kount1) {
743 SAY("easysnd_read: MISTAKE: kount1 is negative\n"); 906 SAM("easysnd_read: MISTAKE: kount1 is negative\n");
907 mutex_unlock(&easycap_dongle[kd].mutex_audio);
744 return -ERESTARTSYS; 908 return -ERESTARTSYS;
745 } 909 }
746 if (!kount1) { 910 if (!kount1) {
747 (peasycap->audio_read)++; 911 (peasycap->audio_read)++;
748 if (peasycap->audio_buffer_page_many <= peasycap->audio_read) 912 if (peasycap->audio_buffer_page_many <= peasycap->audio_read)
749 peasycap->audio_read = 0; 913 peasycap->audio_read = 0;
750 JOT(12, "bumped peasycap->audio_read to %i\n", \ 914 JOM(12, "bumped peasycap->audio_read to %i\n", \
751 peasycap->audio_read); 915 peasycap->audio_read);
752 916
753 if (fragment != (peasycap->audio_read / \ 917 if (fragment != (peasycap->audio_read / \
@@ -757,30 +921,34 @@ while (fragment == (peasycap->audio_read / \
757 if ((0 > peasycap->audio_read) || \ 921 if ((0 > peasycap->audio_read) || \
758 (peasycap->audio_buffer_page_many <= \ 922 (peasycap->audio_buffer_page_many <= \
759 peasycap->audio_read)) { 923 peasycap->audio_read)) {
760 SAY("ERROR: peasycap->audio_read out of range\n"); 924 SAM("ERROR: peasycap->audio_read out of range\n");
925 mutex_unlock(&easycap_dongle[kd].mutex_audio);
761 return -EFAULT; 926 return -EFAULT;
762 } 927 }
763 pdata_buffer = &peasycap->audio_buffer[peasycap->audio_read]; 928 pdata_buffer = &peasycap->audio_buffer[peasycap->audio_read];
764 if ((struct data_buffer *)NULL == pdata_buffer) { 929 if ((struct data_buffer *)NULL == pdata_buffer) {
765 SAY("ERROR: pdata_buffer is NULL\n"); 930 SAM("ERROR: pdata_buffer is NULL\n");
931 mutex_unlock(&easycap_dongle[kd].mutex_audio);
766 return -EFAULT; 932 return -EFAULT;
767 } 933 }
768 if (NULL == pdata_buffer->pgo) { 934 if (NULL == pdata_buffer->pgo) {
769 SAY("ERROR: pdata_buffer->pgo is NULL\n"); 935 SAM("ERROR: pdata_buffer->pgo is NULL\n");
936 mutex_unlock(&easycap_dongle[kd].mutex_audio);
770 return -EFAULT; 937 return -EFAULT;
771 } 938 }
772 if (NULL == pdata_buffer->pto) { 939 if (NULL == pdata_buffer->pto) {
773 SAY("ERROR: pdata_buffer->pto is NULL\n"); 940 SAM("ERROR: pdata_buffer->pto is NULL\n");
941 mutex_unlock(&easycap_dongle[kd].mutex_audio);
774 return -EFAULT; 942 return -EFAULT;
775 } 943 }
776 kount1 = PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo); 944 kount1 = PAGE_SIZE - (pdata_buffer->pto - pdata_buffer->pgo);
777 } 945 }
778 JOT(12, "ready to send %li bytes\n", (long int) kount1); 946 JOM(12, "ready to send %li bytes\n", (long int) kount1);
779 JOT(12, "still to send %li bytes\n", (long int) kount); 947 JOM(12, "still to send %li bytes\n", (long int) kount);
780 more = kount1; 948 more = kount1;
781 if (more > kount) 949 if (more > kount)
782 more = kount; 950 more = kount;
783 JOT(12, "agreed to send %li bytes from page %i\n", \ 951 JOM(12, "agreed to send %li bytes from page %i\n", \
784 more, peasycap->audio_read); 952 more, peasycap->audio_read);
785 if (!more) 953 if (!more)
786 break; 954 break;
@@ -798,7 +966,8 @@ while (fragment == (peasycap->audio_read / \
798/*---------------------------------------------------------------------------*/ 966/*---------------------------------------------------------------------------*/
799 rc = copy_to_user(puserspacebuffer, pdata_buffer->pto, more); 967 rc = copy_to_user(puserspacebuffer, pdata_buffer->pto, more);
800 if (0 != rc) { 968 if (0 != rc) {
801 SAY("ERROR: copy_to_user() returned %li\n", rc); 969 SAM("ERROR: copy_to_user() returned %li\n", rc);
970 mutex_unlock(&easycap_dongle[kd].mutex_audio);
802 return -EFAULT; 971 return -EFAULT;
803 } 972 }
804 *poff += (loff_t)more; 973 *poff += (loff_t)more;
@@ -807,11 +976,11 @@ while (fragment == (peasycap->audio_read / \
807 puserspacebuffer += more; 976 puserspacebuffer += more;
808 kount -= (size_t)more; 977 kount -= (size_t)more;
809} 978}
810JOT(12, "after read, %i=frag read %i=frag fill\n", \ 979JOM(12, "after read, %i=frag read %i=frag fill\n", \
811 (peasycap->audio_read / peasycap->audio_pages_per_fragment), \ 980 (peasycap->audio_read / peasycap->audio_pages_per_fragment), \
812 (peasycap->audio_fill / peasycap->audio_pages_per_fragment)); 981 (peasycap->audio_fill / peasycap->audio_pages_per_fragment));
813if (kount < 0) { 982if (kount < 0) {
814 SAY("MISTAKE: %li=kount %li=szret\n", \ 983 SAM("MISTAKE: %li=kount %li=szret\n", \
815 (long int)kount, (long int)szret); 984 (long int)kount, (long int)szret);
816} 985}
817/*---------------------------------------------------------------------------*/ 986/*---------------------------------------------------------------------------*/
@@ -827,11 +996,11 @@ if (peasycap->audio_sample) {
827 mean = peasycap->audio_niveau; 996 mean = peasycap->audio_niveau;
828 sdr = signed_div(mean, peasycap->audio_sample); 997 sdr = signed_div(mean, peasycap->audio_sample);
829 998
830 JOT(8, "%8lli=mean %8lli=meansquare after %lli samples, =>\n", \ 999 JOM(8, "%8lli=mean %8lli=meansquare after %lli samples, =>\n", \
831 sdr.quotient, above, peasycap->audio_sample); 1000 sdr.quotient, above, peasycap->audio_sample);
832 1001
833 sdr = signed_div(above, 32768); 1002 sdr = signed_div(above, 32768);
834 JOT(8, "audio dynamic range is roughly %lli\n", sdr.quotient); 1003 JOM(8, "audio dynamic range is roughly %lli\n", sdr.quotient);
835} 1004}
836/*---------------------------------------------------------------------------*/ 1005/*---------------------------------------------------------------------------*/
837/* 1006/*
@@ -840,33 +1009,28 @@ if (peasycap->audio_sample) {
840/*---------------------------------------------------------------------------*/ 1009/*---------------------------------------------------------------------------*/
841do_gettimeofday(&timeval); 1010do_gettimeofday(&timeval);
842if (!peasycap->timeval1.tv_sec) { 1011if (!peasycap->timeval1.tv_sec) {
843 audio_bytes = 0; 1012 peasycap->audio_bytes = 0;
844 timeval1 = timeval; 1013 peasycap->timeval3 = timeval;
845 1014 peasycap->timeval1 = peasycap->timeval3;
846 if (mutex_lock_interruptible(&(peasycap->mutex_timeval1)))
847 return -ERESTARTSYS;
848 peasycap->timeval1 = timeval1;
849 mutex_unlock(&(peasycap->mutex_timeval1));
850 sdr.quotient = 192000; 1015 sdr.quotient = 192000;
851} else { 1016} else {
852 audio_bytes += (long long int) szret; 1017 peasycap->audio_bytes += (long long int) szret;
853 below = ((long long int)(1000000)) * \ 1018 below = ((long long int)(1000000)) * \
854 ((long long int)(timeval.tv_sec - timeval1.tv_sec)) + \ 1019 ((long long int)(timeval.tv_sec - \
855 (long long int)(timeval.tv_usec - timeval1.tv_usec); 1020 peasycap->timeval3.tv_sec)) + \
856 above = 1000000 * ((long long int) audio_bytes); 1021 (long long int)(timeval.tv_usec - peasycap->timeval3.tv_usec);
1022 above = 1000000 * ((long long int) peasycap->audio_bytes);
857 1023
858 if (below) 1024 if (below)
859 sdr = signed_div(above, below); 1025 sdr = signed_div(above, below);
860 else 1026 else
861 sdr.quotient = 192000; 1027 sdr.quotient = 192000;
862} 1028}
863JOT(8, "audio streaming at %lli bytes/second\n", sdr.quotient); 1029JOM(8, "audio streaming at %lli bytes/second\n", sdr.quotient);
864if (mutex_lock_interruptible(&(peasycap->mutex_timeval1)))
865 return -ERESTARTSYS;
866peasycap->dnbydt = sdr.quotient; 1030peasycap->dnbydt = sdr.quotient;
867mutex_unlock(&(peasycap->mutex_timeval1));
868 1031
869JOT(8, "returning %li\n", (long int)szret); 1032JOM(8, "returning %li\n", (long int)szret);
1033mutex_unlock(&easycap_dongle[kd].mutex_audio);
870return szret; 1034return szret;
871} 1035}
872/*****************************************************************************/ 1036/*****************************************************************************/
@@ -881,27 +1045,31 @@ submit_audio_urbs(struct easycap *peasycap)
881struct data_urb *pdata_urb; 1045struct data_urb *pdata_urb;
882struct urb *purb; 1046struct urb *purb;
883struct list_head *plist_head; 1047struct list_head *plist_head;
884int j, isbad, m, rc; 1048int j, isbad, nospc, m, rc;
885int isbuf; 1049int isbuf;
886 1050
1051if (NULL == peasycap) {
1052 SAY("ERROR: peasycap is NULL\n");
1053 return -EFAULT;
1054}
887if ((struct list_head *)NULL == peasycap->purb_audio_head) { 1055if ((struct list_head *)NULL == peasycap->purb_audio_head) {
888 SAY("ERROR: peasycap->urb_audio_head uninitialized\n"); 1056 SAM("ERROR: peasycap->urb_audio_head uninitialized\n");
889 return -EFAULT; 1057 return -EFAULT;
890} 1058}
891if ((struct usb_device *)NULL == peasycap->pusb_device) { 1059if ((struct usb_device *)NULL == peasycap->pusb_device) {
892 SAY("ERROR: peasycap->pusb_device is NULL\n"); 1060 SAM("ERROR: peasycap->pusb_device is NULL\n");
893 return -EFAULT; 1061 return -EFAULT;
894} 1062}
895if (!peasycap->audio_isoc_streaming) { 1063if (!peasycap->audio_isoc_streaming) {
896 JOT(4, "initial submission of all audio urbs\n"); 1064 JOM(4, "initial submission of all audio urbs\n");
897 rc = usb_set_interface(peasycap->pusb_device, 1065 rc = usb_set_interface(peasycap->pusb_device,
898 peasycap->audio_interface, \ 1066 peasycap->audio_interface, \
899 peasycap->audio_altsetting_on); 1067 peasycap->audio_altsetting_on);
900 JOT(8, "usb_set_interface(.,%i,%i) returned %i\n", \ 1068 JOM(8, "usb_set_interface(.,%i,%i) returned %i\n", \
901 peasycap->audio_interface, \ 1069 peasycap->audio_interface, \
902 peasycap->audio_altsetting_on, rc); 1070 peasycap->audio_altsetting_on, rc);
903 1071
904 isbad = 0; m = 0; 1072 isbad = 0; nospc = 0; m = 0;
905 list_for_each(plist_head, (peasycap->purb_audio_head)) { 1073 list_for_each(plist_head, (peasycap->purb_audio_head)) {
906 pdata_urb = list_entry(plist_head, struct data_urb, list_head); 1074 pdata_urb = list_entry(plist_head, struct data_urb, list_head);
907 if (NULL != pdata_urb) { 1075 if (NULL != pdata_urb) {
@@ -938,39 +1106,49 @@ if (!peasycap->audio_isoc_streaming) {
938 rc = usb_submit_urb(purb, GFP_KERNEL); 1106 rc = usb_submit_urb(purb, GFP_KERNEL);
939 if (0 != rc) { 1107 if (0 != rc) {
940 isbad++; 1108 isbad++;
941 SAY("ERROR: usb_submit_urb() failed" \ 1109 SAM("ERROR: usb_submit_urb() failed" \
942 " for urb with rc:\n"); 1110 " for urb with rc:\n");
943 switch (rc) { 1111 switch (rc) {
944 case -ENOMEM: { 1112 case -ENOMEM: {
945 SAY("ENOMEM\n"); break; 1113 SAM("-ENOMEM\n");
1114 break;
946 } 1115 }
947 case -ENODEV: { 1116 case -ENODEV: {
948 SAY("ENODEV\n"); break; 1117 SAM("-ENODEV\n");
1118 break;
949 } 1119 }
950 case -ENXIO: { 1120 case -ENXIO: {
951 SAY("ENXIO\n"); break; 1121 SAM("-ENXIO\n");
1122 break;
952 } 1123 }
953 case -EINVAL: { 1124 case -EINVAL: {
954 SAY("EINVAL\n"); break; 1125 SAM("-EINVAL\n");
1126 break;
955 } 1127 }
956 case -EAGAIN: { 1128 case -EAGAIN: {
957 SAY("EAGAIN\n"); break; 1129 SAM("-EAGAIN\n");
1130 break;
958 } 1131 }
959 case -EFBIG: { 1132 case -EFBIG: {
960 SAY("EFBIG\n"); break; 1133 SAM("-EFBIG\n");
1134 break;
961 } 1135 }
962 case -EPIPE: { 1136 case -EPIPE: {
963 SAY("EPIPE\n"); break; 1137 SAM("-EPIPE\n");
1138 break;
964 } 1139 }
965 case -EMSGSIZE: { 1140 case -EMSGSIZE: {
966 SAY("EMSGSIZE\n"); break; 1141 SAM("-EMSGSIZE\n");
1142 break;
967 } 1143 }
968 case -ENOSPC: { 1144 case -ENOSPC: {
969 SAY("ENOSPC\n"); break; 1145 nospc++;
1146 break;
970 } 1147 }
971 default: { 1148 default: {
972 SAY("unknown error code %i\n",\ 1149 SAM("unknown error code %i\n",\
973 rc); break; 1150 rc);
1151 break;
974 } 1152 }
975 } 1153 }
976 } else { 1154 } else {
@@ -983,8 +1161,13 @@ if (!peasycap->audio_isoc_streaming) {
983 isbad++; 1161 isbad++;
984 } 1162 }
985 } 1163 }
1164 if (nospc) {
1165 SAM("-ENOSPC=usb_submit_urb() for %i urbs\n", nospc);
1166 SAM("..... possibly inadequate USB bandwidth\n");
1167 peasycap->audio_eof = 1;
1168 }
986 if (isbad) { 1169 if (isbad) {
987 JOT(4, "attempting cleanup instead of submitting\n"); 1170 JOM(4, "attempting cleanup instead of submitting\n");
988 list_for_each(plist_head, (peasycap->purb_audio_head)) { 1171 list_for_each(plist_head, (peasycap->purb_audio_head)) {
989 pdata_urb = list_entry(plist_head, struct data_urb, \ 1172 pdata_urb = list_entry(plist_head, struct data_urb, \
990 list_head); 1173 list_head);
@@ -997,10 +1180,10 @@ if (!peasycap->audio_isoc_streaming) {
997 peasycap->audio_isoc_streaming = 0; 1180 peasycap->audio_isoc_streaming = 0;
998 } else { 1181 } else {
999 peasycap->audio_isoc_streaming = 1; 1182 peasycap->audio_isoc_streaming = 1;
1000 JOT(4, "submitted %i audio urbs\n", m); 1183 JOM(4, "submitted %i audio urbs\n", m);
1001 } 1184 }
1002} else 1185} else
1003 JOT(4, "already streaming audio urbs\n"); 1186 JOM(4, "already streaming audio urbs\n");
1004 1187
1005return 0; 1188return 0;
1006} 1189}
@@ -1017,10 +1200,14 @@ int m;
1017struct list_head *plist_head; 1200struct list_head *plist_head;
1018struct data_urb *pdata_urb; 1201struct data_urb *pdata_urb;
1019 1202
1203if (NULL == peasycap) {
1204 SAY("ERROR: peasycap is NULL\n");
1205 return -EFAULT;
1206}
1020if (peasycap->audio_isoc_streaming) { 1207if (peasycap->audio_isoc_streaming) {
1021 if ((struct list_head *)NULL != peasycap->purb_audio_head) { 1208 if ((struct list_head *)NULL != peasycap->purb_audio_head) {
1022 peasycap->audio_isoc_streaming = 0; 1209 peasycap->audio_isoc_streaming = 0;
1023 JOT(4, "killing audio urbs\n"); 1210 JOM(4, "killing audio urbs\n");
1024 m = 0; 1211 m = 0;
1025 list_for_each(plist_head, (peasycap->purb_audio_head)) { 1212 list_for_each(plist_head, (peasycap->purb_audio_head)) {
1026 pdata_urb = list_entry(plist_head, struct data_urb, 1213 pdata_urb = list_entry(plist_head, struct data_urb,
@@ -1032,13 +1219,13 @@ if (peasycap->audio_isoc_streaming) {
1032 } 1219 }
1033 } 1220 }
1034 } 1221 }
1035 JOT(4, "%i audio urbs killed\n", m); 1222 JOM(4, "%i audio urbs killed\n", m);
1036 } else { 1223 } else {
1037 SAY("ERROR: peasycap->purb_audio_head is NULL\n"); 1224 SAM("ERROR: peasycap->purb_audio_head is NULL\n");
1038 return -EFAULT; 1225 return -EFAULT;
1039 } 1226 }
1040} else { 1227} else {
1041 JOT(8, "%i=audio_isoc_streaming, no audio urbs killed\n", \ 1228 JOM(8, "%i=audio_isoc_streaming, no audio urbs killed\n", \
1042 peasycap->audio_isoc_streaming); 1229 peasycap->audio_isoc_streaming);
1043} 1230}
1044return 0; 1231return 0;
diff --git a/drivers/staging/easycap/easycap_testcard.c b/drivers/staging/easycap/easycap_testcard.c
index 3c2ce28fab95..e27dfe9a9ba3 100644
--- a/drivers/staging/easycap/easycap_testcard.c
+++ b/drivers/staging/easycap/easycap_testcard.c
@@ -29,37 +29,69 @@
29#include "easycap_debug.h" 29#include "easycap_debug.h"
30 30
31/*****************************************************************************/ 31/*****************************************************************************/
32#define TESTCARD_BYTESPERLINE (2 * 1440) 32#define TESTCARD_BYTESPERLINE (2 * 720)
33void 33void
34easycap_testcard(struct easycap *peasycap, int field_fill) 34easycap_testcard(struct easycap *peasycap, int field)
35{ 35{
36int total; 36int total;
37int y, u, v, r, g, b; 37int y, u, v, r, g, b;
38unsigned char uyvy[4]; 38unsigned char uyvy[4];
39 39int i1, line, k, m, n, more, much, barwidth, barheight;
40int i1, line, k, m, n, more, much, barwidth;
41unsigned char bfbar[TESTCARD_BYTESPERLINE / 8], *p1, *p2; 40unsigned char bfbar[TESTCARD_BYTESPERLINE / 8], *p1, *p2;
42struct data_buffer *pfield_buffer; 41struct data_buffer *pfield_buffer;
43 42
44JOT(8, "%i=field_fill\n", field_fill); 43if (NULL == peasycap) {
45 44 SAY("ERROR: peasycap is NULL\n");
46if ((TESTCARD_BYTESPERLINE / 2) < peasycap->width) { 45 return;
47 SAY("ERROR: image is too wide\n"); 46}
47JOM(8, "%i=field\n", field);
48switch (peasycap->width) {
49case 720:
50case 360: {
51 barwidth = (2 * 720) / 8;
52 break;
53}
54case 704:
55case 352: {
56 barwidth = (2 * 704) / 8;
57 break;
58}
59case 640:
60case 320: {
61 barwidth = (2 * 640) / 8;
62 break;
63}
64default: {
65 SAM("ERROR: cannot set barwidth\n");
48 return; 66 return;
49} 67}
50if (peasycap->width % 16) { 68}
51 SAY("ERROR: indivisible image width\n"); 69if (TESTCARD_BYTESPERLINE < barwidth) {
70 SAM("ERROR: barwidth is too large\n");
52 return; 71 return;
53} 72}
54 73switch (peasycap->height) {
74case 576:
75case 288: {
76 barheight = 576;
77 break;
78}
79case 480:
80case 240: {
81 barheight = 480;
82 break;
83}
84default: {
85 SAM("ERROR: cannot set barheight\n");
86 return;
87}
88}
55total = 0; 89total = 0;
56barwidth = (2 * peasycap->width) / 8; 90k = field;
57
58k = field_fill;
59m = 0; 91m = 0;
60n = 0; 92n = 0;
61 93
62for (line = 0; line < (peasycap->height / 2); line++) { 94for (line = 0; line < (barheight / 2); line++) {
63 for (i1 = 0; i1 < 8; i1++) { 95 for (i1 = 0; i1 < 8; i1++) {
64 r = (i1 * 256)/8; 96 r = (i1 * 256)/8;
65 g = (i1 * 256)/8; 97 g = (i1 * 256)/8;
@@ -88,15 +120,15 @@ for (line = 0; line < (peasycap->height / 2); line++) {
88 120
89 while (more) { 121 while (more) {
90 if ((FIELD_BUFFER_SIZE/PAGE_SIZE) <= m) { 122 if ((FIELD_BUFFER_SIZE/PAGE_SIZE) <= m) {
91 SAY("ERROR: bad m reached\n"); 123 SAM("ERROR: bad m reached\n");
92 return; 124 return;
93 } 125 }
94 if (PAGE_SIZE < n) { 126 if (PAGE_SIZE < n) {
95 SAY("ERROR: bad n reached\n"); return; 127 SAM("ERROR: bad n reached\n"); return;
96 } 128 }
97 129
98 if (0 > more) { 130 if (0 > more) {
99 SAY("ERROR: internal fault\n"); 131 SAM("ERROR: internal fault\n");
100 return; 132 return;
101 } 133 }
102 134
@@ -117,10 +149,6 @@ for (line = 0; line < (peasycap->height / 2); line++) {
117 } 149 }
118 } 150 }
119} 151}
120
121JOT(8, "%i=total\n", total);
122if (total != peasycap->width * peasycap->height)
123 SAY("ERROR: wrong number of bytes written: %i\n", total);
124return; 152return;
125} 153}
126/*****************************************************************************/ 154/*****************************************************************************/
@@ -157,35 +185,35 @@ for (i1 = 0; i1 <= last; i1++)
157 printf("%6i, ", i2); printf("%6i\n};\n", i2); 185 printf("%6i, ", i2); printf("%6i\n};\n", i2);
158 } 186 }
159 } 187 }
160return(0); 188return 0;
161} 189}
162-----------------------------------------------------------------------------*/ 190-----------------------------------------------------------------------------*/
163int tones[2048] = { 191int tones[2048] = {
164 0, 0, 502, 502, 1004, 1004, 1505, 1505, 2005, 2005, 1920, 0, 502, 502, 1004, 1004, 1505, 1505, 2005, 2005,
165 2503, 2503, 2998, 2998, 3491, 3491, 3980, 3980, 4466, 4466, 1932503, 2503, 2998, 2998, 3491, 3491, 3980, 3980, 4466, 4466,
166 4948, 4948, 5424, 5424, 5896, 5896, 6362, 6362, 6822, 6822, 1944948, 4948, 5424, 5424, 5896, 5896, 6362, 6362, 6822, 6822,
167 7276, 7276, 7723, 7723, 8162, 8162, 8594, 8594, 9018, 9018, 1957276, 7276, 7723, 7723, 8162, 8162, 8594, 8594, 9018, 9018,
168 9434, 9434, 9840, 9840, 10237, 10237, 10625, 10625, 11002, 11002, 1969434, 9434, 9840, 9840, 10237, 10237, 10625, 10625, 11002, 11002,
169 11370, 11370, 11726, 11726, 12072, 12072, 12406, 12406, 12728, 12728, 19711370, 11370, 11726, 11726, 12072, 12072, 12406, 12406, 12728, 12728,
170 13038, 13038, 13337, 13337, 13622, 13622, 13895, 13895, 14155, 14155, 19813038, 13038, 13337, 13337, 13622, 13622, 13895, 13895, 14155, 14155,
171 14401, 14401, 14634, 14634, 14853, 14853, 15058, 15058, 15249, 15249, 19914401, 14401, 14634, 14634, 14853, 14853, 15058, 15058, 15249, 15249,
172 15426, 15426, 15588, 15588, 15735, 15735, 15868, 15868, 15985, 15985, 20015426, 15426, 15588, 15588, 15735, 15735, 15868, 15868, 15985, 15985,
173 16088, 16088, 16175, 16175, 16248, 16248, 16305, 16305, 16346, 16346, 20116088, 16088, 16175, 16175, 16248, 16248, 16305, 16305, 16346, 16346,
174 16372, 16372, 16383, 16383, 16379, 16379, 16359, 16359, 16323, 16323, 20216372, 16372, 16383, 16383, 16379, 16379, 16359, 16359, 16323, 16323,
175 16272, 16272, 16206, 16206, 16125, 16125, 16028, 16028, 15917, 15917, 20316272, 16272, 16206, 16206, 16125, 16125, 16028, 16028, 15917, 15917,
176 15790, 15790, 15649, 15649, 15492, 15492, 15322, 15322, 15136, 15136, 20415790, 15790, 15649, 15649, 15492, 15492, 15322, 15322, 15136, 15136,
177 14937, 14937, 14723, 14723, 14496, 14496, 14255, 14255, 14001, 14001, 20514937, 14937, 14723, 14723, 14496, 14496, 14255, 14255, 14001, 14001,
178 13733, 13733, 13452, 13452, 13159, 13159, 12854, 12854, 12536, 12536, 20613733, 13733, 13452, 13452, 13159, 13159, 12854, 12854, 12536, 12536,
179 12207, 12207, 11866, 11866, 11513, 11513, 11150, 11150, 10777, 10777, 20712207, 12207, 11866, 11866, 11513, 11513, 11150, 11150, 10777, 10777,
180 10393, 10393, 10000, 10000, 9597, 9597, 9185, 9185, 8765, 8765, 20810393, 10393, 10000, 10000, 9597, 9597, 9185, 9185, 8765, 8765,
181 8336, 8336, 7900, 7900, 7456, 7456, 7005, 7005, 6547, 6547, 2098336, 8336, 7900, 7900, 7456, 7456, 7005, 7005, 6547, 6547,
182 6083, 6083, 5614, 5614, 5139, 5139, 4659, 4659, 4175, 4175, 2106083, 6083, 5614, 5614, 5139, 5139, 4659, 4659, 4175, 4175,
183 3687, 3687, 3196, 3196, 2701, 2701, 2204, 2204, 1705, 1705, 2113687, 3687, 3196, 3196, 2701, 2701, 2204, 2204, 1705, 1705,
184 1205, 1205, 703, 703, 201, 201, -301, -301, -803, -803, 2121205, 1205, 703, 703, 201, 201, -301, -301, -803, -803,
185 -1305, -1305, -1805, -1805, -2304, -2304, -2801, -2801, -3294, -3294, 213-1305, -1305, -1805, -1805, -2304, -2304, -2801, -2801, -3294, -3294,
186 -3785, -3785, -4272, -4272, -4756, -4756, -5234, -5234, -5708, -5708, 214-3785, -3785, -4272, -4272, -4756, -4756, -5234, -5234, -5708, -5708,
187 -6176, -6176, -6639, -6639, -7095, -7095, -7545, -7545, -7988, -7988, 215-6176, -6176, -6639, -6639, -7095, -7095, -7545, -7545, -7988, -7988,
188 -8423, -8423, -8850, -8850, -9268, -9268, -9679, -9679, -10079, -10079, 216-8423, -8423, -8850, -8850, -9268, -9268, -9679, -9679, -10079, -10079,
189-10471, -10471, -10853, -10853, -11224, -11224, -11585, -11585, -11935, -11935, 217-10471, -10471, -10853, -10853, -11224, -11224, -11585, -11585, -11935, -11935,
190-12273, -12273, -12600, -12600, -12916, -12916, -13219, -13219, -13510, -13510, 218-12273, -12273, -12600, -12600, -12916, -12916, -13219, -13219, -13510, -13510,
191-13788, -13788, -14053, -14053, -14304, -14304, -14543, -14543, -14767, -14767, 219-13788, -13788, -14053, -14053, -14304, -14304, -14543, -14543, -14767, -14767,
@@ -198,35 +226,35 @@ int tones[2048] = {
198-14353, -14353, -14104, -14104, -13842, -13842, -13566, -13566, -13278, -13278, 226-14353, -14353, -14104, -14104, -13842, -13842, -13566, -13566, -13278, -13278,
199-12977, -12977, -12665, -12665, -12340, -12340, -12003, -12003, -11656, -11656, 227-12977, -12977, -12665, -12665, -12340, -12340, -12003, -12003, -11656, -11656,
200-11297, -11297, -10928, -10928, -10548, -10548, -10159, -10159, -9759, -9759, 228-11297, -11297, -10928, -10928, -10548, -10548, -10159, -10159, -9759, -9759,
201 -9351, -9351, -8934, -8934, -8509, -8509, -8075, -8075, -7634, -7634, 229-9351, -9351, -8934, -8934, -8509, -8509, -8075, -8075, -7634, -7634,
202 -7186, -7186, -6731, -6731, -6269, -6269, -5802, -5802, -5329, -5329, 230-7186, -7186, -6731, -6731, -6269, -6269, -5802, -5802, -5329, -5329,
203 -4852, -4852, -4369, -4369, -3883, -3883, -3393, -3393, -2900, -2900, 231-4852, -4852, -4369, -4369, -3883, -3883, -3393, -3393, -2900, -2900,
204 -2404, -2404, -1905, -1905, -1405, -1405, -904, -904, -402, -402, 232-2404, -2404, -1905, -1905, -1405, -1405, -904, -904, -402, -402,
205 100, 100, 603, 603, 1105, 1105, 1605, 1605, 2105, 2105, 233100, 100, 603, 603, 1105, 1105, 1605, 1605, 2105, 2105,
206 2602, 2602, 3097, 3097, 3589, 3589, 4078, 4078, 4563, 4563, 2342602, 2602, 3097, 3097, 3589, 3589, 4078, 4078, 4563, 4563,
207 5043, 5043, 5519, 5519, 5990, 5990, 6455, 6455, 6914, 6914, 2355043, 5043, 5519, 5519, 5990, 5990, 6455, 6455, 6914, 6914,
208 7366, 7366, 7811, 7811, 8249, 8249, 8680, 8680, 9102, 9102, 2367366, 7366, 7811, 7811, 8249, 8249, 8680, 8680, 9102, 9102,
209 9516, 9516, 9920, 9920, 10315, 10315, 10701, 10701, 11077, 11077, 2379516, 9516, 9920, 9920, 10315, 10315, 10701, 10701, 11077, 11077,
210 11442, 11442, 11796, 11796, 12139, 12139, 12471, 12471, 12791, 12791, 23811442, 11442, 11796, 11796, 12139, 12139, 12471, 12471, 12791, 12791,
211 13099, 13099, 13395, 13395, 13678, 13678, 13948, 13948, 14205, 14205, 23913099, 13099, 13395, 13395, 13678, 13678, 13948, 13948, 14205, 14205,
212 14449, 14449, 14679, 14679, 14895, 14895, 15098, 15098, 15286, 15286, 24014449, 14449, 14679, 14679, 14895, 14895, 15098, 15098, 15286, 15286,
213 15459, 15459, 15618, 15618, 15763, 15763, 15892, 15892, 16007, 16007, 24115459, 15459, 15618, 15618, 15763, 15763, 15892, 15892, 16007, 16007,
214 16107, 16107, 16191, 16191, 16260, 16260, 16314, 16314, 16353, 16353, 24216107, 16107, 16191, 16191, 16260, 16260, 16314, 16314, 16353, 16353,
215 16376, 16376, 16384, 16384, 16376, 16376, 16353, 16353, 16314, 16314, 24316376, 16376, 16384, 16384, 16376, 16376, 16353, 16353, 16314, 16314,
216 16260, 16260, 16191, 16191, 16107, 16107, 16007, 16007, 15892, 15892, 24416260, 16260, 16191, 16191, 16107, 16107, 16007, 16007, 15892, 15892,
217 15763, 15763, 15618, 15618, 15459, 15459, 15286, 15286, 15098, 15098, 24515763, 15763, 15618, 15618, 15459, 15459, 15286, 15286, 15098, 15098,
218 14895, 14895, 14679, 14679, 14449, 14449, 14205, 14205, 13948, 13948, 24614895, 14895, 14679, 14679, 14449, 14449, 14205, 14205, 13948, 13948,
219 13678, 13678, 13395, 13395, 13099, 13099, 12791, 12791, 12471, 12471, 24713678, 13678, 13395, 13395, 13099, 13099, 12791, 12791, 12471, 12471,
220 12139, 12139, 11796, 11796, 11442, 11442, 11077, 11077, 10701, 10701, 24812139, 12139, 11796, 11796, 11442, 11442, 11077, 11077, 10701, 10701,
221 10315, 10315, 9920, 9920, 9516, 9516, 9102, 9102, 8680, 8680, 24910315, 10315, 9920, 9920, 9516, 9516, 9102, 9102, 8680, 8680,
222 8249, 8249, 7811, 7811, 7366, 7366, 6914, 6914, 6455, 6455, 2508249, 8249, 7811, 7811, 7366, 7366, 6914, 6914, 6455, 6455,
223 5990, 5990, 5519, 5519, 5043, 5043, 4563, 4563, 4078, 4078, 2515990, 5990, 5519, 5519, 5043, 5043, 4563, 4563, 4078, 4078,
224 3589, 3589, 3097, 3097, 2602, 2602, 2105, 2105, 1605, 1605, 2523589, 3589, 3097, 3097, 2602, 2602, 2105, 2105, 1605, 1605,
225 1105, 1105, 603, 603, 100, 100, -402, -402, -904, -904, 2531105, 1105, 603, 603, 100, 100, -402, -402, -904, -904,
226 -1405, -1405, -1905, -1905, -2404, -2404, -2900, -2900, -3393, -3393, 254-1405, -1405, -1905, -1905, -2404, -2404, -2900, -2900, -3393, -3393,
227 -3883, -3883, -4369, -4369, -4852, -4852, -5329, -5329, -5802, -5802, 255-3883, -3883, -4369, -4369, -4852, -4852, -5329, -5329, -5802, -5802,
228 -6269, -6269, -6731, -6731, -7186, -7186, -7634, -7634, -8075, -8075, 256-6269, -6269, -6731, -6731, -7186, -7186, -7634, -7634, -8075, -8075,
229 -8509, -8509, -8934, -8934, -9351, -9351, -9759, -9759, -10159, -10159, 257-8509, -8509, -8934, -8934, -9351, -9351, -9759, -9759, -10159, -10159,
230-10548, -10548, -10928, -10928, -11297, -11297, -11656, -11656, -12003, -12003, 258-10548, -10548, -10928, -10928, -11297, -11297, -11656, -11656, -12003, -12003,
231-12340, -12340, -12665, -12665, -12977, -12977, -13278, -13278, -13566, -13566, 259-12340, -12340, -12665, -12665, -12977, -12977, -13278, -13278, -13566, -13566,
232-13842, -13842, -14104, -14104, -14353, -14353, -14589, -14589, -14810, -14810, 260-13842, -13842, -14104, -14104, -14353, -14353, -14589, -14589, -14810, -14810,
@@ -239,35 +267,35 @@ int tones[2048] = {
239-14304, -14304, -14053, -14053, -13788, -13788, -13510, -13510, -13219, -13219, 267-14304, -14304, -14053, -14053, -13788, -13788, -13510, -13510, -13219, -13219,
240-12916, -12916, -12600, -12600, -12273, -12273, -11935, -11935, -11585, -11585, 268-12916, -12916, -12600, -12600, -12273, -12273, -11935, -11935, -11585, -11585,
241-11224, -11224, -10853, -10853, -10471, -10471, -10079, -10079, -9679, -9679, 269-11224, -11224, -10853, -10853, -10471, -10471, -10079, -10079, -9679, -9679,
242 -9268, -9268, -8850, -8850, -8423, -8423, -7988, -7988, -7545, -7545, 270-9268, -9268, -8850, -8850, -8423, -8423, -7988, -7988, -7545, -7545,
243 -7095, -7095, -6639, -6639, -6176, -6176, -5708, -5708, -5234, -5234, 271-7095, -7095, -6639, -6639, -6176, -6176, -5708, -5708, -5234, -5234,
244 -4756, -4756, -4272, -4272, -3785, -3785, -3294, -3294, -2801, -2801, 272-4756, -4756, -4272, -4272, -3785, -3785, -3294, -3294, -2801, -2801,
245 -2304, -2304, -1805, -1805, -1305, -1305, -803, -803, -301, -301, 273-2304, -2304, -1805, -1805, -1305, -1305, -803, -803, -301, -301,
246 201, 201, 703, 703, 1205, 1205, 1705, 1705, 2204, 2204, 274201, 201, 703, 703, 1205, 1205, 1705, 1705, 2204, 2204,
247 2701, 2701, 3196, 3196, 3687, 3687, 4175, 4175, 4659, 4659, 2752701, 2701, 3196, 3196, 3687, 3687, 4175, 4175, 4659, 4659,
248 5139, 5139, 5614, 5614, 6083, 6083, 6547, 6547, 7005, 7005, 2765139, 5139, 5614, 5614, 6083, 6083, 6547, 6547, 7005, 7005,
249 7456, 7456, 7900, 7900, 8336, 8336, 8765, 8765, 9185, 9185, 2777456, 7456, 7900, 7900, 8336, 8336, 8765, 8765, 9185, 9185,
250 9597, 9597, 10000, 10000, 10393, 10393, 10777, 10777, 11150, 11150, 2789597, 9597, 10000, 10000, 10393, 10393, 10777, 10777, 11150, 11150,
251 11513, 11513, 11866, 11866, 12207, 12207, 12536, 12536, 12854, 12854, 27911513, 11513, 11866, 11866, 12207, 12207, 12536, 12536, 12854, 12854,
252 13159, 13159, 13452, 13452, 13733, 13733, 14001, 14001, 14255, 14255, 28013159, 13159, 13452, 13452, 13733, 13733, 14001, 14001, 14255, 14255,
253 14496, 14496, 14723, 14723, 14937, 14937, 15136, 15136, 15322, 15322, 28114496, 14496, 14723, 14723, 14937, 14937, 15136, 15136, 15322, 15322,
254 15492, 15492, 15649, 15649, 15790, 15790, 15917, 15917, 16028, 16028, 28215492, 15492, 15649, 15649, 15790, 15790, 15917, 15917, 16028, 16028,
255 16125, 16125, 16206, 16206, 16272, 16272, 16323, 16323, 16359, 16359, 28316125, 16125, 16206, 16206, 16272, 16272, 16323, 16323, 16359, 16359,
256 16379, 16379, 16383, 16383, 16372, 16372, 16346, 16346, 16305, 16305, 28416379, 16379, 16383, 16383, 16372, 16372, 16346, 16346, 16305, 16305,
257 16248, 16248, 16175, 16175, 16088, 16088, 15985, 15985, 15868, 15868, 28516248, 16248, 16175, 16175, 16088, 16088, 15985, 15985, 15868, 15868,
258 15735, 15735, 15588, 15588, 15426, 15426, 15249, 15249, 15058, 15058, 28615735, 15735, 15588, 15588, 15426, 15426, 15249, 15249, 15058, 15058,
259 14853, 14853, 14634, 14634, 14401, 14401, 14155, 14155, 13895, 13895, 28714853, 14853, 14634, 14634, 14401, 14401, 14155, 14155, 13895, 13895,
260 13622, 13622, 13337, 13337, 13038, 13038, 12728, 12728, 12406, 12406, 28813622, 13622, 13337, 13337, 13038, 13038, 12728, 12728, 12406, 12406,
261 12072, 12072, 11726, 11726, 11370, 11370, 11002, 11002, 10625, 10625, 28912072, 12072, 11726, 11726, 11370, 11370, 11002, 11002, 10625, 10625,
262 10237, 10237, 9840, 9840, 9434, 9434, 9018, 9018, 8594, 8594, 29010237, 10237, 9840, 9840, 9434, 9434, 9018, 9018, 8594, 8594,
263 8162, 8162, 7723, 7723, 7276, 7276, 6822, 6822, 6362, 6362, 2918162, 8162, 7723, 7723, 7276, 7276, 6822, 6822, 6362, 6362,
264 5896, 5896, 5424, 5424, 4948, 4948, 4466, 4466, 3980, 3980, 2925896, 5896, 5424, 5424, 4948, 4948, 4466, 4466, 3980, 3980,
265 3491, 3491, 2998, 2998, 2503, 2503, 2005, 2005, 1505, 1505, 2933491, 3491, 2998, 2998, 2503, 2503, 2005, 2005, 1505, 1505,
266 1004, 1004, 502, 502, 0, 0, -502, -502, -1004, -1004, 2941004, 1004, 502, 502, 0, 0, -502, -502, -1004, -1004,
267 -1505, -1505, -2005, -2005, -2503, -2503, -2998, -2998, -3491, -3491, 295-1505, -1505, -2005, -2005, -2503, -2503, -2998, -2998, -3491, -3491,
268 -3980, -3980, -4466, -4466, -4948, -4948, -5424, -5424, -5896, -5896, 296-3980, -3980, -4466, -4466, -4948, -4948, -5424, -5424, -5896, -5896,
269 -6362, -6362, -6822, -6822, -7276, -7276, -7723, -7723, -8162, -8162, 297-6362, -6362, -6822, -6822, -7276, -7276, -7723, -7723, -8162, -8162,
270 -8594, -8594, -9018, -9018, -9434, -9434, -9840, -9840, -10237, -10237, 298-8594, -8594, -9018, -9018, -9434, -9434, -9840, -9840, -10237, -10237,
271-10625, -10625, -11002, -11002, -11370, -11370, -11726, -11726, -12072, -12072, 299-10625, -10625, -11002, -11002, -11370, -11370, -11726, -11726, -12072, -12072,
272-12406, -12406, -12728, -12728, -13038, -13038, -13337, -13337, -13622, -13622, 300-12406, -12406, -12728, -12728, -13038, -13038, -13337, -13337, -13622, -13622,
273-13895, -13895, -14155, -14155, -14401, -14401, -14634, -14634, -14853, -14853, 301-13895, -13895, -14155, -14155, -14401, -14401, -14634, -14634, -14853, -14853,
@@ -280,35 +308,35 @@ int tones[2048] = {
280-14255, -14255, -14001, -14001, -13733, -13733, -13452, -13452, -13159, -13159, 308-14255, -14255, -14001, -14001, -13733, -13733, -13452, -13452, -13159, -13159,
281-12854, -12854, -12536, -12536, -12207, -12207, -11866, -11866, -11513, -11513, 309-12854, -12854, -12536, -12536, -12207, -12207, -11866, -11866, -11513, -11513,
282-11150, -11150, -10777, -10777, -10393, -10393, -10000, -10000, -9597, -9597, 310-11150, -11150, -10777, -10777, -10393, -10393, -10000, -10000, -9597, -9597,
283 -9185, -9185, -8765, -8765, -8336, -8336, -7900, -7900, -7456, -7456, 311-9185, -9185, -8765, -8765, -8336, -8336, -7900, -7900, -7456, -7456,
284 -7005, -7005, -6547, -6547, -6083, -6083, -5614, -5614, -5139, -5139, 312-7005, -7005, -6547, -6547, -6083, -6083, -5614, -5614, -5139, -5139,
285 -4659, -4659, -4175, -4175, -3687, -3687, -3196, -3196, -2701, -2701, 313-4659, -4659, -4175, -4175, -3687, -3687, -3196, -3196, -2701, -2701,
286 -2204, -2204, -1705, -1705, -1205, -1205, -703, -703, -201, -201, 314-2204, -2204, -1705, -1705, -1205, -1205, -703, -703, -201, -201,
287 301, 301, 803, 803, 1305, 1305, 1805, 1805, 2304, 2304, 315301, 301, 803, 803, 1305, 1305, 1805, 1805, 2304, 2304,
288 2801, 2801, 3294, 3294, 3785, 3785, 4272, 4272, 4756, 4756, 3162801, 2801, 3294, 3294, 3785, 3785, 4272, 4272, 4756, 4756,
289 5234, 5234, 5708, 5708, 6176, 6176, 6639, 6639, 7095, 7095, 3175234, 5234, 5708, 5708, 6176, 6176, 6639, 6639, 7095, 7095,
290 7545, 7545, 7988, 7988, 8423, 8423, 8850, 8850, 9268, 9268, 3187545, 7545, 7988, 7988, 8423, 8423, 8850, 8850, 9268, 9268,
291 9679, 9679, 10079, 10079, 10471, 10471, 10853, 10853, 11224, 11224, 3199679, 9679, 10079, 10079, 10471, 10471, 10853, 10853, 11224, 11224,
292 11585, 11585, 11935, 11935, 12273, 12273, 12600, 12600, 12916, 12916, 32011585, 11585, 11935, 11935, 12273, 12273, 12600, 12600, 12916, 12916,
293 13219, 13219, 13510, 13510, 13788, 13788, 14053, 14053, 14304, 14304, 32113219, 13219, 13510, 13510, 13788, 13788, 14053, 14053, 14304, 14304,
294 14543, 14543, 14767, 14767, 14978, 14978, 15175, 15175, 15357, 15357, 32214543, 14543, 14767, 14767, 14978, 14978, 15175, 15175, 15357, 15357,
295 15525, 15525, 15678, 15678, 15817, 15817, 15940, 15940, 16049, 16049, 32315525, 15525, 15678, 15678, 15817, 15817, 15940, 15940, 16049, 16049,
296 16142, 16142, 16221, 16221, 16284, 16284, 16331, 16331, 16364, 16364, 32416142, 16142, 16221, 16221, 16284, 16284, 16331, 16331, 16364, 16364,
297 16381, 16381, 16382, 16382, 16368, 16368, 16339, 16339, 16294, 16294, 32516381, 16381, 16382, 16382, 16368, 16368, 16339, 16339, 16294, 16294,
298 16234, 16234, 16159, 16159, 16069, 16069, 15963, 15963, 15842, 15842, 32616234, 16234, 16159, 16159, 16069, 16069, 15963, 15963, 15842, 15842,
299 15707, 15707, 15557, 15557, 15392, 15392, 15212, 15212, 15018, 15018, 32715707, 15707, 15557, 15557, 15392, 15392, 15212, 15212, 15018, 15018,
300 14810, 14810, 14589, 14589, 14353, 14353, 14104, 14104, 13842, 13842, 32814810, 14810, 14589, 14589, 14353, 14353, 14104, 14104, 13842, 13842,
301 13566, 13566, 13278, 13278, 12977, 12977, 12665, 12665, 12340, 12340, 32913566, 13566, 13278, 13278, 12977, 12977, 12665, 12665, 12340, 12340,
302 12003, 12003, 11656, 11656, 11297, 11297, 10928, 10928, 10548, 10548, 33012003, 12003, 11656, 11656, 11297, 11297, 10928, 10928, 10548, 10548,
303 10159, 10159, 9759, 9759, 9351, 9351, 8934, 8934, 8509, 8509, 33110159, 10159, 9759, 9759, 9351, 9351, 8934, 8934, 8509, 8509,
304 8075, 8075, 7634, 7634, 7186, 7186, 6731, 6731, 6269, 6269, 3328075, 8075, 7634, 7634, 7186, 7186, 6731, 6731, 6269, 6269,
305 5802, 5802, 5329, 5329, 4852, 4852, 4369, 4369, 3883, 3883, 3335802, 5802, 5329, 5329, 4852, 4852, 4369, 4369, 3883, 3883,
306 3393, 3393, 2900, 2900, 2404, 2404, 1905, 1905, 1405, 1405, 3343393, 3393, 2900, 2900, 2404, 2404, 1905, 1905, 1405, 1405,
307 904, 904, 402, 402, -100, -100, -603, -603, -1105, -1105, 335904, 904, 402, 402, -100, -100, -603, -603, -1105, -1105,
308 -1605, -1605, -2105, -2105, -2602, -2602, -3097, -3097, -3589, -3589, 336-1605, -1605, -2105, -2105, -2602, -2602, -3097, -3097, -3589, -3589,
309 -4078, -4078, -4563, -4563, -5043, -5043, -5519, -5519, -5990, -5990, 337-4078, -4078, -4563, -4563, -5043, -5043, -5519, -5519, -5990, -5990,
310 -6455, -6455, -6914, -6914, -7366, -7366, -7811, -7811, -8249, -8249, 338-6455, -6455, -6914, -6914, -7366, -7366, -7811, -7811, -8249, -8249,
311 -8680, -8680, -9102, -9102, -9516, -9516, -9920, -9920, -10315, -10315, 339-8680, -8680, -9102, -9102, -9516, -9516, -9920, -9920, -10315, -10315,
312-10701, -10701, -11077, -11077, -11442, -11442, -11796, -11796, -12139, -12139, 340-10701, -10701, -11077, -11077, -11442, -11442, -11796, -11796, -12139, -12139,
313-12471, -12471, -12791, -12791, -13099, -13099, -13395, -13395, -13678, -13678, 341-12471, -12471, -12791, -12791, -13099, -13099, -13395, -13395, -13678, -13678,
314-13948, -13948, -14205, -14205, -14449, -14449, -14679, -14679, -14895, -14895, 342-13948, -13948, -14205, -14205, -14449, -14449, -14679, -14679, -14895, -14895,
@@ -321,35 +349,35 @@ int tones[2048] = {
321-14205, -14205, -13948, -13948, -13678, -13678, -13395, -13395, -13099, -13099, 349-14205, -14205, -13948, -13948, -13678, -13678, -13395, -13395, -13099, -13099,
322-12791, -12791, -12471, -12471, -12139, -12139, -11796, -11796, -11442, -11442, 350-12791, -12791, -12471, -12471, -12139, -12139, -11796, -11796, -11442, -11442,
323-11077, -11077, -10701, -10701, -10315, -10315, -9920, -9920, -9516, -9516, 351-11077, -11077, -10701, -10701, -10315, -10315, -9920, -9920, -9516, -9516,
324 -9102, -9102, -8680, -8680, -8249, -8249, -7811, -7811, -7366, -7366, 352-9102, -9102, -8680, -8680, -8249, -8249, -7811, -7811, -7366, -7366,
325 -6914, -6914, -6455, -6455, -5990, -5990, -5519, -5519, -5043, -5043, 353-6914, -6914, -6455, -6455, -5990, -5990, -5519, -5519, -5043, -5043,
326 -4563, -4563, -4078, -4078, -3589, -3589, -3097, -3097, -2602, -2602, 354-4563, -4563, -4078, -4078, -3589, -3589, -3097, -3097, -2602, -2602,
327 -2105, -2105, -1605, -1605, -1105, -1105, -603, -603, -100, -100, 355-2105, -2105, -1605, -1605, -1105, -1105, -603, -603, -100, -100,
328 402, 402, 904, 904, 1405, 1405, 1905, 1905, 2404, 2404, 356402, 402, 904, 904, 1405, 1405, 1905, 1905, 2404, 2404,
329 2900, 2900, 3393, 3393, 3883, 3883, 4369, 4369, 4852, 4852, 3572900, 2900, 3393, 3393, 3883, 3883, 4369, 4369, 4852, 4852,
330 5329, 5329, 5802, 5802, 6269, 6269, 6731, 6731, 7186, 7186, 3585329, 5329, 5802, 5802, 6269, 6269, 6731, 6731, 7186, 7186,
331 7634, 7634, 8075, 8075, 8509, 8509, 8934, 8934, 9351, 9351, 3597634, 7634, 8075, 8075, 8509, 8509, 8934, 8934, 9351, 9351,
332 9759, 9759, 10159, 10159, 10548, 10548, 10928, 10928, 11297, 11297, 3609759, 9759, 10159, 10159, 10548, 10548, 10928, 10928, 11297, 11297,
333 11656, 11656, 12003, 12003, 12340, 12340, 12665, 12665, 12977, 12977, 36111656, 11656, 12003, 12003, 12340, 12340, 12665, 12665, 12977, 12977,
334 13278, 13278, 13566, 13566, 13842, 13842, 14104, 14104, 14353, 14353, 36213278, 13278, 13566, 13566, 13842, 13842, 14104, 14104, 14353, 14353,
335 14589, 14589, 14810, 14810, 15018, 15018, 15212, 15212, 15392, 15392, 36314589, 14589, 14810, 14810, 15018, 15018, 15212, 15212, 15392, 15392,
336 15557, 15557, 15707, 15707, 15842, 15842, 15963, 15963, 16069, 16069, 36415557, 15557, 15707, 15707, 15842, 15842, 15963, 15963, 16069, 16069,
337 16159, 16159, 16234, 16234, 16294, 16294, 16339, 16339, 16368, 16368, 36516159, 16159, 16234, 16234, 16294, 16294, 16339, 16339, 16368, 16368,
338 16382, 16382, 16381, 16381, 16364, 16364, 16331, 16331, 16284, 16284, 36616382, 16382, 16381, 16381, 16364, 16364, 16331, 16331, 16284, 16284,
339 16221, 16221, 16142, 16142, 16049, 16049, 15940, 15940, 15817, 15817, 36716221, 16221, 16142, 16142, 16049, 16049, 15940, 15940, 15817, 15817,
340 15678, 15678, 15525, 15525, 15357, 15357, 15175, 15175, 14978, 14978, 36815678, 15678, 15525, 15525, 15357, 15357, 15175, 15175, 14978, 14978,
341 14767, 14767, 14543, 14543, 14304, 14304, 14053, 14053, 13788, 13788, 36914767, 14767, 14543, 14543, 14304, 14304, 14053, 14053, 13788, 13788,
342 13510, 13510, 13219, 13219, 12916, 12916, 12600, 12600, 12273, 12273, 37013510, 13510, 13219, 13219, 12916, 12916, 12600, 12600, 12273, 12273,
343 11935, 11935, 11585, 11585, 11224, 11224, 10853, 10853, 10471, 10471, 37111935, 11935, 11585, 11585, 11224, 11224, 10853, 10853, 10471, 10471,
344 10079, 10079, 9679, 9679, 9268, 9268, 8850, 8850, 8423, 8423, 37210079, 10079, 9679, 9679, 9268, 9268, 8850, 8850, 8423, 8423,
345 7988, 7988, 7545, 7545, 7095, 7095, 6639, 6639, 6176, 6176, 3737988, 7988, 7545, 7545, 7095, 7095, 6639, 6639, 6176, 6176,
346 5708, 5708, 5234, 5234, 4756, 4756, 4272, 4272, 3785, 3785, 3745708, 5708, 5234, 5234, 4756, 4756, 4272, 4272, 3785, 3785,
347 3294, 3294, 2801, 2801, 2304, 2304, 1805, 1805, 1305, 1305, 3753294, 3294, 2801, 2801, 2304, 2304, 1805, 1805, 1305, 1305,
348 803, 803, 301, 301, -201, -201, -703, -703, -1205, -1205, 376803, 803, 301, 301, -201, -201, -703, -703, -1205, -1205,
349 -1705, -1705, -2204, -2204, -2701, -2701, -3196, -3196, -3687, -3687, 377-1705, -1705, -2204, -2204, -2701, -2701, -3196, -3196, -3687, -3687,
350 -4175, -4175, -4659, -4659, -5139, -5139, -5614, -5614, -6083, -6083, 378-4175, -4175, -4659, -4659, -5139, -5139, -5614, -5614, -6083, -6083,
351 -6547, -6547, -7005, -7005, -7456, -7456, -7900, -7900, -8336, -8336, 379-6547, -6547, -7005, -7005, -7456, -7456, -7900, -7900, -8336, -8336,
352 -8765, -8765, -9185, -9185, -9597, -9597, -10000, -10000, -10393, -10393, 380-8765, -8765, -9185, -9185, -9597, -9597, -10000, -10000, -10393, -10393,
353-10777, -10777, -11150, -11150, -11513, -11513, -11866, -11866, -12207, -12207, 381-10777, -10777, -11150, -11150, -11513, -11513, -11866, -11866, -12207, -12207,
354-12536, -12536, -12854, -12854, -13159, -13159, -13452, -13452, -13733, -13733, 382-12536, -12536, -12854, -12854, -13159, -13159, -13452, -13452, -13733, -13733,
355-14001, -14001, -14255, -14255, -14496, -14496, -14723, -14723, -14937, -14937, 383-14001, -14001, -14255, -14255, -14496, -14496, -14723, -14723, -14937, -14937,
@@ -362,10 +390,10 @@ int tones[2048] = {
362-14155, -14155, -13895, -13895, -13622, -13622, -13337, -13337, -13038, -13038, 390-14155, -14155, -13895, -13895, -13622, -13622, -13337, -13337, -13038, -13038,
363-12728, -12728, -12406, -12406, -12072, -12072, -11726, -11726, -11370, -11370, 391-12728, -12728, -12406, -12406, -12072, -12072, -11726, -11726, -11370, -11370,
364-11002, -11002, -10625, -10625, -10237, -10237, -9840, -9840, -9434, -9434, 392-11002, -11002, -10625, -10625, -10237, -10237, -9840, -9840, -9434, -9434,
365 -9018, -9018, -8594, -8594, -8162, -8162, -7723, -7723, -7276, -7276, 393-9018, -9018, -8594, -8594, -8162, -8162, -7723, -7723, -7276, -7276,
366 -6822, -6822, -6362, -6362, -5896, -5896, -5424, -5424, -4948, -4948, 394-6822, -6822, -6362, -6362, -5896, -5896, -5424, -5424, -4948, -4948,
367 -4466, -4466, -3980, -3980, -3491, -3491, -2998, -2998, -2503, -2503, 395-4466, -4466, -3980, -3980, -3491, -3491, -2998, -2998, -2503, -2503,
368 -2005, -2005, -1505, -1505, -1004, -1004, -502, -502 396-2005, -2005, -1505, -1505, -1004, -1004, -502, -502
369}; 397};
370/*****************************************************************************/ 398/*****************************************************************************/
371void 399void
@@ -375,10 +403,12 @@ int i1;
375unsigned char *p2; 403unsigned char *p2;
376struct data_buffer *paudio_buffer; 404struct data_buffer *paudio_buffer;
377 405
378JOT(8, "%i=audio_fill\n", audio_fill); 406if (NULL == peasycap) {
379 407 SAY("ERROR: peasycap is NULL\n");
408 return;
409}
410JOM(8, "%i=audio_fill\n", audio_fill);
380paudio_buffer = &peasycap->audio_buffer[audio_fill]; 411paudio_buffer = &peasycap->audio_buffer[audio_fill];
381
382p2 = (unsigned char *)(paudio_buffer->pgo); 412p2 = (unsigned char *)(paudio_buffer->pgo);
383for (i1 = 0; i1 < PAGE_SIZE; i1 += 4, p2 += 4) { 413for (i1 = 0; i1 < PAGE_SIZE; i1 += 4, p2 += 4) {
384 *p2 = (unsigned char) (0x00FF & tones[i1/2]); 414 *p2 = (unsigned char) (0x00FF & tones[i1/2]);
diff --git a/drivers/staging/et131x/et131x_initpci.c b/drivers/staging/et131x/et131x_initpci.c
index 10bcb45d73a3..f62ba7a68f34 100644
--- a/drivers/staging/et131x/et131x_initpci.c
+++ b/drivers/staging/et131x/et131x_initpci.c
@@ -783,7 +783,7 @@ static void __devexit et131x_pci_remove(struct pci_dev *pdev)
783 /* Retrieve the net_device pointer from the pci_dev struct, as well 783 /* Retrieve the net_device pointer from the pci_dev struct, as well
784 * as the private adapter struct 784 * as the private adapter struct
785 */ 785 */
786 netdev = (struct net_device *) pci_get_drvdata(pdev); 786 netdev = pci_get_drvdata(pdev);
787 adapter = netdev_priv(netdev); 787 adapter = netdev_priv(netdev);
788 788
789 /* Perform device cleanup */ 789 /* Perform device cleanup */
diff --git a/drivers/staging/frontier/alphatrack.c b/drivers/staging/frontier/alphatrack.c
index ef7fbf8b069a..2babb034a254 100644
--- a/drivers/staging/frontier/alphatrack.c
+++ b/drivers/staging/frontier/alphatrack.c
@@ -89,7 +89,7 @@ static int debug = ALPHATRACK_DEBUG;
89 89
90/* Use our own dbg macro */ 90/* Use our own dbg macro */
91#define dbg_info(dev, format, arg...) do \ 91#define dbg_info(dev, format, arg...) do \
92 { if (debug) dev_info(dev , format , ## arg); } while (0) 92 { if (debug) dev_info(dev , format , ## arg); } while (0)
93 93
94#define alphatrack_ocmd_info(dev, cmd, format, arg...) 94#define alphatrack_ocmd_info(dev, cmd, format, arg...)
95 95
@@ -769,7 +769,7 @@ static int usb_alphatrack_probe(struct usb_interface *intf,
769 } 769 }
770 770
771 dev->write_buffer = 771 dev->write_buffer =
772 kmalloc(sizeof(struct alphatrack_ocmd) * true_size, GFP_KERNEL); 772 kmalloc(true_size * sizeof(struct alphatrack_ocmd), GFP_KERNEL);
773 773
774 if (!dev->write_buffer) { 774 if (!dev->write_buffer) {
775 dev_err(&intf->dev, "Couldn't allocate write_buffer\n"); 775 dev_err(&intf->dev, "Couldn't allocate write_buffer\n");
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c
index eed7e94308db..588afd5a5ddb 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c
+++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c
@@ -132,7 +132,7 @@ inline void ft1000_asic_write(struct net_device *dev, u16 offset, u16 value)
132//--------------------------------------------------------------------------- 132//---------------------------------------------------------------------------
133static inline u16 ft1000_read_fifo_len(struct net_device *dev) 133static inline u16 ft1000_read_fifo_len(struct net_device *dev)
134{ 134{
135 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 135 FT1000_INFO *info = netdev_priv(dev);
136 136
137 if (info->AsicID == ELECTRABUZZ_ID) { 137 if (info->AsicID == ELECTRABUZZ_ID) {
138 return (ft1000_read_reg(dev, FT1000_REG_UFIFO_STAT) - 16); 138 return (ft1000_read_reg(dev, FT1000_REG_UFIFO_STAT) - 16);
@@ -155,7 +155,7 @@ static inline u16 ft1000_read_fifo_len(struct net_device *dev)
155//--------------------------------------------------------------------------- 155//---------------------------------------------------------------------------
156u16 ft1000_read_dpram(struct net_device * dev, int offset) 156u16 ft1000_read_dpram(struct net_device * dev, int offset)
157{ 157{
158 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 158 FT1000_INFO *info = netdev_priv(dev);
159 unsigned long flags; 159 unsigned long flags;
160 u16 data; 160 u16 data;
161 161
@@ -184,7 +184,7 @@ u16 ft1000_read_dpram(struct net_device * dev, int offset)
184static inline void ft1000_write_dpram(struct net_device *dev, 184static inline void ft1000_write_dpram(struct net_device *dev,
185 int offset, u16 value) 185 int offset, u16 value)
186{ 186{
187 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 187 FT1000_INFO *info = netdev_priv(dev);
188 unsigned long flags; 188 unsigned long flags;
189 189
190 // Provide mutual exclusive access while reading ASIC registers. 190 // Provide mutual exclusive access while reading ASIC registers.
@@ -208,7 +208,7 @@ static inline void ft1000_write_dpram(struct net_device *dev,
208//--------------------------------------------------------------------------- 208//---------------------------------------------------------------------------
209u16 ft1000_read_dpram_mag_16(struct net_device *dev, int offset, int Index) 209u16 ft1000_read_dpram_mag_16(struct net_device *dev, int offset, int Index)
210{ 210{
211 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 211 FT1000_INFO *info = netdev_priv(dev);
212 unsigned long flags; 212 unsigned long flags;
213 u16 data; 213 u16 data;
214 214
@@ -242,7 +242,7 @@ u16 ft1000_read_dpram_mag_16(struct net_device *dev, int offset, int Index)
242static inline void ft1000_write_dpram_mag_16(struct net_device *dev, 242static inline void ft1000_write_dpram_mag_16(struct net_device *dev,
243 int offset, u16 value, int Index) 243 int offset, u16 value, int Index)
244{ 244{
245 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 245 FT1000_INFO *info = netdev_priv(dev);
246 unsigned long flags; 246 unsigned long flags;
247 247
248 // Provide mutual exclusive access while reading ASIC registers. 248 // Provide mutual exclusive access while reading ASIC registers.
@@ -270,7 +270,7 @@ static inline void ft1000_write_dpram_mag_16(struct net_device *dev,
270//--------------------------------------------------------------------------- 270//---------------------------------------------------------------------------
271u32 ft1000_read_dpram_mag_32(struct net_device *dev, int offset) 271u32 ft1000_read_dpram_mag_32(struct net_device *dev, int offset)
272{ 272{
273 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 273 FT1000_INFO *info = netdev_priv(dev);
274 unsigned long flags; 274 unsigned long flags;
275 u32 data; 275 u32 data;
276 276
@@ -298,7 +298,7 @@ u32 ft1000_read_dpram_mag_32(struct net_device *dev, int offset)
298//--------------------------------------------------------------------------- 298//---------------------------------------------------------------------------
299void ft1000_write_dpram_mag_32(struct net_device *dev, int offset, u32 value) 299void ft1000_write_dpram_mag_32(struct net_device *dev, int offset, u32 value)
300{ 300{
301 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 301 FT1000_INFO *info = netdev_priv(dev);
302 unsigned long flags; 302 unsigned long flags;
303 303
304 // Provide mutual exclusive access while reading ASIC registers. 304 // Provide mutual exclusive access while reading ASIC registers.
@@ -320,7 +320,7 @@ void ft1000_write_dpram_mag_32(struct net_device *dev, int offset, u32 value)
320//--------------------------------------------------------------------------- 320//---------------------------------------------------------------------------
321static void ft1000_enable_interrupts(struct net_device *dev) 321static void ft1000_enable_interrupts(struct net_device *dev)
322{ 322{
323 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 323 FT1000_INFO *info = netdev_priv(dev);
324 u16 tempword; 324 u16 tempword;
325 325
326 DEBUG(1, "ft1000_hw:ft1000_enable_interrupts()\n"); 326 DEBUG(1, "ft1000_hw:ft1000_enable_interrupts()\n");
@@ -345,7 +345,7 @@ static void ft1000_enable_interrupts(struct net_device *dev)
345//--------------------------------------------------------------------------- 345//---------------------------------------------------------------------------
346static void ft1000_disable_interrupts(struct net_device *dev) 346static void ft1000_disable_interrupts(struct net_device *dev)
347{ 347{
348 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 348 FT1000_INFO *info = netdev_priv(dev);
349 u16 tempword; 349 u16 tempword;
350 350
351 DEBUG(1, "ft1000_hw: ft1000_disable_interrupts()\n"); 351 DEBUG(1, "ft1000_hw: ft1000_disable_interrupts()\n");
@@ -370,7 +370,7 @@ static void ft1000_disable_interrupts(struct net_device *dev)
370//--------------------------------------------------------------------------- 370//---------------------------------------------------------------------------
371static void ft1000_reset_asic(struct net_device *dev) 371static void ft1000_reset_asic(struct net_device *dev)
372{ 372{
373 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 373 FT1000_INFO *info = netdev_priv(dev);
374 u16 tempword; 374 u16 tempword;
375 375
376 DEBUG(1, "ft1000_hw:ft1000_reset_asic called\n"); 376 DEBUG(1, "ft1000_hw:ft1000_reset_asic called\n");
@@ -414,7 +414,7 @@ static void ft1000_reset_asic(struct net_device *dev)
414//--------------------------------------------------------------------------- 414//---------------------------------------------------------------------------
415static int ft1000_reset_card(struct net_device *dev) 415static int ft1000_reset_card(struct net_device *dev)
416{ 416{
417 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 417 FT1000_INFO *info = netdev_priv(dev);
418 u16 tempword; 418 u16 tempword;
419 int i; 419 int i;
420 unsigned long flags; 420 unsigned long flags;
@@ -618,7 +618,7 @@ static void ft1000_hbchk(u_long data)
618 FT1000_INFO *info; 618 FT1000_INFO *info;
619 USHORT tempword; 619 USHORT tempword;
620 620
621 info = (FT1000_INFO *) netdev_priv(dev); 621 info = netdev_priv(dev);
622 622
623 if (info->CardReady == 1) { 623 if (info->CardReady == 1) {
624 // Perform dsp heartbeat check 624 // Perform dsp heartbeat check
@@ -831,7 +831,7 @@ static void ft1000_hbchk(u_long data)
831//--------------------------------------------------------------------------- 831//---------------------------------------------------------------------------
832void ft1000_send_cmd (struct net_device *dev, u16 *ptempbuffer, int size, u16 qtype) 832void ft1000_send_cmd (struct net_device *dev, u16 *ptempbuffer, int size, u16 qtype)
833{ 833{
834 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 834 FT1000_INFO *info = netdev_priv(dev);
835 int i; 835 int i;
836 u16 tempword; 836 u16 tempword;
837 unsigned long flags; 837 unsigned long flags;
@@ -916,7 +916,7 @@ void ft1000_send_cmd (struct net_device *dev, u16 *ptempbuffer, int size, u16 qt
916//--------------------------------------------------------------------------- 916//---------------------------------------------------------------------------
917BOOLEAN ft1000_receive_cmd(struct net_device *dev, u16 * pbuffer, int maxsz, u16 *pnxtph) 917BOOLEAN ft1000_receive_cmd(struct net_device *dev, u16 * pbuffer, int maxsz, u16 *pnxtph)
918{ 918{
919 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 919 FT1000_INFO *info = netdev_priv(dev);
920 u16 size; 920 u16 size;
921 u16 *ppseudohdr; 921 u16 *ppseudohdr;
922 int i; 922 int i;
@@ -1009,7 +1009,7 @@ BOOLEAN ft1000_receive_cmd(struct net_device *dev, u16 * pbuffer, int maxsz, u16
1009//--------------------------------------------------------------------------- 1009//---------------------------------------------------------------------------
1010void ft1000_proc_drvmsg(struct net_device *dev) 1010void ft1000_proc_drvmsg(struct net_device *dev)
1011{ 1011{
1012 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 1012 FT1000_INFO *info = netdev_priv(dev);
1013 u16 msgtype; 1013 u16 msgtype;
1014 u16 tempword; 1014 u16 tempword;
1015 PMEDIAMSG pmediamsg; 1015 PMEDIAMSG pmediamsg;
@@ -1292,7 +1292,7 @@ void ft1000_proc_drvmsg(struct net_device *dev)
1292//--------------------------------------------------------------------------- 1292//---------------------------------------------------------------------------
1293int ft1000_parse_dpram_msg(struct net_device *dev) 1293int ft1000_parse_dpram_msg(struct net_device *dev)
1294{ 1294{
1295 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 1295 FT1000_INFO *info = netdev_priv(dev);
1296 u16 doorbell; 1296 u16 doorbell;
1297 u16 portid; 1297 u16 portid;
1298 u16 nxtph; 1298 u16 nxtph;
@@ -1449,7 +1449,7 @@ int ft1000_parse_dpram_msg(struct net_device *dev)
1449//--------------------------------------------------------------------------- 1449//---------------------------------------------------------------------------
1450static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum) 1450static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
1451{ 1451{
1452 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 1452 FT1000_INFO *info = netdev_priv(dev);
1453 u16 i; 1453 u16 i;
1454 u32 templong; 1454 u32 templong;
1455 u16 tempword; 1455 u16 tempword;
@@ -1596,7 +1596,7 @@ static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
1596int ft1000_copy_up_pkt(struct net_device *dev) 1596int ft1000_copy_up_pkt(struct net_device *dev)
1597{ 1597{
1598 u16 tempword; 1598 u16 tempword;
1599 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 1599 FT1000_INFO *info = netdev_priv(dev);
1600 u16 len; 1600 u16 len;
1601 struct sk_buff *skb; 1601 struct sk_buff *skb;
1602 u16 i; 1602 u16 i;
@@ -1783,7 +1783,7 @@ int ft1000_copy_up_pkt(struct net_device *dev)
1783//--------------------------------------------------------------------------- 1783//---------------------------------------------------------------------------
1784int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len) 1784int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len)
1785{ 1785{
1786 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 1786 FT1000_INFO *info = netdev_priv(dev);
1787 union { 1787 union {
1788 PSEUDO_HDR blk; 1788 PSEUDO_HDR blk;
1789 u16 buff[sizeof(PSEUDO_HDR) >> 1]; 1789 u16 buff[sizeof(PSEUDO_HDR) >> 1];
@@ -1943,7 +1943,7 @@ int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len)
1943 1943
1944static struct net_device_stats *ft1000_stats(struct net_device *dev) 1944static struct net_device_stats *ft1000_stats(struct net_device *dev)
1945{ 1945{
1946 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 1946 FT1000_INFO *info = netdev_priv(dev);
1947 return (&info->stats); 1947 return (&info->stats);
1948} 1948}
1949 1949
@@ -1967,7 +1967,7 @@ static int ft1000_open(struct net_device *dev)
1967 1967
1968static int ft1000_close(struct net_device *dev) 1968static int ft1000_close(struct net_device *dev)
1969{ 1969{
1970 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 1970 FT1000_INFO *info = netdev_priv(dev);
1971 1971
1972 DEBUG(0, "ft1000_hw: ft1000_close()\n"); 1972 DEBUG(0, "ft1000_hw: ft1000_close()\n");
1973 1973
@@ -1989,7 +1989,7 @@ static int ft1000_close(struct net_device *dev)
1989 1989
1990static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) 1990static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1991{ 1991{
1992 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 1992 FT1000_INFO *info = netdev_priv(dev);
1993 u8 *pdata; 1993 u8 *pdata;
1994 1994
1995 DEBUG(1, "ft1000_hw: ft1000_start_xmit()\n"); 1995 DEBUG(1, "ft1000_hw: ft1000_start_xmit()\n");
@@ -2026,7 +2026,7 @@ static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
2026static irqreturn_t ft1000_interrupt(int irq, void *dev_id) 2026static irqreturn_t ft1000_interrupt(int irq, void *dev_id)
2027{ 2027{
2028 struct net_device *dev = (struct net_device *)dev_id; 2028 struct net_device *dev = (struct net_device *)dev_id;
2029 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 2029 FT1000_INFO *info = netdev_priv(dev);
2030 u16 tempword; 2030 u16 tempword;
2031 u16 inttype; 2031 u16 inttype;
2032 int cnt; 2032 int cnt;
@@ -2091,7 +2091,7 @@ static irqreturn_t ft1000_interrupt(int irq, void *dev_id)
2091 2091
2092void stop_ft1000_card(struct net_device *dev) 2092void stop_ft1000_card(struct net_device *dev)
2093{ 2093{
2094 FT1000_INFO *info = (FT1000_INFO *) netdev_priv(dev); 2094 FT1000_INFO *info = netdev_priv(dev);
2095 PPROV_RECORD ptr; 2095 PPROV_RECORD ptr;
2096// int cnt; 2096// int cnt;
2097 2097
@@ -2127,7 +2127,7 @@ static void ft1000_get_drvinfo(struct net_device *dev,
2127 struct ethtool_drvinfo *info) 2127 struct ethtool_drvinfo *info)
2128{ 2128{
2129 FT1000_INFO *ft_info; 2129 FT1000_INFO *ft_info;
2130 ft_info = (FT1000_INFO *) netdev_priv(dev); 2130 ft_info = netdev_priv(dev);
2131 2131
2132 snprintf(info->driver, 32, "ft1000"); 2132 snprintf(info->driver, 32, "ft1000");
2133 snprintf(info->bus_info, ETHTOOL_BUSINFO_LEN, "PCMCIA 0x%lx", 2133 snprintf(info->bus_info, ETHTOOL_BUSINFO_LEN, "PCMCIA 0x%lx",
@@ -2139,7 +2139,7 @@ static void ft1000_get_drvinfo(struct net_device *dev,
2139static u32 ft1000_get_link(struct net_device *dev) 2139static u32 ft1000_get_link(struct net_device *dev)
2140{ 2140{
2141 FT1000_INFO *info; 2141 FT1000_INFO *info;
2142 info = (FT1000_INFO *) netdev_priv(dev); 2142 info = netdev_priv(dev);
2143 return info->mediastate; 2143 return info->mediastate;
2144} 2144}
2145 2145
@@ -2185,7 +2185,7 @@ struct net_device *init_ft1000_card(unsigned short irq, int port,
2185 } 2185 }
2186 2186
2187 SET_NETDEV_DEV(dev, fdev); 2187 SET_NETDEV_DEV(dev, fdev);
2188 info = (FT1000_INFO *) netdev_priv(dev); 2188 info = netdev_priv(dev);
2189 2189
2190 memset(info, 0, sizeof(FT1000_INFO)); 2190 memset(info, 0, sizeof(FT1000_INFO));
2191 2191
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c
index b45de9bc1b20..935608e72007 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c
+++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c
@@ -65,7 +65,7 @@ int ft1000ReadProc(char *page, char **start, off_t off,
65 time_t delta; 65 time_t delta;
66 66
67 dev = (struct net_device *)data; 67 dev = (struct net_device *)data;
68 info = (FT1000_INFO *) netdev_priv(dev); 68 info = netdev_priv(dev);
69 69
70 if (off > 0) { 70 if (off > 0) {
71 *eof = 1; 71 *eof = 1;
@@ -174,7 +174,7 @@ static int ft1000NotifyProc(struct notifier_block *this, unsigned long event,
174 struct net_device *dev = ptr; 174 struct net_device *dev = ptr;
175 FT1000_INFO *info; 175 FT1000_INFO *info;
176 176
177 info = (FT1000_INFO *) netdev_priv(dev); 177 info = netdev_priv(dev);
178 178
179 switch (event) { 179 switch (event) {
180 case NETDEV_CHANGENAME: 180 case NETDEV_CHANGENAME:
@@ -195,7 +195,7 @@ void ft1000InitProc(struct net_device *dev)
195{ 195{
196 FT1000_INFO *info; 196 FT1000_INFO *info;
197 197
198 info = (FT1000_INFO *) netdev_priv(dev); 198 info = netdev_priv(dev);
199 199
200 info->proc_ft1000 = proc_mkdir(FT1000_PROC, init_net.proc_net); 200 info->proc_ft1000 = proc_mkdir(FT1000_PROC, init_net.proc_net);
201 create_proc_read_entry(dev->name, 0644, info->proc_ft1000, 201 create_proc_read_entry(dev->name, 0644, info->proc_ft1000,
@@ -208,7 +208,7 @@ void ft1000CleanupProc(struct net_device *dev)
208{ 208{
209 FT1000_INFO *info; 209 FT1000_INFO *info;
210 210
211 info = (FT1000_INFO *) netdev_priv(dev); 211 info = netdev_priv(dev);
212 212
213 remove_proc_entry(dev->name, info->proc_ft1000); 213 remove_proc_entry(dev->name, info->proc_ft1000);
214 remove_proc_entry(FT1000_PROC, init_net.proc_net); 214 remove_proc_entry(FT1000_PROC, init_net.proc_net);
diff --git a/drivers/staging/ft1000/ft1000-usb/Makefile b/drivers/staging/ft1000/ft1000-usb/Makefile
index dd87ecd7918e..f0f524015888 100644
--- a/drivers/staging/ft1000/ft1000-usb/Makefile
+++ b/drivers/staging/ft1000/ft1000-usb/Makefile
@@ -1,3 +1,3 @@
1obj-$(CONFIG_FT1000_USB) += ft1000.o 1obj-$(CONFIG_FT1000_USB) += ft1000.o
2 2
3ft1000-y := ft1000_chdev.o ft1000_download.o ft1000_hw.o ft1000_proc.o ft1000_usb.o 3ft1000-y := ft1000_debug.o ft1000_download.o ft1000_hw.o ft1000_proc.o ft1000_usb.o
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
index 20d509836d9e..149ba59f96bf 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_chdev.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
@@ -27,33 +27,22 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/sched.h> 29#include <linux/sched.h>
30#include <linux/signal.h>
31#include <linux/errno.h> 30#include <linux/errno.h>
32#include <linux/poll.h> 31#include <linux/poll.h>
33#include <linux/netdevice.h> 32#include <linux/netdevice.h>
34#include <linux/delay.h> 33#include <linux/delay.h>
35 34
36#include <linux/fs.h>
37#include <linux/kmod.h>
38#include <linux/ioctl.h> 35#include <linux/ioctl.h>
39#include <linux/unistd.h> 36#include <linux/debugfs.h>
40
41#include "ft1000_usb.h" 37#include "ft1000_usb.h"
42//#include "ft1000_ioctl.h"
43 38
44static int ft1000_flarion_cnt = 0; 39static int ft1000_flarion_cnt = 0;
45 40
46//need to looking usage of ft1000Handle 41static int ft1000_open (struct inode *inode, struct file *file);
47 42static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait);
48static int ft1000_ChOpen (struct inode *Inode, struct file *File); 43static long ft1000_ioctl(struct file *file, unsigned int command,
49static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait); 44 unsigned long argument);
50static long ft1000_ChIoctl(struct file *File, unsigned int Command, 45static int ft1000_release (struct inode *inode, struct file *file);
51 unsigned long Argument);
52static int ft1000_ChRelease (struct inode *Inode, struct file *File);
53
54// Global pointer to device object
55static struct ft1000_device *pdevobj[MAX_NUM_CARDS + 2];
56//static devfs_handle_t ft1000Handle[MAX_NUM_CARDS];
57 46
58// List to free receive command buffer pool 47// List to free receive command buffer pool
59struct list_head freercvpool; 48struct list_head freercvpool;
@@ -63,103 +52,18 @@ spinlock_t free_buff_lock;
63 52
64int numofmsgbuf = 0; 53int numofmsgbuf = 0;
65 54
66// Global variable to indicate that all provisioning data is sent to DSP
67//BOOLEAN fProvComplete;
68
69// 55//
70// Table of entry-point routines for char device 56// Table of entry-point routines for char device
71// 57//
72static struct file_operations ft1000fops = 58static struct file_operations ft1000fops =
73{ 59{
74 .unlocked_ioctl = ft1000_ChIoctl, 60 .unlocked_ioctl = ft1000_ioctl,
75 .poll = ft1000_ChPoll, 61 .poll = ft1000_poll_dev,
76 .open = ft1000_ChOpen, 62 .open = ft1000_open,
77 .release = ft1000_ChRelease, 63 .release = ft1000_release,
78 .llseek = no_llseek, 64 .llseek = no_llseek,
79}; 65};
80 66
81
82
83
84//---------------------------------------------------------------------------
85// Function: exec_mknod
86//
87// Parameters:
88//
89// Returns:
90//
91// Description:
92//
93// Notes:
94//
95//---------------------------------------------------------------------------
96static int exec_mknod (void *pdata)
97{
98 struct ft1000_info *info;
99 char mjnum[4];
100 char minornum[4];
101 char temp[32];
102 int retcode;
103// int i; //aelias [-] reason : unused variable
104 char *envp[] = { "HOME=/", "PATH=/usr/bin:/bin", NULL };
105 char *argv[]={"-m 666",temp,"c",mjnum,minornum,NULL};
106
107 info = pdata;
108 DEBUG("ft1000_chdev:exec_mknod is called with major number = %d\n", info->DeviceMajor);
109 sprintf(temp, "%s%s", "/dev/", info->DeviceName) ;
110 sprintf(mjnum, "%d", info->DeviceMajor);
111 sprintf(minornum, "%d", info->CardNumber);
112
113 //char *argv[]={"mknod","-m 666",temp,"c",mjnum,minornum,NULL};
114// char *argv[]={"-m 666",temp,"c",mjnum,minornum,NULL};
115
116 //for (i=0; i<7;i++)
117 // DEBUG("argv[%d]=%s\n", i, argv[i]);
118
119
120 retcode = call_usermodehelper ("/bin/mknod", argv, envp, 1);
121 if (retcode) {
122 DEBUG("ft1000_chdev:exec_mknod failed to make the node: retcode = %d\n", retcode);
123 }
124
125
126
127 return retcode;
128
129}
130
131//---------------------------------------------------------------------------
132// Function: rm_mknod
133//
134// Description: This module removes the FT1000 device file
135//
136//---------------------------------------------------------------------------
137static int rm_mknod (void *pdata)
138{
139
140 struct ft1000_info *info;
141 //char *argv[4]={"rm", "-f", "/dev/FT1000", NULL};
142 int retcode;
143 char temp[32];
144 char *argv[]={"rm", "-f", temp, NULL};
145
146 info = (struct ft1000_info *)pdata;
147 DEBUG("ft1000_chdev:rm_mknod is called for device %s\n", info->DeviceName);
148 sprintf(temp, "%s%s", "/dev/", info->DeviceName) ;
149
150// char *argv[]={"rm", "-f", temp, NULL};
151
152 retcode = call_usermodehelper ("/bin/rm", argv, NULL, 1);
153 if (retcode) {
154 DEBUG("ft1000_chdev:rm_mknod failed to remove the node: retcode = %d\n", retcode);
155 }
156 else
157 DEBUG("ft1000_chdev:rm_mknod done!\n");
158
159
160 return retcode;
161
162}
163//--------------------------------------------------------------------------- 67//---------------------------------------------------------------------------
164// Function: ft1000_get_buffer 68// Function: ft1000_get_buffer
165// 69//
@@ -233,80 +137,55 @@ void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist)
233// Notes: Only called by init_module(). 137// Notes: Only called by init_module().
234// 138//
235//--------------------------------------------------------------------------- 139//---------------------------------------------------------------------------
236int ft1000_CreateDevice(struct ft1000_device *dev) 140int ft1000_create_dev(struct ft1000_device *dev)
237{ 141{
238 struct ft1000_info *info = netdev_priv(dev->net); 142 struct ft1000_info *info = netdev_priv(dev->net);
239 int result; 143 int result;
240 int i; 144 int i;
241 pid_t pid; 145 struct dentry *dir, *file;
146 struct ft1000_debug_dirs *tmp;
242 147
243 // make a new device name 148 // make a new device name
244 sprintf(info->DeviceName, "%s%d", "FT100", info->CardNumber); 149 sprintf(info->DeviceName, "%s%d", "FT1000_", info->CardNumber);
245
246 // Delete any existing FT1000 node
247 pid = kernel_thread (rm_mknod,(void *)info, 0);
248 msleep(1000);
249 150
250 DEBUG("ft1000_CreateDevice: number of instance = %d\n", ft1000_flarion_cnt); 151 DEBUG("%s: number of instance = %d\n", __func__, ft1000_flarion_cnt);
251 DEBUG("DeviceCreated = %x\n", info->DeviceCreated); 152 DEBUG("DeviceCreated = %x\n", info->DeviceCreated);
252 153
253 //save the device info to global array
254 pdevobj[info->CardNumber] = dev;
255
256 DEBUG("ft1000_CreateDevice: ******SAVED pdevobj[%d]=%p\n", info->CardNumber, pdevobj[info->CardNumber]); //aelias [+] reason:up
257
258 if (info->DeviceCreated) 154 if (info->DeviceCreated)
259 { 155 {
260 DEBUG("ft1000_CreateDevice: \"%s\" already registered\n", info->DeviceName); 156 DEBUG("%s: \"%s\" already registered\n", __func__, info->DeviceName);
261 return -EIO; 157 return -EIO;
262 } 158 }
263 159
264 160
265 // register the device 161 // register the device
266 DEBUG("ft1000_CreateDevice: \"%s\" device registration\n", info->DeviceName); 162 DEBUG("%s: \"%s\" debugfs device registration\n", __func__, info->DeviceName);
267 info->DeviceMajor = 0;
268
269 result = register_chrdev(info->DeviceMajor, info->DeviceName, &ft1000fops);
270 if (result < 0)
271 {
272 DEBUG("ft1000_CreateDevice: unable to get major %d\n", info->DeviceMajor);
273 return result;
274 }
275
276 DEBUG("ft1000_CreateDevice: registered char device \"%s\"\n", info->DeviceName);
277 163
278 // save a dynamic device major number 164 tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL);
279 if (info->DeviceMajor == 0) 165 if (tmp == NULL) {
280 { 166 result = -1;
281 info->DeviceMajor = result; 167 goto fail;
282 DEBUG("ft1000_PcdCreateDevice: device major = %d\n", info->DeviceMajor); 168 }
283 }
284 169
285 // Create a thread to call user mode app to mknod 170 dir = debugfs_create_dir(info->DeviceName, 0);
286 pid = kernel_thread (exec_mknod, (void *)info, 0); 171 if (IS_ERR(dir)) {
172 result = PTR_ERR(dir);
173 goto debug_dir_fail;
174 }
287 175
288 // initialize application information 176 file = debugfs_create_file("device", S_IRUGO | S_IWUSR, dir,
177 dev, &ft1000fops);
178 if (IS_ERR(file)) {
179 result = PTR_ERR(file);
180 goto debug_file_fail;
181 }
289 182
290// if (ft1000_flarion_cnt == 0) { 183 tmp->dent = dir;
291// 184 tmp->file = file;
292// DEBUG("Initialize free_buff_lock and freercvpool\n"); 185 tmp->int_number = info->CardNumber;
293// spin_lock_init(&free_buff_lock); 186 list_add(&(tmp->list), &(info->nodes.list));
294//
295// // initialize a list of buffers to be use for queuing up receive command data
296// INIT_LIST_HEAD (&freercvpool);
297//
298// // create list of free buffers
299// for (i=0; i<NUM_OF_FREE_BUFFERS; i++) {
300// // Get memory for DPRAM_DATA link list
301// pdpram_blk = kmalloc ( sizeof(struct dpram_blk), GFP_KERNEL );
302// // Get a block of memory to store command data
303// pdpram_blk->pbuffer = kmalloc ( MAX_CMD_SQSIZE, GFP_KERNEL );
304// // link provisioning data
305// list_add_tail (&pdpram_blk->list, &freercvpool);
306// }
307// numofmsgbuf = NUM_OF_FREE_BUFFERS;
308// }
309 187
188 DEBUG("%s: registered debugfs directory \"%s\"\n", __func__, info->DeviceName);
310 189
311 // initialize application information 190 // initialize application information
312 info->appcnt = 0; 191 info->appcnt = 0;
@@ -323,17 +202,17 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
323 INIT_LIST_HEAD (&info->app_info[i].app_sqlist); 202 INIT_LIST_HEAD (&info->app_info[i].app_sqlist);
324 } 203 }
325 204
326
327
328
329// ft1000Handle[info->CardNumber] = devfs_register(NULL, info->DeviceName, DEVFS_FL_AUTO_DEVNUM, 0, 0,
330// S_IFCHR | S_IRUGO | S_IWUGO, &ft1000fops, NULL);
331
332
333 info->DeviceCreated = TRUE; 205 info->DeviceCreated = TRUE;
334 ft1000_flarion_cnt++; 206 ft1000_flarion_cnt++;
335 207
336 return result; 208 return 0;
209
210debug_file_fail:
211 debugfs_remove(dir);
212debug_dir_fail:
213 kfree(tmp);
214fail:
215 return result;
337} 216}
338 217
339//--------------------------------------------------------------------------- 218//---------------------------------------------------------------------------
@@ -346,27 +225,33 @@ int ft1000_CreateDevice(struct ft1000_device *dev)
346// Notes: Only called by cleanup_module(). 225// Notes: Only called by cleanup_module().
347// 226//
348//--------------------------------------------------------------------------- 227//---------------------------------------------------------------------------
349void ft1000_DestroyDevice(struct net_device *dev) 228void ft1000_destroy_dev(struct net_device *dev)
350{ 229{
351 struct ft1000_info *info = netdev_priv(dev); 230 struct ft1000_info *info = netdev_priv(dev);
352 int result = 0;
353 pid_t pid;
354 int i; 231 int i;
355 struct dpram_blk *pdpram_blk; 232 struct dpram_blk *pdpram_blk;
356 struct dpram_blk *ptr; 233 struct dpram_blk *ptr;
234 struct list_head *pos, *q;
235 struct ft1000_debug_dirs *dir;
357 236
358 DEBUG("ft1000_chdev:ft1000_DestroyDevice called\n"); 237 DEBUG("%s called\n", __func__);
359 238
360 239
361 240
362 if (info->DeviceCreated) 241 if (info->DeviceCreated)
363 { 242 {
364 ft1000_flarion_cnt--; 243 ft1000_flarion_cnt--;
365 unregister_chrdev(info->DeviceMajor, info->DeviceName); 244 list_for_each_safe(pos, q, &info->nodes.list) {
366 DEBUG("ft1000_DestroyDevice: unregistered device \"%s\", result = %d\n", 245 dir = list_entry(pos, struct ft1000_debug_dirs, list);
367 info->DeviceName, result); 246 if (dir->int_number == info->CardNumber) {
368 247 debugfs_remove(dir->file);
369 pid = kernel_thread (rm_mknod, (void *)info, 0); 248 debugfs_remove(dir->dent);
249 list_del(pos);
250 kfree(dir);
251 }
252 }
253 DEBUG("%s: unregistered device \"%s\"\n", __func__,
254 info->DeviceName);
370 255
371 // Make sure we free any memory reserve for slow Queue 256 // Make sure we free any memory reserve for slow Queue
372 for (i=0; i<MAX_NUM_APP; i++) { 257 for (i=0; i<MAX_NUM_APP; i++) {
@@ -388,19 +273,14 @@ void ft1000_DestroyDevice(struct net_device *dev)
388 kfree(ptr); 273 kfree(ptr);
389 } 274 }
390 } 275 }
391
392// devfs_unregister(ft1000Handle[info->CardNumber]);
393
394 info->DeviceCreated = FALSE; 276 info->DeviceCreated = FALSE;
395
396 pdevobj[info->CardNumber] = NULL;
397 } 277 }
398 278
399 279
400} 280}
401 281
402//--------------------------------------------------------------------------- 282//---------------------------------------------------------------------------
403// Function: ft1000_ChOpen 283// Function: ft1000_open
404// 284//
405// Parameters: 285// Parameters:
406// 286//
@@ -409,28 +289,19 @@ void ft1000_DestroyDevice(struct net_device *dev)
409// Notes: 289// Notes:
410// 290//
411//--------------------------------------------------------------------------- 291//---------------------------------------------------------------------------
412static int ft1000_ChOpen (struct inode *Inode, struct file *File) 292static int ft1000_open (struct inode *inode, struct file *file)
413{ 293{
414 struct ft1000_info *info; 294 struct ft1000_info *info;
295 struct ft1000_device *dev = (struct ft1000_device *)inode->i_private;
415 int i,num; 296 int i,num;
416 297
417 DEBUG("ft1000_ChOpen called\n"); 298 DEBUG("%s called\n", __func__);
418 num = (MINOR(Inode->i_rdev) & 0xf); 299 num = (MINOR(inode->i_rdev) & 0xf);
419 DEBUG("ft1000_ChOpen: minor number=%d\n", num); 300 DEBUG("ft1000_open: minor number=%d\n", num);
420 301
421 for (i=0; i<5; i++) 302 info = file->private_data = netdev_priv(dev->net);
422 DEBUG("pdevobj[%d]=%p\n", i, pdevobj[i]); //aelias [+] reason: down
423 303
424 if ( pdevobj[num] != NULL ) 304 DEBUG("f_owner = %p number of application = %d\n", (&file->f_owner), info->appcnt );
425 //info = (struct ft1000_info *)(pdevobj[num]->net->priv);
426 info = (struct ft1000_info *)netdev_priv(pdevobj[num]->net);
427 else
428 {
429 DEBUG("ft1000_ChOpen: can not find device object %d\n", num);
430 return -1;
431 }
432
433 DEBUG("f_owner = %p number of application = %d\n", (&File->f_owner), info->appcnt );
434 305
435 // Check if maximum number of application exceeded 306 // Check if maximum number of application exceeded
436 if (info->appcnt > MAX_NUM_APP) { 307 if (info->appcnt > MAX_NUM_APP) {
@@ -452,21 +323,19 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
452 } 323 }
453 324
454 info->appcnt++; 325 info->appcnt++;
455 info->app_info[i].fileobject = &File->f_owner; 326 info->app_info[i].fileobject = &file->f_owner;
456 info->app_info[i].nTxMsg = 0; 327 info->app_info[i].nTxMsg = 0;
457 info->app_info[i].nRxMsg = 0; 328 info->app_info[i].nRxMsg = 0;
458 info->app_info[i].nTxMsgReject = 0; 329 info->app_info[i].nTxMsgReject = 0;
459 info->app_info[i].nRxMsgMiss = 0; 330 info->app_info[i].nRxMsgMiss = 0;
460 331
461 File->private_data = pdevobj[num]->net; 332 nonseekable_open(inode, file);
462
463 nonseekable_open(Inode, File);
464 return 0; 333 return 0;
465} 334}
466 335
467 336
468//--------------------------------------------------------------------------- 337//---------------------------------------------------------------------------
469// Function: ft1000_ChPoll 338// Function: ft1000_poll_dev
470// 339//
471// Parameters: 340// Parameters:
472// 341//
@@ -476,47 +345,47 @@ static int ft1000_ChOpen (struct inode *Inode, struct file *File)
476// 345//
477//--------------------------------------------------------------------------- 346//---------------------------------------------------------------------------
478 347
479static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait) 348static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait)
480{ 349{
481 struct net_device *dev = file->private_data; 350 struct net_device *dev = file->private_data;
482 struct ft1000_info *info; 351 struct ft1000_info *info;
483 int i; 352 int i;
484 353
485 //DEBUG("ft1000_ChPoll called\n"); 354 //DEBUG("ft1000_poll_dev called\n");
486 if (ft1000_flarion_cnt == 0) { 355 if (ft1000_flarion_cnt == 0) {
487 DEBUG("FT1000:ft1000_ChPoll called when ft1000_flarion_cnt is zero\n"); 356 DEBUG("FT1000:ft1000_poll_dev called when ft1000_flarion_cnt is zero\n");
488 return (-EBADF); 357 return (-EBADF);
489 } 358 }
490 359
491 info = (struct ft1000_info *) netdev_priv(dev); 360 info = netdev_priv(dev);
492 361
493 // Search for matching file object 362 // Search for matching file object
494 for (i=0; i<MAX_NUM_APP; i++) { 363 for (i=0; i<MAX_NUM_APP; i++) {
495 if ( info->app_info[i].fileobject == &file->f_owner) { 364 if ( info->app_info[i].fileobject == &file->f_owner) {
496 //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id); 365 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id);
497 break; 366 break;
498 } 367 }
499 } 368 }
500 369
501 // Could not find application info block 370 // Could not find application info block
502 if (i == MAX_NUM_APP) { 371 if (i == MAX_NUM_APP) {
503 DEBUG("FT1000:ft1000_ChIoctl:Could not find application info block\n"); 372 DEBUG("FT1000:ft1000_ioctl:Could not find application info block\n");
504 return ( -EACCES ); 373 return ( -EACCES );
505 } 374 }
506 375
507 if (list_empty(&info->app_info[i].app_sqlist) == 0) { 376 if (list_empty(&info->app_info[i].app_sqlist) == 0) {
508 DEBUG("FT1000:ft1000_ChPoll:Message detected in slow queue\n"); 377 DEBUG("FT1000:ft1000_poll_dev:Message detected in slow queue\n");
509 return(POLLIN | POLLRDNORM | POLLPRI); 378 return(POLLIN | POLLRDNORM | POLLPRI);
510 } 379 }
511 380
512 poll_wait (file, &info->app_info[i].wait_dpram_msg, wait); 381 poll_wait (file, &info->app_info[i].wait_dpram_msg, wait);
513 //DEBUG("FT1000:ft1000_ChPoll:Polling for data from DSP\n"); 382 //DEBUG("FT1000:ft1000_poll_dev:Polling for data from DSP\n");
514 383
515 return (0); 384 return (0);
516} 385}
517 386
518//--------------------------------------------------------------------------- 387//---------------------------------------------------------------------------
519// Function: ft1000_ChIoctl 388// Function: ft1000_ioctl
520// 389//
521// Parameters: 390// Parameters:
522// 391//
@@ -525,11 +394,10 @@ static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait)
525// Notes: 394// Notes:
526// 395//
527//--------------------------------------------------------------------------- 396//---------------------------------------------------------------------------
528static long ft1000_ChIoctl (struct file *File, unsigned int Command, 397static long ft1000_ioctl (struct file *file, unsigned int command,
529 unsigned long Argument) 398 unsigned long argument)
530{ 399{
531 void __user *argp = (void __user *)Argument; 400 void __user *argp = (void __user *)argument;
532 struct net_device *dev;
533 struct ft1000_info *info; 401 struct ft1000_info *info;
534 struct ft1000_device *ft1000dev; 402 struct ft1000_device *ft1000dev;
535 int result=0; 403 int result=0;
@@ -550,25 +418,24 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
550 unsigned short ledStat=0; 418 unsigned short ledStat=0;
551 unsigned short conStat=0; 419 unsigned short conStat=0;
552 420
553 //DEBUG("ft1000_ChIoctl called\n"); 421 //DEBUG("ft1000_ioctl called\n");
554 422
555 if (ft1000_flarion_cnt == 0) { 423 if (ft1000_flarion_cnt == 0) {
556 DEBUG("FT1000:ft1000_ChIoctl called when ft1000_flarion_cnt is zero\n"); 424 DEBUG("FT1000:ft1000_ioctl called when ft1000_flarion_cnt is zero\n");
557 return (-EBADF); 425 return (-EBADF);
558 } 426 }
559 427
560 //DEBUG("FT1000:ft1000_ChIoctl:Command = 0x%x Argument = 0x%8x\n", Command, (u32)Argument); 428 //DEBUG("FT1000:ft1000_ioctl:command = 0x%x argument = 0x%8x\n", command, (u32)argument);
561 429
562 dev = File->private_data; 430 info = file->private_data;
563 info = (struct ft1000_info *) netdev_priv(dev); 431 ft1000dev = info->pFt1000Dev;
564 ft1000dev = info->pFt1000Dev; 432 cmd = _IOC_NR(command);
565 cmd = _IOC_NR(Command); 433 //DEBUG("FT1000:ft1000_ioctl:cmd = 0x%x\n", cmd);
566 //DEBUG("FT1000:ft1000_ChIoctl:cmd = 0x%x\n", cmd);
567 434
568 // process the command 435 // process the command
569 switch (cmd) { 436 switch (cmd) {
570 case IOCTL_REGISTER_CMD: 437 case IOCTL_REGISTER_CMD:
571 DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_REGISTER called\n"); 438 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_REGISTER called\n");
572 result = get_user(tempword, (__u16 __user*)argp); 439 result = get_user(tempword, (__u16 __user*)argp);
573 if (result) { 440 if (result) {
574 DEBUG("result = %d failed to get_user\n", result); 441 DEBUG("result = %d failed to get_user\n", result);
@@ -577,9 +444,9 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
577 if (tempword == DSPBCMSGID) { 444 if (tempword == DSPBCMSGID) {
578 // Search for matching file object 445 // Search for matching file object
579 for (i=0; i<MAX_NUM_APP; i++) { 446 for (i=0; i<MAX_NUM_APP; i++) {
580 if ( info->app_info[i].fileobject == &File->f_owner) { 447 if ( info->app_info[i].fileobject == &file->f_owner) {
581 info->app_info[i].DspBCMsgFlag = 1; 448 info->app_info[i].DspBCMsgFlag = 1;
582 DEBUG("FT1000:ft1000_ChIoctl:Registered for broadcast messages\n"); 449 DEBUG("FT1000:ft1000_ioctl:Registered for broadcast messages\n");
583 break; 450 break;
584 } 451 }
585 } 452 }
@@ -587,34 +454,34 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
587 break; 454 break;
588 455
589 case IOCTL_GET_VER_CMD: 456 case IOCTL_GET_VER_CMD:
590 DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_VER called\n"); 457 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_VER called\n");
591 458
592 get_ver_data.drv_ver = FT1000_DRV_VER; 459 get_ver_data.drv_ver = FT1000_DRV_VER;
593 460
594 if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data)) ) { 461 if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data)) ) {
595 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n"); 462 DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n");
596 result = -EFAULT; 463 result = -EFAULT;
597 break; 464 break;
598 } 465 }
599 466
600 DEBUG("FT1000:ft1000_ChIoctl:driver version = 0x%x\n",(unsigned int)get_ver_data.drv_ver); 467 DEBUG("FT1000:ft1000_ioctl:driver version = 0x%x\n",(unsigned int)get_ver_data.drv_ver);
601 468
602 break; 469 break;
603 case IOCTL_CONNECT: 470 case IOCTL_CONNECT:
604 // Connect Message 471 // Connect Message
605 DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_CONNECT\n"); 472 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_CONNECT\n");
606 ConnectionMsg[79] = 0xfc; 473 ConnectionMsg[79] = 0xfc;
607 CardSendCommand(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c); 474 CardSendCommand(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c);
608 475
609 break; 476 break;
610 case IOCTL_DISCONNECT: 477 case IOCTL_DISCONNECT:
611 // Disconnect Message 478 // Disconnect Message
612 DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_DISCONNECT\n"); 479 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_DISCONNECT\n");
613 ConnectionMsg[79] = 0xfd; 480 ConnectionMsg[79] = 0xfd;
614 CardSendCommand(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c); 481 CardSendCommand(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c);
615 break; 482 break;
616 case IOCTL_GET_DSP_STAT_CMD: 483 case IOCTL_GET_DSP_STAT_CMD:
617 //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_DSP_STAT called\n"); 484 //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DSP_STAT called\n");
618 memset(&get_stat_data, 0, sizeof(get_stat_data)); 485 memset(&get_stat_data, 0, sizeof(get_stat_data));
619 memcpy(get_stat_data.DspVer, info->DspVer, DSPVERSZ); 486 memcpy(get_stat_data.DspVer, info->DspVer, DSPVERSZ);
620 memcpy(get_stat_data.HwSerNum, info->HwSerNum, HWSERNUMSZ); 487 memcpy(get_stat_data.HwSerNum, info->HwSerNum, HWSERNUMSZ);
@@ -622,12 +489,12 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
622 memcpy(get_stat_data.eui64, info->eui64, EUISZ); 489 memcpy(get_stat_data.eui64, info->eui64, EUISZ);
623 490
624 if (info->ProgConStat != 0xFF) { 491 if (info->ProgConStat != 0xFF) {
625 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED, (PUCHAR)&ledStat, FT1000_MAG_DSP_LED_INDX); 492 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED, (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
626 get_stat_data.LedStat = ntohs(ledStat); 493 get_stat_data.LedStat = ntohs(ledStat);
627 DEBUG("FT1000:ft1000_ChIoctl: LedStat = 0x%x\n", get_stat_data.LedStat); 494 DEBUG("FT1000:ft1000_ioctl: LedStat = 0x%x\n", get_stat_data.LedStat);
628 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE, (PUCHAR)&conStat, FT1000_MAG_DSP_CON_STATE_INDX); 495 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE, (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
629 get_stat_data.ConStat = ntohs(conStat); 496 get_stat_data.ConStat = ntohs(conStat);
630 DEBUG("FT1000:ft1000_ChIoctl: ConStat = 0x%x\n", get_stat_data.ConStat); 497 DEBUG("FT1000:ft1000_ioctl: ConStat = 0x%x\n", get_stat_data.ConStat);
631 } 498 }
632 else { 499 else {
633 get_stat_data.ConStat = 0x0f; 500 get_stat_data.ConStat = 0x0f;
@@ -642,7 +509,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
642 get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm); 509 get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm);
643 DEBUG("Connection Time = %d\n", (int)get_stat_data.ConTm); 510 DEBUG("Connection Time = %d\n", (int)get_stat_data.ConTm);
644 if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data)) ) { 511 if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data)) ) {
645 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n"); 512 DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n");
646 result = -EFAULT; 513 result = -EFAULT;
647 break; 514 break;
648 } 515 }
@@ -650,17 +517,17 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
650 break; 517 break;
651 case IOCTL_SET_DPRAM_CMD: 518 case IOCTL_SET_DPRAM_CMD:
652 { 519 {
653 IOCTL_DPRAM_BLK *dpram_data; 520 IOCTL_DPRAM_BLK *dpram_data = NULL;
654 //IOCTL_DPRAM_COMMAND dpram_command; 521 //IOCTL_DPRAM_COMMAND dpram_command;
655 USHORT qtype; 522 u16 qtype;
656 USHORT msgsz; 523 u16 msgsz;
657 struct pseudo_hdr *ppseudo_hdr; 524 struct pseudo_hdr *ppseudo_hdr;
658 PUSHORT pmsg; 525 u16 *pmsg;
659 USHORT total_len; 526 u16 total_len;
660 USHORT app_index; 527 u16 app_index;
661 u16 status; 528 u16 status;
662 529
663 //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_SET_DPRAM called\n"); 530 //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_SET_DPRAM called\n");
664 531
665 532
666 if (ft1000_flarion_cnt == 0) { 533 if (ft1000_flarion_cnt == 0) {
@@ -679,15 +546,15 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
679 546
680 if (info->CardReady) { 547 if (info->CardReady) {
681 548
682 //DEBUG("FT1000:ft1000_ChIoctl: try to SET_DPRAM \n"); 549 //DEBUG("FT1000:ft1000_ioctl: try to SET_DPRAM \n");
683 550
684 // Get the length field to see how many bytes to copy 551 // Get the length field to see how many bytes to copy
685 result = get_user(msgsz, (__u16 __user *)argp); 552 result = get_user(msgsz, (__u16 __user *)argp);
686 msgsz = ntohs (msgsz); 553 msgsz = ntohs (msgsz);
687 //DEBUG("FT1000:ft1000_ChIoctl: length of message = %d\n", msgsz); 554 //DEBUG("FT1000:ft1000_ioctl: length of message = %d\n", msgsz);
688 555
689 if (msgsz > MAX_CMD_SQSIZE) { 556 if (msgsz > MAX_CMD_SQSIZE) {
690 DEBUG("FT1000:ft1000_ChIoctl: bad message length = %d\n", msgsz); 557 DEBUG("FT1000:ft1000_ioctl: bad message length = %d\n", msgsz);
691 result = -EINVAL; 558 result = -EINVAL;
692 break; 559 break;
693 } 560 }
@@ -697,22 +564,14 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
697 if (!dpram_data) 564 if (!dpram_data)
698 break; 565 break;
699 566
700 //if ( copy_from_user(&(dpram_command.dpram_blk), (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) { 567 if ( copy_from_user(dpram_data, argp, msgsz+2) ) {
701 if ( copy_from_user(&dpram_data, argp, msgsz+2) ) {
702 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n"); 568 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
703 result = -EFAULT; 569 result = -EFAULT;
704 } 570 }
705 else { 571 else {
706#if 0
707 // whc - for debugging only
708 ptr = (char *)&dpram_data;
709 for (i=0; i<msgsz; i++) {
710 DEBUG(1,"FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
711 }
712#endif
713 // Check if this message came from a registered application 572 // Check if this message came from a registered application
714 for (i=0; i<MAX_NUM_APP; i++) { 573 for (i=0; i<MAX_NUM_APP; i++) {
715 if ( info->app_info[i].fileobject == &File->f_owner) { 574 if ( info->app_info[i].fileobject == &file->f_owner) {
716 break; 575 break;
717 } 576 }
718 } 577 }
@@ -725,16 +584,15 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
725 app_index = i; 584 app_index = i;
726 585
727 // Check message qtype type which is the lower byte within qos_class 586 // Check message qtype type which is the lower byte within qos_class
728 //qtype = ntohs(dpram_command.dpram_blk.pseudohdr.qos_class) & 0xff;
729 qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff; 587 qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff;
730 //DEBUG("FT1000_ft1000_ChIoctl: qtype = %d\n", qtype); 588 //DEBUG("FT1000_ft1000_ioctl: qtype = %d\n", qtype);
731 if (qtype) { 589 if (qtype) {
732 } 590 }
733 else { 591 else {
734 // Put message into Slow Queue 592 // Put message into Slow Queue
735 // Only put a message into the DPRAM if msg doorbell is available 593 // Only put a message into the DPRAM if msg doorbell is available
736 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); 594 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
737 //DEBUG("FT1000_ft1000_ChIoctl: READ REGISTER tempword=%x\n", tempword); 595 //DEBUG("FT1000_ft1000_ioctl: READ REGISTER tempword=%x\n", tempword);
738 if (tempword & FT1000_DB_DPRAM_TX) { 596 if (tempword & FT1000_DB_DPRAM_TX) {
739 // Suspend for 2ms and try again due to DSP doorbell busy 597 // Suspend for 2ms and try again due to DSP doorbell busy
740 mdelay(2); 598 mdelay(2);
@@ -750,7 +608,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
750 mdelay(3); 608 mdelay(3);
751 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); 609 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
752 if (tempword & FT1000_DB_DPRAM_TX) { 610 if (tempword & FT1000_DB_DPRAM_TX) {
753 DEBUG("FT1000:ft1000_ChIoctl:Doorbell not available\n"); 611 DEBUG("FT1000:ft1000_ioctl:Doorbell not available\n");
754 result = -ENOTTY; 612 result = -ENOTTY;
755 kfree(dpram_data); 613 kfree(dpram_data);
756 break; 614 break;
@@ -760,13 +618,12 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
760 } 618 }
761 } 619 }
762 620
763 //DEBUG("FT1000_ft1000_ChIoctl: finished reading register\n"); 621 //DEBUG("FT1000_ft1000_ioctl: finished reading register\n");
764 622
765 // Make sure we are within the limits of the slow queue memory limitation 623 // Make sure we are within the limits of the slow queue memory limitation
766 if ( (msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ) ) { 624 if ( (msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ) ) {
767 // Need to put sequence number plus new checksum for message 625 // Need to put sequence number plus new checksum for message
768 //pmsg = (PUSHORT)&dpram_command.dpram_blk.pseudohdr; 626 pmsg = (u16 *)&dpram_data->pseudohdr;
769 pmsg = (PUSHORT)&dpram_data->pseudohdr;
770 ppseudo_hdr = (struct pseudo_hdr *)pmsg; 627 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
771 total_len = msgsz+2; 628 total_len = msgsz+2;
772 if (total_len & 0x1) { 629 if (total_len & 0x1) {
@@ -785,17 +642,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
785 } 642 }
786 pmsg++; 643 pmsg++;
787 ppseudo_hdr = (struct pseudo_hdr *)pmsg; 644 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
788#if 0 645 CardSendCommand(ft1000dev,(unsigned short*)dpram_data,total_len+2);
789 ptr = dpram_data;
790 DEBUG("FT1000:ft1000_ChIoctl: Command Send\n");
791 for (i=0; i<total_len; i++) {
792 DEBUG("FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
793 }
794#endif
795 //dpram_command.extra = 0;
796
797 //CardSendCommand(ft1000dev,(unsigned char*)&dpram_command,total_len+2);
798 CardSendCommand(ft1000dev,(unsigned short*)dpram_data,total_len+2);
799 646
800 647
801 info->app_info[app_index].nTxMsg++; 648 info->app_info[app_index].nTxMsg++;
@@ -807,7 +654,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
807 } 654 }
808 } 655 }
809 else { 656 else {
810 DEBUG("FT1000:ft1000_ChIoctl: Card not ready take messages\n"); 657 DEBUG("FT1000:ft1000_ioctl: Card not ready take messages\n");
811 result = -EACCES; 658 result = -EACCES;
812 } 659 }
813 kfree(dpram_data); 660 kfree(dpram_data);
@@ -820,7 +667,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
820 IOCTL_DPRAM_BLK __user *pioctl_dpram; 667 IOCTL_DPRAM_BLK __user *pioctl_dpram;
821 int msglen; 668 int msglen;
822 669
823 //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_DPRAM called\n"); 670 //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DPRAM called\n");
824 671
825 if (ft1000_flarion_cnt == 0) { 672 if (ft1000_flarion_cnt == 0) {
826 return (-EBADF); 673 return (-EBADF);
@@ -828,15 +675,15 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
828 675
829 // Search for matching file object 676 // Search for matching file object
830 for (i=0; i<MAX_NUM_APP; i++) { 677 for (i=0; i<MAX_NUM_APP; i++) {
831 if ( info->app_info[i].fileobject == &File->f_owner) { 678 if ( info->app_info[i].fileobject == &file->f_owner) {
832 //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id); 679 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id);
833 break; 680 break;
834 } 681 }
835 } 682 }
836 683
837 // Could not find application info block 684 // Could not find application info block
838 if (i == MAX_NUM_APP) { 685 if (i == MAX_NUM_APP) {
839 DEBUG("FT1000:ft1000_ChIoctl:Could not find application info block\n"); 686 DEBUG("FT1000:ft1000_ioctl:Could not find application info block\n");
840 result = -EBADF; 687 result = -EBADF;
841 break; 688 break;
842 } 689 }
@@ -844,22 +691,22 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
844 result = 0; 691 result = 0;
845 pioctl_dpram = argp; 692 pioctl_dpram = argp;
846 if (list_empty(&info->app_info[i].app_sqlist) == 0) { 693 if (list_empty(&info->app_info[i].app_sqlist) == 0) {
847 //DEBUG("FT1000:ft1000_ChIoctl:Message detected in slow queue\n"); 694 //DEBUG("FT1000:ft1000_ioctl:Message detected in slow queue\n");
848 spin_lock_irqsave(&free_buff_lock, flags); 695 spin_lock_irqsave(&free_buff_lock, flags);
849 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list); 696 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list);
850 list_del(&pdpram_blk->list); 697 list_del(&pdpram_blk->list);
851 info->app_info[i].NumOfMsg--; 698 info->app_info[i].NumOfMsg--;
852 //DEBUG("FT1000:ft1000_ChIoctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg); 699 //DEBUG("FT1000:ft1000_ioctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg);
853 spin_unlock_irqrestore(&free_buff_lock, flags); 700 spin_unlock_irqrestore(&free_buff_lock, flags);
854 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ; 701 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
855 result = get_user(msglen, &pioctl_dpram->total_len); 702 result = get_user(msglen, &pioctl_dpram->total_len);
856 if (result) 703 if (result)
857 break; 704 break;
858 msglen = htons(msglen); 705 msglen = htons(msglen);
859 //DEBUG("FT1000:ft1000_ChIoctl:msg length = %x\n", msglen); 706 //DEBUG("FT1000:ft1000_ioctl:msg length = %x\n", msglen);
860 if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen)) 707 if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen))
861 { 708 {
862 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n"); 709 DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n");
863 result = -EFAULT; 710 result = -EFAULT;
864 break; 711 break;
865 } 712 }
@@ -867,12 +714,12 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
867 ft1000_free_buffer(pdpram_blk, &freercvpool); 714 ft1000_free_buffer(pdpram_blk, &freercvpool);
868 result = msglen; 715 result = msglen;
869 } 716 }
870 //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_DPRAM no message\n"); 717 //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DPRAM no message\n");
871 } 718 }
872 break; 719 break;
873 720
874 default: 721 default:
875 DEBUG("FT1000:ft1000_ChIoctl:unknown command: 0x%x\n", Command); 722 DEBUG("FT1000:ft1000_ioctl:unknown command: 0x%x\n", command);
876 result = -ENOTTY; 723 result = -ENOTTY;
877 break; 724 break;
878 } 725 }
@@ -881,7 +728,7 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
881} 728}
882 729
883//--------------------------------------------------------------------------- 730//---------------------------------------------------------------------------
884// Function: ft1000_ChRelease 731// Function: ft1000_release
885// 732//
886// Parameters: 733// Parameters:
887// 734//
@@ -890,17 +737,17 @@ static long ft1000_ChIoctl (struct file *File, unsigned int Command,
890// Notes: 737// Notes:
891// 738//
892//--------------------------------------------------------------------------- 739//---------------------------------------------------------------------------
893static int ft1000_ChRelease (struct inode *Inode, struct file *File) 740static int ft1000_release (struct inode *inode, struct file *file)
894{ 741{
895 struct ft1000_info *info; 742 struct ft1000_info *info;
896 struct net_device *dev; 743 struct net_device *dev;
897 int i; 744 int i;
898 struct dpram_blk *pdpram_blk; 745 struct dpram_blk *pdpram_blk;
899 746
900 DEBUG("ft1000_ChRelease called\n"); 747 DEBUG("ft1000_release called\n");
901 748
902 dev = File->private_data; 749 dev = file->private_data;
903 info = (struct ft1000_info *) netdev_priv(dev); 750 info = netdev_priv(dev);
904 751
905 if (ft1000_flarion_cnt == 0) { 752 if (ft1000_flarion_cnt == 0) {
906 info->appcnt--; 753 info->appcnt--;
@@ -909,8 +756,8 @@ static int ft1000_ChRelease (struct inode *Inode, struct file *File)
909 756
910 // Search for matching file object 757 // Search for matching file object
911 for (i=0; i<MAX_NUM_APP; i++) { 758 for (i=0; i<MAX_NUM_APP; i++) {
912 if ( info->app_info[i].fileobject == &File->f_owner) { 759 if ( info->app_info[i].fileobject == &file->f_owner) {
913 //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id); 760 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id);
914 break; 761 break;
915 } 762 }
916 } 763 }
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
index 4dd456fbab9b..17546d8ec08d 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
@@ -123,11 +123,11 @@ struct dsp_image_info {
123// Notes: 123// Notes:
124// 124//
125//--------------------------------------------------------------------------- 125//---------------------------------------------------------------------------
126static ULONG check_usb_db (struct ft1000_device *ft1000dev) 126static u32 check_usb_db (struct ft1000_device *ft1000dev)
127{ 127{
128 int loopcnt; 128 int loopcnt;
129 USHORT temp; 129 u16 temp;
130 ULONG status; 130 u32 status;
131 131
132 loopcnt = 0; 132 loopcnt = 0;
133 while (loopcnt < 10) 133 while (loopcnt < 10)
@@ -190,7 +190,7 @@ static ULONG check_usb_db (struct ft1000_device *ft1000dev)
190// Function: get_handshake 190// Function: get_handshake
191// 191//
192// Parameters: struct ft1000_device - device structure 192// Parameters: struct ft1000_device - device structure
193// USHORT expected_value - the handshake value expected 193// u16 expected_value - the handshake value expected
194// 194//
195// Returns: handshakevalue - success 195// Returns: handshakevalue - success
196// HANDSHAKE_TIMEOUT_VALUE - failure 196// HANDSHAKE_TIMEOUT_VALUE - failure
@@ -200,11 +200,11 @@ static ULONG check_usb_db (struct ft1000_device *ft1000dev)
200// Notes: 200// Notes:
201// 201//
202//--------------------------------------------------------------------------- 202//---------------------------------------------------------------------------
203static USHORT get_handshake(struct ft1000_device *ft1000dev, USHORT expected_value) 203static u16 get_handshake(struct ft1000_device *ft1000dev, u16 expected_value)
204{ 204{
205 USHORT handshake; 205 u16 handshake;
206 int loopcnt; 206 int loopcnt;
207 ULONG status=0; 207 u32 status=0;
208 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); 208 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
209 209
210 loopcnt = 0; 210 loopcnt = 0;
@@ -228,7 +228,7 @@ static USHORT get_handshake(struct ft1000_device *ft1000dev, USHORT expected_val
228 status = ft1000_write_register (ft1000dev, FT1000_DB_DNLD_RX, FT1000_REG_DOORBELL); 228 status = ft1000_write_register (ft1000dev, FT1000_DB_DNLD_RX, FT1000_REG_DOORBELL);
229 } 229 }
230 230
231 status = ft1000_read_dpram16 (ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, (PUCHAR)&handshake, 1); 231 status = ft1000_read_dpram16 (ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, (u8 *)&handshake, 1);
232 //DEBUG("get_handshake: handshake is %x\n", tempx); 232 //DEBUG("get_handshake: handshake is %x\n", tempx);
233 handshake = ntohs(handshake); 233 handshake = ntohs(handshake);
234 //DEBUG("get_handshake: after swap, handshake is %x\n", handshake); 234 //DEBUG("get_handshake: after swap, handshake is %x\n", handshake);
@@ -259,7 +259,7 @@ static USHORT get_handshake(struct ft1000_device *ft1000dev, USHORT expected_val
259// Function: put_handshake 259// Function: put_handshake
260// 260//
261// Parameters: struct ft1000_device - device structure 261// Parameters: struct ft1000_device - device structure
262// USHORT handshake_value - handshake to be written 262// u16 handshake_value - handshake to be written
263// 263//
264// Returns: none 264// Returns: none
265// 265//
@@ -269,30 +269,30 @@ static USHORT get_handshake(struct ft1000_device *ft1000dev, USHORT expected_val
269// Notes: 269// Notes:
270// 270//
271//--------------------------------------------------------------------------- 271//---------------------------------------------------------------------------
272static void put_handshake(struct ft1000_device *ft1000dev,USHORT handshake_value) 272static void put_handshake(struct ft1000_device *ft1000dev,u16 handshake_value)
273{ 273{
274 ULONG tempx; 274 u32 tempx;
275 USHORT tempword; 275 u16 tempword;
276 ULONG status; 276 u32 status;
277 277
278 278
279 279
280 tempx = (ULONG)handshake_value; 280 tempx = (u32)handshake_value;
281 tempx = ntohl(tempx); 281 tempx = ntohl(tempx);
282 282
283 tempword = (USHORT)(tempx & 0xffff); 283 tempword = (u16)(tempx & 0xffff);
284 status = ft1000_write_dpram16 (ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, tempword, 0); 284 status = ft1000_write_dpram16 (ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, tempword, 0);
285 tempword = (USHORT)(tempx >> 16); 285 tempword = (u16)(tempx >> 16);
286 status = ft1000_write_dpram16 (ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, tempword, 1); 286 status = ft1000_write_dpram16 (ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, tempword, 1);
287 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX, FT1000_REG_DOORBELL); 287 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX, FT1000_REG_DOORBELL);
288} 288}
289 289
290static USHORT get_handshake_usb(struct ft1000_device *ft1000dev, USHORT expected_value) 290static u16 get_handshake_usb(struct ft1000_device *ft1000dev, u16 expected_value)
291{ 291{
292 USHORT handshake; 292 u16 handshake;
293 int loopcnt; 293 int loopcnt;
294 USHORT temp; 294 u16 temp;
295 ULONG status=0; 295 u32 status=0;
296 296
297 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); 297 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
298 loopcnt = 0; 298 loopcnt = 0;
@@ -300,10 +300,10 @@ static USHORT get_handshake_usb(struct ft1000_device *ft1000dev, USHORT expected
300 while (loopcnt < 100) 300 while (loopcnt < 100)
301 { 301 {
302 if (pft1000info->usbboot == 2) { 302 if (pft1000info->usbboot == 2) {
303 status = ft1000_read_dpram32 (ft1000dev, 0, (PUCHAR)&(pft1000info->tempbuf[0]), 64); 303 status = ft1000_read_dpram32 (ft1000dev, 0, (u8 *)&(pft1000info->tempbuf[0]), 64);
304 for (temp=0; temp<16; temp++) 304 for (temp=0; temp<16; temp++)
305 DEBUG("tempbuf %d = 0x%x\n", temp, pft1000info->tempbuf[temp]); 305 DEBUG("tempbuf %d = 0x%x\n", temp, pft1000info->tempbuf[temp]);
306 status = ft1000_read_dpram16 (ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, (PUCHAR)&handshake, 1); 306 status = ft1000_read_dpram16 (ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, (u8 *)&handshake, 1);
307 DEBUG("handshake from read_dpram16 = 0x%x\n", handshake); 307 DEBUG("handshake from read_dpram16 = 0x%x\n", handshake);
308 if (pft1000info->dspalive == pft1000info->tempbuf[6]) 308 if (pft1000info->dspalive == pft1000info->tempbuf[6])
309 handshake = 0; 309 handshake = 0;
@@ -313,7 +313,7 @@ static USHORT get_handshake_usb(struct ft1000_device *ft1000dev, USHORT expected
313 } 313 }
314 } 314 }
315 else { 315 else {
316 status = ft1000_read_dpram16 (ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, (PUCHAR)&handshake, 1); 316 status = ft1000_read_dpram16 (ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, (u8 *)&handshake, 1);
317 } 317 }
318 loopcnt++; 318 loopcnt++;
319 msleep(10); 319 msleep(10);
@@ -327,7 +327,7 @@ static USHORT get_handshake_usb(struct ft1000_device *ft1000dev, USHORT expected
327 return HANDSHAKE_TIMEOUT_VALUE; 327 return HANDSHAKE_TIMEOUT_VALUE;
328} 328}
329 329
330static void put_handshake_usb(struct ft1000_device *ft1000dev,USHORT handshake_value) 330static void put_handshake_usb(struct ft1000_device *ft1000dev,u16 handshake_value)
331{ 331{
332 int i; 332 int i;
333 333
@@ -346,44 +346,44 @@ static void put_handshake_usb(struct ft1000_device *ft1000dev,USHORT handshake_v
346// Notes: 346// Notes:
347// 347//
348//--------------------------------------------------------------------------- 348//---------------------------------------------------------------------------
349static USHORT get_request_type(struct ft1000_device *ft1000dev) 349static u16 get_request_type(struct ft1000_device *ft1000dev)
350{ 350{
351 USHORT request_type; 351 u16 request_type;
352 ULONG status; 352 u32 status;
353 USHORT tempword; 353 u16 tempword;
354 ULONG tempx; 354 u32 tempx;
355 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); 355 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
356 356
357 if ( pft1000info->bootmode == 1) 357 if ( pft1000info->bootmode == 1)
358 { 358 {
359 status = fix_ft1000_read_dpram32 (ft1000dev, DWNLD_MAG1_TYPE_LOC, (PUCHAR)&tempx); 359 status = fix_ft1000_read_dpram32 (ft1000dev, DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx);
360 tempx = ntohl(tempx); 360 tempx = ntohl(tempx);
361 } 361 }
362 else 362 else
363 { 363 {
364 tempx = 0; 364 tempx = 0;
365 365
366 status = ft1000_read_dpram16 (ft1000dev, DWNLD_MAG1_TYPE_LOC, (PUCHAR)&tempword, 1); 366 status = ft1000_read_dpram16 (ft1000dev, DWNLD_MAG1_TYPE_LOC, (u8 *)&tempword, 1);
367 tempx |= (tempword << 16); 367 tempx |= (tempword << 16);
368 tempx = ntohl(tempx); 368 tempx = ntohl(tempx);
369 } 369 }
370 request_type = (USHORT)tempx; 370 request_type = (u16)tempx;
371 371
372 //DEBUG("get_request_type: request_type is %x\n", request_type); 372 //DEBUG("get_request_type: request_type is %x\n", request_type);
373 return request_type; 373 return request_type;
374 374
375} 375}
376 376
377static USHORT get_request_type_usb(struct ft1000_device *ft1000dev) 377static u16 get_request_type_usb(struct ft1000_device *ft1000dev)
378{ 378{
379 USHORT request_type; 379 u16 request_type;
380 ULONG status; 380 u32 status;
381 USHORT tempword; 381 u16 tempword;
382 ULONG tempx; 382 u32 tempx;
383 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); 383 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
384 if ( pft1000info->bootmode == 1) 384 if ( pft1000info->bootmode == 1)
385 { 385 {
386 status = fix_ft1000_read_dpram32 (ft1000dev, DWNLD_MAG1_TYPE_LOC, (PUCHAR)&tempx); 386 status = fix_ft1000_read_dpram32 (ft1000dev, DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx);
387 tempx = ntohl(tempx); 387 tempx = ntohl(tempx);
388 } 388 }
389 else 389 else
@@ -394,12 +394,12 @@ static USHORT get_request_type_usb(struct ft1000_device *ft1000dev)
394 } 394 }
395 else { 395 else {
396 tempx = 0; 396 tempx = 0;
397 status = ft1000_read_dpram16 (ft1000dev, DWNLD_MAG1_TYPE_LOC, (PUCHAR)&tempword, 1); 397 status = ft1000_read_dpram16 (ft1000dev, DWNLD_MAG1_TYPE_LOC, (u8 *)&tempword, 1);
398 } 398 }
399 tempx |= (tempword << 16); 399 tempx |= (tempword << 16);
400 tempx = ntohl(tempx); 400 tempx = ntohl(tempx);
401 } 401 }
402 request_type = (USHORT)tempx; 402 request_type = (u16)tempx;
403 403
404 //DEBUG("get_request_type: request_type is %x\n", request_type); 404 //DEBUG("get_request_type: request_type is %x\n", request_type);
405 return request_type; 405 return request_type;
@@ -420,22 +420,22 @@ static USHORT get_request_type_usb(struct ft1000_device *ft1000dev)
420//--------------------------------------------------------------------------- 420//---------------------------------------------------------------------------
421static long get_request_value(struct ft1000_device *ft1000dev) 421static long get_request_value(struct ft1000_device *ft1000dev)
422{ 422{
423 ULONG value; 423 u32 value;
424 USHORT tempword; 424 u16 tempword;
425 ULONG status; 425 u32 status;
426 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); 426 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
427 427
428 428
429 if ( pft1000info->bootmode == 1) 429 if ( pft1000info->bootmode == 1)
430 { 430 {
431 status = fix_ft1000_read_dpram32(ft1000dev, DWNLD_MAG1_SIZE_LOC, (PUCHAR)&value); 431 status = fix_ft1000_read_dpram32(ft1000dev, DWNLD_MAG1_SIZE_LOC, (u8 *)&value);
432 value = ntohl(value); 432 value = ntohl(value);
433 } 433 }
434 else 434 else
435 { 435 {
436 status = ft1000_read_dpram16(ft1000dev, DWNLD_MAG1_SIZE_LOC, (PUCHAR)&tempword, 0); 436 status = ft1000_read_dpram16(ft1000dev, DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 0);
437 value = tempword; 437 value = tempword;
438 status = ft1000_read_dpram16(ft1000dev, DWNLD_MAG1_SIZE_LOC, (PUCHAR)&tempword, 1); 438 status = ft1000_read_dpram16(ft1000dev, DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 1);
439 value |= (tempword << 16); 439 value |= (tempword << 16);
440 value = ntohl(value); 440 value = ntohl(value);
441 } 441 }
@@ -449,9 +449,9 @@ static long get_request_value(struct ft1000_device *ft1000dev)
449#if 0 449#if 0
450static long get_request_value_usb(struct ft1000_device *ft1000dev) 450static long get_request_value_usb(struct ft1000_device *ft1000dev)
451{ 451{
452 ULONG value; 452 u32 value;
453 USHORT tempword; 453 u16 tempword;
454 ULONG status; 454 u32 status;
455 struct ft1000_info * pft1000info = netdev_priv(ft1000dev->net); 455 struct ft1000_info * pft1000info = netdev_priv(ft1000dev->net);
456 456
457 if (pft1000info->usbboot == 2) { 457 if (pft1000info->usbboot == 2) {
@@ -460,7 +460,7 @@ static long get_request_value_usb(struct ft1000_device *ft1000dev)
460 } 460 }
461 else { 461 else {
462 value = 0; 462 value = 0;
463 status = ft1000_read_dpram16(ft1000dev, DWNLD_MAG1_SIZE_LOC, (PUCHAR)&tempword, 1); 463 status = ft1000_read_dpram16(ft1000dev, DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 1);
464 } 464 }
465 465
466 value |= (tempword << 16); 466 value |= (tempword << 16);
@@ -490,11 +490,11 @@ static long get_request_value_usb(struct ft1000_device *ft1000dev)
490//--------------------------------------------------------------------------- 490//---------------------------------------------------------------------------
491static void put_request_value(struct ft1000_device *ft1000dev, long lvalue) 491static void put_request_value(struct ft1000_device *ft1000dev, long lvalue)
492{ 492{
493 ULONG tempx; 493 u32 tempx;
494 ULONG status; 494 u32 status;
495 495
496 tempx = ntohl(lvalue); 496 tempx = ntohl(lvalue);
497 status = fix_ft1000_write_dpram32(ft1000dev, DWNLD_MAG1_SIZE_LOC, (PUCHAR)&tempx); 497 status = fix_ft1000_write_dpram32(ft1000dev, DWNLD_MAG1_SIZE_LOC, (u8 *)&tempx);
498 498
499 499
500 500
@@ -516,10 +516,10 @@ static void put_request_value(struct ft1000_device *ft1000dev, long lvalue)
516// Notes: 516// Notes:
517// 517//
518//--------------------------------------------------------------------------- 518//---------------------------------------------------------------------------
519static USHORT hdr_checksum(struct pseudo_hdr *pHdr) 519static u16 hdr_checksum(struct pseudo_hdr *pHdr)
520{ 520{
521 USHORT *usPtr = (USHORT *)pHdr; 521 u16 *usPtr = (u16 *)pHdr;
522 USHORT chksum; 522 u16 chksum;
523 523
524 524
525 chksum = ((((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^ 525 chksum = ((((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^
@@ -533,8 +533,8 @@ static USHORT hdr_checksum(struct pseudo_hdr *pHdr)
533// Function: write_blk 533// Function: write_blk
534// 534//
535// Parameters: struct ft1000_device - device structure 535// Parameters: struct ft1000_device - device structure
536// USHORT **pUsFile - DSP image file pointer in USHORT 536// u16 **pUsFile - DSP image file pointer in u16
537// UCHAR **pUcFile - DSP image file pointer in UCHAR 537// u8 **pUcFile - DSP image file pointer in u8
538// long word_length - lenght of the buffer to be written 538// long word_length - lenght of the buffer to be written
539// to DPRAM 539// to DPRAM
540// 540//
@@ -546,20 +546,20 @@ static USHORT hdr_checksum(struct pseudo_hdr *pHdr)
546// Notes: 546// Notes:
547// 547//
548//--------------------------------------------------------------------------- 548//---------------------------------------------------------------------------
549static ULONG write_blk (struct ft1000_device *ft1000dev, USHORT **pUsFile, UCHAR **pUcFile, long word_length) 549static u32 write_blk (struct ft1000_device *ft1000dev, u16 **pUsFile, u8 **pUcFile, long word_length)
550{ 550{
551 ULONG Status = STATUS_SUCCESS; 551 u32 Status = STATUS_SUCCESS;
552 USHORT dpram; 552 u16 dpram;
553 long temp_word_length; 553 long temp_word_length;
554 int loopcnt, i, j; 554 int loopcnt, i, j;
555 USHORT *pTempFile; 555 u16 *pTempFile;
556 USHORT tempword; 556 u16 tempword;
557 USHORT tempbuffer[64]; 557 u16 tempbuffer[64];
558 USHORT resultbuffer[64]; 558 u16 resultbuffer[64];
559 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); 559 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
560 560
561 //DEBUG("FT1000:download:start word_length = %d\n",(int)word_length); 561 //DEBUG("FT1000:download:start word_length = %d\n",(int)word_length);
562 dpram = (USHORT)DWNLD_MAG1_PS_HDR_LOC; 562 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
563 tempword = *(*pUsFile); 563 tempword = *(*pUsFile);
564 (*pUsFile)++; 564 (*pUsFile)++;
565 Status = ft1000_write_dpram16(ft1000dev, dpram, tempword, 0); 565 Status = ft1000_write_dpram16(ft1000dev, dpram, tempword, 0);
@@ -569,7 +569,7 @@ static ULONG write_blk (struct ft1000_device *ft1000dev, USHORT **pUsFile, UCHAR
569 569
570 *pUcFile = *pUcFile + 4; 570 *pUcFile = *pUcFile + 4;
571 word_length--; 571 word_length--;
572 tempword = (USHORT)word_length; 572 tempword = (u16)word_length;
573 word_length = (word_length / 16) + 1; 573 word_length = (word_length / 16) + 1;
574 pTempFile = *pUsFile; 574 pTempFile = *pUsFile;
575 temp_word_length = word_length; 575 temp_word_length = word_length;
@@ -602,24 +602,24 @@ static ULONG write_blk (struct ft1000_device *ft1000dev, USHORT **pUsFile, UCHAR
602 if (pft1000info->bootmode == 0) 602 if (pft1000info->bootmode == 0)
603 { 603 {
604 if (dpram >= 0x3F4) 604 if (dpram >= 0x3F4)
605 Status = ft1000_write_dpram32 (ft1000dev, dpram, (PUCHAR)&tempbuffer[0], 8); 605 Status = ft1000_write_dpram32 (ft1000dev, dpram, (u8 *)&tempbuffer[0], 8);
606 else 606 else
607 Status = ft1000_write_dpram32 (ft1000dev, dpram, (PUCHAR)&tempbuffer[0], 64); 607 Status = ft1000_write_dpram32 (ft1000dev, dpram, (u8 *)&tempbuffer[0], 64);
608 } 608 }
609 else 609 else
610 { 610 {
611 for (j=0; j<10; j++) 611 for (j=0; j<10; j++)
612 { 612 {
613 Status = ft1000_write_dpram32 (ft1000dev, dpram, (PUCHAR)&tempbuffer[0], 64); 613 Status = ft1000_write_dpram32 (ft1000dev, dpram, (u8 *)&tempbuffer[0], 64);
614 if (Status == STATUS_SUCCESS) 614 if (Status == STATUS_SUCCESS)
615 { 615 {
616 // Work around for ASIC bit stuffing problem. 616 // Work around for ASIC bit stuffing problem.
617 if ( (tempbuffer[31] & 0xfe00) == 0xfe00) 617 if ( (tempbuffer[31] & 0xfe00) == 0xfe00)
618 { 618 {
619 Status = ft1000_write_dpram32(ft1000dev, dpram+12, (PUCHAR)&tempbuffer[24], 64); 619 Status = ft1000_write_dpram32(ft1000dev, dpram+12, (u8 *)&tempbuffer[24], 64);
620 } 620 }
621 // Let's check the data written 621 // Let's check the data written
622 Status = ft1000_read_dpram32 (ft1000dev, dpram, (PUCHAR)&resultbuffer[0], 64); 622 Status = ft1000_read_dpram32 (ft1000dev, dpram, (u8 *)&resultbuffer[0], 64);
623 if ( (tempbuffer[31] & 0xfe00) == 0xfe00) 623 if ( (tempbuffer[31] & 0xfe00) == 0xfe00)
624 { 624 {
625 for (i=0; i<28; i++) 625 for (i=0; i<28; i++)
@@ -633,7 +633,7 @@ static ULONG write_blk (struct ft1000_device *ft1000dev, USHORT **pUsFile, UCHAR
633 break; 633 break;
634 } 634 }
635 } 635 }
636 Status = ft1000_read_dpram32 (ft1000dev, dpram+12, (PUCHAR)&resultbuffer[0], 64); 636 Status = ft1000_read_dpram32 (ft1000dev, dpram+12, (u8 *)&resultbuffer[0], 64);
637 for (i=0; i<16; i++) 637 for (i=0; i<16; i++)
638 { 638 {
639 if (resultbuffer[i] != tempbuffer[i+24]) 639 if (resultbuffer[i] != tempbuffer[i+24])
@@ -689,8 +689,8 @@ static void usb_dnld_complete (struct urb *urb)
689// Function: write_blk_fifo 689// Function: write_blk_fifo
690// 690//
691// Parameters: struct ft1000_device - device structure 691// Parameters: struct ft1000_device - device structure
692// USHORT **pUsFile - DSP image file pointer in USHORT 692// u16 **pUsFile - DSP image file pointer in u16
693// UCHAR **pUcFile - DSP image file pointer in UCHAR 693// u8 **pUcFile - DSP image file pointer in u8
694// long word_length - lenght of the buffer to be written 694// long word_length - lenght of the buffer to be written
695// to DPRAM 695// to DPRAM
696// 696//
@@ -702,9 +702,9 @@ static void usb_dnld_complete (struct urb *urb)
702// Notes: 702// Notes:
703// 703//
704//--------------------------------------------------------------------------- 704//---------------------------------------------------------------------------
705static ULONG write_blk_fifo (struct ft1000_device *ft1000dev, USHORT **pUsFile, UCHAR **pUcFile, long word_length) 705static u32 write_blk_fifo (struct ft1000_device *ft1000dev, u16 **pUsFile, u8 **pUcFile, long word_length)
706{ 706{
707 ULONG Status = STATUS_SUCCESS; 707 u32 Status = STATUS_SUCCESS;
708 int byte_length; 708 int byte_length;
709 long aligncnt; 709 long aligncnt;
710 710
@@ -770,36 +770,36 @@ static ULONG write_blk_fifo (struct ft1000_device *ft1000dev, USHORT **pUsFile,
770// Returns: status - return code 770// Returns: status - return code
771//--------------------------------------------------------------------------- 771//---------------------------------------------------------------------------
772 772
773u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLength) 773u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, u32 FileLength)
774{ 774{
775 u16 Status = STATUS_SUCCESS; 775 u16 status = STATUS_SUCCESS;
776 UINT uiState; 776 u32 state;
777 USHORT handshake; 777 u16 handshake;
778 struct pseudo_hdr *pHdr; 778 struct pseudo_hdr *pseudo_header;
779 USHORT usHdrLength; 779 u16 pseudo_header_len;
780 long word_length; 780 long word_length;
781 USHORT request; 781 u16 request;
782 USHORT temp; 782 u16 temp;
783 USHORT tempword; 783 u16 tempword;
784 784
785 struct dsp_file_hdr *pFileHdr5; 785 struct dsp_file_hdr *file_hdr;
786 struct dsp_image_info *pDspImageInfoV6 = NULL; 786 struct dsp_image_info *dsp_img_info = NULL;
787 long requested_version; 787 long requested_version;
788 BOOLEAN bGoodVersion; 788 bool correct_version;
789 struct drv_msg *pMailBoxData; 789 struct drv_msg *mailbox_data;
790 USHORT *pUsData = NULL; 790 u16 *data = NULL;
791 USHORT *pUsFile = NULL; 791 u16 *s_file = NULL;
792 UCHAR *pUcFile = NULL; 792 u8 *c_file = NULL;
793 UCHAR *pBootEnd = NULL, *pCodeEnd= NULL; 793 u8 *boot_end = NULL, *code_end= NULL;
794 int imageN; 794 int image;
795 long loader_code_address, loader_code_size = 0; 795 long loader_code_address, loader_code_size = 0;
796 long run_address = 0, run_size = 0; 796 long run_address = 0, run_size = 0;
797 797
798 ULONG templong; 798 u32 templong;
799 ULONG image_chksum = 0; 799 u32 image_chksum = 0;
800 800
801 USHORT dpram = 0; 801 u16 dpram = 0;
802 PUCHAR pbuffer; 802 u8 *pbuffer;
803 struct prov_record *pprov_record; 803 struct prov_record *pprov_record;
804 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); 804 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
805 805
@@ -814,24 +814,24 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
814 // Get version id of file, at first 4 bytes of file, for newer files. 814 // Get version id of file, at first 4 bytes of file, for newer files.
815 // 815 //
816 816
817 uiState = STATE_START_DWNLD; 817 state = STATE_START_DWNLD;
818 818
819 pFileHdr5 = (struct dsp_file_hdr *)pFileStart; 819 file_hdr = (struct dsp_file_hdr *)pFileStart;
820 820
821 ft1000_write_register (ft1000dev, 0x800, FT1000_REG_MAG_WATERMARK); 821 ft1000_write_register (ft1000dev, 0x800, FT1000_REG_MAG_WATERMARK);
822 822
823 pUsFile = (USHORT *)(pFileStart + pFileHdr5->loader_offset); 823 s_file = (u16 *)(pFileStart + file_hdr->loader_offset);
824 pUcFile = (UCHAR *)(pFileStart + pFileHdr5->loader_offset); 824 c_file = (u8 *)(pFileStart + file_hdr->loader_offset);
825 825
826 pBootEnd = (UCHAR *)(pFileStart + pFileHdr5->loader_code_end); 826 boot_end = (u8 *)(pFileStart + file_hdr->loader_code_end);
827 827
828 loader_code_address = pFileHdr5->loader_code_address; 828 loader_code_address = file_hdr->loader_code_address;
829 loader_code_size = pFileHdr5->loader_code_size; 829 loader_code_size = file_hdr->loader_code_size;
830 bGoodVersion = FALSE; 830 correct_version = FALSE;
831 831
832 while ((Status == STATUS_SUCCESS) && (uiState != STATE_DONE_FILE)) 832 while ((status == STATUS_SUCCESS) && (state != STATE_DONE_FILE))
833 { 833 {
834 switch (uiState) 834 switch (state)
835 { 835 {
836 case STATE_START_DWNLD: 836 case STATE_START_DWNLD:
837 DEBUG("FT1000:STATE_START_DWNLD\n"); 837 DEBUG("FT1000:STATE_START_DWNLD\n");
@@ -848,10 +848,10 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
848 else 848 else
849 { 849 {
850 DEBUG("FT1000:download:Download error: Handshake failed\n"); 850 DEBUG("FT1000:download:Download error: Handshake failed\n");
851 Status = STATUS_FAILURE; 851 status = STATUS_FAILURE;
852 } 852 }
853 853
854 uiState = STATE_BOOT_DWNLD; 854 state = STATE_BOOT_DWNLD;
855 855
856 break; 856 break;
857 857
@@ -878,11 +878,11 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
878 case REQUEST_DONE_BL: 878 case REQUEST_DONE_BL:
879 DEBUG("FT1000:REQUEST_DONE_BL\n"); 879 DEBUG("FT1000:REQUEST_DONE_BL\n");
880 /* Reposition ptrs to beginning of code section */ 880 /* Reposition ptrs to beginning of code section */
881 pUsFile = (USHORT *)(pBootEnd); 881 s_file = (u16 *)(boot_end);
882 pUcFile = (UCHAR *)(pBootEnd); 882 c_file = (u8 *)(boot_end);
883 //DEBUG("FT1000:download:pUsFile = 0x%8x\n", (int)pUsFile); 883 //DEBUG("FT1000:download:s_file = 0x%8x\n", (int)s_file);
884 //DEBUG("FT1000:download:pUcFile = 0x%8x\n", (int)pUcFile); 884 //DEBUG("FT1000:download:c_file = 0x%8x\n", (int)c_file);
885 uiState = STATE_CODE_DWNLD; 885 state = STATE_CODE_DWNLD;
886 pft1000info->fcodeldr = 1; 886 pft1000info->fcodeldr = 1;
887 break; 887 break;
888 case REQUEST_CODE_SEGMENT: 888 case REQUEST_CODE_SEGMENT:
@@ -893,33 +893,33 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
893 if (word_length > MAX_LENGTH) 893 if (word_length > MAX_LENGTH)
894 { 894 {
895 DEBUG("FT1000:download:Download error: Max length exceeded\n"); 895 DEBUG("FT1000:download:Download error: Max length exceeded\n");
896 Status = STATUS_FAILURE; 896 status = STATUS_FAILURE;
897 break; 897 break;
898 } 898 }
899 if ( (word_length*2 + pUcFile) > pBootEnd) 899 if ( (word_length*2 + c_file) > boot_end)
900 { 900 {
901 /* 901 /*
902 * Error, beyond boot code range. 902 * Error, beyond boot code range.
903 */ 903 */
904 DEBUG("FT1000:download:Download error: Requested len=%d exceeds BOOT code boundry.\n", 904 DEBUG("FT1000:download:Download error: Requested len=%d exceeds BOOT code boundry.\n",
905 (int)word_length); 905 (int)word_length);
906 Status = STATUS_FAILURE; 906 status = STATUS_FAILURE;
907 break; 907 break;
908 } 908 }
909 /* 909 /*
910 * Position ASIC DPRAM auto-increment pointer. 910 * Position ASIC DPRAM auto-increment pointer.
911 */ 911 */
912 dpram = (USHORT)DWNLD_MAG1_PS_HDR_LOC; 912 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
913 if (word_length & 0x1) 913 if (word_length & 0x1)
914 word_length++; 914 word_length++;
915 word_length = word_length / 2; 915 word_length = word_length / 2;
916 916
917 Status = write_blk(ft1000dev, &pUsFile, &pUcFile, word_length); 917 status = write_blk(ft1000dev, &s_file, &c_file, word_length);
918 //DEBUG("write_blk returned %d\n", Status); 918 //DEBUG("write_blk returned %d\n", status);
919 break; 919 break;
920 default: 920 default:
921 DEBUG("FT1000:download:Download error: Bad request type=%d in BOOT download state.\n",request); 921 DEBUG("FT1000:download:Download error: Bad request type=%d in BOOT download state.\n",request);
922 Status = STATUS_FAILURE; 922 status = STATUS_FAILURE;
923 break; 923 break;
924 } 924 }
925 if (pft1000info->usbboot) 925 if (pft1000info->usbboot)
@@ -930,7 +930,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
930 else 930 else
931 { 931 {
932 DEBUG("FT1000:download:Download error: Handshake failed\n"); 932 DEBUG("FT1000:download:Download error: Handshake failed\n");
933 Status = STATUS_FAILURE; 933 status = STATUS_FAILURE;
934 } 934 }
935 935
936 break; 936 break;
@@ -959,7 +959,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
959 break; 959 break;
960 case REQUEST_RUN_ADDRESS: 960 case REQUEST_RUN_ADDRESS:
961 DEBUG("FT1000:download: REQUEST_RUN_ADDRESS\n"); 961 DEBUG("FT1000:download: REQUEST_RUN_ADDRESS\n");
962 if (bGoodVersion) 962 if (correct_version)
963 { 963 {
964 DEBUG("FT1000:download:run_address = 0x%8x\n", (int)run_address); 964 DEBUG("FT1000:download:run_address = 0x%8x\n", (int)run_address);
965 put_request_value(ft1000dev, run_address); 965 put_request_value(ft1000dev, run_address);
@@ -967,13 +967,13 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
967 else 967 else
968 { 968 {
969 DEBUG("FT1000:download:Download error: Got Run address request before image offset request.\n"); 969 DEBUG("FT1000:download:Download error: Got Run address request before image offset request.\n");
970 Status = STATUS_FAILURE; 970 status = STATUS_FAILURE;
971 break; 971 break;
972 } 972 }
973 break; 973 break;
974 case REQUEST_CODE_LENGTH: 974 case REQUEST_CODE_LENGTH:
975 DEBUG("FT1000:download:REQUEST_CODE_LENGTH\n"); 975 DEBUG("FT1000:download:REQUEST_CODE_LENGTH\n");
976 if (bGoodVersion) 976 if (correct_version)
977 { 977 {
978 DEBUG("FT1000:download:run_size = 0x%8x\n", (int)run_size); 978 DEBUG("FT1000:download:run_size = 0x%8x\n", (int)run_size);
979 put_request_value(ft1000dev, run_size); 979 put_request_value(ft1000dev, run_size);
@@ -981,23 +981,23 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
981 else 981 else
982 { 982 {
983 DEBUG("FT1000:download:Download error: Got Size request before image offset request.\n"); 983 DEBUG("FT1000:download:Download error: Got Size request before image offset request.\n");
984 Status = STATUS_FAILURE; 984 status = STATUS_FAILURE;
985 break; 985 break;
986 } 986 }
987 break; 987 break;
988 case REQUEST_DONE_CL: 988 case REQUEST_DONE_CL:
989 pft1000info->usbboot = 3; 989 pft1000info->usbboot = 3;
990 /* Reposition ptrs to beginning of provisioning section */ 990 /* Reposition ptrs to beginning of provisioning section */
991 pUsFile = (USHORT *)(pFileStart + pFileHdr5->commands_offset); 991 s_file = (u16 *)(pFileStart + file_hdr->commands_offset);
992 pUcFile = (UCHAR *)(pFileStart + pFileHdr5->commands_offset); 992 c_file = (u8 *)(pFileStart + file_hdr->commands_offset);
993 uiState = STATE_DONE_DWNLD; 993 state = STATE_DONE_DWNLD;
994 break; 994 break;
995 case REQUEST_CODE_SEGMENT: 995 case REQUEST_CODE_SEGMENT:
996 //DEBUG("FT1000:download: REQUEST_CODE_SEGMENT - CODELOADER\n"); 996 //DEBUG("FT1000:download: REQUEST_CODE_SEGMENT - CODELOADER\n");
997 if (!bGoodVersion) 997 if (!correct_version)
998 { 998 {
999 DEBUG("FT1000:download:Download error: Got Code Segment request before image offset request.\n"); 999 DEBUG("FT1000:download:Download error: Got Code Segment request before image offset request.\n");
1000 Status = STATUS_FAILURE; 1000 status = STATUS_FAILURE;
1001 break; 1001 break;
1002 } 1002 }
1003#if 0 1003#if 0
@@ -1011,28 +1011,28 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
1011#endif 1011#endif
1012 { 1012 {
1013 DEBUG("FT1000:download:Download error: Max length exceeded\n"); 1013 DEBUG("FT1000:download:Download error: Max length exceeded\n");
1014 Status = STATUS_FAILURE; 1014 status = STATUS_FAILURE;
1015 break; 1015 break;
1016 } 1016 }
1017 if ( (word_length*2 + pUcFile) > pCodeEnd) 1017 if ( (word_length*2 + c_file) > code_end)
1018 { 1018 {
1019 /* 1019 /*
1020 * Error, beyond boot code range. 1020 * Error, beyond boot code range.
1021 */ 1021 */
1022 DEBUG("FT1000:download:Download error: Requested len=%d exceeds DSP code boundry.\n", 1022 DEBUG("FT1000:download:Download error: Requested len=%d exceeds DSP code boundry.\n",
1023 (int)word_length); 1023 (int)word_length);
1024 Status = STATUS_FAILURE; 1024 status = STATUS_FAILURE;
1025 break; 1025 break;
1026 } 1026 }
1027 /* 1027 /*
1028 * Position ASIC DPRAM auto-increment pointer. 1028 * Position ASIC DPRAM auto-increment pointer.
1029 */ 1029 */
1030 dpram = (USHORT)DWNLD_MAG1_PS_HDR_LOC; 1030 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
1031 if (word_length & 0x1) 1031 if (word_length & 0x1)
1032 word_length++; 1032 word_length++;
1033 word_length = word_length / 2; 1033 word_length = word_length / 2;
1034 1034
1035 write_blk_fifo (ft1000dev, &pUsFile, &pUcFile, word_length); 1035 write_blk_fifo (ft1000dev, &s_file, &c_file, word_length);
1036 if (pft1000info->usbboot == 0) 1036 if (pft1000info->usbboot == 0)
1037 pft1000info->usbboot++; 1037 pft1000info->usbboot++;
1038 if (pft1000info->usbboot == 1) { 1038 if (pft1000info->usbboot == 1) {
@@ -1047,14 +1047,14 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
1047 // Convert length from byte count to word count. Make sure we round up. 1047 // Convert length from byte count to word count. Make sure we round up.
1048 word_length = (long)(pft1000info->DSPInfoBlklen + 1)/2; 1048 word_length = (long)(pft1000info->DSPInfoBlklen + 1)/2;
1049 put_request_value(ft1000dev, word_length); 1049 put_request_value(ft1000dev, word_length);
1050 pMailBoxData = (struct drv_msg *)&(pft1000info->DSPInfoBlk[0]); 1050 mailbox_data = (struct drv_msg *)&(pft1000info->DSPInfoBlk[0]);
1051 /* 1051 /*
1052 * Position ASIC DPRAM auto-increment pointer. 1052 * Position ASIC DPRAM auto-increment pointer.
1053 */ 1053 */
1054 1054
1055 1055
1056 pUsData = (USHORT *)&pMailBoxData->data[0]; 1056 data = (u16 *)&mailbox_data->data[0];
1057 dpram = (USHORT)DWNLD_MAG1_PS_HDR_LOC; 1057 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
1058 if (word_length & 0x1) 1058 if (word_length & 0x1)
1059 word_length++; 1059 word_length++;
1060 1060
@@ -1064,25 +1064,25 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
1064 for (; word_length > 0; word_length--) /* In words */ 1064 for (; word_length > 0; word_length--) /* In words */
1065 { 1065 {
1066 1066
1067 templong = *pUsData++; 1067 templong = *data++;
1068 templong |= (*pUsData++ << 16); 1068 templong |= (*data++ << 16);
1069 Status = fix_ft1000_write_dpram32 (ft1000dev, dpram++, (PUCHAR)&templong); 1069 status = fix_ft1000_write_dpram32 (ft1000dev, dpram++, (u8 *)&templong);
1070 1070
1071 } 1071 }
1072 break; 1072 break;
1073 1073
1074 case REQUEST_VERSION_INFO: 1074 case REQUEST_VERSION_INFO:
1075 DEBUG("FT1000:download:REQUEST_VERSION_INFO\n"); 1075 DEBUG("FT1000:download:REQUEST_VERSION_INFO\n");
1076 word_length = pFileHdr5->version_data_size; 1076 word_length = file_hdr->version_data_size;
1077 put_request_value(ft1000dev, word_length); 1077 put_request_value(ft1000dev, word_length);
1078 /* 1078 /*
1079 * Position ASIC DPRAM auto-increment pointer. 1079 * Position ASIC DPRAM auto-increment pointer.
1080 */ 1080 */
1081 1081
1082 pUsFile = (USHORT *)(pFileStart + pFileHdr5->version_data_offset); 1082 s_file = (u16 *)(pFileStart + file_hdr->version_data_offset);
1083 1083
1084 1084
1085 dpram = (USHORT)DWNLD_MAG1_PS_HDR_LOC; 1085 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
1086 if (word_length & 0x1) 1086 if (word_length & 0x1)
1087 word_length++; 1087 word_length++;
1088 1088
@@ -1092,59 +1092,59 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
1092 for (; word_length > 0; word_length--) /* In words */ 1092 for (; word_length > 0; word_length--) /* In words */
1093 { 1093 {
1094 1094
1095 templong = ntohs(*pUsFile++); 1095 templong = ntohs(*s_file++);
1096 temp = ntohs(*pUsFile++); 1096 temp = ntohs(*s_file++);
1097 templong |= (temp << 16); 1097 templong |= (temp << 16);
1098 Status = fix_ft1000_write_dpram32 (ft1000dev, dpram++, (PUCHAR)&templong); 1098 status = fix_ft1000_write_dpram32 (ft1000dev, dpram++, (u8 *)&templong);
1099 1099
1100 } 1100 }
1101 break; 1101 break;
1102 1102
1103 case REQUEST_CODE_BY_VERSION: 1103 case REQUEST_CODE_BY_VERSION:
1104 DEBUG("FT1000:download:REQUEST_CODE_BY_VERSION\n"); 1104 DEBUG("FT1000:download:REQUEST_CODE_BY_VERSION\n");
1105 bGoodVersion = FALSE; 1105 correct_version = FALSE;
1106 requested_version = get_request_value(ft1000dev); 1106 requested_version = get_request_value(ft1000dev);
1107 1107
1108 pDspImageInfoV6 = (struct dsp_image_info *)(pFileStart + sizeof(struct dsp_file_hdr )); 1108 dsp_img_info = (struct dsp_image_info *)(pFileStart + sizeof(struct dsp_file_hdr ));
1109 1109
1110 for (imageN = 0; imageN < pFileHdr5->nDspImages; imageN++) 1110 for (image = 0; image < file_hdr->nDspImages; image++)
1111 { 1111 {
1112 1112
1113 temp = (USHORT)(pDspImageInfoV6->version); 1113 temp = (u16)(dsp_img_info->version);
1114 templong = temp; 1114 templong = temp;
1115 temp = (USHORT)(pDspImageInfoV6->version >> 16); 1115 temp = (u16)(dsp_img_info->version >> 16);
1116 templong |= (temp << 16); 1116 templong |= (temp << 16);
1117 if (templong == (ULONG)requested_version) 1117 if (templong == (u32)requested_version)
1118 { 1118 {
1119 bGoodVersion = TRUE; 1119 correct_version = TRUE;
1120 DEBUG("FT1000:download: bGoodVersion is TRUE\n"); 1120 DEBUG("FT1000:download: correct_version is TRUE\n");
1121 pUsFile = (USHORT *)(pFileStart + pDspImageInfoV6->begin_offset); 1121 s_file = (u16 *)(pFileStart + dsp_img_info->begin_offset);
1122 pUcFile = (UCHAR *)(pFileStart + pDspImageInfoV6->begin_offset); 1122 c_file = (u8 *)(pFileStart + dsp_img_info->begin_offset);
1123 pCodeEnd = (UCHAR *)(pFileStart + pDspImageInfoV6->end_offset); 1123 code_end = (u8 *)(pFileStart + dsp_img_info->end_offset);
1124 run_address = pDspImageInfoV6->run_address; 1124 run_address = dsp_img_info->run_address;
1125 run_size = pDspImageInfoV6->image_size; 1125 run_size = dsp_img_info->image_size;
1126 image_chksum = (ULONG)pDspImageInfoV6->checksum; 1126 image_chksum = (u32)dsp_img_info->checksum;
1127 break; 1127 break;
1128 } 1128 }
1129 pDspImageInfoV6++; 1129 dsp_img_info++;
1130 1130
1131 1131
1132 } //end of for 1132 } //end of for
1133 1133
1134 if (!bGoodVersion) 1134 if (!correct_version)
1135 { 1135 {
1136 /* 1136 /*
1137 * Error, beyond boot code range. 1137 * Error, beyond boot code range.
1138 */ 1138 */
1139 DEBUG("FT1000:download:Download error: Bad Version Request = 0x%x.\n",(int)requested_version); 1139 DEBUG("FT1000:download:Download error: Bad Version Request = 0x%x.\n",(int)requested_version);
1140 Status = STATUS_FAILURE; 1140 status = STATUS_FAILURE;
1141 break; 1141 break;
1142 } 1142 }
1143 break; 1143 break;
1144 1144
1145 default: 1145 default:
1146 DEBUG("FT1000:download:Download error: Bad request type=%d in CODE download state.\n",request); 1146 DEBUG("FT1000:download:Download error: Bad request type=%d in CODE download state.\n",request);
1147 Status = STATUS_FAILURE; 1147 status = STATUS_FAILURE;
1148 break; 1148 break;
1149 } 1149 }
1150 if (pft1000info->usbboot) 1150 if (pft1000info->usbboot)
@@ -1155,94 +1155,94 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLe
1155 else 1155 else
1156 { 1156 {
1157 DEBUG("FT1000:download:Download error: Handshake failed\n"); 1157 DEBUG("FT1000:download:Download error: Handshake failed\n");
1158 Status = STATUS_FAILURE; 1158 status = STATUS_FAILURE;
1159 } 1159 }
1160 1160
1161 break; 1161 break;
1162 1162
1163 case STATE_DONE_DWNLD: 1163 case STATE_DONE_DWNLD:
1164 DEBUG("FT1000:download:Code loader is done...\n"); 1164 DEBUG("FT1000:download:Code loader is done...\n");
1165 uiState = STATE_SECTION_PROV; 1165 state = STATE_SECTION_PROV;
1166 break; 1166 break;
1167 1167
1168 case STATE_SECTION_PROV: 1168 case STATE_SECTION_PROV:
1169 DEBUG("FT1000:download:STATE_SECTION_PROV\n"); 1169 DEBUG("FT1000:download:STATE_SECTION_PROV\n");
1170 pHdr = (struct pseudo_hdr *)pUcFile; 1170 pseudo_header = (struct pseudo_hdr *)c_file;
1171 1171
1172 if (pHdr->checksum == hdr_checksum(pHdr)) 1172 if (pseudo_header->checksum == hdr_checksum(pseudo_header))
1173 { 1173 {
1174 if (pHdr->portdest != 0x80 /* Dsp OAM */) 1174 if (pseudo_header->portdest != 0x80 /* Dsp OAM */)
1175 { 1175 {
1176 uiState = STATE_DONE_PROV; 1176 state = STATE_DONE_PROV;
1177 break; 1177 break;
1178 } 1178 }
1179 usHdrLength = ntohs(pHdr->length); /* Byte length for PROV records */ 1179 pseudo_header_len = ntohs(pseudo_header->length); /* Byte length for PROV records */
1180 1180
1181 // Get buffer for provisioning data 1181 // Get buffer for provisioning data
1182 pbuffer = kmalloc((usHdrLength + sizeof(struct pseudo_hdr)), GFP_ATOMIC); 1182 pbuffer = kmalloc((pseudo_header_len + sizeof(struct pseudo_hdr)), GFP_ATOMIC);
1183 if (pbuffer) { 1183 if (pbuffer) {
1184 memcpy(pbuffer, (void *)pUcFile, (UINT)(usHdrLength + sizeof(struct pseudo_hdr))); 1184 memcpy(pbuffer, (void *)c_file, (u32)(pseudo_header_len + sizeof(struct pseudo_hdr)));
1185 // link provisioning data 1185 // link provisioning data
1186 pprov_record = kmalloc(sizeof(struct prov_record), GFP_ATOMIC); 1186 pprov_record = kmalloc(sizeof(struct prov_record), GFP_ATOMIC);
1187 if (pprov_record) { 1187 if (pprov_record) {
1188 pprov_record->pprov_data = pbuffer; 1188 pprov_record->pprov_data = pbuffer;
1189 list_add_tail (&pprov_record->list, &pft1000info->prov_list); 1189 list_add_tail (&pprov_record->list, &pft1000info->prov_list);
1190 // Move to next entry if available 1190 // Move to next entry if available
1191 pUcFile = (UCHAR *)((unsigned long)pUcFile + (UINT)((usHdrLength + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr)); 1191 c_file = (u8 *)((unsigned long)c_file + (u32)((pseudo_header_len + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr));
1192 if ( (unsigned long)(pUcFile) - (unsigned long)(pFileStart) >= (unsigned long)FileLength) { 1192 if ( (unsigned long)(c_file) - (unsigned long)(pFileStart) >= (unsigned long)FileLength) {
1193 uiState = STATE_DONE_FILE; 1193 state = STATE_DONE_FILE;
1194 } 1194 }
1195 } 1195 }
1196 else { 1196 else {
1197 kfree(pbuffer); 1197 kfree(pbuffer);
1198 Status = STATUS_FAILURE; 1198 status = STATUS_FAILURE;
1199 } 1199 }
1200 } 1200 }
1201 else { 1201 else {
1202 Status = STATUS_FAILURE; 1202 status = STATUS_FAILURE;
1203 } 1203 }
1204 } 1204 }
1205 else 1205 else
1206 { 1206 {
1207 /* Checksum did not compute */ 1207 /* Checksum did not compute */
1208 Status = STATUS_FAILURE; 1208 status = STATUS_FAILURE;
1209 } 1209 }
1210 DEBUG("ft1000:download: after STATE_SECTION_PROV, uiState = %d, Status= %d\n", uiState, Status); 1210 DEBUG("ft1000:download: after STATE_SECTION_PROV, state = %d, status= %d\n", state, status);
1211 break; 1211 break;
1212 1212
1213 case STATE_DONE_PROV: 1213 case STATE_DONE_PROV:
1214 DEBUG("FT1000:download:STATE_DONE_PROV\n"); 1214 DEBUG("FT1000:download:STATE_DONE_PROV\n");
1215 uiState = STATE_DONE_FILE; 1215 state = STATE_DONE_FILE;
1216 break; 1216 break;
1217 1217
1218 1218
1219 default: 1219 default:
1220 Status = STATUS_FAILURE; 1220 status = STATUS_FAILURE;
1221 break; 1221 break;
1222 } /* End Switch */ 1222 } /* End Switch */
1223 1223
1224 if (Status != STATUS_SUCCESS) { 1224 if (status != STATUS_SUCCESS) {
1225 break; 1225 break;
1226 } 1226 }
1227 1227
1228/**** 1228/****
1229 // Check if Card is present 1229 // Check if Card is present
1230 Status = Harley_Read_Register(&temp, FT1000_REG_SUP_IMASK); 1230 status = Harley_Read_Register(&temp, FT1000_REG_SUP_IMASK);
1231 if ( (Status != NDIS_STATUS_SUCCESS) || (temp == 0x0000) ) { 1231 if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0x0000) ) {
1232 break; 1232 break;
1233 } 1233 }
1234 1234
1235 Status = Harley_Read_Register(&temp, FT1000_REG_ASIC_ID); 1235 status = Harley_Read_Register(&temp, FT1000_REG_ASIC_ID);
1236 if ( (Status != NDIS_STATUS_SUCCESS) || (temp == 0xffff) ) { 1236 if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0xffff) ) {
1237 break; 1237 break;
1238 } 1238 }
1239****/ 1239****/
1240 1240
1241 } /* End while */ 1241 } /* End while */
1242 1242
1243 DEBUG("Download exiting with status = 0x%8x\n", Status); 1243 DEBUG("Download exiting with status = 0x%8x\n", status);
1244 ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX, FT1000_REG_DOORBELL); 1244 ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX, FT1000_REG_DOORBELL);
1245 1245
1246 return Status; 1246 return status;
1247} 1247}
1248 1248
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
index 5b89ee2a2971..643a63794ade 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
@@ -41,37 +41,9 @@ static int ft1000_chkcard (struct ft1000_device *dev);
41//Jim 41//Jim
42 42
43static u8 tempbuffer[1600]; 43static u8 tempbuffer[1600];
44static unsigned long gCardIndex;
45 44
46#define MAX_RCV_LOOP 100 45#define MAX_RCV_LOOP 100
47 46
48/****************************************************************
49 * ft1000_control_complete
50 ****************************************************************/
51static void ft1000_control_complete(struct urb *urb)
52{
53 struct ft1000_device *ft1000dev = (struct ft1000_device *)urb->context;
54
55 //DEBUG("FT1000_CONTROL_COMPLETE ENTERED\n");
56 if (ft1000dev == NULL )
57 {
58 DEBUG("NULL ft1000dev, failure\n");
59 return ;
60 }
61 else if ( ft1000dev->dev == NULL )
62 {
63 DEBUG("NULL ft1000dev->dev, failure\n");
64 return ;
65 }
66
67 if(waitqueue_active(&ft1000dev->control_wait))
68 {
69 wake_up(&ft1000dev->control_wait);
70 }
71
72 //DEBUG("FT1000_CONTROL_COMPLETE RETURNED\n");
73}
74
75//--------------------------------------------------------------------------- 47//---------------------------------------------------------------------------
76// Function: ft1000_control 48// Function: ft1000_control
77// 49//
@@ -187,7 +159,7 @@ u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegInd
187// Notes: 159// Notes:
188// 160//
189//--------------------------------------------------------------------------- 161//---------------------------------------------------------------------------
190u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRegIndx) 162u16 ft1000_write_register(struct ft1000_device *ft1000dev, u16 value, u16 nRegIndx)
191{ 163{
192 u16 ret = STATUS_SUCCESS; 164 u16 ret = STATUS_SUCCESS;
193 165
@@ -223,7 +195,7 @@ u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRe
223// 195//
224//--------------------------------------------------------------------------- 196//---------------------------------------------------------------------------
225 197
226u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt) 198u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, u16 cnt)
227{ 199{
228 u16 ret = STATUS_SUCCESS; 200 u16 ret = STATUS_SUCCESS;
229 201
@@ -262,7 +234,7 @@ u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buf
262// Notes: 234// Notes:
263// 235//
264//--------------------------------------------------------------------------- 236//---------------------------------------------------------------------------
265u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt) 237u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, u16 cnt)
266{ 238{
267 u16 ret = STATUS_SUCCESS; 239 u16 ret = STATUS_SUCCESS;
268 240
@@ -299,7 +271,7 @@ u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR bu
299// Notes: 271// Notes:
300// 272//
301//--------------------------------------------------------------------------- 273//---------------------------------------------------------------------------
302u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow) 274u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, u8 highlow)
303{ 275{
304 u16 ret = STATUS_SUCCESS; 276 u16 ret = STATUS_SUCCESS;
305 277
@@ -347,7 +319,7 @@ u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buf
347// Notes: 319// Notes:
348// 320//
349//--------------------------------------------------------------------------- 321//---------------------------------------------------------------------------
350u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT value, u8 highlow) 322u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u8 highlow)
351{ 323{
352 u16 ret = STATUS_SUCCESS; 324 u16 ret = STATUS_SUCCESS;
353 325
@@ -392,10 +364,10 @@ u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT va
392// Notes: 364// Notes:
393// 365//
394//--------------------------------------------------------------------------- 366//---------------------------------------------------------------------------
395u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer) 367u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer)
396{ 368{
397 UCHAR buf[16]; 369 u8 buf[16];
398 USHORT pos; 370 u16 pos;
399 u16 ret = STATUS_SUCCESS; 371 u16 ret = STATUS_SUCCESS;
400 372
401 //DEBUG("fix_ft1000_read_dpram32: indx: %d \n", indx); 373 //DEBUG("fix_ft1000_read_dpram32: indx: %d \n", indx);
@@ -441,14 +413,14 @@ u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR
441// Notes: 413// Notes:
442// 414//
443//--------------------------------------------------------------------------- 415//---------------------------------------------------------------------------
444u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer) 416u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer)
445{ 417{
446 USHORT pos1; 418 u16 pos1;
447 USHORT pos2; 419 u16 pos2;
448 USHORT i; 420 u16 i;
449 UCHAR buf[32]; 421 u8 buf[32];
450 UCHAR resultbuffer[32]; 422 u8 resultbuffer[32];
451 PUCHAR pdata; 423 u8 *pdata;
452 u16 ret = STATUS_SUCCESS; 424 u16 ret = STATUS_SUCCESS;
453 425
454 //DEBUG("fix_ft1000_write_dpram32: Entered:\n"); 426 //DEBUG("fix_ft1000_write_dpram32: Entered:\n");
@@ -472,7 +444,7 @@ u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHA
472 return ret; 444 return ret;
473 } 445 }
474 446
475 ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16); 447 ret = ft1000_read_dpram32(ft1000dev, pos1, (u8 *)&resultbuffer[0], 16);
476 if (ret == STATUS_SUCCESS) 448 if (ret == STATUS_SUCCESS)
477 { 449 {
478 buffer = pdata; 450 buffer = pdata;
@@ -487,8 +459,8 @@ u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHA
487 459
488 if (ret == STATUS_FAILURE) 460 if (ret == STATUS_FAILURE)
489 { 461 {
490 ret = ft1000_write_dpram32(ft1000dev, pos1, (PUCHAR)&tempbuffer[0], 16); 462 ret = ft1000_write_dpram32(ft1000dev, pos1, (u8 *)&tempbuffer[0], 16);
491 ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16); 463 ret = ft1000_read_dpram32(ft1000dev, pos1, (u8 *)&resultbuffer[0], 16);
492 if (ret == STATUS_SUCCESS) 464 if (ret == STATUS_SUCCESS)
493 { 465 {
494 buffer = pdata; 466 buffer = pdata;
@@ -518,10 +490,10 @@ u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHA
518// 490//
519// Returns: None 491// Returns: None
520//----------------------------------------------------------------------- 492//-----------------------------------------------------------------------
521static void card_reset_dsp (struct ft1000_device *ft1000dev, BOOLEAN value) 493static void card_reset_dsp (struct ft1000_device *ft1000dev, bool value)
522{ 494{
523 u16 status = STATUS_SUCCESS; 495 u16 status = STATUS_SUCCESS;
524 USHORT tempword; 496 u16 tempword;
525 497
526 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL); 498 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
527 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_CTRL); 499 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_CTRL);
@@ -620,8 +592,8 @@ void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int siz
620int dsp_reload(struct ft1000_device *ft1000dev) 592int dsp_reload(struct ft1000_device *ft1000dev)
621{ 593{
622 u16 status; 594 u16 status;
623 USHORT tempword; 595 u16 tempword;
624 ULONG templong; 596 u32 templong;
625 597
626 struct ft1000_info *pft1000info; 598 struct ft1000_info *pft1000info;
627 599
@@ -648,7 +620,7 @@ int dsp_reload(struct ft1000_device *ft1000dev)
648 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL); 620 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
649 621
650 // Let's check for FEFE 622 // Let's check for FEFE
651 status = ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (PUCHAR)&templong, 4); 623 status = ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (u8 *)&templong, 4);
652 DEBUG("templong (fefe) = 0x%8x\n", templong); 624 DEBUG("templong (fefe) = 0x%8x\n", templong);
653 625
654 // call codeloader 626 // call codeloader
@@ -753,7 +725,7 @@ static int ft1000_reset_card (struct net_device *dev)
753 725
754 // Initialize DSP heartbeat area to ho 726 // Initialize DSP heartbeat area to ho
755 ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag, FT1000_MAG_HI_HO_INDX); 727 ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag, FT1000_MAG_HI_HO_INDX);
756 ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (PCHAR)&tempword, FT1000_MAG_HI_HO_INDX); 728 ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (u8 *)&tempword, FT1000_MAG_HI_HO_INDX);
757 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword); 729 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword);
758 730
759 731
@@ -800,8 +772,7 @@ u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
800 int i, ret_val; 772 int i, ret_val;
801 struct list_head *cur, *tmp; 773 struct list_head *cur, *tmp;
802 char card_nr[2]; 774 char card_nr[2];
803 775 unsigned long gCardIndex = 0;
804 gCardIndex=0; //mbelian
805 776
806 DEBUG("Enter init_ft1000_netdev...\n"); 777 DEBUG("Enter init_ft1000_netdev...\n");
807 778
@@ -813,7 +784,7 @@ u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
813 return -ENOMEM; 784 return -ENOMEM;
814 } 785 }
815 786
816 pInfo = (struct ft1000_info *) netdev_priv(netdev); 787 pInfo = netdev_priv(netdev);
817 788
818 //DEBUG("init_ft1000_netdev: gFt1000Info=%x, netdev=%x, ft1000dev=%x\n", gFt1000Info, netdev, ft1000dev); 789 //DEBUG("init_ft1000_netdev: gFt1000Info=%x, netdev=%x, ft1000dev=%x\n", gFt1000Info, netdev, ft1000dev);
819 790
@@ -821,9 +792,6 @@ u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
821 792
822 dev_alloc_name(netdev, netdev->name); 793 dev_alloc_name(netdev, netdev->name);
823 794
824 //for the first inserted card, decide the card index beginning number, in case there are existing network interfaces
825 if ( gCardIndex == 0 )
826 {
827 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name); 795 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name);
828 796
829 if ( strncmp(netdev->name,"eth", 3) == 0) { 797 if ( strncmp(netdev->name,"eth", 3) == 0) {
@@ -843,13 +811,6 @@ u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
843 ret_val = -ENXIO; 811 ret_val = -ENXIO;
844 goto err_net; 812 goto err_net;
845 } 813 }
846 }
847 else
848 {
849 //not the first inserted card, increase card number by 1
850 pInfo->CardNumber = gCardIndex;
851 /*DEBUG("card number = %d\n", pInfo->CardNumber);*/ //mbelian
852 }
853 814
854 memset(&pInfo->stats, 0, sizeof(struct net_device_stats) ); 815 memset(&pInfo->stats, 0, sizeof(struct net_device_stats) );
855 816
@@ -862,7 +823,6 @@ u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
862 pInfo->mediastate = 0; 823 pInfo->mediastate = 0;
863 pInfo->fifo_cnt = 0; 824 pInfo->fifo_cnt = 0;
864 pInfo->DeviceCreated = FALSE; 825 pInfo->DeviceCreated = FALSE;
865 pInfo->DeviceMajor = 0;
866 pInfo->CurrentInterruptEnableMask = ISR_DEFAULT_MASK; 826 pInfo->CurrentInterruptEnableMask = ISR_DEFAULT_MASK;
867 pInfo->InterruptsEnabled = FALSE; 827 pInfo->InterruptsEnabled = FALSE;
868 pInfo->CardReady = 0; 828 pInfo->CardReady = 0;
@@ -874,13 +834,11 @@ u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
874 pInfo->fCondResetPend = 0; 834 pInfo->fCondResetPend = 0;
875 pInfo->usbboot = 0; 835 pInfo->usbboot = 0;
876 pInfo->dspalive = 0; 836 pInfo->dspalive = 0;
877 for (i=0;i<32 ;i++ ) 837 memset(&pInfo->tempbuf[0], 0, sizeof(pInfo->tempbuf));
878 {
879 pInfo->tempbuf[i] = 0;
880 }
881 838
882 INIT_LIST_HEAD(&pInfo->prov_list); 839 INIT_LIST_HEAD(&pInfo->prov_list);
883 840
841 INIT_LIST_HEAD(&pInfo->nodes.list);
884//mbelian 842//mbelian
885#ifdef HAVE_NET_DEVICE_OPS 843#ifdef HAVE_NET_DEVICE_OPS
886 netdev->netdev_ops = &ftnet_ops; 844 netdev->netdev_ops = &ftnet_ops;
@@ -982,7 +940,7 @@ int reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *int
982 940
983 941
984 //Create character device, implemented by Jim 942 //Create character device, implemented by Jim
985 ft1000_CreateDevice(ft1000dev); 943 ft1000_create_dev(ft1000dev);
986 944
987 DEBUG ("reg_ft1000_netdev returned\n"); 945 DEBUG ("reg_ft1000_netdev returned\n");
988 946
@@ -1026,178 +984,6 @@ static void ft1000_usb_transmit_complete(struct urb *urb)
1026 //DEBUG("Return from ft1000_usb_transmit_complete\n"); 984 //DEBUG("Return from ft1000_usb_transmit_complete\n");
1027} 985}
1028 986
1029
1030/****************************************************************
1031 * ft1000_control
1032 ****************************************************************/
1033static int ft1000_read_fifo_reg(struct ft1000_device *ft1000dev,unsigned int pipe,
1034 u8 request,
1035 u8 requesttype,
1036 u16 value,
1037 u16 index,
1038 void *data,
1039 u16 size,
1040 int timeout)
1041{
1042 u16 ret;
1043
1044 DECLARE_WAITQUEUE(wait, current);
1045 struct urb *urb;
1046 struct usb_ctrlrequest *dr;
1047 int status;
1048
1049 if (ft1000dev == NULL )
1050 {
1051 DEBUG("NULL ft1000dev, failure\n");
1052 return STATUS_FAILURE;
1053 }
1054 else if ( ft1000dev->dev == NULL )
1055 {
1056 DEBUG("NULL ft1000dev->dev, failure\n");
1057 return STATUS_FAILURE;
1058 }
1059
1060 spin_lock(&ft1000dev->device_lock);
1061
1062 if(in_interrupt())
1063 {
1064 spin_unlock(&ft1000dev->device_lock);
1065 return -EBUSY;
1066 }
1067
1068 urb = usb_alloc_urb(0, GFP_KERNEL);
1069 dr = kmalloc(sizeof(struct usb_ctrlrequest), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
1070
1071 if(!urb || !dr)
1072 {
1073 kfree(dr);
1074 usb_free_urb(urb);
1075 spin_unlock(&ft1000dev->device_lock);
1076 return -ENOMEM;
1077 }
1078
1079
1080
1081 dr->bRequestType = requesttype;
1082 dr->bRequest = request;
1083 dr->wValue = value;
1084 dr->wIndex = index;
1085 dr->wLength = size;
1086
1087 usb_fill_control_urb(urb, ft1000dev->dev, pipe, (char*)dr, (void*)data, size, (void *)ft1000_control_complete, (void*)ft1000dev);
1088
1089
1090 init_waitqueue_head(&ft1000dev->control_wait);
1091
1092 set_current_state(TASK_INTERRUPTIBLE);
1093
1094 add_wait_queue(&ft1000dev->control_wait, &wait);
1095
1096
1097
1098
1099 status = usb_submit_urb(urb, GFP_KERNEL);
1100
1101 if(status)
1102 {
1103 usb_free_urb(urb);
1104 kfree(dr);
1105 remove_wait_queue(&ft1000dev->control_wait, &wait);
1106 spin_unlock(&ft1000dev->device_lock);
1107 return status;
1108 }
1109
1110 if(urb->status == -EINPROGRESS)
1111 {
1112 while(timeout && urb->status == -EINPROGRESS)
1113 {
1114 status = timeout = schedule_timeout(timeout);
1115 }
1116 }
1117 else
1118 {
1119 status = 1;
1120 }
1121
1122 remove_wait_queue(&ft1000dev->control_wait, &wait);
1123
1124 if(!status)
1125 {
1126 usb_unlink_urb(urb);
1127 printk("ft1000 timeout\n");
1128 status = -ETIMEDOUT;
1129 }
1130 else
1131 {
1132 status = urb->status;
1133
1134 if(urb->status)
1135 {
1136 printk("ft1000 control message failed (urb addr: %p) with error number: %i\n", urb, (int)status);
1137
1138 usb_clear_halt(ft1000dev->dev, usb_rcvctrlpipe(ft1000dev->dev, 0));
1139 usb_clear_halt(ft1000dev->dev, usb_sndctrlpipe(ft1000dev->dev, 0));
1140 usb_unlink_urb(urb);
1141 }
1142 }
1143
1144
1145
1146 usb_free_urb(urb);
1147 kfree(dr);
1148 spin_unlock(&ft1000dev->device_lock);
1149 return ret;
1150
1151
1152}
1153
1154//---------------------------------------------------------------------------
1155// Function: ft1000_read_fifo_len
1156//
1157// Parameters: ft1000dev - device structure
1158//
1159//
1160// Returns: none
1161//
1162// Description: read the fifo length register content
1163//
1164// Notes:
1165//
1166//---------------------------------------------------------------------------
1167static inline u16 ft1000_read_fifo_len (struct net_device *dev)
1168{
1169 u16 temp;
1170 u16 ret;
1171
1172 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev);
1173 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1174// DEBUG("ft1000_read_fifo_len: enter ft1000dev %x\n", ft1000dev); //aelias [-] reason: warning: format ???%x??? expects type ???unsigned int???, but argument 2 has type ???struct ft1000_device *???
1175 DEBUG("ft1000_read_fifo_len: enter ft1000dev %p\n", ft1000dev); //aelias [+] reason: up
1176
1177 ret = STATUS_SUCCESS;
1178
1179 ret = ft1000_read_fifo_reg(ft1000dev,
1180 usb_rcvctrlpipe(ft1000dev->dev,0),
1181 HARLEY_READ_REGISTER,
1182 HARLEY_READ_OPERATION,
1183 0,
1184 FT1000_REG_MAG_UFSR,
1185 &temp,
1186 2,
1187 LARGE_TIMEOUT);
1188
1189 if (ret>0)
1190 ret = STATUS_SUCCESS;
1191 else
1192 ret = STATUS_FAILURE;
1193
1194 DEBUG("ft1000_read_fifo_len: returned %d\n", temp);
1195
1196 return (temp- 16);
1197
1198}
1199
1200
1201//--------------------------------------------------------------------------- 987//---------------------------------------------------------------------------
1202// 988//
1203// Function: ft1000_copy_down_pkt 989// Function: ft1000_copy_down_pkt
@@ -1219,16 +1005,15 @@ static int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len)
1219 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev; 1005 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
1220 1006
1221 1007
1222 int i, count, ret; 1008 int count, ret;
1223 USHORT *pTemp;
1224 USHORT checksum;
1225 u8 *t; 1009 u8 *t;
1010 struct pseudo_hdr hdr;
1226 1011
1227 if (!pInfo->CardReady) 1012 if (!pInfo->CardReady)
1228 { 1013 {
1229 1014
1230 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n"); 1015 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
1231 return STATUS_FAILURE; 1016 return -ENODEV;
1232 1017
1233 } 1018 }
1234 1019
@@ -1240,27 +1025,27 @@ static int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len)
1240 { 1025 {
1241 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n"); 1026 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n");
1242 DEBUG("size = %d\n", count); 1027 DEBUG("size = %d\n", count);
1243 return STATUS_FAILURE; 1028 return -EINVAL;
1244 } 1029 }
1245 1030
1246 if ( count % 4) 1031 if ( count % 4)
1247 count = count + (4- (count %4) ); 1032 count = count + (4- (count %4) );
1248 1033
1249 pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]); 1034 memset(&hdr, 0, sizeof(struct pseudo_hdr));
1250 *pTemp ++ = ntohs(count); 1035
1251 *pTemp ++ = 0x1020; 1036 hdr.length = ntohs(count);
1252 *pTemp ++ = 0x2010; 1037 hdr.source = 0x10;
1253 *pTemp ++ = 0x9100; 1038 hdr.destination = 0x20;
1254 *pTemp ++ = 0; 1039 hdr.portdest = 0x20;
1255 *pTemp ++ = 0; 1040 hdr.portsrc = 0x10;
1256 *pTemp ++ = 0; 1041 hdr.sh_str_id = 0x91;
1257 pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]); 1042 hdr.control = 0x00;
1258 checksum = *pTemp ++; 1043
1259 for (i=1; i<7; i++) 1044 hdr.checksum = hdr.length ^ hdr.source ^ hdr.destination ^
1260 { 1045 hdr.portdest ^ hdr.portsrc ^ hdr.sh_str_id ^
1261 checksum ^= *pTemp ++; 1046 hdr.control;
1262 } 1047
1263 *pTemp++ = checksum; 1048 memcpy(&pFt1000Dev->tx_buf[0], &hdr, sizeof(hdr));
1264 memcpy(&(pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)]), packet, len); 1049 memcpy(&(pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)]), packet, len);
1265 1050
1266 netif_stop_queue(netdev); 1051 netif_stop_queue(netdev);
@@ -1283,25 +1068,18 @@ static int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len)
1283 }*/ 1068 }*/
1284 1069
1285 1070
1286 ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC); 1071 ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC);
1287 if(ret) 1072 if (ret) {
1288 {
1289 DEBUG("ft1000 failed tx_urb %d\n", ret); 1073 DEBUG("ft1000 failed tx_urb %d\n", ret);
1290 1074 return ret;
1291 return STATUS_FAILURE; 1075 } else {
1292 1076 pInfo->stats.tx_packets++;
1293 } 1077 pInfo->stats.tx_bytes += (len+14);
1294 else 1078 }
1295 {
1296 //DEBUG("ft1000 sucess tx_urb %d\n", ret);
1297
1298 pInfo->stats.tx_packets++;
1299 pInfo->stats.tx_bytes += (len+14);
1300 }
1301 1079
1302 //DEBUG("ft1000_copy_down_pkt() exit\n"); 1080 //DEBUG("ft1000_copy_down_pkt() exit\n");
1303 1081
1304 return STATUS_SUCCESS; 1082 return 0;
1305} 1083}
1306 1084
1307//--------------------------------------------------------------------------- 1085//---------------------------------------------------------------------------
@@ -1331,14 +1109,13 @@ static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1331 if ( skb == NULL ) 1109 if ( skb == NULL )
1332 { 1110 {
1333 DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" ); 1111 DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" );
1334 return STATUS_FAILURE; 1112 return NETDEV_TX_OK;
1335 } 1113 }
1336 1114
1337 if ( pFt1000Dev->status & FT1000_STATUS_CLOSING) 1115 if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1338 { 1116 {
1339 DEBUG("network driver is closed, return\n"); 1117 DEBUG("network driver is closed, return\n");
1340 dev_kfree_skb(skb); 1118 goto err;
1341 return STATUS_SUCCESS;
1342 } 1119 }
1343 1120
1344 //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len); 1121 //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len);
@@ -1357,28 +1134,24 @@ static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1357 { 1134 {
1358 /* Drop packet is mediastate is down */ 1135 /* Drop packet is mediastate is down */
1359 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n"); 1136 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n");
1360 dev_kfree_skb(skb); 1137 goto err;
1361 return STATUS_SUCCESS;
1362 } 1138 }
1363 1139
1364 if ( (skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE) ) 1140 if ( (skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE) )
1365 { 1141 {
1366 /* Drop packet which has invalid size */ 1142 /* Drop packet which has invalid size */
1367 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n"); 1143 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n");
1368 dev_kfree_skb(skb); 1144 goto err;
1369 return STATUS_SUCCESS;
1370 } 1145 }
1371//mbelian 1146//mbelian
1372 if(ft1000_copy_down_pkt (dev, (pdata+ENET_HEADER_SIZE-2), skb->len - ENET_HEADER_SIZE + 2) == STATUS_FAILURE) 1147 ft1000_copy_down_pkt(dev, (pdata+ENET_HEADER_SIZE-2),
1373 { 1148 skb->len - ENET_HEADER_SIZE + 2);
1374 dev_kfree_skb(skb);
1375 return STATUS_SUCCESS;
1376 }
1377 1149
1378 dev_kfree_skb(skb); 1150err:
1151 dev_kfree_skb(skb);
1379 //DEBUG(" ft1000_start_xmit() exit\n"); 1152 //DEBUG(" ft1000_start_xmit() exit\n");
1380 1153
1381 return 0; 1154 return NETDEV_TX_OK;
1382} 1155}
1383 1156
1384//--------------------------------------------------------------------------- 1157//---------------------------------------------------------------------------
@@ -1424,7 +1197,7 @@ static int ft1000_copy_up_pkt (struct urb *urb)
1424 //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n", 1197 //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n",
1425 // urb->transfer_buffer_length, urb->actual_length); 1198 // urb->transfer_buffer_length, urb->actual_length);
1426 1199
1427 chksum = (PUSHORT)ft1000dev->rx_buf; 1200 chksum = (u16 *)ft1000dev->rx_buf;
1428 1201
1429 tempword = *chksum++; 1202 tempword = *chksum++;
1430 for (i=1; i<7; i++) 1203 for (i=1; i<7; i++)
@@ -1521,7 +1294,7 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info)
1521 { 1294 {
1522 DEBUG("network driver is closed, return\n"); 1295 DEBUG("network driver is closed, return\n");
1523 //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian 1296 //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian
1524 return STATUS_SUCCESS; 1297 return -ENODEV;
1525 } 1298 }
1526 1299
1527 usb_fill_bulk_urb(pFt1000Dev->rx_urb, 1300 usb_fill_bulk_urb(pFt1000Dev->rx_urb,
@@ -1536,12 +1309,12 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info)
1536 if((result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC))) 1309 if((result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC)))
1537 { 1310 {
1538 printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result); 1311 printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result);
1539 return STATUS_FAILURE; 1312 return result;
1540 } 1313 }
1541 1314
1542 //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result); 1315 //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result);
1543 1316
1544 return STATUS_SUCCESS; 1317 return 0;
1545} 1318}
1546 1319
1547//--------------------------------------------------------------------------- 1320//---------------------------------------------------------------------------
@@ -1560,8 +1333,9 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info)
1560//--------------------------------------------------------------------------- 1333//---------------------------------------------------------------------------
1561static int ft1000_open (struct net_device *dev) 1334static int ft1000_open (struct net_device *dev)
1562{ 1335{
1563 struct ft1000_info *pInfo = (struct ft1000_info *)netdev_priv(dev); 1336 struct ft1000_info *pInfo = netdev_priv(dev);
1564 struct timeval tv; //mbelian 1337 struct timeval tv; //mbelian
1338 int ret;
1565 1339
1566 DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber); 1340 DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber);
1567 //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len); 1341 //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len);
@@ -1579,8 +1353,9 @@ static int ft1000_open (struct net_device *dev)
1579 1353
1580 netif_carrier_on(dev); //mbelian 1354 netif_carrier_on(dev); //mbelian
1581 1355
1582 ft1000_submit_rx_urb(pInfo); 1356 ret = ft1000_submit_rx_urb(pInfo);
1583 return 0; 1357
1358 return ret;
1584} 1359}
1585 1360
1586//--------------------------------------------------------------------------- 1361//---------------------------------------------------------------------------
@@ -1599,7 +1374,7 @@ static int ft1000_open (struct net_device *dev)
1599//--------------------------------------------------------------------------- 1374//---------------------------------------------------------------------------
1600int ft1000_close(struct net_device *net) 1375int ft1000_close(struct net_device *net)
1601{ 1376{
1602 struct ft1000_info *pInfo = (struct ft1000_info *) netdev_priv(net); 1377 struct ft1000_info *pInfo = netdev_priv(net);
1603 struct ft1000_device *ft1000dev = pInfo->pFt1000Dev; 1378 struct ft1000_device *ft1000dev = pInfo->pFt1000Dev;
1604 1379
1605 //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt); 1380 //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt);
@@ -1622,7 +1397,7 @@ int ft1000_close(struct net_device *net)
1622 1397
1623static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev) 1398static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev)
1624{ 1399{
1625 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev); 1400 struct ft1000_info *info = netdev_priv(dev);
1626 1401
1627 return &(info->stats); //mbelian 1402 return &(info->stats); //mbelian
1628} 1403}
@@ -1648,7 +1423,7 @@ Jim
1648static int ft1000_chkcard (struct ft1000_device *dev) { 1423static int ft1000_chkcard (struct ft1000_device *dev) {
1649 u16 tempword; 1424 u16 tempword;
1650 u16 status; 1425 u16 status;
1651 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net); 1426 struct ft1000_info *info = netdev_priv(dev->net);
1652 1427
1653 if (info->fCondResetPend) 1428 if (info->fCondResetPend)
1654 { 1429 {
@@ -1692,13 +1467,13 @@ static int ft1000_chkcard (struct ft1000_device *dev) {
1692// = 1 (successful) 1467// = 1 (successful)
1693// 1468//
1694//--------------------------------------------------------------------------- 1469//---------------------------------------------------------------------------
1695static BOOLEAN ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) { 1470static bool ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) {
1696 u16 size, ret; 1471 u16 size, ret;
1697 u16 *ppseudohdr; 1472 u16 *ppseudohdr;
1698 int i; 1473 int i;
1699 u16 tempword; 1474 u16 tempword;
1700 1475
1701 ret = ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (PUCHAR)&size, FT1000_MAG_PH_LEN_INDX); 1476 ret = ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (u8 *)&size, FT1000_MAG_PH_LEN_INDX);
1702 size = ntohs(size) + PSEUDOSZ; 1477 size = ntohs(size) + PSEUDOSZ;
1703 if (size > maxsz) { 1478 if (size > maxsz) {
1704 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size); 1479 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size);
@@ -1748,15 +1523,15 @@ static BOOLEAN ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int
1748static int ft1000_dsp_prov(void *arg) 1523static int ft1000_dsp_prov(void *arg)
1749{ 1524{
1750 struct ft1000_device *dev = (struct ft1000_device *)arg; 1525 struct ft1000_device *dev = (struct ft1000_device *)arg;
1751 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net); 1526 struct ft1000_info *info = netdev_priv(dev->net);
1752 u16 tempword; 1527 u16 tempword;
1753 u16 len; 1528 u16 len;
1754 u16 i=0; 1529 u16 i=0;
1755 struct prov_record *ptr; 1530 struct prov_record *ptr;
1756 struct pseudo_hdr *ppseudo_hdr; 1531 struct pseudo_hdr *ppseudo_hdr;
1757 PUSHORT pmsg; 1532 u16 *pmsg;
1758 u16 status; 1533 u16 status;
1759 USHORT TempShortBuf [256]; 1534 u16 TempShortBuf [256];
1760 1535
1761 DEBUG("*** DspProv Entered\n"); 1536 DEBUG("*** DspProv Entered\n");
1762 1537
@@ -1792,7 +1567,7 @@ static int ft1000_dsp_prov(void *arg)
1792 len = htons(len); 1567 len = htons(len);
1793 len += PSEUDOSZ; 1568 len += PSEUDOSZ;
1794 1569
1795 pmsg = (PUSHORT)ptr->pprov_data; 1570 pmsg = (u16 *)ptr->pprov_data;
1796 ppseudo_hdr = (struct pseudo_hdr *)pmsg; 1571 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1797 // Insert slow queue sequence number 1572 // Insert slow queue sequence number
1798 ppseudo_hdr->seq_num = info->squeseqnum++; 1573 ppseudo_hdr->seq_num = info->squeseqnum++;
@@ -1809,7 +1584,7 @@ static int ft1000_dsp_prov(void *arg)
1809 TempShortBuf[1] = htons (len); 1584 TempShortBuf[1] = htons (len);
1810 memcpy(&TempShortBuf[2], ppseudo_hdr, len); 1585 memcpy(&TempShortBuf[2], ppseudo_hdr, len);
1811 1586
1812 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&TempShortBuf[0], (unsigned short)(len+2)); 1587 status = ft1000_write_dpram32 (dev, 0, (u8 *)&TempShortBuf[0], (unsigned short)(len+2));
1813 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL); 1588 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
1814 1589
1815 list_del(&ptr->list); 1590 list_del(&ptr->list);
@@ -1831,7 +1606,7 @@ static int ft1000_dsp_prov(void *arg)
1831 1606
1832 1607
1833static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) { 1608static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
1834 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net); 1609 struct ft1000_info *info = netdev_priv(dev->net);
1835 u16 msgtype; 1610 u16 msgtype;
1836 u16 tempword; 1611 u16 tempword;
1837 struct media_msg *pmediamsg; 1612 struct media_msg *pmediamsg;
@@ -1839,7 +1614,7 @@ static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
1839 struct drv_msg *pdrvmsg; 1614 struct drv_msg *pdrvmsg;
1840 u16 i; 1615 u16 i;
1841 struct pseudo_hdr *ppseudo_hdr; 1616 struct pseudo_hdr *ppseudo_hdr;
1842 PUSHORT pmsg; 1617 u16 *pmsg;
1843 u16 status; 1618 u16 status;
1844 union { 1619 union {
1845 u8 byte[2]; 1620 u8 byte[2];
@@ -1971,7 +1746,7 @@ static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
1971 tempword = ntohs(pdrvmsg->length); 1746 tempword = ntohs(pdrvmsg->length);
1972 info->DSPInfoBlklen = tempword; 1747 info->DSPInfoBlklen = tempword;
1973 if (tempword < (MAX_DSP_SESS_REC-4) ) { 1748 if (tempword < (MAX_DSP_SESS_REC-4) ) {
1974 pmsg = (PUSHORT)&pdrvmsg->data[0]; 1749 pmsg = (u16 *)&pdrvmsg->data[0];
1975 for (i=0; i<((tempword+1)/2); i++) { 1750 for (i=0; i<((tempword+1)/2); i++) {
1976 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg); 1751 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg);
1977 info->DSPInfoBlk[i+10] = *pmsg++; 1752 info->DSPInfoBlk[i+10] = *pmsg++;
@@ -2003,10 +1778,10 @@ static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
2003 1778
2004 // Put message into Slow Queue 1779 // Put message into Slow Queue
2005 // Form Pseudo header 1780 // Form Pseudo header
2006 pmsg = (PUSHORT)info->DSPInfoBlk; 1781 pmsg = (u16 *)info->DSPInfoBlk;
2007 *pmsg++ = 0; 1782 *pmsg++ = 0;
2008 *pmsg++ = htons(info->DSPInfoBlklen+20+info->DSPInfoBlklen); 1783 *pmsg++ = htons(info->DSPInfoBlklen+20+info->DSPInfoBlklen);
2009 ppseudo_hdr = (struct pseudo_hdr *)(PUSHORT)&info->DSPInfoBlk[2]; 1784 ppseudo_hdr = (struct pseudo_hdr *)(u16 *)&info->DSPInfoBlk[2];
2010 ppseudo_hdr->length = htons(info->DSPInfoBlklen+4+info->DSPInfoBlklen); 1785 ppseudo_hdr->length = htons(info->DSPInfoBlklen+4+info->DSPInfoBlklen);
2011 ppseudo_hdr->source = 0x10; 1786 ppseudo_hdr->source = 0x10;
2012 ppseudo_hdr->destination = 0x20; 1787 ppseudo_hdr->destination = 0x20;
@@ -2028,7 +1803,7 @@ static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
2028 } 1803 }
2029 info->DSPInfoBlk[10] = 0x7200; 1804 info->DSPInfoBlk[10] = 0x7200;
2030 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen); 1805 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen);
2031 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPInfoBlk[0], (unsigned short)(info->DSPInfoBlklen+22)); 1806 status = ft1000_write_dpram32 (dev, 0, (u8 *)&info->DSPInfoBlk[0], (unsigned short)(info->DSPInfoBlklen+22));
2032 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL); 1807 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
2033 info->DrvMsgPend = 0; 1808 info->DrvMsgPend = 0;
2034 1809
@@ -2053,7 +1828,7 @@ static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
2053 if ( (tempword & FT1000_DB_DPRAM_TX) == 0) { 1828 if ( (tempword & FT1000_DB_DPRAM_TX) == 0) {
2054 // Put message into Slow Queue 1829 // Put message into Slow Queue
2055 // Form Pseudo header 1830 // Form Pseudo header
2056 pmsg = (PUSHORT)&tempbuffer[0]; 1831 pmsg = (u16 *)&tempbuffer[0];
2057 ppseudo_hdr = (struct pseudo_hdr *)pmsg; 1832 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
2058 ppseudo_hdr->length = htons(0x0012); 1833 ppseudo_hdr->length = htons(0x0012);
2059 ppseudo_hdr->source = 0x10; 1834 ppseudo_hdr->source = 0x10;
@@ -2074,7 +1849,7 @@ static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
2074 for (i=1; i<7; i++) { 1849 for (i=1; i<7; i++) {
2075 ppseudo_hdr->checksum ^= *pmsg++; 1850 ppseudo_hdr->checksum ^= *pmsg++;
2076 } 1851 }
2077 pmsg = (PUSHORT)&tempbuffer[16]; 1852 pmsg = (u16 *)&tempbuffer[16];
2078 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG); 1853 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
2079 *pmsg++ = htons(0x000e); 1854 *pmsg++ = htons(0x000e);
2080 *pmsg++ = htons(info->DSP_TIME[0]); 1855 *pmsg++ = htons(info->DSP_TIME[0]);
@@ -2089,7 +1864,7 @@ static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
2089 *pmsg++ = convert.wrd; 1864 *pmsg++ = convert.wrd;
2090 *pmsg++ = htons(info->DrvErrNum); 1865 *pmsg++ = htons(info->DrvErrNum);
2091 1866
2092 CardSendCommand (dev, (unsigned char*)&tempbuffer[0], (USHORT)(0x0012 + PSEUDOSZ)); 1867 CardSendCommand (dev, (unsigned char*)&tempbuffer[0], (u16)(0x0012 + PSEUDOSZ));
2093 info->DrvErrNum = 0; 1868 info->DrvErrNum = 0;
2094 } 1869 }
2095 info->DrvMsgPend = 0; 1870 info->DrvMsgPend = 0;
@@ -2114,15 +1889,15 @@ out:
2114int ft1000_poll(void* dev_id) { 1889int ft1000_poll(void* dev_id) {
2115 1890
2116 struct ft1000_device *dev = (struct ft1000_device *)dev_id; 1891 struct ft1000_device *dev = (struct ft1000_device *)dev_id;
2117 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net); 1892 struct ft1000_info *info = netdev_priv(dev->net);
2118 1893
2119 u16 tempword; 1894 u16 tempword;
2120 u16 status; 1895 u16 status;
2121 u16 size; 1896 u16 size;
2122 int i; 1897 int i;
2123 USHORT data; 1898 u16 data;
2124 USHORT modulo; 1899 u16 modulo;
2125 USHORT portid; 1900 u16 portid;
2126 u16 nxtph; 1901 u16 nxtph;
2127 struct dpram_blk *pdpram_blk; 1902 struct dpram_blk *pdpram_blk;
2128 struct pseudo_hdr *ppseudo_hdr; 1903 struct pseudo_hdr *ppseudo_hdr;
@@ -2143,14 +1918,14 @@ int ft1000_poll(void* dev_id) {
2143 if (tempword & FT1000_DB_DPRAM_RX) { 1918 if (tempword & FT1000_DB_DPRAM_RX) {
2144 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n"); 1919 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n");
2145 1920
2146 status = ft1000_read_dpram16(dev, 0x200, (PUCHAR)&data, 0); 1921 status = ft1000_read_dpram16(dev, 0x200, (u8 *)&data, 0);
2147 //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data); 1922 //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data);
2148 size = ntohs(data) + 16 + 2; //wai 1923 size = ntohs(data) + 16 + 2; //wai
2149 if (size % 4) { 1924 if (size % 4) {
2150 modulo = 4 - (size % 4); 1925 modulo = 4 - (size % 4);
2151 size = size + modulo; 1926 size = size + modulo;
2152 } 1927 }
2153 status = ft1000_read_dpram16(dev, 0x201, (PUCHAR)&portid, 1); 1928 status = ft1000_read_dpram16(dev, 0x201, (u8 *)&portid, 1);
2154 portid &= 0xff; 1929 portid &= 0xff;
2155 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid); 1930 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid);
2156 1931
@@ -2285,7 +2060,7 @@ int ft1000_poll(void* dev_id) {
2285 status = ft1000_write_register (dev, FT1000_ASIC_RESET_REQ, FT1000_REG_DOORBELL); 2060 status = ft1000_write_register (dev, FT1000_ASIC_RESET_REQ, FT1000_REG_DOORBELL);
2286 status = ft1000_write_register (dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL); 2061 status = ft1000_write_register (dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
2287 // copy dsp session record from Adapter block 2062 // copy dsp session record from Adapter block
2288 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPSess.Rec[0], 1024); 2063 status = ft1000_write_dpram32 (dev, 0, (u8 *)&info->DSPSess.Rec[0], 1024);
2289 // Program WMARK register 2064 // Program WMARK register
2290 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK); 2065 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2291 // ring doorbell to tell DSP that ASIC is out of reset 2066 // ring doorbell to tell DSP that ASIC is out of reset
@@ -2299,10 +2074,10 @@ int ft1000_poll(void* dev_id) {
2299 if (info->fAppMsgPend == 0) { 2074 if (info->fAppMsgPend == 0) {
2300 // Reset ASIC and DSP 2075 // Reset ASIC and DSP
2301 2076
2302 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX); 2077 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (u8 *)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2303 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX); 2078 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (u8 *)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2304 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX); 2079 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (u8 *)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2305 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX); 2080 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (u8 *)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2306 info->CardReady = 0; 2081 info->CardReady = 0;
2307 info->DrvErrNum = DSP_CONDRESET_INFO; 2082 info->DrvErrNum = DSP_CONDRESET_INFO;
2308 DEBUG("ft1000_hw:DSP conditional reset requested\n"); 2083 DEBUG("ft1000_hw:DSP conditional reset requested\n");
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.h b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.h
index c58074131014..ab9312f9f326 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.h
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.h
@@ -4,7 +4,7 @@
4 4
5#include "ft1000_usb.h" 5#include "ft1000_usb.h"
6 6
7extern u16 ft1000_read_register(struct usb_device *dev, PUSHORT Data, u8 nRegIndx); 7extern u16 ft1000_read_register(struct usb_device *dev, u16 *Data, u8 nRegIndx);
8extern u16 ft1000_write_register(struct usb_device *dev, USHORT value, u8 nRegIndx); 8extern u16 ft1000_write_register(struct usb_device *dev, u16 value, u8 nRegIndx);
9 9
10#endif 10#endif
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c b/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c
index 36cdd588fa98..b87542abbe86 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c
@@ -1,3 +1,24 @@
1/*
2 * ft1000_proc.c - ft1000 proc interface
3 *
4 * Copyright (C) 2009-2010 Quintec
5 * (C) 2010 Open-nandra
6 * <marek.belisko@open-nandra.com>
7 *
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file "COPYING" in the main directory of this
10 * archive for more details.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
1#include <linux/module.h> 22#include <linux/module.h>
2#include <linux/kernel.h> 23#include <linux/kernel.h>
3#include <linux/proc_fs.h> 24#include <linux/proc_fs.h>
@@ -14,219 +35,217 @@
14 35
15#define PUTX_TO_PAGE(len,page,message,size,var) \ 36#define PUTX_TO_PAGE(len,page,message,size,var) \
16 len += snprintf(page+len, PAGE_SIZE - len, message); \ 37 len += snprintf(page+len, PAGE_SIZE - len, message); \
17 for(i = 0; i < (size - 1); i++) \ 38 for (i = 0; i < (size - 1); i++) {\
18 { \
19 len += snprintf(page+len, PAGE_SIZE - len, "%02x:", var[i]); \ 39 len += snprintf(page+len, PAGE_SIZE - len, "%02x:", var[i]); \
20 } \ 40 } \
21 len += snprintf(page+len, PAGE_SIZE - len, "%02x\n", var[i]) 41 len += snprintf(page+len, PAGE_SIZE - len, "%02x\n", var[i])
22 42
23#define PUTD_TO_PAGE(len,page,message,size,var) \ 43#define PUTD_TO_PAGE(len,page,message,size,var) \
24 len += snprintf(page+len, PAGE_SIZE - len, message); \ 44 len += snprintf(page+len, PAGE_SIZE - len, message); \
25 for(i = 0; i < (size - 1); i++) \ 45 for (i = 0; i < (size - 1); i++) {\
26 { \
27 len += snprintf(page+len, PAGE_SIZE - len, "%d.", var[i]); \ 46 len += snprintf(page+len, PAGE_SIZE - len, "%d.", var[i]); \
28 } \ 47 } \
29 len += snprintf(page+len, PAGE_SIZE - len, "%d\n", var[i]) 48 len += snprintf(page+len, PAGE_SIZE - len, "%d\n", var[i])
30 49
31 50
32
33
34//#ifdef INIT_NET_NS
35#define FTNET_PROC init_net.proc_net 51#define FTNET_PROC init_net.proc_net
36//#else
37//#define FTNET_PROC proc_net
38//#endif
39 52
40 53
41u16 ft1000_read_dpram16 (struct ft1000_device *ft1000dev, USHORT indx, 54u16 ft1000_read_dpram16 (struct ft1000_device *ft1000dev, u16 indx,
42 PUCHAR buffer, u8 highlow); 55 u8 *buffer, u8 highlow);
43 56
44 57
45static int 58static int
46ft1000ReadProc (char *page, char **start, off_t off, int count, int *eof, 59ft1000ReadProc(char *page, char **start, off_t off, int count, int *eof,
47 void *data) 60 void *data)
48{ 61{
49 struct net_device *dev; 62 struct net_device *dev;
50 int len; 63 int len;
51 int i; 64 int i;
52 unsigned short ledStat; 65 unsigned short ledStat;
53 unsigned short conStat; 66 unsigned short conStat;
54 67
55 struct ft1000_info *info; 68 struct ft1000_info *info;
56 69
57 char *status[] = { "Idle (Disconnect)", "Searching", "Active (Connected)", 70 char *status[] = {
58 "Waiting for L2", "Sleep", "No Coverage", "", "" 71 "Idle (Disconnect)",
59 }; 72 "Searching",
60 73 "Active (Connected)",
61 char *signal[] = { "", "*", "**", "***", "****" }; 74 "Waiting for L2",
62 int strength; 75 "Sleep",
63 int quality; 76 "No Coverage",
64 struct timeval tv; 77 "",
65 time_t delta; 78 "",
66 79 };
67 dev = (struct net_device *) data; 80
68 info = (struct ft1000_info *) netdev_priv(dev); 81 char *signal[] = { "", "*", "**", "***", "****" };
69 82 int strength;
70 if (off > 0) 83 int quality;
71 { 84 struct timeval tv;
72 *eof = 1; 85 time_t delta;
73 return 0; 86
74 } 87 dev = (struct net_device *) data;
75 88 info = netdev_priv(dev);
76 89
77 if (info->ProgConStat != 0xFF) 90 if (off > 0) {
78 { 91 *eof = 1;
79 ft1000_read_dpram16 (info->pFt1000Dev, FT1000_MAG_DSP_LED, 92 return 0;
80 (PUCHAR) & ledStat, FT1000_MAG_DSP_LED_INDX); 93 }
81 info->LedStat = ntohs (ledStat); 94
82 95
83 ft1000_read_dpram16 (info->pFt1000Dev, FT1000_MAG_DSP_CON_STATE, 96 if (info->ProgConStat != 0xFF) {
84 (PUCHAR) & conStat, FT1000_MAG_DSP_CON_STATE_INDX); 97 ft1000_read_dpram16(info->pFt1000Dev, FT1000_MAG_DSP_LED,
85 info->ConStat = ntohs (conStat); 98 (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
86 do_gettimeofday (&tv); 99 info->LedStat = ntohs(ledStat);
87 delta = (tv.tv_sec - info->ConTm); 100
88 } 101 ft1000_read_dpram16(info->pFt1000Dev, FT1000_MAG_DSP_CON_STATE,
89 else 102 (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
90 { 103 info->ConStat = ntohs(conStat);
91 info->ConStat = 0xf; 104 do_gettimeofday(&tv);
92 delta = 0; 105 delta = (tv.tv_sec - info->ConTm);
93 } 106 } else {
94 107 info->ConStat = 0xf;
95 108 delta = 0;
96 109 }
97 i = (info->LedStat) & 0xf; 110
98 switch (i) 111 i = (info->LedStat) & 0xf;
99 { 112 switch (i) {
100 case 0x1: 113 case 0x1:
101 strength = 1; 114 strength = 1;
102 break; 115 break;
103 case 0x3: 116 case 0x3:
104 strength = 2; 117 strength = 2;
105 break; 118 break;
106 case 0x7: 119 case 0x7:
107 strength = 3; 120 strength = 3;
108 break; 121 break;
109 case 0xf: 122 case 0xf:
110 strength = 4; 123 strength = 4;
111 break; 124 break;
112 default: 125 default:
113 strength = 0; 126 strength = 0;
114 } 127 }
115 128
116 i = (info->LedStat >> 8) & 0xf; 129 i = (info->LedStat >> 8) & 0xf;
117 switch (i) 130 switch (i) {
118 { 131 case 0x1:
119 case 0x1: 132 quality = 1;
120 quality = 1; 133 break;
121 break; 134 case 0x3:
122 case 0x3: 135 quality = 2;
123 quality = 2; 136 break;
124 break; 137 case 0x7:
125 case 0x7: 138 quality = 3;
126 quality = 3; 139 break;
127 break; 140 case 0xf:
128 case 0xf: 141 quality = 4;
129 quality = 4; 142 break;
130 break; 143 default:
131 default: 144 quality = 0;
132 quality = 0; 145 }
133 } 146
134 147 len = 0;
135 148 PUTM_TO_PAGE(len, page, "Connection Time: %02ld:%02ld:%02ld\n",
136 len = 0; 149 ((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60));
137 PUTM_TO_PAGE (len, page, "Connection Time: %02ld:%02ld:%02ld\n", 150 PUTM_TO_PAGE(len, page, "Connection Time[s]: %ld\n", delta);
138 ((delta / 3600) % 24), ((delta / 60) % 60), (delta % 60)); 151 PUTM_TO_PAGE(len, page, "Asic ID: %s\n",
139 PUTM_TO_PAGE (len, page, "Connection Time[s]: %ld\n", delta); 152 (info->AsicID) ==
140 PUTM_TO_PAGE (len, page, "Asic ID: %s\n", 153 ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC");
141 (info->AsicID) == 154 PUTX_TO_PAGE(len, page, "SKU: ", SKUSZ, info->Sku);
142 ELECTRABUZZ_ID ? "ELECTRABUZZ ASIC" : "MAGNEMITE ASIC"); 155 PUTX_TO_PAGE(len, page, "EUI64: ", EUISZ, info->eui64);
143 PUTX_TO_PAGE (len, page, "SKU: ", SKUSZ, info->Sku); 156 PUTD_TO_PAGE(len, page, "DSP version number: ", DSPVERSZ, info->DspVer);
144 PUTX_TO_PAGE (len, page, "EUI64: ", EUISZ, info->eui64); 157 PUTX_TO_PAGE(len, page, "Hardware Serial Number: ", HWSERNUMSZ,
145 PUTD_TO_PAGE (len, page, "DSP version number: ", DSPVERSZ, info->DspVer); 158 info->HwSerNum);
146 PUTX_TO_PAGE (len, page, "Hardware Serial Number: ", HWSERNUMSZ, 159 PUTX_TO_PAGE(len, page, "Caliberation Version: ", CALVERSZ,
147 info->HwSerNum); 160 info->RfCalVer);
148 PUTX_TO_PAGE (len, page, "Caliberation Version: ", CALVERSZ, 161 PUTD_TO_PAGE(len, page, "Caliberation Date: ", CALDATESZ,
149 info->RfCalVer); 162 info->RfCalDate);
150 PUTD_TO_PAGE (len, page, "Caliberation Date: ", CALDATESZ, info->RfCalDate); 163 PUTM_TO_PAGE(len, page, "Media State: %s\n",
151 PUTM_TO_PAGE (len, page, "Media State: %s\n", 164 (info->mediastate) ? "link" : "no link");
152 (info->mediastate) ? "link" : "no link"); 165 PUTM_TO_PAGE(len, page, "Connection Status: %s\n",
153 PUTM_TO_PAGE (len, page, "Connection Status: %s\n", 166 status[((info->ConStat) & 0x7)]);
154 status[((info->ConStat) & 0x7)]); 167 PUTM_TO_PAGE(len, page, "RX packets: %ld\n", info->stats.rx_packets);
155 PUTM_TO_PAGE (len, page, "RX packets: %ld\n", info->stats.rx_packets); 168 PUTM_TO_PAGE(len, page, "TX packets: %ld\n", info->stats.tx_packets);
156 PUTM_TO_PAGE (len, page, "TX packets: %ld\n", info->stats.tx_packets); 169 PUTM_TO_PAGE(len, page, "RX bytes: %ld\n", info->stats.rx_bytes);
157 PUTM_TO_PAGE (len, page, "RX bytes: %ld\n", info->stats.rx_bytes); 170 PUTM_TO_PAGE(len, page, "TX bytes: %ld\n", info->stats.tx_bytes);
158 PUTM_TO_PAGE (len, page, "TX bytes: %ld\n", info->stats.tx_bytes); 171 PUTM_TO_PAGE(len, page, "Signal Strength: %s\n", signal[strength]);
159 PUTM_TO_PAGE (len, page, "Signal Strength: %s\n", signal[strength]); 172 PUTM_TO_PAGE(len, page, "Signal Quality: %s\n", signal[quality]);
160 PUTM_TO_PAGE (len, page, "Signal Quality: %s\n", signal[quality]); 173
161 174 return len;
162
163
164
165 return len;
166} 175}
167 176
168static int 177static int
169ft1000NotifyProc (struct notifier_block *this, unsigned long event, void *ptr) 178ft1000NotifyProc(struct notifier_block *this, unsigned long event, void *ptr)
170{ 179{
171 struct net_device *dev = ptr; 180 struct net_device *dev = ptr;
172 struct ft1000_info *info; 181 struct ft1000_info *info;
173 struct proc_dir_entry *ft1000_proc_file; 182 struct proc_dir_entry *ft1000_proc_file;
174 183
175info = (struct ft1000_info *) netdev_priv(dev); 184 info = netdev_priv(dev);
176 185
177 186 switch (event) {
178 switch (event) 187 case NETDEV_CHANGENAME:
179 { 188 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
180 case NETDEV_CHANGENAME: 189 ft1000_proc_file = create_proc_read_entry(dev->name, 0644,
181 remove_proc_entry (info->netdevname, info->ft1000_proc_dir); 190 info->ft1000_proc_dir,
182 ft1000_proc_file = create_proc_read_entry (dev->name, 0644, 191 ft1000ReadProc, dev);
183 info->ft1000_proc_dir, 192 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
184 ft1000ReadProc, dev); 193 break;
185 snprintf (info->netdevname, IFNAMSIZ, "%s", dev->name); 194 }
186 break; 195
187 } 196 return NOTIFY_DONE;
188 return NOTIFY_DONE;
189} 197}
190 198
191static struct notifier_block ft1000_netdev_notifier = { 199static struct notifier_block ft1000_netdev_notifier = {
192 .notifier_call = ft1000NotifyProc 200 .notifier_call = ft1000NotifyProc,
193}; 201};
194 202
195 203
196void 204int ft1000_init_proc(struct net_device *dev)
197ft1000InitProc (struct net_device *dev)
198{ 205{
199 struct ft1000_info *info; 206 struct ft1000_info *info;
200 struct proc_dir_entry *ft1000_proc_file; 207 struct proc_dir_entry *ft1000_proc_file;
201 info = (struct ft1000_info *) netdev_priv(dev); 208 int ret = 0;
202 209
203 210 info = netdev_priv(dev);
204 info->ft1000_proc_dir = proc_mkdir (FT1000_PROC_DIR, FTNET_PROC); 211
205 if (info->ft1000_proc_dir == NULL) 212 info->ft1000_proc_dir = proc_mkdir(FT1000_PROC_DIR, FTNET_PROC);
206 { 213 if (info->ft1000_proc_dir == NULL) {
207 remove_proc_entry (FT1000_PROC_DIR, FTNET_PROC); 214 printk(KERN_WARNING "Unable to create %s dir.\n",
208 } 215 FT1000_PROC_DIR);
209 216 ret = -EINVAL;
210 217 goto fail;
211 ft1000_proc_file = 218 }
212 create_proc_read_entry (dev->name, 0644, info->ft1000_proc_dir, 219
213 ft1000ReadProc, dev); 220 ft1000_proc_file =
214 if (ft1000_proc_file == NULL) 221 create_proc_read_entry(dev->name, 0644,
215 { 222 info->ft1000_proc_dir, ft1000ReadProc, dev);
216 remove_proc_entry (info->netdevname, info->ft1000_proc_dir); 223
217 } 224 if (ft1000_proc_file == NULL) {
218 225 printk(KERN_WARNING "Unable to create /proc entry.\n");
219 snprintf (info->netdevname, IFNAMSIZ, "%s", dev->name); 226 ret = -EINVAL;
220 register_netdevice_notifier (&ft1000_netdev_notifier); 227 goto fail_entry;
221 return; 228 }
229
230 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
231
232 ret = register_netdevice_notifier(&ft1000_netdev_notifier);
233 if (ret)
234 goto fail_notif;
235
236 return 0;
237
238fail_notif:
239 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
240fail_entry:
241 remove_proc_entry(FT1000_PROC_DIR, FTNET_PROC);
242fail:
243 return ret;
222} 244}
223 245
224void 246void ft1000_cleanup_proc(struct ft1000_info *info)
225ft1000CleanupProc(struct ft1000_info *info)
226{ 247{
227 remove_proc_entry (info->netdevname, info->ft1000_proc_dir); 248 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
228 remove_proc_entry (FT1000_PROC_DIR, FTNET_PROC); 249 remove_proc_entry(FT1000_PROC_DIR, FTNET_PROC);
229 unregister_netdevice_notifier (&ft1000_netdev_notifier); 250 unregister_netdevice_notifier(&ft1000_netdev_notifier);
230
231 return;
232} 251}
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
index 28f55b2030e9..79482ac1c489 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
@@ -36,7 +36,7 @@ static struct usb_device_id id_table[] = {
36 36
37MODULE_DEVICE_TABLE(usb, id_table); 37MODULE_DEVICE_TABLE(usb, id_table);
38 38
39static BOOLEAN gPollingfailed = FALSE; 39static bool gPollingfailed = FALSE;
40int ft1000_poll_thread(void *arg) 40int ft1000_poll_thread(void *arg)
41{ 41{
42 int ret = STATUS_SUCCESS; 42 int ret = STATUS_SUCCESS;
@@ -64,7 +64,7 @@ static int ft1000_probe(struct usb_interface *interface,
64 int i, ret = 0, size; 64 int i, ret = 0, size;
65 65
66 struct ft1000_device *ft1000dev; 66 struct ft1000_device *ft1000dev;
67 struct ft1000_info *pft1000info; 67 struct ft1000_info *pft1000info = NULL;
68 const struct firmware *dsp_fw; 68 const struct firmware *dsp_fw;
69 69
70 ft1000dev = kmalloc(sizeof(struct ft1000_device), GFP_KERNEL); 70 ft1000dev = kmalloc(sizeof(struct ft1000_device), GFP_KERNEL);
@@ -84,7 +84,6 @@ static int ft1000_probe(struct usb_interface *interface,
84 ft1000dev->dev = dev; 84 ft1000dev->dev = dev;
85 ft1000dev->status = 0; 85 ft1000dev->status = 0;
86 ft1000dev->net = NULL; 86 ft1000dev->net = NULL;
87 spin_lock_init(&ft1000dev->device_lock);
88 ft1000dev->tx_urb = usb_alloc_urb(0, GFP_ATOMIC); 87 ft1000dev->tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
89 ft1000dev->rx_urb = usb_alloc_urb(0, GFP_ATOMIC); 88 ft1000dev->rx_urb = usb_alloc_urb(0, GFP_ATOMIC);
90 89
@@ -164,7 +163,7 @@ static int ft1000_probe(struct usb_interface *interface,
164 if (ret) 163 if (ret)
165 goto err_load; 164 goto err_load;
166 165
167 pft1000info = (struct ft1000_info *) netdev_priv(ft1000dev->net); 166 pft1000info = netdev_priv(ft1000dev->net);
168 167
169 DEBUG("In probe: pft1000info=%p\n", pft1000info); 168 DEBUG("In probe: pft1000info=%p\n", pft1000info);
170 ret = dsp_reload(ft1000dev); 169 ret = dsp_reload(ft1000dev);
@@ -176,14 +175,18 @@ static int ft1000_probe(struct usb_interface *interface,
176 gPollingfailed = FALSE; 175 gPollingfailed = FALSE;
177 pft1000info->pPollThread = 176 pft1000info->pPollThread =
178 kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll"); 177 kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll");
178
179 if (IS_ERR(pft1000info->pPollThread)) {
180 ret = PTR_ERR(pft1000info->pPollThread);
181 goto err_load;
182 }
183
179 msleep(500); 184 msleep(500);
180 185
181 while (!pft1000info->CardReady) { 186 while (!pft1000info->CardReady) {
182 if (gPollingfailed) { 187 if (gPollingfailed) {
183 if (pft1000info->pPollThread)
184 kthread_stop(pft1000info->pPollThread);
185 ret = -EIO; 188 ret = -EIO;
186 goto err_load; 189 goto err_thread;
187 } 190 }
188 msleep(100); 191 msleep(100);
189 DEBUG("ft1000_probe::Waiting for Card Ready\n"); 192 DEBUG("ft1000_probe::Waiting for Card Ready\n");
@@ -193,14 +196,21 @@ static int ft1000_probe(struct usb_interface *interface,
193 196
194 ret = reg_ft1000_netdev(ft1000dev, interface); 197 ret = reg_ft1000_netdev(ft1000dev, interface);
195 if (ret) 198 if (ret)
196 goto err_load; 199 goto err_thread;
197 200
198 pft1000info->NetDevRegDone = 1; 201 ret = ft1000_init_proc(ft1000dev->net);
202 if (ret)
203 goto err_proc;
199 204
200 ft1000InitProc(ft1000dev->net); 205 pft1000info->NetDevRegDone = 1;
201 206
202 return 0; 207 return 0;
203 208
209err_proc:
210 unregister_netdev(ft1000dev->net);
211 free_netdev(ft1000dev->net);
212err_thread:
213 kthread_stop(pft1000info->pPollThread);
204err_load: 214err_load:
205 kfree(pFileStart); 215 kfree(pFileStart);
206err_fw: 216err_fw:
@@ -218,7 +228,7 @@ static void ft1000_disconnect(struct usb_interface *interface)
218 DEBUG("In disconnect pft1000info=%p\n", pft1000info); 228 DEBUG("In disconnect pft1000info=%p\n", pft1000info);
219 229
220 if (pft1000info) { 230 if (pft1000info) {
221 ft1000CleanupProc(pft1000info); 231 ft1000_cleanup_proc(pft1000info);
222 if (pft1000info->pPollThread) 232 if (pft1000info->pPollThread)
223 kthread_stop(pft1000info->pPollThread); 233 kthread_stop(pft1000info->pPollThread);
224 234
@@ -226,7 +236,7 @@ static void ft1000_disconnect(struct usb_interface *interface)
226 236
227 if (pft1000info->pFt1000Dev->net) { 237 if (pft1000info->pFt1000Dev->net) {
228 DEBUG("ft1000_disconnect: destroy char driver\n"); 238 DEBUG("ft1000_disconnect: destroy char driver\n");
229 ft1000_DestroyDevice(pft1000info->pFt1000Dev->net); 239 ft1000_destroy_dev(pft1000info->pFt1000Dev->net);
230 unregister_netdev(pft1000info->pFt1000Dev->net); 240 unregister_netdev(pft1000info->pFt1000Dev->net);
231 DEBUG 241 DEBUG
232 ("ft1000_disconnect: network device unregisterd\n"); 242 ("ft1000_disconnect: network device unregisterd\n");
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
index a9d419a98a06..a143e9ca4f08 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
@@ -98,16 +98,6 @@ struct prov_record {
98/*end of Jim*/ 98/*end of Jim*/
99#define DEBUG(args...) printk(KERN_INFO args) 99#define DEBUG(args...) printk(KERN_INFO args)
100 100
101#define UCHAR u8
102#define USHORT u16
103#define ULONG u32 /* WTF ??? */
104#define BOOLEAN u8
105#define PULONG u32 *
106#define PUSHORT u16 *
107#define PUCHAR u8 *
108#define PCHAR u8 *
109#define UINT u32
110
111#define FALSE 0 101#define FALSE 0
112#define TRUE 1 102#define TRUE 1
113 103
@@ -372,15 +362,15 @@ struct prov_record {
372 362
373 363
374 364
375#define ISR_EMPTY (UCHAR)0x00 // no bits set in ISR 365#define ISR_EMPTY (u8)0x00 // no bits set in ISR
376 366
377#define ISR_DOORBELL_ACK (UCHAR)0x01 // the doorbell i sent has been recieved. 367#define ISR_DOORBELL_ACK (u8)0x01 // the doorbell i sent has been recieved.
378 368
379#define ISR_DOORBELL_PEND (UCHAR)0x02 // doorbell for me 369#define ISR_DOORBELL_PEND (u8)0x02 // doorbell for me
380 370
381#define ISR_RCV (UCHAR)0x04 // packet received with no errors 371#define ISR_RCV (u8)0x04 // packet received with no errors
382 372
383#define ISR_WATERMARK (UCHAR)0x08 // 373#define ISR_WATERMARK (u8)0x08 //
384 374
385 375
386 376
@@ -466,12 +456,9 @@ struct ft1000_device
466{ 456{
467 struct usb_device *dev; 457 struct usb_device *dev;
468 struct net_device *net; 458 struct net_device *net;
469 spinlock_t device_lock;
470 459
471 u32 status; 460 u32 status;
472 461
473 wait_queue_head_t control_wait;
474
475 struct urb *rx_urb; 462 struct urb *rx_urb;
476 struct urb *tx_urb; 463 struct urb *tx_urb;
477 464
@@ -486,6 +473,13 @@ struct ft1000_device
486// struct net_device_stats stats; //mbelian 473// struct net_device_stats stats; //mbelian
487} __attribute__ ((packed)); 474} __attribute__ ((packed));
488 475
476struct ft1000_debug_dirs {
477 struct list_head list;
478 struct dentry *dent;
479 struct dentry *file;
480 int int_number;
481};
482
489struct ft1000_info { 483struct ft1000_info {
490 struct ft1000_device *pFt1000Dev; 484 struct ft1000_device *pFt1000Dev;
491 struct net_device_stats stats; 485 struct net_device_stats stats;
@@ -497,9 +491,9 @@ struct ft1000_info {
497 unsigned char usbboot; 491 unsigned char usbboot;
498 unsigned short dspalive; 492 unsigned short dspalive;
499 u16 ASIC_ID; 493 u16 ASIC_ID;
500 BOOLEAN fProvComplete; 494 bool fProvComplete;
501 BOOLEAN fCondResetPend; 495 bool fCondResetPend;
502 BOOLEAN fAppMsgPend; 496 bool fAppMsgPend;
503 char *pfwimg; 497 char *pfwimg;
504 int fwimgsz; 498 int fwimgsz;
505 u16 DrvErrNum; 499 u16 DrvErrNum;
@@ -520,7 +514,7 @@ struct ft1000_info {
520 int NetDevRegDone; 514 int NetDevRegDone;
521 u8 CardNumber; 515 u8 CardNumber;
522 u8 DeviceName[15]; 516 u8 DeviceName[15];
523 int DeviceMajor; 517 struct ft1000_debug_dirs nodes;
524 int registered; 518 int registered;
525 int mediastate; 519 int mediastate;
526 int dhcpflg; 520 int dhcpflg;
@@ -567,26 +561,26 @@ struct dpram_blk {
567} __attribute__ ((packed)); 561} __attribute__ ((packed));
568 562
569u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx); 563u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx);
570u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRegIndx); 564u16 ft1000_write_register(struct ft1000_device *ft1000dev, u16 value, u16 nRegIndx);
571u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt); 565u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, u16 cnt);
572u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt); 566u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, u16 cnt);
573u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow); 567u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, u8 highlow);
574u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT value, u8 highlow); 568u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u8 highlow);
575u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer); 569u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer);
576u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer); 570u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer);
577 571
578extern void *pFileStart; 572extern void *pFileStart;
579extern size_t FileLength; 573extern size_t FileLength;
580extern int numofmsgbuf; 574extern int numofmsgbuf;
581 575
582int ft1000_close (struct net_device *dev); 576int ft1000_close (struct net_device *dev);
583u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLength); 577u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, u32 FileLength);
584 578
585extern struct list_head freercvpool; 579extern struct list_head freercvpool;
586extern spinlock_t free_buff_lock; // lock to arbitrate free buffer list for receive command data 580extern spinlock_t free_buff_lock; // lock to arbitrate free buffer list for receive command data
587 581
588int ft1000_CreateDevice(struct ft1000_device *dev); 582int ft1000_create_dev(struct ft1000_device *dev);
589void ft1000_DestroyDevice(struct net_device *dev); 583void ft1000_destroy_dev(struct net_device *dev);
590extern void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size); 584extern void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size);
591 585
592struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist); 586struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist);
@@ -600,8 +594,8 @@ struct usb_interface;
600int reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf); 594int reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf);
601int ft1000_poll(void* dev_id); 595int ft1000_poll(void* dev_id);
602 596
603void ft1000InitProc(struct net_device *dev); 597int ft1000_init_proc(struct net_device *dev);
604void ft1000CleanupProc(struct ft1000_info *info); 598void ft1000_cleanup_proc(struct ft1000_info *info);
605 599
606 600
607 601
diff --git a/drivers/staging/go7007/go7007-driver.c b/drivers/staging/go7007/go7007-driver.c
index 48d4e483d8a4..6c9279a6d606 100644
--- a/drivers/staging/go7007/go7007-driver.c
+++ b/drivers/staging/go7007/go7007-driver.c
@@ -624,7 +624,7 @@ struct go7007 *go7007_alloc(struct go7007_board_info *board, struct device *dev)
624 go->dvd_mode = 0; 624 go->dvd_mode = 0;
625 go->interlace_coding = 0; 625 go->interlace_coding = 0;
626 for (i = 0; i < 4; ++i) 626 for (i = 0; i < 4; ++i)
627 go->modet[i].enable = 0;; 627 go->modet[i].enable = 0;
628 for (i = 0; i < 1624; ++i) 628 for (i = 0; i < 1624; ++i)
629 go->modet_map[i] = 0; 629 go->modet_map[i] = 0;
630 go->audio_deliver = NULL; 630 go->audio_deliver = NULL;
diff --git a/drivers/staging/hv/Makefile b/drivers/staging/hv/Makefile
index b46349bb43bf..acd39bd75b1c 100644
--- a/drivers/staging/hv/Makefile
+++ b/drivers/staging/hv/Makefile
@@ -5,7 +5,7 @@ obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o
5obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o 5obj-$(CONFIG_HYPERV_UTILS) += hv_utils.o
6 6
7hv_vmbus-y := vmbus_drv.o osd.o \ 7hv_vmbus-y := vmbus_drv.o osd.o \
8 vmbus.o hv.o connection.o channel.o \ 8 hv.o connection.o channel.o \
9 channel_mgmt.o ring_buffer.o 9 channel_mgmt.o ring_buffer.o
10hv_storvsc-y := storvsc_drv.o storvsc.o 10hv_storvsc-y := storvsc_drv.o storvsc.o
11hv_blkvsc-y := blkvsc_drv.o blkvsc.o 11hv_blkvsc-y := blkvsc_drv.o blkvsc.o
diff --git a/drivers/staging/hv/blkvsc.c b/drivers/staging/hv/blkvsc.c
index d5b0abd771ab..bc16d9172eb2 100644
--- a/drivers/staging/hv/blkvsc.c
+++ b/drivers/staging/hv/blkvsc.c
@@ -25,24 +25,24 @@
25#include "osd.h" 25#include "osd.h"
26#include "storvsc.c" 26#include "storvsc.c"
27 27
28static const char *gBlkDriverName = "blkvsc"; 28static const char *g_blk_driver_name = "blkvsc";
29 29
30/* {32412632-86cb-44a2-9b5c-50d1417354f5} */ 30/* {32412632-86cb-44a2-9b5c-50d1417354f5} */
31static const struct hv_guid gBlkVscDeviceType = { 31static const struct hv_guid g_blk_device_type = {
32 .data = { 32 .data = {
33 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 33 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44,
34 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 34 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5
35 } 35 }
36}; 36};
37 37
38static int BlkVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) 38static int blk_vsc_on_device_add(struct hv_device *device, void *additional_info)
39{ 39{
40 struct storvsc_device_info *deviceInfo; 40 struct storvsc_device_info *device_info;
41 int ret = 0; 41 int ret = 0;
42 42
43 deviceInfo = (struct storvsc_device_info *)AdditionalInfo; 43 device_info = (struct storvsc_device_info *)additional_info;
44 44
45 ret = StorVscOnDeviceAdd(Device, AdditionalInfo); 45 ret = stor_vsc_on_device_add(device, additional_info);
46 if (ret != 0) 46 if (ret != 0)
47 return ret; 47 return ret;
48 48
@@ -51,31 +51,31 @@ static int BlkVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
51 * id. For IDE devices, the device instance id is formatted as 51 * id. For IDE devices, the device instance id is formatted as
52 * <bus id> * - <device id> - 8899 - 000000000000. 52 * <bus id> * - <device id> - 8899 - 000000000000.
53 */ 53 */
54 deviceInfo->PathId = Device->deviceInstance.data[3] << 24 | 54 device_info->path_id = device->deviceInstance.data[3] << 24 |
55 Device->deviceInstance.data[2] << 16 | 55 device->deviceInstance.data[2] << 16 |
56 Device->deviceInstance.data[1] << 8 | 56 device->deviceInstance.data[1] << 8 |
57 Device->deviceInstance.data[0]; 57 device->deviceInstance.data[0];
58 58
59 deviceInfo->TargetId = Device->deviceInstance.data[5] << 8 | 59 device_info->target_id = device->deviceInstance.data[5] << 8 |
60 Device->deviceInstance.data[4]; 60 device->deviceInstance.data[4];
61 61
62 return ret; 62 return ret;
63} 63}
64 64
65int BlkVscInitialize(struct hv_driver *Driver) 65int blk_vsc_initialize(struct hv_driver *driver)
66{ 66{
67 struct storvsc_driver_object *storDriver; 67 struct storvsc_driver_object *stor_driver;
68 int ret = 0; 68 int ret = 0;
69 69
70 storDriver = (struct storvsc_driver_object *)Driver; 70 stor_driver = (struct storvsc_driver_object *)driver;
71 71
72 /* Make sure we are at least 2 pages since 1 page is used for control */ 72 /* Make sure we are at least 2 pages since 1 page is used for control */
73 /* ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1)); */ 73 /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */
74 74
75 Driver->name = gBlkDriverName; 75 driver->name = g_blk_driver_name;
76 memcpy(&Driver->deviceType, &gBlkVscDeviceType, sizeof(struct hv_guid)); 76 memcpy(&driver->deviceType, &g_blk_device_type, sizeof(struct hv_guid));
77 77
78 storDriver->RequestExtSize = sizeof(struct storvsc_request_extension); 78 stor_driver->request_ext_size = sizeof(struct storvsc_request_extension);
79 79
80 /* 80 /*
81 * Divide the ring buffer data size (which is 1 page less than the ring 81 * Divide the ring buffer data size (which is 1 page less than the ring
@@ -83,20 +83,20 @@ int BlkVscInitialize(struct hv_driver *Driver)
83 * by the max request size (which is 83 * by the max request size (which is
84 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) 84 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
85 */ 85 */
86 storDriver->MaxOutstandingRequestsPerChannel = 86 stor_driver->max_outstanding_req_per_channel =
87 ((storDriver->RingBufferSize - PAGE_SIZE) / 87 ((stor_driver->ring_buffer_size - PAGE_SIZE) /
88 ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + 88 ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET +
89 sizeof(struct vstor_packet) + sizeof(u64), 89 sizeof(struct vstor_packet) + sizeof(u64),
90 sizeof(u64))); 90 sizeof(u64)));
91 91
92 DPRINT_INFO(BLKVSC, "max io outstd %u", 92 DPRINT_INFO(BLKVSC, "max io outstd %u",
93 storDriver->MaxOutstandingRequestsPerChannel); 93 stor_driver->max_outstanding_req_per_channel);
94 94
95 /* Setup the dispatch table */ 95 /* Setup the dispatch table */
96 storDriver->Base.OnDeviceAdd = BlkVscOnDeviceAdd; 96 stor_driver->base.OnDeviceAdd = blk_vsc_on_device_add;
97 storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove; 97 stor_driver->base.OnDeviceRemove = stor_vsc_on_device_remove;
98 storDriver->Base.OnCleanup = StorVscOnCleanup; 98 stor_driver->base.OnCleanup = stor_vsc_on_cleanup;
99 storDriver->OnIORequest = StorVscOnIORequest; 99 stor_driver->on_io_request = stor_vsc_on_io_request;
100 100
101 return ret; 101 return ret;
102} 102}
diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index 3f81ca591064..b3d05fcfe6d2 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -177,13 +177,13 @@ static int blkvsc_drv_init(int (*drv_init)(struct hv_driver *drv))
177 struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx; 177 struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx;
178 int ret; 178 int ret;
179 179
180 storvsc_drv_obj->RingBufferSize = blkvsc_ringbuffer_size; 180 storvsc_drv_obj->ring_buffer_size = blkvsc_ringbuffer_size;
181 181
182 /* Callback to client driver to complete the initialization */ 182 /* Callback to client driver to complete the initialization */
183 drv_init(&storvsc_drv_obj->Base); 183 drv_init(&storvsc_drv_obj->base);
184 184
185 drv_ctx->driver.name = storvsc_drv_obj->Base.name; 185 drv_ctx->driver.name = storvsc_drv_obj->base.name;
186 memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, 186 memcpy(&drv_ctx->class_id, &storvsc_drv_obj->base.deviceType,
187 sizeof(struct hv_guid)); 187 sizeof(struct hv_guid));
188 188
189 drv_ctx->probe = blkvsc_probe; 189 drv_ctx->probe = blkvsc_probe;
@@ -230,8 +230,8 @@ static void blkvsc_drv_exit(void)
230 device_unregister(current_dev); 230 device_unregister(current_dev);
231 } 231 }
232 232
233 if (storvsc_drv_obj->Base.OnCleanup) 233 if (storvsc_drv_obj->base.OnCleanup)
234 storvsc_drv_obj->Base.OnCleanup(&storvsc_drv_obj->Base); 234 storvsc_drv_obj->base.OnCleanup(&storvsc_drv_obj->base);
235 235
236 vmbus_child_driver_unregister(drv_ctx); 236 vmbus_child_driver_unregister(drv_ctx);
237 237
@@ -262,7 +262,7 @@ static int blkvsc_probe(struct device *device)
262 262
263 DPRINT_DBG(BLKVSC_DRV, "blkvsc_probe - enter"); 263 DPRINT_DBG(BLKVSC_DRV, "blkvsc_probe - enter");
264 264
265 if (!storvsc_drv_obj->Base.OnDeviceAdd) { 265 if (!storvsc_drv_obj->base.OnDeviceAdd) {
266 DPRINT_ERR(BLKVSC_DRV, "OnDeviceAdd() not set"); 266 DPRINT_ERR(BLKVSC_DRV, "OnDeviceAdd() not set");
267 ret = -1; 267 ret = -1;
268 goto Cleanup; 268 goto Cleanup;
@@ -284,7 +284,7 @@ static int blkvsc_probe(struct device *device)
284 284
285 blkdev->request_pool = kmem_cache_create(dev_name(&device_ctx->device), 285 blkdev->request_pool = kmem_cache_create(dev_name(&device_ctx->device),
286 sizeof(struct blkvsc_request) + 286 sizeof(struct blkvsc_request) +
287 storvsc_drv_obj->RequestExtSize, 0, 287 storvsc_drv_obj->request_ext_size, 0,
288 SLAB_HWCACHE_ALIGN, NULL); 288 SLAB_HWCACHE_ALIGN, NULL);
289 if (!blkdev->request_pool) { 289 if (!blkdev->request_pool) {
290 ret = -ENOMEM; 290 ret = -ENOMEM;
@@ -293,7 +293,7 @@ static int blkvsc_probe(struct device *device)
293 293
294 294
295 /* Call to the vsc driver to add the device */ 295 /* Call to the vsc driver to add the device */
296 ret = storvsc_drv_obj->Base.OnDeviceAdd(device_obj, &device_info); 296 ret = storvsc_drv_obj->base.OnDeviceAdd(device_obj, &device_info);
297 if (ret != 0) { 297 if (ret != 0) {
298 DPRINT_ERR(BLKVSC_DRV, "unable to add blkvsc device"); 298 DPRINT_ERR(BLKVSC_DRV, "unable to add blkvsc device");
299 goto Cleanup; 299 goto Cleanup;
@@ -301,9 +301,9 @@ static int blkvsc_probe(struct device *device)
301 301
302 blkdev->device_ctx = device_ctx; 302 blkdev->device_ctx = device_ctx;
303 /* this identified the device 0 or 1 */ 303 /* this identified the device 0 or 1 */
304 blkdev->target = device_info.TargetId; 304 blkdev->target = device_info.target_id;
305 /* this identified the ide ctrl 0 or 1 */ 305 /* this identified the ide ctrl 0 or 1 */
306 blkdev->path = device_info.PathId; 306 blkdev->path = device_info.path_id;
307 307
308 dev_set_drvdata(device, blkdev); 308 dev_set_drvdata(device, blkdev);
309 309
@@ -391,7 +391,7 @@ static int blkvsc_probe(struct device *device)
391 return ret; 391 return ret;
392 392
393Remove: 393Remove:
394 storvsc_drv_obj->Base.OnDeviceRemove(device_obj); 394 storvsc_drv_obj->base.OnDeviceRemove(device_obj);
395 395
396Cleanup: 396Cleanup:
397 if (blkdev) { 397 if (blkdev) {
@@ -459,9 +459,9 @@ static int blkvsc_do_flush(struct block_device_context *blkdev)
459 blkvsc_req->req = NULL; 459 blkvsc_req->req = NULL;
460 blkvsc_req->write = 0; 460 blkvsc_req->write = 0;
461 461
462 blkvsc_req->request.DataBuffer.PfnArray[0] = 0; 462 blkvsc_req->request.data_buffer.PfnArray[0] = 0;
463 blkvsc_req->request.DataBuffer.Offset = 0; 463 blkvsc_req->request.data_buffer.Offset = 0;
464 blkvsc_req->request.DataBuffer.Length = 0; 464 blkvsc_req->request.data_buffer.Length = 0;
465 465
466 blkvsc_req->cmnd[0] = SYNCHRONIZE_CACHE; 466 blkvsc_req->cmnd[0] = SYNCHRONIZE_CACHE;
467 blkvsc_req->cmd_len = 10; 467 blkvsc_req->cmd_len = 10;
@@ -506,9 +506,9 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev)
506 blkvsc_req->req = NULL; 506 blkvsc_req->req = NULL;
507 blkvsc_req->write = 0; 507 blkvsc_req->write = 0;
508 508
509 blkvsc_req->request.DataBuffer.PfnArray[0] = page_to_pfn(page_buf); 509 blkvsc_req->request.data_buffer.PfnArray[0] = page_to_pfn(page_buf);
510 blkvsc_req->request.DataBuffer.Offset = 0; 510 blkvsc_req->request.data_buffer.Offset = 0;
511 blkvsc_req->request.DataBuffer.Length = 64; 511 blkvsc_req->request.data_buffer.Length = 64;
512 512
513 blkvsc_req->cmnd[0] = INQUIRY; 513 blkvsc_req->cmnd[0] = INQUIRY;
514 blkvsc_req->cmnd[1] = 0x1; /* Get product data */ 514 blkvsc_req->cmnd[1] = 0x1; /* Get product data */
@@ -593,9 +593,9 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev)
593 blkvsc_req->req = NULL; 593 blkvsc_req->req = NULL;
594 blkvsc_req->write = 0; 594 blkvsc_req->write = 0;
595 595
596 blkvsc_req->request.DataBuffer.PfnArray[0] = page_to_pfn(page_buf); 596 blkvsc_req->request.data_buffer.PfnArray[0] = page_to_pfn(page_buf);
597 blkvsc_req->request.DataBuffer.Offset = 0; 597 blkvsc_req->request.data_buffer.Offset = 0;
598 blkvsc_req->request.DataBuffer.Length = 8; 598 blkvsc_req->request.data_buffer.Length = 8;
599 599
600 blkvsc_req->cmnd[0] = READ_CAPACITY; 600 blkvsc_req->cmnd[0] = READ_CAPACITY;
601 blkvsc_req->cmd_len = 16; 601 blkvsc_req->cmd_len = 16;
@@ -614,7 +614,7 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev)
614 wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); 614 wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
615 615
616 /* check error */ 616 /* check error */
617 if (blkvsc_req->request.Status) { 617 if (blkvsc_req->request.status) {
618 scsi_normalize_sense(blkvsc_req->sense_buffer, 618 scsi_normalize_sense(blkvsc_req->sense_buffer,
619 SCSI_SENSE_BUFFERSIZE, &sense_hdr); 619 SCSI_SENSE_BUFFERSIZE, &sense_hdr);
620 620
@@ -670,9 +670,9 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
670 blkvsc_req->req = NULL; 670 blkvsc_req->req = NULL;
671 blkvsc_req->write = 0; 671 blkvsc_req->write = 0;
672 672
673 blkvsc_req->request.DataBuffer.PfnArray[0] = page_to_pfn(page_buf); 673 blkvsc_req->request.data_buffer.PfnArray[0] = page_to_pfn(page_buf);
674 blkvsc_req->request.DataBuffer.Offset = 0; 674 blkvsc_req->request.data_buffer.Offset = 0;
675 blkvsc_req->request.DataBuffer.Length = 12; 675 blkvsc_req->request.data_buffer.Length = 12;
676 676
677 blkvsc_req->cmnd[0] = 0x9E; /* READ_CAPACITY16; */ 677 blkvsc_req->cmnd[0] = 0x9E; /* READ_CAPACITY16; */
678 blkvsc_req->cmd_len = 16; 678 blkvsc_req->cmd_len = 16;
@@ -691,7 +691,7 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev)
691 wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); 691 wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond);
692 692
693 /* check error */ 693 /* check error */
694 if (blkvsc_req->request.Status) { 694 if (blkvsc_req->request.status) {
695 scsi_normalize_sense(blkvsc_req->sense_buffer, 695 scsi_normalize_sense(blkvsc_req->sense_buffer,
696 SCSI_SENSE_BUFFERSIZE, &sense_hdr); 696 SCSI_SENSE_BUFFERSIZE, &sense_hdr);
697 if (sense_hdr.asc == 0x3A) { 697 if (sense_hdr.asc == 0x3A) {
@@ -741,14 +741,14 @@ static int blkvsc_remove(struct device *device)
741 741
742 DPRINT_DBG(BLKVSC_DRV, "blkvsc_remove()\n"); 742 DPRINT_DBG(BLKVSC_DRV, "blkvsc_remove()\n");
743 743
744 if (!storvsc_drv_obj->Base.OnDeviceRemove) 744 if (!storvsc_drv_obj->base.OnDeviceRemove)
745 return -1; 745 return -1;
746 746
747 /* 747 /*
748 * Call to the vsc driver to let it know that the device is being 748 * Call to the vsc driver to let it know that the device is being
749 * removed 749 * removed
750 */ 750 */
751 ret = storvsc_drv_obj->Base.OnDeviceRemove(device_obj); 751 ret = storvsc_drv_obj->base.OnDeviceRemove(device_obj);
752 if (ret != 0) { 752 if (ret != 0) {
753 /* TODO: */ 753 /* TODO: */
754 DPRINT_ERR(BLKVSC_DRV, 754 DPRINT_ERR(BLKVSC_DRV,
@@ -865,38 +865,38 @@ static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req,
865 (blkvsc_req->write) ? "WRITE" : "READ", 865 (blkvsc_req->write) ? "WRITE" : "READ",
866 (unsigned long) blkvsc_req->sector_start, 866 (unsigned long) blkvsc_req->sector_start,
867 blkvsc_req->sector_count, 867 blkvsc_req->sector_count,
868 blkvsc_req->request.DataBuffer.Offset, 868 blkvsc_req->request.data_buffer.Offset,
869 blkvsc_req->request.DataBuffer.Length); 869 blkvsc_req->request.data_buffer.Length);
870#if 0 870#if 0
871 for (i = 0; i < (blkvsc_req->request.DataBuffer.Length >> 12); i++) { 871 for (i = 0; i < (blkvsc_req->request.data_buffer.Length >> 12); i++) {
872 DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - " 872 DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - "
873 "req %p pfn[%d] %llx\n", 873 "req %p pfn[%d] %llx\n",
874 blkvsc_req, i, 874 blkvsc_req, i,
875 blkvsc_req->request.DataBuffer.PfnArray[i]); 875 blkvsc_req->request.data_buffer.PfnArray[i]);
876 } 876 }
877#endif 877#endif
878 878
879 storvsc_req = &blkvsc_req->request; 879 storvsc_req = &blkvsc_req->request;
880 storvsc_req->Extension = (void *)((unsigned long)blkvsc_req + 880 storvsc_req->extension = (void *)((unsigned long)blkvsc_req +
881 sizeof(struct blkvsc_request)); 881 sizeof(struct blkvsc_request));
882 882
883 storvsc_req->Type = blkvsc_req->write ? WRITE_TYPE : READ_TYPE; 883 storvsc_req->type = blkvsc_req->write ? WRITE_TYPE : READ_TYPE;
884 884
885 storvsc_req->OnIOCompletion = request_completion; 885 storvsc_req->on_io_completion = request_completion;
886 storvsc_req->Context = blkvsc_req; 886 storvsc_req->context = blkvsc_req;
887 887
888 storvsc_req->Host = blkdev->port; 888 storvsc_req->host = blkdev->port;
889 storvsc_req->Bus = blkdev->path; 889 storvsc_req->bus = blkdev->path;
890 storvsc_req->TargetId = blkdev->target; 890 storvsc_req->target_id = blkdev->target;
891 storvsc_req->LunId = 0; /* this is not really used at all */ 891 storvsc_req->lun_id = 0; /* this is not really used at all */
892 892
893 storvsc_req->CdbLen = blkvsc_req->cmd_len; 893 storvsc_req->cdb_len = blkvsc_req->cmd_len;
894 storvsc_req->Cdb = blkvsc_req->cmnd; 894 storvsc_req->cdb = blkvsc_req->cmnd;
895 895
896 storvsc_req->SenseBuffer = blkvsc_req->sense_buffer; 896 storvsc_req->sense_buffer = blkvsc_req->sense_buffer;
897 storvsc_req->SenseBufferSize = SCSI_SENSE_BUFFERSIZE; 897 storvsc_req->sense_buffer_size = SCSI_SENSE_BUFFERSIZE;
898 898
899 ret = storvsc_drv_obj->OnIORequest(&blkdev->device_ctx->device_obj, 899 ret = storvsc_drv_obj->on_io_request(&blkdev->device_ctx->device_obj,
900 &blkvsc_req->request); 900 &blkvsc_req->request);
901 if (ret == 0) 901 if (ret == 0)
902 blkdev->num_outstanding_reqs++; 902 blkdev->num_outstanding_reqs++;
@@ -992,8 +992,10 @@ static int blkvsc_do_request(struct block_device_context *blkdev,
992 992
993 blkvsc_req->dev = blkdev; 993 blkvsc_req->dev = blkdev;
994 blkvsc_req->req = req; 994 blkvsc_req->req = req;
995 blkvsc_req->request.DataBuffer.Offset = bvec->bv_offset; 995 blkvsc_req->request.data_buffer.Offset
996 blkvsc_req->request.DataBuffer.Length = 0; 996 = bvec->bv_offset;
997 blkvsc_req->request.data_buffer.Length
998 = 0;
997 999
998 /* Add to the group */ 1000 /* Add to the group */
999 blkvsc_req->group = group; 1001 blkvsc_req->group = group;
@@ -1007,8 +1009,11 @@ static int blkvsc_do_request(struct block_device_context *blkdev,
1007 } 1009 }
1008 1010
1009 /* Add the curr bvec/segment to the curr blkvsc_req */ 1011 /* Add the curr bvec/segment to the curr blkvsc_req */
1010 blkvsc_req->request.DataBuffer.PfnArray[databuf_idx] = page_to_pfn(bvec->bv_page); 1012 blkvsc_req->request.data_buffer.
1011 blkvsc_req->request.DataBuffer.Length += bvec->bv_len; 1013 PfnArray[databuf_idx]
1014 = page_to_pfn(bvec->bv_page);
1015 blkvsc_req->request.data_buffer.Length
1016 += bvec->bv_len;
1012 1017
1013 prev_bvec = bvec; 1018 prev_bvec = bvec;
1014 1019
@@ -1073,7 +1078,7 @@ static int blkvsc_do_request(struct block_device_context *blkdev,
1073static void blkvsc_cmd_completion(struct hv_storvsc_request *request) 1078static void blkvsc_cmd_completion(struct hv_storvsc_request *request)
1074{ 1079{
1075 struct blkvsc_request *blkvsc_req = 1080 struct blkvsc_request *blkvsc_req =
1076 (struct blkvsc_request *)request->Context; 1081 (struct blkvsc_request *)request->context;
1077 struct block_device_context *blkdev = 1082 struct block_device_context *blkdev =
1078 (struct block_device_context *)blkvsc_req->dev; 1083 (struct block_device_context *)blkvsc_req->dev;
1079 struct scsi_sense_hdr sense_hdr; 1084 struct scsi_sense_hdr sense_hdr;
@@ -1083,7 +1088,7 @@ static void blkvsc_cmd_completion(struct hv_storvsc_request *request)
1083 1088
1084 blkdev->num_outstanding_reqs--; 1089 blkdev->num_outstanding_reqs--;
1085 1090
1086 if (blkvsc_req->request.Status) 1091 if (blkvsc_req->request.status)
1087 if (scsi_normalize_sense(blkvsc_req->sense_buffer, 1092 if (scsi_normalize_sense(blkvsc_req->sense_buffer,
1088 SCSI_SENSE_BUFFERSIZE, &sense_hdr)) 1093 SCSI_SENSE_BUFFERSIZE, &sense_hdr))
1089 scsi_print_sense_hdr("blkvsc", &sense_hdr); 1094 scsi_print_sense_hdr("blkvsc", &sense_hdr);
@@ -1095,7 +1100,7 @@ static void blkvsc_cmd_completion(struct hv_storvsc_request *request)
1095static void blkvsc_request_completion(struct hv_storvsc_request *request) 1100static void blkvsc_request_completion(struct hv_storvsc_request *request)
1096{ 1101{
1097 struct blkvsc_request *blkvsc_req = 1102 struct blkvsc_request *blkvsc_req =
1098 (struct blkvsc_request *)request->Context; 1103 (struct blkvsc_request *)request->context;
1099 struct block_device_context *blkdev = 1104 struct block_device_context *blkdev =
1100 (struct block_device_context *)blkvsc_req->dev; 1105 (struct block_device_context *)blkvsc_req->dev;
1101 unsigned long flags; 1106 unsigned long flags;
@@ -1110,7 +1115,7 @@ static void blkvsc_request_completion(struct hv_storvsc_request *request)
1110 (blkvsc_req->write) ? "WRITE" : "READ", 1115 (blkvsc_req->write) ? "WRITE" : "READ",
1111 (unsigned long)blkvsc_req->sector_start, 1116 (unsigned long)blkvsc_req->sector_start,
1112 blkvsc_req->sector_count, 1117 blkvsc_req->sector_count,
1113 blkvsc_req->request.DataBuffer.Length, 1118 blkvsc_req->request.data_buffer.Length,
1114 blkvsc_req->group->outstanding, 1119 blkvsc_req->group->outstanding,
1115 blkdev->num_outstanding_reqs); 1120 blkdev->num_outstanding_reqs);
1116 1121
@@ -1137,7 +1142,7 @@ static void blkvsc_request_completion(struct hv_storvsc_request *request)
1137 list_del(&comp_req->req_entry); 1142 list_del(&comp_req->req_entry);
1138 1143
1139 if (!__blk_end_request(comp_req->req, 1144 if (!__blk_end_request(comp_req->req,
1140 (!comp_req->request.Status ? 0 : -EIO), 1145 (!comp_req->request.status ? 0 : -EIO),
1141 comp_req->sector_count * blkdev->sector_size)) { 1146 comp_req->sector_count * blkdev->sector_size)) {
1142 /* 1147 /*
1143 * All the sectors have been xferred ie the 1148 * All the sectors have been xferred ie the
@@ -1195,7 +1200,7 @@ static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev)
1195 1200
1196 if (comp_req->req) { 1201 if (comp_req->req) {
1197 ret = __blk_end_request(comp_req->req, 1202 ret = __blk_end_request(comp_req->req,
1198 (!comp_req->request.Status ? 0 : -EIO), 1203 (!comp_req->request.status ? 0 : -EIO),
1199 comp_req->sector_count * 1204 comp_req->sector_count *
1200 blkdev->sector_size); 1205 blkdev->sector_size);
1201 1206
@@ -1482,7 +1487,7 @@ static int __init blkvsc_init(void)
1482 1487
1483 DPRINT_INFO(BLKVSC_DRV, "Blkvsc initializing...."); 1488 DPRINT_INFO(BLKVSC_DRV, "Blkvsc initializing....");
1484 1489
1485 ret = blkvsc_drv_init(BlkVscInitialize); 1490 ret = blkvsc_drv_init(blk_vsc_initialize);
1486 1491
1487 return ret; 1492 return ret;
1488} 1493}
diff --git a/drivers/staging/hv/channel.c b/drivers/staging/hv/channel.c
index 26ebc77f22b7..45a627d77b41 100644
--- a/drivers/staging/hv/channel.c
+++ b/drivers/staging/hv/channel.c
@@ -43,24 +43,24 @@ static void DumpMonitorPage(struct hv_monitor_page *MonitorPage)
43 int j = 0; 43 int j = 0;
44 44
45 DPRINT_DBG(VMBUS, "monitorPage - %p, trigger state - %d", 45 DPRINT_DBG(VMBUS, "monitorPage - %p, trigger state - %d",
46 MonitorPage, MonitorPage->TriggerState); 46 MonitorPage, MonitorPage->trigger_state);
47 47
48 for (i = 0; i < 4; i++) 48 for (i = 0; i < 4; i++)
49 DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i, 49 DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i,
50 MonitorPage->TriggerGroup[i].AsUINT64); 50 MonitorPage->trigger_group[i].as_uint64);
51 51
52 for (i = 0; i < 4; i++) { 52 for (i = 0; i < 4; i++) {
53 for (j = 0; j < 32; j++) { 53 for (j = 0; j < 32; j++) {
54 DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j, 54 DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j,
55 MonitorPage->Latency[i][j]); 55 MonitorPage->latency[i][j]);
56 } 56 }
57 } 57 }
58 for (i = 0; i < 4; i++) { 58 for (i = 0; i < 4; i++) {
59 for (j = 0; j < 32; j++) { 59 for (j = 0; j < 32; j++) {
60 DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j, 60 DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j,
61 MonitorPage->Parameter[i][j].ConnectionId.Asu32); 61 MonitorPage->parameter[i][j].connectionid.asu32);
62 DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j, 62 DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j,
63 MonitorPage->Parameter[i][j].FlagNumber); 63 MonitorPage->parameter[i][j].flag_number);
64 } 64 }
65 } 65 }
66} 66}
@@ -74,21 +74,21 @@ static void vmbus_setevent(struct vmbus_channel *channel)
74{ 74{
75 struct hv_monitor_page *monitorpage; 75 struct hv_monitor_page *monitorpage;
76 76
77 if (channel->OfferMsg.MonitorAllocated) { 77 if (channel->offermsg.monitor_allocated) {
78 /* Each u32 represents 32 channels */ 78 /* Each u32 represents 32 channels */
79 set_bit(channel->OfferMsg.ChildRelId & 31, 79 set_bit(channel->offermsg.child_relid & 31,
80 (unsigned long *) gVmbusConnection.SendInterruptPage + 80 (unsigned long *) gVmbusConnection.SendInterruptPage +
81 (channel->OfferMsg.ChildRelId >> 5)); 81 (channel->offermsg.child_relid >> 5));
82 82
83 monitorpage = gVmbusConnection.MonitorPages; 83 monitorpage = gVmbusConnection.MonitorPages;
84 monitorpage++; /* Get the child to parent monitor page */ 84 monitorpage++; /* Get the child to parent monitor page */
85 85
86 set_bit(channel->MonitorBit, 86 set_bit(channel->monitor_bit,
87 (unsigned long *)&monitorpage->TriggerGroup 87 (unsigned long *)&monitorpage->trigger_group
88 [channel->MonitorGroup].Pending); 88 [channel->monitor_grp].pending);
89 89
90 } else { 90 } else {
91 VmbusSetEvent(channel->OfferMsg.ChildRelId); 91 VmbusSetEvent(channel->offermsg.child_relid);
92 } 92 }
93} 93}
94 94
@@ -97,19 +97,19 @@ static void VmbusChannelClearEvent(struct vmbus_channel *channel)
97{ 97{
98 struct hv_monitor_page *monitorPage; 98 struct hv_monitor_page *monitorPage;
99 99
100 if (Channel->OfferMsg.MonitorAllocated) { 100 if (Channel->offermsg.monitor_allocated) {
101 /* Each u32 represents 32 channels */ 101 /* Each u32 represents 32 channels */
102 clear_bit(Channel->OfferMsg.ChildRelId & 31, 102 clear_bit(Channel->offermsg.child_relid & 31,
103 (unsigned long *)gVmbusConnection.SendInterruptPage + 103 (unsigned long *)gVmbusConnection.SendInterruptPage +
104 (Channel->OfferMsg.ChildRelId >> 5)); 104 (Channel->offermsg.child_relid >> 5));
105 105
106 monitorPage = 106 monitorPage =
107 (struct hv_monitor_page *)gVmbusConnection.MonitorPages; 107 (struct hv_monitor_page *)gVmbusConnection.MonitorPages;
108 monitorPage++; /* Get the child to parent monitor page */ 108 monitorPage++; /* Get the child to parent monitor page */
109 109
110 clear_bit(Channel->MonitorBit, 110 clear_bit(Channel->monitor_bit,
111 (unsigned long *)&monitorPage->TriggerGroup 111 (unsigned long *)&monitorPage->trigger_group
112 [Channel->MonitorGroup].Pending); 112 [Channel->monitor_grp].Pending);
113 } 113 }
114} 114}
115 115
@@ -121,42 +121,42 @@ void vmbus_get_debug_info(struct vmbus_channel *channel,
121 struct vmbus_channel_debug_info *debuginfo) 121 struct vmbus_channel_debug_info *debuginfo)
122{ 122{
123 struct hv_monitor_page *monitorpage; 123 struct hv_monitor_page *monitorpage;
124 u8 monitor_group = (u8)channel->OfferMsg.MonitorId / 32; 124 u8 monitor_group = (u8)channel->offermsg.monitorid / 32;
125 u8 monitor_offset = (u8)channel->OfferMsg.MonitorId % 32; 125 u8 monitor_offset = (u8)channel->offermsg.monitorid % 32;
126 /* u32 monitorBit = 1 << monitorOffset; */ 126 /* u32 monitorBit = 1 << monitorOffset; */
127 127
128 debuginfo->RelId = channel->OfferMsg.ChildRelId; 128 debuginfo->relid = channel->offermsg.child_relid;
129 debuginfo->State = channel->State; 129 debuginfo->state = channel->state;
130 memcpy(&debuginfo->InterfaceType, 130 memcpy(&debuginfo->interfacetype,
131 &channel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid)); 131 &channel->offermsg.offer.InterfaceType, sizeof(struct hv_guid));
132 memcpy(&debuginfo->InterfaceInstance, 132 memcpy(&debuginfo->interface_instance,
133 &channel->OfferMsg.Offer.InterfaceInstance, 133 &channel->offermsg.offer.InterfaceInstance,
134 sizeof(struct hv_guid)); 134 sizeof(struct hv_guid));
135 135
136 monitorpage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages; 136 monitorpage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages;
137 137
138 debuginfo->MonitorId = channel->OfferMsg.MonitorId; 138 debuginfo->monitorid = channel->offermsg.monitorid;
139 139
140 debuginfo->ServerMonitorPending = 140 debuginfo->servermonitor_pending =
141 monitorpage->TriggerGroup[monitor_group].Pending; 141 monitorpage->trigger_group[monitor_group].pending;
142 debuginfo->ServerMonitorLatency = 142 debuginfo->servermonitor_latency =
143 monitorpage->Latency[monitor_group][monitor_offset]; 143 monitorpage->latency[monitor_group][monitor_offset];
144 debuginfo->ServerMonitorConnectionId = 144 debuginfo->servermonitor_connectionid =
145 monitorpage->Parameter[monitor_group] 145 monitorpage->parameter[monitor_group]
146 [monitor_offset].ConnectionId.u.Id; 146 [monitor_offset].connectionid.u.id;
147 147
148 monitorpage++; 148 monitorpage++;
149 149
150 debuginfo->ClientMonitorPending = 150 debuginfo->clientmonitor_pending =
151 monitorpage->TriggerGroup[monitor_group].Pending; 151 monitorpage->trigger_group[monitor_group].pending;
152 debuginfo->ClientMonitorLatency = 152 debuginfo->clientmonitor_latency =
153 monitorpage->Latency[monitor_group][monitor_offset]; 153 monitorpage->latency[monitor_group][monitor_offset];
154 debuginfo->ClientMonitorConnectionId = 154 debuginfo->clientmonitor_connectionid =
155 monitorpage->Parameter[monitor_group] 155 monitorpage->parameter[monitor_group]
156 [monitor_offset].ConnectionId.u.Id; 156 [monitor_offset].connectionid.u.id;
157 157
158 RingBufferGetDebugInfo(&channel->Inbound, &debuginfo->Inbound); 158 ringbuffer_get_debuginfo(&channel->inbound, &debuginfo->inbound);
159 RingBufferGetDebugInfo(&channel->Outbound, &debuginfo->Outbound); 159 ringbuffer_get_debuginfo(&channel->outbound, &debuginfo->outbound);
160} 160}
161 161
162/* 162/*
@@ -176,11 +176,11 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
176 /* ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1))); */ 176 /* ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1))); */
177 /* ASSERT(!(RecvRingBufferSize & (PAGE_SIZE - 1))); */ 177 /* ASSERT(!(RecvRingBufferSize & (PAGE_SIZE - 1))); */
178 178
179 newchannel->OnChannelCallback = onchannelcallback; 179 newchannel->onchannel_callback = onchannelcallback;
180 newchannel->ChannelCallbackContext = context; 180 newchannel->channel_callback_context = context;
181 181
182 /* Allocate the ring buffer */ 182 /* Allocate the ring buffer */
183 out = osd_PageAlloc((send_ringbuffer_size + recv_ringbuffer_size) 183 out = osd_page_alloc((send_ringbuffer_size + recv_ringbuffer_size)
184 >> PAGE_SHIFT); 184 >> PAGE_SHIFT);
185 if (!out) 185 if (!out)
186 return -ENOMEM; 186 return -ENOMEM;
@@ -189,17 +189,17 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
189 189
190 in = (void *)((unsigned long)out + send_ringbuffer_size); 190 in = (void *)((unsigned long)out + send_ringbuffer_size);
191 191
192 newchannel->RingBufferPages = out; 192 newchannel->ringbuffer_pages = out;
193 newchannel->RingBufferPageCount = (send_ringbuffer_size + 193 newchannel->ringbuffer_pagecount = (send_ringbuffer_size +
194 recv_ringbuffer_size) >> PAGE_SHIFT; 194 recv_ringbuffer_size) >> PAGE_SHIFT;
195 195
196 ret = RingBufferInit(&newchannel->Outbound, out, send_ringbuffer_size); 196 ret = ringbuffer_init(&newchannel->outbound, out, send_ringbuffer_size);
197 if (ret != 0) { 197 if (ret != 0) {
198 err = ret; 198 err = ret;
199 goto errorout; 199 goto errorout;
200 } 200 }
201 201
202 ret = RingBufferInit(&newchannel->Inbound, in, recv_ringbuffer_size); 202 ret = ringbuffer_init(&newchannel->inbound, in, recv_ringbuffer_size);
203 if (ret != 0) { 203 if (ret != 0) {
204 err = ret; 204 err = ret;
205 goto errorout; 205 goto errorout;
@@ -210,13 +210,13 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
210 DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...", 210 DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...",
211 newchannel); 211 newchannel);
212 212
213 newchannel->RingBufferGpadlHandle = 0; 213 newchannel->ringbuffer_gpadlhandle = 0;
214 214
215 ret = vmbus_establish_gpadl(newchannel, 215 ret = vmbus_establish_gpadl(newchannel,
216 newchannel->Outbound.RingBuffer, 216 newchannel->outbound.ring_buffer,
217 send_ringbuffer_size + 217 send_ringbuffer_size +
218 recv_ringbuffer_size, 218 recv_ringbuffer_size,
219 &newchannel->RingBufferGpadlHandle); 219 &newchannel->ringbuffer_gpadlhandle);
220 220
221 if (ret != 0) { 221 if (ret != 0) {
222 err = ret; 222 err = ret;
@@ -225,12 +225,12 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
225 225
226 DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p " 226 DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p "
227 "size %d recv ring %p size %d, downstreamoffset %d>", 227 "size %d recv ring %p size %d, downstreamoffset %d>",
228 newchannel, newchannel->OfferMsg.ChildRelId, 228 newchannel, newchannel->offermsg.child_relid,
229 newchannel->RingBufferGpadlHandle, 229 newchannel->ringbuffer_gpadlhandle,
230 newchannel->Outbound.RingBuffer, 230 newchannel->outbound.ring_buffer,
231 newchannel->Outbound.RingSize, 231 newchannel->outbound.ring_size,
232 newchannel->Inbound.RingBuffer, 232 newchannel->inbound.ring_buffer,
233 newchannel->Inbound.RingSize, 233 newchannel->inbound.ring_size,
234 send_ringbuffer_size); 234 send_ringbuffer_size);
235 235
236 /* Create and init the channel open message */ 236 /* Create and init the channel open message */
@@ -242,20 +242,20 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
242 goto errorout; 242 goto errorout;
243 } 243 }
244 244
245 openInfo->WaitEvent = osd_WaitEventCreate(); 245 openInfo->waitevent = osd_waitevent_create();
246 if (!openInfo->WaitEvent) { 246 if (!openInfo->waitevent) {
247 err = -ENOMEM; 247 err = -ENOMEM;
248 goto errorout; 248 goto errorout;
249 } 249 }
250 250
251 openMsg = (struct vmbus_channel_open_channel *)openInfo->Msg; 251 openMsg = (struct vmbus_channel_open_channel *)openInfo->msg;
252 openMsg->Header.MessageType = ChannelMessageOpenChannel; 252 openMsg->header.msgtype = CHANNELMSG_OPENCHANNEL;
253 openMsg->OpenId = newchannel->OfferMsg.ChildRelId; /* FIXME */ 253 openMsg->openid = newchannel->offermsg.child_relid; /* FIXME */
254 openMsg->ChildRelId = newchannel->OfferMsg.ChildRelId; 254 openMsg->child_relid = newchannel->offermsg.child_relid;
255 openMsg->RingBufferGpadlHandle = newchannel->RingBufferGpadlHandle; 255 openMsg->ringbuffer_gpadlhandle = newchannel->ringbuffer_gpadlhandle;
256 openMsg->DownstreamRingBufferPageOffset = send_ringbuffer_size >> 256 openMsg->downstream_ringbuffer_pageoffset = send_ringbuffer_size >>
257 PAGE_SHIFT; 257 PAGE_SHIFT;
258 openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */ 258 openMsg->server_contextarea_gpadlhandle = 0; /* TODO */
259 259
260 if (userdatalen > MAX_USER_DEFINED_BYTES) { 260 if (userdatalen > MAX_USER_DEFINED_BYTES) {
261 err = -EINVAL; 261 err = -EINVAL;
@@ -263,10 +263,10 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
263 } 263 }
264 264
265 if (userdatalen) 265 if (userdatalen)
266 memcpy(openMsg->UserData, userdata, userdatalen); 266 memcpy(openMsg->userdata, userdata, userdatalen);
267 267
268 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); 268 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
269 list_add_tail(&openInfo->MsgListEntry, 269 list_add_tail(&openInfo->msglistentry,
270 &gVmbusConnection.ChannelMsgList); 270 &gVmbusConnection.ChannelMsgList);
271 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); 271 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
272 272
@@ -280,27 +280,27 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
280 } 280 }
281 281
282 /* FIXME: Need to time-out here */ 282 /* FIXME: Need to time-out here */
283 osd_WaitEventWait(openInfo->WaitEvent); 283 osd_waitevent_wait(openInfo->waitevent);
284 284
285 if (openInfo->Response.OpenResult.Status == 0) 285 if (openInfo->response.open_result.status == 0)
286 DPRINT_INFO(VMBUS, "channel <%p> open success!!", newchannel); 286 DPRINT_INFO(VMBUS, "channel <%p> open success!!", newchannel);
287 else 287 else
288 DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!", 288 DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!",
289 newchannel, openInfo->Response.OpenResult.Status); 289 newchannel, openInfo->response.open_result.status);
290 290
291Cleanup: 291Cleanup:
292 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); 292 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
293 list_del(&openInfo->MsgListEntry); 293 list_del(&openInfo->msglistentry);
294 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); 294 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
295 295
296 kfree(openInfo->WaitEvent); 296 kfree(openInfo->waitevent);
297 kfree(openInfo); 297 kfree(openInfo);
298 return 0; 298 return 0;
299 299
300errorout: 300errorout:
301 RingBufferCleanup(&newchannel->Outbound); 301 ringbuffer_cleanup(&newchannel->outbound);
302 RingBufferCleanup(&newchannel->Inbound); 302 ringbuffer_cleanup(&newchannel->inbound);
303 osd_PageFree(out, (send_ringbuffer_size + recv_ringbuffer_size) 303 osd_page_free(out, (send_ringbuffer_size + recv_ringbuffer_size)
304 >> PAGE_SHIFT); 304 >> PAGE_SHIFT);
305 kfree(openInfo); 305 kfree(openInfo);
306 return err; 306 return err;
@@ -322,7 +322,7 @@ static void dump_gpadl_body(struct vmbus_channel_gpadl_body *gpadl, u32 len)
322 322
323 for (i = 0; i < pfncount; i++) 323 for (i = 0; i < pfncount; i++)
324 DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu", 324 DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu",
325 i, gpadl->Pfn[i]); 325 i, gpadl->pfn[i]);
326} 326}
327 327
328/* 328/*
@@ -336,18 +336,18 @@ static void dump_gpadl_header(struct vmbus_channel_gpadl_header *gpadl)
336 336
337 DPRINT_DBG(VMBUS, 337 DPRINT_DBG(VMBUS,
338 "gpadl header - relid %d, range count %d, range buflen %d", 338 "gpadl header - relid %d, range count %d, range buflen %d",
339 gpadl->ChildRelId, gpadl->RangeCount, gpadl->RangeBufLen); 339 gpadl->child_relid, gpadl->rangecount, gpadl->range_buflen);
340 for (i = 0; i < gpadl->RangeCount; i++) { 340 for (i = 0; i < gpadl->rangecount; i++) {
341 pagecount = gpadl->Range[i].ByteCount >> PAGE_SHIFT; 341 pagecount = gpadl->range[i].ByteCount >> PAGE_SHIFT;
342 pagecount = (pagecount > 26) ? 26 : pagecount; 342 pagecount = (pagecount > 26) ? 26 : pagecount;
343 343
344 DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d " 344 DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d "
345 "page count %d", i, gpadl->Range[i].ByteCount, 345 "page count %d", i, gpadl->range[i].ByteCount,
346 gpadl->Range[i].ByteOffset, pagecount); 346 gpadl->range[i].ByteOffset, pagecount);
347 347
348 for (j = 0; j < pagecount; j++) 348 for (j = 0; j < pagecount; j++)
349 DPRINT_DBG(VMBUS, "%d) pfn %llu", j, 349 DPRINT_DBG(VMBUS, "%d) pfn %llu", j,
350 gpadl->Range[i].PfnArray[j]); 350 gpadl->range[i].PfnArray[j]);
351 } 351 }
352} 352}
353 353
@@ -391,18 +391,18 @@ static int create_gpadl_header(void *kbuffer, u32 size,
391 if (!msgheader) 391 if (!msgheader)
392 goto nomem; 392 goto nomem;
393 393
394 INIT_LIST_HEAD(&msgheader->SubMsgList); 394 INIT_LIST_HEAD(&msgheader->submsglist);
395 msgheader->MessageSize = msgsize; 395 msgheader->msgsize = msgsize;
396 396
397 gpadl_header = (struct vmbus_channel_gpadl_header *) 397 gpadl_header = (struct vmbus_channel_gpadl_header *)
398 msgheader->Msg; 398 msgheader->msg;
399 gpadl_header->RangeCount = 1; 399 gpadl_header->rangecount = 1;
400 gpadl_header->RangeBufLen = sizeof(struct gpa_range) + 400 gpadl_header->range_buflen = sizeof(struct gpa_range) +
401 pagecount * sizeof(u64); 401 pagecount * sizeof(u64);
402 gpadl_header->Range[0].ByteOffset = 0; 402 gpadl_header->range[0].ByteOffset = 0;
403 gpadl_header->Range[0].ByteCount = size; 403 gpadl_header->range[0].ByteCount = size;
404 for (i = 0; i < pfncount; i++) 404 for (i = 0; i < pfncount; i++)
405 gpadl_header->Range[0].PfnArray[i] = pfn+i; 405 gpadl_header->range[0].PfnArray[i] = pfn+i;
406 *msginfo = msgheader; 406 *msginfo = msgheader;
407 *messagecount = 1; 407 *messagecount = 1;
408 408
@@ -428,10 +428,10 @@ static int create_gpadl_header(void *kbuffer, u32 size,
428 /* FIXME: we probably need to more if this fails */ 428 /* FIXME: we probably need to more if this fails */
429 if (!msgbody) 429 if (!msgbody)
430 goto nomem; 430 goto nomem;
431 msgbody->MessageSize = msgsize; 431 msgbody->msgsize = msgsize;
432 (*messagecount)++; 432 (*messagecount)++;
433 gpadl_body = 433 gpadl_body =
434 (struct vmbus_channel_gpadl_body *)msgbody->Msg; 434 (struct vmbus_channel_gpadl_body *)msgbody->msg;
435 435
436 /* 436 /*
437 * FIXME: 437 * FIXME:
@@ -440,11 +440,11 @@ static int create_gpadl_header(void *kbuffer, u32 size,
440 */ 440 */
441 /* gpadl_body->Gpadl = kbuffer; */ 441 /* gpadl_body->Gpadl = kbuffer; */
442 for (i = 0; i < pfncurr; i++) 442 for (i = 0; i < pfncurr; i++)
443 gpadl_body->Pfn[i] = pfn + pfnsum + i; 443 gpadl_body->pfn[i] = pfn + pfnsum + i;
444 444
445 /* add to msg header */ 445 /* add to msg header */
446 list_add_tail(&msgbody->MsgListEntry, 446 list_add_tail(&msgbody->msglistentry,
447 &msgheader->SubMsgList); 447 &msgheader->submsglist);
448 pfnsum += pfncurr; 448 pfnsum += pfncurr;
449 pfnleft -= pfncurr; 449 pfnleft -= pfncurr;
450 } 450 }
@@ -456,17 +456,17 @@ static int create_gpadl_header(void *kbuffer, u32 size,
456 msgheader = kzalloc(msgsize, GFP_KERNEL); 456 msgheader = kzalloc(msgsize, GFP_KERNEL);
457 if (msgheader == NULL) 457 if (msgheader == NULL)
458 goto nomem; 458 goto nomem;
459 msgheader->MessageSize = msgsize; 459 msgheader->msgsize = msgsize;
460 460
461 gpadl_header = (struct vmbus_channel_gpadl_header *) 461 gpadl_header = (struct vmbus_channel_gpadl_header *)
462 msgheader->Msg; 462 msgheader->msg;
463 gpadl_header->RangeCount = 1; 463 gpadl_header->rangecount = 1;
464 gpadl_header->RangeBufLen = sizeof(struct gpa_range) + 464 gpadl_header->range_buflen = sizeof(struct gpa_range) +
465 pagecount * sizeof(u64); 465 pagecount * sizeof(u64);
466 gpadl_header->Range[0].ByteOffset = 0; 466 gpadl_header->range[0].ByteOffset = 0;
467 gpadl_header->Range[0].ByteCount = size; 467 gpadl_header->range[0].ByteCount = size;
468 for (i = 0; i < pagecount; i++) 468 for (i = 0; i < pagecount; i++)
469 gpadl_header->Range[0].PfnArray[i] = pfn+i; 469 gpadl_header->range[0].PfnArray[i] = pfn+i;
470 470
471 *msginfo = msgheader; 471 *msginfo = msgheader;
472 *messagecount = 1; 472 *messagecount = 1;
@@ -508,21 +508,21 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
508 if (ret) 508 if (ret)
509 return ret; 509 return ret;
510 510
511 msginfo->WaitEvent = osd_WaitEventCreate(); 511 msginfo->waitevent = osd_waitevent_create();
512 if (!msginfo->WaitEvent) { 512 if (!msginfo->waitevent) {
513 ret = -ENOMEM; 513 ret = -ENOMEM;
514 goto Cleanup; 514 goto Cleanup;
515 } 515 }
516 516
517 gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->Msg; 517 gpadlmsg = (struct vmbus_channel_gpadl_header *)msginfo->msg;
518 gpadlmsg->Header.MessageType = ChannelMessageGpadlHeader; 518 gpadlmsg->header.msgtype = CHANNELMSG_GPADL_HEADER;
519 gpadlmsg->ChildRelId = channel->OfferMsg.ChildRelId; 519 gpadlmsg->child_relid = channel->offermsg.child_relid;
520 gpadlmsg->Gpadl = next_gpadl_handle; 520 gpadlmsg->gpadl = next_gpadl_handle;
521 521
522 dump_gpadl_header(gpadlmsg); 522 dump_gpadl_header(gpadlmsg);
523 523
524 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); 524 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
525 list_add_tail(&msginfo->MsgListEntry, 525 list_add_tail(&msginfo->msglistentry,
526 &gVmbusConnection.ChannelMsgList); 526 &gVmbusConnection.ChannelMsgList);
527 527
528 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); 528 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
@@ -530,9 +530,9 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
530 kbuffer, size, msgcount); 530 kbuffer, size, msgcount);
531 531
532 DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", 532 DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd",
533 msginfo->MessageSize - sizeof(*msginfo)); 533 msginfo->msgsize - sizeof(*msginfo));
534 534
535 ret = VmbusPostMessage(gpadlmsg, msginfo->MessageSize - 535 ret = VmbusPostMessage(gpadlmsg, msginfo->msgsize -
536 sizeof(*msginfo)); 536 sizeof(*msginfo));
537 if (ret != 0) { 537 if (ret != 0) {
538 DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret); 538 DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret);
@@ -540,48 +540,48 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
540 } 540 }
541 541
542 if (msgcount > 1) { 542 if (msgcount > 1) {
543 list_for_each(curr, &msginfo->SubMsgList) { 543 list_for_each(curr, &msginfo->submsglist) {
544 544
545 /* FIXME: should this use list_entry() instead ? */ 545 /* FIXME: should this use list_entry() instead ? */
546 submsginfo = (struct vmbus_channel_msginfo *)curr; 546 submsginfo = (struct vmbus_channel_msginfo *)curr;
547 gpadl_body = 547 gpadl_body =
548 (struct vmbus_channel_gpadl_body *)submsginfo->Msg; 548 (struct vmbus_channel_gpadl_body *)submsginfo->msg;
549 549
550 gpadl_body->Header.MessageType = 550 gpadl_body->header.msgtype =
551 ChannelMessageGpadlBody; 551 CHANNELMSG_GPADL_BODY;
552 gpadl_body->Gpadl = next_gpadl_handle; 552 gpadl_body->gpadl = next_gpadl_handle;
553 553
554 DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", 554 DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd",
555 submsginfo->MessageSize - 555 submsginfo->msgsize -
556 sizeof(*submsginfo)); 556 sizeof(*submsginfo));
557 557
558 dump_gpadl_body(gpadl_body, submsginfo->MessageSize - 558 dump_gpadl_body(gpadl_body, submsginfo->msgsize -
559 sizeof(*submsginfo)); 559 sizeof(*submsginfo));
560 ret = VmbusPostMessage(gpadl_body, 560 ret = VmbusPostMessage(gpadl_body,
561 submsginfo->MessageSize - 561 submsginfo->msgsize -
562 sizeof(*submsginfo)); 562 sizeof(*submsginfo));
563 if (ret != 0) 563 if (ret != 0)
564 goto Cleanup; 564 goto Cleanup;
565 565
566 } 566 }
567 } 567 }
568 osd_WaitEventWait(msginfo->WaitEvent); 568 osd_waitevent_wait(msginfo->waitevent);
569 569
570 /* At this point, we received the gpadl created msg */ 570 /* At this point, we received the gpadl created msg */
571 DPRINT_DBG(VMBUS, "Received GPADL created " 571 DPRINT_DBG(VMBUS, "Received GPADL created "
572 "(relid %d, status %d handle %x)", 572 "(relid %d, status %d handle %x)",
573 channel->OfferMsg.ChildRelId, 573 channel->offermsg.child_relid,
574 msginfo->Response.GpadlCreated.CreationStatus, 574 msginfo->response.gpadl_created.creation_status,
575 gpadlmsg->Gpadl); 575 gpadlmsg->gpadl);
576 576
577 *gpadl_handle = gpadlmsg->Gpadl; 577 *gpadl_handle = gpadlmsg->gpadl;
578 578
579Cleanup: 579Cleanup:
580 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); 580 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
581 list_del(&msginfo->MsgListEntry); 581 list_del(&msginfo->msglistentry);
582 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); 582 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
583 583
584 kfree(msginfo->WaitEvent); 584 kfree(msginfo->waitevent);
585 kfree(msginfo); 585 kfree(msginfo);
586 return ret; 586 return ret;
587} 587}
@@ -604,20 +604,20 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle)
604 if (!info) 604 if (!info)
605 return -ENOMEM; 605 return -ENOMEM;
606 606
607 info->WaitEvent = osd_WaitEventCreate(); 607 info->waitevent = osd_waitevent_create();
608 if (!info->WaitEvent) { 608 if (!info->waitevent) {
609 kfree(info); 609 kfree(info);
610 return -ENOMEM; 610 return -ENOMEM;
611 } 611 }
612 612
613 msg = (struct vmbus_channel_gpadl_teardown *)info->Msg; 613 msg = (struct vmbus_channel_gpadl_teardown *)info->msg;
614 614
615 msg->Header.MessageType = ChannelMessageGpadlTeardown; 615 msg->header.msgtype = CHANNELMSG_GPADL_TEARDOWN;
616 msg->ChildRelId = channel->OfferMsg.ChildRelId; 616 msg->child_relid = channel->offermsg.child_relid;
617 msg->Gpadl = gpadl_handle; 617 msg->gpadl = gpadl_handle;
618 618
619 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); 619 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
620 list_add_tail(&info->MsgListEntry, 620 list_add_tail(&info->msglistentry,
621 &gVmbusConnection.ChannelMsgList); 621 &gVmbusConnection.ChannelMsgList);
622 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); 622 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
623 623
@@ -628,14 +628,14 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle)
628 /* something... */ 628 /* something... */
629 } 629 }
630 630
631 osd_WaitEventWait(info->WaitEvent); 631 osd_waitevent_wait(info->waitevent);
632 632
633 /* Received a torndown response */ 633 /* Received a torndown response */
634 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); 634 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
635 list_del(&info->MsgListEntry); 635 list_del(&info->msglistentry);
636 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); 636 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
637 637
638 kfree(info->WaitEvent); 638 kfree(info->waitevent);
639 kfree(info); 639 kfree(info);
640 return ret; 640 return ret;
641} 641}
@@ -652,7 +652,7 @@ void vmbus_close(struct vmbus_channel *channel)
652 int ret; 652 int ret;
653 653
654 /* Stop callback and cancel the timer asap */ 654 /* Stop callback and cancel the timer asap */
655 channel->OnChannelCallback = NULL; 655 channel->onchannel_callback = NULL;
656 del_timer_sync(&channel->poll_timer); 656 del_timer_sync(&channel->poll_timer);
657 657
658 /* Send a closing message */ 658 /* Send a closing message */
@@ -663,11 +663,11 @@ void vmbus_close(struct vmbus_channel *channel)
663 if (!info) 663 if (!info)
664 return; 664 return;
665 665
666 /* info->waitEvent = osd_WaitEventCreate(); */ 666 /* info->waitEvent = osd_waitevent_create(); */
667 667
668 msg = (struct vmbus_channel_close_channel *)info->Msg; 668 msg = (struct vmbus_channel_close_channel *)info->msg;
669 msg->Header.MessageType = ChannelMessageCloseChannel; 669 msg->header.msgtype = CHANNELMSG_CLOSECHANNEL;
670 msg->ChildRelId = channel->OfferMsg.ChildRelId; 670 msg->child_relid = channel->offermsg.child_relid;
671 671
672 ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_close_channel)); 672 ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_close_channel));
673 if (ret != 0) { 673 if (ret != 0) {
@@ -676,17 +676,17 @@ void vmbus_close(struct vmbus_channel *channel)
676 } 676 }
677 677
678 /* Tear down the gpadl for the channel's ring buffer */ 678 /* Tear down the gpadl for the channel's ring buffer */
679 if (channel->RingBufferGpadlHandle) 679 if (channel->ringbuffer_gpadlhandle)
680 vmbus_teardown_gpadl(channel, 680 vmbus_teardown_gpadl(channel,
681 channel->RingBufferGpadlHandle); 681 channel->ringbuffer_gpadlhandle);
682 682
683 /* TODO: Send a msg to release the childRelId */ 683 /* TODO: Send a msg to release the childRelId */
684 684
685 /* Cleanup the ring buffers for this channel */ 685 /* Cleanup the ring buffers for this channel */
686 RingBufferCleanup(&channel->Outbound); 686 ringbuffer_cleanup(&channel->outbound);
687 RingBufferCleanup(&channel->Inbound); 687 ringbuffer_cleanup(&channel->inbound);
688 688
689 osd_PageFree(channel->RingBufferPages, channel->RingBufferPageCount); 689 osd_page_free(channel->ringbuffer_pages, channel->ringbuffer_pagecount);
690 690
691 kfree(info); 691 kfree(info);
692 692
@@ -696,9 +696,9 @@ void vmbus_close(struct vmbus_channel *channel)
696 * caller will free the channel 696 * caller will free the channel
697 */ 697 */
698 698
699 if (channel->State == CHANNEL_OPEN_STATE) { 699 if (channel->state == CHANNEL_OPEN_STATE) {
700 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); 700 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
701 list_del(&channel->ListEntry); 701 list_del(&channel->listentry);
702 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); 702 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
703 703
704 free_channel(channel); 704 free_channel(channel);
@@ -752,10 +752,10 @@ int vmbus_sendpacket(struct vmbus_channel *channel, const void *buffer,
752 sg_set_buf(&bufferlist[2], &aligned_data, 752 sg_set_buf(&bufferlist[2], &aligned_data,
753 packetlen_aligned - packetlen); 753 packetlen_aligned - packetlen);
754 754
755 ret = RingBufferWrite(&channel->Outbound, bufferlist, 3); 755 ret = ringbuffer_write(&channel->outbound, bufferlist, 3);
756 756
757 /* TODO: We should determine if this is optional */ 757 /* TODO: We should determine if this is optional */
758 if (ret == 0 && !GetRingBufferInterruptMask(&channel->Outbound)) 758 if (ret == 0 && !get_ringbuffer_interrupt_mask(&channel->outbound))
759 vmbus_setevent(channel); 759 vmbus_setevent(channel);
760 760
761 return ret; 761 return ret;
@@ -817,10 +817,10 @@ int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
817 sg_set_buf(&bufferlist[2], &aligned_data, 817 sg_set_buf(&bufferlist[2], &aligned_data,
818 packetlen_aligned - packetlen); 818 packetlen_aligned - packetlen);
819 819
820 ret = RingBufferWrite(&channel->Outbound, bufferlist, 3); 820 ret = ringbuffer_write(&channel->outbound, bufferlist, 3);
821 821
822 /* TODO: We should determine if this is optional */ 822 /* TODO: We should determine if this is optional */
823 if (ret == 0 && !GetRingBufferInterruptMask(&channel->Outbound)) 823 if (ret == 0 && !get_ringbuffer_interrupt_mask(&channel->outbound))
824 vmbus_setevent(channel); 824 vmbus_setevent(channel);
825 825
826 return ret; 826 return ret;
@@ -886,10 +886,10 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
886 sg_set_buf(&bufferlist[2], &aligned_data, 886 sg_set_buf(&bufferlist[2], &aligned_data,
887 packetlen_aligned - packetlen); 887 packetlen_aligned - packetlen);
888 888
889 ret = RingBufferWrite(&channel->Outbound, bufferlist, 3); 889 ret = ringbuffer_write(&channel->outbound, bufferlist, 3);
890 890
891 /* TODO: We should determine if this is optional */ 891 /* TODO: We should determine if this is optional */
892 if (ret == 0 && !GetRingBufferInterruptMask(&channel->Outbound)) 892 if (ret == 0 && !get_ringbuffer_interrupt_mask(&channel->outbound))
893 vmbus_setevent(channel); 893 vmbus_setevent(channel);
894 894
895 return ret; 895 return ret;
@@ -923,7 +923,7 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer,
923 923
924 spin_lock_irqsave(&channel->inbound_lock, flags); 924 spin_lock_irqsave(&channel->inbound_lock, flags);
925 925
926 ret = RingBufferPeek(&channel->Inbound, &desc, 926 ret = ringbuffer_peek(&channel->inbound, &desc,
927 sizeof(struct vmpacket_descriptor)); 927 sizeof(struct vmpacket_descriptor));
928 if (ret != 0) { 928 if (ret != 0) {
929 spin_unlock_irqrestore(&channel->inbound_lock, flags); 929 spin_unlock_irqrestore(&channel->inbound_lock, flags);
@@ -940,7 +940,7 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer,
940 940
941 DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d " 941 DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d "
942 "flag %d tid %llx pktlen %d datalen %d> ", 942 "flag %d tid %llx pktlen %d datalen %d> ",
943 channel, channel->OfferMsg.ChildRelId, desc.Type, 943 channel, channel->offermsg.child_relid, desc.Type,
944 desc.Flags, desc.TransactionId, packetlen, userlen); 944 desc.Flags, desc.TransactionId, packetlen, userlen);
945 945
946 *buffer_actual_len = userlen; 946 *buffer_actual_len = userlen;
@@ -956,7 +956,7 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer,
956 *requestid = desc.TransactionId; 956 *requestid = desc.TransactionId;
957 957
958 /* Copy over the packet to the user buffer */ 958 /* Copy over the packet to the user buffer */
959 ret = RingBufferRead(&channel->Inbound, buffer, userlen, 959 ret = ringbuffer_read(&channel->inbound, buffer, userlen,
960 (desc.DataOffset8 << 3)); 960 (desc.DataOffset8 << 3));
961 961
962 spin_unlock_irqrestore(&channel->inbound_lock, flags); 962 spin_unlock_irqrestore(&channel->inbound_lock, flags);
@@ -983,7 +983,7 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer,
983 983
984 spin_lock_irqsave(&channel->inbound_lock, flags); 984 spin_lock_irqsave(&channel->inbound_lock, flags);
985 985
986 ret = RingBufferPeek(&channel->Inbound, &desc, 986 ret = ringbuffer_peek(&channel->inbound, &desc,
987 sizeof(struct vmpacket_descriptor)); 987 sizeof(struct vmpacket_descriptor));
988 if (ret != 0) { 988 if (ret != 0) {
989 spin_unlock_irqrestore(&channel->inbound_lock, flags); 989 spin_unlock_irqrestore(&channel->inbound_lock, flags);
@@ -999,7 +999,7 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer,
999 999
1000 DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d " 1000 DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d "
1001 "flag %d tid %llx pktlen %d datalen %d> ", 1001 "flag %d tid %llx pktlen %d datalen %d> ",
1002 channel, channel->OfferMsg.ChildRelId, desc.Type, 1002 channel, channel->offermsg.child_relid, desc.Type,
1003 desc.Flags, desc.TransactionId, packetlen, userlen); 1003 desc.Flags, desc.TransactionId, packetlen, userlen);
1004 1004
1005 *buffer_actual_len = packetlen; 1005 *buffer_actual_len = packetlen;
@@ -1015,7 +1015,7 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer,
1015 *requestid = desc.TransactionId; 1015 *requestid = desc.TransactionId;
1016 1016
1017 /* Copy over the entire packet to the user buffer */ 1017 /* Copy over the entire packet to the user buffer */
1018 ret = RingBufferRead(&channel->Inbound, buffer, packetlen, 0); 1018 ret = ringbuffer_read(&channel->inbound, buffer, packetlen, 0);
1019 1019
1020 spin_unlock_irqrestore(&channel->inbound_lock, flags); 1020 spin_unlock_irqrestore(&channel->inbound_lock, flags);
1021 return 0; 1021 return 0;
@@ -1030,7 +1030,7 @@ void vmbus_onchannel_event(struct vmbus_channel *channel)
1030 dump_vmbus_channel(channel); 1030 dump_vmbus_channel(channel);
1031 /* ASSERT(Channel->OnChannelCallback); */ 1031 /* ASSERT(Channel->OnChannelCallback); */
1032 1032
1033 channel->OnChannelCallback(channel->ChannelCallbackContext); 1033 channel->onchannel_callback(channel->channel_callback_context);
1034 1034
1035 mod_timer(&channel->poll_timer, jiffies + usecs_to_jiffies(100)); 1035 mod_timer(&channel->poll_timer, jiffies + usecs_to_jiffies(100));
1036} 1036}
@@ -1042,8 +1042,8 @@ void vmbus_ontimer(unsigned long data)
1042{ 1042{
1043 struct vmbus_channel *channel = (struct vmbus_channel *)data; 1043 struct vmbus_channel *channel = (struct vmbus_channel *)data;
1044 1044
1045 if (channel->OnChannelCallback) 1045 if (channel->onchannel_callback)
1046 channel->OnChannelCallback(channel->ChannelCallbackContext); 1046 channel->onchannel_callback(channel->channel_callback_context);
1047} 1047}
1048 1048
1049/* 1049/*
@@ -1051,7 +1051,7 @@ void vmbus_ontimer(unsigned long data)
1051 */ 1051 */
1052static void dump_vmbus_channel(struct vmbus_channel *channel) 1052static void dump_vmbus_channel(struct vmbus_channel *channel)
1053{ 1053{
1054 DPRINT_DBG(VMBUS, "Channel (%d)", channel->OfferMsg.ChildRelId); 1054 DPRINT_DBG(VMBUS, "Channel (%d)", channel->offermsg.child_relid);
1055 DumpRingInfo(&channel->Outbound, "Outbound "); 1055 dump_ring_info(&channel->outbound, "Outbound ");
1056 DumpRingInfo(&channel->Inbound, "Inbound "); 1056 dump_ring_info(&channel->inbound, "Inbound ");
1057} 1057}
diff --git a/drivers/staging/hv/channel_mgmt.c b/drivers/staging/hv/channel_mgmt.c
index 45dbe305afed..d44d5c39f68b 100644
--- a/drivers/staging/hv/channel_mgmt.c
+++ b/drivers/staging/hv/channel_mgmt.c
@@ -251,8 +251,8 @@ static struct vmbus_channel *alloc_channel(void)
251 channel->poll_timer.data = (unsigned long)channel; 251 channel->poll_timer.data = (unsigned long)channel;
252 channel->poll_timer.function = vmbus_ontimer; 252 channel->poll_timer.function = vmbus_ontimer;
253 253
254 channel->ControlWQ = create_workqueue("hv_vmbus_ctl"); 254 channel->controlwq = create_workqueue("hv_vmbus_ctl");
255 if (!channel->ControlWQ) { 255 if (!channel->controlwq) {
256 kfree(channel); 256 kfree(channel);
257 return NULL; 257 return NULL;
258 } 258 }
@@ -263,12 +263,14 @@ static struct vmbus_channel *alloc_channel(void)
263/* 263/*
264 * release_hannel - Release the vmbus channel object itself 264 * release_hannel - Release the vmbus channel object itself
265 */ 265 */
266static inline void release_channel(void *context) 266static void release_channel(struct work_struct *work)
267{ 267{
268 struct vmbus_channel *channel = context; 268 struct vmbus_channel *channel = container_of(work,
269 struct vmbus_channel,
270 work);
269 271
270 DPRINT_DBG(VMBUS, "releasing channel (%p)", channel); 272 DPRINT_DBG(VMBUS, "releasing channel (%p)", channel);
271 destroy_workqueue(channel->ControlWQ); 273 destroy_workqueue(channel->controlwq);
272 DPRINT_DBG(VMBUS, "channel released (%p)", channel); 274 DPRINT_DBG(VMBUS, "channel released (%p)", channel);
273 275
274 kfree(channel); 276 kfree(channel);
@@ -286,8 +288,8 @@ void free_channel(struct vmbus_channel *channel)
286 * workqueue/thread context 288 * workqueue/thread context
287 * ie we can't destroy ourselves. 289 * ie we can't destroy ourselves.
288 */ 290 */
289 osd_schedule_callback(gVmbusConnection.WorkQueue, release_channel, 291 INIT_WORK(&channel->work, release_channel);
290 channel); 292 queue_work(gVmbusConnection.WorkQueue, &channel->work);
291} 293}
292 294
293 295
@@ -308,29 +310,46 @@ static void count_hv_channel(void)
308 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); 310 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
309} 311}
310 312
313/*
314 * vmbus_process_rescind_offer -
315 * Rescind the offer by initiating a device removal
316 */
317static void vmbus_process_rescind_offer(struct work_struct *work)
318{
319 struct vmbus_channel *channel = container_of(work,
320 struct vmbus_channel,
321 work);
322
323 vmbus_child_device_unregister(channel->device_obj);
324}
311 325
312/* 326/*
313 * vmbus_process_offer - Process the offer by creating a channel/device 327 * vmbus_process_offer - Process the offer by creating a channel/device
314 * associated with this offer 328 * associated with this offer
315 */ 329 */
316static void vmbus_process_offer(void *context) 330static void vmbus_process_offer(struct work_struct *work)
317{ 331{
318 struct vmbus_channel *newchannel = context; 332 struct vmbus_channel *newchannel = container_of(work,
333 struct vmbus_channel,
334 work);
319 struct vmbus_channel *channel; 335 struct vmbus_channel *channel;
320 bool fnew = true; 336 bool fnew = true;
321 int ret; 337 int ret;
322 int cnt; 338 int cnt;
323 unsigned long flags; 339 unsigned long flags;
324 340
341 /* The next possible work is rescind handling */
342 INIT_WORK(&newchannel->work, vmbus_process_rescind_offer);
343
325 /* Make sure this is a new offer */ 344 /* Make sure this is a new offer */
326 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); 345 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
327 346
328 list_for_each_entry(channel, &gVmbusConnection.ChannelList, ListEntry) { 347 list_for_each_entry(channel, &gVmbusConnection.ChannelList, listentry) {
329 if (!memcmp(&channel->OfferMsg.Offer.InterfaceType, 348 if (!memcmp(&channel->offermsg.offer.InterfaceType,
330 &newchannel->OfferMsg.Offer.InterfaceType, 349 &newchannel->offermsg.offer.InterfaceType,
331 sizeof(struct hv_guid)) && 350 sizeof(struct hv_guid)) &&
332 !memcmp(&channel->OfferMsg.Offer.InterfaceInstance, 351 !memcmp(&channel->offermsg.offer.InterfaceInstance,
333 &newchannel->OfferMsg.Offer.InterfaceInstance, 352 &newchannel->offermsg.offer.InterfaceInstance,
334 sizeof(struct hv_guid))) { 353 sizeof(struct hv_guid))) {
335 fnew = false; 354 fnew = false;
336 break; 355 break;
@@ -338,14 +357,14 @@ static void vmbus_process_offer(void *context)
338 } 357 }
339 358
340 if (fnew) 359 if (fnew)
341 list_add_tail(&newchannel->ListEntry, 360 list_add_tail(&newchannel->listentry,
342 &gVmbusConnection.ChannelList); 361 &gVmbusConnection.ChannelList);
343 362
344 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); 363 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
345 364
346 if (!fnew) { 365 if (!fnew) {
347 DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", 366 DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)",
348 newchannel->OfferMsg.ChildRelId); 367 newchannel->offermsg.child_relid);
349 free_channel(newchannel); 368 free_channel(newchannel);
350 return; 369 return;
351 } 370 }
@@ -355,27 +374,27 @@ static void vmbus_process_offer(void *context)
355 * We need to set the DeviceObject field before calling 374 * We need to set the DeviceObject field before calling
356 * VmbusChildDeviceAdd() 375 * VmbusChildDeviceAdd()
357 */ 376 */
358 newchannel->DeviceObject = VmbusChildDeviceCreate( 377 newchannel->device_obj = vmbus_child_device_create(
359 &newchannel->OfferMsg.Offer.InterfaceType, 378 &newchannel->offermsg.offer.InterfaceType,
360 &newchannel->OfferMsg.Offer.InterfaceInstance, 379 &newchannel->offermsg.offer.InterfaceInstance,
361 newchannel); 380 newchannel);
362 381
363 DPRINT_DBG(VMBUS, "child device object allocated - %p", 382 DPRINT_DBG(VMBUS, "child device object allocated - %p",
364 newchannel->DeviceObject); 383 newchannel->device_obj);
365 384
366 /* 385 /*
367 * Add the new device to the bus. This will kick off device-driver 386 * Add the new device to the bus. This will kick off device-driver
368 * binding which eventually invokes the device driver's AddDevice() 387 * binding which eventually invokes the device driver's AddDevice()
369 * method. 388 * method.
370 */ 389 */
371 ret = VmbusChildDeviceAdd(newchannel->DeviceObject); 390 ret = VmbusChildDeviceAdd(newchannel->device_obj);
372 if (ret != 0) { 391 if (ret != 0) {
373 DPRINT_ERR(VMBUS, 392 DPRINT_ERR(VMBUS,
374 "unable to add child device object (relid %d)", 393 "unable to add child device object (relid %d)",
375 newchannel->OfferMsg.ChildRelId); 394 newchannel->offermsg.child_relid);
376 395
377 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); 396 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
378 list_del(&newchannel->ListEntry); 397 list_del(&newchannel->listentry);
379 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); 398 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
380 399
381 free_channel(newchannel); 400 free_channel(newchannel);
@@ -385,11 +404,11 @@ static void vmbus_process_offer(void *context)
385 * so that when we do close the channel normally, we 404 * so that when we do close the channel normally, we
386 * can cleanup properly 405 * can cleanup properly
387 */ 406 */
388 newchannel->State = CHANNEL_OPEN_STATE; 407 newchannel->state = CHANNEL_OPEN_STATE;
389 408
390 /* Open IC channels */ 409 /* Open IC channels */
391 for (cnt = 0; cnt < MAX_MSG_TYPES; cnt++) { 410 for (cnt = 0; cnt < MAX_MSG_TYPES; cnt++) {
392 if (memcmp(&newchannel->OfferMsg.Offer.InterfaceType, 411 if (memcmp(&newchannel->offermsg.offer.InterfaceType,
393 &hv_cb_utils[cnt].data, 412 &hv_cb_utils[cnt].data,
394 sizeof(struct hv_guid)) == 0 && 413 sizeof(struct hv_guid)) == 0 &&
395 vmbus_open(newchannel, 2 * PAGE_SIZE, 414 vmbus_open(newchannel, 2 * PAGE_SIZE,
@@ -406,17 +425,6 @@ static void vmbus_process_offer(void *context)
406} 425}
407 426
408/* 427/*
409 * vmbus_process_rescind_offer -
410 * Rescind the offer by initiating a device removal
411 */
412static void vmbus_process_rescind_offer(void *context)
413{
414 struct vmbus_channel *channel = context;
415
416 VmbusChildDeviceRemove(channel->DeviceObject);
417}
418
419/*
420 * vmbus_onoffer - Handler for channel offers from vmbus in parent partition. 428 * vmbus_onoffer - Handler for channel offers from vmbus in parent partition.
421 * 429 *
422 * We ignore all offers except network and storage offers. For each network and 430 * We ignore all offers except network and storage offers. For each network and
@@ -434,7 +442,7 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
434 442
435 offer = (struct vmbus_channel_offer_channel *)hdr; 443 offer = (struct vmbus_channel_offer_channel *)hdr;
436 for (i = 0; i < MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) { 444 for (i = 0; i < MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) {
437 if (memcmp(&offer->Offer.InterfaceType, 445 if (memcmp(&offer->offer.InterfaceType,
438 &gSupportedDeviceClasses[i], sizeof(struct hv_guid)) == 0) { 446 &gSupportedDeviceClasses[i], sizeof(struct hv_guid)) == 0) {
439 fsupported = 1; 447 fsupported = 1;
440 break; 448 break;
@@ -443,12 +451,12 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
443 451
444 if (!fsupported) { 452 if (!fsupported) {
445 DPRINT_DBG(VMBUS, "Ignoring channel offer notification for " 453 DPRINT_DBG(VMBUS, "Ignoring channel offer notification for "
446 "child relid %d", offer->ChildRelId); 454 "child relid %d", offer->child_relid);
447 return; 455 return;
448 } 456 }
449 457
450 guidtype = &offer->Offer.InterfaceType; 458 guidtype = &offer->offer.InterfaceType;
451 guidinstance = &offer->Offer.InterfaceInstance; 459 guidinstance = &offer->offer.InterfaceInstance;
452 460
453 DPRINT_INFO(VMBUS, "Channel offer notification - " 461 DPRINT_INFO(VMBUS, "Channel offer notification - "
454 "child relid %d monitor id %d allocated %d, " 462 "child relid %d monitor id %d allocated %d, "
@@ -456,8 +464,8 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
456 "%02x%02x%02x%02x%02x%02x%02x%02x} " 464 "%02x%02x%02x%02x%02x%02x%02x%02x} "
457 "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-" 465 "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-"
458 "%02x%02x%02x%02x%02x%02x%02x%02x}", 466 "%02x%02x%02x%02x%02x%02x%02x%02x}",
459 offer->ChildRelId, offer->MonitorId, 467 offer->child_relid, offer->monitorid,
460 offer->MonitorAllocated, 468 offer->monitor_allocated,
461 guidtype->data[3], guidtype->data[2], 469 guidtype->data[3], guidtype->data[2],
462 guidtype->data[1], guidtype->data[0], 470 guidtype->data[1], guidtype->data[0],
463 guidtype->data[5], guidtype->data[4], 471 guidtype->data[5], guidtype->data[4],
@@ -484,14 +492,14 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr)
484 492
485 DPRINT_DBG(VMBUS, "channel object allocated - %p", newchannel); 493 DPRINT_DBG(VMBUS, "channel object allocated - %p", newchannel);
486 494
487 memcpy(&newchannel->OfferMsg, offer, 495 memcpy(&newchannel->offermsg, offer,
488 sizeof(struct vmbus_channel_offer_channel)); 496 sizeof(struct vmbus_channel_offer_channel));
489 newchannel->MonitorGroup = (u8)offer->MonitorId / 32; 497 newchannel->monitor_grp = (u8)offer->monitorid / 32;
490 newchannel->MonitorBit = (u8)offer->MonitorId % 32; 498 newchannel->monitor_bit = (u8)offer->monitorid % 32;
491 499
492 /* TODO: Make sure the offer comes from our parent partition */ 500 /* TODO: Make sure the offer comes from our parent partition */
493 osd_schedule_callback(newchannel->ControlWQ, vmbus_process_offer, 501 INIT_WORK(&newchannel->work, vmbus_process_offer);
494 newchannel); 502 queue_work(newchannel->controlwq, &newchannel->work);
495} 503}
496 504
497/* 505/*
@@ -505,16 +513,16 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
505 struct vmbus_channel *channel; 513 struct vmbus_channel *channel;
506 514
507 rescind = (struct vmbus_channel_rescind_offer *)hdr; 515 rescind = (struct vmbus_channel_rescind_offer *)hdr;
508 channel = GetChannelFromRelId(rescind->ChildRelId); 516 channel = GetChannelFromRelId(rescind->child_relid);
509 if (channel == NULL) { 517 if (channel == NULL) {
510 DPRINT_DBG(VMBUS, "channel not found for relId %d", 518 DPRINT_DBG(VMBUS, "channel not found for relId %d",
511 rescind->ChildRelId); 519 rescind->child_relid);
512 return; 520 return;
513 } 521 }
514 522
515 osd_schedule_callback(channel->ControlWQ, 523 /* work is initialized for vmbus_process_rescind_offer() from
516 vmbus_process_rescind_offer, 524 * vmbus_process_offer() where the channel got created */
517 channel); 525 queue_work(channel->controlwq, &channel->work);
518} 526}
519 527
520/* 528/*
@@ -545,7 +553,7 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
545 unsigned long flags; 553 unsigned long flags;
546 554
547 result = (struct vmbus_channel_open_result *)hdr; 555 result = (struct vmbus_channel_open_result *)hdr;
548 DPRINT_DBG(VMBUS, "vmbus open result - %d", result->Status); 556 DPRINT_DBG(VMBUS, "vmbus open result - %d", result->status);
549 557
550 /* 558 /*
551 * Find the open msg, copy the result and signal/unblock the wait event 559 * Find the open msg, copy the result and signal/unblock the wait event
@@ -556,17 +564,17 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr)
556/* FIXME: this should probably use list_entry() instead */ 564/* FIXME: this should probably use list_entry() instead */
557 msginfo = (struct vmbus_channel_msginfo *)curr; 565 msginfo = (struct vmbus_channel_msginfo *)curr;
558 requestheader = 566 requestheader =
559 (struct vmbus_channel_message_header *)msginfo->Msg; 567 (struct vmbus_channel_message_header *)msginfo->msg;
560 568
561 if (requestheader->MessageType == ChannelMessageOpenChannel) { 569 if (requestheader->msgtype == CHANNELMSG_OPENCHANNEL) {
562 openmsg = 570 openmsg =
563 (struct vmbus_channel_open_channel *)msginfo->Msg; 571 (struct vmbus_channel_open_channel *)msginfo->msg;
564 if (openmsg->ChildRelId == result->ChildRelId && 572 if (openmsg->child_relid == result->child_relid &&
565 openmsg->OpenId == result->OpenId) { 573 openmsg->openid == result->openid) {
566 memcpy(&msginfo->Response.OpenResult, 574 memcpy(&msginfo->response.open_result,
567 result, 575 result,
568 sizeof(struct vmbus_channel_open_result)); 576 sizeof(struct vmbus_channel_open_result));
569 osd_WaitEventSet(msginfo->WaitEvent); 577 osd_waitevent_set(msginfo->waitevent);
570 break; 578 break;
571 } 579 }
572 } 580 }
@@ -592,7 +600,7 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr)
592 600
593 gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr; 601 gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr;
594 DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", 602 DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d",
595 gpadlcreated->CreationStatus); 603 gpadlcreated->creation_status);
596 604
597 /* 605 /*
598 * Find the establish msg, copy the result and signal/unblock the wait 606 * Find the establish msg, copy the result and signal/unblock the wait
@@ -604,19 +612,19 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr)
604/* FIXME: this should probably use list_entry() instead */ 612/* FIXME: this should probably use list_entry() instead */
605 msginfo = (struct vmbus_channel_msginfo *)curr; 613 msginfo = (struct vmbus_channel_msginfo *)curr;
606 requestheader = 614 requestheader =
607 (struct vmbus_channel_message_header *)msginfo->Msg; 615 (struct vmbus_channel_message_header *)msginfo->msg;
608 616
609 if (requestheader->MessageType == ChannelMessageGpadlHeader) { 617 if (requestheader->msgtype == CHANNELMSG_GPADL_HEADER) {
610 gpadlheader = 618 gpadlheader =
611 (struct vmbus_channel_gpadl_header *)requestheader; 619 (struct vmbus_channel_gpadl_header *)requestheader;
612 620
613 if ((gpadlcreated->ChildRelId == 621 if ((gpadlcreated->child_relid ==
614 gpadlheader->ChildRelId) && 622 gpadlheader->child_relid) &&
615 (gpadlcreated->Gpadl == gpadlheader->Gpadl)) { 623 (gpadlcreated->gpadl == gpadlheader->gpadl)) {
616 memcpy(&msginfo->Response.GpadlCreated, 624 memcpy(&msginfo->response.gpadl_created,
617 gpadlcreated, 625 gpadlcreated,
618 sizeof(struct vmbus_channel_gpadl_created)); 626 sizeof(struct vmbus_channel_gpadl_created));
619 osd_WaitEventSet(msginfo->WaitEvent); 627 osd_waitevent_set(msginfo->waitevent);
620 break; 628 break;
621 } 629 }
622 } 630 }
@@ -652,17 +660,17 @@ static void vmbus_ongpadl_torndown(
652/* FIXME: this should probably use list_entry() instead */ 660/* FIXME: this should probably use list_entry() instead */
653 msginfo = (struct vmbus_channel_msginfo *)curr; 661 msginfo = (struct vmbus_channel_msginfo *)curr;
654 requestheader = 662 requestheader =
655 (struct vmbus_channel_message_header *)msginfo->Msg; 663 (struct vmbus_channel_message_header *)msginfo->msg;
656 664
657 if (requestheader->MessageType == ChannelMessageGpadlTeardown) { 665 if (requestheader->msgtype == CHANNELMSG_GPADL_TEARDOWN) {
658 gpadl_teardown = 666 gpadl_teardown =
659 (struct vmbus_channel_gpadl_teardown *)requestheader; 667 (struct vmbus_channel_gpadl_teardown *)requestheader;
660 668
661 if (gpadl_torndown->Gpadl == gpadl_teardown->Gpadl) { 669 if (gpadl_torndown->gpadl == gpadl_teardown->gpadl) {
662 memcpy(&msginfo->Response.GpadlTorndown, 670 memcpy(&msginfo->response.gpadl_torndown,
663 gpadl_torndown, 671 gpadl_torndown,
664 sizeof(struct vmbus_channel_gpadl_torndown)); 672 sizeof(struct vmbus_channel_gpadl_torndown));
665 osd_WaitEventSet(msginfo->WaitEvent); 673 osd_waitevent_set(msginfo->waitevent);
666 break; 674 break;
667 } 675 }
668 } 676 }
@@ -694,16 +702,16 @@ static void vmbus_onversion_response(
694/* FIXME: this should probably use list_entry() instead */ 702/* FIXME: this should probably use list_entry() instead */
695 msginfo = (struct vmbus_channel_msginfo *)curr; 703 msginfo = (struct vmbus_channel_msginfo *)curr;
696 requestheader = 704 requestheader =
697 (struct vmbus_channel_message_header *)msginfo->Msg; 705 (struct vmbus_channel_message_header *)msginfo->msg;
698 706
699 if (requestheader->MessageType == 707 if (requestheader->msgtype ==
700 ChannelMessageInitiateContact) { 708 CHANNELMSG_INITIATE_CONTACT) {
701 initiate = 709 initiate =
702 (struct vmbus_channel_initiate_contact *)requestheader; 710 (struct vmbus_channel_initiate_contact *)requestheader;
703 memcpy(&msginfo->Response.VersionResponse, 711 memcpy(&msginfo->response.version_response,
704 version_response, 712 version_response,
705 sizeof(struct vmbus_channel_version_response)); 713 sizeof(struct vmbus_channel_version_response));
706 osd_WaitEventSet(msginfo->WaitEvent); 714 osd_waitevent_set(msginfo->waitevent);
707 } 715 }
708 } 716 }
709 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); 717 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
@@ -711,24 +719,24 @@ static void vmbus_onversion_response(
711 719
712/* Channel message dispatch table */ 720/* Channel message dispatch table */
713static struct vmbus_channel_message_table_entry 721static struct vmbus_channel_message_table_entry
714 gChannelMessageTable[ChannelMessageCount] = { 722 gChannelMessageTable[CHANNELMSG_COUNT] = {
715 {ChannelMessageInvalid, NULL}, 723 {CHANNELMSG_INVALID, NULL},
716 {ChannelMessageOfferChannel, vmbus_onoffer}, 724 {CHANNELMSG_OFFERCHANNEL, vmbus_onoffer},
717 {ChannelMessageRescindChannelOffer, vmbus_onoffer_rescind}, 725 {CHANNELMSG_RESCIND_CHANNELOFFER, vmbus_onoffer_rescind},
718 {ChannelMessageRequestOffers, NULL}, 726 {CHANNELMSG_REQUESTOFFERS, NULL},
719 {ChannelMessageAllOffersDelivered, vmbus_onoffers_delivered}, 727 {CHANNELMSG_ALLOFFERS_DELIVERED, vmbus_onoffers_delivered},
720 {ChannelMessageOpenChannel, NULL}, 728 {CHANNELMSG_OPENCHANNEL, NULL},
721 {ChannelMessageOpenChannelResult, vmbus_onopen_result}, 729 {CHANNELMSG_OPENCHANNEL_RESULT, vmbus_onopen_result},
722 {ChannelMessageCloseChannel, NULL}, 730 {CHANNELMSG_CLOSECHANNEL, NULL},
723 {ChannelMessageGpadlHeader, NULL}, 731 {CHANNELMSG_GPADL_HEADER, NULL},
724 {ChannelMessageGpadlBody, NULL}, 732 {CHANNELMSG_GPADL_BODY, NULL},
725 {ChannelMessageGpadlCreated, vmbus_ongpadl_created}, 733 {CHANNELMSG_GPADL_CREATED, vmbus_ongpadl_created},
726 {ChannelMessageGpadlTeardown, NULL}, 734 {CHANNELMSG_GPADL_TEARDOWN, NULL},
727 {ChannelMessageGpadlTorndown, vmbus_ongpadl_torndown}, 735 {CHANNELMSG_GPADL_TORNDOWN, vmbus_ongpadl_torndown},
728 {ChannelMessageRelIdReleased, NULL}, 736 {CHANNELMSG_RELID_RELEASED, NULL},
729 {ChannelMessageInitiateContact, NULL}, 737 {CHANNELMSG_INITIATE_CONTACT, NULL},
730 {ChannelMessageVersionResponse, vmbus_onversion_response}, 738 {CHANNELMSG_VERSION_RESPONSE, vmbus_onversion_response},
731 {ChannelMessageUnload, NULL}, 739 {CHANNELMSG_UNLOAD, NULL},
732}; 740};
733 741
734/* 742/*
@@ -742,29 +750,25 @@ void vmbus_onmessage(void *context)
742 struct vmbus_channel_message_header *hdr; 750 struct vmbus_channel_message_header *hdr;
743 int size; 751 int size;
744 752
745 hdr = (struct vmbus_channel_message_header *)msg->u.Payload; 753 hdr = (struct vmbus_channel_message_header *)msg->u.payload;
746 size = msg->Header.PayloadSize; 754 size = msg->header.payload_size;
747 755
748 DPRINT_DBG(VMBUS, "message type %d size %d", hdr->MessageType, size); 756 DPRINT_DBG(VMBUS, "message type %d size %d", hdr->msgtype, size);
749 757
750 if (hdr->MessageType >= ChannelMessageCount) { 758 if (hdr->msgtype >= CHANNELMSG_COUNT) {
751 DPRINT_ERR(VMBUS, 759 DPRINT_ERR(VMBUS,
752 "Received invalid channel message type %d size %d", 760 "Received invalid channel message type %d size %d",
753 hdr->MessageType, size); 761 hdr->msgtype, size);
754 print_hex_dump_bytes("", DUMP_PREFIX_NONE, 762 print_hex_dump_bytes("", DUMP_PREFIX_NONE,
755 (unsigned char *)msg->u.Payload, size); 763 (unsigned char *)msg->u.payload, size);
756 kfree(msg);
757 return; 764 return;
758 } 765 }
759 766
760 if (gChannelMessageTable[hdr->MessageType].messageHandler) 767 if (gChannelMessageTable[hdr->msgtype].messageHandler)
761 gChannelMessageTable[hdr->MessageType].messageHandler(hdr); 768 gChannelMessageTable[hdr->msgtype].messageHandler(hdr);
762 else 769 else
763 DPRINT_ERR(VMBUS, "Unhandled channel message type %d", 770 DPRINT_ERR(VMBUS, "Unhandled channel message type %d",
764 hdr->MessageType); 771 hdr->msgtype);
765
766 /* Free the msg that was allocated in VmbusOnMsgDPC() */
767 kfree(msg);
768} 772}
769 773
770/* 774/*
@@ -782,15 +786,15 @@ int vmbus_request_offers(void)
782 if (!msginfo) 786 if (!msginfo)
783 return -ENOMEM; 787 return -ENOMEM;
784 788
785 msginfo->WaitEvent = osd_WaitEventCreate(); 789 msginfo->waitevent = osd_waitevent_create();
786 if (!msginfo->WaitEvent) { 790 if (!msginfo->waitevent) {
787 kfree(msginfo); 791 kfree(msginfo);
788 return -ENOMEM; 792 return -ENOMEM;
789 } 793 }
790 794
791 msg = (struct vmbus_channel_message_header *)msginfo->Msg; 795 msg = (struct vmbus_channel_message_header *)msginfo->msg;
792 796
793 msg->MessageType = ChannelMessageRequestOffers; 797 msg->msgtype = CHANNELMSG_REQUESTOFFERS;
794 798
795 /*SpinlockAcquire(gVmbusConnection.channelMsgLock); 799 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
796 INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList, 800 INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList,
@@ -808,7 +812,7 @@ int vmbus_request_offers(void)
808 812
809 goto Cleanup; 813 goto Cleanup;
810 } 814 }
811 /* osd_WaitEventWait(msgInfo->waitEvent); */ 815 /* osd_waitevent_wait(msgInfo->waitEvent); */
812 816
813 /*SpinlockAcquire(gVmbusConnection.channelMsgLock); 817 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
814 REMOVE_ENTRY_LIST(&msgInfo->msgListEntry); 818 REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
@@ -817,7 +821,7 @@ int vmbus_request_offers(void)
817 821
818Cleanup: 822Cleanup:
819 if (msginfo) { 823 if (msginfo) {
820 kfree(msginfo->WaitEvent); 824 kfree(msginfo->waitevent);
821 kfree(msginfo); 825 kfree(msginfo);
822 } 826 }
823 827
@@ -837,17 +841,17 @@ void vmbus_release_unattached_channels(void)
837 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); 841 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
838 842
839 list_for_each_entry_safe(channel, pos, &gVmbusConnection.ChannelList, 843 list_for_each_entry_safe(channel, pos, &gVmbusConnection.ChannelList,
840 ListEntry) { 844 listentry) {
841 if (channel == start) 845 if (channel == start)
842 break; 846 break;
843 847
844 if (!channel->DeviceObject->Driver) { 848 if (!channel->device_obj->Driver) {
845 list_del(&channel->ListEntry); 849 list_del(&channel->listentry);
846 DPRINT_INFO(VMBUS, 850 DPRINT_INFO(VMBUS,
847 "Releasing unattached device object %p", 851 "Releasing unattached device object %p",
848 channel->DeviceObject); 852 channel->device_obj);
849 853
850 VmbusChildDeviceRemove(channel->DeviceObject); 854 vmbus_child_device_unregister(channel->device_obj);
851 free_channel(channel); 855 free_channel(channel);
852 } else { 856 } else {
853 if (!start) 857 if (!start)
diff --git a/drivers/staging/hv/channel_mgmt.h b/drivers/staging/hv/channel_mgmt.h
index d16cc0811169..de6b2a0ebf70 100644
--- a/drivers/staging/hv/channel_mgmt.h
+++ b/drivers/staging/hv/channel_mgmt.h
@@ -33,60 +33,60 @@
33 33
34/* Version 1 messages */ 34/* Version 1 messages */
35enum vmbus_channel_message_type { 35enum vmbus_channel_message_type {
36 ChannelMessageInvalid = 0, 36 CHANNELMSG_INVALID = 0,
37 ChannelMessageOfferChannel = 1, 37 CHANNELMSG_OFFERCHANNEL = 1,
38 ChannelMessageRescindChannelOffer = 2, 38 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
39 ChannelMessageRequestOffers = 3, 39 CHANNELMSG_REQUESTOFFERS = 3,
40 ChannelMessageAllOffersDelivered = 4, 40 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
41 ChannelMessageOpenChannel = 5, 41 CHANNELMSG_OPENCHANNEL = 5,
42 ChannelMessageOpenChannelResult = 6, 42 CHANNELMSG_OPENCHANNEL_RESULT = 6,
43 ChannelMessageCloseChannel = 7, 43 CHANNELMSG_CLOSECHANNEL = 7,
44 ChannelMessageGpadlHeader = 8, 44 CHANNELMSG_GPADL_HEADER = 8,
45 ChannelMessageGpadlBody = 9, 45 CHANNELMSG_GPADL_BODY = 9,
46 ChannelMessageGpadlCreated = 10, 46 CHANNELMSG_GPADL_CREATED = 10,
47 ChannelMessageGpadlTeardown = 11, 47 CHANNELMSG_GPADL_TEARDOWN = 11,
48 ChannelMessageGpadlTorndown = 12, 48 CHANNELMSG_GPADL_TORNDOWN = 12,
49 ChannelMessageRelIdReleased = 13, 49 CHANNELMSG_RELID_RELEASED = 13,
50 ChannelMessageInitiateContact = 14, 50 CHANNELMSG_INITIATE_CONTACT = 14,
51 ChannelMessageVersionResponse = 15, 51 CHANNELMSG_VERSION_RESPONSE = 15,
52 ChannelMessageUnload = 16, 52 CHANNELMSG_UNLOAD = 16,
53#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD 53#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
54 ChannelMessageViewRangeAdd = 17, 54 CHANNELMSG_VIEWRANGE_ADD = 17,
55 ChannelMessageViewRangeRemove = 18, 55 CHANNELMSG_VIEWRANGE_REMOVE = 18,
56#endif 56#endif
57 ChannelMessageCount 57 CHANNELMSG_COUNT
58}; 58};
59 59
60struct vmbus_channel_message_header { 60struct vmbus_channel_message_header {
61 enum vmbus_channel_message_type MessageType; 61 enum vmbus_channel_message_type msgtype;
62 u32 Padding; 62 u32 padding;
63} __attribute__((packed)); 63} __attribute__((packed));
64 64
65/* Query VMBus Version parameters */ 65/* Query VMBus Version parameters */
66struct vmbus_channel_query_vmbus_version { 66struct vmbus_channel_query_vmbus_version {
67 struct vmbus_channel_message_header Header; 67 struct vmbus_channel_message_header header;
68 u32 Version; 68 u32 version;
69} __attribute__((packed)); 69} __attribute__((packed));
70 70
71/* VMBus Version Supported parameters */ 71/* VMBus Version Supported parameters */
72struct vmbus_channel_version_supported { 72struct vmbus_channel_version_supported {
73 struct vmbus_channel_message_header Header; 73 struct vmbus_channel_message_header header;
74 bool VersionSupported; 74 bool version_supported;
75} __attribute__((packed)); 75} __attribute__((packed));
76 76
77/* Offer Channel parameters */ 77/* Offer Channel parameters */
78struct vmbus_channel_offer_channel { 78struct vmbus_channel_offer_channel {
79 struct vmbus_channel_message_header Header; 79 struct vmbus_channel_message_header header;
80 struct vmbus_channel_offer Offer; 80 struct vmbus_channel_offer offer;
81 u32 ChildRelId; 81 u32 child_relid;
82 u8 MonitorId; 82 u8 monitorid;
83 bool MonitorAllocated; 83 bool monitor_allocated;
84} __attribute__((packed)); 84} __attribute__((packed));
85 85
86/* Rescind Offer parameters */ 86/* Rescind Offer parameters */
87struct vmbus_channel_rescind_offer { 87struct vmbus_channel_rescind_offer {
88 struct vmbus_channel_message_header Header; 88 struct vmbus_channel_message_header header;
89 u32 ChildRelId; 89 u32 child_relid;
90} __attribute__((packed)); 90} __attribute__((packed));
91 91
92/* 92/*
@@ -100,43 +100,43 @@ struct vmbus_channel_rescind_offer {
100 100
101/* Open Channel parameters */ 101/* Open Channel parameters */
102struct vmbus_channel_open_channel { 102struct vmbus_channel_open_channel {
103 struct vmbus_channel_message_header Header; 103 struct vmbus_channel_message_header header;
104 104
105 /* Identifies the specific VMBus channel that is being opened. */ 105 /* Identifies the specific VMBus channel that is being opened. */
106 u32 ChildRelId; 106 u32 child_relid;
107 107
108 /* ID making a particular open request at a channel offer unique. */ 108 /* ID making a particular open request at a channel offer unique. */
109 u32 OpenId; 109 u32 openid;
110 110
111 /* GPADL for the channel's ring buffer. */ 111 /* GPADL for the channel's ring buffer. */
112 u32 RingBufferGpadlHandle; 112 u32 ringbuffer_gpadlhandle;
113 113
114 /* GPADL for the channel's server context save area. */ 114 /* GPADL for the channel's server context save area. */
115 u32 ServerContextAreaGpadlHandle; 115 u32 server_contextarea_gpadlhandle;
116 116
117 /* 117 /*
118 * The upstream ring buffer begins at offset zero in the memory 118 * The upstream ring buffer begins at offset zero in the memory
119 * described by RingBufferGpadlHandle. The downstream ring buffer 119 * described by RingBufferGpadlHandle. The downstream ring buffer
120 * follows it at this offset (in pages). 120 * follows it at this offset (in pages).
121 */ 121 */
122 u32 DownstreamRingBufferPageOffset; 122 u32 downstream_ringbuffer_pageoffset;
123 123
124 /* User-specific data to be passed along to the server endpoint. */ 124 /* User-specific data to be passed along to the server endpoint. */
125 unsigned char UserData[MAX_USER_DEFINED_BYTES]; 125 unsigned char userdata[MAX_USER_DEFINED_BYTES];
126} __attribute__((packed)); 126} __attribute__((packed));
127 127
128/* Open Channel Result parameters */ 128/* Open Channel Result parameters */
129struct vmbus_channel_open_result { 129struct vmbus_channel_open_result {
130 struct vmbus_channel_message_header Header; 130 struct vmbus_channel_message_header header;
131 u32 ChildRelId; 131 u32 child_relid;
132 u32 OpenId; 132 u32 openid;
133 u32 Status; 133 u32 status;
134} __attribute__((packed)); 134} __attribute__((packed));
135 135
136/* Close channel parameters; */ 136/* Close channel parameters; */
137struct vmbus_channel_close_channel { 137struct vmbus_channel_close_channel {
138 struct vmbus_channel_message_header Header; 138 struct vmbus_channel_message_header header;
139 u32 ChildRelId; 139 u32 child_relid;
140} __attribute__((packed)); 140} __attribute__((packed));
141 141
142/* Channel Message GPADL */ 142/* Channel Message GPADL */
@@ -151,72 +151,72 @@ struct vmbus_channel_close_channel {
151 * follow-up packet that contains more. 151 * follow-up packet that contains more.
152 */ 152 */
153struct vmbus_channel_gpadl_header { 153struct vmbus_channel_gpadl_header {
154 struct vmbus_channel_message_header Header; 154 struct vmbus_channel_message_header header;
155 u32 ChildRelId; 155 u32 child_relid;
156 u32 Gpadl; 156 u32 gpadl;
157 u16 RangeBufLen; 157 u16 range_buflen;
158 u16 RangeCount; 158 u16 rangecount;
159 struct gpa_range Range[0]; 159 struct gpa_range range[0];
160} __attribute__((packed)); 160} __attribute__((packed));
161 161
162/* This is the followup packet that contains more PFNs. */ 162/* This is the followup packet that contains more PFNs. */
163struct vmbus_channel_gpadl_body { 163struct vmbus_channel_gpadl_body {
164 struct vmbus_channel_message_header Header; 164 struct vmbus_channel_message_header header;
165 u32 MessageNumber; 165 u32 msgnumber;
166 u32 Gpadl; 166 u32 gpadl;
167 u64 Pfn[0]; 167 u64 pfn[0];
168} __attribute__((packed)); 168} __attribute__((packed));
169 169
170struct vmbus_channel_gpadl_created { 170struct vmbus_channel_gpadl_created {
171 struct vmbus_channel_message_header Header; 171 struct vmbus_channel_message_header header;
172 u32 ChildRelId; 172 u32 child_relid;
173 u32 Gpadl; 173 u32 gpadl;
174 u32 CreationStatus; 174 u32 creation_status;
175} __attribute__((packed)); 175} __attribute__((packed));
176 176
177struct vmbus_channel_gpadl_teardown { 177struct vmbus_channel_gpadl_teardown {
178 struct vmbus_channel_message_header Header; 178 struct vmbus_channel_message_header header;
179 u32 ChildRelId; 179 u32 child_relid;
180 u32 Gpadl; 180 u32 gpadl;
181} __attribute__((packed)); 181} __attribute__((packed));
182 182
183struct vmbus_channel_gpadl_torndown { 183struct vmbus_channel_gpadl_torndown {
184 struct vmbus_channel_message_header Header; 184 struct vmbus_channel_message_header header;
185 u32 Gpadl; 185 u32 gpadl;
186} __attribute__((packed)); 186} __attribute__((packed));
187 187
188#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD 188#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
189struct vmbus_channel_view_range_add { 189struct vmbus_channel_view_range_add {
190 struct vmbus_channel_message_header Header; 190 struct vmbus_channel_message_header header;
191 PHYSICAL_ADDRESS ViewRangeBase; 191 PHYSICAL_ADDRESS viewrange_base;
192 u64 ViewRangeLength; 192 u64 viewrange_length;
193 u32 ChildRelId; 193 u32 child_relid;
194} __attribute__((packed)); 194} __attribute__((packed));
195 195
196struct vmbus_channel_view_range_remove { 196struct vmbus_channel_view_range_remove {
197 struct vmbus_channel_message_header Header; 197 struct vmbus_channel_message_header header;
198 PHYSICAL_ADDRESS ViewRangeBase; 198 PHYSICAL_ADDRESS viewrange_base;
199 u32 ChildRelId; 199 u32 child_relid;
200} __attribute__((packed)); 200} __attribute__((packed));
201#endif 201#endif
202 202
203struct vmbus_channel_relid_released { 203struct vmbus_channel_relid_released {
204 struct vmbus_channel_message_header Header; 204 struct vmbus_channel_message_header header;
205 u32 ChildRelId; 205 u32 child_relid;
206} __attribute__((packed)); 206} __attribute__((packed));
207 207
208struct vmbus_channel_initiate_contact { 208struct vmbus_channel_initiate_contact {
209 struct vmbus_channel_message_header Header; 209 struct vmbus_channel_message_header header;
210 u32 VMBusVersionRequested; 210 u32 vmbus_version_requested;
211 u32 Padding2; 211 u32 padding2;
212 u64 InterruptPage; 212 u64 interrupt_page;
213 u64 MonitorPage1; 213 u64 monitor_page1;
214 u64 MonitorPage2; 214 u64 monitor_page2;
215} __attribute__((packed)); 215} __attribute__((packed));
216 216
217struct vmbus_channel_version_response { 217struct vmbus_channel_version_response {
218 struct vmbus_channel_message_header Header; 218 struct vmbus_channel_message_header header;
219 bool VersionSupported; 219 bool version_supported;
220} __attribute__((packed)); 220} __attribute__((packed));
221 221
222enum vmbus_channel_state { 222enum vmbus_channel_state {
@@ -226,54 +226,55 @@ enum vmbus_channel_state {
226}; 226};
227 227
228struct vmbus_channel { 228struct vmbus_channel {
229 struct list_head ListEntry; 229 struct list_head listentry;
230 230
231 struct hv_device *DeviceObject; 231 struct hv_device *device_obj;
232 232
233 struct timer_list poll_timer; /* SA-111 workaround */ 233 struct timer_list poll_timer; /* SA-111 workaround */
234 struct work_struct work;
234 235
235 enum vmbus_channel_state State; 236 enum vmbus_channel_state state;
236 237
237 struct vmbus_channel_offer_channel OfferMsg; 238 struct vmbus_channel_offer_channel offermsg;
238 /* 239 /*
239 * These are based on the OfferMsg.MonitorId. 240 * These are based on the OfferMsg.MonitorId.
240 * Save it here for easy access. 241 * Save it here for easy access.
241 */ 242 */
242 u8 MonitorGroup; 243 u8 monitor_grp;
243 u8 MonitorBit; 244 u8 monitor_bit;
244 245
245 u32 RingBufferGpadlHandle; 246 u32 ringbuffer_gpadlhandle;
246 247
247 /* Allocated memory for ring buffer */ 248 /* Allocated memory for ring buffer */
248 void *RingBufferPages; 249 void *ringbuffer_pages;
249 u32 RingBufferPageCount; 250 u32 ringbuffer_pagecount;
250 struct hv_ring_buffer_info Outbound; /* send to parent */ 251 struct hv_ring_buffer_info outbound; /* send to parent */
251 struct hv_ring_buffer_info Inbound; /* receive from parent */ 252 struct hv_ring_buffer_info inbound; /* receive from parent */
252 spinlock_t inbound_lock; 253 spinlock_t inbound_lock;
253 struct workqueue_struct *ControlWQ; 254 struct workqueue_struct *controlwq;
254 255
255 /* Channel callback are invoked in this workqueue context */ 256 /* Channel callback are invoked in this workqueue context */
256 /* HANDLE dataWorkQueue; */ 257 /* HANDLE dataWorkQueue; */
257 258
258 void (*OnChannelCallback)(void *context); 259 void (*onchannel_callback)(void *context);
259 void *ChannelCallbackContext; 260 void *channel_callback_context;
260}; 261};
261 262
262struct vmbus_channel_debug_info { 263struct vmbus_channel_debug_info {
263 u32 RelId; 264 u32 relid;
264 enum vmbus_channel_state State; 265 enum vmbus_channel_state state;
265 struct hv_guid InterfaceType; 266 struct hv_guid interfacetype;
266 struct hv_guid InterfaceInstance; 267 struct hv_guid interface_instance;
267 u32 MonitorId; 268 u32 monitorid;
268 u32 ServerMonitorPending; 269 u32 servermonitor_pending;
269 u32 ServerMonitorLatency; 270 u32 servermonitor_latency;
270 u32 ServerMonitorConnectionId; 271 u32 servermonitor_connectionid;
271 u32 ClientMonitorPending; 272 u32 clientmonitor_pending;
272 u32 ClientMonitorLatency; 273 u32 clientmonitor_latency;
273 u32 ClientMonitorConnectionId; 274 u32 clientmonitor_connectionid;
274 275
275 struct hv_ring_buffer_debug_info Inbound; 276 struct hv_ring_buffer_debug_info inbound;
276 struct hv_ring_buffer_debug_info Outbound; 277 struct hv_ring_buffer_debug_info outbound;
277}; 278};
278 279
279/* 280/*
@@ -282,28 +283,28 @@ struct vmbus_channel_debug_info {
282 */ 283 */
283struct vmbus_channel_msginfo { 284struct vmbus_channel_msginfo {
284 /* Bookkeeping stuff */ 285 /* Bookkeeping stuff */
285 struct list_head MsgListEntry; 286 struct list_head msglistentry;
286 287
287 /* So far, this is only used to handle gpadl body message */ 288 /* So far, this is only used to handle gpadl body message */
288 struct list_head SubMsgList; 289 struct list_head submsglist;
289 290
290 /* Synchronize the request/response if needed */ 291 /* Synchronize the request/response if needed */
291 struct osd_waitevent *WaitEvent; 292 struct osd_waitevent *waitevent;
292 293
293 union { 294 union {
294 struct vmbus_channel_version_supported VersionSupported; 295 struct vmbus_channel_version_supported version_supported;
295 struct vmbus_channel_open_result OpenResult; 296 struct vmbus_channel_open_result open_result;
296 struct vmbus_channel_gpadl_torndown GpadlTorndown; 297 struct vmbus_channel_gpadl_torndown gpadl_torndown;
297 struct vmbus_channel_gpadl_created GpadlCreated; 298 struct vmbus_channel_gpadl_created gpadl_created;
298 struct vmbus_channel_version_response VersionResponse; 299 struct vmbus_channel_version_response version_response;
299 } Response; 300 } response;
300 301
301 u32 MessageSize; 302 u32 msgsize;
302 /* 303 /*
303 * The channel message that goes out on the "wire". 304 * The channel message that goes out on the "wire".
304 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header 305 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
305 */ 306 */
306 unsigned char Msg[0]; 307 unsigned char msg[0];
307}; 308};
308 309
309 310
diff --git a/drivers/staging/hv/connection.c b/drivers/staging/hv/connection.c
index f8477072ace4..c2e298ff4834 100644
--- a/drivers/staging/hv/connection.c
+++ b/drivers/staging/hv/connection.c
@@ -66,7 +66,7 @@ int VmbusConnect(void)
66 * Setup the vmbus event connection for channel interrupt 66 * Setup the vmbus event connection for channel interrupt
67 * abstraction stuff 67 * abstraction stuff
68 */ 68 */
69 gVmbusConnection.InterruptPage = osd_PageAlloc(1); 69 gVmbusConnection.InterruptPage = osd_page_alloc(1);
70 if (gVmbusConnection.InterruptPage == NULL) { 70 if (gVmbusConnection.InterruptPage == NULL) {
71 ret = -1; 71 ret = -1;
72 goto Cleanup; 72 goto Cleanup;
@@ -81,7 +81,7 @@ int VmbusConnect(void)
81 * Setup the monitor notification facility. The 1st page for 81 * Setup the monitor notification facility. The 1st page for
82 * parent->child and the 2nd page for child->parent 82 * parent->child and the 2nd page for child->parent
83 */ 83 */
84 gVmbusConnection.MonitorPages = osd_PageAlloc(2); 84 gVmbusConnection.MonitorPages = osd_page_alloc(2);
85 if (gVmbusConnection.MonitorPages == NULL) { 85 if (gVmbusConnection.MonitorPages == NULL) {
86 ret = -1; 86 ret = -1;
87 goto Cleanup; 87 goto Cleanup;
@@ -95,19 +95,19 @@ int VmbusConnect(void)
95 goto Cleanup; 95 goto Cleanup;
96 } 96 }
97 97
98 msgInfo->WaitEvent = osd_WaitEventCreate(); 98 msgInfo->waitevent = osd_waitevent_create();
99 if (!msgInfo->WaitEvent) { 99 if (!msgInfo->waitevent) {
100 ret = -ENOMEM; 100 ret = -ENOMEM;
101 goto Cleanup; 101 goto Cleanup;
102 } 102 }
103 103
104 msg = (struct vmbus_channel_initiate_contact *)msgInfo->Msg; 104 msg = (struct vmbus_channel_initiate_contact *)msgInfo->msg;
105 105
106 msg->Header.MessageType = ChannelMessageInitiateContact; 106 msg->header.msgtype = CHANNELMSG_INITIATE_CONTACT;
107 msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER; 107 msg->vmbus_version_requested = VMBUS_REVISION_NUMBER;
108 msg->InterruptPage = virt_to_phys(gVmbusConnection.InterruptPage); 108 msg->interrupt_page = virt_to_phys(gVmbusConnection.InterruptPage);
109 msg->MonitorPage1 = virt_to_phys(gVmbusConnection.MonitorPages); 109 msg->monitor_page1 = virt_to_phys(gVmbusConnection.MonitorPages);
110 msg->MonitorPage2 = virt_to_phys( 110 msg->monitor_page2 = virt_to_phys(
111 (void *)((unsigned long)gVmbusConnection.MonitorPages + 111 (void *)((unsigned long)gVmbusConnection.MonitorPages +
112 PAGE_SIZE)); 112 PAGE_SIZE));
113 113
@@ -116,30 +116,30 @@ int VmbusConnect(void)
116 * receive the response before returning from this routine 116 * receive the response before returning from this routine
117 */ 117 */
118 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); 118 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
119 list_add_tail(&msgInfo->MsgListEntry, 119 list_add_tail(&msgInfo->msglistentry,
120 &gVmbusConnection.ChannelMsgList); 120 &gVmbusConnection.ChannelMsgList);
121 121
122 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); 122 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
123 123
124 DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, " 124 DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, "
125 "monitor1 pfn %llx,, monitor2 pfn %llx", 125 "monitor1 pfn %llx,, monitor2 pfn %llx",
126 msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2); 126 msg->interrupt_page, msg->monitor_page1, msg->monitor_page2);
127 127
128 DPRINT_DBG(VMBUS, "Sending channel initiate msg..."); 128 DPRINT_DBG(VMBUS, "Sending channel initiate msg...");
129 ret = VmbusPostMessage(msg, 129 ret = VmbusPostMessage(msg,
130 sizeof(struct vmbus_channel_initiate_contact)); 130 sizeof(struct vmbus_channel_initiate_contact));
131 if (ret != 0) { 131 if (ret != 0) {
132 list_del(&msgInfo->MsgListEntry); 132 list_del(&msgInfo->msglistentry);
133 goto Cleanup; 133 goto Cleanup;
134 } 134 }
135 135
136 /* Wait for the connection response */ 136 /* Wait for the connection response */
137 osd_WaitEventWait(msgInfo->WaitEvent); 137 osd_waitevent_wait(msgInfo->waitevent);
138 138
139 list_del(&msgInfo->MsgListEntry); 139 list_del(&msgInfo->msglistentry);
140 140
141 /* Check if successful */ 141 /* Check if successful */
142 if (msgInfo->Response.VersionResponse.VersionSupported) { 142 if (msgInfo->response.version_response.version_supported) {
143 DPRINT_INFO(VMBUS, "Vmbus connected!!"); 143 DPRINT_INFO(VMBUS, "Vmbus connected!!");
144 gVmbusConnection.ConnectState = Connected; 144 gVmbusConnection.ConnectState = Connected;
145 145
@@ -151,7 +151,7 @@ int VmbusConnect(void)
151 goto Cleanup; 151 goto Cleanup;
152 } 152 }
153 153
154 kfree(msgInfo->WaitEvent); 154 kfree(msgInfo->waitevent);
155 kfree(msgInfo); 155 kfree(msgInfo);
156 return 0; 156 return 0;
157 157
@@ -162,17 +162,17 @@ Cleanup:
162 destroy_workqueue(gVmbusConnection.WorkQueue); 162 destroy_workqueue(gVmbusConnection.WorkQueue);
163 163
164 if (gVmbusConnection.InterruptPage) { 164 if (gVmbusConnection.InterruptPage) {
165 osd_PageFree(gVmbusConnection.InterruptPage, 1); 165 osd_page_free(gVmbusConnection.InterruptPage, 1);
166 gVmbusConnection.InterruptPage = NULL; 166 gVmbusConnection.InterruptPage = NULL;
167 } 167 }
168 168
169 if (gVmbusConnection.MonitorPages) { 169 if (gVmbusConnection.MonitorPages) {
170 osd_PageFree(gVmbusConnection.MonitorPages, 2); 170 osd_page_free(gVmbusConnection.MonitorPages, 2);
171 gVmbusConnection.MonitorPages = NULL; 171 gVmbusConnection.MonitorPages = NULL;
172 } 172 }
173 173
174 if (msgInfo) { 174 if (msgInfo) {
175 kfree(msgInfo->WaitEvent); 175 kfree(msgInfo->waitevent);
176 kfree(msgInfo); 176 kfree(msgInfo);
177 } 177 }
178 178
@@ -195,14 +195,14 @@ int VmbusDisconnect(void)
195 if (!msg) 195 if (!msg)
196 return -ENOMEM; 196 return -ENOMEM;
197 197
198 msg->MessageType = ChannelMessageUnload; 198 msg->msgtype = CHANNELMSG_UNLOAD;
199 199
200 ret = VmbusPostMessage(msg, 200 ret = VmbusPostMessage(msg,
201 sizeof(struct vmbus_channel_message_header)); 201 sizeof(struct vmbus_channel_message_header));
202 if (ret != 0) 202 if (ret != 0)
203 goto Cleanup; 203 goto Cleanup;
204 204
205 osd_PageFree(gVmbusConnection.InterruptPage, 1); 205 osd_page_free(gVmbusConnection.InterruptPage, 1);
206 206
207 /* TODO: iterate thru the msg list and free up */ 207 /* TODO: iterate thru the msg list and free up */
208 destroy_workqueue(gVmbusConnection.WorkQueue); 208 destroy_workqueue(gVmbusConnection.WorkQueue);
@@ -226,8 +226,8 @@ struct vmbus_channel *GetChannelFromRelId(u32 relId)
226 unsigned long flags; 226 unsigned long flags;
227 227
228 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); 228 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
229 list_for_each_entry(channel, &gVmbusConnection.ChannelList, ListEntry) { 229 list_for_each_entry(channel, &gVmbusConnection.ChannelList, listentry) {
230 if (channel->OfferMsg.ChildRelId == relId) { 230 if (channel->offermsg.child_relid == relId) {
231 foundChannel = channel; 231 foundChannel = channel;
232 break; 232 break;
233 } 233 }
@@ -309,9 +309,9 @@ int VmbusPostMessage(void *buffer, size_t bufferLen)
309{ 309{
310 union hv_connection_id connId; 310 union hv_connection_id connId;
311 311
312 connId.Asu32 = 0; 312 connId.asu32 = 0;
313 connId.u.Id = VMBUS_MESSAGE_CONNECTION_ID; 313 connId.u.id = VMBUS_MESSAGE_CONNECTION_ID;
314 return HvPostMessage(connId, 1, buffer, bufferLen); 314 return hv_post_message(connId, 1, buffer, bufferLen);
315} 315}
316 316
317/* 317/*
@@ -324,5 +324,5 @@ int VmbusSetEvent(u32 childRelId)
324 (unsigned long *)gVmbusConnection.SendInterruptPage + 324 (unsigned long *)gVmbusConnection.SendInterruptPage +
325 (childRelId >> 5)); 325 (childRelId >> 5));
326 326
327 return HvSignalEvent(); 327 return hv_signal_event();
328} 328}
diff --git a/drivers/staging/hv/hv.c b/drivers/staging/hv/hv.c
index 86b1ddd90404..a34d713d9c57 100644
--- a/drivers/staging/hv/hv.c
+++ b/drivers/staging/hv/hv.c
@@ -28,17 +28,18 @@
28#include "vmbus_private.h" 28#include "vmbus_private.h"
29 29
30/* The one and only */ 30/* The one and only */
31struct hv_context gHvContext = { 31struct hv_context hv_context = {
32 .SynICInitialized = false, 32 .synic_initialized = false,
33 .HypercallPage = NULL, 33 .hypercall_page = NULL,
34 .SignalEventParam = NULL, 34 .signal_event_param = NULL,
35 .SignalEventBuffer = NULL, 35 .signal_event_buffer = NULL,
36}; 36};
37 37
38/* 38/*
39 * HvQueryHypervisorPresence - Query the cpuid for presense of windows hypervisor 39 * query_hypervisor_presence
40 * - Query the cpuid for presense of windows hypervisor
40 */ 41 */
41static int HvQueryHypervisorPresence(void) 42static int query_hypervisor_presence(void)
42{ 43{
43 unsigned int eax; 44 unsigned int eax;
44 unsigned int ebx; 45 unsigned int ebx;
@@ -50,22 +51,22 @@ static int HvQueryHypervisorPresence(void)
50 ebx = 0; 51 ebx = 0;
51 ecx = 0; 52 ecx = 0;
52 edx = 0; 53 edx = 0;
53 op = HvCpuIdFunctionVersionAndFeatures; 54 op = HVCPUID_VERSION_FEATURES;
54 cpuid(op, &eax, &ebx, &ecx, &edx); 55 cpuid(op, &eax, &ebx, &ecx, &edx);
55 56
56 return ecx & HV_PRESENT_BIT; 57 return ecx & HV_PRESENT_BIT;
57} 58}
58 59
59/* 60/*
60 * HvQueryHypervisorInfo - Get version info of the windows hypervisor 61 * query_hypervisor_info - Get version info of the windows hypervisor
61 */ 62 */
62static int HvQueryHypervisorInfo(void) 63static int query_hypervisor_info(void)
63{ 64{
64 unsigned int eax; 65 unsigned int eax;
65 unsigned int ebx; 66 unsigned int ebx;
66 unsigned int ecx; 67 unsigned int ecx;
67 unsigned int edx; 68 unsigned int edx;
68 unsigned int maxLeaf; 69 unsigned int max_leaf;
69 unsigned int op; 70 unsigned int op;
70 71
71 /* 72 /*
@@ -76,7 +77,7 @@ static int HvQueryHypervisorInfo(void)
76 ebx = 0; 77 ebx = 0;
77 ecx = 0; 78 ecx = 0;
78 edx = 0; 79 edx = 0;
79 op = HvCpuIdFunctionHvVendorAndMaxFunction; 80 op = HVCPUID_VENDOR_MAXFUNCTION;
80 cpuid(op, &eax, &ebx, &ecx, &edx); 81 cpuid(op, &eax, &ebx, &ecx, &edx);
81 82
82 DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c", 83 DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c",
@@ -93,12 +94,12 @@ static int HvQueryHypervisorInfo(void)
93 ((edx >> 16) & 0xFF), 94 ((edx >> 16) & 0xFF),
94 ((edx >> 24) & 0xFF)); 95 ((edx >> 24) & 0xFF));
95 96
96 maxLeaf = eax; 97 max_leaf = eax;
97 eax = 0; 98 eax = 0;
98 ebx = 0; 99 ebx = 0;
99 ecx = 0; 100 ecx = 0;
100 edx = 0; 101 edx = 0;
101 op = HvCpuIdFunctionHvInterface; 102 op = HVCPUID_INTERFACE;
102 cpuid(op, &eax, &ebx, &ecx, &edx); 103 cpuid(op, &eax, &ebx, &ecx, &edx);
103 104
104 DPRINT_INFO(VMBUS, "Interface ID: %c%c%c%c", 105 DPRINT_INFO(VMBUS, "Interface ID: %c%c%c%c",
@@ -107,12 +108,12 @@ static int HvQueryHypervisorInfo(void)
107 ((eax >> 16) & 0xFF), 108 ((eax >> 16) & 0xFF),
108 ((eax >> 24) & 0xFF)); 109 ((eax >> 24) & 0xFF));
109 110
110 if (maxLeaf >= HvCpuIdFunctionMsHvVersion) { 111 if (max_leaf >= HVCPUID_VERSION) {
111 eax = 0; 112 eax = 0;
112 ebx = 0; 113 ebx = 0;
113 ecx = 0; 114 ecx = 0;
114 edx = 0; 115 edx = 0;
115 op = HvCpuIdFunctionMsHvVersion; 116 op = HVCPUID_VERSION;
116 cpuid(op, &eax, &ebx, &ecx, &edx); 117 cpuid(op, &eax, &ebx, &ecx, &edx);
117 DPRINT_INFO(VMBUS, "OS Build:%d-%d.%d-%d-%d.%d",\ 118 DPRINT_INFO(VMBUS, "OS Build:%d-%d.%d-%d-%d.%d",\
118 eax, 119 eax,
@@ -122,80 +123,81 @@ static int HvQueryHypervisorInfo(void)
122 edx >> 24, 123 edx >> 24,
123 edx & 0xFFFFFF); 124 edx & 0xFFFFFF);
124 } 125 }
125 return maxLeaf; 126 return max_leaf;
126} 127}
127 128
128/* 129/*
129 * HvDoHypercall - Invoke the specified hypercall 130 * do_hypercall- Invoke the specified hypercall
130 */ 131 */
131static u64 HvDoHypercall(u64 Control, void *Input, void *Output) 132static u64 do_hypercall(u64 control, void *input, void *output)
132{ 133{
133#ifdef CONFIG_X86_64 134#ifdef CONFIG_X86_64
134 u64 hvStatus = 0; 135 u64 hv_status = 0;
135 u64 inputAddress = (Input) ? virt_to_phys(Input) : 0; 136 u64 input_address = (input) ? virt_to_phys(input) : 0;
136 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0; 137 u64 output_address = (output) ? virt_to_phys(output) : 0;
137 volatile void *hypercallPage = gHvContext.HypercallPage; 138 volatile void *hypercall_page = hv_context.hypercall_page;
138 139
139 DPRINT_DBG(VMBUS, "Hypercall <control %llx input phys %llx virt %p " 140 DPRINT_DBG(VMBUS, "Hypercall <control %llx input phys %llx virt %p "
140 "output phys %llx virt %p hypercall %p>", 141 "output phys %llx virt %p hypercall %p>",
141 Control, inputAddress, Input, 142 control, input_address, input,
142 outputAddress, Output, hypercallPage); 143 output_address, output, hypercall_page);
143 144
144 __asm__ __volatile__("mov %0, %%r8" : : "r" (outputAddress) : "r8"); 145 __asm__ __volatile__("mov %0, %%r8" : : "r" (output_address) : "r8");
145 __asm__ __volatile__("call *%3" : "=a" (hvStatus) : 146 __asm__ __volatile__("call *%3" : "=a" (hv_status) :
146 "c" (Control), "d" (inputAddress), 147 "c" (control), "d" (input_address),
147 "m" (hypercallPage)); 148 "m" (hypercall_page));
148 149
149 DPRINT_DBG(VMBUS, "Hypercall <return %llx>", hvStatus); 150 DPRINT_DBG(VMBUS, "Hypercall <return %llx>", hv_status);
150 151
151 return hvStatus; 152 return hv_status;
152 153
153#else 154#else
154 155
155 u32 controlHi = Control >> 32; 156 u32 control_hi = control >> 32;
156 u32 controlLo = Control & 0xFFFFFFFF; 157 u32 control_lo = control & 0xFFFFFFFF;
157 u32 hvStatusHi = 1; 158 u32 hv_status_hi = 1;
158 u32 hvStatusLo = 1; 159 u32 hv_status_lo = 1;
159 u64 inputAddress = (Input) ? virt_to_phys(Input) : 0; 160 u64 input_address = (input) ? virt_to_phys(input) : 0;
160 u32 inputAddressHi = inputAddress >> 32; 161 u32 input_address_hi = input_address >> 32;
161 u32 inputAddressLo = inputAddress & 0xFFFFFFFF; 162 u32 input_address_lo = input_address & 0xFFFFFFFF;
162 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0; 163 u64 output_address = (output) ? virt_to_phys(output) : 0;
163 u32 outputAddressHi = outputAddress >> 32; 164 u32 output_address_hi = output_address >> 32;
164 u32 outputAddressLo = outputAddress & 0xFFFFFFFF; 165 u32 output_address_lo = output_address & 0xFFFFFFFF;
165 volatile void *hypercallPage = gHvContext.HypercallPage; 166 volatile void *hypercall_page = hv_context.hypercall_page;
166 167
167 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>", 168 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
168 Control, Input, Output); 169 control, input, output);
169 170
170 __asm__ __volatile__ ("call *%8" : "=d"(hvStatusHi), 171 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
171 "=a"(hvStatusLo) : "d" (controlHi), 172 "=a"(hv_status_lo) : "d" (control_hi),
172 "a" (controlLo), "b" (inputAddressHi), 173 "a" (control_lo), "b" (input_address_hi),
173 "c" (inputAddressLo), "D"(outputAddressHi), 174 "c" (input_address_lo), "D"(output_address_hi),
174 "S"(outputAddressLo), "m" (hypercallPage)); 175 "S"(output_address_lo), "m" (hypercall_page));
175 176
176 DPRINT_DBG(VMBUS, "Hypercall <return %llx>", 177 DPRINT_DBG(VMBUS, "Hypercall <return %llx>",
177 hvStatusLo | ((u64)hvStatusHi << 32)); 178 hv_status_lo | ((u64)hv_status_hi << 32));
178 179
179 return hvStatusLo | ((u64)hvStatusHi << 32); 180 return hv_status_lo | ((u64)hv_status_hi << 32);
180#endif /* !x86_64 */ 181#endif /* !x86_64 */
181} 182}
182 183
183/* 184/*
184 * HvInit - Main initialization routine. 185 * hv_init - Main initialization routine.
185 * 186 *
186 * This routine must be called before any other routines in here are called 187 * This routine must be called before any other routines in here are called
187 */ 188 */
188int HvInit(void) 189int hv_init(void)
189{ 190{
190 int ret = 0; 191 int ret = 0;
191 int maxLeaf; 192 int max_leaf;
192 union hv_x64_msr_hypercall_contents hypercallMsr; 193 union hv_x64_msr_hypercall_contents hypercall_msr;
193 void *virtAddr = NULL; 194 void *virtaddr = NULL;
194 195
195 memset(gHvContext.synICEventPage, 0, sizeof(void *) * MAX_NUM_CPUS); 196 memset(hv_context.synic_event_page, 0, sizeof(void *) * MAX_NUM_CPUS);
196 memset(gHvContext.synICMessagePage, 0, sizeof(void *) * MAX_NUM_CPUS); 197 memset(hv_context.synic_message_page, 0,
198 sizeof(void *) * MAX_NUM_CPUS);
197 199
198 if (!HvQueryHypervisorPresence()) { 200 if (!query_hypervisor_presence()) {
199 DPRINT_ERR(VMBUS, "No Windows hypervisor detected!!"); 201 DPRINT_ERR(VMBUS, "No Windows hypervisor detected!!");
200 goto Cleanup; 202 goto Cleanup;
201 } 203 }
@@ -203,146 +205,148 @@ int HvInit(void)
203 DPRINT_INFO(VMBUS, 205 DPRINT_INFO(VMBUS,
204 "Windows hypervisor detected! Retrieving more info..."); 206 "Windows hypervisor detected! Retrieving more info...");
205 207
206 maxLeaf = HvQueryHypervisorInfo(); 208 max_leaf = query_hypervisor_info();
207 /* HvQueryHypervisorFeatures(maxLeaf); */ 209 /* HvQueryHypervisorFeatures(maxLeaf); */
208 210
209 /* 211 /*
210 * We only support running on top of Hyper-V 212 * We only support running on top of Hyper-V
211 */ 213 */
212 rdmsrl(HV_X64_MSR_GUEST_OS_ID, gHvContext.GuestId); 214 rdmsrl(HV_X64_MSR_GUEST_OS_ID, hv_context.guestid);
213 215
214 if (gHvContext.GuestId != 0) { 216 if (hv_context.guestid != 0) {
215 DPRINT_ERR(VMBUS, "Unknown guest id (0x%llx)!!", 217 DPRINT_ERR(VMBUS, "Unknown guest id (0x%llx)!!",
216 gHvContext.GuestId); 218 hv_context.guestid);
217 goto Cleanup; 219 goto Cleanup;
218 } 220 }
219 221
220 /* Write our OS info */ 222 /* Write our OS info */
221 wrmsrl(HV_X64_MSR_GUEST_OS_ID, HV_LINUX_GUEST_ID); 223 wrmsrl(HV_X64_MSR_GUEST_OS_ID, HV_LINUX_GUEST_ID);
222 gHvContext.GuestId = HV_LINUX_GUEST_ID; 224 hv_context.guestid = HV_LINUX_GUEST_ID;
223 225
224 /* See if the hypercall page is already set */ 226 /* See if the hypercall page is already set */
225 rdmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); 227 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
226 228
227 /* 229 /*
228 * Allocate the hypercall page memory 230 * Allocate the hypercall page memory
229 * virtAddr = osd_PageAlloc(1); 231 * virtaddr = osd_page_alloc(1);
230 */ 232 */
231 virtAddr = osd_VirtualAllocExec(PAGE_SIZE); 233 virtaddr = osd_virtual_alloc_exec(PAGE_SIZE);
232 234
233 if (!virtAddr) { 235 if (!virtaddr) {
234 DPRINT_ERR(VMBUS, 236 DPRINT_ERR(VMBUS,
235 "unable to allocate hypercall page!!"); 237 "unable to allocate hypercall page!!");
236 goto Cleanup; 238 goto Cleanup;
237 } 239 }
238 240
239 hypercallMsr.Enable = 1; 241 hypercall_msr.enable = 1;
240 242
241 hypercallMsr.GuestPhysicalAddress = vmalloc_to_pfn(virtAddr); 243 hypercall_msr.guest_physical_address = vmalloc_to_pfn(virtaddr);
242 wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); 244 wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
243 245
244 /* Confirm that hypercall page did get setup. */ 246 /* Confirm that hypercall page did get setup. */
245 hypercallMsr.AsUINT64 = 0; 247 hypercall_msr.as_uint64 = 0;
246 rdmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); 248 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
247 249
248 if (!hypercallMsr.Enable) { 250 if (!hypercall_msr.enable) {
249 DPRINT_ERR(VMBUS, "unable to set hypercall page!!"); 251 DPRINT_ERR(VMBUS, "unable to set hypercall page!!");
250 goto Cleanup; 252 goto Cleanup;
251 } 253 }
252 254
253 gHvContext.HypercallPage = virtAddr; 255 hv_context.hypercall_page = virtaddr;
254 256
255 DPRINT_INFO(VMBUS, "Hypercall page VA=%p, PA=0x%0llx", 257 DPRINT_INFO(VMBUS, "Hypercall page VA=%p, PA=0x%0llx",
256 gHvContext.HypercallPage, 258 hv_context.hypercall_page,
257 (u64)hypercallMsr.GuestPhysicalAddress << PAGE_SHIFT); 259 (u64)hypercall_msr.guest_physical_address << PAGE_SHIFT);
258 260
259 /* Setup the global signal event param for the signal event hypercall */ 261 /* Setup the global signal event param for the signal event hypercall */
260 gHvContext.SignalEventBuffer = 262 hv_context.signal_event_buffer =
261 kmalloc(sizeof(struct hv_input_signal_event_buffer), 263 kmalloc(sizeof(struct hv_input_signal_event_buffer),
262 GFP_KERNEL); 264 GFP_KERNEL);
263 if (!gHvContext.SignalEventBuffer) 265 if (!hv_context.signal_event_buffer)
264 goto Cleanup; 266 goto Cleanup;
265 267
266 gHvContext.SignalEventParam = 268 hv_context.signal_event_param =
267 (struct hv_input_signal_event *) 269 (struct hv_input_signal_event *)
268 (ALIGN_UP((unsigned long)gHvContext.SignalEventBuffer, 270 (ALIGN_UP((unsigned long)
271 hv_context.signal_event_buffer,
269 HV_HYPERCALL_PARAM_ALIGN)); 272 HV_HYPERCALL_PARAM_ALIGN));
270 gHvContext.SignalEventParam->ConnectionId.Asu32 = 0; 273 hv_context.signal_event_param->connectionid.asu32 = 0;
271 gHvContext.SignalEventParam->ConnectionId.u.Id = 274 hv_context.signal_event_param->connectionid.u.id =
272 VMBUS_EVENT_CONNECTION_ID; 275 VMBUS_EVENT_CONNECTION_ID;
273 gHvContext.SignalEventParam->FlagNumber = 0; 276 hv_context.signal_event_param->flag_number = 0;
274 gHvContext.SignalEventParam->RsvdZ = 0; 277 hv_context.signal_event_param->rsvdz = 0;
275 278
276 return ret; 279 return ret;
277 280
278Cleanup: 281Cleanup:
279 if (virtAddr) { 282 if (virtaddr) {
280 if (hypercallMsr.Enable) { 283 if (hypercall_msr.enable) {
281 hypercallMsr.AsUINT64 = 0; 284 hypercall_msr.as_uint64 = 0;
282 wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); 285 wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
283 } 286 }
284 287
285 vfree(virtAddr); 288 vfree(virtaddr);
286 } 289 }
287 ret = -1; 290 ret = -1;
288 return ret; 291 return ret;
289} 292}
290 293
291/* 294/*
292 * HvCleanup - Cleanup routine. 295 * hv_cleanup - Cleanup routine.
293 * 296 *
294 * This routine is called normally during driver unloading or exiting. 297 * This routine is called normally during driver unloading or exiting.
295 */ 298 */
296void HvCleanup(void) 299void hv_cleanup(void)
297{ 300{
298 union hv_x64_msr_hypercall_contents hypercallMsr; 301 union hv_x64_msr_hypercall_contents hypercall_msr;
299 302
300 kfree(gHvContext.SignalEventBuffer); 303 kfree(hv_context.signal_event_buffer);
301 gHvContext.SignalEventBuffer = NULL; 304 hv_context.signal_event_buffer = NULL;
302 gHvContext.SignalEventParam = NULL; 305 hv_context.signal_event_param = NULL;
303 306
304 if (gHvContext.HypercallPage) { 307 if (hv_context.hypercall_page) {
305 hypercallMsr.AsUINT64 = 0; 308 hypercall_msr.as_uint64 = 0;
306 wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); 309 wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
307 vfree(gHvContext.HypercallPage); 310 vfree(hv_context.hypercall_page);
308 gHvContext.HypercallPage = NULL; 311 hv_context.hypercall_page = NULL;
309 } 312 }
310} 313}
311 314
312/* 315/*
313 * HvPostMessage - Post a message using the hypervisor message IPC. 316 * hv_post_message - Post a message using the hypervisor message IPC.
314 * 317 *
315 * This involves a hypercall. 318 * This involves a hypercall.
316 */ 319 */
317u16 HvPostMessage(union hv_connection_id connectionId, 320u16 hv_post_message(union hv_connection_id connection_id,
318 enum hv_message_type messageType, 321 enum hv_message_type message_type,
319 void *payload, size_t payloadSize) 322 void *payload, size_t payload_size)
320{ 323{
321 struct alignedInput { 324 struct aligned_input {
322 u64 alignment8; 325 u64 alignment8;
323 struct hv_input_post_message msg; 326 struct hv_input_post_message msg;
324 }; 327 };
325 328
326 struct hv_input_post_message *alignedMsg; 329 struct hv_input_post_message *aligned_msg;
327 u16 status; 330 u16 status;
328 unsigned long addr; 331 unsigned long addr;
329 332
330 if (payloadSize > HV_MESSAGE_PAYLOAD_BYTE_COUNT) 333 if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT)
331 return -1; 334 return -1;
332 335
333 addr = (unsigned long)kmalloc(sizeof(struct alignedInput), GFP_ATOMIC); 336 addr = (unsigned long)kmalloc(sizeof(struct aligned_input), GFP_ATOMIC);
334 if (!addr) 337 if (!addr)
335 return -1; 338 return -1;
336 339
337 alignedMsg = (struct hv_input_post_message *) 340 aligned_msg = (struct hv_input_post_message *)
338 (ALIGN_UP(addr, HV_HYPERCALL_PARAM_ALIGN)); 341 (ALIGN_UP(addr, HV_HYPERCALL_PARAM_ALIGN));
339 342
340 alignedMsg->ConnectionId = connectionId; 343 aligned_msg->connectionid = connection_id;
341 alignedMsg->MessageType = messageType; 344 aligned_msg->message_type = message_type;
342 alignedMsg->PayloadSize = payloadSize; 345 aligned_msg->payload_size = payload_size;
343 memcpy((void *)alignedMsg->Payload, payload, payloadSize); 346 memcpy((void *)aligned_msg->payload, payload, payload_size);
344 347
345 status = HvDoHypercall(HvCallPostMessage, alignedMsg, NULL) & 0xFFFF; 348 status = do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL)
349 & 0xFFFF;
346 350
347 kfree((void *)addr); 351 kfree((void *)addr);
348 352
@@ -351,38 +355,40 @@ u16 HvPostMessage(union hv_connection_id connectionId,
351 355
352 356
353/* 357/*
354 * HvSignalEvent - Signal an event on the specified connection using the hypervisor event IPC. 358 * hv_signal_event -
359 * Signal an event on the specified connection using the hypervisor event IPC.
355 * 360 *
356 * This involves a hypercall. 361 * This involves a hypercall.
357 */ 362 */
358u16 HvSignalEvent(void) 363u16 hv_signal_event(void)
359{ 364{
360 u16 status; 365 u16 status;
361 366
362 status = HvDoHypercall(HvCallSignalEvent, gHvContext.SignalEventParam, 367 status = do_hypercall(HVCALL_SIGNAL_EVENT,
368 hv_context.signal_event_param,
363 NULL) & 0xFFFF; 369 NULL) & 0xFFFF;
364 return status; 370 return status;
365} 371}
366 372
367/* 373/*
368 * HvSynicInit - Initialize the Synthethic Interrupt Controller. 374 * hv_synic_init - Initialize the Synthethic Interrupt Controller.
369 * 375 *
370 * If it is already initialized by another entity (ie x2v shim), we need to 376 * If it is already initialized by another entity (ie x2v shim), we need to
371 * retrieve the initialized message and event pages. Otherwise, we create and 377 * retrieve the initialized message and event pages. Otherwise, we create and
372 * initialize the message and event pages. 378 * initialize the message and event pages.
373 */ 379 */
374void HvSynicInit(void *irqarg) 380void hv_synic_init(void *irqarg)
375{ 381{
376 u64 version; 382 u64 version;
377 union hv_synic_simp simp; 383 union hv_synic_simp simp;
378 union hv_synic_siefp siefp; 384 union hv_synic_siefp siefp;
379 union hv_synic_sint sharedSint; 385 union hv_synic_sint shared_sint;
380 union hv_synic_scontrol sctrl; 386 union hv_synic_scontrol sctrl;
381 387
382 u32 irqVector = *((u32 *)(irqarg)); 388 u32 irq_vector = *((u32 *)(irqarg));
383 int cpu = smp_processor_id(); 389 int cpu = smp_processor_id();
384 390
385 if (!gHvContext.HypercallPage) 391 if (!hv_context.hypercall_page)
386 return; 392 return;
387 393
388 /* Check the version */ 394 /* Check the version */
@@ -390,110 +396,112 @@ void HvSynicInit(void *irqarg)
390 396
391 DPRINT_INFO(VMBUS, "SynIC version: %llx", version); 397 DPRINT_INFO(VMBUS, "SynIC version: %llx", version);
392 398
393 gHvContext.synICMessagePage[cpu] = (void *)get_zeroed_page(GFP_ATOMIC); 399 hv_context.synic_message_page[cpu] =
400 (void *)get_zeroed_page(GFP_ATOMIC);
394 401
395 if (gHvContext.synICMessagePage[cpu] == NULL) { 402 if (hv_context.synic_message_page[cpu] == NULL) {
396 DPRINT_ERR(VMBUS, 403 DPRINT_ERR(VMBUS,
397 "unable to allocate SYNIC message page!!"); 404 "unable to allocate SYNIC message page!!");
398 goto Cleanup; 405 goto Cleanup;
399 } 406 }
400 407
401 gHvContext.synICEventPage[cpu] = (void *)get_zeroed_page(GFP_ATOMIC); 408 hv_context.synic_event_page[cpu] =
409 (void *)get_zeroed_page(GFP_ATOMIC);
402 410
403 if (gHvContext.synICEventPage[cpu] == NULL) { 411 if (hv_context.synic_event_page[cpu] == NULL) {
404 DPRINT_ERR(VMBUS, 412 DPRINT_ERR(VMBUS,
405 "unable to allocate SYNIC event page!!"); 413 "unable to allocate SYNIC event page!!");
406 goto Cleanup; 414 goto Cleanup;
407 } 415 }
408 416
409 /* Setup the Synic's message page */ 417 /* Setup the Synic's message page */
410 rdmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); 418 rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
411 simp.SimpEnabled = 1; 419 simp.simp_enabled = 1;
412 simp.BaseSimpGpa = virt_to_phys(gHvContext.synICMessagePage[cpu]) 420 simp.base_simp_gpa = virt_to_phys(hv_context.synic_message_page[cpu])
413 >> PAGE_SHIFT; 421 >> PAGE_SHIFT;
414 422
415 DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", simp.AsUINT64); 423 DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", simp.as_uint64);
416 424
417 wrmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); 425 wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
418 426
419 /* Setup the Synic's event page */ 427 /* Setup the Synic's event page */
420 rdmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); 428 rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
421 siefp.SiefpEnabled = 1; 429 siefp.siefp_enabled = 1;
422 siefp.BaseSiefpGpa = virt_to_phys(gHvContext.synICEventPage[cpu]) 430 siefp.base_siefp_gpa = virt_to_phys(hv_context.synic_event_page[cpu])
423 >> PAGE_SHIFT; 431 >> PAGE_SHIFT;
424 432
425 DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", siefp.AsUINT64); 433 DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", siefp.as_uint64);
426 434
427 wrmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); 435 wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
428 436
429 /* Setup the interception SINT. */ 437 /* Setup the interception SINT. */
430 /* wrmsrl((HV_X64_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX), */ 438 /* wrmsrl((HV_X64_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX), */
431 /* interceptionSint.AsUINT64); */ 439 /* interceptionSint.as_uint64); */
432 440
433 /* Setup the shared SINT. */ 441 /* Setup the shared SINT. */
434 rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); 442 rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
435 443
436 sharedSint.AsUINT64 = 0; 444 shared_sint.as_uint64 = 0;
437 sharedSint.Vector = irqVector; /* HV_SHARED_SINT_IDT_VECTOR + 0x20; */ 445 shared_sint.vector = irq_vector; /* HV_SHARED_SINT_IDT_VECTOR + 0x20; */
438 sharedSint.Masked = false; 446 shared_sint.masked = false;
439 sharedSint.AutoEoi = true; 447 shared_sint.auto_eoi = true;
440 448
441 DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx", 449 DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx",
442 sharedSint.AsUINT64); 450 shared_sint.as_uint64);
443 451
444 wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); 452 wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
445 453
446 /* Enable the global synic bit */ 454 /* Enable the global synic bit */
447 rdmsrl(HV_X64_MSR_SCONTROL, sctrl.AsUINT64); 455 rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
448 sctrl.Enable = 1; 456 sctrl.enable = 1;
449 457
450 wrmsrl(HV_X64_MSR_SCONTROL, sctrl.AsUINT64); 458 wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
451 459
452 gHvContext.SynICInitialized = true; 460 hv_context.synic_initialized = true;
453 return; 461 return;
454 462
455Cleanup: 463Cleanup:
456 if (gHvContext.synICEventPage[cpu]) 464 if (hv_context.synic_event_page[cpu])
457 osd_PageFree(gHvContext.synICEventPage[cpu], 1); 465 osd_page_free(hv_context.synic_event_page[cpu], 1);
458 466
459 if (gHvContext.synICMessagePage[cpu]) 467 if (hv_context.synic_message_page[cpu])
460 osd_PageFree(gHvContext.synICMessagePage[cpu], 1); 468 osd_page_free(hv_context.synic_message_page[cpu], 1);
461 return; 469 return;
462} 470}
463 471
464/* 472/*
465 * HvSynicCleanup - Cleanup routine for HvSynicInit(). 473 * hv_synic_cleanup - Cleanup routine for hv_synic_init().
466 */ 474 */
467void HvSynicCleanup(void *arg) 475void hv_synic_cleanup(void *arg)
468{ 476{
469 union hv_synic_sint sharedSint; 477 union hv_synic_sint shared_sint;
470 union hv_synic_simp simp; 478 union hv_synic_simp simp;
471 union hv_synic_siefp siefp; 479 union hv_synic_siefp siefp;
472 int cpu = smp_processor_id(); 480 int cpu = smp_processor_id();
473 481
474 if (!gHvContext.SynICInitialized) 482 if (!hv_context.synic_initialized)
475 return; 483 return;
476 484
477 rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); 485 rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
478 486
479 sharedSint.Masked = 1; 487 shared_sint.masked = 1;
480 488
481 /* Need to correctly cleanup in the case of SMP!!! */ 489 /* Need to correctly cleanup in the case of SMP!!! */
482 /* Disable the interrupt */ 490 /* Disable the interrupt */
483 wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); 491 wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64);
484 492
485 rdmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); 493 rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
486 simp.SimpEnabled = 0; 494 simp.simp_enabled = 0;
487 simp.BaseSimpGpa = 0; 495 simp.base_simp_gpa = 0;
488 496
489 wrmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); 497 wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64);
490 498
491 rdmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); 499 rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
492 siefp.SiefpEnabled = 0; 500 siefp.siefp_enabled = 0;
493 siefp.BaseSiefpGpa = 0; 501 siefp.base_siefp_gpa = 0;
494 502
495 wrmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); 503 wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64);
496 504
497 osd_PageFree(gHvContext.synICMessagePage[cpu], 1); 505 osd_page_free(hv_context.synic_message_page[cpu], 1);
498 osd_PageFree(gHvContext.synICEventPage[cpu], 1); 506 osd_page_free(hv_context.synic_event_page[cpu], 1);
499} 507}
diff --git a/drivers/staging/hv/hv.h b/drivers/staging/hv/hv.h
index 41f5ebb86e17..829aff81bb30 100644
--- a/drivers/staging/hv/hv.h
+++ b/drivers/staging/hv/hv.h
@@ -92,49 +92,49 @@ static const struct hv_guid VMBUS_SERVICE_ID = {
92 92
93 93
94struct hv_input_signal_event_buffer { 94struct hv_input_signal_event_buffer {
95 u64 Align8; 95 u64 align8;
96 struct hv_input_signal_event Event; 96 struct hv_input_signal_event event;
97}; 97};
98 98
99struct hv_context { 99struct hv_context {
100 /* We only support running on top of Hyper-V 100 /* We only support running on top of Hyper-V
101 * So at this point this really can only contain the Hyper-V ID 101 * So at this point this really can only contain the Hyper-V ID
102 */ 102 */
103 u64 GuestId; 103 u64 guestid;
104 104
105 void *HypercallPage; 105 void *hypercall_page;
106 106
107 bool SynICInitialized; 107 bool synic_initialized;
108 108
109 /* 109 /*
110 * This is used as an input param to HvCallSignalEvent hypercall. The 110 * This is used as an input param to HvCallSignalEvent hypercall. The
111 * input param is immutable in our usage and must be dynamic mem (vs 111 * input param is immutable in our usage and must be dynamic mem (vs
112 * stack or global). */ 112 * stack or global). */
113 struct hv_input_signal_event_buffer *SignalEventBuffer; 113 struct hv_input_signal_event_buffer *signal_event_buffer;
114 /* 8-bytes aligned of the buffer above */ 114 /* 8-bytes aligned of the buffer above */
115 struct hv_input_signal_event *SignalEventParam; 115 struct hv_input_signal_event *signal_event_param;
116 116
117 void *synICMessagePage[MAX_NUM_CPUS]; 117 void *synic_message_page[MAX_NUM_CPUS];
118 void *synICEventPage[MAX_NUM_CPUS]; 118 void *synic_event_page[MAX_NUM_CPUS];
119}; 119};
120 120
121extern struct hv_context gHvContext; 121extern struct hv_context hv_context;
122 122
123 123
124/* Hv Interface */ 124/* Hv Interface */
125 125
126extern int HvInit(void); 126extern int hv_init(void);
127 127
128extern void HvCleanup(void); 128extern void hv_cleanup(void);
129 129
130extern u16 HvPostMessage(union hv_connection_id connectionId, 130extern u16 hv_post_message(union hv_connection_id connection_id,
131 enum hv_message_type messageType, 131 enum hv_message_type message_type,
132 void *payload, size_t payloadSize); 132 void *payload, size_t payload_size);
133 133
134extern u16 HvSignalEvent(void); 134extern u16 hv_signal_event(void);
135 135
136extern void HvSynicInit(void *irqarg); 136extern void hv_synic_init(void *irqarg);
137 137
138extern void HvSynicCleanup(void *arg); 138extern void hv_synic_cleanup(void *arg);
139 139
140#endif /* __HV_H__ */ 140#endif /* __HV_H__ */
diff --git a/drivers/staging/hv/hv_api.h b/drivers/staging/hv/hv_api.h
index 9eb818ee07ba..70e863ad0464 100644
--- a/drivers/staging/hv/hv_api.h
+++ b/drivers/staging/hv/hv_api.h
@@ -510,21 +510,21 @@
510 510
511/* 511/*
512 * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent 512 * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
513 * is set by CPUID(HvCpuIdFunctionVersionAndFeatures). 513 * is set by CPUID(HVCPUID_VERSION_FEATURES).
514 */ 514 */
515enum hv_cpuid_function { 515enum hv_cpuid_function {
516 HvCpuIdFunctionVersionAndFeatures = 0x00000001, 516 HVCPUID_VERSION_FEATURES = 0x00000001,
517 HvCpuIdFunctionHvVendorAndMaxFunction = 0x40000000, 517 HVCPUID_VENDOR_MAXFUNCTION = 0x40000000,
518 HvCpuIdFunctionHvInterface = 0x40000001, 518 HVCPUID_INTERFACE = 0x40000001,
519 519
520 /* 520 /*
521 * The remaining functions depend on the value of 521 * The remaining functions depend on the value of
522 * HvCpuIdFunctionInterface 522 * HVCPUID_INTERFACE
523 */ 523 */
524 HvCpuIdFunctionMsHvVersion = 0x40000002, 524 HVCPUID_VERSION = 0x40000002,
525 HvCpuIdFunctionMsHvFeatures = 0x40000003, 525 HVCPUID_FEATURES = 0x40000003,
526 HvCpuIdFunctionMsHvEnlightenmentInformation = 0x40000004, 526 HVCPUID_ENLIGHTENMENT_INFO = 0x40000004,
527 HvCpuIdFunctionMsHvImplementationLimits = 0x40000005, 527 HVCPUID_IMPLEMENTATION_LIMITS = 0x40000005,
528}; 528};
529 529
530/* Define the virtual APIC registers */ 530/* Define the virtual APIC registers */
@@ -575,30 +575,30 @@ enum hv_cpuid_function {
575 575
576/* Define hypervisor message types. */ 576/* Define hypervisor message types. */
577enum hv_message_type { 577enum hv_message_type {
578 HvMessageTypeNone = 0x00000000, 578 HVMSG_NONE = 0x00000000,
579 579
580 /* Memory access messages. */ 580 /* Memory access messages. */
581 HvMessageTypeUnmappedGpa = 0x80000000, 581 HVMSG_UNMAPPED_GPA = 0x80000000,
582 HvMessageTypeGpaIntercept = 0x80000001, 582 HVMSG_GPA_INTERCEPT = 0x80000001,
583 583
584 /* Timer notification messages. */ 584 /* Timer notification messages. */
585 HvMessageTimerExpired = 0x80000010, 585 HVMSG_TIMER_EXPIRED = 0x80000010,
586 586
587 /* Error messages. */ 587 /* Error messages. */
588 HvMessageTypeInvalidVpRegisterValue = 0x80000020, 588 HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020,
589 HvMessageTypeUnrecoverableException = 0x80000021, 589 HVMSG_UNRECOVERABLE_EXCEPTION = 0x80000021,
590 HvMessageTypeUnsupportedFeature = 0x80000022, 590 HVMSG_UNSUPPORTED_FEATURE = 0x80000022,
591 591
592 /* Trace buffer complete messages. */ 592 /* Trace buffer complete messages. */
593 HvMessageTypeEventLogBufferComplete = 0x80000040, 593 HVMSG_EVENTLOG_BUFFERCOMPLETE = 0x80000040,
594 594
595 /* Platform-specific processor intercept messages. */ 595 /* Platform-specific processor intercept messages. */
596 HvMessageTypeX64IoPortIntercept = 0x80010000, 596 HVMSG_X64_IOPORT_INTERCEPT = 0x80010000,
597 HvMessageTypeX64MsrIntercept = 0x80010001, 597 HVMSG_X64_MSR_INTERCEPT = 0x80010001,
598 HvMessageTypeX64CpuidIntercept = 0x80010002, 598 HVMSG_X64_CPUID_INTERCEPT = 0x80010002,
599 HvMessageTypeX64ExceptionIntercept = 0x80010003, 599 HVMSG_X64_EXCEPTION_INTERCEPT = 0x80010003,
600 HvMessageTypeX64ApicEoi = 0x80010004, 600 HVMSG_X64_APIC_EOI = 0x80010004,
601 HvMessageTypeX64LegacyFpError = 0x80010005 601 HVMSG_X64_LEGACY_FP_ERROR = 0x80010005
602}; 602};
603 603
604/* Define the number of synthetic interrupt sources. */ 604/* Define the number of synthetic interrupt sources. */
@@ -610,103 +610,103 @@ enum hv_message_type {
610 610
611/* Define connection identifier type. */ 611/* Define connection identifier type. */
612union hv_connection_id { 612union hv_connection_id {
613 u32 Asu32; 613 u32 asu32;
614 struct { 614 struct {
615 u32 Id:24; 615 u32 id:24;
616 u32 Reserved:8; 616 u32 reserved:8;
617 } u; 617 } u;
618}; 618};
619 619
620/* Define port identifier type. */ 620/* Define port identifier type. */
621union hv_port_id { 621union hv_port_id {
622 u32 Asu32; 622 u32 asu32;
623 struct { 623 struct {
624 u32 Id:24; 624 u32 id:24;
625 u32 Reserved:8; 625 u32 reserved:8;
626 } u ; 626 } u ;
627}; 627};
628 628
629/* Define port type. */ 629/* Define port type. */
630enum hv_port_type { 630enum hv_port_type {
631 HvPortTypeMessage = 1, 631 HVPORT_MSG = 1,
632 HvPortTypeEvent = 2, 632 HVPORT_EVENT = 2,
633 HvPortTypeMonitor = 3 633 HVPORT_MONITOR = 3
634}; 634};
635 635
636/* Define port information structure. */ 636/* Define port information structure. */
637struct hv_port_info { 637struct hv_port_info {
638 enum hv_port_type PortType; 638 enum hv_port_type port_type;
639 u32 Padding; 639 u32 padding;
640 union { 640 union {
641 struct { 641 struct {
642 u32 TargetSint; 642 u32 target_sint;
643 u32 TargetVp; 643 u32 target_vp;
644 u64 RsvdZ; 644 u64 rsvdz;
645 } MessagePortInfo; 645 } message_port_info;
646 struct { 646 struct {
647 u32 TargetSint; 647 u32 target_sint;
648 u32 TargetVp; 648 u32 target_vp;
649 u16 BaseFlagNumber; 649 u16 base_flag_bumber;
650 u16 FlagCount; 650 u16 flag_count;
651 u32 RsvdZ; 651 u32 rsvdz;
652 } EventPortInfo; 652 } event_port_info;
653 struct { 653 struct {
654 u64 MonitorAddress; 654 u64 monitor_address;
655 u64 RsvdZ; 655 u64 rsvdz;
656 } MonitorPortInfo; 656 } monitor_port_info;
657 }; 657 };
658}; 658};
659 659
660struct hv_connection_info { 660struct hv_connection_info {
661 enum hv_port_type PortType; 661 enum hv_port_type port_type;
662 u32 Padding; 662 u32 padding;
663 union { 663 union {
664 struct { 664 struct {
665 u64 RsvdZ; 665 u64 rsvdz;
666 } MessageConnectionInfo; 666 } message_connection_info;
667 struct { 667 struct {
668 u64 RsvdZ; 668 u64 rsvdz;
669 } EventConnectionInfo; 669 } event_connection_info;
670 struct { 670 struct {
671 u64 MonitorAddress; 671 u64 monitor_address;
672 } MonitorConnectionInfo; 672 } monitor_connection_info;
673 }; 673 };
674}; 674};
675 675
676/* Define synthetic interrupt controller message flags. */ 676/* Define synthetic interrupt controller message flags. */
677union hv_message_flags { 677union hv_message_flags {
678 u8 Asu8; 678 u8 asu8;
679 struct { 679 struct {
680 u8 MessagePending:1; 680 u8 msg_pending:1;
681 u8 Reserved:7; 681 u8 reserved:7;
682 }; 682 };
683}; 683};
684 684
685/* Define synthetic interrupt controller message header. */ 685/* Define synthetic interrupt controller message header. */
686struct hv_message_header { 686struct hv_message_header {
687 enum hv_message_type MessageType; 687 enum hv_message_type message_type;
688 u8 PayloadSize; 688 u8 payload_size;
689 union hv_message_flags MessageFlags; 689 union hv_message_flags message_flags;
690 u8 Reserved[2]; 690 u8 reserved[2];
691 union { 691 union {
692 u64 Sender; 692 u64 sender;
693 union hv_port_id Port; 693 union hv_port_id port;
694 }; 694 };
695}; 695};
696 696
697/* Define timer message payload structure. */ 697/* Define timer message payload structure. */
698struct hv_timer_message_payload { 698struct hv_timer_message_payload {
699 u32 TimerIndex; 699 u32 timer_index;
700 u32 Reserved; 700 u32 reserved;
701 u64 ExpirationTime; /* When the timer expired */ 701 u64 expiration_time; /* When the timer expired */
702 u64 DeliveryTime; /* When the message was delivered */ 702 u64 delivery_time; /* When the message was delivered */
703}; 703};
704 704
705/* Define synthetic interrupt controller message format. */ 705/* Define synthetic interrupt controller message format. */
706struct hv_message { 706struct hv_message {
707 struct hv_message_header Header; 707 struct hv_message_header header;
708 union { 708 union {
709 u64 Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; 709 u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
710 } u ; 710 } u ;
711}; 711};
712 712
@@ -715,82 +715,82 @@ struct hv_message {
715 715
716/* Define the synthetic interrupt message page layout. */ 716/* Define the synthetic interrupt message page layout. */
717struct hv_message_page { 717struct hv_message_page {
718 struct hv_message SintMessage[HV_SYNIC_SINT_COUNT]; 718 struct hv_message sint_message[HV_SYNIC_SINT_COUNT];
719}; 719};
720 720
721/* Define the synthetic interrupt controller event flags format. */ 721/* Define the synthetic interrupt controller event flags format. */
722union hv_synic_event_flags { 722union hv_synic_event_flags {
723 u8 Flags8[HV_EVENT_FLAGS_BYTE_COUNT]; 723 u8 flags8[HV_EVENT_FLAGS_BYTE_COUNT];
724 u32 Flags32[HV_EVENT_FLAGS_DWORD_COUNT]; 724 u32 flags32[HV_EVENT_FLAGS_DWORD_COUNT];
725}; 725};
726 726
727/* Define the synthetic interrupt flags page layout. */ 727/* Define the synthetic interrupt flags page layout. */
728struct hv_synic_event_flags_page { 728struct hv_synic_event_flags_page {
729 union hv_synic_event_flags SintEventFlags[HV_SYNIC_SINT_COUNT]; 729 union hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT];
730}; 730};
731 731
732/* Define SynIC control register. */ 732/* Define SynIC control register. */
733union hv_synic_scontrol { 733union hv_synic_scontrol {
734 u64 AsUINT64; 734 u64 as_uint64;
735 struct { 735 struct {
736 u64 Enable:1; 736 u64 enable:1;
737 u64 Reserved:63; 737 u64 reserved:63;
738 }; 738 };
739}; 739};
740 740
741/* Define synthetic interrupt source. */ 741/* Define synthetic interrupt source. */
742union hv_synic_sint { 742union hv_synic_sint {
743 u64 AsUINT64; 743 u64 as_uint64;
744 struct { 744 struct {
745 u64 Vector:8; 745 u64 vector:8;
746 u64 Reserved1:8; 746 u64 reserved1:8;
747 u64 Masked:1; 747 u64 masked:1;
748 u64 AutoEoi:1; 748 u64 auto_eoi:1;
749 u64 Reserved2:46; 749 u64 reserved2:46;
750 }; 750 };
751}; 751};
752 752
753/* Define the format of the SIMP register */ 753/* Define the format of the SIMP register */
754union hv_synic_simp { 754union hv_synic_simp {
755 u64 AsUINT64; 755 u64 as_uint64;
756 struct { 756 struct {
757 u64 SimpEnabled:1; 757 u64 simp_enabled:1;
758 u64 Preserved:11; 758 u64 preserved:11;
759 u64 BaseSimpGpa:52; 759 u64 base_simp_gpa:52;
760 }; 760 };
761}; 761};
762 762
763/* Define the format of the SIEFP register */ 763/* Define the format of the SIEFP register */
764union hv_synic_siefp { 764union hv_synic_siefp {
765 u64 AsUINT64; 765 u64 as_uint64;
766 struct { 766 struct {
767 u64 SiefpEnabled:1; 767 u64 siefp_enabled:1;
768 u64 Preserved:11; 768 u64 preserved:11;
769 u64 BaseSiefpGpa:52; 769 u64 base_siefp_gpa:52;
770 }; 770 };
771}; 771};
772 772
773/* Definitions for the monitored notification facility */ 773/* Definitions for the monitored notification facility */
774union hv_monitor_trigger_group { 774union hv_monitor_trigger_group {
775 u64 AsUINT64; 775 u64 as_uint64;
776 struct { 776 struct {
777 u32 Pending; 777 u32 pending;
778 u32 Armed; 778 u32 armed;
779 }; 779 };
780}; 780};
781 781
782struct hv_monitor_parameter { 782struct hv_monitor_parameter {
783 union hv_connection_id ConnectionId; 783 union hv_connection_id connectionid;
784 u16 FlagNumber; 784 u16 flagnumber;
785 u16 RsvdZ; 785 u16 rsvdz;
786}; 786};
787 787
788union hv_monitor_trigger_state { 788union hv_monitor_trigger_state {
789 u32 Asu32; 789 u32 asu32;
790 790
791 struct { 791 struct {
792 u32 GroupEnable:4; 792 u32 group_enable:4;
793 u32 RsvdZ:28; 793 u32 rsvdz:28;
794 }; 794 };
795}; 795};
796 796
@@ -814,42 +814,42 @@ union hv_monitor_trigger_state {
814/* | 840 | Rsvd4[0] | */ 814/* | 840 | Rsvd4[0] | */
815/* ------------------------------------------------------ */ 815/* ------------------------------------------------------ */
816struct hv_monitor_page { 816struct hv_monitor_page {
817 union hv_monitor_trigger_state TriggerState; 817 union hv_monitor_trigger_state trigger_state;
818 u32 RsvdZ1; 818 u32 rsvdz1;
819 819
820 union hv_monitor_trigger_group TriggerGroup[4]; 820 union hv_monitor_trigger_group trigger_group[4];
821 u64 RsvdZ2[3]; 821 u64 rsvdz2[3];
822 822
823 s32 NextCheckTime[4][32]; 823 s32 next_checktime[4][32];
824 824
825 u16 Latency[4][32]; 825 u16 latency[4][32];
826 u64 RsvdZ3[32]; 826 u64 rsvdz3[32];
827 827
828 struct hv_monitor_parameter Parameter[4][32]; 828 struct hv_monitor_parameter parameter[4][32];
829 829
830 u8 RsvdZ4[1984]; 830 u8 rsvdz4[1984];
831}; 831};
832 832
833/* Declare the various hypercall operations. */ 833/* Declare the various hypercall operations. */
834enum hv_call_code { 834enum hv_call_code {
835 HvCallPostMessage = 0x005c, 835 HVCALL_POST_MESSAGE = 0x005c,
836 HvCallSignalEvent = 0x005d, 836 HVCALL_SIGNAL_EVENT = 0x005d,
837}; 837};
838 838
839/* Definition of the HvPostMessage hypercall input structure. */ 839/* Definition of the hv_post_message hypercall input structure. */
840struct hv_input_post_message { 840struct hv_input_post_message {
841 union hv_connection_id ConnectionId; 841 union hv_connection_id connectionid;
842 u32 Reserved; 842 u32 reserved;
843 enum hv_message_type MessageType; 843 enum hv_message_type message_type;
844 u32 PayloadSize; 844 u32 payload_size;
845 u64 Payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; 845 u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
846}; 846};
847 847
848/* Definition of the HvSignalEvent hypercall input structure. */ 848/* Definition of the hv_signal_event hypercall input structure. */
849struct hv_input_signal_event { 849struct hv_input_signal_event {
850 union hv_connection_id ConnectionId; 850 union hv_connection_id connectionid;
851 u16 FlagNumber; 851 u16 flag_number;
852 u16 RsvdZ; 852 u16 rsvdz;
853}; 853};
854 854
855/* 855/*
@@ -859,16 +859,16 @@ struct hv_input_signal_event {
859 859
860/* Version info reported by guest OS's */ 860/* Version info reported by guest OS's */
861enum hv_guest_os_vendor { 861enum hv_guest_os_vendor {
862 HvGuestOsVendorMicrosoft = 0x0001 862 HVGUESTOS_VENDOR_MICROSOFT = 0x0001
863}; 863};
864 864
865enum hv_guest_os_microsoft_ids { 865enum hv_guest_os_microsoft_ids {
866 HvGuestOsMicrosoftUndefined = 0x00, 866 HVGUESTOS_MICROSOFT_UNDEFINED = 0x00,
867 HvGuestOsMicrosoftMSDOS = 0x01, 867 HVGUESTOS_MICROSOFT_MSDOS = 0x01,
868 HvGuestOsMicrosoftWindows3x = 0x02, 868 HVGUESTOS_MICROSOFT_WINDOWS3X = 0x02,
869 HvGuestOsMicrosoftWindows9x = 0x03, 869 HVGUESTOS_MICROSOFT_WINDOWS9X = 0x03,
870 HvGuestOsMicrosoftWindowsNT = 0x04, 870 HVGUESTOS_MICROSOFT_WINDOWSNT = 0x04,
871 HvGuestOsMicrosoftWindowsCE = 0x05 871 HVGUESTOS_MICROSOFT_WINDOWSCE = 0x05
872}; 872};
873 873
874/* 874/*
@@ -877,14 +877,14 @@ enum hv_guest_os_microsoft_ids {
877#define HV_X64_MSR_GUEST_OS_ID 0x40000000 877#define HV_X64_MSR_GUEST_OS_ID 0x40000000
878 878
879union hv_x64_msr_guest_os_id_contents { 879union hv_x64_msr_guest_os_id_contents {
880 u64 AsUINT64; 880 u64 as_uint64;
881 struct { 881 struct {
882 u64 BuildNumber:16; 882 u64 build_number:16;
883 u64 ServiceVersion:8; /* Service Pack, etc. */ 883 u64 service_version:8; /* Service Pack, etc. */
884 u64 MinorVersion:8; 884 u64 minor_version:8;
885 u64 MajorVersion:8; 885 u64 major_version:8;
886 u64 OsId:8; /* enum hv_guest_os_microsoft_ids (if Vendor=MS) */ 886 u64 os_id:8; /* enum hv_guest_os_microsoft_ids (if Vendor=MS) */
887 u64 VendorId:16; /* enum hv_guest_os_vendor */ 887 u64 vendor_id:16; /* enum hv_guest_os_vendor */
888 }; 888 };
889}; 889};
890 890
@@ -894,11 +894,11 @@ union hv_x64_msr_guest_os_id_contents {
894#define HV_X64_MSR_HYPERCALL 0x40000001 894#define HV_X64_MSR_HYPERCALL 0x40000001
895 895
896union hv_x64_msr_hypercall_contents { 896union hv_x64_msr_hypercall_contents {
897 u64 AsUINT64; 897 u64 as_uint64;
898 struct { 898 struct {
899 u64 Enable:1; 899 u64 enable:1;
900 u64 Reserved:11; 900 u64 reserved:11;
901 u64 GuestPhysicalAddress:52; 901 u64 guest_physical_address:52;
902 }; 902 };
903}; 903};
904 904
diff --git a/drivers/staging/hv/hv_utils.c b/drivers/staging/hv/hv_utils.c
index a99e900ec4c9..0074581f20e8 100644
--- a/drivers/staging/hv/hv_utils.c
+++ b/drivers/staging/hv/hv_utils.c
@@ -38,12 +38,14 @@
38#include "vmbus_api.h" 38#include "vmbus_api.h"
39#include "utils.h" 39#include "utils.h"
40 40
41static u8 *shut_txf_buf;
42static u8 *time_txf_buf;
43static u8 *hbeat_txf_buf;
41 44
42static void shutdown_onchannelcallback(void *context) 45static void shutdown_onchannelcallback(void *context)
43{ 46{
44 struct vmbus_channel *channel = context; 47 struct vmbus_channel *channel = context;
45 u8 *buf; 48 u32 recvlen;
46 u32 buflen, recvlen;
47 u64 requestid; 49 u64 requestid;
48 u8 execute_shutdown = false; 50 u8 execute_shutdown = false;
49 51
@@ -52,24 +54,23 @@ static void shutdown_onchannelcallback(void *context)
52 struct icmsg_hdr *icmsghdrp; 54 struct icmsg_hdr *icmsghdrp;
53 struct icmsg_negotiate *negop = NULL; 55 struct icmsg_negotiate *negop = NULL;
54 56
55 buflen = PAGE_SIZE; 57 vmbus_recvpacket(channel, shut_txf_buf,
56 buf = kmalloc(buflen, GFP_ATOMIC); 58 PAGE_SIZE, &recvlen, &requestid);
57
58 vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid);
59 59
60 if (recvlen > 0) { 60 if (recvlen > 0) {
61 DPRINT_DBG(VMBUS, "shutdown packet: len=%d, requestid=%lld", 61 DPRINT_DBG(VMBUS, "shutdown packet: len=%d, requestid=%lld",
62 recvlen, requestid); 62 recvlen, requestid);
63 63
64 icmsghdrp = (struct icmsg_hdr *)&buf[ 64 icmsghdrp = (struct icmsg_hdr *)&shut_txf_buf[
65 sizeof(struct vmbuspipe_hdr)]; 65 sizeof(struct vmbuspipe_hdr)];
66 66
67 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { 67 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
68 prep_negotiate_resp(icmsghdrp, negop, buf); 68 prep_negotiate_resp(icmsghdrp, negop, shut_txf_buf);
69 } else { 69 } else {
70 shutdown_msg = (struct shutdown_msg_data *)&buf[ 70 shutdown_msg =
71 sizeof(struct vmbuspipe_hdr) + 71 (struct shutdown_msg_data *)&shut_txf_buf[
72 sizeof(struct icmsg_hdr)]; 72 sizeof(struct vmbuspipe_hdr) +
73 sizeof(struct icmsg_hdr)];
73 74
74 switch (shutdown_msg->flags) { 75 switch (shutdown_msg->flags) {
75 case 0: 76 case 0:
@@ -93,13 +94,11 @@ static void shutdown_onchannelcallback(void *context)
93 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION 94 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
94 | ICMSGHDRFLAG_RESPONSE; 95 | ICMSGHDRFLAG_RESPONSE;
95 96
96 vmbus_sendpacket(channel, buf, 97 vmbus_sendpacket(channel, shut_txf_buf,
97 recvlen, requestid, 98 recvlen, requestid,
98 VmbusPacketTypeDataInBand, 0); 99 VmbusPacketTypeDataInBand, 0);
99 } 100 }
100 101
101 kfree(buf);
102
103 if (execute_shutdown == true) 102 if (execute_shutdown == true)
104 orderly_poweroff(false); 103 orderly_poweroff(false);
105} 104}
@@ -150,28 +149,25 @@ static inline void adj_guesttime(u64 hosttime, u8 flags)
150static void timesync_onchannelcallback(void *context) 149static void timesync_onchannelcallback(void *context)
151{ 150{
152 struct vmbus_channel *channel = context; 151 struct vmbus_channel *channel = context;
153 u8 *buf; 152 u32 recvlen;
154 u32 buflen, recvlen;
155 u64 requestid; 153 u64 requestid;
156 struct icmsg_hdr *icmsghdrp; 154 struct icmsg_hdr *icmsghdrp;
157 struct ictimesync_data *timedatap; 155 struct ictimesync_data *timedatap;
158 156
159 buflen = PAGE_SIZE; 157 vmbus_recvpacket(channel, time_txf_buf,
160 buf = kmalloc(buflen, GFP_ATOMIC); 158 PAGE_SIZE, &recvlen, &requestid);
161
162 vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid);
163 159
164 if (recvlen > 0) { 160 if (recvlen > 0) {
165 DPRINT_DBG(VMBUS, "timesync packet: recvlen=%d, requestid=%lld", 161 DPRINT_DBG(VMBUS, "timesync packet: recvlen=%d, requestid=%lld",
166 recvlen, requestid); 162 recvlen, requestid);
167 163
168 icmsghdrp = (struct icmsg_hdr *)&buf[ 164 icmsghdrp = (struct icmsg_hdr *)&time_txf_buf[
169 sizeof(struct vmbuspipe_hdr)]; 165 sizeof(struct vmbuspipe_hdr)];
170 166
171 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { 167 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
172 prep_negotiate_resp(icmsghdrp, NULL, buf); 168 prep_negotiate_resp(icmsghdrp, NULL, time_txf_buf);
173 } else { 169 } else {
174 timedatap = (struct ictimesync_data *)&buf[ 170 timedatap = (struct ictimesync_data *)&time_txf_buf[
175 sizeof(struct vmbuspipe_hdr) + 171 sizeof(struct vmbuspipe_hdr) +
176 sizeof(struct icmsg_hdr)]; 172 sizeof(struct icmsg_hdr)];
177 adj_guesttime(timedatap->parenttime, timedatap->flags); 173 adj_guesttime(timedatap->parenttime, timedatap->flags);
@@ -180,12 +176,10 @@ static void timesync_onchannelcallback(void *context)
180 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION 176 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
181 | ICMSGHDRFLAG_RESPONSE; 177 | ICMSGHDRFLAG_RESPONSE;
182 178
183 vmbus_sendpacket(channel, buf, 179 vmbus_sendpacket(channel, time_txf_buf,
184 recvlen, requestid, 180 recvlen, requestid,
185 VmbusPacketTypeDataInBand, 0); 181 VmbusPacketTypeDataInBand, 0);
186 } 182 }
187
188 kfree(buf);
189} 183}
190 184
191/* 185/*
@@ -196,30 +190,28 @@ static void timesync_onchannelcallback(void *context)
196static void heartbeat_onchannelcallback(void *context) 190static void heartbeat_onchannelcallback(void *context)
197{ 191{
198 struct vmbus_channel *channel = context; 192 struct vmbus_channel *channel = context;
199 u8 *buf; 193 u32 recvlen;
200 u32 buflen, recvlen;
201 u64 requestid; 194 u64 requestid;
202 struct icmsg_hdr *icmsghdrp; 195 struct icmsg_hdr *icmsghdrp;
203 struct heartbeat_msg_data *heartbeat_msg; 196 struct heartbeat_msg_data *heartbeat_msg;
204 197
205 buflen = PAGE_SIZE; 198 vmbus_recvpacket(channel, hbeat_txf_buf,
206 buf = kmalloc(buflen, GFP_ATOMIC); 199 PAGE_SIZE, &recvlen, &requestid);
207
208 vmbus_recvpacket(channel, buf, buflen, &recvlen, &requestid);
209 200
210 if (recvlen > 0) { 201 if (recvlen > 0) {
211 DPRINT_DBG(VMBUS, "heartbeat packet: len=%d, requestid=%lld", 202 DPRINT_DBG(VMBUS, "heartbeat packet: len=%d, requestid=%lld",
212 recvlen, requestid); 203 recvlen, requestid);
213 204
214 icmsghdrp = (struct icmsg_hdr *)&buf[ 205 icmsghdrp = (struct icmsg_hdr *)&hbeat_txf_buf[
215 sizeof(struct vmbuspipe_hdr)]; 206 sizeof(struct vmbuspipe_hdr)];
216 207
217 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) { 208 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
218 prep_negotiate_resp(icmsghdrp, NULL, buf); 209 prep_negotiate_resp(icmsghdrp, NULL, hbeat_txf_buf);
219 } else { 210 } else {
220 heartbeat_msg = (struct heartbeat_msg_data *)&buf[ 211 heartbeat_msg =
221 sizeof(struct vmbuspipe_hdr) + 212 (struct heartbeat_msg_data *)&hbeat_txf_buf[
222 sizeof(struct icmsg_hdr)]; 213 sizeof(struct vmbuspipe_hdr) +
214 sizeof(struct icmsg_hdr)];
223 215
224 DPRINT_DBG(VMBUS, "heartbeat seq = %lld", 216 DPRINT_DBG(VMBUS, "heartbeat seq = %lld",
225 heartbeat_msg->seq_num); 217 heartbeat_msg->seq_num);
@@ -230,12 +222,10 @@ static void heartbeat_onchannelcallback(void *context)
230 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION 222 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
231 | ICMSGHDRFLAG_RESPONSE; 223 | ICMSGHDRFLAG_RESPONSE;
232 224
233 vmbus_sendpacket(channel, buf, 225 vmbus_sendpacket(channel, hbeat_txf_buf,
234 recvlen, requestid, 226 recvlen, requestid,
235 VmbusPacketTypeDataInBand, 0); 227 VmbusPacketTypeDataInBand, 0);
236 } 228 }
237
238 kfree(buf);
239} 229}
240 230
241static const struct pci_device_id __initconst 231static const struct pci_device_id __initconst
@@ -268,15 +258,28 @@ static int __init init_hyperv_utils(void)
268 if (!dmi_check_system(hv_utils_dmi_table)) 258 if (!dmi_check_system(hv_utils_dmi_table))
269 return -ENODEV; 259 return -ENODEV;
270 260
271 hv_cb_utils[HV_SHUTDOWN_MSG].channel->OnChannelCallback = 261 shut_txf_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
262 time_txf_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
263 hbeat_txf_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
264
265 if (!shut_txf_buf || !time_txf_buf || !hbeat_txf_buf) {
266 printk(KERN_INFO
267 "Unable to allocate memory for receive buffer\n");
268 kfree(shut_txf_buf);
269 kfree(time_txf_buf);
270 kfree(hbeat_txf_buf);
271 return -ENOMEM;
272 }
273
274 hv_cb_utils[HV_SHUTDOWN_MSG].channel->onchannel_callback =
272 &shutdown_onchannelcallback; 275 &shutdown_onchannelcallback;
273 hv_cb_utils[HV_SHUTDOWN_MSG].callback = &shutdown_onchannelcallback; 276 hv_cb_utils[HV_SHUTDOWN_MSG].callback = &shutdown_onchannelcallback;
274 277
275 hv_cb_utils[HV_TIMESYNC_MSG].channel->OnChannelCallback = 278 hv_cb_utils[HV_TIMESYNC_MSG].channel->onchannel_callback =
276 &timesync_onchannelcallback; 279 &timesync_onchannelcallback;
277 hv_cb_utils[HV_TIMESYNC_MSG].callback = &timesync_onchannelcallback; 280 hv_cb_utils[HV_TIMESYNC_MSG].callback = &timesync_onchannelcallback;
278 281
279 hv_cb_utils[HV_HEARTBEAT_MSG].channel->OnChannelCallback = 282 hv_cb_utils[HV_HEARTBEAT_MSG].channel->onchannel_callback =
280 &heartbeat_onchannelcallback; 283 &heartbeat_onchannelcallback;
281 hv_cb_utils[HV_HEARTBEAT_MSG].callback = &heartbeat_onchannelcallback; 284 hv_cb_utils[HV_HEARTBEAT_MSG].callback = &heartbeat_onchannelcallback;
282 285
@@ -287,17 +290,21 @@ static void exit_hyperv_utils(void)
287{ 290{
288 printk(KERN_INFO "De-Registered HyperV Utility Driver\n"); 291 printk(KERN_INFO "De-Registered HyperV Utility Driver\n");
289 292
290 hv_cb_utils[HV_SHUTDOWN_MSG].channel->OnChannelCallback = 293 hv_cb_utils[HV_SHUTDOWN_MSG].channel->onchannel_callback =
291 &chn_cb_negotiate; 294 &chn_cb_negotiate;
292 hv_cb_utils[HV_SHUTDOWN_MSG].callback = &chn_cb_negotiate; 295 hv_cb_utils[HV_SHUTDOWN_MSG].callback = &chn_cb_negotiate;
293 296
294 hv_cb_utils[HV_TIMESYNC_MSG].channel->OnChannelCallback = 297 hv_cb_utils[HV_TIMESYNC_MSG].channel->onchannel_callback =
295 &chn_cb_negotiate; 298 &chn_cb_negotiate;
296 hv_cb_utils[HV_TIMESYNC_MSG].callback = &chn_cb_negotiate; 299 hv_cb_utils[HV_TIMESYNC_MSG].callback = &chn_cb_negotiate;
297 300
298 hv_cb_utils[HV_HEARTBEAT_MSG].channel->OnChannelCallback = 301 hv_cb_utils[HV_HEARTBEAT_MSG].channel->onchannel_callback =
299 &chn_cb_negotiate; 302 &chn_cb_negotiate;
300 hv_cb_utils[HV_HEARTBEAT_MSG].callback = &chn_cb_negotiate; 303 hv_cb_utils[HV_HEARTBEAT_MSG].callback = &chn_cb_negotiate;
304
305 kfree(shut_txf_buf);
306 kfree(time_txf_buf);
307 kfree(hbeat_txf_buf);
301} 308}
302 309
303module_init(init_hyperv_utils); 310module_init(init_hyperv_utils);
diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c
index 4c2632cb19e9..df9cd131e953 100644
--- a/drivers/staging/hv/netvsc.c
+++ b/drivers/staging/hv/netvsc.c
@@ -31,147 +31,149 @@
31 31
32 32
33/* Globals */ 33/* Globals */
34static const char *gDriverName = "netvsc"; 34static const char *driver_name = "netvsc";
35 35
36/* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */ 36/* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */
37static const struct hv_guid gNetVscDeviceType = { 37static const struct hv_guid netvsc_device_type = {
38 .data = { 38 .data = {
39 0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, 39 0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,
40 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E 40 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E
41 } 41 }
42}; 42};
43 43
44static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo); 44static int netvsc_device_add(struct hv_device *device, void *additional_info);
45 45
46static int NetVscOnDeviceRemove(struct hv_device *Device); 46static int netvsc_device_remove(struct hv_device *device);
47 47
48static void NetVscOnCleanup(struct hv_driver *Driver); 48static void netvsc_cleanup(struct hv_driver *driver);
49 49
50static void NetVscOnChannelCallback(void *context); 50static void netvsc_channel_cb(void *context);
51 51
52static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device); 52static int netvsc_init_send_buf(struct hv_device *device);
53 53
54static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device); 54static int netvsc_init_recv_buf(struct hv_device *device);
55 55
56static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice); 56static int netvsc_destroy_send_buf(struct netvsc_device *net_device);
57 57
58static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice); 58static int netvsc_destroy_recv_buf(struct netvsc_device *net_device);
59 59
60static int NetVscConnectToVsp(struct hv_device *Device); 60static int netvsc_connect_vsp(struct hv_device *device);
61 61
62static void NetVscOnSendCompletion(struct hv_device *Device, 62static void netvsc_send_completion(struct hv_device *device,
63 struct vmpacket_descriptor *Packet); 63 struct vmpacket_descriptor *packet);
64 64
65static int NetVscOnSend(struct hv_device *Device, 65static int netvsc_send(struct hv_device *device,
66 struct hv_netvsc_packet *Packet); 66 struct hv_netvsc_packet *packet);
67 67
68static void NetVscOnReceive(struct hv_device *Device, 68static void netvsc_receive(struct hv_device *device,
69 struct vmpacket_descriptor *Packet); 69 struct vmpacket_descriptor *packet);
70 70
71static void NetVscOnReceiveCompletion(void *Context); 71static void netvsc_receive_completion(void *context);
72 72
73static void NetVscSendReceiveCompletion(struct hv_device *Device, 73static void netvsc_send_recv_completion(struct hv_device *device,
74 u64 TransactionId); 74 u64 transaction_id);
75 75
76 76
77static struct netvsc_device *AllocNetDevice(struct hv_device *Device) 77static struct netvsc_device *alloc_net_device(struct hv_device *device)
78{ 78{
79 struct netvsc_device *netDevice; 79 struct netvsc_device *net_device;
80 80
81 netDevice = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL); 81 net_device = kzalloc(sizeof(struct netvsc_device), GFP_KERNEL);
82 if (!netDevice) 82 if (!net_device)
83 return NULL; 83 return NULL;
84 84
85 /* Set to 2 to allow both inbound and outbound traffic */ 85 /* Set to 2 to allow both inbound and outbound traffic */
86 atomic_cmpxchg(&netDevice->RefCount, 0, 2); 86 atomic_cmpxchg(&net_device->refcnt, 0, 2);
87 87
88 netDevice->Device = Device; 88 net_device->dev = device;
89 Device->Extension = netDevice; 89 device->Extension = net_device;
90 90
91 return netDevice; 91 return net_device;
92} 92}
93 93
94static void FreeNetDevice(struct netvsc_device *Device) 94static void free_net_device(struct netvsc_device *device)
95{ 95{
96 WARN_ON(atomic_read(&Device->RefCount) == 0); 96 WARN_ON(atomic_read(&device->refcnt) == 0);
97 Device->Device->Extension = NULL; 97 device->dev->Extension = NULL;
98 kfree(Device); 98 kfree(device);
99} 99}
100 100
101 101
102/* Get the net device object iff exists and its refcount > 1 */ 102/* Get the net device object iff exists and its refcount > 1 */
103static struct netvsc_device *GetOutboundNetDevice(struct hv_device *Device) 103static struct netvsc_device *get_outbound_net_device(struct hv_device *device)
104{ 104{
105 struct netvsc_device *netDevice; 105 struct netvsc_device *net_device;
106 106
107 netDevice = Device->Extension; 107 net_device = device->Extension;
108 if (netDevice && atomic_read(&netDevice->RefCount) > 1) 108 if (net_device && atomic_read(&net_device->refcnt) > 1)
109 atomic_inc(&netDevice->RefCount); 109 atomic_inc(&net_device->refcnt);
110 else 110 else
111 netDevice = NULL; 111 net_device = NULL;
112 112
113 return netDevice; 113 return net_device;
114} 114}
115 115
116/* Get the net device object iff exists and its refcount > 0 */ 116/* Get the net device object iff exists and its refcount > 0 */
117static struct netvsc_device *GetInboundNetDevice(struct hv_device *Device) 117static struct netvsc_device *get_inbound_net_device(struct hv_device *device)
118{ 118{
119 struct netvsc_device *netDevice; 119 struct netvsc_device *net_device;
120 120
121 netDevice = Device->Extension; 121 net_device = device->Extension;
122 if (netDevice && atomic_read(&netDevice->RefCount)) 122 if (net_device && atomic_read(&net_device->refcnt))
123 atomic_inc(&netDevice->RefCount); 123 atomic_inc(&net_device->refcnt);
124 else 124 else
125 netDevice = NULL; 125 net_device = NULL;
126 126
127 return netDevice; 127 return net_device;
128} 128}
129 129
130static void PutNetDevice(struct hv_device *Device) 130static void put_net_device(struct hv_device *device)
131{ 131{
132 struct netvsc_device *netDevice; 132 struct netvsc_device *net_device;
133 133
134 netDevice = Device->Extension; 134 net_device = device->Extension;
135 /* ASSERT(netDevice); */ 135 /* ASSERT(netDevice); */
136 136
137 atomic_dec(&netDevice->RefCount); 137 atomic_dec(&net_device->refcnt);
138} 138}
139 139
140static struct netvsc_device *ReleaseOutboundNetDevice(struct hv_device *Device) 140static struct netvsc_device *release_outbound_net_device(
141 struct hv_device *device)
141{ 142{
142 struct netvsc_device *netDevice; 143 struct netvsc_device *net_device;
143 144
144 netDevice = Device->Extension; 145 net_device = device->Extension;
145 if (netDevice == NULL) 146 if (net_device == NULL)
146 return NULL; 147 return NULL;
147 148
148 /* Busy wait until the ref drop to 2, then set it to 1 */ 149 /* Busy wait until the ref drop to 2, then set it to 1 */
149 while (atomic_cmpxchg(&netDevice->RefCount, 2, 1) != 2) 150 while (atomic_cmpxchg(&net_device->refcnt, 2, 1) != 2)
150 udelay(100); 151 udelay(100);
151 152
152 return netDevice; 153 return net_device;
153} 154}
154 155
155static struct netvsc_device *ReleaseInboundNetDevice(struct hv_device *Device) 156static struct netvsc_device *release_inbound_net_device(
157 struct hv_device *device)
156{ 158{
157 struct netvsc_device *netDevice; 159 struct netvsc_device *net_device;
158 160
159 netDevice = Device->Extension; 161 net_device = device->Extension;
160 if (netDevice == NULL) 162 if (net_device == NULL)
161 return NULL; 163 return NULL;
162 164
163 /* Busy wait until the ref drop to 1, then set it to 0 */ 165 /* Busy wait until the ref drop to 1, then set it to 0 */
164 while (atomic_cmpxchg(&netDevice->RefCount, 1, 0) != 1) 166 while (atomic_cmpxchg(&net_device->refcnt, 1, 0) != 1)
165 udelay(100); 167 udelay(100);
166 168
167 Device->Extension = NULL; 169 device->Extension = NULL;
168 return netDevice; 170 return net_device;
169} 171}
170 172
171/* 173/*
172 * NetVscInitialize - Main entry point 174 * netvsc_initialize - Main entry point
173 */ 175 */
174int NetVscInitialize(struct hv_driver *drv) 176int netvsc_initialize(struct hv_driver *drv)
175{ 177{
176 struct netvsc_driver *driver = (struct netvsc_driver *)drv; 178 struct netvsc_driver *driver = (struct netvsc_driver *)drv;
177 179
@@ -185,8 +187,8 @@ int NetVscInitialize(struct hv_driver *drv)
185 /* Make sure we are at least 2 pages since 1 page is used for control */ 187 /* Make sure we are at least 2 pages since 1 page is used for control */
186 /* ASSERT(driver->RingBufferSize >= (PAGE_SIZE << 1)); */ 188 /* ASSERT(driver->RingBufferSize >= (PAGE_SIZE << 1)); */
187 189
188 drv->name = gDriverName; 190 drv->name = driver_name;
189 memcpy(&drv->deviceType, &gNetVscDeviceType, sizeof(struct hv_guid)); 191 memcpy(&drv->deviceType, &netvsc_device_type, sizeof(struct hv_guid));
190 192
191 /* Make sure it is set by the caller */ 193 /* Make sure it is set by the caller */
192 /* FIXME: These probably should still be tested in some way */ 194 /* FIXME: These probably should still be tested in some way */
@@ -194,24 +196,24 @@ int NetVscInitialize(struct hv_driver *drv)
194 /* ASSERT(driver->OnLinkStatusChanged); */ 196 /* ASSERT(driver->OnLinkStatusChanged); */
195 197
196 /* Setup the dispatch table */ 198 /* Setup the dispatch table */
197 driver->Base.OnDeviceAdd = NetVscOnDeviceAdd; 199 driver->base.OnDeviceAdd = netvsc_device_add;
198 driver->Base.OnDeviceRemove = NetVscOnDeviceRemove; 200 driver->base.OnDeviceRemove = netvsc_device_remove;
199 driver->Base.OnCleanup = NetVscOnCleanup; 201 driver->base.OnCleanup = netvsc_cleanup;
200 202
201 driver->OnSend = NetVscOnSend; 203 driver->send = netvsc_send;
202 204
203 RndisFilterInit(driver); 205 rndis_filter_init(driver);
204 return 0; 206 return 0;
205} 207}
206 208
207static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) 209static int netvsc_init_recv_buf(struct hv_device *device)
208{ 210{
209 int ret = 0; 211 int ret = 0;
210 struct netvsc_device *netDevice; 212 struct netvsc_device *net_device;
211 struct nvsp_message *initPacket; 213 struct nvsp_message *init_packet;
212 214
213 netDevice = GetOutboundNetDevice(Device); 215 net_device = get_outbound_net_device(device);
214 if (!netDevice) { 216 if (!net_device) {
215 DPRINT_ERR(NETVSC, "unable to get net device..." 217 DPRINT_ERR(NETVSC, "unable to get net device..."
216 "device being destroyed?"); 218 "device being destroyed?");
217 return -1; 219 return -1;
@@ -220,12 +222,12 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device)
220 /* page-size grandularity */ 222 /* page-size grandularity */
221 /* ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE - 1)) == 0); */ 223 /* ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE - 1)) == 0); */
222 224
223 netDevice->ReceiveBuffer = 225 net_device->recv_buf =
224 osd_PageAlloc(netDevice->ReceiveBufferSize >> PAGE_SHIFT); 226 osd_page_alloc(net_device->recv_buf_size >> PAGE_SHIFT);
225 if (!netDevice->ReceiveBuffer) { 227 if (!net_device->recv_buf) {
226 DPRINT_ERR(NETVSC, 228 DPRINT_ERR(NETVSC,
227 "unable to allocate receive buffer of size %d", 229 "unable to allocate receive buffer of size %d",
228 netDevice->ReceiveBufferSize); 230 net_device->recv_buf_size);
229 ret = -1; 231 ret = -1;
230 goto Cleanup; 232 goto Cleanup;
231 } 233 }
@@ -240,32 +242,34 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device)
240 * channel. Note: This call uses the vmbus connection rather 242 * channel. Note: This call uses the vmbus connection rather
241 * than the channel to establish the gpadl handle. 243 * than the channel to establish the gpadl handle.
242 */ 244 */
243 ret = vmbus_establish_gpadl(Device->channel, netDevice->ReceiveBuffer, 245 ret = vmbus_establish_gpadl(device->channel, net_device->recv_buf,
244 netDevice->ReceiveBufferSize, 246 net_device->recv_buf_size,
245 &netDevice->ReceiveBufferGpadlHandle); 247 &net_device->recv_buf_gpadl_handle);
246 if (ret != 0) { 248 if (ret != 0) {
247 DPRINT_ERR(NETVSC, 249 DPRINT_ERR(NETVSC,
248 "unable to establish receive buffer's gpadl"); 250 "unable to establish receive buffer's gpadl");
249 goto Cleanup; 251 goto Cleanup;
250 } 252 }
251 253
252 /* osd_WaitEventWait(ext->ChannelInitEvent); */ 254 /* osd_waitevent_wait(ext->ChannelInitEvent); */
253 255
254 /* Notify the NetVsp of the gpadl handle */ 256 /* Notify the NetVsp of the gpadl handle */
255 DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendReceiveBuffer..."); 257 DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendReceiveBuffer...");
256 258
257 initPacket = &netDevice->ChannelInitPacket; 259 init_packet = &net_device->channel_init_pkt;
258 260
259 memset(initPacket, 0, sizeof(struct nvsp_message)); 261 memset(init_packet, 0, sizeof(struct nvsp_message));
260 262
261 initPacket->Header.MessageType = NvspMessage1TypeSendReceiveBuffer; 263 init_packet->hdr.msg_type = NVSP_MSG1_TYPE_SEND_RECV_BUF;
262 initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->ReceiveBufferGpadlHandle; 264 init_packet->msg.v1_msg.send_recv_buf.
263 initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID; 265 gpadl_handle = net_device->recv_buf_gpadl_handle;
266 init_packet->msg.v1_msg.
267 send_recv_buf.id = NETVSC_RECEIVE_BUFFER_ID;
264 268
265 /* Send the gpadl notification request */ 269 /* Send the gpadl notification request */
266 ret = vmbus_sendpacket(Device->channel, initPacket, 270 ret = vmbus_sendpacket(device->channel, init_packet,
267 sizeof(struct nvsp_message), 271 sizeof(struct nvsp_message),
268 (unsigned long)initPacket, 272 (unsigned long)init_packet,
269 VmbusPacketTypeDataInBand, 273 VmbusPacketTypeDataInBand,
270 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); 274 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
271 if (ret != 0) { 275 if (ret != 0) {
@@ -274,13 +278,15 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device)
274 goto Cleanup; 278 goto Cleanup;
275 } 279 }
276 280
277 osd_WaitEventWait(netDevice->ChannelInitEvent); 281 osd_waitevent_wait(net_device->channel_init_event);
278 282
279 /* Check the response */ 283 /* Check the response */
280 if (initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status != NvspStatusSuccess) { 284 if (init_packet->msg.v1_msg.
285 send_recv_buf_complete.status != NVSP_STAT_SUCCESS) {
281 DPRINT_ERR(NETVSC, "Unable to complete receive buffer " 286 DPRINT_ERR(NETVSC, "Unable to complete receive buffer "
282 "initialzation with NetVsp - status %d", 287 "initialzation with NetVsp - status %d",
283 initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status); 288 init_packet->msg.v1_msg.
289 send_recv_buf_complete.status);
284 ret = -1; 290 ret = -1;
285 goto Cleanup; 291 goto Cleanup;
286 } 292 }
@@ -289,32 +295,36 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device)
289 /* ASSERT(netDevice->ReceiveSectionCount == 0); */ 295 /* ASSERT(netDevice->ReceiveSectionCount == 0); */
290 /* ASSERT(netDevice->ReceiveSections == NULL); */ 296 /* ASSERT(netDevice->ReceiveSections == NULL); */
291 297
292 netDevice->ReceiveSectionCount = initPacket->Messages.Version1Messages.SendReceiveBufferComplete.NumSections; 298 net_device->recv_section_cnt = init_packet->msg.
299 v1_msg.send_recv_buf_complete.num_sections;
293 300
294 netDevice->ReceiveSections = kmalloc(netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL); 301 net_device->recv_section = kmalloc(net_device->recv_section_cnt
295 if (netDevice->ReceiveSections == NULL) { 302 * sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL);
303 if (net_device->recv_section == NULL) {
296 ret = -1; 304 ret = -1;
297 goto Cleanup; 305 goto Cleanup;
298 } 306 }
299 307
300 memcpy(netDevice->ReceiveSections, 308 memcpy(net_device->recv_section,
301 initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Sections, 309 init_packet->msg.v1_msg.
302 netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section)); 310 send_recv_buf_complete.sections,
311 net_device->recv_section_cnt *
312 sizeof(struct nvsp_1_receive_buffer_section));
303 313
304 DPRINT_INFO(NETVSC, "Receive sections info (count %d, offset %d, " 314 DPRINT_INFO(NETVSC, "Receive sections info (count %d, offset %d, "
305 "endoffset %d, suballoc size %d, num suballocs %d)", 315 "endoffset %d, suballoc size %d, num suballocs %d)",
306 netDevice->ReceiveSectionCount, 316 net_device->recv_section_cnt,
307 netDevice->ReceiveSections[0].Offset, 317 net_device->recv_section[0].offset,
308 netDevice->ReceiveSections[0].EndOffset, 318 net_device->recv_section[0].end_offset,
309 netDevice->ReceiveSections[0].SubAllocationSize, 319 net_device->recv_section[0].sub_alloc_size,
310 netDevice->ReceiveSections[0].NumSubAllocations); 320 net_device->recv_section[0].num_sub_allocs);
311 321
312 /* 322 /*
313 * For 1st release, there should only be 1 section that represents the 323 * For 1st release, there should only be 1 section that represents the
314 * entire receive buffer 324 * entire receive buffer
315 */ 325 */
316 if (netDevice->ReceiveSectionCount != 1 || 326 if (net_device->recv_section_cnt != 1 ||
317 netDevice->ReceiveSections->Offset != 0) { 327 net_device->recv_section->offset != 0) {
318 ret = -1; 328 ret = -1;
319 goto Cleanup; 329 goto Cleanup;
320 } 330 }
@@ -322,26 +332,26 @@ static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device)
322 goto Exit; 332 goto Exit;
323 333
324Cleanup: 334Cleanup:
325 NetVscDestroyReceiveBuffer(netDevice); 335 netvsc_destroy_recv_buf(net_device);
326 336
327Exit: 337Exit:
328 PutNetDevice(Device); 338 put_net_device(device);
329 return ret; 339 return ret;
330} 340}
331 341
332static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device) 342static int netvsc_init_send_buf(struct hv_device *device)
333{ 343{
334 int ret = 0; 344 int ret = 0;
335 struct netvsc_device *netDevice; 345 struct netvsc_device *net_device;
336 struct nvsp_message *initPacket; 346 struct nvsp_message *init_packet;
337 347
338 netDevice = GetOutboundNetDevice(Device); 348 net_device = get_outbound_net_device(device);
339 if (!netDevice) { 349 if (!net_device) {
340 DPRINT_ERR(NETVSC, "unable to get net device..." 350 DPRINT_ERR(NETVSC, "unable to get net device..."
341 "device being destroyed?"); 351 "device being destroyed?");
342 return -1; 352 return -1;
343 } 353 }
344 if (netDevice->SendBufferSize <= 0) { 354 if (net_device->send_buf_size <= 0) {
345 ret = -EINVAL; 355 ret = -EINVAL;
346 goto Cleanup; 356 goto Cleanup;
347 } 357 }
@@ -349,11 +359,11 @@ static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device)
349 /* page-size grandularity */ 359 /* page-size grandularity */
350 /* ASSERT((netDevice->SendBufferSize & (PAGE_SIZE - 1)) == 0); */ 360 /* ASSERT((netDevice->SendBufferSize & (PAGE_SIZE - 1)) == 0); */
351 361
352 netDevice->SendBuffer = 362 net_device->send_buf =
353 osd_PageAlloc(netDevice->SendBufferSize >> PAGE_SHIFT); 363 osd_page_alloc(net_device->send_buf_size >> PAGE_SHIFT);
354 if (!netDevice->SendBuffer) { 364 if (!net_device->send_buf) {
355 DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d", 365 DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d",
356 netDevice->SendBufferSize); 366 net_device->send_buf_size);
357 ret = -1; 367 ret = -1;
358 goto Cleanup; 368 goto Cleanup;
359 } 369 }
@@ -367,31 +377,33 @@ static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device)
367 * channel. Note: This call uses the vmbus connection rather 377 * channel. Note: This call uses the vmbus connection rather
368 * than the channel to establish the gpadl handle. 378 * than the channel to establish the gpadl handle.
369 */ 379 */
370 ret = vmbus_establish_gpadl(Device->channel, netDevice->SendBuffer, 380 ret = vmbus_establish_gpadl(device->channel, net_device->send_buf,
371 netDevice->SendBufferSize, 381 net_device->send_buf_size,
372 &netDevice->SendBufferGpadlHandle); 382 &net_device->send_buf_gpadl_handle);
373 if (ret != 0) { 383 if (ret != 0) {
374 DPRINT_ERR(NETVSC, "unable to establish send buffer's gpadl"); 384 DPRINT_ERR(NETVSC, "unable to establish send buffer's gpadl");
375 goto Cleanup; 385 goto Cleanup;
376 } 386 }
377 387
378 /* osd_WaitEventWait(ext->ChannelInitEvent); */ 388 /* osd_waitevent_wait(ext->ChannelInitEvent); */
379 389
380 /* Notify the NetVsp of the gpadl handle */ 390 /* Notify the NetVsp of the gpadl handle */
381 DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendSendBuffer..."); 391 DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendSendBuffer...");
382 392
383 initPacket = &netDevice->ChannelInitPacket; 393 init_packet = &net_device->channel_init_pkt;
384 394
385 memset(initPacket, 0, sizeof(struct nvsp_message)); 395 memset(init_packet, 0, sizeof(struct nvsp_message));
386 396
387 initPacket->Header.MessageType = NvspMessage1TypeSendSendBuffer; 397 init_packet->hdr.msg_type = NVSP_MSG1_TYPE_SEND_SEND_BUF;
388 initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->SendBufferGpadlHandle; 398 init_packet->msg.v1_msg.send_recv_buf.
389 initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_SEND_BUFFER_ID; 399 gpadl_handle = net_device->send_buf_gpadl_handle;
400 init_packet->msg.v1_msg.send_recv_buf.id =
401 NETVSC_SEND_BUFFER_ID;
390 402
391 /* Send the gpadl notification request */ 403 /* Send the gpadl notification request */
392 ret = vmbus_sendpacket(Device->channel, initPacket, 404 ret = vmbus_sendpacket(device->channel, init_packet,
393 sizeof(struct nvsp_message), 405 sizeof(struct nvsp_message),
394 (unsigned long)initPacket, 406 (unsigned long)init_packet,
395 VmbusPacketTypeDataInBand, 407 VmbusPacketTypeDataInBand,
396 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); 408 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
397 if (ret != 0) { 409 if (ret != 0) {
@@ -400,32 +412,35 @@ static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device)
400 goto Cleanup; 412 goto Cleanup;
401 } 413 }
402 414
403 osd_WaitEventWait(netDevice->ChannelInitEvent); 415 osd_waitevent_wait(net_device->channel_init_event);
404 416
405 /* Check the response */ 417 /* Check the response */
406 if (initPacket->Messages.Version1Messages.SendSendBufferComplete.Status != NvspStatusSuccess) { 418 if (init_packet->msg.v1_msg.
419 send_send_buf_complete.status != NVSP_STAT_SUCCESS) {
407 DPRINT_ERR(NETVSC, "Unable to complete send buffer " 420 DPRINT_ERR(NETVSC, "Unable to complete send buffer "
408 "initialzation with NetVsp - status %d", 421 "initialzation with NetVsp - status %d",
409 initPacket->Messages.Version1Messages.SendSendBufferComplete.Status); 422 init_packet->msg.v1_msg.
423 send_send_buf_complete.status);
410 ret = -1; 424 ret = -1;
411 goto Cleanup; 425 goto Cleanup;
412 } 426 }
413 427
414 netDevice->SendSectionSize = initPacket->Messages.Version1Messages.SendSendBufferComplete.SectionSize; 428 net_device->send_section_size = init_packet->
429 msg.v1_msg.send_send_buf_complete.section_size;
415 430
416 goto Exit; 431 goto Exit;
417 432
418Cleanup: 433Cleanup:
419 NetVscDestroySendBuffer(netDevice); 434 netvsc_destroy_send_buf(net_device);
420 435
421Exit: 436Exit:
422 PutNetDevice(Device); 437 put_net_device(device);
423 return ret; 438 return ret;
424} 439}
425 440
426static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice) 441static int netvsc_destroy_recv_buf(struct netvsc_device *net_device)
427{ 442{
428 struct nvsp_message *revokePacket; 443 struct nvsp_message *revoke_packet;
429 int ret = 0; 444 int ret = 0;
430 445
431 /* 446 /*
@@ -434,20 +449,23 @@ static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice)
434 * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need 449 * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need
435 * to send a revoke msg here 450 * to send a revoke msg here
436 */ 451 */
437 if (NetDevice->ReceiveSectionCount) { 452 if (net_device->recv_section_cnt) {
438 DPRINT_INFO(NETVSC, 453 DPRINT_INFO(NETVSC,
439 "Sending NvspMessage1TypeRevokeReceiveBuffer..."); 454 "Sending NvspMessage1TypeRevokeReceiveBuffer...");
440 455
441 /* Send the revoke receive buffer */ 456 /* Send the revoke receive buffer */
442 revokePacket = &NetDevice->RevokePacket; 457 revoke_packet = &net_device->revoke_packet;
443 memset(revokePacket, 0, sizeof(struct nvsp_message)); 458 memset(revoke_packet, 0, sizeof(struct nvsp_message));
444 459
445 revokePacket->Header.MessageType = NvspMessage1TypeRevokeReceiveBuffer; 460 revoke_packet->hdr.msg_type =
446 revokePacket->Messages.Version1Messages.RevokeReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID; 461 NVSP_MSG1_TYPE_REVOKE_RECV_BUF;
462 revoke_packet->msg.v1_msg.
463 revoke_recv_buf.id = NETVSC_RECEIVE_BUFFER_ID;
447 464
448 ret = vmbus_sendpacket(NetDevice->Device->channel, revokePacket, 465 ret = vmbus_sendpacket(net_device->dev->channel,
466 revoke_packet,
449 sizeof(struct nvsp_message), 467 sizeof(struct nvsp_message),
450 (unsigned long)revokePacket, 468 (unsigned long)revoke_packet,
451 VmbusPacketTypeDataInBand, 0); 469 VmbusPacketTypeDataInBand, 0);
452 /* 470 /*
453 * If we failed here, we might as well return and 471 * If we failed here, we might as well return and
@@ -461,11 +479,11 @@ static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice)
461 } 479 }
462 480
463 /* Teardown the gpadl on the vsp end */ 481 /* Teardown the gpadl on the vsp end */
464 if (NetDevice->ReceiveBufferGpadlHandle) { 482 if (net_device->recv_buf_gpadl_handle) {
465 DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL..."); 483 DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL...");
466 484
467 ret = vmbus_teardown_gpadl(NetDevice->Device->channel, 485 ret = vmbus_teardown_gpadl(net_device->dev->channel,
468 NetDevice->ReceiveBufferGpadlHandle); 486 net_device->recv_buf_gpadl_handle);
469 487
470 /* If we failed here, we might as well return and have a leak rather than continue and a bugchk */ 488 /* If we failed here, we might as well return and have a leak rather than continue and a bugchk */
471 if (ret != 0) { 489 if (ret != 0) {
@@ -473,30 +491,30 @@ static int NetVscDestroyReceiveBuffer(struct netvsc_device *NetDevice)
473 "unable to teardown receive buffer's gpadl"); 491 "unable to teardown receive buffer's gpadl");
474 return -1; 492 return -1;
475 } 493 }
476 NetDevice->ReceiveBufferGpadlHandle = 0; 494 net_device->recv_buf_gpadl_handle = 0;
477 } 495 }
478 496
479 if (NetDevice->ReceiveBuffer) { 497 if (net_device->recv_buf) {
480 DPRINT_INFO(NETVSC, "Freeing up receive buffer..."); 498 DPRINT_INFO(NETVSC, "Freeing up receive buffer...");
481 499
482 /* Free up the receive buffer */ 500 /* Free up the receive buffer */
483 osd_PageFree(NetDevice->ReceiveBuffer, 501 osd_page_free(net_device->recv_buf,
484 NetDevice->ReceiveBufferSize >> PAGE_SHIFT); 502 net_device->recv_buf_size >> PAGE_SHIFT);
485 NetDevice->ReceiveBuffer = NULL; 503 net_device->recv_buf = NULL;
486 } 504 }
487 505
488 if (NetDevice->ReceiveSections) { 506 if (net_device->recv_section) {
489 NetDevice->ReceiveSectionCount = 0; 507 net_device->recv_section_cnt = 0;
490 kfree(NetDevice->ReceiveSections); 508 kfree(net_device->recv_section);
491 NetDevice->ReceiveSections = NULL; 509 net_device->recv_section = NULL;
492 } 510 }
493 511
494 return ret; 512 return ret;
495} 513}
496 514
497static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice) 515static int netvsc_destroy_send_buf(struct netvsc_device *net_device)
498{ 516{
499 struct nvsp_message *revokePacket; 517 struct nvsp_message *revoke_packet;
500 int ret = 0; 518 int ret = 0;
501 519
502 /* 520 /*
@@ -505,20 +523,23 @@ static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice)
505 * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need 523 * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need
506 * to send a revoke msg here 524 * to send a revoke msg here
507 */ 525 */
508 if (NetDevice->SendSectionSize) { 526 if (net_device->send_section_size) {
509 DPRINT_INFO(NETVSC, 527 DPRINT_INFO(NETVSC,
510 "Sending NvspMessage1TypeRevokeSendBuffer..."); 528 "Sending NvspMessage1TypeRevokeSendBuffer...");
511 529
512 /* Send the revoke send buffer */ 530 /* Send the revoke send buffer */
513 revokePacket = &NetDevice->RevokePacket; 531 revoke_packet = &net_device->revoke_packet;
514 memset(revokePacket, 0, sizeof(struct nvsp_message)); 532 memset(revoke_packet, 0, sizeof(struct nvsp_message));
515 533
516 revokePacket->Header.MessageType = NvspMessage1TypeRevokeSendBuffer; 534 revoke_packet->hdr.msg_type =
517 revokePacket->Messages.Version1Messages.RevokeSendBuffer.Id = NETVSC_SEND_BUFFER_ID; 535 NVSP_MSG1_TYPE_REVOKE_SEND_BUF;
536 revoke_packet->msg.v1_msg.
537 revoke_send_buf.id = NETVSC_SEND_BUFFER_ID;
518 538
519 ret = vmbus_sendpacket(NetDevice->Device->channel, revokePacket, 539 ret = vmbus_sendpacket(net_device->dev->channel,
540 revoke_packet,
520 sizeof(struct nvsp_message), 541 sizeof(struct nvsp_message),
521 (unsigned long)revokePacket, 542 (unsigned long)revoke_packet,
522 VmbusPacketTypeDataInBand, 0); 543 VmbusPacketTypeDataInBand, 0);
523 /* 544 /*
524 * If we failed here, we might as well return and have a leak 545 * If we failed here, we might as well return and have a leak
@@ -532,10 +553,10 @@ static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice)
532 } 553 }
533 554
534 /* Teardown the gpadl on the vsp end */ 555 /* Teardown the gpadl on the vsp end */
535 if (NetDevice->SendBufferGpadlHandle) { 556 if (net_device->send_buf_gpadl_handle) {
536 DPRINT_INFO(NETVSC, "Tearing down send buffer's GPADL..."); 557 DPRINT_INFO(NETVSC, "Tearing down send buffer's GPADL...");
537 ret = vmbus_teardown_gpadl(NetDevice->Device->channel, 558 ret = vmbus_teardown_gpadl(net_device->dev->channel,
538 NetDevice->SendBufferGpadlHandle); 559 net_device->send_buf_gpadl_handle);
539 560
540 /* 561 /*
541 * If we failed here, we might as well return and have a leak 562 * If we failed here, we might as well return and have a leak
@@ -546,49 +567,51 @@ static int NetVscDestroySendBuffer(struct netvsc_device *NetDevice)
546 "gpadl"); 567 "gpadl");
547 return -1; 568 return -1;
548 } 569 }
549 NetDevice->SendBufferGpadlHandle = 0; 570 net_device->send_buf_gpadl_handle = 0;
550 } 571 }
551 572
552 if (NetDevice->SendBuffer) { 573 if (net_device->send_buf) {
553 DPRINT_INFO(NETVSC, "Freeing up send buffer..."); 574 DPRINT_INFO(NETVSC, "Freeing up send buffer...");
554 575
555 /* Free up the receive buffer */ 576 /* Free up the receive buffer */
556 osd_PageFree(NetDevice->SendBuffer, 577 osd_page_free(net_device->send_buf,
557 NetDevice->SendBufferSize >> PAGE_SHIFT); 578 net_device->send_buf_size >> PAGE_SHIFT);
558 NetDevice->SendBuffer = NULL; 579 net_device->send_buf = NULL;
559 } 580 }
560 581
561 return ret; 582 return ret;
562} 583}
563 584
564 585
565static int NetVscConnectToVsp(struct hv_device *Device) 586static int netvsc_connect_vsp(struct hv_device *device)
566{ 587{
567 int ret; 588 int ret;
568 struct netvsc_device *netDevice; 589 struct netvsc_device *net_device;
569 struct nvsp_message *initPacket; 590 struct nvsp_message *init_packet;
570 int ndisVersion; 591 int ndis_version;
571 592
572 netDevice = GetOutboundNetDevice(Device); 593 net_device = get_outbound_net_device(device);
573 if (!netDevice) { 594 if (!net_device) {
574 DPRINT_ERR(NETVSC, "unable to get net device..." 595 DPRINT_ERR(NETVSC, "unable to get net device..."
575 "device being destroyed?"); 596 "device being destroyed?");
576 return -1; 597 return -1;
577 } 598 }
578 599
579 initPacket = &netDevice->ChannelInitPacket; 600 init_packet = &net_device->channel_init_pkt;
580 601
581 memset(initPacket, 0, sizeof(struct nvsp_message)); 602 memset(init_packet, 0, sizeof(struct nvsp_message));
582 initPacket->Header.MessageType = NvspMessageTypeInit; 603 init_packet->hdr.msg_type = NVSP_MSG_TYPE_INIT;
583 initPacket->Messages.InitMessages.Init.MinProtocolVersion = NVSP_MIN_PROTOCOL_VERSION; 604 init_packet->msg.init_msg.init.min_protocol_ver =
584 initPacket->Messages.InitMessages.Init.MaxProtocolVersion = NVSP_MAX_PROTOCOL_VERSION; 605 NVSP_MIN_PROTOCOL_VERSION;
606 init_packet->msg.init_msg.init.max_protocol_ver =
607 NVSP_MAX_PROTOCOL_VERSION;
585 608
586 DPRINT_INFO(NETVSC, "Sending NvspMessageTypeInit..."); 609 DPRINT_INFO(NETVSC, "Sending NvspMessageTypeInit...");
587 610
588 /* Send the init request */ 611 /* Send the init request */
589 ret = vmbus_sendpacket(Device->channel, initPacket, 612 ret = vmbus_sendpacket(device->channel, init_packet,
590 sizeof(struct nvsp_message), 613 sizeof(struct nvsp_message),
591 (unsigned long)initPacket, 614 (unsigned long)init_packet,
592 VmbusPacketTypeDataInBand, 615 VmbusPacketTypeDataInBand,
593 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); 616 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
594 617
@@ -597,47 +620,52 @@ static int NetVscConnectToVsp(struct hv_device *Device)
597 goto Cleanup; 620 goto Cleanup;
598 } 621 }
599 622
600 osd_WaitEventWait(netDevice->ChannelInitEvent); 623 osd_waitevent_wait(net_device->channel_init_event);
601 624
602 /* Now, check the response */ 625 /* Now, check the response */
603 /* ASSERT(initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength <= MAX_MULTIPAGE_BUFFER_COUNT); */ 626 /* ASSERT(initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength <= MAX_MULTIPAGE_BUFFER_COUNT); */
604 DPRINT_INFO(NETVSC, "NvspMessageTypeInit status(%d) max mdl chain (%d)", 627 DPRINT_INFO(NETVSC, "NvspMessageTypeInit status(%d) max mdl chain (%d)",
605 initPacket->Messages.InitMessages.InitComplete.Status, 628 init_packet->msg.init_msg.init_complete.status,
606 initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength); 629 init_packet->msg.init_msg.
630 init_complete.max_mdl_chain_len);
607 631
608 if (initPacket->Messages.InitMessages.InitComplete.Status != 632 if (init_packet->msg.init_msg.init_complete.status !=
609 NvspStatusSuccess) { 633 NVSP_STAT_SUCCESS) {
610 DPRINT_ERR(NETVSC, 634 DPRINT_ERR(NETVSC,
611 "unable to initialize with netvsp (status 0x%x)", 635 "unable to initialize with netvsp (status 0x%x)",
612 initPacket->Messages.InitMessages.InitComplete.Status); 636 init_packet->msg.init_msg.init_complete.status);
613 ret = -1; 637 ret = -1;
614 goto Cleanup; 638 goto Cleanup;
615 } 639 }
616 640
617 if (initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion != NVSP_PROTOCOL_VERSION_1) { 641 if (init_packet->msg.init_msg.init_complete.
642 negotiated_protocol_ver != NVSP_PROTOCOL_VERSION_1) {
618 DPRINT_ERR(NETVSC, "unable to initialize with netvsp " 643 DPRINT_ERR(NETVSC, "unable to initialize with netvsp "
619 "(version expected 1 got %d)", 644 "(version expected 1 got %d)",
620 initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion); 645 init_packet->msg.init_msg.
646 init_complete.negotiated_protocol_ver);
621 ret = -1; 647 ret = -1;
622 goto Cleanup; 648 goto Cleanup;
623 } 649 }
624 DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendNdisVersion..."); 650 DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendNdisVersion...");
625 651
626 /* Send the ndis version */ 652 /* Send the ndis version */
627 memset(initPacket, 0, sizeof(struct nvsp_message)); 653 memset(init_packet, 0, sizeof(struct nvsp_message));
628 654
629 ndisVersion = 0x00050000; 655 ndis_version = 0x00050000;
630 656
631 initPacket->Header.MessageType = NvspMessage1TypeSendNdisVersion; 657 init_packet->hdr.msg_type = NVSP_MSG1_TYPE_SEND_NDIS_VER;
632 initPacket->Messages.Version1Messages.SendNdisVersion.NdisMajorVersion = 658 init_packet->msg.v1_msg.
633 (ndisVersion & 0xFFFF0000) >> 16; 659 send_ndis_ver.ndis_major_ver =
634 initPacket->Messages.Version1Messages.SendNdisVersion.NdisMinorVersion = 660 (ndis_version & 0xFFFF0000) >> 16;
635 ndisVersion & 0xFFFF; 661 init_packet->msg.v1_msg.
662 send_ndis_ver.ndis_minor_ver =
663 ndis_version & 0xFFFF;
636 664
637 /* Send the init request */ 665 /* Send the init request */
638 ret = vmbus_sendpacket(Device->channel, initPacket, 666 ret = vmbus_sendpacket(device->channel, init_packet,
639 sizeof(struct nvsp_message), 667 sizeof(struct nvsp_message),
640 (unsigned long)initPacket, 668 (unsigned long)init_packet,
641 VmbusPacketTypeDataInBand, 0); 669 VmbusPacketTypeDataInBand, 0);
642 if (ret != 0) { 670 if (ret != 0) {
643 DPRINT_ERR(NETVSC, 671 DPRINT_ERR(NETVSC,
@@ -651,51 +679,52 @@ static int NetVscConnectToVsp(struct hv_device *Device)
651 * packet) since our Vmbus always set the 679 * packet) since our Vmbus always set the
652 * VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag 680 * VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag
653 */ 681 */
654 /* osd_WaitEventWait(NetVscChannel->ChannelInitEvent); */ 682 /* osd_waitevent_wait(NetVscChannel->ChannelInitEvent); */
655 683
656 /* Post the big receive buffer to NetVSP */ 684 /* Post the big receive buffer to NetVSP */
657 ret = NetVscInitializeReceiveBufferWithNetVsp(Device); 685 ret = netvsc_init_recv_buf(device);
658 if (ret == 0) 686 if (ret == 0)
659 ret = NetVscInitializeSendBufferWithNetVsp(Device); 687 ret = netvsc_init_send_buf(device);
660 688
661Cleanup: 689Cleanup:
662 PutNetDevice(Device); 690 put_net_device(device);
663 return ret; 691 return ret;
664} 692}
665 693
666static void NetVscDisconnectFromVsp(struct netvsc_device *NetDevice) 694static void NetVscDisconnectFromVsp(struct netvsc_device *net_device)
667{ 695{
668 NetVscDestroyReceiveBuffer(NetDevice); 696 netvsc_destroy_recv_buf(net_device);
669 NetVscDestroySendBuffer(NetDevice); 697 netvsc_destroy_send_buf(net_device);
670} 698}
671 699
672/* 700/*
673 * NetVscOnDeviceAdd - Callback when the device belonging to this driver is added 701 * netvsc_device_add - Callback when the device belonging to this
702 * driver is added
674 */ 703 */
675static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) 704static int netvsc_device_add(struct hv_device *device, void *additional_info)
676{ 705{
677 int ret = 0; 706 int ret = 0;
678 int i; 707 int i;
679 struct netvsc_device *netDevice; 708 struct netvsc_device *net_device;
680 struct hv_netvsc_packet *packet, *pos; 709 struct hv_netvsc_packet *packet, *pos;
681 struct netvsc_driver *netDriver = 710 struct netvsc_driver *net_driver =
682 (struct netvsc_driver *)Device->Driver; 711 (struct netvsc_driver *)device->Driver;
683 712
684 netDevice = AllocNetDevice(Device); 713 net_device = alloc_net_device(device);
685 if (!netDevice) { 714 if (!net_device) {
686 ret = -1; 715 ret = -1;
687 goto Cleanup; 716 goto Cleanup;
688 } 717 }
689 718
690 DPRINT_DBG(NETVSC, "netvsc channel object allocated - %p", netDevice); 719 DPRINT_DBG(NETVSC, "netvsc channel object allocated - %p", net_device);
691 720
692 /* Initialize the NetVSC channel extension */ 721 /* Initialize the NetVSC channel extension */
693 netDevice->ReceiveBufferSize = NETVSC_RECEIVE_BUFFER_SIZE; 722 net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE;
694 spin_lock_init(&netDevice->receive_packet_list_lock); 723 spin_lock_init(&net_device->recv_pkt_list_lock);
695 724
696 netDevice->SendBufferSize = NETVSC_SEND_BUFFER_SIZE; 725 net_device->send_buf_size = NETVSC_SEND_BUFFER_SIZE;
697 726
698 INIT_LIST_HEAD(&netDevice->ReceivePacketList); 727 INIT_LIST_HEAD(&net_device->recv_pkt_list);
699 728
700 for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) { 729 for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) {
701 packet = kzalloc(sizeof(struct hv_netvsc_packet) + 730 packet = kzalloc(sizeof(struct hv_netvsc_packet) +
@@ -707,19 +736,19 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
707 NETVSC_RECEIVE_PACKETLIST_COUNT, i); 736 NETVSC_RECEIVE_PACKETLIST_COUNT, i);
708 break; 737 break;
709 } 738 }
710 list_add_tail(&packet->ListEntry, 739 list_add_tail(&packet->list_ent,
711 &netDevice->ReceivePacketList); 740 &net_device->recv_pkt_list);
712 } 741 }
713 netDevice->ChannelInitEvent = osd_WaitEventCreate(); 742 net_device->channel_init_event = osd_waitevent_create();
714 if (!netDevice->ChannelInitEvent) { 743 if (!net_device->channel_init_event) {
715 ret = -ENOMEM; 744 ret = -ENOMEM;
716 goto Cleanup; 745 goto Cleanup;
717 } 746 }
718 747
719 /* Open the channel */ 748 /* Open the channel */
720 ret = vmbus_open(Device->channel, netDriver->RingBufferSize, 749 ret = vmbus_open(device->channel, net_driver->ring_buf_size,
721 netDriver->RingBufferSize, NULL, 0, 750 net_driver->ring_buf_size, NULL, 0,
722 NetVscOnChannelCallback, Device); 751 netvsc_channel_cb, device);
723 752
724 if (ret != 0) { 753 if (ret != 0) {
725 DPRINT_ERR(NETVSC, "unable to open channel: %d", ret); 754 DPRINT_ERR(NETVSC, "unable to open channel: %d", ret);
@@ -731,7 +760,7 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
731 DPRINT_INFO(NETVSC, "*** NetVSC channel opened successfully! ***"); 760 DPRINT_INFO(NETVSC, "*** NetVSC channel opened successfully! ***");
732 761
733 /* Connect with the NetVsp */ 762 /* Connect with the NetVsp */
734 ret = NetVscConnectToVsp(Device); 763 ret = netvsc_connect_vsp(device);
735 if (ret != 0) { 764 if (ret != 0) {
736 DPRINT_ERR(NETVSC, "unable to connect to NetVSP - %d", ret); 765 DPRINT_ERR(NETVSC, "unable to connect to NetVSP - %d", ret);
737 ret = -1; 766 ret = -1;
@@ -745,174 +774,178 @@ static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
745 774
746close: 775close:
747 /* Now, we can close the channel safely */ 776 /* Now, we can close the channel safely */
748 vmbus_close(Device->channel); 777 vmbus_close(device->channel);
749 778
750Cleanup: 779Cleanup:
751 780
752 if (netDevice) { 781 if (net_device) {
753 kfree(netDevice->ChannelInitEvent); 782 kfree(net_device->channel_init_event);
754 783
755 list_for_each_entry_safe(packet, pos, 784 list_for_each_entry_safe(packet, pos,
756 &netDevice->ReceivePacketList, 785 &net_device->recv_pkt_list,
757 ListEntry) { 786 list_ent) {
758 list_del(&packet->ListEntry); 787 list_del(&packet->list_ent);
759 kfree(packet); 788 kfree(packet);
760 } 789 }
761 790
762 ReleaseOutboundNetDevice(Device); 791 release_outbound_net_device(device);
763 ReleaseInboundNetDevice(Device); 792 release_inbound_net_device(device);
764 793
765 FreeNetDevice(netDevice); 794 free_net_device(net_device);
766 } 795 }
767 796
768 return ret; 797 return ret;
769} 798}
770 799
771/* 800/*
772 * NetVscOnDeviceRemove - Callback when the root bus device is removed 801 * netvsc_device_remove - Callback when the root bus device is removed
773 */ 802 */
774static int NetVscOnDeviceRemove(struct hv_device *Device) 803static int netvsc_device_remove(struct hv_device *device)
775{ 804{
776 struct netvsc_device *netDevice; 805 struct netvsc_device *net_device;
777 struct hv_netvsc_packet *netvscPacket, *pos; 806 struct hv_netvsc_packet *netvsc_packet, *pos;
778 807
779 DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...", 808 DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...",
780 Device->Extension); 809 device->Extension);
781 810
782 /* Stop outbound traffic ie sends and receives completions */ 811 /* Stop outbound traffic ie sends and receives completions */
783 netDevice = ReleaseOutboundNetDevice(Device); 812 net_device = release_outbound_net_device(device);
784 if (!netDevice) { 813 if (!net_device) {
785 DPRINT_ERR(NETVSC, "No net device present!!"); 814 DPRINT_ERR(NETVSC, "No net device present!!");
786 return -1; 815 return -1;
787 } 816 }
788 817
789 /* Wait for all send completions */ 818 /* Wait for all send completions */
790 while (atomic_read(&netDevice->NumOutstandingSends)) { 819 while (atomic_read(&net_device->num_outstanding_sends)) {
791 DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", 820 DPRINT_INFO(NETVSC, "waiting for %d requests to complete...",
792 atomic_read(&netDevice->NumOutstandingSends)); 821 atomic_read(&net_device->num_outstanding_sends));
793 udelay(100); 822 udelay(100);
794 } 823 }
795 824
796 DPRINT_INFO(NETVSC, "Disconnecting from netvsp..."); 825 DPRINT_INFO(NETVSC, "Disconnecting from netvsp...");
797 826
798 NetVscDisconnectFromVsp(netDevice); 827 NetVscDisconnectFromVsp(net_device);
799 828
800 DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...", 829 DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...",
801 Device->Extension); 830 device->Extension);
802 831
803 /* Stop inbound traffic ie receives and sends completions */ 832 /* Stop inbound traffic ie receives and sends completions */
804 netDevice = ReleaseInboundNetDevice(Device); 833 net_device = release_inbound_net_device(device);
805 834
806 /* At this point, no one should be accessing netDevice except in here */ 835 /* At this point, no one should be accessing netDevice except in here */
807 DPRINT_INFO(NETVSC, "net device (%p) safe to remove", netDevice); 836 DPRINT_INFO(NETVSC, "net device (%p) safe to remove", net_device);
808 837
809 /* Now, we can close the channel safely */ 838 /* Now, we can close the channel safely */
810 vmbus_close(Device->channel); 839 vmbus_close(device->channel);
811 840
812 /* Release all resources */ 841 /* Release all resources */
813 list_for_each_entry_safe(netvscPacket, pos, 842 list_for_each_entry_safe(netvsc_packet, pos,
814 &netDevice->ReceivePacketList, ListEntry) { 843 &net_device->recv_pkt_list, list_ent) {
815 list_del(&netvscPacket->ListEntry); 844 list_del(&netvsc_packet->list_ent);
816 kfree(netvscPacket); 845 kfree(netvsc_packet);
817 } 846 }
818 847
819 kfree(netDevice->ChannelInitEvent); 848 kfree(net_device->channel_init_event);
820 FreeNetDevice(netDevice); 849 free_net_device(net_device);
821 return 0; 850 return 0;
822} 851}
823 852
824/* 853/*
825 * NetVscOnCleanup - Perform any cleanup when the driver is removed 854 * netvsc_cleanup - Perform any cleanup when the driver is removed
826 */ 855 */
827static void NetVscOnCleanup(struct hv_driver *drv) 856static void netvsc_cleanup(struct hv_driver *drv)
828{ 857{
829} 858}
830 859
831static void NetVscOnSendCompletion(struct hv_device *Device, 860static void netvsc_send_completion(struct hv_device *device,
832 struct vmpacket_descriptor *Packet) 861 struct vmpacket_descriptor *packet)
833{ 862{
834 struct netvsc_device *netDevice; 863 struct netvsc_device *net_device;
835 struct nvsp_message *nvspPacket; 864 struct nvsp_message *nvsp_packet;
836 struct hv_netvsc_packet *nvscPacket; 865 struct hv_netvsc_packet *nvsc_packet;
837 866
838 netDevice = GetInboundNetDevice(Device); 867 net_device = get_inbound_net_device(device);
839 if (!netDevice) { 868 if (!net_device) {
840 DPRINT_ERR(NETVSC, "unable to get net device..." 869 DPRINT_ERR(NETVSC, "unable to get net device..."
841 "device being destroyed?"); 870 "device being destroyed?");
842 return; 871 return;
843 } 872 }
844 873
845 nvspPacket = (struct nvsp_message *)((unsigned long)Packet + (Packet->DataOffset8 << 3)); 874 nvsp_packet = (struct nvsp_message *)((unsigned long)packet +
875 (packet->DataOffset8 << 3));
846 876
847 DPRINT_DBG(NETVSC, "send completion packet - type %d", 877 DPRINT_DBG(NETVSC, "send completion packet - type %d",
848 nvspPacket->Header.MessageType); 878 nvsp_packet->hdr.msg_type);
849 879
850 if ((nvspPacket->Header.MessageType == NvspMessageTypeInitComplete) || 880 if ((nvsp_packet->hdr.msg_type == NVSP_MSG_TYPE_INIT_COMPLETE) ||
851 (nvspPacket->Header.MessageType == 881 (nvsp_packet->hdr.msg_type ==
852 NvspMessage1TypeSendReceiveBufferComplete) || 882 NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE) ||
853 (nvspPacket->Header.MessageType == 883 (nvsp_packet->hdr.msg_type ==
854 NvspMessage1TypeSendSendBufferComplete)) { 884 NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE)) {
855 /* Copy the response back */ 885 /* Copy the response back */
856 memcpy(&netDevice->ChannelInitPacket, nvspPacket, 886 memcpy(&net_device->channel_init_pkt, nvsp_packet,
857 sizeof(struct nvsp_message)); 887 sizeof(struct nvsp_message));
858 osd_WaitEventSet(netDevice->ChannelInitEvent); 888 osd_waitevent_set(net_device->channel_init_event);
859 } else if (nvspPacket->Header.MessageType == 889 } else if (nvsp_packet->hdr.msg_type ==
860 NvspMessage1TypeSendRNDISPacketComplete) { 890 NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE) {
861 /* Get the send context */ 891 /* Get the send context */
862 nvscPacket = (struct hv_netvsc_packet *)(unsigned long)Packet->TransactionId; 892 nvsc_packet = (struct hv_netvsc_packet *)(unsigned long)
893 packet->TransactionId;
863 /* ASSERT(nvscPacket); */ 894 /* ASSERT(nvscPacket); */
864 895
865 /* Notify the layer above us */ 896 /* Notify the layer above us */
866 nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext); 897 nvsc_packet->completion.send.send_completion(
898 nvsc_packet->completion.send.send_completion_ctx);
867 899
868 atomic_dec(&netDevice->NumOutstandingSends); 900 atomic_dec(&net_device->num_outstanding_sends);
869 } else { 901 } else {
870 DPRINT_ERR(NETVSC, "Unknown send completion packet type - " 902 DPRINT_ERR(NETVSC, "Unknown send completion packet type - "
871 "%d received!!", nvspPacket->Header.MessageType); 903 "%d received!!", nvsp_packet->hdr.msg_type);
872 } 904 }
873 905
874 PutNetDevice(Device); 906 put_net_device(device);
875} 907}
876 908
877static int NetVscOnSend(struct hv_device *Device, 909static int netvsc_send(struct hv_device *device,
878 struct hv_netvsc_packet *Packet) 910 struct hv_netvsc_packet *packet)
879{ 911{
880 struct netvsc_device *netDevice; 912 struct netvsc_device *net_device;
881 int ret = 0; 913 int ret = 0;
882 914
883 struct nvsp_message sendMessage; 915 struct nvsp_message sendMessage;
884 916
885 netDevice = GetOutboundNetDevice(Device); 917 net_device = get_outbound_net_device(device);
886 if (!netDevice) { 918 if (!net_device) {
887 DPRINT_ERR(NETVSC, "net device (%p) shutting down..." 919 DPRINT_ERR(NETVSC, "net device (%p) shutting down..."
888 "ignoring outbound packets", netDevice); 920 "ignoring outbound packets", net_device);
889 return -2; 921 return -2;
890 } 922 }
891 923
892 sendMessage.Header.MessageType = NvspMessage1TypeSendRNDISPacket; 924 sendMessage.hdr.msg_type = NVSP_MSG1_TYPE_SEND_RNDIS_PKT;
893 if (Packet->IsDataPacket) { 925 if (packet->is_data_pkt) {
894 /* 0 is RMC_DATA; */ 926 /* 0 is RMC_DATA; */
895 sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 0; 927 sendMessage.msg.v1_msg.send_rndis_pkt.channel_type = 0;
896 } else { 928 } else {
897 /* 1 is RMC_CONTROL; */ 929 /* 1 is RMC_CONTROL; */
898 sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 1; 930 sendMessage.msg.v1_msg.send_rndis_pkt.channel_type = 1;
899 } 931 }
900 932
901 /* Not using send buffer section */ 933 /* Not using send buffer section */
902 sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionIndex = 0xFFFFFFFF; 934 sendMessage.msg.v1_msg.send_rndis_pkt.send_buf_section_index =
903 sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionSize = 0; 935 0xFFFFFFFF;
904 936 sendMessage.msg.v1_msg.send_rndis_pkt.send_buf_section_size = 0;
905 if (Packet->PageBufferCount) { 937
906 ret = vmbus_sendpacket_pagebuffer(Device->channel, 938 if (packet->page_buf_cnt) {
907 Packet->PageBuffers, 939 ret = vmbus_sendpacket_pagebuffer(device->channel,
908 Packet->PageBufferCount, 940 packet->page_buf,
941 packet->page_buf_cnt,
909 &sendMessage, 942 &sendMessage,
910 sizeof(struct nvsp_message), 943 sizeof(struct nvsp_message),
911 (unsigned long)Packet); 944 (unsigned long)packet);
912 } else { 945 } else {
913 ret = vmbus_sendpacket(Device->channel, &sendMessage, 946 ret = vmbus_sendpacket(device->channel, &sendMessage,
914 sizeof(struct nvsp_message), 947 sizeof(struct nvsp_message),
915 (unsigned long)Packet, 948 (unsigned long)packet,
916 VmbusPacketTypeDataInBand, 949 VmbusPacketTypeDataInBand,
917 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); 950 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
918 951
@@ -920,31 +953,31 @@ static int NetVscOnSend(struct hv_device *Device,
920 953
921 if (ret != 0) 954 if (ret != 0)
922 DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", 955 DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d",
923 Packet, ret); 956 packet, ret);
924 957
925 atomic_inc(&netDevice->NumOutstandingSends); 958 atomic_inc(&net_device->num_outstanding_sends);
926 PutNetDevice(Device); 959 put_net_device(device);
927 return ret; 960 return ret;
928} 961}
929 962
930static void NetVscOnReceive(struct hv_device *Device, 963static void netvsc_receive(struct hv_device *device,
931 struct vmpacket_descriptor *Packet) 964 struct vmpacket_descriptor *packet)
932{ 965{
933 struct netvsc_device *netDevice; 966 struct netvsc_device *net_device;
934 struct vmtransfer_page_packet_header *vmxferpagePacket; 967 struct vmtransfer_page_packet_header *vmxferpage_packet;
935 struct nvsp_message *nvspPacket; 968 struct nvsp_message *nvsp_packet;
936 struct hv_netvsc_packet *netvscPacket = NULL; 969 struct hv_netvsc_packet *netvsc_packet = NULL;
937 unsigned long start; 970 unsigned long start;
938 unsigned long end, endVirtual; 971 unsigned long end, end_virtual;
939 /* struct netvsc_driver *netvscDriver; */ 972 /* struct netvsc_driver *netvscDriver; */
940 struct xferpage_packet *xferpagePacket = NULL; 973 struct xferpage_packet *xferpage_packet = NULL;
941 int i, j; 974 int i, j;
942 int count = 0, bytesRemain = 0; 975 int count = 0, bytes_remain = 0;
943 unsigned long flags; 976 unsigned long flags;
944 LIST_HEAD(listHead); 977 LIST_HEAD(listHead);
945 978
946 netDevice = GetInboundNetDevice(Device); 979 net_device = get_inbound_net_device(device);
947 if (!netDevice) { 980 if (!net_device) {
948 DPRINT_ERR(NETVSC, "unable to get net device..." 981 DPRINT_ERR(NETVSC, "unable to get net device..."
949 "device being destroyed?"); 982 "device being destroyed?");
950 return; 983 return;
@@ -954,39 +987,40 @@ static void NetVscOnReceive(struct hv_device *Device,
954 * All inbound packets other than send completion should be xfer page 987 * All inbound packets other than send completion should be xfer page
955 * packet 988 * packet
956 */ 989 */
957 if (Packet->Type != VmbusPacketTypeDataUsingTransferPages) { 990 if (packet->Type != VmbusPacketTypeDataUsingTransferPages) {
958 DPRINT_ERR(NETVSC, "Unknown packet type received - %d", 991 DPRINT_ERR(NETVSC, "Unknown packet type received - %d",
959 Packet->Type); 992 packet->Type);
960 PutNetDevice(Device); 993 put_net_device(device);
961 return; 994 return;
962 } 995 }
963 996
964 nvspPacket = (struct nvsp_message *)((unsigned long)Packet + 997 nvsp_packet = (struct nvsp_message *)((unsigned long)packet +
965 (Packet->DataOffset8 << 3)); 998 (packet->DataOffset8 << 3));
966 999
967 /* Make sure this is a valid nvsp packet */ 1000 /* Make sure this is a valid nvsp packet */
968 if (nvspPacket->Header.MessageType != NvspMessage1TypeSendRNDISPacket) { 1001 if (nvsp_packet->hdr.msg_type !=
1002 NVSP_MSG1_TYPE_SEND_RNDIS_PKT) {
969 DPRINT_ERR(NETVSC, "Unknown nvsp packet type received - %d", 1003 DPRINT_ERR(NETVSC, "Unknown nvsp packet type received - %d",
970 nvspPacket->Header.MessageType); 1004 nvsp_packet->hdr.msg_type);
971 PutNetDevice(Device); 1005 put_net_device(device);
972 return; 1006 return;
973 } 1007 }
974 1008
975 DPRINT_DBG(NETVSC, "NVSP packet received - type %d", 1009 DPRINT_DBG(NETVSC, "NVSP packet received - type %d",
976 nvspPacket->Header.MessageType); 1010 nvsp_packet->hdr.msg_type);
977 1011
978 vmxferpagePacket = (struct vmtransfer_page_packet_header *)Packet; 1012 vmxferpage_packet = (struct vmtransfer_page_packet_header *)packet;
979 1013
980 if (vmxferpagePacket->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID) { 1014 if (vmxferpage_packet->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID) {
981 DPRINT_ERR(NETVSC, "Invalid xfer page set id - " 1015 DPRINT_ERR(NETVSC, "Invalid xfer page set id - "
982 "expecting %x got %x", NETVSC_RECEIVE_BUFFER_ID, 1016 "expecting %x got %x", NETVSC_RECEIVE_BUFFER_ID,
983 vmxferpagePacket->TransferPageSetId); 1017 vmxferpage_packet->TransferPageSetId);
984 PutNetDevice(Device); 1018 put_net_device(device);
985 return; 1019 return;
986 } 1020 }
987 1021
988 DPRINT_DBG(NETVSC, "xfer page - range count %d", 1022 DPRINT_DBG(NETVSC, "xfer page - range count %d",
989 vmxferpagePacket->RangeCount); 1023 vmxferpage_packet->RangeCount);
990 1024
991 /* 1025 /*
992 * Grab free packets (range count + 1) to represent this xfer 1026 * Grab free packets (range count + 1) to represent this xfer
@@ -994,13 +1028,13 @@ static void NetVscOnReceive(struct hv_device *Device,
994 * We grab it here so that we know exactly how many we can 1028 * We grab it here so that we know exactly how many we can
995 * fulfil 1029 * fulfil
996 */ 1030 */
997 spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); 1031 spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags);
998 while (!list_empty(&netDevice->ReceivePacketList)) { 1032 while (!list_empty(&net_device->recv_pkt_list)) {
999 list_move_tail(netDevice->ReceivePacketList.next, &listHead); 1033 list_move_tail(net_device->recv_pkt_list.next, &listHead);
1000 if (++count == vmxferpagePacket->RangeCount + 1) 1034 if (++count == vmxferpage_packet->RangeCount + 1)
1001 break; 1035 break;
1002 } 1036 }
1003 spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags); 1037 spin_unlock_irqrestore(&net_device->recv_pkt_list_lock, flags);
1004 1038
1005 /* 1039 /*
1006 * We need at least 2 netvsc pkts (1 to represent the xfer 1040 * We need at least 2 netvsc pkts (1 to represent the xfer
@@ -1010,140 +1044,149 @@ static void NetVscOnReceive(struct hv_device *Device,
1010 if (count < 2) { 1044 if (count < 2) {
1011 DPRINT_ERR(NETVSC, "Got only %d netvsc pkt...needed %d pkts. " 1045 DPRINT_ERR(NETVSC, "Got only %d netvsc pkt...needed %d pkts. "
1012 "Dropping this xfer page packet completely!", 1046 "Dropping this xfer page packet completely!",
1013 count, vmxferpagePacket->RangeCount + 1); 1047 count, vmxferpage_packet->RangeCount + 1);
1014 1048
1015 /* Return it to the freelist */ 1049 /* Return it to the freelist */
1016 spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); 1050 spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags);
1017 for (i = count; i != 0; i--) { 1051 for (i = count; i != 0; i--) {
1018 list_move_tail(listHead.next, 1052 list_move_tail(listHead.next,
1019 &netDevice->ReceivePacketList); 1053 &net_device->recv_pkt_list);
1020 } 1054 }
1021 spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, 1055 spin_unlock_irqrestore(&net_device->recv_pkt_list_lock,
1022 flags); 1056 flags);
1023 1057
1024 NetVscSendReceiveCompletion(Device, 1058 netvsc_send_recv_completion(device,
1025 vmxferpagePacket->d.TransactionId); 1059 vmxferpage_packet->d.TransactionId);
1026 1060
1027 PutNetDevice(Device); 1061 put_net_device(device);
1028 return; 1062 return;
1029 } 1063 }
1030 1064
1031 /* Remove the 1st packet to represent the xfer page packet itself */ 1065 /* Remove the 1st packet to represent the xfer page packet itself */
1032 xferpagePacket = (struct xferpage_packet *)listHead.next; 1066 xferpage_packet = (struct xferpage_packet *)listHead.next;
1033 list_del(&xferpagePacket->ListEntry); 1067 list_del(&xferpage_packet->list_ent);
1034 1068
1035 /* This is how much we can satisfy */ 1069 /* This is how much we can satisfy */
1036 xferpagePacket->Count = count - 1; 1070 xferpage_packet->count = count - 1;
1037 /* ASSERT(xferpagePacket->Count > 0 && xferpagePacket->Count <= */ 1071 /* ASSERT(xferpagePacket->Count > 0 && xferpagePacket->Count <= */
1038 /* vmxferpagePacket->RangeCount); */ 1072 /* vmxferpagePacket->RangeCount); */
1039 1073
1040 if (xferpagePacket->Count != vmxferpagePacket->RangeCount) { 1074 if (xferpage_packet->count != vmxferpage_packet->RangeCount) {
1041 DPRINT_INFO(NETVSC, "Needed %d netvsc pkts to satisy this xfer " 1075 DPRINT_INFO(NETVSC, "Needed %d netvsc pkts to satisy this xfer "
1042 "page...got %d", vmxferpagePacket->RangeCount, 1076 "page...got %d", vmxferpage_packet->RangeCount,
1043 xferpagePacket->Count); 1077 xferpage_packet->count);
1044 } 1078 }
1045 1079
1046 /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */ 1080 /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */
1047 for (i = 0; i < (count - 1); i++) { 1081 for (i = 0; i < (count - 1); i++) {
1048 netvscPacket = (struct hv_netvsc_packet *)listHead.next; 1082 netvsc_packet = (struct hv_netvsc_packet *)listHead.next;
1049 list_del(&netvscPacket->ListEntry); 1083 list_del(&netvsc_packet->list_ent);
1050 1084
1051 /* Initialize the netvsc packet */ 1085 /* Initialize the netvsc packet */
1052 netvscPacket->XferPagePacket = xferpagePacket; 1086 netvsc_packet->xfer_page_pkt = xferpage_packet;
1053 netvscPacket->Completion.Recv.OnReceiveCompletion = 1087 netvsc_packet->completion.recv.recv_completion =
1054 NetVscOnReceiveCompletion; 1088 netvsc_receive_completion;
1055 netvscPacket->Completion.Recv.ReceiveCompletionContext = 1089 netvsc_packet->completion.recv.recv_completion_ctx =
1056 netvscPacket; 1090 netvsc_packet;
1057 netvscPacket->Device = Device; 1091 netvsc_packet->device = device;
1058 /* Save this so that we can send it back */ 1092 /* Save this so that we can send it back */
1059 netvscPacket->Completion.Recv.ReceiveCompletionTid = 1093 netvsc_packet->completion.recv.recv_completion_tid =
1060 vmxferpagePacket->d.TransactionId; 1094 vmxferpage_packet->d.TransactionId;
1061 1095
1062 netvscPacket->TotalDataBufferLength = 1096 netvsc_packet->total_data_buflen =
1063 vmxferpagePacket->Ranges[i].ByteCount; 1097 vmxferpage_packet->Ranges[i].ByteCount;
1064 netvscPacket->PageBufferCount = 1; 1098 netvsc_packet->page_buf_cnt = 1;
1065 1099
1066 /* ASSERT(vmxferpagePacket->Ranges[i].ByteOffset + */ 1100 /* ASSERT(vmxferpagePacket->Ranges[i].ByteOffset + */
1067 /* vmxferpagePacket->Ranges[i].ByteCount < */ 1101 /* vmxferpagePacket->Ranges[i].ByteCount < */
1068 /* netDevice->ReceiveBufferSize); */ 1102 /* netDevice->ReceiveBufferSize); */
1069 1103
1070 netvscPacket->PageBuffers[0].Length = 1104 netvsc_packet->page_buf[0].Length =
1071 vmxferpagePacket->Ranges[i].ByteCount; 1105 vmxferpage_packet->Ranges[i].ByteCount;
1072 1106
1073 start = virt_to_phys((void *)((unsigned long)netDevice->ReceiveBuffer + vmxferpagePacket->Ranges[i].ByteOffset)); 1107 start = virt_to_phys((void *)((unsigned long)net_device->
1108 recv_buf + vmxferpage_packet->Ranges[i].ByteOffset));
1074 1109
1075 netvscPacket->PageBuffers[0].Pfn = start >> PAGE_SHIFT; 1110 netvsc_packet->page_buf[0].Pfn = start >> PAGE_SHIFT;
1076 endVirtual = (unsigned long)netDevice->ReceiveBuffer 1111 end_virtual = (unsigned long)net_device->recv_buf
1077 + vmxferpagePacket->Ranges[i].ByteOffset 1112 + vmxferpage_packet->Ranges[i].ByteOffset
1078 + vmxferpagePacket->Ranges[i].ByteCount - 1; 1113 + vmxferpage_packet->Ranges[i].ByteCount - 1;
1079 end = virt_to_phys((void *)endVirtual); 1114 end = virt_to_phys((void *)end_virtual);
1080 1115
1081 /* Calculate the page relative offset */ 1116 /* Calculate the page relative offset */
1082 netvscPacket->PageBuffers[0].Offset = 1117 netvsc_packet->page_buf[0].Offset =
1083 vmxferpagePacket->Ranges[i].ByteOffset & (PAGE_SIZE - 1); 1118 vmxferpage_packet->Ranges[i].ByteOffset &
1119 (PAGE_SIZE - 1);
1084 if ((end >> PAGE_SHIFT) != (start >> PAGE_SHIFT)) { 1120 if ((end >> PAGE_SHIFT) != (start >> PAGE_SHIFT)) {
1085 /* Handle frame across multiple pages: */ 1121 /* Handle frame across multiple pages: */
1086 netvscPacket->PageBuffers[0].Length = 1122 netvsc_packet->page_buf[0].Length =
1087 (netvscPacket->PageBuffers[0].Pfn << PAGE_SHIFT) 1123 (netvsc_packet->page_buf[0].Pfn <<
1124 PAGE_SHIFT)
1088 + PAGE_SIZE - start; 1125 + PAGE_SIZE - start;
1089 bytesRemain = netvscPacket->TotalDataBufferLength - 1126 bytes_remain = netvsc_packet->total_data_buflen -
1090 netvscPacket->PageBuffers[0].Length; 1127 netvsc_packet->page_buf[0].Length;
1091 for (j = 1; j < NETVSC_PACKET_MAXPAGE; j++) { 1128 for (j = 1; j < NETVSC_PACKET_MAXPAGE; j++) {
1092 netvscPacket->PageBuffers[j].Offset = 0; 1129 netvsc_packet->page_buf[j].Offset = 0;
1093 if (bytesRemain <= PAGE_SIZE) { 1130 if (bytes_remain <= PAGE_SIZE) {
1094 netvscPacket->PageBuffers[j].Length = bytesRemain; 1131 netvsc_packet->page_buf[j].Length =
1095 bytesRemain = 0; 1132 bytes_remain;
1133 bytes_remain = 0;
1096 } else { 1134 } else {
1097 netvscPacket->PageBuffers[j].Length = PAGE_SIZE; 1135 netvsc_packet->page_buf[j].Length =
1098 bytesRemain -= PAGE_SIZE; 1136 PAGE_SIZE;
1137 bytes_remain -= PAGE_SIZE;
1099 } 1138 }
1100 netvscPacket->PageBuffers[j].Pfn = 1139 netvsc_packet->page_buf[j].Pfn =
1101 virt_to_phys((void *)(endVirtual - bytesRemain)) >> PAGE_SHIFT; 1140 virt_to_phys((void *)(end_virtual -
1102 netvscPacket->PageBufferCount++; 1141 bytes_remain)) >> PAGE_SHIFT;
1103 if (bytesRemain == 0) 1142 netvsc_packet->page_buf_cnt++;
1143 if (bytes_remain == 0)
1104 break; 1144 break;
1105 } 1145 }
1106 /* ASSERT(bytesRemain == 0); */ 1146 /* ASSERT(bytesRemain == 0); */
1107 } 1147 }
1108 DPRINT_DBG(NETVSC, "[%d] - (abs offset %u len %u) => " 1148 DPRINT_DBG(NETVSC, "[%d] - (abs offset %u len %u) => "
1109 "(pfn %llx, offset %u, len %u)", i, 1149 "(pfn %llx, offset %u, len %u)", i,
1110 vmxferpagePacket->Ranges[i].ByteOffset, 1150 vmxferpage_packet->Ranges[i].ByteOffset,
1111 vmxferpagePacket->Ranges[i].ByteCount, 1151 vmxferpage_packet->Ranges[i].ByteCount,
1112 netvscPacket->PageBuffers[0].Pfn, 1152 netvsc_packet->page_buf[0].Pfn,
1113 netvscPacket->PageBuffers[0].Offset, 1153 netvsc_packet->page_buf[0].Offset,
1114 netvscPacket->PageBuffers[0].Length); 1154 netvsc_packet->page_buf[0].Length);
1115 1155
1116 /* Pass it to the upper layer */ 1156 /* Pass it to the upper layer */
1117 ((struct netvsc_driver *)Device->Driver)->OnReceiveCallback(Device, netvscPacket); 1157 ((struct netvsc_driver *)device->Driver)->
1158 recv_cb(device, netvsc_packet);
1118 1159
1119 NetVscOnReceiveCompletion(netvscPacket->Completion.Recv.ReceiveCompletionContext); 1160 netvsc_receive_completion(netvsc_packet->
1161 completion.recv.recv_completion_ctx);
1120 } 1162 }
1121 1163
1122 /* ASSERT(list_empty(&listHead)); */ 1164 /* ASSERT(list_empty(&listHead)); */
1123 1165
1124 PutNetDevice(Device); 1166 put_net_device(device);
1125} 1167}
1126 1168
1127static void NetVscSendReceiveCompletion(struct hv_device *Device, 1169static void netvsc_send_recv_completion(struct hv_device *device,
1128 u64 TransactionId) 1170 u64 transaction_id)
1129{ 1171{
1130 struct nvsp_message recvcompMessage; 1172 struct nvsp_message recvcompMessage;
1131 int retries = 0; 1173 int retries = 0;
1132 int ret; 1174 int ret;
1133 1175
1134 DPRINT_DBG(NETVSC, "Sending receive completion pkt - %llx", 1176 DPRINT_DBG(NETVSC, "Sending receive completion pkt - %llx",
1135 TransactionId); 1177 transaction_id);
1136 1178
1137 recvcompMessage.Header.MessageType = 1179 recvcompMessage.hdr.msg_type =
1138 NvspMessage1TypeSendRNDISPacketComplete; 1180 NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE;
1139 1181
1140 /* FIXME: Pass in the status */ 1182 /* FIXME: Pass in the status */
1141 recvcompMessage.Messages.Version1Messages.SendRNDISPacketComplete.Status = NvspStatusSuccess; 1183 recvcompMessage.msg.v1_msg.send_rndis_pkt_complete.status =
1184 NVSP_STAT_SUCCESS;
1142 1185
1143retry_send_cmplt: 1186retry_send_cmplt:
1144 /* Send the completion */ 1187 /* Send the completion */
1145 ret = vmbus_sendpacket(Device->channel, &recvcompMessage, 1188 ret = vmbus_sendpacket(device->channel, &recvcompMessage,
1146 sizeof(struct nvsp_message), TransactionId, 1189 sizeof(struct nvsp_message), transaction_id,
1147 VmbusPacketTypeCompletion, 0); 1190 VmbusPacketTypeCompletion, 0);
1148 if (ret == 0) { 1191 if (ret == 0) {
1149 /* success */ 1192 /* success */
@@ -1152,7 +1195,7 @@ retry_send_cmplt:
1152 /* no more room...wait a bit and attempt to retry 3 times */ 1195 /* no more room...wait a bit and attempt to retry 3 times */
1153 retries++; 1196 retries++;
1154 DPRINT_ERR(NETVSC, "unable to send receive completion pkt " 1197 DPRINT_ERR(NETVSC, "unable to send receive completion pkt "
1155 "(tid %llx)...retrying %d", TransactionId, retries); 1198 "(tid %llx)...retrying %d", transaction_id, retries);
1156 1199
1157 if (retries < 4) { 1200 if (retries < 4) {
1158 udelay(100); 1201 udelay(100);
@@ -1160,22 +1203,22 @@ retry_send_cmplt:
1160 } else { 1203 } else {
1161 DPRINT_ERR(NETVSC, "unable to send receive completion " 1204 DPRINT_ERR(NETVSC, "unable to send receive completion "
1162 "pkt (tid %llx)...give up retrying", 1205 "pkt (tid %llx)...give up retrying",
1163 TransactionId); 1206 transaction_id);
1164 } 1207 }
1165 } else { 1208 } else {
1166 DPRINT_ERR(NETVSC, "unable to send receive completion pkt - " 1209 DPRINT_ERR(NETVSC, "unable to send receive completion pkt - "
1167 "%llx", TransactionId); 1210 "%llx", transaction_id);
1168 } 1211 }
1169} 1212}
1170 1213
1171/* Send a receive completion packet to RNDIS device (ie NetVsp) */ 1214/* Send a receive completion packet to RNDIS device (ie NetVsp) */
1172static void NetVscOnReceiveCompletion(void *Context) 1215static void netvsc_receive_completion(void *context)
1173{ 1216{
1174 struct hv_netvsc_packet *packet = Context; 1217 struct hv_netvsc_packet *packet = context;
1175 struct hv_device *device = (struct hv_device *)packet->Device; 1218 struct hv_device *device = (struct hv_device *)packet->device;
1176 struct netvsc_device *netDevice; 1219 struct netvsc_device *net_device;
1177 u64 transactionId = 0; 1220 u64 transaction_id = 0;
1178 bool fSendReceiveComp = false; 1221 bool fsend_receive_comp = false;
1179 unsigned long flags; 1222 unsigned long flags;
1180 1223
1181 /* ASSERT(packet->XferPagePacket); */ 1224 /* ASSERT(packet->XferPagePacket); */
@@ -1185,49 +1228,49 @@ static void NetVscOnReceiveCompletion(void *Context)
1185 * send out receive completion, we are using GetInboundNetDevice() 1228 * send out receive completion, we are using GetInboundNetDevice()
1186 * since we may have disable outbound traffic already. 1229 * since we may have disable outbound traffic already.
1187 */ 1230 */
1188 netDevice = GetInboundNetDevice(device); 1231 net_device = get_inbound_net_device(device);
1189 if (!netDevice) { 1232 if (!net_device) {
1190 DPRINT_ERR(NETVSC, "unable to get net device..." 1233 DPRINT_ERR(NETVSC, "unable to get net device..."
1191 "device being destroyed?"); 1234 "device being destroyed?");
1192 return; 1235 return;
1193 } 1236 }
1194 1237
1195 /* Overloading use of the lock. */ 1238 /* Overloading use of the lock. */
1196 spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); 1239 spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags);
1197 1240
1198 /* ASSERT(packet->XferPagePacket->Count > 0); */ 1241 /* ASSERT(packet->XferPagePacket->Count > 0); */
1199 packet->XferPagePacket->Count--; 1242 packet->xfer_page_pkt->count--;
1200 1243
1201 /* 1244 /*
1202 * Last one in the line that represent 1 xfer page packet. 1245 * Last one in the line that represent 1 xfer page packet.
1203 * Return the xfer page packet itself to the freelist 1246 * Return the xfer page packet itself to the freelist
1204 */ 1247 */
1205 if (packet->XferPagePacket->Count == 0) { 1248 if (packet->xfer_page_pkt->count == 0) {
1206 fSendReceiveComp = true; 1249 fsend_receive_comp = true;
1207 transactionId = packet->Completion.Recv.ReceiveCompletionTid; 1250 transaction_id = packet->completion.recv.recv_completion_tid;
1208 list_add_tail(&packet->XferPagePacket->ListEntry, 1251 list_add_tail(&packet->xfer_page_pkt->list_ent,
1209 &netDevice->ReceivePacketList); 1252 &net_device->recv_pkt_list);
1210 1253
1211 } 1254 }
1212 1255
1213 /* Put the packet back */ 1256 /* Put the packet back */
1214 list_add_tail(&packet->ListEntry, &netDevice->ReceivePacketList); 1257 list_add_tail(&packet->list_ent, &net_device->recv_pkt_list);
1215 spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags); 1258 spin_unlock_irqrestore(&net_device->recv_pkt_list_lock, flags);
1216 1259
1217 /* Send a receive completion for the xfer page packet */ 1260 /* Send a receive completion for the xfer page packet */
1218 if (fSendReceiveComp) 1261 if (fsend_receive_comp)
1219 NetVscSendReceiveCompletion(device, transactionId); 1262 netvsc_send_recv_completion(device, transaction_id);
1220 1263
1221 PutNetDevice(device); 1264 put_net_device(device);
1222} 1265}
1223 1266
1224static void NetVscOnChannelCallback(void *Context) 1267static void netvsc_channel_cb(void *context)
1225{ 1268{
1226 int ret; 1269 int ret;
1227 struct hv_device *device = Context; 1270 struct hv_device *device = context;
1228 struct netvsc_device *netDevice; 1271 struct netvsc_device *net_device;
1229 u32 bytesRecvd; 1272 u32 bytes_recvd;
1230 u64 requestId; 1273 u64 request_id;
1231 unsigned char *packet; 1274 unsigned char *packet;
1232 struct vmpacket_descriptor *desc; 1275 struct vmpacket_descriptor *desc;
1233 unsigned char *buffer; 1276 unsigned char *buffer;
@@ -1241,37 +1284,37 @@ static void NetVscOnChannelCallback(void *Context)
1241 return; 1284 return;
1242 buffer = packet; 1285 buffer = packet;
1243 1286
1244 netDevice = GetInboundNetDevice(device); 1287 net_device = get_inbound_net_device(device);
1245 if (!netDevice) { 1288 if (!net_device) {
1246 DPRINT_ERR(NETVSC, "net device (%p) shutting down..." 1289 DPRINT_ERR(NETVSC, "net device (%p) shutting down..."
1247 "ignoring inbound packets", netDevice); 1290 "ignoring inbound packets", net_device);
1248 goto out; 1291 goto out;
1249 } 1292 }
1250 1293
1251 do { 1294 do {
1252 ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen, 1295 ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen,
1253 &bytesRecvd, &requestId); 1296 &bytes_recvd, &request_id);
1254 if (ret == 0) { 1297 if (ret == 0) {
1255 if (bytesRecvd > 0) { 1298 if (bytes_recvd > 0) {
1256 DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx", 1299 DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx",
1257 bytesRecvd, requestId); 1300 bytes_recvd, request_id);
1258 1301
1259 desc = (struct vmpacket_descriptor *)buffer; 1302 desc = (struct vmpacket_descriptor *)buffer;
1260 switch (desc->Type) { 1303 switch (desc->Type) {
1261 case VmbusPacketTypeCompletion: 1304 case VmbusPacketTypeCompletion:
1262 NetVscOnSendCompletion(device, desc); 1305 netvsc_send_completion(device, desc);
1263 break; 1306 break;
1264 1307
1265 case VmbusPacketTypeDataUsingTransferPages: 1308 case VmbusPacketTypeDataUsingTransferPages:
1266 NetVscOnReceive(device, desc); 1309 netvsc_receive(device, desc);
1267 break; 1310 break;
1268 1311
1269 default: 1312 default:
1270 DPRINT_ERR(NETVSC, 1313 DPRINT_ERR(NETVSC,
1271 "unhandled packet type %d, " 1314 "unhandled packet type %d, "
1272 "tid %llx len %d\n", 1315 "tid %llx len %d\n",
1273 desc->Type, requestId, 1316 desc->Type, request_id,
1274 bytesRecvd); 1317 bytes_recvd);
1275 break; 1318 break;
1276 } 1319 }
1277 1320
@@ -1293,20 +1336,20 @@ static void NetVscOnChannelCallback(void *Context)
1293 } 1336 }
1294 } else if (ret == -2) { 1337 } else if (ret == -2) {
1295 /* Handle large packet */ 1338 /* Handle large packet */
1296 buffer = kmalloc(bytesRecvd, GFP_ATOMIC); 1339 buffer = kmalloc(bytes_recvd, GFP_ATOMIC);
1297 if (buffer == NULL) { 1340 if (buffer == NULL) {
1298 /* Try again next time around */ 1341 /* Try again next time around */
1299 DPRINT_ERR(NETVSC, 1342 DPRINT_ERR(NETVSC,
1300 "unable to allocate buffer of size " 1343 "unable to allocate buffer of size "
1301 "(%d)!!", bytesRecvd); 1344 "(%d)!!", bytes_recvd);
1302 break; 1345 break;
1303 } 1346 }
1304 1347
1305 bufferlen = bytesRecvd; 1348 bufferlen = bytes_recvd;
1306 } 1349 }
1307 } while (1); 1350 } while (1);
1308 1351
1309 PutNetDevice(device); 1352 put_net_device(device);
1310out: 1353out:
1311 kfree(buffer); 1354 kfree(buffer);
1312 return; 1355 return;
diff --git a/drivers/staging/hv/netvsc.h b/drivers/staging/hv/netvsc.h
index c71dce5b3f7c..932a77ccdc04 100644
--- a/drivers/staging/hv/netvsc.h
+++ b/drivers/staging/hv/netvsc.h
@@ -38,48 +38,48 @@
38#define NVSP_MAX_PROTOCOL_VERSION NVSP_PROTOCOL_VERSION_1 38#define NVSP_MAX_PROTOCOL_VERSION NVSP_PROTOCOL_VERSION_1
39 39
40enum { 40enum {
41 NvspMessageTypeNone = 0, 41 NVSP_MSG_TYPE_NONE = 0,
42 42
43 /* Init Messages */ 43 /* Init Messages */
44 NvspMessageTypeInit = 1, 44 NVSP_MSG_TYPE_INIT = 1,
45 NvspMessageTypeInitComplete = 2, 45 NVSP_MSG_TYPE_INIT_COMPLETE = 2,
46 46
47 NvspVersionMessageStart = 100, 47 NVSP_VERSION_MSG_START = 100,
48 48
49 /* Version 1 Messages */ 49 /* Version 1 Messages */
50 NvspMessage1TypeSendNdisVersion = NvspVersionMessageStart, 50 NVSP_MSG1_TYPE_SEND_NDIS_VER = NVSP_VERSION_MSG_START,
51 51
52 NvspMessage1TypeSendReceiveBuffer, 52 NVSP_MSG1_TYPE_SEND_RECV_BUF,
53 NvspMessage1TypeSendReceiveBufferComplete, 53 NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE,
54 NvspMessage1TypeRevokeReceiveBuffer, 54 NVSP_MSG1_TYPE_REVOKE_RECV_BUF,
55 55
56 NvspMessage1TypeSendSendBuffer, 56 NVSP_MSG1_TYPE_SEND_SEND_BUF,
57 NvspMessage1TypeSendSendBufferComplete, 57 NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE,
58 NvspMessage1TypeRevokeSendBuffer, 58 NVSP_MSG1_TYPE_REVOKE_SEND_BUF,
59 59
60 NvspMessage1TypeSendRNDISPacket, 60 NVSP_MSG1_TYPE_SEND_RNDIS_PKT,
61 NvspMessage1TypeSendRNDISPacketComplete, 61 NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE,
62 62
63 /* 63 /*
64 * This should be set to the number of messages for the version with 64 * This should be set to the number of messages for the version with
65 * the maximum number of messages. 65 * the maximum number of messages.
66 */ 66 */
67 NvspNumMessagePerVersion = 9, 67 NVSP_NUM_MSG_PER_VERSION = 9,
68}; 68};
69 69
70enum { 70enum {
71 NvspStatusNone = 0, 71 NVSP_STAT_NONE = 0,
72 NvspStatusSuccess, 72 NVSP_STAT_SUCCESS,
73 NvspStatusFailure, 73 NVSP_STAT_FAIL,
74 NvspStatusProtocolVersionRangeTooNew, 74 NVSP_STAT_PROTOCOL_TOO_NEW,
75 NvspStatusProtocolVersionRangeTooOld, 75 NVSP_STAT_PROTOCOL_TOO_OLD,
76 NvspStatusInvalidRndisPacket, 76 NVSP_STAT_INVALID_RNDIS_PKT,
77 NvspStatusBusy, 77 NVSP_STAT_BUSY,
78 NvspStatusMax, 78 NVSP_STAT_MAX,
79}; 79};
80 80
81struct nvsp_message_header { 81struct nvsp_message_header {
82 u32 MessageType; 82 u32 msg_type;
83}; 83};
84 84
85/* Init Messages */ 85/* Init Messages */
@@ -90,8 +90,8 @@ struct nvsp_message_header {
90 * versioning (i.e. this message will be the same for ever). 90 * versioning (i.e. this message will be the same for ever).
91 */ 91 */
92struct nvsp_message_init { 92struct nvsp_message_init {
93 u32 MinProtocolVersion; 93 u32 min_protocol_ver;
94 u32 MaxProtocolVersion; 94 u32 max_protocol_ver;
95} __attribute__((packed)); 95} __attribute__((packed));
96 96
97/* 97/*
@@ -100,14 +100,14 @@ struct nvsp_message_init {
100 * (i.e. this message will be the same for ever). 100 * (i.e. this message will be the same for ever).
101 */ 101 */
102struct nvsp_message_init_complete { 102struct nvsp_message_init_complete {
103 u32 NegotiatedProtocolVersion; 103 u32 negotiated_protocol_ver;
104 u32 MaximumMdlChainLength; 104 u32 max_mdl_chain_len;
105 u32 Status; 105 u32 status;
106} __attribute__((packed)); 106} __attribute__((packed));
107 107
108union nvsp_message_init_uber { 108union nvsp_message_init_uber {
109 struct nvsp_message_init Init; 109 struct nvsp_message_init init;
110 struct nvsp_message_init_complete InitComplete; 110 struct nvsp_message_init_complete init_complete;
111} __attribute__((packed)); 111} __attribute__((packed));
112 112
113/* Version 1 Messages */ 113/* Version 1 Messages */
@@ -117,8 +117,8 @@ union nvsp_message_init_uber {
117 * can use this information when handling OIDs sent by the VSC. 117 * can use this information when handling OIDs sent by the VSC.
118 */ 118 */
119struct nvsp_1_message_send_ndis_version { 119struct nvsp_1_message_send_ndis_version {
120 u32 NdisMajorVersion; 120 u32 ndis_major_ver;
121 u32 NdisMinorVersion; 121 u32 ndis_minor_ver;
122} __attribute__((packed)); 122} __attribute__((packed));
123 123
124/* 124/*
@@ -126,15 +126,15 @@ struct nvsp_1_message_send_ndis_version {
126 * can then use the receive buffer to send data to the VSC. 126 * can then use the receive buffer to send data to the VSC.
127 */ 127 */
128struct nvsp_1_message_send_receive_buffer { 128struct nvsp_1_message_send_receive_buffer {
129 u32 GpadlHandle; 129 u32 gpadl_handle;
130 u16 Id; 130 u16 id;
131} __attribute__((packed)); 131} __attribute__((packed));
132 132
133struct nvsp_1_receive_buffer_section { 133struct nvsp_1_receive_buffer_section {
134 u32 Offset; 134 u32 offset;
135 u32 SubAllocationSize; 135 u32 sub_alloc_size;
136 u32 NumSubAllocations; 136 u32 num_sub_allocs;
137 u32 EndOffset; 137 u32 end_offset;
138} __attribute__((packed)); 138} __attribute__((packed));
139 139
140/* 140/*
@@ -143,8 +143,8 @@ struct nvsp_1_receive_buffer_section {
143 * buffer. 143 * buffer.
144 */ 144 */
145struct nvsp_1_message_send_receive_buffer_complete { 145struct nvsp_1_message_send_receive_buffer_complete {
146 u32 Status; 146 u32 status;
147 u32 NumSections; 147 u32 num_sections;
148 148
149 /* 149 /*
150 * The receive buffer is split into two parts, a large suballocation 150 * The receive buffer is split into two parts, a large suballocation
@@ -165,7 +165,7 @@ struct nvsp_1_message_send_receive_buffer_complete {
165 * LargeOffset SmallOffset 165 * LargeOffset SmallOffset
166 */ 166 */
167 167
168 struct nvsp_1_receive_buffer_section Sections[1]; 168 struct nvsp_1_receive_buffer_section sections[1];
169} __attribute__((packed)); 169} __attribute__((packed));
170 170
171/* 171/*
@@ -174,7 +174,7 @@ struct nvsp_1_message_send_receive_buffer_complete {
174 * again. 174 * again.
175 */ 175 */
176struct nvsp_1_message_revoke_receive_buffer { 176struct nvsp_1_message_revoke_receive_buffer {
177 u16 Id; 177 u16 id;
178}; 178};
179 179
180/* 180/*
@@ -182,8 +182,8 @@ struct nvsp_1_message_revoke_receive_buffer {
182 * can then use the send buffer to send data to the VSP. 182 * can then use the send buffer to send data to the VSP.
183 */ 183 */
184struct nvsp_1_message_send_send_buffer { 184struct nvsp_1_message_send_send_buffer {
185 u32 GpadlHandle; 185 u32 gpadl_handle;
186 u16 Id; 186 u16 id;
187} __attribute__((packed)); 187} __attribute__((packed));
188 188
189/* 189/*
@@ -192,7 +192,7 @@ struct nvsp_1_message_send_send_buffer {
192 * buffer. 192 * buffer.
193 */ 193 */
194struct nvsp_1_message_send_send_buffer_complete { 194struct nvsp_1_message_send_send_buffer_complete {
195 u32 Status; 195 u32 status;
196 196
197 /* 197 /*
198 * The VSC gets to choose the size of the send buffer and the VSP gets 198 * The VSC gets to choose the size of the send buffer and the VSP gets
@@ -200,7 +200,7 @@ struct nvsp_1_message_send_send_buffer_complete {
200 * dynamic reconfigurations when the cost of GPA-direct buffers 200 * dynamic reconfigurations when the cost of GPA-direct buffers
201 * decreases. 201 * decreases.
202 */ 202 */
203 u32 SectionSize; 203 u32 section_size;
204} __attribute__((packed)); 204} __attribute__((packed));
205 205
206/* 206/*
@@ -208,7 +208,7 @@ struct nvsp_1_message_send_send_buffer_complete {
208 * completes this transaction, the vsp should never use the send buffer again. 208 * completes this transaction, the vsp should never use the send buffer again.
209 */ 209 */
210struct nvsp_1_message_revoke_send_buffer { 210struct nvsp_1_message_revoke_send_buffer {
211 u16 Id; 211 u16 id;
212}; 212};
213 213
214/* 214/*
@@ -221,7 +221,7 @@ struct nvsp_1_message_send_rndis_packet {
221 * channels of communication. However, the Network VSP only has one. 221 * channels of communication. However, the Network VSP only has one.
222 * Therefore, the channel travels with the RNDIS packet. 222 * Therefore, the channel travels with the RNDIS packet.
223 */ 223 */
224 u32 ChannelType; 224 u32 channel_type;
225 225
226 /* 226 /*
227 * This field is used to send part or all of the data through a send 227 * This field is used to send part or all of the data through a send
@@ -229,8 +229,8 @@ struct nvsp_1_message_send_rndis_packet {
229 * index is 0xFFFFFFFF, then the send buffer is not being used and all 229 * index is 0xFFFFFFFF, then the send buffer is not being used and all
230 * of the data was sent through other VMBus mechanisms. 230 * of the data was sent through other VMBus mechanisms.
231 */ 231 */
232 u32 SendBufferSectionIndex; 232 u32 send_buf_section_index;
233 u32 SendBufferSectionSize; 233 u32 send_buf_section_size;
234} __attribute__((packed)); 234} __attribute__((packed));
235 235
236/* 236/*
@@ -239,35 +239,35 @@ struct nvsp_1_message_send_rndis_packet {
239 * message cannot use any resources associated with the original RNDIS packet. 239 * message cannot use any resources associated with the original RNDIS packet.
240 */ 240 */
241struct nvsp_1_message_send_rndis_packet_complete { 241struct nvsp_1_message_send_rndis_packet_complete {
242 u32 Status; 242 u32 status;
243}; 243};
244 244
245union nvsp_1_message_uber { 245union nvsp_1_message_uber {
246 struct nvsp_1_message_send_ndis_version SendNdisVersion; 246 struct nvsp_1_message_send_ndis_version send_ndis_ver;
247 247
248 struct nvsp_1_message_send_receive_buffer SendReceiveBuffer; 248 struct nvsp_1_message_send_receive_buffer send_recv_buf;
249 struct nvsp_1_message_send_receive_buffer_complete 249 struct nvsp_1_message_send_receive_buffer_complete
250 SendReceiveBufferComplete; 250 send_recv_buf_complete;
251 struct nvsp_1_message_revoke_receive_buffer RevokeReceiveBuffer; 251 struct nvsp_1_message_revoke_receive_buffer revoke_recv_buf;
252 252
253 struct nvsp_1_message_send_send_buffer SendSendBuffer; 253 struct nvsp_1_message_send_send_buffer send_send_buf;
254 struct nvsp_1_message_send_send_buffer_complete SendSendBufferComplete; 254 struct nvsp_1_message_send_send_buffer_complete send_send_buf_complete;
255 struct nvsp_1_message_revoke_send_buffer RevokeSendBuffer; 255 struct nvsp_1_message_revoke_send_buffer revoke_send_buf;
256 256
257 struct nvsp_1_message_send_rndis_packet SendRNDISPacket; 257 struct nvsp_1_message_send_rndis_packet send_rndis_pkt;
258 struct nvsp_1_message_send_rndis_packet_complete 258 struct nvsp_1_message_send_rndis_packet_complete
259 SendRNDISPacketComplete; 259 send_rndis_pkt_complete;
260} __attribute__((packed)); 260} __attribute__((packed));
261 261
262union nvsp_all_messages { 262union nvsp_all_messages {
263 union nvsp_message_init_uber InitMessages; 263 union nvsp_message_init_uber init_msg;
264 union nvsp_1_message_uber Version1Messages; 264 union nvsp_1_message_uber v1_msg;
265} __attribute__((packed)); 265} __attribute__((packed));
266 266
267/* ALL Messages */ 267/* ALL Messages */
268struct nvsp_message { 268struct nvsp_message {
269 struct nvsp_message_header Header; 269 struct nvsp_message_header hdr;
270 union nvsp_all_messages Messages; 270 union nvsp_all_messages msg;
271} __attribute__((packed)); 271} __attribute__((packed));
272 272
273 273
@@ -293,39 +293,39 @@ struct nvsp_message {
293 293
294/* Per netvsc channel-specific */ 294/* Per netvsc channel-specific */
295struct netvsc_device { 295struct netvsc_device {
296 struct hv_device *Device; 296 struct hv_device *dev;
297 297
298 atomic_t RefCount; 298 atomic_t refcnt;
299 atomic_t NumOutstandingSends; 299 atomic_t num_outstanding_sends;
300 /* 300 /*
301 * List of free preallocated hv_netvsc_packet to represent receive 301 * List of free preallocated hv_netvsc_packet to represent receive
302 * packet 302 * packet
303 */ 303 */
304 struct list_head ReceivePacketList; 304 struct list_head recv_pkt_list;
305 spinlock_t receive_packet_list_lock; 305 spinlock_t recv_pkt_list_lock;
306 306
307 /* Send buffer allocated by us but manages by NetVSP */ 307 /* Send buffer allocated by us but manages by NetVSP */
308 void *SendBuffer; 308 void *send_buf;
309 u32 SendBufferSize; 309 u32 send_buf_size;
310 u32 SendBufferGpadlHandle; 310 u32 send_buf_gpadl_handle;
311 u32 SendSectionSize; 311 u32 send_section_size;
312 312
313 /* Receive buffer allocated by us but manages by NetVSP */ 313 /* Receive buffer allocated by us but manages by NetVSP */
314 void *ReceiveBuffer; 314 void *recv_buf;
315 u32 ReceiveBufferSize; 315 u32 recv_buf_size;
316 u32 ReceiveBufferGpadlHandle; 316 u32 recv_buf_gpadl_handle;
317 u32 ReceiveSectionCount; 317 u32 recv_section_cnt;
318 struct nvsp_1_receive_buffer_section *ReceiveSections; 318 struct nvsp_1_receive_buffer_section *recv_section;
319 319
320 /* Used for NetVSP initialization protocol */ 320 /* Used for NetVSP initialization protocol */
321 struct osd_waitevent *ChannelInitEvent; 321 struct osd_waitevent *channel_init_event;
322 struct nvsp_message ChannelInitPacket; 322 struct nvsp_message channel_init_pkt;
323 323
324 struct nvsp_message RevokePacket; 324 struct nvsp_message revoke_packet;
325 /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */ 325 /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */
326 326
327 /* Holds rndis device info */ 327 /* Holds rndis device info */
328 void *Extension; 328 void *extension;
329}; 329};
330 330
331#endif /* _NETVSC_H_ */ 331#endif /* _NETVSC_H_ */
diff --git a/drivers/staging/hv/netvsc_api.h b/drivers/staging/hv/netvsc_api.h
index 4b5b3ac458c8..b4bed3636594 100644
--- a/drivers/staging/hv/netvsc_api.h
+++ b/drivers/staging/hv/netvsc_api.h
@@ -32,10 +32,10 @@ struct hv_netvsc_packet;
32 32
33/* Represent the xfer page packet which contains 1 or more netvsc packet */ 33/* Represent the xfer page packet which contains 1 or more netvsc packet */
34struct xferpage_packet { 34struct xferpage_packet {
35 struct list_head ListEntry; 35 struct list_head list_ent;
36 36
37 /* # of netvsc packets this xfer packet contains */ 37 /* # of netvsc packets this xfer packet contains */
38 u32 Count; 38 u32 count;
39}; 39};
40 40
41/* The number of pages which are enough to cover jumbo frame buffer. */ 41/* The number of pages which are enough to cover jumbo frame buffer. */
@@ -47,70 +47,70 @@ struct xferpage_packet {
47 */ 47 */
48struct hv_netvsc_packet { 48struct hv_netvsc_packet {
49 /* Bookkeeping stuff */ 49 /* Bookkeeping stuff */
50 struct list_head ListEntry; 50 struct list_head list_ent;
51 51
52 struct hv_device *Device; 52 struct hv_device *device;
53 bool IsDataPacket; 53 bool is_data_pkt;
54 54
55 /* 55 /*
56 * Valid only for receives when we break a xfer page packet 56 * Valid only for receives when we break a xfer page packet
57 * into multiple netvsc packets 57 * into multiple netvsc packets
58 */ 58 */
59 struct xferpage_packet *XferPagePacket; 59 struct xferpage_packet *xfer_page_pkt;
60 60
61 union { 61 union {
62 struct{ 62 struct{
63 u64 ReceiveCompletionTid; 63 u64 recv_completion_tid;
64 void *ReceiveCompletionContext; 64 void *recv_completion_ctx;
65 void (*OnReceiveCompletion)(void *context); 65 void (*recv_completion)(void *context);
66 } Recv; 66 } recv;
67 struct{ 67 struct{
68 u64 SendCompletionTid; 68 u64 send_completion_tid;
69 void *SendCompletionContext; 69 void *send_completion_ctx;
70 void (*OnSendCompletion)(void *context); 70 void (*send_completion)(void *context);
71 } Send; 71 } send;
72 } Completion; 72 } completion;
73 73
74 /* This points to the memory after PageBuffers */ 74 /* This points to the memory after page_buf */
75 void *Extension; 75 void *extension;
76 76
77 u32 TotalDataBufferLength; 77 u32 total_data_buflen;
78 /* Points to the send/receive buffer where the ethernet frame is */ 78 /* Points to the send/receive buffer where the ethernet frame is */
79 u32 PageBufferCount; 79 u32 page_buf_cnt;
80 struct hv_page_buffer PageBuffers[NETVSC_PACKET_MAXPAGE]; 80 struct hv_page_buffer page_buf[NETVSC_PACKET_MAXPAGE];
81}; 81};
82 82
83/* Represents the net vsc driver */ 83/* Represents the net vsc driver */
84struct netvsc_driver { 84struct netvsc_driver {
85 /* Must be the first field */ 85 /* Must be the first field */
86 /* Which is a bug FIXME! */ 86 /* Which is a bug FIXME! */
87 struct hv_driver Base; 87 struct hv_driver base;
88 88
89 u32 RingBufferSize; 89 u32 ring_buf_size;
90 u32 RequestExtSize; 90 u32 req_ext_size;
91 91
92 /* 92 /*
93 * This is set by the caller to allow us to callback when we 93 * This is set by the caller to allow us to callback when we
94 * receive a packet from the "wire" 94 * receive a packet from the "wire"
95 */ 95 */
96 int (*OnReceiveCallback)(struct hv_device *dev, 96 int (*recv_cb)(struct hv_device *dev,
97 struct hv_netvsc_packet *packet); 97 struct hv_netvsc_packet *packet);
98 void (*OnLinkStatusChanged)(struct hv_device *dev, u32 Status); 98 void (*link_status_change)(struct hv_device *dev, u32 status);
99 99
100 /* Specific to this driver */ 100 /* Specific to this driver */
101 int (*OnSend)(struct hv_device *dev, struct hv_netvsc_packet *packet); 101 int (*send)(struct hv_device *dev, struct hv_netvsc_packet *packet);
102 102
103 void *Context; 103 void *ctx;
104}; 104};
105 105
106struct netvsc_device_info { 106struct netvsc_device_info {
107 unsigned char MacAddr[6]; 107 unsigned char mac_adr[6];
108 bool LinkState; /* 0 - link up, 1 - link down */ 108 bool link_state; /* 0 - link up, 1 - link down */
109}; 109};
110 110
111/* Interface */ 111/* Interface */
112int NetVscInitialize(struct hv_driver *drv); 112int netvsc_initialize(struct hv_driver *drv);
113int RndisFilterOnOpen(struct hv_device *Device); 113int rndis_filter_open(struct hv_device *dev);
114int RndisFilterOnClose(struct hv_device *Device); 114int rndis_filter_close(struct hv_device *dev);
115 115
116#endif /* _NETVSC_API_H_ */ 116#endif /* _NETVSC_API_H_ */
diff --git a/drivers/staging/hv/netvsc_drv.c b/drivers/staging/hv/netvsc_drv.c
index 141535295a41..0147b407512c 100644
--- a/drivers/staging/hv/netvsc_drv.c
+++ b/drivers/staging/hv/netvsc_drv.c
@@ -66,6 +66,9 @@ MODULE_PARM_DESC(ring_size, "Ring buffer size (# of pages)");
66/* The one and only one */ 66/* The one and only one */
67static struct netvsc_driver_context g_netvsc_drv; 67static struct netvsc_driver_context g_netvsc_drv;
68 68
69/* no-op so the netdev core doesn't return -EINVAL when modifying the the
70 * multicast address list in SIOCADDMULTI. hv is setup to get all multicast
71 * when it calls RndisFilterOnOpen() */
69static void netvsc_set_multicast_list(struct net_device *net) 72static void netvsc_set_multicast_list(struct net_device *net)
70{ 73{
71} 74}
@@ -78,7 +81,7 @@ static int netvsc_open(struct net_device *net)
78 81
79 if (netif_carrier_ok(net)) { 82 if (netif_carrier_ok(net)) {
80 /* Open up the device */ 83 /* Open up the device */
81 ret = RndisFilterOnOpen(device_obj); 84 ret = rndis_filter_open(device_obj);
82 if (ret != 0) { 85 if (ret != 0) {
83 DPRINT_ERR(NETVSC_DRV, 86 DPRINT_ERR(NETVSC_DRV,
84 "unable to open device (ret %d).", ret); 87 "unable to open device (ret %d).", ret);
@@ -101,7 +104,7 @@ static int netvsc_close(struct net_device *net)
101 104
102 netif_stop_queue(net); 105 netif_stop_queue(net);
103 106
104 ret = RndisFilterOnClose(device_obj); 107 ret = rndis_filter_close(device_obj);
105 if (ret != 0) 108 if (ret != 0)
106 DPRINT_ERR(NETVSC_DRV, "unable to close device (ret %d).", ret); 109 DPRINT_ERR(NETVSC_DRV, "unable to close device (ret %d).", ret);
107 110
@@ -112,7 +115,7 @@ static void netvsc_xmit_completion(void *context)
112{ 115{
113 struct hv_netvsc_packet *packet = (struct hv_netvsc_packet *)context; 116 struct hv_netvsc_packet *packet = (struct hv_netvsc_packet *)context;
114 struct sk_buff *skb = (struct sk_buff *) 117 struct sk_buff *skb = (struct sk_buff *)
115 (unsigned long)packet->Completion.Send.SendCompletionTid; 118 (unsigned long)packet->completion.send.send_completion_tid;
116 119
117 kfree(packet); 120 kfree(packet);
118 121
@@ -151,7 +154,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
151 /* Allocate a netvsc packet based on # of frags. */ 154 /* Allocate a netvsc packet based on # of frags. */
152 packet = kzalloc(sizeof(struct hv_netvsc_packet) + 155 packet = kzalloc(sizeof(struct hv_netvsc_packet) +
153 (num_pages * sizeof(struct hv_page_buffer)) + 156 (num_pages * sizeof(struct hv_page_buffer)) +
154 net_drv_obj->RequestExtSize, GFP_ATOMIC); 157 net_drv_obj->req_ext_size, GFP_ATOMIC);
155 if (!packet) { 158 if (!packet) {
156 /* out of memory, silently drop packet */ 159 /* out of memory, silently drop packet */
157 DPRINT_ERR(NETVSC_DRV, "unable to allocate hv_netvsc_packet"); 160 DPRINT_ERR(NETVSC_DRV, "unable to allocate hv_netvsc_packet");
@@ -161,40 +164,40 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net)
161 return NETDEV_TX_OK; 164 return NETDEV_TX_OK;
162 } 165 }
163 166
164 packet->Extension = (void *)(unsigned long)packet + 167 packet->extension = (void *)(unsigned long)packet +
165 sizeof(struct hv_netvsc_packet) + 168 sizeof(struct hv_netvsc_packet) +
166 (num_pages * sizeof(struct hv_page_buffer)); 169 (num_pages * sizeof(struct hv_page_buffer));
167 170
168 /* Setup the rndis header */ 171 /* Setup the rndis header */
169 packet->PageBufferCount = num_pages; 172 packet->page_buf_cnt = num_pages;
170 173
171 /* TODO: Flush all write buffers/ memory fence ??? */ 174 /* TODO: Flush all write buffers/ memory fence ??? */
172 /* wmb(); */ 175 /* wmb(); */
173 176
174 /* Initialize it from the skb */ 177 /* Initialize it from the skb */
175 packet->TotalDataBufferLength = skb->len; 178 packet->total_data_buflen = skb->len;
176 179
177 /* Start filling in the page buffers starting after RNDIS buffer. */ 180 /* Start filling in the page buffers starting after RNDIS buffer. */
178 packet->PageBuffers[1].Pfn = virt_to_phys(skb->data) >> PAGE_SHIFT; 181 packet->page_buf[1].Pfn = virt_to_phys(skb->data) >> PAGE_SHIFT;
179 packet->PageBuffers[1].Offset 182 packet->page_buf[1].Offset
180 = (unsigned long)skb->data & (PAGE_SIZE - 1); 183 = (unsigned long)skb->data & (PAGE_SIZE - 1);
181 packet->PageBuffers[1].Length = skb_headlen(skb); 184 packet->page_buf[1].Length = skb_headlen(skb);
182 185
183 /* Additional fragments are after SKB data */ 186 /* Additional fragments are after SKB data */
184 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 187 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
185 skb_frag_t *f = &skb_shinfo(skb)->frags[i]; 188 skb_frag_t *f = &skb_shinfo(skb)->frags[i];
186 189
187 packet->PageBuffers[i+2].Pfn = page_to_pfn(f->page); 190 packet->page_buf[i+2].Pfn = page_to_pfn(f->page);
188 packet->PageBuffers[i+2].Offset = f->page_offset; 191 packet->page_buf[i+2].Offset = f->page_offset;
189 packet->PageBuffers[i+2].Length = f->size; 192 packet->page_buf[i+2].Length = f->size;
190 } 193 }
191 194
192 /* Set the completion routine */ 195 /* Set the completion routine */
193 packet->Completion.Send.OnSendCompletion = netvsc_xmit_completion; 196 packet->completion.send.send_completion = netvsc_xmit_completion;
194 packet->Completion.Send.SendCompletionContext = packet; 197 packet->completion.send.send_completion_ctx = packet;
195 packet->Completion.Send.SendCompletionTid = (unsigned long)skb; 198 packet->completion.send.send_completion_tid = (unsigned long)skb;
196 199
197 ret = net_drv_obj->OnSend(&net_device_ctx->device_ctx->device_obj, 200 ret = net_drv_obj->send(&net_device_ctx->device_ctx->device_obj,
198 packet); 201 packet);
199 if (ret == 0) { 202 if (ret == 0) {
200 net->stats.tx_bytes += skb->len; 203 net->stats.tx_bytes += skb->len;
@@ -260,7 +263,7 @@ static int netvsc_recv_callback(struct hv_device *device_obj,
260 } 263 }
261 264
262 /* Allocate a skb - TODO direct I/O to pages? */ 265 /* Allocate a skb - TODO direct I/O to pages? */
263 skb = netdev_alloc_skb_ip_align(net, packet->TotalDataBufferLength); 266 skb = netdev_alloc_skb_ip_align(net, packet->total_data_buflen);
264 if (unlikely(!skb)) { 267 if (unlikely(!skb)) {
265 ++net->stats.rx_dropped; 268 ++net->stats.rx_dropped;
266 return 0; 269 return 0;
@@ -273,17 +276,17 @@ static int netvsc_recv_callback(struct hv_device *device_obj,
273 * Copy to skb. This copy is needed here since the memory pointed by 276 * Copy to skb. This copy is needed here since the memory pointed by
274 * hv_netvsc_packet cannot be deallocated 277 * hv_netvsc_packet cannot be deallocated
275 */ 278 */
276 for (i = 0; i < packet->PageBufferCount; i++) { 279 for (i = 0; i < packet->page_buf_cnt; i++) {
277 data = kmap_atomic(pfn_to_page(packet->PageBuffers[i].Pfn), 280 data = kmap_atomic(pfn_to_page(packet->page_buf[i].Pfn),
278 KM_IRQ1); 281 KM_IRQ1);
279 data = (void *)(unsigned long)data + 282 data = (void *)(unsigned long)data +
280 packet->PageBuffers[i].Offset; 283 packet->page_buf[i].Offset;
281 284
282 memcpy(skb_put(skb, packet->PageBuffers[i].Length), data, 285 memcpy(skb_put(skb, packet->page_buf[i].Length), data,
283 packet->PageBuffers[i].Length); 286 packet->page_buf[i].Length);
284 287
285 kunmap_atomic((void *)((unsigned long)data - 288 kunmap_atomic((void *)((unsigned long)data -
286 packet->PageBuffers[i].Offset), KM_IRQ1); 289 packet->page_buf[i].Offset), KM_IRQ1);
287 } 290 }
288 291
289 local_irq_restore(flags); 292 local_irq_restore(flags);
@@ -346,7 +349,7 @@ static int netvsc_probe(struct device *device)
346 struct netvsc_device_info device_info; 349 struct netvsc_device_info device_info;
347 int ret; 350 int ret;
348 351
349 if (!net_drv_obj->Base.OnDeviceAdd) 352 if (!net_drv_obj->base.OnDeviceAdd)
350 return -1; 353 return -1;
351 354
352 net = alloc_etherdev(sizeof(struct net_device_context)); 355 net = alloc_etherdev(sizeof(struct net_device_context));
@@ -363,7 +366,7 @@ static int netvsc_probe(struct device *device)
363 dev_set_drvdata(device, net); 366 dev_set_drvdata(device, net);
364 367
365 /* Notify the netvsc driver of the new device */ 368 /* Notify the netvsc driver of the new device */
366 ret = net_drv_obj->Base.OnDeviceAdd(device_obj, &device_info); 369 ret = net_drv_obj->base.OnDeviceAdd(device_obj, &device_info);
367 if (ret != 0) { 370 if (ret != 0) {
368 free_netdev(net); 371 free_netdev(net);
369 dev_set_drvdata(device, NULL); 372 dev_set_drvdata(device, NULL);
@@ -382,10 +385,10 @@ static int netvsc_probe(struct device *device)
382 * out of sync with the device's link status 385 * out of sync with the device's link status
383 */ 386 */
384 if (!netif_carrier_ok(net)) 387 if (!netif_carrier_ok(net))
385 if (!device_info.LinkState) 388 if (!device_info.link_state)
386 netif_carrier_on(net); 389 netif_carrier_on(net);
387 390
388 memcpy(net->dev_addr, device_info.MacAddr, ETH_ALEN); 391 memcpy(net->dev_addr, device_info.mac_adr, ETH_ALEN);
389 392
390 net->netdev_ops = &device_ops; 393 net->netdev_ops = &device_ops;
391 394
@@ -398,7 +401,7 @@ static int netvsc_probe(struct device *device)
398 ret = register_netdev(net); 401 ret = register_netdev(net);
399 if (ret != 0) { 402 if (ret != 0) {
400 /* Remove the device and release the resource */ 403 /* Remove the device and release the resource */
401 net_drv_obj->Base.OnDeviceRemove(device_obj); 404 net_drv_obj->base.OnDeviceRemove(device_obj);
402 free_netdev(net); 405 free_netdev(net);
403 } 406 }
404 407
@@ -422,7 +425,7 @@ static int netvsc_remove(struct device *device)
422 return 0; 425 return 0;
423 } 426 }
424 427
425 if (!net_drv_obj->Base.OnDeviceRemove) 428 if (!net_drv_obj->base.OnDeviceRemove)
426 return -1; 429 return -1;
427 430
428 /* Stop outbound asap */ 431 /* Stop outbound asap */
@@ -435,7 +438,7 @@ static int netvsc_remove(struct device *device)
435 * Call to the vsc driver to let it know that the device is being 438 * Call to the vsc driver to let it know that the device is being
436 * removed 439 * removed
437 */ 440 */
438 ret = net_drv_obj->Base.OnDeviceRemove(device_obj); 441 ret = net_drv_obj->base.OnDeviceRemove(device_obj);
439 if (ret != 0) { 442 if (ret != 0) {
440 /* TODO: */ 443 /* TODO: */
441 DPRINT_ERR(NETVSC, "unable to remove vsc device (ret %d)", ret); 444 DPRINT_ERR(NETVSC, "unable to remove vsc device (ret %d)", ret);
@@ -481,8 +484,8 @@ static void netvsc_drv_exit(void)
481 device_unregister(current_dev); 484 device_unregister(current_dev);
482 } 485 }
483 486
484 if (netvsc_drv_obj->Base.OnCleanup) 487 if (netvsc_drv_obj->base.OnCleanup)
485 netvsc_drv_obj->Base.OnCleanup(&netvsc_drv_obj->Base); 488 netvsc_drv_obj->base.OnCleanup(&netvsc_drv_obj->base);
486 489
487 vmbus_child_driver_unregister(drv_ctx); 490 vmbus_child_driver_unregister(drv_ctx);
488 491
@@ -495,15 +498,15 @@ static int netvsc_drv_init(int (*drv_init)(struct hv_driver *drv))
495 struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; 498 struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx;
496 int ret; 499 int ret;
497 500
498 net_drv_obj->RingBufferSize = ring_size * PAGE_SIZE; 501 net_drv_obj->ring_buf_size = ring_size * PAGE_SIZE;
499 net_drv_obj->OnReceiveCallback = netvsc_recv_callback; 502 net_drv_obj->recv_cb = netvsc_recv_callback;
500 net_drv_obj->OnLinkStatusChanged = netvsc_linkstatus_callback; 503 net_drv_obj->link_status_change = netvsc_linkstatus_callback;
501 504
502 /* Callback to client driver to complete the initialization */ 505 /* Callback to client driver to complete the initialization */
503 drv_init(&net_drv_obj->Base); 506 drv_init(&net_drv_obj->base);
504 507
505 drv_ctx->driver.name = net_drv_obj->Base.name; 508 drv_ctx->driver.name = net_drv_obj->base.name;
506 memcpy(&drv_ctx->class_id, &net_drv_obj->Base.deviceType, 509 memcpy(&drv_ctx->class_id, &net_drv_obj->base.deviceType,
507 sizeof(struct hv_guid)); 510 sizeof(struct hv_guid));
508 511
509 drv_ctx->probe = netvsc_probe; 512 drv_ctx->probe = netvsc_probe;
@@ -536,7 +539,7 @@ static int __init netvsc_init(void)
536 if (!dmi_check_system(hv_netvsc_dmi_table)) 539 if (!dmi_check_system(hv_netvsc_dmi_table))
537 return -ENODEV; 540 return -ENODEV;
538 541
539 return netvsc_drv_init(NetVscInitialize); 542 return netvsc_drv_init(netvsc_initialize);
540} 543}
541 544
542static void __exit netvsc_exit(void) 545static void __exit netvsc_exit(void)
diff --git a/drivers/staging/hv/osd.c b/drivers/staging/hv/osd.c
index 8c3eb278a81f..b5a3940331b3 100644
--- a/drivers/staging/hv/osd.c
+++ b/drivers/staging/hv/osd.c
@@ -43,13 +43,7 @@
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include "osd.h" 44#include "osd.h"
45 45
46struct osd_callback_struct { 46void *osd_virtual_alloc_exec(unsigned int size)
47 struct work_struct work;
48 void (*callback)(void *);
49 void *data;
50};
51
52void *osd_VirtualAllocExec(unsigned int size)
53{ 47{
54#ifdef __x86_64__ 48#ifdef __x86_64__
55 return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL_EXEC); 49 return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL_EXEC);
@@ -60,7 +54,7 @@ void *osd_VirtualAllocExec(unsigned int size)
60} 54}
61 55
62/** 56/**
63 * osd_PageAlloc() - Allocate pages 57 * osd_page_alloc() - Allocate pages
64 * @count: Total number of Kernel pages you want to allocate 58 * @count: Total number of Kernel pages you want to allocate
65 * 59 *
66 * Tries to allocate @count number of consecutive free kernel pages. 60 * Tries to allocate @count number of consecutive free kernel pages.
@@ -68,7 +62,7 @@ void *osd_VirtualAllocExec(unsigned int size)
68 * If successfull it will return pointer to the @count pages. 62 * If successfull it will return pointer to the @count pages.
69 * Mainly used by Hyper-V drivers. 63 * Mainly used by Hyper-V drivers.
70 */ 64 */
71void *osd_PageAlloc(unsigned int count) 65void *osd_page_alloc(unsigned int count)
72{ 66{
73 void *p; 67 void *p;
74 68
@@ -85,26 +79,26 @@ void *osd_PageAlloc(unsigned int count)
85 /* if (p) memset(p, 0, PAGE_SIZE); */ 79 /* if (p) memset(p, 0, PAGE_SIZE); */
86 /* return p; */ 80 /* return p; */
87} 81}
88EXPORT_SYMBOL_GPL(osd_PageAlloc); 82EXPORT_SYMBOL_GPL(osd_page_alloc);
89 83
90/** 84/**
91 * osd_PageFree() - Free pages 85 * osd_page_free() - Free pages
92 * @page: Pointer to the first page to be freed 86 * @page: Pointer to the first page to be freed
93 * @count: Total number of Kernel pages you free 87 * @count: Total number of Kernel pages you free
94 * 88 *
95 * Frees the pages allocated by osd_PageAlloc() 89 * Frees the pages allocated by osd_page_alloc()
96 * Mainly used by Hyper-V drivers. 90 * Mainly used by Hyper-V drivers.
97 */ 91 */
98void osd_PageFree(void *page, unsigned int count) 92void osd_page_free(void *page, unsigned int count)
99{ 93{
100 free_pages((unsigned long)page, get_order(count * PAGE_SIZE)); 94 free_pages((unsigned long)page, get_order(count * PAGE_SIZE));
101 /*struct page* p = virt_to_page(page); 95 /*struct page* p = virt_to_page(page);
102 __free_page(p);*/ 96 __free_page(p);*/
103} 97}
104EXPORT_SYMBOL_GPL(osd_PageFree); 98EXPORT_SYMBOL_GPL(osd_page_free);
105 99
106/** 100/**
107 * osd_WaitEventCreate() - Create the event queue 101 * osd_waitevent_create() - Create the event queue
108 * 102 *
109 * Allocates memory for a &struct osd_waitevent. And then calls 103 * Allocates memory for a &struct osd_waitevent. And then calls
110 * init_waitqueue_head to set up the wait queue for the event. 104 * init_waitqueue_head to set up the wait queue for the event.
@@ -114,7 +108,7 @@ EXPORT_SYMBOL_GPL(osd_PageFree);
114 * Returns pointer to &struct osd_waitevent 108 * Returns pointer to &struct osd_waitevent
115 * Mainly used by Hyper-V drivers. 109 * Mainly used by Hyper-V drivers.
116 */ 110 */
117struct osd_waitevent *osd_WaitEventCreate(void) 111struct osd_waitevent *osd_waitevent_create(void)
118{ 112{
119 struct osd_waitevent *wait = kmalloc(sizeof(struct osd_waitevent), 113 struct osd_waitevent *wait = kmalloc(sizeof(struct osd_waitevent),
120 GFP_KERNEL); 114 GFP_KERNEL);
@@ -125,14 +119,14 @@ struct osd_waitevent *osd_WaitEventCreate(void)
125 init_waitqueue_head(&wait->event); 119 init_waitqueue_head(&wait->event);
126 return wait; 120 return wait;
127} 121}
128EXPORT_SYMBOL_GPL(osd_WaitEventCreate); 122EXPORT_SYMBOL_GPL(osd_waitevent_create);
129 123
130 124
131/** 125/**
132 * osd_WaitEventSet() - Wake up the process 126 * osd_waitevent_set() - Wake up the process
133 * @waitEvent: Structure to event to be woken up 127 * @wait_event: Structure to event to be woken up
134 * 128 *
135 * @waitevent is of type &struct osd_waitevent 129 * @wait_event is of type &struct osd_waitevent
136 * 130 *
137 * Wake up the sleeping process so it can do some work. 131 * Wake up the sleeping process so it can do some work.
138 * And set condition indicator in &struct osd_waitevent to indicate 132 * And set condition indicator in &struct osd_waitevent to indicate
@@ -140,18 +134,18 @@ EXPORT_SYMBOL_GPL(osd_WaitEventCreate);
140 * 134 *
141 * Only used by Network and Storage Hyper-V drivers. 135 * Only used by Network and Storage Hyper-V drivers.
142 */ 136 */
143void osd_WaitEventSet(struct osd_waitevent *waitEvent) 137void osd_waitevent_set(struct osd_waitevent *wait_event)
144{ 138{
145 waitEvent->condition = 1; 139 wait_event->condition = 1;
146 wake_up_interruptible(&waitEvent->event); 140 wake_up_interruptible(&wait_event->event);
147} 141}
148EXPORT_SYMBOL_GPL(osd_WaitEventSet); 142EXPORT_SYMBOL_GPL(osd_waitevent_set);
149 143
150/** 144/**
151 * osd_WaitEventWait() - Wait for event till condition is true 145 * osd_waitevent_wait() - Wait for event till condition is true
152 * @waitEvent: Structure to event to be put to sleep 146 * @wait_event: Structure to event to be put to sleep
153 * 147 *
154 * @waitevent is of type &struct osd_waitevent 148 * @wait_event is of type &struct osd_waitevent
155 * 149 *
156 * Set up the process to sleep until waitEvent->condition get true. 150 * Set up the process to sleep until waitEvent->condition get true.
157 * And set condition indicator in &struct osd_waitevent to indicate 151 * And set condition indicator in &struct osd_waitevent to indicate
@@ -161,25 +155,25 @@ EXPORT_SYMBOL_GPL(osd_WaitEventSet);
161 * 155 *
162 * Mainly used by Hyper-V drivers. 156 * Mainly used by Hyper-V drivers.
163 */ 157 */
164int osd_WaitEventWait(struct osd_waitevent *waitEvent) 158int osd_waitevent_wait(struct osd_waitevent *wait_event)
165{ 159{
166 int ret = 0; 160 int ret = 0;
167 161
168 ret = wait_event_interruptible(waitEvent->event, 162 ret = wait_event_interruptible(wait_event->event,
169 waitEvent->condition); 163 wait_event->condition);
170 waitEvent->condition = 0; 164 wait_event->condition = 0;
171 return ret; 165 return ret;
172} 166}
173EXPORT_SYMBOL_GPL(osd_WaitEventWait); 167EXPORT_SYMBOL_GPL(osd_waitevent_wait);
174 168
175/** 169/**
176 * osd_WaitEventWaitEx() - Wait for event or timeout for process wakeup 170 * osd_waitevent_waitex() - Wait for event or timeout for process wakeup
177 * @waitEvent: Structure to event to be put to sleep 171 * @wait_event: Structure to event to be put to sleep
178 * @TimeoutInMs: Total number of Milliseconds to wait before waking up 172 * @timeout_in_ms: Total number of Milliseconds to wait before waking up
179 * 173 *
180 * @waitevent is of type &struct osd_waitevent 174 * @wait_event is of type &struct osd_waitevent
181 * Set up the process to sleep until @waitEvent->condition get true or 175 * Set up the process to sleep until @waitEvent->condition get true or
182 * @TimeoutInMs (Time out in Milliseconds) has been reached. 176 * @timeout_in_ms (Time out in Milliseconds) has been reached.
183 * And set condition indicator in &struct osd_waitevent to indicate 177 * And set condition indicator in &struct osd_waitevent to indicate
184 * the process is in a sleeping state. 178 * the process is in a sleeping state.
185 * 179 *
@@ -187,42 +181,14 @@ EXPORT_SYMBOL_GPL(osd_WaitEventWait);
187 * 181 *
188 * Mainly used by Hyper-V drivers. 182 * Mainly used by Hyper-V drivers.
189 */ 183 */
190int osd_WaitEventWaitEx(struct osd_waitevent *waitEvent, u32 TimeoutInMs) 184int osd_waitevent_waitex(struct osd_waitevent *wait_event, u32 timeout_in_ms)
191{ 185{
192 int ret = 0; 186 int ret = 0;
193 187
194 ret = wait_event_interruptible_timeout(waitEvent->event, 188 ret = wait_event_interruptible_timeout(wait_event->event,
195 waitEvent->condition, 189 wait_event->condition,
196 msecs_to_jiffies(TimeoutInMs)); 190 msecs_to_jiffies(timeout_in_ms));
197 waitEvent->condition = 0; 191 wait_event->condition = 0;
198 return ret; 192 return ret;
199} 193}
200EXPORT_SYMBOL_GPL(osd_WaitEventWaitEx); 194EXPORT_SYMBOL_GPL(osd_waitevent_waitex);
201
202static void osd_callback_work(struct work_struct *work)
203{
204 struct osd_callback_struct *cb = container_of(work,
205 struct osd_callback_struct,
206 work);
207 (cb->callback)(cb->data);
208 kfree(cb);
209}
210
211int osd_schedule_callback(struct workqueue_struct *wq,
212 void (*func)(void *),
213 void *data)
214{
215 struct osd_callback_struct *cb;
216
217 cb = kmalloc(sizeof(*cb), GFP_KERNEL);
218 if (!cb) {
219 printk(KERN_ERR "unable to allocate memory in osd_schedule_callback\n");
220 return -1;
221 }
222
223 cb->callback = func;
224 cb->data = data;
225 INIT_WORK(&cb->work, osd_callback_work);
226 return queue_work(wq, &cb->work);
227}
228
diff --git a/drivers/staging/hv/osd.h b/drivers/staging/hv/osd.h
index ce064e8ea644..870ef0768833 100644
--- a/drivers/staging/hv/osd.h
+++ b/drivers/staging/hv/osd.h
@@ -50,21 +50,17 @@ struct osd_waitevent {
50 50
51/* Osd routines */ 51/* Osd routines */
52 52
53extern void *osd_VirtualAllocExec(unsigned int size); 53extern void *osd_virtual_alloc_exec(unsigned int size);
54 54
55extern void *osd_PageAlloc(unsigned int count); 55extern void *osd_page_alloc(unsigned int count);
56extern void osd_PageFree(void *page, unsigned int count); 56extern void osd_page_free(void *page, unsigned int count);
57 57
58extern struct osd_waitevent *osd_WaitEventCreate(void); 58extern struct osd_waitevent *osd_waitevent_create(void);
59extern void osd_WaitEventSet(struct osd_waitevent *waitEvent); 59extern void osd_waitevent_set(struct osd_waitevent *wait_event);
60extern int osd_WaitEventWait(struct osd_waitevent *waitEvent); 60extern int osd_waitevent_wait(struct osd_waitevent *wait_event);
61 61
62/* If >0, waitEvent got signaled. If ==0, timeout. If < 0, error */ 62/* If >0, wait_event got signaled. If ==0, timeout. If < 0, error */
63extern int osd_WaitEventWaitEx(struct osd_waitevent *waitEvent, 63extern int osd_waitevent_waitex(struct osd_waitevent *wait_event,
64 u32 TimeoutInMs); 64 u32 timeout_in_ms);
65
66int osd_schedule_callback(struct workqueue_struct *wq,
67 void (*func)(void *),
68 void *data);
69 65
70#endif /* _OSD_H_ */ 66#endif /* _OSD_H_ */
diff --git a/drivers/staging/hv/ring_buffer.c b/drivers/staging/hv/ring_buffer.c
index d78c569ac94a..4d53392f1e60 100644
--- a/drivers/staging/hv/ring_buffer.c
+++ b/drivers/staging/hv/ring_buffer.c
@@ -38,7 +38,7 @@
38/*++ 38/*++
39 39
40Name: 40Name:
41 GetRingBufferAvailBytes() 41 get_ringbuffer_availbytes()
42 42
43Description: 43Description:
44 Get number of bytes available to read and to write to 44 Get number of bytes available to read and to write to
@@ -46,33 +46,34 @@ Description:
46 46
47--*/ 47--*/
48static inline void 48static inline void
49GetRingBufferAvailBytes(struct hv_ring_buffer_info *rbi, u32 *read, u32 *write) 49get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
50 u32 *read, u32 *write)
50{ 51{
51 u32 read_loc, write_loc; 52 u32 read_loc, write_loc;
52 53
53 /* Capture the read/write indices before they changed */ 54 /* Capture the read/write indices before they changed */
54 read_loc = rbi->RingBuffer->ReadIndex; 55 read_loc = rbi->ring_buffer->read_index;
55 write_loc = rbi->RingBuffer->WriteIndex; 56 write_loc = rbi->ring_buffer->write_index;
56 57
57 *write = BYTES_AVAIL_TO_WRITE(read_loc, write_loc, rbi->RingDataSize); 58 *write = BYTES_AVAIL_TO_WRITE(read_loc, write_loc, rbi->ring_datasize);
58 *read = rbi->RingDataSize - *write; 59 *read = rbi->ring_datasize - *write;
59} 60}
60 61
61/*++ 62/*++
62 63
63Name: 64Name:
64 GetNextWriteLocation() 65 get_next_write_location()
65 66
66Description: 67Description:
67 Get the next write location for the specified ring buffer 68 Get the next write location for the specified ring buffer
68 69
69--*/ 70--*/
70static inline u32 71static inline u32
71GetNextWriteLocation(struct hv_ring_buffer_info *RingInfo) 72get_next_write_location(struct hv_ring_buffer_info *ring_info)
72{ 73{
73 u32 next = RingInfo->RingBuffer->WriteIndex; 74 u32 next = ring_info->ring_buffer->write_index;
74 75
75 /* ASSERT(next < RingInfo->RingDataSize); */ 76 /* ASSERT(next < ring_info->RingDataSize); */
76 77
77 return next; 78 return next;
78} 79}
@@ -80,34 +81,34 @@ GetNextWriteLocation(struct hv_ring_buffer_info *RingInfo)
80/*++ 81/*++
81 82
82Name: 83Name:
83 SetNextWriteLocation() 84 set_next_write_location()
84 85
85Description: 86Description:
86 Set the next write location for the specified ring buffer 87 Set the next write location for the specified ring buffer
87 88
88--*/ 89--*/
89static inline void 90static inline void
90SetNextWriteLocation(struct hv_ring_buffer_info *RingInfo, 91set_next_write_location(struct hv_ring_buffer_info *ring_info,
91 u32 NextWriteLocation) 92 u32 next_write_location)
92{ 93{
93 RingInfo->RingBuffer->WriteIndex = NextWriteLocation; 94 ring_info->ring_buffer->write_index = next_write_location;
94} 95}
95 96
96/*++ 97/*++
97 98
98Name: 99Name:
99 GetNextReadLocation() 100 get_next_read_location()
100 101
101Description: 102Description:
102 Get the next read location for the specified ring buffer 103 Get the next read location for the specified ring buffer
103 104
104--*/ 105--*/
105static inline u32 106static inline u32
106GetNextReadLocation(struct hv_ring_buffer_info *RingInfo) 107get_next_read_location(struct hv_ring_buffer_info *ring_info)
107{ 108{
108 u32 next = RingInfo->RingBuffer->ReadIndex; 109 u32 next = ring_info->ring_buffer->read_index;
109 110
110 /* ASSERT(next < RingInfo->RingDataSize); */ 111 /* ASSERT(next < ring_info->RingDataSize); */
111 112
112 return next; 113 return next;
113} 114}
@@ -115,7 +116,7 @@ GetNextReadLocation(struct hv_ring_buffer_info *RingInfo)
115/*++ 116/*++
116 117
117Name: 118Name:
118 GetNextReadLocationWithOffset() 119 get_next_readlocation_withoffset()
119 120
120Description: 121Description:
121 Get the next read location + offset for the specified ring buffer. 122 Get the next read location + offset for the specified ring buffer.
@@ -123,13 +124,14 @@ Description:
123 124
124--*/ 125--*/
125static inline u32 126static inline u32
126GetNextReadLocationWithOffset(struct hv_ring_buffer_info *RingInfo, u32 Offset) 127get_next_readlocation_withoffset(struct hv_ring_buffer_info *ring_info,
128 u32 offset)
127{ 129{
128 u32 next = RingInfo->RingBuffer->ReadIndex; 130 u32 next = ring_info->ring_buffer->read_index;
129 131
130 /* ASSERT(next < RingInfo->RingDataSize); */ 132 /* ASSERT(next < ring_info->RingDataSize); */
131 next += Offset; 133 next += offset;
132 next %= RingInfo->RingDataSize; 134 next %= ring_info->ring_datasize;
133 135
134 return next; 136 return next;
135} 137}
@@ -137,141 +139,145 @@ GetNextReadLocationWithOffset(struct hv_ring_buffer_info *RingInfo, u32 Offset)
137/*++ 139/*++
138 140
139Name: 141Name:
140 SetNextReadLocation() 142 set_next_read_location()
141 143
142Description: 144Description:
143 Set the next read location for the specified ring buffer 145 Set the next read location for the specified ring buffer
144 146
145--*/ 147--*/
146static inline void 148static inline void
147SetNextReadLocation(struct hv_ring_buffer_info *RingInfo, u32 NextReadLocation) 149set_next_read_location(struct hv_ring_buffer_info *ring_info,
150 u32 next_read_location)
148{ 151{
149 RingInfo->RingBuffer->ReadIndex = NextReadLocation; 152 ring_info->ring_buffer->read_index = next_read_location;
150} 153}
151 154
152 155
153/*++ 156/*++
154 157
155Name: 158Name:
156 GetRingBuffer() 159 get_ring_buffer()
157 160
158Description: 161Description:
159 Get the start of the ring buffer 162 Get the start of the ring buffer
160 163
161--*/ 164--*/
162static inline void * 165static inline void *
163GetRingBuffer(struct hv_ring_buffer_info *RingInfo) 166get_ring_buffer(struct hv_ring_buffer_info *ring_info)
164{ 167{
165 return (void *)RingInfo->RingBuffer->Buffer; 168 return (void *)ring_info->ring_buffer->buffer;
166} 169}
167 170
168 171
169/*++ 172/*++
170 173
171Name: 174Name:
172 GetRingBufferSize() 175 get_ring_buffersize()
173 176
174Description: 177Description:
175 Get the size of the ring buffer 178 Get the size of the ring buffer
176 179
177--*/ 180--*/
178static inline u32 181static inline u32
179GetRingBufferSize(struct hv_ring_buffer_info *RingInfo) 182get_ring_buffersize(struct hv_ring_buffer_info *ring_info)
180{ 183{
181 return RingInfo->RingDataSize; 184 return ring_info->ring_datasize;
182} 185}
183 186
184/*++ 187/*++
185 188
186Name: 189Name:
187 GetRingBufferIndices() 190 get_ring_bufferindices()
188 191
189Description: 192Description:
190 Get the read and write indices as u64 of the specified ring buffer 193 Get the read and write indices as u64 of the specified ring buffer
191 194
192--*/ 195--*/
193static inline u64 196static inline u64
194GetRingBufferIndices(struct hv_ring_buffer_info *RingInfo) 197get_ring_bufferindices(struct hv_ring_buffer_info *ring_info)
195{ 198{
196 return (u64)RingInfo->RingBuffer->WriteIndex << 32; 199 return (u64)ring_info->ring_buffer->write_index << 32;
197} 200}
198 201
199 202
200/*++ 203/*++
201 204
202Name: 205Name:
203 DumpRingInfo() 206 dump_ring_info()
204 207
205Description: 208Description:
206 Dump out to console the ring buffer info 209 Dump out to console the ring buffer info
207 210
208--*/ 211--*/
209void DumpRingInfo(struct hv_ring_buffer_info *RingInfo, char *Prefix) 212void dump_ring_info(struct hv_ring_buffer_info *ring_info, char *prefix)
210{ 213{
211 u32 bytesAvailToWrite; 214 u32 bytes_avail_towrite;
212 u32 bytesAvailToRead; 215 u32 bytes_avail_toread;
213 216
214 GetRingBufferAvailBytes(RingInfo, 217 get_ringbuffer_availbytes(ring_info,
215 &bytesAvailToRead, 218 &bytes_avail_toread,
216 &bytesAvailToWrite); 219 &bytes_avail_towrite);
217 220
218 DPRINT(VMBUS, 221 DPRINT(VMBUS,
219 DEBUG_RING_LVL, 222 DEBUG_RING_LVL,
220 "%s <<ringinfo %p buffer %p avail write %u " 223 "%s <<ringinfo %p buffer %p avail write %u "
221 "avail read %u read idx %u write idx %u>>", 224 "avail read %u read idx %u write idx %u>>",
222 Prefix, 225 prefix,
223 RingInfo, 226 ring_info,
224 RingInfo->RingBuffer->Buffer, 227 ring_info->ring_buffer->buffer,
225 bytesAvailToWrite, 228 bytes_avail_towrite,
226 bytesAvailToRead, 229 bytes_avail_toread,
227 RingInfo->RingBuffer->ReadIndex, 230 ring_info->ring_buffer->read_index,
228 RingInfo->RingBuffer->WriteIndex); 231 ring_info->ring_buffer->write_index);
229} 232}
230 233
231 234
232/* Internal routines */ 235/* Internal routines */
233 236
234static u32 237static u32
235CopyToRingBuffer( 238copyto_ringbuffer(
236 struct hv_ring_buffer_info *RingInfo, 239 struct hv_ring_buffer_info *ring_info,
237 u32 StartWriteOffset, 240 u32 start_write_offset,
238 void *Src, 241 void *src,
239 u32 SrcLen); 242 u32 srclen);
240 243
241static u32 244static u32
242CopyFromRingBuffer( 245copyfrom_ringbuffer(
243 struct hv_ring_buffer_info *RingInfo, 246 struct hv_ring_buffer_info *ring_info,
244 void *Dest, 247 void *dest,
245 u32 DestLen, 248 u32 destlen,
246 u32 StartReadOffset); 249 u32 start_read_offset);
247 250
248 251
249 252
250/*++ 253/*++
251 254
252Name: 255Name:
253 RingBufferGetDebugInfo() 256 ringbuffer_get_debuginfo()
254 257
255Description: 258Description:
256 Get various debug metrics for the specified ring buffer 259 Get various debug metrics for the specified ring buffer
257 260
258--*/ 261--*/
259void RingBufferGetDebugInfo(struct hv_ring_buffer_info *RingInfo, 262void ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info,
260 struct hv_ring_buffer_debug_info *debug_info) 263 struct hv_ring_buffer_debug_info *debug_info)
261{ 264{
262 u32 bytesAvailToWrite; 265 u32 bytes_avail_towrite;
263 u32 bytesAvailToRead; 266 u32 bytes_avail_toread;
264 267
265 if (RingInfo->RingBuffer) { 268 if (ring_info->ring_buffer) {
266 GetRingBufferAvailBytes(RingInfo, 269 get_ringbuffer_availbytes(ring_info,
267 &bytesAvailToRead, 270 &bytes_avail_toread,
268 &bytesAvailToWrite); 271 &bytes_avail_towrite);
269 272
270 debug_info->BytesAvailToRead = bytesAvailToRead; 273 debug_info->bytes_avail_toread = bytes_avail_toread;
271 debug_info->BytesAvailToWrite = bytesAvailToWrite; 274 debug_info->bytes_avail_towrite = bytes_avail_towrite;
272 debug_info->CurrentReadIndex = RingInfo->RingBuffer->ReadIndex; 275 debug_info->current_read_index =
273 debug_info->CurrentWriteIndex = RingInfo->RingBuffer->WriteIndex; 276 ring_info->ring_buffer->read_index;
274 debug_info->CurrentInterruptMask = RingInfo->RingBuffer->InterruptMask; 277 debug_info->current_write_index =
278 ring_info->ring_buffer->write_index;
279 debug_info->current_interrupt_mask =
280 ring_info->ring_buffer->interrupt_mask;
275 } 281 }
276} 282}
277 283
@@ -279,40 +285,42 @@ void RingBufferGetDebugInfo(struct hv_ring_buffer_info *RingInfo,
279/*++ 285/*++
280 286
281Name: 287Name:
282 GetRingBufferInterruptMask() 288 get_ringbuffer_interrupt_mask()
283 289
284Description: 290Description:
285 Get the interrupt mask for the specified ring buffer 291 Get the interrupt mask for the specified ring buffer
286 292
287--*/ 293--*/
288u32 GetRingBufferInterruptMask(struct hv_ring_buffer_info *rbi) 294u32 get_ringbuffer_interrupt_mask(struct hv_ring_buffer_info *rbi)
289{ 295{
290 return rbi->RingBuffer->InterruptMask; 296 return rbi->ring_buffer->interrupt_mask;
291} 297}
292 298
293/*++ 299/*++
294 300
295Name: 301Name:
296 RingBufferInit() 302 ringbuffer_init()
297 303
298Description: 304Description:
299 Initialize the ring buffer 305 Initialize the ring buffer
300 306
301--*/ 307--*/
302int RingBufferInit(struct hv_ring_buffer_info *RingInfo, void *Buffer, u32 BufferLen) 308int ringbuffer_init(struct hv_ring_buffer_info *ring_info,
309 void *buffer, u32 buflen)
303{ 310{
304 if (sizeof(struct hv_ring_buffer) != PAGE_SIZE) 311 if (sizeof(struct hv_ring_buffer) != PAGE_SIZE)
305 return -EINVAL; 312 return -EINVAL;
306 313
307 memset(RingInfo, 0, sizeof(struct hv_ring_buffer_info)); 314 memset(ring_info, 0, sizeof(struct hv_ring_buffer_info));
308 315
309 RingInfo->RingBuffer = (struct hv_ring_buffer *)Buffer; 316 ring_info->ring_buffer = (struct hv_ring_buffer *)buffer;
310 RingInfo->RingBuffer->ReadIndex = RingInfo->RingBuffer->WriteIndex = 0; 317 ring_info->ring_buffer->read_index =
318 ring_info->ring_buffer->write_index = 0;
311 319
312 RingInfo->RingSize = BufferLen; 320 ring_info->ring_size = buflen;
313 RingInfo->RingDataSize = BufferLen - sizeof(struct hv_ring_buffer); 321 ring_info->ring_datasize = buflen - sizeof(struct hv_ring_buffer);
314 322
315 spin_lock_init(&RingInfo->ring_lock); 323 spin_lock_init(&ring_info->ring_lock);
316 324
317 return 0; 325 return 0;
318} 326}
@@ -320,97 +328,97 @@ int RingBufferInit(struct hv_ring_buffer_info *RingInfo, void *Buffer, u32 Buffe
320/*++ 328/*++
321 329
322Name: 330Name:
323 RingBufferCleanup() 331 ringbuffer_cleanup()
324 332
325Description: 333Description:
326 Cleanup the ring buffer 334 Cleanup the ring buffer
327 335
328--*/ 336--*/
329void RingBufferCleanup(struct hv_ring_buffer_info *RingInfo) 337void ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info)
330{ 338{
331} 339}
332 340
333/*++ 341/*++
334 342
335Name: 343Name:
336 RingBufferWrite() 344 ringbuffer_write()
337 345
338Description: 346Description:
339 Write to the ring buffer 347 Write to the ring buffer
340 348
341--*/ 349--*/
342int RingBufferWrite(struct hv_ring_buffer_info *OutRingInfo, 350int ringbuffer_write(struct hv_ring_buffer_info *outring_info,
343 struct scatterlist *sglist, u32 sgcount) 351 struct scatterlist *sglist, u32 sgcount)
344{ 352{
345 int i = 0; 353 int i = 0;
346 u32 byteAvailToWrite; 354 u32 bytes_avail_towrite;
347 u32 byteAvailToRead; 355 u32 bytes_avail_toread;
348 u32 totalBytesToWrite = 0; 356 u32 totalbytes_towrite = 0;
349 357
350 struct scatterlist *sg; 358 struct scatterlist *sg;
351 volatile u32 nextWriteLocation; 359 volatile u32 next_write_location;
352 u64 prevIndices = 0; 360 u64 prev_indices = 0;
353 unsigned long flags; 361 unsigned long flags;
354 362
355 for_each_sg(sglist, sg, sgcount, i) 363 for_each_sg(sglist, sg, sgcount, i)
356 { 364 {
357 totalBytesToWrite += sg->length; 365 totalbytes_towrite += sg->length;
358 } 366 }
359 367
360 totalBytesToWrite += sizeof(u64); 368 totalbytes_towrite += sizeof(u64);
361 369
362 spin_lock_irqsave(&OutRingInfo->ring_lock, flags); 370 spin_lock_irqsave(&outring_info->ring_lock, flags);
363 371
364 GetRingBufferAvailBytes(OutRingInfo, 372 get_ringbuffer_availbytes(outring_info,
365 &byteAvailToRead, 373 &bytes_avail_toread,
366 &byteAvailToWrite); 374 &bytes_avail_towrite);
367 375
368 DPRINT_DBG(VMBUS, "Writing %u bytes...", totalBytesToWrite); 376 DPRINT_DBG(VMBUS, "Writing %u bytes...", totalbytes_towrite);
369 377
370 /* DumpRingInfo(OutRingInfo, "BEFORE "); */ 378 /* Dumpring_info(Outring_info, "BEFORE "); */
371 379
372 /* If there is only room for the packet, assume it is full. */ 380 /* If there is only room for the packet, assume it is full. */
373 /* Otherwise, the next time around, we think the ring buffer */ 381 /* Otherwise, the next time around, we think the ring buffer */
374 /* is empty since the read index == write index */ 382 /* is empty since the read index == write index */
375 if (byteAvailToWrite <= totalBytesToWrite) { 383 if (bytes_avail_towrite <= totalbytes_towrite) {
376 DPRINT_DBG(VMBUS, 384 DPRINT_DBG(VMBUS,
377 "No more space left on outbound ring buffer " 385 "No more space left on outbound ring buffer "
378 "(needed %u, avail %u)", 386 "(needed %u, avail %u)",
379 totalBytesToWrite, 387 totalbytes_towrite,
380 byteAvailToWrite); 388 bytes_avail_towrite);
381 389
382 spin_unlock_irqrestore(&OutRingInfo->ring_lock, flags); 390 spin_unlock_irqrestore(&outring_info->ring_lock, flags);
383 return -1; 391 return -1;
384 } 392 }
385 393
386 /* Write to the ring buffer */ 394 /* Write to the ring buffer */
387 nextWriteLocation = GetNextWriteLocation(OutRingInfo); 395 next_write_location = get_next_write_location(outring_info);
388 396
389 for_each_sg(sglist, sg, sgcount, i) 397 for_each_sg(sglist, sg, sgcount, i)
390 { 398 {
391 nextWriteLocation = CopyToRingBuffer(OutRingInfo, 399 next_write_location = copyto_ringbuffer(outring_info,
392 nextWriteLocation, 400 next_write_location,
393 sg_virt(sg), 401 sg_virt(sg),
394 sg->length); 402 sg->length);
395 } 403 }
396 404
397 /* Set previous packet start */ 405 /* Set previous packet start */
398 prevIndices = GetRingBufferIndices(OutRingInfo); 406 prev_indices = get_ring_bufferindices(outring_info);
399 407
400 nextWriteLocation = CopyToRingBuffer(OutRingInfo, 408 next_write_location = copyto_ringbuffer(outring_info,
401 nextWriteLocation, 409 next_write_location,
402 &prevIndices, 410 &prev_indices,
403 sizeof(u64)); 411 sizeof(u64));
404 412
405 /* Make sure we flush all writes before updating the writeIndex */ 413 /* Make sure we flush all writes before updating the writeIndex */
406 mb(); 414 mb();
407 415
408 /* Now, update the write location */ 416 /* Now, update the write location */
409 SetNextWriteLocation(OutRingInfo, nextWriteLocation); 417 set_next_write_location(outring_info, next_write_location);
410 418
411 /* DumpRingInfo(OutRingInfo, "AFTER "); */ 419 /* Dumpring_info(Outring_info, "AFTER "); */
412 420
413 spin_unlock_irqrestore(&OutRingInfo->ring_lock, flags); 421 spin_unlock_irqrestore(&outring_info->ring_lock, flags);
414 return 0; 422 return 0;
415} 423}
416 424
@@ -418,47 +426,48 @@ int RingBufferWrite(struct hv_ring_buffer_info *OutRingInfo,
418/*++ 426/*++
419 427
420Name: 428Name:
421 RingBufferPeek() 429 ringbuffer_peek()
422 430
423Description: 431Description:
424 Read without advancing the read index 432 Read without advancing the read index
425 433
426--*/ 434--*/
427int RingBufferPeek(struct hv_ring_buffer_info *InRingInfo, void *Buffer, u32 BufferLen) 435int ringbuffer_peek(struct hv_ring_buffer_info *Inring_info,
436 void *Buffer, u32 buflen)
428{ 437{
429 u32 bytesAvailToWrite; 438 u32 bytes_avail_towrite;
430 u32 bytesAvailToRead; 439 u32 bytes_avail_toread;
431 u32 nextReadLocation = 0; 440 u32 next_read_location = 0;
432 unsigned long flags; 441 unsigned long flags;
433 442
434 spin_lock_irqsave(&InRingInfo->ring_lock, flags); 443 spin_lock_irqsave(&Inring_info->ring_lock, flags);
435 444
436 GetRingBufferAvailBytes(InRingInfo, 445 get_ringbuffer_availbytes(Inring_info,
437 &bytesAvailToRead, 446 &bytes_avail_toread,
438 &bytesAvailToWrite); 447 &bytes_avail_towrite);
439 448
440 /* Make sure there is something to read */ 449 /* Make sure there is something to read */
441 if (bytesAvailToRead < BufferLen) { 450 if (bytes_avail_toread < buflen) {
442 /* DPRINT_DBG(VMBUS, 451 /* DPRINT_DBG(VMBUS,
443 "got callback but not enough to read " 452 "got callback but not enough to read "
444 "<avail to read %d read size %d>!!", 453 "<avail to read %d read size %d>!!",
445 bytesAvailToRead, 454 bytes_avail_toread,
446 BufferLen); */ 455 BufferLen); */
447 456
448 spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); 457 spin_unlock_irqrestore(&Inring_info->ring_lock, flags);
449 458
450 return -1; 459 return -1;
451 } 460 }
452 461
453 /* Convert to byte offset */ 462 /* Convert to byte offset */
454 nextReadLocation = GetNextReadLocation(InRingInfo); 463 next_read_location = get_next_read_location(Inring_info);
455 464
456 nextReadLocation = CopyFromRingBuffer(InRingInfo, 465 next_read_location = copyfrom_ringbuffer(Inring_info,
457 Buffer, 466 Buffer,
458 BufferLen, 467 buflen,
459 nextReadLocation); 468 next_read_location);
460 469
461 spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); 470 spin_unlock_irqrestore(&Inring_info->ring_lock, flags);
462 471
463 return 0; 472 return 0;
464} 473}
@@ -467,58 +476,59 @@ int RingBufferPeek(struct hv_ring_buffer_info *InRingInfo, void *Buffer, u32 Buf
467/*++ 476/*++
468 477
469Name: 478Name:
470 RingBufferRead() 479 ringbuffer_read()
471 480
472Description: 481Description:
473 Read and advance the read index 482 Read and advance the read index
474 483
475--*/ 484--*/
476int RingBufferRead(struct hv_ring_buffer_info *InRingInfo, void *Buffer, 485int ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer,
477 u32 BufferLen, u32 Offset) 486 u32 buflen, u32 offset)
478{ 487{
479 u32 bytesAvailToWrite; 488 u32 bytes_avail_towrite;
480 u32 bytesAvailToRead; 489 u32 bytes_avail_toread;
481 u32 nextReadLocation = 0; 490 u32 next_read_location = 0;
482 u64 prevIndices = 0; 491 u64 prev_indices = 0;
483 unsigned long flags; 492 unsigned long flags;
484 493
485 if (BufferLen <= 0) 494 if (buflen <= 0)
486 return -EINVAL; 495 return -EINVAL;
487 496
488 spin_lock_irqsave(&InRingInfo->ring_lock, flags); 497 spin_lock_irqsave(&inring_info->ring_lock, flags);
489 498
490 GetRingBufferAvailBytes(InRingInfo, 499 get_ringbuffer_availbytes(inring_info,
491 &bytesAvailToRead, 500 &bytes_avail_toread,
492 &bytesAvailToWrite); 501 &bytes_avail_towrite);
493 502
494 DPRINT_DBG(VMBUS, "Reading %u bytes...", BufferLen); 503 DPRINT_DBG(VMBUS, "Reading %u bytes...", buflen);
495 504
496 /* DumpRingInfo(InRingInfo, "BEFORE "); */ 505 /* Dumpring_info(Inring_info, "BEFORE "); */
497 506
498 /* Make sure there is something to read */ 507 /* Make sure there is something to read */
499 if (bytesAvailToRead < BufferLen) { 508 if (bytes_avail_toread < buflen) {
500 DPRINT_DBG(VMBUS, 509 DPRINT_DBG(VMBUS,
501 "got callback but not enough to read " 510 "got callback but not enough to read "
502 "<avail to read %d read size %d>!!", 511 "<avail to read %d read size %d>!!",
503 bytesAvailToRead, 512 bytes_avail_toread,
504 BufferLen); 513 buflen);
505 514
506 spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); 515 spin_unlock_irqrestore(&inring_info->ring_lock, flags);
507 516
508 return -1; 517 return -1;
509 } 518 }
510 519
511 nextReadLocation = GetNextReadLocationWithOffset(InRingInfo, Offset); 520 next_read_location =
521 get_next_readlocation_withoffset(inring_info, offset);
512 522
513 nextReadLocation = CopyFromRingBuffer(InRingInfo, 523 next_read_location = copyfrom_ringbuffer(inring_info,
514 Buffer, 524 buffer,
515 BufferLen, 525 buflen,
516 nextReadLocation); 526 next_read_location);
517 527
518 nextReadLocation = CopyFromRingBuffer(InRingInfo, 528 next_read_location = copyfrom_ringbuffer(inring_info,
519 &prevIndices, 529 &prev_indices,
520 sizeof(u64), 530 sizeof(u64),
521 nextReadLocation); 531 next_read_location);
522 532
523 /* Make sure all reads are done before we update the read index since */ 533 /* Make sure all reads are done before we update the read index since */
524 /* the writer may start writing to the read area once the read index */ 534 /* the writer may start writing to the read area once the read index */
@@ -526,11 +536,11 @@ int RingBufferRead(struct hv_ring_buffer_info *InRingInfo, void *Buffer,
526 mb(); 536 mb();
527 537
528 /* Update the read index */ 538 /* Update the read index */
529 SetNextReadLocation(InRingInfo, nextReadLocation); 539 set_next_read_location(inring_info, next_read_location);
530 540
531 /* DumpRingInfo(InRingInfo, "AFTER "); */ 541 /* Dumpring_info(Inring_info, "AFTER "); */
532 542
533 spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); 543 spin_unlock_irqrestore(&inring_info->ring_lock, flags);
534 544
535 return 0; 545 return 0;
536} 546}
@@ -539,7 +549,7 @@ int RingBufferRead(struct hv_ring_buffer_info *InRingInfo, void *Buffer,
539/*++ 549/*++
540 550
541Name: 551Name:
542 CopyToRingBuffer() 552 copyto_ringbuffer()
543 553
544Description: 554Description:
545 Helper routine to copy from source to ring buffer. 555 Helper routine to copy from source to ring buffer.
@@ -547,37 +557,37 @@ Description:
547 557
548--*/ 558--*/
549static u32 559static u32
550CopyToRingBuffer( 560copyto_ringbuffer(
551 struct hv_ring_buffer_info *RingInfo, 561 struct hv_ring_buffer_info *ring_info,
552 u32 StartWriteOffset, 562 u32 start_write_offset,
553 void *Src, 563 void *src,
554 u32 SrcLen) 564 u32 srclen)
555{ 565{
556 void *ringBuffer = GetRingBuffer(RingInfo); 566 void *ring_buffer = get_ring_buffer(ring_info);
557 u32 ringBufferSize = GetRingBufferSize(RingInfo); 567 u32 ring_buffer_size = get_ring_buffersize(ring_info);
558 u32 fragLen; 568 u32 frag_len;
559 569
560 /* wrap-around detected! */ 570 /* wrap-around detected! */
561 if (SrcLen > ringBufferSize - StartWriteOffset) { 571 if (srclen > ring_buffer_size - start_write_offset) {
562 DPRINT_DBG(VMBUS, "wrap-around detected!"); 572 DPRINT_DBG(VMBUS, "wrap-around detected!");
563 573
564 fragLen = ringBufferSize - StartWriteOffset; 574 frag_len = ring_buffer_size - start_write_offset;
565 memcpy(ringBuffer + StartWriteOffset, Src, fragLen); 575 memcpy(ring_buffer + start_write_offset, src, frag_len);
566 memcpy(ringBuffer, Src + fragLen, SrcLen - fragLen); 576 memcpy(ring_buffer, src + frag_len, srclen - frag_len);
567 } else 577 } else
568 memcpy(ringBuffer + StartWriteOffset, Src, SrcLen); 578 memcpy(ring_buffer + start_write_offset, src, srclen);
569 579
570 StartWriteOffset += SrcLen; 580 start_write_offset += srclen;
571 StartWriteOffset %= ringBufferSize; 581 start_write_offset %= ring_buffer_size;
572 582
573 return StartWriteOffset; 583 return start_write_offset;
574} 584}
575 585
576 586
577/*++ 587/*++
578 588
579Name: 589Name:
580 CopyFromRingBuffer() 590 copyfrom_ringbuffer()
581 591
582Description: 592Description:
583 Helper routine to copy to source from ring buffer. 593 Helper routine to copy to source from ring buffer.
@@ -585,34 +595,34 @@ Description:
585 595
586--*/ 596--*/
587static u32 597static u32
588CopyFromRingBuffer( 598copyfrom_ringbuffer(
589 struct hv_ring_buffer_info *RingInfo, 599 struct hv_ring_buffer_info *ring_info,
590 void *Dest, 600 void *dest,
591 u32 DestLen, 601 u32 destlen,
592 u32 StartReadOffset) 602 u32 start_read_offset)
593{ 603{
594 void *ringBuffer = GetRingBuffer(RingInfo); 604 void *ring_buffer = get_ring_buffer(ring_info);
595 u32 ringBufferSize = GetRingBufferSize(RingInfo); 605 u32 ring_buffer_size = get_ring_buffersize(ring_info);
596 606
597 u32 fragLen; 607 u32 frag_len;
598 608
599 /* wrap-around detected at the src */ 609 /* wrap-around detected at the src */
600 if (DestLen > ringBufferSize - StartReadOffset) { 610 if (destlen > ring_buffer_size - start_read_offset) {
601 DPRINT_DBG(VMBUS, "src wrap-around detected!"); 611 DPRINT_DBG(VMBUS, "src wrap-around detected!");
602 612
603 fragLen = ringBufferSize - StartReadOffset; 613 frag_len = ring_buffer_size - start_read_offset;
604 614
605 memcpy(Dest, ringBuffer + StartReadOffset, fragLen); 615 memcpy(dest, ring_buffer + start_read_offset, frag_len);
606 memcpy(Dest + fragLen, ringBuffer, DestLen - fragLen); 616 memcpy(dest + frag_len, ring_buffer, destlen - frag_len);
607 } else 617 } else
608 618
609 memcpy(Dest, ringBuffer + StartReadOffset, DestLen); 619 memcpy(dest, ring_buffer + start_read_offset, destlen);
610 620
611 621
612 StartReadOffset += DestLen; 622 start_read_offset += destlen;
613 StartReadOffset %= ringBufferSize; 623 start_read_offset %= ring_buffer_size;
614 624
615 return StartReadOffset; 625 return start_read_offset;
616} 626}
617 627
618 628
diff --git a/drivers/staging/hv/ring_buffer.h b/drivers/staging/hv/ring_buffer.h
index a7f1717c6a56..7bd6ecf2f015 100644
--- a/drivers/staging/hv/ring_buffer.h
+++ b/drivers/staging/hv/ring_buffer.h
@@ -29,18 +29,18 @@
29 29
30struct hv_ring_buffer { 30struct hv_ring_buffer {
31 /* Offset in bytes from the start of ring data below */ 31 /* Offset in bytes from the start of ring data below */
32 volatile u32 WriteIndex; 32 volatile u32 write_index;
33 33
34 /* Offset in bytes from the start of ring data below */ 34 /* Offset in bytes from the start of ring data below */
35 volatile u32 ReadIndex; 35 volatile u32 read_index;
36 36
37 volatile u32 InterruptMask; 37 volatile u32 interrupt_mask;
38 38
39 /* Pad it to PAGE_SIZE so that data starts on page boundary */ 39 /* Pad it to PAGE_SIZE so that data starts on page boundary */
40 u8 Reserved[4084]; 40 u8 reserved[4084];
41 41
42 /* NOTE: 42 /* NOTE:
43 * The InterruptMask field is used only for channels but since our 43 * The interrupt_mask field is used only for channels but since our
44 * vmbus connection also uses this data structure and its data starts 44 * vmbus connection also uses this data structure and its data starts
45 * here, we commented out this field. 45 * here, we commented out this field.
46 */ 46 */
@@ -50,24 +50,24 @@ struct hv_ring_buffer {
50 * Ring data starts here + RingDataStartOffset 50 * Ring data starts here + RingDataStartOffset
51 * !!! DO NOT place any fields below this !!! 51 * !!! DO NOT place any fields below this !!!
52 */ 52 */
53 u8 Buffer[0]; 53 u8 buffer[0];
54} __attribute__((packed)); 54} __attribute__((packed));
55 55
56struct hv_ring_buffer_info { 56struct hv_ring_buffer_info {
57 struct hv_ring_buffer *RingBuffer; 57 struct hv_ring_buffer *ring_buffer;
58 u32 RingSize; /* Include the shared header */ 58 u32 ring_size; /* Include the shared header */
59 spinlock_t ring_lock; 59 spinlock_t ring_lock;
60 60
61 u32 RingDataSize; /* < ringSize */ 61 u32 ring_datasize; /* < ring_size */
62 u32 RingDataStartOffset; 62 u32 ring_data_startoffset;
63}; 63};
64 64
65struct hv_ring_buffer_debug_info { 65struct hv_ring_buffer_debug_info {
66 u32 CurrentInterruptMask; 66 u32 current_interrupt_mask;
67 u32 CurrentReadIndex; 67 u32 current_read_index;
68 u32 CurrentWriteIndex; 68 u32 current_write_index;
69 u32 BytesAvailToRead; 69 u32 bytes_avail_toread;
70 u32 BytesAvailToWrite; 70 u32 bytes_avail_towrite;
71}; 71};
72 72
73 73
@@ -75,28 +75,28 @@ struct hv_ring_buffer_debug_info {
75/* Interface */ 75/* Interface */
76 76
77 77
78int RingBufferInit(struct hv_ring_buffer_info *RingInfo, void *Buffer, 78int ringbuffer_init(struct hv_ring_buffer_info *ring_info, void *buffer,
79 u32 BufferLen); 79 u32 buflen);
80 80
81void RingBufferCleanup(struct hv_ring_buffer_info *RingInfo); 81void ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info);
82 82
83int RingBufferWrite(struct hv_ring_buffer_info *RingInfo, 83int ringbuffer_write(struct hv_ring_buffer_info *ring_info,
84 struct scatterlist *sglist, 84 struct scatterlist *sglist,
85 u32 sgcount); 85 u32 sgcount);
86 86
87int RingBufferPeek(struct hv_ring_buffer_info *RingInfo, void *Buffer, 87int ringbuffer_peek(struct hv_ring_buffer_info *ring_info, void *buffer,
88 u32 BufferLen); 88 u32 buflen);
89 89
90int RingBufferRead(struct hv_ring_buffer_info *RingInfo, 90int ringbuffer_read(struct hv_ring_buffer_info *ring_info,
91 void *Buffer, 91 void *buffer,
92 u32 BufferLen, 92 u32 buflen,
93 u32 Offset); 93 u32 offset);
94 94
95u32 GetRingBufferInterruptMask(struct hv_ring_buffer_info *RingInfo); 95u32 get_ringbuffer_interrupt_mask(struct hv_ring_buffer_info *ring_info);
96 96
97void DumpRingInfo(struct hv_ring_buffer_info *RingInfo, char *Prefix); 97void dump_ring_info(struct hv_ring_buffer_info *ring_info, char *prefix);
98 98
99void RingBufferGetDebugInfo(struct hv_ring_buffer_info *RingInfo, 99void ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info,
100 struct hv_ring_buffer_debug_info *debug_info); 100 struct hv_ring_buffer_debug_info *debug_info);
101 101
102#endif /* _RING_BUFFER_H_ */ 102#endif /* _RING_BUFFER_H_ */
diff --git a/drivers/staging/hv/rndis.h b/drivers/staging/hv/rndis.h
index 723e1f15b90d..014de047b86d 100644
--- a/drivers/staging/hv/rndis.h
+++ b/drivers/staging/hv/rndis.h
@@ -288,24 +288,24 @@
288#define RNDIS_DF_RAW_DATA 0x00000004 288#define RNDIS_DF_RAW_DATA 0x00000004
289 289
290/* Remote NDIS medium types. */ 290/* Remote NDIS medium types. */
291#define RNdisMedium802_3 0x00000000 291#define RNDIS_MEDIUM_802_3 0x00000000
292#define RNdisMedium802_5 0x00000001 292#define RNDIS_MEDIUM_802_5 0x00000001
293#define RNdisMediumFddi 0x00000002 293#define RNDIS_MEDIUM_FDDI 0x00000002
294#define RNdisMediumWan 0x00000003 294#define RNDIS_MEDIUM_WAN 0x00000003
295#define RNdisMediumLocalTalk 0x00000004 295#define RNDIS_MEDIUM_LOCAL_TALK 0x00000004
296#define RNdisMediumArcnetRaw 0x00000006 296#define RNDIS_MEDIUM_ARCNET_RAW 0x00000006
297#define RNdisMediumArcnet878_2 0x00000007 297#define RNDIS_MEDIUM_ARCNET_878_2 0x00000007
298#define RNdisMediumAtm 0x00000008 298#define RNDIS_MEDIUM_ATM 0x00000008
299#define RNdisMediumWirelessWan 0x00000009 299#define RNDIS_MEDIUM_WIRELESS_WAN 0x00000009
300#define RNdisMediumIrda 0x0000000a 300#define RNDIS_MEDIUM_IRDA 0x0000000a
301#define RNdisMediumCoWan 0x0000000b 301#define RNDIS_MEDIUM_CO_WAN 0x0000000b
302/* Not a real medium, defined as an upper-bound */ 302/* Not a real medium, defined as an upper-bound */
303#define RNdisMediumMax 0x0000000d 303#define RNDIS_MEDIUM_MAX 0x0000000d
304 304
305 305
306/* Remote NDIS medium connection states. */ 306/* Remote NDIS medium connection states. */
307#define RNdisMediaStateConnected 0x00000000 307#define RNDIS_MEDIA_STATE_CONNECTED 0x00000000
308#define RNdisMediaStateDisconnected 0x00000001 308#define RNDIS_MEDIA_STATE_DISCONNECTED 0x00000001
309 309
310/* Remote NDIS version numbers */ 310/* Remote NDIS version numbers */
311#define RNDIS_MAJOR_VERSION 0x00000001 311#define RNDIS_MAJOR_VERSION 0x00000001
@@ -314,106 +314,106 @@
314 314
315/* NdisInitialize message */ 315/* NdisInitialize message */
316struct rndis_initialize_request { 316struct rndis_initialize_request {
317 u32 RequestId; 317 u32 req_id;
318 u32 MajorVersion; 318 u32 major_ver;
319 u32 MinorVersion; 319 u32 minor_ver;
320 u32 MaxTransferSize; 320 u32 max_xfer_size;
321}; 321};
322 322
323/* Response to NdisInitialize */ 323/* Response to NdisInitialize */
324struct rndis_initialize_complete { 324struct rndis_initialize_complete {
325 u32 RequestId; 325 u32 req_id;
326 u32 Status; 326 u32 status;
327 u32 MajorVersion; 327 u32 major_ver;
328 u32 MinorVersion; 328 u32 minor_ver;
329 u32 DeviceFlags; 329 u32 dev_flags;
330 u32 Medium; 330 u32 medium;
331 u32 MaxPacketsPerMessage; 331 u32 max_pkt_per_msg;
332 u32 MaxTransferSize; 332 u32 max_xfer_size;
333 u32 PacketAlignmentFactor; 333 u32 pkt_alignment_factor;
334 u32 AFListOffset; 334 u32 af_list_offset;
335 u32 AFListSize; 335 u32 af_list_size;
336}; 336};
337 337
338/* Call manager devices only: Information about an address family */ 338/* Call manager devices only: Information about an address family */
339/* supported by the device is appended to the response to NdisInitialize. */ 339/* supported by the device is appended to the response to NdisInitialize. */
340struct rndis_co_address_family { 340struct rndis_co_address_family {
341 u32 AddressFamily; 341 u32 address_family;
342 u32 MajorVersion; 342 u32 major_ver;
343 u32 MinorVersion; 343 u32 minor_ver;
344}; 344};
345 345
346/* NdisHalt message */ 346/* NdisHalt message */
347struct rndis_halt_request { 347struct rndis_halt_request {
348 u32 RequestId; 348 u32 req_id;
349}; 349};
350 350
351/* NdisQueryRequest message */ 351/* NdisQueryRequest message */
352struct rndis_query_request { 352struct rndis_query_request {
353 u32 RequestId; 353 u32 req_id;
354 u32 Oid; 354 u32 oid;
355 u32 InformationBufferLength; 355 u32 info_buflen;
356 u32 InformationBufferOffset; 356 u32 info_buf_offset;
357 u32 DeviceVcHandle; 357 u32 dev_vc_handle;
358}; 358};
359 359
360/* Response to NdisQueryRequest */ 360/* Response to NdisQueryRequest */
361struct rndis_query_complete { 361struct rndis_query_complete {
362 u32 RequestId; 362 u32 req_id;
363 u32 Status; 363 u32 status;
364 u32 InformationBufferLength; 364 u32 info_buflen;
365 u32 InformationBufferOffset; 365 u32 info_buf_offset;
366}; 366};
367 367
368/* NdisSetRequest message */ 368/* NdisSetRequest message */
369struct rndis_set_request { 369struct rndis_set_request {
370 u32 RequestId; 370 u32 req_id;
371 u32 Oid; 371 u32 oid;
372 u32 InformationBufferLength; 372 u32 info_buflen;
373 u32 InformationBufferOffset; 373 u32 info_buf_offset;
374 u32 DeviceVcHandle; 374 u32 dev_vc_handle;
375}; 375};
376 376
377/* Response to NdisSetRequest */ 377/* Response to NdisSetRequest */
378struct rndis_set_complete { 378struct rndis_set_complete {
379 u32 RequestId; 379 u32 req_id;
380 u32 Status; 380 u32 status;
381}; 381};
382 382
383/* NdisReset message */ 383/* NdisReset message */
384struct rndis_reset_request { 384struct rndis_reset_request {
385 u32 Reserved; 385 u32 reserved;
386}; 386};
387 387
388/* Response to NdisReset */ 388/* Response to NdisReset */
389struct rndis_reset_complete { 389struct rndis_reset_complete {
390 u32 Status; 390 u32 status;
391 u32 AddressingReset; 391 u32 addressing_reset;
392}; 392};
393 393
394/* NdisMIndicateStatus message */ 394/* NdisMIndicateStatus message */
395struct rndis_indicate_status { 395struct rndis_indicate_status {
396 u32 Status; 396 u32 status;
397 u32 StatusBufferLength; 397 u32 status_buflen;
398 u32 StatusBufferOffset; 398 u32 status_buf_offset;
399}; 399};
400 400
401/* Diagnostic information passed as the status buffer in */ 401/* Diagnostic information passed as the status buffer in */
402/* struct rndis_indicate_status messages signifying error conditions. */ 402/* struct rndis_indicate_status messages signifying error conditions. */
403struct rndis_diagnostic_info { 403struct rndis_diagnostic_info {
404 u32 DiagStatus; 404 u32 diag_status;
405 u32 ErrorOffset; 405 u32 error_offset;
406}; 406};
407 407
408/* NdisKeepAlive message */ 408/* NdisKeepAlive message */
409struct rndis_keepalive_request { 409struct rndis_keepalive_request {
410 u32 RequestId; 410 u32 req_id;
411}; 411};
412 412
413/* Response to NdisKeepAlive */ 413/* Response to NdisKeepAlive */
414struct rndis_keepalive_complete { 414struct rndis_keepalive_complete {
415 u32 RequestId; 415 u32 req_id;
416 u32 Status; 416 u32 status;
417}; 417};
418 418
419/* 419/*
@@ -422,39 +422,39 @@ struct rndis_keepalive_complete {
422 * to 0 for connectionless data, otherwise it contains the VC handle. 422 * to 0 for connectionless data, otherwise it contains the VC handle.
423 */ 423 */
424struct rndis_packet { 424struct rndis_packet {
425 u32 DataOffset; 425 u32 data_offset;
426 u32 DataLength; 426 u32 data_len;
427 u32 OOBDataOffset; 427 u32 oob_data_offset;
428 u32 OOBDataLength; 428 u32 oob_data_len;
429 u32 NumOOBDataElements; 429 u32 num_oob_data_elements;
430 u32 PerPacketInfoOffset; 430 u32 per_pkt_info_offset;
431 u32 PerPacketInfoLength; 431 u32 per_pkt_info_len;
432 u32 VcHandle; 432 u32 vc_handle;
433 u32 Reserved; 433 u32 reserved;
434}; 434};
435 435
436/* Optional Out of Band data associated with a Data message. */ 436/* Optional Out of Band data associated with a Data message. */
437struct rndis_oobd { 437struct rndis_oobd {
438 u32 Size; 438 u32 size;
439 u32 Type; 439 u32 type;
440 u32 ClassInformationOffset; 440 u32 class_info_offset;
441}; 441};
442 442
443/* Packet extension field contents associated with a Data message. */ 443/* Packet extension field contents associated with a Data message. */
444struct rndis_per_packet_info { 444struct rndis_per_packet_info {
445 u32 Size; 445 u32 size;
446 u32 Type; 446 u32 type;
447 u32 PerPacketInformationOffset; 447 u32 per_pkt_info_offset;
448}; 448};
449 449
450/* Format of Information buffer passed in a SetRequest for the OID */ 450/* Format of Information buffer passed in a SetRequest for the OID */
451/* OID_GEN_RNDIS_CONFIG_PARAMETER. */ 451/* OID_GEN_RNDIS_CONFIG_PARAMETER. */
452struct rndis_config_parameter_info { 452struct rndis_config_parameter_info {
453 u32 ParameterNameOffset; 453 u32 parameter_name_offset;
454 u32 ParameterNameLength; 454 u32 parameter_name_length;
455 u32 ParameterType; 455 u32 parameter_type;
456 u32 ParameterValueOffset; 456 u32 parameter_value_offset;
457 u32 ParameterValueLength; 457 u32 parameter_value_length;
458}; 458};
459 459
460/* Values for ParameterType in struct rndis_config_parameter_info */ 460/* Values for ParameterType in struct rndis_config_parameter_info */
@@ -466,187 +466,188 @@ struct rndis_config_parameter_info {
466 466
467/* CoNdisMiniportCreateVc message */ 467/* CoNdisMiniportCreateVc message */
468struct rcondis_mp_create_vc { 468struct rcondis_mp_create_vc {
469 u32 RequestId; 469 u32 req_id;
470 u32 NdisVcHandle; 470 u32 ndis_vc_handle;
471}; 471};
472 472
473/* Response to CoNdisMiniportCreateVc */ 473/* Response to CoNdisMiniportCreateVc */
474struct rcondis_mp_create_vc_complete { 474struct rcondis_mp_create_vc_complete {
475 u32 RequestId; 475 u32 req_id;
476 u32 DeviceVcHandle; 476 u32 dev_vc_handle;
477 u32 Status; 477 u32 status;
478}; 478};
479 479
480/* CoNdisMiniportDeleteVc message */ 480/* CoNdisMiniportDeleteVc message */
481struct rcondis_mp_delete_vc { 481struct rcondis_mp_delete_vc {
482 u32 RequestId; 482 u32 req_id;
483 u32 DeviceVcHandle; 483 u32 dev_vc_handle;
484}; 484};
485 485
486/* Response to CoNdisMiniportDeleteVc */ 486/* Response to CoNdisMiniportDeleteVc */
487struct rcondis_mp_delete_vc_complete { 487struct rcondis_mp_delete_vc_complete {
488 u32 RequestId; 488 u32 req_id;
489 u32 Status; 489 u32 status;
490}; 490};
491 491
492/* CoNdisMiniportQueryRequest message */ 492/* CoNdisMiniportQueryRequest message */
493struct rcondis_mp_query_request { 493struct rcondis_mp_query_request {
494 u32 RequestId; 494 u32 req_id;
495 u32 RequestType; 495 u32 request_type;
496 u32 Oid; 496 u32 oid;
497 u32 DeviceVcHandle; 497 u32 dev_vc_handle;
498 u32 InformationBufferLength; 498 u32 info_buflen;
499 u32 InformationBufferOffset; 499 u32 info_buf_offset;
500}; 500};
501 501
502/* CoNdisMiniportSetRequest message */ 502/* CoNdisMiniportSetRequest message */
503struct rcondis_mp_set_request { 503struct rcondis_mp_set_request {
504 u32 RequestId; 504 u32 req_id;
505 u32 RequestType; 505 u32 request_type;
506 u32 Oid; 506 u32 oid;
507 u32 DeviceVcHandle; 507 u32 dev_vc_handle;
508 u32 InformationBufferLength; 508 u32 info_buflen;
509 u32 InformationBufferOffset; 509 u32 info_buf_offset;
510}; 510};
511 511
512/* CoNdisIndicateStatus message */ 512/* CoNdisIndicateStatus message */
513struct rcondis_indicate_status { 513struct rcondis_indicate_status {
514 u32 NdisVcHandle; 514 u32 ndis_vc_handle;
515 u32 Status; 515 u32 status;
516 u32 StatusBufferLength; 516 u32 status_buflen;
517 u32 StatusBufferOffset; 517 u32 status_buf_offset;
518}; 518};
519 519
520/* CONDIS Call/VC parameters */ 520/* CONDIS Call/VC parameters */
521struct rcondis_specific_parameters { 521struct rcondis_specific_parameters {
522 u32 ParameterType; 522 u32 parameter_type;
523 u32 ParameterLength; 523 u32 parameter_length;
524 u32 ParameterOffset; 524 u32 parameter_lffset;
525}; 525};
526 526
527struct rcondis_media_parameters { 527struct rcondis_media_parameters {
528 u32 Flags; 528 u32 flags;
529 u32 Reserved1; 529 u32 reserved1;
530 u32 Reserved2; 530 u32 reserved2;
531 struct rcondis_specific_parameters MediaSpecific; 531 struct rcondis_specific_parameters media_specific;
532}; 532};
533 533
534struct rndis_flowspec { 534struct rndis_flowspec {
535 u32 TokenRate; 535 u32 token_rate;
536 u32 TokenBucketSize; 536 u32 token_bucket_size;
537 u32 PeakBandwidth; 537 u32 peak_bandwidth;
538 u32 Latency; 538 u32 latency;
539 u32 DelayVariation; 539 u32 delay_variation;
540 u32 ServiceType; 540 u32 service_type;
541 u32 MaxSduSize; 541 u32 max_sdu_size;
542 u32 MinimumPolicedSize; 542 u32 minimum_policed_size;
543}; 543};
544 544
545struct rcondis_call_manager_parameters { 545struct rcondis_call_manager_parameters {
546 struct rndis_flowspec Transmit; 546 struct rndis_flowspec transmit;
547 struct rndis_flowspec Receive; 547 struct rndis_flowspec receive;
548 struct rcondis_specific_parameters CallMgrSpecific; 548 struct rcondis_specific_parameters call_mgr_specific;
549}; 549};
550 550
551/* CoNdisMiniportActivateVc message */ 551/* CoNdisMiniportActivateVc message */
552struct rcondis_mp_activate_vc_request { 552struct rcondis_mp_activate_vc_request {
553 u32 RequestId; 553 u32 req_id;
554 u32 Flags; 554 u32 flags;
555 u32 DeviceVcHandle; 555 u32 dev_vc_handle;
556 u32 MediaParamsOffset; 556 u32 media_params_offset;
557 u32 MediaParamsLength; 557 u32 media_params_length;
558 u32 CallMgrParamsOffset; 558 u32 call_mgr_params_offset;
559 u32 CallMgrParamsLength; 559 u32 call_mgr_params_length;
560}; 560};
561 561
562/* Response to CoNdisMiniportActivateVc */ 562/* Response to CoNdisMiniportActivateVc */
563struct rcondis_mp_activate_vc_complete { 563struct rcondis_mp_activate_vc_complete {
564 u32 RequestId; 564 u32 req_id;
565 u32 Status; 565 u32 status;
566}; 566};
567 567
568/* CoNdisMiniportDeactivateVc message */ 568/* CoNdisMiniportDeactivateVc message */
569struct rcondis_mp_deactivate_vc_request { 569struct rcondis_mp_deactivate_vc_request {
570 u32 RequestId; 570 u32 req_id;
571 u32 Flags; 571 u32 flags;
572 u32 DeviceVcHandle; 572 u32 dev_vc_handle;
573}; 573};
574 574
575/* Response to CoNdisMiniportDeactivateVc */ 575/* Response to CoNdisMiniportDeactivateVc */
576struct rcondis_mp_deactivate_vc_complete { 576struct rcondis_mp_deactivate_vc_complete {
577 u32 RequestId; 577 u32 req_id;
578 u32 Status; 578 u32 status;
579}; 579};
580 580
581 581
582/* union with all of the RNDIS messages */ 582/* union with all of the RNDIS messages */
583union rndis_message_container { 583union rndis_message_container {
584 struct rndis_packet Packet; 584 struct rndis_packet pkt;
585 struct rndis_initialize_request InitializeRequest; 585 struct rndis_initialize_request init_req;
586 struct rndis_halt_request HaltRequest; 586 struct rndis_halt_request halt_req;
587 struct rndis_query_request QueryRequest; 587 struct rndis_query_request query_req;
588 struct rndis_set_request SetRequest; 588 struct rndis_set_request set_req;
589 struct rndis_reset_request ResetRequest; 589 struct rndis_reset_request reset_req;
590 struct rndis_keepalive_request KeepaliveRequest; 590 struct rndis_keepalive_request keep_alive_req;
591 struct rndis_indicate_status IndicateStatus; 591 struct rndis_indicate_status indicate_status;
592 struct rndis_initialize_complete InitializeComplete; 592 struct rndis_initialize_complete init_complete;
593 struct rndis_query_complete QueryComplete; 593 struct rndis_query_complete query_complete;
594 struct rndis_set_complete SetComplete; 594 struct rndis_set_complete set_complete;
595 struct rndis_reset_complete ResetComplete; 595 struct rndis_reset_complete reset_complete;
596 struct rndis_keepalive_complete KeepaliveComplete; 596 struct rndis_keepalive_complete keep_alive_complete;
597 struct rcondis_mp_create_vc CoMiniportCreateVc; 597 struct rcondis_mp_create_vc co_miniport_create_vc;
598 struct rcondis_mp_delete_vc CoMiniportDeleteVc; 598 struct rcondis_mp_delete_vc co_miniport_delete_vc;
599 struct rcondis_indicate_status CoIndicateStatus; 599 struct rcondis_indicate_status co_indicate_status;
600 struct rcondis_mp_activate_vc_request CoMiniportActivateVc; 600 struct rcondis_mp_activate_vc_request co_miniport_activate_vc;
601 struct rcondis_mp_deactivate_vc_request CoMiniportDeactivateVc; 601 struct rcondis_mp_deactivate_vc_request co_miniport_deactivate_vc;
602 struct rcondis_mp_create_vc_complete CoMiniportCreateVcComplete; 602 struct rcondis_mp_create_vc_complete co_miniport_create_vc_complete;
603 struct rcondis_mp_delete_vc_complete CoMiniportDeleteVcComplete; 603 struct rcondis_mp_delete_vc_complete co_miniport_delete_vc_complete;
604 struct rcondis_mp_activate_vc_complete CoMiniportActivateVcComplete; 604 struct rcondis_mp_activate_vc_complete co_miniport_activate_vc_complete;
605 struct rcondis_mp_deactivate_vc_complete CoMiniportDeactivateVcComplete; 605 struct rcondis_mp_deactivate_vc_complete
606 co_miniport_deactivate_vc_complete;
606}; 607};
607 608
608/* Remote NDIS message format */ 609/* Remote NDIS message format */
609struct rndis_message { 610struct rndis_message {
610 u32 NdisMessageType; 611 u32 ndis_msg_type;
611 612
612 /* Total length of this message, from the beginning */ 613 /* Total length of this message, from the beginning */
613 /* of the sruct rndis_message, in bytes. */ 614 /* of the sruct rndis_message, in bytes. */
614 u32 MessageLength; 615 u32 msg_len;
615 616
616 /* Actual message */ 617 /* Actual message */
617 union rndis_message_container Message; 618 union rndis_message_container msg;
618}; 619};
619 620
620/* Handy macros */ 621/* Handy macros */
621 622
622/* get the size of an RNDIS message. Pass in the message type, */ 623/* get the size of an RNDIS message. Pass in the message type, */
623/* struct rndis_set_request, struct rndis_packet for example */ 624/* struct rndis_set_request, struct rndis_packet for example */
624#define RNDIS_MESSAGE_SIZE(Message) \ 625#define RNDIS_MESSAGE_SIZE(msg) \
625 (sizeof(Message) + (sizeof(struct rndis_message) - \ 626 (sizeof(msg) + (sizeof(struct rndis_message) - \
626 sizeof(union rndis_message_container))) 627 sizeof(union rndis_message_container)))
627 628
628/* get pointer to info buffer with message pointer */ 629/* get pointer to info buffer with message pointer */
629#define MESSAGE_TO_INFO_BUFFER(Message) \ 630#define MESSAGE_TO_INFO_BUFFER(msg) \
630 (((unsigned char *)(Message)) + Message->InformationBufferOffset) 631 (((unsigned char *)(msg)) + msg->info_buf_offset)
631 632
632/* get pointer to status buffer with message pointer */ 633/* get pointer to status buffer with message pointer */
633#define MESSAGE_TO_STATUS_BUFFER(Message) \ 634#define MESSAGE_TO_STATUS_BUFFER(msg) \
634 (((unsigned char *)(Message)) + Message->StatusBufferOffset) 635 (((unsigned char *)(msg)) + msg->status_buf_offset)
635 636
636/* get pointer to OOBD buffer with message pointer */ 637/* get pointer to OOBD buffer with message pointer */
637#define MESSAGE_TO_OOBD_BUFFER(Message) \ 638#define MESSAGE_TO_OOBD_BUFFER(msg) \
638 (((unsigned char *)(Message)) + Message->OOBDataOffset) 639 (((unsigned char *)(msg)) + msg->oob_data_offset)
639 640
640/* get pointer to data buffer with message pointer */ 641/* get pointer to data buffer with message pointer */
641#define MESSAGE_TO_DATA_BUFFER(Message) \ 642#define MESSAGE_TO_DATA_BUFFER(msg) \
642 (((unsigned char *)(Message)) + Message->PerPacketInfoOffset) 643 (((unsigned char *)(msg)) + msg->per_pkt_info_offset)
643 644
644/* get pointer to contained message from NDIS_MESSAGE pointer */ 645/* get pointer to contained message from NDIS_MESSAGE pointer */
645#define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(RndisMessage) \ 646#define RNDIS_MESSAGE_PTR_TO_MESSAGE_PTR(rndis_msg) \
646 ((void *) &RndisMessage->Message) 647 ((void *) &rndis_msg->msg)
647 648
648/* get pointer to contained message from NDIS_MESSAGE pointer */ 649/* get pointer to contained message from NDIS_MESSAGE pointer */
649#define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(RndisMessage) \ 650#define RNDIS_MESSAGE_RAW_PTR_TO_MESSAGE_PTR(rndis_msg) \
650 ((void *) RndisMessage) 651 ((void *) rndis_msg)
651 652
652#endif /* _RNDIS_H_ */ 653#endif /* _RNDIS_H_ */
diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c
index fa2141f454f0..53676dcbf381 100644
--- a/drivers/staging/hv/rndis_filter.c
+++ b/drivers/staging/hv/rndis_filter.c
@@ -32,7 +32,7 @@
32/* Data types */ 32/* Data types */
33struct rndis_filter_driver_object { 33struct rndis_filter_driver_object {
34 /* The original driver */ 34 /* The original driver */
35 struct netvsc_driver InnerDriver; 35 struct netvsc_driver inner_drv;
36}; 36};
37 37
38enum rndis_device_state { 38enum rndis_device_state {
@@ -43,63 +43,63 @@ enum rndis_device_state {
43}; 43};
44 44
45struct rndis_device { 45struct rndis_device {
46 struct netvsc_device *NetDevice; 46 struct netvsc_device *net_dev;
47 47
48 enum rndis_device_state State; 48 enum rndis_device_state state;
49 u32 LinkStatus; 49 u32 link_stat;
50 atomic_t NewRequestId; 50 atomic_t new_req_id;
51 51
52 spinlock_t request_lock; 52 spinlock_t request_lock;
53 struct list_head RequestList; 53 struct list_head req_list;
54 54
55 unsigned char HwMacAddr[ETH_ALEN]; 55 unsigned char hw_mac_adr[ETH_ALEN];
56}; 56};
57 57
58struct rndis_request { 58struct rndis_request {
59 struct list_head ListEntry; 59 struct list_head list_ent;
60 struct osd_waitevent *WaitEvent; 60 struct osd_waitevent *waitevent;
61 61
62 /* 62 /*
63 * FIXME: We assumed a fixed size response here. If we do ever need to 63 * FIXME: We assumed a fixed size response here. If we do ever need to
64 * handle a bigger response, we can either define a max response 64 * handle a bigger response, we can either define a max response
65 * message or add a response buffer variable above this field 65 * message or add a response buffer variable above this field
66 */ 66 */
67 struct rndis_message ResponseMessage; 67 struct rndis_message response_msg;
68 68
69 /* Simplify allocation by having a netvsc packet inline */ 69 /* Simplify allocation by having a netvsc packet inline */
70 struct hv_netvsc_packet Packet; 70 struct hv_netvsc_packet pkt;
71 struct hv_page_buffer Buffer; 71 struct hv_page_buffer buf;
72 /* FIXME: We assumed a fixed size request here. */ 72 /* FIXME: We assumed a fixed size request here. */
73 struct rndis_message RequestMessage; 73 struct rndis_message request_msg;
74}; 74};
75 75
76 76
77struct rndis_filter_packet { 77struct rndis_filter_packet {
78 void *CompletionContext; 78 void *completion_ctx;
79 void (*OnCompletion)(void *context); 79 void (*completion)(void *context);
80 struct rndis_message Message; 80 struct rndis_message msg;
81}; 81};
82 82
83 83
84static int RndisFilterOnDeviceAdd(struct hv_device *Device, 84static int rndis_filte_device_add(struct hv_device *dev,
85 void *AdditionalInfo); 85 void *additional_info);
86 86
87static int RndisFilterOnDeviceRemove(struct hv_device *Device); 87static int rndis_filter_device_remove(struct hv_device *dev);
88 88
89static void RndisFilterOnCleanup(struct hv_driver *Driver); 89static void rndis_filter_cleanup(struct hv_driver *drv);
90 90
91static int RndisFilterOnSend(struct hv_device *Device, 91static int rndis_filter_send(struct hv_device *dev,
92 struct hv_netvsc_packet *Packet); 92 struct hv_netvsc_packet *pkt);
93 93
94static void RndisFilterOnSendCompletion(void *Context); 94static void rndis_filter_send_completion(void *ctx);
95 95
96static void RndisFilterOnSendRequestCompletion(void *Context); 96static void rndis_filter_send_request_completion(void *ctx);
97 97
98 98
99/* The one and only */ 99/* The one and only */
100static struct rndis_filter_driver_object gRndisFilter; 100static struct rndis_filter_driver_object rndis_filter;
101 101
102static struct rndis_device *GetRndisDevice(void) 102static struct rndis_device *get_rndis_device(void)
103{ 103{
104 struct rndis_device *device; 104 struct rndis_device *device;
105 105
@@ -109,19 +109,19 @@ static struct rndis_device *GetRndisDevice(void)
109 109
110 spin_lock_init(&device->request_lock); 110 spin_lock_init(&device->request_lock);
111 111
112 INIT_LIST_HEAD(&device->RequestList); 112 INIT_LIST_HEAD(&device->req_list);
113 113
114 device->State = RNDIS_DEV_UNINITIALIZED; 114 device->state = RNDIS_DEV_UNINITIALIZED;
115 115
116 return device; 116 return device;
117} 117}
118 118
119static struct rndis_request *GetRndisRequest(struct rndis_device *Device, 119static struct rndis_request *get_rndis_request(struct rndis_device *dev,
120 u32 MessageType, 120 u32 msg_type,
121 u32 MessageLength) 121 u32 msg_len)
122{ 122{
123 struct rndis_request *request; 123 struct rndis_request *request;
124 struct rndis_message *rndisMessage; 124 struct rndis_message *rndis_msg;
125 struct rndis_set_request *set; 125 struct rndis_set_request *set;
126 unsigned long flags; 126 unsigned long flags;
127 127
@@ -129,61 +129,61 @@ static struct rndis_request *GetRndisRequest(struct rndis_device *Device,
129 if (!request) 129 if (!request)
130 return NULL; 130 return NULL;
131 131
132 request->WaitEvent = osd_WaitEventCreate(); 132 request->waitevent = osd_waitevent_create();
133 if (!request->WaitEvent) { 133 if (!request->waitevent) {
134 kfree(request); 134 kfree(request);
135 return NULL; 135 return NULL;
136 } 136 }
137 137
138 rndisMessage = &request->RequestMessage; 138 rndis_msg = &request->request_msg;
139 rndisMessage->NdisMessageType = MessageType; 139 rndis_msg->ndis_msg_type = msg_type;
140 rndisMessage->MessageLength = MessageLength; 140 rndis_msg->msg_len = msg_len;
141 141
142 /* 142 /*
143 * Set the request id. This field is always after the rndis header for 143 * Set the request id. This field is always after the rndis header for
144 * request/response packet types so we just used the SetRequest as a 144 * request/response packet types so we just used the SetRequest as a
145 * template 145 * template
146 */ 146 */
147 set = &rndisMessage->Message.SetRequest; 147 set = &rndis_msg->msg.set_req;
148 set->RequestId = atomic_inc_return(&Device->NewRequestId); 148 set->req_id = atomic_inc_return(&dev->new_req_id);
149 149
150 /* Add to the request list */ 150 /* Add to the request list */
151 spin_lock_irqsave(&Device->request_lock, flags); 151 spin_lock_irqsave(&dev->request_lock, flags);
152 list_add_tail(&request->ListEntry, &Device->RequestList); 152 list_add_tail(&request->list_ent, &dev->req_list);
153 spin_unlock_irqrestore(&Device->request_lock, flags); 153 spin_unlock_irqrestore(&dev->request_lock, flags);
154 154
155 return request; 155 return request;
156} 156}
157 157
158static void PutRndisRequest(struct rndis_device *Device, 158static void put_rndis_request(struct rndis_device *dev,
159 struct rndis_request *Request) 159 struct rndis_request *req)
160{ 160{
161 unsigned long flags; 161 unsigned long flags;
162 162
163 spin_lock_irqsave(&Device->request_lock, flags); 163 spin_lock_irqsave(&dev->request_lock, flags);
164 list_del(&Request->ListEntry); 164 list_del(&req->list_ent);
165 spin_unlock_irqrestore(&Device->request_lock, flags); 165 spin_unlock_irqrestore(&dev->request_lock, flags);
166 166
167 kfree(Request->WaitEvent); 167 kfree(req->waitevent);
168 kfree(Request); 168 kfree(req);
169} 169}
170 170
171static void DumpRndisMessage(struct rndis_message *RndisMessage) 171static void dump_rndis_message(struct rndis_message *rndis_msg)
172{ 172{
173 switch (RndisMessage->NdisMessageType) { 173 switch (rndis_msg->ndis_msg_type) {
174 case REMOTE_NDIS_PACKET_MSG: 174 case REMOTE_NDIS_PACKET_MSG:
175 DPRINT_DBG(NETVSC, "REMOTE_NDIS_PACKET_MSG (len %u, " 175 DPRINT_DBG(NETVSC, "REMOTE_NDIS_PACKET_MSG (len %u, "
176 "data offset %u data len %u, # oob %u, " 176 "data offset %u data len %u, # oob %u, "
177 "oob offset %u, oob len %u, pkt offset %u, " 177 "oob offset %u, oob len %u, pkt offset %u, "
178 "pkt len %u", 178 "pkt len %u",
179 RndisMessage->MessageLength, 179 rndis_msg->msg_len,
180 RndisMessage->Message.Packet.DataOffset, 180 rndis_msg->msg.pkt.data_offset,
181 RndisMessage->Message.Packet.DataLength, 181 rndis_msg->msg.pkt.data_len,
182 RndisMessage->Message.Packet.NumOOBDataElements, 182 rndis_msg->msg.pkt.num_oob_data_elements,
183 RndisMessage->Message.Packet.OOBDataOffset, 183 rndis_msg->msg.pkt.oob_data_offset,
184 RndisMessage->Message.Packet.OOBDataLength, 184 rndis_msg->msg.pkt.oob_data_len,
185 RndisMessage->Message.Packet.PerPacketInfoOffset, 185 rndis_msg->msg.pkt.per_pkt_info_offset,
186 RndisMessage->Message.Packet.PerPacketInfoLength); 186 rndis_msg->msg.pkt.per_pkt_info_len);
187 break; 187 break;
188 188
189 case REMOTE_NDIS_INITIALIZE_CMPLT: 189 case REMOTE_NDIS_INITIALIZE_CMPLT:
@@ -191,147 +191,157 @@ static void DumpRndisMessage(struct rndis_message *RndisMessage)
191 "(len %u, id 0x%x, status 0x%x, major %d, minor %d, " 191 "(len %u, id 0x%x, status 0x%x, major %d, minor %d, "
192 "device flags %d, max xfer size 0x%x, max pkts %u, " 192 "device flags %d, max xfer size 0x%x, max pkts %u, "
193 "pkt aligned %u)", 193 "pkt aligned %u)",
194 RndisMessage->MessageLength, 194 rndis_msg->msg_len,
195 RndisMessage->Message.InitializeComplete.RequestId, 195 rndis_msg->msg.init_complete.req_id,
196 RndisMessage->Message.InitializeComplete.Status, 196 rndis_msg->msg.init_complete.status,
197 RndisMessage->Message.InitializeComplete.MajorVersion, 197 rndis_msg->msg.init_complete.major_ver,
198 RndisMessage->Message.InitializeComplete.MinorVersion, 198 rndis_msg->msg.init_complete.minor_ver,
199 RndisMessage->Message.InitializeComplete.DeviceFlags, 199 rndis_msg->msg.init_complete.dev_flags,
200 RndisMessage->Message.InitializeComplete.MaxTransferSize, 200 rndis_msg->msg.init_complete.max_xfer_size,
201 RndisMessage->Message.InitializeComplete.MaxPacketsPerMessage, 201 rndis_msg->msg.init_complete.
202 RndisMessage->Message.InitializeComplete.PacketAlignmentFactor); 202 max_pkt_per_msg,
203 rndis_msg->msg.init_complete.
204 pkt_alignment_factor);
203 break; 205 break;
204 206
205 case REMOTE_NDIS_QUERY_CMPLT: 207 case REMOTE_NDIS_QUERY_CMPLT:
206 DPRINT_DBG(NETVSC, "REMOTE_NDIS_QUERY_CMPLT " 208 DPRINT_DBG(NETVSC, "REMOTE_NDIS_QUERY_CMPLT "
207 "(len %u, id 0x%x, status 0x%x, buf len %u, " 209 "(len %u, id 0x%x, status 0x%x, buf len %u, "
208 "buf offset %u)", 210 "buf offset %u)",
209 RndisMessage->MessageLength, 211 rndis_msg->msg_len,
210 RndisMessage->Message.QueryComplete.RequestId, 212 rndis_msg->msg.query_complete.req_id,
211 RndisMessage->Message.QueryComplete.Status, 213 rndis_msg->msg.query_complete.status,
212 RndisMessage->Message.QueryComplete.InformationBufferLength, 214 rndis_msg->msg.query_complete.
213 RndisMessage->Message.QueryComplete.InformationBufferOffset); 215 info_buflen,
216 rndis_msg->msg.query_complete.
217 info_buf_offset);
214 break; 218 break;
215 219
216 case REMOTE_NDIS_SET_CMPLT: 220 case REMOTE_NDIS_SET_CMPLT:
217 DPRINT_DBG(NETVSC, 221 DPRINT_DBG(NETVSC,
218 "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)", 222 "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)",
219 RndisMessage->MessageLength, 223 rndis_msg->msg_len,
220 RndisMessage->Message.SetComplete.RequestId, 224 rndis_msg->msg.set_complete.req_id,
221 RndisMessage->Message.SetComplete.Status); 225 rndis_msg->msg.set_complete.status);
222 break; 226 break;
223 227
224 case REMOTE_NDIS_INDICATE_STATUS_MSG: 228 case REMOTE_NDIS_INDICATE_STATUS_MSG:
225 DPRINT_DBG(NETVSC, "REMOTE_NDIS_INDICATE_STATUS_MSG " 229 DPRINT_DBG(NETVSC, "REMOTE_NDIS_INDICATE_STATUS_MSG "
226 "(len %u, status 0x%x, buf len %u, buf offset %u)", 230 "(len %u, status 0x%x, buf len %u, buf offset %u)",
227 RndisMessage->MessageLength, 231 rndis_msg->msg_len,
228 RndisMessage->Message.IndicateStatus.Status, 232 rndis_msg->msg.indicate_status.status,
229 RndisMessage->Message.IndicateStatus.StatusBufferLength, 233 rndis_msg->msg.indicate_status.status_buflen,
230 RndisMessage->Message.IndicateStatus.StatusBufferOffset); 234 rndis_msg->msg.indicate_status.status_buf_offset);
231 break; 235 break;
232 236
233 default: 237 default:
234 DPRINT_DBG(NETVSC, "0x%x (len %u)", 238 DPRINT_DBG(NETVSC, "0x%x (len %u)",
235 RndisMessage->NdisMessageType, 239 rndis_msg->ndis_msg_type,
236 RndisMessage->MessageLength); 240 rndis_msg->msg_len);
237 break; 241 break;
238 } 242 }
239} 243}
240 244
241static int RndisFilterSendRequest(struct rndis_device *Device, 245static int rndis_filter_send_request(struct rndis_device *dev,
242 struct rndis_request *Request) 246 struct rndis_request *req)
243{ 247{
244 int ret; 248 int ret;
245 struct hv_netvsc_packet *packet; 249 struct hv_netvsc_packet *packet;
246 250
247 /* Setup the packet to send it */ 251 /* Setup the packet to send it */
248 packet = &Request->Packet; 252 packet = &req->pkt;
249 253
250 packet->IsDataPacket = false; 254 packet->is_data_pkt = false;
251 packet->TotalDataBufferLength = Request->RequestMessage.MessageLength; 255 packet->total_data_buflen = req->request_msg.msg_len;
252 packet->PageBufferCount = 1; 256 packet->page_buf_cnt = 1;
253 257
254 packet->PageBuffers[0].Pfn = virt_to_phys(&Request->RequestMessage) >> 258 packet->page_buf[0].Pfn = virt_to_phys(&req->request_msg) >>
255 PAGE_SHIFT; 259 PAGE_SHIFT;
256 packet->PageBuffers[0].Length = Request->RequestMessage.MessageLength; 260 packet->page_buf[0].Length = req->request_msg.msg_len;
257 packet->PageBuffers[0].Offset = 261 packet->page_buf[0].Offset =
258 (unsigned long)&Request->RequestMessage & (PAGE_SIZE - 1); 262 (unsigned long)&req->request_msg & (PAGE_SIZE - 1);
259 263
260 packet->Completion.Send.SendCompletionContext = Request;/* packet; */ 264 packet->completion.send.send_completion_ctx = req;/* packet; */
261 packet->Completion.Send.OnSendCompletion = 265 packet->completion.send.send_completion =
262 RndisFilterOnSendRequestCompletion; 266 rndis_filter_send_request_completion;
263 packet->Completion.Send.SendCompletionTid = (unsigned long)Device; 267 packet->completion.send.send_completion_tid = (unsigned long)dev;
264 268
265 ret = gRndisFilter.InnerDriver.OnSend(Device->NetDevice->Device, packet); 269 ret = rndis_filter.inner_drv.send(dev->net_dev->dev, packet);
266 return ret; 270 return ret;
267} 271}
268 272
269static void RndisFilterReceiveResponse(struct rndis_device *Device, 273static void rndis_filter_receive_response(struct rndis_device *dev,
270 struct rndis_message *Response) 274 struct rndis_message *resp)
271{ 275{
272 struct rndis_request *request = NULL; 276 struct rndis_request *request = NULL;
273 bool found = false; 277 bool found = false;
274 unsigned long flags; 278 unsigned long flags;
275 279
276 spin_lock_irqsave(&Device->request_lock, flags); 280 spin_lock_irqsave(&dev->request_lock, flags);
277 list_for_each_entry(request, &Device->RequestList, ListEntry) { 281 list_for_each_entry(request, &dev->req_list, list_ent) {
278 /* 282 /*
279 * All request/response message contains RequestId as the 1st 283 * All request/response message contains RequestId as the 1st
280 * field 284 * field
281 */ 285 */
282 if (request->RequestMessage.Message.InitializeRequest.RequestId 286 if (request->request_msg.msg.init_req.req_id
283 == Response->Message.InitializeComplete.RequestId) { 287 == resp->msg.init_complete.req_id) {
284 DPRINT_DBG(NETVSC, "found rndis request for " 288 DPRINT_DBG(NETVSC, "found rndis request for "
285 "this response (id 0x%x req type 0x%x res " 289 "this response (id 0x%x req type 0x%x res "
286 "type 0x%x)", 290 "type 0x%x)",
287 request->RequestMessage.Message.InitializeRequest.RequestId, 291 request->request_msg.msg.
288 request->RequestMessage.NdisMessageType, 292 init_req.req_id,
289 Response->NdisMessageType); 293 request->request_msg.ndis_msg_type,
294 resp->ndis_msg_type);
290 295
291 found = true; 296 found = true;
292 break; 297 break;
293 } 298 }
294 } 299 }
295 spin_unlock_irqrestore(&Device->request_lock, flags); 300 spin_unlock_irqrestore(&dev->request_lock, flags);
296 301
297 if (found) { 302 if (found) {
298 if (Response->MessageLength <= sizeof(struct rndis_message)) { 303 if (resp->msg_len <= sizeof(struct rndis_message)) {
299 memcpy(&request->ResponseMessage, Response, 304 memcpy(&request->response_msg, resp,
300 Response->MessageLength); 305 resp->msg_len);
301 } else { 306 } else {
302 DPRINT_ERR(NETVSC, "rndis response buffer overflow " 307 DPRINT_ERR(NETVSC, "rndis response buffer overflow "
303 "detected (size %u max %zu)", 308 "detected (size %u max %zu)",
304 Response->MessageLength, 309 resp->msg_len,
305 sizeof(struct rndis_filter_packet)); 310 sizeof(struct rndis_filter_packet));
306 311
307 if (Response->NdisMessageType == 312 if (resp->ndis_msg_type ==
308 REMOTE_NDIS_RESET_CMPLT) { 313 REMOTE_NDIS_RESET_CMPLT) {
309 /* does not have a request id field */ 314 /* does not have a request id field */
310 request->ResponseMessage.Message.ResetComplete.Status = STATUS_BUFFER_OVERFLOW; 315 request->response_msg.msg.reset_complete.
316 status = STATUS_BUFFER_OVERFLOW;
311 } else { 317 } else {
312 request->ResponseMessage.Message.InitializeComplete.Status = STATUS_BUFFER_OVERFLOW; 318 request->response_msg.msg.
319 init_complete.status =
320 STATUS_BUFFER_OVERFLOW;
313 } 321 }
314 } 322 }
315 323
316 osd_WaitEventSet(request->WaitEvent); 324 osd_waitevent_set(request->waitevent);
317 } else { 325 } else {
318 DPRINT_ERR(NETVSC, "no rndis request found for this response " 326 DPRINT_ERR(NETVSC, "no rndis request found for this response "
319 "(id 0x%x res type 0x%x)", 327 "(id 0x%x res type 0x%x)",
320 Response->Message.InitializeComplete.RequestId, 328 resp->msg.init_complete.req_id,
321 Response->NdisMessageType); 329 resp->ndis_msg_type);
322 } 330 }
323} 331}
324 332
325static void RndisFilterReceiveIndicateStatus(struct rndis_device *Device, 333static void rndis_filter_receive_indicate_status(struct rndis_device *dev,
326 struct rndis_message *Response) 334 struct rndis_message *resp)
327{ 335{
328 struct rndis_indicate_status *indicate = 336 struct rndis_indicate_status *indicate =
329 &Response->Message.IndicateStatus; 337 &resp->msg.indicate_status;
330 338
331 if (indicate->Status == RNDIS_STATUS_MEDIA_CONNECT) { 339 if (indicate->status == RNDIS_STATUS_MEDIA_CONNECT) {
332 gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 1); 340 rndis_filter.inner_drv.link_status_change(
333 } else if (indicate->Status == RNDIS_STATUS_MEDIA_DISCONNECT) { 341 dev->net_dev->dev, 1);
334 gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 0); 342 } else if (indicate->status == RNDIS_STATUS_MEDIA_DISCONNECT) {
343 rndis_filter.inner_drv.link_status_change(
344 dev->net_dev->dev, 0);
335 } else { 345 } else {
336 /* 346 /*
337 * TODO: 347 * TODO:
@@ -339,18 +349,18 @@ static void RndisFilterReceiveIndicateStatus(struct rndis_device *Device,
339 } 349 }
340} 350}
341 351
342static void RndisFilterReceiveData(struct rndis_device *Device, 352static void rndis_filter_receive_data(struct rndis_device *dev,
343 struct rndis_message *Message, 353 struct rndis_message *msg,
344 struct hv_netvsc_packet *Packet) 354 struct hv_netvsc_packet *pkt)
345{ 355{
346 struct rndis_packet *rndisPacket; 356 struct rndis_packet *rndis_pkt;
347 u32 dataOffset; 357 u32 data_offset;
348 358
349 /* empty ethernet frame ?? */ 359 /* empty ethernet frame ?? */
350 /* ASSERT(Packet->PageBuffers[0].Length > */ 360 /* ASSERT(Packet->PageBuffers[0].Length > */
351 /* RNDIS_MESSAGE_SIZE(struct rndis_packet)); */ 361 /* RNDIS_MESSAGE_SIZE(struct rndis_packet)); */
352 362
353 rndisPacket = &Message->Message.Packet; 363 rndis_pkt = &msg->msg.pkt;
354 364
355 /* 365 /*
356 * FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this 366 * FIXME: Handle multiple rndis pkt msgs that maybe enclosed in this
@@ -358,48 +368,48 @@ static void RndisFilterReceiveData(struct rndis_device *Device,
358 */ 368 */
359 369
360 /* Remove the rndis header and pass it back up the stack */ 370 /* Remove the rndis header and pass it back up the stack */
361 dataOffset = RNDIS_HEADER_SIZE + rndisPacket->DataOffset; 371 data_offset = RNDIS_HEADER_SIZE + rndis_pkt->data_offset;
362 372
363 Packet->TotalDataBufferLength -= dataOffset; 373 pkt->total_data_buflen -= data_offset;
364 Packet->PageBuffers[0].Offset += dataOffset; 374 pkt->page_buf[0].Offset += data_offset;
365 Packet->PageBuffers[0].Length -= dataOffset; 375 pkt->page_buf[0].Length -= data_offset;
366 376
367 Packet->IsDataPacket = true; 377 pkt->is_data_pkt = true;
368 378
369 gRndisFilter.InnerDriver.OnReceiveCallback(Device->NetDevice->Device, 379 rndis_filter.inner_drv.recv_cb(dev->net_dev->dev,
370 Packet); 380 pkt);
371} 381}
372 382
373static int RndisFilterOnReceive(struct hv_device *Device, 383static int rndis_filter_receive(struct hv_device *dev,
374 struct hv_netvsc_packet *Packet) 384 struct hv_netvsc_packet *pkt)
375{ 385{
376 struct netvsc_device *netDevice = Device->Extension; 386 struct netvsc_device *net_dev = dev->Extension;
377 struct rndis_device *rndisDevice; 387 struct rndis_device *rndis_dev;
378 struct rndis_message rndisMessage; 388 struct rndis_message rndis_msg;
379 struct rndis_message *rndisHeader; 389 struct rndis_message *rndis_hdr;
380 390
381 if (!netDevice) 391 if (!net_dev)
382 return -EINVAL; 392 return -EINVAL;
383 393
384 /* Make sure the rndis device state is initialized */ 394 /* Make sure the rndis device state is initialized */
385 if (!netDevice->Extension) { 395 if (!net_dev->extension) {
386 DPRINT_ERR(NETVSC, "got rndis message but no rndis device..." 396 DPRINT_ERR(NETVSC, "got rndis message but no rndis device..."
387 "dropping this message!"); 397 "dropping this message!");
388 return -1; 398 return -1;
389 } 399 }
390 400
391 rndisDevice = (struct rndis_device *)netDevice->Extension; 401 rndis_dev = (struct rndis_device *)net_dev->extension;
392 if (rndisDevice->State == RNDIS_DEV_UNINITIALIZED) { 402 if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) {
393 DPRINT_ERR(NETVSC, "got rndis message but rndis device " 403 DPRINT_ERR(NETVSC, "got rndis message but rndis device "
394 "uninitialized...dropping this message!"); 404 "uninitialized...dropping this message!");
395 return -1; 405 return -1;
396 } 406 }
397 407
398 rndisHeader = (struct rndis_message *)kmap_atomic( 408 rndis_hdr = (struct rndis_message *)kmap_atomic(
399 pfn_to_page(Packet->PageBuffers[0].Pfn), KM_IRQ0); 409 pfn_to_page(pkt->page_buf[0].Pfn), KM_IRQ0);
400 410
401 rndisHeader = (void *)((unsigned long)rndisHeader + 411 rndis_hdr = (void *)((unsigned long)rndis_hdr +
402 Packet->PageBuffers[0].Offset); 412 pkt->page_buf[0].Offset);
403 413
404 /* Make sure we got a valid rndis message */ 414 /* Make sure we got a valid rndis message */
405 /* 415 /*
@@ -408,39 +418,39 @@ static int RndisFilterOnReceive(struct hv_device *Device,
408 * range shows 52 bytes 418 * range shows 52 bytes
409 * */ 419 * */
410#if 0 420#if 0
411 if (Packet->TotalDataBufferLength != rndisHeader->MessageLength) { 421 if (pkt->total_data_buflen != rndis_hdr->msg_len) {
412 kunmap_atomic(rndisHeader - Packet->PageBuffers[0].Offset, 422 kunmap_atomic(rndis_hdr - pkt->page_buf[0].Offset,
413 KM_IRQ0); 423 KM_IRQ0);
414 424
415 DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u " 425 DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u "
416 "bytes got %u)...dropping this message!", 426 "bytes got %u)...dropping this message!",
417 rndisHeader->MessageLength, 427 rndis_hdr->msg_len,
418 Packet->TotalDataBufferLength); 428 pkt->total_data_buflen);
419 return -1; 429 return -1;
420 } 430 }
421#endif 431#endif
422 432
423 if ((rndisHeader->NdisMessageType != REMOTE_NDIS_PACKET_MSG) && 433 if ((rndis_hdr->ndis_msg_type != REMOTE_NDIS_PACKET_MSG) &&
424 (rndisHeader->MessageLength > sizeof(struct rndis_message))) { 434 (rndis_hdr->msg_len > sizeof(struct rndis_message))) {
425 DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow " 435 DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow "
426 "detected (got %u, max %zu)...marking it an error!", 436 "detected (got %u, max %zu)...marking it an error!",
427 rndisHeader->MessageLength, 437 rndis_hdr->msg_len,
428 sizeof(struct rndis_message)); 438 sizeof(struct rndis_message));
429 } 439 }
430 440
431 memcpy(&rndisMessage, rndisHeader, 441 memcpy(&rndis_msg, rndis_hdr,
432 (rndisHeader->MessageLength > sizeof(struct rndis_message)) ? 442 (rndis_hdr->msg_len > sizeof(struct rndis_message)) ?
433 sizeof(struct rndis_message) : 443 sizeof(struct rndis_message) :
434 rndisHeader->MessageLength); 444 rndis_hdr->msg_len);
435 445
436 kunmap_atomic(rndisHeader - Packet->PageBuffers[0].Offset, KM_IRQ0); 446 kunmap_atomic(rndis_hdr - pkt->page_buf[0].Offset, KM_IRQ0);
437 447
438 DumpRndisMessage(&rndisMessage); 448 dump_rndis_message(&rndis_msg);
439 449
440 switch (rndisMessage.NdisMessageType) { 450 switch (rndis_msg.ndis_msg_type) {
441 case REMOTE_NDIS_PACKET_MSG: 451 case REMOTE_NDIS_PACKET_MSG:
442 /* data msg */ 452 /* data msg */
443 RndisFilterReceiveData(rndisDevice, &rndisMessage, Packet); 453 rndis_filter_receive_data(rndis_dev, &rndis_msg, pkt);
444 break; 454 break;
445 455
446 case REMOTE_NDIS_INITIALIZE_CMPLT: 456 case REMOTE_NDIS_INITIALIZE_CMPLT:
@@ -449,37 +459,37 @@ static int RndisFilterOnReceive(struct hv_device *Device,
449 /* case REMOTE_NDIS_RESET_CMPLT: */ 459 /* case REMOTE_NDIS_RESET_CMPLT: */
450 /* case REMOTE_NDIS_KEEPALIVE_CMPLT: */ 460 /* case REMOTE_NDIS_KEEPALIVE_CMPLT: */
451 /* completion msgs */ 461 /* completion msgs */
452 RndisFilterReceiveResponse(rndisDevice, &rndisMessage); 462 rndis_filter_receive_response(rndis_dev, &rndis_msg);
453 break; 463 break;
454 464
455 case REMOTE_NDIS_INDICATE_STATUS_MSG: 465 case REMOTE_NDIS_INDICATE_STATUS_MSG:
456 /* notification msgs */ 466 /* notification msgs */
457 RndisFilterReceiveIndicateStatus(rndisDevice, &rndisMessage); 467 rndis_filter_receive_indicate_status(rndis_dev, &rndis_msg);
458 break; 468 break;
459 default: 469 default:
460 DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)", 470 DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)",
461 rndisMessage.NdisMessageType, 471 rndis_msg.ndis_msg_type,
462 rndisMessage.MessageLength); 472 rndis_msg.msg_len);
463 break; 473 break;
464 } 474 }
465 475
466 return 0; 476 return 0;
467} 477}
468 478
469static int RndisFilterQueryDevice(struct rndis_device *Device, u32 Oid, 479static int rndis_filter_query_device(struct rndis_device *dev, u32 oid,
470 void *Result, u32 *ResultSize) 480 void *result, u32 *result_size)
471{ 481{
472 struct rndis_request *request; 482 struct rndis_request *request;
473 u32 inresultSize = *ResultSize; 483 u32 inresult_size = *result_size;
474 struct rndis_query_request *query; 484 struct rndis_query_request *query;
475 struct rndis_query_complete *queryComplete; 485 struct rndis_query_complete *query_complete;
476 int ret = 0; 486 int ret = 0;
477 487
478 if (!Result) 488 if (!result)
479 return -EINVAL; 489 return -EINVAL;
480 490
481 *ResultSize = 0; 491 *result_size = 0;
482 request = GetRndisRequest(Device, REMOTE_NDIS_QUERY_MSG, 492 request = get_rndis_request(dev, REMOTE_NDIS_QUERY_MSG,
483 RNDIS_MESSAGE_SIZE(struct rndis_query_request)); 493 RNDIS_MESSAGE_SIZE(struct rndis_query_request));
484 if (!request) { 494 if (!request) {
485 ret = -1; 495 ret = -1;
@@ -487,71 +497,71 @@ static int RndisFilterQueryDevice(struct rndis_device *Device, u32 Oid,
487 } 497 }
488 498
489 /* Setup the rndis query */ 499 /* Setup the rndis query */
490 query = &request->RequestMessage.Message.QueryRequest; 500 query = &request->request_msg.msg.query_req;
491 query->Oid = Oid; 501 query->oid = oid;
492 query->InformationBufferOffset = sizeof(struct rndis_query_request); 502 query->info_buf_offset = sizeof(struct rndis_query_request);
493 query->InformationBufferLength = 0; 503 query->info_buflen = 0;
494 query->DeviceVcHandle = 0; 504 query->dev_vc_handle = 0;
495 505
496 ret = RndisFilterSendRequest(Device, request); 506 ret = rndis_filter_send_request(dev, request);
497 if (ret != 0) 507 if (ret != 0)
498 goto Cleanup; 508 goto Cleanup;
499 509
500 osd_WaitEventWait(request->WaitEvent); 510 osd_waitevent_wait(request->waitevent);
501 511
502 /* Copy the response back */ 512 /* Copy the response back */
503 queryComplete = &request->ResponseMessage.Message.QueryComplete; 513 query_complete = &request->response_msg.msg.query_complete;
504 514
505 if (queryComplete->InformationBufferLength > inresultSize) { 515 if (query_complete->info_buflen > inresult_size) {
506 ret = -1; 516 ret = -1;
507 goto Cleanup; 517 goto Cleanup;
508 } 518 }
509 519
510 memcpy(Result, 520 memcpy(result,
511 (void *)((unsigned long)queryComplete + 521 (void *)((unsigned long)query_complete +
512 queryComplete->InformationBufferOffset), 522 query_complete->info_buf_offset),
513 queryComplete->InformationBufferLength); 523 query_complete->info_buflen);
514 524
515 *ResultSize = queryComplete->InformationBufferLength; 525 *result_size = query_complete->info_buflen;
516 526
517Cleanup: 527Cleanup:
518 if (request) 528 if (request)
519 PutRndisRequest(Device, request); 529 put_rndis_request(dev, request);
520 530
521 return ret; 531 return ret;
522} 532}
523 533
524static int RndisFilterQueryDeviceMac(struct rndis_device *Device) 534static int rndis_filter_query_device_mac(struct rndis_device *dev)
525{ 535{
526 u32 size = ETH_ALEN; 536 u32 size = ETH_ALEN;
527 537
528 return RndisFilterQueryDevice(Device, 538 return rndis_filter_query_device(dev,
529 RNDIS_OID_802_3_PERMANENT_ADDRESS, 539 RNDIS_OID_802_3_PERMANENT_ADDRESS,
530 Device->HwMacAddr, &size); 540 dev->hw_mac_adr, &size);
531} 541}
532 542
533static int RndisFilterQueryDeviceLinkStatus(struct rndis_device *Device) 543static int rndis_filter_query_device_link_status(struct rndis_device *dev)
534{ 544{
535 u32 size = sizeof(u32); 545 u32 size = sizeof(u32);
536 546
537 return RndisFilterQueryDevice(Device, 547 return rndis_filter_query_device(dev,
538 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, 548 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
539 &Device->LinkStatus, &size); 549 &dev->link_stat, &size);
540} 550}
541 551
542static int RndisFilterSetPacketFilter(struct rndis_device *Device, 552static int rndis_filter_set_packet_filter(struct rndis_device *dev,
543 u32 NewFilter) 553 u32 new_filter)
544{ 554{
545 struct rndis_request *request; 555 struct rndis_request *request;
546 struct rndis_set_request *set; 556 struct rndis_set_request *set;
547 struct rndis_set_complete *setComplete; 557 struct rndis_set_complete *set_complete;
548 u32 status; 558 u32 status;
549 int ret; 559 int ret;
550 560
551 /* ASSERT(RNDIS_MESSAGE_SIZE(struct rndis_set_request) + sizeof(u32) <= */ 561 /* ASSERT(RNDIS_MESSAGE_SIZE(struct rndis_set_request) + sizeof(u32) <= */
552 /* sizeof(struct rndis_message)); */ 562 /* sizeof(struct rndis_message)); */
553 563
554 request = GetRndisRequest(Device, REMOTE_NDIS_SET_MSG, 564 request = get_rndis_request(dev, REMOTE_NDIS_SET_MSG,
555 RNDIS_MESSAGE_SIZE(struct rndis_set_request) + 565 RNDIS_MESSAGE_SIZE(struct rndis_set_request) +
556 sizeof(u32)); 566 sizeof(u32));
557 if (!request) { 567 if (!request) {
@@ -560,19 +570,19 @@ static int RndisFilterSetPacketFilter(struct rndis_device *Device,
560 } 570 }
561 571
562 /* Setup the rndis set */ 572 /* Setup the rndis set */
563 set = &request->RequestMessage.Message.SetRequest; 573 set = &request->request_msg.msg.set_req;
564 set->Oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER; 574 set->oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER;
565 set->InformationBufferLength = sizeof(u32); 575 set->info_buflen = sizeof(u32);
566 set->InformationBufferOffset = sizeof(struct rndis_set_request); 576 set->info_buf_offset = sizeof(struct rndis_set_request);
567 577
568 memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request), 578 memcpy((void *)(unsigned long)set + sizeof(struct rndis_set_request),
569 &NewFilter, sizeof(u32)); 579 &new_filter, sizeof(u32));
570 580
571 ret = RndisFilterSendRequest(Device, request); 581 ret = rndis_filter_send_request(dev, request);
572 if (ret != 0) 582 if (ret != 0)
573 goto Cleanup; 583 goto Cleanup;
574 584
575 ret = osd_WaitEventWaitEx(request->WaitEvent, 2000/*2sec*/); 585 ret = osd_waitevent_waitex(request->waitevent, 2000/*2sec*/);
576 if (!ret) { 586 if (!ret) {
577 ret = -1; 587 ret = -1;
578 DPRINT_ERR(NETVSC, "timeout before we got a set response..."); 588 DPRINT_ERR(NETVSC, "timeout before we got a set response...");
@@ -584,27 +594,27 @@ static int RndisFilterSetPacketFilter(struct rndis_device *Device,
584 } else { 594 } else {
585 if (ret > 0) 595 if (ret > 0)
586 ret = 0; 596 ret = 0;
587 setComplete = &request->ResponseMessage.Message.SetComplete; 597 set_complete = &request->response_msg.msg.set_complete;
588 status = setComplete->Status; 598 status = set_complete->status;
589 } 599 }
590 600
591Cleanup: 601Cleanup:
592 if (request) 602 if (request)
593 PutRndisRequest(Device, request); 603 put_rndis_request(dev, request);
594Exit: 604Exit:
595 return ret; 605 return ret;
596} 606}
597 607
598int RndisFilterInit(struct netvsc_driver *Driver) 608int rndis_filter_init(struct netvsc_driver *drv)
599{ 609{
600 DPRINT_DBG(NETVSC, "sizeof(struct rndis_filter_packet) == %zd", 610 DPRINT_DBG(NETVSC, "sizeof(struct rndis_filter_packet) == %zd",
601 sizeof(struct rndis_filter_packet)); 611 sizeof(struct rndis_filter_packet));
602 612
603 Driver->RequestExtSize = sizeof(struct rndis_filter_packet); 613 drv->req_ext_size = sizeof(struct rndis_filter_packet);
604 614
605 /* Driver->Context = rndisDriver; */ 615 /* Driver->Context = rndisDriver; */
606 616
607 memset(&gRndisFilter, 0, sizeof(struct rndis_filter_driver_object)); 617 memset(&rndis_filter, 0, sizeof(struct rndis_filter_driver_object));
608 618
609 /*rndisDriver->Driver = Driver; 619 /*rndisDriver->Driver = Driver;
610 620
@@ -612,38 +622,38 @@ int RndisFilterInit(struct netvsc_driver *Driver)
612 rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/ 622 rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/
613 623
614 /* Save the original dispatch handlers before we override it */ 624 /* Save the original dispatch handlers before we override it */
615 gRndisFilter.InnerDriver.Base.OnDeviceAdd = Driver->Base.OnDeviceAdd; 625 rndis_filter.inner_drv.base.OnDeviceAdd = drv->base.OnDeviceAdd;
616 gRndisFilter.InnerDriver.Base.OnDeviceRemove = 626 rndis_filter.inner_drv.base.OnDeviceRemove =
617 Driver->Base.OnDeviceRemove; 627 drv->base.OnDeviceRemove;
618 gRndisFilter.InnerDriver.Base.OnCleanup = Driver->Base.OnCleanup; 628 rndis_filter.inner_drv.base.OnCleanup = drv->base.OnCleanup;
619 629
620 /* ASSERT(Driver->OnSend); */ 630 /* ASSERT(Driver->OnSend); */
621 /* ASSERT(Driver->OnReceiveCallback); */ 631 /* ASSERT(Driver->OnReceiveCallback); */
622 gRndisFilter.InnerDriver.OnSend = Driver->OnSend; 632 rndis_filter.inner_drv.send = drv->send;
623 gRndisFilter.InnerDriver.OnReceiveCallback = Driver->OnReceiveCallback; 633 rndis_filter.inner_drv.recv_cb = drv->recv_cb;
624 gRndisFilter.InnerDriver.OnLinkStatusChanged = 634 rndis_filter.inner_drv.link_status_change =
625 Driver->OnLinkStatusChanged; 635 drv->link_status_change;
626 636
627 /* Override */ 637 /* Override */
628 Driver->Base.OnDeviceAdd = RndisFilterOnDeviceAdd; 638 drv->base.OnDeviceAdd = rndis_filte_device_add;
629 Driver->Base.OnDeviceRemove = RndisFilterOnDeviceRemove; 639 drv->base.OnDeviceRemove = rndis_filter_device_remove;
630 Driver->Base.OnCleanup = RndisFilterOnCleanup; 640 drv->base.OnCleanup = rndis_filter_cleanup;
631 Driver->OnSend = RndisFilterOnSend; 641 drv->send = rndis_filter_send;
632 /* Driver->QueryLinkStatus = RndisFilterQueryDeviceLinkStatus; */ 642 /* Driver->QueryLinkStatus = RndisFilterQueryDeviceLinkStatus; */
633 Driver->OnReceiveCallback = RndisFilterOnReceive; 643 drv->recv_cb = rndis_filter_receive;
634 644
635 return 0; 645 return 0;
636} 646}
637 647
638static int RndisFilterInitDevice(struct rndis_device *Device) 648static int rndis_filter_init_device(struct rndis_device *dev)
639{ 649{
640 struct rndis_request *request; 650 struct rndis_request *request;
641 struct rndis_initialize_request *init; 651 struct rndis_initialize_request *init;
642 struct rndis_initialize_complete *initComplete; 652 struct rndis_initialize_complete *init_complete;
643 u32 status; 653 u32 status;
644 int ret; 654 int ret;
645 655
646 request = GetRndisRequest(Device, REMOTE_NDIS_INITIALIZE_MSG, 656 request = get_rndis_request(dev, REMOTE_NDIS_INITIALIZE_MSG,
647 RNDIS_MESSAGE_SIZE(struct rndis_initialize_request)); 657 RNDIS_MESSAGE_SIZE(struct rndis_initialize_request));
648 if (!request) { 658 if (!request) {
649 ret = -1; 659 ret = -1;
@@ -651,105 +661,105 @@ static int RndisFilterInitDevice(struct rndis_device *Device)
651 } 661 }
652 662
653 /* Setup the rndis set */ 663 /* Setup the rndis set */
654 init = &request->RequestMessage.Message.InitializeRequest; 664 init = &request->request_msg.msg.init_req;
655 init->MajorVersion = RNDIS_MAJOR_VERSION; 665 init->major_ver = RNDIS_MAJOR_VERSION;
656 init->MinorVersion = RNDIS_MINOR_VERSION; 666 init->minor_ver = RNDIS_MINOR_VERSION;
657 /* FIXME: Use 1536 - rounded ethernet frame size */ 667 /* FIXME: Use 1536 - rounded ethernet frame size */
658 init->MaxTransferSize = 2048; 668 init->max_xfer_size = 2048;
659 669
660 Device->State = RNDIS_DEV_INITIALIZING; 670 dev->state = RNDIS_DEV_INITIALIZING;
661 671
662 ret = RndisFilterSendRequest(Device, request); 672 ret = rndis_filter_send_request(dev, request);
663 if (ret != 0) { 673 if (ret != 0) {
664 Device->State = RNDIS_DEV_UNINITIALIZED; 674 dev->state = RNDIS_DEV_UNINITIALIZED;
665 goto Cleanup; 675 goto Cleanup;
666 } 676 }
667 677
668 osd_WaitEventWait(request->WaitEvent); 678 osd_waitevent_wait(request->waitevent);
669 679
670 initComplete = &request->ResponseMessage.Message.InitializeComplete; 680 init_complete = &request->response_msg.msg.init_complete;
671 status = initComplete->Status; 681 status = init_complete->status;
672 if (status == RNDIS_STATUS_SUCCESS) { 682 if (status == RNDIS_STATUS_SUCCESS) {
673 Device->State = RNDIS_DEV_INITIALIZED; 683 dev->state = RNDIS_DEV_INITIALIZED;
674 ret = 0; 684 ret = 0;
675 } else { 685 } else {
676 Device->State = RNDIS_DEV_UNINITIALIZED; 686 dev->state = RNDIS_DEV_UNINITIALIZED;
677 ret = -1; 687 ret = -1;
678 } 688 }
679 689
680Cleanup: 690Cleanup:
681 if (request) 691 if (request)
682 PutRndisRequest(Device, request); 692 put_rndis_request(dev, request);
683 693
684 return ret; 694 return ret;
685} 695}
686 696
687static void RndisFilterHaltDevice(struct rndis_device *Device) 697static void rndis_filter_halt_device(struct rndis_device *dev)
688{ 698{
689 struct rndis_request *request; 699 struct rndis_request *request;
690 struct rndis_halt_request *halt; 700 struct rndis_halt_request *halt;
691 701
692 /* Attempt to do a rndis device halt */ 702 /* Attempt to do a rndis device halt */
693 request = GetRndisRequest(Device, REMOTE_NDIS_HALT_MSG, 703 request = get_rndis_request(dev, REMOTE_NDIS_HALT_MSG,
694 RNDIS_MESSAGE_SIZE(struct rndis_halt_request)); 704 RNDIS_MESSAGE_SIZE(struct rndis_halt_request));
695 if (!request) 705 if (!request)
696 goto Cleanup; 706 goto Cleanup;
697 707
698 /* Setup the rndis set */ 708 /* Setup the rndis set */
699 halt = &request->RequestMessage.Message.HaltRequest; 709 halt = &request->request_msg.msg.halt_req;
700 halt->RequestId = atomic_inc_return(&Device->NewRequestId); 710 halt->req_id = atomic_inc_return(&dev->new_req_id);
701 711
702 /* Ignore return since this msg is optional. */ 712 /* Ignore return since this msg is optional. */
703 RndisFilterSendRequest(Device, request); 713 rndis_filter_send_request(dev, request);
704 714
705 Device->State = RNDIS_DEV_UNINITIALIZED; 715 dev->state = RNDIS_DEV_UNINITIALIZED;
706 716
707Cleanup: 717Cleanup:
708 if (request) 718 if (request)
709 PutRndisRequest(Device, request); 719 put_rndis_request(dev, request);
710 return; 720 return;
711} 721}
712 722
713static int RndisFilterOpenDevice(struct rndis_device *Device) 723static int rndis_filter_open_device(struct rndis_device *dev)
714{ 724{
715 int ret; 725 int ret;
716 726
717 if (Device->State != RNDIS_DEV_INITIALIZED) 727 if (dev->state != RNDIS_DEV_INITIALIZED)
718 return 0; 728 return 0;
719 729
720 ret = RndisFilterSetPacketFilter(Device, 730 ret = rndis_filter_set_packet_filter(dev,
721 NDIS_PACKET_TYPE_BROADCAST | 731 NDIS_PACKET_TYPE_BROADCAST |
722 NDIS_PACKET_TYPE_ALL_MULTICAST | 732 NDIS_PACKET_TYPE_ALL_MULTICAST |
723 NDIS_PACKET_TYPE_DIRECTED); 733 NDIS_PACKET_TYPE_DIRECTED);
724 if (ret == 0) 734 if (ret == 0)
725 Device->State = RNDIS_DEV_DATAINITIALIZED; 735 dev->state = RNDIS_DEV_DATAINITIALIZED;
726 736
727 return ret; 737 return ret;
728} 738}
729 739
730static int RndisFilterCloseDevice(struct rndis_device *Device) 740static int rndis_filter_close_device(struct rndis_device *dev)
731{ 741{
732 int ret; 742 int ret;
733 743
734 if (Device->State != RNDIS_DEV_DATAINITIALIZED) 744 if (dev->state != RNDIS_DEV_DATAINITIALIZED)
735 return 0; 745 return 0;
736 746
737 ret = RndisFilterSetPacketFilter(Device, 0); 747 ret = rndis_filter_set_packet_filter(dev, 0);
738 if (ret == 0) 748 if (ret == 0)
739 Device->State = RNDIS_DEV_INITIALIZED; 749 dev->state = RNDIS_DEV_INITIALIZED;
740 750
741 return ret; 751 return ret;
742} 752}
743 753
744static int RndisFilterOnDeviceAdd(struct hv_device *Device, 754static int rndis_filte_device_add(struct hv_device *dev,
745 void *AdditionalInfo) 755 void *additional_info)
746{ 756{
747 int ret; 757 int ret;
748 struct netvsc_device *netDevice; 758 struct netvsc_device *netDevice;
749 struct rndis_device *rndisDevice; 759 struct rndis_device *rndisDevice;
750 struct netvsc_device_info *deviceInfo = AdditionalInfo; 760 struct netvsc_device_info *deviceInfo = additional_info;
751 761
752 rndisDevice = GetRndisDevice(); 762 rndisDevice = get_rndis_device();
753 if (!rndisDevice) 763 if (!rndisDevice)
754 return -1; 764 return -1;
755 765
@@ -760,7 +770,7 @@ static int RndisFilterOnDeviceAdd(struct hv_device *Device,
760 * NOTE! Once the channel is created, we may get a receive callback 770 * NOTE! Once the channel is created, we may get a receive callback
761 * (RndisFilterOnReceive()) before this call is completed 771 * (RndisFilterOnReceive()) before this call is completed
762 */ 772 */
763 ret = gRndisFilter.InnerDriver.Base.OnDeviceAdd(Device, AdditionalInfo); 773 ret = rndis_filter.inner_drv.base.OnDeviceAdd(dev, additional_info);
764 if (ret != 0) { 774 if (ret != 0) {
765 kfree(rndisDevice); 775 kfree(rndisDevice);
766 return ret; 776 return ret;
@@ -768,15 +778,15 @@ static int RndisFilterOnDeviceAdd(struct hv_device *Device,
768 778
769 779
770 /* Initialize the rndis device */ 780 /* Initialize the rndis device */
771 netDevice = Device->Extension; 781 netDevice = dev->Extension;
772 /* ASSERT(netDevice); */ 782 /* ASSERT(netDevice); */
773 /* ASSERT(netDevice->Device); */ 783 /* ASSERT(netDevice->Device); */
774 784
775 netDevice->Extension = rndisDevice; 785 netDevice->extension = rndisDevice;
776 rndisDevice->NetDevice = netDevice; 786 rndisDevice->net_dev = netDevice;
777 787
778 /* Send the rndis initialization message */ 788 /* Send the rndis initialization message */
779 ret = RndisFilterInitDevice(rndisDevice); 789 ret = rndis_filter_init_device(rndisDevice);
780 if (ret != 0) { 790 if (ret != 0) {
781 /* 791 /*
782 * TODO: If rndis init failed, we will need to shut down the 792 * TODO: If rndis init failed, we will need to shut down the
@@ -785,7 +795,7 @@ static int RndisFilterOnDeviceAdd(struct hv_device *Device,
785 } 795 }
786 796
787 /* Get the mac address */ 797 /* Get the mac address */
788 ret = RndisFilterQueryDeviceMac(rndisDevice); 798 ret = rndis_filter_query_device_mac(rndisDevice);
789 if (ret != 0) { 799 if (ret != 0) {
790 /* 800 /*
791 * TODO: shutdown rndis device and the channel 801 * TODO: shutdown rndis device and the channel
@@ -793,62 +803,62 @@ static int RndisFilterOnDeviceAdd(struct hv_device *Device,
793 } 803 }
794 804
795 DPRINT_INFO(NETVSC, "Device 0x%p mac addr %pM", 805 DPRINT_INFO(NETVSC, "Device 0x%p mac addr %pM",
796 rndisDevice, rndisDevice->HwMacAddr); 806 rndisDevice, rndisDevice->hw_mac_adr);
797 807
798 memcpy(deviceInfo->MacAddr, rndisDevice->HwMacAddr, ETH_ALEN); 808 memcpy(deviceInfo->mac_adr, rndisDevice->hw_mac_adr, ETH_ALEN);
799 809
800 RndisFilterQueryDeviceLinkStatus(rndisDevice); 810 rndis_filter_query_device_link_status(rndisDevice);
801 811
802 deviceInfo->LinkState = rndisDevice->LinkStatus; 812 deviceInfo->link_state = rndisDevice->link_stat;
803 DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice, 813 DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice,
804 ((deviceInfo->LinkState) ? ("down") : ("up"))); 814 ((deviceInfo->link_state) ? ("down") : ("up")));
805 815
806 return ret; 816 return ret;
807} 817}
808 818
809static int RndisFilterOnDeviceRemove(struct hv_device *Device) 819static int rndis_filter_device_remove(struct hv_device *dev)
810{ 820{
811 struct netvsc_device *netDevice = Device->Extension; 821 struct netvsc_device *net_dev = dev->Extension;
812 struct rndis_device *rndisDevice = netDevice->Extension; 822 struct rndis_device *rndis_dev = net_dev->extension;
813 823
814 /* Halt and release the rndis device */ 824 /* Halt and release the rndis device */
815 RndisFilterHaltDevice(rndisDevice); 825 rndis_filter_halt_device(rndis_dev);
816 826
817 kfree(rndisDevice); 827 kfree(rndis_dev);
818 netDevice->Extension = NULL; 828 net_dev->extension = NULL;
819 829
820 /* Pass control to inner driver to remove the device */ 830 /* Pass control to inner driver to remove the device */
821 gRndisFilter.InnerDriver.Base.OnDeviceRemove(Device); 831 rndis_filter.inner_drv.base.OnDeviceRemove(dev);
822 832
823 return 0; 833 return 0;
824} 834}
825 835
826static void RndisFilterOnCleanup(struct hv_driver *Driver) 836static void rndis_filter_cleanup(struct hv_driver *drv)
827{ 837{
828} 838}
829 839
830int RndisFilterOnOpen(struct hv_device *Device) 840int rndis_filter_open(struct hv_device *dev)
831{ 841{
832 struct netvsc_device *netDevice = Device->Extension; 842 struct netvsc_device *netDevice = dev->Extension;
833 843
834 if (!netDevice) 844 if (!netDevice)
835 return -EINVAL; 845 return -EINVAL;
836 846
837 return RndisFilterOpenDevice(netDevice->Extension); 847 return rndis_filter_open_device(netDevice->extension);
838} 848}
839 849
840int RndisFilterOnClose(struct hv_device *Device) 850int rndis_filter_close(struct hv_device *dev)
841{ 851{
842 struct netvsc_device *netDevice = Device->Extension; 852 struct netvsc_device *netDevice = dev->Extension;
843 853
844 if (!netDevice) 854 if (!netDevice)
845 return -EINVAL; 855 return -EINVAL;
846 856
847 return RndisFilterCloseDevice(netDevice->Extension); 857 return rndis_filter_close_device(netDevice->extension);
848} 858}
849 859
850static int RndisFilterOnSend(struct hv_device *Device, 860static int rndis_filter_send(struct hv_device *dev,
851 struct hv_netvsc_packet *Packet) 861 struct hv_netvsc_packet *pkt)
852{ 862{
853 int ret; 863 int ret;
854 struct rndis_filter_packet *filterPacket; 864 struct rndis_filter_packet *filterPacket;
@@ -857,62 +867,62 @@ static int RndisFilterOnSend(struct hv_device *Device,
857 u32 rndisMessageSize; 867 u32 rndisMessageSize;
858 868
859 /* Add the rndis header */ 869 /* Add the rndis header */
860 filterPacket = (struct rndis_filter_packet *)Packet->Extension; 870 filterPacket = (struct rndis_filter_packet *)pkt->extension;
861 /* ASSERT(filterPacket); */ 871 /* ASSERT(filterPacket); */
862 872
863 memset(filterPacket, 0, sizeof(struct rndis_filter_packet)); 873 memset(filterPacket, 0, sizeof(struct rndis_filter_packet));
864 874
865 rndisMessage = &filterPacket->Message; 875 rndisMessage = &filterPacket->msg;
866 rndisMessageSize = RNDIS_MESSAGE_SIZE(struct rndis_packet); 876 rndisMessageSize = RNDIS_MESSAGE_SIZE(struct rndis_packet);
867 877
868 rndisMessage->NdisMessageType = REMOTE_NDIS_PACKET_MSG; 878 rndisMessage->ndis_msg_type = REMOTE_NDIS_PACKET_MSG;
869 rndisMessage->MessageLength = Packet->TotalDataBufferLength + 879 rndisMessage->msg_len = pkt->total_data_buflen +
870 rndisMessageSize; 880 rndisMessageSize;
871 881
872 rndisPacket = &rndisMessage->Message.Packet; 882 rndisPacket = &rndisMessage->msg.pkt;
873 rndisPacket->DataOffset = sizeof(struct rndis_packet); 883 rndisPacket->data_offset = sizeof(struct rndis_packet);
874 rndisPacket->DataLength = Packet->TotalDataBufferLength; 884 rndisPacket->data_len = pkt->total_data_buflen;
875 885
876 Packet->IsDataPacket = true; 886 pkt->is_data_pkt = true;
877 Packet->PageBuffers[0].Pfn = virt_to_phys(rndisMessage) >> PAGE_SHIFT; 887 pkt->page_buf[0].Pfn = virt_to_phys(rndisMessage) >> PAGE_SHIFT;
878 Packet->PageBuffers[0].Offset = 888 pkt->page_buf[0].Offset =
879 (unsigned long)rndisMessage & (PAGE_SIZE-1); 889 (unsigned long)rndisMessage & (PAGE_SIZE-1);
880 Packet->PageBuffers[0].Length = rndisMessageSize; 890 pkt->page_buf[0].Length = rndisMessageSize;
881 891
882 /* Save the packet send completion and context */ 892 /* Save the packet send completion and context */
883 filterPacket->OnCompletion = Packet->Completion.Send.OnSendCompletion; 893 filterPacket->completion = pkt->completion.send.send_completion;
884 filterPacket->CompletionContext = 894 filterPacket->completion_ctx =
885 Packet->Completion.Send.SendCompletionContext; 895 pkt->completion.send.send_completion_ctx;
886 896
887 /* Use ours */ 897 /* Use ours */
888 Packet->Completion.Send.OnSendCompletion = RndisFilterOnSendCompletion; 898 pkt->completion.send.send_completion = rndis_filter_send_completion;
889 Packet->Completion.Send.SendCompletionContext = filterPacket; 899 pkt->completion.send.send_completion_ctx = filterPacket;
890 900
891 ret = gRndisFilter.InnerDriver.OnSend(Device, Packet); 901 ret = rndis_filter.inner_drv.send(dev, pkt);
892 if (ret != 0) { 902 if (ret != 0) {
893 /* 903 /*
894 * Reset the completion to originals to allow retries from 904 * Reset the completion to originals to allow retries from
895 * above 905 * above
896 */ 906 */
897 Packet->Completion.Send.OnSendCompletion = 907 pkt->completion.send.send_completion =
898 filterPacket->OnCompletion; 908 filterPacket->completion;
899 Packet->Completion.Send.SendCompletionContext = 909 pkt->completion.send.send_completion_ctx =
900 filterPacket->CompletionContext; 910 filterPacket->completion_ctx;
901 } 911 }
902 912
903 return ret; 913 return ret;
904} 914}
905 915
906static void RndisFilterOnSendCompletion(void *Context) 916static void rndis_filter_send_completion(void *ctx)
907{ 917{
908 struct rndis_filter_packet *filterPacket = Context; 918 struct rndis_filter_packet *filterPacket = ctx;
909 919
910 /* Pass it back to the original handler */ 920 /* Pass it back to the original handler */
911 filterPacket->OnCompletion(filterPacket->CompletionContext); 921 filterPacket->completion(filterPacket->completion_ctx);
912} 922}
913 923
914 924
915static void RndisFilterOnSendRequestCompletion(void *Context) 925static void rndis_filter_send_request_completion(void *ctx)
916{ 926{
917 /* Noop */ 927 /* Noop */
918} 928}
diff --git a/drivers/staging/hv/rndis_filter.h b/drivers/staging/hv/rndis_filter.h
index 764b9bf3e5dc..4da18f3cbade 100644
--- a/drivers/staging/hv/rndis_filter.h
+++ b/drivers/staging/hv/rndis_filter.h
@@ -50,6 +50,6 @@
50 50
51/* Interface */ 51/* Interface */
52 52
53extern int RndisFilterInit(struct netvsc_driver *driver); 53extern int rndis_filter_init(struct netvsc_driver *driver);
54 54
55#endif /* _RNDISFILTER_H_ */ 55#endif /* _RNDISFILTER_H_ */
diff --git a/drivers/staging/hv/storvsc.c b/drivers/staging/hv/storvsc.c
index 19e87f689fa0..9295113e09b9 100644
--- a/drivers/staging/hv/storvsc.c
+++ b/drivers/staging/hv/storvsc.c
@@ -34,43 +34,43 @@
34struct storvsc_request_extension { 34struct storvsc_request_extension {
35 /* LIST_ENTRY ListEntry; */ 35 /* LIST_ENTRY ListEntry; */
36 36
37 struct hv_storvsc_request *Request; 37 struct hv_storvsc_request *request;
38 struct hv_device *Device; 38 struct hv_device *device;
39 39
40 /* Synchronize the request/response if needed */ 40 /* Synchronize the request/response if needed */
41 struct osd_waitevent *WaitEvent; 41 struct osd_waitevent *wait_event;
42 42
43 struct vstor_packet VStorPacket; 43 struct vstor_packet vstor_packet;
44}; 44};
45 45
46/* A storvsc device is a device object that contains a vmbus channel */ 46/* A storvsc device is a device object that contains a vmbus channel */
47struct storvsc_device { 47struct storvsc_device {
48 struct hv_device *Device; 48 struct hv_device *device;
49 49
50 /* 0 indicates the device is being destroyed */ 50 /* 0 indicates the device is being destroyed */
51 atomic_t RefCount; 51 atomic_t ref_count;
52 52
53 atomic_t NumOutstandingRequests; 53 atomic_t num_outstanding_req;
54 54
55 /* 55 /*
56 * Each unique Port/Path/Target represents 1 channel ie scsi 56 * Each unique Port/Path/Target represents 1 channel ie scsi
57 * controller. In reality, the pathid, targetid is always 0 57 * controller. In reality, the pathid, targetid is always 0
58 * and the port is set by us 58 * and the port is set by us
59 */ 59 */
60 unsigned int PortNumber; 60 unsigned int port_number;
61 unsigned char PathId; 61 unsigned char path_id;
62 unsigned char TargetId; 62 unsigned char target_id;
63 63
64 /* LIST_ENTRY OutstandingRequestList; */ 64 /* LIST_ENTRY OutstandingRequestList; */
65 /* HANDLE OutstandingRequestLock; */ 65 /* HANDLE OutstandingRequestLock; */
66 66
67 /* Used for vsc/vsp channel reset process */ 67 /* Used for vsc/vsp channel reset process */
68 struct storvsc_request_extension InitRequest; 68 struct storvsc_request_extension init_request;
69 struct storvsc_request_extension ResetRequest; 69 struct storvsc_request_extension reset_request;
70}; 70};
71 71
72 72
73static const char *gDriverName = "storvsc"; 73static const char *g_driver_name = "storvsc";
74 74
75/* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */ 75/* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
76static const struct hv_guid gStorVscDeviceType = { 76static const struct hv_guid gStorVscDeviceType = {
@@ -81,131 +81,133 @@ static const struct hv_guid gStorVscDeviceType = {
81}; 81};
82 82
83 83
84static inline struct storvsc_device *AllocStorDevice(struct hv_device *Device) 84static inline struct storvsc_device *alloc_stor_device(struct hv_device *device)
85{ 85{
86 struct storvsc_device *storDevice; 86 struct storvsc_device *stor_device;
87 87
88 storDevice = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL); 88 stor_device = kzalloc(sizeof(struct storvsc_device), GFP_KERNEL);
89 if (!storDevice) 89 if (!stor_device)
90 return NULL; 90 return NULL;
91 91
92 /* Set to 2 to allow both inbound and outbound traffics */ 92 /* Set to 2 to allow both inbound and outbound traffics */
93 /* (ie GetStorDevice() and MustGetStorDevice()) to proceed. */ 93 /* (ie get_stor_device() and must_get_stor_device()) to proceed. */
94 atomic_cmpxchg(&storDevice->RefCount, 0, 2); 94 atomic_cmpxchg(&stor_device->ref_count, 0, 2);
95 95
96 storDevice->Device = Device; 96 stor_device->device = device;
97 Device->Extension = storDevice; 97 device->Extension = stor_device;
98 98
99 return storDevice; 99 return stor_device;
100} 100}
101 101
102static inline void FreeStorDevice(struct storvsc_device *Device) 102static inline void free_stor_device(struct storvsc_device *device)
103{ 103{
104 /* ASSERT(atomic_read(&Device->RefCount) == 0); */ 104 /* ASSERT(atomic_read(&device->ref_count) == 0); */
105 kfree(Device); 105 kfree(device);
106} 106}
107 107
108/* Get the stordevice object iff exists and its refcount > 1 */ 108/* Get the stordevice object iff exists and its refcount > 1 */
109static inline struct storvsc_device *GetStorDevice(struct hv_device *Device) 109static inline struct storvsc_device *get_stor_device(struct hv_device *device)
110{ 110{
111 struct storvsc_device *storDevice; 111 struct storvsc_device *stor_device;
112 112
113 storDevice = (struct storvsc_device *)Device->Extension; 113 stor_device = (struct storvsc_device *)device->Extension;
114 if (storDevice && atomic_read(&storDevice->RefCount) > 1) 114 if (stor_device && atomic_read(&stor_device->ref_count) > 1)
115 atomic_inc(&storDevice->RefCount); 115 atomic_inc(&stor_device->ref_count);
116 else 116 else
117 storDevice = NULL; 117 stor_device = NULL;
118 118
119 return storDevice; 119 return stor_device;
120} 120}
121 121
122/* Get the stordevice object iff exists and its refcount > 0 */ 122/* Get the stordevice object iff exists and its refcount > 0 */
123static inline struct storvsc_device *MustGetStorDevice(struct hv_device *Device) 123static inline struct storvsc_device *must_get_stor_device(
124 struct hv_device *device)
124{ 125{
125 struct storvsc_device *storDevice; 126 struct storvsc_device *stor_device;
126 127
127 storDevice = (struct storvsc_device *)Device->Extension; 128 stor_device = (struct storvsc_device *)device->Extension;
128 if (storDevice && atomic_read(&storDevice->RefCount)) 129 if (stor_device && atomic_read(&stor_device->ref_count))
129 atomic_inc(&storDevice->RefCount); 130 atomic_inc(&stor_device->ref_count);
130 else 131 else
131 storDevice = NULL; 132 stor_device = NULL;
132 133
133 return storDevice; 134 return stor_device;
134} 135}
135 136
136static inline void PutStorDevice(struct hv_device *Device) 137static inline void put_stor_device(struct hv_device *device)
137{ 138{
138 struct storvsc_device *storDevice; 139 struct storvsc_device *stor_device;
139 140
140 storDevice = (struct storvsc_device *)Device->Extension; 141 stor_device = (struct storvsc_device *)device->Extension;
141 /* ASSERT(storDevice); */ 142 /* ASSERT(stor_device); */
142 143
143 atomic_dec(&storDevice->RefCount); 144 atomic_dec(&stor_device->ref_count);
144 /* ASSERT(atomic_read(&storDevice->RefCount)); */ 145 /* ASSERT(atomic_read(&stor_device->ref_count)); */
145} 146}
146 147
147/* Drop ref count to 1 to effectively disable GetStorDevice() */ 148/* Drop ref count to 1 to effectively disable get_stor_device() */
148static inline struct storvsc_device *ReleaseStorDevice(struct hv_device *Device) 149static inline struct storvsc_device *release_stor_device(
150 struct hv_device *device)
149{ 151{
150 struct storvsc_device *storDevice; 152 struct storvsc_device *stor_device;
151 153
152 storDevice = (struct storvsc_device *)Device->Extension; 154 stor_device = (struct storvsc_device *)device->Extension;
153 /* ASSERT(storDevice); */ 155 /* ASSERT(stor_device); */
154 156
155 /* Busy wait until the ref drop to 2, then set it to 1 */ 157 /* Busy wait until the ref drop to 2, then set it to 1 */
156 while (atomic_cmpxchg(&storDevice->RefCount, 2, 1) != 2) 158 while (atomic_cmpxchg(&stor_device->ref_count, 2, 1) != 2)
157 udelay(100); 159 udelay(100);
158 160
159 return storDevice; 161 return stor_device;
160} 162}
161 163
162/* Drop ref count to 0. No one can use StorDevice object. */ 164/* Drop ref count to 0. No one can use stor_device object. */
163static inline struct storvsc_device *FinalReleaseStorDevice( 165static inline struct storvsc_device *final_release_stor_device(
164 struct hv_device *Device) 166 struct hv_device *device)
165{ 167{
166 struct storvsc_device *storDevice; 168 struct storvsc_device *stor_device;
167 169
168 storDevice = (struct storvsc_device *)Device->Extension; 170 stor_device = (struct storvsc_device *)device->Extension;
169 /* ASSERT(storDevice); */ 171 /* ASSERT(stor_device); */
170 172
171 /* Busy wait until the ref drop to 1, then set it to 0 */ 173 /* Busy wait until the ref drop to 1, then set it to 0 */
172 while (atomic_cmpxchg(&storDevice->RefCount, 1, 0) != 1) 174 while (atomic_cmpxchg(&stor_device->ref_count, 1, 0) != 1)
173 udelay(100); 175 udelay(100);
174 176
175 Device->Extension = NULL; 177 device->Extension = NULL;
176 return storDevice; 178 return stor_device;
177} 179}
178 180
179static int StorVscChannelInit(struct hv_device *Device) 181static int stor_vsc_channel_init(struct hv_device *device)
180{ 182{
181 struct storvsc_device *storDevice; 183 struct storvsc_device *stor_device;
182 struct storvsc_request_extension *request; 184 struct storvsc_request_extension *request;
183 struct vstor_packet *vstorPacket; 185 struct vstor_packet *vstor_packet;
184 int ret; 186 int ret;
185 187
186 storDevice = GetStorDevice(Device); 188 stor_device = get_stor_device(device);
187 if (!storDevice) { 189 if (!stor_device) {
188 DPRINT_ERR(STORVSC, "unable to get stor device..." 190 DPRINT_ERR(STORVSC, "unable to get stor device..."
189 "device being destroyed?"); 191 "device being destroyed?");
190 return -1; 192 return -1;
191 } 193 }
192 194
193 request = &storDevice->InitRequest; 195 request = &stor_device->init_request;
194 vstorPacket = &request->VStorPacket; 196 vstor_packet = &request->vstor_packet;
195 197
196 /* 198 /*
197 * Now, initiate the vsc/vsp initialization protocol on the open 199 * Now, initiate the vsc/vsp initialization protocol on the open
198 * channel 200 * channel
199 */ 201 */
200 memset(request, 0, sizeof(struct storvsc_request_extension)); 202 memset(request, 0, sizeof(struct storvsc_request_extension));
201 request->WaitEvent = osd_WaitEventCreate(); 203 request->wait_event = osd_waitevent_create();
202 if (!request->WaitEvent) { 204 if (!request->wait_event) {
203 ret = -ENOMEM; 205 ret = -ENOMEM;
204 goto nomem; 206 goto nomem;
205 } 207 }
206 208
207 vstorPacket->Operation = VStorOperationBeginInitialization; 209 vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION;
208 vstorPacket->Flags = REQUEST_COMPLETION_FLAG; 210 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
209 211
210 /*SpinlockAcquire(gDriverExt.packetListLock); 212 /*SpinlockAcquire(gDriverExt.packetListLock);
211 INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry); 213 INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry);
@@ -213,7 +215,7 @@ static int StorVscChannelInit(struct hv_device *Device)
213 215
214 DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION..."); 216 DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION...");
215 217
216 ret = vmbus_sendpacket(Device->channel, vstorPacket, 218 ret = vmbus_sendpacket(device->channel, vstor_packet,
217 sizeof(struct vstor_packet), 219 sizeof(struct vstor_packet),
218 (unsigned long)request, 220 (unsigned long)request,
219 VmbusPacketTypeDataInBand, 221 VmbusPacketTypeDataInBand,
@@ -224,27 +226,27 @@ static int StorVscChannelInit(struct hv_device *Device)
224 goto Cleanup; 226 goto Cleanup;
225 } 227 }
226 228
227 osd_WaitEventWait(request->WaitEvent); 229 osd_waitevent_wait(request->wait_event);
228 230
229 if (vstorPacket->Operation != VStorOperationCompleteIo || 231 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
230 vstorPacket->Status != 0) { 232 vstor_packet->status != 0) {
231 DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed " 233 DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed "
232 "(op %d status 0x%x)", 234 "(op %d status 0x%x)",
233 vstorPacket->Operation, vstorPacket->Status); 235 vstor_packet->operation, vstor_packet->status);
234 goto Cleanup; 236 goto Cleanup;
235 } 237 }
236 238
237 DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION..."); 239 DPRINT_INFO(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION...");
238 240
239 /* reuse the packet for version range supported */ 241 /* reuse the packet for version range supported */
240 memset(vstorPacket, 0, sizeof(struct vstor_packet)); 242 memset(vstor_packet, 0, sizeof(struct vstor_packet));
241 vstorPacket->Operation = VStorOperationQueryProtocolVersion; 243 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROTOCOL_VERSION;
242 vstorPacket->Flags = REQUEST_COMPLETION_FLAG; 244 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
243 245
244 vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT; 246 vstor_packet->version.major_minor = VMSTOR_PROTOCOL_VERSION_CURRENT;
245 FILL_VMSTOR_REVISION(vstorPacket->Version.Revision); 247 FILL_VMSTOR_REVISION(vstor_packet->version.revision);
246 248
247 ret = vmbus_sendpacket(Device->channel, vstorPacket, 249 ret = vmbus_sendpacket(device->channel, vstor_packet,
248 sizeof(struct vstor_packet), 250 sizeof(struct vstor_packet),
249 (unsigned long)request, 251 (unsigned long)request,
250 VmbusPacketTypeDataInBand, 252 VmbusPacketTypeDataInBand,
@@ -255,27 +257,27 @@ static int StorVscChannelInit(struct hv_device *Device)
255 goto Cleanup; 257 goto Cleanup;
256 } 258 }
257 259
258 osd_WaitEventWait(request->WaitEvent); 260 osd_waitevent_wait(request->wait_event);
259 261
260 /* TODO: Check returned version */ 262 /* TODO: Check returned version */
261 if (vstorPacket->Operation != VStorOperationCompleteIo || 263 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
262 vstorPacket->Status != 0) { 264 vstor_packet->status != 0) {
263 DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed " 265 DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed "
264 "(op %d status 0x%x)", 266 "(op %d status 0x%x)",
265 vstorPacket->Operation, vstorPacket->Status); 267 vstor_packet->operation, vstor_packet->status);
266 goto Cleanup; 268 goto Cleanup;
267 } 269 }
268 270
269 /* Query channel properties */ 271 /* Query channel properties */
270 DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION..."); 272 DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION...");
271 273
272 memset(vstorPacket, 0, sizeof(struct vstor_packet)); 274 memset(vstor_packet, 0, sizeof(struct vstor_packet));
273 vstorPacket->Operation = VStorOperationQueryProperties; 275 vstor_packet->operation = VSTOR_OPERATION_QUERY_PROPERTIES;
274 vstorPacket->Flags = REQUEST_COMPLETION_FLAG; 276 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
275 vstorPacket->StorageChannelProperties.PortNumber = 277 vstor_packet->storage_channel_properties.port_number =
276 storDevice->PortNumber; 278 stor_device->port_number;
277 279
278 ret = vmbus_sendpacket(Device->channel, vstorPacket, 280 ret = vmbus_sendpacket(device->channel, vstor_packet,
279 sizeof(struct vstor_packet), 281 sizeof(struct vstor_packet),
280 (unsigned long)request, 282 (unsigned long)request,
281 VmbusPacketTypeDataInBand, 283 VmbusPacketTypeDataInBand,
@@ -287,31 +289,32 @@ static int StorVscChannelInit(struct hv_device *Device)
287 goto Cleanup; 289 goto Cleanup;
288 } 290 }
289 291
290 osd_WaitEventWait(request->WaitEvent); 292 osd_waitevent_wait(request->wait_event);
291 293
292 /* TODO: Check returned version */ 294 /* TODO: Check returned version */
293 if (vstorPacket->Operation != VStorOperationCompleteIo || 295 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
294 vstorPacket->Status != 0) { 296 vstor_packet->status != 0) {
295 DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed " 297 DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed "
296 "(op %d status 0x%x)", 298 "(op %d status 0x%x)",
297 vstorPacket->Operation, vstorPacket->Status); 299 vstor_packet->operation, vstor_packet->status);
298 goto Cleanup; 300 goto Cleanup;
299 } 301 }
300 302
301 storDevice->PathId = vstorPacket->StorageChannelProperties.PathId; 303 stor_device->path_id = vstor_packet->storage_channel_properties.path_id;
302 storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId; 304 stor_device->target_id
305 = vstor_packet->storage_channel_properties.target_id;
303 306
304 DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x", 307 DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x",
305 vstorPacket->StorageChannelProperties.Flags, 308 vstor_packet->storage_channel_properties.flags,
306 vstorPacket->StorageChannelProperties.MaxTransferBytes); 309 vstor_packet->storage_channel_properties.max_transfer_bytes);
307 310
308 DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION..."); 311 DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION...");
309 312
310 memset(vstorPacket, 0, sizeof(struct vstor_packet)); 313 memset(vstor_packet, 0, sizeof(struct vstor_packet));
311 vstorPacket->Operation = VStorOperationEndInitialization; 314 vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION;
312 vstorPacket->Flags = REQUEST_COMPLETION_FLAG; 315 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
313 316
314 ret = vmbus_sendpacket(Device->channel, vstorPacket, 317 ret = vmbus_sendpacket(device->channel, vstor_packet,
315 sizeof(struct vstor_packet), 318 sizeof(struct vstor_packet),
316 (unsigned long)request, 319 (unsigned long)request,
317 VmbusPacketTypeDataInBand, 320 VmbusPacketTypeDataInBand,
@@ -323,125 +326,125 @@ static int StorVscChannelInit(struct hv_device *Device)
323 goto Cleanup; 326 goto Cleanup;
324 } 327 }
325 328
326 osd_WaitEventWait(request->WaitEvent); 329 osd_waitevent_wait(request->wait_event);
327 330
328 if (vstorPacket->Operation != VStorOperationCompleteIo || 331 if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO ||
329 vstorPacket->Status != 0) { 332 vstor_packet->status != 0) {
330 DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed " 333 DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed "
331 "(op %d status 0x%x)", 334 "(op %d status 0x%x)",
332 vstorPacket->Operation, vstorPacket->Status); 335 vstor_packet->operation, vstor_packet->status);
333 goto Cleanup; 336 goto Cleanup;
334 } 337 }
335 338
336 DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****"); 339 DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****");
337 340
338Cleanup: 341Cleanup:
339 kfree(request->WaitEvent); 342 kfree(request->wait_event);
340 request->WaitEvent = NULL; 343 request->wait_event = NULL;
341nomem: 344nomem:
342 PutStorDevice(Device); 345 put_stor_device(device);
343 return ret; 346 return ret;
344} 347}
345 348
346static void StorVscOnIOCompletion(struct hv_device *Device, 349static void stor_vsc_on_io_completion(struct hv_device *device,
347 struct vstor_packet *VStorPacket, 350 struct vstor_packet *vstor_packet,
348 struct storvsc_request_extension *RequestExt) 351 struct storvsc_request_extension *request_ext)
349{ 352{
350 struct hv_storvsc_request *request; 353 struct hv_storvsc_request *request;
351 struct storvsc_device *storDevice; 354 struct storvsc_device *stor_device;
352 355
353 storDevice = MustGetStorDevice(Device); 356 stor_device = must_get_stor_device(device);
354 if (!storDevice) { 357 if (!stor_device) {
355 DPRINT_ERR(STORVSC, "unable to get stor device..." 358 DPRINT_ERR(STORVSC, "unable to get stor device..."
356 "device being destroyed?"); 359 "device being destroyed?");
357 return; 360 return;
358 } 361 }
359 362
360 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p " 363 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p "
361 "completed bytes xfer %u", RequestExt, 364 "completed bytes xfer %u", request_ext,
362 VStorPacket->VmSrb.DataTransferLength); 365 vstor_packet->vm_srb.data_transfer_length);
363 366
364 /* ASSERT(RequestExt != NULL); */ 367 /* ASSERT(request_ext != NULL); */
365 /* ASSERT(RequestExt->Request != NULL); */ 368 /* ASSERT(request_ext->request != NULL); */
366 369
367 request = RequestExt->Request; 370 request = request_ext->request;
368 371
369 /* ASSERT(request->OnIOCompletion != NULL); */ 372 /* ASSERT(request->OnIOCompletion != NULL); */
370 373
371 /* Copy over the status...etc */ 374 /* Copy over the status...etc */
372 request->Status = VStorPacket->VmSrb.ScsiStatus; 375 request->status = vstor_packet->vm_srb.scsi_status;
373 376
374 if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1) { 377 if (request->status != 0 || vstor_packet->vm_srb.srb_status != 1) {
375 DPRINT_WARN(STORVSC, 378 DPRINT_WARN(STORVSC,
376 "cmd 0x%x scsi status 0x%x srb status 0x%x\n", 379 "cmd 0x%x scsi status 0x%x srb status 0x%x\n",
377 request->Cdb[0], VStorPacket->VmSrb.ScsiStatus, 380 request->cdb[0], vstor_packet->vm_srb.scsi_status,
378 VStorPacket->VmSrb.SrbStatus); 381 vstor_packet->vm_srb.srb_status);
379 } 382 }
380 383
381 if ((request->Status & 0xFF) == 0x02) { 384 if ((request->status & 0xFF) == 0x02) {
382 /* CHECK_CONDITION */ 385 /* CHECK_CONDITION */
383 if (VStorPacket->VmSrb.SrbStatus & 0x80) { 386 if (vstor_packet->vm_srb.srb_status & 0x80) {
384 /* autosense data available */ 387 /* autosense data available */
385 DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data " 388 DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data "
386 "valid - len %d\n", RequestExt, 389 "valid - len %d\n", request_ext,
387 VStorPacket->VmSrb.SenseInfoLength); 390 vstor_packet->vm_srb.sense_info_length);
388 391
389 /* ASSERT(VStorPacket->VmSrb.SenseInfoLength <= */ 392 /* ASSERT(vstor_packet->vm_srb.sense_info_length <= */
390 /* request->SenseBufferSize); */ 393 /* request->SenseBufferSize); */
391 memcpy(request->SenseBuffer, 394 memcpy(request->sense_buffer,
392 VStorPacket->VmSrb.SenseData, 395 vstor_packet->vm_srb.sense_data,
393 VStorPacket->VmSrb.SenseInfoLength); 396 vstor_packet->vm_srb.sense_info_length);
394 397
395 request->SenseBufferSize = 398 request->sense_buffer_size =
396 VStorPacket->VmSrb.SenseInfoLength; 399 vstor_packet->vm_srb.sense_info_length;
397 } 400 }
398 } 401 }
399 402
400 /* TODO: */ 403 /* TODO: */
401 request->BytesXfer = VStorPacket->VmSrb.DataTransferLength; 404 request->bytes_xfer = vstor_packet->vm_srb.data_transfer_length;
402 405
403 request->OnIOCompletion(request); 406 request->on_io_completion(request);
404 407
405 atomic_dec(&storDevice->NumOutstandingRequests); 408 atomic_dec(&stor_device->num_outstanding_req);
406 409
407 PutStorDevice(Device); 410 put_stor_device(device);
408} 411}
409 412
410static void StorVscOnReceive(struct hv_device *Device, 413static void stor_vsc_on_receive(struct hv_device *device,
411 struct vstor_packet *VStorPacket, 414 struct vstor_packet *vstor_packet,
412 struct storvsc_request_extension *RequestExt) 415 struct storvsc_request_extension *request_ext)
413{ 416{
414 switch (VStorPacket->Operation) { 417 switch (vstor_packet->operation) {
415 case VStorOperationCompleteIo: 418 case VSTOR_OPERATION_COMPLETE_IO:
416 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION"); 419 DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION");
417 StorVscOnIOCompletion(Device, VStorPacket, RequestExt); 420 stor_vsc_on_io_completion(device, vstor_packet, request_ext);
418 break; 421 break;
419 case VStorOperationRemoveDevice: 422 case VSTOR_OPERATION_REMOVE_DEVICE:
420 DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION"); 423 DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION");
421 /* TODO: */ 424 /* TODO: */
422 break; 425 break;
423 426
424 default: 427 default:
425 DPRINT_INFO(STORVSC, "Unknown operation received - %d", 428 DPRINT_INFO(STORVSC, "Unknown operation received - %d",
426 VStorPacket->Operation); 429 vstor_packet->operation);
427 break; 430 break;
428 } 431 }
429} 432}
430 433
431static void StorVscOnChannelCallback(void *context) 434static void stor_vsc_on_channel_callback(void *context)
432{ 435{
433 struct hv_device *device = (struct hv_device *)context; 436 struct hv_device *device = (struct hv_device *)context;
434 struct storvsc_device *storDevice; 437 struct storvsc_device *stor_device;
435 u32 bytesRecvd; 438 u32 bytes_recvd;
436 u64 requestId; 439 u64 request_id;
437 unsigned char packet[ALIGN_UP(sizeof(struct vstor_packet), 8)]; 440 unsigned char packet[ALIGN_UP(sizeof(struct vstor_packet), 8)];
438 struct storvsc_request_extension *request; 441 struct storvsc_request_extension *request;
439 int ret; 442 int ret;
440 443
441 /* ASSERT(device); */ 444 /* ASSERT(device); */
442 445
443 storDevice = MustGetStorDevice(device); 446 stor_device = must_get_stor_device(device);
444 if (!storDevice) { 447 if (!stor_device) {
445 DPRINT_ERR(STORVSC, "unable to get stor device..." 448 DPRINT_ERR(STORVSC, "unable to get stor device..."
446 "device being destroyed?"); 449 "device being destroyed?");
447 return; 450 return;
@@ -450,32 +453,33 @@ static void StorVscOnChannelCallback(void *context)
450 do { 453 do {
451 ret = vmbus_recvpacket(device->channel, packet, 454 ret = vmbus_recvpacket(device->channel, packet,
452 ALIGN_UP(sizeof(struct vstor_packet), 8), 455 ALIGN_UP(sizeof(struct vstor_packet), 8),
453 &bytesRecvd, &requestId); 456 &bytes_recvd, &request_id);
454 if (ret == 0 && bytesRecvd > 0) { 457 if (ret == 0 && bytes_recvd > 0) {
455 DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", 458 DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx",
456 bytesRecvd, requestId); 459 bytes_recvd, request_id);
457 460
458 /* ASSERT(bytesRecvd == sizeof(struct vstor_packet)); */ 461 /* ASSERT(bytes_recvd ==
462 sizeof(struct vstor_packet)); */
459 463
460 request = (struct storvsc_request_extension *) 464 request = (struct storvsc_request_extension *)
461 (unsigned long)requestId; 465 (unsigned long)request_id;
462 /* ASSERT(request);c */ 466 /* ASSERT(request);c */
463 467
464 /* if (vstorPacket.Flags & SYNTHETIC_FLAG) */ 468 /* if (vstor_packet.Flags & SYNTHETIC_FLAG) */
465 if ((request == &storDevice->InitRequest) || 469 if ((request == &stor_device->init_request) ||
466 (request == &storDevice->ResetRequest)) { 470 (request == &stor_device->reset_request)) {
467 /* DPRINT_INFO(STORVSC, 471 /* DPRINT_INFO(STORVSC,
468 * "reset completion - operation " 472 * "reset completion - operation "
469 * "%u status %u", 473 * "%u status %u",
470 * vstorPacket.Operation, 474 * vstor_packet.Operation,
471 * vstorPacket.Status); */ 475 * vstor_packet.Status); */
472 476
473 memcpy(&request->VStorPacket, packet, 477 memcpy(&request->vstor_packet, packet,
474 sizeof(struct vstor_packet)); 478 sizeof(struct vstor_packet));
475 479
476 osd_WaitEventSet(request->WaitEvent); 480 osd_waitevent_set(request->wait_event);
477 } else { 481 } else {
478 StorVscOnReceive(device, 482 stor_vsc_on_receive(device,
479 (struct vstor_packet *)packet, 483 (struct vstor_packet *)packet,
480 request); 484 request);
481 } 485 }
@@ -485,52 +489,55 @@ static void StorVscOnChannelCallback(void *context)
485 } 489 }
486 } while (1); 490 } while (1);
487 491
488 PutStorDevice(device); 492 put_stor_device(device);
489 return; 493 return;
490} 494}
491 495
492static int StorVscConnectToVsp(struct hv_device *Device) 496static int stor_vsc_connect_to_vsp(struct hv_device *device)
493{ 497{
494 struct vmstorage_channel_properties props; 498 struct vmstorage_channel_properties props;
495 struct storvsc_driver_object *storDriver; 499 struct storvsc_driver_object *stor_driver;
496 int ret; 500 int ret;
497 501
498 storDriver = (struct storvsc_driver_object *)Device->Driver; 502 stor_driver = (struct storvsc_driver_object *)device->Driver;
499 memset(&props, 0, sizeof(struct vmstorage_channel_properties)); 503 memset(&props, 0, sizeof(struct vmstorage_channel_properties));
500 504
501 /* Open the channel */ 505 /* Open the channel */
502 ret = vmbus_open(Device->channel, 506 ret = vmbus_open(device->channel,
503 storDriver->RingBufferSize, storDriver->RingBufferSize, 507 stor_driver->ring_buffer_size,
508 stor_driver->ring_buffer_size,
504 (void *)&props, 509 (void *)&props,
505 sizeof(struct vmstorage_channel_properties), 510 sizeof(struct vmstorage_channel_properties),
506 StorVscOnChannelCallback, Device); 511 stor_vsc_on_channel_callback, device);
507 512
508 DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", 513 DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d",
509 props.PathId, props.TargetId, props.MaxTransferBytes); 514 props.path_id, props.target_id, props.max_transfer_bytes);
510 515
511 if (ret != 0) { 516 if (ret != 0) {
512 DPRINT_ERR(STORVSC, "unable to open channel: %d", ret); 517 DPRINT_ERR(STORVSC, "unable to open channel: %d", ret);
513 return -1; 518 return -1;
514 } 519 }
515 520
516 ret = StorVscChannelInit(Device); 521 ret = stor_vsc_channel_init(device);
517 522
518 return ret; 523 return ret;
519} 524}
520 525
521/* 526/*
522 * StorVscOnDeviceAdd - Callback when the device belonging to this driver is added 527 * stor_vsc_on_device_add - Callback when the device belonging to this driver
528 * is added
523 */ 529 */
524static int StorVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) 530static int stor_vsc_on_device_add(struct hv_device *device,
531 void *additional_info)
525{ 532{
526 struct storvsc_device *storDevice; 533 struct storvsc_device *stor_device;
527 /* struct vmstorage_channel_properties *props; */ 534 /* struct vmstorage_channel_properties *props; */
528 struct storvsc_device_info *deviceInfo; 535 struct storvsc_device_info *device_info;
529 int ret = 0; 536 int ret = 0;
530 537
531 deviceInfo = (struct storvsc_device_info *)AdditionalInfo; 538 device_info = (struct storvsc_device_info *)additional_info;
532 storDevice = AllocStorDevice(Device); 539 stor_device = alloc_stor_device(device);
533 if (!storDevice) { 540 if (!stor_device) {
534 ret = -1; 541 ret = -1;
535 goto Cleanup; 542 goto Cleanup;
536 } 543 }
@@ -550,103 +557,103 @@ static int StorVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo)
550 storChannel->PathId = props->PathId; 557 storChannel->PathId = props->PathId;
551 storChannel->TargetId = props->TargetId; */ 558 storChannel->TargetId = props->TargetId; */
552 559
553 storDevice->PortNumber = deviceInfo->PortNumber; 560 stor_device->port_number = device_info->port_number;
554 /* Send it back up */ 561 /* Send it back up */
555 ret = StorVscConnectToVsp(Device); 562 ret = stor_vsc_connect_to_vsp(device);
556 563
557 /* deviceInfo->PortNumber = storDevice->PortNumber; */ 564 /* device_info->PortNumber = stor_device->PortNumber; */
558 deviceInfo->PathId = storDevice->PathId; 565 device_info->path_id = stor_device->path_id;
559 deviceInfo->TargetId = storDevice->TargetId; 566 device_info->target_id = stor_device->target_id;
560 567
561 DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n", 568 DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n",
562 storDevice->PortNumber, storDevice->PathId, 569 stor_device->port_number, stor_device->path_id,
563 storDevice->TargetId); 570 stor_device->target_id);
564 571
565Cleanup: 572Cleanup:
566 return ret; 573 return ret;
567} 574}
568 575
569/* 576/*
570 * StorVscOnDeviceRemove - Callback when the our device is being removed 577 * stor_vsc_on_device_remove - Callback when the our device is being removed
571 */ 578 */
572static int StorVscOnDeviceRemove(struct hv_device *Device) 579static int stor_vsc_on_device_remove(struct hv_device *device)
573{ 580{
574 struct storvsc_device *storDevice; 581 struct storvsc_device *stor_device;
575 582
576 DPRINT_INFO(STORVSC, "disabling storage device (%p)...", 583 DPRINT_INFO(STORVSC, "disabling storage device (%p)...",
577 Device->Extension); 584 device->Extension);
578 585
579 storDevice = ReleaseStorDevice(Device); 586 stor_device = release_stor_device(device);
580 587
581 /* 588 /*
582 * At this point, all outbound traffic should be disable. We 589 * At this point, all outbound traffic should be disable. We
583 * only allow inbound traffic (responses) to proceed so that 590 * only allow inbound traffic (responses) to proceed so that
584 * outstanding requests can be completed. 591 * outstanding requests can be completed.
585 */ 592 */
586 while (atomic_read(&storDevice->NumOutstandingRequests)) { 593 while (atomic_read(&stor_device->num_outstanding_req)) {
587 DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", 594 DPRINT_INFO(STORVSC, "waiting for %d requests to complete...",
588 atomic_read(&storDevice->NumOutstandingRequests)); 595 atomic_read(&stor_device->num_outstanding_req));
589 udelay(100); 596 udelay(100);
590 } 597 }
591 598
592 DPRINT_INFO(STORVSC, "removing storage device (%p)...", 599 DPRINT_INFO(STORVSC, "removing storage device (%p)...",
593 Device->Extension); 600 device->Extension);
594 601
595 storDevice = FinalReleaseStorDevice(Device); 602 stor_device = final_release_stor_device(device);
596 603
597 DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", storDevice); 604 DPRINT_INFO(STORVSC, "storage device (%p) safe to remove", stor_device);
598 605
599 /* Close the channel */ 606 /* Close the channel */
600 vmbus_close(Device->channel); 607 vmbus_close(device->channel);
601 608
602 FreeStorDevice(storDevice); 609 free_stor_device(stor_device);
603 return 0; 610 return 0;
604} 611}
605 612
606int StorVscOnHostReset(struct hv_device *Device) 613int stor_vsc_on_host_reset(struct hv_device *device)
607{ 614{
608 struct storvsc_device *storDevice; 615 struct storvsc_device *stor_device;
609 struct storvsc_request_extension *request; 616 struct storvsc_request_extension *request;
610 struct vstor_packet *vstorPacket; 617 struct vstor_packet *vstor_packet;
611 int ret; 618 int ret;
612 619
613 DPRINT_INFO(STORVSC, "resetting host adapter..."); 620 DPRINT_INFO(STORVSC, "resetting host adapter...");
614 621
615 storDevice = GetStorDevice(Device); 622 stor_device = get_stor_device(device);
616 if (!storDevice) { 623 if (!stor_device) {
617 DPRINT_ERR(STORVSC, "unable to get stor device..." 624 DPRINT_ERR(STORVSC, "unable to get stor device..."
618 "device being destroyed?"); 625 "device being destroyed?");
619 return -1; 626 return -1;
620 } 627 }
621 628
622 request = &storDevice->ResetRequest; 629 request = &stor_device->reset_request;
623 vstorPacket = &request->VStorPacket; 630 vstor_packet = &request->vstor_packet;
624 631
625 request->WaitEvent = osd_WaitEventCreate(); 632 request->wait_event = osd_waitevent_create();
626 if (!request->WaitEvent) { 633 if (!request->wait_event) {
627 ret = -ENOMEM; 634 ret = -ENOMEM;
628 goto Cleanup; 635 goto Cleanup;
629 } 636 }
630 637
631 vstorPacket->Operation = VStorOperationResetBus; 638 vstor_packet->operation = VSTOR_OPERATION_RESET_BUS;
632 vstorPacket->Flags = REQUEST_COMPLETION_FLAG; 639 vstor_packet->flags = REQUEST_COMPLETION_FLAG;
633 vstorPacket->VmSrb.PathId = storDevice->PathId; 640 vstor_packet->vm_srb.path_id = stor_device->path_id;
634 641
635 ret = vmbus_sendpacket(Device->channel, vstorPacket, 642 ret = vmbus_sendpacket(device->channel, vstor_packet,
636 sizeof(struct vstor_packet), 643 sizeof(struct vstor_packet),
637 (unsigned long)&storDevice->ResetRequest, 644 (unsigned long)&stor_device->reset_request,
638 VmbusPacketTypeDataInBand, 645 VmbusPacketTypeDataInBand,
639 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); 646 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
640 if (ret != 0) { 647 if (ret != 0) {
641 DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", 648 DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d",
642 vstorPacket, ret); 649 vstor_packet, ret);
643 goto Cleanup; 650 goto Cleanup;
644 } 651 }
645 652
646 /* FIXME: Add a timeout */ 653 /* FIXME: Add a timeout */
647 osd_WaitEventWait(request->WaitEvent); 654 osd_waitevent_wait(request->wait_event);
648 655
649 kfree(request->WaitEvent); 656 kfree(request->wait_event);
650 DPRINT_INFO(STORVSC, "host adapter reset completed"); 657 DPRINT_INFO(STORVSC, "host adapter reset completed");
651 658
652 /* 659 /*
@@ -655,118 +662,118 @@ int StorVscOnHostReset(struct hv_device *Device)
655 */ 662 */
656 663
657Cleanup: 664Cleanup:
658 PutStorDevice(Device); 665 put_stor_device(device);
659 return ret; 666 return ret;
660} 667}
661 668
662/* 669/*
663 * StorVscOnIORequest - Callback to initiate an I/O request 670 * stor_vsc_on_io_request - Callback to initiate an I/O request
664 */ 671 */
665static int StorVscOnIORequest(struct hv_device *Device, 672static int stor_vsc_on_io_request(struct hv_device *device,
666 struct hv_storvsc_request *Request) 673 struct hv_storvsc_request *request)
667{ 674{
668 struct storvsc_device *storDevice; 675 struct storvsc_device *stor_device;
669 struct storvsc_request_extension *requestExtension; 676 struct storvsc_request_extension *request_extension;
670 struct vstor_packet *vstorPacket; 677 struct vstor_packet *vstor_packet;
671 int ret = 0; 678 int ret = 0;
672 679
673 requestExtension = 680 request_extension =
674 (struct storvsc_request_extension *)Request->Extension; 681 (struct storvsc_request_extension *)request->extension;
675 vstorPacket = &requestExtension->VStorPacket; 682 vstor_packet = &request_extension->vstor_packet;
676 storDevice = GetStorDevice(Device); 683 stor_device = get_stor_device(device);
677 684
678 DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, " 685 DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, "
679 "Extension %p", Device, storDevice, Request, 686 "Extension %p", device, stor_device, request,
680 requestExtension); 687 request_extension);
681 688
682 DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d", 689 DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d",
683 Request, Request->DataBuffer.Length, Request->Bus, 690 request, request->data_buffer.Length, request->bus,
684 Request->TargetId, Request->LunId, Request->CdbLen); 691 request->target_id, request->lun_id, request->cdb_len);
685 692
686 if (!storDevice) { 693 if (!stor_device) {
687 DPRINT_ERR(STORVSC, "unable to get stor device..." 694 DPRINT_ERR(STORVSC, "unable to get stor device..."
688 "device being destroyed?"); 695 "device being destroyed?");
689 return -2; 696 return -2;
690 } 697 }
691 698
692 /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, Request->Cdb, 699 /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, request->Cdb,
693 * Request->CdbLen); */ 700 * request->CdbLen); */
694 701
695 requestExtension->Request = Request; 702 request_extension->request = request;
696 requestExtension->Device = Device; 703 request_extension->device = device;
697 704
698 memset(vstorPacket, 0 , sizeof(struct vstor_packet)); 705 memset(vstor_packet, 0 , sizeof(struct vstor_packet));
699 706
700 vstorPacket->Flags |= REQUEST_COMPLETION_FLAG; 707 vstor_packet->flags |= REQUEST_COMPLETION_FLAG;
701 708
702 vstorPacket->VmSrb.Length = sizeof(struct vmscsi_request); 709 vstor_packet->vm_srb.length = sizeof(struct vmscsi_request);
703 710
704 vstorPacket->VmSrb.PortNumber = Request->Host; 711 vstor_packet->vm_srb.port_number = request->host;
705 vstorPacket->VmSrb.PathId = Request->Bus; 712 vstor_packet->vm_srb.path_id = request->bus;
706 vstorPacket->VmSrb.TargetId = Request->TargetId; 713 vstor_packet->vm_srb.target_id = request->target_id;
707 vstorPacket->VmSrb.Lun = Request->LunId; 714 vstor_packet->vm_srb.lun = request->lun_id;
708 715
709 vstorPacket->VmSrb.SenseInfoLength = SENSE_BUFFER_SIZE; 716 vstor_packet->vm_srb.sense_info_length = SENSE_BUFFER_SIZE;
710 717
711 /* Copy over the scsi command descriptor block */ 718 /* Copy over the scsi command descriptor block */
712 vstorPacket->VmSrb.CdbLength = Request->CdbLen; 719 vstor_packet->vm_srb.cdb_length = request->cdb_len;
713 memcpy(&vstorPacket->VmSrb.Cdb, Request->Cdb, Request->CdbLen); 720 memcpy(&vstor_packet->vm_srb.cdb, request->cdb, request->cdb_len);
714 721
715 vstorPacket->VmSrb.DataIn = Request->Type; 722 vstor_packet->vm_srb.data_in = request->type;
716 vstorPacket->VmSrb.DataTransferLength = Request->DataBuffer.Length; 723 vstor_packet->vm_srb.data_transfer_length = request->data_buffer.Length;
717 724
718 vstorPacket->Operation = VStorOperationExecuteSRB; 725 vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB;
719 726
720 DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, " 727 DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, "
721 "lun %d senselen %d cdblen %d", 728 "lun %d senselen %d cdblen %d",
722 vstorPacket->VmSrb.Length, 729 vstor_packet->vm_srb.length,
723 vstorPacket->VmSrb.PortNumber, 730 vstor_packet->vm_srb.port_number,
724 vstorPacket->VmSrb.PathId, 731 vstor_packet->vm_srb.path_id,
725 vstorPacket->VmSrb.TargetId, 732 vstor_packet->vm_srb.target_id,
726 vstorPacket->VmSrb.Lun, 733 vstor_packet->vm_srb.lun,
727 vstorPacket->VmSrb.SenseInfoLength, 734 vstor_packet->vm_srb.sense_info_length,
728 vstorPacket->VmSrb.CdbLength); 735 vstor_packet->vm_srb.cdb_length);
729 736
730 if (requestExtension->Request->DataBuffer.Length) { 737 if (request_extension->request->data_buffer.Length) {
731 ret = vmbus_sendpacket_multipagebuffer(Device->channel, 738 ret = vmbus_sendpacket_multipagebuffer(device->channel,
732 &requestExtension->Request->DataBuffer, 739 &request_extension->request->data_buffer,
733 vstorPacket, 740 vstor_packet,
734 sizeof(struct vstor_packet), 741 sizeof(struct vstor_packet),
735 (unsigned long)requestExtension); 742 (unsigned long)request_extension);
736 } else { 743 } else {
737 ret = vmbus_sendpacket(Device->channel, vstorPacket, 744 ret = vmbus_sendpacket(device->channel, vstor_packet,
738 sizeof(struct vstor_packet), 745 sizeof(struct vstor_packet),
739 (unsigned long)requestExtension, 746 (unsigned long)request_extension,
740 VmbusPacketTypeDataInBand, 747 VmbusPacketTypeDataInBand,
741 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); 748 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
742 } 749 }
743 750
744 if (ret != 0) { 751 if (ret != 0) {
745 DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", 752 DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d",
746 vstorPacket, ret); 753 vstor_packet, ret);
747 } 754 }
748 755
749 atomic_inc(&storDevice->NumOutstandingRequests); 756 atomic_inc(&stor_device->num_outstanding_req);
750 757
751 PutStorDevice(Device); 758 put_stor_device(device);
752 return ret; 759 return ret;
753} 760}
754 761
755/* 762/*
756 * StorVscOnCleanup - Perform any cleanup when the driver is removed 763 * stor_vsc_on_cleanup - Perform any cleanup when the driver is removed
757 */ 764 */
758static void StorVscOnCleanup(struct hv_driver *Driver) 765static void stor_vsc_on_cleanup(struct hv_driver *driver)
759{ 766{
760} 767}
761 768
762/* 769/*
763 * StorVscInitialize - Main entry point 770 * stor_vsc_initialize - Main entry point
764 */ 771 */
765int StorVscInitialize(struct hv_driver *Driver) 772int stor_vsc_initialize(struct hv_driver *driver)
766{ 773{
767 struct storvsc_driver_object *storDriver; 774 struct storvsc_driver_object *stor_driver;
768 775
769 storDriver = (struct storvsc_driver_object *)Driver; 776 stor_driver = (struct storvsc_driver_object *)driver;
770 777
771 DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd " 778 DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd "
772 "sizeof(struct storvsc_request_extension)=%zd " 779 "sizeof(struct storvsc_request_extension)=%zd "
@@ -778,13 +785,14 @@ int StorVscInitialize(struct hv_driver *Driver)
778 sizeof(struct vmscsi_request)); 785 sizeof(struct vmscsi_request));
779 786
780 /* Make sure we are at least 2 pages since 1 page is used for control */ 787 /* Make sure we are at least 2 pages since 1 page is used for control */
781 /* ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1)); */ 788 /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */
782 789
783 Driver->name = gDriverName; 790 driver->name = g_driver_name;
784 memcpy(&Driver->deviceType, &gStorVscDeviceType, 791 memcpy(&driver->deviceType, &gStorVscDeviceType,
785 sizeof(struct hv_guid)); 792 sizeof(struct hv_guid));
786 793
787 storDriver->RequestExtSize = sizeof(struct storvsc_request_extension); 794 stor_driver->request_ext_size =
795 sizeof(struct storvsc_request_extension);
788 796
789 /* 797 /*
790 * Divide the ring buffer data size (which is 1 page less 798 * Divide the ring buffer data size (which is 1 page less
@@ -792,22 +800,22 @@ int StorVscInitialize(struct hv_driver *Driver)
792 * the ring buffer indices) by the max request size (which is 800 * the ring buffer indices) by the max request size (which is
793 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) 801 * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64)
794 */ 802 */
795 storDriver->MaxOutstandingRequestsPerChannel = 803 stor_driver->max_outstanding_req_per_channel =
796 ((storDriver->RingBufferSize - PAGE_SIZE) / 804 ((stor_driver->ring_buffer_size - PAGE_SIZE) /
797 ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + 805 ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET +
798 sizeof(struct vstor_packet) + sizeof(u64), 806 sizeof(struct vstor_packet) + sizeof(u64),
799 sizeof(u64))); 807 sizeof(u64)));
800 808
801 DPRINT_INFO(STORVSC, "max io %u, currently %u\n", 809 DPRINT_INFO(STORVSC, "max io %u, currently %u\n",
802 storDriver->MaxOutstandingRequestsPerChannel, 810 stor_driver->max_outstanding_req_per_channel,
803 STORVSC_MAX_IO_REQUESTS); 811 STORVSC_MAX_IO_REQUESTS);
804 812
805 /* Setup the dispatch table */ 813 /* Setup the dispatch table */
806 storDriver->Base.OnDeviceAdd = StorVscOnDeviceAdd; 814 stor_driver->base.OnDeviceAdd = stor_vsc_on_device_add;
807 storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove; 815 stor_driver->base.OnDeviceRemove = stor_vsc_on_device_remove;
808 storDriver->Base.OnCleanup = StorVscOnCleanup; 816 stor_driver->base.OnCleanup = stor_vsc_on_cleanup;
809 817
810 storDriver->OnIORequest = StorVscOnIORequest; 818 stor_driver->on_io_request = stor_vsc_on_io_request;
811 819
812 return 0; 820 return 0;
813} 821}
diff --git a/drivers/staging/hv/storvsc_api.h b/drivers/staging/hv/storvsc_api.h
index 8505a1c5f9ee..fbf57556d890 100644
--- a/drivers/staging/hv/storvsc_api.h
+++ b/drivers/staging/hv/storvsc_api.h
@@ -53,58 +53,58 @@ enum storvsc_request_type{
53}; 53};
54 54
55struct hv_storvsc_request { 55struct hv_storvsc_request {
56 enum storvsc_request_type Type; 56 enum storvsc_request_type type;
57 u32 Host; 57 u32 host;
58 u32 Bus; 58 u32 bus;
59 u32 TargetId; 59 u32 target_id;
60 u32 LunId; 60 u32 lun_id;
61 u8 *Cdb; 61 u8 *cdb;
62 u32 CdbLen; 62 u32 cdb_len;
63 u32 Status; 63 u32 status;
64 u32 BytesXfer; 64 u32 bytes_xfer;
65 65
66 unsigned char *SenseBuffer; 66 unsigned char *sense_buffer;
67 u32 SenseBufferSize; 67 u32 sense_buffer_size;
68 68
69 void *Context; 69 void *context;
70 70
71 void (*OnIOCompletion)(struct hv_storvsc_request *Request); 71 void (*on_io_completion)(struct hv_storvsc_request *request);
72 72
73 /* This points to the memory after DataBuffer */ 73 /* This points to the memory after DataBuffer */
74 void *Extension; 74 void *extension;
75 75
76 struct hv_multipage_buffer DataBuffer; 76 struct hv_multipage_buffer data_buffer;
77}; 77};
78 78
79/* Represents the block vsc driver */ 79/* Represents the block vsc driver */
80struct storvsc_driver_object { 80struct storvsc_driver_object {
81 /* Must be the first field */ 81 /* Must be the first field */
82 /* Which is a bug FIXME! */ 82 /* Which is a bug FIXME! */
83 struct hv_driver Base; 83 struct hv_driver base;
84 84
85 /* Set by caller (in bytes) */ 85 /* Set by caller (in bytes) */
86 u32 RingBufferSize; 86 u32 ring_buffer_size;
87 87
88 /* Allocate this much private extension for each I/O request */ 88 /* Allocate this much private extension for each I/O request */
89 u32 RequestExtSize; 89 u32 request_ext_size;
90 90
91 /* Maximum # of requests in flight per channel/device */ 91 /* Maximum # of requests in flight per channel/device */
92 u32 MaxOutstandingRequestsPerChannel; 92 u32 max_outstanding_req_per_channel;
93 93
94 /* Specific to this driver */ 94 /* Specific to this driver */
95 int (*OnIORequest)(struct hv_device *Device, 95 int (*on_io_request)(struct hv_device *device,
96 struct hv_storvsc_request *Request); 96 struct hv_storvsc_request *request);
97}; 97};
98 98
99struct storvsc_device_info { 99struct storvsc_device_info {
100 unsigned int PortNumber; 100 unsigned int port_number;
101 unsigned char PathId; 101 unsigned char path_id;
102 unsigned char TargetId; 102 unsigned char target_id;
103}; 103};
104 104
105/* Interface */ 105/* Interface */
106int StorVscInitialize(struct hv_driver *driver); 106int stor_vsc_initialize(struct hv_driver *driver);
107int StorVscOnHostReset(struct hv_device *Device); 107int stor_vsc_on_host_reset(struct hv_device *device);
108int BlkVscInitialize(struct hv_driver *driver); 108int blk_vsc_initialize(struct hv_driver *driver);
109 109
110#endif /* _STORVSC_API_H_ */ 110#endif /* _STORVSC_API_H_ */
diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c
index 6f8d67d0d64f..17f1b344fbc5 100644
--- a/drivers/staging/hv/storvsc_drv.c
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -140,28 +140,28 @@ static int storvsc_drv_init(int (*drv_init)(struct hv_driver *drv))
140 struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv.drv_obj; 140 struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv.drv_obj;
141 struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx; 141 struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx;
142 142
143 storvsc_drv_obj->RingBufferSize = storvsc_ringbuffer_size; 143 storvsc_drv_obj->ring_buffer_size = storvsc_ringbuffer_size;
144 144
145 /* Callback to client driver to complete the initialization */ 145 /* Callback to client driver to complete the initialization */
146 drv_init(&storvsc_drv_obj->Base); 146 drv_init(&storvsc_drv_obj->base);
147 147
148 DPRINT_INFO(STORVSC_DRV, 148 DPRINT_INFO(STORVSC_DRV,
149 "request extension size %u, max outstanding reqs %u", 149 "request extension size %u, max outstanding reqs %u",
150 storvsc_drv_obj->RequestExtSize, 150 storvsc_drv_obj->request_ext_size,
151 storvsc_drv_obj->MaxOutstandingRequestsPerChannel); 151 storvsc_drv_obj->max_outstanding_req_per_channel);
152 152
153 if (storvsc_drv_obj->MaxOutstandingRequestsPerChannel < 153 if (storvsc_drv_obj->max_outstanding_req_per_channel <
154 STORVSC_MAX_IO_REQUESTS) { 154 STORVSC_MAX_IO_REQUESTS) {
155 DPRINT_ERR(STORVSC_DRV, 155 DPRINT_ERR(STORVSC_DRV,
156 "The number of outstanding io requests (%d) " 156 "The number of outstanding io requests (%d) "
157 "is larger than that supported (%d) internally.", 157 "is larger than that supported (%d) internally.",
158 STORVSC_MAX_IO_REQUESTS, 158 STORVSC_MAX_IO_REQUESTS,
159 storvsc_drv_obj->MaxOutstandingRequestsPerChannel); 159 storvsc_drv_obj->max_outstanding_req_per_channel);
160 return -1; 160 return -1;
161 } 161 }
162 162
163 drv_ctx->driver.name = storvsc_drv_obj->Base.name; 163 drv_ctx->driver.name = storvsc_drv_obj->base.name;
164 memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, 164 memcpy(&drv_ctx->class_id, &storvsc_drv_obj->base.deviceType,
165 sizeof(struct hv_guid)); 165 sizeof(struct hv_guid));
166 166
167 drv_ctx->probe = storvsc_probe; 167 drv_ctx->probe = storvsc_probe;
@@ -206,8 +206,8 @@ static void storvsc_drv_exit(void)
206 device_unregister(current_dev); 206 device_unregister(current_dev);
207 } 207 }
208 208
209 if (storvsc_drv_obj->Base.OnCleanup) 209 if (storvsc_drv_obj->base.OnCleanup)
210 storvsc_drv_obj->Base.OnCleanup(&storvsc_drv_obj->Base); 210 storvsc_drv_obj->base.OnCleanup(&storvsc_drv_obj->base);
211 211
212 vmbus_child_driver_unregister(drv_ctx); 212 vmbus_child_driver_unregister(drv_ctx);
213 return; 213 return;
@@ -231,7 +231,7 @@ static int storvsc_probe(struct device *device)
231 struct host_device_context *host_device_ctx; 231 struct host_device_context *host_device_ctx;
232 struct storvsc_device_info device_info; 232 struct storvsc_device_info device_info;
233 233
234 if (!storvsc_drv_obj->Base.OnDeviceAdd) 234 if (!storvsc_drv_obj->base.OnDeviceAdd)
235 return -1; 235 return -1;
236 236
237 host = scsi_host_alloc(&scsi_driver, 237 host = scsi_host_alloc(&scsi_driver,
@@ -252,7 +252,7 @@ static int storvsc_probe(struct device *device)
252 host_device_ctx->request_pool = 252 host_device_ctx->request_pool =
253 kmem_cache_create(dev_name(&device_ctx->device), 253 kmem_cache_create(dev_name(&device_ctx->device),
254 sizeof(struct storvsc_cmd_request) + 254 sizeof(struct storvsc_cmd_request) +
255 storvsc_drv_obj->RequestExtSize, 0, 255 storvsc_drv_obj->request_ext_size, 0,
256 SLAB_HWCACHE_ALIGN, NULL); 256 SLAB_HWCACHE_ALIGN, NULL);
257 257
258 if (!host_device_ctx->request_pool) { 258 if (!host_device_ctx->request_pool) {
@@ -260,9 +260,9 @@ static int storvsc_probe(struct device *device)
260 return -ENOMEM; 260 return -ENOMEM;
261 } 261 }
262 262
263 device_info.PortNumber = host->host_no; 263 device_info.port_number = host->host_no;
264 /* Call to the vsc driver to add the device */ 264 /* Call to the vsc driver to add the device */
265 ret = storvsc_drv_obj->Base.OnDeviceAdd(device_obj, 265 ret = storvsc_drv_obj->base.OnDeviceAdd(device_obj,
266 (void *)&device_info); 266 (void *)&device_info);
267 if (ret != 0) { 267 if (ret != 0) {
268 DPRINT_ERR(STORVSC_DRV, "unable to add scsi vsc device"); 268 DPRINT_ERR(STORVSC_DRV, "unable to add scsi vsc device");
@@ -272,8 +272,8 @@ static int storvsc_probe(struct device *device)
272 } 272 }
273 273
274 /* host_device_ctx->port = device_info.PortNumber; */ 274 /* host_device_ctx->port = device_info.PortNumber; */
275 host_device_ctx->path = device_info.PathId; 275 host_device_ctx->path = device_info.path_id;
276 host_device_ctx->target = device_info.TargetId; 276 host_device_ctx->target = device_info.target_id;
277 277
278 /* max # of devices per target */ 278 /* max # of devices per target */
279 host->max_lun = STORVSC_MAX_LUNS_PER_TARGET; 279 host->max_lun = STORVSC_MAX_LUNS_PER_TARGET;
@@ -287,7 +287,7 @@ static int storvsc_probe(struct device *device)
287 if (ret != 0) { 287 if (ret != 0) {
288 DPRINT_ERR(STORVSC_DRV, "unable to add scsi host device"); 288 DPRINT_ERR(STORVSC_DRV, "unable to add scsi host device");
289 289
290 storvsc_drv_obj->Base.OnDeviceRemove(device_obj); 290 storvsc_drv_obj->base.OnDeviceRemove(device_obj);
291 291
292 kmem_cache_destroy(host_device_ctx->request_pool); 292 kmem_cache_destroy(host_device_ctx->request_pool);
293 scsi_host_put(host); 293 scsi_host_put(host);
@@ -317,14 +317,14 @@ static int storvsc_remove(struct device *device)
317 (struct host_device_context *)host->hostdata; 317 (struct host_device_context *)host->hostdata;
318 318
319 319
320 if (!storvsc_drv_obj->Base.OnDeviceRemove) 320 if (!storvsc_drv_obj->base.OnDeviceRemove)
321 return -1; 321 return -1;
322 322
323 /* 323 /*
324 * Call to the vsc driver to let it know that the device is being 324 * Call to the vsc driver to let it know that the device is being
325 * removed 325 * removed
326 */ 326 */
327 ret = storvsc_drv_obj->Base.OnDeviceRemove(device_obj); 327 ret = storvsc_drv_obj->base.OnDeviceRemove(device_obj);
328 if (ret != 0) { 328 if (ret != 0) {
329 /* TODO: */ 329 /* TODO: */
330 DPRINT_ERR(STORVSC, "unable to remove vsc device (ret %d)", 330 DPRINT_ERR(STORVSC, "unable to remove vsc device (ret %d)",
@@ -350,7 +350,7 @@ static int storvsc_remove(struct device *device)
350static void storvsc_commmand_completion(struct hv_storvsc_request *request) 350static void storvsc_commmand_completion(struct hv_storvsc_request *request)
351{ 351{
352 struct storvsc_cmd_request *cmd_request = 352 struct storvsc_cmd_request *cmd_request =
353 (struct storvsc_cmd_request *)request->Context; 353 (struct storvsc_cmd_request *)request->context;
354 struct scsi_cmnd *scmnd = cmd_request->cmd; 354 struct scsi_cmnd *scmnd = cmd_request->cmd;
355 struct host_device_context *host_device_ctx = 355 struct host_device_context *host_device_ctx =
356 (struct host_device_context *)scmnd->device->host->hostdata; 356 (struct host_device_context *)scmnd->device->host->hostdata;
@@ -375,16 +375,17 @@ static void storvsc_commmand_completion(struct hv_storvsc_request *request)
375 cmd_request->bounce_sgl_count); 375 cmd_request->bounce_sgl_count);
376 } 376 }
377 377
378 scmnd->result = request->Status; 378 scmnd->result = request->status;
379 379
380 if (scmnd->result) { 380 if (scmnd->result) {
381 if (scsi_normalize_sense(scmnd->sense_buffer, 381 if (scsi_normalize_sense(scmnd->sense_buffer,
382 request->SenseBufferSize, &sense_hdr)) 382 request->sense_buffer_size, &sense_hdr))
383 scsi_print_sense_hdr("storvsc", &sense_hdr); 383 scsi_print_sense_hdr("storvsc", &sense_hdr);
384 } 384 }
385 385
386 /* ASSERT(request->BytesXfer <= request->DataBuffer.Length); */ 386 /* ASSERT(request->BytesXfer <= request->data_buffer.Length); */
387 scsi_set_resid(scmnd, request->DataBuffer.Length - request->BytesXfer); 387 scsi_set_resid(scmnd,
388 request->data_buffer.Length - request->bytes_xfer);
388 389
389 scsi_done_fn = scmnd->scsi_done; 390 scsi_done_fn = scmnd->scsi_done;
390 391
@@ -657,42 +658,42 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd,
657 658
658 request = &cmd_request->request; 659 request = &cmd_request->request;
659 660
660 request->Extension = 661 request->extension =
661 (void *)((unsigned long)cmd_request + request_size); 662 (void *)((unsigned long)cmd_request + request_size);
662 DPRINT_DBG(STORVSC_DRV, "req %p size %d ext %d", request, request_size, 663 DPRINT_DBG(STORVSC_DRV, "req %p size %d ext %d", request, request_size,
663 storvsc_drv_obj->RequestExtSize); 664 storvsc_drv_obj->request_ext_size);
664 665
665 /* Build the SRB */ 666 /* Build the SRB */
666 switch (scmnd->sc_data_direction) { 667 switch (scmnd->sc_data_direction) {
667 case DMA_TO_DEVICE: 668 case DMA_TO_DEVICE:
668 request->Type = WRITE_TYPE; 669 request->type = WRITE_TYPE;
669 break; 670 break;
670 case DMA_FROM_DEVICE: 671 case DMA_FROM_DEVICE:
671 request->Type = READ_TYPE; 672 request->type = READ_TYPE;
672 break; 673 break;
673 default: 674 default:
674 request->Type = UNKNOWN_TYPE; 675 request->type = UNKNOWN_TYPE;
675 break; 676 break;
676 } 677 }
677 678
678 request->OnIOCompletion = storvsc_commmand_completion; 679 request->on_io_completion = storvsc_commmand_completion;
679 request->Context = cmd_request;/* scmnd; */ 680 request->context = cmd_request;/* scmnd; */
680 681
681 /* request->PortId = scmnd->device->channel; */ 682 /* request->PortId = scmnd->device->channel; */
682 request->Host = host_device_ctx->port; 683 request->host = host_device_ctx->port;
683 request->Bus = scmnd->device->channel; 684 request->bus = scmnd->device->channel;
684 request->TargetId = scmnd->device->id; 685 request->target_id = scmnd->device->id;
685 request->LunId = scmnd->device->lun; 686 request->lun_id = scmnd->device->lun;
686 687
687 /* ASSERT(scmnd->cmd_len <= 16); */ 688 /* ASSERT(scmnd->cmd_len <= 16); */
688 request->CdbLen = scmnd->cmd_len; 689 request->cdb_len = scmnd->cmd_len;
689 request->Cdb = scmnd->cmnd; 690 request->cdb = scmnd->cmnd;
690 691
691 request->SenseBuffer = scmnd->sense_buffer; 692 request->sense_buffer = scmnd->sense_buffer;
692 request->SenseBufferSize = SCSI_SENSE_BUFFERSIZE; 693 request->sense_buffer_size = SCSI_SENSE_BUFFERSIZE;
693 694
694 695
695 request->DataBuffer.Length = scsi_bufflen(scmnd); 696 request->data_buffer.Length = scsi_bufflen(scmnd);
696 if (scsi_sg_count(scmnd)) { 697 if (scsi_sg_count(scmnd)) {
697 sgl = (struct scatterlist *)scsi_sglist(scmnd); 698 sgl = (struct scatterlist *)scsi_sglist(scmnd);
698 sg_count = scsi_sg_count(scmnd); 699 sg_count = scsi_sg_count(scmnd);
@@ -733,25 +734,25 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd,
733 sg_count = cmd_request->bounce_sgl_count; 734 sg_count = cmd_request->bounce_sgl_count;
734 } 735 }
735 736
736 request->DataBuffer.Offset = sgl[0].offset; 737 request->data_buffer.Offset = sgl[0].offset;
737 738
738 for (i = 0; i < sg_count; i++) { 739 for (i = 0; i < sg_count; i++) {
739 DPRINT_DBG(STORVSC_DRV, "sgl[%d] len %d offset %d\n", 740 DPRINT_DBG(STORVSC_DRV, "sgl[%d] len %d offset %d\n",
740 i, sgl[i].length, sgl[i].offset); 741 i, sgl[i].length, sgl[i].offset);
741 request->DataBuffer.PfnArray[i] = 742 request->data_buffer.PfnArray[i] =
742 page_to_pfn(sg_page((&sgl[i]))); 743 page_to_pfn(sg_page((&sgl[i])));
743 } 744 }
744 } else if (scsi_sglist(scmnd)) { 745 } else if (scsi_sglist(scmnd)) {
745 /* ASSERT(scsi_bufflen(scmnd) <= PAGE_SIZE); */ 746 /* ASSERT(scsi_bufflen(scmnd) <= PAGE_SIZE); */
746 request->DataBuffer.Offset = 747 request->data_buffer.Offset =
747 virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1); 748 virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1);
748 request->DataBuffer.PfnArray[0] = 749 request->data_buffer.PfnArray[0] =
749 virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT; 750 virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT;
750 } 751 }
751 752
752retry_request: 753retry_request:
753 /* Invokes the vsc to start an IO */ 754 /* Invokes the vsc to start an IO */
754 ret = storvsc_drv_obj->OnIORequest(&device_ctx->device_obj, 755 ret = storvsc_drv_obj->on_io_request(&device_ctx->device_obj,
755 &cmd_request->request); 756 &cmd_request->request);
756 if (ret == -1) { 757 if (ret == -1) {
757 /* no more space */ 758 /* no more space */
@@ -844,7 +845,7 @@ static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd)
844 scmnd->device, &device_ctx->device_obj); 845 scmnd->device, &device_ctx->device_obj);
845 846
846 /* Invokes the vsc to reset the host/bus */ 847 /* Invokes the vsc to reset the host/bus */
847 ret = StorVscOnHostReset(&device_ctx->device_obj); 848 ret = stor_vsc_on_host_reset(&device_ctx->device_obj);
848 if (ret != 0) 849 if (ret != 0)
849 return ret; 850 return ret;
850 851
@@ -939,7 +940,7 @@ static int __init storvsc_init(void)
939 int ret; 940 int ret;
940 941
941 DPRINT_INFO(STORVSC_DRV, "Storvsc initializing...."); 942 DPRINT_INFO(STORVSC_DRV, "Storvsc initializing....");
942 ret = storvsc_drv_init(StorVscInitialize); 943 ret = storvsc_drv_init(stor_vsc_initialize);
943 return ret; 944 return ret;
944} 945}
945 946
diff --git a/drivers/staging/hv/vmbus.c b/drivers/staging/hv/vmbus.c
deleted file mode 100644
index d449daf81976..000000000000
--- a/drivers/staging/hv/vmbus.c
+++ /dev/null
@@ -1,274 +0,0 @@
1/*
2 * Copyright (c) 2009, Microsoft Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 *
17 * Authors:
18 * Haiyang Zhang <haiyangz@microsoft.com>
19 * Hank Janssen <hjanssen@microsoft.com>
20 *
21 */
22#include <linux/kernel.h>
23#include <linux/mm.h>
24#include <linux/slab.h>
25#include "osd.h"
26#include "logging.h"
27#include "version_info.h"
28#include "vmbus_private.h"
29
30static const char *gDriverName = "vmbus";
31
32/*
33 * Windows vmbus does not defined this.
34 * We defined this to be consistent with other devices
35 */
36/* {c5295816-f63a-4d5f-8d1a-4daf999ca185} */
37static const struct hv_guid gVmbusDeviceType = {
38 .data = {
39 0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d,
40 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85
41 }
42};
43
44/* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */
45static const struct hv_guid gVmbusDeviceId = {
46 .data = {
47 0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40,
48 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5
49 }
50};
51
52static struct hv_driver *gDriver; /* vmbus driver object */
53static struct hv_device *gDevice; /* vmbus root device */
54
55/*
56 * VmbusGetChannelOffers - Retrieve the channel offers from the parent partition
57 */
58static void VmbusGetChannelOffers(void)
59{
60 vmbus_request_offers();
61}
62
63/*
64 * VmbusCreateChildDevice - Creates the child device on the bus that represents the channel offer
65 */
66struct hv_device *VmbusChildDeviceCreate(struct hv_guid *DeviceType,
67 struct hv_guid *DeviceInstance,
68 struct vmbus_channel *channel)
69{
70 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
71
72 return vmbusDriver->OnChildDeviceCreate(DeviceType, DeviceInstance,
73 channel);
74}
75
76/*
77 * VmbusChildDeviceAdd - Registers the child device with the vmbus
78 */
79int VmbusChildDeviceAdd(struct hv_device *ChildDevice)
80{
81 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
82
83 return vmbusDriver->OnChildDeviceAdd(gDevice, ChildDevice);
84}
85
86/*
87 * VmbusChildDeviceRemove Unregisters the child device from the vmbus
88 */
89void VmbusChildDeviceRemove(struct hv_device *ChildDevice)
90{
91 struct vmbus_driver *vmbusDriver = (struct vmbus_driver *)gDriver;
92
93 vmbusDriver->OnChildDeviceRemove(ChildDevice);
94}
95
96/*
97 * VmbusOnDeviceAdd - Callback when the root bus device is added
98 */
99static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo)
100{
101 u32 *irqvector = AdditionalInfo;
102 int ret;
103
104 gDevice = dev;
105
106 memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
107 memcpy(&gDevice->deviceInstance, &gVmbusDeviceId,
108 sizeof(struct hv_guid));
109
110 /* strcpy(dev->name, "vmbus"); */
111 /* SynIC setup... */
112 on_each_cpu(HvSynicInit, (void *)irqvector, 1);
113
114 /* Connect to VMBus in the root partition */
115 ret = VmbusConnect();
116
117 /* VmbusSendEvent(device->localPortId+1); */
118 return ret;
119}
120
121/*
122 * VmbusOnDeviceRemove - Callback when the root bus device is removed
123 */
124static int VmbusOnDeviceRemove(struct hv_device *dev)
125{
126 int ret = 0;
127
128 vmbus_release_unattached_channels();
129 VmbusDisconnect();
130 on_each_cpu(HvSynicCleanup, NULL, 1);
131 return ret;
132}
133
134/*
135 * VmbusOnCleanup - Perform any cleanup when the driver is removed
136 */
137static void VmbusOnCleanup(struct hv_driver *drv)
138{
139 /* struct vmbus_driver *driver = (struct vmbus_driver *)drv; */
140
141 HvCleanup();
142}
143
144/*
145 * VmbusOnMsgDPC - DPC routine to handle messages from the hypervisior
146 */
147static void VmbusOnMsgDPC(struct hv_driver *drv)
148{
149 int cpu = smp_processor_id();
150 void *page_addr = gHvContext.synICMessagePage[cpu];
151 struct hv_message *msg = (struct hv_message *)page_addr +
152 VMBUS_MESSAGE_SINT;
153 struct hv_message *copied;
154
155 while (1) {
156 if (msg->Header.MessageType == HvMessageTypeNone) {
157 /* no msg */
158 break;
159 } else {
160 copied = kmemdup(msg, sizeof(*copied), GFP_ATOMIC);
161 if (copied == NULL)
162 continue;
163
164 osd_schedule_callback(gVmbusConnection.WorkQueue,
165 vmbus_onmessage,
166 (void *)copied);
167 }
168
169 msg->Header.MessageType = HvMessageTypeNone;
170
171 /*
172 * Make sure the write to MessageType (ie set to
173 * HvMessageTypeNone) happens before we read the
174 * MessagePending and EOMing. Otherwise, the EOMing
175 * will not deliver any more messages since there is
176 * no empty slot
177 */
178 mb();
179
180 if (msg->Header.MessageFlags.MessagePending) {
181 /*
182 * This will cause message queue rescan to
183 * possibly deliver another msg from the
184 * hypervisor
185 */
186 wrmsrl(HV_X64_MSR_EOM, 0);
187 }
188 }
189}
190
191/*
192 * VmbusOnEventDPC - DPC routine to handle events from the hypervisior
193 */
194static void VmbusOnEventDPC(struct hv_driver *drv)
195{
196 /* TODO: Process any events */
197 VmbusOnEvents();
198}
199
200/*
201 * VmbusOnISR - ISR routine
202 */
203static int VmbusOnISR(struct hv_driver *drv)
204{
205 int ret = 0;
206 int cpu = smp_processor_id();
207 void *page_addr;
208 struct hv_message *msg;
209 union hv_synic_event_flags *event;
210
211 page_addr = gHvContext.synICMessagePage[cpu];
212 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
213
214 /* Check if there are actual msgs to be process */
215 if (msg->Header.MessageType != HvMessageTypeNone) {
216 DPRINT_DBG(VMBUS, "received msg type %d size %d",
217 msg->Header.MessageType,
218 msg->Header.PayloadSize);
219 ret |= 0x1;
220 }
221
222 /* TODO: Check if there are events to be process */
223 page_addr = gHvContext.synICEventPage[cpu];
224 event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT;
225
226 /* Since we are a child, we only need to check bit 0 */
227 if (test_and_clear_bit(0, (unsigned long *) &event->Flags32[0])) {
228 DPRINT_DBG(VMBUS, "received event %d", event->Flags32[0]);
229 ret |= 0x2;
230 }
231
232 return ret;
233}
234
235/*
236 * VmbusInitialize - Main entry point
237 */
238int VmbusInitialize(struct hv_driver *drv)
239{
240 struct vmbus_driver *driver = (struct vmbus_driver *)drv;
241 int ret;
242
243 DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++",
244 HV_DRV_VERSION);
245 DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++",
246 VMBUS_REVISION_NUMBER);
247 DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++",
248 VMBUS_MESSAGE_SINT);
249 DPRINT_DBG(VMBUS, "sizeof(vmbus_channel_packet_page_buffer)=%zd, "
250 "sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%zd",
251 sizeof(struct vmbus_channel_packet_page_buffer),
252 sizeof(struct vmbus_channel_packet_multipage_buffer));
253
254 drv->name = gDriverName;
255 memcpy(&drv->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
256
257 /* Setup dispatch table */
258 driver->Base.OnDeviceAdd = VmbusOnDeviceAdd;
259 driver->Base.OnDeviceRemove = VmbusOnDeviceRemove;
260 driver->Base.OnCleanup = VmbusOnCleanup;
261 driver->OnIsr = VmbusOnISR;
262 driver->OnMsgDpc = VmbusOnMsgDPC;
263 driver->OnEventDpc = VmbusOnEventDPC;
264 driver->GetChannelOffers = VmbusGetChannelOffers;
265
266 /* Hypervisor initialization...setup hypercall page..etc */
267 ret = HvInit();
268 if (ret != 0)
269 DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x",
270 ret);
271 gDriver = drv;
272
273 return ret;
274}
diff --git a/drivers/staging/hv/vmbus_api.h b/drivers/staging/hv/vmbus_api.h
index 2af42e550076..2da3f52610b3 100644
--- a/drivers/staging/hv/vmbus_api.h
+++ b/drivers/staging/hv/vmbus_api.h
@@ -115,28 +115,4 @@ struct hv_device {
115 void *Extension; 115 void *Extension;
116}; 116};
117 117
118/* Vmbus driver object */
119struct vmbus_driver {
120 /* !! Must be the 1st field !! */
121 /* FIXME if ^, then someone is doing somthing stupid */
122 struct hv_driver Base;
123
124 /* Set by the caller */
125 struct hv_device * (*OnChildDeviceCreate)(struct hv_guid *DeviceType,
126 struct hv_guid *DeviceInstance,
127 struct vmbus_channel *channel);
128 void (*OnChildDeviceDestroy)(struct hv_device *device);
129 int (*OnChildDeviceAdd)(struct hv_device *RootDevice,
130 struct hv_device *ChildDevice);
131 void (*OnChildDeviceRemove)(struct hv_device *device);
132
133 /* Set by the callee */
134 int (*OnIsr)(struct hv_driver *driver);
135 void (*OnMsgDpc)(struct hv_driver *driver);
136 void (*OnEventDpc)(struct hv_driver *driver);
137 void (*GetChannelOffers)(void);
138};
139
140int VmbusInitialize(struct hv_driver *drv);
141
142#endif /* _VMBUS_API_H_ */ 118#endif /* _VMBUS_API_H_ */
diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
index 0d9f3a411e72..84fdb64d3ceb 100644
--- a/drivers/staging/hv/vmbus_drv.c
+++ b/drivers/staging/hv/vmbus_drv.c
@@ -33,6 +33,7 @@
33#include "logging.h" 33#include "logging.h"
34#include "vmbus.h" 34#include "vmbus.h"
35#include "channel.h" 35#include "channel.h"
36#include "vmbus_private.h"
36 37
37 38
38/* FIXME! We need to do this dynamically for PIC and APIC system */ 39/* FIXME! We need to do this dynamically for PIC and APIC system */
@@ -46,7 +47,7 @@ struct vmbus_driver_context {
46 /* The driver field is not used in here. Instead, the bus field is */ 47 /* The driver field is not used in here. Instead, the bus field is */
47 /* used to represent the driver */ 48 /* used to represent the driver */
48 struct driver_context drv_ctx; 49 struct driver_context drv_ctx;
49 struct vmbus_driver drv_obj; 50 struct hv_driver drv_obj;
50 51
51 struct bus_type bus; 52 struct bus_type bus;
52 struct tasklet_struct msg_dpc; 53 struct tasklet_struct msg_dpc;
@@ -69,13 +70,6 @@ static irqreturn_t vmbus_isr(int irq, void *dev_id);
69static void vmbus_device_release(struct device *device); 70static void vmbus_device_release(struct device *device);
70static void vmbus_bus_release(struct device *device); 71static void vmbus_bus_release(struct device *device);
71 72
72static struct hv_device *vmbus_child_device_create(struct hv_guid *type,
73 struct hv_guid *instance,
74 struct vmbus_channel *channel);
75static void vmbus_child_device_destroy(struct hv_device *device_obj);
76static int vmbus_child_device_register(struct hv_device *root_device_obj,
77 struct hv_device *child_device_obj);
78static void vmbus_child_device_unregister(struct hv_device *child_device_obj);
79static ssize_t vmbus_show_device_attr(struct device *dev, 73static ssize_t vmbus_show_device_attr(struct device *dev,
80 struct device_attribute *dev_attr, 74 struct device_attribute *dev_attr,
81 char *buf); 75 char *buf);
@@ -129,6 +123,182 @@ static struct vmbus_driver_context g_vmbus_drv = {
129 .bus.dev_attrs = vmbus_device_attrs, 123 .bus.dev_attrs = vmbus_device_attrs,
130}; 124};
131 125
126static const char *gDriverName = "hyperv";
127
128/*
129 * Windows vmbus does not defined this.
130 * We defined this to be consistent with other devices
131 */
132/* {c5295816-f63a-4d5f-8d1a-4daf999ca185} */
133static const struct hv_guid gVmbusDeviceType = {
134 .data = {
135 0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d,
136 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85
137 }
138};
139
140/* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */
141static const struct hv_guid gVmbusDeviceId = {
142 .data = {
143 0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40,
144 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5
145 }
146};
147
148static struct hv_device *gDevice; /* vmbus root device */
149
150/*
151 * VmbusChildDeviceAdd - Registers the child device with the vmbus
152 */
153int VmbusChildDeviceAdd(struct hv_device *ChildDevice)
154{
155 return vmbus_child_device_register(gDevice, ChildDevice);
156}
157
158/*
159 * VmbusOnDeviceAdd - Callback when the root bus device is added
160 */
161static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo)
162{
163 u32 *irqvector = AdditionalInfo;
164 int ret;
165
166 gDevice = dev;
167
168 memcpy(&gDevice->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
169 memcpy(&gDevice->deviceInstance, &gVmbusDeviceId,
170 sizeof(struct hv_guid));
171
172 /* strcpy(dev->name, "vmbus"); */
173 /* SynIC setup... */
174 on_each_cpu(hv_synic_init, (void *)irqvector, 1);
175
176 /* Connect to VMBus in the root partition */
177 ret = VmbusConnect();
178
179 /* VmbusSendEvent(device->localPortId+1); */
180 return ret;
181}
182
183/*
184 * VmbusOnDeviceRemove - Callback when the root bus device is removed
185 */
186static int VmbusOnDeviceRemove(struct hv_device *dev)
187{
188 int ret = 0;
189
190 vmbus_release_unattached_channels();
191 VmbusDisconnect();
192 on_each_cpu(hv_synic_cleanup, NULL, 1);
193 return ret;
194}
195
196/*
197 * VmbusOnCleanup - Perform any cleanup when the driver is removed
198 */
199static void VmbusOnCleanup(struct hv_driver *drv)
200{
201 /* struct vmbus_driver *driver = (struct vmbus_driver *)drv; */
202
203 hv_cleanup();
204}
205
206struct onmessage_work_context {
207 struct work_struct work;
208 struct hv_message msg;
209};
210
211static void vmbus_onmessage_work(struct work_struct *work)
212{
213 struct onmessage_work_context *ctx;
214
215 ctx = container_of(work, struct onmessage_work_context,
216 work);
217 vmbus_onmessage(&ctx->msg);
218 kfree(ctx);
219}
220
221/*
222 * vmbus_on_msg_dpc - DPC routine to handle messages from the hypervisior
223 */
224static void vmbus_on_msg_dpc(struct hv_driver *drv)
225{
226 int cpu = smp_processor_id();
227 void *page_addr = hv_context.synic_message_page[cpu];
228 struct hv_message *msg = (struct hv_message *)page_addr +
229 VMBUS_MESSAGE_SINT;
230 struct onmessage_work_context *ctx;
231
232 while (1) {
233 if (msg->header.message_type == HVMSG_NONE) {
234 /* no msg */
235 break;
236 } else {
237 ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
238 if (ctx == NULL)
239 continue;
240 INIT_WORK(&ctx->work, vmbus_onmessage_work);
241 memcpy(&ctx->msg, msg, sizeof(*msg));
242 queue_work(gVmbusConnection.WorkQueue, &ctx->work);
243 }
244
245 msg->header.message_type = HVMSG_NONE;
246
247 /*
248 * Make sure the write to MessageType (ie set to
249 * HVMSG_NONE) happens before we read the
250 * MessagePending and EOMing. Otherwise, the EOMing
251 * will not deliver any more messages since there is
252 * no empty slot
253 */
254 mb();
255
256 if (msg->header.message_flags.msg_pending) {
257 /*
258 * This will cause message queue rescan to
259 * possibly deliver another msg from the
260 * hypervisor
261 */
262 wrmsrl(HV_X64_MSR_EOM, 0);
263 }
264 }
265}
266
267/*
268 * vmbus_on_isr - ISR routine
269 */
270static int vmbus_on_isr(struct hv_driver *drv)
271{
272 int ret = 0;
273 int cpu = smp_processor_id();
274 void *page_addr;
275 struct hv_message *msg;
276 union hv_synic_event_flags *event;
277
278 page_addr = hv_context.synic_message_page[cpu];
279 msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
280
281 /* Check if there are actual msgs to be process */
282 if (msg->header.message_type != HVMSG_NONE) {
283 DPRINT_DBG(VMBUS, "received msg type %d size %d",
284 msg->header.message_type,
285 msg->header.payload_size);
286 ret |= 0x1;
287 }
288
289 /* TODO: Check if there are events to be process */
290 page_addr = hv_context.synic_event_page[cpu];
291 event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT;
292
293 /* Since we are a child, we only need to check bit 0 */
294 if (test_and_clear_bit(0, (unsigned long *) &event->flags32[0])) {
295 DPRINT_DBG(VMBUS, "received event %d", event->flags32[0]);
296 ret |= 0x2;
297 }
298
299 return ret;
300}
301
132static void get_channel_info(struct hv_device *device, 302static void get_channel_info(struct hv_device *device,
133 struct hv_device_info *info) 303 struct hv_device_info *info)
134{ 304{
@@ -139,35 +309,38 @@ static void get_channel_info(struct hv_device *device,
139 309
140 vmbus_get_debug_info(device->channel, &debug_info); 310 vmbus_get_debug_info(device->channel, &debug_info);
141 311
142 info->ChannelId = debug_info.RelId; 312 info->ChannelId = debug_info.relid;
143 info->ChannelState = debug_info.State; 313 info->ChannelState = debug_info.state;
144 memcpy(&info->ChannelType, &debug_info.InterfaceType, 314 memcpy(&info->ChannelType, &debug_info.interfacetype,
145 sizeof(struct hv_guid)); 315 sizeof(struct hv_guid));
146 memcpy(&info->ChannelInstance, &debug_info.InterfaceInstance, 316 memcpy(&info->ChannelInstance, &debug_info.interface_instance,
147 sizeof(struct hv_guid)); 317 sizeof(struct hv_guid));
148 318
149 info->MonitorId = debug_info.MonitorId; 319 info->MonitorId = debug_info.monitorid;
150 320
151 info->ServerMonitorPending = debug_info.ServerMonitorPending; 321 info->ServerMonitorPending = debug_info.servermonitor_pending;
152 info->ServerMonitorLatency = debug_info.ServerMonitorLatency; 322 info->ServerMonitorLatency = debug_info.servermonitor_latency;
153 info->ServerMonitorConnectionId = debug_info.ServerMonitorConnectionId; 323 info->ServerMonitorConnectionId = debug_info.servermonitor_connectionid;
154 324
155 info->ClientMonitorPending = debug_info.ClientMonitorPending; 325 info->ClientMonitorPending = debug_info.clientmonitor_pending;
156 info->ClientMonitorLatency = debug_info.ClientMonitorLatency; 326 info->ClientMonitorLatency = debug_info.clientmonitor_latency;
157 info->ClientMonitorConnectionId = debug_info.ClientMonitorConnectionId; 327 info->ClientMonitorConnectionId = debug_info.clientmonitor_connectionid;
158 328
159 info->Inbound.InterruptMask = debug_info.Inbound.CurrentInterruptMask; 329 info->Inbound.InterruptMask = debug_info.inbound.current_interrupt_mask;
160 info->Inbound.ReadIndex = debug_info.Inbound.CurrentReadIndex; 330 info->Inbound.ReadIndex = debug_info.inbound.current_read_index;
161 info->Inbound.WriteIndex = debug_info.Inbound.CurrentWriteIndex; 331 info->Inbound.WriteIndex = debug_info.inbound.current_write_index;
162 info->Inbound.BytesAvailToRead = debug_info.Inbound.BytesAvailToRead; 332 info->Inbound.BytesAvailToRead = debug_info.inbound.bytes_avail_toread;
163 info->Inbound.BytesAvailToWrite = debug_info.Inbound.BytesAvailToWrite; 333 info->Inbound.BytesAvailToWrite =
164 334 debug_info.inbound.bytes_avail_towrite;
165 info->Outbound.InterruptMask = debug_info.Outbound.CurrentInterruptMask; 335
166 info->Outbound.ReadIndex = debug_info.Outbound.CurrentReadIndex; 336 info->Outbound.InterruptMask =
167 info->Outbound.WriteIndex = debug_info.Outbound.CurrentWriteIndex; 337 debug_info.outbound.current_interrupt_mask;
168 info->Outbound.BytesAvailToRead = debug_info.Outbound.BytesAvailToRead; 338 info->Outbound.ReadIndex = debug_info.outbound.current_read_index;
339 info->Outbound.WriteIndex = debug_info.outbound.current_write_index;
340 info->Outbound.BytesAvailToRead =
341 debug_info.outbound.bytes_avail_toread;
169 info->Outbound.BytesAvailToWrite = 342 info->Outbound.BytesAvailToWrite =
170 debug_info.Outbound.BytesAvailToWrite; 343 debug_info.outbound.bytes_avail_towrite;
171} 344}
172 345
173/* 346/*
@@ -286,44 +459,55 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
286 * - setup the vmbus root device 459 * - setup the vmbus root device
287 * - retrieve the channel offers 460 * - retrieve the channel offers
288 */ 461 */
289static int vmbus_bus_init(int (*drv_init)(struct hv_driver *drv)) 462static int vmbus_bus_init(void)
290{ 463{
291 struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv; 464 struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv;
292 struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; 465 struct hv_driver *driver = &g_vmbus_drv.drv_obj;
293 struct vm_device *dev_ctx = &g_vmbus_drv.device_ctx; 466 struct vm_device *dev_ctx = &g_vmbus_drv.device_ctx;
294 int ret; 467 int ret;
295 unsigned int vector; 468 unsigned int vector;
296 469
297 /* 470 DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++",
298 * Set this up to allow lower layer to callback to add/remove child 471 HV_DRV_VERSION);
299 * devices on the bus 472 DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++",
300 */ 473 VMBUS_REVISION_NUMBER);
301 vmbus_drv_obj->OnChildDeviceCreate = vmbus_child_device_create; 474 DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++",
302 vmbus_drv_obj->OnChildDeviceDestroy = vmbus_child_device_destroy; 475 VMBUS_MESSAGE_SINT);
303 vmbus_drv_obj->OnChildDeviceAdd = vmbus_child_device_register; 476 DPRINT_DBG(VMBUS, "sizeof(vmbus_channel_packet_page_buffer)=%zd, "
304 vmbus_drv_obj->OnChildDeviceRemove = vmbus_child_device_unregister; 477 "sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%zd",
305 478 sizeof(struct vmbus_channel_packet_page_buffer),
306 /* Call to bus driver to initialize */ 479 sizeof(struct vmbus_channel_packet_multipage_buffer));
307 ret = drv_init(&vmbus_drv_obj->Base); 480
481 driver->name = gDriverName;
482 memcpy(&driver->deviceType, &gVmbusDeviceType, sizeof(struct hv_guid));
483
484 /* Setup dispatch table */
485 driver->OnDeviceAdd = VmbusOnDeviceAdd;
486 driver->OnDeviceRemove = VmbusOnDeviceRemove;
487 driver->OnCleanup = VmbusOnCleanup;
488
489 /* Hypervisor initialization...setup hypercall page..etc */
490 ret = hv_init();
308 if (ret != 0) { 491 if (ret != 0) {
309 DPRINT_ERR(VMBUS_DRV, "Unable to initialize vmbus (%d)", ret); 492 DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x",
493 ret);
310 goto cleanup; 494 goto cleanup;
311 } 495 }
312 496
313 /* Sanity checks */ 497 /* Sanity checks */
314 if (!vmbus_drv_obj->Base.OnDeviceAdd) { 498 if (!driver->OnDeviceAdd) {
315 DPRINT_ERR(VMBUS_DRV, "OnDeviceAdd() routine not set"); 499 DPRINT_ERR(VMBUS_DRV, "OnDeviceAdd() routine not set");
316 ret = -1; 500 ret = -1;
317 goto cleanup; 501 goto cleanup;
318 } 502 }
319 503
320 vmbus_drv_ctx->bus.name = vmbus_drv_obj->Base.name; 504 vmbus_drv_ctx->bus.name = driver->name;
321 505
322 /* Initialize the bus context */ 506 /* Initialize the bus context */
323 tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_msg_dpc, 507 tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_msg_dpc,
324 (unsigned long)vmbus_drv_obj); 508 (unsigned long)driver);
325 tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_event_dpc, 509 tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_event_dpc,
326 (unsigned long)vmbus_drv_obj); 510 (unsigned long)driver);
327 511
328 /* Now, register the bus driver with LDM */ 512 /* Now, register the bus driver with LDM */
329 ret = bus_register(&vmbus_drv_ctx->bus); 513 ret = bus_register(&vmbus_drv_ctx->bus);
@@ -334,7 +518,7 @@ static int vmbus_bus_init(int (*drv_init)(struct hv_driver *drv))
334 518
335 /* Get the interrupt resource */ 519 /* Get the interrupt resource */
336 ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM, 520 ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM,
337 vmbus_drv_obj->Base.name, NULL); 521 driver->name, NULL);
338 522
339 if (ret != 0) { 523 if (ret != 0) {
340 DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d", 524 DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d",
@@ -352,7 +536,7 @@ static int vmbus_bus_init(int (*drv_init)(struct hv_driver *drv))
352 /* Call to bus driver to add the root device */ 536 /* Call to bus driver to add the root device */
353 memset(dev_ctx, 0, sizeof(struct vm_device)); 537 memset(dev_ctx, 0, sizeof(struct vm_device));
354 538
355 ret = vmbus_drv_obj->Base.OnDeviceAdd(&dev_ctx->device_obj, &vector); 539 ret = driver->OnDeviceAdd(&dev_ctx->device_obj, &vector);
356 if (ret != 0) { 540 if (ret != 0) {
357 DPRINT_ERR(VMBUS_DRV, 541 DPRINT_ERR(VMBUS_DRV,
358 "ERROR - Unable to add vmbus root device"); 542 "ERROR - Unable to add vmbus root device");
@@ -392,9 +576,7 @@ static int vmbus_bus_init(int (*drv_init)(struct hv_driver *drv))
392 goto cleanup; 576 goto cleanup;
393 } 577 }
394 578
395 579 vmbus_request_offers();
396 vmbus_drv_obj->GetChannelOffers();
397
398 wait_for_completion(&hv_channel_ready); 580 wait_for_completion(&hv_channel_ready);
399 581
400cleanup: 582cleanup:
@@ -408,17 +590,17 @@ cleanup:
408 */ 590 */
409static void vmbus_bus_exit(void) 591static void vmbus_bus_exit(void)
410{ 592{
411 struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj; 593 struct hv_driver *driver = &g_vmbus_drv.drv_obj;
412 struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv; 594 struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv;
413 595
414 struct vm_device *dev_ctx = &g_vmbus_drv.device_ctx; 596 struct vm_device *dev_ctx = &g_vmbus_drv.device_ctx;
415 597
416 /* Remove the root device */ 598 /* Remove the root device */
417 if (vmbus_drv_obj->Base.OnDeviceRemove) 599 if (driver->OnDeviceRemove)
418 vmbus_drv_obj->Base.OnDeviceRemove(&dev_ctx->device_obj); 600 driver->OnDeviceRemove(&dev_ctx->device_obj);
419 601
420 if (vmbus_drv_obj->Base.OnCleanup) 602 if (driver->OnCleanup)
421 vmbus_drv_obj->Base.OnCleanup(&vmbus_drv_obj->Base); 603 driver->OnCleanup(driver);
422 604
423 /* Unregister the root bus device */ 605 /* Unregister the root bus device */
424 device_unregister(&dev_ctx->device); 606 device_unregister(&dev_ctx->device);
@@ -446,7 +628,6 @@ static void vmbus_bus_exit(void)
446 */ 628 */
447int vmbus_child_driver_register(struct driver_context *driver_ctx) 629int vmbus_child_driver_register(struct driver_context *driver_ctx)
448{ 630{
449 struct vmbus_driver *vmbus_drv_obj = &g_vmbus_drv.drv_obj;
450 int ret; 631 int ret;
451 632
452 DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s", 633 DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s",
@@ -457,7 +638,7 @@ int vmbus_child_driver_register(struct driver_context *driver_ctx)
457 638
458 ret = driver_register(&driver_ctx->driver); 639 ret = driver_register(&driver_ctx->driver);
459 640
460 vmbus_drv_obj->GetChannelOffers(); 641 vmbus_request_offers();
461 642
462 return ret; 643 return ret;
463} 644}
@@ -489,9 +670,9 @@ EXPORT_SYMBOL(vmbus_child_driver_unregister);
489 * vmbus_child_device_create - Creates and registers a new child device 670 * vmbus_child_device_create - Creates and registers a new child device
490 * on the vmbus. 671 * on the vmbus.
491 */ 672 */
492static struct hv_device *vmbus_child_device_create(struct hv_guid *type, 673struct hv_device *vmbus_child_device_create(struct hv_guid *type,
493 struct hv_guid *instance, 674 struct hv_guid *instance,
494 struct vmbus_channel *channel) 675 struct vmbus_channel *channel)
495{ 676{
496 struct vm_device *child_device_ctx; 677 struct vm_device *child_device_ctx;
497 struct hv_device *child_device_obj; 678 struct hv_device *child_device_obj;
@@ -538,8 +719,8 @@ static struct hv_device *vmbus_child_device_create(struct hv_guid *type,
538/* 719/*
539 * vmbus_child_device_register - Register the child device on the specified bus 720 * vmbus_child_device_register - Register the child device on the specified bus
540 */ 721 */
541static int vmbus_child_device_register(struct hv_device *root_device_obj, 722int vmbus_child_device_register(struct hv_device *root_device_obj,
542 struct hv_device *child_device_obj) 723 struct hv_device *child_device_obj)
543{ 724{
544 int ret = 0; 725 int ret = 0;
545 struct vm_device *root_device_ctx = 726 struct vm_device *root_device_ctx =
@@ -583,7 +764,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
583 * vmbus_child_device_unregister - Remove the specified child device 764 * vmbus_child_device_unregister - Remove the specified child device
584 * from the vmbus. 765 * from the vmbus.
585 */ 766 */
586static void vmbus_child_device_unregister(struct hv_device *device_obj) 767void vmbus_child_device_unregister(struct hv_device *device_obj)
587{ 768{
588 struct vm_device *device_ctx = to_vm_device(device_obj); 769 struct vm_device *device_ctx = to_vm_device(device_obj);
589 770
@@ -601,13 +782,6 @@ static void vmbus_child_device_unregister(struct hv_device *device_obj)
601} 782}
602 783
603/* 784/*
604 * vmbus_child_device_destroy - Destroy the specified child device on the vmbus.
605 */
606static void vmbus_child_device_destroy(struct hv_device *device_obj)
607{
608}
609
610/*
611 * vmbus_uevent - add uevent for our device 785 * vmbus_uevent - add uevent for our device
612 * 786 *
613 * This routine is invoked when a device is added or removed on the vmbus to 787 * This routine is invoked when a device is added or removed on the vmbus to
@@ -701,7 +875,7 @@ static int vmbus_match(struct device *device, struct device_driver *driver)
701 struct vmbus_driver_context *vmbus_drv_ctx = 875 struct vmbus_driver_context *vmbus_drv_ctx =
702 (struct vmbus_driver_context *)driver_ctx; 876 (struct vmbus_driver_context *)driver_ctx;
703 877
704 device_ctx->device_obj.Driver = &vmbus_drv_ctx->drv_obj.Base; 878 device_ctx->device_obj.Driver = &vmbus_drv_ctx->drv_obj;
705 DPRINT_INFO(VMBUS_DRV, 879 DPRINT_INFO(VMBUS_DRV,
706 "device object (%p) set to driver object (%p)", 880 "device object (%p) set to driver object (%p)",
707 &device_ctx->device_obj, 881 &device_ctx->device_obj,
@@ -849,7 +1023,6 @@ static void vmbus_device_release(struct device *device)
849{ 1023{
850 struct vm_device *device_ctx = device_to_vm_device(device); 1024 struct vm_device *device_ctx = device_to_vm_device(device);
851 1025
852 /* vmbus_child_device_destroy(&device_ctx->device_obj); */
853 kfree(device_ctx); 1026 kfree(device_ctx);
854 1027
855 /* !!DO NOT REFERENCE device_ctx anymore at this point!! */ 1028 /* !!DO NOT REFERENCE device_ctx anymore at this point!! */
@@ -860,36 +1033,28 @@ static void vmbus_device_release(struct device *device)
860 */ 1033 */
861static void vmbus_msg_dpc(unsigned long data) 1034static void vmbus_msg_dpc(unsigned long data)
862{ 1035{
863 struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data; 1036 struct hv_driver *driver = (struct hv_driver *)data;
864
865 /* ASSERT(vmbus_drv_obj->OnMsgDpc != NULL); */
866 1037
867 /* Call to bus driver to handle interrupt */ 1038 /* Call to bus driver to handle interrupt */
868 vmbus_drv_obj->OnMsgDpc(&vmbus_drv_obj->Base); 1039 vmbus_on_msg_dpc(driver);
869} 1040}
870 1041
871/* 1042/*
872 * vmbus_msg_dpc - Tasklet routine to handle hypervisor events 1043 * vmbus_event_dpc - Tasklet routine to handle hypervisor events
873 */ 1044 */
874static void vmbus_event_dpc(unsigned long data) 1045static void vmbus_event_dpc(unsigned long data)
875{ 1046{
876 struct vmbus_driver *vmbus_drv_obj = (struct vmbus_driver *)data;
877
878 /* ASSERT(vmbus_drv_obj->OnEventDpc != NULL); */
879
880 /* Call to bus driver to handle interrupt */ 1047 /* Call to bus driver to handle interrupt */
881 vmbus_drv_obj->OnEventDpc(&vmbus_drv_obj->Base); 1048 VmbusOnEvents();
882} 1049}
883 1050
884static irqreturn_t vmbus_isr(int irq, void *dev_id) 1051static irqreturn_t vmbus_isr(int irq, void *dev_id)
885{ 1052{
886 struct vmbus_driver *vmbus_driver_obj = &g_vmbus_drv.drv_obj; 1053 struct hv_driver *driver = &g_vmbus_drv.drv_obj;
887 int ret; 1054 int ret;
888 1055
889 /* ASSERT(vmbus_driver_obj->OnIsr != NULL); */
890
891 /* Call to bus driver to handle interrupt */ 1056 /* Call to bus driver to handle interrupt */
892 ret = vmbus_driver_obj->OnIsr(&vmbus_driver_obj->Base); 1057 ret = vmbus_on_isr(driver);
893 1058
894 /* Schedules a dpc if necessary */ 1059 /* Schedules a dpc if necessary */
895 if (ret > 0) { 1060 if (ret > 0) {
@@ -928,7 +1093,7 @@ static int __init vmbus_init(void)
928 if (!dmi_check_system(microsoft_hv_dmi_table)) 1093 if (!dmi_check_system(microsoft_hv_dmi_table))
929 return -ENODEV; 1094 return -ENODEV;
930 1095
931 return vmbus_bus_init(VmbusInitialize); 1096 return vmbus_bus_init();
932} 1097}
933 1098
934static void __exit vmbus_exit(void) 1099static void __exit vmbus_exit(void)
diff --git a/drivers/staging/hv/vmbus_private.h b/drivers/staging/hv/vmbus_private.h
index 09eaec964b30..07f6d22eeabb 100644
--- a/drivers/staging/hv/vmbus_private.h
+++ b/drivers/staging/hv/vmbus_private.h
@@ -102,13 +102,14 @@ extern struct VMBUS_CONNECTION gVmbusConnection;
102 102
103/* General vmbus interface */ 103/* General vmbus interface */
104 104
105struct hv_device *VmbusChildDeviceCreate(struct hv_guid *deviceType, 105struct hv_device *vmbus_child_device_create(struct hv_guid *deviceType,
106 struct hv_guid *deviceInstance, 106 struct hv_guid *deviceInstance,
107 struct vmbus_channel *channel); 107 struct vmbus_channel *channel);
108 108
109int VmbusChildDeviceAdd(struct hv_device *Device); 109int VmbusChildDeviceAdd(struct hv_device *Device);
110 110int vmbus_child_device_register(struct hv_device *root_device_obj,
111void VmbusChildDeviceRemove(struct hv_device *Device); 111 struct hv_device *child_device_obj);
112void vmbus_child_device_unregister(struct hv_device *device_obj);
112 113
113/* static void */ 114/* static void */
114/* VmbusChildDeviceDestroy( */ 115/* VmbusChildDeviceDestroy( */
diff --git a/drivers/staging/hv/vstorage.h b/drivers/staging/hv/vstorage.h
index 4ea597d7a7d7..ae8be84394d5 100644
--- a/drivers/staging/hv/vstorage.h
+++ b/drivers/staging/hv/vstorage.h
@@ -27,15 +27,17 @@
27 27
28#define REVISION_STRING(REVISION_) #REVISION_ 28#define REVISION_STRING(REVISION_) #REVISION_
29#define FILL_VMSTOR_REVISION(RESULT_LVALUE_) \ 29#define FILL_VMSTOR_REVISION(RESULT_LVALUE_) \
30{ \ 30 do { \
31 char *revisionString = REVISION_STRING($Revision : 6 $) + 11; \ 31 char *revision_string \
32 RESULT_LVALUE_ = 0; \ 32 = REVISION_STRING($Rev : 6 $) + 6; \
33 while (*revisionString >= '0' && *revisionString <= '9') { \ 33 RESULT_LVALUE_ = 0; \
34 RESULT_LVALUE_ *= 10; \ 34 while (*revision_string >= '0' \
35 RESULT_LVALUE_ += *revisionString - '0'; \ 35 && *revision_string <= '9') { \
36 revisionString++; \ 36 RESULT_LVALUE_ *= 10; \
37 } \ 37 RESULT_LVALUE_ += *revision_string - '0'; \
38} 38 revision_string++; \
39 } \
40 } while (0)
39 41
40/* Major/minor macros. Minor version is in LSB, meaning that earlier flat */ 42/* Major/minor macros. Minor version is in LSB, meaning that earlier flat */
41/* version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1). */ 43/* version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1). */
@@ -65,17 +67,17 @@
65 67
66/* Packet structure describing virtual storage requests. */ 68/* Packet structure describing virtual storage requests. */
67enum vstor_packet_operation { 69enum vstor_packet_operation {
68 VStorOperationCompleteIo = 1, 70 VSTOR_OPERATION_COMPLETE_IO = 1,
69 VStorOperationRemoveDevice = 2, 71 VSTOR_OPERATION_REMOVE_DEVICE = 2,
70 VStorOperationExecuteSRB = 3, 72 VSTOR_OPERATION_EXECUTE_SRB = 3,
71 VStorOperationResetLun = 4, 73 VSTOR_OPERATION_RESET_LUN = 4,
72 VStorOperationResetAdapter = 5, 74 VSTOR_OPERATION_RESET_ADAPTER = 5,
73 VStorOperationResetBus = 6, 75 VSTOR_OPERATION_RESET_BUS = 6,
74 VStorOperationBeginInitialization = 7, 76 VSTOR_OPERATION_BEGIN_INITIALIZATION = 7,
75 VStorOperationEndInitialization = 8, 77 VSTOR_OPERATION_END_INITIALIZATION = 8,
76 VStorOperationQueryProtocolVersion = 9, 78 VSTOR_OPERATION_QUERY_PROTOCOL_VERSION = 9,
77 VStorOperationQueryProperties = 10, 79 VSTOR_OPERATION_QUERY_PROPERTIES = 10,
78 VStorOperationMaximum = 10 80 VSTOR_OPERATION_MAXIMUM = 10
79}; 81};
80 82
81/* 83/*
@@ -89,31 +91,29 @@ enum vstor_packet_operation {
89#define SENSE_BUFFER_SIZE 0x12 91#define SENSE_BUFFER_SIZE 0x12
90#endif 92#endif
91 93
92#define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14 94#define MAX_DATA_BUF_LEN_WITH_PADDING 0x14
93 95
94struct vmscsi_request { 96struct vmscsi_request {
95 unsigned short Length; 97 unsigned short length;
96 unsigned char SrbStatus; 98 unsigned char srb_status;
97 unsigned char ScsiStatus; 99 unsigned char scsi_status;
98 100
99 unsigned char PortNumber; 101 unsigned char port_number;
100 unsigned char PathId; 102 unsigned char path_id;
101 unsigned char TargetId; 103 unsigned char target_id;
102 unsigned char Lun; 104 unsigned char lun;
103 105
104 unsigned char CdbLength; 106 unsigned char cdb_length;
105 unsigned char SenseInfoLength; 107 unsigned char sense_info_length;
106 unsigned char DataIn; 108 unsigned char data_in;
107 unsigned char Reserved; 109 unsigned char reserved;
108 110
109 unsigned int DataTransferLength; 111 unsigned int data_transfer_length;
110 112
111 union { 113 union {
112 unsigned char Cdb[CDB16GENERIC_LENGTH]; 114 unsigned char cdb[CDB16GENERIC_LENGTH];
113 115 unsigned char sense_data[SENSE_BUFFER_SIZE];
114 unsigned char SenseData[SENSE_BUFFER_SIZE]; 116 unsigned char reserved_array[MAX_DATA_BUF_LEN_WITH_PADDING];
115
116 unsigned char ReservedArray[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
117 }; 117 };
118} __attribute((packed)); 118} __attribute((packed));
119 119
@@ -123,24 +123,24 @@ struct vmscsi_request {
123 * properties of the channel. 123 * properties of the channel.
124 */ 124 */
125struct vmstorage_channel_properties { 125struct vmstorage_channel_properties {
126 unsigned short ProtocolVersion; 126 unsigned short protocol_version;
127 unsigned char PathId; 127 unsigned char path_id;
128 unsigned char TargetId; 128 unsigned char target_id;
129 129
130 /* Note: port number is only really known on the client side */ 130 /* Note: port number is only really known on the client side */
131 unsigned int PortNumber; 131 unsigned int port_number;
132 unsigned int Flags; 132 unsigned int flags;
133 unsigned int MaxTransferBytes; 133 unsigned int max_transfer_bytes;
134 134
135 /* This id is unique for each channel and will correspond with */ 135 /* This id is unique for each channel and will correspond with */
136 /* vendor specific data in the inquirydata */ 136 /* vendor specific data in the inquirydata */
137 unsigned long long UniqueId; 137 unsigned long long unique_id;
138} __attribute__((packed)); 138} __attribute__((packed));
139 139
140/* This structure is sent during the storage protocol negotiations. */ 140/* This structure is sent during the storage protocol negotiations. */
141struct vmstorage_protocol_version { 141struct vmstorage_protocol_version {
142 /* Major (MSW) and minor (LSW) version numbers. */ 142 /* Major (MSW) and minor (LSW) version numbers. */
143 unsigned short MajorMinor; 143 unsigned short major_minor;
144 144
145 /* 145 /*
146 * Revision number is auto-incremented whenever this file is changed 146 * Revision number is auto-incremented whenever this file is changed
@@ -148,7 +148,7 @@ struct vmstorage_protocol_version {
148 * definitely indicate incompatibility--but it does indicate mismatched 148 * definitely indicate incompatibility--but it does indicate mismatched
149 * builds. 149 * builds.
150 */ 150 */
151 unsigned short Revision; 151 unsigned short revision;
152} __attribute__((packed)); 152} __attribute__((packed));
153 153
154/* Channel Property Flags */ 154/* Channel Property Flags */
@@ -157,13 +157,13 @@ struct vmstorage_protocol_version {
157 157
158struct vstor_packet { 158struct vstor_packet {
159 /* Requested operation type */ 159 /* Requested operation type */
160 enum vstor_packet_operation Operation; 160 enum vstor_packet_operation operation;
161 161
162 /* Flags - see below for values */ 162 /* Flags - see below for values */
163 unsigned int Flags; 163 unsigned int flags;
164 164
165 /* Status of the request returned from the server side. */ 165 /* Status of the request returned from the server side. */
166 unsigned int Status; 166 unsigned int status;
167 167
168 /* Data payload area */ 168 /* Data payload area */
169 union { 169 union {
@@ -171,13 +171,13 @@ struct vstor_packet {
171 * Structure used to forward SCSI commands from the 171 * Structure used to forward SCSI commands from the
172 * client to the server. 172 * client to the server.
173 */ 173 */
174 struct vmscsi_request VmSrb; 174 struct vmscsi_request vm_srb;
175 175
176 /* Structure used to query channel properties. */ 176 /* Structure used to query channel properties. */
177 struct vmstorage_channel_properties StorageChannelProperties; 177 struct vmstorage_channel_properties storage_channel_properties;
178 178
179 /* Used during version negotiations. */ 179 /* Used during version negotiations. */
180 struct vmstorage_protocol_version Version; 180 struct vmstorage_protocol_version version;
181 }; 181 };
182} __attribute__((packed)); 182} __attribute__((packed));
183 183
diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio b/drivers/staging/iio/Documentation/sysfs-bus-iio
index fdb017a1c1a2..2dde97de75f8 100644
--- a/drivers/staging/iio/Documentation/sysfs-bus-iio
+++ b/drivers/staging/iio/Documentation/sysfs-bus-iio
@@ -1,11 +1,12 @@
1What: /sys/bus/iio/devices/device[n] 1What: /sys/bus/iio/devices/deviceX
2KernelVersion: 2.6.35 2KernelVersion: 2.6.35
3Contact: linux-iio@vger.kernel.org 3Contact: linux-iio@vger.kernel.org
4Description: 4Description:
5 Hardware chip or device accessed by on communication port. 5 Hardware chip or device accessed by on communication port.
6 Corresponds to a grouping of sensor channels. 6 Corresponds to a grouping of sensor channels. X is the IIO
7 index of the device.
7 8
8What: /sys/bus/iio/devices/trigger[n] 9What: /sys/bus/iio/devices/triggerX
9KernelVersion: 2.6.35 10KernelVersion: 2.6.35
10Contact: linux-iio@vger.kernel.org 11Contact: linux-iio@vger.kernel.org
11Description: 12Description:
@@ -13,25 +14,26 @@ Description:
13 May be provided by a device driver that also has an IIO device 14 May be provided by a device driver that also has an IIO device
14 based on hardware generated events (e.g. data ready) or 15 based on hardware generated events (e.g. data ready) or
15 provided by a separate driver for other hardware (e.g. 16 provided by a separate driver for other hardware (e.g.
16 periodic timer, gpio or high resolution timer). 17 periodic timer, GPIO or high resolution timer).
17 Contains trigger type specific elements. These do not 18 Contains trigger type specific elements. These do not
18 generalize well and hence are not documented in this file. 19 generalize well and hence are not documented in this file.
20 X is the IIO index of the trigger.
19 21
20What: /sys/bus/iio/devices/device[n]:buffer 22What: /sys/bus/iio/devices/deviceX:buffer
21KernelVersion: 2.6.35 23KernelVersion: 2.6.35
22Contact: linux-iio@vger.kernel.org 24Contact: linux-iio@vger.kernel.org
23Description: 25Description:
24 Link to /sys/class/iio/device[n]/device[n]:buffer. n indicates 26 Link to /sys/class/iio/deviceX/deviceX:buffer. X indicates
25 the device with which this buffer buffer is associated. 27 the device with which this buffer buffer is associated.
26 28
27What: /sys/.../device[n]/name 29What: /sys/bus/iio/devices/deviceX/name
28KernelVersion: 2.6.35 30KernelVersion: 2.6.35
29Contact: linux-iio@vger.kernel.org 31Contact: linux-iio@vger.kernel.org
30Description: 32Description:
31 Description of the physical chip / device. Typically a part 33 Description of the physical chip / device for device X.
32 number. 34 Typically a part number.
33 35
34What: /sys/.../device[n]/sampling_frequency 36What: /sys/bus/iio/devices/deviceX/sampling_frequency
35KernelVersion: 2.6.35 37KernelVersion: 2.6.35
36Contact: linux-iio@vger.kernel.org 38Contact: linux-iio@vger.kernel.org
37Description: 39Description:
@@ -44,158 +46,233 @@ Description:
44 relevant directories. If it effects all of the above 46 relevant directories. If it effects all of the above
45 then it is to be found in the base device directory as here. 47 then it is to be found in the base device directory as here.
46 48
47What: /sys/.../device[n]/sampling_frequency_available 49What: /sys/bus/iio/devices/deviceX/sampling_frequency_available
48KernelVersion: 2.6.35 50KernelVersion: 2.6.35
49Contact: linux-iio@vger.kernel.org 51Contact: linux-iio@vger.kernel.org
50Description: 52Description:
51 When the internal sampling clock can only take a small 53 When the internal sampling clock can only take a small
52 discrete set of values, this file lists those availale. 54 discrete set of values, this file lists those available.
53 55
54What: /sys/.../device[n]/in[m][_name]_raw 56What: /sys/bus/iio/devices/deviceX/inY_raw
57What: /sys/bus/iio/devices/deviceX/inY_supply_raw
55KernelVersion: 2.6.35 58KernelVersion: 2.6.35
56Contact: linux-iio@vger.kernel.org 59Contact: linux-iio@vger.kernel.org
57Description: 60Description:
58 Raw (unscaled no bias removal etc) voltage measurement from 61 Raw (unscaled no bias removal etc) voltage measurement from
59 channel m. name is used in special cases where this does 62 channel Y. In special cases where the channel does not
60 not correspond to externally available input (e.g. supply 63 correspond to externally available input one of the named
61 voltage monitoring in which case the file is in_supply_raw). 64 versions may be used. The number must always be specified and
62 If the device supports events on this channel then m must be 65 unique to allow association with event codes.
63 specified (even on named channels) so as to allow the source 66
64 of event codes to be identified. 67What: /sys/bus/iio/devices/deviceX/inY-inZ_raw
65
66What: /sys/.../device[n]/in[m][_name]_offset
67KernelVersion: 2.6.35 68KernelVersion: 2.6.35
68Contact: linux-iio@vger.kernel.org 69Contact: linux-iio@vger.kernel.org
69Description: 70Description:
70 If known for a device, offset to be added to in[m]_raw prior 71 Raw (unscaled) differential voltage measurement equivalent to
71 to scaling by in[_name][m]_scale in order to obtain voltage in 72 channel Y - channel Z where these channel numbers apply to the
72 millivolts. Not present if the offset is always 0 or unknown. 73 physically equivalent inputs when non differential readings are
73 If m is not present, then voltage offset applies to all in 74 separately available. In differential only parts, then all that
74 channels. May be writable if a variable offset is controlled 75 is required is a consistent labeling.
75 by the device. Note that this is different to calibbias which
76 is for devices that apply offsets to compensate for variation
77 between different instances of the part, typically adjusted by
78 using some hardware supported calibration procedure.
79 76
80What: /sys/.../device[n]/in[m][_name]_offset_available 77What: /sys/bus/iio/devices/deviceX/temp_raw
78What: /sys/bus/iio/devices/deviceX/temp_x_raw
79What: /sys/bus/iio/devices/deviceX/temp_y_raw
80What: /sys/bus/iio/devices/deviceX/temp_z_raw
81KernelVersion: 2.6.35 81KernelVersion: 2.6.35
82Contact: linux-iio@vger.kernel.org 82Contact: linux-iio@vger.kernel.org
83Description: 83Description:
84 If a small number of discrete offset values are available, this 84 Raw (unscaled no bias removal etc) temperature measurement.
85 will be a space separated list. If these are independant (but 85 It an axis is specified it generally means that the temperature
86 options the same) for individual offsets then m should not be 86 sensor is associated with one part of a compound device (e.g.
87 present. 87 a gyroscope axis).
88 88
89What: /sys/.../device[n]/in[m][_name]_offset_[min|max] 89What: /sys/bus/iio/devices/deviceX/accel_x_raw
90What: /sys/bus/iio/devices/deviceX/accel_y_raw
91What: /sys/bus/iio/devices/deviceX/accel_z_raw
90KernelVersion: 2.6.35 92KernelVersion: 2.6.35
91Contact: linux-iio@vger.kernel.org 93Contact: linux-iio@vger.kernel.org
92Description: 94Description:
93 If a more or less continuous range of voltage offsets are 95 Acceleration in direction x, y or z (may be arbitrarily assigned
94 supported then these specify the minimum and maximum. If shared 96 but should match other such assignments on device)
95 by all in channels then m is not present. 97 channel m (not present if only one accelerometer channel at
98 this orientation). Has all of the equivalent parameters as per
99 inY. Units after application of scale and offset are m/s^2.
96 100
97What: /sys/.../device[n]/in[m][_name]_calibbias 101What: /sys/bus/iio/devices/deviceX/gyro_x_raw
102What: /sys/bus/iio/devices/deviceX/gyro_y_raw
103What: /sys/bus/iio/devices/deviceX/gyro_z_raw
98KernelVersion: 2.6.35 104KernelVersion: 2.6.35
99Contact: linux-iio@vger.kernel.org 105Contact: linux-iio@vger.kernel.org
100Description: 106Description:
101 Hardware applied calibration offset. (assumed to fix production 107 Angular velocity about axis x, y or z (may be arbitrarily
102 inaccuracies) 108 assigned) Data converted by application of offset then scale to
109 radians per second. Has all the equivalent parameters as
110 per inY.
103 111
104What /sys/.../device[n]/in[m][_name]_calibscale 112What: /sys/bus/iio/devices/deviceX/incli_x_raw
113What: /sys/bus/iio/devices/deviceX/incli_y_raw
114What: /sys/bus/iio/devices/deviceX/incli_z_raw
105KernelVersion: 2.6.35 115KernelVersion: 2.6.35
106Contact: linux-iio@vger.kernel.org 116Contact: linux-iio@vger.kernel.org
107Description: 117Description:
108 Hardware applied calibration scale factor. (assumed to fix 118 Inclination raw reading about axis x, y or z (may be
109 production inaccuracies) 119 arbitrarily assigned). Data converted by application of offset
120 and scale to Degrees.
110 121
111What: /sys/.../device[n]/in[m][_name]_scale 122What: /sys/bus/iio/devices/deviceX/magn_x_raw
123What: /sys/bus/iio/devices/deviceX/magn_y_raw
124What: /sys/bus/iio/devices/deviceX/magn_z_raw
112KernelVersion: 2.6.35 125KernelVersion: 2.6.35
113Contact: linux-iio@vger.kernel.org 126Contact: linux-iio@vger.kernel.org
114Description: 127Description:
115 If known for a device, scale to be applied to volt[m]_raw post 128 Magnetic field along axis x, y or z (may be arbitrarily
116 addition of in[_name][m]_offset in order to obtain the measured 129 assigned) channel m (not present if only one magnetometer
117 voltage in millivolts. If shared across all in channels then 130 at this orientation). Data converted by application of
118 m is not present. 131 offset then scale to Gauss. Has all the equivalent modifiers
132 as per inY.
119 133
120What: /sys/.../device[n]/in[m]-in[o]_raw 134What: /sys/bus/iio/devices/deviceX/accel_x_peak_raw
121KernelVersion: 2.6.35 135What: /sys/bus/iio/devices/deviceX/accel_y_peak_raw
136What: /sys/bus/iio/devices/deviceX/accel_z_peak_raw
137KernelVersion: 2.6.36
122Contact: linux-iio@vger.kernel.org 138Contact: linux-iio@vger.kernel.org
123Description: 139Description:
124 Raw (unscaled) differential voltage measurement equivalent to 140 Some devices provide a store of the highest value seen since
125 channel m - channel o where these channel numbers apply to the 141 some reset condition. These attributes allow access to this
126 physically equivalent inputs when non differential readings are 142 and are otherwise the direct equivalent of the
127 separately available. In differential only parts, then all that 143 <type>Y[_name]_raw attributes.
128 is required is a consistent labelling.
129 144
130What: /sys/.../device[n]/accel[_x|_y|_z][m]_raw 145What: /sys/bus/iio/devices/deviceX/accel_xyz_squared_peak_raw
131KernelVersion: 2.6.35 146KernelVersion: 2.6.36
132Contact: linux-iio@vger.kernel.org 147Contact: linux-iio@vger.kernel.org
133Description: 148Description:
134 Acceleration in direction x, y or z (may be arbitrarily assigned 149 A computed peak value based on the sum squared magnitude of
135 but should match other such assignments on device) 150 the underlying value in the specified directions.
136 channel m (not present if only one accelerometer channel at
137 this orientation). Has all of the equivalent parameters as per
138 in[m]. Units after application of scale and offset are m/s^2.
139 151
140What: /sys/.../device[n]/gyro[_x|_y|_z][m]_raw 152What: /sys/bus/iio/devices/deviceX/accel_offset
153What: /sys/bus/iio/devices/deviceX/temp_offset
141KernelVersion: 2.6.35 154KernelVersion: 2.6.35
142Contact: linux-iio@vger.kernel.org 155Contact: linux-iio@vger.kernel.org
143Description: 156Description:
144 Angular velocity about axis x, y or z (may be arbitrarily 157 If known for a device, offset to be added to <type>[Y]_raw prior
145 assigned) channel m (not present if only one gyroscope at 158 to scaling by <type>[Y]_scale in order to obtain value in the
146 this orientation). 159 <type> units as specified in <type>[y]_raw documentation.
147 Data converted by application of offset then scale to 160 Not present if the offset is always 0 or unknown. If Y is not
148 radians per second. Has all the equivalent parameters as 161 present, then the offset applies to all in channels of <type>.
149 per in[m]. 162 May be writable if a variable offset can be applied on the
150 163 device. Note that this is different to calibbias which
151What: /sys/.../device[n]/incli[_x|_y|_z][m]_raw 164 is for devices (or drivers) that apply offsets to compensate
165 for variation between different instances of the part, typically
166 adjusted by using some hardware supported calibration procedure.
167
168What: /sys/bus/iio/devices/deviceX/inY_scale
169What: /sys/bus/iio/devices/deviceX/inY_supply_scale
170What: /sys/bus/iio/devices/deviceX/in_scale
171What: /sys/bus/iio/devices/deviceX/accel_scale
172What: /sys/bus/iio/devices/deviceX/accel_peak_scale
173What: /sys/bus/iio/devices/deviceX/gyro_scale
174What: /sys/bus/iio/devices/deviceX/magn_scale
175What: /sys/bus/iio/devices/deviceX/magn_x_scale
176What: /sys/bus/iio/devices/deviceX/magn_y_scale
177What: /sys/bus/iio/devices/deviceX/magn_z_scale
152KernelVersion: 2.6.35 178KernelVersion: 2.6.35
153Contact: linux-iio@vger.kernel.org 179Contact: linux-iio@vger.kernel.org
154Description: 180Description:
155 Inclination raw reading about axis x, y or z (may be arbitarily 181 If known for a device, scale to be applied to <type>Y[_name]_raw
156 assigned) channel m (not present if only one inclinometer at 182 post addition of <type>[Y][_name]_offset in order to obtain the
157 this orientation). Data converted by application of offset 183 measured value in <type> units as specified in
158 and scale to Degrees. 184 <type>[Y][_name]_raw documentation.. If shared across all in
159 185 channels then Y is not present and the value is called
160What: /sys/.../device[n]/magn[_x|_y|_z][m]_raw 186 <type>[Y][_name]_scale. The peak modifier means this value
187 is applied to <type>Y[_name]_peak_raw values.
188
189What: /sys/bus/iio/devices/deviceX/accel_x_calibbias
190What: /sys/bus/iio/devices/deviceX/accel_y_calibbias
191What: /sys/bus/iio/devices/deviceX/accel_z_calibbias
192What: /sys/bus/iio/devices/deviceX/gyro_x_calibbias
193What: /sys/bus/iio/devices/deviceX/gyro_y_calibbias
194What: /sys/bus/iio/devices/deviceX/gyro_z_calibbias
161KernelVersion: 2.6.35 195KernelVersion: 2.6.35
162Contact: linux-iio@vger.kernel.org 196Contact: linux-iio@vger.kernel.org
163Description: 197Description:
164 Magnetic field along axis x, y or z (may be arbitrarily 198 Hardware applied calibration offset. (assumed to fix production
165 assigned) channel m (not present if only one magnetometer 199 inaccuracies). If shared across all channels, <type>_calibbias
166 at this orientation). Data converted by application of 200 is used.
167 offset then scale to Gauss. Has all the equivalent modifiers 201
168 as per in[m]. 202What /sys/bus/iio/devices/deviceX/inY_calibscale
169 203What /sys/bus/iio/devices/deviceX/inY_supply_calibscale
170What: /sys/.../device[n]/device[n]:event[m] 204What /sys/bus/iio/devices/deviceX/in_calibscale
205What /sys/bus/iio/devices/deviceX/accel_x_calibscale
206What /sys/bus/iio/devices/deviceX/accel_y_calibscale
207What /sys/bus/iio/devices/deviceX/accel_z_calibscale
208What /sys/bus/iio/devices/deviceX/gyro_x_calibscale
209What /sys/bus/iio/devices/deviceX/gyro_y_calibscale
210What /sys/bus/iio/devices/deviceX/gyro_z_calibscale
171KernelVersion: 2.6.35 211KernelVersion: 2.6.35
172Contact: linux-iio@vger.kernel.org 212Contact: linux-iio@vger.kernel.org
173Description: 213Description:
174 Configuration of which hardware generated events are passed up to 214 Hardware applied calibration scale factor. (assumed to fix
175 userspace. Some of these are a bit complex to generalize so this 215 production inaccuracies). If shared across all channels,
176 section is a work in progress. 216 <type>_calibscale is used.
177 217
178What: /sys/.../device[n]:event[m]/dev 218What: /sys/bus/iio/devices/deviceX/accel_scale_available
179KernelVersion: 2.6.35 219KernelVersion: 2.635
180Contact: linux-iio@vger.kernel.org 220Contact: linux-iio@vger.kernel.org
181Description: 221Description:
182 major:minor character device numbers for the event line. 222 If a discrete set of scale values are available, they
223 are listed in this attribute.
183 224
184Taking accel_x0 as an example 225What: /sys/bus/iio/devices/deviceX/deviceX:eventY
226KernelVersion: 2.6.35
227Contact: linux-iio@vger.kernel.org
228Description:
229 Configuration of which hardware generated events are passed up
230 to user-space.
185 231
186What: /sys/.../device[n]:event[m]/accel_x0_thresh[_rising|_falling]_en 232What: /sys/bus/iio/devices/deviceX:event/dev
233What: /sys/bus/iio/devices/deviceX:eventY/dev
234KernelVersion: 2.6.35
235Contact: linux-iio@vger.kernel.org
236Description:
237 major:minor character device numbers for the event line Y of
238 device X.
239
240What: /sys/.../deviceX:eventY/accel_x_thresh_rising_en
241What: /sys/.../deviceX:eventY/accel_x_thresh_falling_en
242What: /sys/.../deviceX:eventY/accel_y_thresh_rising_en
243What: /sys/.../deviceX:eventY/accel_y_thresh_falling_en
244What: /sys/.../deviceX:eventY/accel_z_thresh_rising_en
245What: /sys/.../deviceX:eventY/accel_z_thresh_falling_en
246What: /sys/.../deviceX:eventY/gyro_x_thresh_rising_en
247What: /sys/.../deviceX:eventY/gyro_x_thresh_falling_en
248What: /sys/.../deviceX:eventY/gyro_y_thresh_rising_en
249What: /sys/.../deviceX:eventY/gyro_y_thresh_falling_en
250What: /sys/.../deviceX:eventY/gyro_z_thresh_rising_en
251What: /sys/.../deviceX:eventY/gyro_z_thresh_falling_en
252What: /sys/.../deviceX:eventY/magn_x_thresh_rising_en
253What: /sys/.../deviceX:eventY/magn_x_thresh_falling_en
254What: /sys/.../deviceX:eventY/magn_y_thresh_rising_en
255What: /sys/.../deviceX:eventY/magn_y_thresh_falling_en
256What: /sys/.../deviceX:eventY/magn_z_thresh_rising_en
257What: /sys/.../deviceX:eventY/magn_z_thresh_falling_en
258What: /sys/.../deviceX:eventY/inZ_supply_thresh_rising_en
259What: /sys/.../deviceX:eventY/inZ_supply_thresh_falling_en
260What: /sys/.../deviceX:eventY/inZ_thresh_rising_en
261What: /sys/.../deviceX:eventY/inZ_thresh_falling_en
262What: /sys/.../deviceX:eventY/temp_thresh_rising_en
263What: /sys/.../deviceX:eventY/temp_thresh_falling_en
187KernelVersion: 2.6.37 264KernelVersion: 2.6.37
188Contact: linux-iio@vger.kernel.org 265Contact: linux-iio@vger.kernel.org
189Description: 266Description:
190 Event generated when accel_x0 passes a threshold in the specfied 267 Event generated when channel passes a threshold in the specified
191 (_rising|_falling) direction. If the direction is not specified, 268 (_rising|_falling) direction. If the direction is not specified,
192 then either the device will report an event which ever direction 269 then either the device will report an event which ever direction
193 a single threshold value is called in (e.g. 270 a single threshold value is called in (e.g.
194 accel_x0_<raw|input>_thresh_value) or 271 <type>[Z][_name]_<raw|input>_thresh_value) or
195 accel_x0_<raw|input>_thresh_rising_value and 272 <type>[Z][_name]_<raw|input>_thresh_rising_value and
196 accel_x0_<raw|input>_thresh_falling_value may take different 273 <type>[Z][_name]_<raw|input>_thresh_falling_value may take
197 values, but the device can only enable both thresholds or 274 different values, but the device can only enable both thresholds
198 neither. 275 or neither.
199 Note the driver will assume the last p events requested are 276 Note the driver will assume the last p events requested are
200 to be enabled where p is however many it supports (which may 277 to be enabled where p is however many it supports (which may
201 vary depending on the exact set requested. So if you want to be 278 vary depending on the exact set requested. So if you want to be
@@ -205,186 +282,338 @@ Description:
205 a given event type is enabled a future point (and not those for 282 a given event type is enabled a future point (and not those for
206 whatever event was previously enabled). 283 whatever event was previously enabled).
207 284
208What: /sys/.../accel_x0_<raw|input>_thresh[_rising|_falling]_value 285What: /sys/.../deviceX:eventY/accel_x_roc_rising_en
286What: /sys/.../deviceX:eventY/accel_x_roc_falling_en
287What: /sys/.../deviceX:eventY/accel_y_roc_rising_en
288What: /sys/.../deviceX:eventY/accel_y_roc_falling_en
289What: /sys/.../deviceX:eventY/accel_z_roc_rising_en
290What: /sys/.../deviceX:eventY/accel_z_roc_falling_en
291What: /sys/.../deviceX:eventY/gyro_x_roc_rising_en
292What: /sys/.../deviceX:eventY/gyro_x_roc_falling_en
293What: /sys/.../deviceX:eventY/gyro_y_roc_rising_en
294What: /sys/.../deviceX:eventY/gyro_y_roc_falling_en
295What: /sys/.../deviceX:eventY/gyro_z_roc_rising_en
296What: /sys/.../deviceX:eventY/gyro_z_roc_falling_en
297What: /sys/.../deviceX:eventY/magn_x_roc_rising_en
298What: /sys/.../deviceX:eventY/magn_x_roc_falling_en
299What: /sys/.../deviceX:eventY/magn_y_roc_rising_en
300What: /sys/.../deviceX:eventY/magn_y_roc_falling_en
301What: /sys/.../deviceX:eventY/magn_z_roc_rising_en
302What: /sys/.../deviceX:eventY/magn_z_roc_falling_en
303What: /sys/.../deviceX:eventY/inZ_supply_roc_rising_en
304What: /sys/.../deviceX:eventY/inZ_supply_roc_falling_en
305What: /sys/.../deviceX:eventY/inZ_roc_rising_en
306What: /sys/.../deviceX:eventY/inZ_roc_falling_en
307What: /sys/.../deviceX:eventY/temp_roc_rising_en
308What: /sys/.../deviceX:eventY/temp_roc_falling_en
309KernelVersion: 2.6.37
310Contact: linux-iio@vger.kernel.org
311Description:
312 Event generated when channel passes a threshold on the rate of
313 change (1st differential) in the specified (_rising|_falling)
314 direction. If the direction is not specified, then either the
315 device will report an event which ever direction a single
316 threshold value is called in (e.g.
317 <type>[Z][_name]_<raw|input>_roc_value) or
318 <type>[Z][_name]_<raw|input>_roc_rising_value and
319 <type>[Z][_name]_<raw|input>_roc_falling_value may take
320 different values, but the device can only enable both rate of
321 change thresholds or neither.
322 Note the driver will assume the last p events requested are
323 to be enabled where p is however many it supports (which may
324 vary depending on the exact set requested. So if you want to be
325 sure you have set what you think you have, check the contents of
326 these attributes after everything is configured. Drivers may
327 have to buffer any parameters so that they are consistent when
328 a given event type is enabled a future point (and not those for
329 whatever event was previously enabled).
330
331What: /sys/.../deviceX:eventY/accel_x_raw_thresh_rising_value
332What: /sys/.../deviceX:eventY/accel_x_raw_thresh_falling_value
333What: /sys/.../deviceX:eventY/accel_y_raw_thresh_rising_value
334What: /sys/.../deviceX:eventY/accel_y_raw_thresh_falling_value
335What: /sys/.../deviceX:eventY/accel_z_raw_thresh_rising_value
336What: /sys/.../deviceX:eventY/accel_z_raw_thresh_falling_value
337What: /sys/.../deviceX:eventY/gyro_x_raw_thresh_rising_value
338What: /sys/.../deviceX:eventY/gyro_x_raw_thresh_falling_value
339What: /sys/.../deviceX:eventY/gyro_y_raw_thresh_rising_value
340What: /sys/.../deviceX:eventY/gyro_y_raw_thresh_falling_value
341What: /sys/.../deviceX:eventY/gyro_z_raw_thresh_rising_value
342What: /sys/.../deviceX:eventY/gyro_z_raw_thresh_falling_value
343What: /sys/.../deviceX:eventY/magn_x_raw_thresh_rising_value
344What: /sys/.../deviceX:eventY/magn_x_raw_thresh_falling_value
345What: /sys/.../deviceX:eventY/magn_y_raw_thresh_rising_value
346What: /sys/.../deviceX:eventY/magn_y_raw_thresh_falling_value
347What: /sys/.../deviceX:eventY/magn_z_raw_thresh_rising_value
348What: /sys/.../deviceX:eventY/magn_z_raw_thresh_falling_value
349What: /sys/.../deviceX:eventY/inZ_supply_raw_thresh_rising_value
350What: /sys/.../deviceX:eventY/inZ_supply_raw_thresh_falling_value
351What: /sys/.../deviceX:eventY/inZ_raw_thresh_falling_value
352What: /sys/.../deviceX:eventY/inZ_raw_thresh_falling_value
353What: /sys/.../deviceX:eventY/temp_raw_thresh_falling_value
354What: /sys/.../deviceX:eventY/temp_raw_thresh_falling_value
209KernelVersion: 2.6.37 355KernelVersion: 2.6.37
210Contact: linux-iio@vger.kernel.org 356Contact: linux-iio@vger.kernel.org
211Description: 357Description:
212 Specifies the value of threshold that the device is comparing 358 Specifies the value of threshold that the device is comparing
213 against for the events enabled by 359 against for the events enabled by
214 accel_x0_<raw|input>_thresh[_rising|falling]_en. 360 <type>Z[_name]_thresh[_rising|falling]_en.
215 If seperate exist for the two directions, but direction is 361 If separate attributes exist for the two directions, but
216 not specified for this attribute, then a single threshold value 362 direction is not specified for this attribute, then a single
217 applies to both directions. 363 threshold value applies to both directions.
218 The raw or input element of the name indicates whether the 364 The raw or input element of the name indicates whether the
219 value is in raw device units or in processed units (as _raw 365 value is in raw device units or in processed units (as _raw
220 and _input do on sysfs direct channel read attributes). 366 and _input do on sysfs direct channel read attributes).
221 367
222What: /sys/.../accel_x0_thresh[_rising|_falling]_meanperiod 368What: /sys/.../deviceX:eventY/accel_x_raw_roc_rising_value
369What: /sys/.../deviceX:eventY/accel_x_raw_roc_falling_value
370What: /sys/.../deviceX:eventY/accel_y_raw_roc_rising_value
371What: /sys/.../deviceX:eventY/accel_y_raw_roc_falling_value
372What: /sys/.../deviceX:eventY/accel_z_raw_roc_rising_value
373What: /sys/.../deviceX:eventY/accel_z_raw_roc_falling_value
374What: /sys/.../deviceX:eventY/gyro_x_raw_roc_rising_value
375What: /sys/.../deviceX:eventY/gyro_x_raw_roc_falling_value
376What: /sys/.../deviceX:eventY/gyro_y_raw_roc_rising_value
377What: /sys/.../deviceX:eventY/gyro_y_raw_roc_falling_value
378What: /sys/.../deviceX:eventY/gyro_z_raw_roc_rising_value
379What: /sys/.../deviceX:eventY/gyro_z_raw_roc_falling_value
380What: /sys/.../deviceX:eventY/magn_x_raw_roc_rising_value
381What: /sys/.../deviceX:eventY/magn_x_raw_roc_falling_value
382What: /sys/.../deviceX:eventY/magn_y_raw_roc_rising_value
383What: /sys/.../deviceX:eventY/magn_y_raw_roc_falling_value
384What: /sys/.../deviceX:eventY/magn_z_raw_roc_rising_value
385What: /sys/.../deviceX:eventY/magn_z_raw_roc_falling_value
386What: /sys/.../deviceX:eventY/inZ_supply_raw_roc_rising_value
387What: /sys/.../deviceX:eventY/inZ_supply_raw_roc_falling_value
388What: /sys/.../deviceX:eventY/inZ_raw_roc_falling_value
389What: /sys/.../deviceX:eventY/inZ_raw_roc_falling_value
390What: /sys/.../deviceX:eventY/temp_raw_roc_falling_value
391What: /sys/.../deviceX:eventY/temp_raw_roc_falling_value
223KernelVersion: 2.6.37 392KernelVersion: 2.6.37
224Contact: linux-iio@vger.kernel.org 393Contact: linux-iio@vger.kernel.org
225Description: 394Description:
226 Period of time (in seconds) over which the raw channel value 395 Specifies the value of rate of change threshold that the
227 is averaged before being compared with the threshold set in 396 device is comparing against for the events enabled by
228 accel_x0_thresh[_rising|_falling]_meanperiod. If direction is 397 <type>[Z][_name]_roc[_rising|falling]_en.
229 not specified then this mean period applies to both directions. 398 If separate attributes exist for the two directions,
399 but direction is not specified for this attribute,
400 then a single threshold value applies to both directions.
401 The raw or input element of the name indicates whether the
402 value is in raw device units or in processed units (as _raw
403 and _input do on sysfs direct channel read attributes).
230 404
231What: /sys/.../accel_x0_thresh[_rising|_falling]_period 405What: /sys/.../deviceX:eventY/accel_x_thresh_rising_period
406What: /sys/.../deviceX:eventY/accel_x_thresh_falling_period
407hat: /sys/.../deviceX:eventY/accel_x_roc_rising_period
408What: /sys/.../deviceX:eventY/accel_x_roc_falling_period
409What: /sys/.../deviceX:eventY/accel_y_thresh_rising_period
410What: /sys/.../deviceX:eventY/accel_y_thresh_falling_period
411What: /sys/.../deviceX:eventY/accel_y_roc_rising_period
412What: /sys/.../deviceX:eventY/accel_y_roc_falling_period
413What: /sys/.../deviceX:eventY/accel_z_thresh_rising_period
414What: /sys/.../deviceX:eventY/accel_z_thresh_falling_period
415What: /sys/.../deviceX:eventY/accel_z_roc_rising_period
416What: /sys/.../deviceX:eventY/accel_z_roc_falling_period
417What: /sys/.../deviceX:eventY/gyro_x_thresh_rising_period
418What: /sys/.../deviceX:eventY/gyro_x_thresh_falling_period
419What: /sys/.../deviceX:eventY/gyro_x_roc_rising_period
420What: /sys/.../deviceX:eventY/gyro_x_roc_falling_period
421What: /sys/.../deviceX:eventY/gyro_y_thresh_rising_period
422What: /sys/.../deviceX:eventY/gyro_y_thresh_falling_period
423What: /sys/.../deviceX:eventY/gyro_y_roc_rising_period
424What: /sys/.../deviceX:eventY/gyro_y_roc_falling_period
425What: /sys/.../deviceX:eventY/gyro_z_thresh_rising_period
426What: /sys/.../deviceX:eventY/gyro_z_thresh_falling_period
427What: /sys/.../deviceX:eventY/gyro_z_roc_rising_period
428What: /sys/.../deviceX:eventY/gyro_z_roc_falling_period
429What: /sys/.../deviceX:eventY/magn_x_thresh_rising_period
430What: /sys/.../deviceX:eventY/magn_x_thresh_falling_period
431What: /sys/.../deviceX:eventY/magn_x_roc_rising_period
432What: /sys/.../deviceX:eventY/magn_x_roc_falling_period
433What: /sys/.../deviceX:eventY/magn_y_thresh_rising_period
434What: /sys/.../deviceX:eventY/magn_y_thresh_falling_period
435What: /sys/.../deviceX:eventY/magn_y_roc_rising_period
436What: /sys/.../deviceX:eventY/magn_y_roc_falling_period
437What: /sys/.../deviceX:eventY/magn_z_thresh_rising_period
438What: /sys/.../deviceX:eventY/magn_z_thresh_falling_period
439What: /sys/.../deviceX:eventY/magn_z_roc_rising_period
440What: /sys/.../deviceX:eventY/magn_z_roc_falling_period
441What: /sys/.../deviceX:eventY/inZ_supply_thresh_rising_period
442What: /sys/.../deviceX:eventY/inZ_supply_thresh_falling_period
443What: /sys/.../deviceX:eventY/inz_supply_roc_rising_period
444What: /sys/.../deviceX:eventY/inZ_supply_roc_falling_period
445What: /sys/.../deviceX:eventY/inZ_thresh_rising_period
446What: /sys/.../deviceX:eventY/inZ_thresh_falling_period
447What: /sys/.../deviceX:eventY/inZ_roc_rising_period
448What: /sys/.../deviceX:eventY/inZ_roc_falling_period
449What: /sys/.../deviceX:eventY/temp_thresh_rising_period
450What: /sys/.../deviceX:eventY/temp_thresh_falling_period
451What: /sys/.../deviceX:eventY/temp_roc_rising_period
452What: /sys/.../deviceX:eventY/temp_roc_falling_period
453What: /sys/.../deviceX:eventY/accel_x&y&z_mag_falling_period
232KernelVersion: 2.6.37 454KernelVersion: 2.6.37
233Contact: linux-iio@vger.kernel.org 455Contact: linux-iio@vger.kernel.org
234Description: 456Description:
235 Period of time (in seconds) for which the threshold must be 457 Period of time (in seconds) for which the condition must be
236 passed before an event is generated. If direction is not 458 met before an event is generated. If direction is not
237 specified then this period applies to both directions. 459 specified then this period applies to both directions.
238 460
239What: /sys/.../device[n]:event[m]/accel_x0_mag[_rising|_falling]_en 461What: /sys/.../deviceX:eventY/accel_mag_en
462What: /sys/.../deviceX:eventY/accel_mag_rising_en
463What: /sys/.../deviceX:eventY/accel_mag_falling_en
464What: /sys/.../deviceX:eventY/accel_x_mag_en
465What: /sys/.../deviceX:eventY/accel_x_mag_rising_en
466What: /sys/.../deviceX:eventY/accel_x_mag_falling_en
467What: /sys/.../deviceX:eventY/accel_y_mag_en
468What: /sys/.../deviceX:eventY/accel_y_mag_rising_en
469What: /sys/.../deviceX:eventY/accel_y_mag_falling_en
470What: /sys/.../deviceX:eventY/accel_z_mag_en
471What: /sys/.../deviceX:eventY/accel_z_mag_rising_en
472What: /sys/.../deviceX:eventY/accel_z_mag_falling_en
473What: /sys/.../deviceX:eventY/accel_x&y&z_mag_rising_en
474What: /sys/.../deviceX:eventY/accel_x&y&z_mag_falling_en
240KernelVersion: 2.6.37 475KernelVersion: 2.6.37
241Contact: linux-iio@vger.kernel.org 476Contact: linux-iio@vger.kernel.org
242Description: 477Description:
243 Similar to accel_x0_thresh[_rising|_falling]_en, but here the 478 Similar to accel_x_thresh[_rising|_falling]_en, but here the
244 magnitude of the channel is compared to the threshold, not its 479 magnitude of the channel is compared to the threshold, not its
245 signed value. 480 signed value.
246 481
247What: /sys/.../accel_x0_<raw|input>_mag[_rising|_falling]_value 482What: /sys/.../accel_raw_mag_value
248KernelVersion: 2.6.37 483What: /sys/.../accel_x_raw_mag_rising_value
249Contact: linux-iio@vger.kernel.org 484What: /sys/.../accel_y_raw_mag_rising_value
250Description: 485What: /sys/.../accel_z_raw_mag_rising_value
251 The value to which the magnitude of the channel is compared.
252
253What: /sys/.../accel_x0_mag[_rising|_falling]_meanperiod
254KernelVersion: 2.6.37
255Contact: linux-iio@vger.kernel.org
256Description:
257 Period of time (in seconds) over which the value of the channel
258 is averaged before being compared to the threshold
259
260What: /sys/.../accel_x0_mag[_rising|_falling]_period
261KernelVersion: 2.6.37
262Contact: linux-iio@vger.kernel.org
263Description:
264 Period of time (in seconds) for which the condition must be true
265 before an event occurs.
266
267What: /sys/.../device[n]:event[m]/accel_x0_roc[_rising|_falling]_en
268KernelVersion: 2.6.37 486KernelVersion: 2.6.37
269Contact: linux-iio@vger.kernel.org 487Contact: linux-iio@vger.kernel.org
270Description: 488Description:
271 Similar to accel_x0_thresh[_rising|_falling]_en, but here the 489 The value to which the magnitude of the channel is compared. If
272 first differential is compared with the threshold. 490 number or direction is not specified, applies to all channels of
491 this type.
273 492
274What: /sys/.../accel_x0_<raw|input>_roc[_rising|_falling]_value 493What: /sys/bus/iio/devices/deviceX:buffer:event/dev
275KernelVersion: 2.6.37
276Contact: linux-iio@vger.kernel.org
277Description:
278 The value to which the first differential of the channel is
279 compared.
280
281What: /sys/.../accel_x0_roc[_rising|_falling]_meanperiod
282KernelVersion: 2.6.37
283Contact: linux-iio@vger.kernel.org
284Description:
285 Period of time (in seconds) over which the value of the channel
286 is averaged before being compared to the threshold
287
288What: /sys/.../accel_x0_roc[_rising|_falling]_period
289KernelVersion: 2.6.37
290Contact: linux-iio@vger.kernel.org
291Description:
292 Period of time (in seconds) for which the condition must be true
293 before an event occurs.
294
295What: /sys/.../device[n]/device[n]:buffer:event/dev
296KernelVersion: 2.6.35 494KernelVersion: 2.6.35
297Contact: linux-iio@vger.kernel.org 495Contact: linux-iio@vger.kernel.org
298Description: 496Description:
299 Buffer for device n event character device major:minor numbers. 497 Buffer for device X event character device major:minor numbers.
300 498
301What: /sys/.../device[n]/device[n]:buffer:access/dev 499What: /sys/bus/iio/devices/deviceX:buffer:access/dev
302KernelVersion: 2.6.35 500KernelVersion: 2.6.35
303Contact: linux-iio@vger.kernel.org 501Contact: linux-iio@vger.kernel.org
304Description: 502Description:
305 Buffer for device n access character device o major:minor numbers. 503 Buffer for device X access character device major:minor numbers.
306 504
307What: /sys/.../device[n]:buffer/trigger 505What: /sys/bus/iio/devices/deviceX:buffer/trigger
308KernelVersion: 2.6.35 506KernelVersion: 2.6.35
309Contact: linux-iio@vger.kernel.org 507Contact: linux-iio@vger.kernel.org
310Description: 508Description:
311 The name of the trigger source being used, as per string given 509 The name of the trigger source being used, as per string given
312 in /sys/class/iio/trigger[n]/name. 510 in /sys/class/iio/triggerY/name.
313 511
314What: /sys/.../device[n]:buffer/length 512What: /sys/bus/iio/devices/deviceX:buffer/length
315KernelVersion: 2.6.35 513KernelVersion: 2.6.35
316Contact: linux-iio@vger.kernel.org 514Contact: linux-iio@vger.kernel.org
317Description: 515Description:
318 Number of scans contained by the buffer. 516 Number of scans contained by the buffer.
319 517
320What: /sys/.../device[n]:buffer/bytes_per_datum 518What: /sys/bus/iio/devices/deviceX:buffer/bytes_per_datum
321KernelVersion: 2.6.37 519KernelVersion: 2.6.37
322Contact: linux-iio@vger.kernel.org 520Contact: linux-iio@vger.kernel.org
323Description: 521Description:
324 Bytes per scan. Due to alignment fun, the scan may be larger 522 Bytes per scan. Due to alignment fun, the scan may be larger
325 than implied directly by the scan_element parameters. 523 than implied directly by the scan_element parameters.
326 524
327What: /sys/.../device[n]:buffer/enable 525What: /sys/bus/iio/devices/deviceX:buffer/enable
328KernelVersion: 2.6.35 526KernelVersion: 2.6.35
329Contact: linux-iio@vger.kernel.org 527Contact: linux-iio@vger.kernel.org
330Description: 528Description:
331 Actually start the buffer capture up. Will start trigger 529 Actually start the buffer capture up. Will start trigger
332 if first device and appropriate. 530 if first device and appropriate.
333 531
334What: /sys/.../device[n]:buffer/alignment 532What: /sys/bus/iio/devices/deviceX:buffer/scan_elements
335KernelVersion: 2.6.35
336Contact: linux-iio@vger.kernel.org
337Description:
338 Minimum data alignment. Scan elements larger than this are
339 aligned to the nearest power of 2 times this. (may not be
340 true in weird hardware buffers that pack data well)
341
342What: /sys/.../device[n]/buffer/scan_elements
343KernelVersion: 2.6.37 533KernelVersion: 2.6.37
344Contact: linux-iio@vger.kernel.org 534Contact: linux-iio@vger.kernel.org
345Description: 535Description:
346 Directory containing interfaces for elements that will be 536 Directory containing interfaces for elements that will be
347 captured for a single triggered sample set in the buffer. 537 captured for a single triggered sample set in the buffer.
348 538
349What: /sys/.../device[n]/buffer/scan_elements/accel_x0_en 539What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/accel_x_en
540What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/accel_y_en
541What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/accel_z_en
542What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/gyro_x_en
543What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/gyro_y_en
544What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/gyro_z_en
545What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/magn_x_en
546What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/magn_y_en
547What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/magn_z_en
548What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/timestamp_en
549What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/inY_supply_en
550What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/inY_en
551What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/inY-inZ_en
552What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/incli_x_en
553What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/incli_y_en
350KernelVersion: 2.6.37 554KernelVersion: 2.6.37
351Contact: linux-iio@vger.kernel.org 555Contact: linux-iio@vger.kernel.org
352Description: 556Description:
353 Scan element control for triggered data capture. 557 Scan element control for triggered data capture.
354 558
355What: /sys/.../device[n]/buffer/scan_elements/accel[_x0]_type 559What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/accel_type
560What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/gyro_type
561What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/magn_type
562What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/incli_type
563What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/inY_type
564What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/in-in_type
565What: /sys/.../deviceX:buffer/scan_elements/inY_supply_type
566What: /sys/.../deviceX:buffer/scan_elements/timestamp_type
356KernelVersion: 2.6.37 567KernelVersion: 2.6.37
357Contact: linux-iio@vger.kernel.org 568Contact: linux-iio@vger.kernel.org
358Description: 569Description:
359 Description of the scan element data storage within the buffer 570 Description of the scan element data storage within the buffer
360 and hence the form in which it is read from userspace. 571 and hence the form in which it is read from user-space.
361 Form is [s|u]bits/storagebits. s or u specifies if signed 572 Form is [s|u]bits/storagebits[>>shift]. s or u specifies if
362 (2's complement) or unsigned. bits is the number of bits of 573 signed (2's complement) or unsigned. bits is the number of bits
363 data and storagebits is the space (after padding) that it 574 of data and storagebits is the space (after padding) that it
364 occupies in the buffer. Note that some devices will have 575 occupies in the buffer. shift if specified, is the shift that
365 additional information in the unused bits so to get a clean 576 needs to be applied prior to masking out unused bits. Some
366 value, the bits value must be used to mask the buffer output 577 devices put their data in the middle of the transferred elements
367 value appropriately. The storagebits value also specifies the 578 with additional information on both sides. Note that some
368 data alignment. So s48/64 will be a signed 48 bit integer 579 devices will have additional information in the unused bits
369 stored in a 64 bit location aligned to a a64 bit boundary. 580 so to get a clean value, the bits value must be used to mask
581 the buffer output value appropriately. The storagebits value
582 also specifies the data alignment. So s48/64>>2 will be a
583 signed 48 bit integer stored in a 64 bit location aligned to
584 a a64 bit boundary. To obtain the clean value, shift right 2
585 and apply a mask to zero the top 16 bits of the result.
370 For other storage combinations this attribute will be extended 586 For other storage combinations this attribute will be extended
371 appropriately. 587 appropriately.
372 588
373What: /sys/.../device[n]/buffer/scan_elements/accel[_x0]_index 589What: /sys/.../deviceX:buffer/scan_elements/accel_type_available
590KernelVersion: 2.6.37
591Contact: linux-iio@vger.kernel.org
592Description:
593 If the type parameter can take one of a small set of values,
594 this attribute lists them.
595
596What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/inY_index
597What: /sys/.../deviceX:buffer/scan_elements/inY_supply_index
598What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/accel_x_index
599What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/accel_y_index
600What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/accel_z_index
601What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/gyro_x_index
602What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/gyro_y_index
603What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/gyro_z_index
604What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/magn_x_index
605What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/magn_y_index
606What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/magn_z_index
607What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/incli_x_index
608What: /sys/bus/iio/devices/deviceX:buffer/scan_elements/incli_y_index
609What: /sys/.../deviceX:buffer/scan_elements/timestamp_index
374KernelVersion: 2.6.37 610KernelVersion: 2.6.37
375Contact: linux-iio@vger.kernel.org 611Contact: linux-iio@vger.kernel.org
376Description: 612Description:
377 A single positive integer specifying the position of this 613 A single positive integer specifying the position of this
378 scan element in the buffer. Note these are not dependant on 614 scan element in the buffer. Note these are not dependent on
379 what is enabled and may not be contiguous. Thus for userspace 615 what is enabled and may not be contiguous. Thus for user-space
380 to establish the full layout these must be used in conjunction 616 to establish the full layout these must be used in conjunction
381 with all _en attributes to establish which channels are present, 617 with all _en attributes to establish which channels are present,
382 and the relevant _type attributes to establish the data storage 618 and the relevant _type attributes to establish the data storage
383 format. 619 format.
384
385What: /sys/.../device[n]/buffer/scan_elements/accel[_x0]_shift
386KernelVersion: 2.6.37
387Contact: linux-iio@vger.kernel.org
388Description:
389 A bit shift (to right) that must be applied prior to
390 extracting the bits specified by accel[_x0]_precision.
diff --git a/drivers/staging/iio/Documentation/sysfs-bus-iio-dds b/drivers/staging/iio/Documentation/sysfs-bus-iio-dds
new file mode 100644
index 000000000000..ffdd5478a35d
--- /dev/null
+++ b/drivers/staging/iio/Documentation/sysfs-bus-iio-dds
@@ -0,0 +1,93 @@
1
2What: /sys/bus/iio/devices/.../ddsX_freqY
3KernelVersion: 2.6.37
4Contact: linux-iio@vger.kernel.org
5Description:
6 Stores frequency into tuning word Y.
7 There will be more than one ddsX_freqY file, which allows for
8 pin controlled FSK Frequency Shift Keying
9 (ddsX_pincontrol_freq_en is active) or the user can control
10 the desired active tuning word by writing Y to the
11 ddsX_freqsymbol file.
12
13What: /sys/bus/iio/devices/.../ddsX_freqY_scale
14KernelVersion: 2.6.37
15Contact: linux-iio@vger.kernel.org
16Description:
17 Scale to be applied to ddsX_freqY in order to obtain the
18 desired value in Hz. If shared across all frequency registers
19 Y is not present. It is also possible X is not present if
20 shared across all channels.
21
22What: /sys/bus/iio/devices/.../ddsX_freqsymbol
23KernelVersion: 2.6.37
24Contact: linux-iio@vger.kernel.org
25Description:
26 Specifies the active output frequency tuning word. The value
27 corresponds to the Y in ddsX_freqY. To exit this mode the user
28 can write ddsX_pincontrol_freq_en or ddsX_out_enable file.
29
30What: /sys/bus/iio/devices/.../ddsX_phaseY
31KernelVersion: 2.6.37
32Contact: linux-iio@vger.kernel.org
33Description:
34 Stores phase into Y.
35 There will be more than one ddsX_phaseY file, which allows for
36 pin controlled PSK Phase Shift Keying
37 (ddsX_pincontrol_phase_en is active) or the user can
38 control the desired phase Y which is added to the phase
39 accumulator output by writing Y to the en_phase file.
40
41What: /sys/bus/iio/devices/.../ddsX_phaseY_scale
42KernelVersion: 2.6.37
43Contact: linux-iio@vger.kernel.org
44Description:
45 Scale to be applied to ddsX_phaseY in order to obtain the
46 desired value in rad. If shared across all phase registers
47 Y is not present. It is also possible X is not present if
48 shared across all channels.
49
50What: /sys/bus/iio/devices/.../ddsX_phasesymbol
51KernelVersion: 2.6.37
52Contact: linux-iio@vger.kernel.org
53Description:
54 Specifies the active phase Y which is added to the phase
55 accumulator output. The value corresponds to the Y in
56 ddsX_phaseY. To exit this mode the user can write
57 ddsX_pincontrol_phase_en or disable file.
58
59What: /sys/bus/iio/devices/.../ddsX_pincontrol_en
60What: /sys/bus/iio/devices/.../ddsX_pincontrol_freq_en
61What: /sys/bus/iio/devices/.../ddsX_pincontrol_phase_en
62KernelVersion: 2.6.37
63Contact: linux-iio@vger.kernel.org
64Description:
65 ddsX_pincontrol_en: Both, the active frequency and phase is
66 controlled by the respective phase and frequency control inputs.
67 In case the device in question allows to independent controls,
68 then there are dedicated files (ddsX_pincontrol_freq_en,
69 ddsX_pincontrol_phase_en).
70
71What: /sys/bus/iio/devices/.../ddsX_out_enable
72What: /sys/bus/iio/devices/.../ddsX_outY_enable
73KernelVersion: 2.6.37
74Contact: linux-iio@vger.kernel.org
75Description:
76 ddsX_outY_enable controls signal generation on output Y of
77 channel X. Y may be suppressed if all channels are
78 controlled together.
79
80What: /sys/bus/iio/devices/.../ddsX_outY_wavetype
81KernelVersion: 2.6.37
82Contact: linux-iio@vger.kernel.org
83Description:
84 Specifies the output waveform.
85 (sine, triangle, ramp, square, ...)
86 For a list of available output waveform options read
87 available_output_modes.
88
89What: /sys/bus/iio/devices/.../ddsX_outY_wavetype_available
90KernelVersion: 2.6.37
91Contact: linux-iio@vger.kernel.org
92Description:
93 Lists all available output waveform options.
diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig
index ed48815a916b..e2ac07d86110 100644
--- a/drivers/staging/iio/Kconfig
+++ b/drivers/staging/iio/Kconfig
@@ -42,11 +42,15 @@ config IIO_TRIGGER
42 42
43source "drivers/staging/iio/accel/Kconfig" 43source "drivers/staging/iio/accel/Kconfig"
44source "drivers/staging/iio/adc/Kconfig" 44source "drivers/staging/iio/adc/Kconfig"
45source "drivers/staging/iio/addac/Kconfig"
46source "drivers/staging/iio/dac/Kconfig"
47source "drivers/staging/iio/dds/Kconfig"
45source "drivers/staging/iio/gyro/Kconfig" 48source "drivers/staging/iio/gyro/Kconfig"
46source "drivers/staging/iio/imu/Kconfig" 49source "drivers/staging/iio/imu/Kconfig"
47source "drivers/staging/iio/light/Kconfig" 50source "drivers/staging/iio/light/Kconfig"
48source "drivers/staging/iio/magnetometer/Kconfig" 51source "drivers/staging/iio/magnetometer/Kconfig"
49 52source "drivers/staging/iio/meter/Kconfig"
53source "drivers/staging/iio/resolver/Kconfig"
50source "drivers/staging/iio/trigger/Kconfig" 54source "drivers/staging/iio/trigger/Kconfig"
51 55
52endif # IIO 56endif # IIO
diff --git a/drivers/staging/iio/Makefile b/drivers/staging/iio/Makefile
index e909674920fc..f9b5fb2fe8f1 100644
--- a/drivers/staging/iio/Makefile
+++ b/drivers/staging/iio/Makefile
@@ -11,8 +11,13 @@ obj-$(CONFIG_IIO_SW_RING) += ring_sw.o
11 11
12obj-y += accel/ 12obj-y += accel/
13obj-y += adc/ 13obj-y += adc/
14obj-y += addac/
15obj-y += dac/
16obj-y += dds/
14obj-y += gyro/ 17obj-y += gyro/
15obj-y += imu/ 18obj-y += imu/
16obj-y += light/ 19obj-y += light/
17obj-y += trigger/
18obj-y += magnetometer/ 20obj-y += magnetometer/
21obj-y += meter/
22obj-y += resolver/
23obj-y += trigger/
diff --git a/drivers/staging/iio/TODO b/drivers/staging/iio/TODO
index 898cba1c939f..d1ad35e24abb 100644
--- a/drivers/staging/iio/TODO
+++ b/drivers/staging/iio/TODO
@@ -61,6 +61,10 @@ necessitate a header that is also visible from arch board
61files. (avoided at the moment to keep the driver set 61files. (avoided at the moment to keep the driver set
62contained in staging). 62contained in staging).
63 63
64ADI Drivers:
65CC the device-drivers-devel@blackfin.uclinux.org mailing list when
66e-mailing the normal IIO list (see below).
67
64Documentation 68Documentation
651) Lots of cleanup and expansion. 691) Lots of cleanup and expansion.
662) Some device require indvidual docs. 702) Some device require indvidual docs.
diff --git a/drivers/staging/iio/accel/Kconfig b/drivers/staging/iio/accel/Kconfig
index 5926c03be1a5..a34f1d3e673c 100644
--- a/drivers/staging/iio/accel/Kconfig
+++ b/drivers/staging/iio/accel/Kconfig
@@ -3,6 +3,33 @@
3# 3#
4comment "Accelerometers" 4comment "Accelerometers"
5 5
6config ADIS16201
7 tristate "Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer"
8 depends on SPI
9 select IIO_TRIGGER if IIO_RING_BUFFER
10 select IIO_SW_RING if IIO_RING_BUFFER
11 help
12 Say yes here to build support for Analog Devices adis16201 dual-axis
13 digital inclinometer and accelerometer.
14
15config ADIS16203
16 tristate "Analog Devices ADIS16203 Programmable 360 Degrees Inclinometer"
17 depends on SPI
18 select IIO_TRIGGER if IIO_RING_BUFFER
19 select IIO_SW_RING if IIO_RING_BUFFER
20 help
21 Say yes here to build support for Analog Devices adis16203 Programmable
22 360 Degrees Inclinometer.
23
24config ADIS16204
25 tristate "Analog Devices ADIS16204 Programmable High-g Digital Impact Sensor and Recorder"
26 depends on SPI
27 select IIO_TRIGGER if IIO_RING_BUFFER
28 select IIO_SW_RING if IIO_RING_BUFFER
29 help
30 Say yes here to build support for Analog Devices adis16204 Programmable
31 High-g Digital Impact Sensor and Recorder.
32
6config ADIS16209 33config ADIS16209
7 tristate "Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer" 34 tristate "Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer"
8 depends on SPI 35 depends on SPI
diff --git a/drivers/staging/iio/accel/Makefile b/drivers/staging/iio/accel/Makefile
index ff84703a16f6..1b2a6d3ddafa 100644
--- a/drivers/staging/iio/accel/Makefile
+++ b/drivers/staging/iio/accel/Makefile
@@ -2,6 +2,18 @@
2# Makefile for industrial I/O accelerometer drivers 2# Makefile for industrial I/O accelerometer drivers
3# 3#
4 4
5adis16201-y := adis16201_core.o
6adis16201-$(CONFIG_IIO_RING_BUFFER) += adis16201_ring.o adis16201_trigger.o
7obj-$(CONFIG_ADIS16201) += adis16201.o
8
9adis16203-y := adis16203_core.o
10adis16203-$(CONFIG_IIO_RING_BUFFER) += adis16203_ring.o adis16203_trigger.o
11obj-$(CONFIG_ADIS16203) += adis16203.o
12
13adis16204-y := adis16204_core.o
14adis16204-$(CONFIG_IIO_RING_BUFFER) += adis16204_ring.o adis16204_trigger.o
15obj-$(CONFIG_ADIS16204) += adis16204.o
16
5adis16209-y := adis16209_core.o 17adis16209-y := adis16209_core.o
6adis16209-$(CONFIG_IIO_RING_BUFFER) += adis16209_ring.o adis16209_trigger.o 18adis16209-$(CONFIG_IIO_RING_BUFFER) += adis16209_ring.o adis16209_trigger.o
7obj-$(CONFIG_ADIS16209) += adis16209.o 19obj-$(CONFIG_ADIS16209) += adis16209.o
diff --git a/drivers/staging/iio/accel/accel.h b/drivers/staging/iio/accel/accel.h
index f5f61b2497aa..50651f835cea 100644
--- a/drivers/staging/iio/accel/accel.h
+++ b/drivers/staging/iio/accel/accel.h
@@ -65,3 +65,23 @@
65#define IIO_DEV_ATTR_ACCEL_Z(_show, _addr) \ 65#define IIO_DEV_ATTR_ACCEL_Z(_show, _addr) \
66 IIO_DEVICE_ATTR(accel_z_raw, S_IRUGO, _show, NULL, _addr) 66 IIO_DEVICE_ATTR(accel_z_raw, S_IRUGO, _show, NULL, _addr)
67 67
68#define IIO_DEV_ATTR_ACCEL_XY(_show, _addr) \
69 IIO_DEVICE_ATTR(accel_xy, S_IRUGO, _show, NULL, _addr)
70
71#define IIO_DEV_ATTR_ACCEL_PEAK(_show, _addr) \
72 IIO_DEVICE_ATTR(accel_peak, S_IRUGO, _show, NULL, _addr)
73
74#define IIO_DEV_ATTR_ACCEL_XPEAK(_show, _addr) \
75 IIO_DEVICE_ATTR(accel_xpeak, S_IRUGO, _show, NULL, _addr)
76
77#define IIO_DEV_ATTR_ACCEL_YPEAK(_show, _addr) \
78 IIO_DEVICE_ATTR(accel_ypeak, S_IRUGO, _show, NULL, _addr)
79
80#define IIO_DEV_ATTR_ACCEL_ZPEAK(_show, _addr) \
81 IIO_DEVICE_ATTR(accel_zpeak, S_IRUGO, _show, NULL, _addr)
82
83#define IIO_DEV_ATTR_ACCEL_XYPEAK(_show, _addr) \
84 IIO_DEVICE_ATTR(accel_xypeak, S_IRUGO, _show, NULL, _addr)
85
86#define IIO_DEV_ATTR_ACCEL_XYZPEAK(_show, _addr) \
87 IIO_DEVICE_ATTR(accel_xyzpeak, S_IRUGO, _show, NULL, _addr)
diff --git a/drivers/staging/iio/accel/adis16201.h b/drivers/staging/iio/accel/adis16201.h
new file mode 100644
index 000000000000..c9bf22c13428
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16201.h
@@ -0,0 +1,150 @@
1#ifndef SPI_ADIS16201_H_
2#define SPI_ADIS16201_H_
3
4#define ADIS16201_STARTUP_DELAY 220 /* ms */
5
6#define ADIS16201_READ_REG(a) a
7#define ADIS16201_WRITE_REG(a) ((a) | 0x80)
8
9#define ADIS16201_FLASH_CNT 0x00 /* Flash memory write count */
10#define ADIS16201_SUPPLY_OUT 0x02 /* Output, power supply */
11#define ADIS16201_XACCL_OUT 0x04 /* Output, x-axis accelerometer */
12#define ADIS16201_YACCL_OUT 0x06 /* Output, y-axis accelerometer */
13#define ADIS16201_AUX_ADC 0x08 /* Output, auxiliary ADC input */
14#define ADIS16201_TEMP_OUT 0x0A /* Output, temperature */
15#define ADIS16201_XINCL_OUT 0x0C /* Output, x-axis inclination */
16#define ADIS16201_YINCL_OUT 0x0E /* Output, y-axis inclination */
17#define ADIS16201_XACCL_OFFS 0x10 /* Calibration, x-axis acceleration offset */
18#define ADIS16201_YACCL_OFFS 0x12 /* Calibration, y-axis acceleration offset */
19#define ADIS16201_XACCL_SCALE 0x14 /* x-axis acceleration scale factor */
20#define ADIS16201_YACCL_SCALE 0x16 /* y-axis acceleration scale factor */
21#define ADIS16201_XINCL_OFFS 0x18 /* Calibration, x-axis inclination offset */
22#define ADIS16201_YINCL_OFFS 0x1A /* Calibration, y-axis inclination offset */
23#define ADIS16201_XINCL_SCALE 0x1C /* x-axis inclination scale factor */
24#define ADIS16201_YINCL_SCALE 0x1E /* y-axis inclination scale factor */
25#define ADIS16201_ALM_MAG1 0x20 /* Alarm 1 amplitude threshold */
26#define ADIS16201_ALM_MAG2 0x22 /* Alarm 2 amplitude threshold */
27#define ADIS16201_ALM_SMPL1 0x24 /* Alarm 1, sample period */
28#define ADIS16201_ALM_SMPL2 0x26 /* Alarm 2, sample period */
29#define ADIS16201_ALM_CTRL 0x28 /* Alarm control */
30#define ADIS16201_AUX_DAC 0x30 /* Auxiliary DAC data */
31#define ADIS16201_GPIO_CTRL 0x32 /* General-purpose digital input/output control */
32#define ADIS16201_MSC_CTRL 0x34 /* Miscellaneous control */
33#define ADIS16201_SMPL_PRD 0x36 /* Internal sample period (rate) control */
34#define ADIS16201_AVG_CNT 0x38 /* Operation, filter configuration */
35#define ADIS16201_SLP_CNT 0x3A /* Operation, sleep mode control */
36#define ADIS16201_DIAG_STAT 0x3C /* Diagnostics, system status register */
37#define ADIS16201_GLOB_CMD 0x3E /* Operation, system command register */
38
39#define ADIS16201_OUTPUTS 7
40
41/* MSC_CTRL */
42#define ADIS16201_MSC_CTRL_SELF_TEST_EN (1 << 8) /* Self-test enable */
43#define ADIS16201_MSC_CTRL_DATA_RDY_EN (1 << 2) /* Data-ready enable: 1 = enabled, 0 = disabled */
44#define ADIS16201_MSC_CTRL_ACTIVE_HIGH (1 << 1) /* Data-ready polarity: 1 = active high, 0 = active low */
45#define ADIS16201_MSC_CTRL_DATA_RDY_DIO1 (1 << 0) /* Data-ready line selection: 1 = DIO1, 0 = DIO0 */
46
47/* DIAG_STAT */
48#define ADIS16201_DIAG_STAT_ALARM2 (1<<9) /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */
49#define ADIS16201_DIAG_STAT_ALARM1 (1<<8) /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */
50#define ADIS16201_DIAG_STAT_SPI_FAIL (1<<3) /* SPI communications failure */
51#define ADIS16201_DIAG_STAT_FLASH_UPT (1<<2) /* Flash update failure */
52#define ADIS16201_DIAG_STAT_POWER_HIGH (1<<1) /* Power supply above 3.625 V */
53#define ADIS16201_DIAG_STAT_POWER_LOW (1<<0) /* Power supply below 3.15 V */
54
55/* GLOB_CMD */
56#define ADIS16201_GLOB_CMD_SW_RESET (1<<7)
57#define ADIS16201_GLOB_CMD_FACTORY_CAL (1<<1)
58
59#define ADIS16201_MAX_TX 14
60#define ADIS16201_MAX_RX 14
61
62#define ADIS16201_ERROR_ACTIVE (1<<14)
63
64/**
65 * struct adis16201_state - device instance specific data
66 * @us: actual spi_device
67 * @work_trigger_to_ring: bh for triggered event handling
68 * @inter: used to check if new interrupt has been triggered
69 * @last_timestamp: passing timestamp from th to bh of interrupt handler
70 * @indio_dev: industrial I/O device structure
71 * @trig: data ready trigger registered with iio
72 * @tx: transmit buffer
73 * @rx: recieve buffer
74 * @buf_lock: mutex to protect tx and rx
75 **/
76struct adis16201_state {
77 struct spi_device *us;
78 struct work_struct work_trigger_to_ring;
79 s64 last_timestamp;
80 struct iio_dev *indio_dev;
81 struct iio_trigger *trig;
82 u8 *tx;
83 u8 *rx;
84 struct mutex buf_lock;
85};
86
87int adis16201_set_irq(struct device *dev, bool enable);
88
89#ifdef CONFIG_IIO_RING_BUFFER
90enum adis16201_scan {
91 ADIS16201_SCAN_SUPPLY,
92 ADIS16201_SCAN_ACC_X,
93 ADIS16201_SCAN_ACC_Y,
94 ADIS16201_SCAN_AUX_ADC,
95 ADIS16201_SCAN_TEMP,
96 ADIS16201_SCAN_INCLI_X,
97 ADIS16201_SCAN_INCLI_Y,
98};
99
100void adis16201_remove_trigger(struct iio_dev *indio_dev);
101int adis16201_probe_trigger(struct iio_dev *indio_dev);
102
103ssize_t adis16201_read_data_from_ring(struct device *dev,
104 struct device_attribute *attr,
105 char *buf);
106
107int adis16201_configure_ring(struct iio_dev *indio_dev);
108void adis16201_unconfigure_ring(struct iio_dev *indio_dev);
109
110int adis16201_initialize_ring(struct iio_ring_buffer *ring);
111void adis16201_uninitialize_ring(struct iio_ring_buffer *ring);
112#else /* CONFIG_IIO_RING_BUFFER */
113
114static inline void adis16201_remove_trigger(struct iio_dev *indio_dev)
115{
116}
117
118static inline int adis16201_probe_trigger(struct iio_dev *indio_dev)
119{
120 return 0;
121}
122
123static inline ssize_t
124adis16201_read_data_from_ring(struct device *dev,
125 struct device_attribute *attr,
126 char *buf)
127{
128 return 0;
129}
130
131static int adis16201_configure_ring(struct iio_dev *indio_dev)
132{
133 return 0;
134}
135
136static inline void adis16201_unconfigure_ring(struct iio_dev *indio_dev)
137{
138}
139
140static inline int adis16201_initialize_ring(struct iio_ring_buffer *ring)
141{
142 return 0;
143}
144
145static inline void adis16201_uninitialize_ring(struct iio_ring_buffer *ring)
146{
147}
148
149#endif /* CONFIG_IIO_RING_BUFFER */
150#endif /* SPI_ADIS16201_H_ */
diff --git a/drivers/staging/iio/accel/adis16201_core.c b/drivers/staging/iio/accel/adis16201_core.c
new file mode 100644
index 000000000000..79b785a0013a
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16201_core.c
@@ -0,0 +1,659 @@
1/*
2 * ADIS16201 Programmable Digital Vibration Sensor driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "accel.h"
24#include "inclinometer.h"
25#include "../gyro/gyro.h"
26#include "../adc/adc.h"
27
28#include "adis16201.h"
29
30#define DRIVER_NAME "adis16201"
31
32static int adis16201_check_status(struct device *dev);
33
34/**
35 * adis16201_spi_write_reg_8() - write single byte to a register
36 * @dev: device associated with child of actual device (iio_dev or iio_trig)
37 * @reg_address: the address of the register to be written
38 * @val: the value to write
39 **/
40static int adis16201_spi_write_reg_8(struct device *dev,
41 u8 reg_address,
42 u8 val)
43{
44 int ret;
45 struct iio_dev *indio_dev = dev_get_drvdata(dev);
46 struct adis16201_state *st = iio_dev_get_devdata(indio_dev);
47
48 mutex_lock(&st->buf_lock);
49 st->tx[0] = ADIS16201_WRITE_REG(reg_address);
50 st->tx[1] = val;
51
52 ret = spi_write(st->us, st->tx, 2);
53 mutex_unlock(&st->buf_lock);
54
55 return ret;
56}
57
58/**
59 * adis16201_spi_write_reg_16() - write 2 bytes to a pair of registers
60 * @dev: device associated with child of actual device (iio_dev or iio_trig)
61 * @reg_address: the address of the lower of the two registers. Second register
62 * is assumed to have address one greater.
63 * @val: value to be written
64 **/
65static int adis16201_spi_write_reg_16(struct device *dev,
66 u8 lower_reg_address,
67 u16 value)
68{
69 int ret;
70 struct spi_message msg;
71 struct iio_dev *indio_dev = dev_get_drvdata(dev);
72 struct adis16201_state *st = iio_dev_get_devdata(indio_dev);
73 struct spi_transfer xfers[] = {
74 {
75 .tx_buf = st->tx,
76 .bits_per_word = 8,
77 .len = 2,
78 .cs_change = 1,
79 }, {
80 .tx_buf = st->tx + 2,
81 .bits_per_word = 8,
82 .len = 2,
83 .cs_change = 1,
84 },
85 };
86
87 mutex_lock(&st->buf_lock);
88 st->tx[0] = ADIS16201_WRITE_REG(lower_reg_address);
89 st->tx[1] = value & 0xFF;
90 st->tx[2] = ADIS16201_WRITE_REG(lower_reg_address + 1);
91 st->tx[3] = (value >> 8) & 0xFF;
92
93 spi_message_init(&msg);
94 spi_message_add_tail(&xfers[0], &msg);
95 spi_message_add_tail(&xfers[1], &msg);
96 ret = spi_sync(st->us, &msg);
97 mutex_unlock(&st->buf_lock);
98
99 return ret;
100}
101
102/**
103 * adis16201_spi_read_reg_16() - read 2 bytes from a 16-bit register
104 * @dev: device associated with child of actual device (iio_dev or iio_trig)
105 * @reg_address: the address of the lower of the two registers. Second register
106 * is assumed to have address one greater.
107 * @val: somewhere to pass back the value read
108 **/
109static int adis16201_spi_read_reg_16(struct device *dev,
110 u8 lower_reg_address,
111 u16 *val)
112{
113 struct spi_message msg;
114 struct iio_dev *indio_dev = dev_get_drvdata(dev);
115 struct adis16201_state *st = iio_dev_get_devdata(indio_dev);
116 int ret;
117 struct spi_transfer xfers[] = {
118 {
119 .tx_buf = st->tx,
120 .bits_per_word = 8,
121 .len = 2,
122 .cs_change = 1,
123 .delay_usecs = 20,
124 }, {
125 .rx_buf = st->rx,
126 .bits_per_word = 8,
127 .len = 2,
128 .cs_change = 1,
129 .delay_usecs = 20,
130 },
131 };
132
133 mutex_lock(&st->buf_lock);
134 st->tx[0] = ADIS16201_READ_REG(lower_reg_address);
135 st->tx[1] = 0;
136
137 spi_message_init(&msg);
138 spi_message_add_tail(&xfers[0], &msg);
139 spi_message_add_tail(&xfers[1], &msg);
140 ret = spi_sync(st->us, &msg);
141 if (ret) {
142 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
143 lower_reg_address);
144 goto error_ret;
145 }
146 *val = (st->rx[0] << 8) | st->rx[1];
147
148error_ret:
149 mutex_unlock(&st->buf_lock);
150 return ret;
151}
152
153static ssize_t adis16201_read_12bit_unsigned(struct device *dev,
154 struct device_attribute *attr,
155 char *buf)
156{
157 int ret;
158 u16 val = 0;
159 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
160
161 ret = adis16201_spi_read_reg_16(dev, this_attr->address, &val);
162 if (ret)
163 return ret;
164
165 if (val & ADIS16201_ERROR_ACTIVE) {
166 ret = adis16201_check_status(dev);
167 if (ret)
168 return ret;
169 }
170
171 return sprintf(buf, "%u\n", val & 0x0FFF);
172}
173
174static ssize_t adis16201_read_temp(struct device *dev,
175 struct device_attribute *attr,
176 char *buf)
177{
178 struct iio_dev *indio_dev = dev_get_drvdata(dev);
179 ssize_t ret;
180 u16 val;
181
182 /* Take the iio_dev status lock */
183 mutex_lock(&indio_dev->mlock);
184
185 ret = adis16201_spi_read_reg_16(dev, ADIS16201_TEMP_OUT, (u16 *)&val);
186 if (ret)
187 goto error_ret;
188
189 if (val & ADIS16201_ERROR_ACTIVE) {
190 ret = adis16201_check_status(dev);
191 if (ret)
192 goto error_ret;
193 }
194
195 val &= 0xFFF;
196 ret = sprintf(buf, "%d\n", val);
197
198error_ret:
199 mutex_unlock(&indio_dev->mlock);
200 return ret;
201}
202
203static ssize_t adis16201_read_9bit_signed(struct device *dev,
204 struct device_attribute *attr,
205 char *buf)
206{
207 struct iio_dev *indio_dev = dev_get_drvdata(dev);
208 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
209 s16 val = 0;
210 ssize_t ret;
211
212 mutex_lock(&indio_dev->mlock);
213
214 ret = adis16201_spi_read_reg_16(dev, this_attr->address, (u16 *)&val);
215 if (!ret) {
216 if (val & ADIS16201_ERROR_ACTIVE) {
217 ret = adis16201_check_status(dev);
218 if (ret)
219 goto error_ret;
220 }
221 val = ((s16)(val << 7) >> 7);
222 ret = sprintf(buf, "%d\n", val);
223 }
224
225error_ret:
226 mutex_unlock(&indio_dev->mlock);
227
228 return ret;
229}
230
231static ssize_t adis16201_read_12bit_signed(struct device *dev,
232 struct device_attribute *attr,
233 char *buf)
234{
235 struct iio_dev *indio_dev = dev_get_drvdata(dev);
236 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
237 s16 val = 0;
238 ssize_t ret;
239
240 mutex_lock(&indio_dev->mlock);
241
242 ret = adis16201_spi_read_reg_16(dev, this_attr->address, (u16 *)&val);
243 if (!ret) {
244 if (val & ADIS16201_ERROR_ACTIVE) {
245 ret = adis16201_check_status(dev);
246 if (ret)
247 goto error_ret;
248 }
249
250 val = ((s16)(val << 4) >> 4);
251 ret = sprintf(buf, "%d\n", val);
252 }
253
254error_ret:
255 mutex_unlock(&indio_dev->mlock);
256
257 return ret;
258}
259
260static ssize_t adis16201_read_14bit_signed(struct device *dev,
261 struct device_attribute *attr,
262 char *buf)
263{
264 struct iio_dev *indio_dev = dev_get_drvdata(dev);
265 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
266 s16 val = 0;
267 ssize_t ret;
268
269 mutex_lock(&indio_dev->mlock);
270
271 ret = adis16201_spi_read_reg_16(dev, this_attr->address, (u16 *)&val);
272 if (!ret) {
273 if (val & ADIS16201_ERROR_ACTIVE) {
274 ret = adis16201_check_status(dev);
275 if (ret)
276 goto error_ret;
277 }
278
279 val = ((s16)(val << 2) >> 2);
280 ret = sprintf(buf, "%d\n", val);
281 }
282
283error_ret:
284 mutex_unlock(&indio_dev->mlock);
285
286 return ret;
287}
288
289static ssize_t adis16201_write_16bit(struct device *dev,
290 struct device_attribute *attr,
291 const char *buf,
292 size_t len)
293{
294 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
295 int ret;
296 long val;
297
298 ret = strict_strtol(buf, 10, &val);
299 if (ret)
300 goto error_ret;
301 ret = adis16201_spi_write_reg_16(dev, this_attr->address, val);
302
303error_ret:
304 return ret ? ret : len;
305}
306
307static int adis16201_reset(struct device *dev)
308{
309 int ret;
310 ret = adis16201_spi_write_reg_8(dev,
311 ADIS16201_GLOB_CMD,
312 ADIS16201_GLOB_CMD_SW_RESET);
313 if (ret)
314 dev_err(dev, "problem resetting device");
315
316 return ret;
317}
318
319static ssize_t adis16201_write_reset(struct device *dev,
320 struct device_attribute *attr,
321 const char *buf, size_t len)
322{
323 if (len < 1)
324 return -EINVAL;
325 switch (buf[0]) {
326 case '1':
327 case 'y':
328 case 'Y':
329 return adis16201_reset(dev);
330 }
331 return -EINVAL;
332}
333
334int adis16201_set_irq(struct device *dev, bool enable)
335{
336 int ret = 0;
337 u16 msc;
338
339 ret = adis16201_spi_read_reg_16(dev, ADIS16201_MSC_CTRL, &msc);
340 if (ret)
341 goto error_ret;
342
343 msc |= ADIS16201_MSC_CTRL_ACTIVE_HIGH;
344 msc &= ~ADIS16201_MSC_CTRL_DATA_RDY_DIO1;
345 if (enable)
346 msc |= ADIS16201_MSC_CTRL_DATA_RDY_EN;
347 else
348 msc &= ~ADIS16201_MSC_CTRL_DATA_RDY_EN;
349
350 ret = adis16201_spi_write_reg_16(dev, ADIS16201_MSC_CTRL, msc);
351
352error_ret:
353 return ret;
354}
355
356static int adis16201_check_status(struct device *dev)
357{
358 u16 status;
359 int ret;
360
361 ret = adis16201_spi_read_reg_16(dev, ADIS16201_DIAG_STAT, &status);
362 if (ret < 0) {
363 dev_err(dev, "Reading status failed\n");
364 goto error_ret;
365 }
366 ret = status & 0xF;
367 if (ret)
368 ret = -EFAULT;
369
370 if (status & ADIS16201_DIAG_STAT_SPI_FAIL)
371 dev_err(dev, "SPI failure\n");
372 if (status & ADIS16201_DIAG_STAT_FLASH_UPT)
373 dev_err(dev, "Flash update failed\n");
374 if (status & ADIS16201_DIAG_STAT_POWER_HIGH)
375 dev_err(dev, "Power supply above 3.625V\n");
376 if (status & ADIS16201_DIAG_STAT_POWER_LOW)
377 dev_err(dev, "Power supply below 3.15V\n");
378
379error_ret:
380 return ret;
381}
382
383static int adis16201_self_test(struct device *dev)
384{
385 int ret;
386 ret = adis16201_spi_write_reg_16(dev,
387 ADIS16201_MSC_CTRL,
388 ADIS16201_MSC_CTRL_SELF_TEST_EN);
389 if (ret) {
390 dev_err(dev, "problem starting self test");
391 goto err_ret;
392 }
393
394 ret = adis16201_check_status(dev);
395
396err_ret:
397 return ret;
398}
399
400static int adis16201_initial_setup(struct adis16201_state *st)
401{
402 int ret;
403 struct device *dev = &st->indio_dev->dev;
404
405 /* Disable IRQ */
406 ret = adis16201_set_irq(dev, false);
407 if (ret) {
408 dev_err(dev, "disable irq failed");
409 goto err_ret;
410 }
411
412 /* Do self test */
413 ret = adis16201_self_test(dev);
414 if (ret) {
415 dev_err(dev, "self test failure");
416 goto err_ret;
417 }
418
419 /* Read status register to check the result */
420 ret = adis16201_check_status(dev);
421 if (ret) {
422 adis16201_reset(dev);
423 dev_err(dev, "device not playing ball -> reset");
424 msleep(ADIS16201_STARTUP_DELAY);
425 ret = adis16201_check_status(dev);
426 if (ret) {
427 dev_err(dev, "giving up");
428 goto err_ret;
429 }
430 }
431
432 printk(KERN_INFO DRIVER_NAME ": at CS%d (irq %d)\n",
433 st->us->chip_select, st->us->irq);
434
435err_ret:
436 return ret;
437}
438
439static IIO_DEV_ATTR_IN_NAMED_RAW(0, supply, adis16201_read_12bit_unsigned,
440 ADIS16201_SUPPLY_OUT);
441static IIO_CONST_ATTR(in0_supply_scale, "0.00122");
442static IIO_DEV_ATTR_IN_RAW(1, adis16201_read_12bit_unsigned,
443 ADIS16201_AUX_ADC);
444static IIO_CONST_ATTR(in1_scale, "0.00061");
445
446static IIO_DEV_ATTR_ACCEL_X(adis16201_read_14bit_signed,
447 ADIS16201_XACCL_OUT);
448static IIO_DEV_ATTR_ACCEL_Y(adis16201_read_14bit_signed,
449 ADIS16201_YACCL_OUT);
450static IIO_DEV_ATTR_ACCEL_X_OFFSET(S_IWUSR | S_IRUGO,
451 adis16201_read_12bit_signed,
452 adis16201_write_16bit,
453 ADIS16201_XACCL_OFFS);
454static IIO_DEV_ATTR_ACCEL_Y_OFFSET(S_IWUSR | S_IRUGO,
455 adis16201_read_12bit_signed,
456 adis16201_write_16bit,
457 ADIS16201_YACCL_OFFS);
458static IIO_CONST_ATTR(accel_scale, "0.4625");
459
460static IIO_DEV_ATTR_INCLI_X(adis16201_read_14bit_signed,
461 ADIS16201_XINCL_OUT);
462static IIO_DEV_ATTR_INCLI_Y(adis16201_read_14bit_signed,
463 ADIS16201_YINCL_OUT);
464static IIO_DEV_ATTR_INCLI_X_OFFSET(S_IWUSR | S_IRUGO,
465 adis16201_read_9bit_signed,
466 adis16201_write_16bit,
467 ADIS16201_XACCL_OFFS);
468static IIO_DEV_ATTR_INCLI_Y_OFFSET(S_IWUSR | S_IRUGO,
469 adis16201_read_9bit_signed,
470 adis16201_write_16bit,
471 ADIS16201_YACCL_OFFS);
472static IIO_CONST_ATTR(incli_scale, "0.1");
473
474static IIO_DEV_ATTR_TEMP_RAW(adis16201_read_temp);
475static IIO_CONST_ATTR(temp_offset, "25");
476static IIO_CONST_ATTR(temp_scale, "-0.47");
477
478static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, adis16201_write_reset, 0);
479
480static IIO_CONST_ATTR(name, "adis16201");
481
482static struct attribute *adis16201_event_attributes[] = {
483 NULL
484};
485
486static struct attribute_group adis16201_event_attribute_group = {
487 .attrs = adis16201_event_attributes,
488};
489
490static struct attribute *adis16201_attributes[] = {
491 &iio_dev_attr_in0_supply_raw.dev_attr.attr,
492 &iio_const_attr_in0_supply_scale.dev_attr.attr,
493 &iio_dev_attr_temp_raw.dev_attr.attr,
494 &iio_const_attr_temp_offset.dev_attr.attr,
495 &iio_const_attr_temp_scale.dev_attr.attr,
496 &iio_dev_attr_reset.dev_attr.attr,
497 &iio_const_attr_name.dev_attr.attr,
498 &iio_dev_attr_in1_raw.dev_attr.attr,
499 &iio_const_attr_in1_scale.dev_attr.attr,
500 &iio_dev_attr_accel_x_raw.dev_attr.attr,
501 &iio_dev_attr_accel_y_raw.dev_attr.attr,
502 &iio_dev_attr_accel_x_offset.dev_attr.attr,
503 &iio_dev_attr_accel_y_offset.dev_attr.attr,
504 &iio_const_attr_accel_scale.dev_attr.attr,
505 &iio_dev_attr_incli_x_raw.dev_attr.attr,
506 &iio_dev_attr_incli_y_raw.dev_attr.attr,
507 &iio_dev_attr_incli_x_offset.dev_attr.attr,
508 &iio_dev_attr_incli_y_offset.dev_attr.attr,
509 &iio_const_attr_incli_scale.dev_attr.attr,
510 NULL
511};
512
513static const struct attribute_group adis16201_attribute_group = {
514 .attrs = adis16201_attributes,
515};
516
517static int __devinit adis16201_probe(struct spi_device *spi)
518{
519 int ret, regdone = 0;
520 struct adis16201_state *st = kzalloc(sizeof *st, GFP_KERNEL);
521 if (!st) {
522 ret = -ENOMEM;
523 goto error_ret;
524 }
525 /* this is only used for removal purposes */
526 spi_set_drvdata(spi, st);
527
528 /* Allocate the comms buffers */
529 st->rx = kzalloc(sizeof(*st->rx)*ADIS16201_MAX_RX, GFP_KERNEL);
530 if (st->rx == NULL) {
531 ret = -ENOMEM;
532 goto error_free_st;
533 }
534 st->tx = kzalloc(sizeof(*st->tx)*ADIS16201_MAX_TX, GFP_KERNEL);
535 if (st->tx == NULL) {
536 ret = -ENOMEM;
537 goto error_free_rx;
538 }
539 st->us = spi;
540 mutex_init(&st->buf_lock);
541 /* setup the industrialio driver allocated elements */
542 st->indio_dev = iio_allocate_device();
543 if (st->indio_dev == NULL) {
544 ret = -ENOMEM;
545 goto error_free_tx;
546 }
547
548 st->indio_dev->dev.parent = &spi->dev;
549 st->indio_dev->num_interrupt_lines = 1;
550 st->indio_dev->event_attrs = &adis16201_event_attribute_group;
551 st->indio_dev->attrs = &adis16201_attribute_group;
552 st->indio_dev->dev_data = (void *)(st);
553 st->indio_dev->driver_module = THIS_MODULE;
554 st->indio_dev->modes = INDIO_DIRECT_MODE;
555
556 ret = adis16201_configure_ring(st->indio_dev);
557 if (ret)
558 goto error_free_dev;
559
560 ret = iio_device_register(st->indio_dev);
561 if (ret)
562 goto error_unreg_ring_funcs;
563 regdone = 1;
564
565 ret = adis16201_initialize_ring(st->indio_dev->ring);
566 if (ret) {
567 printk(KERN_ERR "failed to initialize the ring\n");
568 goto error_unreg_ring_funcs;
569 }
570
571 if (spi->irq) {
572 ret = iio_register_interrupt_line(spi->irq,
573 st->indio_dev,
574 0,
575 IRQF_TRIGGER_RISING,
576 "adis16201");
577 if (ret)
578 goto error_uninitialize_ring;
579
580 ret = adis16201_probe_trigger(st->indio_dev);
581 if (ret)
582 goto error_unregister_line;
583 }
584
585 /* Get the device into a sane initial state */
586 ret = adis16201_initial_setup(st);
587 if (ret)
588 goto error_remove_trigger;
589 return 0;
590
591error_remove_trigger:
592 adis16201_remove_trigger(st->indio_dev);
593error_unregister_line:
594 if (spi->irq)
595 iio_unregister_interrupt_line(st->indio_dev, 0);
596error_uninitialize_ring:
597 adis16201_uninitialize_ring(st->indio_dev->ring);
598error_unreg_ring_funcs:
599 adis16201_unconfigure_ring(st->indio_dev);
600error_free_dev:
601 if (regdone)
602 iio_device_unregister(st->indio_dev);
603 else
604 iio_free_device(st->indio_dev);
605error_free_tx:
606 kfree(st->tx);
607error_free_rx:
608 kfree(st->rx);
609error_free_st:
610 kfree(st);
611error_ret:
612 return ret;
613}
614
615static int adis16201_remove(struct spi_device *spi)
616{
617 struct adis16201_state *st = spi_get_drvdata(spi);
618 struct iio_dev *indio_dev = st->indio_dev;
619
620 flush_scheduled_work();
621
622 adis16201_remove_trigger(indio_dev);
623 if (spi->irq)
624 iio_unregister_interrupt_line(indio_dev, 0);
625
626 adis16201_uninitialize_ring(indio_dev->ring);
627 iio_device_unregister(indio_dev);
628 adis16201_unconfigure_ring(indio_dev);
629 kfree(st->tx);
630 kfree(st->rx);
631 kfree(st);
632
633 return 0;
634}
635
636static struct spi_driver adis16201_driver = {
637 .driver = {
638 .name = "adis16201",
639 .owner = THIS_MODULE,
640 },
641 .probe = adis16201_probe,
642 .remove = __devexit_p(adis16201_remove),
643};
644
645static __init int adis16201_init(void)
646{
647 return spi_register_driver(&adis16201_driver);
648}
649module_init(adis16201_init);
650
651static __exit void adis16201_exit(void)
652{
653 spi_unregister_driver(&adis16201_driver);
654}
655module_exit(adis16201_exit);
656
657MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
658MODULE_DESCRIPTION("Analog Devices ADIS16201 Programmable Digital Vibration Sensor driver");
659MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c
new file mode 100644
index 000000000000..e6870a2721f1
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16201_ring.c
@@ -0,0 +1,218 @@
1#include <linux/interrupt.h>
2#include <linux/irq.h>
3#include <linux/gpio.h>
4#include <linux/workqueue.h>
5#include <linux/mutex.h>
6#include <linux/device.h>
7#include <linux/kernel.h>
8#include <linux/spi/spi.h>
9#include <linux/slab.h>
10#include <linux/sysfs.h>
11#include <linux/list.h>
12
13#include "../iio.h"
14#include "../sysfs.h"
15#include "../ring_sw.h"
16#include "accel.h"
17#include "../trigger.h"
18#include "adis16201.h"
19
20static IIO_SCAN_EL_C(in_supply, ADIS16201_SCAN_SUPPLY, ADIS16201_SUPPLY_OUT, NULL);
21static IIO_CONST_ATTR_SCAN_EL_TYPE(in_supply, u, 12, 16);
22static IIO_SCAN_EL_C(accel_x, ADIS16201_SCAN_ACC_X, ADIS16201_XACCL_OUT, NULL);
23static IIO_SCAN_EL_C(accel_y, ADIS16201_SCAN_ACC_Y, ADIS16201_YACCL_OUT, NULL);
24static IIO_CONST_ATTR_SCAN_EL_TYPE(accel, s, 14, 16);
25static IIO_SCAN_EL_C(in0, ADIS16201_SCAN_AUX_ADC, ADIS16201_AUX_ADC, NULL);
26static IIO_CONST_ATTR_SCAN_EL_TYPE(in0, u, 12, 16);
27static IIO_SCAN_EL_C(temp, ADIS16201_SCAN_TEMP, ADIS16201_TEMP_OUT, NULL);
28static IIO_CONST_ATTR_SCAN_EL_TYPE(temp, u, 12, 16);
29static IIO_SCAN_EL_C(incli_x, ADIS16201_SCAN_INCLI_X,
30 ADIS16201_XINCL_OUT, NULL);
31static IIO_SCAN_EL_C(incli_y, ADIS16201_SCAN_INCLI_Y,
32 ADIS16201_YINCL_OUT, NULL);
33static IIO_CONST_ATTR_SCAN_EL_TYPE(incli, s, 14, 16);
34static IIO_SCAN_EL_TIMESTAMP(7);
35static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
36
37static struct attribute *adis16201_scan_el_attrs[] = {
38 &iio_scan_el_in_supply.dev_attr.attr,
39 &iio_const_attr_in_supply_index.dev_attr.attr,
40 &iio_const_attr_in_supply_type.dev_attr.attr,
41 &iio_scan_el_accel_x.dev_attr.attr,
42 &iio_const_attr_accel_x_index.dev_attr.attr,
43 &iio_scan_el_accel_y.dev_attr.attr,
44 &iio_const_attr_accel_y_index.dev_attr.attr,
45 &iio_const_attr_accel_type.dev_attr.attr,
46 &iio_scan_el_in0.dev_attr.attr,
47 &iio_const_attr_in0_index.dev_attr.attr,
48 &iio_const_attr_in0_type.dev_attr.attr,
49 &iio_scan_el_temp.dev_attr.attr,
50 &iio_const_attr_temp_index.dev_attr.attr,
51 &iio_const_attr_temp_type.dev_attr.attr,
52 &iio_scan_el_incli_x.dev_attr.attr,
53 &iio_const_attr_incli_x_index.dev_attr.attr,
54 &iio_scan_el_incli_y.dev_attr.attr,
55 &iio_const_attr_incli_y_index.dev_attr.attr,
56 &iio_const_attr_incli_type.dev_attr.attr,
57 &iio_scan_el_timestamp.dev_attr.attr,
58 &iio_const_attr_timestamp_index.dev_attr.attr,
59 &iio_const_attr_timestamp_type.dev_attr.attr,
60 NULL,
61};
62
63static struct attribute_group adis16201_scan_el_group = {
64 .attrs = adis16201_scan_el_attrs,
65 .name = "scan_elements",
66};
67
68/**
69 * adis16201_poll_func_th() top half interrupt handler called by trigger
70 * @private_data: iio_dev
71 **/
72static void adis16201_poll_func_th(struct iio_dev *indio_dev, s64 time)
73{
74 struct adis16201_state *st = iio_dev_get_devdata(indio_dev);
75 st->last_timestamp = time;
76 schedule_work(&st->work_trigger_to_ring);
77}
78
79/**
80 * adis16201_read_ring_data() read data registers which will be placed into ring
81 * @dev: device associated with child of actual device (iio_dev or iio_trig)
82 * @rx: somewhere to pass back the value read
83 **/
84static int adis16201_read_ring_data(struct device *dev, u8 *rx)
85{
86 struct spi_message msg;
87 struct iio_dev *indio_dev = dev_get_drvdata(dev);
88 struct adis16201_state *st = iio_dev_get_devdata(indio_dev);
89 struct spi_transfer xfers[ADIS16201_OUTPUTS + 1];
90 int ret;
91 int i;
92
93 mutex_lock(&st->buf_lock);
94
95 spi_message_init(&msg);
96
97 memset(xfers, 0, sizeof(xfers));
98 for (i = 0; i <= ADIS16201_OUTPUTS; i++) {
99 xfers[i].bits_per_word = 8;
100 xfers[i].cs_change = 1;
101 xfers[i].len = 2;
102 xfers[i].delay_usecs = 20;
103 xfers[i].tx_buf = st->tx + 2 * i;
104 st->tx[2 * i] = ADIS16201_READ_REG(ADIS16201_SUPPLY_OUT + 2 * i);
105 st->tx[2 * i + 1] = 0;
106 if (i >= 1)
107 xfers[i].rx_buf = rx + 2 * (i - 1);
108 spi_message_add_tail(&xfers[i], &msg);
109 }
110
111 ret = spi_sync(st->us, &msg);
112 if (ret)
113 dev_err(&st->us->dev, "problem when burst reading");
114
115 mutex_unlock(&st->buf_lock);
116
117 return ret;
118}
119
120/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
121 * specific to be rolled into the core.
122 */
123static void adis16201_trigger_bh_to_ring(struct work_struct *work_s)
124{
125 struct adis16201_state *st
126 = container_of(work_s, struct adis16201_state,
127 work_trigger_to_ring);
128 struct iio_ring_buffer *ring = st->indio_dev->ring;
129
130 int i = 0;
131 s16 *data;
132 size_t datasize = ring->access.get_bytes_per_datum(ring);
133
134 data = kmalloc(datasize, GFP_KERNEL);
135 if (data == NULL) {
136 dev_err(&st->us->dev, "memory alloc failed in ring bh");
137 return;
138 }
139
140 if (ring->scan_count)
141 if (adis16201_read_ring_data(&st->indio_dev->dev, st->rx) >= 0)
142 for (; i < ring->scan_count; i++)
143 data[i] = be16_to_cpup(
144 (__be16 *)&(st->rx[i*2]));
145
146 /* Guaranteed to be aligned with 8 byte boundary */
147 if (ring->scan_timestamp)
148 *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp;
149
150 ring->access.store_to(ring,
151 (u8 *)data,
152 st->last_timestamp);
153
154 iio_trigger_notify_done(st->indio_dev->trig);
155 kfree(data);
156
157 return;
158}
159
160void adis16201_unconfigure_ring(struct iio_dev *indio_dev)
161{
162 kfree(indio_dev->pollfunc);
163 iio_sw_rb_free(indio_dev->ring);
164}
165
166int adis16201_configure_ring(struct iio_dev *indio_dev)
167{
168 int ret = 0;
169 struct adis16201_state *st = indio_dev->dev_data;
170 struct iio_ring_buffer *ring;
171 INIT_WORK(&st->work_trigger_to_ring, adis16201_trigger_bh_to_ring);
172
173 ring = iio_sw_rb_allocate(indio_dev);
174 if (!ring) {
175 ret = -ENOMEM;
176 return ret;
177 }
178 indio_dev->ring = ring;
179 /* Effectively select the ring buffer implementation */
180 iio_ring_sw_register_funcs(&ring->access);
181 ring->bpe = 2;
182 ring->scan_el_attrs = &adis16201_scan_el_group;
183 ring->scan_timestamp = true;
184 ring->preenable = &iio_sw_ring_preenable;
185 ring->postenable = &iio_triggered_ring_postenable;
186 ring->predisable = &iio_triggered_ring_predisable;
187 ring->owner = THIS_MODULE;
188
189 /* Set default scan mode */
190 iio_scan_mask_set(ring, iio_scan_el_in_supply.number);
191 iio_scan_mask_set(ring, iio_scan_el_accel_x.number);
192 iio_scan_mask_set(ring, iio_scan_el_accel_y.number);
193 iio_scan_mask_set(ring, iio_scan_el_temp.number);
194 iio_scan_mask_set(ring, iio_scan_el_in0.number);
195 iio_scan_mask_set(ring, iio_scan_el_incli_x.number);
196 iio_scan_mask_set(ring, iio_scan_el_incli_y.number);
197
198 ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16201_poll_func_th);
199 if (ret)
200 goto error_iio_sw_rb_free;
201
202 indio_dev->modes |= INDIO_RING_TRIGGERED;
203 return 0;
204
205error_iio_sw_rb_free:
206 iio_sw_rb_free(indio_dev->ring);
207 return ret;
208}
209
210int adis16201_initialize_ring(struct iio_ring_buffer *ring)
211{
212 return iio_ring_buffer_register(ring, 0);
213}
214
215void adis16201_uninitialize_ring(struct iio_ring_buffer *ring)
216{
217 iio_ring_buffer_unregister(ring);
218}
diff --git a/drivers/staging/iio/accel/adis16201_trigger.c b/drivers/staging/iio/accel/adis16201_trigger.c
new file mode 100644
index 000000000000..8a9cea1986e7
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16201_trigger.c
@@ -0,0 +1,122 @@
1#include <linux/interrupt.h>
2#include <linux/irq.h>
3#include <linux/mutex.h>
4#include <linux/device.h>
5#include <linux/kernel.h>
6#include <linux/sysfs.h>
7#include <linux/list.h>
8#include <linux/spi/spi.h>
9
10#include "../iio.h"
11#include "../sysfs.h"
12#include "../trigger.h"
13#include "adis16201.h"
14
15/**
16 * adis16201_data_rdy_trig_poll() the event handler for the data rdy trig
17 **/
18static int adis16201_data_rdy_trig_poll(struct iio_dev *dev_info,
19 int index,
20 s64 timestamp,
21 int no_test)
22{
23 struct adis16201_state *st = iio_dev_get_devdata(dev_info);
24 struct iio_trigger *trig = st->trig;
25
26 iio_trigger_poll(trig, timestamp);
27
28 return IRQ_HANDLED;
29}
30
31IIO_EVENT_SH(data_rdy_trig, &adis16201_data_rdy_trig_poll);
32
33static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);
34
35static struct attribute *adis16201_trigger_attrs[] = {
36 &dev_attr_name.attr,
37 NULL,
38};
39
40static const struct attribute_group adis16201_trigger_attr_group = {
41 .attrs = adis16201_trigger_attrs,
42};
43
44/**
45 * adis16201_data_rdy_trigger_set_state() set datardy interrupt state
46 **/
47static int adis16201_data_rdy_trigger_set_state(struct iio_trigger *trig,
48 bool state)
49{
50 struct adis16201_state *st = trig->private_data;
51 struct iio_dev *indio_dev = st->indio_dev;
52 int ret = 0;
53
54 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
55 ret = adis16201_set_irq(&st->indio_dev->dev, state);
56 if (state == false) {
57 iio_remove_event_from_list(&iio_event_data_rdy_trig,
58 &indio_dev->interrupts[0]
59 ->ev_list);
60 flush_scheduled_work();
61 } else {
62 iio_add_event_to_list(&iio_event_data_rdy_trig,
63 &indio_dev->interrupts[0]->ev_list);
64 }
65 return ret;
66}
67
68/**
69 * adis16201_trig_try_reen() try renabling irq for data rdy trigger
70 * @trig: the datardy trigger
71 **/
72static int adis16201_trig_try_reen(struct iio_trigger *trig)
73{
74 struct adis16201_state *st = trig->private_data;
75 enable_irq(st->us->irq);
76 return 0;
77}
78
79int adis16201_probe_trigger(struct iio_dev *indio_dev)
80{
81 int ret;
82 struct adis16201_state *st = indio_dev->dev_data;
83
84 st->trig = iio_allocate_trigger();
85 st->trig->name = kasprintf(GFP_KERNEL,
86 "adis16201-dev%d",
87 indio_dev->id);
88 if (!st->trig->name) {
89 ret = -ENOMEM;
90 goto error_free_trig;
91 }
92 st->trig->dev.parent = &st->us->dev;
93 st->trig->owner = THIS_MODULE;
94 st->trig->private_data = st;
95 st->trig->set_trigger_state = &adis16201_data_rdy_trigger_set_state;
96 st->trig->try_reenable = &adis16201_trig_try_reen;
97 st->trig->control_attrs = &adis16201_trigger_attr_group;
98 ret = iio_trigger_register(st->trig);
99
100 /* select default trigger */
101 indio_dev->trig = st->trig;
102 if (ret)
103 goto error_free_trig_name;
104
105 return 0;
106
107error_free_trig_name:
108 kfree(st->trig->name);
109error_free_trig:
110 iio_free_trigger(st->trig);
111
112 return ret;
113}
114
115void adis16201_remove_trigger(struct iio_dev *indio_dev)
116{
117 struct adis16201_state *state = indio_dev->dev_data;
118
119 iio_trigger_unregister(state->trig);
120 kfree(state->trig->name);
121 iio_free_trigger(state->trig);
122}
diff --git a/drivers/staging/iio/accel/adis16203.h b/drivers/staging/iio/accel/adis16203.h
new file mode 100644
index 000000000000..b39323eac9e3
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16203.h
@@ -0,0 +1,143 @@
1#ifndef SPI_ADIS16203_H_
2#define SPI_ADIS16203_H_
3
4#define ADIS16203_STARTUP_DELAY 220 /* ms */
5
6#define ADIS16203_READ_REG(a) a
7#define ADIS16203_WRITE_REG(a) ((a) | 0x80)
8
9#define ADIS16203_FLASH_CNT 0x00 /* Flash memory write count */
10#define ADIS16203_SUPPLY_OUT 0x02 /* Output, power supply */
11#define ADIS16203_AUX_ADC 0x08 /* Output, auxiliary ADC input */
12#define ADIS16203_TEMP_OUT 0x0A /* Output, temperature */
13#define ADIS16203_XINCL_OUT 0x0C /* Output, x-axis inclination */
14#define ADIS16203_YINCL_OUT 0x0E /* Output, y-axis inclination */
15#define ADIS16203_INCL_NULL 0x18 /* Incline null calibration */
16#define ADIS16203_ALM_MAG1 0x20 /* Alarm 1 amplitude threshold */
17#define ADIS16203_ALM_MAG2 0x22 /* Alarm 2 amplitude threshold */
18#define ADIS16203_ALM_SMPL1 0x24 /* Alarm 1, sample period */
19#define ADIS16203_ALM_SMPL2 0x26 /* Alarm 2, sample period */
20#define ADIS16203_ALM_CTRL 0x28 /* Alarm control */
21#define ADIS16203_AUX_DAC 0x30 /* Auxiliary DAC data */
22#define ADIS16203_GPIO_CTRL 0x32 /* General-purpose digital input/output control */
23#define ADIS16203_MSC_CTRL 0x34 /* Miscellaneous control */
24#define ADIS16203_SMPL_PRD 0x36 /* Internal sample period (rate) control */
25#define ADIS16203_AVG_CNT 0x38 /* Operation, filter configuration */
26#define ADIS16203_SLP_CNT 0x3A /* Operation, sleep mode control */
27#define ADIS16203_DIAG_STAT 0x3C /* Diagnostics, system status register */
28#define ADIS16203_GLOB_CMD 0x3E /* Operation, system command register */
29
30#define ADIS16203_OUTPUTS 5
31
32/* MSC_CTRL */
33#define ADIS16203_MSC_CTRL_PWRUP_SELF_TEST (1 << 10) /* Self-test at power-on: 1 = disabled, 0 = enabled */
34#define ADIS16203_MSC_CTRL_REVERSE_ROT_EN (1 << 9) /* Reverses rotation of both inclination outputs */
35#define ADIS16203_MSC_CTRL_SELF_TEST_EN (1 << 8) /* Self-test enable */
36#define ADIS16203_MSC_CTRL_DATA_RDY_EN (1 << 2) /* Data-ready enable: 1 = enabled, 0 = disabled */
37#define ADIS16203_MSC_CTRL_ACTIVE_HIGH (1 << 1) /* Data-ready polarity: 1 = active high, 0 = active low */
38#define ADIS16203_MSC_CTRL_DATA_RDY_DIO1 (1 << 0) /* Data-ready line selection: 1 = DIO1, 0 = DIO0 */
39
40/* DIAG_STAT */
41#define ADIS16203_DIAG_STAT_ALARM2 (1<<9) /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */
42#define ADIS16203_DIAG_STAT_ALARM1 (1<<8) /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */
43#define ADIS16203_DIAG_STAT_SELFTEST_FAIL (1<<5) /* Self-test diagnostic error flag */
44#define ADIS16203_DIAG_STAT_SPI_FAIL (1<<3) /* SPI communications failure */
45#define ADIS16203_DIAG_STAT_FLASH_UPT (1<<2) /* Flash update failure */
46#define ADIS16203_DIAG_STAT_POWER_HIGH (1<<1) /* Power supply above 3.625 V */
47#define ADIS16203_DIAG_STAT_POWER_LOW (1<<0) /* Power supply below 3.15 V */
48
49/* GLOB_CMD */
50#define ADIS16203_GLOB_CMD_SW_RESET (1<<7)
51#define ADIS16203_GLOB_CMD_CLEAR_STAT (1<<4)
52#define ADIS16203_GLOB_CMD_FACTORY_CAL (1<<1)
53
54#define ADIS16203_MAX_TX 12
55#define ADIS16203_MAX_RX 10
56
57#define ADIS16203_ERROR_ACTIVE (1<<14)
58
59/**
60 * struct adis16203_state - device instance specific data
61 * @us: actual spi_device
62 * @work_trigger_to_ring: bh for triggered event handling
63 * @inter: used to check if new interrupt has been triggered
64 * @last_timestamp: passing timestamp from th to bh of interrupt handler
65 * @indio_dev: industrial I/O device structure
66 * @trig: data ready trigger registered with iio
67 * @tx: transmit buffer
68 * @rx: recieve buffer
69 * @buf_lock: mutex to protect tx and rx
70 **/
71struct adis16203_state {
72 struct spi_device *us;
73 struct work_struct work_trigger_to_ring;
74 s64 last_timestamp;
75 struct iio_dev *indio_dev;
76 struct iio_trigger *trig;
77 u8 *tx;
78 u8 *rx;
79 struct mutex buf_lock;
80};
81
82int adis16203_set_irq(struct device *dev, bool enable);
83
84#ifdef CONFIG_IIO_RING_BUFFER
85enum adis16203_scan {
86 ADIS16203_SCAN_SUPPLY,
87 ADIS16203_SCAN_AUX_ADC,
88 ADIS16203_SCAN_TEMP,
89 ADIS16203_SCAN_INCLI_X,
90 ADIS16203_SCAN_INCLI_Y,
91};
92
93void adis16203_remove_trigger(struct iio_dev *indio_dev);
94int adis16203_probe_trigger(struct iio_dev *indio_dev);
95
96ssize_t adis16203_read_data_from_ring(struct device *dev,
97 struct device_attribute *attr,
98 char *buf);
99
100int adis16203_configure_ring(struct iio_dev *indio_dev);
101void adis16203_unconfigure_ring(struct iio_dev *indio_dev);
102
103int adis16203_initialize_ring(struct iio_ring_buffer *ring);
104void adis16203_uninitialize_ring(struct iio_ring_buffer *ring);
105#else /* CONFIG_IIO_RING_BUFFER */
106
107static inline void adis16203_remove_trigger(struct iio_dev *indio_dev)
108{
109}
110
111static inline int adis16203_probe_trigger(struct iio_dev *indio_dev)
112{
113 return 0;
114}
115
116static inline ssize_t
117adis16203_read_data_from_ring(struct device *dev,
118 struct device_attribute *attr,
119 char *buf)
120{
121 return 0;
122}
123
124static int adis16203_configure_ring(struct iio_dev *indio_dev)
125{
126 return 0;
127}
128
129static inline void adis16203_unconfigure_ring(struct iio_dev *indio_dev)
130{
131}
132
133static inline int adis16203_initialize_ring(struct iio_ring_buffer *ring)
134{
135 return 0;
136}
137
138static inline void adis16203_uninitialize_ring(struct iio_ring_buffer *ring)
139{
140}
141
142#endif /* CONFIG_IIO_RING_BUFFER */
143#endif /* SPI_ADIS16203_H_ */
diff --git a/drivers/staging/iio/accel/adis16203_core.c b/drivers/staging/iio/accel/adis16203_core.c
new file mode 100644
index 000000000000..b57f19087a93
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16203_core.c
@@ -0,0 +1,568 @@
1/*
2 * ADIS16203 Programmable Digital Vibration Sensor driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "accel.h"
24#include "inclinometer.h"
25#include "../gyro/gyro.h"
26#include "../adc/adc.h"
27
28#include "adis16203.h"
29
30#define DRIVER_NAME "adis16203"
31
32static int adis16203_check_status(struct device *dev);
33
34/**
35 * adis16203_spi_write_reg_8() - write single byte to a register
36 * @dev: device associated with child of actual device (iio_dev or iio_trig)
37 * @reg_address: the address of the register to be written
38 * @val: the value to write
39 **/
40static int adis16203_spi_write_reg_8(struct device *dev,
41 u8 reg_address,
42 u8 val)
43{
44 int ret;
45 struct iio_dev *indio_dev = dev_get_drvdata(dev);
46 struct adis16203_state *st = iio_dev_get_devdata(indio_dev);
47
48 mutex_lock(&st->buf_lock);
49 st->tx[0] = ADIS16203_WRITE_REG(reg_address);
50 st->tx[1] = val;
51
52 ret = spi_write(st->us, st->tx, 2);
53 mutex_unlock(&st->buf_lock);
54
55 return ret;
56}
57
58/**
59 * adis16203_spi_write_reg_16() - write 2 bytes to a pair of registers
60 * @dev: device associated with child of actual device (iio_dev or iio_trig)
61 * @reg_address: the address of the lower of the two registers. Second register
62 * is assumed to have address one greater.
63 * @val: value to be written
64 **/
65static int adis16203_spi_write_reg_16(struct device *dev,
66 u8 lower_reg_address,
67 u16 value)
68{
69 int ret;
70 struct spi_message msg;
71 struct iio_dev *indio_dev = dev_get_drvdata(dev);
72 struct adis16203_state *st = iio_dev_get_devdata(indio_dev);
73 struct spi_transfer xfers[] = {
74 {
75 .tx_buf = st->tx,
76 .bits_per_word = 8,
77 .len = 2,
78 .cs_change = 1,
79 }, {
80 .tx_buf = st->tx + 2,
81 .bits_per_word = 8,
82 .len = 2,
83 .cs_change = 1,
84 },
85 };
86
87 mutex_lock(&st->buf_lock);
88 st->tx[0] = ADIS16203_WRITE_REG(lower_reg_address);
89 st->tx[1] = value & 0xFF;
90 st->tx[2] = ADIS16203_WRITE_REG(lower_reg_address + 1);
91 st->tx[3] = (value >> 8) & 0xFF;
92
93 spi_message_init(&msg);
94 spi_message_add_tail(&xfers[0], &msg);
95 spi_message_add_tail(&xfers[1], &msg);
96 ret = spi_sync(st->us, &msg);
97 mutex_unlock(&st->buf_lock);
98
99 return ret;
100}
101
102/**
103 * adis16203_spi_read_reg_16() - read 2 bytes from a 16-bit register
104 * @dev: device associated with child of actual device (iio_dev or iio_trig)
105 * @reg_address: the address of the lower of the two registers. Second register
106 * is assumed to have address one greater.
107 * @val: somewhere to pass back the value read
108 **/
109static int adis16203_spi_read_reg_16(struct device *dev,
110 u8 lower_reg_address,
111 u16 *val)
112{
113 struct spi_message msg;
114 struct iio_dev *indio_dev = dev_get_drvdata(dev);
115 struct adis16203_state *st = iio_dev_get_devdata(indio_dev);
116 int ret;
117 struct spi_transfer xfers[] = {
118 {
119 .tx_buf = st->tx,
120 .bits_per_word = 8,
121 .len = 2,
122 .cs_change = 1,
123 .delay_usecs = 20,
124 }, {
125 .rx_buf = st->rx,
126 .bits_per_word = 8,
127 .len = 2,
128 .cs_change = 1,
129 .delay_usecs = 20,
130 },
131 };
132
133 mutex_lock(&st->buf_lock);
134 st->tx[0] = ADIS16203_READ_REG(lower_reg_address);
135 st->tx[1] = 0;
136
137 spi_message_init(&msg);
138 spi_message_add_tail(&xfers[0], &msg);
139 spi_message_add_tail(&xfers[1], &msg);
140 ret = spi_sync(st->us, &msg);
141 if (ret) {
142 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
143 lower_reg_address);
144 goto error_ret;
145 }
146 *val = (st->rx[0] << 8) | st->rx[1];
147
148error_ret:
149 mutex_unlock(&st->buf_lock);
150 return ret;
151}
152
153static ssize_t adis16203_read_12bit_unsigned(struct device *dev,
154 struct device_attribute *attr,
155 char *buf)
156{
157 int ret;
158 u16 val = 0;
159 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
160
161 ret = adis16203_spi_read_reg_16(dev, this_attr->address, &val);
162 if (ret)
163 return ret;
164
165 if (val & ADIS16203_ERROR_ACTIVE)
166 adis16203_check_status(dev);
167
168 return sprintf(buf, "%u\n", val & 0x0FFF);
169}
170
171static ssize_t adis16203_read_temp(struct device *dev,
172 struct device_attribute *attr,
173 char *buf)
174{
175 struct iio_dev *indio_dev = dev_get_drvdata(dev);
176 ssize_t ret;
177 u16 val;
178
179 /* Take the iio_dev status lock */
180 mutex_lock(&indio_dev->mlock);
181
182 ret = adis16203_spi_read_reg_16(dev, ADIS16203_TEMP_OUT, (u16 *)&val);
183 if (ret)
184 goto error_ret;
185
186 if (val & ADIS16203_ERROR_ACTIVE)
187 adis16203_check_status(dev);
188
189 val &= 0xFFF;
190 ret = sprintf(buf, "%d\n", val);
191
192error_ret:
193 mutex_unlock(&indio_dev->mlock);
194 return ret;
195}
196
197static ssize_t adis16203_read_14bit_signed(struct device *dev,
198 struct device_attribute *attr,
199 char *buf)
200{
201 struct iio_dev *indio_dev = dev_get_drvdata(dev);
202 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
203 s16 val = 0;
204 ssize_t ret;
205
206 mutex_lock(&indio_dev->mlock);
207
208 ret = adis16203_spi_read_reg_16(dev, this_attr->address, (u16 *)&val);
209 if (!ret) {
210 if (val & ADIS16203_ERROR_ACTIVE)
211 adis16203_check_status(dev);
212
213 val = ((s16)(val << 2) >> 2);
214 ret = sprintf(buf, "%d\n", val);
215 }
216
217 mutex_unlock(&indio_dev->mlock);
218
219 return ret;
220}
221
222static ssize_t adis16203_write_16bit(struct device *dev,
223 struct device_attribute *attr,
224 const char *buf,
225 size_t len)
226{
227 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
228 int ret;
229 long val;
230
231 ret = strict_strtol(buf, 10, &val);
232 if (ret)
233 goto error_ret;
234 ret = adis16203_spi_write_reg_16(dev, this_attr->address, val);
235
236error_ret:
237 return ret ? ret : len;
238}
239
240static int adis16203_reset(struct device *dev)
241{
242 int ret;
243 ret = adis16203_spi_write_reg_8(dev,
244 ADIS16203_GLOB_CMD,
245 ADIS16203_GLOB_CMD_SW_RESET);
246 if (ret)
247 dev_err(dev, "problem resetting device");
248
249 return ret;
250}
251
252static ssize_t adis16203_write_reset(struct device *dev,
253 struct device_attribute *attr,
254 const char *buf, size_t len)
255{
256 if (len < 1)
257 return -EINVAL;
258 switch (buf[0]) {
259 case '1':
260 case 'y':
261 case 'Y':
262 return adis16203_reset(dev);
263 }
264 return -EINVAL;
265}
266
267int adis16203_set_irq(struct device *dev, bool enable)
268{
269 int ret = 0;
270 u16 msc;
271
272 ret = adis16203_spi_read_reg_16(dev, ADIS16203_MSC_CTRL, &msc);
273 if (ret)
274 goto error_ret;
275
276 msc |= ADIS16203_MSC_CTRL_ACTIVE_HIGH;
277 msc &= ~ADIS16203_MSC_CTRL_DATA_RDY_DIO1;
278 if (enable)
279 msc |= ADIS16203_MSC_CTRL_DATA_RDY_EN;
280 else
281 msc &= ~ADIS16203_MSC_CTRL_DATA_RDY_EN;
282
283 ret = adis16203_spi_write_reg_16(dev, ADIS16203_MSC_CTRL, msc);
284
285error_ret:
286 return ret;
287}
288
289static int adis16203_check_status(struct device *dev)
290{
291 u16 status;
292 int ret;
293
294 ret = adis16203_spi_read_reg_16(dev, ADIS16203_DIAG_STAT, &status);
295 if (ret < 0) {
296 dev_err(dev, "Reading status failed\n");
297 goto error_ret;
298 }
299 ret = status & 0x1F;
300
301 if (status & ADIS16203_DIAG_STAT_SELFTEST_FAIL)
302 dev_err(dev, "Self test failure\n");
303 if (status & ADIS16203_DIAG_STAT_SPI_FAIL)
304 dev_err(dev, "SPI failure\n");
305 if (status & ADIS16203_DIAG_STAT_FLASH_UPT)
306 dev_err(dev, "Flash update failed\n");
307 if (status & ADIS16203_DIAG_STAT_POWER_HIGH)
308 dev_err(dev, "Power supply above 3.625V\n");
309 if (status & ADIS16203_DIAG_STAT_POWER_LOW)
310 dev_err(dev, "Power supply below 3.15V\n");
311
312error_ret:
313 return ret;
314}
315
316static int adis16203_self_test(struct device *dev)
317{
318 int ret;
319 ret = adis16203_spi_write_reg_16(dev,
320 ADIS16203_MSC_CTRL,
321 ADIS16203_MSC_CTRL_SELF_TEST_EN);
322 if (ret) {
323 dev_err(dev, "problem starting self test");
324 goto err_ret;
325 }
326
327 adis16203_check_status(dev);
328
329err_ret:
330 return ret;
331}
332
333static int adis16203_initial_setup(struct adis16203_state *st)
334{
335 int ret;
336 struct device *dev = &st->indio_dev->dev;
337
338 /* Disable IRQ */
339 ret = adis16203_set_irq(dev, false);
340 if (ret) {
341 dev_err(dev, "disable irq failed");
342 goto err_ret;
343 }
344
345 /* Do self test */
346 ret = adis16203_self_test(dev);
347 if (ret) {
348 dev_err(dev, "self test failure");
349 goto err_ret;
350 }
351
352 /* Read status register to check the result */
353 ret = adis16203_check_status(dev);
354 if (ret) {
355 adis16203_reset(dev);
356 dev_err(dev, "device not playing ball -> reset");
357 msleep(ADIS16203_STARTUP_DELAY);
358 ret = adis16203_check_status(dev);
359 if (ret) {
360 dev_err(dev, "giving up");
361 goto err_ret;
362 }
363 }
364
365 printk(KERN_INFO DRIVER_NAME ": at CS%d (irq %d)\n",
366 st->us->chip_select, st->us->irq);
367
368err_ret:
369 return ret;
370}
371
372static IIO_DEV_ATTR_IN_NAMED_RAW(0, supply, adis16203_read_12bit_unsigned,
373 ADIS16203_SUPPLY_OUT);
374static IIO_CONST_ATTR(in0_supply_scale, "0.00122");
375static IIO_DEV_ATTR_IN_RAW(1, adis16203_read_12bit_unsigned,
376 ADIS16203_AUX_ADC);
377static IIO_CONST_ATTR(in1_scale, "0.00061");
378
379static IIO_DEV_ATTR_INCLI_X(adis16203_read_14bit_signed,
380 ADIS16203_XINCL_OUT);
381static IIO_DEV_ATTR_INCLI_Y(adis16203_read_14bit_signed,
382 ADIS16203_YINCL_OUT);
383static IIO_DEV_ATTR_INCLI_X_OFFSET(S_IWUSR | S_IRUGO,
384 adis16203_read_14bit_signed,
385 adis16203_write_16bit,
386 ADIS16203_INCL_NULL);
387static IIO_CONST_ATTR(incli_scale, "0.025");
388
389static IIO_DEV_ATTR_TEMP_RAW(adis16203_read_temp);
390static IIO_CONST_ATTR(temp_offset, "25");
391static IIO_CONST_ATTR(temp_scale, "-0.47");
392
393static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, adis16203_write_reset, 0);
394
395static IIO_CONST_ATTR(name, "adis16203");
396
397static struct attribute *adis16203_event_attributes[] = {
398 NULL
399};
400
401static struct attribute_group adis16203_event_attribute_group = {
402 .attrs = adis16203_event_attributes,
403};
404
405static struct attribute *adis16203_attributes[] = {
406 &iio_dev_attr_in0_supply_raw.dev_attr.attr,
407 &iio_const_attr_in0_supply_scale.dev_attr.attr,
408 &iio_dev_attr_temp_raw.dev_attr.attr,
409 &iio_const_attr_temp_offset.dev_attr.attr,
410 &iio_const_attr_temp_scale.dev_attr.attr,
411 &iio_dev_attr_reset.dev_attr.attr,
412 &iio_const_attr_name.dev_attr.attr,
413 &iio_dev_attr_in1_raw.dev_attr.attr,
414 &iio_const_attr_in1_scale.dev_attr.attr,
415 &iio_dev_attr_incli_x_raw.dev_attr.attr,
416 &iio_dev_attr_incli_y_raw.dev_attr.attr,
417 &iio_dev_attr_incli_x_offset.dev_attr.attr,
418 &iio_const_attr_incli_scale.dev_attr.attr,
419 NULL
420};
421
422static const struct attribute_group adis16203_attribute_group = {
423 .attrs = adis16203_attributes,
424};
425
426static int __devinit adis16203_probe(struct spi_device *spi)
427{
428 int ret, regdone = 0;
429 struct adis16203_state *st = kzalloc(sizeof *st, GFP_KERNEL);
430 if (!st) {
431 ret = -ENOMEM;
432 goto error_ret;
433 }
434 /* this is only used for removal purposes */
435 spi_set_drvdata(spi, st);
436
437 /* Allocate the comms buffers */
438 st->rx = kzalloc(sizeof(*st->rx)*ADIS16203_MAX_RX, GFP_KERNEL);
439 if (st->rx == NULL) {
440 ret = -ENOMEM;
441 goto error_free_st;
442 }
443 st->tx = kzalloc(sizeof(*st->tx)*ADIS16203_MAX_TX, GFP_KERNEL);
444 if (st->tx == NULL) {
445 ret = -ENOMEM;
446 goto error_free_rx;
447 }
448 st->us = spi;
449 mutex_init(&st->buf_lock);
450 /* setup the industrialio driver allocated elements */
451 st->indio_dev = iio_allocate_device();
452 if (st->indio_dev == NULL) {
453 ret = -ENOMEM;
454 goto error_free_tx;
455 }
456
457 st->indio_dev->dev.parent = &spi->dev;
458 st->indio_dev->num_interrupt_lines = 1;
459 st->indio_dev->event_attrs = &adis16203_event_attribute_group;
460 st->indio_dev->attrs = &adis16203_attribute_group;
461 st->indio_dev->dev_data = (void *)(st);
462 st->indio_dev->driver_module = THIS_MODULE;
463 st->indio_dev->modes = INDIO_DIRECT_MODE;
464
465 ret = adis16203_configure_ring(st->indio_dev);
466 if (ret)
467 goto error_free_dev;
468
469 ret = iio_device_register(st->indio_dev);
470 if (ret)
471 goto error_unreg_ring_funcs;
472 regdone = 1;
473
474 ret = adis16203_initialize_ring(st->indio_dev->ring);
475 if (ret) {
476 printk(KERN_ERR "failed to initialize the ring\n");
477 goto error_unreg_ring_funcs;
478 }
479
480 if (spi->irq) {
481 ret = iio_register_interrupt_line(spi->irq,
482 st->indio_dev,
483 0,
484 IRQF_TRIGGER_RISING,
485 "adis16203");
486 if (ret)
487 goto error_uninitialize_ring;
488
489 ret = adis16203_probe_trigger(st->indio_dev);
490 if (ret)
491 goto error_unregister_line;
492 }
493
494 /* Get the device into a sane initial state */
495 ret = adis16203_initial_setup(st);
496 if (ret)
497 goto error_remove_trigger;
498 return 0;
499
500error_remove_trigger:
501 adis16203_remove_trigger(st->indio_dev);
502error_unregister_line:
503 if (spi->irq)
504 iio_unregister_interrupt_line(st->indio_dev, 0);
505error_uninitialize_ring:
506 adis16203_uninitialize_ring(st->indio_dev->ring);
507error_unreg_ring_funcs:
508 adis16203_unconfigure_ring(st->indio_dev);
509error_free_dev:
510 if (regdone)
511 iio_device_unregister(st->indio_dev);
512 else
513 iio_free_device(st->indio_dev);
514error_free_tx:
515 kfree(st->tx);
516error_free_rx:
517 kfree(st->rx);
518error_free_st:
519 kfree(st);
520error_ret:
521 return ret;
522}
523
524static int adis16203_remove(struct spi_device *spi)
525{
526 struct adis16203_state *st = spi_get_drvdata(spi);
527 struct iio_dev *indio_dev = st->indio_dev;
528
529 flush_scheduled_work();
530
531 adis16203_remove_trigger(indio_dev);
532 if (spi->irq)
533 iio_unregister_interrupt_line(indio_dev, 0);
534
535 adis16203_uninitialize_ring(indio_dev->ring);
536 iio_device_unregister(indio_dev);
537 adis16203_unconfigure_ring(indio_dev);
538 kfree(st->tx);
539 kfree(st->rx);
540 kfree(st);
541
542 return 0;
543}
544
545static struct spi_driver adis16203_driver = {
546 .driver = {
547 .name = "adis16203",
548 .owner = THIS_MODULE,
549 },
550 .probe = adis16203_probe,
551 .remove = __devexit_p(adis16203_remove),
552};
553
554static __init int adis16203_init(void)
555{
556 return spi_register_driver(&adis16203_driver);
557}
558module_init(adis16203_init);
559
560static __exit void adis16203_exit(void)
561{
562 spi_unregister_driver(&adis16203_driver);
563}
564module_exit(adis16203_exit);
565
566MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
567MODULE_DESCRIPTION("Analog Devices ADIS16203 Programmable Digital Vibration Sensor driver");
568MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/accel/adis16203_ring.c b/drivers/staging/iio/accel/adis16203_ring.c
new file mode 100644
index 000000000000..3d774f7efa25
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16203_ring.c
@@ -0,0 +1,211 @@
1#include <linux/interrupt.h>
2#include <linux/irq.h>
3#include <linux/gpio.h>
4#include <linux/workqueue.h>
5#include <linux/mutex.h>
6#include <linux/device.h>
7#include <linux/kernel.h>
8#include <linux/spi/spi.h>
9#include <linux/slab.h>
10#include <linux/sysfs.h>
11#include <linux/list.h>
12
13#include "../iio.h"
14#include "../sysfs.h"
15#include "../ring_sw.h"
16#include "accel.h"
17#include "../trigger.h"
18#include "adis16203.h"
19
20static IIO_SCAN_EL_C(in_supply, ADIS16203_SCAN_SUPPLY, ADIS16203_SUPPLY_OUT, NULL);
21static IIO_CONST_ATTR_SCAN_EL_TYPE(in_supply, u, 12, 16);
22static IIO_SCAN_EL_C(in0, ADIS16203_SCAN_AUX_ADC, ADIS16203_AUX_ADC, NULL);
23static IIO_CONST_ATTR_SCAN_EL_TYPE(in0, u, 12, 16);
24static IIO_SCAN_EL_C(temp, ADIS16203_SCAN_TEMP, ADIS16203_TEMP_OUT, NULL);
25static IIO_CONST_ATTR_SCAN_EL_TYPE(temp, u, 12, 16);
26static IIO_SCAN_EL_C(incli_x, ADIS16203_SCAN_INCLI_X,
27 ADIS16203_XINCL_OUT, NULL);
28static IIO_SCAN_EL_C(incli_y, ADIS16203_SCAN_INCLI_Y,
29 ADIS16203_YINCL_OUT, NULL);
30static IIO_CONST_ATTR_SCAN_EL_TYPE(incli, s, 14, 16);
31static IIO_SCAN_EL_TIMESTAMP(5);
32static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
33
34static struct attribute *adis16203_scan_el_attrs[] = {
35 &iio_scan_el_in_supply.dev_attr.attr,
36 &iio_const_attr_in_supply_index.dev_attr.attr,
37 &iio_const_attr_in_supply_type.dev_attr.attr,
38 &iio_scan_el_in0.dev_attr.attr,
39 &iio_const_attr_in0_index.dev_attr.attr,
40 &iio_const_attr_in0_type.dev_attr.attr,
41 &iio_scan_el_temp.dev_attr.attr,
42 &iio_const_attr_temp_index.dev_attr.attr,
43 &iio_const_attr_temp_type.dev_attr.attr,
44 &iio_scan_el_incli_x.dev_attr.attr,
45 &iio_const_attr_incli_x_index.dev_attr.attr,
46 &iio_scan_el_incli_y.dev_attr.attr,
47 &iio_const_attr_incli_y_index.dev_attr.attr,
48 &iio_const_attr_incli_type.dev_attr.attr,
49 &iio_scan_el_timestamp.dev_attr.attr,
50 &iio_const_attr_timestamp_index.dev_attr.attr,
51 &iio_const_attr_timestamp_type.dev_attr.attr,
52 NULL,
53};
54
55static struct attribute_group adis16203_scan_el_group = {
56 .attrs = adis16203_scan_el_attrs,
57 .name = "scan_elements",
58};
59
60/**
61 * adis16203_poll_func_th() top half interrupt handler called by trigger
62 * @private_data: iio_dev
63 **/
64static void adis16203_poll_func_th(struct iio_dev *indio_dev, s64 timestamp)
65{
66 struct adis16203_state *st = iio_dev_get_devdata(indio_dev);
67 st->last_timestamp = timestamp;
68 schedule_work(&st->work_trigger_to_ring);
69}
70
71/**
72 * adis16203_read_ring_data() read data registers which will be placed into ring
73 * @dev: device associated with child of actual device (iio_dev or iio_trig)
74 * @rx: somewhere to pass back the value read
75 **/
76static int adis16203_read_ring_data(struct device *dev, u8 *rx)
77{
78 struct spi_message msg;
79 struct iio_dev *indio_dev = dev_get_drvdata(dev);
80 struct adis16203_state *st = iio_dev_get_devdata(indio_dev);
81 struct spi_transfer xfers[ADIS16203_OUTPUTS + 1];
82 int ret;
83 int i;
84
85 mutex_lock(&st->buf_lock);
86
87 spi_message_init(&msg);
88
89 memset(xfers, 0, sizeof(xfers));
90 for (i = 0; i <= ADIS16203_OUTPUTS; i++) {
91 xfers[i].bits_per_word = 8;
92 xfers[i].cs_change = 1;
93 xfers[i].len = 2;
94 xfers[i].delay_usecs = 20;
95 xfers[i].tx_buf = st->tx + 2 * i;
96 if (i < 1) /* SUPPLY_OUT: 0x02, AUX_ADC: 0x08 */
97 st->tx[2 * i] = ADIS16203_READ_REG(ADIS16203_SUPPLY_OUT + 2 * i);
98 else
99 st->tx[2 * i] = ADIS16203_READ_REG(ADIS16203_SUPPLY_OUT + 2 * i + 6);
100 st->tx[2 * i + 1] = 0;
101 if (i >= 1)
102 xfers[i].rx_buf = rx + 2 * (i - 1);
103 spi_message_add_tail(&xfers[i], &msg);
104 }
105
106 ret = spi_sync(st->us, &msg);
107 if (ret)
108 dev_err(&st->us->dev, "problem when burst reading");
109
110 mutex_unlock(&st->buf_lock);
111
112 return ret;
113}
114
115/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
116 * specific to be rolled into the core.
117 */
118static void adis16203_trigger_bh_to_ring(struct work_struct *work_s)
119{
120 struct adis16203_state *st
121 = container_of(work_s, struct adis16203_state,
122 work_trigger_to_ring);
123 struct iio_ring_buffer *ring = st->indio_dev->ring;
124
125 int i = 0;
126 s16 *data;
127 size_t datasize = ring->access.get_bytes_per_datum(ring);
128
129 data = kmalloc(datasize, GFP_KERNEL);
130 if (data == NULL) {
131 dev_err(&st->us->dev, "memory alloc failed in ring bh");
132 return;
133 }
134
135 if (ring->scan_count)
136 if (adis16203_read_ring_data(&st->indio_dev->dev, st->rx) >= 0)
137 for (; i < ring->scan_count; i++)
138 data[i] = be16_to_cpup(
139 (__be16 *)&(st->rx[i*2]));
140
141 /* Guaranteed to be aligned with 8 byte boundary */
142 if (ring->scan_timestamp)
143 *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp;
144
145 ring->access.store_to(ring,
146 (u8 *)data,
147 st->last_timestamp);
148
149 iio_trigger_notify_done(st->indio_dev->trig);
150 kfree(data);
151
152 return;
153}
154
155void adis16203_unconfigure_ring(struct iio_dev *indio_dev)
156{
157 kfree(indio_dev->pollfunc);
158 iio_sw_rb_free(indio_dev->ring);
159}
160
161int adis16203_configure_ring(struct iio_dev *indio_dev)
162{
163 int ret = 0;
164 struct adis16203_state *st = indio_dev->dev_data;
165 struct iio_ring_buffer *ring;
166 INIT_WORK(&st->work_trigger_to_ring, adis16203_trigger_bh_to_ring);
167
168 ring = iio_sw_rb_allocate(indio_dev);
169 if (!ring) {
170 ret = -ENOMEM;
171 return ret;
172 }
173 indio_dev->ring = ring;
174 /* Effectively select the ring buffer implementation */
175 iio_ring_sw_register_funcs(&ring->access);
176 ring->bpe = 2;
177 ring->scan_el_attrs = &adis16203_scan_el_group;
178 ring->scan_timestamp = true;
179 ring->preenable = &iio_sw_ring_preenable;
180 ring->postenable = &iio_triggered_ring_postenable;
181 ring->predisable = &iio_triggered_ring_predisable;
182 ring->owner = THIS_MODULE;
183
184 /* Set default scan mode */
185 iio_scan_mask_set(ring, iio_scan_el_in_supply.number);
186 iio_scan_mask_set(ring, iio_scan_el_temp.number);
187 iio_scan_mask_set(ring, iio_scan_el_in0.number);
188 iio_scan_mask_set(ring, iio_scan_el_incli_x.number);
189 iio_scan_mask_set(ring, iio_scan_el_incli_y.number);
190
191 ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16203_poll_func_th);
192 if (ret)
193 goto error_iio_sw_rb_free;
194
195 indio_dev->modes |= INDIO_RING_TRIGGERED;
196 return 0;
197
198error_iio_sw_rb_free:
199 iio_sw_rb_free(indio_dev->ring);
200 return ret;
201}
202
203int adis16203_initialize_ring(struct iio_ring_buffer *ring)
204{
205 return iio_ring_buffer_register(ring, 0);
206}
207
208void adis16203_uninitialize_ring(struct iio_ring_buffer *ring)
209{
210 iio_ring_buffer_unregister(ring);
211}
diff --git a/drivers/staging/iio/accel/adis16203_trigger.c b/drivers/staging/iio/accel/adis16203_trigger.c
new file mode 100644
index 000000000000..50be51c25dc2
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16203_trigger.c
@@ -0,0 +1,122 @@
1#include <linux/interrupt.h>
2#include <linux/irq.h>
3#include <linux/mutex.h>
4#include <linux/device.h>
5#include <linux/kernel.h>
6#include <linux/sysfs.h>
7#include <linux/list.h>
8#include <linux/spi/spi.h>
9
10#include "../iio.h"
11#include "../sysfs.h"
12#include "../trigger.h"
13#include "adis16203.h"
14
15/**
16 * adis16203_data_rdy_trig_poll() the event handler for the data rdy trig
17 **/
18static int adis16203_data_rdy_trig_poll(struct iio_dev *dev_info,
19 int index,
20 s64 timestamp,
21 int no_test)
22{
23 struct adis16203_state *st = iio_dev_get_devdata(dev_info);
24 struct iio_trigger *trig = st->trig;
25
26 iio_trigger_poll(trig, timestamp);
27
28 return IRQ_HANDLED;
29}
30
31IIO_EVENT_SH(data_rdy_trig, &adis16203_data_rdy_trig_poll);
32
33static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);
34
35static struct attribute *adis16203_trigger_attrs[] = {
36 &dev_attr_name.attr,
37 NULL,
38};
39
40static const struct attribute_group adis16203_trigger_attr_group = {
41 .attrs = adis16203_trigger_attrs,
42};
43
44/**
45 * adis16203_data_rdy_trigger_set_state() set datardy interrupt state
46 **/
47static int adis16203_data_rdy_trigger_set_state(struct iio_trigger *trig,
48 bool state)
49{
50 struct adis16203_state *st = trig->private_data;
51 struct iio_dev *indio_dev = st->indio_dev;
52 int ret = 0;
53
54 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
55 ret = adis16203_set_irq(&st->indio_dev->dev, state);
56 if (state == false) {
57 iio_remove_event_from_list(&iio_event_data_rdy_trig,
58 &indio_dev->interrupts[0]
59 ->ev_list);
60 flush_scheduled_work();
61 } else {
62 iio_add_event_to_list(&iio_event_data_rdy_trig,
63 &indio_dev->interrupts[0]->ev_list);
64 }
65 return ret;
66}
67
68/**
69 * adis16203_trig_try_reen() try renabling irq for data rdy trigger
70 * @trig: the datardy trigger
71 **/
72static int adis16203_trig_try_reen(struct iio_trigger *trig)
73{
74 struct adis16203_state *st = trig->private_data;
75 enable_irq(st->us->irq);
76 return 0;
77}
78
79int adis16203_probe_trigger(struct iio_dev *indio_dev)
80{
81 int ret;
82 struct adis16203_state *st = indio_dev->dev_data;
83
84 st->trig = iio_allocate_trigger();
85 st->trig->name = kasprintf(GFP_KERNEL,
86 "adis16203-dev%d",
87 indio_dev->id);
88 if (!st->trig->name) {
89 ret = -ENOMEM;
90 goto error_free_trig;
91 }
92 st->trig->dev.parent = &st->us->dev;
93 st->trig->owner = THIS_MODULE;
94 st->trig->private_data = st;
95 st->trig->set_trigger_state = &adis16203_data_rdy_trigger_set_state;
96 st->trig->try_reenable = &adis16203_trig_try_reen;
97 st->trig->control_attrs = &adis16203_trigger_attr_group;
98 ret = iio_trigger_register(st->trig);
99
100 /* select default trigger */
101 indio_dev->trig = st->trig;
102 if (ret)
103 goto error_free_trig_name;
104
105 return 0;
106
107error_free_trig_name:
108 kfree(st->trig->name);
109error_free_trig:
110 iio_free_trigger(st->trig);
111
112 return ret;
113}
114
115void adis16203_remove_trigger(struct iio_dev *indio_dev)
116{
117 struct adis16203_state *state = indio_dev->dev_data;
118
119 iio_trigger_unregister(state->trig);
120 kfree(state->trig->name);
121 iio_free_trigger(state->trig);
122}
diff --git a/drivers/staging/iio/accel/adis16204.h b/drivers/staging/iio/accel/adis16204.h
new file mode 100644
index 000000000000..e9ed7cb048cf
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16204.h
@@ -0,0 +1,151 @@
1#ifndef SPI_ADIS16204_H_
2#define SPI_ADIS16204_H_
3
4#define ADIS16204_STARTUP_DELAY 220 /* ms */
5
6#define ADIS16204_READ_REG(a) a
7#define ADIS16204_WRITE_REG(a) ((a) | 0x80)
8
9#define ADIS16204_FLASH_CNT 0x00 /* Flash memory write count */
10#define ADIS16204_SUPPLY_OUT 0x02 /* Output, power supply */
11#define ADIS16204_XACCL_OUT 0x04 /* Output, x-axis accelerometer */
12#define ADIS16204_YACCL_OUT 0x06 /* Output, y-axis accelerometer */
13#define ADIS16204_AUX_ADC 0x08 /* Output, auxiliary ADC input */
14#define ADIS16204_TEMP_OUT 0x0A /* Output, temperature */
15#define ADIS16204_X_PEAK_OUT 0x0C /* Twos complement */
16#define ADIS16204_Y_PEAK_OUT 0x0E /* Twos complement */
17#define ADIS16204_XACCL_NULL 0x10 /* Calibration, x-axis acceleration offset null */
18#define ADIS16204_YACCL_NULL 0x12 /* Calibration, y-axis acceleration offset null */
19#define ADIS16204_XACCL_SCALE 0x14 /* X-axis scale factor calibration register */
20#define ADIS16204_YACCL_SCALE 0x16 /* Y-axis scale factor calibration register */
21#define ADIS16204_XY_RSS_OUT 0x18 /* XY combined acceleration (RSS) */
22#define ADIS16204_XY_PEAK_OUT 0x1A /* Peak, XY combined output (RSS) */
23#define ADIS16204_CAP_BUF_1 0x1C /* Capture buffer output register 1 */
24#define ADIS16204_CAP_BUF_2 0x1E /* Capture buffer output register 2 */
25#define ADIS16204_ALM_MAG1 0x20 /* Alarm 1 amplitude threshold */
26#define ADIS16204_ALM_MAG2 0x22 /* Alarm 2 amplitude threshold */
27#define ADIS16204_ALM_CTRL 0x28 /* Alarm control */
28#define ADIS16204_CAPT_PNTR 0x2A /* Capture register address pointer */
29#define ADIS16204_AUX_DAC 0x30 /* Auxiliary DAC data */
30#define ADIS16204_GPIO_CTRL 0x32 /* General-purpose digital input/output control */
31#define ADIS16204_MSC_CTRL 0x34 /* Miscellaneous control */
32#define ADIS16204_SMPL_PRD 0x36 /* Internal sample period (rate) control */
33#define ADIS16204_AVG_CNT 0x38 /* Operation, filter configuration */
34#define ADIS16204_SLP_CNT 0x3A /* Operation, sleep mode control */
35#define ADIS16204_DIAG_STAT 0x3C /* Diagnostics, system status register */
36#define ADIS16204_GLOB_CMD 0x3E /* Operation, system command register */
37
38#define ADIS16204_OUTPUTS 5
39
40/* MSC_CTRL */
41#define ADIS16204_MSC_CTRL_PWRUP_SELF_TEST (1 << 10) /* Self-test at power-on: 1 = disabled, 0 = enabled */
42#define ADIS16204_MSC_CTRL_SELF_TEST_EN (1 << 8) /* Self-test enable */
43#define ADIS16204_MSC_CTRL_DATA_RDY_EN (1 << 2) /* Data-ready enable: 1 = enabled, 0 = disabled */
44#define ADIS16204_MSC_CTRL_ACTIVE_HIGH (1 << 1) /* Data-ready polarity: 1 = active high, 0 = active low */
45#define ADIS16204_MSC_CTRL_DATA_RDY_DIO2 (1 << 0) /* Data-ready line selection: 1 = DIO2, 0 = DIO1 */
46
47/* DIAG_STAT */
48#define ADIS16204_DIAG_STAT_ALARM2 (1<<9) /* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */
49#define ADIS16204_DIAG_STAT_ALARM1 (1<<8) /* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */
50#define ADIS16204_DIAG_STAT_SELFTEST_FAIL (1<<5) /* Self-test diagnostic error flag: 1 = error condition,
51 0 = normal operation */
52#define ADIS16204_DIAG_STAT_SPI_FAIL (1<<3) /* SPI communications failure */
53#define ADIS16204_DIAG_STAT_FLASH_UPT (1<<2) /* Flash update failure */
54#define ADIS16204_DIAG_STAT_POWER_HIGH (1<<1) /* Power supply above 3.625 V */
55#define ADIS16204_DIAG_STAT_POWER_LOW (1<<0) /* Power supply below 2.975 V */
56
57/* GLOB_CMD */
58#define ADIS16204_GLOB_CMD_SW_RESET (1<<7)
59#define ADIS16204_GLOB_CMD_CLEAR_STAT (1<<4)
60#define ADIS16204_GLOB_CMD_FACTORY_CAL (1<<1)
61
62#define ADIS16204_MAX_TX 24
63#define ADIS16204_MAX_RX 24
64
65#define ADIS16204_ERROR_ACTIVE (1<<14)
66
67/**
68 * struct adis16204_state - device instance specific data
69 * @us: actual spi_device
70 * @work_trigger_to_ring: bh for triggered event handling
71 * @inter: used to check if new interrupt has been triggered
72 * @last_timestamp: passing timestamp from th to bh of interrupt handler
73 * @indio_dev: industrial I/O device structure
74 * @trig: data ready trigger registered with iio
75 * @tx: transmit buffer
76 * @rx: recieve buffer
77 * @buf_lock: mutex to protect tx and rx
78 **/
79struct adis16204_state {
80 struct spi_device *us;
81 struct work_struct work_trigger_to_ring;
82 s64 last_timestamp;
83 struct iio_dev *indio_dev;
84 struct iio_trigger *trig;
85 u8 *tx;
86 u8 *rx;
87 struct mutex buf_lock;
88};
89
90int adis16204_set_irq(struct device *dev, bool enable);
91
92#ifdef CONFIG_IIO_RING_BUFFER
93enum adis16204_scan {
94 ADIS16204_SCAN_SUPPLY,
95 ADIS16204_SCAN_ACC_X,
96 ADIS16204_SCAN_ACC_Y,
97 ADIS16204_SCAN_AUX_ADC,
98 ADIS16204_SCAN_TEMP,
99};
100
101void adis16204_remove_trigger(struct iio_dev *indio_dev);
102int adis16204_probe_trigger(struct iio_dev *indio_dev);
103
104ssize_t adis16204_read_data_from_ring(struct device *dev,
105 struct device_attribute *attr,
106 char *buf);
107
108int adis16204_configure_ring(struct iio_dev *indio_dev);
109void adis16204_unconfigure_ring(struct iio_dev *indio_dev);
110
111int adis16204_initialize_ring(struct iio_ring_buffer *ring);
112void adis16204_uninitialize_ring(struct iio_ring_buffer *ring);
113#else /* CONFIG_IIO_RING_BUFFER */
114
115static inline void adis16204_remove_trigger(struct iio_dev *indio_dev)
116{
117}
118
119static inline int adis16204_probe_trigger(struct iio_dev *indio_dev)
120{
121 return 0;
122}
123
124static inline ssize_t
125adis16204_read_data_from_ring(struct device *dev,
126 struct device_attribute *attr,
127 char *buf)
128{
129 return 0;
130}
131
132static int adis16204_configure_ring(struct iio_dev *indio_dev)
133{
134 return 0;
135}
136
137static inline void adis16204_unconfigure_ring(struct iio_dev *indio_dev)
138{
139}
140
141static inline int adis16204_initialize_ring(struct iio_ring_buffer *ring)
142{
143 return 0;
144}
145
146static inline void adis16204_uninitialize_ring(struct iio_ring_buffer *ring)
147{
148}
149
150#endif /* CONFIG_IIO_RING_BUFFER */
151#endif /* SPI_ADIS16204_H_ */
diff --git a/drivers/staging/iio/accel/adis16204_core.c b/drivers/staging/iio/accel/adis16204_core.c
new file mode 100644
index 000000000000..cc15e40726fc
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16204_core.c
@@ -0,0 +1,613 @@
1/*
2 * ADIS16204 Programmable High-g Digital Impact Sensor and Recorder
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "accel.h"
24#include "../gyro/gyro.h"
25#include "../adc/adc.h"
26
27#include "adis16204.h"
28
29#define DRIVER_NAME "adis16204"
30
31static int adis16204_check_status(struct device *dev);
32
33/**
34 * adis16204_spi_write_reg_8() - write single byte to a register
35 * @dev: device associated with child of actual device (iio_dev or iio_trig)
36 * @reg_address: the address of the register to be written
37 * @val: the value to write
38 **/
39static int adis16204_spi_write_reg_8(struct device *dev,
40 u8 reg_address,
41 u8 val)
42{
43 int ret;
44 struct iio_dev *indio_dev = dev_get_drvdata(dev);
45 struct adis16204_state *st = iio_dev_get_devdata(indio_dev);
46
47 mutex_lock(&st->buf_lock);
48 st->tx[0] = ADIS16204_WRITE_REG(reg_address);
49 st->tx[1] = val;
50
51 ret = spi_write(st->us, st->tx, 2);
52 mutex_unlock(&st->buf_lock);
53
54 return ret;
55}
56
57/**
58 * adis16204_spi_write_reg_16() - write 2 bytes to a pair of registers
59 * @dev: device associated with child of actual device (iio_dev or iio_trig)
60 * @reg_address: the address of the lower of the two registers. Second register
61 * is assumed to have address one greater.
62 * @val: value to be written
63 **/
64static int adis16204_spi_write_reg_16(struct device *dev,
65 u8 lower_reg_address,
66 u16 value)
67{
68 int ret;
69 struct spi_message msg;
70 struct iio_dev *indio_dev = dev_get_drvdata(dev);
71 struct adis16204_state *st = iio_dev_get_devdata(indio_dev);
72 struct spi_transfer xfers[] = {
73 {
74 .tx_buf = st->tx,
75 .bits_per_word = 8,
76 .len = 2,
77 .cs_change = 1,
78 }, {
79 .tx_buf = st->tx + 2,
80 .bits_per_word = 8,
81 .len = 2,
82 .cs_change = 1,
83 },
84 };
85
86 mutex_lock(&st->buf_lock);
87 st->tx[0] = ADIS16204_WRITE_REG(lower_reg_address);
88 st->tx[1] = value & 0xFF;
89 st->tx[2] = ADIS16204_WRITE_REG(lower_reg_address + 1);
90 st->tx[3] = (value >> 8) & 0xFF;
91
92 spi_message_init(&msg);
93 spi_message_add_tail(&xfers[0], &msg);
94 spi_message_add_tail(&xfers[1], &msg);
95 ret = spi_sync(st->us, &msg);
96 mutex_unlock(&st->buf_lock);
97
98 return ret;
99}
100
101/**
102 * adis16204_spi_read_reg_16() - read 2 bytes from a 16-bit register
103 * @dev: device associated with child of actual device (iio_dev or iio_trig)
104 * @reg_address: the address of the lower of the two registers. Second register
105 * is assumed to have address one greater.
106 * @val: somewhere to pass back the value read
107 **/
108static int adis16204_spi_read_reg_16(struct device *dev,
109 u8 lower_reg_address,
110 u16 *val)
111{
112 struct spi_message msg;
113 struct iio_dev *indio_dev = dev_get_drvdata(dev);
114 struct adis16204_state *st = iio_dev_get_devdata(indio_dev);
115 int ret;
116 struct spi_transfer xfers[] = {
117 {
118 .tx_buf = st->tx,
119 .bits_per_word = 8,
120 .len = 2,
121 .cs_change = 1,
122 .delay_usecs = 20,
123 }, {
124 .rx_buf = st->rx,
125 .bits_per_word = 8,
126 .len = 2,
127 .cs_change = 1,
128 .delay_usecs = 20,
129 },
130 };
131
132 mutex_lock(&st->buf_lock);
133 st->tx[0] = ADIS16204_READ_REG(lower_reg_address);
134 st->tx[1] = 0;
135
136 spi_message_init(&msg);
137 spi_message_add_tail(&xfers[0], &msg);
138 spi_message_add_tail(&xfers[1], &msg);
139 ret = spi_sync(st->us, &msg);
140 if (ret) {
141 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
142 lower_reg_address);
143 goto error_ret;
144 }
145 *val = (st->rx[0] << 8) | st->rx[1];
146
147error_ret:
148 mutex_unlock(&st->buf_lock);
149 return ret;
150}
151
152static ssize_t adis16204_read_12bit_unsigned(struct device *dev,
153 struct device_attribute *attr,
154 char *buf)
155{
156 int ret;
157 u16 val = 0;
158 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
159
160 ret = adis16204_spi_read_reg_16(dev, this_attr->address, &val);
161 if (ret)
162 return ret;
163
164 if (val & ADIS16204_ERROR_ACTIVE)
165 adis16204_check_status(dev);
166
167 return sprintf(buf, "%u\n", val & 0x0FFF);
168}
169
170static ssize_t adis16204_read_temp(struct device *dev,
171 struct device_attribute *attr,
172 char *buf)
173{
174 struct iio_dev *indio_dev = dev_get_drvdata(dev);
175 ssize_t ret;
176 u16 val;
177
178 /* Take the iio_dev status lock */
179 mutex_lock(&indio_dev->mlock);
180
181 ret = adis16204_spi_read_reg_16(dev, ADIS16204_TEMP_OUT, (u16 *)&val);
182 if (ret)
183 goto error_ret;
184
185 if (val & ADIS16204_ERROR_ACTIVE)
186 adis16204_check_status(dev);
187
188 val &= 0xFFF;
189 ret = sprintf(buf, "%d\n", val);
190
191error_ret:
192 mutex_unlock(&indio_dev->mlock);
193 return ret;
194}
195
196static ssize_t adis16204_read_12bit_signed(struct device *dev,
197 struct device_attribute *attr,
198 char *buf)
199{
200 struct iio_dev *indio_dev = dev_get_drvdata(dev);
201 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
202 s16 val = 0;
203 ssize_t ret;
204
205 mutex_lock(&indio_dev->mlock);
206
207 ret = adis16204_spi_read_reg_16(dev, this_attr->address, (u16 *)&val);
208 if (!ret) {
209 if (val & ADIS16204_ERROR_ACTIVE)
210 adis16204_check_status(dev);
211
212 val = ((s16)(val << 4) >> 4);
213 ret = sprintf(buf, "%d\n", val);
214 }
215
216 mutex_unlock(&indio_dev->mlock);
217
218 return ret;
219}
220
221static ssize_t adis16204_read_14bit_signed(struct device *dev,
222 struct device_attribute *attr,
223 char *buf)
224{
225 struct iio_dev *indio_dev = dev_get_drvdata(dev);
226 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
227 s16 val = 0;
228 ssize_t ret;
229
230 mutex_lock(&indio_dev->mlock);
231
232 ret = adis16204_spi_read_reg_16(dev, this_attr->address, (u16 *)&val);
233 if (!ret) {
234 if (val & ADIS16204_ERROR_ACTIVE)
235 adis16204_check_status(dev);
236
237 val = ((s16)(val << 2) >> 2);
238 ret = sprintf(buf, "%d\n", val);
239 }
240
241 mutex_unlock(&indio_dev->mlock);
242
243 return ret;
244}
245
246static ssize_t adis16204_write_16bit(struct device *dev,
247 struct device_attribute *attr,
248 const char *buf,
249 size_t len)
250{
251 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
252 int ret;
253 long val;
254
255 ret = strict_strtol(buf, 10, &val);
256 if (ret)
257 goto error_ret;
258 ret = adis16204_spi_write_reg_16(dev, this_attr->address, val);
259
260error_ret:
261 return ret ? ret : len;
262}
263
264static int adis16204_reset(struct device *dev)
265{
266 int ret;
267 ret = adis16204_spi_write_reg_8(dev,
268 ADIS16204_GLOB_CMD,
269 ADIS16204_GLOB_CMD_SW_RESET);
270 if (ret)
271 dev_err(dev, "problem resetting device");
272
273 return ret;
274}
275
276static ssize_t adis16204_write_reset(struct device *dev,
277 struct device_attribute *attr,
278 const char *buf, size_t len)
279{
280 if (len < 1)
281 return -EINVAL;
282 switch (buf[0]) {
283 case '1':
284 case 'y':
285 case 'Y':
286 return adis16204_reset(dev);
287 }
288 return -EINVAL;
289}
290
291int adis16204_set_irq(struct device *dev, bool enable)
292{
293 int ret = 0;
294 u16 msc;
295
296 ret = adis16204_spi_read_reg_16(dev, ADIS16204_MSC_CTRL, &msc);
297 if (ret)
298 goto error_ret;
299
300 msc |= ADIS16204_MSC_CTRL_ACTIVE_HIGH;
301 msc &= ~ADIS16204_MSC_CTRL_DATA_RDY_DIO2;
302 if (enable)
303 msc |= ADIS16204_MSC_CTRL_DATA_RDY_EN;
304 else
305 msc &= ~ADIS16204_MSC_CTRL_DATA_RDY_EN;
306
307 ret = adis16204_spi_write_reg_16(dev, ADIS16204_MSC_CTRL, msc);
308
309error_ret:
310 return ret;
311}
312
313static int adis16204_check_status(struct device *dev)
314{
315 u16 status;
316 int ret;
317
318 ret = adis16204_spi_read_reg_16(dev, ADIS16204_DIAG_STAT, &status);
319 if (ret < 0) {
320 dev_err(dev, "Reading status failed\n");
321 goto error_ret;
322 }
323 ret = status & 0x1F;
324
325 if (status & ADIS16204_DIAG_STAT_SELFTEST_FAIL)
326 dev_err(dev, "Self test failure\n");
327 if (status & ADIS16204_DIAG_STAT_SPI_FAIL)
328 dev_err(dev, "SPI failure\n");
329 if (status & ADIS16204_DIAG_STAT_FLASH_UPT)
330 dev_err(dev, "Flash update failed\n");
331 if (status & ADIS16204_DIAG_STAT_POWER_HIGH)
332 dev_err(dev, "Power supply above 3.625V\n");
333 if (status & ADIS16204_DIAG_STAT_POWER_LOW)
334 dev_err(dev, "Power supply below 2.975V\n");
335
336error_ret:
337 return ret;
338}
339
340static int adis16204_self_test(struct device *dev)
341{
342 int ret;
343 ret = adis16204_spi_write_reg_16(dev,
344 ADIS16204_MSC_CTRL,
345 ADIS16204_MSC_CTRL_SELF_TEST_EN);
346 if (ret) {
347 dev_err(dev, "problem starting self test");
348 goto err_ret;
349 }
350
351 adis16204_check_status(dev);
352
353err_ret:
354 return ret;
355}
356
357static int adis16204_initial_setup(struct adis16204_state *st)
358{
359 int ret;
360 struct device *dev = &st->indio_dev->dev;
361
362 /* Disable IRQ */
363 ret = adis16204_set_irq(dev, false);
364 if (ret) {
365 dev_err(dev, "disable irq failed");
366 goto err_ret;
367 }
368
369 /* Do self test */
370 ret = adis16204_self_test(dev);
371 if (ret) {
372 dev_err(dev, "self test failure");
373 goto err_ret;
374 }
375
376 /* Read status register to check the result */
377 ret = adis16204_check_status(dev);
378 if (ret) {
379 adis16204_reset(dev);
380 dev_err(dev, "device not playing ball -> reset");
381 msleep(ADIS16204_STARTUP_DELAY);
382 ret = adis16204_check_status(dev);
383 if (ret) {
384 dev_err(dev, "giving up");
385 goto err_ret;
386 }
387 }
388
389 printk(KERN_INFO DRIVER_NAME ": at CS%d (irq %d)\n",
390 st->us->chip_select, st->us->irq);
391
392err_ret:
393 return ret;
394}
395
396static IIO_DEV_ATTR_IN_NAMED_RAW(0, supply, adis16204_read_12bit_unsigned,
397 ADIS16204_SUPPLY_OUT);
398static IIO_CONST_ATTR(in0_supply_scale, "0.00122");
399static IIO_DEV_ATTR_IN_RAW(1, adis16204_read_12bit_unsigned,
400 ADIS16204_AUX_ADC);
401static IIO_CONST_ATTR(in1_scale, "0.00061");
402
403static IIO_DEV_ATTR_ACCEL_X(adis16204_read_14bit_signed,
404 ADIS16204_XACCL_OUT);
405static IIO_DEV_ATTR_ACCEL_Y(adis16204_read_14bit_signed,
406 ADIS16204_YACCL_OUT);
407static IIO_DEV_ATTR_ACCEL_XY(adis16204_read_14bit_signed,
408 ADIS16204_XY_RSS_OUT);
409static IIO_DEV_ATTR_ACCEL_XPEAK(adis16204_read_14bit_signed,
410 ADIS16204_X_PEAK_OUT);
411static IIO_DEV_ATTR_ACCEL_YPEAK(adis16204_read_14bit_signed,
412 ADIS16204_Y_PEAK_OUT);
413static IIO_DEV_ATTR_ACCEL_XYPEAK(adis16204_read_14bit_signed,
414 ADIS16204_XY_PEAK_OUT);
415static IIO_DEV_ATTR_ACCEL_X_OFFSET(S_IWUSR | S_IRUGO,
416 adis16204_read_12bit_signed,
417 adis16204_write_16bit,
418 ADIS16204_XACCL_NULL);
419static IIO_DEV_ATTR_ACCEL_Y_OFFSET(S_IWUSR | S_IRUGO,
420 adis16204_read_12bit_signed,
421 adis16204_write_16bit,
422 ADIS16204_YACCL_NULL);
423static IIO_CONST_ATTR(accel_x_scale, "0.017125");
424static IIO_CONST_ATTR(accel_y_scale, "0.008407");
425static IIO_CONST_ATTR(accel_xy_scale, "0.017125");
426
427static IIO_DEV_ATTR_TEMP_RAW(adis16204_read_temp);
428static IIO_CONST_ATTR(temp_offset, "25");
429static IIO_CONST_ATTR(temp_scale, "-0.47");
430
431static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, adis16204_write_reset, 0);
432
433static IIO_CONST_ATTR(name, "adis16204");
434
435static struct attribute *adis16204_event_attributes[] = {
436 NULL
437};
438
439static struct attribute_group adis16204_event_attribute_group = {
440 .attrs = adis16204_event_attributes,
441};
442
443static struct attribute *adis16204_attributes[] = {
444 &iio_dev_attr_in0_supply_raw.dev_attr.attr,
445 &iio_const_attr_in0_supply_scale.dev_attr.attr,
446 &iio_dev_attr_temp_raw.dev_attr.attr,
447 &iio_const_attr_temp_offset.dev_attr.attr,
448 &iio_const_attr_temp_scale.dev_attr.attr,
449 &iio_dev_attr_reset.dev_attr.attr,
450 &iio_const_attr_name.dev_attr.attr,
451 &iio_dev_attr_in1_raw.dev_attr.attr,
452 &iio_const_attr_in1_scale.dev_attr.attr,
453 &iio_dev_attr_accel_x_raw.dev_attr.attr,
454 &iio_dev_attr_accel_y_raw.dev_attr.attr,
455 &iio_dev_attr_accel_xy.dev_attr.attr,
456 &iio_dev_attr_accel_xpeak.dev_attr.attr,
457 &iio_dev_attr_accel_ypeak.dev_attr.attr,
458 &iio_dev_attr_accel_xypeak.dev_attr.attr,
459 &iio_dev_attr_accel_x_offset.dev_attr.attr,
460 &iio_dev_attr_accel_y_offset.dev_attr.attr,
461 &iio_const_attr_accel_x_scale.dev_attr.attr,
462 &iio_const_attr_accel_y_scale.dev_attr.attr,
463 &iio_const_attr_accel_xy_scale.dev_attr.attr,
464 NULL
465};
466
467static const struct attribute_group adis16204_attribute_group = {
468 .attrs = adis16204_attributes,
469};
470
471static int __devinit adis16204_probe(struct spi_device *spi)
472{
473 int ret, regdone = 0;
474 struct adis16204_state *st = kzalloc(sizeof *st, GFP_KERNEL);
475 if (!st) {
476 ret = -ENOMEM;
477 goto error_ret;
478 }
479 /* this is only used for removal purposes */
480 spi_set_drvdata(spi, st);
481
482 /* Allocate the comms buffers */
483 st->rx = kzalloc(sizeof(*st->rx)*ADIS16204_MAX_RX, GFP_KERNEL);
484 if (st->rx == NULL) {
485 ret = -ENOMEM;
486 goto error_free_st;
487 }
488 st->tx = kzalloc(sizeof(*st->tx)*ADIS16204_MAX_TX, GFP_KERNEL);
489 if (st->tx == NULL) {
490 ret = -ENOMEM;
491 goto error_free_rx;
492 }
493 st->us = spi;
494 mutex_init(&st->buf_lock);
495 /* setup the industrialio driver allocated elements */
496 st->indio_dev = iio_allocate_device();
497 if (st->indio_dev == NULL) {
498 ret = -ENOMEM;
499 goto error_free_tx;
500 }
501
502 st->indio_dev->dev.parent = &spi->dev;
503 st->indio_dev->num_interrupt_lines = 1;
504 st->indio_dev->event_attrs = &adis16204_event_attribute_group;
505 st->indio_dev->attrs = &adis16204_attribute_group;
506 st->indio_dev->dev_data = (void *)(st);
507 st->indio_dev->driver_module = THIS_MODULE;
508 st->indio_dev->modes = INDIO_DIRECT_MODE;
509
510 ret = adis16204_configure_ring(st->indio_dev);
511 if (ret)
512 goto error_free_dev;
513
514 ret = iio_device_register(st->indio_dev);
515 if (ret)
516 goto error_unreg_ring_funcs;
517 regdone = 1;
518
519 ret = adis16204_initialize_ring(st->indio_dev->ring);
520 if (ret) {
521 printk(KERN_ERR "failed to initialize the ring\n");
522 goto error_unreg_ring_funcs;
523 }
524
525 if (spi->irq) {
526 ret = iio_register_interrupt_line(spi->irq,
527 st->indio_dev,
528 0,
529 IRQF_TRIGGER_RISING,
530 "adis16204");
531 if (ret)
532 goto error_uninitialize_ring;
533
534 ret = adis16204_probe_trigger(st->indio_dev);
535 if (ret)
536 goto error_unregister_line;
537 }
538
539 /* Get the device into a sane initial state */
540 ret = adis16204_initial_setup(st);
541 if (ret)
542 goto error_remove_trigger;
543 return 0;
544
545error_remove_trigger:
546 adis16204_remove_trigger(st->indio_dev);
547error_unregister_line:
548 if (spi->irq)
549 iio_unregister_interrupt_line(st->indio_dev, 0);
550error_uninitialize_ring:
551 adis16204_uninitialize_ring(st->indio_dev->ring);
552error_unreg_ring_funcs:
553 adis16204_unconfigure_ring(st->indio_dev);
554error_free_dev:
555 if (regdone)
556 iio_device_unregister(st->indio_dev);
557 else
558 iio_free_device(st->indio_dev);
559error_free_tx:
560 kfree(st->tx);
561error_free_rx:
562 kfree(st->rx);
563error_free_st:
564 kfree(st);
565error_ret:
566 return ret;
567}
568
569static int adis16204_remove(struct spi_device *spi)
570{
571 struct adis16204_state *st = spi_get_drvdata(spi);
572 struct iio_dev *indio_dev = st->indio_dev;
573
574 flush_scheduled_work();
575
576 adis16204_remove_trigger(indio_dev);
577 if (spi->irq)
578 iio_unregister_interrupt_line(indio_dev, 0);
579
580 adis16204_uninitialize_ring(indio_dev->ring);
581 iio_device_unregister(indio_dev);
582 adis16204_unconfigure_ring(indio_dev);
583 kfree(st->tx);
584 kfree(st->rx);
585 kfree(st);
586
587 return 0;
588}
589
590static struct spi_driver adis16204_driver = {
591 .driver = {
592 .name = "adis16204",
593 .owner = THIS_MODULE,
594 },
595 .probe = adis16204_probe,
596 .remove = __devexit_p(adis16204_remove),
597};
598
599static __init int adis16204_init(void)
600{
601 return spi_register_driver(&adis16204_driver);
602}
603module_init(adis16204_init);
604
605static __exit void adis16204_exit(void)
606{
607 spi_unregister_driver(&adis16204_driver);
608}
609module_exit(adis16204_exit);
610
611MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
612MODULE_DESCRIPTION("Analog Devices ADIS16204 Programmable High-g Digital Impact Sensor and Recorder");
613MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/accel/adis16204_ring.c b/drivers/staging/iio/accel/adis16204_ring.c
new file mode 100644
index 000000000000..420b160fe3ab
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16204_ring.c
@@ -0,0 +1,206 @@
1#include <linux/interrupt.h>
2#include <linux/irq.h>
3#include <linux/gpio.h>
4#include <linux/workqueue.h>
5#include <linux/mutex.h>
6#include <linux/device.h>
7#include <linux/kernel.h>
8#include <linux/spi/spi.h>
9#include <linux/slab.h>
10#include <linux/sysfs.h>
11#include <linux/list.h>
12
13#include "../iio.h"
14#include "../sysfs.h"
15#include "../ring_sw.h"
16#include "accel.h"
17#include "../trigger.h"
18#include "adis16204.h"
19
20static IIO_SCAN_EL_C(in_supply, ADIS16204_SCAN_SUPPLY, ADIS16204_SUPPLY_OUT, NULL);
21static IIO_CONST_ATTR_SCAN_EL_TYPE(in_supply, u, 12, 16);
22static IIO_SCAN_EL_C(accel_x, ADIS16204_SCAN_ACC_X, ADIS16204_XACCL_OUT, NULL);
23static IIO_SCAN_EL_C(accel_y, ADIS16204_SCAN_ACC_Y, ADIS16204_YACCL_OUT, NULL);
24static IIO_CONST_ATTR_SCAN_EL_TYPE(accel, s, 14, 16);
25static IIO_SCAN_EL_C(in0, ADIS16204_SCAN_AUX_ADC, ADIS16204_AUX_ADC, NULL);
26static IIO_CONST_ATTR_SCAN_EL_TYPE(in0, u, 12, 16);
27static IIO_SCAN_EL_C(temp, ADIS16204_SCAN_TEMP, ADIS16204_TEMP_OUT, NULL);
28static IIO_CONST_ATTR_SCAN_EL_TYPE(temp, u, 12, 16);
29static IIO_SCAN_EL_TIMESTAMP(5);
30static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
31
32static struct attribute *adis16204_scan_el_attrs[] = {
33 &iio_scan_el_in_supply.dev_attr.attr,
34 &iio_const_attr_in_supply_index.dev_attr.attr,
35 &iio_const_attr_in_supply_type.dev_attr.attr,
36 &iio_scan_el_accel_x.dev_attr.attr,
37 &iio_const_attr_accel_x_index.dev_attr.attr,
38 &iio_scan_el_accel_y.dev_attr.attr,
39 &iio_const_attr_accel_y_index.dev_attr.attr,
40 &iio_const_attr_accel_type.dev_attr.attr,
41 &iio_scan_el_in0.dev_attr.attr,
42 &iio_const_attr_in0_index.dev_attr.attr,
43 &iio_const_attr_in0_type.dev_attr.attr,
44 &iio_scan_el_temp.dev_attr.attr,
45 &iio_const_attr_temp_index.dev_attr.attr,
46 &iio_const_attr_temp_type.dev_attr.attr,
47 &iio_scan_el_timestamp.dev_attr.attr,
48 &iio_const_attr_timestamp_index.dev_attr.attr,
49 &iio_const_attr_timestamp_type.dev_attr.attr,
50 NULL,
51};
52
53static struct attribute_group adis16204_scan_el_group = {
54 .attrs = adis16204_scan_el_attrs,
55 .name = "scan_elements",
56};
57
58/**
59 * adis16204_poll_func_th() top half interrupt handler called by trigger
60 * @private_data: iio_dev
61 **/
62static void adis16204_poll_func_th(struct iio_dev *indio_dev, s64 timestamp)
63{
64 struct adis16204_state *st = iio_dev_get_devdata(indio_dev);
65 st->last_timestamp = timestamp;
66 schedule_work(&st->work_trigger_to_ring);
67}
68
69/**
70 * adis16204_read_ring_data() read data registers which will be placed into ring
71 * @dev: device associated with child of actual device (iio_dev or iio_trig)
72 * @rx: somewhere to pass back the value read
73 **/
74static int adis16204_read_ring_data(struct device *dev, u8 *rx)
75{
76 struct spi_message msg;
77 struct iio_dev *indio_dev = dev_get_drvdata(dev);
78 struct adis16204_state *st = iio_dev_get_devdata(indio_dev);
79 struct spi_transfer xfers[ADIS16204_OUTPUTS + 1];
80 int ret;
81 int i;
82
83 mutex_lock(&st->buf_lock);
84
85 spi_message_init(&msg);
86
87 memset(xfers, 0, sizeof(xfers));
88 for (i = 0; i <= ADIS16204_OUTPUTS; i++) {
89 xfers[i].bits_per_word = 8;
90 xfers[i].cs_change = 1;
91 xfers[i].len = 2;
92 xfers[i].delay_usecs = 20;
93 xfers[i].tx_buf = st->tx + 2 * i;
94 st->tx[2 * i] = ADIS16204_READ_REG(ADIS16204_SUPPLY_OUT + 2 * i);
95 st->tx[2 * i + 1] = 0;
96 if (i >= 1)
97 xfers[i].rx_buf = rx + 2 * (i - 1);
98 spi_message_add_tail(&xfers[i], &msg);
99 }
100
101 ret = spi_sync(st->us, &msg);
102 if (ret)
103 dev_err(&st->us->dev, "problem when burst reading");
104
105 mutex_unlock(&st->buf_lock);
106
107 return ret;
108}
109
110/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
111 * specific to be rolled into the core.
112 */
113static void adis16204_trigger_bh_to_ring(struct work_struct *work_s)
114{
115 struct adis16204_state *st
116 = container_of(work_s, struct adis16204_state,
117 work_trigger_to_ring);
118 struct iio_ring_buffer *ring = st->indio_dev->ring;
119
120 int i = 0;
121 s16 *data;
122 size_t datasize = ring->access.get_bytes_per_datum(ring);
123
124 data = kmalloc(datasize, GFP_KERNEL);
125 if (data == NULL) {
126 dev_err(&st->us->dev, "memory alloc failed in ring bh");
127 return;
128 }
129
130 if (ring->scan_count)
131 if (adis16204_read_ring_data(&st->indio_dev->dev, st->rx) >= 0)
132 for (; i < ring->scan_count; i++)
133 data[i] = be16_to_cpup(
134 (__be16 *)&(st->rx[i*2]));
135
136 /* Guaranteed to be aligned with 8 byte boundary */
137 if (ring->scan_timestamp)
138 *((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp;
139
140 ring->access.store_to(ring,
141 (u8 *)data,
142 st->last_timestamp);
143
144 iio_trigger_notify_done(st->indio_dev->trig);
145 kfree(data);
146
147 return;
148}
149
150void adis16204_unconfigure_ring(struct iio_dev *indio_dev)
151{
152 kfree(indio_dev->pollfunc);
153 iio_sw_rb_free(indio_dev->ring);
154}
155
156int adis16204_configure_ring(struct iio_dev *indio_dev)
157{
158 int ret = 0;
159 struct adis16204_state *st = indio_dev->dev_data;
160 struct iio_ring_buffer *ring;
161 INIT_WORK(&st->work_trigger_to_ring, adis16204_trigger_bh_to_ring);
162
163 ring = iio_sw_rb_allocate(indio_dev);
164 if (!ring) {
165 ret = -ENOMEM;
166 return ret;
167 }
168 indio_dev->ring = ring;
169 /* Effectively select the ring buffer implementation */
170 iio_ring_sw_register_funcs(&ring->access);
171 ring->bpe = 2;
172 ring->scan_el_attrs = &adis16204_scan_el_group;
173 ring->scan_timestamp = true;
174 ring->preenable = &iio_sw_ring_preenable;
175 ring->postenable = &iio_triggered_ring_postenable;
176 ring->predisable = &iio_triggered_ring_predisable;
177 ring->owner = THIS_MODULE;
178
179 /* Set default scan mode */
180 iio_scan_mask_set(ring, iio_scan_el_in_supply.number);
181 iio_scan_mask_set(ring, iio_scan_el_accel_x.number);
182 iio_scan_mask_set(ring, iio_scan_el_accel_y.number);
183 iio_scan_mask_set(ring, iio_scan_el_temp.number);
184 iio_scan_mask_set(ring, iio_scan_el_in0.number);
185
186 ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16204_poll_func_th);
187 if (ret)
188 goto error_iio_sw_rb_free;
189
190 indio_dev->modes |= INDIO_RING_TRIGGERED;
191 return 0;
192
193error_iio_sw_rb_free:
194 iio_sw_rb_free(indio_dev->ring);
195 return ret;
196}
197
198int adis16204_initialize_ring(struct iio_ring_buffer *ring)
199{
200 return iio_ring_buffer_register(ring, 0);
201}
202
203void adis16204_uninitialize_ring(struct iio_ring_buffer *ring)
204{
205 iio_ring_buffer_unregister(ring);
206}
diff --git a/drivers/staging/iio/accel/adis16204_trigger.c b/drivers/staging/iio/accel/adis16204_trigger.c
new file mode 100644
index 000000000000..8e9db90e51eb
--- /dev/null
+++ b/drivers/staging/iio/accel/adis16204_trigger.c
@@ -0,0 +1,122 @@
1#include <linux/interrupt.h>
2#include <linux/irq.h>
3#include <linux/mutex.h>
4#include <linux/device.h>
5#include <linux/kernel.h>
6#include <linux/sysfs.h>
7#include <linux/list.h>
8#include <linux/spi/spi.h>
9
10#include "../iio.h"
11#include "../sysfs.h"
12#include "../trigger.h"
13#include "adis16204.h"
14
15/**
16 * adis16204_data_rdy_trig_poll() the event handler for the data rdy trig
17 **/
18static int adis16204_data_rdy_trig_poll(struct iio_dev *dev_info,
19 int index,
20 s64 timestamp,
21 int no_test)
22{
23 struct adis16204_state *st = iio_dev_get_devdata(dev_info);
24 struct iio_trigger *trig = st->trig;
25
26 iio_trigger_poll(trig, timestamp);
27
28 return IRQ_HANDLED;
29}
30
31IIO_EVENT_SH(data_rdy_trig, &adis16204_data_rdy_trig_poll);
32
33static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);
34
35static struct attribute *adis16204_trigger_attrs[] = {
36 &dev_attr_name.attr,
37 NULL,
38};
39
40static const struct attribute_group adis16204_trigger_attr_group = {
41 .attrs = adis16204_trigger_attrs,
42};
43
44/**
45 * adis16204_data_rdy_trigger_set_state() set datardy interrupt state
46 **/
47static int adis16204_data_rdy_trigger_set_state(struct iio_trigger *trig,
48 bool state)
49{
50 struct adis16204_state *st = trig->private_data;
51 struct iio_dev *indio_dev = st->indio_dev;
52 int ret = 0;
53
54 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
55 ret = adis16204_set_irq(&st->indio_dev->dev, state);
56 if (state == false) {
57 iio_remove_event_from_list(&iio_event_data_rdy_trig,
58 &indio_dev->interrupts[0]
59 ->ev_list);
60 flush_scheduled_work();
61 } else {
62 iio_add_event_to_list(&iio_event_data_rdy_trig,
63 &indio_dev->interrupts[0]->ev_list);
64 }
65 return ret;
66}
67
68/**
69 * adis16204_trig_try_reen() try renabling irq for data rdy trigger
70 * @trig: the datardy trigger
71 **/
72static int adis16204_trig_try_reen(struct iio_trigger *trig)
73{
74 struct adis16204_state *st = trig->private_data;
75 enable_irq(st->us->irq);
76 return 0;
77}
78
79int adis16204_probe_trigger(struct iio_dev *indio_dev)
80{
81 int ret;
82 struct adis16204_state *st = indio_dev->dev_data;
83
84 st->trig = iio_allocate_trigger();
85 st->trig->name = kasprintf(GFP_KERNEL,
86 "adis16204-dev%d",
87 indio_dev->id);
88 if (!st->trig->name) {
89 ret = -ENOMEM;
90 goto error_free_trig;
91 }
92 st->trig->dev.parent = &st->us->dev;
93 st->trig->owner = THIS_MODULE;
94 st->trig->private_data = st;
95 st->trig->set_trigger_state = &adis16204_data_rdy_trigger_set_state;
96 st->trig->try_reenable = &adis16204_trig_try_reen;
97 st->trig->control_attrs = &adis16204_trigger_attr_group;
98 ret = iio_trigger_register(st->trig);
99
100 /* select default trigger */
101 indio_dev->trig = st->trig;
102 if (ret)
103 goto error_free_trig_name;
104
105 return 0;
106
107error_free_trig_name:
108 kfree(st->trig->name);
109error_free_trig:
110 iio_free_trigger(st->trig);
111
112 return ret;
113}
114
115void adis16204_remove_trigger(struct iio_dev *indio_dev)
116{
117 struct adis16204_state *state = indio_dev->dev_data;
118
119 iio_trigger_unregister(state->trig);
120 kfree(state->trig->name);
121 iio_free_trigger(state->trig);
122}
diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c
index 033135c6f226..8eba0af98ed5 100644
--- a/drivers/staging/iio/accel/adis16209_ring.c
+++ b/drivers/staging/iio/accel/adis16209_ring.c
@@ -105,7 +105,7 @@ static int adis16209_read_ring_data(struct device *dev, u8 *rx)
105 xfers[i].bits_per_word = 8; 105 xfers[i].bits_per_word = 8;
106 xfers[i].cs_change = 1; 106 xfers[i].cs_change = 1;
107 xfers[i].len = 2; 107 xfers[i].len = 2;
108 xfers[i].delay_usecs = 20; 108 xfers[i].delay_usecs = 30;
109 xfers[i].tx_buf = st->tx + 2 * i; 109 xfers[i].tx_buf = st->tx + 2 * i;
110 st->tx[2 * i] 110 st->tx[2 * i]
111 = ADIS16209_READ_REG(ADIS16209_SUPPLY_OUT + 2 * i); 111 = ADIS16209_READ_REG(ADIS16209_SUPPLY_OUT + 2 * i);
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index 330d5d6dbba4..1fd088a11076 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -517,7 +517,7 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev)
517 517
518 ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th); 518 ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th);
519 if (ret) 519 if (ret)
520 goto error_iio_sw_rb_free;; 520 goto error_iio_sw_rb_free;
521 indio_dev->modes |= INDIO_RING_TRIGGERED; 521 indio_dev->modes |= INDIO_RING_TRIGGERED;
522 return 0; 522 return 0;
523 523
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index acb67677e563..86869cd233ae 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -27,6 +27,41 @@ config MAX1363_RING_BUFFER
27 Say yes here to include ring buffer support in the MAX1363 27 Say yes here to include ring buffer support in the MAX1363
28 ADC driver. 28 ADC driver.
29 29
30config AD7150
31 tristate "Analog Devices ad7150/1/6 capacitive sensor driver"
32 depends on I2C
33 help
34 Say yes here to build support for Analog Devices capacitive sensors.
35 (ad7150, ad7151, ad7156) Provides direct access via sysfs.
36
37config AD7152
38 tristate "Analog Devices ad7152/3 capacitive sensor driver"
39 depends on I2C
40 help
41 Say yes here to build support for Analog Devices capacitive sensors.
42 (ad7152, ad7153) Provides direct access via sysfs.
43
44config AD7291
45 tristate "Analog Devices AD7291 temperature sensor driver"
46 depends on I2C
47 help
48 Say yes here to build support for Analog Devices AD7291
49 temperature sensors.
50
51config AD7298
52 tristate "Analog Devices AD7298 temperature sensor and ADC driver"
53 depends on SPI
54 help
55 Say yes here to build support for Analog Devices AD7298
56 temperature sensors and ADC.
57
58config AD7314
59 tristate "Analog Devices AD7314 temperature sensor driver"
60 depends on SPI
61 help
62 Say yes here to build support for Analog Devices AD7314
63 temperature sensors.
64
30config AD799X 65config AD799X
31 tristate "Analog Devices AD799x ADC driver" 66 tristate "Analog Devices AD799x ADC driver"
32 depends on I2C 67 depends on I2C
@@ -50,9 +85,9 @@ config AD799X_RING_BUFFER
50config AD7476 85config AD7476
51 tristate "Analog Devices AD7475/6/7/8 AD7466/7/8 and AD7495 ADC driver" 86 tristate "Analog Devices AD7475/6/7/8 AD7466/7/8 and AD7495 ADC driver"
52 depends on SPI 87 depends on SPI
53 select IIO_RING_BUFFER 88 select IIO_RING_BUFFER
54 select IIO_SW_RING 89 select IIO_SW_RING
55 select IIO_TRIGGER 90 select IIO_TRIGGER
56 help 91 help
57 Say yes here to build support for Analog Devices 92 Say yes here to build support for Analog Devices
58 AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, AD7495 93 AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, AD7495
@@ -61,3 +96,55 @@ config AD7476
61 96
62 To compile this driver as a module, choose M here: the 97 To compile this driver as a module, choose M here: the
63 module will be called ad7476. 98 module will be called ad7476.
99
100config AD7887
101 tristate "Analog Devices AD7887 ADC driver"
102 depends on SPI
103 select IIO_RING_BUFFER
104 select IIO_SW_RING
105 select IIO_TRIGGER
106 help
107 Say yes here to build support for Analog Devices
108 AD7887 SPI analog to digital convertor (ADC).
109 If unsure, say N (but it's safe to say "Y").
110
111 To compile this driver as a module, choose M here: the
112 module will be called ad7887.
113
114config AD7745
115 tristate "Analog Devices AD7745, AD7746 AD7747 capacitive sensor driver"
116 depends on I2C
117 help
118 Say yes here to build support for Analog Devices capacitive sensors.
119 (AD7745, AD7746, AD7747) Provides direct access via sysfs.
120
121 To compile this driver as a module, choose M here: the
122 module will be called ad7745.
123
124config AD7816
125 tristate "Analog Devices AD7816/7/8 temperature sensor and ADC driver"
126 depends on SPI
127 help
128 Say yes here to build support for Analog Devices AD7816/7/8
129 temperature sensors and ADC.
130
131config ADT75
132 tristate "Analog Devices ADT75 temperature sensor driver"
133 depends on I2C
134 help
135 Say yes here to build support for Analog Devices ADT75
136 temperature sensors.
137
138config ADT7310
139 tristate "Analog Devices ADT7310 temperature sensor driver"
140 depends on SPI
141 help
142 Say yes here to build support for Analog Devices ADT7310
143 temperature sensors.
144
145config ADT7410
146 tristate "Analog Devices ADT7410 temperature sensor driver"
147 depends on I2C
148 help
149 Say yes here to build support for Analog Devices ADT7410
150 temperature sensors.
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index b62c319bcedd..6f231a2cb777 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -14,3 +14,18 @@ obj-$(CONFIG_AD799X) += ad799x.o
14ad7476-y := ad7476_core.o 14ad7476-y := ad7476_core.o
15ad7476-$(CONFIG_IIO_RING_BUFFER) += ad7476_ring.o 15ad7476-$(CONFIG_IIO_RING_BUFFER) += ad7476_ring.o
16obj-$(CONFIG_AD7476) += ad7476.o 16obj-$(CONFIG_AD7476) += ad7476.o
17
18ad7887-y := ad7887_core.o
19ad7887-$(CONFIG_IIO_RING_BUFFER) += ad7887_ring.o
20obj-$(CONFIG_AD7887) += ad7887.o
21
22obj-$(CONFIG_AD7150) += ad7150.o
23obj-$(CONFIG_AD7152) += ad7152.o
24obj-$(CONFIG_AD7291) += ad7291.o
25obj-$(CONFIG_AD7298) += ad7298.o
26obj-$(CONFIG_AD7314) += ad7314.o
27obj-$(CONFIG_AD7745) += ad7745.o
28obj-$(CONFIG_AD7816) += ad7816.o
29obj-$(CONFIG_ADT75) += adt75.o
30obj-$(CONFIG_ADT7310) += adt7310.o
31obj-$(CONFIG_ADT7410) += adt7410.o
diff --git a/drivers/staging/iio/adc/ad7150.c b/drivers/staging/iio/adc/ad7150.c
new file mode 100644
index 000000000000..8555766109d8
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7150.c
@@ -0,0 +1,877 @@
1/*
2 * AD7150 capacitive sensor driver supporting AD7150/1/6
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/workqueue.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/sysfs.h>
16#include <linux/list.h>
17#include <linux/i2c.h>
18#include <linux/rtc.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23/*
24 * AD7150 registers definition
25 */
26
27#define AD7150_STATUS 0
28#define AD7150_STATUS_OUT1 (1 << 3)
29#define AD7150_STATUS_OUT2 (1 << 5)
30#define AD7150_CH1_DATA_HIGH 1
31#define AD7150_CH1_DATA_LOW 2
32#define AD7150_CH2_DATA_HIGH 3
33#define AD7150_CH2_DATA_LOW 4
34#define AD7150_CH1_AVG_HIGH 5
35#define AD7150_CH1_AVG_LOW 6
36#define AD7150_CH2_AVG_HIGH 7
37#define AD7150_CH2_AVG_LOW 8
38#define AD7150_CH1_SENSITIVITY 9
39#define AD7150_CH1_THR_HOLD_H 9
40#define AD7150_CH1_TIMEOUT 10
41#define AD7150_CH1_THR_HOLD_L 10
42#define AD7150_CH1_SETUP 11
43#define AD7150_CH2_SENSITIVITY 12
44#define AD7150_CH2_THR_HOLD_H 12
45#define AD7150_CH2_TIMEOUT 13
46#define AD7150_CH2_THR_HOLD_L 13
47#define AD7150_CH2_SETUP 14
48#define AD7150_CFG 15
49#define AD7150_CFG_FIX (1 << 7)
50#define AD7150_PD_TIMER 16
51#define AD7150_CH1_CAPDAC 17
52#define AD7150_CH2_CAPDAC 18
53#define AD7150_SN3 19
54#define AD7150_SN2 20
55#define AD7150_SN1 21
56#define AD7150_SN0 22
57#define AD7150_ID 23
58
59#define AD7150_MAX_CONV_MODE 4
60
61/*
62 * struct ad7150_chip_info - chip specifc information
63 */
64
65struct ad7150_chip_info {
66 const char *name;
67 struct i2c_client *client;
68 struct iio_dev *indio_dev;
69 struct work_struct thresh_work;
70 bool inter;
71 s64 last_timestamp;
72 u16 ch1_threshold; /* Ch1 Threshold (in fixed threshold mode) */
73 u8 ch1_sensitivity; /* Ch1 Sensitivity (in adaptive threshold mode) */
74 u8 ch1_timeout; /* Ch1 Timeout (in adaptive threshold mode) */
75 u8 ch1_setup;
76 u16 ch2_threshold; /* Ch2 Threshold (in fixed threshold mode) */
77 u8 ch2_sensitivity; /* Ch1 Sensitivity (in adaptive threshold mode) */
78 u8 ch2_timeout; /* Ch1 Timeout (in adaptive threshold mode) */
79 u8 ch2_setup;
80 u8 powerdown_timer;
81 char threshold_mode[10]; /* adaptive/fixed threshold mode */
82 int old_state;
83 char *conversion_mode;
84};
85
86struct ad7150_conversion_mode {
87 char *name;
88 u8 reg_cfg;
89};
90
91struct ad7150_conversion_mode ad7150_conv_mode_table[AD7150_MAX_CONV_MODE] = {
92 { "idle", 0 },
93 { "continuous-conversion", 1 },
94 { "single-conversion", 2 },
95 { "power-down", 3 },
96};
97
98/*
99 * ad7150 register access by I2C
100 */
101
102static int ad7150_i2c_read(struct ad7150_chip_info *chip, u8 reg, u8 *data, int len)
103{
104 struct i2c_client *client = chip->client;
105 int ret = 0;
106
107 ret = i2c_master_send(client, &reg, 1);
108 if (ret < 0) {
109 dev_err(&client->dev, "I2C write error\n");
110 return ret;
111 }
112
113 ret = i2c_master_recv(client, data, len);
114 if (ret < 0) {
115 dev_err(&client->dev, "I2C read error\n");
116 return ret;
117 }
118
119 return ret;
120}
121
122static int ad7150_i2c_write(struct ad7150_chip_info *chip, u8 reg, u8 data)
123{
124 struct i2c_client *client = chip->client;
125 int ret = 0;
126
127 u8 tx[2] = {
128 reg,
129 data,
130 };
131
132 ret = i2c_master_send(client, tx, 2);
133 if (ret < 0)
134 dev_err(&client->dev, "I2C write error\n");
135
136 return ret;
137}
138
139/*
140 * sysfs nodes
141 */
142
143#define IIO_DEV_ATTR_AVAIL_CONVERSION_MODES(_show) \
144 IIO_DEVICE_ATTR(available_conversion_modes, S_IRUGO, _show, NULL, 0)
145#define IIO_DEV_ATTR_CONVERSION_MODE(_mode, _show, _store) \
146 IIO_DEVICE_ATTR(conversion_mode, _mode, _show, _store, 0)
147#define IIO_DEV_ATTR_AVAIL_THRESHOLD_MODES(_show) \
148 IIO_DEVICE_ATTR(available_threshold_modes, S_IRUGO, _show, NULL, 0)
149#define IIO_DEV_ATTR_THRESHOLD_MODE(_mode, _show, _store) \
150 IIO_DEVICE_ATTR(threshold_mode, _mode, _show, _store, 0)
151#define IIO_DEV_ATTR_CH1_THRESHOLD(_mode, _show, _store) \
152 IIO_DEVICE_ATTR(ch1_threshold, _mode, _show, _store, 0)
153#define IIO_DEV_ATTR_CH2_THRESHOLD(_mode, _show, _store) \
154 IIO_DEVICE_ATTR(ch2_threshold, _mode, _show, _store, 0)
155#define IIO_DEV_ATTR_CH1_SENSITIVITY(_mode, _show, _store) \
156 IIO_DEVICE_ATTR(ch1_sensitivity, _mode, _show, _store, 0)
157#define IIO_DEV_ATTR_CH2_SENSITIVITY(_mode, _show, _store) \
158 IIO_DEVICE_ATTR(ch2_sensitivity, _mode, _show, _store, 0)
159#define IIO_DEV_ATTR_CH1_TIMEOUT(_mode, _show, _store) \
160 IIO_DEVICE_ATTR(ch1_timeout, _mode, _show, _store, 0)
161#define IIO_DEV_ATTR_CH2_TIMEOUT(_mode, _show, _store) \
162 IIO_DEVICE_ATTR(ch2_timeout, _mode, _show, _store, 0)
163#define IIO_DEV_ATTR_CH1_VALUE(_show) \
164 IIO_DEVICE_ATTR(ch1_value, S_IRUGO, _show, NULL, 0)
165#define IIO_DEV_ATTR_CH2_VALUE(_show) \
166 IIO_DEVICE_ATTR(ch2_value, S_IRUGO, _show, NULL, 0)
167#define IIO_DEV_ATTR_CH1_SETUP(_mode, _show, _store) \
168 IIO_DEVICE_ATTR(ch1_setup, _mode, _show, _store, 0)
169#define IIO_DEV_ATTR_CH2_SETUP(_mode, _show, _store) \
170 IIO_DEVICE_ATTR(ch2_setup, _mode, _show, _store, 0)
171#define IIO_DEV_ATTR_POWERDOWN_TIMER(_mode, _show, _store) \
172 IIO_DEVICE_ATTR(powerdown_timer, _mode, _show, _store, 0)
173
174static ssize_t ad7150_show_conversion_modes(struct device *dev,
175 struct device_attribute *attr,
176 char *buf)
177{
178 int i;
179 int len = 0;
180
181 for (i = 0; i < AD7150_MAX_CONV_MODE; i++)
182 len += sprintf(buf + len, "%s\n", ad7150_conv_mode_table[i].name);
183
184 return len;
185}
186
187static IIO_DEV_ATTR_AVAIL_CONVERSION_MODES(ad7150_show_conversion_modes);
188
189static ssize_t ad7150_show_conversion_mode(struct device *dev,
190 struct device_attribute *attr,
191 char *buf)
192{
193 struct iio_dev *dev_info = dev_get_drvdata(dev);
194 struct ad7150_chip_info *chip = dev_info->dev_data;
195
196 return sprintf(buf, "%s\n", chip->conversion_mode);
197}
198
199static ssize_t ad7150_store_conversion_mode(struct device *dev,
200 struct device_attribute *attr,
201 const char *buf,
202 size_t len)
203{
204 struct iio_dev *dev_info = dev_get_drvdata(dev);
205 struct ad7150_chip_info *chip = dev_info->dev_data;
206 u8 cfg;
207 int i;
208
209 ad7150_i2c_read(chip, AD7150_CFG, &cfg, 1);
210
211 for (i = 0; i < AD7150_MAX_CONV_MODE; i++) {
212 if (strncmp(buf, ad7150_conv_mode_table[i].name,
213 strlen(ad7150_conv_mode_table[i].name) - 1) == 0) {
214 chip->conversion_mode = ad7150_conv_mode_table[i].name;
215 cfg |= 0x18 | ad7150_conv_mode_table[i].reg_cfg;
216 ad7150_i2c_write(chip, AD7150_CFG, cfg);
217 return len;
218 }
219 }
220
221 dev_err(dev, "not supported conversion mode\n");
222
223 return -EINVAL;
224}
225
226static IIO_DEV_ATTR_CONVERSION_MODE(S_IRUGO | S_IWUSR,
227 ad7150_show_conversion_mode,
228 ad7150_store_conversion_mode);
229
230static ssize_t ad7150_show_threshold_modes(struct device *dev,
231 struct device_attribute *attr,
232 char *buf)
233{
234 return sprintf(buf, "adaptive\nfixed\n");
235}
236
237static IIO_DEV_ATTR_AVAIL_THRESHOLD_MODES(ad7150_show_threshold_modes);
238
239static ssize_t ad7150_show_ch1_value(struct device *dev,
240 struct device_attribute *attr,
241 char *buf)
242{
243 struct iio_dev *dev_info = dev_get_drvdata(dev);
244 struct ad7150_chip_info *chip = dev_info->dev_data;
245 u8 data[2];
246
247 ad7150_i2c_read(chip, AD7150_CH1_DATA_HIGH, data, 2);
248 return sprintf(buf, "%d\n", ((int) data[0] << 8) | data[1]);
249}
250
251static IIO_DEV_ATTR_CH1_VALUE(ad7150_show_ch1_value);
252
253static ssize_t ad7150_show_ch2_value(struct device *dev,
254 struct device_attribute *attr,
255 char *buf)
256{
257 struct iio_dev *dev_info = dev_get_drvdata(dev);
258 struct ad7150_chip_info *chip = dev_info->dev_data;
259 u8 data[2];
260
261 ad7150_i2c_read(chip, AD7150_CH2_DATA_HIGH, data, 2);
262 return sprintf(buf, "%d\n", ((int) data[0] << 8) | data[1]);
263}
264
265static IIO_DEV_ATTR_CH2_VALUE(ad7150_show_ch2_value);
266
267static ssize_t ad7150_show_threshold_mode(struct device *dev,
268 struct device_attribute *attr,
269 char *buf)
270{
271 struct iio_dev *dev_info = dev_get_drvdata(dev);
272 struct ad7150_chip_info *chip = dev_info->dev_data;
273
274 return sprintf(buf, "%s\n", chip->threshold_mode);
275}
276
277static ssize_t ad7150_store_threshold_mode(struct device *dev,
278 struct device_attribute *attr,
279 const char *buf,
280 size_t len)
281{
282 struct iio_dev *dev_info = dev_get_drvdata(dev);
283 struct ad7150_chip_info *chip = dev_info->dev_data;
284 u8 cfg;
285
286 ad7150_i2c_read(chip, AD7150_CFG, &cfg, 1);
287
288 if (strncmp(buf, "fixed", 5) == 0) {
289 strcpy(chip->threshold_mode, "fixed");
290 cfg |= AD7150_CFG_FIX;
291 ad7150_i2c_write(chip, AD7150_CFG, cfg);
292
293 return len;
294 } else if (strncmp(buf, "adaptive", 8) == 0) {
295 strcpy(chip->threshold_mode, "adaptive");
296 cfg &= ~AD7150_CFG_FIX;
297 ad7150_i2c_write(chip, AD7150_CFG, cfg);
298
299 return len;
300 }
301
302 dev_err(dev, "not supported threshold mode\n");
303 return -EINVAL;
304}
305
306static IIO_DEV_ATTR_THRESHOLD_MODE(S_IRUGO | S_IWUSR,
307 ad7150_show_threshold_mode,
308 ad7150_store_threshold_mode);
309
310static ssize_t ad7150_show_ch1_threshold(struct device *dev,
311 struct device_attribute *attr,
312 char *buf)
313{
314 struct iio_dev *dev_info = dev_get_drvdata(dev);
315 struct ad7150_chip_info *chip = dev_info->dev_data;
316
317 return sprintf(buf, "%d\n", chip->ch1_threshold);
318}
319
320static ssize_t ad7150_store_ch1_threshold(struct device *dev,
321 struct device_attribute *attr,
322 const char *buf,
323 size_t len)
324{
325 struct iio_dev *dev_info = dev_get_drvdata(dev);
326 struct ad7150_chip_info *chip = dev_info->dev_data;
327 unsigned long data;
328 int ret;
329
330 ret = strict_strtoul(buf, 10, &data);
331
332 if ((!ret) && (data < 0x10000)) {
333 ad7150_i2c_write(chip, AD7150_CH1_THR_HOLD_H, data >> 8);
334 ad7150_i2c_write(chip, AD7150_CH1_THR_HOLD_L, data);
335 chip->ch1_threshold = data;
336 return len;
337 }
338
339 return -EINVAL;
340}
341
342static IIO_DEV_ATTR_CH1_THRESHOLD(S_IRUGO | S_IWUSR,
343 ad7150_show_ch1_threshold,
344 ad7150_store_ch1_threshold);
345
346static ssize_t ad7150_show_ch2_threshold(struct device *dev,
347 struct device_attribute *attr,
348 char *buf)
349{
350 struct iio_dev *dev_info = dev_get_drvdata(dev);
351 struct ad7150_chip_info *chip = dev_info->dev_data;
352
353 return sprintf(buf, "%d\n", chip->ch2_threshold);
354}
355
356static ssize_t ad7150_store_ch2_threshold(struct device *dev,
357 struct device_attribute *attr,
358 const char *buf,
359 size_t len)
360{
361 struct iio_dev *dev_info = dev_get_drvdata(dev);
362 struct ad7150_chip_info *chip = dev_info->dev_data;
363 unsigned long data;
364 int ret;
365
366 ret = strict_strtoul(buf, 10, &data);
367
368 if ((!ret) && (data < 0x10000)) {
369 ad7150_i2c_write(chip, AD7150_CH2_THR_HOLD_H, data >> 8);
370 ad7150_i2c_write(chip, AD7150_CH2_THR_HOLD_L, data);
371 chip->ch2_threshold = data;
372 return len;
373 }
374
375 return -EINVAL;
376}
377
378static IIO_DEV_ATTR_CH2_THRESHOLD(S_IRUGO | S_IWUSR,
379 ad7150_show_ch2_threshold,
380 ad7150_store_ch2_threshold);
381
382static ssize_t ad7150_show_ch1_sensitivity(struct device *dev,
383 struct device_attribute *attr,
384 char *buf)
385{
386 struct iio_dev *dev_info = dev_get_drvdata(dev);
387 struct ad7150_chip_info *chip = dev_info->dev_data;
388
389 return sprintf(buf, "%d\n", chip->ch1_sensitivity);
390}
391
392static ssize_t ad7150_store_ch1_sensitivity(struct device *dev,
393 struct device_attribute *attr,
394 const char *buf,
395 size_t len)
396{
397 struct iio_dev *dev_info = dev_get_drvdata(dev);
398 struct ad7150_chip_info *chip = dev_info->dev_data;
399 unsigned long data;
400 int ret;
401
402 ret = strict_strtoul(buf, 10, &data);
403
404 if ((!ret) && (data < 0x100)) {
405 ad7150_i2c_write(chip, AD7150_CH1_SENSITIVITY, data);
406 chip->ch1_sensitivity = data;
407 return len;
408 }
409
410 return -EINVAL;
411}
412
413static IIO_DEV_ATTR_CH1_SENSITIVITY(S_IRUGO | S_IWUSR,
414 ad7150_show_ch1_sensitivity,
415 ad7150_store_ch1_sensitivity);
416
417static ssize_t ad7150_show_ch2_sensitivity(struct device *dev,
418 struct device_attribute *attr,
419 char *buf)
420{
421 struct iio_dev *dev_info = dev_get_drvdata(dev);
422 struct ad7150_chip_info *chip = dev_info->dev_data;
423
424 return sprintf(buf, "%d\n", chip->ch2_sensitivity);
425}
426
427static ssize_t ad7150_store_ch2_sensitivity(struct device *dev,
428 struct device_attribute *attr,
429 const char *buf,
430 size_t len)
431{
432 struct iio_dev *dev_info = dev_get_drvdata(dev);
433 struct ad7150_chip_info *chip = dev_info->dev_data;
434 unsigned long data;
435 int ret;
436
437 ret = strict_strtoul(buf, 10, &data);
438
439 if ((!ret) && (data < 0x100)) {
440 ad7150_i2c_write(chip, AD7150_CH2_SENSITIVITY, data);
441 chip->ch2_sensitivity = data;
442 return len;
443 }
444
445 return -EINVAL;
446}
447
448static IIO_DEV_ATTR_CH2_SENSITIVITY(S_IRUGO | S_IWUSR,
449 ad7150_show_ch2_sensitivity,
450 ad7150_store_ch2_sensitivity);
451
452static ssize_t ad7150_show_ch1_timeout(struct device *dev,
453 struct device_attribute *attr,
454 char *buf)
455{
456 struct iio_dev *dev_info = dev_get_drvdata(dev);
457 struct ad7150_chip_info *chip = dev_info->dev_data;
458
459 return sprintf(buf, "%d\n", chip->ch1_timeout);
460}
461
462static ssize_t ad7150_store_ch1_timeout(struct device *dev,
463 struct device_attribute *attr,
464 const char *buf,
465 size_t len)
466{
467 struct iio_dev *dev_info = dev_get_drvdata(dev);
468 struct ad7150_chip_info *chip = dev_info->dev_data;
469 unsigned long data;
470 int ret;
471
472 ret = strict_strtoul(buf, 10, &data);
473
474 if ((!ret) && (data < 0x100)) {
475 ad7150_i2c_write(chip, AD7150_CH1_TIMEOUT, data);
476 chip->ch1_timeout = data;
477 return len;
478 }
479
480 return -EINVAL;
481}
482
483static IIO_DEV_ATTR_CH1_TIMEOUT(S_IRUGO | S_IWUSR,
484 ad7150_show_ch1_timeout,
485 ad7150_store_ch1_timeout);
486
487static ssize_t ad7150_show_ch2_timeout(struct device *dev,
488 struct device_attribute *attr,
489 char *buf)
490{
491 struct iio_dev *dev_info = dev_get_drvdata(dev);
492 struct ad7150_chip_info *chip = dev_info->dev_data;
493
494 return sprintf(buf, "%d\n", chip->ch2_timeout);
495}
496
497static ssize_t ad7150_store_ch2_timeout(struct device *dev,
498 struct device_attribute *attr,
499 const char *buf,
500 size_t len)
501{
502 struct iio_dev *dev_info = dev_get_drvdata(dev);
503 struct ad7150_chip_info *chip = dev_info->dev_data;
504 unsigned long data;
505 int ret;
506
507 ret = strict_strtoul(buf, 10, &data);
508
509 if ((!ret) && (data < 0x100)) {
510 ad7150_i2c_write(chip, AD7150_CH2_TIMEOUT, data);
511 chip->ch2_timeout = data;
512 return len;
513 }
514
515 return -EINVAL;
516}
517
518static IIO_DEV_ATTR_CH2_TIMEOUT(S_IRUGO | S_IWUSR,
519 ad7150_show_ch2_timeout,
520 ad7150_store_ch2_timeout);
521
522static ssize_t ad7150_show_ch1_setup(struct device *dev,
523 struct device_attribute *attr,
524 char *buf)
525{
526 struct iio_dev *dev_info = dev_get_drvdata(dev);
527 struct ad7150_chip_info *chip = dev_info->dev_data;
528
529 return sprintf(buf, "0x%02x\n", chip->ch1_setup);
530}
531
532static ssize_t ad7150_store_ch1_setup(struct device *dev,
533 struct device_attribute *attr,
534 const char *buf,
535 size_t len)
536{
537 struct iio_dev *dev_info = dev_get_drvdata(dev);
538 struct ad7150_chip_info *chip = dev_info->dev_data;
539 unsigned long data;
540 int ret;
541
542 ret = strict_strtoul(buf, 10, &data);
543
544 if ((!ret) && (data < 0x100)) {
545 ad7150_i2c_write(chip, AD7150_CH1_SETUP, data);
546 chip->ch1_setup = data;
547 return len;
548 }
549
550
551 return -EINVAL;
552}
553
554static IIO_DEV_ATTR_CH1_SETUP(S_IRUGO | S_IWUSR,
555 ad7150_show_ch1_setup,
556 ad7150_store_ch1_setup);
557
558static ssize_t ad7150_show_ch2_setup(struct device *dev,
559 struct device_attribute *attr,
560 char *buf)
561{
562 struct iio_dev *dev_info = dev_get_drvdata(dev);
563 struct ad7150_chip_info *chip = dev_info->dev_data;
564
565 return sprintf(buf, "0x%02x\n", chip->ch2_setup);
566}
567
568static ssize_t ad7150_store_ch2_setup(struct device *dev,
569 struct device_attribute *attr,
570 const char *buf,
571 size_t len)
572{
573 struct iio_dev *dev_info = dev_get_drvdata(dev);
574 struct ad7150_chip_info *chip = dev_info->dev_data;
575 unsigned long data;
576 int ret;
577
578 ret = strict_strtoul(buf, 10, &data);
579
580 if ((!ret) && (data < 0x100)) {
581 ad7150_i2c_write(chip, AD7150_CH2_SETUP, data);
582 chip->ch2_setup = data;
583 return len;
584 }
585
586 return -EINVAL;
587}
588
589static IIO_DEV_ATTR_CH2_SETUP(S_IRUGO | S_IWUSR,
590 ad7150_show_ch2_setup,
591 ad7150_store_ch2_setup);
592
593static ssize_t ad7150_show_name(struct device *dev,
594 struct device_attribute *attr,
595 char *buf)
596{
597 struct iio_dev *dev_info = dev_get_drvdata(dev);
598 struct ad7150_chip_info *chip = dev_info->dev_data;
599 return sprintf(buf, "%s\n", chip->name);
600}
601
602static IIO_DEVICE_ATTR(name, S_IRUGO, ad7150_show_name, NULL, 0);
603
604static ssize_t ad7150_show_powerdown_timer(struct device *dev,
605 struct device_attribute *attr,
606 char *buf)
607{
608 struct iio_dev *dev_info = dev_get_drvdata(dev);
609 struct ad7150_chip_info *chip = dev_info->dev_data;
610
611 return sprintf(buf, "0x%02x\n", chip->powerdown_timer);
612}
613
614static ssize_t ad7150_store_powerdown_timer(struct device *dev,
615 struct device_attribute *attr,
616 const char *buf,
617 size_t len)
618{
619 struct iio_dev *dev_info = dev_get_drvdata(dev);
620 struct ad7150_chip_info *chip = dev_info->dev_data;
621 unsigned long data;
622 int ret;
623
624 ret = strict_strtoul(buf, 10, &data);
625
626 if ((!ret) && (data < 0x40)) {
627 chip->powerdown_timer = data;
628 return len;
629 }
630
631 return -EINVAL;
632}
633
634static IIO_DEV_ATTR_POWERDOWN_TIMER(S_IRUGO | S_IWUSR,
635 ad7150_show_powerdown_timer,
636 ad7150_store_powerdown_timer);
637
638static struct attribute *ad7150_attributes[] = {
639 &iio_dev_attr_available_threshold_modes.dev_attr.attr,
640 &iio_dev_attr_threshold_mode.dev_attr.attr,
641 &iio_dev_attr_ch1_threshold.dev_attr.attr,
642 &iio_dev_attr_ch2_threshold.dev_attr.attr,
643 &iio_dev_attr_ch1_timeout.dev_attr.attr,
644 &iio_dev_attr_ch2_timeout.dev_attr.attr,
645 &iio_dev_attr_ch1_setup.dev_attr.attr,
646 &iio_dev_attr_ch2_setup.dev_attr.attr,
647 &iio_dev_attr_ch1_sensitivity.dev_attr.attr,
648 &iio_dev_attr_ch2_sensitivity.dev_attr.attr,
649 &iio_dev_attr_powerdown_timer.dev_attr.attr,
650 &iio_dev_attr_ch1_value.dev_attr.attr,
651 &iio_dev_attr_ch2_value.dev_attr.attr,
652 &iio_dev_attr_name.dev_attr.attr,
653 NULL,
654};
655
656static const struct attribute_group ad7150_attribute_group = {
657 .attrs = ad7150_attributes,
658};
659
660/*
661 * threshold events
662 */
663
664#define IIO_EVENT_CODE_CH1_HIGH IIO_BUFFER_EVENT_CODE(0)
665#define IIO_EVENT_CODE_CH1_LOW IIO_BUFFER_EVENT_CODE(1)
666#define IIO_EVENT_CODE_CH2_HIGH IIO_BUFFER_EVENT_CODE(2)
667#define IIO_EVENT_CODE_CH2_LOW IIO_BUFFER_EVENT_CODE(3)
668
669#define IIO_EVENT_ATTR_CH1_HIGH_SH(_evlist, _show, _store, _mask) \
670 IIO_EVENT_ATTR_SH(ch1_high, _evlist, _show, _store, _mask)
671
672#define IIO_EVENT_ATTR_CH2_HIGH_SH(_evlist, _show, _store, _mask) \
673 IIO_EVENT_ATTR_SH(ch2_high, _evlist, _show, _store, _mask)
674
675#define IIO_EVENT_ATTR_CH1_LOW_SH(_evlist, _show, _store, _mask) \
676 IIO_EVENT_ATTR_SH(ch1_low, _evlist, _show, _store, _mask)
677
678#define IIO_EVENT_ATTR_CH2_LOW_SH(_evlist, _show, _store, _mask) \
679 IIO_EVENT_ATTR_SH(ch2_low, _evlist, _show, _store, _mask)
680
681static void ad7150_interrupt_handler_bh(struct work_struct *work_s)
682{
683 struct ad7150_chip_info *chip =
684 container_of(work_s, struct ad7150_chip_info, thresh_work);
685 u8 int_status;
686
687 enable_irq(chip->client->irq);
688
689 ad7150_i2c_read(chip, AD7150_STATUS, &int_status, 1);
690
691 if ((int_status & AD7150_STATUS_OUT1) && !(chip->old_state & AD7150_STATUS_OUT1))
692 iio_push_event(chip->indio_dev, 0,
693 IIO_EVENT_CODE_CH1_HIGH,
694 chip->last_timestamp);
695 else if ((!(int_status & AD7150_STATUS_OUT1)) && (chip->old_state & AD7150_STATUS_OUT1))
696 iio_push_event(chip->indio_dev, 0,
697 IIO_EVENT_CODE_CH1_LOW,
698 chip->last_timestamp);
699
700 if ((int_status & AD7150_STATUS_OUT2) && !(chip->old_state & AD7150_STATUS_OUT2))
701 iio_push_event(chip->indio_dev, 0,
702 IIO_EVENT_CODE_CH2_HIGH,
703 chip->last_timestamp);
704 else if ((!(int_status & AD7150_STATUS_OUT2)) && (chip->old_state & AD7150_STATUS_OUT2))
705 iio_push_event(chip->indio_dev, 0,
706 IIO_EVENT_CODE_CH2_LOW,
707 chip->last_timestamp);
708}
709
710static int ad7150_interrupt_handler_th(struct iio_dev *dev_info,
711 int index,
712 s64 timestamp,
713 int no_test)
714{
715 struct ad7150_chip_info *chip = dev_info->dev_data;
716
717 chip->last_timestamp = timestamp;
718 schedule_work(&chip->thresh_work);
719
720 return 0;
721}
722
723IIO_EVENT_SH(threshold, &ad7150_interrupt_handler_th);
724
725static ssize_t ad7150_query_out_mode(struct device *dev,
726 struct device_attribute *attr,
727 char *buf)
728{
729 /*
730 * AD7150 provides two logic output channels, which can be used as interrupt
731 * but the pins are not configurable
732 */
733 return sprintf(buf, "1\n");
734}
735
736static ssize_t ad7150_set_out_mode(struct device *dev,
737 struct device_attribute *attr,
738 const char *buf,
739 size_t len)
740{
741 return len;
742}
743
744IIO_EVENT_ATTR_CH1_HIGH_SH(iio_event_threshold, ad7150_query_out_mode, ad7150_set_out_mode, 0);
745IIO_EVENT_ATTR_CH2_HIGH_SH(iio_event_threshold, ad7150_query_out_mode, ad7150_set_out_mode, 0);
746IIO_EVENT_ATTR_CH1_LOW_SH(iio_event_threshold, ad7150_query_out_mode, ad7150_set_out_mode, 0);
747IIO_EVENT_ATTR_CH2_LOW_SH(iio_event_threshold, ad7150_query_out_mode, ad7150_set_out_mode, 0);
748
749static struct attribute *ad7150_event_attributes[] = {
750 &iio_event_attr_ch1_high.dev_attr.attr,
751 &iio_event_attr_ch2_high.dev_attr.attr,
752 &iio_event_attr_ch1_low.dev_attr.attr,
753 &iio_event_attr_ch2_low.dev_attr.attr,
754 NULL,
755};
756
757static struct attribute_group ad7150_event_attribute_group = {
758 .attrs = ad7150_event_attributes,
759};
760
761/*
762 * device probe and remove
763 */
764
765static int __devinit ad7150_probe(struct i2c_client *client,
766 const struct i2c_device_id *id)
767{
768 int ret = 0, regdone = 0;
769 struct ad7150_chip_info *chip = kzalloc(sizeof(*chip), GFP_KERNEL);
770 if (chip == NULL) {
771 ret = -ENOMEM;
772 goto error_ret;
773 }
774
775 /* this is only used for device removal purposes */
776 i2c_set_clientdata(client, chip);
777
778 chip->client = client;
779 chip->name = id->name;
780
781 chip->indio_dev = iio_allocate_device();
782 if (chip->indio_dev == NULL) {
783 ret = -ENOMEM;
784 goto error_free_chip;
785 }
786
787 /* Echipabilish that the iio_dev is a child of the i2c device */
788 chip->indio_dev->dev.parent = &client->dev;
789 chip->indio_dev->attrs = &ad7150_attribute_group;
790 chip->indio_dev->event_attrs = &ad7150_event_attribute_group;
791 chip->indio_dev->dev_data = (void *)(chip);
792 chip->indio_dev->driver_module = THIS_MODULE;
793 chip->indio_dev->num_interrupt_lines = 1;
794 chip->indio_dev->modes = INDIO_DIRECT_MODE;
795
796 ret = iio_device_register(chip->indio_dev);
797 if (ret)
798 goto error_free_dev;
799 regdone = 1;
800
801 if (client->irq && gpio_is_valid(irq_to_gpio(client->irq)) > 0) {
802 ret = iio_register_interrupt_line(client->irq,
803 chip->indio_dev,
804 0,
805 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
806 "ad7150");
807 if (ret)
808 goto error_free_dev;
809
810 iio_add_event_to_list(iio_event_attr_ch2_low.listel,
811 &chip->indio_dev->interrupts[0]->ev_list);
812
813 INIT_WORK(&chip->thresh_work, ad7150_interrupt_handler_bh);
814 }
815
816 dev_err(&client->dev, "%s capacitive sensor registered, irq: %d\n", id->name, client->irq);
817
818 return 0;
819
820error_free_dev:
821 if (regdone)
822 iio_device_unregister(chip->indio_dev);
823 else
824 iio_free_device(chip->indio_dev);
825error_free_chip:
826 kfree(chip);
827error_ret:
828 return ret;
829}
830
831static int __devexit ad7150_remove(struct i2c_client *client)
832{
833 struct ad7150_chip_info *chip = i2c_get_clientdata(client);
834 struct iio_dev *indio_dev = chip->indio_dev;
835
836 if (client->irq && gpio_is_valid(irq_to_gpio(client->irq)) > 0)
837 iio_unregister_interrupt_line(indio_dev, 0);
838 iio_device_unregister(indio_dev);
839 kfree(chip);
840
841 return 0;
842}
843
844static const struct i2c_device_id ad7150_id[] = {
845 { "ad7150", 0 },
846 { "ad7151", 0 },
847 { "ad7156", 0 },
848 {}
849};
850
851MODULE_DEVICE_TABLE(i2c, ad7150_id);
852
853static struct i2c_driver ad7150_driver = {
854 .driver = {
855 .name = "ad7150",
856 },
857 .probe = ad7150_probe,
858 .remove = __devexit_p(ad7150_remove),
859 .id_table = ad7150_id,
860};
861
862static __init int ad7150_init(void)
863{
864 return i2c_add_driver(&ad7150_driver);
865}
866
867static __exit void ad7150_exit(void)
868{
869 i2c_del_driver(&ad7150_driver);
870}
871
872MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
873MODULE_DESCRIPTION("Analog Devices ad7150/1/6 capacitive sensor driver");
874MODULE_LICENSE("GPL v2");
875
876module_init(ad7150_init);
877module_exit(ad7150_exit);
diff --git a/drivers/staging/iio/adc/ad7152.c b/drivers/staging/iio/adc/ad7152.c
new file mode 100644
index 000000000000..fa7f84062307
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7152.c
@@ -0,0 +1,610 @@
1/*
2 * AD7152 capacitive sensor driver supporting AD7152/3
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/workqueue.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/sysfs.h>
16#include <linux/list.h>
17#include <linux/i2c.h>
18#include <linux/rtc.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23/*
24 * AD7152 registers definition
25 */
26
27#define AD7152_STATUS 0
28#define AD7152_STATUS_RDY1 (1 << 0)
29#define AD7152_STATUS_RDY2 (1 << 1)
30#define AD7152_CH1_DATA_HIGH 1
31#define AD7152_CH1_DATA_LOW 2
32#define AD7152_CH2_DATA_HIGH 3
33#define AD7152_CH2_DATA_LOW 4
34#define AD7152_CH1_OFFS_HIGH 5
35#define AD7152_CH1_OFFS_LOW 6
36#define AD7152_CH2_OFFS_HIGH 7
37#define AD7152_CH2_OFFS_LOW 8
38#define AD7152_CH1_GAIN_HIGH 9
39#define AD7152_CH1_GAIN_LOW 10
40#define AD7152_CH1_SETUP 11
41#define AD7152_CH2_GAIN_HIGH 12
42#define AD7152_CH2_GAIN_LOW 13
43#define AD7152_CH2_SETUP 14
44#define AD7152_CFG 15
45#define AD7152_RESEVERD 16
46#define AD7152_CAPDAC_POS 17
47#define AD7152_CAPDAC_NEG 18
48#define AD7152_CFG2 26
49
50#define AD7152_MAX_CONV_MODE 6
51
52/*
53 * struct ad7152_chip_info - chip specifc information
54 */
55
56struct ad7152_chip_info {
57 const char *name;
58 struct i2c_client *client;
59 struct iio_dev *indio_dev;
60 u16 ch1_offset; /* Channel 1 offset calibration coefficient */
61 u16 ch1_gain; /* Channel 1 gain coefficient */
62 u8 ch1_setup;
63 u16 ch2_offset; /* Channel 2 offset calibration coefficient */
64 u16 ch2_gain; /* Channel 1 gain coefficient */
65 u8 ch2_setup;
66 u8 filter_rate_setup; /* Capacitive channel digital filter setup; conversion time/update rate setup per channel */
67 char *conversion_mode;
68};
69
70struct ad7152_conversion_mode {
71 char *name;
72 u8 reg_cfg;
73};
74
75struct ad7152_conversion_mode ad7152_conv_mode_table[AD7152_MAX_CONV_MODE] = {
76 { "idle", 0 },
77 { "continuous-conversion", 1 },
78 { "single-conversion", 2 },
79 { "power-down", 3 },
80 { "offset-calibration", 5 },
81 { "gain-calibration", 6 },
82};
83
84/*
85 * ad7152 register access by I2C
86 */
87
88static int ad7152_i2c_read(struct ad7152_chip_info *chip, u8 reg, u8 *data, int len)
89{
90 struct i2c_client *client = chip->client;
91 int ret;
92
93 ret = i2c_master_send(client, &reg, 1);
94 if (ret < 0) {
95 dev_err(&client->dev, "I2C write error\n");
96 return ret;
97 }
98
99 ret = i2c_master_recv(client, data, len);
100 if (ret < 0) {
101 dev_err(&client->dev, "I2C read error\n");
102 }
103
104 return ret;
105}
106
107static int ad7152_i2c_write(struct ad7152_chip_info *chip, u8 reg, u8 data)
108{
109 struct i2c_client *client = chip->client;
110 int ret;
111
112 u8 tx[2] = {
113 reg,
114 data,
115 };
116
117 ret = i2c_master_send(client, tx, 2);
118 if (ret < 0)
119 dev_err(&client->dev, "I2C write error\n");
120
121 return ret;
122}
123
124/*
125 * sysfs nodes
126 */
127
128#define IIO_DEV_ATTR_AVAIL_CONVERSION_MODES(_show) \
129 IIO_DEVICE_ATTR(available_conversion_modes, S_IRUGO, _show, NULL, 0)
130#define IIO_DEV_ATTR_CONVERSION_MODE(_mode, _show, _store) \
131 IIO_DEVICE_ATTR(conversion_mode, _mode, _show, _store, 0)
132#define IIO_DEV_ATTR_CH1_OFFSET(_mode, _show, _store) \
133 IIO_DEVICE_ATTR(ch1_offset, _mode, _show, _store, 0)
134#define IIO_DEV_ATTR_CH2_OFFSET(_mode, _show, _store) \
135 IIO_DEVICE_ATTR(ch2_offset, _mode, _show, _store, 0)
136#define IIO_DEV_ATTR_CH1_GAIN(_mode, _show, _store) \
137 IIO_DEVICE_ATTR(ch1_gain, _mode, _show, _store, 0)
138#define IIO_DEV_ATTR_CH2_GAIN(_mode, _show, _store) \
139 IIO_DEVICE_ATTR(ch2_gain, _mode, _show, _store, 0)
140#define IIO_DEV_ATTR_CH1_VALUE(_show) \
141 IIO_DEVICE_ATTR(ch1_value, S_IRUGO, _show, NULL, 0)
142#define IIO_DEV_ATTR_CH2_VALUE(_show) \
143 IIO_DEVICE_ATTR(ch2_value, S_IRUGO, _show, NULL, 0)
144#define IIO_DEV_ATTR_CH1_SETUP(_mode, _show, _store) \
145 IIO_DEVICE_ATTR(ch1_setup, _mode, _show, _store, 0)
146#define IIO_DEV_ATTR_CH2_SETUP(_mode, _show, _store) \
147 IIO_DEVICE_ATTR(ch2_setup, _mode, _show, _store, 0)
148#define IIO_DEV_ATTR_FILTER_RATE_SETUP(_mode, _show, _store) \
149 IIO_DEVICE_ATTR(filter_rate_setup, _mode, _show, _store, 0)
150
151static ssize_t ad7152_show_conversion_modes(struct device *dev,
152 struct device_attribute *attr,
153 char *buf)
154{
155 int i;
156 int len = 0;
157
158 for (i = 0; i < AD7152_MAX_CONV_MODE; i++)
159 len += sprintf(buf + len, "%s ", ad7152_conv_mode_table[i].name);
160
161 len += sprintf(buf + len, "\n");
162
163 return len;
164}
165
166static IIO_DEV_ATTR_AVAIL_CONVERSION_MODES(ad7152_show_conversion_modes);
167
168static ssize_t ad7152_show_ch1_value(struct device *dev,
169 struct device_attribute *attr,
170 char *buf)
171{
172 struct iio_dev *dev_info = dev_get_drvdata(dev);
173 struct ad7152_chip_info *chip = dev_info->dev_data;
174 u8 data[2];
175
176 ad7152_i2c_read(chip, AD7152_CH1_DATA_HIGH, data, 2);
177 return sprintf(buf, "%d\n", ((int)data[0] << 8) | data[1]);
178}
179
180static IIO_DEV_ATTR_CH1_VALUE(ad7152_show_ch1_value);
181
182static ssize_t ad7152_show_ch2_value(struct device *dev,
183 struct device_attribute *attr,
184 char *buf)
185{
186 struct iio_dev *dev_info = dev_get_drvdata(dev);
187 struct ad7152_chip_info *chip = dev_info->dev_data;
188 u8 data[2];
189
190 ad7152_i2c_read(chip, AD7152_CH2_DATA_HIGH, data, 2);
191 return sprintf(buf, "%d\n", ((int)data[0] << 8) | data[1]);
192}
193
194static IIO_DEV_ATTR_CH2_VALUE(ad7152_show_ch2_value);
195
196static ssize_t ad7152_show_conversion_mode(struct device *dev,
197 struct device_attribute *attr,
198 char *buf)
199{
200 struct iio_dev *dev_info = dev_get_drvdata(dev);
201 struct ad7152_chip_info *chip = dev_info->dev_data;
202
203 return sprintf(buf, "%s\n", chip->conversion_mode);
204}
205
206static ssize_t ad7152_store_conversion_mode(struct device *dev,
207 struct device_attribute *attr,
208 const char *buf,
209 size_t len)
210{
211 struct iio_dev *dev_info = dev_get_drvdata(dev);
212 struct ad7152_chip_info *chip = dev_info->dev_data;
213 u8 cfg;
214 int i;
215
216 ad7152_i2c_read(chip, AD7152_CFG, &cfg, 1);
217
218 for (i = 0; i < AD7152_MAX_CONV_MODE; i++)
219 if (strncmp(buf, ad7152_conv_mode_table[i].name,
220 strlen(ad7152_conv_mode_table[i].name) - 1) == 0) {
221 chip->conversion_mode = ad7152_conv_mode_table[i].name;
222 cfg |= 0x18 | ad7152_conv_mode_table[i].reg_cfg;
223 ad7152_i2c_write(chip, AD7152_CFG, cfg);
224 return len;
225 }
226
227 dev_err(dev, "not supported conversion mode\n");
228
229 return -EINVAL;
230}
231
232static IIO_DEV_ATTR_CONVERSION_MODE(S_IRUGO | S_IWUSR,
233 ad7152_show_conversion_mode,
234 ad7152_store_conversion_mode);
235
236static ssize_t ad7152_show_ch1_offset(struct device *dev,
237 struct device_attribute *attr,
238 char *buf)
239{
240 struct iio_dev *dev_info = dev_get_drvdata(dev);
241 struct ad7152_chip_info *chip = dev_info->dev_data;
242
243 return sprintf(buf, "%d\n", chip->ch1_offset);
244}
245
246static ssize_t ad7152_store_ch1_offset(struct device *dev,
247 struct device_attribute *attr,
248 const char *buf,
249 size_t len)
250{
251 struct iio_dev *dev_info = dev_get_drvdata(dev);
252 struct ad7152_chip_info *chip = dev_info->dev_data;
253 unsigned long data;
254 int ret;
255
256 ret = strict_strtoul(buf, 10, &data);
257
258 if ((!ret) && (data < 0x10000)) {
259 ad7152_i2c_write(chip, AD7152_CH1_OFFS_HIGH, data >> 8);
260 ad7152_i2c_write(chip, AD7152_CH1_OFFS_LOW, data);
261 chip->ch1_offset = data;
262 return len;
263 }
264
265 return -EINVAL;
266}
267
268static IIO_DEV_ATTR_CH1_OFFSET(S_IRUGO | S_IWUSR,
269 ad7152_show_ch1_offset,
270 ad7152_store_ch1_offset);
271
272static ssize_t ad7152_show_ch2_offset(struct device *dev,
273 struct device_attribute *attr,
274 char *buf)
275{
276 struct iio_dev *dev_info = dev_get_drvdata(dev);
277 struct ad7152_chip_info *chip = dev_info->dev_data;
278
279 return sprintf(buf, "%d\n", chip->ch2_offset);
280}
281
282static ssize_t ad7152_store_ch2_offset(struct device *dev,
283 struct device_attribute *attr,
284 const char *buf,
285 size_t len)
286{
287 struct iio_dev *dev_info = dev_get_drvdata(dev);
288 struct ad7152_chip_info *chip = dev_info->dev_data;
289 unsigned long data;
290 int ret;
291
292 ret = strict_strtoul(buf, 10, &data);
293
294 if ((!ret) && (data < 0x10000)) {
295 ad7152_i2c_write(chip, AD7152_CH2_OFFS_HIGH, data >> 8);
296 ad7152_i2c_write(chip, AD7152_CH2_OFFS_LOW, data);
297 chip->ch2_offset = data;
298 return len;
299 }
300
301 return -EINVAL;
302}
303
304static IIO_DEV_ATTR_CH2_OFFSET(S_IRUGO | S_IWUSR,
305 ad7152_show_ch2_offset,
306 ad7152_store_ch2_offset);
307
308static ssize_t ad7152_show_ch1_gain(struct device *dev,
309 struct device_attribute *attr,
310 char *buf)
311{
312 struct iio_dev *dev_info = dev_get_drvdata(dev);
313 struct ad7152_chip_info *chip = dev_info->dev_data;
314
315 return sprintf(buf, "%d\n", chip->ch1_gain);
316}
317
318static ssize_t ad7152_store_ch1_gain(struct device *dev,
319 struct device_attribute *attr,
320 const char *buf,
321 size_t len)
322{
323 struct iio_dev *dev_info = dev_get_drvdata(dev);
324 struct ad7152_chip_info *chip = dev_info->dev_data;
325 unsigned long data;
326 int ret;
327
328 ret = strict_strtoul(buf, 10, &data);
329
330 if ((!ret) && (data < 0x10000)) {
331 ad7152_i2c_write(chip, AD7152_CH1_GAIN_HIGH, data >> 8);
332 ad7152_i2c_write(chip, AD7152_CH1_GAIN_LOW, data);
333 chip->ch1_gain = data;
334 return len;
335 }
336
337 return -EINVAL;
338}
339
340static IIO_DEV_ATTR_CH1_GAIN(S_IRUGO | S_IWUSR,
341 ad7152_show_ch1_gain,
342 ad7152_store_ch1_gain);
343
344static ssize_t ad7152_show_ch2_gain(struct device *dev,
345 struct device_attribute *attr,
346 char *buf)
347{
348 struct iio_dev *dev_info = dev_get_drvdata(dev);
349 struct ad7152_chip_info *chip = dev_info->dev_data;
350
351 return sprintf(buf, "%d\n", chip->ch2_gain);
352}
353
354static ssize_t ad7152_store_ch2_gain(struct device *dev,
355 struct device_attribute *attr,
356 const char *buf,
357 size_t len)
358{
359 struct iio_dev *dev_info = dev_get_drvdata(dev);
360 struct ad7152_chip_info *chip = dev_info->dev_data;
361 unsigned long data;
362 int ret;
363
364 ret = strict_strtoul(buf, 10, &data);
365
366 if ((!ret) && (data < 0x10000)) {
367 ad7152_i2c_write(chip, AD7152_CH2_GAIN_HIGH, data >> 8);
368 ad7152_i2c_write(chip, AD7152_CH2_GAIN_LOW, data);
369 chip->ch2_gain = data;
370 return len;
371 }
372
373 return -EINVAL;
374}
375
376static IIO_DEV_ATTR_CH2_GAIN(S_IRUGO | S_IWUSR,
377 ad7152_show_ch2_gain,
378 ad7152_store_ch2_gain);
379
380static ssize_t ad7152_show_ch1_setup(struct device *dev,
381 struct device_attribute *attr,
382 char *buf)
383{
384 struct iio_dev *dev_info = dev_get_drvdata(dev);
385 struct ad7152_chip_info *chip = dev_info->dev_data;
386
387 return sprintf(buf, "0x%02x\n", chip->ch1_setup);
388}
389
390static ssize_t ad7152_store_ch1_setup(struct device *dev,
391 struct device_attribute *attr,
392 const char *buf,
393 size_t len)
394{
395 struct iio_dev *dev_info = dev_get_drvdata(dev);
396 struct ad7152_chip_info *chip = dev_info->dev_data;
397 unsigned long data;
398 int ret;
399
400 ret = strict_strtoul(buf, 10, &data);
401
402 if ((!ret) && (data < 0x100)) {
403 ad7152_i2c_write(chip, AD7152_CH1_SETUP, data);
404 chip->ch1_setup = data;
405 return len;
406 }
407
408 return -EINVAL;
409}
410
411static IIO_DEV_ATTR_CH1_SETUP(S_IRUGO | S_IWUSR,
412 ad7152_show_ch1_setup,
413 ad7152_store_ch1_setup);
414
415static ssize_t ad7152_show_ch2_setup(struct device *dev,
416 struct device_attribute *attr,
417 char *buf)
418{
419 struct iio_dev *dev_info = dev_get_drvdata(dev);
420 struct ad7152_chip_info *chip = dev_info->dev_data;
421
422 return sprintf(buf, "0x%02x\n", chip->ch2_setup);
423}
424
425static ssize_t ad7152_store_ch2_setup(struct device *dev,
426 struct device_attribute *attr,
427 const char *buf,
428 size_t len)
429{
430 struct iio_dev *dev_info = dev_get_drvdata(dev);
431 struct ad7152_chip_info *chip = dev_info->dev_data;
432 unsigned long data;
433 int ret;
434
435 ret = strict_strtoul(buf, 10, &data);
436
437 if ((!ret) && (data < 0x100)) {
438 ad7152_i2c_write(chip, AD7152_CH2_SETUP, data);
439 chip->ch2_setup = data;
440 return len;
441 }
442
443 return -EINVAL;
444}
445
446static IIO_DEV_ATTR_CH2_SETUP(S_IRUGO | S_IWUSR,
447 ad7152_show_ch2_setup,
448 ad7152_store_ch2_setup);
449
450static ssize_t ad7152_show_filter_rate_setup(struct device *dev,
451 struct device_attribute *attr,
452 char *buf)
453{
454 struct iio_dev *dev_info = dev_get_drvdata(dev);
455 struct ad7152_chip_info *chip = dev_info->dev_data;
456
457 return sprintf(buf, "0x%02x\n", chip->filter_rate_setup);
458}
459
460static ssize_t ad7152_store_filter_rate_setup(struct device *dev,
461 struct device_attribute *attr,
462 const char *buf,
463 size_t len)
464{
465 struct iio_dev *dev_info = dev_get_drvdata(dev);
466 struct ad7152_chip_info *chip = dev_info->dev_data;
467 unsigned long data;
468 int ret;
469
470 ret = strict_strtoul(buf, 10, &data);
471
472 if ((!ret) && (data < 0x100)) {
473 ad7152_i2c_write(chip, AD7152_CFG2, data);
474 chip->filter_rate_setup = data;
475 return len;
476 }
477
478 return -EINVAL;
479}
480
481static IIO_DEV_ATTR_FILTER_RATE_SETUP(S_IRUGO | S_IWUSR,
482 ad7152_show_filter_rate_setup,
483 ad7152_store_filter_rate_setup);
484
485static ssize_t ad7152_show_name(struct device *dev,
486 struct device_attribute *attr,
487 char *buf)
488{
489 struct iio_dev *dev_info = dev_get_drvdata(dev);
490 struct ad7152_chip_info *chip = dev_info->dev_data;
491 return sprintf(buf, "%s\n", chip->name);
492}
493
494static IIO_DEVICE_ATTR(name, S_IRUGO, ad7152_show_name, NULL, 0);
495
496static struct attribute *ad7152_attributes[] = {
497 &iio_dev_attr_available_conversion_modes.dev_attr.attr,
498 &iio_dev_attr_conversion_mode.dev_attr.attr,
499 &iio_dev_attr_ch1_gain.dev_attr.attr,
500 &iio_dev_attr_ch2_gain.dev_attr.attr,
501 &iio_dev_attr_ch1_offset.dev_attr.attr,
502 &iio_dev_attr_ch2_offset.dev_attr.attr,
503 &iio_dev_attr_ch1_value.dev_attr.attr,
504 &iio_dev_attr_ch2_value.dev_attr.attr,
505 &iio_dev_attr_ch1_setup.dev_attr.attr,
506 &iio_dev_attr_ch2_setup.dev_attr.attr,
507 &iio_dev_attr_filter_rate_setup.dev_attr.attr,
508 &iio_dev_attr_name.dev_attr.attr,
509 NULL,
510};
511
512static const struct attribute_group ad7152_attribute_group = {
513 .attrs = ad7152_attributes,
514};
515
516/*
517 * device probe and remove
518 */
519
520static int __devinit ad7152_probe(struct i2c_client *client,
521 const struct i2c_device_id *id)
522{
523 int ret = 0;
524 struct ad7152_chip_info *chip = kzalloc(sizeof(*chip), GFP_KERNEL);
525 if (chip == NULL) {
526 ret = -ENOMEM;
527 goto error_ret;
528 }
529
530 /* this is only used for device removal purposes */
531 i2c_set_clientdata(client, chip);
532
533 chip->client = client;
534 chip->name = id->name;
535
536 chip->indio_dev = iio_allocate_device();
537 if (chip->indio_dev == NULL) {
538 ret = -ENOMEM;
539 goto error_free_chip;
540 }
541
542 /* Echipabilish that the iio_dev is a child of the i2c device */
543 chip->indio_dev->dev.parent = &client->dev;
544 chip->indio_dev->attrs = &ad7152_attribute_group;
545 chip->indio_dev->dev_data = (void *)(chip);
546 chip->indio_dev->driver_module = THIS_MODULE;
547 chip->indio_dev->modes = INDIO_DIRECT_MODE;
548
549 ret = iio_device_register(chip->indio_dev);
550 if (ret)
551 goto error_free_dev;
552
553 dev_err(&client->dev, "%s capacitive sensor registered\n", id->name);
554
555 return 0;
556
557error_free_dev:
558 iio_free_device(chip->indio_dev);
559error_free_chip:
560 kfree(chip);
561error_ret:
562 return ret;
563}
564
565static int __devexit ad7152_remove(struct i2c_client *client)
566{
567 struct ad7152_chip_info *chip = i2c_get_clientdata(client);
568 struct iio_dev *indio_dev = chip->indio_dev;
569
570 if (client->irq && gpio_is_valid(irq_to_gpio(client->irq)) > 0)
571 iio_unregister_interrupt_line(indio_dev, 0);
572 iio_device_unregister(indio_dev);
573 kfree(chip);
574
575 return 0;
576}
577
578static const struct i2c_device_id ad7152_id[] = {
579 { "ad7152", 0 },
580 { "ad7153", 0 },
581 {}
582};
583
584MODULE_DEVICE_TABLE(i2c, ad7152_id);
585
586static struct i2c_driver ad7152_driver = {
587 .driver = {
588 .name = "ad7152",
589 },
590 .probe = ad7152_probe,
591 .remove = __devexit_p(ad7152_remove),
592 .id_table = ad7152_id,
593};
594
595static __init int ad7152_init(void)
596{
597 return i2c_add_driver(&ad7152_driver);
598}
599
600static __exit void ad7152_exit(void)
601{
602 i2c_del_driver(&ad7152_driver);
603}
604
605MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
606MODULE_DESCRIPTION("Analog Devices ad7152/3 capacitive sensor driver");
607MODULE_LICENSE("GPL v2");
608
609module_init(ad7152_init);
610module_exit(ad7152_exit);
diff --git a/drivers/staging/iio/adc/ad7291.c b/drivers/staging/iio/adc/ad7291.c
new file mode 100644
index 000000000000..34041a72aa52
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7291.c
@@ -0,0 +1,1039 @@
1/*
2 * AD7291 digital temperature sensor driver supporting AD7291
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/workqueue.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/sysfs.h>
16#include <linux/list.h>
17#include <linux/i2c.h>
18#include <linux/rtc.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23/*
24 * AD7291 registers definition
25 */
26#define AD7291_COMMAND 0
27#define AD7291_VOLTAGE 1
28#define AD7291_T_SENSE 2
29#define AD7291_T_AVERAGE 3
30#define AD7291_VOLTAGE_LIMIT_BASE 4
31#define AD7291_VOLTAGE_LIMIT_COUNT 8
32#define AD7291_T_SENSE_HIGH 0x1c
33#define AD7291_T_SENSE_LOW 0x1d
34#define AD7291_T_SENSE_HYST 0x1e
35#define AD7291_VOLTAGE_ALERT_STATUS 0x1f
36#define AD7291_T_ALERT_STATUS 0x20
37
38/*
39 * AD7291 command
40 */
41#define AD7291_AUTOCYCLE 0x1
42#define AD7291_RESET 0x2
43#define AD7291_ALART_CLEAR 0x4
44#define AD7291_ALART_POLARITY 0x8
45#define AD7291_EXT_REF 0x10
46#define AD7291_NOISE_DELAY 0x20
47#define AD7291_T_SENSE_MASK 0x40
48#define AD7291_VOLTAGE_MASK 0xff00
49#define AD7291_VOLTAGE_OFFSET 0x8
50
51/*
52 * AD7291 value masks
53 */
54#define AD7291_CHANNEL_MASK 0xf000
55#define AD7291_VALUE_MASK 0xfff
56#define AD7291_T_VALUE_SIGN 0x400
57#define AD7291_T_VALUE_FLOAT_OFFSET 2
58#define AD7291_T_VALUE_FLOAT_MASK 0x2
59
60/*
61 * struct ad7291_chip_info - chip specifc information
62 */
63
64struct ad7291_chip_info {
65 const char *name;
66 struct i2c_client *client;
67 struct iio_dev *indio_dev;
68 struct work_struct thresh_work;
69 s64 last_timestamp;
70 u16 command;
71 u8 channels; /* Active voltage channels */
72};
73
74/*
75 * struct ad7291_chip_info - chip specifc information
76 */
77
78struct ad7291_limit_regs {
79 u16 data_high;
80 u16 data_low;
81 u16 hysteresis;
82};
83
84/*
85 * ad7291 register access by I2C
86 */
87static int ad7291_i2c_read(struct ad7291_chip_info *chip, u8 reg, u16 *data)
88{
89 struct i2c_client *client = chip->client;
90 int ret = 0;
91
92 ret = i2c_smbus_read_word_data(client, reg);
93 if (ret < 0) {
94 dev_err(&client->dev, "I2C read error\n");
95 return ret;
96 }
97
98 *data = swab16((u16)ret);
99
100 return 0;
101}
102
103static int ad7291_i2c_write(struct ad7291_chip_info *chip, u8 reg, u16 data)
104{
105 struct i2c_client *client = chip->client;
106 int ret = 0;
107
108 ret = i2c_smbus_write_word_data(client, reg, swab16(data));
109 if (ret < 0)
110 dev_err(&client->dev, "I2C write error\n");
111
112 return ret;
113}
114
115/* Returns negative errno, or else the number of words read. */
116static int ad7291_i2c_read_data(struct ad7291_chip_info *chip, u8 reg, u16 *data)
117{
118 struct i2c_client *client = chip->client;
119 u8 commands[4];
120 int ret = 0;
121 int i, count;
122
123 if (reg == AD7291_T_SENSE || reg == AD7291_T_AVERAGE)
124 count = 2;
125 else if (reg == AD7291_VOLTAGE) {
126 if (!chip->channels) {
127 dev_err(&client->dev, "No voltage channel is selected.\n");
128 return -EINVAL;
129 }
130 count = 2 + chip->channels * 2;
131 } else {
132 dev_err(&client->dev, "I2C wrong data register\n");
133 return -EINVAL;
134 }
135
136 commands[0] = 0;
137 commands[1] = (chip->command >> 8) & 0xff;
138 commands[2] = chip->command & 0xff;
139 commands[3] = reg;
140
141 ret = i2c_master_send(client, commands, 4);
142 if (ret < 0) {
143 dev_err(&client->dev, "I2C master send error\n");
144 return ret;
145 }
146
147 ret = i2c_master_recv(client, (u8 *)data, count);
148 if (ret < 0) {
149 dev_err(&client->dev, "I2C master receive error\n");
150 return ret;
151 }
152 ret >>= 2;
153
154 for (i = 0; i < ret; i++)
155 data[i] = swab16(data[i]);
156
157 return ret;
158}
159
160static ssize_t ad7291_show_mode(struct device *dev,
161 struct device_attribute *attr,
162 char *buf)
163{
164 struct iio_dev *dev_info = dev_get_drvdata(dev);
165 struct ad7291_chip_info *chip = dev_info->dev_data;
166
167 if (chip->command & AD7291_AUTOCYCLE)
168 return sprintf(buf, "autocycle\n");
169 else
170 return sprintf(buf, "command\n");
171}
172
173static ssize_t ad7291_store_mode(struct device *dev,
174 struct device_attribute *attr,
175 const char *buf,
176 size_t len)
177{
178 struct iio_dev *dev_info = dev_get_drvdata(dev);
179 struct ad7291_chip_info *chip = dev_info->dev_data;
180 u16 command;
181 int ret;
182
183 command = chip->command & (~AD7291_AUTOCYCLE);
184 if (strcmp(buf, "autocycle"))
185 command |= AD7291_AUTOCYCLE;
186
187 ret = ad7291_i2c_write(chip, AD7291_COMMAND, command);
188 if (ret)
189 return -EIO;
190
191 chip->command = command;
192
193 return ret;
194}
195
196static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
197 ad7291_show_mode,
198 ad7291_store_mode,
199 0);
200
201static ssize_t ad7291_show_available_modes(struct device *dev,
202 struct device_attribute *attr,
203 char *buf)
204{
205 return sprintf(buf, "command\nautocycle\n");
206}
207
208static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7291_show_available_modes, NULL, 0);
209
210static ssize_t ad7291_store_reset(struct device *dev,
211 struct device_attribute *attr,
212 const char *buf,
213 size_t len)
214{
215 struct iio_dev *dev_info = dev_get_drvdata(dev);
216 struct ad7291_chip_info *chip = dev_info->dev_data;
217 u16 command;
218 int ret;
219
220 command = chip->command | AD7291_RESET;
221
222 ret = ad7291_i2c_write(chip, AD7291_COMMAND, command);
223 if (ret)
224 return -EIO;
225
226 return ret;
227}
228
229static IIO_DEVICE_ATTR(reset, S_IWUSR,
230 NULL,
231 ad7291_store_reset,
232 0);
233
234static ssize_t ad7291_show_ext_ref(struct device *dev,
235 struct device_attribute *attr,
236 char *buf)
237{
238 struct iio_dev *dev_info = dev_get_drvdata(dev);
239 struct ad7291_chip_info *chip = dev_info->dev_data;
240
241 return sprintf(buf, "%d\n", !!(chip->command & AD7291_EXT_REF));
242}
243
244static ssize_t ad7291_store_ext_ref(struct device *dev,
245 struct device_attribute *attr,
246 const char *buf,
247 size_t len)
248{
249 struct iio_dev *dev_info = dev_get_drvdata(dev);
250 struct ad7291_chip_info *chip = dev_info->dev_data;
251 u16 command;
252 int ret;
253
254 command = chip->command & (~AD7291_EXT_REF);
255 if (strcmp(buf, "1"))
256 command |= AD7291_EXT_REF;
257
258 ret = ad7291_i2c_write(chip, AD7291_COMMAND, command);
259 if (ret)
260 return -EIO;
261
262 chip->command = command;
263
264 return ret;
265}
266
267static IIO_DEVICE_ATTR(ext_ref, S_IRUGO | S_IWUSR,
268 ad7291_show_ext_ref,
269 ad7291_store_ext_ref,
270 0);
271
272static ssize_t ad7291_show_noise_delay(struct device *dev,
273 struct device_attribute *attr,
274 char *buf)
275{
276 struct iio_dev *dev_info = dev_get_drvdata(dev);
277 struct ad7291_chip_info *chip = dev_info->dev_data;
278
279 return sprintf(buf, "%d\n", !!(chip->command & AD7291_NOISE_DELAY));
280}
281
282static ssize_t ad7291_store_noise_delay(struct device *dev,
283 struct device_attribute *attr,
284 const char *buf,
285 size_t len)
286{
287 struct iio_dev *dev_info = dev_get_drvdata(dev);
288 struct ad7291_chip_info *chip = dev_info->dev_data;
289 u16 command;
290 int ret;
291
292 command = chip->command & (~AD7291_NOISE_DELAY);
293 if (strcmp(buf, "1"))
294 command |= AD7291_NOISE_DELAY;
295
296 ret = ad7291_i2c_write(chip, AD7291_COMMAND, command);
297 if (ret)
298 return -EIO;
299
300 chip->command = command;
301
302 return ret;
303}
304
305static IIO_DEVICE_ATTR(noise_delay, S_IRUGO | S_IWUSR,
306 ad7291_show_noise_delay,
307 ad7291_store_noise_delay,
308 0);
309
310static ssize_t ad7291_show_t_sense(struct device *dev,
311 struct device_attribute *attr,
312 char *buf)
313{
314 struct iio_dev *dev_info = dev_get_drvdata(dev);
315 struct ad7291_chip_info *chip = dev_info->dev_data;
316 u16 data;
317 char sign = ' ';
318 int ret;
319
320 ret = ad7291_i2c_read_data(chip, AD7291_T_SENSE, &data);
321 if (ret)
322 return -EIO;
323
324 if (data & AD7291_T_VALUE_SIGN) {
325 /* convert supplement to positive value */
326 data = (AD7291_T_VALUE_SIGN << 1) - data;
327 sign = '-';
328 }
329
330 return sprintf(buf, "%c%d.%.2d\n", sign,
331 (data >> AD7291_T_VALUE_FLOAT_OFFSET),
332 (data & AD7291_T_VALUE_FLOAT_MASK) * 25);
333}
334
335static IIO_DEVICE_ATTR(t_sense, S_IRUGO, ad7291_show_t_sense, NULL, 0);
336
337static ssize_t ad7291_show_t_average(struct device *dev,
338 struct device_attribute *attr,
339 char *buf)
340{
341 struct iio_dev *dev_info = dev_get_drvdata(dev);
342 struct ad7291_chip_info *chip = dev_info->dev_data;
343 u16 data;
344 char sign = ' ';
345 int ret;
346
347 ret = ad7291_i2c_read_data(chip, AD7291_T_AVERAGE, &data);
348 if (ret)
349 return -EIO;
350
351 if (data & AD7291_T_VALUE_SIGN) {
352 /* convert supplement to positive value */
353 data = (AD7291_T_VALUE_SIGN << 1) - data;
354 sign = '-';
355 }
356
357 return sprintf(buf, "%c%d.%.2d\n", sign,
358 (data >> AD7291_T_VALUE_FLOAT_OFFSET),
359 (data & AD7291_T_VALUE_FLOAT_MASK) * 25);
360}
361
362static IIO_DEVICE_ATTR(t_average, S_IRUGO, ad7291_show_t_average, NULL, 0);
363
364static ssize_t ad7291_show_voltage(struct device *dev,
365 struct device_attribute *attr,
366 char *buf)
367{
368 struct iio_dev *dev_info = dev_get_drvdata(dev);
369 struct ad7291_chip_info *chip = dev_info->dev_data;
370 u16 data[AD7291_VOLTAGE_LIMIT_COUNT];
371 int i, size, ret;
372
373 ret = ad7291_i2c_read_data(chip, AD7291_VOLTAGE, data);
374 if (ret)
375 return -EIO;
376
377 for (i = 0; i < AD7291_VOLTAGE_LIMIT_COUNT; i++) {
378 if (chip->command & (AD7291_T_SENSE_MASK << i)) {
379 ret = sprintf(buf, "channel[%d]=%d\n", i,
380 data[i] & AD7291_VALUE_MASK);
381 if (ret < 0)
382 break;
383 buf += ret;
384 size += ret;
385 }
386 }
387
388 return size;
389}
390
391static IIO_DEVICE_ATTR(voltage, S_IRUGO, ad7291_show_voltage, NULL, 0);
392
393static ssize_t ad7291_show_channel_mask(struct device *dev,
394 struct device_attribute *attr,
395 char *buf)
396{
397 struct iio_dev *dev_info = dev_get_drvdata(dev);
398 struct ad7291_chip_info *chip = dev_info->dev_data;
399
400 return sprintf(buf, "0x%x\n", (chip->command & AD7291_VOLTAGE_MASK) >>
401 AD7291_VOLTAGE_OFFSET);
402}
403
404static ssize_t ad7291_store_channel_mask(struct device *dev,
405 struct device_attribute *attr,
406 const char *buf,
407 size_t len)
408{
409 struct iio_dev *dev_info = dev_get_drvdata(dev);
410 struct ad7291_chip_info *chip = dev_info->dev_data;
411 u16 command;
412 unsigned long data;
413 int i, ret;
414
415 ret = strict_strtoul(buf, 16, &data);
416 if (ret || data > 0xff)
417 return -EINVAL;
418
419 command = chip->command & (~AD7291_VOLTAGE_MASK);
420 command |= data << AD7291_VOLTAGE_OFFSET;
421
422 ret = ad7291_i2c_write(chip, AD7291_COMMAND, command);
423 if (ret)
424 return -EIO;
425
426 chip->command = command;
427
428 for (i = 0, chip->channels = 0; i < AD7291_VOLTAGE_LIMIT_COUNT; i++) {
429 if (chip->command & (AD7291_T_SENSE_MASK << i))
430 chip->channels++;
431 }
432
433 return ret;
434}
435
436static IIO_DEVICE_ATTR(channel_mask, S_IRUGO | S_IWUSR,
437 ad7291_show_channel_mask,
438 ad7291_store_channel_mask,
439 0);
440
441static ssize_t ad7291_show_name(struct device *dev,
442 struct device_attribute *attr,
443 char *buf)
444{
445 struct iio_dev *dev_info = dev_get_drvdata(dev);
446 struct ad7291_chip_info *chip = dev_info->dev_data;
447 return sprintf(buf, "%s\n", chip->name);
448}
449
450static IIO_DEVICE_ATTR(name, S_IRUGO, ad7291_show_name, NULL, 0);
451
452static struct attribute *ad7291_attributes[] = {
453 &iio_dev_attr_available_modes.dev_attr.attr,
454 &iio_dev_attr_mode.dev_attr.attr,
455 &iio_dev_attr_reset.dev_attr.attr,
456 &iio_dev_attr_ext_ref.dev_attr.attr,
457 &iio_dev_attr_noise_delay.dev_attr.attr,
458 &iio_dev_attr_t_sense.dev_attr.attr,
459 &iio_dev_attr_t_average.dev_attr.attr,
460 &iio_dev_attr_voltage.dev_attr.attr,
461 &iio_dev_attr_channel_mask.dev_attr.attr,
462 &iio_dev_attr_name.dev_attr.attr,
463 NULL,
464};
465
466static const struct attribute_group ad7291_attribute_group = {
467 .attrs = ad7291_attributes,
468};
469
470/*
471 * temperature bound events
472 */
473
474#define IIO_EVENT_CODE_AD7291_T_SENSE_HIGH IIO_BUFFER_EVENT_CODE(0)
475#define IIO_EVENT_CODE_AD7291_T_SENSE_LOW IIO_BUFFER_EVENT_CODE(1)
476#define IIO_EVENT_CODE_AD7291_T_AVG_HIGH IIO_BUFFER_EVENT_CODE(2)
477#define IIO_EVENT_CODE_AD7291_T_AVG_LOW IIO_BUFFER_EVENT_CODE(3)
478#define IIO_EVENT_CODE_AD7291_VOLTAGE_BASE IIO_BUFFER_EVENT_CODE(4)
479
480static void ad7291_interrupt_bh(struct work_struct *work_s)
481{
482 struct ad7291_chip_info *chip =
483 container_of(work_s, struct ad7291_chip_info, thresh_work);
484 u16 t_status, v_status;
485 u16 command;
486 int i;
487
488 if (ad7291_i2c_read(chip, AD7291_T_ALERT_STATUS, &t_status))
489 return;
490
491 if (ad7291_i2c_read(chip, AD7291_VOLTAGE_ALERT_STATUS, &v_status))
492 return;
493
494 if (!(t_status || v_status))
495 return;
496
497 command = chip->command | AD7291_ALART_CLEAR;
498 ad7291_i2c_write(chip, AD7291_COMMAND, command);
499
500 command = chip->command & ~AD7291_ALART_CLEAR;
501 ad7291_i2c_write(chip, AD7291_COMMAND, command);
502
503 enable_irq(chip->client->irq);
504
505 for (i = 0; i < 4; i++) {
506 if (t_status & (1 << i))
507 iio_push_event(chip->indio_dev, 0,
508 IIO_EVENT_CODE_AD7291_T_SENSE_HIGH + i,
509 chip->last_timestamp);
510 }
511
512 for (i = 0; i < AD7291_VOLTAGE_LIMIT_COUNT*2; i++) {
513 if (v_status & (1 << i))
514 iio_push_event(chip->indio_dev, 0,
515 IIO_EVENT_CODE_AD7291_VOLTAGE_BASE + i,
516 chip->last_timestamp);
517 }
518}
519
520static int ad7291_interrupt(struct iio_dev *dev_info,
521 int index,
522 s64 timestamp,
523 int no_test)
524{
525 struct ad7291_chip_info *chip = dev_info->dev_data;
526
527 chip->last_timestamp = timestamp;
528 schedule_work(&chip->thresh_work);
529
530 return 0;
531}
532
533IIO_EVENT_SH(ad7291, &ad7291_interrupt);
534
535static inline ssize_t ad7291_show_t_bound(struct device *dev,
536 struct device_attribute *attr,
537 u8 bound_reg,
538 char *buf)
539{
540 struct iio_dev *dev_info = dev_get_drvdata(dev);
541 struct ad7291_chip_info *chip = dev_info->dev_data;
542 u16 data;
543 char sign = ' ';
544 int ret;
545
546 ret = ad7291_i2c_read(chip, bound_reg, &data);
547 if (ret)
548 return -EIO;
549
550 data &= AD7291_VALUE_MASK;
551 if (data & AD7291_T_VALUE_SIGN) {
552 /* convert supplement to positive value */
553 data = (AD7291_T_VALUE_SIGN << 1) - data;
554 sign = '-';
555 }
556
557 return sprintf(buf, "%c%d.%.2d\n", sign,
558 data >> AD7291_T_VALUE_FLOAT_OFFSET,
559 (data & AD7291_T_VALUE_FLOAT_MASK) * 25);
560}
561
562static inline ssize_t ad7291_set_t_bound(struct device *dev,
563 struct device_attribute *attr,
564 u8 bound_reg,
565 const char *buf,
566 size_t len)
567{
568 struct iio_dev *dev_info = dev_get_drvdata(dev);
569 struct ad7291_chip_info *chip = dev_info->dev_data;
570 long tmp1, tmp2;
571 u16 data;
572 char *pos;
573 int ret;
574
575 pos = strchr(buf, '.');
576
577 ret = strict_strtol(buf, 10, &tmp1);
578
579 if (ret || tmp1 > 127 || tmp1 < -128)
580 return -EINVAL;
581
582 if (pos) {
583 len = strlen(pos);
584 if (len > AD7291_T_VALUE_FLOAT_OFFSET)
585 len = AD7291_T_VALUE_FLOAT_OFFSET;
586 pos[len] = 0;
587 ret = strict_strtol(pos, 10, &tmp2);
588
589 if (!ret)
590 tmp2 = (tmp2 / 25) * 25;
591 }
592
593 if (tmp1 < 0)
594 data = (u16)(-tmp1);
595 else
596 data = (u16)tmp1;
597 data = (data << AD7291_T_VALUE_FLOAT_OFFSET) |
598 (tmp2 & AD7291_T_VALUE_FLOAT_MASK);
599 if (tmp1 < 0)
600 /* convert positive value to supplyment */
601 data = (AD7291_T_VALUE_SIGN << 1) - data;
602
603 ret = ad7291_i2c_write(chip, bound_reg, data);
604 if (ret)
605 return -EIO;
606
607 return ret;
608}
609
610static ssize_t ad7291_show_t_sense_high(struct device *dev,
611 struct device_attribute *attr,
612 char *buf)
613{
614 return ad7291_show_t_bound(dev, attr,
615 AD7291_T_SENSE_HIGH, buf);
616}
617
618static inline ssize_t ad7291_set_t_sense_high(struct device *dev,
619 struct device_attribute *attr,
620 const char *buf,
621 size_t len)
622{
623 return ad7291_set_t_bound(dev, attr,
624 AD7291_T_SENSE_HIGH, buf, len);
625}
626
627static ssize_t ad7291_show_t_sense_low(struct device *dev,
628 struct device_attribute *attr,
629 char *buf)
630{
631 return ad7291_show_t_bound(dev, attr,
632 AD7291_T_SENSE_LOW, buf);
633}
634
635static inline ssize_t ad7291_set_t_sense_low(struct device *dev,
636 struct device_attribute *attr,
637 const char *buf,
638 size_t len)
639{
640 return ad7291_set_t_bound(dev, attr,
641 AD7291_T_SENSE_LOW, buf, len);
642}
643
644static ssize_t ad7291_show_t_sense_hyst(struct device *dev,
645 struct device_attribute *attr,
646 char *buf)
647{
648 return ad7291_show_t_bound(dev, attr,
649 AD7291_T_SENSE_HYST, buf);
650}
651
652static inline ssize_t ad7291_set_t_sense_hyst(struct device *dev,
653 struct device_attribute *attr,
654 const char *buf,
655 size_t len)
656{
657 return ad7291_set_t_bound(dev, attr,
658 AD7291_T_SENSE_HYST, buf, len);
659}
660
661static inline ssize_t ad7291_show_v_bound(struct device *dev,
662 struct device_attribute *attr,
663 u8 bound_reg,
664 char *buf)
665{
666 struct iio_dev *dev_info = dev_get_drvdata(dev);
667 struct ad7291_chip_info *chip = dev_info->dev_data;
668 u16 data;
669 int ret;
670
671 if (bound_reg < AD7291_VOLTAGE_LIMIT_BASE ||
672 bound_reg >= AD7291_VOLTAGE_LIMIT_BASE +
673 AD7291_VOLTAGE_LIMIT_COUNT)
674 return -EINVAL;
675
676 ret = ad7291_i2c_read(chip, bound_reg, &data);
677 if (ret)
678 return -EIO;
679
680 data &= AD7291_VALUE_MASK;
681
682 return sprintf(buf, "%d\n", data);
683}
684
685static inline ssize_t ad7291_set_v_bound(struct device *dev,
686 struct device_attribute *attr,
687 u8 bound_reg,
688 const char *buf,
689 size_t len)
690{
691 struct iio_dev *dev_info = dev_get_drvdata(dev);
692 struct ad7291_chip_info *chip = dev_info->dev_data;
693 unsigned long value;
694 u16 data;
695 int ret;
696
697 if (bound_reg < AD7291_VOLTAGE_LIMIT_BASE ||
698 bound_reg >= AD7291_VOLTAGE_LIMIT_BASE +
699 AD7291_VOLTAGE_LIMIT_COUNT)
700 return -EINVAL;
701
702 ret = strict_strtoul(buf, 10, &value);
703
704 if (ret || value >= 4096)
705 return -EINVAL;
706
707 data = (u16)value;
708 ret = ad7291_i2c_write(chip, bound_reg, data);
709 if (ret)
710 return -EIO;
711
712 return ret;
713}
714
715static int ad7291_get_voltage_limit_regs(const char *channel)
716{
717 int index;
718
719 if (strlen(channel) < 3 && channel[0] != 'v')
720 return -EINVAL;
721
722 index = channel[1] - '0';
723 if (index >= AD7291_VOLTAGE_LIMIT_COUNT)
724 return -EINVAL;
725
726 return index;
727}
728
729static ssize_t ad7291_show_voltage_high(struct device *dev,
730 struct device_attribute *attr,
731 char *buf)
732{
733 int regs;
734
735 regs = ad7291_get_voltage_limit_regs(attr->attr.name);
736
737 if (regs < 0)
738 return regs;
739
740 return ad7291_show_t_bound(dev, attr, regs, buf);
741}
742
743static inline ssize_t ad7291_set_voltage_high(struct device *dev,
744 struct device_attribute *attr,
745 const char *buf,
746 size_t len)
747{
748 int regs;
749
750 regs = ad7291_get_voltage_limit_regs(attr->attr.name);
751
752 if (regs < 0)
753 return regs;
754
755 return ad7291_set_t_bound(dev, attr, regs, buf, len);
756}
757
758static ssize_t ad7291_show_voltage_low(struct device *dev,
759 struct device_attribute *attr,
760 char *buf)
761{
762 int regs;
763
764 regs = ad7291_get_voltage_limit_regs(attr->attr.name);
765
766 if (regs < 0)
767 return regs;
768
769 return ad7291_show_t_bound(dev, attr, regs+1, buf);
770}
771
772static inline ssize_t ad7291_set_voltage_low(struct device *dev,
773 struct device_attribute *attr,
774 const char *buf,
775 size_t len)
776{
777 int regs;
778
779 regs = ad7291_get_voltage_limit_regs(attr->attr.name);
780
781 if (regs < 0)
782 return regs;
783
784 return ad7291_set_t_bound(dev, attr, regs+1, buf, len);
785}
786
787static ssize_t ad7291_show_voltage_hyst(struct device *dev,
788 struct device_attribute *attr,
789 char *buf)
790{
791 int regs;
792
793 regs = ad7291_get_voltage_limit_regs(attr->attr.name);
794
795 if (regs < 0)
796 return regs;
797
798 return ad7291_show_t_bound(dev, attr, regs+2, buf);
799}
800
801static inline ssize_t ad7291_set_voltage_hyst(struct device *dev,
802 struct device_attribute *attr,
803 const char *buf,
804 size_t len)
805{
806 int regs;
807
808 regs = ad7291_get_voltage_limit_regs(attr->attr.name);
809
810 if (regs < 0)
811 return regs;
812
813 return ad7291_set_t_bound(dev, attr, regs+2, buf, len);
814}
815
816IIO_EVENT_ATTR_SH(t_sense_high, iio_event_ad7291,
817 ad7291_show_t_sense_high, ad7291_set_t_sense_high, 0);
818IIO_EVENT_ATTR_SH(t_sense_low, iio_event_ad7291,
819 ad7291_show_t_sense_low, ad7291_set_t_sense_low, 0);
820IIO_EVENT_ATTR_SH(t_sense_hyst, iio_event_ad7291,
821 ad7291_show_t_sense_hyst, ad7291_set_t_sense_hyst, 0);
822
823IIO_EVENT_ATTR_SH(v0_high, iio_event_ad7291,
824 ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
825IIO_EVENT_ATTR_SH(v0_low, iio_event_ad7291,
826 ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
827IIO_EVENT_ATTR_SH(v0_hyst, iio_event_ad7291,
828 ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
829IIO_EVENT_ATTR_SH(v1_high, iio_event_ad7291,
830 ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
831IIO_EVENT_ATTR_SH(v1_low, iio_event_ad7291,
832 ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
833IIO_EVENT_ATTR_SH(v1_hyst, iio_event_ad7291,
834 ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
835IIO_EVENT_ATTR_SH(v2_high, iio_event_ad7291,
836 ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
837IIO_EVENT_ATTR_SH(v2_low, iio_event_ad7291,
838 ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
839IIO_EVENT_ATTR_SH(v2_hyst, iio_event_ad7291,
840 ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
841IIO_EVENT_ATTR_SH(v3_high, iio_event_ad7291,
842 ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
843IIO_EVENT_ATTR_SH(v3_low, iio_event_ad7291,
844 ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
845IIO_EVENT_ATTR_SH(v3_hyst, iio_event_ad7291,
846 ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
847IIO_EVENT_ATTR_SH(v4_high, iio_event_ad7291,
848 ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
849IIO_EVENT_ATTR_SH(v4_low, iio_event_ad7291,
850 ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
851IIO_EVENT_ATTR_SH(v4_hyst, iio_event_ad7291,
852 ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
853IIO_EVENT_ATTR_SH(v5_high, iio_event_ad7291,
854 ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
855IIO_EVENT_ATTR_SH(v5_low, iio_event_ad7291,
856 ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
857IIO_EVENT_ATTR_SH(v5_hyst, iio_event_ad7291,
858 ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
859IIO_EVENT_ATTR_SH(v6_high, iio_event_ad7291,
860 ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
861IIO_EVENT_ATTR_SH(v6_low, iio_event_ad7291,
862 ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
863IIO_EVENT_ATTR_SH(v6_hyst, iio_event_ad7291,
864 ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
865IIO_EVENT_ATTR_SH(v7_high, iio_event_ad7291,
866 ad7291_show_voltage_high, ad7291_set_voltage_high, 0);
867IIO_EVENT_ATTR_SH(v7_low, iio_event_ad7291,
868 ad7291_show_voltage_low, ad7291_set_voltage_low, 0);
869IIO_EVENT_ATTR_SH(v7_hyst, iio_event_ad7291,
870 ad7291_show_voltage_hyst, ad7291_set_voltage_hyst, 0);
871
872static struct attribute *ad7291_event_attributes[] = {
873 &iio_event_attr_t_sense_high.dev_attr.attr,
874 &iio_event_attr_t_sense_low.dev_attr.attr,
875 &iio_event_attr_t_sense_hyst.dev_attr.attr,
876 &iio_event_attr_v0_high.dev_attr.attr,
877 &iio_event_attr_v0_low.dev_attr.attr,
878 &iio_event_attr_v0_hyst.dev_attr.attr,
879 &iio_event_attr_v1_high.dev_attr.attr,
880 &iio_event_attr_v1_low.dev_attr.attr,
881 &iio_event_attr_v1_hyst.dev_attr.attr,
882 &iio_event_attr_v2_high.dev_attr.attr,
883 &iio_event_attr_v2_low.dev_attr.attr,
884 &iio_event_attr_v2_hyst.dev_attr.attr,
885 &iio_event_attr_v3_high.dev_attr.attr,
886 &iio_event_attr_v3_low.dev_attr.attr,
887 &iio_event_attr_v3_hyst.dev_attr.attr,
888 &iio_event_attr_v4_high.dev_attr.attr,
889 &iio_event_attr_v4_low.dev_attr.attr,
890 &iio_event_attr_v4_hyst.dev_attr.attr,
891 &iio_event_attr_v5_high.dev_attr.attr,
892 &iio_event_attr_v5_low.dev_attr.attr,
893 &iio_event_attr_v5_hyst.dev_attr.attr,
894 &iio_event_attr_v6_high.dev_attr.attr,
895 &iio_event_attr_v6_low.dev_attr.attr,
896 &iio_event_attr_v6_hyst.dev_attr.attr,
897 &iio_event_attr_v7_high.dev_attr.attr,
898 &iio_event_attr_v7_low.dev_attr.attr,
899 &iio_event_attr_v7_hyst.dev_attr.attr,
900 NULL,
901};
902
903static struct attribute_group ad7291_event_attribute_group = {
904 .attrs = ad7291_event_attributes,
905};
906
907/*
908 * device probe and remove
909 */
910
911static int __devinit ad7291_probe(struct i2c_client *client,
912 const struct i2c_device_id *id)
913{
914 struct ad7291_chip_info *chip;
915 int ret = 0;
916
917 chip = kzalloc(sizeof(struct ad7291_chip_info), GFP_KERNEL);
918
919 if (chip == NULL)
920 return -ENOMEM;
921
922 /* this is only used for device removal purposes */
923 i2c_set_clientdata(client, chip);
924
925 chip->client = client;
926 chip->name = id->name;
927 chip->command = AD7291_NOISE_DELAY | AD7291_T_SENSE_MASK;
928
929 chip->indio_dev = iio_allocate_device();
930 if (chip->indio_dev == NULL) {
931 ret = -ENOMEM;
932 goto error_free_chip;
933 }
934
935 chip->indio_dev->dev.parent = &client->dev;
936 chip->indio_dev->attrs = &ad7291_attribute_group;
937 chip->indio_dev->event_attrs = &ad7291_event_attribute_group;
938 chip->indio_dev->dev_data = (void *)chip;
939 chip->indio_dev->driver_module = THIS_MODULE;
940 chip->indio_dev->num_interrupt_lines = 1;
941 chip->indio_dev->modes = INDIO_DIRECT_MODE;
942
943 ret = iio_device_register(chip->indio_dev);
944 if (ret)
945 goto error_free_dev;
946
947 if (client->irq > 0) {
948 ret = iio_register_interrupt_line(client->irq,
949 chip->indio_dev,
950 0,
951 IRQF_TRIGGER_LOW,
952 chip->name);
953 if (ret)
954 goto error_unreg_dev;
955
956 /*
957 * The event handler list element refer to iio_event_ad7291.
958 * All event attributes bind to the same event handler.
959 * So, only register event handler once.
960 */
961 iio_add_event_to_list(&iio_event_ad7291,
962 &chip->indio_dev->interrupts[0]->ev_list);
963
964 INIT_WORK(&chip->thresh_work, ad7291_interrupt_bh);
965
966 /* set irq polarity low level */
967 chip->command |= AD7291_ALART_POLARITY;
968 }
969
970 ret = ad7291_i2c_write(chip, AD7291_COMMAND, chip->command);
971 if (ret) {
972 ret = -EIO;
973 goto error_unreg_irq;
974 }
975
976 dev_info(&client->dev, "%s temperature sensor registered.\n",
977 id->name);
978
979 return 0;
980
981error_unreg_irq:
982 iio_unregister_interrupt_line(chip->indio_dev, 0);
983error_unreg_dev:
984 iio_device_unregister(chip->indio_dev);
985error_free_dev:
986 iio_free_device(chip->indio_dev);
987error_free_chip:
988 kfree(chip);
989
990 return ret;
991}
992
993static int __devexit ad7291_remove(struct i2c_client *client)
994{
995 struct ad7291_chip_info *chip = i2c_get_clientdata(client);
996 struct iio_dev *indio_dev = chip->indio_dev;
997
998 if (client->irq)
999 iio_unregister_interrupt_line(indio_dev, 0);
1000 iio_device_unregister(indio_dev);
1001 iio_free_device(chip->indio_dev);
1002 kfree(chip);
1003
1004 return 0;
1005}
1006
1007static const struct i2c_device_id ad7291_id[] = {
1008 { "ad7291", 0 },
1009 {}
1010};
1011
1012MODULE_DEVICE_TABLE(i2c, ad7291_id);
1013
1014static struct i2c_driver ad7291_driver = {
1015 .driver = {
1016 .name = "ad7291",
1017 },
1018 .probe = ad7291_probe,
1019 .remove = __devexit_p(ad7291_remove),
1020 .id_table = ad7291_id,
1021};
1022
1023static __init int ad7291_init(void)
1024{
1025 return i2c_add_driver(&ad7291_driver);
1026}
1027
1028static __exit void ad7291_exit(void)
1029{
1030 i2c_del_driver(&ad7291_driver);
1031}
1032
1033MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
1034MODULE_DESCRIPTION("Analog Devices AD7291 digital"
1035 " temperature sensor driver");
1036MODULE_LICENSE("GPL v2");
1037
1038module_init(ad7291_init);
1039module_exit(ad7291_exit);
diff --git a/drivers/staging/iio/adc/ad7298.c b/drivers/staging/iio/adc/ad7298.c
new file mode 100644
index 000000000000..1a080c977637
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7298.c
@@ -0,0 +1,501 @@
1/*
2 * AD7298 digital temperature sensor driver supporting AD7298
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/workqueue.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/sysfs.h>
16#include <linux/list.h>
17#include <linux/spi/spi.h>
18#include <linux/rtc.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23/*
24 * AD7298 command
25 */
26#define AD7298_PD 0x1
27#define AD7298_T_AVG_MASK 0x2
28#define AD7298_EXT_REF 0x4
29#define AD7298_T_SENSE_MASK 0x20
30#define AD7298_VOLTAGE_MASK 0x3fc0
31#define AD7298_VOLTAGE_OFFSET 0x6
32#define AD7298_VOLTAGE_LIMIT_COUNT 8
33#define AD7298_REPEAT 0x40
34#define AD7298_WRITE 0x80
35
36/*
37 * AD7298 value masks
38 */
39#define AD7298_CHANNEL_MASK 0xf000
40#define AD7298_VALUE_MASK 0xfff
41#define AD7298_T_VALUE_SIGN 0x400
42#define AD7298_T_VALUE_FLOAT_OFFSET 2
43#define AD7298_T_VALUE_FLOAT_MASK 0x2
44
45/*
46 * struct ad7298_chip_info - chip specifc information
47 */
48
49struct ad7298_chip_info {
50 const char *name;
51 struct spi_device *spi_dev;
52 struct iio_dev *indio_dev;
53 u16 command;
54 u16 busy_pin;
55 u8 channels; /* Active voltage channels */
56};
57
58/*
59 * ad7298 register access by SPI
60 */
61static int ad7298_spi_write(struct ad7298_chip_info *chip, u16 data)
62{
63 struct spi_device *spi_dev = chip->spi_dev;
64 int ret = 0;
65
66 data |= AD7298_WRITE;
67 data = cpu_to_be16(data);
68 ret = spi_write(spi_dev, (u8 *)&data, sizeof(data));
69 if (ret < 0)
70 dev_err(&spi_dev->dev, "SPI write error\n");
71
72 return ret;
73}
74
75static int ad7298_spi_read(struct ad7298_chip_info *chip, u16 mask, u16 *data)
76{
77 struct spi_device *spi_dev = chip->spi_dev;
78 int ret = 0;
79 u8 count = chip->channels;
80 u16 command;
81 int i;
82
83 if (mask & AD7298_T_SENSE_MASK) {
84 command = chip->command & ~(AD7298_T_AVG_MASK | AD7298_VOLTAGE_MASK);
85 command |= AD7298_T_SENSE_MASK;
86 count = 1;
87 } else if (mask & AD7298_T_AVG_MASK) {
88 command = chip->command & ~AD7298_VOLTAGE_MASK;
89 command |= AD7298_T_SENSE_MASK | AD7298_T_AVG_MASK;
90 count = 2;
91 } else if (mask & AD7298_VOLTAGE_MASK) {
92 command = chip->command & ~(AD7298_T_AVG_MASK | AD7298_T_SENSE_MASK);
93 count = chip->channels;
94 }
95
96 ret = ad7298_spi_write(chip, chip->command);
97 if (ret < 0) {
98 dev_err(&spi_dev->dev, "SPI write command error\n");
99 return ret;
100 }
101
102 ret = spi_read(spi_dev, (u8 *)&command, sizeof(command));
103 if (ret < 0) {
104 dev_err(&spi_dev->dev, "SPI read error\n");
105 return ret;
106 }
107
108 i = 10000;
109 while (i && gpio_get_value(chip->busy_pin)) {
110 cpu_relax();
111 i--;
112 }
113 if (!i) {
114 dev_err(&spi_dev->dev, "Always in busy convertion.\n");
115 return -EBUSY;
116 }
117
118 for (i = 0; i < count; i++) {
119 ret = spi_read(spi_dev, (u8 *)&data[i], sizeof(data[i]));
120 if (ret < 0) {
121 dev_err(&spi_dev->dev, "SPI read error\n");
122 return ret;
123 }
124 *data = be16_to_cpu(data[i]);
125 }
126
127 return 0;
128}
129
130static ssize_t ad7298_show_mode(struct device *dev,
131 struct device_attribute *attr,
132 char *buf)
133{
134 struct iio_dev *dev_info = dev_get_drvdata(dev);
135 struct ad7298_chip_info *chip = dev_info->dev_data;
136
137 if (chip->command & AD7298_REPEAT)
138 return sprintf(buf, "repeat\n");
139 else
140 return sprintf(buf, "normal\n");
141}
142
143static ssize_t ad7298_store_mode(struct device *dev,
144 struct device_attribute *attr,
145 const char *buf,
146 size_t len)
147{
148 struct iio_dev *dev_info = dev_get_drvdata(dev);
149 struct ad7298_chip_info *chip = dev_info->dev_data;
150
151 if (strcmp(buf, "repeat"))
152 chip->command |= AD7298_REPEAT;
153 else
154 chip->command &= (~AD7298_REPEAT);
155
156 return 1;
157}
158
159static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
160 ad7298_show_mode,
161 ad7298_store_mode,
162 0);
163
164static ssize_t ad7298_show_available_modes(struct device *dev,
165 struct device_attribute *attr,
166 char *buf)
167{
168 return sprintf(buf, "normal\nrepeat\n");
169}
170
171static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7298_show_available_modes, NULL, 0);
172
173static ssize_t ad7298_store_reset(struct device *dev,
174 struct device_attribute *attr,
175 const char *buf,
176 size_t len)
177{
178 struct iio_dev *dev_info = dev_get_drvdata(dev);
179 struct ad7298_chip_info *chip = dev_info->dev_data;
180 u16 command;
181 int ret;
182
183 command = chip->command & ~AD7298_PD;
184
185 ret = ad7298_spi_write(chip, command);
186 if (ret)
187 return -EIO;
188
189 command = chip->command | AD7298_PD;
190
191 ret = ad7298_spi_write(chip, command);
192 if (ret)
193 return -EIO;
194
195 return len;
196}
197
198static IIO_DEVICE_ATTR(reset, S_IWUSR,
199 NULL,
200 ad7298_store_reset,
201 0);
202
203static ssize_t ad7298_show_ext_ref(struct device *dev,
204 struct device_attribute *attr,
205 char *buf)
206{
207 struct iio_dev *dev_info = dev_get_drvdata(dev);
208 struct ad7298_chip_info *chip = dev_info->dev_data;
209
210 return sprintf(buf, "%d\n", !!(chip->command & AD7298_EXT_REF));
211}
212
213static ssize_t ad7298_store_ext_ref(struct device *dev,
214 struct device_attribute *attr,
215 const char *buf,
216 size_t len)
217{
218 struct iio_dev *dev_info = dev_get_drvdata(dev);
219 struct ad7298_chip_info *chip = dev_info->dev_data;
220 u16 command;
221 int ret;
222
223 command = chip->command & (~AD7298_EXT_REF);
224 if (strcmp(buf, "1"))
225 command |= AD7298_EXT_REF;
226
227 ret = ad7298_spi_write(chip, command);
228 if (ret)
229 return -EIO;
230
231 chip->command = command;
232
233 return len;
234}
235
236static IIO_DEVICE_ATTR(ext_ref, S_IRUGO | S_IWUSR,
237 ad7298_show_ext_ref,
238 ad7298_store_ext_ref,
239 0);
240
241static ssize_t ad7298_show_t_sense(struct device *dev,
242 struct device_attribute *attr,
243 char *buf)
244{
245 struct iio_dev *dev_info = dev_get_drvdata(dev);
246 struct ad7298_chip_info *chip = dev_info->dev_data;
247 u16 data;
248 char sign = ' ';
249 int ret;
250
251 ret = ad7298_spi_read(chip, AD7298_T_SENSE_MASK, &data);
252 if (ret)
253 return -EIO;
254
255 if (data & AD7298_T_VALUE_SIGN) {
256 /* convert supplement to positive value */
257 data = (AD7298_T_VALUE_SIGN << 1) - data;
258 sign = '-';
259 }
260
261 return sprintf(buf, "%c%d.%.2d\n", sign,
262 (data >> AD7298_T_VALUE_FLOAT_OFFSET),
263 (data & AD7298_T_VALUE_FLOAT_MASK) * 25);
264}
265
266static IIO_DEVICE_ATTR(t_sense, S_IRUGO, ad7298_show_t_sense, NULL, 0);
267
268static ssize_t ad7298_show_t_average(struct device *dev,
269 struct device_attribute *attr,
270 char *buf)
271{
272 struct iio_dev *dev_info = dev_get_drvdata(dev);
273 struct ad7298_chip_info *chip = dev_info->dev_data;
274 u16 data[2];
275 char sign = ' ';
276 int ret;
277
278 ret = ad7298_spi_read(chip, AD7298_T_AVG_MASK, data);
279 if (ret)
280 return -EIO;
281
282 if (data[1] & AD7298_T_VALUE_SIGN) {
283 /* convert supplement to positive value */
284 data[1] = (AD7298_T_VALUE_SIGN << 1) - data[1];
285 sign = '-';
286 }
287
288 return sprintf(buf, "%c%d.%.2d\n", sign,
289 (data[1] >> AD7298_T_VALUE_FLOAT_OFFSET),
290 (data[1] & AD7298_T_VALUE_FLOAT_MASK) * 25);
291}
292
293static IIO_DEVICE_ATTR(t_average, S_IRUGO, ad7298_show_t_average, NULL, 0);
294
295static ssize_t ad7298_show_voltage(struct device *dev,
296 struct device_attribute *attr,
297 char *buf)
298{
299 struct iio_dev *dev_info = dev_get_drvdata(dev);
300 struct ad7298_chip_info *chip = dev_info->dev_data;
301 u16 data[AD7298_VOLTAGE_LIMIT_COUNT];
302 int i, size, ret;
303
304 ret = ad7298_spi_read(chip, AD7298_VOLTAGE_MASK, data);
305 if (ret)
306 return -EIO;
307
308 for (i = 0; i < AD7298_VOLTAGE_LIMIT_COUNT; i++) {
309 if (chip->command & (AD7298_T_SENSE_MASK << i)) {
310 ret = sprintf(buf, "channel[%d]=%d\n", i,
311 data[i] & AD7298_VALUE_MASK);
312 if (ret < 0)
313 break;
314 buf += ret;
315 size += ret;
316 }
317 }
318
319 return size;
320}
321
322static IIO_DEVICE_ATTR(voltage, S_IRUGO, ad7298_show_voltage, NULL, 0);
323
324static ssize_t ad7298_show_channel_mask(struct device *dev,
325 struct device_attribute *attr,
326 char *buf)
327{
328 struct iio_dev *dev_info = dev_get_drvdata(dev);
329 struct ad7298_chip_info *chip = dev_info->dev_data;
330
331 return sprintf(buf, "0x%x\n", (chip->command & AD7298_VOLTAGE_MASK) >>
332 AD7298_VOLTAGE_OFFSET);
333}
334
335static ssize_t ad7298_store_channel_mask(struct device *dev,
336 struct device_attribute *attr,
337 const char *buf,
338 size_t len)
339{
340 struct iio_dev *dev_info = dev_get_drvdata(dev);
341 struct ad7298_chip_info *chip = dev_info->dev_data;
342 unsigned long data;
343 int i, ret;
344
345 ret = strict_strtoul(buf, 16, &data);
346 if (ret || data > 0xff)
347 return -EINVAL;
348
349 chip->command &= (~AD7298_VOLTAGE_MASK);
350 chip->command |= data << AD7298_VOLTAGE_OFFSET;
351
352 for (i = 0, chip->channels = 0; i < AD7298_VOLTAGE_LIMIT_COUNT; i++) {
353 if (chip->command & (AD7298_T_SENSE_MASK << i))
354 chip->channels++;
355 }
356
357 return ret;
358}
359
360static IIO_DEVICE_ATTR(channel_mask, S_IRUGO | S_IWUSR,
361 ad7298_show_channel_mask,
362 ad7298_store_channel_mask,
363 0);
364
365static ssize_t ad7298_show_name(struct device *dev,
366 struct device_attribute *attr,
367 char *buf)
368{
369 struct iio_dev *dev_info = dev_get_drvdata(dev);
370 struct ad7298_chip_info *chip = dev_info->dev_data;
371 return sprintf(buf, "%s\n", chip->name);
372}
373
374static IIO_DEVICE_ATTR(name, S_IRUGO, ad7298_show_name, NULL, 0);
375
376static struct attribute *ad7298_attributes[] = {
377 &iio_dev_attr_available_modes.dev_attr.attr,
378 &iio_dev_attr_mode.dev_attr.attr,
379 &iio_dev_attr_reset.dev_attr.attr,
380 &iio_dev_attr_ext_ref.dev_attr.attr,
381 &iio_dev_attr_t_sense.dev_attr.attr,
382 &iio_dev_attr_t_average.dev_attr.attr,
383 &iio_dev_attr_voltage.dev_attr.attr,
384 &iio_dev_attr_channel_mask.dev_attr.attr,
385 &iio_dev_attr_name.dev_attr.attr,
386 NULL,
387};
388
389static const struct attribute_group ad7298_attribute_group = {
390 .attrs = ad7298_attributes,
391};
392
393/*
394 * device probe and remove
395 */
396static int __devinit ad7298_probe(struct spi_device *spi_dev)
397{
398 struct ad7298_chip_info *chip;
399 unsigned short *pins = spi_dev->dev.platform_data;
400 int ret = 0;
401
402 chip = kzalloc(sizeof(struct ad7298_chip_info), GFP_KERNEL);
403
404 if (chip == NULL)
405 return -ENOMEM;
406
407 /* this is only used for device removal purposes */
408 dev_set_drvdata(&spi_dev->dev, chip);
409
410 chip->spi_dev = spi_dev;
411 chip->name = spi_dev->modalias;
412 chip->busy_pin = pins[0];
413
414 ret = gpio_request(chip->busy_pin, chip->name);
415 if (ret) {
416 dev_err(&spi_dev->dev, "Fail to request busy gpio PIN %d.\n",
417 chip->busy_pin);
418 goto error_free_chip;
419 }
420 gpio_direction_input(chip->busy_pin);
421
422 chip->indio_dev = iio_allocate_device();
423 if (chip->indio_dev == NULL) {
424 ret = -ENOMEM;
425 goto error_free_gpio;
426 }
427
428 chip->indio_dev->dev.parent = &spi_dev->dev;
429 chip->indio_dev->attrs = &ad7298_attribute_group;
430 chip->indio_dev->dev_data = (void *)chip;
431 chip->indio_dev->driver_module = THIS_MODULE;
432 chip->indio_dev->modes = INDIO_DIRECT_MODE;
433
434 ret = iio_device_register(chip->indio_dev);
435 if (ret)
436 goto error_free_dev;
437
438 dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n",
439 chip->name);
440
441 return 0;
442
443error_free_dev:
444 iio_free_device(chip->indio_dev);
445error_free_gpio:
446 gpio_free(chip->busy_pin);
447error_free_chip:
448 kfree(chip);
449
450 return ret;
451}
452
453static int __devexit ad7298_remove(struct spi_device *spi_dev)
454{
455 struct ad7298_chip_info *chip = dev_get_drvdata(&spi_dev->dev);
456 struct iio_dev *indio_dev = chip->indio_dev;
457
458 dev_set_drvdata(&spi_dev->dev, NULL);
459 iio_device_unregister(indio_dev);
460 iio_free_device(chip->indio_dev);
461 gpio_free(chip->busy_pin);
462 kfree(chip);
463
464 return 0;
465}
466
467static const struct spi_device_id ad7298_id[] = {
468 { "ad7298", 0 },
469 {}
470};
471
472MODULE_DEVICE_TABLE(spi, ad7298_id);
473
474static struct spi_driver ad7298_driver = {
475 .driver = {
476 .name = "ad7298",
477 .bus = &spi_bus_type,
478 .owner = THIS_MODULE,
479 },
480 .probe = ad7298_probe,
481 .remove = __devexit_p(ad7298_remove),
482 .id_table = ad7298_id,
483};
484
485static __init int ad7298_init(void)
486{
487 return spi_register_driver(&ad7298_driver);
488}
489
490static __exit void ad7298_exit(void)
491{
492 spi_unregister_driver(&ad7298_driver);
493}
494
495MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
496MODULE_DESCRIPTION("Analog Devices AD7298 digital"
497 " temperature sensor and ADC driver");
498MODULE_LICENSE("GPL v2");
499
500module_init(ad7298_init);
501module_exit(ad7298_exit);
diff --git a/drivers/staging/iio/adc/ad7314.c b/drivers/staging/iio/adc/ad7314.c
new file mode 100644
index 000000000000..8c17b1fe9026
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7314.c
@@ -0,0 +1,308 @@
1/*
2 * AD7314 digital temperature sensor driver for AD7314, ADT7301 and ADT7302
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/workqueue.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/sysfs.h>
16#include <linux/list.h>
17#include <linux/spi/spi.h>
18#include <linux/rtc.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23/*
24 * AD7314 power mode
25 */
26#define AD7314_PD 0x2000
27
28/*
29 * AD7314 temperature masks
30 */
31#define AD7314_TEMP_SIGN 0x200
32#define AD7314_TEMP_MASK 0x7FE0
33#define AD7314_TEMP_OFFSET 5
34#define AD7314_TEMP_FLOAT_OFFSET 2
35#define AD7314_TEMP_FLOAT_MASK 0x3
36
37/*
38 * ADT7301 and ADT7302 temperature masks
39 */
40#define ADT7301_TEMP_SIGN 0x2000
41#define ADT7301_TEMP_MASK 0x2FFF
42#define ADT7301_TEMP_FLOAT_OFFSET 5
43#define ADT7301_TEMP_FLOAT_MASK 0x1F
44
45/*
46 * struct ad7314_chip_info - chip specifc information
47 */
48
49struct ad7314_chip_info {
50 const char *name;
51 struct spi_device *spi_dev;
52 struct iio_dev *indio_dev;
53 s64 last_timestamp;
54 u8 mode;
55};
56
57/*
58 * ad7314 register access by SPI
59 */
60
61static int ad7314_spi_read(struct ad7314_chip_info *chip, u16 *data)
62{
63 struct spi_device *spi_dev = chip->spi_dev;
64 int ret = 0;
65 u16 value;
66
67 ret = spi_read(spi_dev, (u8 *)&value, sizeof(value));
68 if (ret < 0) {
69 dev_err(&spi_dev->dev, "SPI read error\n");
70 return ret;
71 }
72
73 *data = be16_to_cpu((u16)value);
74
75 return ret;
76}
77
78static int ad7314_spi_write(struct ad7314_chip_info *chip, u16 data)
79{
80 struct spi_device *spi_dev = chip->spi_dev;
81 int ret = 0;
82 u16 value = cpu_to_be16(data);
83
84 ret = spi_write(spi_dev, (u8 *)&value, sizeof(value));
85 if (ret < 0)
86 dev_err(&spi_dev->dev, "SPI write error\n");
87
88 return ret;
89}
90
91static ssize_t ad7314_show_mode(struct device *dev,
92 struct device_attribute *attr,
93 char *buf)
94{
95 struct iio_dev *dev_info = dev_get_drvdata(dev);
96 struct ad7314_chip_info *chip = dev_info->dev_data;
97
98 if (chip->mode)
99 return sprintf(buf, "power-save\n");
100 else
101 return sprintf(buf, "full\n");
102}
103
104static ssize_t ad7314_store_mode(struct device *dev,
105 struct device_attribute *attr,
106 const char *buf,
107 size_t len)
108{
109 struct iio_dev *dev_info = dev_get_drvdata(dev);
110 struct ad7314_chip_info *chip = dev_info->dev_data;
111 u16 mode = 0;
112 int ret;
113
114 if (!strcmp(buf, "full"))
115 mode = AD7314_PD;
116
117 ret = ad7314_spi_write(chip, mode);
118 if (ret)
119 return -EIO;
120
121 chip->mode = mode;
122
123 return len;
124}
125
126static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
127 ad7314_show_mode,
128 ad7314_store_mode,
129 0);
130
131static ssize_t ad7314_show_available_modes(struct device *dev,
132 struct device_attribute *attr,
133 char *buf)
134{
135 return sprintf(buf, "full\npower-save\n");
136}
137
138static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7314_show_available_modes, NULL, 0);
139
140static ssize_t ad7314_show_temperature(struct device *dev,
141 struct device_attribute *attr,
142 char *buf)
143{
144 struct iio_dev *dev_info = dev_get_drvdata(dev);
145 struct ad7314_chip_info *chip = dev_info->dev_data;
146 u16 data;
147 char sign = ' ';
148 int ret;
149
150 if (chip->mode) {
151 ret = ad7314_spi_write(chip, 0);
152 if (ret)
153 return -EIO;
154 }
155
156 ret = ad7314_spi_read(chip, &data);
157 if (ret)
158 return -EIO;
159
160 if (chip->mode)
161 ad7314_spi_write(chip, chip->mode);
162
163 if (strcmp(chip->name, "ad7314")) {
164 data = (data & AD7314_TEMP_MASK) >>
165 AD7314_TEMP_OFFSET;
166 if (data & AD7314_TEMP_SIGN) {
167 data = (AD7314_TEMP_SIGN << 1) - data;
168 sign = '-';
169 }
170
171 return sprintf(buf, "%c%d.%.2d\n", sign,
172 data >> AD7314_TEMP_FLOAT_OFFSET,
173 (data & AD7314_TEMP_FLOAT_MASK) * 25);
174 } else {
175 data &= ADT7301_TEMP_MASK;
176 if (data & ADT7301_TEMP_SIGN) {
177 data = (ADT7301_TEMP_SIGN << 1) - data;
178 sign = '-';
179 }
180
181 return sprintf(buf, "%c%d.%.5d\n", sign,
182 data >> ADT7301_TEMP_FLOAT_OFFSET,
183 (data & ADT7301_TEMP_FLOAT_MASK) * 3125);
184 }
185}
186
187static IIO_DEVICE_ATTR(temperature, S_IRUGO, ad7314_show_temperature, NULL, 0);
188
189static ssize_t ad7314_show_name(struct device *dev,
190 struct device_attribute *attr,
191 char *buf)
192{
193 struct iio_dev *dev_info = dev_get_drvdata(dev);
194 struct ad7314_chip_info *chip = dev_info->dev_data;
195 return sprintf(buf, "%s\n", chip->name);
196}
197
198static IIO_DEVICE_ATTR(name, S_IRUGO, ad7314_show_name, NULL, 0);
199
200static struct attribute *ad7314_attributes[] = {
201 &iio_dev_attr_available_modes.dev_attr.attr,
202 &iio_dev_attr_mode.dev_attr.attr,
203 &iio_dev_attr_temperature.dev_attr.attr,
204 &iio_dev_attr_name.dev_attr.attr,
205 NULL,
206};
207
208static const struct attribute_group ad7314_attribute_group = {
209 .attrs = ad7314_attributes,
210};
211
212/*
213 * device probe and remove
214 */
215
216static int __devinit ad7314_probe(struct spi_device *spi_dev)
217{
218 struct ad7314_chip_info *chip;
219 int ret = 0;
220
221 chip = kzalloc(sizeof(struct ad7314_chip_info), GFP_KERNEL);
222
223 if (chip == NULL)
224 return -ENOMEM;
225
226 /* this is only used for device removal purposes */
227 dev_set_drvdata(&spi_dev->dev, chip);
228
229 chip->spi_dev = spi_dev;
230 chip->name = spi_dev->modalias;
231
232 chip->indio_dev = iio_allocate_device();
233 if (chip->indio_dev == NULL) {
234 ret = -ENOMEM;
235 goto error_free_chip;
236 }
237
238 chip->indio_dev->dev.parent = &spi_dev->dev;
239 chip->indio_dev->attrs = &ad7314_attribute_group;
240 chip->indio_dev->dev_data = (void *)chip;
241 chip->indio_dev->driver_module = THIS_MODULE;
242
243 ret = iio_device_register(chip->indio_dev);
244 if (ret)
245 goto error_free_dev;
246
247 dev_info(&spi_dev->dev, "%s temperature sensor registered.\n",
248 chip->name);
249
250 return 0;
251error_free_dev:
252 iio_free_device(chip->indio_dev);
253error_free_chip:
254 kfree(chip);
255
256 return ret;
257}
258
259static int __devexit ad7314_remove(struct spi_device *spi_dev)
260{
261 struct ad7314_chip_info *chip = dev_get_drvdata(&spi_dev->dev);
262 struct iio_dev *indio_dev = chip->indio_dev;
263
264 dev_set_drvdata(&spi_dev->dev, NULL);
265 if (spi_dev->irq)
266 iio_unregister_interrupt_line(indio_dev, 0);
267 iio_device_unregister(indio_dev);
268 iio_free_device(chip->indio_dev);
269 kfree(chip);
270
271 return 0;
272}
273
274static const struct spi_device_id ad7314_id[] = {
275 { "adt7301", 0 },
276 { "adt7302", 0 },
277 { "ad7314", 0 },
278 {}
279};
280
281static struct spi_driver ad7314_driver = {
282 .driver = {
283 .name = "ad7314",
284 .bus = &spi_bus_type,
285 .owner = THIS_MODULE,
286 },
287 .probe = ad7314_probe,
288 .remove = __devexit_p(ad7314_remove),
289 .id_table = ad7314_id,
290};
291
292static __init int ad7314_init(void)
293{
294 return spi_register_driver(&ad7314_driver);
295}
296
297static __exit void ad7314_exit(void)
298{
299 spi_unregister_driver(&ad7314_driver);
300}
301
302MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
303MODULE_DESCRIPTION("Analog Devices AD7314, ADT7301 and ADT7302 digital"
304 " temperature sensor driver");
305MODULE_LICENSE("GPL v2");
306
307module_init(ad7314_init);
308module_exit(ad7314_exit);
diff --git a/drivers/staging/iio/adc/ad7745.c b/drivers/staging/iio/adc/ad7745.c
new file mode 100644
index 000000000000..ab7ef8450ae2
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7745.c
@@ -0,0 +1,734 @@
1/*
2 * AD774X capacitive sensor driver supporting AD7745/6/7
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/workqueue.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/sysfs.h>
16#include <linux/list.h>
17#include <linux/i2c.h>
18#include <linux/rtc.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23/*
24 * AD774X registers definition
25 */
26
27#define AD774X_STATUS 0
28#define AD774X_STATUS_RDY (1 << 2)
29#define AD774X_STATUS_RDYVT (1 << 1)
30#define AD774X_STATUS_RDYCAP (1 << 0)
31#define AD774X_CAP_DATA_HIGH 1
32#define AD774X_CAP_DATA_MID 2
33#define AD774X_CAP_DATA_LOW 3
34#define AD774X_VT_DATA_HIGH 4
35#define AD774X_VT_DATA_MID 5
36#define AD774X_VT_DATA_LOW 6
37#define AD774X_CAP_SETUP 7
38#define AD774X_VT_SETUP 8
39#define AD774X_EXEC_SETUP 9
40#define AD774X_CFG 10
41#define AD774X_CAPDACA 11
42#define AD774X_CAPDACB 12
43#define AD774X_CAPDAC_EN (1 << 7)
44#define AD774X_CAP_OFFH 13
45#define AD774X_CAP_OFFL 14
46#define AD774X_CAP_GAINH 15
47#define AD774X_CAP_GAINL 16
48#define AD774X_VOLT_GAINH 17
49#define AD774X_VOLT_GAINL 18
50
51#define AD774X_MAX_CONV_MODE 6
52
53/*
54 * struct ad774x_chip_info - chip specifc information
55 */
56
57struct ad774x_chip_info {
58 const char *name;
59 struct i2c_client *client;
60 struct iio_dev *indio_dev;
61 struct work_struct thresh_work;
62 bool inter;
63 s64 last_timestamp;
64 u16 cap_offs; /* Capacitive offset */
65 u16 cap_gain; /* Capacitive gain calibration */
66 u16 volt_gain; /* Voltage gain calibration */
67 u8 cap_setup;
68 u8 vt_setup;
69 u8 exec_setup;
70
71 char *conversion_mode;
72};
73
74struct ad774x_conversion_mode {
75 char *name;
76 u8 reg_cfg;
77};
78
79struct ad774x_conversion_mode ad774x_conv_mode_table[AD774X_MAX_CONV_MODE] = {
80 { "idle", 0 },
81 { "continuous-conversion", 1 },
82 { "single-conversion", 2 },
83 { "power-down", 3 },
84 { "offset-calibration", 5 },
85 { "gain-calibration", 6 },
86};
87
88/*
89 * ad774x register access by I2C
90 */
91
92static int ad774x_i2c_read(struct ad774x_chip_info *chip, u8 reg, u8 *data, int len)
93{
94 struct i2c_client *client = chip->client;
95 int ret;
96
97 ret = i2c_master_send(client, &reg, 1);
98 if (ret < 0) {
99 dev_err(&client->dev, "I2C write error\n");
100 return ret;
101 }
102
103 ret = i2c_master_recv(client, data, len);
104 if (ret < 0) {
105 dev_err(&client->dev, "I2C read error\n");
106 return ret;
107 }
108
109 return ret;
110}
111
112static int ad774x_i2c_write(struct ad774x_chip_info *chip, u8 reg, u8 data)
113{
114 struct i2c_client *client = chip->client;
115 int ret;
116
117 u8 tx[2] = {
118 reg,
119 data,
120 };
121
122 ret = i2c_master_send(client, tx, 2);
123 if (ret < 0)
124 dev_err(&client->dev, "I2C write error\n");
125
126 return ret;
127}
128
129/*
130 * sysfs nodes
131 */
132
133#define IIO_DEV_ATTR_AVAIL_CONVERSION_MODES(_show) \
134 IIO_DEVICE_ATTR(available_conversion_modes, S_IRUGO, _show, NULL, 0)
135#define IIO_DEV_ATTR_CONVERSION_MODE(_mode, _show, _store) \
136 IIO_DEVICE_ATTR(conversion_mode, _mode, _show, _store, 0)
137#define IIO_DEV_ATTR_CAP_SETUP(_mode, _show, _store) \
138 IIO_DEVICE_ATTR(cap_setup, _mode, _show, _store, 0)
139#define IIO_DEV_ATTR_VT_SETUP(_mode, _show, _store) \
140 IIO_DEVICE_ATTR(in0_setup, _mode, _show, _store, 0)
141#define IIO_DEV_ATTR_EXEC_SETUP(_mode, _show, _store) \
142 IIO_DEVICE_ATTR(exec_setup, _mode, _show, _store, 0)
143#define IIO_DEV_ATTR_VOLT_GAIN(_mode, _show, _store) \
144 IIO_DEVICE_ATTR(in0_gain, _mode, _show, _store, 0)
145#define IIO_DEV_ATTR_CAP_OFFS(_mode, _show, _store) \
146 IIO_DEVICE_ATTR(cap_offs, _mode, _show, _store, 0)
147#define IIO_DEV_ATTR_CAP_GAIN(_mode, _show, _store) \
148 IIO_DEVICE_ATTR(cap_gain, _mode, _show, _store, 0)
149#define IIO_DEV_ATTR_CAP_DATA(_show) \
150 IIO_DEVICE_ATTR(cap0_raw, S_IRUGO, _show, NULL, 0)
151#define IIO_DEV_ATTR_VT_DATA(_show) \
152 IIO_DEVICE_ATTR(in0_raw, S_IRUGO, _show, NULL, 0)
153
154static ssize_t ad774x_show_conversion_modes(struct device *dev,
155 struct device_attribute *attr,
156 char *buf)
157{
158 int i;
159 int len = 0;
160
161 for (i = 0; i < AD774X_MAX_CONV_MODE; i++)
162 len += sprintf(buf + len, "%s ", ad774x_conv_mode_table[i].name);
163
164 len += sprintf(buf + len, "\n");
165
166 return len;
167}
168
169static IIO_DEV_ATTR_AVAIL_CONVERSION_MODES(ad774x_show_conversion_modes);
170
171static ssize_t ad774x_show_conversion_mode(struct device *dev,
172 struct device_attribute *attr,
173 char *buf)
174{
175 struct iio_dev *dev_info = dev_get_drvdata(dev);
176 struct ad774x_chip_info *chip = dev_info->dev_data;
177
178 return sprintf(buf, "%s\n", chip->conversion_mode);
179}
180
181static ssize_t ad774x_store_conversion_mode(struct device *dev,
182 struct device_attribute *attr,
183 const char *buf,
184 size_t len)
185{
186 struct iio_dev *dev_info = dev_get_drvdata(dev);
187 struct ad774x_chip_info *chip = dev_info->dev_data;
188 u8 cfg;
189 int i;
190
191 ad774x_i2c_read(chip, AD774X_CFG, &cfg, 1);
192
193 for (i = 0; i < AD774X_MAX_CONV_MODE; i++) {
194 if (strncmp(buf, ad774x_conv_mode_table[i].name,
195 strlen(ad774x_conv_mode_table[i].name) - 1) == 0) {
196 chip->conversion_mode = ad774x_conv_mode_table[i].name;
197 cfg |= 0x18 | ad774x_conv_mode_table[i].reg_cfg;
198 ad774x_i2c_write(chip, AD774X_CFG, cfg);
199 return len;
200 }
201 }
202
203 dev_err(dev, "not supported conversion mode\n");
204
205 return -EINVAL;
206}
207
208static IIO_DEV_ATTR_CONVERSION_MODE(S_IRUGO | S_IWUSR,
209 ad774x_show_conversion_mode,
210 ad774x_store_conversion_mode);
211
212static ssize_t ad774x_show_dac_value(struct device *dev,
213 struct device_attribute *attr,
214 char *buf)
215{
216 struct iio_dev *dev_info = dev_get_drvdata(dev);
217 struct ad774x_chip_info *chip = dev_info->dev_data;
218 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
219 u8 data;
220
221 ad774x_i2c_read(chip, this_attr->address, &data, 1);
222
223 return sprintf(buf, "%02x\n", data & 0x7F);
224}
225
226static ssize_t ad774x_store_dac_value(struct device *dev,
227 struct device_attribute *attr,
228 const char *buf,
229 size_t len)
230{
231 struct iio_dev *dev_info = dev_get_drvdata(dev);
232 struct ad774x_chip_info *chip = dev_info->dev_data;
233 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
234 unsigned long data;
235 int ret;
236
237 ret = strict_strtoul(buf, 10, &data);
238
239 if (!ret) {
240 ad774x_i2c_write(chip, this_attr->address,
241 (data ? AD774X_CAPDAC_EN : 0) | (data & 0x7F));
242 return len;
243 }
244
245 return -EINVAL;
246}
247
248static IIO_DEVICE_ATTR(capdac0_raw, S_IRUGO | S_IWUSR,
249 ad774x_show_dac_value,
250 ad774x_store_dac_value,
251 AD774X_CAPDACA);
252
253static IIO_DEVICE_ATTR(capdac1_raw, S_IRUGO | S_IWUSR,
254 ad774x_show_dac_value,
255 ad774x_store_dac_value,
256 AD774X_CAPDACB);
257
258static ssize_t ad774x_show_cap_setup(struct device *dev,
259 struct device_attribute *attr,
260 char *buf)
261{
262 struct iio_dev *dev_info = dev_get_drvdata(dev);
263 struct ad774x_chip_info *chip = dev_info->dev_data;
264
265 return sprintf(buf, "0x%02x\n", chip->cap_setup);
266}
267
268static ssize_t ad774x_store_cap_setup(struct device *dev,
269 struct device_attribute *attr,
270 const char *buf,
271 size_t len)
272{
273 struct iio_dev *dev_info = dev_get_drvdata(dev);
274 struct ad774x_chip_info *chip = dev_info->dev_data;
275 unsigned long data;
276 int ret;
277
278 ret = strict_strtoul(buf, 10, &data);
279
280 if ((!ret) && (data < 0x100)) {
281 ad774x_i2c_write(chip, AD774X_CAP_SETUP, data);
282 chip->cap_setup = data;
283 return len;
284 }
285
286 return -EINVAL;
287}
288
289static IIO_DEV_ATTR_CAP_SETUP(S_IRUGO | S_IWUSR,
290 ad774x_show_cap_setup,
291 ad774x_store_cap_setup);
292
293static ssize_t ad774x_show_vt_setup(struct device *dev,
294 struct device_attribute *attr,
295 char *buf)
296{
297 struct iio_dev *dev_info = dev_get_drvdata(dev);
298 struct ad774x_chip_info *chip = dev_info->dev_data;
299
300 return sprintf(buf, "0x%02x\n", chip->vt_setup);
301}
302
303static ssize_t ad774x_store_vt_setup(struct device *dev,
304 struct device_attribute *attr,
305 const char *buf,
306 size_t len)
307{
308 struct iio_dev *dev_info = dev_get_drvdata(dev);
309 struct ad774x_chip_info *chip = dev_info->dev_data;
310 unsigned long data;
311 int ret;
312
313 ret = strict_strtoul(buf, 10, &data);
314
315 if ((!ret) && (data < 0x100)) {
316 ad774x_i2c_write(chip, AD774X_VT_SETUP, data);
317 chip->vt_setup = data;
318 return len;
319 }
320
321 return -EINVAL;
322}
323
324static IIO_DEV_ATTR_VT_SETUP(S_IRUGO | S_IWUSR,
325 ad774x_show_vt_setup,
326 ad774x_store_vt_setup);
327
328static ssize_t ad774x_show_exec_setup(struct device *dev,
329 struct device_attribute *attr,
330 char *buf)
331{
332 struct iio_dev *dev_info = dev_get_drvdata(dev);
333 struct ad774x_chip_info *chip = dev_info->dev_data;
334
335 return sprintf(buf, "0x%02x\n", chip->exec_setup);
336}
337
338static ssize_t ad774x_store_exec_setup(struct device *dev,
339 struct device_attribute *attr,
340 const char *buf,
341 size_t len)
342{
343 struct iio_dev *dev_info = dev_get_drvdata(dev);
344 struct ad774x_chip_info *chip = dev_info->dev_data;
345 unsigned long data;
346 int ret;
347
348 ret = strict_strtoul(buf, 10, &data);
349
350 if ((!ret) && (data < 0x100)) {
351 ad774x_i2c_write(chip, AD774X_EXEC_SETUP, data);
352 chip->exec_setup = data;
353 return len;
354 }
355
356 return -EINVAL;
357}
358
359static IIO_DEV_ATTR_EXEC_SETUP(S_IRUGO | S_IWUSR,
360 ad774x_show_exec_setup,
361 ad774x_store_exec_setup);
362
363static ssize_t ad774x_show_volt_gain(struct device *dev,
364 struct device_attribute *attr,
365 char *buf)
366{
367 struct iio_dev *dev_info = dev_get_drvdata(dev);
368 struct ad774x_chip_info *chip = dev_info->dev_data;
369
370 return sprintf(buf, "%d\n", chip->volt_gain);
371}
372
373static ssize_t ad774x_store_volt_gain(struct device *dev,
374 struct device_attribute *attr,
375 const char *buf,
376 size_t len)
377{
378 struct iio_dev *dev_info = dev_get_drvdata(dev);
379 struct ad774x_chip_info *chip = dev_info->dev_data;
380 unsigned long data;
381 int ret;
382
383 ret = strict_strtoul(buf, 10, &data);
384
385 if ((!ret) && (data < 0x10000)) {
386 ad774x_i2c_write(chip, AD774X_VOLT_GAINH, data >> 8);
387 ad774x_i2c_write(chip, AD774X_VOLT_GAINL, data);
388 chip->volt_gain = data;
389 return len;
390 }
391
392 return -EINVAL;
393}
394
395static IIO_DEV_ATTR_VOLT_GAIN(S_IRUGO | S_IWUSR,
396 ad774x_show_volt_gain,
397 ad774x_store_volt_gain);
398
399static ssize_t ad774x_show_cap_data(struct device *dev,
400 struct device_attribute *attr,
401 char *buf)
402{
403 struct iio_dev *dev_info = dev_get_drvdata(dev);
404 struct ad774x_chip_info *chip = dev_info->dev_data;
405 unsigned long data;
406 char tmp[3];
407
408 ad774x_i2c_read(chip, AD774X_CAP_DATA_HIGH, tmp, 3);
409 data = ((int)tmp[0] << 16) | ((int)tmp[1] << 8) | (int)tmp[2];
410
411 return sprintf(buf, "%ld\n", data);
412}
413
414static IIO_DEV_ATTR_CAP_DATA(ad774x_show_cap_data);
415
416static ssize_t ad774x_show_vt_data(struct device *dev,
417 struct device_attribute *attr,
418 char *buf)
419{
420 struct iio_dev *dev_info = dev_get_drvdata(dev);
421 struct ad774x_chip_info *chip = dev_info->dev_data;
422 unsigned long data;
423 char tmp[3];
424
425 ad774x_i2c_read(chip, AD774X_VT_DATA_HIGH, tmp, 3);
426 data = ((int)tmp[0] << 16) | ((int)tmp[1] << 8) | (int)tmp[2];
427
428 return sprintf(buf, "%ld\n", data);
429}
430
431static IIO_DEV_ATTR_VT_DATA(ad774x_show_vt_data);
432
433static ssize_t ad774x_show_cap_offs(struct device *dev,
434 struct device_attribute *attr,
435 char *buf)
436{
437 struct iio_dev *dev_info = dev_get_drvdata(dev);
438 struct ad774x_chip_info *chip = dev_info->dev_data;
439
440 return sprintf(buf, "%d\n", chip->cap_offs);
441}
442
443static ssize_t ad774x_store_cap_offs(struct device *dev,
444 struct device_attribute *attr,
445 const char *buf,
446 size_t len)
447{
448 struct iio_dev *dev_info = dev_get_drvdata(dev);
449 struct ad774x_chip_info *chip = dev_info->dev_data;
450 unsigned long data;
451 int ret;
452
453 ret = strict_strtoul(buf, 10, &data);
454
455 if ((!ret) && (data < 0x10000)) {
456 ad774x_i2c_write(chip, AD774X_CAP_OFFH, data >> 8);
457 ad774x_i2c_write(chip, AD774X_CAP_OFFL, data);
458 chip->cap_offs = data;
459 return len;
460 }
461
462 return -EINVAL;
463}
464
465static IIO_DEV_ATTR_CAP_OFFS(S_IRUGO | S_IWUSR,
466 ad774x_show_cap_offs,
467 ad774x_store_cap_offs);
468
469static ssize_t ad774x_show_cap_gain(struct device *dev,
470 struct device_attribute *attr,
471 char *buf)
472{
473 struct iio_dev *dev_info = dev_get_drvdata(dev);
474 struct ad774x_chip_info *chip = dev_info->dev_data;
475
476 return sprintf(buf, "%d\n", chip->cap_gain);
477}
478
479static ssize_t ad774x_store_cap_gain(struct device *dev,
480 struct device_attribute *attr,
481 const char *buf,
482 size_t len)
483{
484 struct iio_dev *dev_info = dev_get_drvdata(dev);
485 struct ad774x_chip_info *chip = dev_info->dev_data;
486 unsigned long data;
487 int ret;
488
489 ret = strict_strtoul(buf, 10, &data);
490
491 if ((!ret) && (data < 0x10000)) {
492 ad774x_i2c_write(chip, AD774X_CAP_GAINH, data >> 8);
493 ad774x_i2c_write(chip, AD774X_CAP_GAINL, data);
494 chip->cap_gain = data;
495 return len;
496 }
497
498 return -EINVAL;
499}
500
501static IIO_DEV_ATTR_CAP_GAIN(S_IRUGO | S_IWUSR,
502 ad774x_show_cap_gain,
503 ad774x_store_cap_gain);
504
505static ssize_t ad774x_show_name(struct device *dev,
506 struct device_attribute *attr,
507 char *buf)
508{
509 struct iio_dev *dev_info = dev_get_drvdata(dev);
510 struct ad774x_chip_info *chip = dev_info->dev_data;
511 return sprintf(buf, "%s\n", chip->name);
512}
513
514static IIO_DEVICE_ATTR(name, S_IRUGO, ad774x_show_name, NULL, 0);
515
516static struct attribute *ad774x_attributes[] = {
517 &iio_dev_attr_available_conversion_modes.dev_attr.attr,
518 &iio_dev_attr_conversion_mode.dev_attr.attr,
519 &iio_dev_attr_cap_setup.dev_attr.attr,
520 &iio_dev_attr_in0_setup.dev_attr.attr,
521 &iio_dev_attr_exec_setup.dev_attr.attr,
522 &iio_dev_attr_cap_offs.dev_attr.attr,
523 &iio_dev_attr_cap_gain.dev_attr.attr,
524 &iio_dev_attr_in0_gain.dev_attr.attr,
525 &iio_dev_attr_in0_raw.dev_attr.attr,
526 &iio_dev_attr_cap0_raw.dev_attr.attr,
527 &iio_dev_attr_capdac0_raw.dev_attr.attr,
528 &iio_dev_attr_capdac1_raw.dev_attr.attr,
529 &iio_dev_attr_name.dev_attr.attr,
530 NULL,
531};
532
533static const struct attribute_group ad774x_attribute_group = {
534 .attrs = ad774x_attributes,
535};
536
537/*
538 * data ready events
539 */
540
541#define IIO_EVENT_CODE_CAP_RDY IIO_BUFFER_EVENT_CODE(0)
542#define IIO_EVENT_CODE_VT_RDY IIO_BUFFER_EVENT_CODE(1)
543
544#define IIO_EVENT_ATTR_CAP_RDY_SH(_evlist, _show, _store, _mask) \
545 IIO_EVENT_ATTR_SH(cap_rdy, _evlist, _show, _store, _mask)
546
547#define IIO_EVENT_ATTR_VT_RDY_SH(_evlist, _show, _store, _mask) \
548 IIO_EVENT_ATTR_SH(vt_rdy, _evlist, _show, _store, _mask)
549
550static void ad774x_interrupt_handler_bh(struct work_struct *work_s)
551{
552 struct ad774x_chip_info *chip =
553 container_of(work_s, struct ad774x_chip_info, thresh_work);
554 u8 int_status;
555
556 enable_irq(chip->client->irq);
557
558 ad774x_i2c_read(chip, AD774X_STATUS, &int_status, 1);
559
560 if (int_status & AD774X_STATUS_RDYCAP)
561 iio_push_event(chip->indio_dev, 0,
562 IIO_EVENT_CODE_CAP_RDY,
563 chip->last_timestamp);
564
565 if (int_status & AD774X_STATUS_RDYVT)
566 iio_push_event(chip->indio_dev, 0,
567 IIO_EVENT_CODE_VT_RDY,
568 chip->last_timestamp);
569}
570
571static int ad774x_interrupt_handler_th(struct iio_dev *dev_info,
572 int index,
573 s64 timestamp,
574 int no_test)
575{
576 struct ad774x_chip_info *chip = dev_info->dev_data;
577
578 chip->last_timestamp = timestamp;
579 schedule_work(&chip->thresh_work);
580
581 return 0;
582}
583
584IIO_EVENT_SH(data_rdy, &ad774x_interrupt_handler_th);
585
586static ssize_t ad774x_query_out_mode(struct device *dev,
587 struct device_attribute *attr,
588 char *buf)
589{
590 /*
591 * AD774X provides one /RDY pin, which can be used as interrupt
592 * but the pin is not configurable
593 */
594 return sprintf(buf, "1\n");
595}
596
597static ssize_t ad774x_set_out_mode(struct device *dev,
598 struct device_attribute *attr,
599 const char *buf,
600 size_t len)
601{
602 return len;
603}
604
605IIO_EVENT_ATTR_CAP_RDY_SH(iio_event_data_rdy, ad774x_query_out_mode, ad774x_set_out_mode, 0);
606IIO_EVENT_ATTR_VT_RDY_SH(iio_event_data_rdy, ad774x_query_out_mode, ad774x_set_out_mode, 0);
607
608static struct attribute *ad774x_event_attributes[] = {
609 &iio_event_attr_cap_rdy.dev_attr.attr,
610 &iio_event_attr_vt_rdy.dev_attr.attr,
611 NULL,
612};
613
614static struct attribute_group ad774x_event_attribute_group = {
615 .attrs = ad774x_event_attributes,
616};
617
618/*
619 * device probe and remove
620 */
621
622static int __devinit ad774x_probe(struct i2c_client *client,
623 const struct i2c_device_id *id)
624{
625 int ret = 0, regdone = 0;
626 struct ad774x_chip_info *chip = kzalloc(sizeof(*chip), GFP_KERNEL);
627 if (chip == NULL) {
628 ret = -ENOMEM;
629 goto error_ret;
630 }
631
632 /* this is only used for device removal purposes */
633 i2c_set_clientdata(client, chip);
634
635 chip->client = client;
636 chip->name = id->name;
637
638 chip->indio_dev = iio_allocate_device();
639 if (chip->indio_dev == NULL) {
640 ret = -ENOMEM;
641 goto error_free_chip;
642 }
643
644 /* Establish that the iio_dev is a child of the i2c device */
645 chip->indio_dev->dev.parent = &client->dev;
646 chip->indio_dev->attrs = &ad774x_attribute_group;
647 chip->indio_dev->event_attrs = &ad774x_event_attribute_group;
648 chip->indio_dev->dev_data = (void *)(chip);
649 chip->indio_dev->driver_module = THIS_MODULE;
650 chip->indio_dev->num_interrupt_lines = 1;
651 chip->indio_dev->modes = INDIO_DIRECT_MODE;
652
653 ret = iio_device_register(chip->indio_dev);
654 if (ret)
655 goto error_free_dev;
656 regdone = 1;
657
658 if (client->irq) {
659 ret = iio_register_interrupt_line(client->irq,
660 chip->indio_dev,
661 0,
662 IRQF_TRIGGER_FALLING,
663 "ad774x");
664 if (ret)
665 goto error_free_dev;
666
667 iio_add_event_to_list(iio_event_attr_cap_rdy.listel,
668 &chip->indio_dev->interrupts[0]->ev_list);
669
670 INIT_WORK(&chip->thresh_work, ad774x_interrupt_handler_bh);
671 }
672
673 dev_err(&client->dev, "%s capacitive sensor registered, irq: %d\n", id->name, client->irq);
674
675 return 0;
676
677error_free_dev:
678 if (regdone)
679 iio_device_unregister(chip->indio_dev);
680 else
681 iio_free_device(chip->indio_dev);
682error_free_chip:
683 kfree(chip);
684error_ret:
685 return ret;
686}
687
688static int __devexit ad774x_remove(struct i2c_client *client)
689{
690 struct ad774x_chip_info *chip = i2c_get_clientdata(client);
691 struct iio_dev *indio_dev = chip->indio_dev;
692
693 if (client->irq)
694 iio_unregister_interrupt_line(indio_dev, 0);
695 iio_device_unregister(indio_dev);
696 kfree(chip);
697
698 return 0;
699}
700
701static const struct i2c_device_id ad774x_id[] = {
702 { "ad7745", 0 },
703 { "ad7746", 0 },
704 { "ad7747", 0 },
705 {}
706};
707
708MODULE_DEVICE_TABLE(i2c, ad774x_id);
709
710static struct i2c_driver ad774x_driver = {
711 .driver = {
712 .name = "ad774x",
713 },
714 .probe = ad774x_probe,
715 .remove = __devexit_p(ad774x_remove),
716 .id_table = ad774x_id,
717};
718
719static __init int ad774x_init(void)
720{
721 return i2c_add_driver(&ad774x_driver);
722}
723
724static __exit void ad774x_exit(void)
725{
726 i2c_del_driver(&ad774x_driver);
727}
728
729MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
730MODULE_DESCRIPTION("Analog Devices ad7745/6/7 capacitive sensor driver");
731MODULE_LICENSE("GPL v2");
732
733module_init(ad774x_init);
734module_exit(ad774x_exit);
diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
new file mode 100644
index 000000000000..ad7415a6b8d9
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -0,0 +1,535 @@
1/*
2 * AD7816 digital temperature sensor driver supporting AD7816/7/8
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/workqueue.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/sysfs.h>
16#include <linux/list.h>
17#include <linux/spi/spi.h>
18#include <linux/rtc.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23/*
24 * AD7816 config masks
25 */
26#define AD7816_FULL 0x1
27#define AD7816_PD 0x2
28#define AD7816_CS_MASK 0x7
29#define AD7816_CS_MAX 0x4
30
31/*
32 * AD7816 temperature masks
33 */
34#define AD7816_VALUE_OFFSET 6
35#define AD7816_BOUND_VALUE_BASE 0x8
36#define AD7816_BOUND_VALUE_MIN -95
37#define AD7816_BOUND_VALUE_MAX 152
38#define AD7816_TEMP_FLOAT_OFFSET 2
39#define AD7816_TEMP_FLOAT_MASK 0x3
40
41
42/*
43 * struct ad7816_chip_info - chip specifc information
44 */
45
46struct ad7816_chip_info {
47 const char *name;
48 struct spi_device *spi_dev;
49 struct iio_dev *indio_dev;
50 struct work_struct thresh_work;
51 s64 last_timestamp;
52 u16 rdwr_pin;
53 u16 convert_pin;
54 u16 busy_pin;
55 u8 oti_data[AD7816_CS_MAX+1];
56 u8 channel_id; /* 0 always be temperature */
57 u8 mode;
58};
59
60/*
61 * ad7816 data access by SPI
62 */
63static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)
64{
65 struct spi_device *spi_dev = chip->spi_dev;
66 int ret = 0;
67
68 gpio_set_value(chip->rdwr_pin, 1);
69 gpio_set_value(chip->rdwr_pin, 0);
70 ret = spi_write(spi_dev, &chip->channel_id, sizeof(chip->channel_id));
71 if (ret < 0) {
72 dev_err(&spi_dev->dev, "SPI channel setting error\n");
73 return ret;
74 }
75 gpio_set_value(chip->rdwr_pin, 1);
76
77
78 if (chip->mode == AD7816_PD) { /* operating mode 2 */
79 gpio_set_value(chip->convert_pin, 1);
80 gpio_set_value(chip->convert_pin, 0);
81 } else { /* operating mode 1 */
82 gpio_set_value(chip->convert_pin, 0);
83 gpio_set_value(chip->convert_pin, 1);
84 }
85
86 while (gpio_get_value(chip->busy_pin))
87 cpu_relax();
88
89 gpio_set_value(chip->rdwr_pin, 0);
90 gpio_set_value(chip->rdwr_pin, 1);
91 ret = spi_read(spi_dev, (u8 *)data, sizeof(*data));
92 if (ret < 0) {
93 dev_err(&spi_dev->dev, "SPI data read error\n");
94 return ret;
95 }
96
97 *data = be16_to_cpu(*data);
98
99 return ret;
100}
101
102static int ad7816_spi_write(struct ad7816_chip_info *chip, u8 data)
103{
104 struct spi_device *spi_dev = chip->spi_dev;
105 int ret = 0;
106
107 gpio_set_value(chip->rdwr_pin, 1);
108 gpio_set_value(chip->rdwr_pin, 0);
109 ret = spi_write(spi_dev, &data, sizeof(data));
110 if (ret < 0)
111 dev_err(&spi_dev->dev, "SPI oti data write error\n");
112
113 return ret;
114}
115
116static ssize_t ad7816_show_mode(struct device *dev,
117 struct device_attribute *attr,
118 char *buf)
119{
120 struct iio_dev *dev_info = dev_get_drvdata(dev);
121 struct ad7816_chip_info *chip = dev_info->dev_data;
122
123 if (chip->mode)
124 return sprintf(buf, "power-save\n");
125 else
126 return sprintf(buf, "full\n");
127}
128
129static ssize_t ad7816_store_mode(struct device *dev,
130 struct device_attribute *attr,
131 const char *buf,
132 size_t len)
133{
134 struct iio_dev *dev_info = dev_get_drvdata(dev);
135 struct ad7816_chip_info *chip = dev_info->dev_data;
136
137 if (strcmp(buf, "full")) {
138 gpio_set_value(chip->rdwr_pin, 1);
139 chip->mode = AD7816_FULL;
140 } else {
141 gpio_set_value(chip->rdwr_pin, 0);
142 chip->mode = AD7816_PD;
143 }
144
145 return len;
146}
147
148static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
149 ad7816_show_mode,
150 ad7816_store_mode,
151 0);
152
153static ssize_t ad7816_show_available_modes(struct device *dev,
154 struct device_attribute *attr,
155 char *buf)
156{
157 return sprintf(buf, "full\npower-save\n");
158}
159
160static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7816_show_available_modes, NULL, 0);
161
162static ssize_t ad7816_show_channel(struct device *dev,
163 struct device_attribute *attr,
164 char *buf)
165{
166 struct iio_dev *dev_info = dev_get_drvdata(dev);
167 struct ad7816_chip_info *chip = dev_info->dev_data;
168
169 return sprintf(buf, "%d\n", chip->channel_id);
170}
171
172static ssize_t ad7816_store_channel(struct device *dev,
173 struct device_attribute *attr,
174 const char *buf,
175 size_t len)
176{
177 struct iio_dev *dev_info = dev_get_drvdata(dev);
178 struct ad7816_chip_info *chip = dev_info->dev_data;
179 unsigned long data;
180 int ret;
181
182 ret = strict_strtoul(buf, 10, &data);
183 if (ret)
184 return -EINVAL;
185
186 if (data > AD7816_CS_MAX && data != AD7816_CS_MASK) {
187 dev_err(&chip->spi_dev->dev, "Invalid channel id %lu for %s.\n",
188 data, chip->name);
189 return -EINVAL;
190 } else if (strcmp(chip->name, "ad7818") == 0 && data > 1) {
191 dev_err(&chip->spi_dev->dev,
192 "Invalid channel id %lu for ad7818.\n", data);
193 return -EINVAL;
194 } else if (strcmp(chip->name, "ad7816") == 0 && data > 0) {
195 dev_err(&chip->spi_dev->dev,
196 "Invalid channel id %lu for ad7816.\n", data);
197 return -EINVAL;
198 }
199
200 chip->channel_id = data;
201
202 return len;
203}
204
205static IIO_DEVICE_ATTR(channel, S_IRUGO | S_IWUSR,
206 ad7816_show_channel,
207 ad7816_store_channel,
208 0);
209
210
211static ssize_t ad7816_show_value(struct device *dev,
212 struct device_attribute *attr,
213 char *buf)
214{
215 struct iio_dev *dev_info = dev_get_drvdata(dev);
216 struct ad7816_chip_info *chip = dev_info->dev_data;
217 u16 data;
218 s8 value;
219 int ret;
220
221 ret = ad7816_spi_read(chip, &data);
222 if (ret)
223 return -EIO;
224
225 data >>= AD7816_VALUE_OFFSET;
226
227 if (chip->channel_id == 0) {
228 value = (s8)((data >> AD7816_TEMP_FLOAT_OFFSET) - 103);
229 data &= AD7816_TEMP_FLOAT_MASK;
230 if (value < 0)
231 data = (1 << AD7816_TEMP_FLOAT_OFFSET) - data;
232 return sprintf(buf, "%d.%.2d\n", value, data * 25);
233 } else
234 return sprintf(buf, "%u\n", data);
235}
236
237static IIO_DEVICE_ATTR(value, S_IRUGO, ad7816_show_value, NULL, 0);
238
239static ssize_t ad7816_show_name(struct device *dev,
240 struct device_attribute *attr,
241 char *buf)
242{
243 struct iio_dev *dev_info = dev_get_drvdata(dev);
244 struct ad7816_chip_info *chip = dev_info->dev_data;
245 return sprintf(buf, "%s\n", chip->name);
246}
247
248static IIO_DEVICE_ATTR(name, S_IRUGO, ad7816_show_name, NULL, 0);
249
250static struct attribute *ad7816_attributes[] = {
251 &iio_dev_attr_available_modes.dev_attr.attr,
252 &iio_dev_attr_mode.dev_attr.attr,
253 &iio_dev_attr_channel.dev_attr.attr,
254 &iio_dev_attr_value.dev_attr.attr,
255 &iio_dev_attr_name.dev_attr.attr,
256 NULL,
257};
258
259static const struct attribute_group ad7816_attribute_group = {
260 .attrs = ad7816_attributes,
261};
262
263/*
264 * temperature bound events
265 */
266
267#define IIO_EVENT_CODE_AD7816_OTI IIO_BUFFER_EVENT_CODE(0)
268
269static void ad7816_interrupt_bh(struct work_struct *work_s)
270{
271 struct ad7816_chip_info *chip =
272 container_of(work_s, struct ad7816_chip_info, thresh_work);
273
274 enable_irq(chip->spi_dev->irq);
275
276 iio_push_event(chip->indio_dev, 0,
277 IIO_EVENT_CODE_AD7816_OTI,
278 chip->last_timestamp);
279}
280
281static int ad7816_interrupt(struct iio_dev *dev_info,
282 int index,
283 s64 timestamp,
284 int no_test)
285{
286 struct ad7816_chip_info *chip = dev_info->dev_data;
287
288 chip->last_timestamp = timestamp;
289 schedule_work(&chip->thresh_work);
290
291 return 0;
292}
293
294IIO_EVENT_SH(ad7816, &ad7816_interrupt);
295
296static ssize_t ad7816_show_oti(struct device *dev,
297 struct device_attribute *attr,
298 char *buf)
299{
300 struct iio_dev *dev_info = dev_get_drvdata(dev);
301 struct ad7816_chip_info *chip = dev_info->dev_data;
302 int value;
303
304 if (chip->channel_id > AD7816_CS_MAX) {
305 dev_err(dev, "Invalid oti channel id %d.\n", chip->channel_id);
306 return -EINVAL;
307 } else if (chip->channel_id == 0) {
308 value = AD7816_BOUND_VALUE_MIN +
309 (chip->oti_data[chip->channel_id] -
310 AD7816_BOUND_VALUE_BASE);
311 return sprintf(buf, "%d\n", value);
312 } else
313 return sprintf(buf, "%u\n", chip->oti_data[chip->channel_id]);
314}
315
316static inline ssize_t ad7816_set_oti(struct device *dev,
317 struct device_attribute *attr,
318 const char *buf,
319 size_t len)
320{
321 struct iio_dev *dev_info = dev_get_drvdata(dev);
322 struct ad7816_chip_info *chip = dev_info->dev_data;
323 long value;
324 u8 data;
325 int ret;
326
327 ret = strict_strtol(buf, 10, &value);
328
329 if (chip->channel_id > AD7816_CS_MAX) {
330 dev_err(dev, "Invalid oti channel id %d.\n", chip->channel_id);
331 return -EINVAL;
332 } else if (chip->channel_id == 0) {
333 if (ret || value < AD7816_BOUND_VALUE_MIN ||
334 value > AD7816_BOUND_VALUE_MAX)
335 return -EINVAL;
336
337 data = (u8)(value - AD7816_BOUND_VALUE_MIN +
338 AD7816_BOUND_VALUE_BASE);
339 } else {
340 if (ret || value < AD7816_BOUND_VALUE_BASE || value > 255)
341 return -EINVAL;
342
343 data = (u8)value;
344 }
345
346 ret = ad7816_spi_write(chip, data);
347 if (ret)
348 return -EIO;
349
350 chip->oti_data[chip->channel_id] = data;
351
352 return len;
353}
354
355IIO_EVENT_ATTR_SH(oti, iio_event_ad7816,
356 ad7816_show_oti, ad7816_set_oti, 0);
357
358static struct attribute *ad7816_event_attributes[] = {
359 &iio_event_attr_oti.dev_attr.attr,
360 NULL,
361};
362
363static struct attribute_group ad7816_event_attribute_group = {
364 .attrs = ad7816_event_attributes,
365};
366
367/*
368 * device probe and remove
369 */
370
371static int __devinit ad7816_probe(struct spi_device *spi_dev)
372{
373 struct ad7816_chip_info *chip;
374 unsigned short *pins = spi_dev->dev.platform_data;
375 int ret = 0;
376 int i;
377
378 if (!pins) {
379 dev_err(&spi_dev->dev, "No necessary GPIO platform data.\n");
380 return -EINVAL;
381 }
382
383 chip = kzalloc(sizeof(struct ad7816_chip_info), GFP_KERNEL);
384
385 if (chip == NULL)
386 return -ENOMEM;
387
388 /* this is only used for device removal purposes */
389 dev_set_drvdata(&spi_dev->dev, chip);
390
391 chip->spi_dev = spi_dev;
392 chip->name = spi_dev->modalias;
393 for (i = 0; i <= AD7816_CS_MAX; i++)
394 chip->oti_data[i] = 203;
395 chip->rdwr_pin = pins[0];
396 chip->convert_pin = pins[1];
397 chip->busy_pin = pins[2];
398
399 ret = gpio_request(chip->rdwr_pin, chip->name);
400 if (ret) {
401 dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
402 chip->rdwr_pin);
403 goto error_free_chip;
404 }
405 gpio_direction_input(chip->rdwr_pin);
406 ret = gpio_request(chip->convert_pin, chip->name);
407 if (ret) {
408 dev_err(&spi_dev->dev, "Fail to request convert gpio PIN %d.\n",
409 chip->convert_pin);
410 goto error_free_gpio_rdwr;
411 }
412 gpio_direction_input(chip->convert_pin);
413 ret = gpio_request(chip->busy_pin, chip->name);
414 if (ret) {
415 dev_err(&spi_dev->dev, "Fail to request busy gpio PIN %d.\n",
416 chip->busy_pin);
417 goto error_free_gpio_convert;
418 }
419 gpio_direction_input(chip->busy_pin);
420
421 chip->indio_dev = iio_allocate_device();
422 if (chip->indio_dev == NULL) {
423 ret = -ENOMEM;
424 goto error_free_gpio;
425 }
426
427 chip->indio_dev->dev.parent = &spi_dev->dev;
428 chip->indio_dev->attrs = &ad7816_attribute_group;
429 chip->indio_dev->event_attrs = &ad7816_event_attribute_group;
430 chip->indio_dev->dev_data = (void *)chip;
431 chip->indio_dev->driver_module = THIS_MODULE;
432 chip->indio_dev->num_interrupt_lines = 1;
433 chip->indio_dev->modes = INDIO_DIRECT_MODE;
434
435 ret = iio_device_register(chip->indio_dev);
436 if (ret)
437 goto error_free_dev;
438
439 if (spi_dev->irq) {
440 /* Only low trigger is supported in ad7816/7/8 */
441 ret = iio_register_interrupt_line(spi_dev->irq,
442 chip->indio_dev,
443 0,
444 IRQF_TRIGGER_LOW,
445 chip->name);
446 if (ret)
447 goto error_unreg_dev;
448
449 /*
450 * The event handler list element refer to iio_event_ad7816.
451 * All event attributes bind to the same event handler.
452 * So, only register event handler once.
453 */
454 iio_add_event_to_list(&iio_event_ad7816,
455 &chip->indio_dev->interrupts[0]->ev_list);
456
457 INIT_WORK(&chip->thresh_work, ad7816_interrupt_bh);
458 }
459
460 dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n",
461 chip->name);
462
463 return 0;
464
465error_unreg_dev:
466 iio_device_unregister(chip->indio_dev);
467error_free_dev:
468 iio_free_device(chip->indio_dev);
469error_free_gpio:
470 gpio_free(chip->busy_pin);
471error_free_gpio_convert:
472 gpio_free(chip->convert_pin);
473error_free_gpio_rdwr:
474 gpio_free(chip->rdwr_pin);
475error_free_chip:
476 kfree(chip);
477
478 return ret;
479}
480
481static int __devexit ad7816_remove(struct spi_device *spi_dev)
482{
483 struct ad7816_chip_info *chip = dev_get_drvdata(&spi_dev->dev);
484 struct iio_dev *indio_dev = chip->indio_dev;
485
486 dev_set_drvdata(&spi_dev->dev, NULL);
487 if (spi_dev->irq)
488 iio_unregister_interrupt_line(indio_dev, 0);
489 iio_device_unregister(indio_dev);
490 iio_free_device(chip->indio_dev);
491 gpio_free(chip->busy_pin);
492 gpio_free(chip->convert_pin);
493 gpio_free(chip->rdwr_pin);
494 kfree(chip);
495
496 return 0;
497}
498
499static const struct spi_device_id ad7816_id[] = {
500 { "ad7816", 0 },
501 { "ad7817", 0 },
502 { "ad7818", 0 },
503 {}
504};
505
506MODULE_DEVICE_TABLE(spi, ad7816_id);
507
508static struct spi_driver ad7816_driver = {
509 .driver = {
510 .name = "ad7816",
511 .bus = &spi_bus_type,
512 .owner = THIS_MODULE,
513 },
514 .probe = ad7816_probe,
515 .remove = __devexit_p(ad7816_remove),
516 .id_table = ad7816_id,
517};
518
519static __init int ad7816_init(void)
520{
521 return spi_register_driver(&ad7816_driver);
522}
523
524static __exit void ad7816_exit(void)
525{
526 spi_unregister_driver(&ad7816_driver);
527}
528
529MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
530MODULE_DESCRIPTION("Analog Devices AD7816/7/8 digital"
531 " temperature sensor driver");
532MODULE_LICENSE("GPL v2");
533
534module_init(ad7816_init);
535module_exit(ad7816_exit);
diff --git a/drivers/staging/iio/adc/ad7887.h b/drivers/staging/iio/adc/ad7887.h
new file mode 100644
index 000000000000..8c2a218c9496
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7887.h
@@ -0,0 +1,105 @@
1/*
2 * AD7887 SPI ADC driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8#ifndef IIO_ADC_AD7887_H_
9#define IIO_ADC_AD7887_H_
10
11#define AD7887_REF_DIS (1 << 5) /* on-chip reference disable */
12#define AD7887_DUAL (1 << 4) /* dual-channel mode */
13#define AD7887_CH_AIN1 (1 << 3) /* convert on channel 1, DUAL=1 */
14#define AD7887_CH_AIN0 (0 << 3) /* convert on channel 0, DUAL=0,1 */
15#define AD7887_PM_MODE1 (0) /* CS based shutdown */
16#define AD7887_PM_MODE2 (1) /* full on */
17#define AD7887_PM_MODE3 (2) /* auto shutdown after conversion */
18#define AD7887_PM_MODE4 (3) /* standby mode */
19
20enum ad7887_channels {
21 AD7887_CH0,
22 AD7887_CH0_CH1,
23 AD7887_CH1,
24};
25
26#define RES_MASK(bits) ((1 << (bits)) - 1) /* TODO: move this into a common header */
27
28/*
29 * TODO: struct ad7887_platform_data needs to go into include/linux/iio
30 */
31
32struct ad7887_platform_data {
33 /* External Vref voltage applied */
34 u16 vref_mv;
35 /*
36 * AD7887:
37 * In single channel mode en_dual = flase, AIN1/Vref pins assumes its
38 * Vref function. In dual channel mode en_dual = true, AIN1 becomes the
39 * second input channel, and Vref is internally connected to Vdd.
40 */
41 bool en_dual;
42 /*
43 * AD7887:
44 * use_onchip_ref = true, the Vref is internally connected to the 2.500V
45 * Voltage reference. If use_onchip_ref = false, the reference voltage
46 * is supplied by AIN1/Vref
47 */
48 bool use_onchip_ref;
49};
50
51struct ad7887_chip_info {
52 u8 bits; /* number of ADC bits */
53 u8 storagebits; /* number of bits read from the ADC */
54 u8 left_shift; /* number of bits the sample must be shifted */
55 char sign; /* [s]igned or [u]nsigned */
56 u16 int_vref_mv; /* internal reference voltage */
57};
58
59struct ad7887_state {
60 struct iio_dev *indio_dev;
61 struct spi_device *spi;
62 const struct ad7887_chip_info *chip_info;
63 struct regulator *reg;
64 struct work_struct poll_work;
65 atomic_t protect_ring;
66 u16 int_vref_mv;
67 bool en_dual;
68 struct spi_transfer xfer[4];
69 struct spi_message msg[3];
70 struct spi_message *ring_msg;
71 unsigned char tx_cmd_buf[8];
72
73 /*
74 * DMA (thus cache coherency maintenance) requires the
75 * transfer buffers to live in their own cache lines.
76 */
77
78 unsigned char data[4] ____cacheline_aligned;
79};
80
81enum ad7887_supported_device_ids {
82 ID_AD7887
83};
84
85#ifdef CONFIG_IIO_RING_BUFFER
86int ad7887_scan_from_ring(struct ad7887_state *st, long mask);
87int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev);
88void ad7887_ring_cleanup(struct iio_dev *indio_dev);
89#else /* CONFIG_IIO_RING_BUFFER */
90static inline int ad7887_scan_from_ring(struct ad7887_state *st, long mask)
91{
92 return 0;
93}
94
95static inline int
96ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
97{
98 return 0;
99}
100
101static inline void ad7887_ring_cleanup(struct iio_dev *indio_dev)
102{
103}
104#endif /* CONFIG_IIO_RING_BUFFER */
105#endif /* IIO_ADC_AD7887_H_ */
diff --git a/drivers/staging/iio/adc/ad7887_core.c b/drivers/staging/iio/adc/ad7887_core.c
new file mode 100644
index 000000000000..685908995d49
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7887_core.c
@@ -0,0 +1,305 @@
1/*
2 * AD7887 SPI ADC driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/workqueue.h>
11#include <linux/device.h>
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/sysfs.h>
15#include <linux/list.h>
16#include <linux/spi/spi.h>
17#include <linux/regulator/consumer.h>
18#include <linux/err.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22#include "../ring_generic.h"
23#include "adc.h"
24
25#include "ad7887.h"
26
27static int ad7887_scan_direct(struct ad7887_state *st, unsigned ch)
28{
29 int ret = spi_sync(st->spi, &st->msg[ch]);
30 if (ret)
31 return ret;
32
33 return (st->data[(ch * 2)] << 8) | st->data[(ch * 2) + 1];
34}
35
36static ssize_t ad7887_scan(struct device *dev,
37 struct device_attribute *attr,
38 char *buf)
39{
40 struct iio_dev *dev_info = dev_get_drvdata(dev);
41 struct ad7887_state *st = dev_info->dev_data;
42 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
43 int ret;
44
45 mutex_lock(&dev_info->mlock);
46 if (iio_ring_enabled(dev_info))
47 ret = ad7887_scan_from_ring(st, 1 << this_attr->address);
48 else
49 ret = ad7887_scan_direct(st, this_attr->address);
50 mutex_unlock(&dev_info->mlock);
51
52 if (ret < 0)
53 return ret;
54
55 return sprintf(buf, "%d\n", (ret >> st->chip_info->left_shift) &
56 RES_MASK(st->chip_info->bits));
57}
58static IIO_DEV_ATTR_IN_RAW(0, ad7887_scan, 0);
59static IIO_DEV_ATTR_IN_RAW(1, ad7887_scan, 1);
60
61static ssize_t ad7887_show_scale(struct device *dev,
62 struct device_attribute *attr,
63 char *buf)
64{
65 /* Driver currently only support internal vref */
66 struct iio_dev *dev_info = dev_get_drvdata(dev);
67 struct ad7887_state *st = iio_dev_get_devdata(dev_info);
68 /* Corresponds to Vref / 2^(bits) */
69 unsigned int scale_uv = (st->int_vref_mv * 1000) >> st->chip_info->bits;
70
71 return sprintf(buf, "%d.%d\n", scale_uv / 1000, scale_uv % 1000);
72}
73static IIO_DEVICE_ATTR(in_scale, S_IRUGO, ad7887_show_scale, NULL, 0);
74
75static ssize_t ad7887_show_name(struct device *dev,
76 struct device_attribute *attr,
77 char *buf)
78{
79 struct iio_dev *dev_info = dev_get_drvdata(dev);
80 struct ad7887_state *st = iio_dev_get_devdata(dev_info);
81
82 return sprintf(buf, "%s\n", spi_get_device_id(st->spi)->name);
83}
84static IIO_DEVICE_ATTR(name, S_IRUGO, ad7887_show_name, NULL, 0);
85
86static struct attribute *ad7887_attributes[] = {
87 &iio_dev_attr_in0_raw.dev_attr.attr,
88 &iio_dev_attr_in1_raw.dev_attr.attr,
89 &iio_dev_attr_in_scale.dev_attr.attr,
90 &iio_dev_attr_name.dev_attr.attr,
91 NULL,
92};
93
94static mode_t ad7887_attr_is_visible(struct kobject *kobj,
95 struct attribute *attr, int n)
96{
97 struct device *dev = container_of(kobj, struct device, kobj);
98 struct iio_dev *dev_info = dev_get_drvdata(dev);
99 struct ad7887_state *st = iio_dev_get_devdata(dev_info);
100
101 mode_t mode = attr->mode;
102
103 if ((attr == &iio_dev_attr_in1_raw.dev_attr.attr) && !st->en_dual)
104 mode = 0;
105
106 return mode;
107}
108
109static const struct attribute_group ad7887_attribute_group = {
110 .attrs = ad7887_attributes,
111 .is_visible = ad7887_attr_is_visible,
112};
113
114static const struct ad7887_chip_info ad7887_chip_info_tbl[] = {
115 /*
116 * More devices added in future
117 */
118 [ID_AD7887] = {
119 .bits = 12,
120 .storagebits = 16,
121 .left_shift = 0,
122 .sign = IIO_SCAN_EL_TYPE_UNSIGNED,
123 .int_vref_mv = 2500,
124 },
125};
126
127static int __devinit ad7887_probe(struct spi_device *spi)
128{
129 struct ad7887_platform_data *pdata = spi->dev.platform_data;
130 struct ad7887_state *st;
131 int ret, voltage_uv = 0;
132
133 st = kzalloc(sizeof(*st), GFP_KERNEL);
134 if (st == NULL) {
135 ret = -ENOMEM;
136 goto error_ret;
137 }
138
139 st->reg = regulator_get(&spi->dev, "vcc");
140 if (!IS_ERR(st->reg)) {
141 ret = regulator_enable(st->reg);
142 if (ret)
143 goto error_put_reg;
144
145 voltage_uv = regulator_get_voltage(st->reg);
146 }
147
148 st->chip_info =
149 &ad7887_chip_info_tbl[spi_get_device_id(spi)->driver_data];
150
151 spi_set_drvdata(spi, st);
152
153 atomic_set(&st->protect_ring, 0);
154 st->spi = spi;
155
156 st->indio_dev = iio_allocate_device();
157 if (st->indio_dev == NULL) {
158 ret = -ENOMEM;
159 goto error_disable_reg;
160 }
161
162 /* Estabilish that the iio_dev is a child of the spi device */
163 st->indio_dev->dev.parent = &spi->dev;
164 st->indio_dev->attrs = &ad7887_attribute_group;
165 st->indio_dev->dev_data = (void *)(st);
166 st->indio_dev->driver_module = THIS_MODULE;
167 st->indio_dev->modes = INDIO_DIRECT_MODE;
168
169 /* Setup default message */
170
171 st->tx_cmd_buf[0] = AD7887_CH_AIN0 | AD7887_PM_MODE4 |
172 ((pdata && pdata->use_onchip_ref) ?
173 0 : AD7887_REF_DIS);
174
175 st->xfer[0].rx_buf = &st->data[0];
176 st->xfer[0].tx_buf = &st->tx_cmd_buf[0];
177 st->xfer[0].len = 2;
178
179 spi_message_init(&st->msg[AD7887_CH0]);
180 spi_message_add_tail(&st->xfer[0], &st->msg[AD7887_CH0]);
181
182 if (pdata && pdata->en_dual) {
183 st->tx_cmd_buf[0] |= AD7887_DUAL | AD7887_REF_DIS;
184
185 st->tx_cmd_buf[2] = AD7887_CH_AIN1 | AD7887_DUAL |
186 AD7887_REF_DIS | AD7887_PM_MODE4;
187 st->tx_cmd_buf[4] = AD7887_CH_AIN0 | AD7887_DUAL |
188 AD7887_REF_DIS | AD7887_PM_MODE4;
189 st->tx_cmd_buf[6] = AD7887_CH_AIN1 | AD7887_DUAL |
190 AD7887_REF_DIS | AD7887_PM_MODE4;
191
192 st->xfer[1].rx_buf = &st->data[0];
193 st->xfer[1].tx_buf = &st->tx_cmd_buf[2];
194 st->xfer[1].len = 2;
195
196 st->xfer[2].rx_buf = &st->data[2];
197 st->xfer[2].tx_buf = &st->tx_cmd_buf[4];
198 st->xfer[2].len = 2;
199
200 spi_message_init(&st->msg[AD7887_CH0_CH1]);
201 spi_message_add_tail(&st->xfer[1], &st->msg[AD7887_CH0_CH1]);
202 spi_message_add_tail(&st->xfer[2], &st->msg[AD7887_CH0_CH1]);
203
204 st->xfer[3].rx_buf = &st->data[0];
205 st->xfer[3].tx_buf = &st->tx_cmd_buf[6];
206 st->xfer[3].len = 2;
207
208 spi_message_init(&st->msg[AD7887_CH1]);
209 spi_message_add_tail(&st->xfer[3], &st->msg[AD7887_CH1]);
210
211 st->en_dual = true;
212
213 if (pdata && pdata->vref_mv)
214 st->int_vref_mv = pdata->vref_mv;
215 else if (voltage_uv)
216 st->int_vref_mv = voltage_uv / 1000;
217 else
218 dev_warn(&spi->dev, "reference voltage unspecified\n");
219
220 } else {
221 if (pdata && pdata->vref_mv)
222 st->int_vref_mv = pdata->vref_mv;
223 else if (pdata && pdata->use_onchip_ref)
224 st->int_vref_mv = st->chip_info->int_vref_mv;
225 else
226 dev_warn(&spi->dev, "reference voltage unspecified\n");
227 }
228
229
230 ret = ad7887_register_ring_funcs_and_init(st->indio_dev);
231 if (ret)
232 goto error_free_device;
233
234 ret = iio_device_register(st->indio_dev);
235 if (ret)
236 goto error_free_device;
237
238 ret = iio_ring_buffer_register(st->indio_dev->ring, 0);
239 if (ret)
240 goto error_cleanup_ring;
241 return 0;
242
243error_cleanup_ring:
244 ad7887_ring_cleanup(st->indio_dev);
245 iio_device_unregister(st->indio_dev);
246error_free_device:
247 iio_free_device(st->indio_dev);
248error_disable_reg:
249 if (!IS_ERR(st->reg))
250 regulator_disable(st->reg);
251error_put_reg:
252 if (!IS_ERR(st->reg))
253 regulator_put(st->reg);
254 kfree(st);
255error_ret:
256 return ret;
257}
258
259static int ad7887_remove(struct spi_device *spi)
260{
261 struct ad7887_state *st = spi_get_drvdata(spi);
262 struct iio_dev *indio_dev = st->indio_dev;
263 iio_ring_buffer_unregister(indio_dev->ring);
264 ad7887_ring_cleanup(indio_dev);
265 iio_device_unregister(indio_dev);
266 if (!IS_ERR(st->reg)) {
267 regulator_disable(st->reg);
268 regulator_put(st->reg);
269 }
270 kfree(st);
271 return 0;
272}
273
274static const struct spi_device_id ad7887_id[] = {
275 {"ad7887", ID_AD7887},
276 {}
277};
278
279static struct spi_driver ad7887_driver = {
280 .driver = {
281 .name = "ad7887",
282 .bus = &spi_bus_type,
283 .owner = THIS_MODULE,
284 },
285 .probe = ad7887_probe,
286 .remove = __devexit_p(ad7887_remove),
287 .id_table = ad7887_id,
288};
289
290static int __init ad7887_init(void)
291{
292 return spi_register_driver(&ad7887_driver);
293}
294module_init(ad7887_init);
295
296static void __exit ad7887_exit(void)
297{
298 spi_unregister_driver(&ad7887_driver);
299}
300module_exit(ad7887_exit);
301
302MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
303MODULE_DESCRIPTION("Analog Devices AD7887 ADC");
304MODULE_LICENSE("GPL v2");
305MODULE_ALIAS("spi:ad7887");
diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
new file mode 100644
index 000000000000..6b9cb1f95a1e
--- /dev/null
+++ b/drivers/staging/iio/adc/ad7887_ring.c
@@ -0,0 +1,266 @@
1/*
2 * Copyright 2010 Analog Devices Inc.
3 * Copyright (C) 2008 Jonathan Cameron
4 *
5 * Licensed under the GPL-2 or later.
6 *
7 * ad7887_ring.c
8 */
9
10#include <linux/interrupt.h>
11#include <linux/gpio.h>
12#include <linux/workqueue.h>
13#include <linux/device.h>
14#include <linux/kernel.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17#include <linux/list.h>
18#include <linux/spi/spi.h>
19
20#include "../iio.h"
21#include "../ring_generic.h"
22#include "../ring_sw.h"
23#include "../trigger.h"
24#include "../sysfs.h"
25
26#include "ad7887.h"
27
28static IIO_SCAN_EL_C(in0, 0, 0, NULL);
29static IIO_SCAN_EL_C(in1, 1, 0, NULL);
30
31static ssize_t ad7887_show_type(struct device *dev,
32 struct device_attribute *attr,
33 char *buf)
34{
35 struct iio_ring_buffer *ring = dev_get_drvdata(dev);
36 struct iio_dev *indio_dev = ring->indio_dev;
37 struct ad7887_state *st = indio_dev->dev_data;
38
39 return sprintf(buf, "%c%d/%d>>%d\n", st->chip_info->sign,
40 st->chip_info->bits, st->chip_info->storagebits,
41 st->chip_info->left_shift);
42}
43static IIO_DEVICE_ATTR(in_type, S_IRUGO, ad7887_show_type, NULL, 0);
44
45static struct attribute *ad7887_scan_el_attrs[] = {
46 &iio_scan_el_in0.dev_attr.attr,
47 &iio_const_attr_in0_index.dev_attr.attr,
48 &iio_scan_el_in1.dev_attr.attr,
49 &iio_const_attr_in1_index.dev_attr.attr,
50 &iio_dev_attr_in_type.dev_attr.attr,
51 NULL,
52};
53
54static mode_t ad7887_scan_el_attr_is_visible(struct kobject *kobj,
55 struct attribute *attr, int n)
56{
57 struct device *dev = container_of(kobj, struct device, kobj);
58 struct iio_ring_buffer *ring = dev_get_drvdata(dev);
59 struct iio_dev *indio_dev = ring->indio_dev;
60 struct ad7887_state *st = indio_dev->dev_data;
61
62 mode_t mode = attr->mode;
63
64 if ((attr == &iio_scan_el_in1.dev_attr.attr) ||
65 (attr == &iio_const_attr_in1_index.dev_attr.attr))
66 if (!st->en_dual)
67 mode = 0;
68
69 return mode;
70}
71
72static struct attribute_group ad7887_scan_el_group = {
73 .name = "scan_elements",
74 .attrs = ad7887_scan_el_attrs,
75 .is_visible = ad7887_scan_el_attr_is_visible,
76};
77
78int ad7887_scan_from_ring(struct ad7887_state *st, long mask)
79{
80 struct iio_ring_buffer *ring = st->indio_dev->ring;
81 int count = 0, ret;
82 u16 *ring_data;
83
84 if (!(ring->scan_mask & mask)) {
85 ret = -EBUSY;
86 goto error_ret;
87 }
88
89 ring_data = kmalloc(ring->access.get_bytes_per_datum(ring), GFP_KERNEL);
90 if (ring_data == NULL) {
91 ret = -ENOMEM;
92 goto error_ret;
93 }
94 ret = ring->access.read_last(ring, (u8 *) ring_data);
95 if (ret)
96 goto error_free_ring_data;
97
98 /* for single channel scan the result is stored with zero offset */
99 if ((ring->scan_mask == ((1 << 1) | (1 << 0))) && (mask == (1 << 1)))
100 count = 1;
101
102 ret = be16_to_cpu(ring_data[count]);
103
104error_free_ring_data:
105 kfree(ring_data);
106error_ret:
107 return ret;
108}
109
110/**
111 * ad7887_ring_preenable() setup the parameters of the ring before enabling
112 *
113 * The complex nature of the setting of the nuber of bytes per datum is due
114 * to this driver currently ensuring that the timestamp is stored at an 8
115 * byte boundary.
116 **/
117static int ad7887_ring_preenable(struct iio_dev *indio_dev)
118{
119 struct ad7887_state *st = indio_dev->dev_data;
120 struct iio_ring_buffer *ring = indio_dev->ring;
121 size_t d_size;
122
123 if (indio_dev->ring->access.set_bytes_per_datum) {
124 d_size = st->chip_info->storagebits / 8 + sizeof(s64);
125 if (d_size % 8)
126 d_size += 8 - (d_size % 8);
127 indio_dev->ring->access.set_bytes_per_datum(indio_dev->ring,
128 d_size);
129 }
130
131 switch (ring->scan_mask) {
132 case (1 << 0):
133 st->ring_msg = &st->msg[AD7887_CH0];
134 break;
135 case (1 << 1):
136 st->ring_msg = &st->msg[AD7887_CH1];
137 /* Dummy read: push CH1 setting down to hardware */
138 spi_sync(st->spi, st->ring_msg);
139 break;
140 case ((1 << 1) | (1 << 0)):
141 st->ring_msg = &st->msg[AD7887_CH0_CH1];
142 break;
143 }
144
145 return 0;
146}
147
148static int ad7887_ring_postdisable(struct iio_dev *indio_dev)
149{
150 struct ad7887_state *st = indio_dev->dev_data;
151
152 /* dummy read: restore default CH0 settin */
153 return spi_sync(st->spi, &st->msg[AD7887_CH0]);
154}
155
156/**
157 * ad7887_poll_func_th() th of trigger launched polling to ring buffer
158 *
159 * As sampling only occurs on spi comms occuring, leave timestamping until
160 * then. Some triggers will generate their own time stamp. Currently
161 * there is no way of notifying them when no one cares.
162 **/
163static void ad7887_poll_func_th(struct iio_dev *indio_dev, s64 time)
164{
165 struct ad7887_state *st = indio_dev->dev_data;
166
167 schedule_work(&st->poll_work);
168 return;
169}
170/**
171 * ad7887_poll_bh_to_ring() bh of trigger launched polling to ring buffer
172 * @work_s: the work struct through which this was scheduled
173 *
174 * Currently there is no option in this driver to disable the saving of
175 * timestamps within the ring.
176 * I think the one copy of this at a time was to avoid problems if the
177 * trigger was set far too high and the reads then locked up the computer.
178 **/
179static void ad7887_poll_bh_to_ring(struct work_struct *work_s)
180{
181 struct ad7887_state *st = container_of(work_s, struct ad7887_state,
182 poll_work);
183 struct iio_dev *indio_dev = st->indio_dev;
184 struct iio_sw_ring_buffer *sw_ring = iio_to_sw_ring(indio_dev->ring);
185 struct iio_ring_buffer *ring = indio_dev->ring;
186 s64 time_ns;
187 __u8 *buf;
188 int b_sent;
189 size_t d_size;
190
191 unsigned int bytes = ring->scan_count * st->chip_info->storagebits / 8;
192
193 /* Ensure the timestamp is 8 byte aligned */
194 d_size = bytes + sizeof(s64);
195 if (d_size % sizeof(s64))
196 d_size += sizeof(s64) - (d_size % sizeof(s64));
197
198 /* Ensure only one copy of this function running at a time */
199 if (atomic_inc_return(&st->protect_ring) > 1)
200 return;
201
202 buf = kzalloc(d_size, GFP_KERNEL);
203 if (buf == NULL)
204 return;
205
206 b_sent = spi_sync(st->spi, st->ring_msg);
207 if (b_sent)
208 goto done;
209
210 time_ns = iio_get_time_ns();
211
212 memcpy(buf, st->data, bytes);
213 memcpy(buf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
214
215 indio_dev->ring->access.store_to(&sw_ring->buf, buf, time_ns);
216done:
217 kfree(buf);
218 atomic_dec(&st->protect_ring);
219}
220
221int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
222{
223 struct ad7887_state *st = indio_dev->dev_data;
224 int ret;
225
226 indio_dev->ring = iio_sw_rb_allocate(indio_dev);
227 if (!indio_dev->ring) {
228 ret = -ENOMEM;
229 goto error_ret;
230 }
231 /* Effectively select the ring buffer implementation */
232 iio_ring_sw_register_funcs(&indio_dev->ring->access);
233 ret = iio_alloc_pollfunc(indio_dev, NULL, &ad7887_poll_func_th);
234 if (ret)
235 goto error_deallocate_sw_rb;
236
237 /* Ring buffer functions - here trigger setup related */
238
239 indio_dev->ring->preenable = &ad7887_ring_preenable;
240 indio_dev->ring->postenable = &iio_triggered_ring_postenable;
241 indio_dev->ring->predisable = &iio_triggered_ring_predisable;
242 indio_dev->ring->postdisable = &ad7887_ring_postdisable;
243 indio_dev->ring->scan_el_attrs = &ad7887_scan_el_group;
244
245 INIT_WORK(&st->poll_work, &ad7887_poll_bh_to_ring);
246
247 /* Flag that polled ring buffering is possible */
248 indio_dev->modes |= INDIO_RING_TRIGGERED;
249 return 0;
250error_deallocate_sw_rb:
251 iio_sw_rb_free(indio_dev->ring);
252error_ret:
253 return ret;
254}
255
256void ad7887_ring_cleanup(struct iio_dev *indio_dev)
257{
258 /* ensure that the trigger has been detached */
259 if (indio_dev->trig) {
260 iio_put_trigger(indio_dev->trig);
261 iio_trigger_dettach_poll_func(indio_dev->trig,
262 indio_dev->pollfunc);
263 }
264 kfree(indio_dev->pollfunc);
265 iio_sw_rb_free(indio_dev->ring);
266}
diff --git a/drivers/staging/iio/adc/adt7310.c b/drivers/staging/iio/adc/adt7310.c
new file mode 100644
index 000000000000..771a409ee94c
--- /dev/null
+++ b/drivers/staging/iio/adc/adt7310.c
@@ -0,0 +1,952 @@
1/*
2 * ADT7310 digital temperature sensor driver supporting ADT7310
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/workqueue.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/sysfs.h>
16#include <linux/list.h>
17#include <linux/spi/spi.h>
18#include <linux/rtc.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23/*
24 * ADT7310 registers definition
25 */
26
27#define ADT7310_STATUS 0
28#define ADT7310_CONFIG 1
29#define ADT7310_TEMPERATURE 2
30#define ADT7310_ID 3
31#define ADT7310_T_CRIT 4
32#define ADT7310_T_HYST 5
33#define ADT7310_T_ALARM_HIGH 6
34#define ADT7310_T_ALARM_LOW 7
35
36/*
37 * ADT7310 status
38 */
39#define ADT7310_STAT_T_LOW 0x10
40#define ADT7310_STAT_T_HIGH 0x20
41#define ADT7310_STAT_T_CRIT 0x40
42#define ADT7310_STAT_NOT_RDY 0x80
43
44/*
45 * ADT7310 config
46 */
47#define ADT7310_FAULT_QUEUE_MASK 0x3
48#define ADT7310_CT_POLARITY 0x4
49#define ADT7310_INT_POLARITY 0x8
50#define ADT7310_EVENT_MODE 0x10
51#define ADT7310_MODE_MASK 0x60
52#define ADT7310_ONESHOT 0x20
53#define ADT7310_SPS 0x40
54#define ADT7310_PD 0x60
55#define ADT7310_RESOLUTION 0x80
56
57/*
58 * ADT7310 masks
59 */
60#define ADT7310_T16_VALUE_SIGN 0x8000
61#define ADT7310_T16_VALUE_FLOAT_OFFSET 7
62#define ADT7310_T16_VALUE_FLOAT_MASK 0x7F
63#define ADT7310_T13_VALUE_SIGN 0x1000
64#define ADT7310_T13_VALUE_OFFSET 3
65#define ADT7310_T13_VALUE_FLOAT_OFFSET 4
66#define ADT7310_T13_VALUE_FLOAT_MASK 0xF
67#define ADT7310_T_HYST_MASK 0xF
68#define ADT7310_DEVICE_ID_MASK 0x7
69#define ADT7310_MANUFACTORY_ID_MASK 0xF8
70#define ADT7310_MANUFACTORY_ID_OFFSET 3
71
72
73#define ADT7310_CMD_REG_MASK 0x28
74#define ADT7310_CMD_REG_OFFSET 3
75#define ADT7310_CMD_READ 0x40
76#define ADT7310_CMD_CON_READ 0x4
77
78#define ADT7310_IRQS 2
79
80/*
81 * struct adt7310_chip_info - chip specifc information
82 */
83
84struct adt7310_chip_info {
85 const char *name;
86 struct spi_device *spi_dev;
87 struct iio_dev *indio_dev;
88 struct work_struct thresh_work;
89 s64 last_timestamp;
90 u8 config;
91};
92
93/*
94 * adt7310 register access by SPI
95 */
96
97static int adt7310_spi_read_word(struct adt7310_chip_info *chip, u8 reg, u16 *data)
98{
99 struct spi_device *spi_dev = chip->spi_dev;
100 u8 command = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK;
101 int ret = 0;
102
103 command |= ADT7310_CMD_READ;
104 ret = spi_write(spi_dev, &command, sizeof(command));
105 if (ret < 0) {
106 dev_err(&spi_dev->dev, "SPI write command error\n");
107 return ret;
108 }
109
110 ret = spi_read(spi_dev, (u8 *)data, sizeof(*data));
111 if (ret < 0) {
112 dev_err(&spi_dev->dev, "SPI read word error\n");
113 return ret;
114 }
115
116 *data = be16_to_cpu(*data);
117
118 return 0;
119}
120
121static int adt7310_spi_write_word(struct adt7310_chip_info *chip, u8 reg, u16 data)
122{
123 struct spi_device *spi_dev = chip->spi_dev;
124 u8 buf[3];
125 int ret = 0;
126
127 buf[0] = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK;
128 buf[1] = (u8)(data >> 8);
129 buf[2] = (u8)(data & 0xFF);
130
131 ret = spi_write(spi_dev, buf, 3);
132 if (ret < 0) {
133 dev_err(&spi_dev->dev, "SPI write word error\n");
134 return ret;
135 }
136
137 return ret;
138}
139
140static int adt7310_spi_read_byte(struct adt7310_chip_info *chip, u8 reg, u8 *data)
141{
142 struct spi_device *spi_dev = chip->spi_dev;
143 u8 command = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK;
144 int ret = 0;
145
146 command |= ADT7310_CMD_READ;
147 ret = spi_write(spi_dev, &command, sizeof(command));
148 if (ret < 0) {
149 dev_err(&spi_dev->dev, "SPI write command error\n");
150 return ret;
151 }
152
153 ret = spi_read(spi_dev, data, sizeof(*data));
154 if (ret < 0) {
155 dev_err(&spi_dev->dev, "SPI read byte error\n");
156 return ret;
157 }
158
159 return 0;
160}
161
162static int adt7310_spi_write_byte(struct adt7310_chip_info *chip, u8 reg, u8 data)
163{
164 struct spi_device *spi_dev = chip->spi_dev;
165 u8 buf[2];
166 int ret = 0;
167
168 buf[0] = (reg << ADT7310_CMD_REG_OFFSET) & ADT7310_CMD_REG_MASK;
169 buf[1] = data;
170
171 ret = spi_write(spi_dev, buf, 2);
172 if (ret < 0) {
173 dev_err(&spi_dev->dev, "SPI write byte error\n");
174 return ret;
175 }
176
177 return ret;
178}
179
180static ssize_t adt7310_show_mode(struct device *dev,
181 struct device_attribute *attr,
182 char *buf)
183{
184 struct iio_dev *dev_info = dev_get_drvdata(dev);
185 struct adt7310_chip_info *chip = dev_info->dev_data;
186 u8 config;
187
188 config = chip->config & ADT7310_MODE_MASK;
189
190 switch (config) {
191 case ADT7310_PD:
192 return sprintf(buf, "power-down\n");
193 case ADT7310_ONESHOT:
194 return sprintf(buf, "one-shot\n");
195 case ADT7310_SPS:
196 return sprintf(buf, "sps\n");
197 default:
198 return sprintf(buf, "full\n");
199 }
200}
201
202static ssize_t adt7310_store_mode(struct device *dev,
203 struct device_attribute *attr,
204 const char *buf,
205 size_t len)
206{
207 struct iio_dev *dev_info = dev_get_drvdata(dev);
208 struct adt7310_chip_info *chip = dev_info->dev_data;
209 u16 config;
210 int ret;
211
212 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
213 if (ret)
214 return -EIO;
215
216 config = chip->config & (~ADT7310_MODE_MASK);
217 if (strcmp(buf, "power-down"))
218 config |= ADT7310_PD;
219 else if (strcmp(buf, "one-shot"))
220 config |= ADT7310_ONESHOT;
221 else if (strcmp(buf, "sps"))
222 config |= ADT7310_SPS;
223
224 ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config);
225 if (ret)
226 return -EIO;
227
228 chip->config = config;
229
230 return len;
231}
232
233static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
234 adt7310_show_mode,
235 adt7310_store_mode,
236 0);
237
238static ssize_t adt7310_show_available_modes(struct device *dev,
239 struct device_attribute *attr,
240 char *buf)
241{
242 return sprintf(buf, "full\none-shot\nsps\npower-down\n");
243}
244
245static IIO_DEVICE_ATTR(available_modes, S_IRUGO, adt7310_show_available_modes, NULL, 0);
246
247static ssize_t adt7310_show_resolution(struct device *dev,
248 struct device_attribute *attr,
249 char *buf)
250{
251 struct iio_dev *dev_info = dev_get_drvdata(dev);
252 struct adt7310_chip_info *chip = dev_info->dev_data;
253 int ret;
254 int bits;
255
256 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
257 if (ret)
258 return -EIO;
259
260 if (chip->config & ADT7310_RESOLUTION)
261 bits = 16;
262 else
263 bits = 13;
264
265 return sprintf(buf, "%d bits\n", bits);
266}
267
268static ssize_t adt7310_store_resolution(struct device *dev,
269 struct device_attribute *attr,
270 const char *buf,
271 size_t len)
272{
273 struct iio_dev *dev_info = dev_get_drvdata(dev);
274 struct adt7310_chip_info *chip = dev_info->dev_data;
275 unsigned long data;
276 u16 config;
277 int ret;
278
279 ret = strict_strtoul(buf, 10, &data);
280 if (ret)
281 return -EINVAL;
282
283 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
284 if (ret)
285 return -EIO;
286
287 config = chip->config & (~ADT7310_RESOLUTION);
288 if (data)
289 config |= ADT7310_RESOLUTION;
290
291 ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config);
292 if (ret)
293 return -EIO;
294
295 chip->config = config;
296
297 return len;
298}
299
300static IIO_DEVICE_ATTR(resolution, S_IRUGO | S_IWUSR,
301 adt7310_show_resolution,
302 adt7310_store_resolution,
303 0);
304
305static ssize_t adt7310_show_id(struct device *dev,
306 struct device_attribute *attr,
307 char *buf)
308{
309 struct iio_dev *dev_info = dev_get_drvdata(dev);
310 struct adt7310_chip_info *chip = dev_info->dev_data;
311 u8 id;
312 int ret;
313
314 ret = adt7310_spi_read_byte(chip, ADT7310_ID, &id);
315 if (ret)
316 return -EIO;
317
318 return sprintf(buf, "device id: 0x%x\nmanufactory id: 0x%x\n",
319 id & ADT7310_DEVICE_ID_MASK,
320 (id & ADT7310_MANUFACTORY_ID_MASK) >> ADT7310_MANUFACTORY_ID_OFFSET);
321}
322
323static IIO_DEVICE_ATTR(id, S_IRUGO | S_IWUSR,
324 adt7310_show_id,
325 NULL,
326 0);
327
328static ssize_t adt7310_convert_temperature(struct adt7310_chip_info *chip,
329 u16 data, char *buf)
330{
331 char sign = ' ';
332
333 if (chip->config & ADT7310_RESOLUTION) {
334 if (data & ADT7310_T16_VALUE_SIGN) {
335 /* convert supplement to positive value */
336 data = (u16)((ADT7310_T16_VALUE_SIGN << 1) - (u32)data);
337 sign = '-';
338 }
339 return sprintf(buf, "%c%d.%.7d\n", sign,
340 (data >> ADT7310_T16_VALUE_FLOAT_OFFSET),
341 (data & ADT7310_T16_VALUE_FLOAT_MASK) * 78125);
342 } else {
343 if (data & ADT7310_T13_VALUE_SIGN) {
344 /* convert supplement to positive value */
345 data >>= ADT7310_T13_VALUE_OFFSET;
346 data = (ADT7310_T13_VALUE_SIGN << 1) - data;
347 sign = '-';
348 }
349 return sprintf(buf, "%c%d.%.4d\n", sign,
350 (data >> ADT7310_T13_VALUE_FLOAT_OFFSET),
351 (data & ADT7310_T13_VALUE_FLOAT_MASK) * 625);
352 }
353}
354
355static ssize_t adt7310_show_value(struct device *dev,
356 struct device_attribute *attr,
357 char *buf)
358{
359 struct iio_dev *dev_info = dev_get_drvdata(dev);
360 struct adt7310_chip_info *chip = dev_info->dev_data;
361 u8 status;
362 u16 data;
363 int ret, i = 0;
364
365 do {
366 ret = adt7310_spi_read_byte(chip, ADT7310_STATUS, &status);
367 if (ret)
368 return -EIO;
369 i++;
370 if (i == 10000)
371 return -EIO;
372 } while (status & ADT7310_STAT_NOT_RDY);
373
374 ret = adt7310_spi_read_word(chip, ADT7310_TEMPERATURE, &data);
375 if (ret)
376 return -EIO;
377
378 return adt7310_convert_temperature(chip, data, buf);
379}
380
381static IIO_DEVICE_ATTR(value, S_IRUGO, adt7310_show_value, NULL, 0);
382
383static ssize_t adt7310_show_name(struct device *dev,
384 struct device_attribute *attr,
385 char *buf)
386{
387 struct iio_dev *dev_info = dev_get_drvdata(dev);
388 struct adt7310_chip_info *chip = dev_info->dev_data;
389 return sprintf(buf, "%s\n", chip->name);
390}
391
392static IIO_DEVICE_ATTR(name, S_IRUGO, adt7310_show_name, NULL, 0);
393
394static struct attribute *adt7310_attributes[] = {
395 &iio_dev_attr_available_modes.dev_attr.attr,
396 &iio_dev_attr_mode.dev_attr.attr,
397 &iio_dev_attr_resolution.dev_attr.attr,
398 &iio_dev_attr_id.dev_attr.attr,
399 &iio_dev_attr_value.dev_attr.attr,
400 &iio_dev_attr_name.dev_attr.attr,
401 NULL,
402};
403
404static const struct attribute_group adt7310_attribute_group = {
405 .attrs = adt7310_attributes,
406};
407
408/*
409 * temperature bound events
410 */
411
412#define IIO_EVENT_CODE_ADT7310_ABOVE_ALARM IIO_BUFFER_EVENT_CODE(0)
413#define IIO_EVENT_CODE_ADT7310_BELLOW_ALARM IIO_BUFFER_EVENT_CODE(1)
414#define IIO_EVENT_CODE_ADT7310_ABOVE_CRIT IIO_BUFFER_EVENT_CODE(2)
415
416static void adt7310_interrupt_bh(struct work_struct *work_s)
417{
418 struct adt7310_chip_info *chip =
419 container_of(work_s, struct adt7310_chip_info, thresh_work);
420 u8 status;
421
422 if (adt7310_spi_read_byte(chip, ADT7310_STATUS, &status))
423 return;
424
425 if (status & ADT7310_STAT_T_HIGH)
426 iio_push_event(chip->indio_dev, 0,
427 IIO_EVENT_CODE_ADT7310_ABOVE_ALARM,
428 chip->last_timestamp);
429 if (status & ADT7310_STAT_T_LOW)
430 iio_push_event(chip->indio_dev, 0,
431 IIO_EVENT_CODE_ADT7310_BELLOW_ALARM,
432 chip->last_timestamp);
433 if (status & ADT7310_STAT_T_CRIT)
434 iio_push_event(chip->indio_dev, 0,
435 IIO_EVENT_CODE_ADT7310_ABOVE_CRIT,
436 chip->last_timestamp);
437}
438
439static int adt7310_interrupt(struct iio_dev *dev_info,
440 int index,
441 s64 timestamp,
442 int no_test)
443{
444 struct adt7310_chip_info *chip = dev_info->dev_data;
445
446 chip->last_timestamp = timestamp;
447 schedule_work(&chip->thresh_work);
448
449 return 0;
450}
451
452IIO_EVENT_SH(adt7310, &adt7310_interrupt);
453IIO_EVENT_SH(adt7310_ct, &adt7310_interrupt);
454
455static ssize_t adt7310_show_event_mode(struct device *dev,
456 struct device_attribute *attr,
457 char *buf)
458{
459 struct iio_dev *dev_info = dev_get_drvdata(dev);
460 struct adt7310_chip_info *chip = dev_info->dev_data;
461 int ret;
462
463 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
464 if (ret)
465 return -EIO;
466
467 if (chip->config & ADT7310_EVENT_MODE)
468 return sprintf(buf, "interrupt\n");
469 else
470 return sprintf(buf, "comparator\n");
471}
472
473static ssize_t adt7310_set_event_mode(struct device *dev,
474 struct device_attribute *attr,
475 const char *buf,
476 size_t len)
477{
478 struct iio_dev *dev_info = dev_get_drvdata(dev);
479 struct adt7310_chip_info *chip = dev_info->dev_data;
480 u16 config;
481 int ret;
482
483 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
484 if (ret)
485 return -EIO;
486
487 config = chip->config &= ~ADT7310_EVENT_MODE;
488 if (strcmp(buf, "comparator") != 0)
489 config |= ADT7310_EVENT_MODE;
490
491 ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config);
492 if (ret)
493 return -EIO;
494
495 chip->config = config;
496
497 return len;
498}
499
500static ssize_t adt7310_show_available_event_modes(struct device *dev,
501 struct device_attribute *attr,
502 char *buf)
503{
504 return sprintf(buf, "comparator\ninterrupt\n");
505}
506
507static ssize_t adt7310_show_fault_queue(struct device *dev,
508 struct device_attribute *attr,
509 char *buf)
510{
511 struct iio_dev *dev_info = dev_get_drvdata(dev);
512 struct adt7310_chip_info *chip = dev_info->dev_data;
513 int ret;
514
515 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
516 if (ret)
517 return -EIO;
518
519 return sprintf(buf, "%d\n", chip->config & ADT7310_FAULT_QUEUE_MASK);
520}
521
522static ssize_t adt7310_set_fault_queue(struct device *dev,
523 struct device_attribute *attr,
524 const char *buf,
525 size_t len)
526{
527 struct iio_dev *dev_info = dev_get_drvdata(dev);
528 struct adt7310_chip_info *chip = dev_info->dev_data;
529 unsigned long data;
530 int ret;
531 u8 config;
532
533 ret = strict_strtoul(buf, 10, &data);
534 if (ret || data > 3)
535 return -EINVAL;
536
537 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
538 if (ret)
539 return -EIO;
540
541 config = chip->config & ~ADT7310_FAULT_QUEUE_MASK;
542 config |= data;
543 ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, config);
544 if (ret)
545 return -EIO;
546
547 chip->config = config;
548
549 return len;
550}
551
552static inline ssize_t adt7310_show_t_bound(struct device *dev,
553 struct device_attribute *attr,
554 u8 bound_reg,
555 char *buf)
556{
557 struct iio_dev *dev_info = dev_get_drvdata(dev);
558 struct adt7310_chip_info *chip = dev_info->dev_data;
559 u16 data;
560 int ret;
561
562 ret = adt7310_spi_read_word(chip, bound_reg, &data);
563 if (ret)
564 return -EIO;
565
566 return adt7310_convert_temperature(chip, data, buf);
567}
568
569static inline ssize_t adt7310_set_t_bound(struct device *dev,
570 struct device_attribute *attr,
571 u8 bound_reg,
572 const char *buf,
573 size_t len)
574{
575 struct iio_dev *dev_info = dev_get_drvdata(dev);
576 struct adt7310_chip_info *chip = dev_info->dev_data;
577 long tmp1, tmp2;
578 u16 data;
579 char *pos;
580 int ret;
581
582 pos = strchr(buf, '.');
583
584 ret = strict_strtol(buf, 10, &tmp1);
585
586 if (ret || tmp1 > 127 || tmp1 < -128)
587 return -EINVAL;
588
589 if (pos) {
590 len = strlen(pos);
591
592 if (chip->config & ADT7310_RESOLUTION) {
593 if (len > ADT7310_T16_VALUE_FLOAT_OFFSET)
594 len = ADT7310_T16_VALUE_FLOAT_OFFSET;
595 pos[len] = 0;
596 ret = strict_strtol(pos, 10, &tmp2);
597
598 if (!ret)
599 tmp2 = (tmp2 / 78125) * 78125;
600 } else {
601 if (len > ADT7310_T13_VALUE_FLOAT_OFFSET)
602 len = ADT7310_T13_VALUE_FLOAT_OFFSET;
603 pos[len] = 0;
604 ret = strict_strtol(pos, 10, &tmp2);
605
606 if (!ret)
607 tmp2 = (tmp2 / 625) * 625;
608 }
609 }
610
611 if (tmp1 < 0)
612 data = (u16)(-tmp1);
613 else
614 data = (u16)tmp1;
615
616 if (chip->config & ADT7310_RESOLUTION) {
617 data = (data << ADT7310_T16_VALUE_FLOAT_OFFSET) |
618 (tmp2 & ADT7310_T16_VALUE_FLOAT_MASK);
619
620 if (tmp1 < 0)
621 /* convert positive value to supplyment */
622 data = (u16)((ADT7310_T16_VALUE_SIGN << 1) - (u32)data);
623 } else {
624 data = (data << ADT7310_T13_VALUE_FLOAT_OFFSET) |
625 (tmp2 & ADT7310_T13_VALUE_FLOAT_MASK);
626
627 if (tmp1 < 0)
628 /* convert positive value to supplyment */
629 data = (ADT7310_T13_VALUE_SIGN << 1) - data;
630 data <<= ADT7310_T13_VALUE_OFFSET;
631 }
632
633 ret = adt7310_spi_write_word(chip, bound_reg, data);
634 if (ret)
635 return -EIO;
636
637 return len;
638}
639
640static ssize_t adt7310_show_t_alarm_high(struct device *dev,
641 struct device_attribute *attr,
642 char *buf)
643{
644 return adt7310_show_t_bound(dev, attr,
645 ADT7310_T_ALARM_HIGH, buf);
646}
647
648static inline ssize_t adt7310_set_t_alarm_high(struct device *dev,
649 struct device_attribute *attr,
650 const char *buf,
651 size_t len)
652{
653 return adt7310_set_t_bound(dev, attr,
654 ADT7310_T_ALARM_HIGH, buf, len);
655}
656
657static ssize_t adt7310_show_t_alarm_low(struct device *dev,
658 struct device_attribute *attr,
659 char *buf)
660{
661 return adt7310_show_t_bound(dev, attr,
662 ADT7310_T_ALARM_LOW, buf);
663}
664
665static inline ssize_t adt7310_set_t_alarm_low(struct device *dev,
666 struct device_attribute *attr,
667 const char *buf,
668 size_t len)
669{
670 return adt7310_set_t_bound(dev, attr,
671 ADT7310_T_ALARM_LOW, buf, len);
672}
673
674static ssize_t adt7310_show_t_crit(struct device *dev,
675 struct device_attribute *attr,
676 char *buf)
677{
678 return adt7310_show_t_bound(dev, attr,
679 ADT7310_T_CRIT, buf);
680}
681
682static inline ssize_t adt7310_set_t_crit(struct device *dev,
683 struct device_attribute *attr,
684 const char *buf,
685 size_t len)
686{
687 return adt7310_set_t_bound(dev, attr,
688 ADT7310_T_CRIT, buf, len);
689}
690
691static ssize_t adt7310_show_t_hyst(struct device *dev,
692 struct device_attribute *attr,
693 char *buf)
694{
695 struct iio_dev *dev_info = dev_get_drvdata(dev);
696 struct adt7310_chip_info *chip = dev_info->dev_data;
697 int ret;
698 u8 t_hyst;
699
700 ret = adt7310_spi_read_byte(chip, ADT7310_T_HYST, &t_hyst);
701 if (ret)
702 return -EIO;
703
704 return sprintf(buf, "%d\n", t_hyst & ADT7310_T_HYST_MASK);
705}
706
707static inline ssize_t adt7310_set_t_hyst(struct device *dev,
708 struct device_attribute *attr,
709 const char *buf,
710 size_t len)
711{
712 struct iio_dev *dev_info = dev_get_drvdata(dev);
713 struct adt7310_chip_info *chip = dev_info->dev_data;
714 int ret;
715 unsigned long data;
716 u8 t_hyst;
717
718 ret = strict_strtol(buf, 10, &data);
719
720 if (ret || data > ADT7310_T_HYST_MASK)
721 return -EINVAL;
722
723 t_hyst = (u8)data;
724
725 ret = adt7310_spi_write_byte(chip, ADT7310_T_HYST, t_hyst);
726 if (ret)
727 return -EIO;
728
729 return len;
730}
731
732IIO_EVENT_ATTR_SH(event_mode, iio_event_adt7310,
733 adt7310_show_event_mode, adt7310_set_event_mode, 0);
734IIO_EVENT_ATTR_SH(available_event_modes, iio_event_adt7310,
735 adt7310_show_available_event_modes, NULL, 0);
736IIO_EVENT_ATTR_SH(fault_queue, iio_event_adt7310,
737 adt7310_show_fault_queue, adt7310_set_fault_queue, 0);
738IIO_EVENT_ATTR_SH(t_alarm_high, iio_event_adt7310,
739 adt7310_show_t_alarm_high, adt7310_set_t_alarm_high, 0);
740IIO_EVENT_ATTR_SH(t_alarm_low, iio_event_adt7310,
741 adt7310_show_t_alarm_low, adt7310_set_t_alarm_low, 0);
742IIO_EVENT_ATTR_SH(t_crit, iio_event_adt7310_ct,
743 adt7310_show_t_crit, adt7310_set_t_crit, 0);
744IIO_EVENT_ATTR_SH(t_hyst, iio_event_adt7310,
745 adt7310_show_t_hyst, adt7310_set_t_hyst, 0);
746
747static struct attribute *adt7310_event_int_attributes[] = {
748 &iio_event_attr_event_mode.dev_attr.attr,
749 &iio_event_attr_available_event_modes.dev_attr.attr,
750 &iio_event_attr_fault_queue.dev_attr.attr,
751 &iio_event_attr_t_alarm_high.dev_attr.attr,
752 &iio_event_attr_t_alarm_low.dev_attr.attr,
753 &iio_event_attr_t_hyst.dev_attr.attr,
754 NULL,
755};
756
757static struct attribute *adt7310_event_ct_attributes[] = {
758 &iio_event_attr_event_mode.dev_attr.attr,
759 &iio_event_attr_available_event_modes.dev_attr.attr,
760 &iio_event_attr_fault_queue.dev_attr.attr,
761 &iio_event_attr_t_crit.dev_attr.attr,
762 &iio_event_attr_t_hyst.dev_attr.attr,
763 NULL,
764};
765
766static struct attribute_group adt7310_event_attribute_group[ADT7310_IRQS] = {
767 {
768 .attrs = adt7310_event_int_attributes,
769 },
770 {
771 .attrs = adt7310_event_ct_attributes,
772 }
773};
774
775/*
776 * device probe and remove
777 */
778
779static int __devinit adt7310_probe(struct spi_device *spi_dev)
780{
781 struct adt7310_chip_info *chip;
782 int ret = 0;
783 unsigned long *adt7310_platform_data = spi_dev->dev.platform_data;
784 unsigned long irq_flags;
785
786 chip = kzalloc(sizeof(struct adt7310_chip_info), GFP_KERNEL);
787
788 if (chip == NULL)
789 return -ENOMEM;
790
791 /* this is only used for device removal purposes */
792 dev_set_drvdata(&spi_dev->dev, chip);
793
794 chip->spi_dev = spi_dev;
795 chip->name = spi_dev->modalias;
796
797 chip->indio_dev = iio_allocate_device();
798 if (chip->indio_dev == NULL) {
799 ret = -ENOMEM;
800 goto error_free_chip;
801 }
802
803 chip->indio_dev->dev.parent = &spi_dev->dev;
804 chip->indio_dev->attrs = &adt7310_attribute_group;
805 chip->indio_dev->event_attrs = adt7310_event_attribute_group;
806 chip->indio_dev->dev_data = (void *)chip;
807 chip->indio_dev->driver_module = THIS_MODULE;
808 chip->indio_dev->num_interrupt_lines = ADT7310_IRQS;
809 chip->indio_dev->modes = INDIO_DIRECT_MODE;
810
811 ret = iio_device_register(chip->indio_dev);
812 if (ret)
813 goto error_free_dev;
814
815 /* CT critcal temperature event. line 0 */
816 if (spi_dev->irq) {
817 if (adt7310_platform_data[2])
818 irq_flags = adt7310_platform_data[2];
819 else
820 irq_flags = IRQF_TRIGGER_LOW;
821 ret = iio_register_interrupt_line(spi_dev->irq,
822 chip->indio_dev,
823 0,
824 irq_flags,
825 chip->name);
826 if (ret)
827 goto error_unreg_dev;
828
829 /*
830 * The event handler list element refer to iio_event_adt7310.
831 * All event attributes bind to the same event handler.
832 * One event handler can only be added to one event list.
833 */
834 iio_add_event_to_list(&iio_event_adt7310,
835 &chip->indio_dev->interrupts[0]->ev_list);
836 }
837
838 /* INT bound temperature alarm event. line 1 */
839 if (adt7310_platform_data[0]) {
840 ret = iio_register_interrupt_line(adt7310_platform_data[0],
841 chip->indio_dev,
842 1,
843 adt7310_platform_data[1],
844 chip->name);
845 if (ret)
846 goto error_unreg_ct_irq;
847
848 /*
849 * The event handler list element refer to iio_event_adt7310.
850 * All event attributes bind to the same event handler.
851 * One event handler can only be added to one event list.
852 */
853 iio_add_event_to_list(&iio_event_adt7310_ct,
854 &chip->indio_dev->interrupts[1]->ev_list);
855 }
856
857 if (spi_dev->irq && adt7310_platform_data[0]) {
858 INIT_WORK(&chip->thresh_work, adt7310_interrupt_bh);
859
860 ret = adt7310_spi_read_byte(chip, ADT7310_CONFIG, &chip->config);
861 if (ret) {
862 ret = -EIO;
863 goto error_unreg_int_irq;
864 }
865
866 /* set irq polarity low level */
867 chip->config &= ~ADT7310_CT_POLARITY;
868
869 if (adt7310_platform_data[1] & IRQF_TRIGGER_HIGH)
870 chip->config |= ADT7310_INT_POLARITY;
871 else
872 chip->config &= ~ADT7310_INT_POLARITY;
873
874 ret = adt7310_spi_write_byte(chip, ADT7310_CONFIG, chip->config);
875 if (ret) {
876 ret = -EIO;
877 goto error_unreg_int_irq;
878 }
879 }
880
881 dev_info(&spi_dev->dev, "%s temperature sensor registered.\n",
882 chip->name);
883
884 return 0;
885
886error_unreg_int_irq:
887 iio_unregister_interrupt_line(chip->indio_dev, 1);
888error_unreg_ct_irq:
889 iio_unregister_interrupt_line(chip->indio_dev, 0);
890error_unreg_dev:
891 iio_device_unregister(chip->indio_dev);
892error_free_dev:
893 iio_free_device(chip->indio_dev);
894error_free_chip:
895 kfree(chip);
896
897 return ret;
898}
899
900static int __devexit adt7310_remove(struct spi_device *spi_dev)
901{
902 struct adt7310_chip_info *chip = dev_get_drvdata(&spi_dev->dev);
903 struct iio_dev *indio_dev = chip->indio_dev;
904 unsigned long *adt7310_platform_data = spi_dev->dev.platform_data;
905
906 dev_set_drvdata(&spi_dev->dev, NULL);
907 if (adt7310_platform_data[0])
908 iio_unregister_interrupt_line(indio_dev, 1);
909 if (spi_dev->irq)
910 iio_unregister_interrupt_line(indio_dev, 0);
911 iio_device_unregister(indio_dev);
912 iio_free_device(chip->indio_dev);
913 kfree(chip);
914
915 return 0;
916}
917
918static const struct spi_device_id adt7310_id[] = {
919 { "adt7310", 0 },
920 {}
921};
922
923MODULE_DEVICE_TABLE(spi, adt7310_id);
924
925static struct spi_driver adt7310_driver = {
926 .driver = {
927 .name = "adt7310",
928 .bus = &spi_bus_type,
929 .owner = THIS_MODULE,
930 },
931 .probe = adt7310_probe,
932 .remove = __devexit_p(adt7310_remove),
933 .id_table = adt7310_id,
934};
935
936static __init int adt7310_init(void)
937{
938 return spi_register_driver(&adt7310_driver);
939}
940
941static __exit void adt7310_exit(void)
942{
943 spi_unregister_driver(&adt7310_driver);
944}
945
946MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
947MODULE_DESCRIPTION("Analog Devices ADT7310 digital"
948 " temperature sensor driver");
949MODULE_LICENSE("GPL v2");
950
951module_init(adt7310_init);
952module_exit(adt7310_exit);
diff --git a/drivers/staging/iio/adc/adt7410.c b/drivers/staging/iio/adc/adt7410.c
new file mode 100644
index 000000000000..c345f27ec7fc
--- /dev/null
+++ b/drivers/staging/iio/adc/adt7410.c
@@ -0,0 +1,915 @@
1/*
2 * ADT7410 digital temperature sensor driver supporting ADT7410
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/workqueue.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/sysfs.h>
16#include <linux/list.h>
17#include <linux/i2c.h>
18#include <linux/rtc.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23/*
24 * ADT7410 registers definition
25 */
26
27#define ADT7410_TEMPERATURE 0
28#define ADT7410_STATUS 2
29#define ADT7410_CONFIG 3
30#define ADT7410_T_ALARM_HIGH 4
31#define ADT7410_T_ALARM_LOW 6
32#define ADT7410_T_CRIT 8
33#define ADT7410_T_HYST 0xA
34#define ADT7410_ID 0xB
35#define ADT7410_RESET 0x2F
36
37/*
38 * ADT7410 status
39 */
40#define ADT7410_STAT_T_LOW 0x10
41#define ADT7410_STAT_T_HIGH 0x20
42#define ADT7410_STAT_T_CRIT 0x40
43#define ADT7410_STAT_NOT_RDY 0x80
44
45/*
46 * ADT7410 config
47 */
48#define ADT7410_FAULT_QUEUE_MASK 0x3
49#define ADT7410_CT_POLARITY 0x4
50#define ADT7410_INT_POLARITY 0x8
51#define ADT7410_EVENT_MODE 0x10
52#define ADT7410_MODE_MASK 0x60
53#define ADT7410_ONESHOT 0x20
54#define ADT7410_SPS 0x40
55#define ADT7410_PD 0x60
56#define ADT7410_RESOLUTION 0x80
57
58/*
59 * ADT7410 masks
60 */
61#define ADT7410_T16_VALUE_SIGN 0x8000
62#define ADT7410_T16_VALUE_FLOAT_OFFSET 7
63#define ADT7410_T16_VALUE_FLOAT_MASK 0x7F
64#define ADT7410_T13_VALUE_SIGN 0x1000
65#define ADT7410_T13_VALUE_OFFSET 3
66#define ADT7410_T13_VALUE_FLOAT_OFFSET 4
67#define ADT7410_T13_VALUE_FLOAT_MASK 0xF
68#define ADT7410_T_HYST_MASK 0xF
69#define ADT7410_DEVICE_ID_MASK 0xF
70#define ADT7410_MANUFACTORY_ID_MASK 0xF0
71#define ADT7410_MANUFACTORY_ID_OFFSET 4
72
73#define ADT7410_IRQS 2
74
75/*
76 * struct adt7410_chip_info - chip specifc information
77 */
78
79struct adt7410_chip_info {
80 const char *name;
81 struct i2c_client *client;
82 struct iio_dev *indio_dev;
83 struct work_struct thresh_work;
84 s64 last_timestamp;
85 u8 config;
86};
87
88/*
89 * adt7410 register access by I2C
90 */
91
92static int adt7410_i2c_read_word(struct adt7410_chip_info *chip, u8 reg, u16 *data)
93{
94 struct i2c_client *client = chip->client;
95 int ret = 0;
96
97 ret = i2c_smbus_read_word_data(client, reg);
98 if (ret < 0) {
99 dev_err(&client->dev, "I2C read error\n");
100 return ret;
101 }
102
103 *data = swab16((u16)ret);
104
105 return 0;
106}
107
108static int adt7410_i2c_write_word(struct adt7410_chip_info *chip, u8 reg, u16 data)
109{
110 struct i2c_client *client = chip->client;
111 int ret = 0;
112
113 ret = i2c_smbus_write_word_data(client, reg, swab16(data));
114 if (ret < 0)
115 dev_err(&client->dev, "I2C write error\n");
116
117 return ret;
118}
119
120static int adt7410_i2c_read_byte(struct adt7410_chip_info *chip, u8 reg, u8 *data)
121{
122 struct i2c_client *client = chip->client;
123 int ret = 0;
124
125 ret = i2c_smbus_read_byte_data(client, reg);
126 if (ret < 0) {
127 dev_err(&client->dev, "I2C read error\n");
128 return ret;
129 }
130
131 *data = (u8)ret;
132
133 return 0;
134}
135
136static int adt7410_i2c_write_byte(struct adt7410_chip_info *chip, u8 reg, u8 data)
137{
138 struct i2c_client *client = chip->client;
139 int ret = 0;
140
141 ret = i2c_smbus_write_byte_data(client, reg, data);
142 if (ret < 0)
143 dev_err(&client->dev, "I2C write error\n");
144
145 return ret;
146}
147
148static ssize_t adt7410_show_mode(struct device *dev,
149 struct device_attribute *attr,
150 char *buf)
151{
152 struct iio_dev *dev_info = dev_get_drvdata(dev);
153 struct adt7410_chip_info *chip = dev_info->dev_data;
154 u8 config;
155
156 config = chip->config & ADT7410_MODE_MASK;
157
158 switch (config) {
159 case ADT7410_PD:
160 return sprintf(buf, "power-down\n");
161 case ADT7410_ONESHOT:
162 return sprintf(buf, "one-shot\n");
163 case ADT7410_SPS:
164 return sprintf(buf, "sps\n");
165 default:
166 return sprintf(buf, "full\n");
167 }
168}
169
170static ssize_t adt7410_store_mode(struct device *dev,
171 struct device_attribute *attr,
172 const char *buf,
173 size_t len)
174{
175 struct iio_dev *dev_info = dev_get_drvdata(dev);
176 struct adt7410_chip_info *chip = dev_info->dev_data;
177 u16 config;
178 int ret;
179
180 ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
181 if (ret)
182 return -EIO;
183
184 config = chip->config & (~ADT7410_MODE_MASK);
185 if (strcmp(buf, "power-down"))
186 config |= ADT7410_PD;
187 else if (strcmp(buf, "one-shot"))
188 config |= ADT7410_ONESHOT;
189 else if (strcmp(buf, "sps"))
190 config |= ADT7410_SPS;
191
192 ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config);
193 if (ret)
194 return -EIO;
195
196 chip->config = config;
197
198 return ret;
199}
200
201static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
202 adt7410_show_mode,
203 adt7410_store_mode,
204 0);
205
206static ssize_t adt7410_show_available_modes(struct device *dev,
207 struct device_attribute *attr,
208 char *buf)
209{
210 return sprintf(buf, "full\none-shot\nsps\npower-down\n");
211}
212
213static IIO_DEVICE_ATTR(available_modes, S_IRUGO, adt7410_show_available_modes, NULL, 0);
214
215static ssize_t adt7410_show_resolution(struct device *dev,
216 struct device_attribute *attr,
217 char *buf)
218{
219 struct iio_dev *dev_info = dev_get_drvdata(dev);
220 struct adt7410_chip_info *chip = dev_info->dev_data;
221 int ret;
222 int bits;
223
224 ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
225 if (ret)
226 return -EIO;
227
228 if (chip->config & ADT7410_RESOLUTION)
229 bits = 16;
230 else
231 bits = 13;
232
233 return sprintf(buf, "%d bits\n", bits);
234}
235
236static ssize_t adt7410_store_resolution(struct device *dev,
237 struct device_attribute *attr,
238 const char *buf,
239 size_t len)
240{
241 struct iio_dev *dev_info = dev_get_drvdata(dev);
242 struct adt7410_chip_info *chip = dev_info->dev_data;
243 unsigned long data;
244 u16 config;
245 int ret;
246
247 ret = strict_strtoul(buf, 10, &data);
248 if (ret)
249 return -EINVAL;
250
251 ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
252 if (ret)
253 return -EIO;
254
255 config = chip->config & (~ADT7410_RESOLUTION);
256 if (data)
257 config |= ADT7410_RESOLUTION;
258
259 ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config);
260 if (ret)
261 return -EIO;
262
263 chip->config = config;
264
265 return ret;
266}
267
268static IIO_DEVICE_ATTR(resolution, S_IRUGO | S_IWUSR,
269 adt7410_show_resolution,
270 adt7410_store_resolution,
271 0);
272
273static ssize_t adt7410_show_id(struct device *dev,
274 struct device_attribute *attr,
275 char *buf)
276{
277 struct iio_dev *dev_info = dev_get_drvdata(dev);
278 struct adt7410_chip_info *chip = dev_info->dev_data;
279 u8 id;
280 int ret;
281
282 ret = adt7410_i2c_read_byte(chip, ADT7410_ID, &id);
283 if (ret)
284 return -EIO;
285
286 return sprintf(buf, "device id: 0x%x\nmanufactory id: 0x%x\n",
287 id & ADT7410_DEVICE_ID_MASK,
288 (id & ADT7410_MANUFACTORY_ID_MASK) >> ADT7410_MANUFACTORY_ID_OFFSET);
289}
290
291static IIO_DEVICE_ATTR(id, S_IRUGO | S_IWUSR,
292 adt7410_show_id,
293 NULL,
294 0);
295
296static ssize_t adt7410_convert_temperature(struct adt7410_chip_info *chip,
297 u16 data, char *buf)
298{
299 char sign = ' ';
300
301 if (chip->config & ADT7410_RESOLUTION) {
302 if (data & ADT7410_T16_VALUE_SIGN) {
303 /* convert supplement to positive value */
304 data = (u16)((ADT7410_T16_VALUE_SIGN << 1) - (u32)data);
305 sign = '-';
306 }
307 return sprintf(buf, "%c%d.%.7d\n", sign,
308 (data >> ADT7410_T16_VALUE_FLOAT_OFFSET),
309 (data & ADT7410_T16_VALUE_FLOAT_MASK) * 78125);
310 } else {
311 if (data & ADT7410_T13_VALUE_SIGN) {
312 /* convert supplement to positive value */
313 data >>= ADT7410_T13_VALUE_OFFSET;
314 data = (ADT7410_T13_VALUE_SIGN << 1) - data;
315 sign = '-';
316 }
317 return sprintf(buf, "%c%d.%.4d\n", sign,
318 (data >> ADT7410_T13_VALUE_FLOAT_OFFSET),
319 (data & ADT7410_T13_VALUE_FLOAT_MASK) * 625);
320 }
321}
322
323static ssize_t adt7410_show_value(struct device *dev,
324 struct device_attribute *attr,
325 char *buf)
326{
327 struct iio_dev *dev_info = dev_get_drvdata(dev);
328 struct adt7410_chip_info *chip = dev_info->dev_data;
329 u8 status;
330 u16 data;
331 int ret, i = 0;
332
333 do {
334 ret = adt7410_i2c_read_byte(chip, ADT7410_STATUS, &status);
335 if (ret)
336 return -EIO;
337 i++;
338 if (i == 10000)
339 return -EIO;
340 } while (status & ADT7410_STAT_NOT_RDY);
341
342 ret = adt7410_i2c_read_word(chip, ADT7410_TEMPERATURE, &data);
343 if (ret)
344 return -EIO;
345
346 return adt7410_convert_temperature(chip, data, buf);
347}
348
349static IIO_DEVICE_ATTR(value, S_IRUGO, adt7410_show_value, NULL, 0);
350
351static ssize_t adt7410_show_name(struct device *dev,
352 struct device_attribute *attr,
353 char *buf)
354{
355 struct iio_dev *dev_info = dev_get_drvdata(dev);
356 struct adt7410_chip_info *chip = dev_info->dev_data;
357 return sprintf(buf, "%s\n", chip->name);
358}
359
360static IIO_DEVICE_ATTR(name, S_IRUGO, adt7410_show_name, NULL, 0);
361
362static struct attribute *adt7410_attributes[] = {
363 &iio_dev_attr_available_modes.dev_attr.attr,
364 &iio_dev_attr_mode.dev_attr.attr,
365 &iio_dev_attr_resolution.dev_attr.attr,
366 &iio_dev_attr_id.dev_attr.attr,
367 &iio_dev_attr_value.dev_attr.attr,
368 &iio_dev_attr_name.dev_attr.attr,
369 NULL,
370};
371
372static const struct attribute_group adt7410_attribute_group = {
373 .attrs = adt7410_attributes,
374};
375
376/*
377 * temperature bound events
378 */
379
380#define IIO_EVENT_CODE_ADT7410_ABOVE_ALARM IIO_BUFFER_EVENT_CODE(0)
381#define IIO_EVENT_CODE_ADT7410_BELLOW_ALARM IIO_BUFFER_EVENT_CODE(1)
382#define IIO_EVENT_CODE_ADT7410_ABOVE_CRIT IIO_BUFFER_EVENT_CODE(2)
383
384static void adt7410_interrupt_bh(struct work_struct *work_s)
385{
386 struct adt7410_chip_info *chip =
387 container_of(work_s, struct adt7410_chip_info, thresh_work);
388 u8 status;
389
390 if (adt7410_i2c_read_byte(chip, ADT7410_STATUS, &status))
391 return;
392
393 enable_irq(chip->client->irq);
394
395 if (status & ADT7410_STAT_T_HIGH)
396 iio_push_event(chip->indio_dev, 0,
397 IIO_EVENT_CODE_ADT7410_ABOVE_ALARM,
398 chip->last_timestamp);
399 if (status & ADT7410_STAT_T_LOW)
400 iio_push_event(chip->indio_dev, 0,
401 IIO_EVENT_CODE_ADT7410_BELLOW_ALARM,
402 chip->last_timestamp);
403 if (status & ADT7410_STAT_T_CRIT)
404 iio_push_event(chip->indio_dev, 0,
405 IIO_EVENT_CODE_ADT7410_ABOVE_CRIT,
406 chip->last_timestamp);
407}
408
409static int adt7410_interrupt(struct iio_dev *dev_info,
410 int index,
411 s64 timestamp,
412 int no_test)
413{
414 struct adt7410_chip_info *chip = dev_info->dev_data;
415
416 chip->last_timestamp = timestamp;
417 schedule_work(&chip->thresh_work);
418
419 return 0;
420}
421
422IIO_EVENT_SH(adt7410, &adt7410_interrupt);
423IIO_EVENT_SH(adt7410_ct, &adt7410_interrupt);
424
425static ssize_t adt7410_show_event_mode(struct device *dev,
426 struct device_attribute *attr,
427 char *buf)
428{
429 struct iio_dev *dev_info = dev_get_drvdata(dev);
430 struct adt7410_chip_info *chip = dev_info->dev_data;
431 int ret;
432
433 ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
434 if (ret)
435 return -EIO;
436
437 if (chip->config & ADT7410_EVENT_MODE)
438 return sprintf(buf, "interrupt\n");
439 else
440 return sprintf(buf, "comparator\n");
441}
442
443static ssize_t adt7410_set_event_mode(struct device *dev,
444 struct device_attribute *attr,
445 const char *buf,
446 size_t len)
447{
448 struct iio_dev *dev_info = dev_get_drvdata(dev);
449 struct adt7410_chip_info *chip = dev_info->dev_data;
450 u16 config;
451 int ret;
452
453 ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
454 if (ret)
455 return -EIO;
456
457 config = chip->config &= ~ADT7410_EVENT_MODE;
458 if (strcmp(buf, "comparator") != 0)
459 config |= ADT7410_EVENT_MODE;
460
461 ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config);
462 if (ret)
463 return -EIO;
464
465 chip->config = config;
466
467 return ret;
468}
469
470static ssize_t adt7410_show_available_event_modes(struct device *dev,
471 struct device_attribute *attr,
472 char *buf)
473{
474 return sprintf(buf, "comparator\ninterrupt\n");
475}
476
477static ssize_t adt7410_show_fault_queue(struct device *dev,
478 struct device_attribute *attr,
479 char *buf)
480{
481 struct iio_dev *dev_info = dev_get_drvdata(dev);
482 struct adt7410_chip_info *chip = dev_info->dev_data;
483 int ret;
484
485 ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
486 if (ret)
487 return -EIO;
488
489 return sprintf(buf, "%d\n", chip->config & ADT7410_FAULT_QUEUE_MASK);
490}
491
492static ssize_t adt7410_set_fault_queue(struct device *dev,
493 struct device_attribute *attr,
494 const char *buf,
495 size_t len)
496{
497 struct iio_dev *dev_info = dev_get_drvdata(dev);
498 struct adt7410_chip_info *chip = dev_info->dev_data;
499 unsigned long data;
500 int ret;
501 u8 config;
502
503 ret = strict_strtoul(buf, 10, &data);
504 if (ret || data > 3)
505 return -EINVAL;
506
507 ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
508 if (ret)
509 return -EIO;
510
511 config = chip->config & ~ADT7410_FAULT_QUEUE_MASK;
512 config |= data;
513 ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, config);
514 if (ret)
515 return -EIO;
516
517 chip->config = config;
518
519 return ret;
520}
521
522static inline ssize_t adt7410_show_t_bound(struct device *dev,
523 struct device_attribute *attr,
524 u8 bound_reg,
525 char *buf)
526{
527 struct iio_dev *dev_info = dev_get_drvdata(dev);
528 struct adt7410_chip_info *chip = dev_info->dev_data;
529 u16 data;
530 int ret;
531
532 ret = adt7410_i2c_read_word(chip, bound_reg, &data);
533 if (ret)
534 return -EIO;
535
536 return adt7410_convert_temperature(chip, data, buf);
537}
538
539static inline ssize_t adt7410_set_t_bound(struct device *dev,
540 struct device_attribute *attr,
541 u8 bound_reg,
542 const char *buf,
543 size_t len)
544{
545 struct iio_dev *dev_info = dev_get_drvdata(dev);
546 struct adt7410_chip_info *chip = dev_info->dev_data;
547 long tmp1, tmp2;
548 u16 data;
549 char *pos;
550 int ret;
551
552 pos = strchr(buf, '.');
553
554 ret = strict_strtol(buf, 10, &tmp1);
555
556 if (ret || tmp1 > 127 || tmp1 < -128)
557 return -EINVAL;
558
559 if (pos) {
560 len = strlen(pos);
561
562 if (chip->config & ADT7410_RESOLUTION) {
563 if (len > ADT7410_T16_VALUE_FLOAT_OFFSET)
564 len = ADT7410_T16_VALUE_FLOAT_OFFSET;
565 pos[len] = 0;
566 ret = strict_strtol(pos, 10, &tmp2);
567
568 if (!ret)
569 tmp2 = (tmp2 / 78125) * 78125;
570 } else {
571 if (len > ADT7410_T13_VALUE_FLOAT_OFFSET)
572 len = ADT7410_T13_VALUE_FLOAT_OFFSET;
573 pos[len] = 0;
574 ret = strict_strtol(pos, 10, &tmp2);
575
576 if (!ret)
577 tmp2 = (tmp2 / 625) * 625;
578 }
579 }
580
581 if (tmp1 < 0)
582 data = (u16)(-tmp1);
583 else
584 data = (u16)tmp1;
585
586 if (chip->config & ADT7410_RESOLUTION) {
587 data = (data << ADT7410_T16_VALUE_FLOAT_OFFSET) |
588 (tmp2 & ADT7410_T16_VALUE_FLOAT_MASK);
589
590 if (tmp1 < 0)
591 /* convert positive value to supplyment */
592 data = (u16)((ADT7410_T16_VALUE_SIGN << 1) - (u32)data);
593 } else {
594 data = (data << ADT7410_T13_VALUE_FLOAT_OFFSET) |
595 (tmp2 & ADT7410_T13_VALUE_FLOAT_MASK);
596
597 if (tmp1 < 0)
598 /* convert positive value to supplyment */
599 data = (ADT7410_T13_VALUE_SIGN << 1) - data;
600 data <<= ADT7410_T13_VALUE_OFFSET;
601 }
602
603 ret = adt7410_i2c_write_word(chip, bound_reg, data);
604 if (ret)
605 return -EIO;
606
607 return ret;
608}
609
610static ssize_t adt7410_show_t_alarm_high(struct device *dev,
611 struct device_attribute *attr,
612 char *buf)
613{
614 return adt7410_show_t_bound(dev, attr,
615 ADT7410_T_ALARM_HIGH, buf);
616}
617
618static inline ssize_t adt7410_set_t_alarm_high(struct device *dev,
619 struct device_attribute *attr,
620 const char *buf,
621 size_t len)
622{
623 return adt7410_set_t_bound(dev, attr,
624 ADT7410_T_ALARM_HIGH, buf, len);
625}
626
627static ssize_t adt7410_show_t_alarm_low(struct device *dev,
628 struct device_attribute *attr,
629 char *buf)
630{
631 return adt7410_show_t_bound(dev, attr,
632 ADT7410_T_ALARM_LOW, buf);
633}
634
635static inline ssize_t adt7410_set_t_alarm_low(struct device *dev,
636 struct device_attribute *attr,
637 const char *buf,
638 size_t len)
639{
640 return adt7410_set_t_bound(dev, attr,
641 ADT7410_T_ALARM_LOW, buf, len);
642}
643
644static ssize_t adt7410_show_t_crit(struct device *dev,
645 struct device_attribute *attr,
646 char *buf)
647{
648 return adt7410_show_t_bound(dev, attr,
649 ADT7410_T_CRIT, buf);
650}
651
652static inline ssize_t adt7410_set_t_crit(struct device *dev,
653 struct device_attribute *attr,
654 const char *buf,
655 size_t len)
656{
657 return adt7410_set_t_bound(dev, attr,
658 ADT7410_T_CRIT, buf, len);
659}
660
661static ssize_t adt7410_show_t_hyst(struct device *dev,
662 struct device_attribute *attr,
663 char *buf)
664{
665 struct iio_dev *dev_info = dev_get_drvdata(dev);
666 struct adt7410_chip_info *chip = dev_info->dev_data;
667 int ret;
668 u8 t_hyst;
669
670 ret = adt7410_i2c_read_byte(chip, ADT7410_T_HYST, &t_hyst);
671 if (ret)
672 return -EIO;
673
674 return sprintf(buf, "%d\n", t_hyst & ADT7410_T_HYST_MASK);
675}
676
677static inline ssize_t adt7410_set_t_hyst(struct device *dev,
678 struct device_attribute *attr,
679 const char *buf,
680 size_t len)
681{
682 struct iio_dev *dev_info = dev_get_drvdata(dev);
683 struct adt7410_chip_info *chip = dev_info->dev_data;
684 int ret;
685 unsigned long data;
686 u8 t_hyst;
687
688 ret = strict_strtol(buf, 10, &data);
689
690 if (ret || data > ADT7410_T_HYST_MASK)
691 return -EINVAL;
692
693 t_hyst = (u8)data;
694
695 ret = adt7410_i2c_write_byte(chip, ADT7410_T_HYST, t_hyst);
696 if (ret)
697 return -EIO;
698
699 return ret;
700}
701
702IIO_EVENT_ATTR_SH(event_mode, iio_event_adt7410,
703 adt7410_show_event_mode, adt7410_set_event_mode, 0);
704IIO_EVENT_ATTR_SH(available_event_modes, iio_event_adt7410,
705 adt7410_show_available_event_modes, NULL, 0);
706IIO_EVENT_ATTR_SH(fault_queue, iio_event_adt7410,
707 adt7410_show_fault_queue, adt7410_set_fault_queue, 0);
708IIO_EVENT_ATTR_SH(t_alarm_high, iio_event_adt7410,
709 adt7410_show_t_alarm_high, adt7410_set_t_alarm_high, 0);
710IIO_EVENT_ATTR_SH(t_alarm_low, iio_event_adt7410,
711 adt7410_show_t_alarm_low, adt7410_set_t_alarm_low, 0);
712IIO_EVENT_ATTR_SH(t_crit, iio_event_adt7410_ct,
713 adt7410_show_t_crit, adt7410_set_t_crit, 0);
714IIO_EVENT_ATTR_SH(t_hyst, iio_event_adt7410,
715 adt7410_show_t_hyst, adt7410_set_t_hyst, 0);
716
717static struct attribute *adt7410_event_int_attributes[] = {
718 &iio_event_attr_event_mode.dev_attr.attr,
719 &iio_event_attr_available_event_modes.dev_attr.attr,
720 &iio_event_attr_fault_queue.dev_attr.attr,
721 &iio_event_attr_t_alarm_high.dev_attr.attr,
722 &iio_event_attr_t_alarm_low.dev_attr.attr,
723 &iio_event_attr_t_hyst.dev_attr.attr,
724 NULL,
725};
726
727static struct attribute *adt7410_event_ct_attributes[] = {
728 &iio_event_attr_event_mode.dev_attr.attr,
729 &iio_event_attr_available_event_modes.dev_attr.attr,
730 &iio_event_attr_fault_queue.dev_attr.attr,
731 &iio_event_attr_t_crit.dev_attr.attr,
732 &iio_event_attr_t_hyst.dev_attr.attr,
733 NULL,
734};
735
736static struct attribute_group adt7410_event_attribute_group[ADT7410_IRQS] = {
737 {
738 .attrs = adt7410_event_int_attributes,
739 },
740 {
741 .attrs = adt7410_event_ct_attributes,
742 }
743};
744
745/*
746 * device probe and remove
747 */
748
749static int __devinit adt7410_probe(struct i2c_client *client,
750 const struct i2c_device_id *id)
751{
752 struct adt7410_chip_info *chip;
753 int ret = 0;
754 unsigned long *adt7410_platform_data = client->dev.platform_data;
755
756 chip = kzalloc(sizeof(struct adt7410_chip_info), GFP_KERNEL);
757
758 if (chip == NULL)
759 return -ENOMEM;
760
761 /* this is only used for device removal purposes */
762 i2c_set_clientdata(client, chip);
763
764 chip->client = client;
765 chip->name = id->name;
766
767 chip->indio_dev = iio_allocate_device();
768 if (chip->indio_dev == NULL) {
769 ret = -ENOMEM;
770 goto error_free_chip;
771 }
772
773 chip->indio_dev->dev.parent = &client->dev;
774 chip->indio_dev->attrs = &adt7410_attribute_group;
775 chip->indio_dev->event_attrs = adt7410_event_attribute_group;
776 chip->indio_dev->dev_data = (void *)chip;
777 chip->indio_dev->driver_module = THIS_MODULE;
778 chip->indio_dev->num_interrupt_lines = ADT7410_IRQS;
779 chip->indio_dev->modes = INDIO_DIRECT_MODE;
780
781 ret = iio_device_register(chip->indio_dev);
782 if (ret)
783 goto error_free_dev;
784
785 /* CT critcal temperature event. line 0 */
786 if (client->irq) {
787 ret = iio_register_interrupt_line(client->irq,
788 chip->indio_dev,
789 0,
790 IRQF_TRIGGER_LOW,
791 chip->name);
792 if (ret)
793 goto error_unreg_dev;
794
795 /*
796 * The event handler list element refer to iio_event_adt7410.
797 * All event attributes bind to the same event handler.
798 * One event handler can only be added to one event list.
799 */
800 iio_add_event_to_list(&iio_event_adt7410,
801 &chip->indio_dev->interrupts[0]->ev_list);
802 }
803
804 /* INT bound temperature alarm event. line 1 */
805 if (adt7410_platform_data[0]) {
806 ret = iio_register_interrupt_line(adt7410_platform_data[0],
807 chip->indio_dev,
808 1,
809 adt7410_platform_data[1],
810 chip->name);
811 if (ret)
812 goto error_unreg_ct_irq;
813
814 /*
815 * The event handler list element refer to iio_event_adt7410.
816 * All event attributes bind to the same event handler.
817 * One event handler can only be added to one event list.
818 */
819 iio_add_event_to_list(&iio_event_adt7410_ct,
820 &chip->indio_dev->interrupts[1]->ev_list);
821 }
822
823 if (client->irq && adt7410_platform_data[0]) {
824 INIT_WORK(&chip->thresh_work, adt7410_interrupt_bh);
825
826 ret = adt7410_i2c_read_byte(chip, ADT7410_CONFIG, &chip->config);
827 if (ret) {
828 ret = -EIO;
829 goto error_unreg_int_irq;
830 }
831
832 /* set irq polarity low level */
833 chip->config &= ~ADT7410_CT_POLARITY;
834
835 if (adt7410_platform_data[1] & IRQF_TRIGGER_HIGH)
836 chip->config |= ADT7410_INT_POLARITY;
837 else
838 chip->config &= ~ADT7410_INT_POLARITY;
839
840 ret = adt7410_i2c_write_byte(chip, ADT7410_CONFIG, chip->config);
841 if (ret) {
842 ret = -EIO;
843 goto error_unreg_int_irq;
844 }
845 }
846
847 dev_info(&client->dev, "%s temperature sensor registered.\n",
848 id->name);
849
850 return 0;
851
852error_unreg_int_irq:
853 iio_unregister_interrupt_line(chip->indio_dev, 1);
854error_unreg_ct_irq:
855 iio_unregister_interrupt_line(chip->indio_dev, 0);
856error_unreg_dev:
857 iio_device_unregister(chip->indio_dev);
858error_free_dev:
859 iio_free_device(chip->indio_dev);
860error_free_chip:
861 kfree(chip);
862
863 return ret;
864}
865
866static int __devexit adt7410_remove(struct i2c_client *client)
867{
868 struct adt7410_chip_info *chip = i2c_get_clientdata(client);
869 struct iio_dev *indio_dev = chip->indio_dev;
870 unsigned long *adt7410_platform_data = client->dev.platform_data;
871
872 if (adt7410_platform_data[0])
873 iio_unregister_interrupt_line(indio_dev, 1);
874 if (client->irq)
875 iio_unregister_interrupt_line(indio_dev, 0);
876 iio_device_unregister(indio_dev);
877 iio_free_device(chip->indio_dev);
878 kfree(chip);
879
880 return 0;
881}
882
883static const struct i2c_device_id adt7410_id[] = {
884 { "adt7410", 0 },
885 {}
886};
887
888MODULE_DEVICE_TABLE(i2c, adt7410_id);
889
890static struct i2c_driver adt7410_driver = {
891 .driver = {
892 .name = "adt7410",
893 },
894 .probe = adt7410_probe,
895 .remove = __devexit_p(adt7410_remove),
896 .id_table = adt7410_id,
897};
898
899static __init int adt7410_init(void)
900{
901 return i2c_add_driver(&adt7410_driver);
902}
903
904static __exit void adt7410_exit(void)
905{
906 i2c_del_driver(&adt7410_driver);
907}
908
909MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
910MODULE_DESCRIPTION("Analog Devices ADT7410 digital"
911 " temperature sensor driver");
912MODULE_LICENSE("GPL v2");
913
914module_init(adt7410_init);
915module_exit(adt7410_exit);
diff --git a/drivers/staging/iio/adc/adt75.c b/drivers/staging/iio/adc/adt75.c
new file mode 100644
index 000000000000..aff4d31eb89c
--- /dev/null
+++ b/drivers/staging/iio/adc/adt75.c
@@ -0,0 +1,732 @@
1/*
2 * ADT75 digital temperature sensor driver supporting ADT75
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/workqueue.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/slab.h>
15#include <linux/sysfs.h>
16#include <linux/list.h>
17#include <linux/i2c.h>
18#include <linux/rtc.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23/*
24 * ADT75 registers definition
25 */
26
27#define ADT75_TEMPERATURE 0
28#define ADT75_CONFIG 1
29#define ADT75_T_HYST 2
30#define ADT75_T_OS 3
31#define ADT75_ONESHOT 4
32
33/*
34 * ADT75 config
35 */
36#define ADT75_PD 0x1
37#define ADT75_OS_INT 0x2
38#define ADT75_OS_POLARITY 0x4
39#define ADT75_FAULT_QUEUE_MASK 0x18
40#define ADT75_FAULT_QUEUE_OFFSET 3
41#define ADT75_SMBUS_ALART 0x8
42
43/*
44 * ADT75 masks
45 */
46#define ADT75_VALUE_SIGN 0x800
47#define ADT75_VALUE_OFFSET 4
48#define ADT75_VALUE_FLOAT_OFFSET 4
49#define ADT75_VALUE_FLOAT_MASK 0xF
50
51
52/*
53 * struct adt75_chip_info - chip specifc information
54 */
55
56struct adt75_chip_info {
57 const char *name;
58 struct i2c_client *client;
59 struct iio_dev *indio_dev;
60 struct work_struct thresh_work;
61 s64 last_timestamp;
62 u8 config;
63};
64
65/*
66 * adt75 register access by I2C
67 */
68
69static int adt75_i2c_read(struct adt75_chip_info *chip, u8 reg, u8 *data)
70{
71 struct i2c_client *client = chip->client;
72 int ret = 0, len;
73
74 ret = i2c_smbus_write_byte(client, reg);
75 if (ret < 0) {
76 dev_err(&client->dev, "I2C read register address error\n");
77 return ret;
78 }
79
80 if (reg == ADT75_CONFIG || reg == ADT75_ONESHOT)
81 len = 1;
82 else
83 len = 2;
84
85 ret = i2c_master_recv(client, data, len);
86 if (ret < 0) {
87 dev_err(&client->dev, "I2C read error\n");
88 return ret;
89 }
90
91 return ret;
92}
93
94static int adt75_i2c_write(struct adt75_chip_info *chip, u8 reg, u8 data)
95{
96 struct i2c_client *client = chip->client;
97 int ret = 0;
98
99 if (reg == ADT75_CONFIG || reg == ADT75_ONESHOT)
100 ret = i2c_smbus_write_byte_data(client, reg, data);
101 else
102 ret = i2c_smbus_write_word_data(client, reg, data);
103
104 if (ret < 0)
105 dev_err(&client->dev, "I2C write error\n");
106
107 return ret;
108}
109
110static ssize_t adt75_show_mode(struct device *dev,
111 struct device_attribute *attr,
112 char *buf)
113{
114 struct iio_dev *dev_info = dev_get_drvdata(dev);
115 struct adt75_chip_info *chip = dev_info->dev_data;
116
117 if (chip->config & ADT75_PD)
118 return sprintf(buf, "power-save\n");
119 else
120 return sprintf(buf, "full\n");
121}
122
123static ssize_t adt75_store_mode(struct device *dev,
124 struct device_attribute *attr,
125 const char *buf,
126 size_t len)
127{
128 struct iio_dev *dev_info = dev_get_drvdata(dev);
129 struct adt75_chip_info *chip = dev_info->dev_data;
130 int ret;
131 u8 config;
132
133 ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
134 if (ret)
135 return -EIO;
136
137 config = chip->config & ~ADT75_PD;
138 if (!strcmp(buf, "full"))
139 config |= ADT75_PD;
140
141 ret = adt75_i2c_write(chip, ADT75_CONFIG, config);
142 if (ret)
143 return -EIO;
144
145 chip->config = config;
146
147 return ret;
148}
149
150static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
151 adt75_show_mode,
152 adt75_store_mode,
153 0);
154
155static ssize_t adt75_show_available_modes(struct device *dev,
156 struct device_attribute *attr,
157 char *buf)
158{
159 return sprintf(buf, "full\npower-down\n");
160}
161
162static IIO_DEVICE_ATTR(available_modes, S_IRUGO, adt75_show_available_modes, NULL, 0);
163
164static ssize_t adt75_show_oneshot(struct device *dev,
165 struct device_attribute *attr,
166 char *buf)
167{
168 struct iio_dev *dev_info = dev_get_drvdata(dev);
169 struct adt75_chip_info *chip = dev_info->dev_data;
170
171 return sprintf(buf, "%d\n", !!(chip->config & ADT75_ONESHOT));
172}
173
174static ssize_t adt75_store_oneshot(struct device *dev,
175 struct device_attribute *attr,
176 const char *buf,
177 size_t len)
178{
179 struct iio_dev *dev_info = dev_get_drvdata(dev);
180 struct adt75_chip_info *chip = dev_info->dev_data;
181 unsigned long data = 0;
182 int ret;
183 u8 config;
184
185 ret = strict_strtoul(buf, 10, &data);
186 if (ret)
187 return -EINVAL;
188
189
190 ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
191 if (ret)
192 return -EIO;
193
194 config = chip->config & ~ADT75_ONESHOT;
195 if (data)
196 config |= ADT75_ONESHOT;
197
198 ret = adt75_i2c_write(chip, ADT75_CONFIG, config);
199 if (ret)
200 return -EIO;
201
202 chip->config = config;
203
204 return ret;
205}
206
207static IIO_DEVICE_ATTR(oneshot, S_IRUGO | S_IWUSR,
208 adt75_show_oneshot,
209 adt75_store_oneshot,
210 0);
211
212static ssize_t adt75_show_value(struct device *dev,
213 struct device_attribute *attr,
214 char *buf)
215{
216 struct iio_dev *dev_info = dev_get_drvdata(dev);
217 struct adt75_chip_info *chip = dev_info->dev_data;
218 u16 data;
219 char sign = ' ';
220 int ret;
221
222 if (chip->config & ADT75_PD) {
223 dev_err(dev, "Can't read value in power-down mode.\n");
224 return -EIO;
225 }
226
227 if (chip->config & ADT75_ONESHOT) {
228 /* write to active converter */
229 ret = i2c_smbus_write_byte(chip->client, ADT75_ONESHOT);
230 if (ret)
231 return -EIO;
232 }
233
234 ret = adt75_i2c_read(chip, ADT75_TEMPERATURE, (u8 *)&data);
235 if (ret)
236 return -EIO;
237
238 data = swab16(data) >> ADT75_VALUE_OFFSET;
239 if (data & ADT75_VALUE_SIGN) {
240 /* convert supplement to positive value */
241 data = (ADT75_VALUE_SIGN << 1) - data;
242 sign = '-';
243 }
244
245 return sprintf(buf, "%c%d.%.4d\n", sign,
246 (data >> ADT75_VALUE_FLOAT_OFFSET),
247 (data & ADT75_VALUE_FLOAT_MASK) * 625);
248}
249
250static IIO_DEVICE_ATTR(value, S_IRUGO, adt75_show_value, NULL, 0);
251
252static ssize_t adt75_show_name(struct device *dev,
253 struct device_attribute *attr,
254 char *buf)
255{
256 struct iio_dev *dev_info = dev_get_drvdata(dev);
257 struct adt75_chip_info *chip = dev_info->dev_data;
258 return sprintf(buf, "%s\n", chip->name);
259}
260
261static IIO_DEVICE_ATTR(name, S_IRUGO, adt75_show_name, NULL, 0);
262
263static struct attribute *adt75_attributes[] = {
264 &iio_dev_attr_available_modes.dev_attr.attr,
265 &iio_dev_attr_mode.dev_attr.attr,
266 &iio_dev_attr_oneshot.dev_attr.attr,
267 &iio_dev_attr_value.dev_attr.attr,
268 &iio_dev_attr_name.dev_attr.attr,
269 NULL,
270};
271
272static const struct attribute_group adt75_attribute_group = {
273 .attrs = adt75_attributes,
274};
275
276/*
277 * temperature bound events
278 */
279
280#define IIO_EVENT_CODE_ADT75_OTI IIO_BUFFER_EVENT_CODE(0)
281
282static void adt75_interrupt_bh(struct work_struct *work_s)
283{
284 struct adt75_chip_info *chip =
285 container_of(work_s, struct adt75_chip_info, thresh_work);
286
287 enable_irq(chip->client->irq);
288
289 iio_push_event(chip->indio_dev, 0,
290 IIO_EVENT_CODE_ADT75_OTI,
291 chip->last_timestamp);
292}
293
294static int adt75_interrupt(struct iio_dev *dev_info,
295 int index,
296 s64 timestamp,
297 int no_test)
298{
299 struct adt75_chip_info *chip = dev_info->dev_data;
300
301 chip->last_timestamp = timestamp;
302 schedule_work(&chip->thresh_work);
303
304 return 0;
305}
306
307IIO_EVENT_SH(adt75, &adt75_interrupt);
308
309static ssize_t adt75_show_oti_mode(struct device *dev,
310 struct device_attribute *attr,
311 char *buf)
312{
313 struct iio_dev *dev_info = dev_get_drvdata(dev);
314 struct adt75_chip_info *chip = dev_info->dev_data;
315 int ret;
316
317 /* retrive ALART status */
318 ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
319 if (ret)
320 return -EIO;
321
322 if (chip->config & ADT75_OS_INT)
323 return sprintf(buf, "interrupt\n");
324 else
325 return sprintf(buf, "comparator\n");
326}
327
328static ssize_t adt75_set_oti_mode(struct device *dev,
329 struct device_attribute *attr,
330 const char *buf,
331 size_t len)
332{
333 struct iio_dev *dev_info = dev_get_drvdata(dev);
334 struct adt75_chip_info *chip = dev_info->dev_data;
335 int ret;
336 u8 config;
337
338 /* retrive ALART status */
339 ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
340 if (ret)
341 return -EIO;
342
343 config = chip->config & ~ADT75_OS_INT;
344 if (strcmp(buf, "comparator") != 0)
345 config |= ADT75_OS_INT;
346
347 ret = adt75_i2c_write(chip, ADT75_CONFIG, config);
348 if (ret)
349 return -EIO;
350
351 chip->config = config;
352
353 return ret;
354}
355
356static ssize_t adt75_show_available_oti_modes(struct device *dev,
357 struct device_attribute *attr,
358 char *buf)
359{
360 return sprintf(buf, "comparator\ninterrupt\n");
361}
362
363static ssize_t adt75_show_smbus_alart(struct device *dev,
364 struct device_attribute *attr,
365 char *buf)
366{
367 struct iio_dev *dev_info = dev_get_drvdata(dev);
368 struct adt75_chip_info *chip = dev_info->dev_data;
369 int ret;
370
371 /* retrive ALART status */
372 ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
373 if (ret)
374 return -EIO;
375
376 return sprintf(buf, "%d\n", !!(chip->config & ADT75_SMBUS_ALART));
377}
378
379static ssize_t adt75_set_smbus_alart(struct device *dev,
380 struct device_attribute *attr,
381 const char *buf,
382 size_t len)
383{
384 struct iio_dev *dev_info = dev_get_drvdata(dev);
385 struct adt75_chip_info *chip = dev_info->dev_data;
386 unsigned long data = 0;
387 int ret;
388 u8 config;
389
390 ret = strict_strtoul(buf, 10, &data);
391 if (ret)
392 return -EINVAL;
393
394 /* retrive ALART status */
395 ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
396 if (ret)
397 return -EIO;
398
399 config = chip->config & ~ADT75_SMBUS_ALART;
400 if (data)
401 config |= ADT75_SMBUS_ALART;
402
403 ret = adt75_i2c_write(chip, ADT75_CONFIG, config);
404 if (ret)
405 return -EIO;
406
407 chip->config = config;
408
409 return ret;
410}
411
412static ssize_t adt75_show_fault_queue(struct device *dev,
413 struct device_attribute *attr,
414 char *buf)
415{
416 struct iio_dev *dev_info = dev_get_drvdata(dev);
417 struct adt75_chip_info *chip = dev_info->dev_data;
418 int ret;
419
420 /* retrive ALART status */
421 ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
422 if (ret)
423 return -EIO;
424
425 return sprintf(buf, "%d\n", (chip->config & ADT75_FAULT_QUEUE_MASK) >>
426 ADT75_FAULT_QUEUE_OFFSET);
427}
428
429static ssize_t adt75_set_fault_queue(struct device *dev,
430 struct device_attribute *attr,
431 const char *buf,
432 size_t len)
433{
434 struct iio_dev *dev_info = dev_get_drvdata(dev);
435 struct adt75_chip_info *chip = dev_info->dev_data;
436 unsigned long data;
437 int ret;
438 u8 config;
439
440 ret = strict_strtoul(buf, 10, &data);
441 if (ret || data > 3)
442 return -EINVAL;
443
444 /* retrive ALART status */
445 ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
446 if (ret)
447 return -EIO;
448
449 config = chip->config & ~ADT75_FAULT_QUEUE_MASK;
450 config |= (data << ADT75_FAULT_QUEUE_OFFSET);
451 ret = adt75_i2c_write(chip, ADT75_CONFIG, config);
452 if (ret)
453 return -EIO;
454
455 chip->config = config;
456
457 return ret;
458}
459static inline ssize_t adt75_show_t_bound(struct device *dev,
460 struct device_attribute *attr,
461 u8 bound_reg,
462 char *buf)
463{
464 struct iio_dev *dev_info = dev_get_drvdata(dev);
465 struct adt75_chip_info *chip = dev_info->dev_data;
466 u16 data;
467 char sign = ' ';
468 int ret;
469
470 ret = adt75_i2c_read(chip, bound_reg, (u8 *)&data);
471 if (ret)
472 return -EIO;
473
474 data = swab16(data) >> ADT75_VALUE_OFFSET;
475 if (data & ADT75_VALUE_SIGN) {
476 /* convert supplement to positive value */
477 data = (ADT75_VALUE_SIGN << 1) - data;
478 sign = '-';
479 }
480
481 return sprintf(buf, "%c%d.%.4d\n", sign,
482 (data >> ADT75_VALUE_FLOAT_OFFSET),
483 (data & ADT75_VALUE_FLOAT_MASK) * 625);
484}
485
486static inline ssize_t adt75_set_t_bound(struct device *dev,
487 struct device_attribute *attr,
488 u8 bound_reg,
489 const char *buf,
490 size_t len)
491{
492 struct iio_dev *dev_info = dev_get_drvdata(dev);
493 struct adt75_chip_info *chip = dev_info->dev_data;
494 long tmp1, tmp2;
495 u16 data;
496 char *pos;
497 int ret;
498
499 pos = strchr(buf, '.');
500
501 ret = strict_strtol(buf, 10, &tmp1);
502
503 if (ret || tmp1 > 127 || tmp1 < -128)
504 return -EINVAL;
505
506 if (pos) {
507 len = strlen(pos);
508 if (len > ADT75_VALUE_FLOAT_OFFSET)
509 len = ADT75_VALUE_FLOAT_OFFSET;
510 pos[len] = 0;
511 ret = strict_strtol(pos, 10, &tmp2);
512
513 if (!ret)
514 tmp2 = (tmp2 / 625) * 625;
515 }
516
517 if (tmp1 < 0)
518 data = (u16)(-tmp1);
519 else
520 data = (u16)tmp1;
521 data = (data << ADT75_VALUE_FLOAT_OFFSET) | (tmp2 & ADT75_VALUE_FLOAT_MASK);
522 if (tmp1 < 0)
523 /* convert positive value to supplyment */
524 data = (ADT75_VALUE_SIGN << 1) - data;
525 data <<= ADT75_VALUE_OFFSET;
526 data = swab16(data);
527
528 ret = adt75_i2c_write(chip, bound_reg, (u8)data);
529 if (ret)
530 return -EIO;
531
532 return ret;
533}
534
535static ssize_t adt75_show_t_os(struct device *dev,
536 struct device_attribute *attr,
537 char *buf)
538{
539 return adt75_show_t_bound(dev, attr,
540 ADT75_T_OS, buf);
541}
542
543static inline ssize_t adt75_set_t_os(struct device *dev,
544 struct device_attribute *attr,
545 const char *buf,
546 size_t len)
547{
548 return adt75_set_t_bound(dev, attr,
549 ADT75_T_OS, buf, len);
550}
551
552static ssize_t adt75_show_t_hyst(struct device *dev,
553 struct device_attribute *attr,
554 char *buf)
555{
556 return adt75_show_t_bound(dev, attr,
557 ADT75_T_HYST, buf);
558}
559
560static inline ssize_t adt75_set_t_hyst(struct device *dev,
561 struct device_attribute *attr,
562 const char *buf,
563 size_t len)
564{
565 return adt75_set_t_bound(dev, attr,
566 ADT75_T_HYST, buf, len);
567}
568
569IIO_EVENT_ATTR_SH(oti_mode, iio_event_adt75,
570 adt75_show_oti_mode, adt75_set_oti_mode, 0);
571IIO_EVENT_ATTR_SH(available_oti_modes, iio_event_adt75,
572 adt75_show_available_oti_modes, NULL, 0);
573IIO_EVENT_ATTR_SH(smbus_alart, iio_event_adt75,
574 adt75_show_smbus_alart, adt75_set_smbus_alart, 0);
575IIO_EVENT_ATTR_SH(fault_queue, iio_event_adt75,
576 adt75_show_fault_queue, adt75_set_fault_queue, 0);
577IIO_EVENT_ATTR_SH(t_os, iio_event_adt75,
578 adt75_show_t_os, adt75_set_t_os, 0);
579IIO_EVENT_ATTR_SH(t_hyst, iio_event_adt75,
580 adt75_show_t_hyst, adt75_set_t_hyst, 0);
581
582static struct attribute *adt75_event_attributes[] = {
583 &iio_event_attr_oti_mode.dev_attr.attr,
584 &iio_event_attr_available_oti_modes.dev_attr.attr,
585 &iio_event_attr_smbus_alart.dev_attr.attr,
586 &iio_event_attr_fault_queue.dev_attr.attr,
587 &iio_event_attr_t_os.dev_attr.attr,
588 &iio_event_attr_t_hyst.dev_attr.attr,
589 NULL,
590};
591
592static struct attribute_group adt75_event_attribute_group = {
593 .attrs = adt75_event_attributes,
594};
595
596/*
597 * device probe and remove
598 */
599
600static int __devinit adt75_probe(struct i2c_client *client,
601 const struct i2c_device_id *id)
602{
603 struct adt75_chip_info *chip;
604 int ret = 0;
605
606 chip = kzalloc(sizeof(struct adt75_chip_info), GFP_KERNEL);
607
608 if (chip == NULL)
609 return -ENOMEM;
610
611 /* this is only used for device removal purposes */
612 i2c_set_clientdata(client, chip);
613
614 chip->client = client;
615 chip->name = id->name;
616
617 chip->indio_dev = iio_allocate_device();
618 if (chip->indio_dev == NULL) {
619 ret = -ENOMEM;
620 goto error_free_chip;
621 }
622
623 chip->indio_dev->dev.parent = &client->dev;
624 chip->indio_dev->attrs = &adt75_attribute_group;
625 chip->indio_dev->event_attrs = &adt75_event_attribute_group;
626 chip->indio_dev->dev_data = (void *)chip;
627 chip->indio_dev->driver_module = THIS_MODULE;
628 chip->indio_dev->num_interrupt_lines = 1;
629 chip->indio_dev->modes = INDIO_DIRECT_MODE;
630
631 ret = iio_device_register(chip->indio_dev);
632 if (ret)
633 goto error_free_dev;
634
635 if (client->irq > 0) {
636 ret = iio_register_interrupt_line(client->irq,
637 chip->indio_dev,
638 0,
639 IRQF_TRIGGER_LOW,
640 chip->name);
641 if (ret)
642 goto error_unreg_dev;
643
644 /*
645 * The event handler list element refer to iio_event_adt75.
646 * All event attributes bind to the same event handler.
647 * So, only register event handler once.
648 */
649 iio_add_event_to_list(&iio_event_adt75,
650 &chip->indio_dev->interrupts[0]->ev_list);
651
652 INIT_WORK(&chip->thresh_work, adt75_interrupt_bh);
653
654 ret = adt75_i2c_read(chip, ADT75_CONFIG, &chip->config);
655 if (ret) {
656 ret = -EIO;
657 goto error_unreg_irq;
658 }
659
660 /* set irq polarity low level */
661 chip->config &= ~ADT75_OS_POLARITY;
662
663 ret = adt75_i2c_write(chip, ADT75_CONFIG, chip->config);
664 if (ret) {
665 ret = -EIO;
666 goto error_unreg_irq;
667 }
668 }
669
670 dev_info(&client->dev, "%s temperature sensor registered.\n",
671 id->name);
672
673 return 0;
674error_unreg_irq:
675 iio_unregister_interrupt_line(chip->indio_dev, 0);
676error_unreg_dev:
677 iio_device_unregister(chip->indio_dev);
678error_free_dev:
679 iio_free_device(chip->indio_dev);
680error_free_chip:
681 kfree(chip);
682
683 return ret;
684}
685
686static int __devexit adt75_remove(struct i2c_client *client)
687{
688 struct adt75_chip_info *chip = i2c_get_clientdata(client);
689 struct iio_dev *indio_dev = chip->indio_dev;
690
691 if (client->irq)
692 iio_unregister_interrupt_line(indio_dev, 0);
693 iio_device_unregister(indio_dev);
694 iio_free_device(chip->indio_dev);
695 kfree(chip);
696
697 return 0;
698}
699
700static const struct i2c_device_id adt75_id[] = {
701 { "adt75", 0 },
702 {}
703};
704
705MODULE_DEVICE_TABLE(i2c, adt75_id);
706
707static struct i2c_driver adt75_driver = {
708 .driver = {
709 .name = "adt75",
710 },
711 .probe = adt75_probe,
712 .remove = __devexit_p(adt75_remove),
713 .id_table = adt75_id,
714};
715
716static __init int adt75_init(void)
717{
718 return i2c_add_driver(&adt75_driver);
719}
720
721static __exit void adt75_exit(void)
722{
723 i2c_del_driver(&adt75_driver);
724}
725
726MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
727MODULE_DESCRIPTION("Analog Devices ADT75 digital"
728 " temperature sensor driver");
729MODULE_LICENSE("GPL v2");
730
731module_init(adt75_init);
732module_exit(adt75_exit);
diff --git a/drivers/staging/iio/addac/Kconfig b/drivers/staging/iio/addac/Kconfig
new file mode 100644
index 000000000000..9847baf02700
--- /dev/null
+++ b/drivers/staging/iio/addac/Kconfig
@@ -0,0 +1,25 @@
1#
2# ADDAC drivers
3#
4comment "Analog digital bi-direction convertors"
5
6config ADT7316
7 tristate "Analog Devices ADT7316/7/8 ADT7516/7/9 temperature sensor, ADC and DAC driver"
8 help
9 Say yes here to build support for Analog Devices ADT7316, ADT7317, ADT7318
10 and ADT7516, ADT7517, ADT7519 temperature sensors, ADC and DAC.
11
12config ADT7316_SPI
13 tristate "support SPI bus connection"
14 depends on SPI && ADT7316
15 default y
16 help
17 Say yes here to build SPI bus support for Analog Devices ADT7316/7/8
18 and ADT7516/7/9.
19
20config ADT7316_I2C
21 tristate "support I2C bus connection"
22 depends on I2C && ADT7316
23 help
24 Say yes here to build I2C bus support for Analog Devices ADT7316/7/8
25 and ADT7516/7/9.
diff --git a/drivers/staging/iio/addac/Makefile b/drivers/staging/iio/addac/Makefile
new file mode 100644
index 000000000000..4c7686133692
--- /dev/null
+++ b/drivers/staging/iio/addac/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for industrial I/O ADDAC drivers
3#
4
5obj-$(CONFIG_ADT7316) += adt7316.o
6obj-$(CONFIG_ADT7316_SPI) += adt7316-spi.o
7obj-$(CONFIG_ADT7316_I2C) += adt7316-i2c.o
diff --git a/drivers/staging/iio/addac/adt7316-i2c.c b/drivers/staging/iio/addac/adt7316-i2c.c
new file mode 100644
index 000000000000..52d1ea349635
--- /dev/null
+++ b/drivers/staging/iio/addac/adt7316-i2c.c
@@ -0,0 +1,170 @@
1/*
2 * I2C bus driver for ADT7316/7/8 ADT7516/7/9 digital temperature
3 * sensor, ADC and DAC
4 *
5 * Copyright 2010 Analog Devices Inc.
6 *
7 * Licensed under the GPL-2 or later.
8 */
9
10#include <linux/device.h>
11#include <linux/kernel.h>
12#include <linux/i2c.h>
13#include <linux/interrupt.h>
14
15#include "adt7316.h"
16
17/*
18 * adt7316 register access by I2C
19 */
20static int adt7316_i2c_read(void *client, u8 reg, u8 *data)
21{
22 struct i2c_client *cl = client;
23 int ret = 0;
24
25 ret = i2c_smbus_write_byte(cl, reg);
26 if (ret < 0) {
27 dev_err(&cl->dev, "I2C fail to select reg\n");
28 return ret;
29 }
30
31 ret = i2c_smbus_read_byte(client);
32 if (ret < 0) {
33 dev_err(&cl->dev, "I2C read error\n");
34 return ret;
35 }
36
37 return 0;
38}
39
40static int adt7316_i2c_write(void *client, u8 reg, u8 data)
41{
42 struct i2c_client *cl = client;
43 int ret = 0;
44
45 ret = i2c_smbus_write_byte_data(cl, reg, data);
46 if (ret < 0)
47 dev_err(&cl->dev, "I2C write error\n");
48
49 return ret;
50}
51
52static int adt7316_i2c_multi_read(void *client, u8 reg, u8 count, u8 *data)
53{
54 struct i2c_client *cl = client;
55 int i, ret = 0;
56
57 if (count > ADT7316_REG_MAX_ADDR)
58 count = ADT7316_REG_MAX_ADDR;
59
60 for (i = 0; i < count; i++) {
61 ret = adt7316_i2c_read(cl, reg, &data[i]);
62 if (ret < 0) {
63 dev_err(&cl->dev, "I2C multi read error\n");
64 return ret;
65 }
66 }
67
68 return 0;
69}
70
71static int adt7316_i2c_multi_write(void *client, u8 reg, u8 count, u8 *data)
72{
73 struct i2c_client *cl = client;
74 int i, ret = 0;
75
76 if (count > ADT7316_REG_MAX_ADDR)
77 count = ADT7316_REG_MAX_ADDR;
78
79 for (i = 0; i < count; i++) {
80 ret = adt7316_i2c_write(cl, reg, data[i]);
81 if (ret < 0) {
82 dev_err(&cl->dev, "I2C multi write error\n");
83 return ret;
84 }
85 }
86
87 return 0;
88}
89
90/*
91 * device probe and remove
92 */
93
94static int __devinit adt7316_i2c_probe(struct i2c_client *client,
95 const struct i2c_device_id *id)
96{
97 struct adt7316_bus bus = {
98 .client = client,
99 .irq = client->irq,
100 .irq_flags = IRQF_TRIGGER_LOW,
101 .read = adt7316_i2c_read,
102 .write = adt7316_i2c_write,
103 .multi_read = adt7316_i2c_multi_read,
104 .multi_write = adt7316_i2c_multi_write,
105 };
106
107 return adt7316_probe(&client->dev, &bus, id->name);
108}
109
110static int __devexit adt7316_i2c_remove(struct i2c_client *client)
111{
112 return adt7316_remove(&client->dev);;
113}
114
115static const struct i2c_device_id adt7316_i2c_id[] = {
116 { "adt7316", 0 },
117 { "adt7317", 0 },
118 { "adt7318", 0 },
119 { "adt7516", 0 },
120 { "adt7517", 0 },
121 { "adt7519", 0 },
122 { }
123};
124
125MODULE_DEVICE_TABLE(i2c, adt7316_i2c_id);
126
127#ifdef CONFIG_PM
128static int adt7316_i2c_suspend(struct i2c_client *client, pm_message_t message)
129{
130 return adt7316_disable(&client->dev);
131}
132
133static int adt7316_i2c_resume(struct i2c_client *client)
134{
135 return adt7316_enable(&client->dev);
136}
137#else
138# define adt7316_i2c_suspend NULL
139# define adt7316_i2c_resume NULL
140#endif
141
142static struct i2c_driver adt7316_driver = {
143 .driver = {
144 .name = "adt7316",
145 .owner = THIS_MODULE,
146 },
147 .probe = adt7316_i2c_probe,
148 .remove = __devexit_p(adt7316_i2c_remove),
149 .suspend = adt7316_i2c_suspend,
150 .resume = adt7316_i2c_resume,
151 .id_table = adt7316_i2c_id,
152};
153
154static __init int adt7316_i2c_init(void)
155{
156 return i2c_add_driver(&adt7316_driver);
157}
158
159static __exit void adt7316_i2c_exit(void)
160{
161 i2c_del_driver(&adt7316_driver);
162}
163
164MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
165MODULE_DESCRIPTION("I2C bus driver for Analog Devices ADT7316/7/9 and"
166 "ADT7516/7/8 digital temperature sensor, ADC and DAC");
167MODULE_LICENSE("GPL v2");
168
169module_init(adt7316_i2c_init);
170module_exit(adt7316_i2c_exit);
diff --git a/drivers/staging/iio/addac/adt7316-spi.c b/drivers/staging/iio/addac/adt7316-spi.c
new file mode 100644
index 000000000000..369d4d01ed97
--- /dev/null
+++ b/drivers/staging/iio/addac/adt7316-spi.c
@@ -0,0 +1,180 @@
1/*
2 * API bus driver for ADT7316/7/8 ADT7516/7/9 digital temperature
3 * sensor, ADC and DAC
4 *
5 * Copyright 2010 Analog Devices Inc.
6 *
7 * Licensed under the GPL-2 or later.
8 */
9
10#include <linux/device.h>
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/interrupt.h>
14#include <linux/spi/spi.h>
15
16#include "adt7316.h"
17
18#define ADT7316_SPI_MAX_FREQ_HZ 5000000
19#define ADT7316_SPI_CMD_READ 0x91
20#define ADT7316_SPI_CMD_WRITE 0x90
21
22/*
23 * adt7316 register access by SPI
24 */
25
26static int adt7316_spi_multi_read(void *client, u8 reg, u8 count, u8 *data)
27{
28 struct spi_device *spi_dev = client;
29 u8 cmd[2];
30 int ret = 0;
31
32 if (count > ADT7316_REG_MAX_ADDR)
33 count = ADT7316_REG_MAX_ADDR;
34
35 cmd[0] = ADT7316_SPI_CMD_WRITE;
36 cmd[1] = reg;
37
38 ret = spi_write(spi_dev, cmd, 2);
39 if (ret < 0) {
40 dev_err(&spi_dev->dev, "SPI fail to select reg\n");
41 return ret;
42 }
43
44 cmd[0] = ADT7316_SPI_CMD_READ;
45
46 ret = spi_write_then_read(spi_dev, cmd, 1, data, count);
47 if (ret < 0) {
48 dev_err(&spi_dev->dev, "SPI read data error\n");
49 return ret;
50 }
51
52 return 0;
53}
54
55static int adt7316_spi_multi_write(void *client, u8 reg, u8 count, u8 *data)
56{
57 struct spi_device *spi_dev = client;
58 u8 buf[ADT7316_REG_MAX_ADDR + 2];
59 int i, ret = 0;
60
61 if (count > ADT7316_REG_MAX_ADDR)
62 count = ADT7316_REG_MAX_ADDR;
63
64 buf[0] = ADT7316_SPI_CMD_WRITE;
65 buf[1] = reg;
66 for (i = 0; i < count; i++)
67 buf[i + 2] = data[i];
68
69 ret = spi_write(spi_dev, buf, count + 2);
70 if (ret < 0) {
71 dev_err(&spi_dev->dev, "SPI write error\n");
72 return ret;
73 }
74
75 return ret;
76}
77
78static int adt7316_spi_read(void *client, u8 reg, u8 *data)
79{
80 return adt7316_spi_multi_read(client, reg, 1, data);
81}
82
83static int adt7316_spi_write(void *client, u8 reg, u8 val)
84{
85 return adt7316_spi_multi_write(client, reg, 1, &val);
86}
87
88/*
89 * device probe and remove
90 */
91
92static int __devinit adt7316_spi_probe(struct spi_device *spi_dev)
93{
94 struct adt7316_bus bus = {
95 .client = spi_dev,
96 .irq = spi_dev->irq,
97 .irq_flags = IRQF_TRIGGER_LOW,
98 .read = adt7316_spi_read,
99 .write = adt7316_spi_write,
100 .multi_read = adt7316_spi_multi_read,
101 .multi_write = adt7316_spi_multi_write,
102 };
103
104 /* don't exceed max specified SPI CLK frequency */
105 if (spi_dev->max_speed_hz > ADT7316_SPI_MAX_FREQ_HZ) {
106 dev_err(&spi_dev->dev, "SPI CLK %d Hz?\n",
107 spi_dev->max_speed_hz);
108 return -EINVAL;
109 }
110
111 /* switch from default I2C protocol to SPI protocol */
112 adt7316_spi_write(spi_dev, 0, 0);
113 adt7316_spi_write(spi_dev, 0, 0);
114 adt7316_spi_write(spi_dev, 0, 0);
115
116 return adt7316_probe(&spi_dev->dev, &bus, spi_dev->modalias);
117}
118
119static int __devexit adt7316_spi_remove(struct spi_device *spi_dev)
120{
121 return adt7316_remove(&spi_dev->dev);
122}
123
124static const struct spi_device_id adt7316_spi_id[] = {
125 { "adt7316", 0 },
126 { "adt7317", 0 },
127 { "adt7318", 0 },
128 { "adt7516", 0 },
129 { "adt7517", 0 },
130 { "adt7519", 0 },
131 { }
132};
133
134MODULE_DEVICE_TABLE(spi, adt7316_spi_id);
135
136#ifdef CONFIG_PM
137static int adt7316_spi_suspend(struct spi_device *spi_dev, pm_message_t message)
138{
139 return adt7316_disable(&spi_dev->dev);
140}
141
142static int adt7316_spi_resume(struct spi_device *spi_dev)
143{
144 return adt7316_enable(&spi_dev->dev);
145}
146#else
147# define adt7316_spi_suspend NULL
148# define adt7316_spi_resume NULL
149#endif
150
151static struct spi_driver adt7316_driver = {
152 .driver = {
153 .name = "adt7316",
154 .bus = &spi_bus_type,
155 .owner = THIS_MODULE,
156 },
157 .probe = adt7316_spi_probe,
158 .remove = __devexit_p(adt7316_spi_remove),
159 .suspend = adt7316_spi_suspend,
160 .resume = adt7316_spi_resume,
161 .id_table = adt7316_spi_id,
162};
163
164static __init int adt7316_spi_init(void)
165{
166 return spi_register_driver(&adt7316_driver);
167}
168
169static __exit void adt7316_spi_exit(void)
170{
171 spi_unregister_driver(&adt7316_driver);
172}
173
174MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
175MODULE_DESCRIPTION("SPI bus driver for Analog Devices ADT7316/7/8 and"
176 "ADT7516/7/9 digital temperature sensor, ADC and DAC");
177MODULE_LICENSE("GPL v2");
178
179module_init(adt7316_spi_init);
180module_exit(adt7316_spi_exit);
diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c
new file mode 100644
index 000000000000..d1b5b13629d9
--- /dev/null
+++ b/drivers/staging/iio/addac/adt7316.c
@@ -0,0 +1,2402 @@
1/*
2 * ADT7316 digital temperature sensor driver supporting ADT7316/7/8 ADT7516/7/9
3 *
4 *
5 * Copyright 2010 Analog Devices Inc.
6 *
7 * Licensed under the GPL-2 or later.
8 */
9
10#include <linux/interrupt.h>
11#include <linux/gpio.h>
12#include <linux/workqueue.h>
13#include <linux/device.h>
14#include <linux/kernel.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17#include <linux/list.h>
18#include <linux/i2c.h>
19#include <linux/rtc.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "adt7316.h"
24
25/*
26 * ADT7316 registers definition
27 */
28#define ADT7316_INT_STAT1 0x0
29#define ADT7316_INT_STAT2 0x1
30#define ADT7316_LSB_IN_TEMP_VDD 0x3
31#define ADT7316_LSB_IN_TEMP_MASK 0x3
32#define ADT7316_LSB_VDD_MASK 0xC
33#define ADT7316_LSB_VDD_OFFSET 2
34#define ADT7316_LSB_EX_TEMP_AIN 0x4
35#define ADT7316_LSB_EX_TEMP_MASK 0x3
36#define ADT7516_LSB_AIN_SHIFT 2
37#define ADT7316_AD_MSB_DATA_BASE 0x6
38#define ADT7316_AD_MSB_DATA_REGS 3
39#define ADT7516_AD_MSB_DATA_REGS 6
40#define ADT7316_MSB_VDD 0x6
41#define ADT7316_MSB_IN_TEMP 0x7
42#define ADT7316_MSB_EX_TEMP 0x8
43#define ADT7516_MSB_AIN1 0x8
44#define ADT7516_MSB_AIN2 0x9
45#define ADT7516_MSB_AIN3 0xA
46#define ADT7516_MSB_AIN4 0xB
47#define ADT7316_DA_DATA_BASE 0x10
48#define ADT7316_DA_MSB_DATA_REGS 4
49#define ADT7316_LSB_DAC_A 0x10
50#define ADT7316_MSB_DAC_A 0x11
51#define ADT7316_LSB_DAC_B 0x12
52#define ADT7316_MSB_DAC_B 0x13
53#define ADT7316_LSB_DAC_C 0x14
54#define ADT7316_MSB_DAC_C 0x15
55#define ADT7316_LSB_DAC_D 0x16
56#define ADT7316_MSB_DAC_D 0x17
57#define ADT7316_CONFIG1 0x18
58#define ADT7316_CONFIG2 0x19
59#define ADT7316_CONFIG3 0x1A
60#define ADT7316_LDAC_CONFIG 0x1B
61#define ADT7316_DAC_CONFIG 0x1C
62#define ADT7316_INT_MASK1 0x1D
63#define ADT7316_INT_MASK2 0x1E
64#define ADT7316_IN_TEMP_OFFSET 0x1F
65#define ADT7316_EX_TEMP_OFFSET 0x20
66#define ADT7316_IN_ANALOG_TEMP_OFFSET 0x21
67#define ADT7316_EX_ANALOG_TEMP_OFFSET 0x22
68#define ADT7316_VDD_HIGH 0x23
69#define ADT7316_VDD_LOW 0x24
70#define ADT7316_IN_TEMP_HIGH 0x25
71#define ADT7316_IN_TEMP_LOW 0x26
72#define ADT7316_EX_TEMP_HIGH 0x27
73#define ADT7316_EX_TEMP_LOW 0x28
74#define ADT7516_AIN2_HIGH 0x2B
75#define ADT7516_AIN2_LOW 0x2C
76#define ADT7516_AIN3_HIGH 0x2D
77#define ADT7516_AIN3_LOW 0x2E
78#define ADT7516_AIN4_HIGH 0x2F
79#define ADT7516_AIN4_LOW 0x30
80#define ADT7316_DEVICE_ID 0x4D
81#define ADT7316_MANUFACTURE_ID 0x4E
82#define ADT7316_DEVICE_REV 0x4F
83#define ADT7316_SPI_LOCK_STAT 0x7F
84
85/*
86 * ADT7316 config1
87 */
88#define ADT7316_EN 0x1
89#define ADT7516_SEL_EX_TEMP 0x4
90#define ADT7516_SEL_AIN1_2_EX_TEMP_MASK 0x6
91#define ADT7516_SEL_AIN3 0x8
92#define ADT7316_INT_EN 0x20
93#define ADT7316_INT_POLARITY 0x40
94#define ADT7316_PD 0x80
95
96/*
97 * ADT7316 config2
98 */
99#define ADT7316_AD_SINGLE_CH_MASK 0x3
100#define ADT7516_AD_SINGLE_CH_MASK 0x7
101#define ADT7316_AD_SINGLE_CH_VDD 0
102#define ADT7316_AD_SINGLE_CH_IN 1
103#define ADT7316_AD_SINGLE_CH_EX 2
104#define ADT7516_AD_SINGLE_CH_AIN1 2
105#define ADT7516_AD_SINGLE_CH_AIN2 3
106#define ADT7516_AD_SINGLE_CH_AIN3 4
107#define ADT7516_AD_SINGLE_CH_AIN4 5
108#define ADT7316_AD_SINGLE_CH_MODE 0x10
109#define ADT7316_DISABLE_AVERAGING 0x20
110#define ADT7316_EN_SMBUS_TIMEOUT 0x40
111#define ADT7316_RESET 0x80
112
113/*
114 * ADT7316 config3
115 */
116#define ADT7316_ADCLK_22_5 0x1
117#define ADT7316_DA_HIGH_RESOLUTION 0x2
118#define ADT7316_DA_EN_VIA_DAC_LDCA 0x4
119#define ADT7516_AIN_IN_VREF 0x10
120#define ADT7316_EN_IN_TEMP_PROP_DACA 0x20
121#define ADT7316_EN_EX_TEMP_PROP_DACB 0x40
122
123/*
124 * ADT7316 DAC config
125 */
126#define ADT7316_DA_2VREF_CH_MASK 0xF
127#define ADT7316_DA_EN_MODE_MASK 0x30
128#define ADT7316_DA_EN_MODE_SINGLE 0x00
129#define ADT7316_DA_EN_MODE_AB_CD 0x10
130#define ADT7316_DA_EN_MODE_ABCD 0x20
131#define ADT7316_DA_EN_MODE_LDAC 0x30
132#define ADT7316_VREF_BYPASS_DAC_AB 0x40
133#define ADT7316_VREF_BYPASS_DAC_CD 0x80
134
135/*
136 * ADT7316 LDAC config
137 */
138#define ADT7316_LDAC_EN_DA_MASK 0xF
139#define ADT7316_DAC_IN_VREF 0x10
140#define ADT7516_DAC_AB_IN_VREF 0x10
141#define ADT7516_DAC_CD_IN_VREF 0x20
142#define ADT7516_DAC_IN_VREF_OFFSET 4
143#define ADT7516_DAC_IN_VREF_MASK 0x30
144
145/*
146 * ADT7316 INT_MASK2
147 */
148#define ADT7316_INT_MASK2_VDD 0x10
149
150/*
151 * ADT7316 value masks
152 */
153#define ADT7316_VALUE_MASK 0xfff
154#define ADT7316_T_VALUE_SIGN 0x400
155#define ADT7316_T_VALUE_FLOAT_OFFSET 2
156#define ADT7316_T_VALUE_FLOAT_MASK 0x2
157
158/*
159 * Chip ID
160 */
161#define ID_ADT7316 0x1
162#define ID_ADT7317 0x2
163#define ID_ADT7318 0x3
164#define ID_ADT7516 0x11
165#define ID_ADT7517 0x12
166#define ID_ADT7519 0x14
167
168#define ID_FAMILY_MASK 0xF0
169#define ID_ADT73XX 0x0
170#define ID_ADT75XX 0x10
171
172/*
173 * struct adt7316_chip_info - chip specifc information
174 */
175
176struct adt7316_chip_info {
177 const char *name;
178 struct iio_dev *indio_dev;
179 struct work_struct thresh_work;
180 s64 last_timestamp;
181 struct adt7316_bus bus;
182 u16 ldac_pin;
183 u16 int_mask; /* 0x2f */
184 u8 config1;
185 u8 config2;
186 u8 config3;
187 u8 dac_config; /* DAC config */
188 u8 ldac_config; /* LDAC config */
189 u8 dac_bits; /* 8, 10, 12 */
190 u8 id; /* chip id */
191};
192
193/*
194 * Logic interrupt mask for user application to enable
195 * interrupts.
196 */
197#define ADT7316_IN_TEMP_HIGH_INT_MASK 0x1
198#define ADT7316_IN_TEMP_LOW_INT_MASK 0x2
199#define ADT7316_EX_TEMP_HIGH_INT_MASK 0x4
200#define ADT7316_EX_TEMP_LOW_INT_MASK 0x8
201#define ADT7316_EX_TEMP_FAULT_INT_MASK 0x10
202#define ADT7516_AIN1_INT_MASK 0x4
203#define ADT7516_AIN2_INT_MASK 0x20
204#define ADT7516_AIN3_INT_MASK 0x40
205#define ADT7516_AIN4_INT_MASK 0x80
206#define ADT7316_VDD_INT_MASK 0x100
207#define ADT7316_TEMP_INT_MASK 0x1F
208#define ADT7516_AIN_INT_MASK 0xE0
209#define ADT7316_TEMP_AIN_INT_MASK \
210 (ADT7316_TEMP_INT_MASK | ADT7316_TEMP_INT_MASK)
211
212/*
213 * struct adt7316_chip_info - chip specifc information
214 */
215
216struct adt7316_limit_regs {
217 u16 data_high;
218 u16 data_low;
219};
220
221static ssize_t adt7316_show_enabled(struct device *dev,
222 struct device_attribute *attr,
223 char *buf)
224{
225 struct iio_dev *dev_info = dev_get_drvdata(dev);
226 struct adt7316_chip_info *chip = dev_info->dev_data;
227
228 return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_EN));
229}
230
231static ssize_t _adt7316_store_enabled(struct adt7316_chip_info *chip,
232 int enable)
233{
234 u8 config1;
235 int ret;
236
237 if (enable)
238 config1 = chip->config1 | ADT7316_EN;
239 else
240 config1 = chip->config1 & ~ADT7316_EN;
241
242 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
243 if (ret)
244 return -EIO;
245
246 chip->config1 = config1;
247
248 return ret;
249
250}
251
252static ssize_t adt7316_store_enabled(struct device *dev,
253 struct device_attribute *attr,
254 const char *buf,
255 size_t len)
256{
257 struct iio_dev *dev_info = dev_get_drvdata(dev);
258 struct adt7316_chip_info *chip = dev_info->dev_data;
259 int enable;
260
261 if (!memcmp(buf, "1", 1))
262 enable = 1;
263 else
264 enable = 0;
265
266 if (_adt7316_store_enabled(chip, enable) < 0)
267 return -EIO;
268 else
269 return len;
270}
271
272static IIO_DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR,
273 adt7316_show_enabled,
274 adt7316_store_enabled,
275 0);
276
277static ssize_t adt7316_show_select_ex_temp(struct device *dev,
278 struct device_attribute *attr,
279 char *buf)
280{
281 struct iio_dev *dev_info = dev_get_drvdata(dev);
282 struct adt7316_chip_info *chip = dev_info->dev_data;
283
284 if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
285 return -EPERM;
286
287 return sprintf(buf, "%d\n", !!(chip->config1 & ADT7516_SEL_EX_TEMP));
288}
289
290static ssize_t adt7316_store_select_ex_temp(struct device *dev,
291 struct device_attribute *attr,
292 const char *buf,
293 size_t len)
294{
295 struct iio_dev *dev_info = dev_get_drvdata(dev);
296 struct adt7316_chip_info *chip = dev_info->dev_data;
297 u8 config1;
298 int ret;
299
300 if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
301 return -EPERM;
302
303 config1 = chip->config1 & (~ADT7516_SEL_EX_TEMP);
304 if (!memcmp(buf, "1", 1))
305 config1 |= ADT7516_SEL_EX_TEMP;
306
307 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
308 if (ret)
309 return -EIO;
310
311 chip->config1 = config1;
312
313 return len;
314}
315
316static IIO_DEVICE_ATTR(select_ex_temp, S_IRUGO | S_IWUSR,
317 adt7316_show_select_ex_temp,
318 adt7316_store_select_ex_temp,
319 0);
320
321static ssize_t adt7316_show_mode(struct device *dev,
322 struct device_attribute *attr,
323 char *buf)
324{
325 struct iio_dev *dev_info = dev_get_drvdata(dev);
326 struct adt7316_chip_info *chip = dev_info->dev_data;
327
328 if (chip->config2 & ADT7316_AD_SINGLE_CH_MODE)
329 return sprintf(buf, "single_channel\n");
330 else
331 return sprintf(buf, "round_robin\n");
332}
333
334static ssize_t adt7316_store_mode(struct device *dev,
335 struct device_attribute *attr,
336 const char *buf,
337 size_t len)
338{
339 struct iio_dev *dev_info = dev_get_drvdata(dev);
340 struct adt7316_chip_info *chip = dev_info->dev_data;
341 u8 config2;
342 int ret;
343
344 config2 = chip->config2 & (~ADT7316_AD_SINGLE_CH_MODE);
345 if (!memcmp(buf, "single_channel", 14))
346 config2 |= ADT7316_AD_SINGLE_CH_MODE;
347
348 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
349 if (ret)
350 return -EIO;
351
352 chip->config2 = config2;
353
354 return len;
355}
356
357static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
358 adt7316_show_mode,
359 adt7316_store_mode,
360 0);
361
362static ssize_t adt7316_show_all_modes(struct device *dev,
363 struct device_attribute *attr,
364 char *buf)
365{
366 return sprintf(buf, "single_channel\nround_robin\n");
367}
368
369static IIO_DEVICE_ATTR(all_modes, S_IRUGO, adt7316_show_all_modes, NULL, 0);
370
371static ssize_t adt7316_show_ad_channel(struct device *dev,
372 struct device_attribute *attr,
373 char *buf)
374{
375 struct iio_dev *dev_info = dev_get_drvdata(dev);
376 struct adt7316_chip_info *chip = dev_info->dev_data;
377
378 if (!(chip->config2 & ADT7316_AD_SINGLE_CH_MODE))
379 return -EPERM;
380
381 switch (chip->config2 & ADT7516_AD_SINGLE_CH_MASK) {
382 case ADT7316_AD_SINGLE_CH_VDD:
383 return sprintf(buf, "0 - VDD\n");
384 case ADT7316_AD_SINGLE_CH_IN:
385 return sprintf(buf, "1 - Internal Temperature\n");
386 case ADT7316_AD_SINGLE_CH_EX:
387 if (((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) &&
388 (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0)
389 return sprintf(buf, "2 - AIN1\n");
390 else
391 return sprintf(buf, "2 - External Temperature\n");
392 case ADT7516_AD_SINGLE_CH_AIN2:
393 if ((chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0)
394 return sprintf(buf, "3 - AIN2\n");
395 else
396 return sprintf(buf, "N/A\n");
397 case ADT7516_AD_SINGLE_CH_AIN3:
398 if (chip->config1 & ADT7516_SEL_AIN3)
399 return sprintf(buf, "4 - AIN3\n");
400 else
401 return sprintf(buf, "N/A\n");
402 case ADT7516_AD_SINGLE_CH_AIN4:
403 return sprintf(buf, "5 - AIN4\n");
404 default:
405 return sprintf(buf, "N/A\n");
406 };
407}
408
409static ssize_t adt7316_store_ad_channel(struct device *dev,
410 struct device_attribute *attr,
411 const char *buf,
412 size_t len)
413{
414 struct iio_dev *dev_info = dev_get_drvdata(dev);
415 struct adt7316_chip_info *chip = dev_info->dev_data;
416 u8 config2;
417 unsigned long data = 0;
418 int ret;
419
420 if (!(chip->config2 & ADT7316_AD_SINGLE_CH_MODE))
421 return -EPERM;
422
423 ret = strict_strtoul(buf, 10, &data);
424 if (ret)
425 return -EINVAL;
426
427 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) {
428 if (data > 5)
429 return -EINVAL;
430
431 config2 = chip->config2 & (~ADT7516_AD_SINGLE_CH_MASK);
432 } else {
433 if (data > 2)
434 return -EINVAL;
435
436 config2 = chip->config2 & (~ADT7316_AD_SINGLE_CH_MASK);
437 }
438
439
440 config2 |= data;
441
442 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
443 if (ret)
444 return -EIO;
445
446 chip->config2 = config2;
447
448 return len;
449}
450
451static IIO_DEVICE_ATTR(ad_channel, S_IRUGO | S_IWUSR,
452 adt7316_show_ad_channel,
453 adt7316_store_ad_channel,
454 0);
455
456static ssize_t adt7316_show_all_ad_channels(struct device *dev,
457 struct device_attribute *attr,
458 char *buf)
459{
460 struct iio_dev *dev_info = dev_get_drvdata(dev);
461 struct adt7316_chip_info *chip = dev_info->dev_data;
462
463 if (!(chip->config2 & ADT7316_AD_SINGLE_CH_MODE))
464 return -EPERM;
465
466 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
467 return sprintf(buf, "0 - VDD\n1 - Internal Temperature\n"
468 "2 - External Temperature or AIN2\n"
469 "3 - AIN2\n4 - AIN3\n5 - AIN4\n");
470 else
471 return sprintf(buf, "0 - VDD\n1 - Internal Temperature\n"
472 "2 - External Temperature\n");
473}
474
475static IIO_DEVICE_ATTR(all_ad_channels, S_IRUGO,
476 adt7316_show_all_ad_channels, NULL, 0);
477
478static ssize_t adt7316_show_disable_averaging(struct device *dev,
479 struct device_attribute *attr,
480 char *buf)
481{
482 struct iio_dev *dev_info = dev_get_drvdata(dev);
483 struct adt7316_chip_info *chip = dev_info->dev_data;
484
485 return sprintf(buf, "%d\n",
486 !!(chip->config2 & ADT7316_DISABLE_AVERAGING));
487}
488
489static ssize_t adt7316_store_disable_averaging(struct device *dev,
490 struct device_attribute *attr,
491 const char *buf,
492 size_t len)
493{
494 struct iio_dev *dev_info = dev_get_drvdata(dev);
495 struct adt7316_chip_info *chip = dev_info->dev_data;
496 u8 config2;
497 int ret;
498
499 config2 = chip->config2 & (~ADT7316_DISABLE_AVERAGING);
500 if (!memcmp(buf, "1", 1))
501 config2 |= ADT7316_DISABLE_AVERAGING;
502
503 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
504 if (ret)
505 return -EIO;
506
507 chip->config2 = config2;
508
509 return len;
510}
511
512static IIO_DEVICE_ATTR(disable_averaging, S_IRUGO | S_IWUSR,
513 adt7316_show_disable_averaging,
514 adt7316_store_disable_averaging,
515 0);
516
517static ssize_t adt7316_show_enable_smbus_timeout(struct device *dev,
518 struct device_attribute *attr,
519 char *buf)
520{
521 struct iio_dev *dev_info = dev_get_drvdata(dev);
522 struct adt7316_chip_info *chip = dev_info->dev_data;
523
524 return sprintf(buf, "%d\n",
525 !!(chip->config2 & ADT7316_EN_SMBUS_TIMEOUT));
526}
527
528static ssize_t adt7316_store_enable_smbus_timeout(struct device *dev,
529 struct device_attribute *attr,
530 const char *buf,
531 size_t len)
532{
533 struct iio_dev *dev_info = dev_get_drvdata(dev);
534 struct adt7316_chip_info *chip = dev_info->dev_data;
535 u8 config2;
536 int ret;
537
538 config2 = chip->config2 & (~ADT7316_EN_SMBUS_TIMEOUT);
539 if (!memcmp(buf, "1", 1))
540 config2 |= ADT7316_EN_SMBUS_TIMEOUT;
541
542 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
543 if (ret)
544 return -EIO;
545
546 chip->config2 = config2;
547
548 return len;
549}
550
551static IIO_DEVICE_ATTR(enable_smbus_timeout, S_IRUGO | S_IWUSR,
552 adt7316_show_enable_smbus_timeout,
553 adt7316_store_enable_smbus_timeout,
554 0);
555
556
557static ssize_t adt7316_store_reset(struct device *dev,
558 struct device_attribute *attr,
559 const char *buf,
560 size_t len)
561{
562 struct iio_dev *dev_info = dev_get_drvdata(dev);
563 struct adt7316_chip_info *chip = dev_info->dev_data;
564 u8 config2;
565 int ret;
566
567 config2 = chip->config2 | ADT7316_RESET;
568
569 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG2, config2);
570 if (ret)
571 return -EIO;
572
573 return len;
574}
575
576static IIO_DEVICE_ATTR(reset, S_IWUSR,
577 NULL,
578 adt7316_store_reset,
579 0);
580
581static ssize_t adt7316_show_powerdown(struct device *dev,
582 struct device_attribute *attr,
583 char *buf)
584{
585 struct iio_dev *dev_info = dev_get_drvdata(dev);
586 struct adt7316_chip_info *chip = dev_info->dev_data;
587
588 return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_PD));
589}
590
591static ssize_t adt7316_store_powerdown(struct device *dev,
592 struct device_attribute *attr,
593 const char *buf,
594 size_t len)
595{
596 struct iio_dev *dev_info = dev_get_drvdata(dev);
597 struct adt7316_chip_info *chip = dev_info->dev_data;
598 u8 config1;
599 int ret;
600
601 config1 = chip->config1 & (~ADT7316_PD);
602 if (!memcmp(buf, "1", 1))
603 config1 |= ADT7316_PD;
604
605 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
606 if (ret)
607 return -EIO;
608
609 chip->config1 = config1;
610
611 return len;
612}
613
614static IIO_DEVICE_ATTR(powerdown, S_IRUGO | S_IWUSR,
615 adt7316_show_powerdown,
616 adt7316_store_powerdown,
617 0);
618
619static ssize_t adt7316_show_fast_ad_clock(struct device *dev,
620 struct device_attribute *attr,
621 char *buf)
622{
623 struct iio_dev *dev_info = dev_get_drvdata(dev);
624 struct adt7316_chip_info *chip = dev_info->dev_data;
625
626 return sprintf(buf, "%d\n", !!(chip->config3 & ADT7316_ADCLK_22_5));
627}
628
629static ssize_t adt7316_store_fast_ad_clock(struct device *dev,
630 struct device_attribute *attr,
631 const char *buf,
632 size_t len)
633{
634 struct iio_dev *dev_info = dev_get_drvdata(dev);
635 struct adt7316_chip_info *chip = dev_info->dev_data;
636 u8 config3;
637 int ret;
638
639 config3 = chip->config3 & (~ADT7316_ADCLK_22_5);
640 if (!memcmp(buf, "1", 1))
641 config3 |= ADT7316_ADCLK_22_5;
642
643 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
644 if (ret)
645 return -EIO;
646
647 chip->config3 = config3;
648
649 return len;
650}
651
652static IIO_DEVICE_ATTR(fast_ad_clock, S_IRUGO | S_IWUSR,
653 adt7316_show_fast_ad_clock,
654 adt7316_store_fast_ad_clock,
655 0);
656
657static ssize_t adt7316_show_da_high_resolution(struct device *dev,
658 struct device_attribute *attr,
659 char *buf)
660{
661 struct iio_dev *dev_info = dev_get_drvdata(dev);
662 struct adt7316_chip_info *chip = dev_info->dev_data;
663
664 if (chip->config3 & ADT7316_DA_HIGH_RESOLUTION) {
665 if (chip->id == ID_ADT7316 || chip->id == ID_ADT7516)
666 return sprintf(buf, "1 (12 bits)\n");
667 else if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517)
668 return sprintf(buf, "1 (10 bits)\n");
669 }
670
671 return sprintf(buf, "0 (8 bits)\n");
672}
673
674static ssize_t adt7316_store_da_high_resolution(struct device *dev,
675 struct device_attribute *attr,
676 const char *buf,
677 size_t len)
678{
679 struct iio_dev *dev_info = dev_get_drvdata(dev);
680 struct adt7316_chip_info *chip = dev_info->dev_data;
681 u8 config3;
682 int ret;
683
684 chip->dac_bits = 8;
685
686 if (!memcmp(buf, "1", 1)) {
687 config3 = chip->config3 | ADT7316_DA_HIGH_RESOLUTION;
688 if (chip->id == ID_ADT7316 || chip->id == ID_ADT7516)
689 chip->dac_bits = 12;
690 else if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517)
691 chip->dac_bits = 10;
692 } else
693 config3 = chip->config3 & (~ADT7316_DA_HIGH_RESOLUTION);
694
695 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
696 if (ret)
697 return -EIO;
698
699 chip->config3 = config3;
700
701 return len;
702}
703
704static IIO_DEVICE_ATTR(da_high_resolution, S_IRUGO | S_IWUSR,
705 adt7316_show_da_high_resolution,
706 adt7316_store_da_high_resolution,
707 0);
708
709static ssize_t adt7316_show_AIN_internal_Vref(struct device *dev,
710 struct device_attribute *attr,
711 char *buf)
712{
713 struct iio_dev *dev_info = dev_get_drvdata(dev);
714 struct adt7316_chip_info *chip = dev_info->dev_data;
715
716 if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
717 return -EPERM;
718
719 return sprintf(buf, "%d\n",
720 !!(chip->config3 & ADT7516_AIN_IN_VREF));
721}
722
723static ssize_t adt7316_store_AIN_internal_Vref(struct device *dev,
724 struct device_attribute *attr,
725 const char *buf,
726 size_t len)
727{
728 struct iio_dev *dev_info = dev_get_drvdata(dev);
729 struct adt7316_chip_info *chip = dev_info->dev_data;
730 u8 config3;
731 int ret;
732
733 if ((chip->id & ID_FAMILY_MASK) != ID_ADT75XX)
734 return -EPERM;
735
736 if (memcmp(buf, "1", 1))
737 config3 = chip->config3 & (~ADT7516_AIN_IN_VREF);
738 else
739 config3 = chip->config3 | ADT7516_AIN_IN_VREF;
740
741 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
742 if (ret)
743 return -EIO;
744
745 chip->config3 = config3;
746
747 return len;
748}
749
750static IIO_DEVICE_ATTR(AIN_internal_Vref, S_IRUGO | S_IWUSR,
751 adt7316_show_AIN_internal_Vref,
752 adt7316_store_AIN_internal_Vref,
753 0);
754
755
756static ssize_t adt7316_show_enable_prop_DACA(struct device *dev,
757 struct device_attribute *attr,
758 char *buf)
759{
760 struct iio_dev *dev_info = dev_get_drvdata(dev);
761 struct adt7316_chip_info *chip = dev_info->dev_data;
762
763 return sprintf(buf, "%d\n",
764 !!(chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA));
765}
766
767static ssize_t adt7316_store_enable_prop_DACA(struct device *dev,
768 struct device_attribute *attr,
769 const char *buf,
770 size_t len)
771{
772 struct iio_dev *dev_info = dev_get_drvdata(dev);
773 struct adt7316_chip_info *chip = dev_info->dev_data;
774 u8 config3;
775 int ret;
776
777 config3 = chip->config3 & (~ADT7316_EN_IN_TEMP_PROP_DACA);
778 if (!memcmp(buf, "1", 1))
779 config3 |= ADT7316_EN_IN_TEMP_PROP_DACA;
780
781 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
782 if (ret)
783 return -EIO;
784
785 chip->config3 = config3;
786
787 return len;
788}
789
790static IIO_DEVICE_ATTR(enable_proportion_DACA, S_IRUGO | S_IWUSR,
791 adt7316_show_enable_prop_DACA,
792 adt7316_store_enable_prop_DACA,
793 0);
794
795static ssize_t adt7316_show_enable_prop_DACB(struct device *dev,
796 struct device_attribute *attr,
797 char *buf)
798{
799 struct iio_dev *dev_info = dev_get_drvdata(dev);
800 struct adt7316_chip_info *chip = dev_info->dev_data;
801
802 return sprintf(buf, "%d\n",
803 !!(chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB));
804}
805
806static ssize_t adt7316_store_enable_prop_DACB(struct device *dev,
807 struct device_attribute *attr,
808 const char *buf,
809 size_t len)
810{
811 struct iio_dev *dev_info = dev_get_drvdata(dev);
812 struct adt7316_chip_info *chip = dev_info->dev_data;
813 u8 config3;
814 int ret;
815
816 config3 = chip->config3 & (~ADT7316_EN_EX_TEMP_PROP_DACB);
817 if (!memcmp(buf, "1", 1))
818 config3 |= ADT7316_EN_EX_TEMP_PROP_DACB;
819
820 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
821 if (ret)
822 return -EIO;
823
824 chip->config3 = config3;
825
826 return len;
827}
828
829static IIO_DEVICE_ATTR(enable_proportion_DACB, S_IRUGO | S_IWUSR,
830 adt7316_show_enable_prop_DACB,
831 adt7316_store_enable_prop_DACB,
832 0);
833
834static ssize_t adt7316_show_DAC_2Vref_ch_mask(struct device *dev,
835 struct device_attribute *attr,
836 char *buf)
837{
838 struct iio_dev *dev_info = dev_get_drvdata(dev);
839 struct adt7316_chip_info *chip = dev_info->dev_data;
840
841 return sprintf(buf, "0x%x\n",
842 chip->dac_config & ADT7316_DA_2VREF_CH_MASK);
843}
844
845static ssize_t adt7316_store_DAC_2Vref_ch_mask(struct device *dev,
846 struct device_attribute *attr,
847 const char *buf,
848 size_t len)
849{
850 struct iio_dev *dev_info = dev_get_drvdata(dev);
851 struct adt7316_chip_info *chip = dev_info->dev_data;
852 u8 dac_config;
853 unsigned long data = 0;
854 int ret;
855
856 ret = strict_strtoul(buf, 16, &data);
857 if (ret || data > ADT7316_DA_2VREF_CH_MASK)
858 return -EINVAL;
859
860 dac_config = chip->dac_config & (~ADT7316_DA_2VREF_CH_MASK);
861 dac_config |= data;
862
863 ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
864 if (ret)
865 return -EIO;
866
867 chip->dac_config = dac_config;
868
869 return len;
870}
871
872static IIO_DEVICE_ATTR(DAC_2Vref_channels_mask, S_IRUGO | S_IWUSR,
873 adt7316_show_DAC_2Vref_ch_mask,
874 adt7316_store_DAC_2Vref_ch_mask,
875 0);
876
877static ssize_t adt7316_show_DAC_update_mode(struct device *dev,
878 struct device_attribute *attr,
879 char *buf)
880{
881 struct iio_dev *dev_info = dev_get_drvdata(dev);
882 struct adt7316_chip_info *chip = dev_info->dev_data;
883
884 if (!(chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA))
885 return sprintf(buf, "manual\n");
886 else {
887 switch (chip->dac_config & ADT7316_DA_EN_MODE_MASK) {
888 case ADT7316_DA_EN_MODE_SINGLE:
889 return sprintf(buf, "0 - auto at any MSB DAC writing\n");
890 case ADT7316_DA_EN_MODE_AB_CD:
891 return sprintf(buf, "1 - auto at MSB DAC AB and CD writing\n");
892 case ADT7316_DA_EN_MODE_ABCD:
893 return sprintf(buf, "2 - auto at MSB DAC ABCD writing\n");
894 default: /* ADT7316_DA_EN_MODE_LDAC */
895 return sprintf(buf, "3 - manual\n");
896 };
897 }
898}
899
900static ssize_t adt7316_store_DAC_update_mode(struct device *dev,
901 struct device_attribute *attr,
902 const char *buf,
903 size_t len)
904{
905 struct iio_dev *dev_info = dev_get_drvdata(dev);
906 struct adt7316_chip_info *chip = dev_info->dev_data;
907 u8 dac_config;
908 unsigned long data;
909 int ret;
910
911 if (!(chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA))
912 return -EPERM;
913
914 ret = strict_strtoul(buf, 10, &data);
915 if (ret || data > ADT7316_DA_EN_MODE_MASK)
916 return -EINVAL;
917
918 dac_config = chip->dac_config & (~ADT7316_DA_EN_MODE_MASK);
919 dac_config |= data;
920
921 ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
922 if (ret)
923 return -EIO;
924
925 chip->dac_config = dac_config;
926
927 return len;
928}
929
930static IIO_DEVICE_ATTR(DAC_update_mode, S_IRUGO | S_IWUSR,
931 adt7316_show_DAC_update_mode,
932 adt7316_store_DAC_update_mode,
933 0);
934
935static ssize_t adt7316_show_all_DAC_update_modes(struct device *dev,
936 struct device_attribute *attr,
937 char *buf)
938{
939 struct iio_dev *dev_info = dev_get_drvdata(dev);
940 struct adt7316_chip_info *chip = dev_info->dev_data;
941
942 if (chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA)
943 return sprintf(buf, "0 - auto at any MSB DAC writing\n"
944 "1 - auto at MSB DAC AB and CD writing\n"
945 "2 - auto at MSB DAC ABCD writing\n"
946 "3 - manual\n");
947 else
948 return sprintf(buf, "manual\n");
949}
950
951static IIO_DEVICE_ATTR(all_DAC_update_modes, S_IRUGO,
952 adt7316_show_all_DAC_update_modes, NULL, 0);
953
954
955static ssize_t adt7316_store_update_DAC(struct device *dev,
956 struct device_attribute *attr,
957 const char *buf,
958 size_t len)
959{
960 struct iio_dev *dev_info = dev_get_drvdata(dev);
961 struct adt7316_chip_info *chip = dev_info->dev_data;
962 u8 ldac_config;
963 unsigned long data;
964 int ret;
965
966 if (chip->config3 & ADT7316_DA_EN_VIA_DAC_LDCA) {
967 if ((chip->dac_config & ADT7316_DA_EN_MODE_MASK) !=
968 ADT7316_DA_EN_MODE_LDAC)
969 return -EPERM;
970
971 ret = strict_strtoul(buf, 16, &data);
972 if (ret || data > ADT7316_LDAC_EN_DA_MASK)
973 return -EINVAL;
974
975 ldac_config = chip->ldac_config & (~ADT7316_LDAC_EN_DA_MASK);
976 ldac_config |= data;
977
978 ret = chip->bus.write(chip->bus.client, ADT7316_LDAC_CONFIG,
979 ldac_config);
980 if (ret)
981 return -EIO;
982 } else {
983 gpio_set_value(chip->ldac_pin, 0);
984 gpio_set_value(chip->ldac_pin, 1);
985 }
986
987 return len;
988}
989
990static IIO_DEVICE_ATTR(update_DAC, S_IRUGO | S_IWUSR,
991 NULL,
992 adt7316_store_update_DAC,
993 0);
994
995static ssize_t adt7316_show_DA_AB_Vref_bypass(struct device *dev,
996 struct device_attribute *attr,
997 char *buf)
998{
999 struct iio_dev *dev_info = dev_get_drvdata(dev);
1000 struct adt7316_chip_info *chip = dev_info->dev_data;
1001
1002 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
1003 return -EPERM;
1004
1005 return sprintf(buf, "%d\n",
1006 !!(chip->dac_config & ADT7316_VREF_BYPASS_DAC_AB));
1007}
1008
1009static ssize_t adt7316_store_DA_AB_Vref_bypass(struct device *dev,
1010 struct device_attribute *attr,
1011 const char *buf,
1012 size_t len)
1013{
1014 struct iio_dev *dev_info = dev_get_drvdata(dev);
1015 struct adt7316_chip_info *chip = dev_info->dev_data;
1016 u8 dac_config;
1017 int ret;
1018
1019 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
1020 return -EPERM;
1021
1022 dac_config = chip->dac_config & (~ADT7316_VREF_BYPASS_DAC_AB);
1023 if (!memcmp(buf, "1", 1))
1024 dac_config |= ADT7316_VREF_BYPASS_DAC_AB;
1025
1026 ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
1027 if (ret)
1028 return -EIO;
1029
1030 chip->dac_config = dac_config;
1031
1032 return len;
1033}
1034
1035static IIO_DEVICE_ATTR(DA_AB_Vref_bypass, S_IRUGO | S_IWUSR,
1036 adt7316_show_DA_AB_Vref_bypass,
1037 adt7316_store_DA_AB_Vref_bypass,
1038 0);
1039
1040static ssize_t adt7316_show_DA_CD_Vref_bypass(struct device *dev,
1041 struct device_attribute *attr,
1042 char *buf)
1043{
1044 struct iio_dev *dev_info = dev_get_drvdata(dev);
1045 struct adt7316_chip_info *chip = dev_info->dev_data;
1046
1047 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
1048 return -EPERM;
1049
1050 return sprintf(buf, "%d\n",
1051 !!(chip->dac_config & ADT7316_VREF_BYPASS_DAC_CD));
1052}
1053
1054static ssize_t adt7316_store_DA_CD_Vref_bypass(struct device *dev,
1055 struct device_attribute *attr,
1056 const char *buf,
1057 size_t len)
1058{
1059 struct iio_dev *dev_info = dev_get_drvdata(dev);
1060 struct adt7316_chip_info *chip = dev_info->dev_data;
1061 u8 dac_config;
1062 int ret;
1063
1064 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
1065 return -EPERM;
1066
1067 dac_config = chip->dac_config & (~ADT7316_VREF_BYPASS_DAC_CD);
1068 if (!memcmp(buf, "1", 1))
1069 dac_config |= ADT7316_VREF_BYPASS_DAC_CD;
1070
1071 ret = chip->bus.write(chip->bus.client, ADT7316_DAC_CONFIG, dac_config);
1072 if (ret)
1073 return -EIO;
1074
1075 chip->dac_config = dac_config;
1076
1077 return len;
1078}
1079
1080static IIO_DEVICE_ATTR(DA_CD_Vref_bypass, S_IRUGO | S_IWUSR,
1081 adt7316_show_DA_CD_Vref_bypass,
1082 adt7316_store_DA_CD_Vref_bypass,
1083 0);
1084
1085static ssize_t adt7316_show_DAC_internal_Vref(struct device *dev,
1086 struct device_attribute *attr,
1087 char *buf)
1088{
1089 struct iio_dev *dev_info = dev_get_drvdata(dev);
1090 struct adt7316_chip_info *chip = dev_info->dev_data;
1091
1092 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
1093 return sprintf(buf, "0x%x\n",
1094 (chip->dac_config & ADT7516_DAC_IN_VREF_MASK) >>
1095 ADT7516_DAC_IN_VREF_OFFSET);
1096 else
1097 return sprintf(buf, "%d\n",
1098 !!(chip->dac_config & ADT7316_DAC_IN_VREF));
1099}
1100
1101static ssize_t adt7316_store_DAC_internal_Vref(struct device *dev,
1102 struct device_attribute *attr,
1103 const char *buf,
1104 size_t len)
1105{
1106 struct iio_dev *dev_info = dev_get_drvdata(dev);
1107 struct adt7316_chip_info *chip = dev_info->dev_data;
1108 u8 ldac_config;
1109 unsigned long data;
1110 int ret;
1111
1112 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) {
1113 ret = strict_strtoul(buf, 16, &data);
1114 if (ret || data > 3)
1115 return -EINVAL;
1116
1117 ldac_config = chip->ldac_config & (~ADT7516_DAC_IN_VREF_MASK);
1118 if (data & 0x1)
1119 ldac_config |= ADT7516_DAC_AB_IN_VREF;
1120 else if (data & 0x2)
1121 ldac_config |= ADT7516_DAC_CD_IN_VREF;
1122 } else {
1123 ret = strict_strtoul(buf, 16, &data);
1124 if (ret)
1125 return -EINVAL;
1126
1127 ldac_config = chip->ldac_config & (~ADT7316_DAC_IN_VREF);
1128 if (data)
1129 ldac_config = chip->ldac_config | ADT7316_DAC_IN_VREF;
1130 }
1131
1132 ret = chip->bus.write(chip->bus.client, ADT7316_LDAC_CONFIG, ldac_config);
1133 if (ret)
1134 return -EIO;
1135
1136 chip->ldac_config = ldac_config;
1137
1138 return len;
1139}
1140
1141static IIO_DEVICE_ATTR(DAC_internal_Vref, S_IRUGO | S_IWUSR,
1142 adt7316_show_DAC_internal_Vref,
1143 adt7316_store_DAC_internal_Vref,
1144 0);
1145
1146static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip,
1147 int channel, char *buf)
1148{
1149 u16 data;
1150 u8 msb, lsb;
1151 char sign = ' ';
1152 int ret;
1153
1154 if ((chip->config2 & ADT7316_AD_SINGLE_CH_MODE) &&
1155 channel != (chip->config2 & ADT7516_AD_SINGLE_CH_MASK))
1156 return -EPERM;
1157
1158 switch (channel) {
1159 case ADT7316_AD_SINGLE_CH_IN:
1160 ret = chip->bus.read(chip->bus.client,
1161 ADT7316_LSB_IN_TEMP_VDD, &lsb);
1162 if (ret)
1163 return -EIO;
1164
1165 ret = chip->bus.read(chip->bus.client,
1166 ADT7316_AD_MSB_DATA_BASE + channel, &msb);
1167 if (ret)
1168 return -EIO;
1169
1170 data = msb << ADT7316_T_VALUE_FLOAT_OFFSET;
1171 data |= lsb & ADT7316_LSB_IN_TEMP_MASK;
1172 break;
1173 case ADT7316_AD_SINGLE_CH_VDD:
1174 ret = chip->bus.read(chip->bus.client,
1175 ADT7316_LSB_IN_TEMP_VDD, &lsb);
1176 if (ret)
1177 return -EIO;
1178
1179 ret = chip->bus.read(chip->bus.client,
1180
1181 ADT7316_AD_MSB_DATA_BASE + channel, &msb);
1182 if (ret)
1183 return -EIO;
1184
1185 data = msb << ADT7316_T_VALUE_FLOAT_OFFSET;
1186 data |= (lsb & ADT7316_LSB_VDD_MASK) >> ADT7316_LSB_VDD_OFFSET;
1187 return sprintf(buf, "%d\n", data);
1188 default: /* ex_temp and ain */
1189 ret = chip->bus.read(chip->bus.client,
1190 ADT7316_LSB_EX_TEMP_AIN, &lsb);
1191 if (ret)
1192 return -EIO;
1193
1194 ret = chip->bus.read(chip->bus.client,
1195 ADT7316_AD_MSB_DATA_BASE + channel, &msb);
1196 if (ret)
1197 return -EIO;
1198
1199 data = msb << ADT7316_T_VALUE_FLOAT_OFFSET;
1200 data |= lsb & (ADT7316_LSB_EX_TEMP_MASK <<
1201 (ADT7516_LSB_AIN_SHIFT * (channel -
1202 (ADT7316_MSB_EX_TEMP - ADT7316_AD_MSB_DATA_BASE))));
1203
1204 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
1205 return sprintf(buf, "%d\n", data);
1206 else
1207 break;
1208 };
1209
1210 if (data & ADT7316_T_VALUE_SIGN) {
1211 /* convert supplement to positive value */
1212 data = (ADT7316_T_VALUE_SIGN << 1) - data;
1213 sign = '-';
1214 }
1215
1216 return sprintf(buf, "%c%d.%.2d\n", sign,
1217 (data >> ADT7316_T_VALUE_FLOAT_OFFSET),
1218 (data & ADT7316_T_VALUE_FLOAT_MASK) * 25);
1219}
1220
1221static ssize_t adt7316_show_VDD(struct device *dev,
1222 struct device_attribute *attr,
1223 char *buf)
1224{
1225 struct iio_dev *dev_info = dev_get_drvdata(dev);
1226 struct adt7316_chip_info *chip = dev_info->dev_data;
1227
1228 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_VDD, buf);
1229}
1230static IIO_DEVICE_ATTR(VDD, S_IRUGO, adt7316_show_VDD, NULL, 0);
1231
1232static ssize_t adt7316_show_in_temp(struct device *dev,
1233 struct device_attribute *attr,
1234 char *buf)
1235{
1236 struct iio_dev *dev_info = dev_get_drvdata(dev);
1237 struct adt7316_chip_info *chip = dev_info->dev_data;
1238
1239 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_IN, buf);
1240}
1241
1242static IIO_DEVICE_ATTR(in_temp, S_IRUGO, adt7316_show_in_temp, NULL, 0);
1243
1244static ssize_t adt7316_show_ex_temp_AIN1(struct device *dev,
1245 struct device_attribute *attr,
1246 char *buf)
1247{
1248 struct iio_dev *dev_info = dev_get_drvdata(dev);
1249 struct adt7316_chip_info *chip = dev_info->dev_data;
1250
1251 return adt7316_show_ad(chip, ADT7316_AD_SINGLE_CH_EX, buf);
1252}
1253
1254static IIO_DEVICE_ATTR(ex_temp_AIN1, S_IRUGO, adt7316_show_ex_temp_AIN1, NULL, 0);
1255static IIO_DEVICE_ATTR(ex_temp, S_IRUGO, adt7316_show_ex_temp_AIN1, NULL, 0);
1256
1257static ssize_t adt7316_show_AIN2(struct device *dev,
1258 struct device_attribute *attr,
1259 char *buf)
1260{
1261 struct iio_dev *dev_info = dev_get_drvdata(dev);
1262 struct adt7316_chip_info *chip = dev_info->dev_data;
1263
1264 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN2, buf);
1265}
1266static IIO_DEVICE_ATTR(AIN2, S_IRUGO, adt7316_show_AIN2, NULL, 0);
1267
1268static ssize_t adt7316_show_AIN3(struct device *dev,
1269 struct device_attribute *attr,
1270 char *buf)
1271{
1272 struct iio_dev *dev_info = dev_get_drvdata(dev);
1273 struct adt7316_chip_info *chip = dev_info->dev_data;
1274
1275 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN3, buf);
1276}
1277static IIO_DEVICE_ATTR(AIN3, S_IRUGO, adt7316_show_AIN3, NULL, 0);
1278
1279static ssize_t adt7316_show_AIN4(struct device *dev,
1280 struct device_attribute *attr,
1281 char *buf)
1282{
1283 struct iio_dev *dev_info = dev_get_drvdata(dev);
1284 struct adt7316_chip_info *chip = dev_info->dev_data;
1285
1286 return adt7316_show_ad(chip, ADT7516_AD_SINGLE_CH_AIN4, buf);
1287}
1288static IIO_DEVICE_ATTR(AIN4, S_IRUGO, adt7316_show_AIN4, NULL, 0);
1289
1290static ssize_t adt7316_show_temp_offset(struct adt7316_chip_info *chip,
1291 int offset_addr, char *buf)
1292{
1293 int data;
1294 u8 val;
1295 int ret;
1296
1297 ret = chip->bus.read(chip->bus.client, offset_addr, &val);
1298 if (ret)
1299 return -EIO;
1300
1301 data = (int)val;
1302 if (val & 0x80)
1303 data -= 256;
1304
1305 return sprintf(buf, "%d\n", data);
1306}
1307
1308static ssize_t adt7316_store_temp_offset(struct adt7316_chip_info *chip,
1309 int offset_addr, const char *buf, size_t len)
1310{
1311 long data;
1312 u8 val;
1313 int ret;
1314
1315 ret = strict_strtol(buf, 10, &data);
1316 if (ret || data > 127 || data < -128)
1317 return -EINVAL;
1318
1319 if (data < 0)
1320 data += 256;
1321
1322 val = (u8)data;
1323
1324 ret = chip->bus.write(chip->bus.client, offset_addr, val);
1325 if (ret)
1326 return -EIO;
1327
1328 return len;
1329}
1330
1331static ssize_t adt7316_show_in_temp_offset(struct device *dev,
1332 struct device_attribute *attr,
1333 char *buf)
1334{
1335 struct iio_dev *dev_info = dev_get_drvdata(dev);
1336 struct adt7316_chip_info *chip = dev_info->dev_data;
1337
1338 return adt7316_show_temp_offset(chip, ADT7316_IN_TEMP_OFFSET, buf);
1339}
1340
1341static ssize_t adt7316_store_in_temp_offset(struct device *dev,
1342 struct device_attribute *attr,
1343 const char *buf,
1344 size_t len)
1345{
1346 struct iio_dev *dev_info = dev_get_drvdata(dev);
1347 struct adt7316_chip_info *chip = dev_info->dev_data;
1348
1349 return adt7316_store_temp_offset(chip, ADT7316_IN_TEMP_OFFSET, buf, len);
1350}
1351
1352static IIO_DEVICE_ATTR(in_temp_offset, S_IRUGO | S_IWUSR,
1353 adt7316_show_in_temp_offset,
1354 adt7316_store_in_temp_offset, 0);
1355
1356static ssize_t adt7316_show_ex_temp_offset(struct device *dev,
1357 struct device_attribute *attr,
1358 char *buf)
1359{
1360 struct iio_dev *dev_info = dev_get_drvdata(dev);
1361 struct adt7316_chip_info *chip = dev_info->dev_data;
1362
1363 return adt7316_show_temp_offset(chip, ADT7316_EX_TEMP_OFFSET, buf);
1364}
1365
1366static ssize_t adt7316_store_ex_temp_offset(struct device *dev,
1367 struct device_attribute *attr,
1368 const char *buf,
1369 size_t len)
1370{
1371 struct iio_dev *dev_info = dev_get_drvdata(dev);
1372 struct adt7316_chip_info *chip = dev_info->dev_data;
1373
1374 return adt7316_store_temp_offset(chip, ADT7316_EX_TEMP_OFFSET, buf, len);
1375}
1376
1377static IIO_DEVICE_ATTR(ex_temp_offset, S_IRUGO | S_IWUSR,
1378 adt7316_show_ex_temp_offset,
1379 adt7316_store_ex_temp_offset, 0);
1380
1381static ssize_t adt7316_show_in_analog_temp_offset(struct device *dev,
1382 struct device_attribute *attr,
1383 char *buf)
1384{
1385 struct iio_dev *dev_info = dev_get_drvdata(dev);
1386 struct adt7316_chip_info *chip = dev_info->dev_data;
1387
1388 return adt7316_show_temp_offset(chip,
1389 ADT7316_IN_ANALOG_TEMP_OFFSET, buf);
1390}
1391
1392static ssize_t adt7316_store_in_analog_temp_offset(struct device *dev,
1393 struct device_attribute *attr,
1394 const char *buf,
1395 size_t len)
1396{
1397 struct iio_dev *dev_info = dev_get_drvdata(dev);
1398 struct adt7316_chip_info *chip = dev_info->dev_data;
1399
1400 return adt7316_store_temp_offset(chip,
1401 ADT7316_IN_ANALOG_TEMP_OFFSET, buf, len);
1402}
1403
1404static IIO_DEVICE_ATTR(in_analog_temp_offset, S_IRUGO | S_IWUSR,
1405 adt7316_show_in_analog_temp_offset,
1406 adt7316_store_in_analog_temp_offset, 0);
1407
1408static ssize_t adt7316_show_ex_analog_temp_offset(struct device *dev,
1409 struct device_attribute *attr,
1410 char *buf)
1411{
1412 struct iio_dev *dev_info = dev_get_drvdata(dev);
1413 struct adt7316_chip_info *chip = dev_info->dev_data;
1414
1415 return adt7316_show_temp_offset(chip,
1416 ADT7316_EX_ANALOG_TEMP_OFFSET, buf);
1417}
1418
1419static ssize_t adt7316_store_ex_analog_temp_offset(struct device *dev,
1420 struct device_attribute *attr,
1421 const char *buf,
1422 size_t len)
1423{
1424 struct iio_dev *dev_info = dev_get_drvdata(dev);
1425 struct adt7316_chip_info *chip = dev_info->dev_data;
1426
1427 return adt7316_store_temp_offset(chip,
1428 ADT7316_EX_ANALOG_TEMP_OFFSET, buf, len);
1429}
1430
1431static IIO_DEVICE_ATTR(ex_analog_temp_offset, S_IRUGO | S_IWUSR,
1432 adt7316_show_ex_analog_temp_offset,
1433 adt7316_store_ex_analog_temp_offset, 0);
1434
1435static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
1436 int channel, char *buf)
1437{
1438 u16 data;
1439 u8 msb, lsb, offset;
1440 int ret;
1441
1442 if (channel >= ADT7316_DA_MSB_DATA_REGS ||
1443 (channel == 0 &&
1444 (chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) ||
1445 (channel == 1 &&
1446 (chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB)))
1447 return -EPERM;
1448
1449 offset = chip->dac_bits - 8;
1450
1451 if (chip->dac_bits > 8) {
1452 ret = chip->bus.read(chip->bus.client,
1453 ADT7316_DA_DATA_BASE + channel * 2, &lsb);
1454 if (ret)
1455 return -EIO;
1456 }
1457
1458 ret = chip->bus.read(chip->bus.client,
1459 ADT7316_DA_DATA_BASE + 1 + channel * 2, &msb);
1460 if (ret)
1461 return -EIO;
1462
1463 data = (msb << offset) + (lsb & ((1 << offset) - 1));
1464
1465 return sprintf(buf, "%d\n", data);
1466}
1467
1468static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip,
1469 int channel, const char *buf, size_t len)
1470{
1471 u8 msb, lsb, offset;
1472 unsigned long data;
1473 int ret;
1474
1475 if (channel >= ADT7316_DA_MSB_DATA_REGS ||
1476 (channel == 0 &&
1477 (chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) ||
1478 (channel == 1 &&
1479 (chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB)))
1480 return -EPERM;
1481
1482 offset = chip->dac_bits - 8;
1483
1484 ret = strict_strtoul(buf, 10, &data);
1485 if (ret || data >= (1 << chip->dac_bits))
1486 return -EINVAL;
1487
1488 if (chip->dac_bits > 8) {
1489 lsb = data & (1 << offset);
1490 ret = chip->bus.write(chip->bus.client,
1491 ADT7316_DA_DATA_BASE + channel * 2, lsb);
1492 if (ret)
1493 return -EIO;
1494 }
1495
1496 msb = data >> offset;
1497 ret = chip->bus.write(chip->bus.client,
1498 ADT7316_DA_DATA_BASE + 1 + channel * 2, msb);
1499 if (ret)
1500 return -EIO;
1501
1502 return len;
1503}
1504
1505static ssize_t adt7316_show_DAC_A(struct device *dev,
1506 struct device_attribute *attr,
1507 char *buf)
1508{
1509 struct iio_dev *dev_info = dev_get_drvdata(dev);
1510 struct adt7316_chip_info *chip = dev_info->dev_data;
1511
1512 return adt7316_show_DAC(chip, 0, buf);
1513}
1514
1515static ssize_t adt7316_store_DAC_A(struct device *dev,
1516 struct device_attribute *attr,
1517 const char *buf,
1518 size_t len)
1519{
1520 struct iio_dev *dev_info = dev_get_drvdata(dev);
1521 struct adt7316_chip_info *chip = dev_info->dev_data;
1522
1523 return adt7316_store_DAC(chip, 0, buf, len);
1524}
1525
1526static IIO_DEVICE_ATTR(DAC_A, S_IRUGO | S_IWUSR, adt7316_show_DAC_A,
1527 adt7316_store_DAC_A, 0);
1528
1529static ssize_t adt7316_show_DAC_B(struct device *dev,
1530 struct device_attribute *attr,
1531 char *buf)
1532{
1533 struct iio_dev *dev_info = dev_get_drvdata(dev);
1534 struct adt7316_chip_info *chip = dev_info->dev_data;
1535
1536 return adt7316_show_DAC(chip, 1, buf);
1537}
1538
1539static ssize_t adt7316_store_DAC_B(struct device *dev,
1540 struct device_attribute *attr,
1541 const char *buf,
1542 size_t len)
1543{
1544 struct iio_dev *dev_info = dev_get_drvdata(dev);
1545 struct adt7316_chip_info *chip = dev_info->dev_data;
1546
1547 return adt7316_store_DAC(chip, 1, buf, len);
1548}
1549
1550static IIO_DEVICE_ATTR(DAC_B, S_IRUGO | S_IWUSR, adt7316_show_DAC_B,
1551 adt7316_store_DAC_B, 0);
1552
1553static ssize_t adt7316_show_DAC_C(struct device *dev,
1554 struct device_attribute *attr,
1555 char *buf)
1556{
1557 struct iio_dev *dev_info = dev_get_drvdata(dev);
1558 struct adt7316_chip_info *chip = dev_info->dev_data;
1559
1560 return adt7316_show_DAC(chip, 2, buf);
1561}
1562
1563static ssize_t adt7316_store_DAC_C(struct device *dev,
1564 struct device_attribute *attr,
1565 const char *buf,
1566 size_t len)
1567{
1568 struct iio_dev *dev_info = dev_get_drvdata(dev);
1569 struct adt7316_chip_info *chip = dev_info->dev_data;
1570
1571 return adt7316_store_DAC(chip, 2, buf, len);
1572}
1573
1574static IIO_DEVICE_ATTR(DAC_C, S_IRUGO | S_IWUSR, adt7316_show_DAC_C,
1575 adt7316_store_DAC_C, 0);
1576
1577static ssize_t adt7316_show_DAC_D(struct device *dev,
1578 struct device_attribute *attr,
1579 char *buf)
1580{
1581 struct iio_dev *dev_info = dev_get_drvdata(dev);
1582 struct adt7316_chip_info *chip = dev_info->dev_data;
1583
1584 return adt7316_show_DAC(chip, 3, buf);
1585}
1586
1587static ssize_t adt7316_store_DAC_D(struct device *dev,
1588 struct device_attribute *attr,
1589 const char *buf,
1590 size_t len)
1591{
1592 struct iio_dev *dev_info = dev_get_drvdata(dev);
1593 struct adt7316_chip_info *chip = dev_info->dev_data;
1594
1595 return adt7316_store_DAC(chip, 3, buf, len);
1596}
1597
1598static IIO_DEVICE_ATTR(DAC_D, S_IRUGO | S_IWUSR, adt7316_show_DAC_D,
1599 adt7316_store_DAC_D, 0);
1600
1601static ssize_t adt7316_show_device_id(struct device *dev,
1602 struct device_attribute *attr,
1603 char *buf)
1604{
1605 struct iio_dev *dev_info = dev_get_drvdata(dev);
1606 struct adt7316_chip_info *chip = dev_info->dev_data;
1607 u8 id;
1608 int ret;
1609
1610 ret = chip->bus.read(chip->bus.client, ADT7316_DEVICE_ID, &id);
1611 if (ret)
1612 return -EIO;
1613
1614 return sprintf(buf, "%d\n", id);
1615}
1616
1617static IIO_DEVICE_ATTR(device_id, S_IRUGO, adt7316_show_device_id, NULL, 0);
1618
1619static ssize_t adt7316_show_manufactorer_id(struct device *dev,
1620 struct device_attribute *attr,
1621 char *buf)
1622{
1623 struct iio_dev *dev_info = dev_get_drvdata(dev);
1624 struct adt7316_chip_info *chip = dev_info->dev_data;
1625 u8 id;
1626 int ret;
1627
1628 ret = chip->bus.read(chip->bus.client, ADT7316_MANUFACTURE_ID, &id);
1629 if (ret)
1630 return -EIO;
1631
1632 return sprintf(buf, "%d\n", id);
1633}
1634
1635static IIO_DEVICE_ATTR(manufactorer_id, S_IRUGO,
1636 adt7316_show_manufactorer_id, NULL, 0);
1637
1638static ssize_t adt7316_show_device_rev(struct device *dev,
1639 struct device_attribute *attr,
1640 char *buf)
1641{
1642 struct iio_dev *dev_info = dev_get_drvdata(dev);
1643 struct adt7316_chip_info *chip = dev_info->dev_data;
1644 u8 rev;
1645 int ret;
1646
1647 ret = chip->bus.read(chip->bus.client, ADT7316_DEVICE_REV, &rev);
1648 if (ret)
1649 return -EIO;
1650
1651 return sprintf(buf, "%d\n", rev);
1652}
1653
1654static IIO_DEVICE_ATTR(device_rev, S_IRUGO, adt7316_show_device_rev, NULL, 0);
1655
1656static ssize_t adt7316_show_bus_type(struct device *dev,
1657 struct device_attribute *attr,
1658 char *buf)
1659{
1660 struct iio_dev *dev_info = dev_get_drvdata(dev);
1661 struct adt7316_chip_info *chip = dev_info->dev_data;
1662 u8 stat;
1663 int ret;
1664
1665 ret = chip->bus.read(chip->bus.client, ADT7316_SPI_LOCK_STAT, &stat);
1666 if (ret)
1667 return -EIO;
1668
1669 if (stat)
1670 return sprintf(buf, "spi\n");
1671 else
1672 return sprintf(buf, "i2c\n");
1673}
1674
1675static IIO_DEVICE_ATTR(bus_type, S_IRUGO, adt7316_show_bus_type, NULL, 0);
1676
1677static ssize_t adt7316_show_name(struct device *dev,
1678 struct device_attribute *attr,
1679 char *buf)
1680{
1681 struct iio_dev *dev_info = dev_get_drvdata(dev);
1682 struct adt7316_chip_info *chip = dev_info->dev_data;
1683
1684 return sprintf(buf, "%s\n", chip->name);
1685}
1686
1687static IIO_DEVICE_ATTR(name, S_IRUGO, adt7316_show_name, NULL, 0);
1688
1689static struct attribute *adt7316_attributes[] = {
1690 &iio_dev_attr_all_modes.dev_attr.attr,
1691 &iio_dev_attr_mode.dev_attr.attr,
1692 &iio_dev_attr_reset.dev_attr.attr,
1693 &iio_dev_attr_enabled.dev_attr.attr,
1694 &iio_dev_attr_ad_channel.dev_attr.attr,
1695 &iio_dev_attr_all_ad_channels.dev_attr.attr,
1696 &iio_dev_attr_disable_averaging.dev_attr.attr,
1697 &iio_dev_attr_enable_smbus_timeout.dev_attr.attr,
1698 &iio_dev_attr_powerdown.dev_attr.attr,
1699 &iio_dev_attr_fast_ad_clock.dev_attr.attr,
1700 &iio_dev_attr_da_high_resolution.dev_attr.attr,
1701 &iio_dev_attr_enable_proportion_DACA.dev_attr.attr,
1702 &iio_dev_attr_enable_proportion_DACB.dev_attr.attr,
1703 &iio_dev_attr_DAC_2Vref_channels_mask.dev_attr.attr,
1704 &iio_dev_attr_DAC_update_mode.dev_attr.attr,
1705 &iio_dev_attr_all_DAC_update_modes.dev_attr.attr,
1706 &iio_dev_attr_update_DAC.dev_attr.attr,
1707 &iio_dev_attr_DA_AB_Vref_bypass.dev_attr.attr,
1708 &iio_dev_attr_DA_CD_Vref_bypass.dev_attr.attr,
1709 &iio_dev_attr_DAC_internal_Vref.dev_attr.attr,
1710 &iio_dev_attr_VDD.dev_attr.attr,
1711 &iio_dev_attr_in_temp.dev_attr.attr,
1712 &iio_dev_attr_ex_temp.dev_attr.attr,
1713 &iio_dev_attr_in_temp_offset.dev_attr.attr,
1714 &iio_dev_attr_ex_temp_offset.dev_attr.attr,
1715 &iio_dev_attr_in_analog_temp_offset.dev_attr.attr,
1716 &iio_dev_attr_ex_analog_temp_offset.dev_attr.attr,
1717 &iio_dev_attr_DAC_A.dev_attr.attr,
1718 &iio_dev_attr_DAC_B.dev_attr.attr,
1719 &iio_dev_attr_DAC_C.dev_attr.attr,
1720 &iio_dev_attr_DAC_D.dev_attr.attr,
1721 &iio_dev_attr_device_id.dev_attr.attr,
1722 &iio_dev_attr_manufactorer_id.dev_attr.attr,
1723 &iio_dev_attr_device_rev.dev_attr.attr,
1724 &iio_dev_attr_bus_type.dev_attr.attr,
1725 &iio_dev_attr_name.dev_attr.attr,
1726 NULL,
1727};
1728
1729static const struct attribute_group adt7316_attribute_group = {
1730 .attrs = adt7316_attributes,
1731};
1732
1733static struct attribute *adt7516_attributes[] = {
1734 &iio_dev_attr_all_modes.dev_attr.attr,
1735 &iio_dev_attr_mode.dev_attr.attr,
1736 &iio_dev_attr_select_ex_temp.dev_attr.attr,
1737 &iio_dev_attr_reset.dev_attr.attr,
1738 &iio_dev_attr_enabled.dev_attr.attr,
1739 &iio_dev_attr_ad_channel.dev_attr.attr,
1740 &iio_dev_attr_all_ad_channels.dev_attr.attr,
1741 &iio_dev_attr_disable_averaging.dev_attr.attr,
1742 &iio_dev_attr_enable_smbus_timeout.dev_attr.attr,
1743 &iio_dev_attr_powerdown.dev_attr.attr,
1744 &iio_dev_attr_fast_ad_clock.dev_attr.attr,
1745 &iio_dev_attr_AIN_internal_Vref.dev_attr.attr,
1746 &iio_dev_attr_da_high_resolution.dev_attr.attr,
1747 &iio_dev_attr_enable_proportion_DACA.dev_attr.attr,
1748 &iio_dev_attr_enable_proportion_DACB.dev_attr.attr,
1749 &iio_dev_attr_DAC_2Vref_channels_mask.dev_attr.attr,
1750 &iio_dev_attr_DAC_update_mode.dev_attr.attr,
1751 &iio_dev_attr_all_DAC_update_modes.dev_attr.attr,
1752 &iio_dev_attr_update_DAC.dev_attr.attr,
1753 &iio_dev_attr_DA_AB_Vref_bypass.dev_attr.attr,
1754 &iio_dev_attr_DA_CD_Vref_bypass.dev_attr.attr,
1755 &iio_dev_attr_DAC_internal_Vref.dev_attr.attr,
1756 &iio_dev_attr_VDD.dev_attr.attr,
1757 &iio_dev_attr_in_temp.dev_attr.attr,
1758 &iio_dev_attr_ex_temp_AIN1.dev_attr.attr,
1759 &iio_dev_attr_AIN2.dev_attr.attr,
1760 &iio_dev_attr_AIN3.dev_attr.attr,
1761 &iio_dev_attr_AIN4.dev_attr.attr,
1762 &iio_dev_attr_in_temp_offset.dev_attr.attr,
1763 &iio_dev_attr_ex_temp_offset.dev_attr.attr,
1764 &iio_dev_attr_in_analog_temp_offset.dev_attr.attr,
1765 &iio_dev_attr_ex_analog_temp_offset.dev_attr.attr,
1766 &iio_dev_attr_DAC_A.dev_attr.attr,
1767 &iio_dev_attr_DAC_B.dev_attr.attr,
1768 &iio_dev_attr_DAC_C.dev_attr.attr,
1769 &iio_dev_attr_DAC_D.dev_attr.attr,
1770 &iio_dev_attr_device_id.dev_attr.attr,
1771 &iio_dev_attr_manufactorer_id.dev_attr.attr,
1772 &iio_dev_attr_device_rev.dev_attr.attr,
1773 &iio_dev_attr_bus_type.dev_attr.attr,
1774 &iio_dev_attr_name.dev_attr.attr,
1775 NULL,
1776};
1777
1778static const struct attribute_group adt7516_attribute_group = {
1779 .attrs = adt7516_attributes,
1780};
1781
1782
1783/*
1784 * temperature bound events
1785 */
1786
1787#define IIO_EVENT_CODE_ADT7316_IN_TEMP_HIGH IIO_BUFFER_EVENT_CODE(0)
1788#define IIO_EVENT_CODE_ADT7316_IN_TEMP_LOW IIO_BUFFER_EVENT_CODE(1)
1789#define IIO_EVENT_CODE_ADT7316_EX_TEMP_HIGH IIO_BUFFER_EVENT_CODE(2)
1790#define IIO_EVENT_CODE_ADT7316_EX_TEMP_LOW IIO_BUFFER_EVENT_CODE(3)
1791#define IIO_EVENT_CODE_ADT7316_EX_TEMP_FAULT IIO_BUFFER_EVENT_CODE(4)
1792#define IIO_EVENT_CODE_ADT7516_AIN1 IIO_BUFFER_EVENT_CODE(5)
1793#define IIO_EVENT_CODE_ADT7516_AIN2 IIO_BUFFER_EVENT_CODE(6)
1794#define IIO_EVENT_CODE_ADT7516_AIN3 IIO_BUFFER_EVENT_CODE(7)
1795#define IIO_EVENT_CODE_ADT7516_AIN4 IIO_BUFFER_EVENT_CODE(8)
1796#define IIO_EVENT_CODE_ADT7316_VDD IIO_BUFFER_EVENT_CODE(9)
1797
1798static void adt7316_interrupt_bh(struct work_struct *work_s)
1799{
1800 struct adt7316_chip_info *chip =
1801 container_of(work_s, struct adt7316_chip_info, thresh_work);
1802 u8 stat1, stat2;
1803 int i, ret, count;
1804
1805 ret = chip->bus.read(chip->bus.client, ADT7316_INT_STAT1, &stat1);
1806 if (!ret) {
1807 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
1808 count = 8;
1809 else
1810 count = 5;
1811
1812 for (i = 0; i < count; i++) {
1813 if (stat1 & (1 << i))
1814 iio_push_event(chip->indio_dev, 0,
1815 IIO_EVENT_CODE_ADT7316_IN_TEMP_HIGH + i,
1816 chip->last_timestamp);
1817 }
1818 }
1819
1820 ret = chip->bus.read(chip->bus.client, ADT7316_INT_STAT2, &stat2);
1821 if (!ret) {
1822 if (stat2 & ADT7316_INT_MASK2_VDD)
1823 iio_push_event(chip->indio_dev, 0,
1824 IIO_EVENT_CODE_ADT7316_VDD,
1825 chip->last_timestamp);
1826 }
1827
1828 enable_irq(chip->bus.irq);
1829}
1830
1831static int adt7316_interrupt(struct iio_dev *dev_info,
1832 int index,
1833 s64 timestamp,
1834 int no_test)
1835{
1836 struct adt7316_chip_info *chip = dev_info->dev_data;
1837
1838 chip->last_timestamp = timestamp;
1839 schedule_work(&chip->thresh_work);
1840
1841 return 0;
1842}
1843
1844IIO_EVENT_SH(adt7316, &adt7316_interrupt);
1845
1846/*
1847 * Show mask of enabled interrupts in Hex.
1848 */
1849static ssize_t adt7316_show_int_mask(struct device *dev,
1850 struct device_attribute *attr,
1851 char *buf)
1852{
1853 struct iio_dev *dev_info = dev_get_drvdata(dev);
1854 struct adt7316_chip_info *chip = dev_info->dev_data;
1855
1856 return sprintf(buf, "0x%x\n", chip->int_mask);
1857}
1858
1859/*
1860 * Set 1 to the mask in Hex to enabled interrupts.
1861 */
1862static ssize_t adt7316_set_int_mask(struct device *dev,
1863 struct device_attribute *attr,
1864 const char *buf,
1865 size_t len)
1866{
1867 struct iio_dev *dev_info = dev_get_drvdata(dev);
1868 struct adt7316_chip_info *chip = dev_info->dev_data;
1869 unsigned long data;
1870 int ret;
1871 u8 mask;
1872
1873 ret = strict_strtoul(buf, 16, &data);
1874 if (ret || data >= ADT7316_VDD_INT_MASK + 1)
1875 return -EINVAL;
1876
1877 if (data & ADT7316_VDD_INT_MASK)
1878 mask = 0; /* enable vdd int */
1879 else
1880 mask = ADT7316_INT_MASK2_VDD; /* disable vdd int */
1881
1882 ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK2, mask);
1883 if (!ret) {
1884 chip->int_mask &= ~ADT7316_VDD_INT_MASK;
1885 chip->int_mask |= data & ADT7316_VDD_INT_MASK;
1886 }
1887
1888 if (data & ADT7316_TEMP_AIN_INT_MASK) {
1889 if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX)
1890 /* mask in reg is opposite, set 1 to disable */
1891 mask = (~data) & ADT7316_TEMP_INT_MASK;
1892 else
1893 /* mask in reg is opposite, set 1 to disable */
1894 mask = (~data) & ADT7316_TEMP_AIN_INT_MASK;
1895 }
1896 ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK1, mask);
1897
1898 chip->int_mask = mask;
1899
1900 return len;
1901}
1902static inline ssize_t adt7316_show_ad_bound(struct device *dev,
1903 struct device_attribute *attr,
1904 u8 bound_reg,
1905 char *buf)
1906{
1907 struct iio_dev *dev_info = dev_get_drvdata(dev);
1908 struct adt7316_chip_info *chip = dev_info->dev_data;
1909 u8 val;
1910 int data;
1911 int ret;
1912
1913 if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX &&
1914 bound_reg > ADT7316_EX_TEMP_LOW)
1915 return -EPERM;
1916
1917 ret = chip->bus.read(chip->bus.client, bound_reg, &val);
1918 if (ret)
1919 return -EIO;
1920
1921 data = (int)val;
1922
1923 if (!((chip->id & ID_FAMILY_MASK) == ID_ADT75XX &&
1924 (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0)) {
1925 if (data & 0x80)
1926 data -= 256;
1927 }
1928
1929 return sprintf(buf, "%d\n", data);
1930}
1931
1932static inline ssize_t adt7316_set_ad_bound(struct device *dev,
1933 struct device_attribute *attr,
1934 u8 bound_reg,
1935 const char *buf,
1936 size_t len)
1937{
1938 struct iio_dev *dev_info = dev_get_drvdata(dev);
1939 struct adt7316_chip_info *chip = dev_info->dev_data;
1940 long data;
1941 u8 val;
1942 int ret;
1943
1944 if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX &&
1945 bound_reg > ADT7316_EX_TEMP_LOW)
1946 return -EPERM;
1947
1948 ret = strict_strtol(buf, 10, &data);
1949 if (ret)
1950 return -EINVAL;
1951
1952 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX &&
1953 (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0) {
1954 if (data > 255 || data < 0)
1955 return -EINVAL;
1956 } else {
1957 if (data > 127 || data < -128)
1958 return -EINVAL;
1959
1960 if (data < 0)
1961 data += 256;
1962 }
1963
1964 val = (u8)data;
1965
1966 ret = chip->bus.write(chip->bus.client, bound_reg, val);
1967 if (ret)
1968 return -EIO;
1969
1970 return len;
1971}
1972
1973static ssize_t adt7316_show_in_temp_high(struct device *dev,
1974 struct device_attribute *attr,
1975 char *buf)
1976{
1977 return adt7316_show_ad_bound(dev, attr,
1978 ADT7316_IN_TEMP_HIGH, buf);
1979}
1980
1981static inline ssize_t adt7316_set_in_temp_high(struct device *dev,
1982 struct device_attribute *attr,
1983 const char *buf,
1984 size_t len)
1985{
1986 return adt7316_set_ad_bound(dev, attr,
1987 ADT7316_IN_TEMP_HIGH, buf, len);
1988}
1989
1990static ssize_t adt7316_show_in_temp_low(struct device *dev,
1991 struct device_attribute *attr,
1992 char *buf)
1993{
1994 return adt7316_show_ad_bound(dev, attr,
1995 ADT7316_IN_TEMP_LOW, buf);
1996}
1997
1998static inline ssize_t adt7316_set_in_temp_low(struct device *dev,
1999 struct device_attribute *attr,
2000 const char *buf,
2001 size_t len)
2002{
2003 return adt7316_set_ad_bound(dev, attr,
2004 ADT7316_IN_TEMP_LOW, buf, len);
2005}
2006
2007static ssize_t adt7316_show_ex_temp_ain1_high(struct device *dev,
2008 struct device_attribute *attr,
2009 char *buf)
2010{
2011 return adt7316_show_ad_bound(dev, attr,
2012 ADT7316_EX_TEMP_HIGH, buf);
2013}
2014
2015static inline ssize_t adt7316_set_ex_temp_ain1_high(struct device *dev,
2016 struct device_attribute *attr,
2017 const char *buf,
2018 size_t len)
2019{
2020 return adt7316_set_ad_bound(dev, attr,
2021 ADT7316_EX_TEMP_HIGH, buf, len);
2022}
2023
2024static ssize_t adt7316_show_ex_temp_ain1_low(struct device *dev,
2025 struct device_attribute *attr,
2026 char *buf)
2027{
2028 return adt7316_show_ad_bound(dev, attr,
2029 ADT7316_EX_TEMP_LOW, buf);
2030}
2031
2032static inline ssize_t adt7316_set_ex_temp_ain1_low(struct device *dev,
2033 struct device_attribute *attr,
2034 const char *buf,
2035 size_t len)
2036{
2037 return adt7316_set_ad_bound(dev, attr,
2038 ADT7316_EX_TEMP_LOW, buf, len);
2039}
2040
2041static ssize_t adt7316_show_ain2_high(struct device *dev,
2042 struct device_attribute *attr,
2043 char *buf)
2044{
2045 return adt7316_show_ad_bound(dev, attr,
2046 ADT7516_AIN2_HIGH, buf);
2047}
2048
2049static inline ssize_t adt7316_set_ain2_high(struct device *dev,
2050 struct device_attribute *attr,
2051 const char *buf,
2052 size_t len)
2053{
2054 return adt7316_set_ad_bound(dev, attr,
2055 ADT7516_AIN2_HIGH, buf, len);
2056}
2057
2058static ssize_t adt7316_show_ain2_low(struct device *dev,
2059 struct device_attribute *attr,
2060 char *buf)
2061{
2062 return adt7316_show_ad_bound(dev, attr,
2063 ADT7516_AIN2_LOW, buf);
2064}
2065
2066static inline ssize_t adt7316_set_ain2_low(struct device *dev,
2067 struct device_attribute *attr,
2068 const char *buf,
2069 size_t len)
2070{
2071 return adt7316_set_ad_bound(dev, attr,
2072 ADT7516_AIN2_LOW, buf, len);
2073}
2074
2075static ssize_t adt7316_show_ain3_high(struct device *dev,
2076 struct device_attribute *attr,
2077 char *buf)
2078{
2079 return adt7316_show_ad_bound(dev, attr,
2080 ADT7516_AIN3_HIGH, buf);
2081}
2082
2083static inline ssize_t adt7316_set_ain3_high(struct device *dev,
2084 struct device_attribute *attr,
2085 const char *buf,
2086 size_t len)
2087{
2088 return adt7316_set_ad_bound(dev, attr,
2089 ADT7516_AIN3_HIGH, buf, len);
2090}
2091
2092static ssize_t adt7316_show_ain3_low(struct device *dev,
2093 struct device_attribute *attr,
2094 char *buf)
2095{
2096 return adt7316_show_ad_bound(dev, attr,
2097 ADT7516_AIN3_LOW, buf);
2098}
2099
2100static inline ssize_t adt7316_set_ain3_low(struct device *dev,
2101 struct device_attribute *attr,
2102 const char *buf,
2103 size_t len)
2104{
2105 return adt7316_set_ad_bound(dev, attr,
2106 ADT7516_AIN3_LOW, buf, len);
2107}
2108
2109static ssize_t adt7316_show_ain4_high(struct device *dev,
2110 struct device_attribute *attr,
2111 char *buf)
2112{
2113 return adt7316_show_ad_bound(dev, attr,
2114 ADT7516_AIN4_HIGH, buf);
2115}
2116
2117static inline ssize_t adt7316_set_ain4_high(struct device *dev,
2118 struct device_attribute *attr,
2119 const char *buf,
2120 size_t len)
2121{
2122 return adt7316_set_ad_bound(dev, attr,
2123 ADT7516_AIN4_HIGH, buf, len);
2124}
2125
2126static ssize_t adt7316_show_ain4_low(struct device *dev,
2127 struct device_attribute *attr,
2128 char *buf)
2129{
2130 return adt7316_show_ad_bound(dev, attr,
2131 ADT7516_AIN4_LOW, buf);
2132}
2133
2134static inline ssize_t adt7316_set_ain4_low(struct device *dev,
2135 struct device_attribute *attr,
2136 const char *buf,
2137 size_t len)
2138{
2139 return adt7316_set_ad_bound(dev, attr,
2140 ADT7516_AIN4_LOW, buf, len);
2141}
2142
2143static ssize_t adt7316_show_int_enabled(struct device *dev,
2144 struct device_attribute *attr,
2145 char *buf)
2146{
2147 struct iio_dev *dev_info = dev_get_drvdata(dev);
2148 struct adt7316_chip_info *chip = dev_info->dev_data;
2149
2150 return sprintf(buf, "%d\n", !!(chip->config1 & ADT7316_INT_EN));
2151}
2152
2153static ssize_t adt7316_set_int_enabled(struct device *dev,
2154 struct device_attribute *attr,
2155 const char *buf,
2156 size_t len)
2157{
2158 struct iio_dev *dev_info = dev_get_drvdata(dev);
2159 struct adt7316_chip_info *chip = dev_info->dev_data;
2160 u8 config1;
2161 int ret;
2162
2163 config1 = chip->config1 & (~ADT7316_INT_EN);
2164 if (!memcmp(buf, "1", 1))
2165 config1 |= ADT7316_INT_EN;
2166
2167 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, config1);
2168 if (ret)
2169 return -EIO;
2170
2171 chip->config1 = config1;
2172
2173 return len;
2174}
2175
2176
2177IIO_EVENT_ATTR_SH(int_mask, iio_event_adt7316,
2178 adt7316_show_int_mask, adt7316_set_int_mask, 0);
2179IIO_EVENT_ATTR_SH(in_temp_high, iio_event_adt7316,
2180 adt7316_show_in_temp_high, adt7316_set_in_temp_high, 0);
2181IIO_EVENT_ATTR_SH(in_temp_low, iio_event_adt7316,
2182 adt7316_show_in_temp_low, adt7316_set_in_temp_low, 0);
2183IIO_EVENT_ATTR_SH(ex_temp_high, iio_event_adt7316,
2184 adt7316_show_ex_temp_ain1_high,
2185 adt7316_set_ex_temp_ain1_high, 0);
2186IIO_EVENT_ATTR_SH(ex_temp_low, iio_event_adt7316,
2187 adt7316_show_ex_temp_ain1_low,
2188 adt7316_set_ex_temp_ain1_low, 0);
2189IIO_EVENT_ATTR_SH(ex_temp_ain1_high, iio_event_adt7316,
2190 adt7316_show_ex_temp_ain1_high,
2191 adt7316_set_ex_temp_ain1_high, 0);
2192IIO_EVENT_ATTR_SH(ex_temp_ain1_low, iio_event_adt7316,
2193 adt7316_show_ex_temp_ain1_low,
2194 adt7316_set_ex_temp_ain1_low, 0);
2195IIO_EVENT_ATTR_SH(ain2_high, iio_event_adt7316,
2196 adt7316_show_ain2_high, adt7316_set_ain2_high, 0);
2197IIO_EVENT_ATTR_SH(ain2_low, iio_event_adt7316,
2198 adt7316_show_ain2_low, adt7316_set_ain2_low, 0);
2199IIO_EVENT_ATTR_SH(ain3_high, iio_event_adt7316,
2200 adt7316_show_ain3_high, adt7316_set_ain3_high, 0);
2201IIO_EVENT_ATTR_SH(ain3_low, iio_event_adt7316,
2202 adt7316_show_ain3_low, adt7316_set_ain3_low, 0);
2203IIO_EVENT_ATTR_SH(ain4_high, iio_event_adt7316,
2204 adt7316_show_ain4_high, adt7316_set_ain4_high, 0);
2205IIO_EVENT_ATTR_SH(ain4_low, iio_event_adt7316,
2206 adt7316_show_ain4_low, adt7316_set_ain4_low, 0);
2207IIO_EVENT_ATTR_SH(int_enabled, iio_event_adt7316,
2208 adt7316_show_int_enabled, adt7316_set_int_enabled, 0);
2209
2210static struct attribute *adt7316_event_attributes[] = {
2211 &iio_event_attr_int_mask.dev_attr.attr,
2212 &iio_event_attr_in_temp_high.dev_attr.attr,
2213 &iio_event_attr_in_temp_low.dev_attr.attr,
2214 &iio_event_attr_ex_temp_high.dev_attr.attr,
2215 &iio_event_attr_ex_temp_low.dev_attr.attr,
2216 &iio_event_attr_int_enabled.dev_attr.attr,
2217 NULL,
2218};
2219
2220static struct attribute_group adt7316_event_attribute_group = {
2221 .attrs = adt7316_event_attributes,
2222};
2223
2224static struct attribute *adt7516_event_attributes[] = {
2225 &iio_event_attr_int_mask.dev_attr.attr,
2226 &iio_event_attr_in_temp_high.dev_attr.attr,
2227 &iio_event_attr_in_temp_low.dev_attr.attr,
2228 &iio_event_attr_ex_temp_ain1_high.dev_attr.attr,
2229 &iio_event_attr_ex_temp_ain1_low.dev_attr.attr,
2230 &iio_event_attr_ain2_high.dev_attr.attr,
2231 &iio_event_attr_ain2_low.dev_attr.attr,
2232 &iio_event_attr_ain3_high.dev_attr.attr,
2233 &iio_event_attr_ain3_low.dev_attr.attr,
2234 &iio_event_attr_ain4_high.dev_attr.attr,
2235 &iio_event_attr_ain4_low.dev_attr.attr,
2236 &iio_event_attr_int_enabled.dev_attr.attr,
2237 NULL,
2238};
2239
2240static struct attribute_group adt7516_event_attribute_group = {
2241 .attrs = adt7516_event_attributes,
2242};
2243
2244#ifdef CONFIG_PM
2245int adt7316_disable(struct device *dev)
2246{
2247 struct iio_dev *dev_info = dev_get_drvdata(dev);
2248 struct adt7316_chip_info *chip = dev_info->dev_data;
2249
2250 return _adt7316_store_enabled(chip, 0);
2251}
2252EXPORT_SYMBOL(adt7316_disable);
2253
2254int adt7316_enable(struct device *dev)
2255{
2256 struct iio_dev *dev_info = dev_get_drvdata(dev);
2257 struct adt7316_chip_info *chip = dev_info->dev_data;
2258
2259 return _adt7316_store_enabled(chip, 1);
2260}
2261EXPORT_SYMBOL(adt7316_enable);
2262#endif
2263
2264/*
2265 * device probe and remove
2266 */
2267int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus,
2268 const char *name)
2269{
2270 struct adt7316_chip_info *chip;
2271 unsigned short *adt7316_platform_data = dev->platform_data;
2272 int ret = 0;
2273
2274 chip = kzalloc(sizeof(struct adt7316_chip_info), GFP_KERNEL);
2275
2276 if (chip == NULL)
2277 return -ENOMEM;
2278
2279 /* this is only used for device removal purposes */
2280 dev_set_drvdata(dev, chip);
2281
2282 chip->bus = *bus;
2283 chip->name = name;
2284
2285 if (name[4] == '3')
2286 chip->id = ID_ADT7316 + (name[6] - '6');
2287 else if (name[4] == '5')
2288 chip->id = ID_ADT7516 + (name[6] - '6');
2289 else
2290 return -ENODEV;
2291
2292 chip->ldac_pin = adt7316_platform_data[1];
2293 if (chip->ldac_pin) {
2294 chip->config3 |= ADT7316_DA_EN_VIA_DAC_LDCA;
2295 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
2296 chip->config1 |= ADT7516_SEL_AIN3;
2297 }
2298 chip->int_mask = ADT7316_TEMP_INT_MASK | ADT7316_VDD_INT_MASK;
2299 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX)
2300 chip->int_mask |= ADT7516_AIN_INT_MASK;
2301
2302 chip->indio_dev = iio_allocate_device();
2303 if (chip->indio_dev == NULL) {
2304 ret = -ENOMEM;
2305 goto error_free_chip;
2306 }
2307
2308 chip->indio_dev->dev.parent = dev;
2309 if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) {
2310 chip->indio_dev->attrs = &adt7516_attribute_group;
2311 chip->indio_dev->event_attrs = &adt7516_event_attribute_group;
2312 } else {
2313 chip->indio_dev->attrs = &adt7316_attribute_group;
2314 chip->indio_dev->event_attrs = &adt7316_event_attribute_group;
2315 }
2316 chip->indio_dev->dev_data = (void *)chip;
2317 chip->indio_dev->driver_module = THIS_MODULE;
2318 chip->indio_dev->num_interrupt_lines = 1;
2319 chip->indio_dev->modes = INDIO_DIRECT_MODE;
2320
2321 ret = iio_device_register(chip->indio_dev);
2322 if (ret)
2323 goto error_free_dev;
2324
2325 if (chip->bus.irq > 0) {
2326 if (adt7316_platform_data[0])
2327 chip->bus.irq_flags = adt7316_platform_data[0];
2328
2329 ret = iio_register_interrupt_line(chip->bus.irq,
2330 chip->indio_dev,
2331 0,
2332 chip->bus.irq_flags,
2333 chip->name);
2334 if (ret)
2335 goto error_unreg_dev;
2336
2337 /*
2338 * The event handler list element refer to iio_event_adt7316.
2339 * All event attributes bind to the same event handler.
2340 * So, only register event handler once.
2341 */
2342 iio_add_event_to_list(&iio_event_adt7316,
2343 &chip->indio_dev->interrupts[0]->ev_list);
2344
2345 INIT_WORK(&chip->thresh_work, adt7316_interrupt_bh);
2346
2347 if (chip->bus.irq_flags & IRQF_TRIGGER_HIGH)
2348 chip->config1 |= ADT7316_INT_POLARITY;
2349 }
2350
2351 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG1, chip->config1);
2352 if (ret) {
2353 ret = -EIO;
2354 goto error_unreg_irq;
2355 }
2356
2357 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, chip->config3);
2358 if (ret) {
2359 ret = -EIO;
2360 goto error_unreg_irq;
2361 }
2362
2363 dev_info(dev, "%s temperature sensor, ADC and DAC registered.\n",
2364 chip->name);
2365
2366 return 0;
2367
2368error_unreg_irq:
2369 iio_unregister_interrupt_line(chip->indio_dev, 0);
2370error_unreg_dev:
2371 iio_device_unregister(chip->indio_dev);
2372error_free_dev:
2373 iio_free_device(chip->indio_dev);
2374error_free_chip:
2375 kfree(chip);
2376
2377 return ret;
2378}
2379EXPORT_SYMBOL(adt7316_probe);
2380
2381int __devexit adt7316_remove(struct device *dev)
2382{
2383
2384 struct iio_dev *dev_info = dev_get_drvdata(dev);
2385 struct adt7316_chip_info *chip = dev_info->dev_data;
2386 struct iio_dev *indio_dev = chip->indio_dev;
2387
2388 dev_set_drvdata(dev, NULL);
2389 if (chip->bus.irq)
2390 iio_unregister_interrupt_line(indio_dev, 0);
2391 iio_device_unregister(indio_dev);
2392 iio_free_device(chip->indio_dev);
2393 kfree(chip);
2394
2395 return 0;
2396}
2397EXPORT_SYMBOL(adt7316_remove);
2398
2399MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
2400MODULE_DESCRIPTION("Analog Devices ADT7316/7/8 and ADT7516/7/9 digital"
2401 " temperature sensor, ADC and DAC driver");
2402MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/addac/adt7316.h b/drivers/staging/iio/addac/adt7316.h
new file mode 100644
index 000000000000..d34bd679bb4e
--- /dev/null
+++ b/drivers/staging/iio/addac/adt7316.h
@@ -0,0 +1,33 @@
1/*
2 * ADT7316 digital temperature sensor driver supporting ADT7316/7/8 ADT7516/7/9
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#ifndef _ADT7316_H_
10#define _ADT7316_H_
11
12#include <linux/types.h>
13
14#define ADT7316_REG_MAX_ADDR 0x3F
15
16struct adt7316_bus {
17 void *client;
18 int irq;
19 int irq_flags;
20 int (*read) (void *client, u8 reg, u8 *data);
21 int (*write) (void *client, u8 reg, u8 val);
22 int (*multi_read) (void *client, u8 first_reg, u8 count, u8 *data);
23 int (*multi_write) (void *client, u8 first_reg, u8 count, u8 *data);
24};
25
26#ifdef CONFIG_PM
27int adt7316_disable(struct device *dev);
28int adt7316_enable(struct device *dev);
29#endif
30int adt7316_probe(struct device *dev, struct adt7316_bus *bus, const char *name);
31int adt7316_remove(struct device *dev);
32
33#endif
diff --git a/drivers/staging/iio/dac/Kconfig b/drivers/staging/iio/dac/Kconfig
new file mode 100644
index 000000000000..9191bd23cc08
--- /dev/null
+++ b/drivers/staging/iio/dac/Kconfig
@@ -0,0 +1,21 @@
1#
2# DAC drivers
3#
4comment "Digital to analog convertors"
5
6config AD5624R_SPI
7 tristate "Analog Devices AD5624/44/64R DAC spi driver"
8 depends on SPI
9 help
10 Say yes here to build support for Analog Devices AD5624R, AD5644R and
11 AD5664R convertors (DAC). This driver uses the common SPI interface.
12
13config AD5446
14 tristate "Analog Devices AD5444/6, AD5620/40/60 and AD5541A/12A DAC SPI driver"
15 depends on SPI
16 help
17 Say yes here to build support for Analog Devices AD5444, AD5446,
18 AD5620, AD5640, AD5660 and AD5541A, AD5512A DACs.
19
20 To compile this driver as a module, choose M here: the
21 module will be called ad5446.
diff --git a/drivers/staging/iio/dac/Makefile b/drivers/staging/iio/dac/Makefile
new file mode 100644
index 000000000000..7cf331b4e001
--- /dev/null
+++ b/drivers/staging/iio/dac/Makefile
@@ -0,0 +1,6 @@
1#
2# Makefile for industrial I/O DAC drivers
3#
4
5obj-$(CONFIG_AD5624R_SPI) += ad5624r_spi.o
6obj-$(CONFIG_AD5446) += ad5446.o
diff --git a/drivers/staging/iio/dac/ad5446.c b/drivers/staging/iio/dac/ad5446.c
new file mode 100644
index 000000000000..e3387cd31145
--- /dev/null
+++ b/drivers/staging/iio/dac/ad5446.c
@@ -0,0 +1,323 @@
1/*
2 * AD5446 SPI DAC driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/workqueue.h>
11#include <linux/device.h>
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/sysfs.h>
15#include <linux/list.h>
16#include <linux/spi/spi.h>
17#include <linux/regulator/consumer.h>
18#include <linux/err.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22#include "dac.h"
23
24#include "ad5446.h"
25
26static void ad5446_store_sample(struct ad5446_state *st, unsigned val)
27{
28 st->data.d16 = cpu_to_be16(AD5446_LOAD |
29 (val << st->chip_info->left_shift));
30}
31
32static void ad5542_store_sample(struct ad5446_state *st, unsigned val)
33{
34 st->data.d16 = cpu_to_be16(val << st->chip_info->left_shift);
35}
36
37static void ad5620_store_sample(struct ad5446_state *st, unsigned val)
38{
39 st->data.d16 = cpu_to_be16(AD5620_LOAD |
40 (val << st->chip_info->left_shift));
41}
42
43static void ad5660_store_sample(struct ad5446_state *st, unsigned val)
44{
45 val |= AD5660_LOAD;
46 st->data.d24[0] = (val >> 16) & 0xFF;
47 st->data.d24[1] = (val >> 8) & 0xFF;
48 st->data.d24[2] = val & 0xFF;
49}
50
51static ssize_t ad5446_write(struct device *dev,
52 struct device_attribute *attr,
53 const char *buf,
54 size_t len)
55{
56 struct iio_dev *dev_info = dev_get_drvdata(dev);
57 struct ad5446_state *st = dev_info->dev_data;
58 int ret;
59 long val;
60
61 ret = strict_strtol(buf, 10, &val);
62 if (ret)
63 goto error_ret;
64
65 if (val > RES_MASK(st->chip_info->bits)) {
66 ret = -EINVAL;
67 goto error_ret;
68 }
69
70 mutex_lock(&dev_info->mlock);
71 st->chip_info->store_sample(st, val);
72 ret = spi_sync(st->spi, &st->msg);
73 mutex_unlock(&dev_info->mlock);
74
75error_ret:
76 return ret ? ret : len;
77}
78
79static IIO_DEV_ATTR_OUT_RAW(0, ad5446_write, 0);
80
81static ssize_t ad5446_show_scale(struct device *dev,
82 struct device_attribute *attr,
83 char *buf)
84{
85 struct iio_dev *dev_info = dev_get_drvdata(dev);
86 struct ad5446_state *st = iio_dev_get_devdata(dev_info);
87 /* Corresponds to Vref / 2^(bits) */
88 unsigned int scale_uv = (st->vref_mv * 1000) >> st->chip_info->bits;
89
90 return sprintf(buf, "%d.%d\n", scale_uv / 1000, scale_uv % 1000);
91}
92static IIO_DEVICE_ATTR(out_scale, S_IRUGO, ad5446_show_scale, NULL, 0);
93
94static ssize_t ad5446_show_name(struct device *dev,
95 struct device_attribute *attr,
96 char *buf)
97{
98 struct iio_dev *dev_info = dev_get_drvdata(dev);
99 struct ad5446_state *st = iio_dev_get_devdata(dev_info);
100
101 return sprintf(buf, "%s\n", spi_get_device_id(st->spi)->name);
102}
103static IIO_DEVICE_ATTR(name, S_IRUGO, ad5446_show_name, NULL, 0);
104
105static struct attribute *ad5446_attributes[] = {
106 &iio_dev_attr_out0_raw.dev_attr.attr,
107 &iio_dev_attr_out_scale.dev_attr.attr,
108 &iio_dev_attr_name.dev_attr.attr,
109 NULL,
110};
111
112static const struct attribute_group ad5446_attribute_group = {
113 .attrs = ad5446_attributes,
114};
115
116static const struct ad5446_chip_info ad5446_chip_info_tbl[] = {
117 [ID_AD5444] = {
118 .bits = 12,
119 .storagebits = 16,
120 .left_shift = 2,
121 .store_sample = ad5446_store_sample,
122 },
123 [ID_AD5446] = {
124 .bits = 14,
125 .storagebits = 16,
126 .left_shift = 0,
127 .store_sample = ad5446_store_sample,
128 },
129 [ID_AD5542A] = {
130 .bits = 16,
131 .storagebits = 16,
132 .left_shift = 0,
133 .store_sample = ad5542_store_sample,
134 },
135 [ID_AD5512A] = {
136 .bits = 12,
137 .storagebits = 16,
138 .left_shift = 4,
139 .store_sample = ad5542_store_sample,
140 },
141 [ID_AD5620_2500] = {
142 .bits = 12,
143 .storagebits = 16,
144 .left_shift = 2,
145 .int_vref_mv = 2500,
146 .store_sample = ad5620_store_sample,
147 },
148 [ID_AD5620_1250] = {
149 .bits = 12,
150 .storagebits = 16,
151 .left_shift = 2,
152 .int_vref_mv = 1250,
153 .store_sample = ad5620_store_sample,
154 },
155 [ID_AD5640_2500] = {
156 .bits = 14,
157 .storagebits = 16,
158 .left_shift = 0,
159 .int_vref_mv = 2500,
160 .store_sample = ad5620_store_sample,
161 },
162 [ID_AD5640_1250] = {
163 .bits = 14,
164 .storagebits = 16,
165 .left_shift = 0,
166 .int_vref_mv = 1250,
167 .store_sample = ad5620_store_sample,
168 },
169 [ID_AD5660_2500] = {
170 .bits = 16,
171 .storagebits = 24,
172 .left_shift = 0,
173 .int_vref_mv = 2500,
174 .store_sample = ad5660_store_sample,
175 },
176 [ID_AD5660_1250] = {
177 .bits = 16,
178 .storagebits = 24,
179 .left_shift = 0,
180 .int_vref_mv = 1250,
181 .store_sample = ad5660_store_sample,
182 },
183};
184
185static int __devinit ad5446_probe(struct spi_device *spi)
186{
187 struct ad5446_state *st;
188 int ret, voltage_uv = 0;
189
190 st = kzalloc(sizeof(*st), GFP_KERNEL);
191 if (st == NULL) {
192 ret = -ENOMEM;
193 goto error_ret;
194 }
195
196 st->reg = regulator_get(&spi->dev, "vcc");
197 if (!IS_ERR(st->reg)) {
198 ret = regulator_enable(st->reg);
199 if (ret)
200 goto error_put_reg;
201
202 voltage_uv = regulator_get_voltage(st->reg);
203 }
204
205 st->chip_info =
206 &ad5446_chip_info_tbl[spi_get_device_id(spi)->driver_data];
207
208 spi_set_drvdata(spi, st);
209
210 st->spi = spi;
211
212 st->indio_dev = iio_allocate_device();
213 if (st->indio_dev == NULL) {
214 ret = -ENOMEM;
215 goto error_disable_reg;
216 }
217
218 /* Estabilish that the iio_dev is a child of the spi device */
219 st->indio_dev->dev.parent = &spi->dev;
220 st->indio_dev->attrs = &ad5446_attribute_group;
221 st->indio_dev->dev_data = (void *)(st);
222 st->indio_dev->driver_module = THIS_MODULE;
223 st->indio_dev->modes = INDIO_DIRECT_MODE;
224
225 /* Setup default message */
226
227 st->xfer.tx_buf = &st->data;
228 st->xfer.len = st->chip_info->storagebits / 8;
229
230 spi_message_init(&st->msg);
231 spi_message_add_tail(&st->xfer, &st->msg);
232
233 switch (spi_get_device_id(spi)->driver_data) {
234 case ID_AD5620_2500:
235 case ID_AD5620_1250:
236 case ID_AD5640_2500:
237 case ID_AD5640_1250:
238 case ID_AD5660_2500:
239 case ID_AD5660_1250:
240 st->vref_mv = st->chip_info->int_vref_mv;
241 break;
242 default:
243 if (voltage_uv)
244 st->vref_mv = voltage_uv / 1000;
245 else
246 dev_warn(&spi->dev,
247 "reference voltage unspecified\n");
248 }
249
250 ret = iio_device_register(st->indio_dev);
251 if (ret)
252 goto error_free_device;
253
254 return 0;
255
256error_free_device:
257 iio_free_device(st->indio_dev);
258error_disable_reg:
259 if (!IS_ERR(st->reg))
260 regulator_disable(st->reg);
261error_put_reg:
262 if (!IS_ERR(st->reg))
263 regulator_put(st->reg);
264 kfree(st);
265error_ret:
266 return ret;
267}
268
269static int ad5446_remove(struct spi_device *spi)
270{
271 struct ad5446_state *st = spi_get_drvdata(spi);
272 struct iio_dev *indio_dev = st->indio_dev;
273
274 iio_device_unregister(indio_dev);
275 if (!IS_ERR(st->reg)) {
276 regulator_disable(st->reg);
277 regulator_put(st->reg);
278 }
279 kfree(st);
280 return 0;
281}
282
283static const struct spi_device_id ad5446_id[] = {
284 {"ad5444", ID_AD5444},
285 {"ad5446", ID_AD5446},
286 {"ad5542a", ID_AD5542A},
287 {"ad5512a", ID_AD5512A},
288 {"ad5620-2500", ID_AD5620_2500}, /* AD5620/40/60: */
289 {"ad5620-1250", ID_AD5620_1250}, /* part numbers may look differently */
290 {"ad5640-2500", ID_AD5640_2500},
291 {"ad5640-1250", ID_AD5640_1250},
292 {"ad5660-2500", ID_AD5660_2500},
293 {"ad5660-1250", ID_AD5660_1250},
294 {}
295};
296
297static struct spi_driver ad5446_driver = {
298 .driver = {
299 .name = "ad5446",
300 .bus = &spi_bus_type,
301 .owner = THIS_MODULE,
302 },
303 .probe = ad5446_probe,
304 .remove = __devexit_p(ad5446_remove),
305 .id_table = ad5446_id,
306};
307
308static int __init ad5446_init(void)
309{
310 return spi_register_driver(&ad5446_driver);
311}
312module_init(ad5446_init);
313
314static void __exit ad5446_exit(void)
315{
316 spi_unregister_driver(&ad5446_driver);
317}
318module_exit(ad5446_exit);
319
320MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
321MODULE_DESCRIPTION("Analog Devices AD5444/AD5446 DAC");
322MODULE_LICENSE("GPL v2");
323MODULE_ALIAS("spi:ad5446");
diff --git a/drivers/staging/iio/dac/ad5446.h b/drivers/staging/iio/dac/ad5446.h
new file mode 100644
index 000000000000..902542e22c4a
--- /dev/null
+++ b/drivers/staging/iio/dac/ad5446.h
@@ -0,0 +1,96 @@
1/*
2 * AD5446 SPI DAC driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8#ifndef IIO_DAC_AD5446_H_
9#define IIO_DAC_AD5446_H_
10
11/* DAC Control Bits */
12
13#define AD5446_LOAD (0x0 << 14) /* Load and update */
14#define AD5446_SDO_DIS (0x1 << 14) /* Disable SDO */
15#define AD5446_NOP (0x2 << 14) /* No operation */
16#define AD5446_CLK_RISING (0x3 << 14) /* Clock data on rising edge */
17
18#define AD5620_LOAD (0x0 << 14) /* Load and update Norm Operation*/
19#define AD5620_PWRDWN_1k (0x1 << 14) /* Power-down: 1kOhm to GND */
20#define AD5620_PWRDWN_100k (0x2 << 14) /* Power-down: 100kOhm to GND */
21#define AD5620_PWRDWN_TRISTATE (0x3 << 14) /* Power-down: Three-state */
22
23#define AD5660_LOAD (0x0 << 16) /* Load and update Norm Operation*/
24#define AD5660_PWRDWN_1k (0x1 << 16) /* Power-down: 1kOhm to GND */
25#define AD5660_PWRDWN_100k (0x2 << 16) /* Power-down: 100kOhm to GND */
26#define AD5660_PWRDWN_TRISTATE (0x3 << 16) /* Power-down: Three-state */
27
28#define RES_MASK(bits) ((1 << (bits)) - 1)
29
30/**
31 * struct ad5446_state - driver instance specific data
32 * @indio_dev: the industrial I/O device
33 * @spi: spi_device
34 * @chip_info: chip model specific constants, available modes etc
35 * @reg: supply regulator
36 * @poll_work: bottom half of polling interrupt handler
37 * @vref_mv: actual reference voltage used
38 * @xfer: default spi transfer
39 * @msg: default spi message
40 * @data: spi transmit buffer
41 */
42
43struct ad5446_state {
44 struct iio_dev *indio_dev;
45 struct spi_device *spi;
46 const struct ad5446_chip_info *chip_info;
47 struct regulator *reg;
48 struct work_struct poll_work;
49 unsigned short vref_mv;
50 struct spi_transfer xfer;
51 struct spi_message msg;
52 union {
53 unsigned short d16;
54 unsigned char d24[3];
55 } data;
56};
57
58/**
59 * struct ad5446_chip_info - chip specific information
60 * @bits: accuracy of the DAC in bits
61 * @storagebits: number of bits written to the DAC
62 * @left_shift: number of bits the datum must be shifted
63 * @int_vref_mv: AD5620/40/60: the internal reference voltage
64 * @store_sample: chip specific helper function to store the datum
65 */
66
67struct ad5446_chip_info {
68 u8 bits;
69 u8 storagebits;
70 u8 left_shift;
71 u16 int_vref_mv;
72 void (*store_sample) (struct ad5446_state *st, unsigned val);
73};
74
75/**
76 * ad5446_supported_device_ids:
77 * The AD5620/40/60 parts are available in different fixed internal reference
78 * voltage options. The actual part numbers may look differently
79 * (and a bit cryptic), however this style is used to make clear which
80 * parts are supported here.
81 */
82
83enum ad5446_supported_device_ids {
84 ID_AD5444,
85 ID_AD5446,
86 ID_AD5542A,
87 ID_AD5512A,
88 ID_AD5620_2500,
89 ID_AD5620_1250,
90 ID_AD5640_2500,
91 ID_AD5640_1250,
92 ID_AD5660_2500,
93 ID_AD5660_1250,
94};
95
96#endif /* IIO_DAC_AD5446_H_ */
diff --git a/drivers/staging/iio/dac/ad5624r.h b/drivers/staging/iio/dac/ad5624r.h
new file mode 100644
index 000000000000..ce518be652b7
--- /dev/null
+++ b/drivers/staging/iio/dac/ad5624r.h
@@ -0,0 +1,21 @@
1#ifndef SPI_AD5624R_H_
2#define SPI_AD5624R_H_
3
4#define AD5624R_DAC_CHANNELS 4
5
6#define AD5624R_ADDR_DAC0 0x0
7#define AD5624R_ADDR_DAC1 0x1
8#define AD5624R_ADDR_DAC2 0x2
9#define AD5624R_ADDR_DAC3 0x3
10#define AD5624R_ADDR_ALL_DAC 0x7
11
12#define AD5624R_CMD_WRITE_INPUT_N 0x0
13#define AD5624R_CMD_UPDATE_DAC_N 0x1
14#define AD5624R_CMD_WRITE_INPUT_N_UPDATE_ALL 0x2
15#define AD5624R_CMD_WRITE_INPUT_N_UPDATE_N 0x3
16#define AD5624R_CMD_POWERDOWN_DAC 0x4
17#define AD5624R_CMD_RESET 0x5
18#define AD5624R_CMD_LDAC_SETUP 0x6
19#define AD5624R_CMD_INTERNAL_REFER_SETUP 0x7
20
21#endif
diff --git a/drivers/staging/iio/dac/ad5624r_spi.c b/drivers/staging/iio/dac/ad5624r_spi.c
new file mode 100644
index 000000000000..2b1c6dde4fdd
--- /dev/null
+++ b/drivers/staging/iio/dac/ad5624r_spi.c
@@ -0,0 +1,300 @@
1/*
2 * AD5624R, AD5644R, AD5664R Digital to analog convertors spi driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/gpio.h>
11#include <linux/fs.h>
12#include <linux/device.h>
13#include <linux/kernel.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17#include <linux/delay.h>
18
19#include "../iio.h"
20#include "../sysfs.h"
21#include "dac.h"
22#include "ad5624r.h"
23
24/**
25 * struct ad5624r_state - device related storage
26 * @indio_dev: associated industrial IO device
27 * @us: spi device
28 **/
29struct ad5624r_state {
30 struct iio_dev *indio_dev;
31 struct spi_device *us;
32 int data_len;
33 int ldac_mode;
34 int dac_power_mode[AD5624R_DAC_CHANNELS];
35 int internal_ref;
36};
37
38static int ad5624r_spi_write(struct spi_device *spi,
39 u8 cmd, u8 addr, u16 val, u8 len)
40{
41 u32 data;
42 u8 msg[3];
43
44 /*
45 * The input shift register is 24 bits wide. The first two bits are don't care bits.
46 * The next three are the command bits, C2 to C0, followed by the 3-bit DAC address,
47 * A2 to A0, and then the 16-, 14-, 12-bit data-word. The data-word comprises the 16-,
48 * 14-, 12-bit input code followed by 0, 2, or 4 don't care bits, for the AD5664R,
49 * AD5644R, and AD5624R, respectively.
50 */
51 data = (0 << 22) | (cmd << 19) | (addr << 16) | (val << (16 - len));
52 msg[0] = data >> 16;
53 msg[1] = data >> 8;
54 msg[2] = data;
55
56 return spi_write(spi, msg, 3);
57}
58
59static ssize_t ad5624r_write_dac(struct device *dev,
60 struct device_attribute *attr,
61 const char *buf, size_t len)
62{
63 long readin;
64 int ret;
65 struct iio_dev *indio_dev = dev_get_drvdata(dev);
66 struct ad5624r_state *st = indio_dev->dev_data;
67 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
68
69 ret = strict_strtol(buf, 10, &readin);
70 if (ret)
71 return ret;
72
73 ret = ad5624r_spi_write(st->us, AD5624R_CMD_WRITE_INPUT_N_UPDATE_N,
74 this_attr->address, readin, st->data_len);
75 return ret ? ret : len;
76}
77
78static ssize_t ad5624r_read_ldac_mode(struct device *dev,
79 struct device_attribute *attr, char *buf)
80{
81 struct iio_dev *indio_dev = dev_get_drvdata(dev);
82 struct ad5624r_state *st = indio_dev->dev_data;
83
84 return sprintf(buf, "%x\n", st->ldac_mode);
85}
86
87static ssize_t ad5624r_write_ldac_mode(struct device *dev,
88 struct device_attribute *attr,
89 const char *buf, size_t len)
90{
91 long readin;
92 int ret;
93 struct iio_dev *indio_dev = dev_get_drvdata(dev);
94 struct ad5624r_state *st = indio_dev->dev_data;
95
96 ret = strict_strtol(buf, 16, &readin);
97 if (ret)
98 return ret;
99
100 ret = ad5624r_spi_write(st->us, AD5624R_CMD_LDAC_SETUP, 0,
101 readin & 0xF, 16);
102 st->ldac_mode = readin & 0xF;
103
104 return ret ? ret : len;
105}
106
107static ssize_t ad5624r_read_dac_power_mode(struct device *dev,
108 struct device_attribute *attr,
109 char *buf)
110{
111 struct iio_dev *indio_dev = dev_get_drvdata(dev);
112 struct ad5624r_state *st = indio_dev->dev_data;
113 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
114
115 return sprintf(buf, "%d\n", st->dac_power_mode[this_attr->address]);
116}
117
118static ssize_t ad5624r_write_dac_power_mode(struct device *dev,
119 struct device_attribute *attr,
120 const char *buf, size_t len)
121{
122 long readin;
123 int ret;
124 struct iio_dev *indio_dev = dev_get_drvdata(dev);
125 struct ad5624r_state *st = indio_dev->dev_data;
126 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
127
128 ret = strict_strtol(buf, 10, &readin);
129 if (ret)
130 return ret;
131
132 ret = ad5624r_spi_write(st->us, AD5624R_CMD_POWERDOWN_DAC, 0,
133 ((readin & 0x3) << 4) |
134 (1 << this_attr->address), 16);
135
136 st->dac_power_mode[this_attr->address] = readin & 0x3;
137
138 return ret ? ret : len;
139}
140
141static ssize_t ad5624r_read_internal_ref_mode(struct device *dev,
142 struct device_attribute *attr,
143 char *buf)
144{
145 struct iio_dev *indio_dev = dev_get_drvdata(dev);
146 struct ad5624r_state *st = indio_dev->dev_data;
147
148 return sprintf(buf, "%d\n", st->internal_ref);
149}
150
151static ssize_t ad5624r_write_internal_ref_mode(struct device *dev,
152 struct device_attribute *attr,
153 const char *buf, size_t len)
154{
155 long readin;
156 int ret;
157 struct iio_dev *indio_dev = dev_get_drvdata(dev);
158 struct ad5624r_state *st = indio_dev->dev_data;
159
160 ret = strict_strtol(buf, 10, &readin);
161 if (ret)
162 return ret;
163
164 ret = ad5624r_spi_write(st->us, AD5624R_CMD_INTERNAL_REFER_SETUP, 0,
165 !!readin, 16);
166
167 st->internal_ref = !!readin;
168
169 return ret ? ret : len;
170}
171
172static IIO_DEV_ATTR_OUT_RAW(0, ad5624r_write_dac, AD5624R_ADDR_DAC0);
173static IIO_DEV_ATTR_OUT_RAW(1, ad5624r_write_dac, AD5624R_ADDR_DAC1);
174static IIO_DEV_ATTR_OUT_RAW(2, ad5624r_write_dac, AD5624R_ADDR_DAC2);
175static IIO_DEV_ATTR_OUT_RAW(3, ad5624r_write_dac, AD5624R_ADDR_DAC3);
176
177static IIO_DEVICE_ATTR(ldac_mode, S_IRUGO | S_IWUSR, ad5624r_read_ldac_mode,
178 ad5624r_write_ldac_mode, 0);
179static IIO_DEVICE_ATTR(internal_ref, S_IRUGO | S_IWUSR,
180 ad5624r_read_internal_ref_mode,
181 ad5624r_write_internal_ref_mode, 0);
182
183#define IIO_DEV_ATTR_DAC_POWER_MODE(_num, _show, _store, _addr) \
184 IIO_DEVICE_ATTR(dac_power_mode_##_num, S_IRUGO | S_IWUSR, _show, _store, _addr)
185
186static IIO_DEV_ATTR_DAC_POWER_MODE(0, ad5624r_read_dac_power_mode,
187 ad5624r_write_dac_power_mode, 0);
188static IIO_DEV_ATTR_DAC_POWER_MODE(1, ad5624r_read_dac_power_mode,
189 ad5624r_write_dac_power_mode, 1);
190static IIO_DEV_ATTR_DAC_POWER_MODE(2, ad5624r_read_dac_power_mode,
191 ad5624r_write_dac_power_mode, 2);
192static IIO_DEV_ATTR_DAC_POWER_MODE(3, ad5624r_read_dac_power_mode,
193 ad5624r_write_dac_power_mode, 3);
194
195static struct attribute *ad5624r_attributes[] = {
196 &iio_dev_attr_out0_raw.dev_attr.attr,
197 &iio_dev_attr_out1_raw.dev_attr.attr,
198 &iio_dev_attr_out2_raw.dev_attr.attr,
199 &iio_dev_attr_out3_raw.dev_attr.attr,
200 &iio_dev_attr_dac_power_mode_0.dev_attr.attr,
201 &iio_dev_attr_dac_power_mode_1.dev_attr.attr,
202 &iio_dev_attr_dac_power_mode_2.dev_attr.attr,
203 &iio_dev_attr_dac_power_mode_3.dev_attr.attr,
204 &iio_dev_attr_ldac_mode.dev_attr.attr,
205 &iio_dev_attr_internal_ref.dev_attr.attr,
206 NULL,
207};
208
209static const struct attribute_group ad5624r_attribute_group = {
210 .attrs = ad5624r_attributes,
211};
212
213static int __devinit ad5624r_probe(struct spi_device *spi)
214{
215 struct ad5624r_state *st;
216 int ret = 0;
217
218 st = kzalloc(sizeof(*st), GFP_KERNEL);
219 if (st == NULL) {
220 ret = -ENOMEM;
221 goto error_ret;
222 }
223 spi_set_drvdata(spi, st);
224
225 st->data_len = spi_get_device_id(spi)->driver_data;
226
227 st->us = spi;
228 st->indio_dev = iio_allocate_device();
229 if (st->indio_dev == NULL) {
230 ret = -ENOMEM;
231 goto error_free_st;
232 }
233 st->indio_dev->dev.parent = &spi->dev;
234 st->indio_dev->num_interrupt_lines = 0;
235 st->indio_dev->event_attrs = NULL;
236
237 st->indio_dev->attrs = &ad5624r_attribute_group;
238 st->indio_dev->dev_data = (void *)(st);
239 st->indio_dev->driver_module = THIS_MODULE;
240 st->indio_dev->modes = INDIO_DIRECT_MODE;
241
242 ret = iio_device_register(st->indio_dev);
243 if (ret)
244 goto error_free_dev;
245
246 spi->mode = SPI_MODE_0;
247 spi_setup(spi);
248
249 return 0;
250
251error_free_dev:
252 iio_free_device(st->indio_dev);
253error_free_st:
254 kfree(st);
255error_ret:
256 return ret;
257}
258
259static int __devexit ad5624r_remove(struct spi_device *spi)
260{
261 struct ad5624r_state *st = spi_get_drvdata(spi);
262
263 iio_device_unregister(st->indio_dev);
264 kfree(st);
265
266 return 0;
267}
268
269static const struct spi_device_id ad5624r_id[] = {
270 {"ad5624r", 12},
271 {"ad5644r", 14},
272 {"ad5664r", 16},
273 {}
274};
275
276static struct spi_driver ad5624r_driver = {
277 .driver = {
278 .name = "ad5624r",
279 .owner = THIS_MODULE,
280 },
281 .probe = ad5624r_probe,
282 .remove = __devexit_p(ad5624r_remove),
283 .id_table = ad5624r_id,
284};
285
286static __init int ad5624r_spi_init(void)
287{
288 return spi_register_driver(&ad5624r_driver);
289}
290module_init(ad5624r_spi_init);
291
292static __exit void ad5624r_spi_exit(void)
293{
294 spi_unregister_driver(&ad5624r_driver);
295}
296module_exit(ad5624r_spi_exit);
297
298MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
299MODULE_DESCRIPTION("Analog Devices AD5624/44/64R DAC spi driver");
300MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/dac/dac.h b/drivers/staging/iio/dac/dac.h
new file mode 100644
index 000000000000..1d82f353241c
--- /dev/null
+++ b/drivers/staging/iio/dac/dac.h
@@ -0,0 +1,6 @@
1/*
2 * dac.h - sysfs attributes associated with DACs
3 */
4
5#define IIO_DEV_ATTR_OUT_RAW(_num, _store, _addr) \
6 IIO_DEVICE_ATTR(out##_num##_raw, S_IWUSR, NULL, _store, _addr)
diff --git a/drivers/staging/iio/dds/Kconfig b/drivers/staging/iio/dds/Kconfig
new file mode 100644
index 000000000000..a047da62daf0
--- /dev/null
+++ b/drivers/staging/iio/dds/Kconfig
@@ -0,0 +1,56 @@
1#
2# Direct Digital Synthesis drivers
3#
4comment "Direct Digital Synthesis"
5
6config AD5930
7 tristate "Analog Devices ad5930/5932 driver"
8 depends on SPI
9 help
10 Say yes here to build support for Analog Devices DDS chip
11 ad5930/ad5932, provides direct access via sysfs.
12
13config AD9832
14 tristate "Analog Devices ad9832/5 driver"
15 depends on SPI
16 help
17 Say yes here to build support for Analog Devices DDS chip
18 ad9832 and ad9835, provides direct access via sysfs.
19
20config AD9834
21 tristate "Analog Devices ad9833/4/ driver"
22 depends on SPI
23 help
24 Say yes here to build support for Analog Devices DDS chip
25 AD9833 and AD9834, provides direct access via sysfs.
26
27 To compile this driver as a module, choose M here: the
28 module will be called ad9834.
29
30config AD9850
31 tristate "Analog Devices ad9850/1 driver"
32 depends on SPI
33 help
34 Say yes here to build support for Analog Devices DDS chip
35 ad9850/1, provides direct access via sysfs.
36
37config AD9852
38 tristate "Analog Devices ad9852/4 driver"
39 depends on SPI
40 help
41 Say yes here to build support for Analog Devices DDS chip
42 ad9852/4, provides direct access via sysfs.
43
44config AD9910
45 tristate "Analog Devices ad9910 driver"
46 depends on SPI
47 help
48 Say yes here to build support for Analog Devices DDS chip
49 ad9910, provides direct access via sysfs.
50
51config AD9951
52 tristate "Analog Devices ad9951 driver"
53 depends on SPI
54 help
55 Say yes here to build support for Analog Devices DDS chip
56 ad9951, provides direct access via sysfs.
diff --git a/drivers/staging/iio/dds/Makefile b/drivers/staging/iio/dds/Makefile
new file mode 100644
index 000000000000..147746176b9b
--- /dev/null
+++ b/drivers/staging/iio/dds/Makefile
@@ -0,0 +1,11 @@
1#
2# Makefile for Direct Digital Synthesis drivers
3#
4
5obj-$(CONFIG_AD5930) += ad5930.o
6obj-$(CONFIG_AD9832) += ad9832.o
7obj-$(CONFIG_AD9834) += ad9834.o
8obj-$(CONFIG_AD9850) += ad9850.o
9obj-$(CONFIG_AD9852) += ad9852.o
10obj-$(CONFIG_AD9910) += ad9910.o
11obj-$(CONFIG_AD9951) += ad9951.o
diff --git a/drivers/staging/iio/dds/ad5930.c b/drivers/staging/iio/dds/ad5930.c
new file mode 100644
index 000000000000..f80039c5d539
--- /dev/null
+++ b/drivers/staging/iio/dds/ad5930.c
@@ -0,0 +1,170 @@
1/*
2 * Driver for ADI Direct Digital Synthesis ad5930
3 *
4 * Copyright (c) 2010-2010 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/types.h>
12#include <linux/mutex.h>
13#include <linux/device.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17
18#include "../iio.h"
19#include "../sysfs.h"
20
21#define DRV_NAME "ad5930"
22
23#define value_mask (u16)0xf000
24#define addr_shift 12
25
26/* Register format: 4 bits addr + 12 bits value */
27struct ad5903_config {
28 u16 control;
29 u16 incnum;
30 u16 frqdelt[2];
31 u16 incitvl;
32 u16 buritvl;
33 u16 strtfrq[2];
34};
35
36struct ad5930_state {
37 struct mutex lock;
38 struct iio_dev *idev;
39 struct spi_device *sdev;
40};
41
42static ssize_t ad5930_set_parameter(struct device *dev,
43 struct device_attribute *attr,
44 const char *buf,
45 size_t len)
46{
47 struct spi_message msg;
48 struct spi_transfer xfer;
49 int ret;
50 struct ad5903_config *config = (struct ad5903_config *)buf;
51 struct iio_dev *idev = dev_get_drvdata(dev);
52 struct ad5930_state *st = idev->dev_data;
53
54 config->control = (config->control & ~value_mask);
55 config->incnum = (config->control & ~value_mask) | (1 << addr_shift);
56 config->frqdelt[0] = (config->control & ~value_mask) | (2 << addr_shift);
57 config->frqdelt[1] = (config->control & ~value_mask) | 3 << addr_shift;
58 config->incitvl = (config->control & ~value_mask) | 4 << addr_shift;
59 config->buritvl = (config->control & ~value_mask) | 8 << addr_shift;
60 config->strtfrq[0] = (config->control & ~value_mask) | 0xc << addr_shift;
61 config->strtfrq[1] = (config->control & ~value_mask) | 0xd << addr_shift;
62
63 xfer.len = len;
64 xfer.tx_buf = config;
65 mutex_lock(&st->lock);
66
67 spi_message_init(&msg);
68 spi_message_add_tail(&xfer, &msg);
69 ret = spi_sync(st->sdev, &msg);
70 if (ret)
71 goto error_ret;
72error_ret:
73 mutex_unlock(&st->lock);
74
75 return ret ? ret : len;
76}
77
78static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad5930_set_parameter, 0);
79
80static struct attribute *ad5930_attributes[] = {
81 &iio_dev_attr_dds.dev_attr.attr,
82 NULL,
83};
84
85static const struct attribute_group ad5930_attribute_group = {
86 .name = DRV_NAME,
87 .attrs = ad5930_attributes,
88};
89
90static int __devinit ad5930_probe(struct spi_device *spi)
91{
92 struct ad5930_state *st;
93 int ret = 0;
94
95 st = kzalloc(sizeof(*st), GFP_KERNEL);
96 if (st == NULL) {
97 ret = -ENOMEM;
98 goto error_ret;
99 }
100 spi_set_drvdata(spi, st);
101
102 mutex_init(&st->lock);
103 st->sdev = spi;
104
105 st->idev = iio_allocate_device();
106 if (st->idev == NULL) {
107 ret = -ENOMEM;
108 goto error_free_st;
109 }
110 st->idev->dev.parent = &spi->dev;
111 st->idev->num_interrupt_lines = 0;
112 st->idev->event_attrs = NULL;
113
114 st->idev->attrs = &ad5930_attribute_group;
115 st->idev->dev_data = (void *)(st);
116 st->idev->driver_module = THIS_MODULE;
117 st->idev->modes = INDIO_DIRECT_MODE;
118
119 ret = iio_device_register(st->idev);
120 if (ret)
121 goto error_free_dev;
122 spi->max_speed_hz = 2000000;
123 spi->mode = SPI_MODE_3;
124 spi->bits_per_word = 16;
125 spi_setup(spi);
126
127 return 0;
128
129error_free_dev:
130 iio_free_device(st->idev);
131error_free_st:
132 kfree(st);
133error_ret:
134 return ret;
135}
136
137static int __devexit ad5930_remove(struct spi_device *spi)
138{
139 struct ad5930_state *st = spi_get_drvdata(spi);
140
141 iio_device_unregister(st->idev);
142 kfree(st);
143
144 return 0;
145}
146
147static struct spi_driver ad5930_driver = {
148 .driver = {
149 .name = DRV_NAME,
150 .owner = THIS_MODULE,
151 },
152 .probe = ad5930_probe,
153 .remove = __devexit_p(ad5930_remove),
154};
155
156static __init int ad5930_spi_init(void)
157{
158 return spi_register_driver(&ad5930_driver);
159}
160module_init(ad5930_spi_init);
161
162static __exit void ad5930_spi_exit(void)
163{
164 spi_unregister_driver(&ad5930_driver);
165}
166module_exit(ad5930_spi_exit);
167
168MODULE_AUTHOR("Cliff Cai");
169MODULE_DESCRIPTION("Analog Devices ad5930 driver");
170MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/dds/ad9832.c b/drivers/staging/iio/dds/ad9832.c
new file mode 100644
index 000000000000..e911893b3db0
--- /dev/null
+++ b/drivers/staging/iio/dds/ad9832.c
@@ -0,0 +1,264 @@
1/*
2 * Driver for ADI Direct Digital Synthesis ad9832
3 *
4 * Copyright (c) 2010 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/types.h>
12#include <linux/mutex.h>
13#include <linux/device.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17
18#include "../iio.h"
19#include "../sysfs.h"
20
21#define DRV_NAME "ad9832"
22
23#define value_mask (u16)0xf000
24#define cmd_shift 12
25#define add_shift 8
26#define AD9832_SYNC (1 << 13)
27#define AD9832_SELSRC (1 << 12)
28#define AD9832_SLEEP (1 << 13)
29#define AD9832_RESET (1 << 12)
30#define AD9832_CLR (1 << 11)
31
32#define ADD_FREQ0LL 0x0
33#define ADD_FREQ0HL 0x1
34#define ADD_FREQ0LM 0x2
35#define ADD_FREQ0HM 0x3
36#define ADD_FREQ1LL 0x4
37#define ADD_FREQ1HL 0x5
38#define ADD_FREQ1LM 0x6
39#define ADD_FREQ1HM 0x7
40#define ADD_PHASE0L 0x8
41#define ADD_PHASE0H 0x9
42#define ADD_PHASE1L 0xa
43#define ADD_PHASE1H 0xb
44#define ADD_PHASE2L 0xc
45#define ADD_PHASE2H 0xd
46#define ADD_PHASE3L 0xe
47#define ADD_PHASE3H 0xf
48
49#define CMD_PHA8BITSW 0x1
50#define CMD_PHA16BITSW 0x0
51#define CMD_FRE8BITSW 0x3
52#define CMD_FRE16BITSW 0x2
53#define CMD_SELBITSCTL 0x6
54
55struct ad9832_setting {
56 u16 freq0[4];
57 u16 freq1[4];
58 u16 phase0[2];
59 u16 phase1[2];
60 u16 phase2[2];
61 u16 phase3[2];
62};
63
64struct ad9832_state {
65 struct mutex lock;
66 struct iio_dev *idev;
67 struct spi_device *sdev;
68};
69
70static ssize_t ad9832_set_parameter(struct device *dev,
71 struct device_attribute *attr,
72 const char *buf,
73 size_t len)
74{
75 struct spi_message msg;
76 struct spi_transfer xfer;
77 int ret;
78 struct ad9832_setting config;
79 struct iio_dev *idev = dev_get_drvdata(dev);
80 struct ad9832_state *st = idev->dev_data;
81
82 config.freq0[0] = (CMD_FRE8BITSW << add_shift | ADD_FREQ0LL << add_shift | buf[0]);
83 config.freq0[1] = (CMD_FRE16BITSW << add_shift | ADD_FREQ0HL << add_shift | buf[1]);
84 config.freq0[2] = (CMD_FRE8BITSW << add_shift | ADD_FREQ0LM << add_shift | buf[2]);
85 config.freq0[3] = (CMD_FRE16BITSW << add_shift | ADD_FREQ0HM << add_shift | buf[3]);
86 config.freq1[0] = (CMD_FRE8BITSW << add_shift | ADD_FREQ1LL << add_shift | buf[4]);
87 config.freq1[1] = (CMD_FRE16BITSW << add_shift | ADD_FREQ1HL << add_shift | buf[5]);
88 config.freq1[2] = (CMD_FRE8BITSW << add_shift | ADD_FREQ1LM << add_shift | buf[6]);
89 config.freq1[3] = (CMD_FRE16BITSW << add_shift | ADD_FREQ1HM << add_shift | buf[7]);
90
91 config.phase0[0] = (CMD_PHA8BITSW << add_shift | ADD_PHASE0L << add_shift | buf[9]);
92 config.phase0[1] = (CMD_PHA16BITSW << add_shift | ADD_PHASE0H << add_shift | buf[10]);
93 config.phase1[0] = (CMD_PHA8BITSW << add_shift | ADD_PHASE1L << add_shift | buf[11]);
94 config.phase1[1] = (CMD_PHA16BITSW << add_shift | ADD_PHASE1H << add_shift | buf[12]);
95 config.phase2[0] = (CMD_PHA8BITSW << add_shift | ADD_PHASE2L << add_shift | buf[13]);
96 config.phase2[1] = (CMD_PHA16BITSW << add_shift | ADD_PHASE2H << add_shift | buf[14]);
97 config.phase3[0] = (CMD_PHA8BITSW << add_shift | ADD_PHASE3L << add_shift | buf[15]);
98 config.phase3[1] = (CMD_PHA16BITSW << add_shift | ADD_PHASE3H << add_shift | buf[16]);
99
100 xfer.len = 2 * len;
101 xfer.tx_buf = &config;
102 mutex_lock(&st->lock);
103
104 spi_message_init(&msg);
105 spi_message_add_tail(&xfer, &msg);
106 ret = spi_sync(st->sdev, &msg);
107 if (ret)
108 goto error_ret;
109error_ret:
110 mutex_unlock(&st->lock);
111
112 return ret ? ret : len;
113}
114
115static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9832_set_parameter, 0);
116
117static struct attribute *ad9832_attributes[] = {
118 &iio_dev_attr_dds.dev_attr.attr,
119 NULL,
120};
121
122static const struct attribute_group ad9832_attribute_group = {
123 .name = DRV_NAME,
124 .attrs = ad9832_attributes,
125};
126
127static void ad9832_init(struct ad9832_state *st)
128{
129 struct spi_message msg;
130 struct spi_transfer xfer;
131 int ret;
132 u16 config = 0;
133
134 config = 0x3 << 14 | AD9832_SLEEP | AD9832_RESET | AD9832_CLR;
135
136 mutex_lock(&st->lock);
137
138 xfer.len = 2;
139 xfer.tx_buf = &config;
140
141 spi_message_init(&msg);
142 spi_message_add_tail(&xfer, &msg);
143 ret = spi_sync(st->sdev, &msg);
144 if (ret)
145 goto error_ret;
146
147 config = 0x2 << 14 | AD9832_SYNC | AD9832_SELSRC;
148 xfer.len = 2;
149 xfer.tx_buf = &config;
150
151 spi_message_init(&msg);
152 spi_message_add_tail(&xfer, &msg);
153 ret = spi_sync(st->sdev, &msg);
154 if (ret)
155 goto error_ret;
156
157 config = CMD_SELBITSCTL << cmd_shift;
158 xfer.len = 2;
159 xfer.tx_buf = &config;
160
161 spi_message_init(&msg);
162 spi_message_add_tail(&xfer, &msg);
163 ret = spi_sync(st->sdev, &msg);
164 if (ret)
165 goto error_ret;
166
167 config = 0x3 << 14;
168
169 xfer.len = 2;
170 xfer.tx_buf = &config;
171
172 spi_message_init(&msg);
173 spi_message_add_tail(&xfer, &msg);
174 ret = spi_sync(st->sdev, &msg);
175 if (ret)
176 goto error_ret;
177error_ret:
178 mutex_unlock(&st->lock);
179
180
181
182}
183
184static int __devinit ad9832_probe(struct spi_device *spi)
185{
186 struct ad9832_state *st;
187 int ret = 0;
188
189 st = kzalloc(sizeof(*st), GFP_KERNEL);
190 if (st == NULL) {
191 ret = -ENOMEM;
192 goto error_ret;
193 }
194 spi_set_drvdata(spi, st);
195
196 mutex_init(&st->lock);
197 st->sdev = spi;
198
199 st->idev = iio_allocate_device();
200 if (st->idev == NULL) {
201 ret = -ENOMEM;
202 goto error_free_st;
203 }
204 st->idev->dev.parent = &spi->dev;
205 st->idev->num_interrupt_lines = 0;
206 st->idev->event_attrs = NULL;
207
208 st->idev->attrs = &ad9832_attribute_group;
209 st->idev->dev_data = (void *)(st);
210 st->idev->driver_module = THIS_MODULE;
211 st->idev->modes = INDIO_DIRECT_MODE;
212
213 ret = iio_device_register(st->idev);
214 if (ret)
215 goto error_free_dev;
216 spi->max_speed_hz = 2000000;
217 spi->mode = SPI_MODE_3;
218 spi->bits_per_word = 16;
219 spi_setup(spi);
220 ad9832_init(st);
221 return 0;
222
223error_free_dev:
224 iio_free_device(st->idev);
225error_free_st:
226 kfree(st);
227error_ret:
228 return ret;
229}
230
231static int __devexit ad9832_remove(struct spi_device *spi)
232{
233 struct ad9832_state *st = spi_get_drvdata(spi);
234
235 iio_device_unregister(st->idev);
236 kfree(st);
237
238 return 0;
239}
240
241static struct spi_driver ad9832_driver = {
242 .driver = {
243 .name = DRV_NAME,
244 .owner = THIS_MODULE,
245 },
246 .probe = ad9832_probe,
247 .remove = __devexit_p(ad9832_remove),
248};
249
250static __init int ad9832_spi_init(void)
251{
252 return spi_register_driver(&ad9832_driver);
253}
254module_init(ad9832_spi_init);
255
256static __exit void ad9832_spi_exit(void)
257{
258 spi_unregister_driver(&ad9832_driver);
259}
260module_exit(ad9832_spi_exit);
261
262MODULE_AUTHOR("Cliff Cai");
263MODULE_DESCRIPTION("Analog Devices ad9832 driver");
264MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/dds/ad9834.c b/drivers/staging/iio/dds/ad9834.c
new file mode 100644
index 000000000000..eb1a681874f9
--- /dev/null
+++ b/drivers/staging/iio/dds/ad9834.c
@@ -0,0 +1,477 @@
1/*
2 * AD9834 SPI DAC driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/workqueue.h>
11#include <linux/device.h>
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/sysfs.h>
15#include <linux/list.h>
16#include <linux/spi/spi.h>
17#include <linux/regulator/consumer.h>
18#include <linux/err.h>
19#include <asm/div64.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "dds.h"
24
25#include "ad9834.h"
26
27static unsigned int ad9834_calc_freqreg(unsigned long mclk, unsigned long fout)
28{
29 unsigned long long freqreg = (u64) fout * (u64) (1 << AD9834_FREQ_BITS);
30 do_div(freqreg, mclk);
31 return freqreg;
32}
33
34static int ad9834_write_frequency(struct ad9834_state *st,
35 unsigned long addr, unsigned long fout)
36{
37 unsigned long regval;
38
39 if (fout > (st->mclk / 2))
40 return -EINVAL;
41
42 regval = ad9834_calc_freqreg(st->mclk, fout);
43
44 st->freq_data[0] = cpu_to_be16(addr | (regval &
45 RES_MASK(AD9834_FREQ_BITS / 2)));
46 st->freq_data[1] = cpu_to_be16(addr | ((regval >>
47 (AD9834_FREQ_BITS / 2)) &
48 RES_MASK(AD9834_FREQ_BITS / 2)));
49
50 return spi_sync(st->spi, &st->freq_msg);;
51}
52
53static int ad9834_write_phase(struct ad9834_state *st,
54 unsigned long addr, unsigned long phase)
55{
56 if (phase > (1 << AD9834_PHASE_BITS))
57 return -EINVAL;
58 st->data = cpu_to_be16(addr | phase);
59
60 return spi_sync(st->spi, &st->msg);
61}
62
63static ssize_t ad9834_write(struct device *dev,
64 struct device_attribute *attr,
65 const char *buf,
66 size_t len)
67{
68 struct iio_dev *dev_info = dev_get_drvdata(dev);
69 struct ad9834_state *st = dev_info->dev_data;
70 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
71 int ret;
72 long val;
73
74 ret = strict_strtoul(buf, 10, &val);
75 if (ret)
76 goto error_ret;
77
78 mutex_lock(&dev_info->mlock);
79 switch (this_attr->address) {
80 case AD9834_REG_FREQ0:
81 case AD9834_REG_FREQ1:
82 ret = ad9834_write_frequency(st, this_attr->address, val);
83 break;
84 case AD9834_REG_PHASE0:
85 case AD9834_REG_PHASE1:
86 ret = ad9834_write_phase(st, this_attr->address, val);
87 break;
88 case AD9834_OPBITEN:
89 if (st->control & AD9834_MODE) {
90 ret = -EINVAL; /* AD9843 reserved mode */
91 break;
92 }
93
94 if (val)
95 st->control |= AD9834_OPBITEN;
96 else
97 st->control &= ~AD9834_OPBITEN;
98
99 st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
100 ret = spi_sync(st->spi, &st->msg);
101 break;
102 case AD9834_PIN_SW:
103 if (val)
104 st->control |= AD9834_PIN_SW;
105 else
106 st->control &= ~AD9834_PIN_SW;
107 st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
108 ret = spi_sync(st->spi, &st->msg);
109 break;
110 case AD9834_FSEL:
111 case AD9834_PSEL:
112 if (val == 0)
113 st->control &= ~(this_attr->address | AD9834_PIN_SW);
114 else if (val == 1) {
115 st->control |= this_attr->address;
116 st->control &= ~AD9834_PIN_SW;
117 } else {
118 ret = -EINVAL;
119 break;
120 }
121 st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
122 ret = spi_sync(st->spi, &st->msg);
123 break;
124 case AD9834_RESET:
125 if (val)
126 st->control &= ~AD9834_RESET;
127 else
128 st->control |= AD9834_RESET;
129
130 st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
131 ret = spi_sync(st->spi, &st->msg);
132 break;
133 default:
134 ret = -ENODEV;
135 }
136 mutex_unlock(&dev_info->mlock);
137
138error_ret:
139 return ret ? ret : len;
140}
141
142static ssize_t ad9834_store_wavetype(struct device *dev,
143 struct device_attribute *attr,
144 const char *buf,
145 size_t len)
146{
147 struct iio_dev *dev_info = dev_get_drvdata(dev);
148 struct ad9834_state *st = dev_info->dev_data;
149 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
150 int ret = 0;
151 bool is_ad9833 = st->devid == ID_AD9833;
152
153 mutex_lock(&dev_info->mlock);
154
155 switch (this_attr->address) {
156 case 0:
157 if (sysfs_streq(buf, "sine")) {
158 st->control &= ~AD9834_MODE;
159 if (is_ad9833)
160 st->control &= ~AD9834_OPBITEN;
161 } else if (sysfs_streq(buf, "triangle")) {
162 if (is_ad9833) {
163 st->control &= ~AD9834_OPBITEN;
164 st->control |= AD9834_MODE;
165 } else if (st->control & AD9834_OPBITEN) {
166 ret = -EINVAL; /* AD9843 reserved mode */
167 } else {
168 st->control |= AD9834_MODE;
169 }
170 } else if (is_ad9833 && sysfs_streq(buf, "square")) {
171 st->control &= ~AD9834_MODE;
172 st->control |= AD9834_OPBITEN;
173 } else {
174 ret = -EINVAL;
175 }
176
177 break;
178 case 1:
179 if (sysfs_streq(buf, "square") &&
180 !(st->control & AD9834_MODE)) {
181 st->control &= ~AD9834_MODE;
182 st->control |= AD9834_OPBITEN;
183 } else {
184 ret = -EINVAL;
185 }
186 break;
187 default:
188 ret = -EINVAL;
189 break;
190 }
191
192 if (!ret) {
193 st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
194 ret = spi_sync(st->spi, &st->msg);
195 }
196 mutex_unlock(&dev_info->mlock);
197
198 return ret ? ret : len;
199}
200
201static ssize_t ad9834_show_name(struct device *dev,
202 struct device_attribute *attr,
203 char *buf)
204{
205 struct iio_dev *dev_info = dev_get_drvdata(dev);
206 struct ad9834_state *st = iio_dev_get_devdata(dev_info);
207
208 return sprintf(buf, "%s\n", spi_get_device_id(st->spi)->name);
209}
210static IIO_DEVICE_ATTR(name, S_IRUGO, ad9834_show_name, NULL, 0);
211
212static ssize_t ad9834_show_out0_wavetype_available(struct device *dev,
213 struct device_attribute *attr,
214 char *buf)
215{
216 struct iio_dev *dev_info = dev_get_drvdata(dev);
217 struct ad9834_state *st = iio_dev_get_devdata(dev_info);
218 char *str;
219
220 if (st->devid == ID_AD9833)
221 str = "sine triangle square";
222 else if (st->control & AD9834_OPBITEN)
223 str = "sine";
224 else
225 str = "sine triangle";
226
227 return sprintf(buf, "%s\n", str);
228}
229
230
231static IIO_DEVICE_ATTR(dds0_out0_wavetype_available, S_IRUGO,
232 ad9834_show_out0_wavetype_available, NULL, 0);
233
234static ssize_t ad9834_show_out1_wavetype_available(struct device *dev,
235 struct device_attribute *attr,
236 char *buf)
237{
238 struct iio_dev *dev_info = dev_get_drvdata(dev);
239 struct ad9834_state *st = iio_dev_get_devdata(dev_info);
240 char *str;
241
242 if (st->control & AD9834_MODE)
243 str = "";
244 else
245 str = "square";
246
247 return sprintf(buf, "%s\n", str);
248}
249
250static IIO_DEVICE_ATTR(dds0_out1_wavetype_available, S_IRUGO,
251 ad9834_show_out1_wavetype_available, NULL, 0);
252
253/**
254 * see dds.h for further information
255 */
256
257static IIO_DEV_ATTR_FREQ(0, 0, S_IWUSR, NULL, ad9834_write, AD9834_REG_FREQ0);
258static IIO_DEV_ATTR_FREQ(0, 1, S_IWUSR, NULL, ad9834_write, AD9834_REG_FREQ1);
259static IIO_DEV_ATTR_FREQSYMBOL(0, S_IWUSR, NULL, ad9834_write, AD9834_FSEL);
260static IIO_CONST_ATTR_FREQ_SCALE(0, "1"); /* 1Hz */
261
262static IIO_DEV_ATTR_PHASE(0, 0, S_IWUSR, NULL, ad9834_write, AD9834_REG_PHASE0);
263static IIO_DEV_ATTR_PHASE(0, 1, S_IWUSR, NULL, ad9834_write, AD9834_REG_PHASE1);
264static IIO_DEV_ATTR_PHASESYMBOL(0, S_IWUSR, NULL, ad9834_write, AD9834_PSEL);
265static IIO_CONST_ATTR_PHASE_SCALE(0, "0.0015339808"); /* 2PI/2^12 rad*/
266
267static IIO_DEV_ATTR_PINCONTROL_EN(0, S_IWUSR, NULL,
268 ad9834_write, AD9834_PIN_SW);
269static IIO_DEV_ATTR_OUT_ENABLE(0, S_IWUSR, NULL, ad9834_write, AD9834_RESET);
270static IIO_DEV_ATTR_OUTY_ENABLE(0, 1, S_IWUSR, NULL,
271 ad9834_write, AD9834_OPBITEN);
272static IIO_DEV_ATTR_OUT_WAVETYPE(0, 0, ad9834_store_wavetype, 0);
273static IIO_DEV_ATTR_OUT_WAVETYPE(0, 1, ad9834_store_wavetype, 1);
274
275static struct attribute *ad9834_attributes[] = {
276 &iio_dev_attr_dds0_freq0.dev_attr.attr,
277 &iio_dev_attr_dds0_freq1.dev_attr.attr,
278 &iio_const_attr_dds0_freq_scale.dev_attr.attr,
279 &iio_dev_attr_dds0_phase0.dev_attr.attr,
280 &iio_dev_attr_dds0_phase1.dev_attr.attr,
281 &iio_const_attr_dds0_phase_scale.dev_attr.attr,
282 &iio_dev_attr_dds0_pincontrol_en.dev_attr.attr,
283 &iio_dev_attr_dds0_freqsymbol.dev_attr.attr,
284 &iio_dev_attr_dds0_phasesymbol.dev_attr.attr,
285 &iio_dev_attr_dds0_out_enable.dev_attr.attr,
286 &iio_dev_attr_dds0_out1_enable.dev_attr.attr,
287 &iio_dev_attr_dds0_out0_wavetype.dev_attr.attr,
288 &iio_dev_attr_dds0_out1_wavetype.dev_attr.attr,
289 &iio_dev_attr_dds0_out0_wavetype_available.dev_attr.attr,
290 &iio_dev_attr_dds0_out1_wavetype_available.dev_attr.attr,
291 &iio_dev_attr_name.dev_attr.attr,
292 NULL,
293};
294
295static mode_t ad9834_attr_is_visible(struct kobject *kobj,
296 struct attribute *attr, int n)
297{
298 struct device *dev = container_of(kobj, struct device, kobj);
299 struct iio_dev *dev_info = dev_get_drvdata(dev);
300 struct ad9834_state *st = iio_dev_get_devdata(dev_info);
301
302 mode_t mode = attr->mode;
303
304 if (st->devid == ID_AD9834)
305 return mode;
306
307 if ((attr == &iio_dev_attr_dds0_out1_enable.dev_attr.attr) ||
308 (attr == &iio_dev_attr_dds0_out1_wavetype.dev_attr.attr) ||
309 (attr ==
310 &iio_dev_attr_dds0_out1_wavetype_available.dev_attr.attr))
311 mode = 0;
312
313 return mode;
314}
315
316static const struct attribute_group ad9834_attribute_group = {
317 .attrs = ad9834_attributes,
318 .is_visible = ad9834_attr_is_visible,
319};
320
321static int __devinit ad9834_probe(struct spi_device *spi)
322{
323 struct ad9834_platform_data *pdata = spi->dev.platform_data;
324 struct ad9834_state *st;
325 int ret;
326
327 if (!pdata) {
328 dev_dbg(&spi->dev, "no platform data?\n");
329 return -ENODEV;
330 }
331
332 st = kzalloc(sizeof(*st), GFP_KERNEL);
333 if (st == NULL) {
334 ret = -ENOMEM;
335 goto error_ret;
336 }
337
338 st->reg = regulator_get(&spi->dev, "vcc");
339 if (!IS_ERR(st->reg)) {
340 ret = regulator_enable(st->reg);
341 if (ret)
342 goto error_put_reg;
343 }
344
345 st->mclk = pdata->mclk;
346
347 spi_set_drvdata(spi, st);
348
349 st->spi = spi;
350 st->devid = spi_get_device_id(spi)->driver_data;
351
352 st->indio_dev = iio_allocate_device();
353 if (st->indio_dev == NULL) {
354 ret = -ENOMEM;
355 goto error_disable_reg;
356 }
357
358 st->indio_dev->dev.parent = &spi->dev;
359 st->indio_dev->attrs = &ad9834_attribute_group;
360 st->indio_dev->dev_data = (void *) st;
361 st->indio_dev->driver_module = THIS_MODULE;
362 st->indio_dev->modes = INDIO_DIRECT_MODE;
363
364 /* Setup default messages */
365
366 st->xfer.tx_buf = &st->data;
367 st->xfer.len = 2;
368
369 spi_message_init(&st->msg);
370 spi_message_add_tail(&st->xfer, &st->msg);
371
372 st->freq_xfer[0].tx_buf = &st->freq_data[0];
373 st->freq_xfer[0].len = 2;
374 st->freq_xfer[0].cs_change = 1;
375 st->freq_xfer[1].tx_buf = &st->freq_data[1];
376 st->freq_xfer[1].len = 2;
377
378 spi_message_init(&st->freq_msg);
379 spi_message_add_tail(&st->freq_xfer[0], &st->freq_msg);
380 spi_message_add_tail(&st->freq_xfer[1], &st->freq_msg);
381
382 st->control = AD9834_B28 | AD9834_RESET;
383
384 if (!pdata->en_div2)
385 st->control |= AD9834_DIV2;
386
387 if (!pdata->en_signbit_msb_out && (st->devid == ID_AD9834))
388 st->control |= AD9834_SIGN_PIB;
389
390 st->data = cpu_to_be16(AD9834_REG_CMD | st->control);
391 ret = spi_sync(st->spi, &st->msg);
392 if (ret) {
393 dev_err(&spi->dev, "device init failed\n");
394 goto error_free_device;
395 }
396
397 ret = ad9834_write_frequency(st, AD9834_REG_FREQ0, pdata->freq0);
398 if (ret)
399 goto error_free_device;
400
401 ret = ad9834_write_frequency(st, AD9834_REG_FREQ1, pdata->freq1);
402 if (ret)
403 goto error_free_device;
404
405 ret = ad9834_write_phase(st, AD9834_REG_PHASE0, pdata->phase0);
406 if (ret)
407 goto error_free_device;
408
409 ret = ad9834_write_phase(st, AD9834_REG_PHASE1, pdata->phase1);
410 if (ret)
411 goto error_free_device;
412
413 ret = iio_device_register(st->indio_dev);
414 if (ret)
415 goto error_free_device;
416
417 return 0;
418
419error_free_device:
420 iio_free_device(st->indio_dev);
421error_disable_reg:
422 if (!IS_ERR(st->reg))
423 regulator_disable(st->reg);
424error_put_reg:
425 if (!IS_ERR(st->reg))
426 regulator_put(st->reg);
427 kfree(st);
428error_ret:
429 return ret;
430}
431
432static int __devexit ad9834_remove(struct spi_device *spi)
433{
434 struct ad9834_state *st = spi_get_drvdata(spi);
435
436 iio_device_unregister(st->indio_dev);
437 if (!IS_ERR(st->reg)) {
438 regulator_disable(st->reg);
439 regulator_put(st->reg);
440 }
441 kfree(st);
442 return 0;
443}
444
445static const struct spi_device_id ad9834_id[] = {
446 {"ad9833", ID_AD9833},
447 {"ad9834", ID_AD9834},
448 {}
449};
450
451static struct spi_driver ad9834_driver = {
452 .driver = {
453 .name = "ad9834",
454 .bus = &spi_bus_type,
455 .owner = THIS_MODULE,
456 },
457 .probe = ad9834_probe,
458 .remove = __devexit_p(ad9834_remove),
459 .id_table = ad9834_id,
460};
461
462static int __init ad9834_init(void)
463{
464 return spi_register_driver(&ad9834_driver);
465}
466module_init(ad9834_init);
467
468static void __exit ad9834_exit(void)
469{
470 spi_unregister_driver(&ad9834_driver);
471}
472module_exit(ad9834_exit);
473
474MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
475MODULE_DESCRIPTION("Analog Devices AD9833/AD9834 DDS");
476MODULE_LICENSE("GPL v2");
477MODULE_ALIAS("spi:ad9834");
diff --git a/drivers/staging/iio/dds/ad9834.h b/drivers/staging/iio/dds/ad9834.h
new file mode 100644
index 000000000000..0fc3b8859e9e
--- /dev/null
+++ b/drivers/staging/iio/dds/ad9834.h
@@ -0,0 +1,112 @@
1/*
2 * AD9834 SPI DDS driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8#ifndef IIO_DDS_AD9834_H_
9#define IIO_DDS_AD9834_H_
10
11/* Registers */
12
13#define AD9834_REG_CMD (0 << 14)
14#define AD9834_REG_FREQ0 (1 << 14)
15#define AD9834_REG_FREQ1 (2 << 14)
16#define AD9834_REG_PHASE0 (6 << 13)
17#define AD9834_REG_PHASE1 (7 << 13)
18
19/* Command Control Bits */
20
21#define AD9834_B28 (1 << 13)
22#define AD9834_HLB (1 << 12)
23#define AD9834_FSEL (1 << 11)
24#define AD9834_PSEL (1 << 10)
25#define AD9834_PIN_SW (1 << 9)
26#define AD9834_RESET (1 << 8)
27#define AD9834_SLEEP1 (1 << 7)
28#define AD9834_SLEEP12 (1 << 6)
29#define AD9834_OPBITEN (1 << 5)
30#define AD9834_SIGN_PIB (1 << 4)
31#define AD9834_DIV2 (1 << 3)
32#define AD9834_MODE (1 << 1)
33
34#define AD9834_FREQ_BITS 28
35#define AD9834_PHASE_BITS 12
36
37#define RES_MASK(bits) ((1 << (bits)) - 1)
38
39/**
40 * struct ad9834_state - driver instance specific data
41 * @indio_dev: the industrial I/O device
42 * @spi: spi_device
43 * @reg: supply regulator
44 * @mclk: external master clock
45 * @control: cached control word
46 * @xfer: default spi transfer
47 * @msg: default spi message
48 * @freq_xfer: tuning word spi transfer
49 * @freq_msg: tuning word spi message
50 * @data: spi transmit buffer
51 * @freq_data: tuning word spi transmit buffer
52 */
53
54struct ad9834_state {
55 struct iio_dev *indio_dev;
56 struct spi_device *spi;
57 struct regulator *reg;
58 unsigned int mclk;
59 unsigned short control;
60 unsigned short devid;
61 struct spi_transfer xfer;
62 struct spi_message msg;
63 struct spi_transfer freq_xfer[2];
64 struct spi_message freq_msg;
65
66 /*
67 * DMA (thus cache coherency maintenance) requires the
68 * transfer buffers to live in their own cache lines.
69 */
70 unsigned short data ____cacheline_aligned;
71 unsigned short freq_data[2] ;
72};
73
74
75/*
76 * TODO: struct ad7887_platform_data needs to go into include/linux/iio
77 */
78
79/**
80 * struct ad9834_platform_data - platform specific information
81 * @mclk: master clock in Hz
82 * @freq0: power up freq0 tuning word in Hz
83 * @freq1: power up freq1 tuning word in Hz
84 * @phase0: power up phase0 value [0..4095] correlates with 0..2PI
85 * @phase1: power up phase1 value [0..4095] correlates with 0..2PI
86 * @en_div2: digital output/2 is passed to the SIGN BIT OUT pin
87 * @en_signbit_msb_out: the MSB (or MSB/2) of the DAC data is connected to the
88 * SIGN BIT OUT pin. en_div2 controls whether it is the MSB
89 * or MSB/2 that is output. if en_signbit_msb_out=false,
90 * the on-board comparator is connected to SIGN BIT OUT
91 */
92
93struct ad9834_platform_data {
94 unsigned int mclk;
95 unsigned int freq0;
96 unsigned int freq1;
97 unsigned short phase0;
98 unsigned short phase1;
99 bool en_div2;
100 bool en_signbit_msb_out;
101};
102
103/**
104 * ad9834_supported_device_ids:
105 */
106
107enum ad9834_supported_device_ids {
108 ID_AD9833,
109 ID_AD9834,
110};
111
112#endif /* IIO_DDS_AD9834_H_ */
diff --git a/drivers/staging/iio/dds/ad9850.c b/drivers/staging/iio/dds/ad9850.c
new file mode 100644
index 000000000000..b259bfeaf5aa
--- /dev/null
+++ b/drivers/staging/iio/dds/ad9850.c
@@ -0,0 +1,156 @@
1/*
2 * Driver for ADI Direct Digital Synthesis ad9850
3 *
4 * Copyright (c) 2010-2010 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/types.h>
12#include <linux/mutex.h>
13#include <linux/device.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17
18#include "../iio.h"
19#include "../sysfs.h"
20
21#define DRV_NAME "ad9850"
22
23#define value_mask (u16)0xf000
24#define addr_shift 12
25
26/* Register format: 4 bits addr + 12 bits value */
27struct ad9850_config {
28 u8 control[5];
29};
30
31struct ad9850_state {
32 struct mutex lock;
33 struct iio_dev *idev;
34 struct spi_device *sdev;
35};
36
37static ssize_t ad9850_set_parameter(struct device *dev,
38 struct device_attribute *attr,
39 const char *buf,
40 size_t len)
41{
42 struct spi_message msg;
43 struct spi_transfer xfer;
44 int ret;
45 struct ad9850_config *config = (struct ad9850_config *)buf;
46 struct iio_dev *idev = dev_get_drvdata(dev);
47 struct ad9850_state *st = idev->dev_data;
48
49 xfer.len = len;
50 xfer.tx_buf = config;
51 mutex_lock(&st->lock);
52
53 spi_message_init(&msg);
54 spi_message_add_tail(&xfer, &msg);
55 ret = spi_sync(st->sdev, &msg);
56 if (ret)
57 goto error_ret;
58error_ret:
59 mutex_unlock(&st->lock);
60
61 return ret ? ret : len;
62}
63
64static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9850_set_parameter, 0);
65
66static struct attribute *ad9850_attributes[] = {
67 &iio_dev_attr_dds.dev_attr.attr,
68 NULL,
69};
70
71static const struct attribute_group ad9850_attribute_group = {
72 .name = DRV_NAME,
73 .attrs = ad9850_attributes,
74};
75
76static int __devinit ad9850_probe(struct spi_device *spi)
77{
78 struct ad9850_state *st;
79 int ret = 0;
80
81 st = kzalloc(sizeof(*st), GFP_KERNEL);
82 if (st == NULL) {
83 ret = -ENOMEM;
84 goto error_ret;
85 }
86 spi_set_drvdata(spi, st);
87
88 mutex_init(&st->lock);
89 st->sdev = spi;
90
91 st->idev = iio_allocate_device();
92 if (st->idev == NULL) {
93 ret = -ENOMEM;
94 goto error_free_st;
95 }
96 st->idev->dev.parent = &spi->dev;
97 st->idev->num_interrupt_lines = 0;
98 st->idev->event_attrs = NULL;
99
100 st->idev->attrs = &ad9850_attribute_group;
101 st->idev->dev_data = (void *)(st);
102 st->idev->driver_module = THIS_MODULE;
103 st->idev->modes = INDIO_DIRECT_MODE;
104
105 ret = iio_device_register(st->idev);
106 if (ret)
107 goto error_free_dev;
108 spi->max_speed_hz = 2000000;
109 spi->mode = SPI_MODE_3;
110 spi->bits_per_word = 16;
111 spi_setup(spi);
112
113 return 0;
114
115error_free_dev:
116 iio_free_device(st->idev);
117error_free_st:
118 kfree(st);
119error_ret:
120 return ret;
121}
122
123static int __devexit ad9850_remove(struct spi_device *spi)
124{
125 struct ad9850_state *st = spi_get_drvdata(spi);
126
127 iio_device_unregister(st->idev);
128 kfree(st);
129
130 return 0;
131}
132
133static struct spi_driver ad9850_driver = {
134 .driver = {
135 .name = DRV_NAME,
136 .owner = THIS_MODULE,
137 },
138 .probe = ad9850_probe,
139 .remove = __devexit_p(ad9850_remove),
140};
141
142static __init int ad9850_spi_init(void)
143{
144 return spi_register_driver(&ad9850_driver);
145}
146module_init(ad9850_spi_init);
147
148static __exit void ad9850_spi_exit(void)
149{
150 spi_unregister_driver(&ad9850_driver);
151}
152module_exit(ad9850_spi_exit);
153
154MODULE_AUTHOR("Cliff Cai");
155MODULE_DESCRIPTION("Analog Devices ad9850 driver");
156MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/dds/ad9852.c b/drivers/staging/iio/dds/ad9852.c
new file mode 100644
index 000000000000..594fb6a94331
--- /dev/null
+++ b/drivers/staging/iio/dds/ad9852.c
@@ -0,0 +1,305 @@
1/*
2 * Driver for ADI Direct Digital Synthesis ad9852
3 *
4 * Copyright (c) 2010 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/types.h>
12#include <linux/mutex.h>
13#include <linux/device.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17
18#include "../iio.h"
19#include "../sysfs.h"
20
21#define DRV_NAME "ad9852"
22
23#define addr_phaad1 0x0
24#define addr_phaad2 0x1
25#define addr_fretu1 0x2
26#define addr_fretu2 0x3
27#define addr_delfre 0x4
28#define addr_updclk 0x5
29#define addr_ramclk 0x6
30#define addr_contrl 0x7
31#define addr_optskm 0x8
32#define addr_optskr 0xa
33#define addr_dacctl 0xb
34
35#define COMPPD (1 << 4)
36#define REFMULT2 (1 << 2)
37#define BYPPLL (1 << 5)
38#define PLLRANG (1 << 6)
39#define IEUPCLK (1)
40#define OSKEN (1 << 5)
41
42#define read_bit (1 << 7)
43
44/* Register format: 1 byte addr + value */
45struct ad9852_config {
46 u8 phajst0[3];
47 u8 phajst1[3];
48 u8 fretun1[6];
49 u8 fretun2[6];
50 u8 dltafre[6];
51 u8 updtclk[5];
52 u8 ramprat[4];
53 u8 control[5];
54 u8 outpskm[3];
55 u8 outpskr[2];
56 u8 daccntl[3];
57};
58
59struct ad9852_state {
60 struct mutex lock;
61 struct iio_dev *idev;
62 struct spi_device *sdev;
63};
64
65static ssize_t ad9852_set_parameter(struct device *dev,
66 struct device_attribute *attr,
67 const char *buf,
68 size_t len)
69{
70 struct spi_message msg;
71 struct spi_transfer xfer;
72 int ret;
73 struct ad9852_config *config = (struct ad9852_config *)buf;
74 struct iio_dev *idev = dev_get_drvdata(dev);
75 struct ad9852_state *st = idev->dev_data;
76
77 xfer.len = 3;
78 xfer.tx_buf = &config->phajst0[0];
79 mutex_lock(&st->lock);
80
81 spi_message_init(&msg);
82 spi_message_add_tail(&xfer, &msg);
83 ret = spi_sync(st->sdev, &msg);
84 if (ret)
85 goto error_ret;
86
87 xfer.len = 3;
88 xfer.tx_buf = &config->phajst1[0];
89
90 spi_message_init(&msg);
91 spi_message_add_tail(&xfer, &msg);
92 ret = spi_sync(st->sdev, &msg);
93 if (ret)
94 goto error_ret;
95
96 xfer.len = 6;
97 xfer.tx_buf = &config->fretun1[0];
98
99 spi_message_init(&msg);
100 spi_message_add_tail(&xfer, &msg);
101 ret = spi_sync(st->sdev, &msg);
102 if (ret)
103 goto error_ret;
104
105 xfer.len = 6;
106 xfer.tx_buf = &config->fretun2[0];
107
108 spi_message_init(&msg);
109 spi_message_add_tail(&xfer, &msg);
110 ret = spi_sync(st->sdev, &msg);
111 if (ret)
112 goto error_ret;
113
114 xfer.len = 6;
115 xfer.tx_buf = &config->dltafre[0];
116
117 spi_message_init(&msg);
118 spi_message_add_tail(&xfer, &msg);
119 ret = spi_sync(st->sdev, &msg);
120 if (ret)
121 goto error_ret;
122
123 xfer.len = 5;
124 xfer.tx_buf = &config->updtclk[0];
125
126 spi_message_init(&msg);
127 spi_message_add_tail(&xfer, &msg);
128 ret = spi_sync(st->sdev, &msg);
129 if (ret)
130 goto error_ret;
131
132 xfer.len = 4;
133 xfer.tx_buf = &config->ramprat[0];
134
135 spi_message_init(&msg);
136 spi_message_add_tail(&xfer, &msg);
137 ret = spi_sync(st->sdev, &msg);
138 if (ret)
139 goto error_ret;
140
141 xfer.len = 5;
142 xfer.tx_buf = &config->control[0];
143
144 spi_message_init(&msg);
145 spi_message_add_tail(&xfer, &msg);
146 ret = spi_sync(st->sdev, &msg);
147 if (ret)
148 goto error_ret;
149
150 xfer.len = 3;
151 xfer.tx_buf = &config->outpskm[0];
152
153 spi_message_init(&msg);
154 spi_message_add_tail(&xfer, &msg);
155 ret = spi_sync(st->sdev, &msg);
156 if (ret)
157 goto error_ret;
158
159 xfer.len = 2;
160 xfer.tx_buf = &config->outpskr[0];
161
162 spi_message_init(&msg);
163 spi_message_add_tail(&xfer, &msg);
164 ret = spi_sync(st->sdev, &msg);
165 if (ret)
166 goto error_ret;
167
168 xfer.len = 3;
169 xfer.tx_buf = &config->daccntl[0];
170
171 spi_message_init(&msg);
172 spi_message_add_tail(&xfer, &msg);
173 ret = spi_sync(st->sdev, &msg);
174 if (ret)
175 goto error_ret;
176error_ret:
177 mutex_unlock(&st->lock);
178
179 return ret ? ret : len;
180}
181
182static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9852_set_parameter, 0);
183
184static void ad9852_init(struct ad9852_state *st)
185{
186 struct spi_message msg;
187 struct spi_transfer xfer;
188 int ret;
189 u8 config[5];
190
191 config[0] = addr_contrl;
192 config[1] = COMPPD;
193 config[2] = REFMULT2 | BYPPLL | PLLRANG;
194 config[3] = IEUPCLK;
195 config[4] = OSKEN;
196
197 mutex_lock(&st->lock);
198
199 xfer.len = 5;
200 xfer.tx_buf = &config;
201
202 spi_message_init(&msg);
203 spi_message_add_tail(&xfer, &msg);
204 ret = spi_sync(st->sdev, &msg);
205 if (ret)
206 goto error_ret;
207
208error_ret:
209 mutex_unlock(&st->lock);
210
211
212
213}
214
215static struct attribute *ad9852_attributes[] = {
216 &iio_dev_attr_dds.dev_attr.attr,
217 NULL,
218};
219
220static const struct attribute_group ad9852_attribute_group = {
221 .name = DRV_NAME,
222 .attrs = ad9852_attributes,
223};
224
225static int __devinit ad9852_probe(struct spi_device *spi)
226{
227 struct ad9852_state *st;
228 int ret = 0;
229
230 st = kzalloc(sizeof(*st), GFP_KERNEL);
231 if (st == NULL) {
232 ret = -ENOMEM;
233 goto error_ret;
234 }
235 spi_set_drvdata(spi, st);
236
237 mutex_init(&st->lock);
238 st->sdev = spi;
239
240 st->idev = iio_allocate_device();
241 if (st->idev == NULL) {
242 ret = -ENOMEM;
243 goto error_free_st;
244 }
245 st->idev->dev.parent = &spi->dev;
246 st->idev->num_interrupt_lines = 0;
247 st->idev->event_attrs = NULL;
248
249 st->idev->attrs = &ad9852_attribute_group;
250 st->idev->dev_data = (void *)(st);
251 st->idev->driver_module = THIS_MODULE;
252 st->idev->modes = INDIO_DIRECT_MODE;
253
254 ret = iio_device_register(st->idev);
255 if (ret)
256 goto error_free_dev;
257 spi->max_speed_hz = 2000000;
258 spi->mode = SPI_MODE_3;
259 spi->bits_per_word = 8;
260 spi_setup(spi);
261 ad9852_init(st);
262 return 0;
263
264error_free_dev:
265 iio_free_device(st->idev);
266error_free_st:
267 kfree(st);
268error_ret:
269 return ret;
270}
271
272static int __devexit ad9852_remove(struct spi_device *spi)
273{
274 struct ad9852_state *st = spi_get_drvdata(spi);
275
276 iio_device_unregister(st->idev);
277 kfree(st);
278
279 return 0;
280}
281
282static struct spi_driver ad9852_driver = {
283 .driver = {
284 .name = DRV_NAME,
285 .owner = THIS_MODULE,
286 },
287 .probe = ad9852_probe,
288 .remove = __devexit_p(ad9852_remove),
289};
290
291static __init int ad9852_spi_init(void)
292{
293 return spi_register_driver(&ad9852_driver);
294}
295module_init(ad9852_spi_init);
296
297static __exit void ad9852_spi_exit(void)
298{
299 spi_unregister_driver(&ad9852_driver);
300}
301module_exit(ad9852_spi_exit);
302
303MODULE_AUTHOR("Cliff Cai");
304MODULE_DESCRIPTION("Analog Devices ad9852 driver");
305MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/dds/ad9910.c b/drivers/staging/iio/dds/ad9910.c
new file mode 100644
index 000000000000..e8fb75cb66ec
--- /dev/null
+++ b/drivers/staging/iio/dds/ad9910.c
@@ -0,0 +1,440 @@
1/*
2 * Driver for ADI Direct Digital Synthesis ad9910
3 *
4 * Copyright (c) 2010 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/types.h>
12#include <linux/mutex.h>
13#include <linux/device.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17
18#include "../iio.h"
19#include "../sysfs.h"
20
21#define DRV_NAME "ad9910"
22
23#define CFR1 0x0
24#define CFR2 0x1
25#define CFR3 0x2
26
27#define AUXDAC 0x3
28#define IOUPD 0x4
29#define FTW 0x7
30#define POW 0x8
31#define ASF 0x9
32#define MULTC 0x0A
33#define DIG_RAMPL 0x0B
34#define DIG_RAMPS 0x0C
35#define DIG_RAMPR 0x0D
36#define SIN_TONEP0 0x0E
37#define SIN_TONEP1 0x0F
38#define SIN_TONEP2 0x10
39#define SIN_TONEP3 0x11
40#define SIN_TONEP4 0x12
41#define SIN_TONEP5 0x13
42#define SIN_TONEP6 0x14
43#define SIN_TONEP7 0x15
44
45#define RAM_ENABLE (1 << 7)
46
47#define MANUAL_OSK (1 << 7)
48#define INVSIC (1 << 6)
49#define DDS_SINEOP (1)
50
51#define AUTO_OSK (1)
52#define OSKEN (1 << 1)
53#define LOAD_ARR (1 << 2)
54#define CLR_PHA (1 << 3)
55#define CLR_DIG (1 << 4)
56#define ACLR_PHA (1 << 5)
57#define ACLR_DIG (1 << 6)
58#define LOAD_LRR (1 << 7)
59
60#define LSB_FST (1)
61#define SDIO_IPT (1 << 1)
62#define EXT_PWD (1 << 3)
63#define ADAC_PWD (1 << 4)
64#define REFCLK_PWD (1 << 5)
65#define DAC_PWD (1 << 6)
66#define DIG_PWD (1 << 7)
67
68#define ENA_AMP (1)
69#define READ_FTW (1)
70#define DIGR_LOW (1 << 1)
71#define DIGR_HIGH (1 << 2)
72#define DIGR_ENA (1 << 3)
73#define SYNCCLK_ENA (1 << 6)
74#define ITER_IOUPD (1 << 7)
75
76#define TX_ENA (1 << 1)
77#define PDCLK_INV (1 << 2)
78#define PDCLK_ENB (1 << 3)
79
80#define PARA_ENA (1 << 4)
81#define SYNC_DIS (1 << 5)
82#define DATA_ASS (1 << 6)
83#define MATCH_ENA (1 << 7)
84
85#define PLL_ENA (1)
86#define PFD_RST (1 << 2)
87#define REFCLK_RST (1 << 6)
88#define REFCLK_BYP (1 << 7)
89
90/* Register format: 1 byte addr + value */
91struct ad9910_config {
92 u8 auxdac[5];
93 u8 ioupd[5];
94 u8 ftw[5];
95 u8 pow[3];
96 u8 asf[5];
97 u8 multc[5];
98 u8 dig_rampl[9];
99 u8 dig_ramps[9];
100 u8 dig_rampr[5];
101 u8 sin_tonep0[9];
102 u8 sin_tonep1[9];
103 u8 sin_tonep2[9];
104 u8 sin_tonep3[9];
105 u8 sin_tonep4[9];
106 u8 sin_tonep5[9];
107 u8 sin_tonep6[9];
108 u8 sin_tonep7[9];
109};
110
111struct ad9910_state {
112 struct mutex lock;
113 struct iio_dev *idev;
114 struct spi_device *sdev;
115};
116
117static ssize_t ad9910_set_parameter(struct device *dev,
118 struct device_attribute *attr,
119 const char *buf,
120 size_t len)
121{
122 struct spi_message msg;
123 struct spi_transfer xfer;
124 int ret;
125 struct ad9910_config *config = (struct ad9910_config *)buf;
126 struct iio_dev *idev = dev_get_drvdata(dev);
127 struct ad9910_state *st = idev->dev_data;
128
129 xfer.len = 5;
130 xfer.tx_buf = &config->auxdac[0];
131 mutex_lock(&st->lock);
132
133 spi_message_init(&msg);
134 spi_message_add_tail(&xfer, &msg);
135 ret = spi_sync(st->sdev, &msg);
136 if (ret)
137 goto error_ret;
138
139 xfer.len = 5;
140 xfer.tx_buf = &config->ioupd[0];
141
142 spi_message_init(&msg);
143 spi_message_add_tail(&xfer, &msg);
144 ret = spi_sync(st->sdev, &msg);
145 if (ret)
146 goto error_ret;
147
148 xfer.len = 5;
149 xfer.tx_buf = &config->ftw[0];
150
151 spi_message_init(&msg);
152 spi_message_add_tail(&xfer, &msg);
153 ret = spi_sync(st->sdev, &msg);
154 if (ret)
155 goto error_ret;
156
157 xfer.len = 3;
158 xfer.tx_buf = &config->pow[0];
159
160 spi_message_init(&msg);
161 spi_message_add_tail(&xfer, &msg);
162 ret = spi_sync(st->sdev, &msg);
163 if (ret)
164 goto error_ret;
165
166 xfer.len = 5;
167 xfer.tx_buf = &config->asf[0];
168
169 spi_message_init(&msg);
170 spi_message_add_tail(&xfer, &msg);
171 ret = spi_sync(st->sdev, &msg);
172 if (ret)
173 goto error_ret;
174
175 xfer.len = 5;
176 xfer.tx_buf = &config->multc[0];
177
178 spi_message_init(&msg);
179 spi_message_add_tail(&xfer, &msg);
180 ret = spi_sync(st->sdev, &msg);
181 if (ret)
182 goto error_ret;
183
184 xfer.len = 9;
185 xfer.tx_buf = &config->dig_rampl[0];
186
187 spi_message_init(&msg);
188 spi_message_add_tail(&xfer, &msg);
189 ret = spi_sync(st->sdev, &msg);
190 if (ret)
191 goto error_ret;
192
193 xfer.len = 9;
194 xfer.tx_buf = &config->dig_ramps[0];
195
196 spi_message_init(&msg);
197 spi_message_add_tail(&xfer, &msg);
198 ret = spi_sync(st->sdev, &msg);
199 if (ret)
200 goto error_ret;
201
202 xfer.len = 5;
203 xfer.tx_buf = &config->dig_rampr[0];
204
205 spi_message_init(&msg);
206 spi_message_add_tail(&xfer, &msg);
207 ret = spi_sync(st->sdev, &msg);
208 if (ret)
209 goto error_ret;
210
211 xfer.len = 9;
212 xfer.tx_buf = &config->sin_tonep0[0];
213
214 spi_message_init(&msg);
215 spi_message_add_tail(&xfer, &msg);
216 ret = spi_sync(st->sdev, &msg);
217 if (ret)
218 goto error_ret;
219
220 xfer.len = 9;
221 xfer.tx_buf = &config->sin_tonep1[0];
222
223 spi_message_init(&msg);
224 spi_message_add_tail(&xfer, &msg);
225 ret = spi_sync(st->sdev, &msg);
226 if (ret)
227 goto error_ret;
228
229 xfer.len = 9;
230 xfer.tx_buf = &config->sin_tonep2[0];
231
232 spi_message_init(&msg);
233 spi_message_add_tail(&xfer, &msg);
234 ret = spi_sync(st->sdev, &msg);
235 if (ret)
236 goto error_ret;
237 xfer.len = 9;
238 xfer.tx_buf = &config->sin_tonep3[0];
239
240 spi_message_init(&msg);
241 spi_message_add_tail(&xfer, &msg);
242 ret = spi_sync(st->sdev, &msg);
243 if (ret)
244 goto error_ret;
245
246 xfer.len = 9;
247 xfer.tx_buf = &config->sin_tonep4[0];
248
249 spi_message_init(&msg);
250 spi_message_add_tail(&xfer, &msg);
251 ret = spi_sync(st->sdev, &msg);
252 if (ret)
253 goto error_ret;
254
255 xfer.len = 9;
256 xfer.tx_buf = &config->sin_tonep5[0];
257
258 spi_message_init(&msg);
259 spi_message_add_tail(&xfer, &msg);
260 ret = spi_sync(st->sdev, &msg);
261 if (ret)
262 goto error_ret;
263
264 xfer.len = 9;
265 xfer.tx_buf = &config->sin_tonep6[0];
266
267 spi_message_init(&msg);
268 spi_message_add_tail(&xfer, &msg);
269 ret = spi_sync(st->sdev, &msg);
270 if (ret)
271 goto error_ret;
272
273 xfer.len = 9;
274 xfer.tx_buf = &config->sin_tonep7[0];
275
276 spi_message_init(&msg);
277 spi_message_add_tail(&xfer, &msg);
278 ret = spi_sync(st->sdev, &msg);
279 if (ret)
280 goto error_ret;
281error_ret:
282 mutex_unlock(&st->lock);
283
284 return ret ? ret : len;
285}
286
287static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9910_set_parameter, 0);
288
289static void ad9910_init(struct ad9910_state *st)
290{
291 struct spi_message msg;
292 struct spi_transfer xfer;
293 int ret;
294 u8 cfr[5];
295
296 cfr[0] = CFR1;
297 cfr[1] = 0;
298 cfr[2] = MANUAL_OSK | INVSIC | DDS_SINEOP;
299 cfr[3] = AUTO_OSK | OSKEN | ACLR_PHA | ACLR_DIG | LOAD_LRR;
300 cfr[4] = 0;
301
302 mutex_lock(&st->lock);
303
304 xfer.len = 5;
305 xfer.tx_buf = &cfr;
306
307 spi_message_init(&msg);
308 spi_message_add_tail(&xfer, &msg);
309 ret = spi_sync(st->sdev, &msg);
310 if (ret)
311 goto error_ret;
312
313 cfr[0] = CFR2;
314 cfr[1] = ENA_AMP;
315 cfr[2] = READ_FTW | DIGR_ENA | ITER_IOUPD;
316 cfr[3] = TX_ENA | PDCLK_INV | PDCLK_ENB;
317 cfr[4] = PARA_ENA;
318
319 xfer.len = 5;
320 xfer.tx_buf = &cfr;
321
322 spi_message_init(&msg);
323 spi_message_add_tail(&xfer, &msg);
324 ret = spi_sync(st->sdev, &msg);
325 if (ret)
326 goto error_ret;
327
328 cfr[0] = CFR3;
329 cfr[1] = PLL_ENA;
330 cfr[2] = 0;
331 cfr[3] = REFCLK_RST | REFCLK_BYP;
332 cfr[4] = 0;
333
334 xfer.len = 5;
335 xfer.tx_buf = &cfr;
336
337 spi_message_init(&msg);
338 spi_message_add_tail(&xfer, &msg);
339 ret = spi_sync(st->sdev, &msg);
340 if (ret)
341 goto error_ret;
342
343error_ret:
344 mutex_unlock(&st->lock);
345
346
347
348}
349
350static struct attribute *ad9910_attributes[] = {
351 &iio_dev_attr_dds.dev_attr.attr,
352 NULL,
353};
354
355static const struct attribute_group ad9910_attribute_group = {
356 .name = DRV_NAME,
357 .attrs = ad9910_attributes,
358};
359
360static int __devinit ad9910_probe(struct spi_device *spi)
361{
362 struct ad9910_state *st;
363 int ret = 0;
364
365 st = kzalloc(sizeof(*st), GFP_KERNEL);
366 if (st == NULL) {
367 ret = -ENOMEM;
368 goto error_ret;
369 }
370 spi_set_drvdata(spi, st);
371
372 mutex_init(&st->lock);
373 st->sdev = spi;
374
375 st->idev = iio_allocate_device();
376 if (st->idev == NULL) {
377 ret = -ENOMEM;
378 goto error_free_st;
379 }
380 st->idev->dev.parent = &spi->dev;
381 st->idev->num_interrupt_lines = 0;
382 st->idev->event_attrs = NULL;
383
384 st->idev->attrs = &ad9910_attribute_group;
385 st->idev->dev_data = (void *)(st);
386 st->idev->driver_module = THIS_MODULE;
387 st->idev->modes = INDIO_DIRECT_MODE;
388
389 ret = iio_device_register(st->idev);
390 if (ret)
391 goto error_free_dev;
392 spi->max_speed_hz = 2000000;
393 spi->mode = SPI_MODE_3;
394 spi->bits_per_word = 8;
395 spi_setup(spi);
396 ad9910_init(st);
397 return 0;
398
399error_free_dev:
400 iio_free_device(st->idev);
401error_free_st:
402 kfree(st);
403error_ret:
404 return ret;
405}
406
407static int __devexit ad9910_remove(struct spi_device *spi)
408{
409 struct ad9910_state *st = spi_get_drvdata(spi);
410
411 iio_device_unregister(st->idev);
412 kfree(st);
413
414 return 0;
415}
416
417static struct spi_driver ad9910_driver = {
418 .driver = {
419 .name = DRV_NAME,
420 .owner = THIS_MODULE,
421 },
422 .probe = ad9910_probe,
423 .remove = __devexit_p(ad9910_remove),
424};
425
426static __init int ad9910_spi_init(void)
427{
428 return spi_register_driver(&ad9910_driver);
429}
430module_init(ad9910_spi_init);
431
432static __exit void ad9910_spi_exit(void)
433{
434 spi_unregister_driver(&ad9910_driver);
435}
436module_exit(ad9910_spi_exit);
437
438MODULE_AUTHOR("Cliff Cai");
439MODULE_DESCRIPTION("Analog Devices ad9910 driver");
440MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/dds/ad9951.c b/drivers/staging/iio/dds/ad9951.c
new file mode 100644
index 000000000000..57eddf6d4713
--- /dev/null
+++ b/drivers/staging/iio/dds/ad9951.c
@@ -0,0 +1,249 @@
1/*
2 * Driver for ADI Direct Digital Synthesis ad9951
3 *
4 * Copyright (c) 2010 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/types.h>
12#include <linux/mutex.h>
13#include <linux/device.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17
18#include "../iio.h"
19#include "../sysfs.h"
20
21#define DRV_NAME "ad9951"
22
23#define CFR1 0x0
24#define CFR2 0x1
25
26#define AUTO_OSK (1)
27#define OSKEN (1 << 1)
28#define LOAD_ARR (1 << 2)
29
30#define AUTO_SYNC (1 << 7)
31
32#define LSB_FST (1)
33#define SDIO_IPT (1 << 1)
34#define CLR_PHA (1 << 2)
35#define SINE_OPT (1 << 4)
36#define ACLR_PHA (1 << 5)
37
38#define VCO_RANGE (1 << 2)
39
40#define CRS_OPT (1 << 1)
41#define HMANU_SYNC (1 << 2)
42#define HSPD_SYNC (1 << 3)
43
44/* Register format: 1 byte addr + value */
45struct ad9951_config {
46 u8 asf[3];
47 u8 arr[2];
48 u8 ftw0[5];
49 u8 ftw1[3];
50};
51
52struct ad9951_state {
53 struct mutex lock;
54 struct iio_dev *idev;
55 struct spi_device *sdev;
56};
57
58static ssize_t ad9951_set_parameter(struct device *dev,
59 struct device_attribute *attr,
60 const char *buf,
61 size_t len)
62{
63 struct spi_message msg;
64 struct spi_transfer xfer;
65 int ret;
66 struct ad9951_config *config = (struct ad9951_config *)buf;
67 struct iio_dev *idev = dev_get_drvdata(dev);
68 struct ad9951_state *st = idev->dev_data;
69
70 xfer.len = 3;
71 xfer.tx_buf = &config->asf[0];
72 mutex_lock(&st->lock);
73
74 spi_message_init(&msg);
75 spi_message_add_tail(&xfer, &msg);
76 ret = spi_sync(st->sdev, &msg);
77 if (ret)
78 goto error_ret;
79
80 xfer.len = 2;
81 xfer.tx_buf = &config->arr[0];
82
83 spi_message_init(&msg);
84 spi_message_add_tail(&xfer, &msg);
85 ret = spi_sync(st->sdev, &msg);
86 if (ret)
87 goto error_ret;
88
89 xfer.len = 5;
90 xfer.tx_buf = &config->ftw0[0];
91
92 spi_message_init(&msg);
93 spi_message_add_tail(&xfer, &msg);
94 ret = spi_sync(st->sdev, &msg);
95 if (ret)
96 goto error_ret;
97
98 xfer.len = 3;
99 xfer.tx_buf = &config->ftw1[0];
100
101 spi_message_init(&msg);
102 spi_message_add_tail(&xfer, &msg);
103 ret = spi_sync(st->sdev, &msg);
104 if (ret)
105 goto error_ret;
106error_ret:
107 mutex_unlock(&st->lock);
108
109 return ret ? ret : len;
110}
111
112static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9951_set_parameter, 0);
113
114static void ad9951_init(struct ad9951_state *st)
115{
116 struct spi_message msg;
117 struct spi_transfer xfer;
118 int ret;
119 u8 cfr[5];
120
121 cfr[0] = CFR1;
122 cfr[1] = 0;
123 cfr[2] = LSB_FST | CLR_PHA | SINE_OPT | ACLR_PHA;
124 cfr[3] = AUTO_OSK | OSKEN | LOAD_ARR;
125 cfr[4] = 0;
126
127 mutex_lock(&st->lock);
128
129 xfer.len = 5;
130 xfer.tx_buf = &cfr;
131
132 spi_message_init(&msg);
133 spi_message_add_tail(&xfer, &msg);
134 ret = spi_sync(st->sdev, &msg);
135 if (ret)
136 goto error_ret;
137
138 cfr[0] = CFR2;
139 cfr[1] = VCO_RANGE;
140 cfr[2] = HSPD_SYNC;
141 cfr[3] = 0;
142
143 xfer.len = 4;
144 xfer.tx_buf = &cfr;
145
146 spi_message_init(&msg);
147 spi_message_add_tail(&xfer, &msg);
148 ret = spi_sync(st->sdev, &msg);
149 if (ret)
150 goto error_ret;
151
152error_ret:
153 mutex_unlock(&st->lock);
154
155
156
157}
158
159static struct attribute *ad9951_attributes[] = {
160 &iio_dev_attr_dds.dev_attr.attr,
161 NULL,
162};
163
164static const struct attribute_group ad9951_attribute_group = {
165 .name = DRV_NAME,
166 .attrs = ad9951_attributes,
167};
168
169static int __devinit ad9951_probe(struct spi_device *spi)
170{
171 struct ad9951_state *st;
172 int ret = 0;
173
174 st = kzalloc(sizeof(*st), GFP_KERNEL);
175 if (st == NULL) {
176 ret = -ENOMEM;
177 goto error_ret;
178 }
179 spi_set_drvdata(spi, st);
180
181 mutex_init(&st->lock);
182 st->sdev = spi;
183
184 st->idev = iio_allocate_device();
185 if (st->idev == NULL) {
186 ret = -ENOMEM;
187 goto error_free_st;
188 }
189 st->idev->dev.parent = &spi->dev;
190 st->idev->num_interrupt_lines = 0;
191 st->idev->event_attrs = NULL;
192
193 st->idev->attrs = &ad9951_attribute_group;
194 st->idev->dev_data = (void *)(st);
195 st->idev->driver_module = THIS_MODULE;
196 st->idev->modes = INDIO_DIRECT_MODE;
197
198 ret = iio_device_register(st->idev);
199 if (ret)
200 goto error_free_dev;
201 spi->max_speed_hz = 2000000;
202 spi->mode = SPI_MODE_3;
203 spi->bits_per_word = 8;
204 spi_setup(spi);
205 ad9951_init(st);
206 return 0;
207
208error_free_dev:
209 iio_free_device(st->idev);
210error_free_st:
211 kfree(st);
212error_ret:
213 return ret;
214}
215
216static int __devexit ad9951_remove(struct spi_device *spi)
217{
218 struct ad9951_state *st = spi_get_drvdata(spi);
219
220 iio_device_unregister(st->idev);
221 kfree(st);
222
223 return 0;
224}
225
226static struct spi_driver ad9951_driver = {
227 .driver = {
228 .name = DRV_NAME,
229 .owner = THIS_MODULE,
230 },
231 .probe = ad9951_probe,
232 .remove = __devexit_p(ad9951_remove),
233};
234
235static __init int ad9951_spi_init(void)
236{
237 return spi_register_driver(&ad9951_driver);
238}
239module_init(ad9951_spi_init);
240
241static __exit void ad9951_spi_exit(void)
242{
243 spi_unregister_driver(&ad9951_driver);
244}
245module_exit(ad9951_spi_exit);
246
247MODULE_AUTHOR("Cliff Cai");
248MODULE_DESCRIPTION("Analog Devices ad9951 driver");
249MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/dds/dds.h b/drivers/staging/iio/dds/dds.h
new file mode 100644
index 000000000000..d8ac3a93baf6
--- /dev/null
+++ b/drivers/staging/iio/dds/dds.h
@@ -0,0 +1,110 @@
1/*
2 * dds.h - sysfs attributes associated with DDS devices
3 *
4 * Copyright (c) 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9/**
10 * /sys/bus/iio/devices/.../ddsX_freqY
11 */
12
13#define IIO_DEV_ATTR_FREQ(_channel, _num, _mode, _show, _store, _addr) \
14 IIO_DEVICE_ATTR(dds##_channel##_freq##_num, \
15 _mode, _show, _store, _addr)
16
17/**
18 * /sys/bus/iio/devices/.../ddsX_freqY_scale
19 */
20
21#define IIO_CONST_ATTR_FREQ_SCALE(_channel, _string) \
22 IIO_CONST_ATTR(dds##_channel##_freq_scale, _string)
23
24/**
25 * /sys/bus/iio/devices/.../ddsX_freqsymbol
26 */
27
28#define IIO_DEV_ATTR_FREQSYMBOL(_channel, _mode, _show, _store, _addr) \
29 IIO_DEVICE_ATTR(dds##_channel##_freqsymbol, \
30 _mode, _show, _store, _addr);
31
32/**
33 * /sys/bus/iio/devices/.../ddsX_phaseY
34 */
35
36#define IIO_DEV_ATTR_PHASE(_channel, _num, _mode, _show, _store, _addr) \
37 IIO_DEVICE_ATTR(dds##_channel##_phase##_num, \
38 _mode, _show, _store, _addr)
39
40/**
41 * /sys/bus/iio/devices/.../ddsX_phaseY_scale
42 */
43
44#define IIO_CONST_ATTR_PHASE_SCALE(_channel, _string) \
45 IIO_CONST_ATTR(dds##_channel##_phase_scale, _string)
46
47/**
48 * /sys/bus/iio/devices/.../ddsX_phasesymbol
49 */
50
51#define IIO_DEV_ATTR_PHASESYMBOL(_channel, _mode, _show, _store, _addr) \
52 IIO_DEVICE_ATTR(dds##_channel##_phasesymbol, \
53 _mode, _show, _store, _addr);
54
55/**
56 * /sys/bus/iio/devices/.../ddsX_pincontrol_en
57 */
58
59#define IIO_DEV_ATTR_PINCONTROL_EN(_channel, _mode, _show, _store, _addr)\
60 IIO_DEVICE_ATTR(dds##_channel##_pincontrol_en, \
61 _mode, _show, _store, _addr);
62
63/**
64 * /sys/bus/iio/devices/.../ddsX_pincontrol_freq_en
65 */
66
67#define IIO_DEV_ATTR_PINCONTROL_FREQ_EN(_channel, _mode, _show, _store, _addr)\
68 IIO_DEVICE_ATTR(dds##_channel##_pincontrol_freq_en, \
69 _mode, _show, _store, _addr);
70
71/**
72 * /sys/bus/iio/devices/.../ddsX_pincontrol_phase_en
73 */
74
75#define IIO_DEV_ATTR_PINCONTROL_PHASE_EN(_channel, _mode, _show, _store, _addr)\
76 IIO_DEVICE_ATTR(dds##_channel##_pincontrol_phase_en, \
77 _mode, _show, _store, _addr);
78
79/**
80 * /sys/bus/iio/devices/.../ddsX_out_enable
81 */
82
83#define IIO_DEV_ATTR_OUT_ENABLE(_channel, _mode, _show, _store, _addr) \
84 IIO_DEVICE_ATTR(dds##_channel##_out_enable, \
85 _mode, _show, _store, _addr);
86
87/**
88 * /sys/bus/iio/devices/.../ddsX_outY_enable
89 */
90
91#define IIO_DEV_ATTR_OUTY_ENABLE(_channel, _output, \
92 _mode, _show, _store, _addr) \
93 IIO_DEVICE_ATTR(dds##_channel##_out##_output##_enable, \
94 _mode, _show, _store, _addr);
95
96/**
97 * /sys/bus/iio/devices/.../ddsX_outY_wavetype
98 */
99
100#define IIO_DEV_ATTR_OUT_WAVETYPE(_channel, _output, _store, _addr) \
101 IIO_DEVICE_ATTR(dds##_channel##_out##_output##_wavetype, \
102 S_IWUSR, NULL, _store, _addr);
103
104/**
105 * /sys/bus/iio/devices/.../ddsX_outY_wavetype_available
106 */
107
108#define IIO_CONST_ATTR_OUT_WAVETYPES_AVAILABLE(_channel, _output, _modes)\
109 IIO_CONST_ATTR(dds##_channel##_out##_output##_wavetype_available,\
110 _modes);
diff --git a/drivers/staging/iio/gyro/Kconfig b/drivers/staging/iio/gyro/Kconfig
index c4043610c0df..236f15fdbfc9 100644
--- a/drivers/staging/iio/gyro/Kconfig
+++ b/drivers/staging/iio/gyro/Kconfig
@@ -3,11 +3,45 @@
3# 3#
4comment "Digital gyroscope sensors" 4comment "Digital gyroscope sensors"
5 5
6config ADIS16060
7 tristate "Analog Devices ADIS16060 Yaw Rate Gyroscope with SPI driver"
8 depends on SPI
9 help
10 Say yes here to build support for Analog Devices adis16060 wide bandwidth
11 yaw rate gyroscope with SPI.
12
13config ADIS16080
14 tristate "Analog Devices ADIS16080/100 Yaw Rate Gyroscope with SPI driver"
15 depends on SPI
16 help
17 Say yes here to build support for Analog Devices adis16080/100 Yaw Rate
18 Gyroscope with SPI.
19
20config ADIS16130
21 tristate "Analog Devices ADIS16130 High Precision Angular Rate Sensor driver"
22 depends on SPI
23 help
24 Say yes here to build support for Analog Devices ADIS16130 High Precision
25 Angular Rate Sensor driver.
26
6config ADIS16260 27config ADIS16260
7 tristate "Analog Devices ADIS16260/5 Digital Gyroscope Sensor SPI driver" 28 tristate "Analog Devices ADIS16260 ADIS16265 Digital Gyroscope Sensor SPI driver"
8 depends on SPI 29 depends on SPI
9 select IIO_TRIGGER if IIO_RING_BUFFER 30 select IIO_TRIGGER if IIO_RING_BUFFER
10 select IIO_SW_RING if IIO_RING_BUFFER 31 select IIO_SW_RING if IIO_RING_BUFFER
11 help 32 help
12 Say yes here to build support for Analog Devices adis16260/5 33 Say yes here to build support for Analog Devices ADIS16260 ADIS16265
13 programmable digital gyroscope sensor. 34 programmable digital gyroscope sensor.
35
36 This driver can also be built as a module. If so, the module
37 will be called adis16260.
38
39config ADIS16251
40 tristate "Analog Devices ADIS16251 Digital Gyroscope Sensor SPI driver"
41 depends on SPI
42 help
43 Say yes here to build support for Analog Devices adis16261 programmable
44 digital gyroscope sensor.
45
46 This driver can also be built as a module. If so, the module
47 will be called adis16251.
diff --git a/drivers/staging/iio/gyro/Makefile b/drivers/staging/iio/gyro/Makefile
index b5f0dc01122c..2764c15025a5 100644
--- a/drivers/staging/iio/gyro/Makefile
+++ b/drivers/staging/iio/gyro/Makefile
@@ -2,6 +2,18 @@
2# Makefile for digital gyroscope sensor drivers 2# Makefile for digital gyroscope sensor drivers
3# 3#
4 4
5adis16060-y := adis16060_core.o
6obj-$(CONFIG_ADIS16060) += adis16060.o
7
8adis16080-y := adis16080_core.o
9obj-$(CONFIG_ADIS16080) += adis16080.o
10
11adis16130-y := adis16130_core.o
12obj-$(CONFIG_ADIS16130) += adis16130.o
13
5adis16260-y := adis16260_core.o 14adis16260-y := adis16260_core.o
6adis16260-$(CONFIG_IIO_RING_BUFFER) += adis16260_ring.o adis16260_trigger.o 15adis16260-$(CONFIG_IIO_RING_BUFFER) += adis16260_ring.o adis16260_trigger.o
7obj-$(CONFIG_ADIS16260) += adis16260.o 16obj-$(CONFIG_ADIS16260) += adis16260.o
17
18adis16251-y := adis16251_core.o
19obj-$(CONFIG_ADIS16251) += adis16251.o
diff --git a/drivers/staging/iio/gyro/adis16060.h b/drivers/staging/iio/gyro/adis16060.h
new file mode 100644
index 000000000000..5c00e5385ee0
--- /dev/null
+++ b/drivers/staging/iio/gyro/adis16060.h
@@ -0,0 +1,101 @@
1#ifndef SPI_ADIS16060_H_
2#define SPI_ADIS16060_H_
3
4#define ADIS16060_GYRO 0x20 /* Measure Angular Rate (Gyro) */
5#define ADIS16060_SUPPLY_OUT 0x10 /* Measure Temperature */
6#define ADIS16060_AIN2 0x80 /* Measure AIN2 */
7#define ADIS16060_AIN1 0x40 /* Measure AIN1 */
8#define ADIS16060_TEMP_OUT 0x22 /* Set Positive Self-Test and Output for Angular Rate */
9#define ADIS16060_ANGL_OUT 0x21 /* Set Negative Self-Test and Output for Angular Rate */
10
11#define ADIS16060_MAX_TX 3
12#define ADIS16060_MAX_RX 3
13
14/**
15 * struct adis16060_state - device instance specific data
16 * @us_w: actual spi_device to write data
17 * @work_trigger_to_ring: bh for triggered event handling
18 * @inter: used to check if new interrupt has been triggered
19 * @last_timestamp: passing timestamp from th to bh of interrupt handler
20 * @indio_dev: industrial I/O device structure
21 * @trig: data ready trigger registered with iio
22 * @tx: transmit buffer
23 * @rx: recieve buffer
24 * @buf_lock: mutex to protect tx and rx
25 **/
26struct adis16060_state {
27 struct spi_device *us_w;
28 struct spi_device *us_r;
29 struct work_struct work_trigger_to_ring;
30 s64 last_timestamp;
31 struct iio_dev *indio_dev;
32 struct iio_trigger *trig;
33 u8 *tx;
34 u8 *rx;
35 struct mutex buf_lock;
36};
37
38#if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
39/* At the moment triggers are only used for ring buffer
40 * filling. This may change!
41 */
42
43enum adis16060_scan {
44 ADIS16060_SCAN_GYRO,
45 ADIS16060_SCAN_TEMP,
46 ADIS16060_SCAN_ADC_1,
47 ADIS16060_SCAN_ADC_2,
48};
49
50void adis16060_remove_trigger(struct iio_dev *indio_dev);
51int adis16060_probe_trigger(struct iio_dev *indio_dev);
52
53ssize_t adis16060_read_data_from_ring(struct device *dev,
54 struct device_attribute *attr,
55 char *buf);
56
57
58int adis16060_configure_ring(struct iio_dev *indio_dev);
59void adis16060_unconfigure_ring(struct iio_dev *indio_dev);
60
61int adis16060_initialize_ring(struct iio_ring_buffer *ring);
62void adis16060_uninitialize_ring(struct iio_ring_buffer *ring);
63#else /* CONFIG_IIO_RING_BUFFER */
64
65static inline void adis16060_remove_trigger(struct iio_dev *indio_dev)
66{
67}
68
69static inline int adis16060_probe_trigger(struct iio_dev *indio_dev)
70{
71 return 0;
72}
73
74static inline ssize_t
75adis16060_read_data_from_ring(struct device *dev,
76 struct device_attribute *attr,
77 char *buf)
78{
79 return 0;
80}
81
82static int adis16060_configure_ring(struct iio_dev *indio_dev)
83{
84 return 0;
85}
86
87static inline void adis16060_unconfigure_ring(struct iio_dev *indio_dev)
88{
89}
90
91static inline int adis16060_initialize_ring(struct iio_ring_buffer *ring)
92{
93 return 0;
94}
95
96static inline void adis16060_uninitialize_ring(struct iio_ring_buffer *ring)
97{
98}
99
100#endif /* CONFIG_IIO_RING_BUFFER */
101#endif /* SPI_ADIS16060_H_ */
diff --git a/drivers/staging/iio/gyro/adis16060_core.c b/drivers/staging/iio/gyro/adis16060_core.c
new file mode 100644
index 000000000000..fc48aca04bd3
--- /dev/null
+++ b/drivers/staging/iio/gyro/adis16060_core.c
@@ -0,0 +1,319 @@
1/*
2 * ADIS16060 Wide Bandwidth Yaw Rate Gyroscope with SPI driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "gyro.h"
24#include "../adc/adc.h"
25
26#include "adis16060.h"
27
28#define DRIVER_NAME "adis16060"
29
30struct adis16060_state *adis16060_st;
31
32int adis16060_spi_write(struct device *dev,
33 u8 val)
34{
35 int ret;
36 struct iio_dev *indio_dev = dev_get_drvdata(dev);
37 struct adis16060_state *st = iio_dev_get_devdata(indio_dev);
38
39 mutex_lock(&st->buf_lock);
40 st->tx[0] = 0;
41 st->tx[1] = 0;
42 st->tx[2] = val; /* The last 8 bits clocked in are latched */
43
44 ret = spi_write(st->us_w, st->tx, 3);
45 mutex_unlock(&st->buf_lock);
46
47 return ret;
48}
49
50int adis16060_spi_read(struct device *dev,
51 u16 *val)
52{
53 int ret;
54 struct iio_dev *indio_dev = dev_get_drvdata(dev);
55 struct adis16060_state *st = iio_dev_get_devdata(indio_dev);
56
57 mutex_lock(&st->buf_lock);
58
59 ret = spi_read(st->us_r, st->rx, 3);
60
61 /* The internal successive approximation ADC begins the conversion process
62 * on the falling edge of MSEL1 and starts to place data MSB first on the
63 * DOUT line at the 6th falling edge of SCLK
64 */
65 if (ret == 0)
66 *val = ((st->rx[0] & 0x3) << 12) | (st->rx[1] << 4) | ((st->rx[2] >> 4) & 0xF);
67 mutex_unlock(&st->buf_lock);
68
69 return ret;
70}
71
72static ssize_t adis16060_read(struct device *dev,
73 struct device_attribute *attr,
74 char *buf)
75{
76 struct iio_dev *indio_dev = dev_get_drvdata(dev);
77 u16 val;
78 ssize_t ret;
79
80 /* Take the iio_dev status lock */
81 mutex_lock(&indio_dev->mlock);
82 ret = adis16060_spi_read(dev, &val);
83 mutex_unlock(&indio_dev->mlock);
84
85 if (ret == 0)
86 return sprintf(buf, "%d\n", val);
87 else
88 return ret;
89}
90
91static ssize_t adis16060_write(struct device *dev,
92 struct device_attribute *attr,
93 const char *buf,
94 size_t len)
95{
96 int ret;
97 long val;
98
99 ret = strict_strtol(buf, 16, &val);
100 if (ret)
101 goto error_ret;
102 ret = adis16060_spi_write(dev, val);
103
104error_ret:
105 return ret ? ret : len;
106}
107
108#define IIO_DEV_ATTR_IN(_show) \
109 IIO_DEVICE_ATTR(in, S_IRUGO, _show, NULL, 0)
110
111#define IIO_DEV_ATTR_OUT(_store) \
112 IIO_DEVICE_ATTR(out, S_IRUGO, NULL, _store, 0)
113
114static IIO_DEV_ATTR_IN(adis16060_read);
115static IIO_DEV_ATTR_OUT(adis16060_write);
116
117static IIO_CONST_ATTR(name, "adis16060");
118
119static struct attribute *adis16060_event_attributes[] = {
120 NULL
121};
122
123static struct attribute_group adis16060_event_attribute_group = {
124 .attrs = adis16060_event_attributes,
125};
126
127static struct attribute *adis16060_attributes[] = {
128 &iio_dev_attr_in.dev_attr.attr,
129 &iio_dev_attr_out.dev_attr.attr,
130 &iio_const_attr_name.dev_attr.attr,
131 NULL
132};
133
134static const struct attribute_group adis16060_attribute_group = {
135 .attrs = adis16060_attributes,
136};
137
138static int __devinit adis16060_r_probe(struct spi_device *spi)
139{
140 int ret, regdone = 0;
141 struct adis16060_state *st = kzalloc(sizeof *st, GFP_KERNEL);
142 if (!st) {
143 ret = -ENOMEM;
144 goto error_ret;
145 }
146 /* this is only used for removal purposes */
147 spi_set_drvdata(spi, st);
148
149 /* Allocate the comms buffers */
150 st->rx = kzalloc(sizeof(*st->rx)*ADIS16060_MAX_RX, GFP_KERNEL);
151 if (st->rx == NULL) {
152 ret = -ENOMEM;
153 goto error_free_st;
154 }
155 st->tx = kzalloc(sizeof(*st->tx)*ADIS16060_MAX_TX, GFP_KERNEL);
156 if (st->tx == NULL) {
157 ret = -ENOMEM;
158 goto error_free_rx;
159 }
160 st->us_r = spi;
161 mutex_init(&st->buf_lock);
162 /* setup the industrialio driver allocated elements */
163 st->indio_dev = iio_allocate_device();
164 if (st->indio_dev == NULL) {
165 ret = -ENOMEM;
166 goto error_free_tx;
167 }
168
169 st->indio_dev->dev.parent = &spi->dev;
170 st->indio_dev->num_interrupt_lines = 1;
171 st->indio_dev->event_attrs = &adis16060_event_attribute_group;
172 st->indio_dev->attrs = &adis16060_attribute_group;
173 st->indio_dev->dev_data = (void *)(st);
174 st->indio_dev->driver_module = THIS_MODULE;
175 st->indio_dev->modes = INDIO_DIRECT_MODE;
176
177 ret = adis16060_configure_ring(st->indio_dev);
178 if (ret)
179 goto error_free_dev;
180
181 ret = iio_device_register(st->indio_dev);
182 if (ret)
183 goto error_unreg_ring_funcs;
184 regdone = 1;
185
186 ret = adis16060_initialize_ring(st->indio_dev->ring);
187 if (ret) {
188 printk(KERN_ERR "failed to initialize the ring\n");
189 goto error_unreg_ring_funcs;
190 }
191
192 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) {
193 ret = iio_register_interrupt_line(spi->irq,
194 st->indio_dev,
195 0,
196 IRQF_TRIGGER_RISING,
197 "adis16060");
198 if (ret)
199 goto error_uninitialize_ring;
200
201 ret = adis16060_probe_trigger(st->indio_dev);
202 if (ret)
203 goto error_unregister_line;
204 }
205
206 adis16060_st = st;
207 return 0;
208
209error_unregister_line:
210 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
211 iio_unregister_interrupt_line(st->indio_dev, 0);
212error_uninitialize_ring:
213 adis16060_uninitialize_ring(st->indio_dev->ring);
214error_unreg_ring_funcs:
215 adis16060_unconfigure_ring(st->indio_dev);
216error_free_dev:
217 if (regdone)
218 iio_device_unregister(st->indio_dev);
219 else
220 iio_free_device(st->indio_dev);
221error_free_tx:
222 kfree(st->tx);
223error_free_rx:
224 kfree(st->rx);
225error_free_st:
226 kfree(st);
227error_ret:
228 return ret;
229}
230
231/* fixme, confirm ordering in this function */
232static int adis16060_r_remove(struct spi_device *spi)
233{
234 struct adis16060_state *st = spi_get_drvdata(spi);
235 struct iio_dev *indio_dev = st->indio_dev;
236
237 flush_scheduled_work();
238
239 adis16060_remove_trigger(indio_dev);
240 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
241 iio_unregister_interrupt_line(indio_dev, 0);
242
243 adis16060_uninitialize_ring(indio_dev->ring);
244 adis16060_unconfigure_ring(indio_dev);
245 iio_device_unregister(indio_dev);
246 kfree(st->tx);
247 kfree(st->rx);
248 kfree(st);
249
250 return 0;
251}
252
253static int __devinit adis16060_w_probe(struct spi_device *spi)
254{
255 int ret;
256 struct adis16060_state *st = adis16060_st;
257 if (!st) {
258 ret = -ENODEV;
259 goto error_ret;
260 }
261 spi_set_drvdata(spi, st);
262 st->us_w = spi;
263 return 0;
264
265error_ret:
266 return ret;
267}
268
269static int adis16060_w_remove(struct spi_device *spi)
270{
271 return 0;
272}
273
274static struct spi_driver adis16060_r_driver = {
275 .driver = {
276 .name = "adis16060_r",
277 .owner = THIS_MODULE,
278 },
279 .probe = adis16060_r_probe,
280 .remove = __devexit_p(adis16060_r_remove),
281};
282
283static struct spi_driver adis16060_w_driver = {
284 .driver = {
285 .name = "adis16060_w",
286 .owner = THIS_MODULE,
287 },
288 .probe = adis16060_w_probe,
289 .remove = __devexit_p(adis16060_w_remove),
290};
291
292static __init int adis16060_init(void)
293{
294 int ret;
295
296 ret = spi_register_driver(&adis16060_r_driver);
297 if (ret < 0)
298 return ret;
299
300 ret = spi_register_driver(&adis16060_w_driver);
301 if (ret < 0) {
302 spi_unregister_driver(&adis16060_r_driver);
303 return ret;
304 }
305
306 return 0;
307}
308module_init(adis16060_init);
309
310static __exit void adis16060_exit(void)
311{
312 spi_unregister_driver(&adis16060_w_driver);
313 spi_unregister_driver(&adis16060_r_driver);
314}
315module_exit(adis16060_exit);
316
317MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
318MODULE_DESCRIPTION("Analog Devices ADIS16060 Yaw Rate Gyroscope with SPI driver");
319MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/gyro/adis16080.h b/drivers/staging/iio/gyro/adis16080.h
new file mode 100644
index 000000000000..3fcbe67f7c31
--- /dev/null
+++ b/drivers/staging/iio/gyro/adis16080.h
@@ -0,0 +1,102 @@
1#ifndef SPI_ADIS16080_H_
2#define SPI_ADIS16080_H_
3
4#define ADIS16080_DIN_CODE 4 /* Output data format setting. 0: Twos complement. 1: Offset binary. */
5#define ADIS16080_DIN_GYRO (0 << 10) /* Gyroscope output */
6#define ADIS16080_DIN_TEMP (1 << 10) /* Temperature output */
7#define ADIS16080_DIN_AIN1 (2 << 10)
8#define ADIS16080_DIN_AIN2 (3 << 10)
9#define ADIS16080_DIN_WRITE (1 << 15) /* 1: Write contents on DIN to control register.
10 * 0: No changes to control register.
11 */
12
13#define ADIS16080_MAX_TX 2
14#define ADIS16080_MAX_RX 2
15
16/**
17 * struct adis16080_state - device instance specific data
18 * @us: actual spi_device to write data
19 * @work_trigger_to_ring: bh for triggered event handling
20 * @inter: used to check if new interrupt has been triggered
21 * @last_timestamp: passing timestamp from th to bh of interrupt handler
22 * @indio_dev: industrial I/O device structure
23 * @trig: data ready trigger registered with iio
24 * @tx: transmit buffer
25 * @rx: recieve buffer
26 * @buf_lock: mutex to protect tx and rx
27 **/
28struct adis16080_state {
29 struct spi_device *us;
30 struct work_struct work_trigger_to_ring;
31 s64 last_timestamp;
32 struct iio_dev *indio_dev;
33 struct iio_trigger *trig;
34 u8 *tx;
35 u8 *rx;
36 struct mutex buf_lock;
37};
38
39#if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
40/* At the moment triggers are only used for ring buffer
41 * filling. This may change!
42 */
43
44enum adis16080_scan {
45 ADIS16080_SCAN_GYRO,
46 ADIS16080_SCAN_TEMP,
47 ADIS16080_SCAN_ADC_1,
48 ADIS16080_SCAN_ADC_2,
49};
50
51void adis16080_remove_trigger(struct iio_dev *indio_dev);
52int adis16080_probe_trigger(struct iio_dev *indio_dev);
53
54ssize_t adis16080_read_data_from_ring(struct device *dev,
55 struct device_attribute *attr,
56 char *buf);
57
58
59int adis16080_configure_ring(struct iio_dev *indio_dev);
60void adis16080_unconfigure_ring(struct iio_dev *indio_dev);
61
62int adis16080_initialize_ring(struct iio_ring_buffer *ring);
63void adis16080_uninitialize_ring(struct iio_ring_buffer *ring);
64#else /* CONFIG_IIO_RING_BUFFER */
65
66static inline void adis16080_remove_trigger(struct iio_dev *indio_dev)
67{
68}
69
70static inline int adis16080_probe_trigger(struct iio_dev *indio_dev)
71{
72 return 0;
73}
74
75static inline ssize_t
76adis16080_read_data_from_ring(struct device *dev,
77 struct device_attribute *attr,
78 char *buf)
79{
80 return 0;
81}
82
83static int adis16080_configure_ring(struct iio_dev *indio_dev)
84{
85 return 0;
86}
87
88static inline void adis16080_unconfigure_ring(struct iio_dev *indio_dev)
89{
90}
91
92static inline int adis16080_initialize_ring(struct iio_ring_buffer *ring)
93{
94 return 0;
95}
96
97static inline void adis16080_uninitialize_ring(struct iio_ring_buffer *ring)
98{
99}
100
101#endif /* CONFIG_IIO_RING_BUFFER */
102#endif /* SPI_ADIS16080_H_ */
diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/staging/iio/gyro/adis16080_core.c
new file mode 100644
index 000000000000..0efb768db7d3
--- /dev/null
+++ b/drivers/staging/iio/gyro/adis16080_core.c
@@ -0,0 +1,271 @@
1/*
2 * ADIS16080/100 Yaw Rate Gyroscope with SPI driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "gyro.h"
24#include "../adc/adc.h"
25
26#include "adis16080.h"
27
28#define DRIVER_NAME "adis16080"
29
30struct adis16080_state *adis16080_st;
31
32int adis16080_spi_write(struct device *dev,
33 u16 val)
34{
35 int ret;
36 struct iio_dev *indio_dev = dev_get_drvdata(dev);
37 struct adis16080_state *st = iio_dev_get_devdata(indio_dev);
38
39 mutex_lock(&st->buf_lock);
40 st->tx[0] = val >> 8;
41 st->tx[1] = val;
42
43 ret = spi_write(st->us, st->tx, 2);
44 mutex_unlock(&st->buf_lock);
45
46 return ret;
47}
48
49int adis16080_spi_read(struct device *dev,
50 u16 *val)
51{
52 int ret;
53 struct iio_dev *indio_dev = dev_get_drvdata(dev);
54 struct adis16080_state *st = iio_dev_get_devdata(indio_dev);
55
56 mutex_lock(&st->buf_lock);
57
58 ret = spi_read(st->us, st->rx, 2);
59
60 if (ret == 0)
61 *val = ((st->rx[0] & 0xF) << 8) | st->rx[1];
62 mutex_unlock(&st->buf_lock);
63
64 return ret;
65}
66
67static ssize_t adis16080_read(struct device *dev,
68 struct device_attribute *attr,
69 char *buf)
70{
71 struct iio_dev *indio_dev = dev_get_drvdata(dev);
72 u16 val;
73 ssize_t ret;
74
75 /* Take the iio_dev status lock */
76 mutex_lock(&indio_dev->mlock);
77 ret = adis16080_spi_read(dev, &val);
78 mutex_unlock(&indio_dev->mlock);
79
80 if (ret == 0)
81 return sprintf(buf, "%d\n", val);
82 else
83 return ret;
84}
85
86static ssize_t adis16080_write(struct device *dev,
87 struct device_attribute *attr,
88 const char *buf,
89 size_t len)
90{
91 int ret;
92 long val;
93
94 ret = strict_strtol(buf, 16, &val);
95 if (ret)
96 goto error_ret;
97 ret = adis16080_spi_write(dev, val);
98
99error_ret:
100 return ret ? ret : len;
101}
102
103#define IIO_DEV_ATTR_IN(_show) \
104 IIO_DEVICE_ATTR(in, S_IRUGO, _show, NULL, 0)
105
106#define IIO_DEV_ATTR_OUT(_store) \
107 IIO_DEVICE_ATTR(out, S_IRUGO, NULL, _store, 0)
108
109static IIO_DEV_ATTR_IN(adis16080_read);
110static IIO_DEV_ATTR_OUT(adis16080_write);
111
112static IIO_CONST_ATTR(name, "adis16080");
113
114static struct attribute *adis16080_event_attributes[] = {
115 NULL
116};
117
118static struct attribute_group adis16080_event_attribute_group = {
119 .attrs = adis16080_event_attributes,
120};
121
122static struct attribute *adis16080_attributes[] = {
123 &iio_dev_attr_in.dev_attr.attr,
124 &iio_dev_attr_out.dev_attr.attr,
125 &iio_const_attr_name.dev_attr.attr,
126 NULL
127};
128
129static const struct attribute_group adis16080_attribute_group = {
130 .attrs = adis16080_attributes,
131};
132
133static int __devinit adis16080_probe(struct spi_device *spi)
134{
135 int ret, regdone = 0;
136 struct adis16080_state *st = kzalloc(sizeof *st, GFP_KERNEL);
137 if (!st) {
138 ret = -ENOMEM;
139 goto error_ret;
140 }
141 /* this is only used for removal purposes */
142 spi_set_drvdata(spi, st);
143
144 /* Allocate the comms buffers */
145 st->rx = kzalloc(sizeof(*st->rx)*ADIS16080_MAX_RX, GFP_KERNEL);
146 if (st->rx == NULL) {
147 ret = -ENOMEM;
148 goto error_free_st;
149 }
150 st->tx = kzalloc(sizeof(*st->tx)*ADIS16080_MAX_TX, GFP_KERNEL);
151 if (st->tx == NULL) {
152 ret = -ENOMEM;
153 goto error_free_rx;
154 }
155 st->us = spi;
156 mutex_init(&st->buf_lock);
157 /* setup the industrialio driver allocated elements */
158 st->indio_dev = iio_allocate_device();
159 if (st->indio_dev == NULL) {
160 ret = -ENOMEM;
161 goto error_free_tx;
162 }
163
164 st->indio_dev->dev.parent = &spi->dev;
165 st->indio_dev->num_interrupt_lines = 1;
166 st->indio_dev->event_attrs = &adis16080_event_attribute_group;
167 st->indio_dev->attrs = &adis16080_attribute_group;
168 st->indio_dev->dev_data = (void *)(st);
169 st->indio_dev->driver_module = THIS_MODULE;
170 st->indio_dev->modes = INDIO_DIRECT_MODE;
171
172 ret = adis16080_configure_ring(st->indio_dev);
173 if (ret)
174 goto error_free_dev;
175
176 ret = iio_device_register(st->indio_dev);
177 if (ret)
178 goto error_unreg_ring_funcs;
179 regdone = 1;
180
181 ret = adis16080_initialize_ring(st->indio_dev->ring);
182 if (ret) {
183 printk(KERN_ERR "failed to initialize the ring\n");
184 goto error_unreg_ring_funcs;
185 }
186
187 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) {
188 ret = iio_register_interrupt_line(spi->irq,
189 st->indio_dev,
190 0,
191 IRQF_TRIGGER_RISING,
192 "adis16080");
193 if (ret)
194 goto error_uninitialize_ring;
195
196 ret = adis16080_probe_trigger(st->indio_dev);
197 if (ret)
198 goto error_unregister_line;
199 }
200
201 adis16080_st = st;
202 return 0;
203
204error_unregister_line:
205 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
206 iio_unregister_interrupt_line(st->indio_dev, 0);
207error_uninitialize_ring:
208 adis16080_uninitialize_ring(st->indio_dev->ring);
209error_unreg_ring_funcs:
210 adis16080_unconfigure_ring(st->indio_dev);
211error_free_dev:
212 if (regdone)
213 iio_device_unregister(st->indio_dev);
214 else
215 iio_free_device(st->indio_dev);
216error_free_tx:
217 kfree(st->tx);
218error_free_rx:
219 kfree(st->rx);
220error_free_st:
221 kfree(st);
222error_ret:
223 return ret;
224}
225
226/* fixme, confirm ordering in this function */
227static int adis16080_remove(struct spi_device *spi)
228{
229 struct adis16080_state *st = spi_get_drvdata(spi);
230 struct iio_dev *indio_dev = st->indio_dev;
231
232 flush_scheduled_work();
233
234 adis16080_remove_trigger(indio_dev);
235 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
236 iio_unregister_interrupt_line(indio_dev, 0);
237
238 adis16080_uninitialize_ring(indio_dev->ring);
239 adis16080_unconfigure_ring(indio_dev);
240 iio_device_unregister(indio_dev);
241 kfree(st->tx);
242 kfree(st->rx);
243 kfree(st);
244
245 return 0;
246}
247
248static struct spi_driver adis16080_driver = {
249 .driver = {
250 .name = "adis16080",
251 .owner = THIS_MODULE,
252 },
253 .probe = adis16080_probe,
254 .remove = __devexit_p(adis16080_remove),
255};
256
257static __init int adis16080_init(void)
258{
259 return spi_register_driver(&adis16080_driver);
260}
261module_init(adis16080_init);
262
263static __exit void adis16080_exit(void)
264{
265 spi_unregister_driver(&adis16080_driver);
266}
267module_exit(adis16080_exit);
268
269MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
270MODULE_DESCRIPTION("Analog Devices ADIS16080/100 Yaw Rate Gyroscope with SPI driver");
271MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/gyro/adis16130.h b/drivers/staging/iio/gyro/adis16130.h
new file mode 100644
index 000000000000..ab80ef6a8961
--- /dev/null
+++ b/drivers/staging/iio/gyro/adis16130.h
@@ -0,0 +1,108 @@
1#ifndef SPI_ADIS16130_H_
2#define SPI_ADIS16130_H_
3
4#define ADIS16130_CON 0x0
5#define ADIS16130_CON_RD (1 << 6)
6#define ADIS16130_IOP 0x1
7#define ADIS16130_IOP_ALL_RDY (1 << 3) /* 1 = data-ready signal low when unread data on all channels; */
8#define ADIS16130_IOP_SYNC (1 << 0) /* 1 = synchronization enabled */
9#define ADIS16130_RATEDATA 0x8 /* Gyroscope output, rate of rotation */
10#define ADIS16130_TEMPDATA 0xA /* Temperature output */
11#define ADIS16130_RATECS 0x28 /* Gyroscope channel setup */
12#define ADIS16130_RATECS_EN (1 << 3) /* 1 = channel enable; */
13#define ADIS16130_TEMPCS 0x2A /* Temperature channel setup */
14#define ADIS16130_TEMPCS_EN (1 << 3)
15#define ADIS16130_RATECONV 0x30
16#define ADIS16130_TEMPCONV 0x32
17#define ADIS16130_MODE 0x38
18#define ADIS16130_MODE_24BIT (1 << 1) /* 1 = 24-bit resolution; */
19
20#define ADIS16130_MAX_TX 4
21#define ADIS16130_MAX_RX 4
22
23/**
24 * struct adis16130_state - device instance specific data
25 * @us: actual spi_device to write data
26 * @work_trigger_to_ring: bh for triggered event handling
27 * @inter: used to check if new interrupt has been triggered
28 * @last_timestamp: passing timestamp from th to bh of interrupt handler
29 * @indio_dev: industrial I/O device structure
30 * @trig: data ready trigger registered with iio
31 * @tx: transmit buffer
32 * @rx: recieve buffer
33 * @buf_lock: mutex to protect tx and rx
34 **/
35struct adis16130_state {
36 struct spi_device *us;
37 struct work_struct work_trigger_to_ring;
38 s64 last_timestamp;
39 struct iio_dev *indio_dev;
40 struct iio_trigger *trig;
41 u8 *tx;
42 u8 *rx;
43 u32 mode; /* 1: 24bits mode 0:16bits mode */
44 struct mutex buf_lock;
45};
46
47#if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
48/* At the moment triggers are only used for ring buffer
49 * filling. This may change!
50 */
51
52enum adis16130_scan {
53 ADIS16130_SCAN_GYRO,
54 ADIS16130_SCAN_TEMP,
55};
56
57void adis16130_remove_trigger(struct iio_dev *indio_dev);
58int adis16130_probe_trigger(struct iio_dev *indio_dev);
59
60ssize_t adis16130_read_data_from_ring(struct device *dev,
61 struct device_attribute *attr,
62 char *buf);
63
64
65int adis16130_configure_ring(struct iio_dev *indio_dev);
66void adis16130_unconfigure_ring(struct iio_dev *indio_dev);
67
68int adis16130_initialize_ring(struct iio_ring_buffer *ring);
69void adis16130_uninitialize_ring(struct iio_ring_buffer *ring);
70#else /* CONFIG_IIO_RING_BUFFER */
71
72static inline void adis16130_remove_trigger(struct iio_dev *indio_dev)
73{
74}
75
76static inline int adis16130_probe_trigger(struct iio_dev *indio_dev)
77{
78 return 0;
79}
80
81static inline ssize_t
82adis16130_read_data_from_ring(struct device *dev,
83 struct device_attribute *attr,
84 char *buf)
85{
86 return 0;
87}
88
89static int adis16130_configure_ring(struct iio_dev *indio_dev)
90{
91 return 0;
92}
93
94static inline void adis16130_unconfigure_ring(struct iio_dev *indio_dev)
95{
96}
97
98static inline int adis16130_initialize_ring(struct iio_ring_buffer *ring)
99{
100 return 0;
101}
102
103static inline void adis16130_uninitialize_ring(struct iio_ring_buffer *ring)
104{
105}
106
107#endif /* CONFIG_IIO_RING_BUFFER */
108#endif /* SPI_ADIS16130_H_ */
diff --git a/drivers/staging/iio/gyro/adis16130_core.c b/drivers/staging/iio/gyro/adis16130_core.c
new file mode 100644
index 000000000000..49ffc7b26e8a
--- /dev/null
+++ b/drivers/staging/iio/gyro/adis16130_core.c
@@ -0,0 +1,313 @@
1/*
2 * ADIS16130 Digital Output, High Precision Angular Rate Sensor driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "gyro.h"
24#include "../adc/adc.h"
25
26#include "adis16130.h"
27
28#define DRIVER_NAME "adis16130"
29
30struct adis16130_state *adis16130_st;
31
32int adis16130_spi_write(struct device *dev, u8 reg_addr,
33 u8 val)
34{
35 int ret;
36 struct iio_dev *indio_dev = dev_get_drvdata(dev);
37 struct adis16130_state *st = iio_dev_get_devdata(indio_dev);
38
39 mutex_lock(&st->buf_lock);
40 st->tx[0] = reg_addr;
41 st->tx[1] = val;
42
43 ret = spi_write(st->us, st->tx, 2);
44 mutex_unlock(&st->buf_lock);
45
46 return ret;
47}
48
49int adis16130_spi_read(struct device *dev, u8 reg_addr,
50 u32 *val)
51{
52 int ret;
53 struct iio_dev *indio_dev = dev_get_drvdata(dev);
54 struct adis16130_state *st = iio_dev_get_devdata(indio_dev);
55
56 mutex_lock(&st->buf_lock);
57
58 st->tx[0] = ADIS16130_CON_RD | reg_addr;
59 if (st->mode)
60 ret = spi_read(st->us, st->rx, 4);
61 else
62 ret = spi_read(st->us, st->rx, 3);
63
64 if (ret == 0) {
65 if (st->mode)
66 *val = (st->rx[1] << 16) | (st->rx[2] << 8) | st->rx[3];
67 else
68 *val = (st->rx[1] << 8) | st->rx[2];
69 }
70
71 mutex_unlock(&st->buf_lock);
72
73 return ret;
74}
75
76static ssize_t adis16130_gyro_read(struct device *dev,
77 struct device_attribute *attr,
78 char *buf)
79{
80 struct iio_dev *indio_dev = dev_get_drvdata(dev);
81 u32 val;
82 ssize_t ret;
83
84 /* Take the iio_dev status lock */
85 mutex_lock(&indio_dev->mlock);
86 ret = adis16130_spi_read(dev, ADIS16130_RATEDATA, &val);
87 mutex_unlock(&indio_dev->mlock);
88
89 if (ret == 0)
90 return sprintf(buf, "%d\n", val);
91 else
92 return ret;
93}
94
95static ssize_t adis16130_temp_read(struct device *dev,
96 struct device_attribute *attr,
97 char *buf)
98{
99 struct iio_dev *indio_dev = dev_get_drvdata(dev);
100 u32 val;
101 ssize_t ret;
102
103 /* Take the iio_dev status lock */
104 mutex_lock(&indio_dev->mlock);
105 ret = adis16130_spi_read(dev, ADIS16130_TEMPDATA, &val);
106 mutex_unlock(&indio_dev->mlock);
107
108 if (ret == 0)
109 return sprintf(buf, "%d\n", val);
110 else
111 return ret;
112}
113
114static ssize_t adis16130_bitsmode_read(struct device *dev,
115 struct device_attribute *attr,
116 char *buf)
117{
118 struct iio_dev *indio_dev = dev_get_drvdata(dev);
119 struct adis16130_state *st = iio_dev_get_devdata(indio_dev);
120
121 return sprintf(buf, "%d\n", st->mode);
122}
123
124static ssize_t adis16130_bitsmode_write(struct device *dev,
125 struct device_attribute *attr,
126 const char *buf,
127 size_t len)
128{
129 int ret;
130 long val;
131
132 ret = strict_strtol(buf, 16, &val);
133 if (ret)
134 goto error_ret;
135 ret = adis16130_spi_write(dev, ADIS16130_MODE, !!val);
136
137error_ret:
138 return ret ? ret : len;
139}
140
141static IIO_DEV_ATTR_TEMP_RAW(adis16130_temp_read);
142
143static IIO_CONST_ATTR(name, "adis16130");
144
145static IIO_DEV_ATTR_GYRO(adis16130_gyro_read,
146 ADIS16130_RATEDATA);
147
148#define IIO_DEV_ATTR_BITS_MODE(_mode, _show, _store, _addr) \
149 IIO_DEVICE_ATTR(bits_mode, _mode, _show, _store, _addr)
150
151static IIO_DEV_ATTR_BITS_MODE(S_IWUSR | S_IRUGO, adis16130_bitsmode_read, adis16130_bitsmode_write,
152 ADIS16130_MODE);
153
154static struct attribute *adis16130_event_attributes[] = {
155 NULL
156};
157
158static struct attribute_group adis16130_event_attribute_group = {
159 .attrs = adis16130_event_attributes,
160};
161
162static struct attribute *adis16130_attributes[] = {
163 &iio_dev_attr_temp_raw.dev_attr.attr,
164 &iio_const_attr_name.dev_attr.attr,
165 &iio_dev_attr_gyro_raw.dev_attr.attr,
166 &iio_dev_attr_bits_mode.dev_attr.attr,
167 NULL
168};
169
170static const struct attribute_group adis16130_attribute_group = {
171 .attrs = adis16130_attributes,
172};
173
174static int __devinit adis16130_probe(struct spi_device *spi)
175{
176 int ret, regdone = 0;
177 struct adis16130_state *st = kzalloc(sizeof *st, GFP_KERNEL);
178 if (!st) {
179 ret = -ENOMEM;
180 goto error_ret;
181 }
182 /* this is only used for removal purposes */
183 spi_set_drvdata(spi, st);
184
185 /* Allocate the comms buffers */
186 st->rx = kzalloc(sizeof(*st->rx)*ADIS16130_MAX_RX, GFP_KERNEL);
187 if (st->rx == NULL) {
188 ret = -ENOMEM;
189 goto error_free_st;
190 }
191 st->tx = kzalloc(sizeof(*st->tx)*ADIS16130_MAX_TX, GFP_KERNEL);
192 if (st->tx == NULL) {
193 ret = -ENOMEM;
194 goto error_free_rx;
195 }
196 st->us = spi;
197 mutex_init(&st->buf_lock);
198 /* setup the industrialio driver allocated elements */
199 st->indio_dev = iio_allocate_device();
200 if (st->indio_dev == NULL) {
201 ret = -ENOMEM;
202 goto error_free_tx;
203 }
204
205 st->indio_dev->dev.parent = &spi->dev;
206 st->indio_dev->num_interrupt_lines = 1;
207 st->indio_dev->event_attrs = &adis16130_event_attribute_group;
208 st->indio_dev->attrs = &adis16130_attribute_group;
209 st->indio_dev->dev_data = (void *)(st);
210 st->indio_dev->driver_module = THIS_MODULE;
211 st->indio_dev->modes = INDIO_DIRECT_MODE;
212 st->mode = 1;
213
214 ret = adis16130_configure_ring(st->indio_dev);
215 if (ret)
216 goto error_free_dev;
217
218 ret = iio_device_register(st->indio_dev);
219 if (ret)
220 goto error_unreg_ring_funcs;
221 regdone = 1;
222
223 ret = adis16130_initialize_ring(st->indio_dev->ring);
224 if (ret) {
225 printk(KERN_ERR "failed to initialize the ring\n");
226 goto error_unreg_ring_funcs;
227 }
228
229 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) {
230 ret = iio_register_interrupt_line(spi->irq,
231 st->indio_dev,
232 0,
233 IRQF_TRIGGER_RISING,
234 "adis16130");
235 if (ret)
236 goto error_uninitialize_ring;
237
238 ret = adis16130_probe_trigger(st->indio_dev);
239 if (ret)
240 goto error_unregister_line;
241 }
242
243 adis16130_st = st;
244 return 0;
245
246error_unregister_line:
247 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
248 iio_unregister_interrupt_line(st->indio_dev, 0);
249error_uninitialize_ring:
250 adis16130_uninitialize_ring(st->indio_dev->ring);
251error_unreg_ring_funcs:
252 adis16130_unconfigure_ring(st->indio_dev);
253error_free_dev:
254 if (regdone)
255 iio_device_unregister(st->indio_dev);
256 else
257 iio_free_device(st->indio_dev);
258error_free_tx:
259 kfree(st->tx);
260error_free_rx:
261 kfree(st->rx);
262error_free_st:
263 kfree(st);
264error_ret:
265 return ret;
266}
267
268/* fixme, confirm ordering in this function */
269static int adis16130_remove(struct spi_device *spi)
270{
271 struct adis16130_state *st = spi_get_drvdata(spi);
272 struct iio_dev *indio_dev = st->indio_dev;
273
274 flush_scheduled_work();
275
276 adis16130_remove_trigger(indio_dev);
277 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
278 iio_unregister_interrupt_line(indio_dev, 0);
279
280 adis16130_uninitialize_ring(indio_dev->ring);
281 adis16130_unconfigure_ring(indio_dev);
282 iio_device_unregister(indio_dev);
283 kfree(st->tx);
284 kfree(st->rx);
285 kfree(st);
286
287 return 0;
288}
289
290static struct spi_driver adis16130_driver = {
291 .driver = {
292 .name = "adis16130",
293 .owner = THIS_MODULE,
294 },
295 .probe = adis16130_probe,
296 .remove = __devexit_p(adis16130_remove),
297};
298
299static __init int adis16130_init(void)
300{
301 return spi_register_driver(&adis16130_driver);
302}
303module_init(adis16130_init);
304
305static __exit void adis16130_exit(void)
306{
307 spi_unregister_driver(&adis16130_driver);
308}
309module_exit(adis16130_exit);
310
311MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
312MODULE_DESCRIPTION("Analog Devices ADIS16130 High Precision Angular Rate Sensor driver");
313MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/gyro/adis16251.h b/drivers/staging/iio/gyro/adis16251.h
new file mode 100644
index 000000000000..d23852cf78e8
--- /dev/null
+++ b/drivers/staging/iio/gyro/adis16251.h
@@ -0,0 +1,185 @@
1#ifndef SPI_ADIS16251_H_
2#define SPI_ADIS16251_H_
3
4#define ADIS16251_STARTUP_DELAY 220 /* ms */
5
6#define ADIS16251_READ_REG(a) a
7#define ADIS16251_WRITE_REG(a) ((a) | 0x80)
8
9#define ADIS16251_ENDURANCE 0x00 /* Flash memory write count */
10#define ADIS16251_SUPPLY_OUT 0x02 /* Power supply measurement */
11#define ADIS16251_GYRO_OUT 0x04 /* X-axis gyroscope output */
12#define ADIS16251_AUX_ADC 0x0A /* analog input channel measurement */
13#define ADIS16251_TEMP_OUT 0x0C /* internal temperature measurement */
14#define ADIS16251_ANGL_OUT 0x0E /* angle displacement */
15#define ADIS16251_GYRO_OFF 0x14 /* Calibration, offset/bias adjustment */
16#define ADIS16251_GYRO_SCALE 0x16 /* Calibration, scale adjustment */
17#define ADIS16251_ALM_MAG1 0x20 /* Alarm 1 magnitude/polarity setting */
18#define ADIS16251_ALM_MAG2 0x22 /* Alarm 2 magnitude/polarity setting */
19#define ADIS16251_ALM_SMPL1 0x24 /* Alarm 1 dynamic rate of change setting */
20#define ADIS16251_ALM_SMPL2 0x26 /* Alarm 2 dynamic rate of change setting */
21#define ADIS16251_ALM_CTRL 0x28 /* Alarm control */
22#define ADIS16251_AUX_DAC 0x30 /* Auxiliary DAC data */
23#define ADIS16251_GPIO_CTRL 0x32 /* Control, digital I/O line */
24#define ADIS16251_MSC_CTRL 0x34 /* Control, data ready, self-test settings */
25#define ADIS16251_SMPL_PRD 0x36 /* Control, internal sample rate */
26#define ADIS16251_SENS_AVG 0x38 /* Control, dynamic range, filtering */
27#define ADIS16251_SLP_CNT 0x3A /* Control, sleep mode initiation */
28#define ADIS16251_DIAG_STAT 0x3C /* Diagnostic, error flags */
29#define ADIS16251_GLOB_CMD 0x3E /* Control, global commands */
30
31#define ADIS16251_ERROR_ACTIVE (1<<14)
32#define ADIS16251_NEW_DATA (1<<14)
33
34/* MSC_CTRL */
35#define ADIS16251_MSC_CTRL_INT_SELF_TEST (1<<10) /* Internal self-test enable */
36#define ADIS16251_MSC_CTRL_NEG_SELF_TEST (1<<9)
37#define ADIS16251_MSC_CTRL_POS_SELF_TEST (1<<8)
38#define ADIS16251_MSC_CTRL_DATA_RDY_EN (1<<2)
39#define ADIS16251_MSC_CTRL_DATA_RDY_POL_HIGH (1<<1)
40#define ADIS16251_MSC_CTRL_DATA_RDY_DIO2 (1<<0)
41
42/* SMPL_PRD */
43#define ADIS16251_SMPL_PRD_TIME_BASE (1<<7) /* Time base (tB): 0 = 1.953 ms, 1 = 60.54 ms */
44#define ADIS16251_SMPL_PRD_DIV_MASK 0x7F
45
46/* SLP_CNT */
47#define ADIS16251_SLP_CNT_POWER_OFF 0x80
48
49/* DIAG_STAT */
50#define ADIS16251_DIAG_STAT_ALARM2 (1<<9)
51#define ADIS16251_DIAG_STAT_ALARM1 (1<<8)
52#define ADIS16251_DIAG_STAT_SELF_TEST (1<<5)
53#define ADIS16251_DIAG_STAT_OVERFLOW (1<<4)
54#define ADIS16251_DIAG_STAT_SPI_FAIL (1<<3)
55#define ADIS16251_DIAG_STAT_FLASH_UPT (1<<2)
56#define ADIS16251_DIAG_STAT_POWER_HIGH (1<<1)
57#define ADIS16251_DIAG_STAT_POWER_LOW (1<<0)
58
59#define ADIS16251_DIAG_STAT_ERR_MASK (ADIS16251_DIAG_STAT_ALARM2 | \
60 ADIS16251_DIAG_STAT_ALARM1 | \
61 ADIS16251_DIAG_STAT_SELF_TEST | \
62 ADIS16251_DIAG_STAT_OVERFLOW | \
63 ADIS16251_DIAG_STAT_SPI_FAIL | \
64 ADIS16251_DIAG_STAT_FLASH_UPT | \
65 ADIS16251_DIAG_STAT_POWER_HIGH | \
66 ADIS16251_DIAG_STAT_POWER_LOW)
67
68/* GLOB_CMD */
69#define ADIS16251_GLOB_CMD_SW_RESET (1<<7)
70#define ADIS16251_GLOB_CMD_FLASH_UPD (1<<3)
71#define ADIS16251_GLOB_CMD_DAC_LATCH (1<<2)
72#define ADIS16251_GLOB_CMD_FAC_CALIB (1<<1)
73#define ADIS16251_GLOB_CMD_AUTO_NULL (1<<0)
74
75#define ADIS16251_MAX_TX 24
76#define ADIS16251_MAX_RX 24
77
78#define ADIS16251_SPI_SLOW (u32)(300 * 1000)
79#define ADIS16251_SPI_BURST (u32)(1000 * 1000)
80#define ADIS16251_SPI_FAST (u32)(2000 * 1000)
81
82/**
83 * struct adis16251_state - device instance specific data
84 * @us: actual spi_device
85 * @work_trigger_to_ring: bh for triggered event handling
86 * @inter: used to check if new interrupt has been triggered
87 * @last_timestamp: passing timestamp from th to bh of interrupt handler
88 * @indio_dev: industrial I/O device structure
89 * @trig: data ready trigger registered with iio
90 * @tx: transmit buffer
91 * @rx: recieve buffer
92 * @buf_lock: mutex to protect tx and rx
93 **/
94struct adis16251_state {
95 struct spi_device *us;
96 struct work_struct work_trigger_to_ring;
97 s64 last_timestamp;
98 struct iio_dev *indio_dev;
99 struct iio_trigger *trig;
100 u8 *tx;
101 u8 *rx;
102 struct mutex buf_lock;
103};
104
105int adis16251_spi_write_reg_8(struct device *dev,
106 u8 reg_address,
107 u8 val);
108
109int adis16251_spi_read_burst(struct device *dev, u8 *rx);
110
111int adis16251_spi_read_sequence(struct device *dev,
112 u8 *tx, u8 *rx, int num);
113
114int adis16251_set_irq(struct device *dev, bool enable);
115
116int adis16251_reset(struct device *dev);
117
118int adis16251_stop_device(struct device *dev);
119
120int adis16251_check_status(struct device *dev);
121
122#if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
123/* At the moment triggers are only used for ring buffer
124 * filling. This may change!
125 */
126
127enum adis16251_scan {
128 ADIS16251_SCAN_SUPPLY,
129 ADIS16251_SCAN_GYRO,
130 ADIS16251_SCAN_TEMP,
131 ADIS16251_SCAN_ADC_0,
132};
133
134void adis16251_remove_trigger(struct iio_dev *indio_dev);
135int adis16251_probe_trigger(struct iio_dev *indio_dev);
136
137ssize_t adis16251_read_data_from_ring(struct device *dev,
138 struct device_attribute *attr,
139 char *buf);
140
141
142int adis16251_configure_ring(struct iio_dev *indio_dev);
143void adis16251_unconfigure_ring(struct iio_dev *indio_dev);
144
145int adis16251_initialize_ring(struct iio_ring_buffer *ring);
146void adis16251_uninitialize_ring(struct iio_ring_buffer *ring);
147#else /* CONFIG_IIO_RING_BUFFER */
148
149static inline void adis16251_remove_trigger(struct iio_dev *indio_dev)
150{
151}
152
153static inline int adis16251_probe_trigger(struct iio_dev *indio_dev)
154{
155 return 0;
156}
157
158static inline ssize_t
159adis16251_read_data_from_ring(struct device *dev,
160 struct device_attribute *attr,
161 char *buf)
162{
163 return 0;
164}
165
166static int adis16251_configure_ring(struct iio_dev *indio_dev)
167{
168 return 0;
169}
170
171static inline void adis16251_unconfigure_ring(struct iio_dev *indio_dev)
172{
173}
174
175static inline int adis16251_initialize_ring(struct iio_ring_buffer *ring)
176{
177 return 0;
178}
179
180static inline void adis16251_uninitialize_ring(struct iio_ring_buffer *ring)
181{
182}
183
184#endif /* CONFIG_IIO_RING_BUFFER */
185#endif /* SPI_ADIS16251_H_ */
diff --git a/drivers/staging/iio/gyro/adis16251_core.c b/drivers/staging/iio/gyro/adis16251_core.c
new file mode 100644
index 000000000000..a0d400f7ee62
--- /dev/null
+++ b/drivers/staging/iio/gyro/adis16251_core.c
@@ -0,0 +1,777 @@
1/*
2 * ADIS16251 Programmable Digital Gyroscope Sensor Driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "gyro.h"
24#include "../adc/adc.h"
25
26#include "adis16251.h"
27
28#define DRIVER_NAME "adis16251"
29
30/* At the moment the spi framework doesn't allow global setting of cs_change.
31 * It's in the likely to be added comment at the top of spi.h.
32 * This means that use cannot be made of spi_write etc.
33 */
34
35/**
36 * adis16251_spi_write_reg_8() - write single byte to a register
37 * @dev: device associated with child of actual device (iio_dev or iio_trig)
38 * @reg_address: the address of the register to be written
39 * @val: the value to write
40 **/
41int adis16251_spi_write_reg_8(struct device *dev,
42 u8 reg_address,
43 u8 val)
44{
45 int ret;
46 struct iio_dev *indio_dev = dev_get_drvdata(dev);
47 struct adis16251_state *st = iio_dev_get_devdata(indio_dev);
48
49 mutex_lock(&st->buf_lock);
50 st->tx[0] = ADIS16251_WRITE_REG(reg_address);
51 st->tx[1] = val;
52
53 ret = spi_write(st->us, st->tx, 2);
54 mutex_unlock(&st->buf_lock);
55
56 return ret;
57}
58
59/**
60 * adis16251_spi_write_reg_16() - write 2 bytes to a pair of registers
61 * @dev: device associated with child of actual device (iio_dev or iio_trig)
62 * @reg_address: the address of the lower of the two registers. Second register
63 * is assumed to have address one greater.
64 * @val: value to be written
65 **/
66static int adis16251_spi_write_reg_16(struct device *dev,
67 u8 lower_reg_address,
68 u16 value)
69{
70 int ret;
71 struct spi_message msg;
72 struct iio_dev *indio_dev = dev_get_drvdata(dev);
73 struct adis16251_state *st = iio_dev_get_devdata(indio_dev);
74 struct spi_transfer xfers[] = {
75 {
76 .tx_buf = st->tx,
77 .bits_per_word = 8,
78 .len = 2,
79 .cs_change = 1,
80 }, {
81 .tx_buf = st->tx + 2,
82 .bits_per_word = 8,
83 .len = 2,
84 .cs_change = 1,
85 },
86 };
87
88 mutex_lock(&st->buf_lock);
89 st->tx[0] = ADIS16251_WRITE_REG(lower_reg_address);
90 st->tx[1] = value & 0xFF;
91 st->tx[2] = ADIS16251_WRITE_REG(lower_reg_address + 1);
92 st->tx[3] = (value >> 8) & 0xFF;
93
94 spi_message_init(&msg);
95 spi_message_add_tail(&xfers[0], &msg);
96 spi_message_add_tail(&xfers[1], &msg);
97 ret = spi_sync(st->us, &msg);
98 mutex_unlock(&st->buf_lock);
99
100 return ret;
101}
102
103/**
104 * adis16251_spi_read_reg_16() - read 2 bytes from a 16-bit register
105 * @dev: device associated with child of actual device (iio_dev or iio_trig)
106 * @reg_address: the address of the lower of the two registers. Second register
107 * is assumed to have address one greater.
108 * @val: somewhere to pass back the value read
109 **/
110static int adis16251_spi_read_reg_16(struct device *dev,
111 u8 lower_reg_address,
112 u16 *val)
113{
114 struct spi_message msg;
115 struct iio_dev *indio_dev = dev_get_drvdata(dev);
116 struct adis16251_state *st = iio_dev_get_devdata(indio_dev);
117 int ret;
118 struct spi_transfer xfers[] = {
119 {
120 .tx_buf = st->tx,
121 .bits_per_word = 8,
122 .len = 2,
123 .cs_change = 1,
124 }, {
125 .rx_buf = st->rx,
126 .bits_per_word = 8,
127 .len = 2,
128 .cs_change = 1,
129 },
130 };
131
132 mutex_lock(&st->buf_lock);
133 st->tx[0] = ADIS16251_READ_REG(lower_reg_address);
134 st->tx[1] = 0;
135 st->tx[2] = 0;
136 st->tx[3] = 0;
137
138 spi_message_init(&msg);
139 spi_message_add_tail(&xfers[0], &msg);
140 spi_message_add_tail(&xfers[1], &msg);
141 ret = spi_sync(st->us, &msg);
142 if (ret) {
143 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
144 lower_reg_address);
145 goto error_ret;
146 }
147 *val = (st->rx[0] << 8) | st->rx[1];
148
149error_ret:
150 mutex_unlock(&st->buf_lock);
151 return ret;
152}
153
154/**
155 * adis16251_spi_read_burst() - read all data registers
156 * @dev: device associated with child of actual device (iio_dev or iio_trig)
157 * @rx: somewhere to pass back the value read (min size is 24 bytes)
158 **/
159int adis16251_spi_read_burst(struct device *dev, u8 *rx)
160{
161 struct spi_message msg;
162 struct iio_dev *indio_dev = dev_get_drvdata(dev);
163 struct adis16251_state *st = iio_dev_get_devdata(indio_dev);
164 u32 old_speed_hz = st->us->max_speed_hz;
165 int ret;
166
167 struct spi_transfer xfers[] = {
168 {
169 .tx_buf = st->tx,
170 .bits_per_word = 8,
171 .len = 2,
172 .cs_change = 0,
173 }, {
174 .rx_buf = rx,
175 .bits_per_word = 8,
176 .len = 24,
177 .cs_change = 1,
178 },
179 };
180
181 mutex_lock(&st->buf_lock);
182 st->tx[0] = ADIS16251_READ_REG(ADIS16251_GLOB_CMD);
183 st->tx[1] = 0;
184
185 spi_message_init(&msg);
186 spi_message_add_tail(&xfers[0], &msg);
187 spi_message_add_tail(&xfers[1], &msg);
188
189 st->us->max_speed_hz = min(ADIS16251_SPI_BURST, old_speed_hz);
190 spi_setup(st->us);
191
192 ret = spi_sync(st->us, &msg);
193 if (ret)
194 dev_err(&st->us->dev, "problem when burst reading");
195
196 st->us->max_speed_hz = old_speed_hz;
197 spi_setup(st->us);
198 mutex_unlock(&st->buf_lock);
199 return ret;
200}
201
202/**
203 * adis16251_spi_read_sequence() - read a sequence of 16-bit registers
204 * @dev: device associated with child of actual device (iio_dev or iio_trig)
205 * @tx: register addresses in bytes 0,2,4,6... (min size is 2*num bytes)
206 * @rx: somewhere to pass back the value read (min size is 2*num bytes)
207 **/
208int adis16251_spi_read_sequence(struct device *dev,
209 u8 *tx, u8 *rx, int num)
210{
211 struct spi_message msg;
212 struct spi_transfer *xfers;
213 struct iio_dev *indio_dev = dev_get_drvdata(dev);
214 struct adis16251_state *st = iio_dev_get_devdata(indio_dev);
215 int ret, i;
216
217 xfers = kzalloc(num + 1, GFP_KERNEL);
218 if (xfers == NULL) {
219 dev_err(&st->us->dev, "memory alloc failed");
220 ret = -ENOMEM;
221 goto error_ret;
222 }
223
224 /* tx: |add1|addr2|addr3|...|addrN |zero|
225 * rx: |zero|res1 |res2 |...|resN-1|resN| */
226 spi_message_init(&msg);
227 for (i = 0; i < num + 1; i++) {
228 if (i > 0)
229 xfers[i].rx_buf = st->rx + 2*(i - 1);
230 if (i < num)
231 xfers[i].tx_buf = st->tx + 2*i;
232 xfers[i].bits_per_word = 8;
233 xfers[i].len = 2;
234 xfers[i].cs_change = 1;
235 spi_message_add_tail(&xfers[i], &msg);
236 }
237
238 mutex_lock(&st->buf_lock);
239
240 ret = spi_sync(st->us, &msg);
241 if (ret)
242 dev_err(&st->us->dev, "problem when reading sequence");
243
244 mutex_unlock(&st->buf_lock);
245 kfree(xfers);
246
247error_ret:
248 return ret;
249}
250
251static ssize_t adis16251_spi_read_signed(struct device *dev,
252 struct device_attribute *attr,
253 char *buf,
254 unsigned bits)
255{
256 int ret;
257 s16 val = 0;
258 unsigned shift = 16 - bits;
259 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
260
261 ret = adis16251_spi_read_reg_16(dev, this_attr->address, (u16 *)&val);
262 if (ret)
263 return ret;
264
265 if (val & ADIS16251_ERROR_ACTIVE)
266 adis16251_check_status(dev);
267 val = ((s16)(val << shift) >> shift);
268 return sprintf(buf, "%d\n", val);
269}
270
271static ssize_t adis16251_read_12bit_unsigned(struct device *dev,
272 struct device_attribute *attr,
273 char *buf)
274{
275 int ret;
276 u16 val = 0;
277 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
278
279 ret = adis16251_spi_read_reg_16(dev, this_attr->address, &val);
280 if (ret)
281 return ret;
282
283 if (val & ADIS16251_ERROR_ACTIVE)
284 adis16251_check_status(dev);
285
286 return sprintf(buf, "%u\n", val & 0x0FFF);
287}
288
289static ssize_t adis16251_read_14bit_signed(struct device *dev,
290 struct device_attribute *attr,
291 char *buf)
292{
293 struct iio_dev *indio_dev = dev_get_drvdata(dev);
294 ssize_t ret;
295
296 /* Take the iio_dev status lock */
297 mutex_lock(&indio_dev->mlock);
298 ret = adis16251_spi_read_signed(dev, attr, buf, 14);
299 mutex_unlock(&indio_dev->mlock);
300
301 return ret;
302}
303
304static ssize_t adis16251_read_12bit_signed(struct device *dev,
305 struct device_attribute *attr,
306 char *buf)
307{
308 struct iio_dev *indio_dev = dev_get_drvdata(dev);
309 ssize_t ret;
310
311 /* Take the iio_dev status lock */
312 mutex_lock(&indio_dev->mlock);
313 ret = adis16251_spi_read_signed(dev, attr, buf, 12);
314 mutex_unlock(&indio_dev->mlock);
315
316 return ret;
317}
318
319static ssize_t adis16251_write_16bit(struct device *dev,
320 struct device_attribute *attr,
321 const char *buf,
322 size_t len)
323{
324 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
325 int ret;
326 long val;
327
328 ret = strict_strtol(buf, 10, &val);
329 if (ret)
330 goto error_ret;
331 ret = adis16251_spi_write_reg_16(dev, this_attr->address, val);
332
333error_ret:
334 return ret ? ret : len;
335}
336
337static ssize_t adis16251_read_frequency(struct device *dev,
338 struct device_attribute *attr,
339 char *buf)
340{
341 int ret, len = 0;
342 u16 t;
343 int sps;
344 ret = adis16251_spi_read_reg_16(dev,
345 ADIS16251_SMPL_PRD,
346 &t);
347 if (ret)
348 return ret;
349 sps = (t & ADIS16251_SMPL_PRD_TIME_BASE) ? 8 : 256;
350 sps /= (t & ADIS16251_SMPL_PRD_DIV_MASK) + 1;
351 len = sprintf(buf, "%d SPS\n", sps);
352 return len;
353}
354
355static ssize_t adis16251_write_frequency(struct device *dev,
356 struct device_attribute *attr,
357 const char *buf,
358 size_t len)
359{
360 struct iio_dev *indio_dev = dev_get_drvdata(dev);
361 struct adis16251_state *st = iio_dev_get_devdata(indio_dev);
362 long val;
363 int ret;
364 u8 t;
365
366 ret = strict_strtol(buf, 10, &val);
367 if (ret)
368 return ret;
369
370 mutex_lock(&indio_dev->mlock);
371
372 t = (256 / val);
373 if (t > 0)
374 t--;
375 t &= ADIS16251_SMPL_PRD_DIV_MASK;
376 if ((t & ADIS16251_SMPL_PRD_DIV_MASK) >= 0x0A)
377 st->us->max_speed_hz = ADIS16251_SPI_SLOW;
378 else
379 st->us->max_speed_hz = ADIS16251_SPI_FAST;
380
381 ret = adis16251_spi_write_reg_8(dev,
382 ADIS16251_SMPL_PRD,
383 t);
384
385 mutex_unlock(&indio_dev->mlock);
386
387 return ret ? ret : len;
388}
389
390static ssize_t adis16251_write_reset(struct device *dev,
391 struct device_attribute *attr,
392 const char *buf, size_t len)
393{
394 if (len < 1)
395 return -1;
396 switch (buf[0]) {
397 case '1':
398 case 'y':
399 case 'Y':
400 return adis16251_reset(dev);
401 }
402 return -1;
403}
404
405
406
407int adis16251_set_irq(struct device *dev, bool enable)
408{
409 int ret;
410 u16 msc;
411 ret = adis16251_spi_read_reg_16(dev, ADIS16251_MSC_CTRL, &msc);
412 if (ret)
413 goto error_ret;
414
415 msc |= ADIS16251_MSC_CTRL_DATA_RDY_POL_HIGH;
416 if (enable)
417 msc |= ADIS16251_MSC_CTRL_DATA_RDY_EN;
418 else
419 msc &= ~ADIS16251_MSC_CTRL_DATA_RDY_EN;
420
421 ret = adis16251_spi_write_reg_16(dev, ADIS16251_MSC_CTRL, msc);
422 if (ret)
423 goto error_ret;
424
425error_ret:
426 return ret;
427}
428
429int adis16251_reset(struct device *dev)
430{
431 int ret;
432 ret = adis16251_spi_write_reg_8(dev,
433 ADIS16251_GLOB_CMD,
434 ADIS16251_GLOB_CMD_SW_RESET);
435 if (ret)
436 dev_err(dev, "problem resetting device");
437
438 return ret;
439}
440
441/* Power down the device */
442int adis16251_stop_device(struct device *dev)
443{
444 int ret;
445 u16 val = ADIS16251_SLP_CNT_POWER_OFF;
446
447 ret = adis16251_spi_write_reg_16(dev, ADIS16251_SLP_CNT, val);
448 if (ret)
449 dev_err(dev, "problem with turning device off: SLP_CNT");
450
451 return ret;
452}
453
454static int adis16251_self_test(struct device *dev)
455{
456 int ret;
457
458 ret = adis16251_spi_write_reg_16(dev,
459 ADIS16251_MSC_CTRL,
460 ADIS16251_MSC_CTRL_INT_SELF_TEST);
461 if (ret) {
462 dev_err(dev, "problem starting self test");
463 goto err_ret;
464 }
465
466 adis16251_check_status(dev);
467
468err_ret:
469 return ret;
470}
471
472int adis16251_check_status(struct device *dev)
473{
474 u16 status;
475 int ret;
476
477 ret = adis16251_spi_read_reg_16(dev, ADIS16251_DIAG_STAT, &status);
478
479 if (ret < 0) {
480 dev_err(dev, "Reading status failed\n");
481 goto error_ret;
482 }
483
484 if (!(status & ADIS16251_DIAG_STAT_ERR_MASK)) {
485 ret = 0;
486 goto error_ret;
487 }
488
489 ret = -EFAULT;
490
491 if (status & ADIS16251_DIAG_STAT_ALARM2)
492 dev_err(dev, "Alarm 2 active\n");
493 if (status & ADIS16251_DIAG_STAT_ALARM1)
494 dev_err(dev, "Alarm 1 active\n");
495 if (status & ADIS16251_DIAG_STAT_SELF_TEST)
496 dev_err(dev, "Self test error\n");
497 if (status & ADIS16251_DIAG_STAT_OVERFLOW)
498 dev_err(dev, "Sensor overrange\n");
499 if (status & ADIS16251_DIAG_STAT_SPI_FAIL)
500 dev_err(dev, "SPI failure\n");
501 if (status & ADIS16251_DIAG_STAT_FLASH_UPT)
502 dev_err(dev, "Flash update failed\n");
503 if (status & ADIS16251_DIAG_STAT_POWER_HIGH)
504 dev_err(dev, "Power supply above 5.25V\n");
505 if (status & ADIS16251_DIAG_STAT_POWER_LOW)
506 dev_err(dev, "Power supply below 4.75V\n");
507
508error_ret:
509 return ret;
510}
511
512static int adis16251_initial_setup(struct adis16251_state *st)
513{
514 int ret;
515 u16 smp_prd;
516 struct device *dev = &st->indio_dev->dev;
517
518 /* use low spi speed for init */
519 st->us->max_speed_hz = ADIS16251_SPI_SLOW;
520 st->us->mode = SPI_MODE_3;
521 spi_setup(st->us);
522
523 /* Disable IRQ */
524 ret = adis16251_set_irq(dev, false);
525 if (ret) {
526 dev_err(dev, "disable irq failed");
527 goto err_ret;
528 }
529
530 /* Do self test */
531
532 /* Read status register to check the result */
533 ret = adis16251_check_status(dev);
534 if (ret) {
535 adis16251_reset(dev);
536 dev_err(dev, "device not playing ball -> reset");
537 msleep(ADIS16251_STARTUP_DELAY);
538 ret = adis16251_check_status(dev);
539 if (ret) {
540 dev_err(dev, "giving up");
541 goto err_ret;
542 }
543 }
544
545 printk(KERN_INFO DRIVER_NAME ": at CS%d (irq %d)\n",
546 st->us->chip_select, st->us->irq);
547
548 /* use high spi speed if possible */
549 ret = adis16251_spi_read_reg_16(dev, ADIS16251_SMPL_PRD, &smp_prd);
550 if (!ret && (smp_prd & ADIS16251_SMPL_PRD_DIV_MASK) < 0x0A) {
551 st->us->max_speed_hz = ADIS16251_SPI_SLOW;
552 spi_setup(st->us);
553 }
554
555err_ret:
556 return ret;
557}
558
559static IIO_DEV_ATTR_IN_NAMED_RAW(0, supply, adis16251_read_12bit_signed,
560 ADIS16251_SUPPLY_OUT);
561static IIO_CONST_ATTR(in0_supply_scale, "0.0018315");
562
563static IIO_DEV_ATTR_GYRO(adis16251_read_14bit_signed,
564 ADIS16251_GYRO_OUT);
565static IIO_DEV_ATTR_GYRO_SCALE(S_IWUSR | S_IRUGO,
566 adis16251_read_12bit_signed,
567 adis16251_write_16bit,
568 ADIS16251_GYRO_SCALE);
569static IIO_DEV_ATTR_GYRO_OFFSET(S_IWUSR | S_IRUGO,
570 adis16251_read_12bit_signed,
571 adis16251_write_16bit,
572 ADIS16251_GYRO_OFF);
573
574static IIO_DEV_ATTR_TEMP_RAW(adis16251_read_12bit_signed);
575static IIO_CONST_ATTR(temp_offset, "25 K");
576static IIO_CONST_ATTR(temp_scale, "0.1453 K");
577
578static IIO_DEV_ATTR_IN_NAMED_RAW(1, aux, adis16251_read_12bit_unsigned,
579 ADIS16251_AUX_ADC);
580static IIO_CONST_ATTR(in1_aux_scale, "0.0006105");
581
582static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
583 adis16251_read_frequency,
584 adis16251_write_frequency);
585static IIO_DEV_ATTR_ANGL(adis16251_read_14bit_signed,
586 ADIS16251_ANGL_OUT);
587
588static IIO_DEV_ATTR_RESET(adis16251_write_reset);
589
590static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("0.129 ~ 256");
591
592static IIO_CONST_ATTR(name, "adis16251");
593
594static struct attribute *adis16251_event_attributes[] = {
595 NULL
596};
597
598static struct attribute_group adis16251_event_attribute_group = {
599 .attrs = adis16251_event_attributes,
600};
601
602static struct attribute *adis16251_attributes[] = {
603 &iio_dev_attr_in0_supply_raw.dev_attr.attr,
604 &iio_const_attr_in0_supply_scale.dev_attr.attr,
605 &iio_dev_attr_gyro_raw.dev_attr.attr,
606 &iio_dev_attr_gyro_scale.dev_attr.attr,
607 &iio_dev_attr_gyro_offset.dev_attr.attr,
608 &iio_dev_attr_angl_raw.dev_attr.attr,
609 &iio_dev_attr_temp_raw.dev_attr.attr,
610 &iio_const_attr_temp_offset.dev_attr.attr,
611 &iio_const_attr_temp_scale.dev_attr.attr,
612 &iio_dev_attr_in1_aux_raw.dev_attr.attr,
613 &iio_const_attr_in1_aux_scale.dev_attr.attr,
614 &iio_dev_attr_sampling_frequency.dev_attr.attr,
615 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
616 &iio_dev_attr_reset.dev_attr.attr,
617 &iio_const_attr_name.dev_attr.attr,
618 NULL
619};
620
621static const struct attribute_group adis16251_attribute_group = {
622 .attrs = adis16251_attributes,
623};
624
625static int __devinit adis16251_probe(struct spi_device *spi)
626{
627 int ret, regdone = 0;
628 struct adis16251_state *st = kzalloc(sizeof *st, GFP_KERNEL);
629 if (!st) {
630 ret = -ENOMEM;
631 goto error_ret;
632 }
633 /* this is only used for removal purposes */
634 spi_set_drvdata(spi, st);
635
636 /* Allocate the comms buffers */
637 st->rx = kzalloc(sizeof(*st->rx)*ADIS16251_MAX_RX, GFP_KERNEL);
638 if (st->rx == NULL) {
639 ret = -ENOMEM;
640 goto error_free_st;
641 }
642 st->tx = kzalloc(sizeof(*st->tx)*ADIS16251_MAX_TX, GFP_KERNEL);
643 if (st->tx == NULL) {
644 ret = -ENOMEM;
645 goto error_free_rx;
646 }
647 st->us = spi;
648 mutex_init(&st->buf_lock);
649 /* setup the industrialio driver allocated elements */
650 st->indio_dev = iio_allocate_device();
651 if (st->indio_dev == NULL) {
652 ret = -ENOMEM;
653 goto error_free_tx;
654 }
655
656 st->indio_dev->dev.parent = &spi->dev;
657 st->indio_dev->num_interrupt_lines = 1;
658 st->indio_dev->event_attrs = &adis16251_event_attribute_group;
659 st->indio_dev->attrs = &adis16251_attribute_group;
660 st->indio_dev->dev_data = (void *)(st);
661 st->indio_dev->driver_module = THIS_MODULE;
662 st->indio_dev->modes = INDIO_DIRECT_MODE;
663
664 ret = adis16251_configure_ring(st->indio_dev);
665 if (ret)
666 goto error_free_dev;
667
668 ret = iio_device_register(st->indio_dev);
669 if (ret)
670 goto error_unreg_ring_funcs;
671 regdone = 1;
672
673 ret = adis16251_initialize_ring(st->indio_dev->ring);
674 if (ret) {
675 printk(KERN_ERR "failed to initialize the ring\n");
676 goto error_unreg_ring_funcs;
677 }
678
679 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) {
680 ret = iio_register_interrupt_line(spi->irq,
681 st->indio_dev,
682 0,
683 IRQF_TRIGGER_RISING,
684 "adis16251");
685 if (ret)
686 goto error_uninitialize_ring;
687
688 ret = adis16251_probe_trigger(st->indio_dev);
689 if (ret)
690 goto error_unregister_line;
691 }
692
693 /* Get the device into a sane initial state */
694 ret = adis16251_initial_setup(st);
695 if (ret)
696 goto error_remove_trigger;
697 return 0;
698
699error_remove_trigger:
700 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
701 adis16251_remove_trigger(st->indio_dev);
702error_unregister_line:
703 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
704 iio_unregister_interrupt_line(st->indio_dev, 0);
705error_uninitialize_ring:
706 adis16251_uninitialize_ring(st->indio_dev->ring);
707error_unreg_ring_funcs:
708 adis16251_unconfigure_ring(st->indio_dev);
709error_free_dev:
710 if (regdone)
711 iio_device_unregister(st->indio_dev);
712 else
713 iio_free_device(st->indio_dev);
714error_free_tx:
715 kfree(st->tx);
716error_free_rx:
717 kfree(st->rx);
718error_free_st:
719 kfree(st);
720error_ret:
721 return ret;
722}
723
724/* fixme, confirm ordering in this function */
725static int adis16251_remove(struct spi_device *spi)
726{
727 int ret;
728 struct adis16251_state *st = spi_get_drvdata(spi);
729 struct iio_dev *indio_dev = st->indio_dev;
730
731 ret = adis16251_stop_device(&(indio_dev->dev));
732 if (ret)
733 goto err_ret;
734
735 flush_scheduled_work();
736
737 adis16251_remove_trigger(indio_dev);
738 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
739 iio_unregister_interrupt_line(indio_dev, 0);
740
741 adis16251_uninitialize_ring(indio_dev->ring);
742 adis16251_unconfigure_ring(indio_dev);
743 iio_device_unregister(indio_dev);
744 kfree(st->tx);
745 kfree(st->rx);
746 kfree(st);
747
748 return 0;
749
750err_ret:
751 return ret;
752}
753
754static struct spi_driver adis16251_driver = {
755 .driver = {
756 .name = "adis16251",
757 .owner = THIS_MODULE,
758 },
759 .probe = adis16251_probe,
760 .remove = __devexit_p(adis16251_remove),
761};
762
763static __init int adis16251_init(void)
764{
765 return spi_register_driver(&adis16251_driver);
766}
767module_init(adis16251_init);
768
769static __exit void adis16251_exit(void)
770{
771 spi_unregister_driver(&adis16251_driver);
772}
773module_exit(adis16251_exit);
774
775MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
776MODULE_DESCRIPTION("Analog Devices ADIS16251 Digital Gyroscope Sensor SPI driver");
777MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/gyro/adis16260.h b/drivers/staging/iio/gyro/adis16260.h
index 812440af57d6..c1fd4364287f 100644
--- a/drivers/staging/iio/gyro/adis16260.h
+++ b/drivers/staging/iio/gyro/adis16260.h
@@ -1,5 +1,6 @@
1#ifndef SPI_ADIS16260_H_ 1#ifndef SPI_ADIS16260_H_
2#define SPI_ADIS16260_H_ 2#define SPI_ADIS16260_H_
3#include "adis16260_platform_data.h"
3 4
4#define ADIS16260_STARTUP_DELAY 220 /* ms */ 5#define ADIS16260_STARTUP_DELAY 220 /* ms */
5 6
@@ -92,6 +93,7 @@
92 * @tx: transmit buffer 93 * @tx: transmit buffer
93 * @rx: recieve buffer 94 * @rx: recieve buffer
94 * @buf_lock: mutex to protect tx and rx 95 * @buf_lock: mutex to protect tx and rx
96 * @negate: negate the scale parameter
95 **/ 97 **/
96struct adis16260_state { 98struct adis16260_state {
97 struct spi_device *us; 99 struct spi_device *us;
@@ -102,6 +104,7 @@ struct adis16260_state {
102 u8 *tx; 104 u8 *tx;
103 u8 *rx; 105 u8 *rx;
104 struct mutex buf_lock; 106 struct mutex buf_lock;
107 unsigned negate:1;
105}; 108};
106 109
107int adis16260_set_irq(struct device *dev, bool enable); 110int adis16260_set_irq(struct device *dev, bool enable);
diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
index 7d7716e5857c..045e27da980a 100644
--- a/drivers/staging/iio/gyro/adis16260_core.c
+++ b/drivers/staging/iio/gyro/adis16260_core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * ADIS16260 Programmable Digital Gyroscope Sensor Driver 2 * ADIS16260/ADIS16265 Programmable Digital Gyroscope Sensor Driver
3 * 3 *
4 * Copyright 2010 Analog Devices Inc. 4 * Copyright 2010 Analog Devices Inc.
5 * 5 *
@@ -134,8 +134,6 @@ static int adis16260_spi_read_reg_16(struct device *dev,
134 mutex_lock(&st->buf_lock); 134 mutex_lock(&st->buf_lock);
135 st->tx[0] = ADIS16260_READ_REG(lower_reg_address); 135 st->tx[0] = ADIS16260_READ_REG(lower_reg_address);
136 st->tx[1] = 0; 136 st->tx[1] = 0;
137 st->tx[2] = 0;
138 st->tx[3] = 0;
139 137
140 spi_message_init(&msg); 138 spi_message_init(&msg);
141 spi_message_add_tail(&xfers[0], &msg); 139 spi_message_add_tail(&xfers[0], &msg);
@@ -293,6 +291,22 @@ static ssize_t adis16260_write_frequency(struct device *dev,
293 return ret ? ret : len; 291 return ret ? ret : len;
294} 292}
295 293
294static ssize_t adis16260_read_gyro_scale(struct device *dev,
295 struct device_attribute *attr,
296 char *buf)
297{
298 struct iio_dev *indio_dev = dev_get_drvdata(dev);
299 struct adis16260_state *st = iio_dev_get_devdata(indio_dev);
300 ssize_t ret = 0;
301
302 if (st->negate)
303 ret = sprintf(buf, "-");
304 /* Take the iio_dev status lock */
305 ret += sprintf(buf + ret, "%s\n", "0.00127862821");
306
307 return ret;
308}
309
296static int adis16260_reset(struct device *dev) 310static int adis16260_reset(struct device *dev)
297{ 311{
298 int ret; 312 int ret;
@@ -447,18 +461,6 @@ static IIO_DEV_ATTR_IN_NAMED_RAW(0, supply,
447 ADIS16260_SUPPLY_OUT); 461 ADIS16260_SUPPLY_OUT);
448static IIO_CONST_ATTR_IN_NAMED_SCALE(0, supply, "0.0018315"); 462static IIO_CONST_ATTR_IN_NAMED_SCALE(0, supply, "0.0018315");
449 463
450static IIO_DEV_ATTR_GYRO(adis16260_read_14bit_signed,
451 ADIS16260_GYRO_OUT);
452static IIO_CONST_ATTR_GYRO_SCALE("0.00127862821");
453static IIO_DEV_ATTR_GYRO_CALIBSCALE(S_IWUSR | S_IRUGO,
454 adis16260_read_14bit_signed,
455 adis16260_write_16bit,
456 ADIS16260_GYRO_SCALE);
457static IIO_DEV_ATTR_GYRO_CALIBBIAS(S_IWUSR | S_IRUGO,
458 adis16260_read_12bit_signed,
459 adis16260_write_16bit,
460 ADIS16260_GYRO_OFF);
461
462static IIO_DEV_ATTR_TEMP_RAW(adis16260_read_12bit_unsigned); 464static IIO_DEV_ATTR_TEMP_RAW(adis16260_read_12bit_unsigned);
463static IIO_CONST_ATTR_TEMP_OFFSET("25"); 465static IIO_CONST_ATTR_TEMP_OFFSET("25");
464static IIO_CONST_ATTR_TEMP_SCALE("0.1453"); 466static IIO_CONST_ATTR_TEMP_SCALE("0.1453");
@@ -470,8 +472,6 @@ static IIO_CONST_ATTR(in1_scale, "0.0006105");
470static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, 472static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
471 adis16260_read_frequency, 473 adis16260_read_frequency,
472 adis16260_write_frequency); 474 adis16260_write_frequency);
473static IIO_DEV_ATTR_ANGL(adis16260_read_14bit_signed,
474 ADIS16260_ANGL_OUT);
475 475
476static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, adis16260_write_reset, 0); 476static IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, adis16260_write_reset, 0);
477 477
@@ -487,38 +487,70 @@ static struct attribute_group adis16260_event_attribute_group = {
487 .attrs = adis16260_event_attributes, 487 .attrs = adis16260_event_attributes,
488}; 488};
489 489
490static struct attribute *adis16260_attributes[] = { 490#define ADIS16260_GYRO_ATTR_SET(axis) \
491 &iio_dev_attr_in0_supply_raw.dev_attr.attr, 491 IIO_DEV_ATTR_GYRO##axis(adis16260_read_14bit_signed, \
492 &iio_const_attr_in0_supply_scale.dev_attr.attr, 492 ADIS16260_GYRO_OUT); \
493 &iio_dev_attr_gyro_raw.dev_attr.attr, 493 static IIO_DEV_ATTR_GYRO##axis##_SCALE(S_IRUGO, \
494 &iio_const_attr_gyro_scale.dev_attr.attr, 494 adis16260_read_gyro_scale, \
495 &iio_dev_attr_gyro_calibscale.dev_attr.attr, 495 NULL, \
496 &iio_dev_attr_gyro_calibbias.dev_attr.attr, 496 0); \
497 &iio_dev_attr_angl_raw.dev_attr.attr, 497 static IIO_DEV_ATTR_GYRO##axis##_CALIBSCALE(S_IRUGO | S_IWUSR, \
498 &iio_dev_attr_temp_raw.dev_attr.attr, 498 adis16260_read_12bit_unsigned, \
499 &iio_const_attr_temp_offset.dev_attr.attr, 499 adis16260_write_16bit, \
500 &iio_const_attr_temp_scale.dev_attr.attr, 500 ADIS16260_GYRO_SCALE); \
501 &iio_dev_attr_in1_raw.dev_attr.attr, 501 static IIO_DEV_ATTR_GYRO##axis##_CALIBBIAS(S_IWUSR | S_IRUGO, \
502 &iio_const_attr_in1_scale.dev_attr.attr, 502 adis16260_read_12bit_signed, \
503 &iio_dev_attr_sampling_frequency.dev_attr.attr, 503 adis16260_write_16bit, \
504 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 504 ADIS16260_GYRO_OFF); \
505 &iio_dev_attr_reset.dev_attr.attr, 505 static IIO_DEV_ATTR_ANGL##axis(adis16260_read_14bit_signed, \
506 &iio_const_attr_name.dev_attr.attr, 506 ADIS16260_ANGL_OUT);
507 NULL 507
508}; 508static ADIS16260_GYRO_ATTR_SET();
509static ADIS16260_GYRO_ATTR_SET(_X);
510static ADIS16260_GYRO_ATTR_SET(_Y);
511static ADIS16260_GYRO_ATTR_SET(_Z);
512
513#define ADIS16260_ATTR_GROUP(axis) \
514 struct attribute *adis16260_attributes##axis[] = { \
515 &iio_dev_attr_in0_supply_raw.dev_attr.attr, \
516 &iio_const_attr_in0_supply_scale.dev_attr.attr, \
517 &iio_dev_attr_gyro##axis##_raw.dev_attr.attr, \
518 &iio_dev_attr_gyro##axis##_scale.dev_attr.attr, \
519 &iio_dev_attr_gyro##axis##_calibscale.dev_attr.attr, \
520 &iio_dev_attr_gyro##axis##_calibbias.dev_attr.attr, \
521 &iio_dev_attr_angl##axis##_raw.dev_attr.attr, \
522 &iio_dev_attr_temp_raw.dev_attr.attr, \
523 &iio_const_attr_temp_offset.dev_attr.attr, \
524 &iio_const_attr_temp_scale.dev_attr.attr, \
525 &iio_dev_attr_in1_raw.dev_attr.attr, \
526 &iio_const_attr_in1_scale.dev_attr.attr, \
527 &iio_dev_attr_sampling_frequency.dev_attr.attr, \
528 &iio_const_attr_sampling_frequency_available.dev_attr.attr, \
529 &iio_dev_attr_reset.dev_attr.attr, \
530 &iio_const_attr_name.dev_attr.attr, \
531 NULL \
532 }; \
533 static const struct attribute_group adis16260_attribute_group##axis \
534 = { \
535 .attrs = adis16260_attributes##axis, \
536 };
509 537
510static const struct attribute_group adis16260_attribute_group = { 538static ADIS16260_ATTR_GROUP();
511 .attrs = adis16260_attributes, 539static ADIS16260_ATTR_GROUP(_x);
512}; 540static ADIS16260_ATTR_GROUP(_y);
541static ADIS16260_ATTR_GROUP(_z);
513 542
514static int __devinit adis16260_probe(struct spi_device *spi) 543static int __devinit adis16260_probe(struct spi_device *spi)
515{ 544{
516 int ret, regdone = 0; 545 int ret, regdone = 0;
546 struct adis16260_platform_data *pd = spi->dev.platform_data;
517 struct adis16260_state *st = kzalloc(sizeof *st, GFP_KERNEL); 547 struct adis16260_state *st = kzalloc(sizeof *st, GFP_KERNEL);
518 if (!st) { 548 if (!st) {
519 ret = -ENOMEM; 549 ret = -ENOMEM;
520 goto error_ret; 550 goto error_ret;
521 } 551 }
552 if (pd)
553 st->negate = pd->negate;
522 /* this is only used for removal purposes */ 554 /* this is only used for removal purposes */
523 spi_set_drvdata(spi, st); 555 spi_set_drvdata(spi, st);
524 556
@@ -545,7 +577,24 @@ static int __devinit adis16260_probe(struct spi_device *spi)
545 st->indio_dev->dev.parent = &spi->dev; 577 st->indio_dev->dev.parent = &spi->dev;
546 st->indio_dev->num_interrupt_lines = 1; 578 st->indio_dev->num_interrupt_lines = 1;
547 st->indio_dev->event_attrs = &adis16260_event_attribute_group; 579 st->indio_dev->event_attrs = &adis16260_event_attribute_group;
548 st->indio_dev->attrs = &adis16260_attribute_group; 580 if (pd && pd->direction)
581 switch (pd->direction) {
582 case 'x':
583 st->indio_dev->attrs = &adis16260_attribute_group_x;
584 break;
585 case 'y':
586 st->indio_dev->attrs = &adis16260_attribute_group_y;
587 break;
588 case 'z':
589 st->indio_dev->attrs = &adis16260_attribute_group_z;
590 break;
591 default:
592 st->indio_dev->attrs = &adis16260_attribute_group;
593 break;
594 }
595 else
596 st->indio_dev->attrs = &adis16260_attribute_group;
597
549 st->indio_dev->dev_data = (void *)(st); 598 st->indio_dev->dev_data = (void *)(st);
550 st->indio_dev->driver_module = THIS_MODULE; 599 st->indio_dev->driver_module = THIS_MODULE;
551 st->indio_dev->modes = INDIO_DIRECT_MODE; 600 st->indio_dev->modes = INDIO_DIRECT_MODE;
@@ -635,6 +684,18 @@ err_ret:
635 return ret; 684 return ret;
636} 685}
637 686
687/*
688 * These parts do not need to be differentiated until someone adds
689 * support for the on chip filtering.
690 */
691static const struct spi_device_id adis16260_id[] = {
692 {"adis16260", 0},
693 {"adis16265", 0},
694 {"adis16250", 0},
695 {"adis16255", 0},
696 {}
697};
698
638static struct spi_driver adis16260_driver = { 699static struct spi_driver adis16260_driver = {
639 .driver = { 700 .driver = {
640 .name = "adis16260", 701 .name = "adis16260",
@@ -642,6 +703,7 @@ static struct spi_driver adis16260_driver = {
642 }, 703 },
643 .probe = adis16260_probe, 704 .probe = adis16260_probe,
644 .remove = __devexit_p(adis16260_remove), 705 .remove = __devexit_p(adis16260_remove),
706 .id_table = adis16260_id,
645}; 707};
646 708
647static __init int adis16260_init(void) 709static __init int adis16260_init(void)
diff --git a/drivers/staging/iio/gyro/adis16260_platform_data.h b/drivers/staging/iio/gyro/adis16260_platform_data.h
new file mode 100644
index 000000000000..12802e97be92
--- /dev/null
+++ b/drivers/staging/iio/gyro/adis16260_platform_data.h
@@ -0,0 +1,19 @@
1/*
2 * ADIS16260 Programmable Digital Gyroscope Sensor Driver Platform Data
3 *
4 * Based on adis16255.h Matthia Brugger <m_brugger&web.de>
5 *
6 * Copyright (C) 2010 Fraunhofer Institute for Integrated Circuits
7 *
8 * Licensed under the GPL-2 or later.
9 */
10
11/**
12 * struct adis16260_platform_data - instance specific data
13 * @direction: x y or z
14 * @negate: flag to indicate value should be inverted.
15 **/
16struct adis16260_platform_data {
17 char direction;
18 unsigned negate:1;
19};
diff --git a/drivers/staging/iio/gyro/gyro.h b/drivers/staging/iio/gyro/gyro.h
index 98b837b775a2..b4ea5bf161ff 100644
--- a/drivers/staging/iio/gyro/gyro.h
+++ b/drivers/staging/iio/gyro/gyro.h
@@ -71,3 +71,12 @@
71 71
72#define IIO_DEV_ATTR_ANGL(_show, _addr) \ 72#define IIO_DEV_ATTR_ANGL(_show, _addr) \
73 IIO_DEVICE_ATTR(angl_raw, S_IRUGO, _show, NULL, _addr) 73 IIO_DEVICE_ATTR(angl_raw, S_IRUGO, _show, NULL, _addr)
74
75#define IIO_DEV_ATTR_ANGL_X(_show, _addr) \
76 IIO_DEVICE_ATTR(angl_x_raw, S_IRUGO, _show, NULL, _addr)
77
78#define IIO_DEV_ATTR_ANGL_Y(_show, _addr) \
79 IIO_DEVICE_ATTR(angl_y_raw, S_IRUGO, _show, NULL, _addr)
80
81#define IIO_DEV_ATTR_ANGL_Z(_show, _addr) \
82 IIO_DEVICE_ATTR(angl_z_raw, S_IRUGO, _show, NULL, _addr)
diff --git a/drivers/staging/iio/imu/adis16350_core.c b/drivers/staging/iio/imu/adis16350_core.c
index 97c1ec8594ce..cf7176bc766b 100644
--- a/drivers/staging/iio/imu/adis16350_core.c
+++ b/drivers/staging/iio/imu/adis16350_core.c
@@ -570,6 +570,7 @@ static struct attribute *adis16350_attributes[] = {
570 &iio_dev_attr_temp_y_raw.dev_attr.attr, 570 &iio_dev_attr_temp_y_raw.dev_attr.attr,
571 &iio_dev_attr_temp_z_raw.dev_attr.attr, 571 &iio_dev_attr_temp_z_raw.dev_attr.attr,
572 &iio_const_attr_temp_scale.dev_attr.attr, 572 &iio_const_attr_temp_scale.dev_attr.attr,
573 &iio_const_attr_temp_offset.dev_attr.attr,
573 &iio_dev_attr_in1_raw.dev_attr.attr, 574 &iio_dev_attr_in1_raw.dev_attr.attr,
574 &iio_const_attr_in1_scale.dev_attr.attr, 575 &iio_const_attr_in1_scale.dev_attr.attr,
575 &iio_dev_attr_sampling_frequency.dev_attr.attr, 576 &iio_dev_attr_sampling_frequency.dev_attr.attr,
diff --git a/drivers/staging/iio/meter/Kconfig b/drivers/staging/iio/meter/Kconfig
new file mode 100644
index 000000000000..12e36e460693
--- /dev/null
+++ b/drivers/staging/iio/meter/Kconfig
@@ -0,0 +1,61 @@
1#
2# IIO meter drivers configuration
3#
4comment "Active energy metering IC"
5
6config ADE7753
7 tristate "Analog Devices ADE7753/6 Single-Phase Multifunction Metering IC Driver"
8 depends on SPI
9 help
10 Say yes here to build support for Analog Devices ADE7753 Single-Phase Multifunction
11 Metering IC with di/dt Sensor Interface.
12
13config ADE7754
14 tristate "Analog Devices ADE7754 Polyphase Multifunction Energy Metering IC Driver"
15 depends on SPI
16 help
17 Say yes here to build support for Analog Devices ADE7754 Polyphase
18 Multifunction Energy Metering IC Driver.
19
20config ADE7758
21 tristate "Analog Devices ADE7758 Poly Phase Multifunction Energy Metering IC Driver"
22 depends on SPI
23 select IIO_TRIGGER if IIO_RING_BUFFER
24 select IIO_SW_RING if IIO_RING_BUFFER
25 help
26 Say yes here to build support for Analog Devices ADE7758 Polyphase
27 Multifunction Energy Metering IC with Per Phase Information Driver.
28
29config ADE7759
30 tristate "Analog Devices ADE7759 Active Energy Metering IC Driver"
31 depends on SPI
32 help
33 Say yes here to build support for Analog Devices ADE7758 Active Energy
34 Metering IC with di/dt Sensor Interface.
35
36config ADE7854
37 tristate "Analog Devices ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver"
38 depends on SPI || I2C
39 help
40 Say yes here to build support for Analog Devices ADE7854/58/68/78 Polyphase
41 Multifunction Energy Metering IC Driver.
42
43config ADE7854_I2C
44 tristate "support I2C bus connection"
45 depends on ADE7854 && I2C
46 default y
47 help
48 Say Y here if you have ADE7854/58/68/78 hooked to an I2C bus.
49
50 To compile this driver as a module, choose M here: the
51 module will be called ade7854-i2c.
52
53config ADE7854_SPI
54 tristate "support SPI bus connection"
55 depends on ADE7854 && SPI
56 default y
57 help
58 Say Y here if you have ADE7854/58/68/78 hooked to a SPI bus.
59
60 To compile this driver as a module, choose M here: the
61 module will be called ade7854-spi.
diff --git a/drivers/staging/iio/meter/Makefile b/drivers/staging/iio/meter/Makefile
new file mode 100644
index 000000000000..0cc7d5140dfe
--- /dev/null
+++ b/drivers/staging/iio/meter/Makefile
@@ -0,0 +1,15 @@
1#
2# Makefile for metering ic drivers
3#
4
5obj-$(CONFIG_ADE7753) += ade7753.o
6obj-$(CONFIG_ADE7754) += ade7754.o
7
8ade7758-y := ade7758_core.o
9ade7758-$(CONFIG_IIO_RING_BUFFER) += ade7758_ring.o ade7758_trigger.o
10obj-$(CONFIG_ADE7758) += ade7758.o
11
12obj-$(CONFIG_ADE7759) += ade7759.o
13obj-$(CONFIG_ADE7854) += ade7854.o
14obj-$(CONFIG_ADE7854_I2C) += ade7854-i2c.o
15obj-$(CONFIG_ADE7854_SPI) += ade7854-spi.o
diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c
new file mode 100644
index 000000000000..e72afbd2b841
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7753.c
@@ -0,0 +1,730 @@
1/*
2 * ADE7753 Single-Phase Multifunction Metering IC with di/dt Sensor Interface Driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "meter.h"
24#include "ade7753.h"
25
26int ade7753_spi_write_reg_8(struct device *dev,
27 u8 reg_address,
28 u8 val)
29{
30 int ret;
31 struct iio_dev *indio_dev = dev_get_drvdata(dev);
32 struct ade7753_state *st = iio_dev_get_devdata(indio_dev);
33
34 mutex_lock(&st->buf_lock);
35 st->tx[0] = ADE7753_WRITE_REG(reg_address);
36 st->tx[1] = val;
37
38 ret = spi_write(st->us, st->tx, 2);
39 mutex_unlock(&st->buf_lock);
40
41 return ret;
42}
43
44static int ade7753_spi_write_reg_16(struct device *dev,
45 u8 reg_address,
46 u16 value)
47{
48 int ret;
49 struct spi_message msg;
50 struct iio_dev *indio_dev = dev_get_drvdata(dev);
51 struct ade7753_state *st = iio_dev_get_devdata(indio_dev);
52 struct spi_transfer xfers[] = {
53 {
54 .tx_buf = st->tx,
55 .bits_per_word = 8,
56 .len = 3,
57 }
58 };
59
60 mutex_lock(&st->buf_lock);
61 st->tx[0] = ADE7753_WRITE_REG(reg_address);
62 st->tx[1] = (value >> 8) & 0xFF;
63 st->tx[2] = value & 0xFF;
64
65 spi_message_init(&msg);
66 spi_message_add_tail(xfers, &msg);
67 ret = spi_sync(st->us, &msg);
68 mutex_unlock(&st->buf_lock);
69
70 return ret;
71}
72
73static int ade7753_spi_read_reg_8(struct device *dev,
74 u8 reg_address,
75 u8 *val)
76{
77 struct spi_message msg;
78 struct iio_dev *indio_dev = dev_get_drvdata(dev);
79 struct ade7753_state *st = iio_dev_get_devdata(indio_dev);
80 int ret;
81 struct spi_transfer xfers[] = {
82 {
83 .tx_buf = st->tx,
84 .rx_buf = st->rx,
85 .bits_per_word = 8,
86 .len = 2,
87 },
88 };
89
90 mutex_lock(&st->buf_lock);
91 st->tx[0] = ADE7753_READ_REG(reg_address);
92 st->tx[1] = 0;
93
94 spi_message_init(&msg);
95 spi_message_add_tail(xfers, &msg);
96 ret = spi_sync(st->us, &msg);
97 if (ret) {
98 dev_err(&st->us->dev, "problem when reading 8 bit register 0x%02X",
99 reg_address);
100 goto error_ret;
101 }
102 *val = st->rx[1];
103
104error_ret:
105 mutex_unlock(&st->buf_lock);
106 return ret;
107}
108
109static int ade7753_spi_read_reg_16(struct device *dev,
110 u8 reg_address,
111 u16 *val)
112{
113 struct spi_message msg;
114 struct iio_dev *indio_dev = dev_get_drvdata(dev);
115 struct ade7753_state *st = iio_dev_get_devdata(indio_dev);
116 int ret;
117 struct spi_transfer xfers[] = {
118 {
119 .tx_buf = st->tx,
120 .rx_buf = st->rx,
121 .bits_per_word = 8,
122 .len = 3,
123 },
124 };
125
126 mutex_lock(&st->buf_lock);
127 st->tx[0] = ADE7753_READ_REG(reg_address);
128 st->tx[1] = 0;
129 st->tx[2] = 0;
130
131 spi_message_init(&msg);
132 spi_message_add_tail(xfers, &msg);
133 ret = spi_sync(st->us, &msg);
134 if (ret) {
135 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
136 reg_address);
137 goto error_ret;
138 }
139 *val = (st->rx[1] << 8) | st->rx[2];
140
141error_ret:
142 mutex_unlock(&st->buf_lock);
143 return ret;
144}
145
146static int ade7753_spi_read_reg_24(struct device *dev,
147 u8 reg_address,
148 u32 *val)
149{
150 struct spi_message msg;
151 struct iio_dev *indio_dev = dev_get_drvdata(dev);
152 struct ade7753_state *st = iio_dev_get_devdata(indio_dev);
153 int ret;
154 struct spi_transfer xfers[] = {
155 {
156 .tx_buf = st->tx,
157 .rx_buf = st->rx,
158 .bits_per_word = 8,
159 .len = 4,
160 },
161 };
162
163 mutex_lock(&st->buf_lock);
164 st->tx[0] = ADE7753_READ_REG(reg_address);
165 st->tx[1] = 0;
166 st->tx[2] = 0;
167 st->tx[3] = 0;
168
169 spi_message_init(&msg);
170 spi_message_add_tail(xfers, &msg);
171 ret = spi_sync(st->us, &msg);
172 if (ret) {
173 dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X",
174 reg_address);
175 goto error_ret;
176 }
177 *val = (st->rx[1] << 16) | (st->rx[2] << 8) | st->rx[3];
178
179error_ret:
180 mutex_unlock(&st->buf_lock);
181 return ret;
182}
183
184static ssize_t ade7753_read_8bit(struct device *dev,
185 struct device_attribute *attr,
186 char *buf)
187{
188 int ret;
189 u8 val = 0;
190 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
191
192 ret = ade7753_spi_read_reg_8(dev, this_attr->address, &val);
193 if (ret)
194 return ret;
195
196 return sprintf(buf, "%u\n", val);
197}
198
199static ssize_t ade7753_read_16bit(struct device *dev,
200 struct device_attribute *attr,
201 char *buf)
202{
203 int ret;
204 u16 val = 0;
205 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
206
207 ret = ade7753_spi_read_reg_16(dev, this_attr->address, &val);
208 if (ret)
209 return ret;
210
211 return sprintf(buf, "%u\n", val);
212}
213
214static ssize_t ade7753_read_24bit(struct device *dev,
215 struct device_attribute *attr,
216 char *buf)
217{
218 int ret;
219 u32 val = 0;
220 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
221
222 ret = ade7753_spi_read_reg_24(dev, this_attr->address, &val);
223 if (ret)
224 return ret;
225
226 return sprintf(buf, "%u\n", val & 0xFFFFFF);
227}
228
229static ssize_t ade7753_write_8bit(struct device *dev,
230 struct device_attribute *attr,
231 const char *buf,
232 size_t len)
233{
234 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
235 int ret;
236 long val;
237
238 ret = strict_strtol(buf, 10, &val);
239 if (ret)
240 goto error_ret;
241 ret = ade7753_spi_write_reg_8(dev, this_attr->address, val);
242
243error_ret:
244 return ret ? ret : len;
245}
246
247static ssize_t ade7753_write_16bit(struct device *dev,
248 struct device_attribute *attr,
249 const char *buf,
250 size_t len)
251{
252 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
253 int ret;
254 long val;
255
256 ret = strict_strtol(buf, 10, &val);
257 if (ret)
258 goto error_ret;
259 ret = ade7753_spi_write_reg_16(dev, this_attr->address, val);
260
261error_ret:
262 return ret ? ret : len;
263}
264
265static int ade7753_reset(struct device *dev)
266{
267 int ret;
268 u16 val;
269 ade7753_spi_read_reg_16(dev,
270 ADE7753_MODE,
271 &val);
272 val |= 1 << 6; /* Software Chip Reset */
273 ret = ade7753_spi_write_reg_16(dev,
274 ADE7753_MODE,
275 val);
276
277 return ret;
278}
279
280static ssize_t ade7753_write_reset(struct device *dev,
281 struct device_attribute *attr,
282 const char *buf, size_t len)
283{
284 if (len < 1)
285 return -1;
286 switch (buf[0]) {
287 case '1':
288 case 'y':
289 case 'Y':
290 return ade7753_reset(dev);
291 }
292 return -1;
293}
294
295static IIO_DEV_ATTR_AENERGY(ade7753_read_24bit, ADE7753_AENERGY);
296static IIO_DEV_ATTR_LAENERGY(ade7753_read_24bit, ADE7753_LAENERGY);
297static IIO_DEV_ATTR_VAENERGY(ade7753_read_24bit, ADE7753_VAENERGY);
298static IIO_DEV_ATTR_LVAENERGY(ade7753_read_24bit, ADE7753_LVAENERGY);
299static IIO_DEV_ATTR_CFDEN(S_IWUSR | S_IRUGO,
300 ade7753_read_16bit,
301 ade7753_write_16bit,
302 ADE7753_CFDEN);
303static IIO_DEV_ATTR_CFNUM(S_IWUSR | S_IRUGO,
304 ade7753_read_8bit,
305 ade7753_write_8bit,
306 ADE7753_CFNUM);
307static IIO_DEV_ATTR_CHKSUM(ade7753_read_8bit, ADE7753_CHKSUM);
308static IIO_DEV_ATTR_PHCAL(S_IWUSR | S_IRUGO,
309 ade7753_read_16bit,
310 ade7753_write_16bit,
311 ADE7753_PHCAL);
312static IIO_DEV_ATTR_APOS(S_IWUSR | S_IRUGO,
313 ade7753_read_16bit,
314 ade7753_write_16bit,
315 ADE7753_APOS);
316static IIO_DEV_ATTR_SAGCYC(S_IWUSR | S_IRUGO,
317 ade7753_read_8bit,
318 ade7753_write_8bit,
319 ADE7753_SAGCYC);
320static IIO_DEV_ATTR_SAGLVL(S_IWUSR | S_IRUGO,
321 ade7753_read_8bit,
322 ade7753_write_8bit,
323 ADE7753_SAGLVL);
324static IIO_DEV_ATTR_LINECYC(S_IWUSR | S_IRUGO,
325 ade7753_read_8bit,
326 ade7753_write_8bit,
327 ADE7753_LINECYC);
328static IIO_DEV_ATTR_WDIV(S_IWUSR | S_IRUGO,
329 ade7753_read_8bit,
330 ade7753_write_8bit,
331 ADE7753_WDIV);
332static IIO_DEV_ATTR_IRMS(S_IWUSR | S_IRUGO,
333 ade7753_read_24bit,
334 NULL,
335 ADE7753_IRMS);
336static IIO_DEV_ATTR_VRMS(S_IRUGO,
337 ade7753_read_24bit,
338 NULL,
339 ADE7753_VRMS);
340static IIO_DEV_ATTR_IRMSOS(S_IWUSR | S_IRUGO,
341 ade7753_read_16bit,
342 ade7753_write_16bit,
343 ADE7753_IRMSOS);
344static IIO_DEV_ATTR_VRMSOS(S_IWUSR | S_IRUGO,
345 ade7753_read_16bit,
346 ade7753_write_16bit,
347 ADE7753_VRMSOS);
348static IIO_DEV_ATTR_WGAIN(S_IWUSR | S_IRUGO,
349 ade7753_read_16bit,
350 ade7753_write_16bit,
351 ADE7753_WGAIN);
352static IIO_DEV_ATTR_VAGAIN(S_IWUSR | S_IRUGO,
353 ade7753_read_16bit,
354 ade7753_write_16bit,
355 ADE7753_VAGAIN);
356static IIO_DEV_ATTR_PGA_GAIN(S_IWUSR | S_IRUGO,
357 ade7753_read_16bit,
358 ade7753_write_16bit,
359 ADE7753_GAIN);
360static IIO_DEV_ATTR_IPKLVL(S_IWUSR | S_IRUGO,
361 ade7753_read_8bit,
362 ade7753_write_8bit,
363 ADE7753_IPKLVL);
364static IIO_DEV_ATTR_VPKLVL(S_IWUSR | S_IRUGO,
365 ade7753_read_8bit,
366 ade7753_write_8bit,
367 ADE7753_VPKLVL);
368static IIO_DEV_ATTR_IPEAK(S_IRUGO,
369 ade7753_read_24bit,
370 NULL,
371 ADE7753_IPEAK);
372static IIO_DEV_ATTR_VPEAK(S_IRUGO,
373 ade7753_read_24bit,
374 NULL,
375 ADE7753_VPEAK);
376static IIO_DEV_ATTR_VPERIOD(S_IRUGO,
377 ade7753_read_16bit,
378 NULL,
379 ADE7753_PERIOD);
380static IIO_DEV_ATTR_CH_OFF(1, S_IWUSR | S_IRUGO,
381 ade7753_read_8bit,
382 ade7753_write_8bit,
383 ADE7753_CH1OS);
384static IIO_DEV_ATTR_CH_OFF(2, S_IWUSR | S_IRUGO,
385 ade7753_read_8bit,
386 ade7753_write_8bit,
387 ADE7753_CH2OS);
388
389static int ade7753_set_irq(struct device *dev, bool enable)
390{
391 int ret;
392 u8 irqen;
393 ret = ade7753_spi_read_reg_8(dev, ADE7753_IRQEN, &irqen);
394 if (ret)
395 goto error_ret;
396
397 if (enable)
398 irqen |= 1 << 3; /* Enables an interrupt when a data is
399 present in the waveform register */
400 else
401 irqen &= ~(1 << 3);
402
403 ret = ade7753_spi_write_reg_8(dev, ADE7753_IRQEN, irqen);
404 if (ret)
405 goto error_ret;
406
407error_ret:
408 return ret;
409}
410
411/* Power down the device */
412int ade7753_stop_device(struct device *dev)
413{
414 int ret;
415 u16 val;
416 ade7753_spi_read_reg_16(dev,
417 ADE7753_MODE,
418 &val);
419 val |= 1 << 4; /* AD converters can be turned off */
420 ret = ade7753_spi_write_reg_16(dev,
421 ADE7753_MODE,
422 val);
423
424 return ret;
425}
426
427static int ade7753_initial_setup(struct ade7753_state *st)
428{
429 int ret;
430 struct device *dev = &st->indio_dev->dev;
431
432 /* use low spi speed for init */
433 st->us->mode = SPI_MODE_3;
434 spi_setup(st->us);
435
436 /* Disable IRQ */
437 ret = ade7753_set_irq(dev, false);
438 if (ret) {
439 dev_err(dev, "disable irq failed");
440 goto err_ret;
441 }
442
443 ade7753_reset(dev);
444 msleep(ADE7753_STARTUP_DELAY);
445
446err_ret:
447 return ret;
448}
449
450static ssize_t ade7753_read_frequency(struct device *dev,
451 struct device_attribute *attr,
452 char *buf)
453{
454 int ret, len = 0;
455 u8 t;
456 int sps;
457 ret = ade7753_spi_read_reg_8(dev,
458 ADE7753_MODE,
459 &t);
460 if (ret)
461 return ret;
462
463 t = (t >> 11) & 0x3;
464 sps = 27900 / (1 + t);
465
466 len = sprintf(buf, "%d SPS\n", sps);
467 return len;
468}
469
470static ssize_t ade7753_write_frequency(struct device *dev,
471 struct device_attribute *attr,
472 const char *buf,
473 size_t len)
474{
475 struct iio_dev *indio_dev = dev_get_drvdata(dev);
476 struct ade7753_state *st = iio_dev_get_devdata(indio_dev);
477 unsigned long val;
478 int ret;
479 u16 reg, t;
480
481 ret = strict_strtol(buf, 10, &val);
482 if (ret)
483 return ret;
484
485 mutex_lock(&indio_dev->mlock);
486
487 t = (27900 / val);
488 if (t > 0)
489 t--;
490
491 if (t > 1)
492 st->us->max_speed_hz = ADE7753_SPI_SLOW;
493 else
494 st->us->max_speed_hz = ADE7753_SPI_FAST;
495
496 ret = ade7753_spi_read_reg_16(dev,
497 ADE7753_MODE,
498 &reg);
499 if (ret)
500 goto out;
501
502 reg &= ~(3 << 11);
503 reg |= t << 11;
504
505 ret = ade7753_spi_write_reg_16(dev,
506 ADE7753_MODE,
507 reg);
508
509out:
510 mutex_unlock(&indio_dev->mlock);
511
512 return ret ? ret : len;
513}
514static IIO_DEV_ATTR_TEMP_RAW(ade7753_read_8bit);
515static IIO_CONST_ATTR(temp_offset, "-25 C");
516static IIO_CONST_ATTR(temp_scale, "0.67 C");
517
518static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
519 ade7753_read_frequency,
520 ade7753_write_frequency);
521
522static IIO_DEV_ATTR_RESET(ade7753_write_reset);
523
524static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("27900 14000 7000 3500");
525
526static IIO_CONST_ATTR(name, "ade7753");
527
528static struct attribute *ade7753_event_attributes[] = {
529 NULL
530};
531
532static struct attribute_group ade7753_event_attribute_group = {
533 .attrs = ade7753_event_attributes,
534};
535
536static struct attribute *ade7753_attributes[] = {
537 &iio_dev_attr_temp_raw.dev_attr.attr,
538 &iio_const_attr_temp_offset.dev_attr.attr,
539 &iio_const_attr_temp_scale.dev_attr.attr,
540 &iio_dev_attr_sampling_frequency.dev_attr.attr,
541 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
542 &iio_dev_attr_reset.dev_attr.attr,
543 &iio_const_attr_name.dev_attr.attr,
544 &iio_dev_attr_phcal.dev_attr.attr,
545 &iio_dev_attr_cfden.dev_attr.attr,
546 &iio_dev_attr_aenergy.dev_attr.attr,
547 &iio_dev_attr_laenergy.dev_attr.attr,
548 &iio_dev_attr_vaenergy.dev_attr.attr,
549 &iio_dev_attr_lvaenergy.dev_attr.attr,
550 &iio_dev_attr_cfnum.dev_attr.attr,
551 &iio_dev_attr_apos.dev_attr.attr,
552 &iio_dev_attr_sagcyc.dev_attr.attr,
553 &iio_dev_attr_saglvl.dev_attr.attr,
554 &iio_dev_attr_linecyc.dev_attr.attr,
555 &iio_dev_attr_chksum.dev_attr.attr,
556 &iio_dev_attr_pga_gain.dev_attr.attr,
557 &iio_dev_attr_wgain.dev_attr.attr,
558 &iio_dev_attr_choff_1.dev_attr.attr,
559 &iio_dev_attr_choff_2.dev_attr.attr,
560 &iio_dev_attr_wdiv.dev_attr.attr,
561 &iio_dev_attr_irms.dev_attr.attr,
562 &iio_dev_attr_vrms.dev_attr.attr,
563 &iio_dev_attr_irmsos.dev_attr.attr,
564 &iio_dev_attr_vrmsos.dev_attr.attr,
565 &iio_dev_attr_vagain.dev_attr.attr,
566 &iio_dev_attr_ipklvl.dev_attr.attr,
567 &iio_dev_attr_vpklvl.dev_attr.attr,
568 &iio_dev_attr_ipeak.dev_attr.attr,
569 &iio_dev_attr_vpeak.dev_attr.attr,
570 &iio_dev_attr_vperiod.dev_attr.attr,
571 NULL,
572};
573
574static const struct attribute_group ade7753_attribute_group = {
575 .attrs = ade7753_attributes,
576};
577
578static int __devinit ade7753_probe(struct spi_device *spi)
579{
580 int ret, regdone = 0;
581 struct ade7753_state *st = kzalloc(sizeof *st, GFP_KERNEL);
582 if (!st) {
583 ret = -ENOMEM;
584 goto error_ret;
585 }
586 /* this is only used for removal purposes */
587 spi_set_drvdata(spi, st);
588
589 /* Allocate the comms buffers */
590 st->rx = kzalloc(sizeof(*st->rx)*ADE7753_MAX_RX, GFP_KERNEL);
591 if (st->rx == NULL) {
592 ret = -ENOMEM;
593 goto error_free_st;
594 }
595 st->tx = kzalloc(sizeof(*st->tx)*ADE7753_MAX_TX, GFP_KERNEL);
596 if (st->tx == NULL) {
597 ret = -ENOMEM;
598 goto error_free_rx;
599 }
600 st->us = spi;
601 mutex_init(&st->buf_lock);
602 /* setup the industrialio driver allocated elements */
603 st->indio_dev = iio_allocate_device();
604 if (st->indio_dev == NULL) {
605 ret = -ENOMEM;
606 goto error_free_tx;
607 }
608
609 st->indio_dev->dev.parent = &spi->dev;
610 st->indio_dev->num_interrupt_lines = 1;
611 st->indio_dev->event_attrs = &ade7753_event_attribute_group;
612 st->indio_dev->attrs = &ade7753_attribute_group;
613 st->indio_dev->dev_data = (void *)(st);
614 st->indio_dev->driver_module = THIS_MODULE;
615 st->indio_dev->modes = INDIO_DIRECT_MODE;
616
617 ret = ade7753_configure_ring(st->indio_dev);
618 if (ret)
619 goto error_free_dev;
620
621 ret = iio_device_register(st->indio_dev);
622 if (ret)
623 goto error_unreg_ring_funcs;
624 regdone = 1;
625
626 ret = ade7753_initialize_ring(st->indio_dev->ring);
627 if (ret) {
628 printk(KERN_ERR "failed to initialize the ring\n");
629 goto error_unreg_ring_funcs;
630 }
631
632 if (spi->irq) {
633 ret = iio_register_interrupt_line(spi->irq,
634 st->indio_dev,
635 0,
636 IRQF_TRIGGER_FALLING,
637 "ade7753");
638 if (ret)
639 goto error_uninitialize_ring;
640
641 ret = ade7753_probe_trigger(st->indio_dev);
642 if (ret)
643 goto error_unregister_line;
644 }
645
646 /* Get the device into a sane initial state */
647 ret = ade7753_initial_setup(st);
648 if (ret)
649 goto error_remove_trigger;
650 return 0;
651
652error_remove_trigger:
653 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
654 ade7753_remove_trigger(st->indio_dev);
655error_unregister_line:
656 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
657 iio_unregister_interrupt_line(st->indio_dev, 0);
658error_uninitialize_ring:
659 ade7753_uninitialize_ring(st->indio_dev->ring);
660error_unreg_ring_funcs:
661 ade7753_unconfigure_ring(st->indio_dev);
662error_free_dev:
663 if (regdone)
664 iio_device_unregister(st->indio_dev);
665 else
666 iio_free_device(st->indio_dev);
667error_free_tx:
668 kfree(st->tx);
669error_free_rx:
670 kfree(st->rx);
671error_free_st:
672 kfree(st);
673error_ret:
674 return ret;
675}
676
677/* fixme, confirm ordering in this function */
678static int ade7753_remove(struct spi_device *spi)
679{
680 int ret;
681 struct ade7753_state *st = spi_get_drvdata(spi);
682 struct iio_dev *indio_dev = st->indio_dev;
683
684 ret = ade7753_stop_device(&(indio_dev->dev));
685 if (ret)
686 goto err_ret;
687
688 flush_scheduled_work();
689
690 ade7753_remove_trigger(indio_dev);
691 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
692 iio_unregister_interrupt_line(indio_dev, 0);
693
694 ade7753_uninitialize_ring(indio_dev->ring);
695 ade7753_unconfigure_ring(indio_dev);
696 iio_device_unregister(indio_dev);
697 kfree(st->tx);
698 kfree(st->rx);
699 kfree(st);
700
701 return 0;
702
703err_ret:
704 return ret;
705}
706
707static struct spi_driver ade7753_driver = {
708 .driver = {
709 .name = "ade7753",
710 .owner = THIS_MODULE,
711 },
712 .probe = ade7753_probe,
713 .remove = __devexit_p(ade7753_remove),
714};
715
716static __init int ade7753_init(void)
717{
718 return spi_register_driver(&ade7753_driver);
719}
720module_init(ade7753_init);
721
722static __exit void ade7753_exit(void)
723{
724 spi_unregister_driver(&ade7753_driver);
725}
726module_exit(ade7753_exit);
727
728MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
729MODULE_DESCRIPTION("Analog Devices ADE7753/6 Single-Phase Multifunction Metering IC Driver");
730MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/meter/ade7753.h b/drivers/staging/iio/meter/ade7753.h
new file mode 100644
index 000000000000..a3722b8c90fa
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7753.h
@@ -0,0 +1,140 @@
1#ifndef _ADE7753_H
2#define _ADE7753_H
3
4#define ADE7753_WAVEFORM 0x01
5#define ADE7753_AENERGY 0x02
6#define ADE7753_RAENERGY 0x03
7#define ADE7753_LAENERGY 0x04
8#define ADE7753_VAENERGY 0x05
9#define ADE7753_RVAENERGY 0x06
10#define ADE7753_LVAENERGY 0x07
11#define ADE7753_LVARENERGY 0x08
12#define ADE7753_MODE 0x09
13#define ADE7753_IRQEN 0x0A
14#define ADE7753_STATUS 0x0B
15#define ADE7753_RSTSTATUS 0x0C
16#define ADE7753_CH1OS 0x0D
17#define ADE7753_CH2OS 0x0E
18#define ADE7753_GAIN 0x0F
19#define ADE7753_PHCAL 0x10
20#define ADE7753_APOS 0x11
21#define ADE7753_WGAIN 0x12
22#define ADE7753_WDIV 0x13
23#define ADE7753_CFNUM 0x14
24#define ADE7753_CFDEN 0x15
25#define ADE7753_IRMS 0x16
26#define ADE7753_VRMS 0x17
27#define ADE7753_IRMSOS 0x18
28#define ADE7753_VRMSOS 0x19
29#define ADE7753_VAGAIN 0x1A
30#define ADE7753_VADIV 0x1B
31#define ADE7753_LINECYC 0x1C
32#define ADE7753_ZXTOUT 0x1D
33#define ADE7753_SAGCYC 0x1E
34#define ADE7753_SAGLVL 0x1F
35#define ADE7753_IPKLVL 0x20
36#define ADE7753_VPKLVL 0x21
37#define ADE7753_IPEAK 0x22
38#define ADE7753_RSTIPEAK 0x23
39#define ADE7753_VPEAK 0x24
40#define ADE7753_RSTVPEAK 0x25
41#define ADE7753_TEMP 0x26
42#define ADE7753_PERIOD 0x27
43#define ADE7753_TMODE 0x3D
44#define ADE7753_CHKSUM 0x3E
45#define ADE7753_DIEREV 0x3F
46
47#define ADE7753_READ_REG(a) a
48#define ADE7753_WRITE_REG(a) ((a) | 0x80)
49
50#define ADE7753_MAX_TX 4
51#define ADE7753_MAX_RX 4
52#define ADE7753_STARTUP_DELAY 1
53
54#define ADE7753_SPI_SLOW (u32)(300 * 1000)
55#define ADE7753_SPI_BURST (u32)(1000 * 1000)
56#define ADE7753_SPI_FAST (u32)(2000 * 1000)
57
58#define DRIVER_NAME "ade7753"
59
60/**
61 * struct ade7753_state - device instance specific data
62 * @us: actual spi_device
63 * @work_trigger_to_ring: bh for triggered event handling
64 * @inter: used to check if new interrupt has been triggered
65 * @last_timestamp: passing timestamp from th to bh of interrupt handler
66 * @indio_dev: industrial I/O device structure
67 * @trig: data ready trigger registered with iio
68 * @tx: transmit buffer
69 * @rx: recieve buffer
70 * @buf_lock: mutex to protect tx and rx
71 **/
72struct ade7753_state {
73 struct spi_device *us;
74 struct work_struct work_trigger_to_ring;
75 s64 last_timestamp;
76 struct iio_dev *indio_dev;
77 struct iio_trigger *trig;
78 u8 *tx;
79 u8 *rx;
80 struct mutex buf_lock;
81};
82#if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
83/* At the moment triggers are only used for ring buffer
84 * filling. This may change!
85 */
86
87enum ade7753_scan {
88 ADE7753_SCAN_ACTIVE_POWER,
89 ADE7753_SCAN_CH1,
90 ADE7753_SCAN_CH2,
91};
92
93void ade7753_remove_trigger(struct iio_dev *indio_dev);
94int ade7753_probe_trigger(struct iio_dev *indio_dev);
95
96ssize_t ade7753_read_data_from_ring(struct device *dev,
97 struct device_attribute *attr,
98 char *buf);
99
100
101int ade7753_configure_ring(struct iio_dev *indio_dev);
102void ade7753_unconfigure_ring(struct iio_dev *indio_dev);
103
104int ade7753_initialize_ring(struct iio_ring_buffer *ring);
105void ade7753_uninitialize_ring(struct iio_ring_buffer *ring);
106#else /* CONFIG_IIO_RING_BUFFER */
107
108static inline void ade7753_remove_trigger(struct iio_dev *indio_dev)
109{
110}
111static inline int ade7753_probe_trigger(struct iio_dev *indio_dev)
112{
113 return 0;
114}
115
116static inline ssize_t
117ade7753_read_data_from_ring(struct device *dev,
118 struct device_attribute *attr,
119 char *buf)
120{
121 return 0;
122}
123
124static int ade7753_configure_ring(struct iio_dev *indio_dev)
125{
126 return 0;
127}
128static inline void ade7753_unconfigure_ring(struct iio_dev *indio_dev)
129{
130}
131static inline int ade7753_initialize_ring(struct iio_ring_buffer *ring)
132{
133 return 0;
134}
135static inline void ade7753_uninitialize_ring(struct iio_ring_buffer *ring)
136{
137}
138#endif /* CONFIG_IIO_RING_BUFFER */
139
140#endif
diff --git a/drivers/staging/iio/meter/ade7754.c b/drivers/staging/iio/meter/ade7754.c
new file mode 100644
index 000000000000..23dedfa7a270
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7754.c
@@ -0,0 +1,756 @@
1/*
2 * ADE7754 Polyphase Multifunction Energy Metering IC Driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "meter.h"
24#include "ade7754.h"
25
26static int ade7754_spi_write_reg_8(struct device *dev,
27 u8 reg_address,
28 u8 val)
29{
30 int ret;
31 struct iio_dev *indio_dev = dev_get_drvdata(dev);
32 struct ade7754_state *st = iio_dev_get_devdata(indio_dev);
33
34 mutex_lock(&st->buf_lock);
35 st->tx[0] = ADE7754_WRITE_REG(reg_address);
36 st->tx[1] = val;
37
38 ret = spi_write(st->us, st->tx, 2);
39 mutex_unlock(&st->buf_lock);
40
41 return ret;
42}
43
44static int ade7754_spi_write_reg_16(struct device *dev,
45 u8 reg_address,
46 u16 value)
47{
48 int ret;
49 struct spi_message msg;
50 struct iio_dev *indio_dev = dev_get_drvdata(dev);
51 struct ade7754_state *st = iio_dev_get_devdata(indio_dev);
52 struct spi_transfer xfers[] = {
53 {
54 .tx_buf = st->tx,
55 .bits_per_word = 8,
56 .len = 3,
57 }
58 };
59
60 mutex_lock(&st->buf_lock);
61 st->tx[0] = ADE7754_WRITE_REG(reg_address);
62 st->tx[1] = (value >> 8) & 0xFF;
63 st->tx[2] = value & 0xFF;
64
65 spi_message_init(&msg);
66 spi_message_add_tail(xfers, &msg);
67 ret = spi_sync(st->us, &msg);
68 mutex_unlock(&st->buf_lock);
69
70 return ret;
71}
72
73static int ade7754_spi_read_reg_8(struct device *dev,
74 u8 reg_address,
75 u8 *val)
76{
77 struct spi_message msg;
78 struct iio_dev *indio_dev = dev_get_drvdata(dev);
79 struct ade7754_state *st = iio_dev_get_devdata(indio_dev);
80 int ret;
81 struct spi_transfer xfers[] = {
82 {
83 .tx_buf = st->tx,
84 .rx_buf = st->rx,
85 .bits_per_word = 8,
86 .len = 2,
87 },
88 };
89
90 mutex_lock(&st->buf_lock);
91 st->tx[0] = ADE7754_READ_REG(reg_address);
92 st->tx[1] = 0;
93
94 spi_message_init(&msg);
95 spi_message_add_tail(xfers, &msg);
96 ret = spi_sync(st->us, &msg);
97 if (ret) {
98 dev_err(&st->us->dev, "problem when reading 8 bit register 0x%02X",
99 reg_address);
100 goto error_ret;
101 }
102 *val = st->rx[1];
103
104error_ret:
105 mutex_unlock(&st->buf_lock);
106 return ret;
107}
108
109static int ade7754_spi_read_reg_16(struct device *dev,
110 u8 reg_address,
111 u16 *val)
112{
113 struct spi_message msg;
114 struct iio_dev *indio_dev = dev_get_drvdata(dev);
115 struct ade7754_state *st = iio_dev_get_devdata(indio_dev);
116 int ret;
117 struct spi_transfer xfers[] = {
118 {
119 .tx_buf = st->tx,
120 .rx_buf = st->rx,
121 .bits_per_word = 8,
122 .len = 3,
123 },
124 };
125
126 mutex_lock(&st->buf_lock);
127 st->tx[0] = ADE7754_READ_REG(reg_address);
128 st->tx[1] = 0;
129 st->tx[2] = 0;
130
131 spi_message_init(&msg);
132 spi_message_add_tail(xfers, &msg);
133 ret = spi_sync(st->us, &msg);
134 if (ret) {
135 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
136 reg_address);
137 goto error_ret;
138 }
139 *val = (st->rx[1] << 8) | st->rx[2];
140
141error_ret:
142 mutex_unlock(&st->buf_lock);
143 return ret;
144}
145
146static int ade7754_spi_read_reg_24(struct device *dev,
147 u8 reg_address,
148 u32 *val)
149{
150 struct spi_message msg;
151 struct iio_dev *indio_dev = dev_get_drvdata(dev);
152 struct ade7754_state *st = iio_dev_get_devdata(indio_dev);
153 int ret;
154 struct spi_transfer xfers[] = {
155 {
156 .tx_buf = st->tx,
157 .rx_buf = st->rx,
158 .bits_per_word = 8,
159 .len = 4,
160 },
161 };
162
163 mutex_lock(&st->buf_lock);
164 st->tx[0] = ADE7754_READ_REG(reg_address);
165 st->tx[1] = 0;
166 st->tx[2] = 0;
167 st->tx[3] = 0;
168
169 spi_message_init(&msg);
170 spi_message_add_tail(xfers, &msg);
171 ret = spi_sync(st->us, &msg);
172 if (ret) {
173 dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X",
174 reg_address);
175 goto error_ret;
176 }
177 *val = (st->rx[1] << 16) | (st->rx[2] << 8) | st->rx[3];
178
179error_ret:
180 mutex_unlock(&st->buf_lock);
181 return ret;
182}
183
184static ssize_t ade7754_read_8bit(struct device *dev,
185 struct device_attribute *attr,
186 char *buf)
187{
188 int ret;
189 u8 val = 0;
190 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
191
192 ret = ade7754_spi_read_reg_8(dev, this_attr->address, &val);
193 if (ret)
194 return ret;
195
196 return sprintf(buf, "%u\n", val);
197}
198
199static ssize_t ade7754_read_16bit(struct device *dev,
200 struct device_attribute *attr,
201 char *buf)
202{
203 int ret;
204 u16 val = 0;
205 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
206
207 ret = ade7754_spi_read_reg_16(dev, this_attr->address, &val);
208 if (ret)
209 return ret;
210
211 return sprintf(buf, "%u\n", val);
212}
213
214static ssize_t ade7754_read_24bit(struct device *dev,
215 struct device_attribute *attr,
216 char *buf)
217{
218 int ret;
219 u32 val = 0;
220 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
221
222 ret = ade7754_spi_read_reg_24(dev, this_attr->address, &val);
223 if (ret)
224 return ret;
225
226 return sprintf(buf, "%u\n", val & 0xFFFFFF);
227}
228
229static ssize_t ade7754_write_8bit(struct device *dev,
230 struct device_attribute *attr,
231 const char *buf,
232 size_t len)
233{
234 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
235 int ret;
236 long val;
237
238 ret = strict_strtol(buf, 10, &val);
239 if (ret)
240 goto error_ret;
241 ret = ade7754_spi_write_reg_8(dev, this_attr->address, val);
242
243error_ret:
244 return ret ? ret : len;
245}
246
247static ssize_t ade7754_write_16bit(struct device *dev,
248 struct device_attribute *attr,
249 const char *buf,
250 size_t len)
251{
252 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
253 int ret;
254 long val;
255
256 ret = strict_strtol(buf, 10, &val);
257 if (ret)
258 goto error_ret;
259 ret = ade7754_spi_write_reg_16(dev, this_attr->address, val);
260
261error_ret:
262 return ret ? ret : len;
263}
264
265static int ade7754_reset(struct device *dev)
266{
267 int ret;
268 u8 val;
269 ade7754_spi_read_reg_8(dev,
270 ADE7754_OPMODE,
271 &val);
272 val |= 1 << 6; /* Software Chip Reset */
273 ret = ade7754_spi_write_reg_8(dev,
274 ADE7754_OPMODE,
275 val);
276
277 return ret;
278}
279
280
281static ssize_t ade7754_write_reset(struct device *dev,
282 struct device_attribute *attr,
283 const char *buf, size_t len)
284{
285 if (len < 1)
286 return -1;
287 switch (buf[0]) {
288 case '1':
289 case 'y':
290 case 'Y':
291 return ade7754_reset(dev);
292 }
293 return -1;
294}
295
296static IIO_DEV_ATTR_AENERGY(ade7754_read_24bit, ADE7754_AENERGY);
297static IIO_DEV_ATTR_LAENERGY(ade7754_read_24bit, ADE7754_LAENERGY);
298static IIO_DEV_ATTR_VAENERGY(ade7754_read_24bit, ADE7754_VAENERGY);
299static IIO_DEV_ATTR_LVAENERGY(ade7754_read_24bit, ADE7754_LVAENERGY);
300static IIO_DEV_ATTR_VPEAK(S_IWUSR | S_IRUGO,
301 ade7754_read_8bit,
302 ade7754_write_8bit,
303 ADE7754_VPEAK);
304static IIO_DEV_ATTR_IPEAK(S_IWUSR | S_IRUGO,
305 ade7754_read_8bit,
306 ade7754_write_8bit,
307 ADE7754_VPEAK);
308static IIO_DEV_ATTR_APHCAL(S_IWUSR | S_IRUGO,
309 ade7754_read_8bit,
310 ade7754_write_8bit,
311 ADE7754_APHCAL);
312static IIO_DEV_ATTR_BPHCAL(S_IWUSR | S_IRUGO,
313 ade7754_read_8bit,
314 ade7754_write_8bit,
315 ADE7754_BPHCAL);
316static IIO_DEV_ATTR_CPHCAL(S_IWUSR | S_IRUGO,
317 ade7754_read_8bit,
318 ade7754_write_8bit,
319 ADE7754_CPHCAL);
320static IIO_DEV_ATTR_AAPOS(S_IWUSR | S_IRUGO,
321 ade7754_read_16bit,
322 ade7754_write_16bit,
323 ADE7754_AAPOS);
324static IIO_DEV_ATTR_BAPOS(S_IWUSR | S_IRUGO,
325 ade7754_read_16bit,
326 ade7754_write_16bit,
327 ADE7754_BAPOS);
328static IIO_DEV_ATTR_CAPOS(S_IWUSR | S_IRUGO,
329 ade7754_read_16bit,
330 ade7754_write_16bit,
331 ADE7754_CAPOS);
332static IIO_DEV_ATTR_WDIV(S_IWUSR | S_IRUGO,
333 ade7754_read_8bit,
334 ade7754_write_8bit,
335 ADE7754_WDIV);
336static IIO_DEV_ATTR_VADIV(S_IWUSR | S_IRUGO,
337 ade7754_read_8bit,
338 ade7754_write_8bit,
339 ADE7754_VADIV);
340static IIO_DEV_ATTR_CFNUM(S_IWUSR | S_IRUGO,
341 ade7754_read_16bit,
342 ade7754_write_16bit,
343 ADE7754_CFNUM);
344static IIO_DEV_ATTR_CFDEN(S_IWUSR | S_IRUGO,
345 ade7754_read_16bit,
346 ade7754_write_16bit,
347 ADE7754_CFDEN);
348static IIO_DEV_ATTR_ACTIVE_POWER_A_GAIN(S_IWUSR | S_IRUGO,
349 ade7754_read_16bit,
350 ade7754_write_16bit,
351 ADE7754_AAPGAIN);
352static IIO_DEV_ATTR_ACTIVE_POWER_B_GAIN(S_IWUSR | S_IRUGO,
353 ade7754_read_16bit,
354 ade7754_write_16bit,
355 ADE7754_BAPGAIN);
356static IIO_DEV_ATTR_ACTIVE_POWER_C_GAIN(S_IWUSR | S_IRUGO,
357 ade7754_read_16bit,
358 ade7754_write_16bit,
359 ADE7754_CAPGAIN);
360static IIO_DEV_ATTR_AIRMS(S_IRUGO,
361 ade7754_read_24bit,
362 NULL,
363 ADE7754_AIRMS);
364static IIO_DEV_ATTR_BIRMS(S_IRUGO,
365 ade7754_read_24bit,
366 NULL,
367 ADE7754_BIRMS);
368static IIO_DEV_ATTR_CIRMS(S_IRUGO,
369 ade7754_read_24bit,
370 NULL,
371 ADE7754_CIRMS);
372static IIO_DEV_ATTR_AVRMS(S_IRUGO,
373 ade7754_read_24bit,
374 NULL,
375 ADE7754_AVRMS);
376static IIO_DEV_ATTR_BVRMS(S_IRUGO,
377 ade7754_read_24bit,
378 NULL,
379 ADE7754_BVRMS);
380static IIO_DEV_ATTR_CVRMS(S_IRUGO,
381 ade7754_read_24bit,
382 NULL,
383 ADE7754_CVRMS);
384static IIO_DEV_ATTR_AIRMSOS(S_IRUGO,
385 ade7754_read_16bit,
386 ade7754_write_16bit,
387 ADE7754_AIRMSOS);
388static IIO_DEV_ATTR_BIRMSOS(S_IRUGO,
389 ade7754_read_16bit,
390 ade7754_write_16bit,
391 ADE7754_BIRMSOS);
392static IIO_DEV_ATTR_CIRMSOS(S_IRUGO,
393 ade7754_read_16bit,
394 ade7754_write_16bit,
395 ADE7754_CIRMSOS);
396static IIO_DEV_ATTR_AVRMSOS(S_IRUGO,
397 ade7754_read_16bit,
398 ade7754_write_16bit,
399 ADE7754_AVRMSOS);
400static IIO_DEV_ATTR_BVRMSOS(S_IRUGO,
401 ade7754_read_16bit,
402 ade7754_write_16bit,
403 ADE7754_BVRMSOS);
404static IIO_DEV_ATTR_CVRMSOS(S_IRUGO,
405 ade7754_read_16bit,
406 ade7754_write_16bit,
407 ADE7754_CVRMSOS);
408
409static int ade7754_set_irq(struct device *dev, bool enable)
410{
411 int ret;
412 u16 irqen;
413 ret = ade7754_spi_read_reg_16(dev, ADE7754_IRQEN, &irqen);
414 if (ret)
415 goto error_ret;
416
417 if (enable)
418 irqen |= 1 << 14; /* Enables an interrupt when a data is
419 present in the waveform register */
420 else
421 irqen &= ~(1 << 14);
422
423 ret = ade7754_spi_write_reg_16(dev, ADE7754_IRQEN, irqen);
424 if (ret)
425 goto error_ret;
426
427error_ret:
428 return ret;
429}
430
431/* Power down the device */
432static int ade7754_stop_device(struct device *dev)
433{
434 int ret;
435 u8 val;
436 ade7754_spi_read_reg_8(dev,
437 ADE7754_OPMODE,
438 &val);
439 val |= 7 << 3; /* ADE7754 powered down */
440 ret = ade7754_spi_write_reg_8(dev,
441 ADE7754_OPMODE,
442 val);
443
444 return ret;
445}
446
447static int ade7754_initial_setup(struct ade7754_state *st)
448{
449 int ret;
450 struct device *dev = &st->indio_dev->dev;
451
452 /* use low spi speed for init */
453 st->us->mode = SPI_MODE_3;
454 spi_setup(st->us);
455
456 /* Disable IRQ */
457 ret = ade7754_set_irq(dev, false);
458 if (ret) {
459 dev_err(dev, "disable irq failed");
460 goto err_ret;
461 }
462
463 ade7754_reset(dev);
464 msleep(ADE7754_STARTUP_DELAY);
465
466err_ret:
467 return ret;
468}
469
470static ssize_t ade7754_read_frequency(struct device *dev,
471 struct device_attribute *attr,
472 char *buf)
473{
474 int ret, len = 0;
475 u8 t;
476 int sps;
477 ret = ade7754_spi_read_reg_8(dev,
478 ADE7754_WAVMODE,
479 &t);
480 if (ret)
481 return ret;
482
483 t = (t >> 3) & 0x3;
484 sps = 26000 / (1 + t);
485
486 len = sprintf(buf, "%d SPS\n", sps);
487 return len;
488}
489
490static ssize_t ade7754_write_frequency(struct device *dev,
491 struct device_attribute *attr,
492 const char *buf,
493 size_t len)
494{
495 struct iio_dev *indio_dev = dev_get_drvdata(dev);
496 struct ade7754_state *st = iio_dev_get_devdata(indio_dev);
497 unsigned long val;
498 int ret;
499 u8 reg, t;
500
501 ret = strict_strtol(buf, 10, &val);
502 if (ret)
503 return ret;
504
505 mutex_lock(&indio_dev->mlock);
506
507 t = (26000 / val);
508 if (t > 0)
509 t--;
510
511 if (t > 1)
512 st->us->max_speed_hz = ADE7754_SPI_SLOW;
513 else
514 st->us->max_speed_hz = ADE7754_SPI_FAST;
515
516 ret = ade7754_spi_read_reg_8(dev,
517 ADE7754_WAVMODE,
518 &reg);
519 if (ret)
520 goto out;
521
522 reg &= ~(3 << 3);
523 reg |= t << 3;
524
525 ret = ade7754_spi_write_reg_8(dev,
526 ADE7754_WAVMODE,
527 reg);
528
529out:
530 mutex_unlock(&indio_dev->mlock);
531
532 return ret ? ret : len;
533}
534static IIO_DEV_ATTR_TEMP_RAW(ade7754_read_8bit);
535static IIO_CONST_ATTR(temp_offset, "129 C");
536static IIO_CONST_ATTR(temp_scale, "4 C");
537
538static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
539 ade7754_read_frequency,
540 ade7754_write_frequency);
541
542static IIO_DEV_ATTR_RESET(ade7754_write_reset);
543
544static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("26000 13000 65000 33000");
545
546static IIO_CONST_ATTR(name, "ade7754");
547
548static struct attribute *ade7754_event_attributes[] = {
549 NULL
550};
551
552static struct attribute_group ade7754_event_attribute_group = {
553 .attrs = ade7754_event_attributes,
554};
555
556static struct attribute *ade7754_attributes[] = {
557 &iio_dev_attr_temp_raw.dev_attr.attr,
558 &iio_const_attr_temp_offset.dev_attr.attr,
559 &iio_const_attr_temp_scale.dev_attr.attr,
560 &iio_dev_attr_sampling_frequency.dev_attr.attr,
561 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
562 &iio_dev_attr_reset.dev_attr.attr,
563 &iio_const_attr_name.dev_attr.attr,
564 &iio_dev_attr_aenergy.dev_attr.attr,
565 &iio_dev_attr_laenergy.dev_attr.attr,
566 &iio_dev_attr_vaenergy.dev_attr.attr,
567 &iio_dev_attr_lvaenergy.dev_attr.attr,
568 &iio_dev_attr_vpeak.dev_attr.attr,
569 &iio_dev_attr_ipeak.dev_attr.attr,
570 &iio_dev_attr_aphcal.dev_attr.attr,
571 &iio_dev_attr_bphcal.dev_attr.attr,
572 &iio_dev_attr_cphcal.dev_attr.attr,
573 &iio_dev_attr_aapos.dev_attr.attr,
574 &iio_dev_attr_bapos.dev_attr.attr,
575 &iio_dev_attr_capos.dev_attr.attr,
576 &iio_dev_attr_wdiv.dev_attr.attr,
577 &iio_dev_attr_vadiv.dev_attr.attr,
578 &iio_dev_attr_cfnum.dev_attr.attr,
579 &iio_dev_attr_cfden.dev_attr.attr,
580 &iio_dev_attr_active_power_a_gain.dev_attr.attr,
581 &iio_dev_attr_active_power_b_gain.dev_attr.attr,
582 &iio_dev_attr_active_power_c_gain.dev_attr.attr,
583 &iio_dev_attr_airms.dev_attr.attr,
584 &iio_dev_attr_birms.dev_attr.attr,
585 &iio_dev_attr_cirms.dev_attr.attr,
586 &iio_dev_attr_avrms.dev_attr.attr,
587 &iio_dev_attr_bvrms.dev_attr.attr,
588 &iio_dev_attr_cvrms.dev_attr.attr,
589 &iio_dev_attr_airmsos.dev_attr.attr,
590 &iio_dev_attr_birmsos.dev_attr.attr,
591 &iio_dev_attr_cirmsos.dev_attr.attr,
592 &iio_dev_attr_avrmsos.dev_attr.attr,
593 &iio_dev_attr_bvrmsos.dev_attr.attr,
594 &iio_dev_attr_cvrmsos.dev_attr.attr,
595 NULL,
596};
597
598static const struct attribute_group ade7754_attribute_group = {
599 .attrs = ade7754_attributes,
600};
601
602
603
604static int __devinit ade7754_probe(struct spi_device *spi)
605{
606 int ret, regdone = 0;
607 struct ade7754_state *st = kzalloc(sizeof *st, GFP_KERNEL);
608 if (!st) {
609 ret = -ENOMEM;
610 goto error_ret;
611 }
612 /* this is only used for removal purposes */
613 spi_set_drvdata(spi, st);
614
615 /* Allocate the comms buffers */
616 st->rx = kzalloc(sizeof(*st->rx)*ADE7754_MAX_RX, GFP_KERNEL);
617 if (st->rx == NULL) {
618 ret = -ENOMEM;
619 goto error_free_st;
620 }
621 st->tx = kzalloc(sizeof(*st->tx)*ADE7754_MAX_TX, GFP_KERNEL);
622 if (st->tx == NULL) {
623 ret = -ENOMEM;
624 goto error_free_rx;
625 }
626 st->us = spi;
627 mutex_init(&st->buf_lock);
628 /* setup the industrialio driver allocated elements */
629 st->indio_dev = iio_allocate_device();
630 if (st->indio_dev == NULL) {
631 ret = -ENOMEM;
632 goto error_free_tx;
633 }
634
635 st->indio_dev->dev.parent = &spi->dev;
636 st->indio_dev->num_interrupt_lines = 1;
637 st->indio_dev->event_attrs = &ade7754_event_attribute_group;
638 st->indio_dev->attrs = &ade7754_attribute_group;
639 st->indio_dev->dev_data = (void *)(st);
640 st->indio_dev->driver_module = THIS_MODULE;
641 st->indio_dev->modes = INDIO_DIRECT_MODE;
642
643 ret = ade7754_configure_ring(st->indio_dev);
644 if (ret)
645 goto error_free_dev;
646
647 ret = iio_device_register(st->indio_dev);
648 if (ret)
649 goto error_unreg_ring_funcs;
650 regdone = 1;
651
652 ret = ade7754_initialize_ring(st->indio_dev->ring);
653 if (ret) {
654 printk(KERN_ERR "failed to initialize the ring\n");
655 goto error_unreg_ring_funcs;
656 }
657
658 if (spi->irq) {
659 ret = iio_register_interrupt_line(spi->irq,
660 st->indio_dev,
661 0,
662 IRQF_TRIGGER_FALLING,
663 "ade7754");
664 if (ret)
665 goto error_uninitialize_ring;
666
667 ret = ade7754_probe_trigger(st->indio_dev);
668 if (ret)
669 goto error_unregister_line;
670 }
671
672 /* Get the device into a sane initial state */
673 ret = ade7754_initial_setup(st);
674 if (ret)
675 goto error_remove_trigger;
676 return 0;
677
678error_remove_trigger:
679 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
680 ade7754_remove_trigger(st->indio_dev);
681error_unregister_line:
682 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
683 iio_unregister_interrupt_line(st->indio_dev, 0);
684error_uninitialize_ring:
685 ade7754_uninitialize_ring(st->indio_dev->ring);
686error_unreg_ring_funcs:
687 ade7754_unconfigure_ring(st->indio_dev);
688error_free_dev:
689 if (regdone)
690 iio_device_unregister(st->indio_dev);
691 else
692 iio_free_device(st->indio_dev);
693error_free_tx:
694 kfree(st->tx);
695error_free_rx:
696 kfree(st->rx);
697error_free_st:
698 kfree(st);
699error_ret:
700 return ret;
701}
702
703/* fixme, confirm ordering in this function */
704static int ade7754_remove(struct spi_device *spi)
705{
706 int ret;
707 struct ade7754_state *st = spi_get_drvdata(spi);
708 struct iio_dev *indio_dev = st->indio_dev;
709
710 ret = ade7754_stop_device(&(indio_dev->dev));
711 if (ret)
712 goto err_ret;
713
714 flush_scheduled_work();
715
716 ade7754_remove_trigger(indio_dev);
717 if (spi->irq)
718 iio_unregister_interrupt_line(indio_dev, 0);
719
720 ade7754_uninitialize_ring(indio_dev->ring);
721 ade7754_unconfigure_ring(indio_dev);
722 iio_device_unregister(indio_dev);
723 kfree(st->tx);
724 kfree(st->rx);
725 kfree(st);
726
727 return 0;
728
729err_ret:
730 return ret;
731}
732
733static struct spi_driver ade7754_driver = {
734 .driver = {
735 .name = "ade7754",
736 .owner = THIS_MODULE,
737 },
738 .probe = ade7754_probe,
739 .remove = __devexit_p(ade7754_remove),
740};
741
742static __init int ade7754_init(void)
743{
744 return spi_register_driver(&ade7754_driver);
745}
746module_init(ade7754_init);
747
748static __exit void ade7754_exit(void)
749{
750 spi_unregister_driver(&ade7754_driver);
751}
752module_exit(ade7754_exit);
753
754MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
755MODULE_DESCRIPTION("Analog Devices ADE7754 Polyphase Multifunction Energy Metering IC Driver");
756MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/meter/ade7754.h b/drivers/staging/iio/meter/ade7754.h
new file mode 100644
index 000000000000..f6a3e4b926cf
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7754.h
@@ -0,0 +1,161 @@
1#ifndef _ADE7754_H
2#define _ADE7754_H
3
4#define ADE7754_AENERGY 0x01
5#define ADE7754_RAENERGY 0x02
6#define ADE7754_LAENERGY 0x03
7#define ADE7754_VAENERGY 0x04
8#define ADE7754_RVAENERGY 0x05
9#define ADE7754_LVAENERGY 0x06
10#define ADE7754_PERIOD 0x07
11#define ADE7754_TEMP 0x08
12#define ADE7754_WFORM 0x09
13#define ADE7754_OPMODE 0x0A
14#define ADE7754_MMODE 0x0B
15#define ADE7754_WAVMODE 0x0C
16#define ADE7754_WATMODE 0x0D
17#define ADE7754_VAMODE 0x0E
18#define ADE7754_IRQEN 0x0F
19#define ADE7754_STATUS 0x10
20#define ADE7754_RSTATUS 0x11
21#define ADE7754_ZXTOUT 0x12
22#define ADE7754_LINCYC 0x13
23#define ADE7754_SAGCYC 0x14
24#define ADE7754_SAGLVL 0x15
25#define ADE7754_VPEAK 0x16
26#define ADE7754_IPEAK 0x17
27#define ADE7754_GAIN 0x18
28#define ADE7754_AWG 0x19
29#define ADE7754_BWG 0x1A
30#define ADE7754_CWG 0x1B
31#define ADE7754_AVAG 0x1C
32#define ADE7754_BVAG 0x1D
33#define ADE7754_CVAG 0x1E
34#define ADE7754_APHCAL 0x1F
35#define ADE7754_BPHCAL 0x20
36#define ADE7754_CPHCAL 0x21
37#define ADE7754_AAPOS 0x22
38#define ADE7754_BAPOS 0x23
39#define ADE7754_CAPOS 0x24
40#define ADE7754_CFNUM 0x25
41#define ADE7754_CFDEN 0x26
42#define ADE7754_WDIV 0x27
43#define ADE7754_VADIV 0x28
44#define ADE7754_AIRMS 0x29
45#define ADE7754_BIRMS 0x2A
46#define ADE7754_CIRMS 0x2B
47#define ADE7754_AVRMS 0x2C
48#define ADE7754_BVRMS 0x2D
49#define ADE7754_CVRMS 0x2E
50#define ADE7754_AIRMSOS 0x2F
51#define ADE7754_BIRMSOS 0x30
52#define ADE7754_CIRMSOS 0x31
53#define ADE7754_AVRMSOS 0x32
54#define ADE7754_BVRMSOS 0x33
55#define ADE7754_CVRMSOS 0x34
56#define ADE7754_AAPGAIN 0x35
57#define ADE7754_BAPGAIN 0x36
58#define ADE7754_CAPGAIN 0x37
59#define ADE7754_AVGAIN 0x38
60#define ADE7754_BVGAIN 0x39
61#define ADE7754_CVGAIN 0x3A
62#define ADE7754_CHKSUM 0x3E
63#define ADE7754_VERSION 0x3F
64
65#define ADE7754_READ_REG(a) a
66#define ADE7754_WRITE_REG(a) ((a) | 0x80)
67
68#define ADE7754_MAX_TX 4
69#define ADE7754_MAX_RX 4
70#define ADE7754_STARTUP_DELAY 1
71
72#define ADE7754_SPI_SLOW (u32)(300 * 1000)
73#define ADE7754_SPI_BURST (u32)(1000 * 1000)
74#define ADE7754_SPI_FAST (u32)(2000 * 1000)
75
76#define DRIVER_NAME "ade7754"
77
78/**
79 * struct ade7754_state - device instance specific data
80 * @us: actual spi_device
81 * @work_trigger_to_ring: bh for triggered event handling
82 * @inter: used to check if new interrupt has been triggered
83 * @last_timestamp: passing timestamp from th to bh of interrupt handler
84 * @indio_dev: industrial I/O device structure
85 * @trig: data ready trigger registered with iio
86 * @tx: transmit buffer
87 * @rx: recieve buffer
88 * @buf_lock: mutex to protect tx and rx
89 **/
90struct ade7754_state {
91 struct spi_device *us;
92 struct work_struct work_trigger_to_ring;
93 s64 last_timestamp;
94 struct iio_dev *indio_dev;
95 struct iio_trigger *trig;
96 u8 *tx;
97 u8 *rx;
98 struct mutex buf_lock;
99};
100#if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
101/* At the moment triggers are only used for ring buffer
102 * filling. This may change!
103 */
104
105enum ade7754_scan {
106 ADE7754_SCAN_PHA_V,
107 ADE7754_SCAN_PHB_V,
108 ADE7754_SCAN_PHC_V,
109 ADE7754_SCAN_PHA_I,
110 ADE7754_SCAN_PHB_I,
111 ADE7754_SCAN_PHC_I,
112};
113
114void ade7754_remove_trigger(struct iio_dev *indio_dev);
115int ade7754_probe_trigger(struct iio_dev *indio_dev);
116
117ssize_t ade7754_read_data_from_ring(struct device *dev,
118 struct device_attribute *attr,
119 char *buf);
120
121
122int ade7754_configure_ring(struct iio_dev *indio_dev);
123void ade7754_unconfigure_ring(struct iio_dev *indio_dev);
124
125int ade7754_initialize_ring(struct iio_ring_buffer *ring);
126void ade7754_uninitialize_ring(struct iio_ring_buffer *ring);
127#else /* CONFIG_IIO_RING_BUFFER */
128
129static inline void ade7754_remove_trigger(struct iio_dev *indio_dev)
130{
131}
132static inline int ade7754_probe_trigger(struct iio_dev *indio_dev)
133{
134 return 0;
135}
136
137static inline ssize_t
138ade7754_read_data_from_ring(struct device *dev,
139 struct device_attribute *attr,
140 char *buf)
141{
142 return 0;
143}
144
145static int ade7754_configure_ring(struct iio_dev *indio_dev)
146{
147 return 0;
148}
149static inline void ade7754_unconfigure_ring(struct iio_dev *indio_dev)
150{
151}
152static inline int ade7754_initialize_ring(struct iio_ring_buffer *ring)
153{
154 return 0;
155}
156static inline void ade7754_uninitialize_ring(struct iio_ring_buffer *ring)
157{
158}
159#endif /* CONFIG_IIO_RING_BUFFER */
160
161#endif
diff --git a/drivers/staging/iio/meter/ade7758.h b/drivers/staging/iio/meter/ade7758.h
new file mode 100644
index 000000000000..df5bb7ba5a0f
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7758.h
@@ -0,0 +1,171 @@
1#ifndef _ADE7758_H
2#define _ADE7758_H
3
4#define ADE7758_AWATTHR 0x01
5#define ADE7758_BWATTHR 0x02
6#define ADE7758_CWATTHR 0x03
7#define ADE7758_AVARHR 0x04
8#define ADE7758_BVARHR 0x05
9#define ADE7758_CVARHR 0x06
10#define ADE7758_AVAHR 0x07
11#define ADE7758_BVAHR 0x08
12#define ADE7758_CVAHR 0x09
13#define ADE7758_AIRMS 0x0A
14#define ADE7758_BIRMS 0x0B
15#define ADE7758_CIRMS 0x0C
16#define ADE7758_AVRMS 0x0D
17#define ADE7758_BVRMS 0x0E
18#define ADE7758_CVRMS 0x0F
19#define ADE7758_FREQ 0x10
20#define ADE7758_TEMP 0x11
21#define ADE7758_WFORM 0x12
22#define ADE7758_OPMODE 0x13
23#define ADE7758_MMODE 0x14
24#define ADE7758_WAVMODE 0x15
25#define ADE7758_COMPMODE 0x16
26#define ADE7758_LCYCMODE 0x17
27#define ADE7758_MASK 0x18
28#define ADE7758_STATUS 0x19
29#define ADE7758_RSTATUS 0x1A
30#define ADE7758_ZXTOUT 0x1B
31#define ADE7758_LINECYC 0x1C
32#define ADE7758_SAGCYC 0x1D
33#define ADE7758_SAGLVL 0x1E
34#define ADE7758_VPINTLVL 0x1F
35#define ADE7758_IPINTLVL 0x20
36#define ADE7758_VPEAK 0x21
37#define ADE7758_IPEAK 0x22
38#define ADE7758_GAIN 0x23
39#define ADE7758_AVRMSGAIN 0x24
40#define ADE7758_BVRMSGAIN 0x25
41#define ADE7758_CVRMSGAIN 0x26
42#define ADE7758_AIGAIN 0x27
43#define ADE7758_BIGAIN 0x28
44#define ADE7758_CIGAIN 0x29
45#define ADE7758_AWG 0x2A
46#define ADE7758_BWG 0x2B
47#define ADE7758_CWG 0x2C
48#define ADE7758_AVARG 0x2D
49#define ADE7758_BVARG 0x2E
50#define ADE7758_CVARG 0x2F
51#define ADE7758_AVAG 0x30
52#define ADE7758_BVAG 0x31
53#define ADE7758_CVAG 0x32
54#define ADE7758_AVRMSOS 0x33
55#define ADE7758_BVRMSOS 0x34
56#define ADE7758_CVRMSOS 0x35
57#define ADE7758_AIRMSOS 0x36
58#define ADE7758_BIRMSOS 0x37
59#define ADE7758_CIRMSOS 0x38
60#define ADE7758_AWAITOS 0x39
61#define ADE7758_BWAITOS 0x3A
62#define ADE7758_CWAITOS 0x3B
63#define ADE7758_AVAROS 0x3C
64#define ADE7758_BVAROS 0x3D
65#define ADE7758_CVAROS 0x3E
66#define ADE7758_APHCAL 0x3F
67#define ADE7758_BPHCAL 0x40
68#define ADE7758_CPHCAL 0x41
69#define ADE7758_WDIV 0x42
70#define ADE7758_VADIV 0x44
71#define ADE7758_VARDIV 0x43
72#define ADE7758_APCFNUM 0x45
73#define ADE7758_APCFDEN 0x46
74#define ADE7758_VARCFNUM 0x47
75#define ADE7758_VARCFDEN 0x48
76#define ADE7758_CHKSUM 0x7E
77#define ADE7758_VERSION 0x7F
78
79#define ADE7758_READ_REG(a) a
80#define ADE7758_WRITE_REG(a) ((a) | 0x80)
81
82#define ADE7758_MAX_TX 8
83#define ADE7758_MAX_RX 4
84#define ADE7758_STARTUP_DELAY 1
85
86#define ADE7758_SPI_SLOW (u32)(300 * 1000)
87#define ADE7758_SPI_BURST (u32)(1000 * 1000)
88#define ADE7758_SPI_FAST (u32)(2000 * 1000)
89
90#define DRIVER_NAME "ade7758"
91
92/**
93 * struct ade7758_state - device instance specific data
94 * @us: actual spi_device
95 * @work_trigger_to_ring: bh for triggered event handling
96 * @inter: used to check if new interrupt has been triggered
97 * @last_timestamp: passing timestamp from th to bh of interrupt handler
98 * @indio_dev: industrial I/O device structure
99 * @trig: data ready trigger registered with iio
100 * @tx: transmit buffer
101 * @rx: recieve buffer
102 * @buf_lock: mutex to protect tx and rx
103 **/
104struct ade7758_state {
105 struct spi_device *us;
106 struct work_struct work_trigger_to_ring;
107 s64 last_timestamp;
108 struct iio_dev *indio_dev;
109 struct iio_trigger *trig;
110 u8 *tx;
111 u8 *rx;
112 struct mutex buf_lock;
113};
114#ifdef CONFIG_IIO_RING_BUFFER
115/* At the moment triggers are only used for ring buffer
116 * filling. This may change!
117 */
118
119enum ade7758_scan {
120 ADE7758_SCAN_WFORM,
121};
122
123void ade7758_remove_trigger(struct iio_dev *indio_dev);
124int ade7758_probe_trigger(struct iio_dev *indio_dev);
125
126ssize_t ade7758_read_data_from_ring(struct device *dev,
127 struct device_attribute *attr,
128 char *buf);
129
130
131int ade7758_configure_ring(struct iio_dev *indio_dev);
132void ade7758_unconfigure_ring(struct iio_dev *indio_dev);
133
134int ade7758_initialize_ring(struct iio_ring_buffer *ring);
135void ade7758_uninitialize_ring(struct iio_ring_buffer *ring);
136int ade7758_set_irq(struct device *dev, bool enable);
137#else /* CONFIG_IIO_RING_BUFFER */
138
139static inline void ade7758_remove_trigger(struct iio_dev *indio_dev)
140{
141}
142static inline int ade7758_probe_trigger(struct iio_dev *indio_dev)
143{
144 return 0;
145}
146
147static inline ssize_t
148ade7758_read_data_from_ring(struct device *dev,
149 struct device_attribute *attr,
150 char *buf)
151{
152 return 0;
153}
154
155static int ade7758_configure_ring(struct iio_dev *indio_dev)
156{
157 return 0;
158}
159static inline void ade7758_unconfigure_ring(struct iio_dev *indio_dev)
160{
161}
162static inline int ade7758_initialize_ring(struct iio_ring_buffer *ring)
163{
164 return 0;
165}
166static inline void ade7758_uninitialize_ring(struct iio_ring_buffer *ring)
167{
168}
169#endif /* CONFIG_IIO_RING_BUFFER */
170
171#endif
diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
new file mode 100644
index 000000000000..b7634cb7aa4f
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7758_core.c
@@ -0,0 +1,866 @@
1/*
2 * ADE7758 Polyphase Multifunction Energy Metering IC Driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "meter.h"
24#include "ade7758.h"
25
26int ade7758_spi_write_reg_8(struct device *dev,
27 u8 reg_address,
28 u8 val)
29{
30 int ret;
31 struct iio_dev *indio_dev = dev_get_drvdata(dev);
32 struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
33
34 mutex_lock(&st->buf_lock);
35 st->tx[0] = ADE7758_WRITE_REG(reg_address);
36 st->tx[1] = val;
37
38 ret = spi_write(st->us, st->tx, 2);
39 mutex_unlock(&st->buf_lock);
40
41 return ret;
42}
43
44static int ade7758_spi_write_reg_16(struct device *dev,
45 u8 reg_address,
46 u16 value)
47{
48 int ret;
49 struct spi_message msg;
50 struct iio_dev *indio_dev = dev_get_drvdata(dev);
51 struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
52 struct spi_transfer xfers[] = {
53 {
54 .tx_buf = st->tx,
55 .bits_per_word = 8,
56 .len = 3,
57 }
58 };
59
60 mutex_lock(&st->buf_lock);
61 st->tx[0] = ADE7758_WRITE_REG(reg_address);
62 st->tx[1] = (value >> 8) & 0xFF;
63 st->tx[2] = value & 0xFF;
64
65 spi_message_init(&msg);
66 spi_message_add_tail(xfers, &msg);
67 ret = spi_sync(st->us, &msg);
68 mutex_unlock(&st->buf_lock);
69
70 return ret;
71}
72
73static int ade7758_spi_write_reg_24(struct device *dev,
74 u8 reg_address,
75 u32 value)
76{
77 int ret;
78 struct spi_message msg;
79 struct iio_dev *indio_dev = dev_get_drvdata(dev);
80 struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
81 struct spi_transfer xfers[] = {
82 {
83 .tx_buf = st->tx,
84 .bits_per_word = 8,
85 .len = 4,
86 }
87 };
88
89 mutex_lock(&st->buf_lock);
90 st->tx[0] = ADE7758_WRITE_REG(reg_address);
91 st->tx[1] = (value >> 16) & 0xFF;
92 st->tx[2] = (value >> 8) & 0xFF;
93 st->tx[3] = value & 0xFF;
94
95 spi_message_init(&msg);
96 spi_message_add_tail(xfers, &msg);
97 ret = spi_sync(st->us, &msg);
98 mutex_unlock(&st->buf_lock);
99
100 return ret;
101}
102
103static int ade7758_spi_read_reg_8(struct device *dev,
104 u8 reg_address,
105 u8 *val)
106{
107 struct spi_message msg;
108 struct iio_dev *indio_dev = dev_get_drvdata(dev);
109 struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
110 int ret;
111 struct spi_transfer xfers[] = {
112 {
113 .tx_buf = st->tx,
114 .rx_buf = st->rx,
115 .bits_per_word = 8,
116 .len = 2,
117 },
118 };
119
120 mutex_lock(&st->buf_lock);
121 st->tx[0] = ADE7758_READ_REG(reg_address);
122 st->tx[1] = 0;
123
124 spi_message_init(&msg);
125 spi_message_add_tail(xfers, &msg);
126 ret = spi_sync(st->us, &msg);
127 if (ret) {
128 dev_err(&st->us->dev, "problem when reading 8 bit register 0x%02X",
129 reg_address);
130 goto error_ret;
131 }
132 *val = st->rx[1];
133
134error_ret:
135 mutex_unlock(&st->buf_lock);
136 return ret;
137}
138
139static int ade7758_spi_read_reg_16(struct device *dev,
140 u8 reg_address,
141 u16 *val)
142{
143 struct spi_message msg;
144 struct iio_dev *indio_dev = dev_get_drvdata(dev);
145 struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
146 int ret;
147 struct spi_transfer xfers[] = {
148 {
149 .tx_buf = st->tx,
150 .rx_buf = st->rx,
151 .bits_per_word = 8,
152 .len = 3,
153 },
154 };
155
156 mutex_lock(&st->buf_lock);
157 st->tx[0] = ADE7758_READ_REG(reg_address);
158 st->tx[1] = 0;
159 st->tx[2] = 0;
160
161 spi_message_init(&msg);
162 spi_message_add_tail(xfers, &msg);
163 ret = spi_sync(st->us, &msg);
164 if (ret) {
165 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
166 reg_address);
167 goto error_ret;
168 }
169 *val = (st->rx[1] << 8) | st->rx[2];
170
171error_ret:
172 mutex_unlock(&st->buf_lock);
173 return ret;
174}
175
176static int ade7758_spi_read_reg_24(struct device *dev,
177 u8 reg_address,
178 u32 *val)
179{
180 struct spi_message msg;
181 struct iio_dev *indio_dev = dev_get_drvdata(dev);
182 struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
183 int ret;
184 struct spi_transfer xfers[] = {
185 {
186 .tx_buf = st->tx,
187 .rx_buf = st->rx,
188 .bits_per_word = 8,
189 .len = 4,
190 },
191 };
192
193 mutex_lock(&st->buf_lock);
194 st->tx[0] = ADE7758_READ_REG(reg_address);
195 st->tx[1] = 0;
196 st->tx[2] = 0;
197 st->tx[3] = 0;
198
199 spi_message_init(&msg);
200 spi_message_add_tail(xfers, &msg);
201 ret = spi_sync(st->us, &msg);
202 if (ret) {
203 dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X",
204 reg_address);
205 goto error_ret;
206 }
207 *val = (st->rx[1] << 16) | (st->rx[2] << 8) | st->rx[3];
208
209error_ret:
210 mutex_unlock(&st->buf_lock);
211 return ret;
212}
213
214static ssize_t ade7758_read_8bit(struct device *dev,
215 struct device_attribute *attr,
216 char *buf)
217{
218 int ret;
219 u8 val = 0;
220 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
221
222 ret = ade7758_spi_read_reg_8(dev, this_attr->address, &val);
223 if (ret)
224 return ret;
225
226 return sprintf(buf, "%u\n", val);
227}
228
229static ssize_t ade7758_read_16bit(struct device *dev,
230 struct device_attribute *attr,
231 char *buf)
232{
233 int ret;
234 u16 val = 0;
235 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
236
237 ret = ade7758_spi_read_reg_16(dev, this_attr->address, &val);
238 if (ret)
239 return ret;
240
241 return sprintf(buf, "%u\n", val);
242}
243
244static ssize_t ade7758_read_24bit(struct device *dev,
245 struct device_attribute *attr,
246 char *buf)
247{
248 int ret;
249 u32 val = 0;
250 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
251
252 ret = ade7758_spi_read_reg_24(dev, this_attr->address, &val);
253 if (ret)
254 return ret;
255
256 return sprintf(buf, "%u\n", val & 0xFFFFFF);
257}
258
259static ssize_t ade7758_write_8bit(struct device *dev,
260 struct device_attribute *attr,
261 const char *buf,
262 size_t len)
263{
264 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
265 int ret;
266 long val;
267
268 ret = strict_strtol(buf, 10, &val);
269 if (ret)
270 goto error_ret;
271 ret = ade7758_spi_write_reg_8(dev, this_attr->address, val);
272
273error_ret:
274 return ret ? ret : len;
275}
276
277static ssize_t ade7758_write_16bit(struct device *dev,
278 struct device_attribute *attr,
279 const char *buf,
280 size_t len)
281{
282 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
283 int ret;
284 long val;
285
286 ret = strict_strtol(buf, 10, &val);
287 if (ret)
288 goto error_ret;
289 ret = ade7758_spi_write_reg_16(dev, this_attr->address, val);
290
291error_ret:
292 return ret ? ret : len;
293}
294
295int ade7758_reset(struct device *dev)
296{
297 int ret;
298 u8 val;
299 ade7758_spi_read_reg_8(dev,
300 ADE7758_OPMODE,
301 &val);
302 val |= 1 << 6; /* Software Chip Reset */
303 ret = ade7758_spi_write_reg_8(dev,
304 ADE7758_OPMODE,
305 val);
306
307 return ret;
308}
309
310static ssize_t ade7758_write_reset(struct device *dev,
311 struct device_attribute *attr,
312 const char *buf, size_t len)
313{
314 if (len < 1)
315 return -1;
316 switch (buf[0]) {
317 case '1':
318 case 'y':
319 case 'Y':
320 return ade7758_reset(dev);
321 }
322 return -1;
323}
324
325static IIO_DEV_ATTR_VPEAK(S_IWUSR | S_IRUGO,
326 ade7758_read_8bit,
327 ade7758_write_8bit,
328 ADE7758_VPEAK);
329static IIO_DEV_ATTR_IPEAK(S_IWUSR | S_IRUGO,
330 ade7758_read_8bit,
331 ade7758_write_8bit,
332 ADE7758_VPEAK);
333static IIO_DEV_ATTR_APHCAL(S_IWUSR | S_IRUGO,
334 ade7758_read_8bit,
335 ade7758_write_8bit,
336 ADE7758_APHCAL);
337static IIO_DEV_ATTR_BPHCAL(S_IWUSR | S_IRUGO,
338 ade7758_read_8bit,
339 ade7758_write_8bit,
340 ADE7758_BPHCAL);
341static IIO_DEV_ATTR_CPHCAL(S_IWUSR | S_IRUGO,
342 ade7758_read_8bit,
343 ade7758_write_8bit,
344 ADE7758_CPHCAL);
345static IIO_DEV_ATTR_WDIV(S_IWUSR | S_IRUGO,
346 ade7758_read_8bit,
347 ade7758_write_8bit,
348 ADE7758_WDIV);
349static IIO_DEV_ATTR_VADIV(S_IWUSR | S_IRUGO,
350 ade7758_read_8bit,
351 ade7758_write_8bit,
352 ADE7758_VADIV);
353static IIO_DEV_ATTR_AIRMS(S_IRUGO,
354 ade7758_read_24bit,
355 NULL,
356 ADE7758_AIRMS);
357static IIO_DEV_ATTR_BIRMS(S_IRUGO,
358 ade7758_read_24bit,
359 NULL,
360 ADE7758_BIRMS);
361static IIO_DEV_ATTR_CIRMS(S_IRUGO,
362 ade7758_read_24bit,
363 NULL,
364 ADE7758_CIRMS);
365static IIO_DEV_ATTR_AVRMS(S_IRUGO,
366 ade7758_read_24bit,
367 NULL,
368 ADE7758_AVRMS);
369static IIO_DEV_ATTR_BVRMS(S_IRUGO,
370 ade7758_read_24bit,
371 NULL,
372 ADE7758_BVRMS);
373static IIO_DEV_ATTR_CVRMS(S_IRUGO,
374 ade7758_read_24bit,
375 NULL,
376 ADE7758_CVRMS);
377static IIO_DEV_ATTR_AIRMSOS(S_IWUSR | S_IRUGO,
378 ade7758_read_16bit,
379 ade7758_write_16bit,
380 ADE7758_AIRMSOS);
381static IIO_DEV_ATTR_BIRMSOS(S_IWUSR | S_IRUGO,
382 ade7758_read_16bit,
383 ade7758_write_16bit,
384 ADE7758_BIRMSOS);
385static IIO_DEV_ATTR_CIRMSOS(S_IWUSR | S_IRUGO,
386 ade7758_read_16bit,
387 ade7758_write_16bit,
388 ADE7758_CIRMSOS);
389static IIO_DEV_ATTR_AVRMSOS(S_IWUSR | S_IRUGO,
390 ade7758_read_16bit,
391 ade7758_write_16bit,
392 ADE7758_AVRMSOS);
393static IIO_DEV_ATTR_BVRMSOS(S_IWUSR | S_IRUGO,
394 ade7758_read_16bit,
395 ade7758_write_16bit,
396 ADE7758_BVRMSOS);
397static IIO_DEV_ATTR_CVRMSOS(S_IWUSR | S_IRUGO,
398 ade7758_read_16bit,
399 ade7758_write_16bit,
400 ADE7758_CVRMSOS);
401static IIO_DEV_ATTR_AIGAIN(S_IWUSR | S_IRUGO,
402 ade7758_read_16bit,
403 ade7758_write_16bit,
404 ADE7758_AIGAIN);
405static IIO_DEV_ATTR_BIGAIN(S_IWUSR | S_IRUGO,
406 ade7758_read_16bit,
407 ade7758_write_16bit,
408 ADE7758_BIGAIN);
409static IIO_DEV_ATTR_CIGAIN(S_IWUSR | S_IRUGO,
410 ade7758_read_16bit,
411 ade7758_write_16bit,
412 ADE7758_CIGAIN);
413static IIO_DEV_ATTR_AVRMSGAIN(S_IWUSR | S_IRUGO,
414 ade7758_read_16bit,
415 ade7758_write_16bit,
416 ADE7758_AVRMSGAIN);
417static IIO_DEV_ATTR_BVRMSGAIN(S_IWUSR | S_IRUGO,
418 ade7758_read_16bit,
419 ade7758_write_16bit,
420 ADE7758_BVRMSGAIN);
421static IIO_DEV_ATTR_CVRMSGAIN(S_IWUSR | S_IRUGO,
422 ade7758_read_16bit,
423 ade7758_write_16bit,
424 ADE7758_CVRMSGAIN);
425
426int ade7758_set_irq(struct device *dev, bool enable)
427{
428 int ret;
429 u32 irqen;
430 ret = ade7758_spi_read_reg_24(dev, ADE7758_MASK, &irqen);
431 if (ret)
432 goto error_ret;
433
434 if (enable)
435 irqen |= 1 << 16; /* Enables an interrupt when a data is
436 present in the waveform register */
437 else
438 irqen &= ~(1 << 16);
439
440 ret = ade7758_spi_write_reg_24(dev, ADE7758_MASK, irqen);
441 if (ret)
442 goto error_ret;
443
444error_ret:
445 return ret;
446}
447
448/* Power down the device */
449static int ade7758_stop_device(struct device *dev)
450{
451 int ret;
452 u8 val;
453 ade7758_spi_read_reg_8(dev,
454 ADE7758_OPMODE,
455 &val);
456 val |= 7 << 3; /* ADE7758 powered down */
457 ret = ade7758_spi_write_reg_8(dev,
458 ADE7758_OPMODE,
459 val);
460
461 return ret;
462}
463
464static int ade7758_initial_setup(struct ade7758_state *st)
465{
466 int ret;
467 struct device *dev = &st->indio_dev->dev;
468
469 /* use low spi speed for init */
470 st->us->mode = SPI_MODE_3;
471 spi_setup(st->us);
472
473 /* Disable IRQ */
474 ret = ade7758_set_irq(dev, false);
475 if (ret) {
476 dev_err(dev, "disable irq failed");
477 goto err_ret;
478 }
479
480 ade7758_reset(dev);
481 msleep(ADE7758_STARTUP_DELAY);
482
483err_ret:
484 return ret;
485}
486
487static ssize_t ade7758_read_frequency(struct device *dev,
488 struct device_attribute *attr,
489 char *buf)
490{
491 int ret, len = 0;
492 u8 t;
493 int sps;
494 ret = ade7758_spi_read_reg_8(dev,
495 ADE7758_WAVMODE,
496 &t);
497 if (ret)
498 return ret;
499
500 t = (t >> 5) & 0x3;
501 sps = 26040 / (1 << t);
502
503 len = sprintf(buf, "%d SPS\n", sps);
504 return len;
505}
506
507static ssize_t ade7758_write_frequency(struct device *dev,
508 struct device_attribute *attr,
509 const char *buf,
510 size_t len)
511{
512 struct iio_dev *indio_dev = dev_get_drvdata(dev);
513 struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
514 unsigned long val;
515 int ret;
516 u8 reg, t;
517
518 ret = strict_strtol(buf, 10, &val);
519 if (ret)
520 return ret;
521
522 mutex_lock(&indio_dev->mlock);
523
524 t = (26040 / val);
525 if (t > 0)
526 t >>= 1;
527
528 if (t > 1)
529 st->us->max_speed_hz = ADE7758_SPI_SLOW;
530 else
531 st->us->max_speed_hz = ADE7758_SPI_FAST;
532
533 ret = ade7758_spi_read_reg_8(dev,
534 ADE7758_WAVMODE,
535 &reg);
536 if (ret)
537 goto out;
538
539 reg &= ~(5 << 3);
540 reg |= t << 5;
541
542 ret = ade7758_spi_write_reg_8(dev,
543 ADE7758_WAVMODE,
544 reg);
545
546out:
547 mutex_unlock(&indio_dev->mlock);
548
549 return ret ? ret : len;
550}
551
552static ssize_t ade7758_read_waveform_type(struct device *dev,
553 struct device_attribute *attr,
554 char *buf)
555{
556 int ret, len = 0;
557 u8 t;
558 ret = ade7758_spi_read_reg_8(dev,
559 ADE7758_WAVMODE,
560 &t);
561 if (ret)
562 return ret;
563
564 t = (t >> 2) & 0x7;
565
566 len = sprintf(buf, "%d\n", t);
567
568 return len;
569}
570
571static ssize_t ade7758_write_waveform_type(struct device *dev,
572 struct device_attribute *attr,
573 const char *buf,
574 size_t len)
575{
576 struct iio_dev *indio_dev = dev_get_drvdata(dev);
577 unsigned long val;
578 int ret;
579 u8 reg;
580
581 ret = strict_strtol(buf, 10, &val);
582 if (ret)
583 return ret;
584
585 if (val > 4)
586 return -EINVAL;
587
588 mutex_lock(&indio_dev->mlock);
589
590 ret = ade7758_spi_read_reg_8(dev,
591 ADE7758_WAVMODE,
592 &reg);
593 if (ret)
594 goto out;
595
596 reg &= ~(7 << 2);
597 reg |= val << 2;
598
599 ret = ade7758_spi_write_reg_8(dev,
600 ADE7758_WAVMODE,
601 reg);
602
603out:
604 mutex_unlock(&indio_dev->mlock);
605
606 return ret ? ret : len;
607}
608
609static IIO_DEV_ATTR_TEMP_RAW(ade7758_read_8bit);
610static IIO_CONST_ATTR(temp_offset, "129 C");
611static IIO_CONST_ATTR(temp_scale, "4 C");
612
613static IIO_DEV_ATTR_AWATTHR(ade7758_read_16bit,
614 ADE7758_AWATTHR);
615static IIO_DEV_ATTR_BWATTHR(ade7758_read_16bit,
616 ADE7758_BWATTHR);
617static IIO_DEV_ATTR_CWATTHR(ade7758_read_16bit,
618 ADE7758_CWATTHR);
619static IIO_DEV_ATTR_AVARHR(ade7758_read_16bit,
620 ADE7758_AVARHR);
621static IIO_DEV_ATTR_BVARHR(ade7758_read_16bit,
622 ADE7758_BVARHR);
623static IIO_DEV_ATTR_CVARHR(ade7758_read_16bit,
624 ADE7758_CVARHR);
625static IIO_DEV_ATTR_AVAHR(ade7758_read_16bit,
626 ADE7758_AVAHR);
627static IIO_DEV_ATTR_BVAHR(ade7758_read_16bit,
628 ADE7758_BVAHR);
629static IIO_DEV_ATTR_CVAHR(ade7758_read_16bit,
630 ADE7758_CVAHR);
631
632static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
633 ade7758_read_frequency,
634 ade7758_write_frequency);
635
636/**
637 * IIO_DEV_ATTR_WAVEFORM_TYPE - set the type of waveform.
638 * @_mode: sysfs file mode/permissions
639 * @_show: output method for the attribute
640 * @_store: input method for the attribute
641 **/
642#define IIO_DEV_ATTR_WAVEFORM_TYPE(_mode, _show, _store) \
643 IIO_DEVICE_ATTR(waveform_type, _mode, _show, _store, 0)
644
645static IIO_DEV_ATTR_WAVEFORM_TYPE(S_IWUSR | S_IRUGO,
646 ade7758_read_waveform_type,
647 ade7758_write_waveform_type);
648
649static IIO_DEV_ATTR_RESET(ade7758_write_reset);
650
651static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("26000 13000 65000 33000");
652
653static IIO_CONST_ATTR(name, "ade7758");
654
655static struct attribute *ade7758_event_attributes[] = {
656 NULL
657};
658
659static struct attribute_group ade7758_event_attribute_group = {
660 .attrs = ade7758_event_attributes,
661};
662
663static struct attribute *ade7758_attributes[] = {
664 &iio_dev_attr_temp_raw.dev_attr.attr,
665 &iio_const_attr_temp_offset.dev_attr.attr,
666 &iio_const_attr_temp_scale.dev_attr.attr,
667 &iio_dev_attr_sampling_frequency.dev_attr.attr,
668 &iio_dev_attr_waveform_type.dev_attr.attr,
669 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
670 &iio_dev_attr_reset.dev_attr.attr,
671 &iio_const_attr_name.dev_attr.attr,
672 &iio_dev_attr_awatthr.dev_attr.attr,
673 &iio_dev_attr_bwatthr.dev_attr.attr,
674 &iio_dev_attr_cwatthr.dev_attr.attr,
675 &iio_dev_attr_avarhr.dev_attr.attr,
676 &iio_dev_attr_bvarhr.dev_attr.attr,
677 &iio_dev_attr_cvarhr.dev_attr.attr,
678 &iio_dev_attr_avahr.dev_attr.attr,
679 &iio_dev_attr_bvahr.dev_attr.attr,
680 &iio_dev_attr_cvahr.dev_attr.attr,
681 &iio_dev_attr_vpeak.dev_attr.attr,
682 &iio_dev_attr_ipeak.dev_attr.attr,
683 &iio_dev_attr_aphcal.dev_attr.attr,
684 &iio_dev_attr_bphcal.dev_attr.attr,
685 &iio_dev_attr_cphcal.dev_attr.attr,
686 &iio_dev_attr_wdiv.dev_attr.attr,
687 &iio_dev_attr_vadiv.dev_attr.attr,
688 &iio_dev_attr_airms.dev_attr.attr,
689 &iio_dev_attr_birms.dev_attr.attr,
690 &iio_dev_attr_cirms.dev_attr.attr,
691 &iio_dev_attr_avrms.dev_attr.attr,
692 &iio_dev_attr_bvrms.dev_attr.attr,
693 &iio_dev_attr_cvrms.dev_attr.attr,
694 &iio_dev_attr_aigain.dev_attr.attr,
695 &iio_dev_attr_bigain.dev_attr.attr,
696 &iio_dev_attr_cigain.dev_attr.attr,
697 &iio_dev_attr_avrmsgain.dev_attr.attr,
698 &iio_dev_attr_bvrmsgain.dev_attr.attr,
699 &iio_dev_attr_cvrmsgain.dev_attr.attr,
700 &iio_dev_attr_airmsos.dev_attr.attr,
701 &iio_dev_attr_birmsos.dev_attr.attr,
702 &iio_dev_attr_cirmsos.dev_attr.attr,
703 &iio_dev_attr_avrmsos.dev_attr.attr,
704 &iio_dev_attr_bvrmsos.dev_attr.attr,
705 &iio_dev_attr_cvrmsos.dev_attr.attr,
706 NULL,
707};
708
709static const struct attribute_group ade7758_attribute_group = {
710 .attrs = ade7758_attributes,
711};
712
713
714
715static int __devinit ade7758_probe(struct spi_device *spi)
716{
717 int ret, regdone = 0;
718 struct ade7758_state *st = kzalloc(sizeof *st, GFP_KERNEL);
719 if (!st) {
720 ret = -ENOMEM;
721 goto error_ret;
722 }
723 /* this is only used for removal purposes */
724 spi_set_drvdata(spi, st);
725
726 /* Allocate the comms buffers */
727 st->rx = kzalloc(sizeof(*st->rx)*ADE7758_MAX_RX, GFP_KERNEL);
728 if (st->rx == NULL) {
729 ret = -ENOMEM;
730 goto error_free_st;
731 }
732 st->tx = kzalloc(sizeof(*st->tx)*ADE7758_MAX_TX, GFP_KERNEL);
733 if (st->tx == NULL) {
734 ret = -ENOMEM;
735 goto error_free_rx;
736 }
737 st->us = spi;
738 mutex_init(&st->buf_lock);
739 /* setup the industrialio driver allocated elements */
740 st->indio_dev = iio_allocate_device();
741 if (st->indio_dev == NULL) {
742 ret = -ENOMEM;
743 goto error_free_tx;
744 }
745
746 st->indio_dev->dev.parent = &spi->dev;
747 st->indio_dev->num_interrupt_lines = 1;
748 st->indio_dev->event_attrs = &ade7758_event_attribute_group;
749 st->indio_dev->attrs = &ade7758_attribute_group;
750 st->indio_dev->dev_data = (void *)(st);
751 st->indio_dev->driver_module = THIS_MODULE;
752 st->indio_dev->modes = INDIO_DIRECT_MODE;
753
754 ret = ade7758_configure_ring(st->indio_dev);
755 if (ret)
756 goto error_free_dev;
757
758 ret = iio_device_register(st->indio_dev);
759 if (ret)
760 goto error_unreg_ring_funcs;
761 regdone = 1;
762
763 ret = ade7758_initialize_ring(st->indio_dev->ring);
764 if (ret) {
765 printk(KERN_ERR "failed to initialize the ring\n");
766 goto error_unreg_ring_funcs;
767 }
768
769 if (spi->irq) {
770 ret = iio_register_interrupt_line(spi->irq,
771 st->indio_dev,
772 0,
773 IRQF_TRIGGER_FALLING,
774 "ade7758");
775 if (ret)
776 goto error_uninitialize_ring;
777
778 ret = ade7758_probe_trigger(st->indio_dev);
779 if (ret)
780 goto error_unregister_line;
781 }
782
783 /* Get the device into a sane initial state */
784 ret = ade7758_initial_setup(st);
785 if (ret)
786 goto error_remove_trigger;
787 return 0;
788
789error_remove_trigger:
790 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
791 ade7758_remove_trigger(st->indio_dev);
792error_unregister_line:
793 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
794 iio_unregister_interrupt_line(st->indio_dev, 0);
795error_uninitialize_ring:
796 ade7758_uninitialize_ring(st->indio_dev->ring);
797error_unreg_ring_funcs:
798 ade7758_unconfigure_ring(st->indio_dev);
799error_free_dev:
800 if (regdone)
801 iio_device_unregister(st->indio_dev);
802 else
803 iio_free_device(st->indio_dev);
804error_free_tx:
805 kfree(st->tx);
806error_free_rx:
807 kfree(st->rx);
808error_free_st:
809 kfree(st);
810error_ret:
811 return ret;
812}
813
814static int ade7758_remove(struct spi_device *spi)
815{
816 int ret;
817 struct ade7758_state *st = spi_get_drvdata(spi);
818 struct iio_dev *indio_dev = st->indio_dev;
819
820 ret = ade7758_stop_device(&(indio_dev->dev));
821 if (ret)
822 goto err_ret;
823
824 flush_scheduled_work();
825
826 ade7758_remove_trigger(indio_dev);
827 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
828 iio_unregister_interrupt_line(indio_dev, 0);
829
830 ade7758_uninitialize_ring(indio_dev->ring);
831 iio_device_unregister(indio_dev);
832 ade7758_unconfigure_ring(indio_dev);
833 kfree(st->tx);
834 kfree(st->rx);
835 kfree(st);
836
837 return 0;
838
839err_ret:
840 return ret;
841}
842
843static struct spi_driver ade7758_driver = {
844 .driver = {
845 .name = "ade7758",
846 .owner = THIS_MODULE,
847 },
848 .probe = ade7758_probe,
849 .remove = __devexit_p(ade7758_remove),
850};
851
852static __init int ade7758_init(void)
853{
854 return spi_register_driver(&ade7758_driver);
855}
856module_init(ade7758_init);
857
858static __exit void ade7758_exit(void)
859{
860 spi_unregister_driver(&ade7758_driver);
861}
862module_exit(ade7758_exit);
863
864MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
865MODULE_DESCRIPTION("Analog Devices ADE7758 Polyphase Multifunction Energy Metering IC Driver");
866MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
new file mode 100644
index 000000000000..274b4a07808c
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7758_ring.c
@@ -0,0 +1,212 @@
1#include <linux/interrupt.h>
2#include <linux/irq.h>
3#include <linux/gpio.h>
4#include <linux/workqueue.h>
5#include <linux/mutex.h>
6#include <linux/device.h>
7#include <linux/kernel.h>
8#include <linux/spi/spi.h>
9#include <linux/slab.h>
10#include <linux/sysfs.h>
11#include <linux/list.h>
12
13#include "../iio.h"
14#include "../sysfs.h"
15#include "../ring_sw.h"
16#include "../accel/accel.h"
17#include "../trigger.h"
18#include "ade7758.h"
19
20/**
21 * combine_8_to_32() utility function to munge to u8s into u32
22 **/
23static inline u32 combine_8_to_32(u8 lower, u8 mid, u8 upper)
24{
25 u32 _lower = lower;
26 u32 _mid = mid;
27 u32 _upper = upper;
28
29 return _lower | (_mid << 8) | (_upper << 16);
30}
31
32static IIO_SCAN_EL_C(wform, ADE7758_SCAN_WFORM, ADE7758_WFORM, NULL);
33static IIO_CONST_ATTR_SCAN_EL_TYPE(wform, s, 24, 32);
34static IIO_SCAN_EL_TIMESTAMP(1);
35static IIO_CONST_ATTR_SCAN_EL_TYPE(timestamp, s, 64, 64);
36
37static struct attribute *ade7758_scan_el_attrs[] = {
38 &iio_scan_el_wform.dev_attr.attr,
39 &iio_const_attr_wform_index.dev_attr.attr,
40 &iio_const_attr_wform_type.dev_attr.attr,
41 &iio_scan_el_timestamp.dev_attr.attr,
42 &iio_const_attr_timestamp_index.dev_attr.attr,
43 &iio_const_attr_timestamp_type.dev_attr.attr,
44 NULL,
45};
46
47static struct attribute_group ade7758_scan_el_group = {
48 .attrs = ade7758_scan_el_attrs,
49 .name = "scan_elements",
50};
51
52/**
53 * ade7758_poll_func_th() top half interrupt handler called by trigger
54 * @private_data: iio_dev
55 **/
56static void ade7758_poll_func_th(struct iio_dev *indio_dev, s64 time)
57{
58 struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
59 st->last_timestamp = time;
60 schedule_work(&st->work_trigger_to_ring);
61 /* Indicate that this interrupt is being handled */
62
63 /* Technically this is trigger related, but without this
64 * handler running there is currently no way for the interrupt
65 * to clear.
66 */
67}
68
69/**
70 * ade7758_spi_read_burst() - read all data registers
71 * @dev: device associated with child of actual device (iio_dev or iio_trig)
72 * @rx: somewhere to pass back the value read (min size is 24 bytes)
73 **/
74static int ade7758_spi_read_burst(struct device *dev, u8 *rx)
75{
76 struct spi_message msg;
77 struct iio_dev *indio_dev = dev_get_drvdata(dev);
78 struct ade7758_state *st = iio_dev_get_devdata(indio_dev);
79 int ret;
80
81 struct spi_transfer xfers[] = {
82 {
83 .tx_buf = st->tx,
84 .rx_buf = rx,
85 .bits_per_word = 8,
86 .len = 4,
87 }, {
88 .tx_buf = st->tx + 4,
89 .rx_buf = rx,
90 .bits_per_word = 8,
91 .len = 4,
92 },
93 };
94
95 mutex_lock(&st->buf_lock);
96 st->tx[0] = ADE7758_READ_REG(ADE7758_RSTATUS);
97 st->tx[1] = 0;
98 st->tx[2] = 0;
99 st->tx[3] = 0;
100 st->tx[4] = ADE7758_READ_REG(ADE7758_WFORM);
101 st->tx[5] = 0;
102 st->tx[6] = 0;
103 st->tx[7] = 0;
104
105 spi_message_init(&msg);
106 spi_message_add_tail(&xfers[0], &msg);
107 spi_message_add_tail(&xfers[1], &msg);
108 ret = spi_sync(st->us, &msg);
109 if (ret)
110 dev_err(&st->us->dev, "problem when reading WFORM value\n");
111
112 mutex_unlock(&st->buf_lock);
113
114 return ret;
115}
116
117/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
118 * specific to be rolled into the core.
119 */
120static void ade7758_trigger_bh_to_ring(struct work_struct *work_s)
121{
122 struct ade7758_state *st
123 = container_of(work_s, struct ade7758_state,
124 work_trigger_to_ring);
125 struct iio_ring_buffer *ring = st->indio_dev->ring;
126
127 int i = 0;
128 s32 *data;
129 size_t datasize = ring->access.get_bytes_per_datum(ring);
130
131 data = kmalloc(datasize, GFP_KERNEL);
132 if (data == NULL) {
133 dev_err(&st->us->dev, "memory alloc failed in ring bh");
134 return;
135 }
136
137 if (ring->scan_count)
138 if (ade7758_spi_read_burst(&st->indio_dev->dev, st->rx) >= 0)
139 for (; i < ring->scan_count; i++)
140 data[i] = combine_8_to_32(st->rx[i*2+2],
141 st->rx[i*2+1],
142 st->rx[i*2]);
143
144 /* Guaranteed to be aligned with 8 byte boundary */
145 if (ring->scan_timestamp)
146 *((s64 *)
147 (((u32)data + 4 * ring->scan_count + 4) & ~0x7)) =
148 st->last_timestamp;
149
150 ring->access.store_to(ring,
151 (u8 *)data,
152 st->last_timestamp);
153
154 iio_trigger_notify_done(st->indio_dev->trig);
155 kfree(data);
156
157 return;
158}
159
160void ade7758_unconfigure_ring(struct iio_dev *indio_dev)
161{
162 kfree(indio_dev->pollfunc);
163 iio_sw_rb_free(indio_dev->ring);
164}
165
166int ade7758_configure_ring(struct iio_dev *indio_dev)
167{
168 int ret = 0;
169 struct ade7758_state *st = indio_dev->dev_data;
170 struct iio_ring_buffer *ring;
171 INIT_WORK(&st->work_trigger_to_ring, ade7758_trigger_bh_to_ring);
172
173 ring = iio_sw_rb_allocate(indio_dev);
174 if (!ring) {
175 ret = -ENOMEM;
176 return ret;
177 }
178 indio_dev->ring = ring;
179 /* Effectively select the ring buffer implementation */
180 iio_ring_sw_register_funcs(&ring->access);
181 ring->bpe = 4;
182 ring->scan_el_attrs = &ade7758_scan_el_group;
183 ring->scan_timestamp = true;
184 ring->preenable = &iio_sw_ring_preenable;
185 ring->postenable = &iio_triggered_ring_postenable;
186 ring->predisable = &iio_triggered_ring_predisable;
187 ring->owner = THIS_MODULE;
188
189 /* Set default scan mode */
190 iio_scan_mask_set(ring, iio_scan_el_wform.number);
191
192 ret = iio_alloc_pollfunc(indio_dev, NULL, &ade7758_poll_func_th);
193 if (ret)
194 goto error_iio_sw_rb_free;
195
196 indio_dev->modes |= INDIO_RING_TRIGGERED;
197 return 0;
198
199error_iio_sw_rb_free:
200 iio_sw_rb_free(indio_dev->ring);
201 return ret;
202}
203
204int ade7758_initialize_ring(struct iio_ring_buffer *ring)
205{
206 return iio_ring_buffer_register(ring, 0);
207}
208
209void ade7758_uninitialize_ring(struct iio_ring_buffer *ring)
210{
211 iio_ring_buffer_unregister(ring);
212}
diff --git a/drivers/staging/iio/meter/ade7758_trigger.c b/drivers/staging/iio/meter/ade7758_trigger.c
new file mode 100644
index 000000000000..60abca0c28ff
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7758_trigger.c
@@ -0,0 +1,125 @@
1#include <linux/interrupt.h>
2#include <linux/irq.h>
3#include <linux/mutex.h>
4#include <linux/device.h>
5#include <linux/kernel.h>
6#include <linux/sysfs.h>
7#include <linux/list.h>
8#include <linux/spi/spi.h>
9
10#include "../iio.h"
11#include "../sysfs.h"
12#include "../trigger.h"
13#include "ade7758.h"
14
15/**
16 * ade7758_data_rdy_trig_poll() the event handler for the data rdy trig
17 **/
18static int ade7758_data_rdy_trig_poll(struct iio_dev *dev_info,
19 int index,
20 s64 timestamp,
21 int no_test)
22{
23 struct ade7758_state *st = iio_dev_get_devdata(dev_info);
24 struct iio_trigger *trig = st->trig;
25
26 iio_trigger_poll(trig, timestamp);
27
28 return IRQ_HANDLED;
29}
30
31IIO_EVENT_SH(data_rdy_trig, &ade7758_data_rdy_trig_poll);
32
33static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL);
34
35static struct attribute *ade7758_trigger_attrs[] = {
36 &dev_attr_name.attr,
37 NULL,
38};
39
40static const struct attribute_group ade7758_trigger_attr_group = {
41 .attrs = ade7758_trigger_attrs,
42};
43
44/**
45 * ade7758_data_rdy_trigger_set_state() set datardy interrupt state
46 **/
47static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig,
48 bool state)
49{
50 struct ade7758_state *st = trig->private_data;
51 struct iio_dev *indio_dev = st->indio_dev;
52 int ret = 0;
53
54 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
55 ret = ade7758_set_irq(&st->indio_dev->dev, state);
56 if (state == false) {
57 iio_remove_event_from_list(&iio_event_data_rdy_trig,
58 &indio_dev->interrupts[0]
59 ->ev_list);
60 /* possible quirk with handler currently worked around
61 by ensuring the work queue is empty */
62 flush_scheduled_work();
63 } else {
64 iio_add_event_to_list(&iio_event_data_rdy_trig,
65 &indio_dev->interrupts[0]->ev_list);
66 }
67 return ret;
68}
69
70/**
71 * ade7758_trig_try_reen() try renabling irq for data rdy trigger
72 * @trig: the datardy trigger
73 **/
74static int ade7758_trig_try_reen(struct iio_trigger *trig)
75{
76 struct ade7758_state *st = trig->private_data;
77 enable_irq(st->us->irq);
78 /* irq reenabled so success! */
79 return 0;
80}
81
82int ade7758_probe_trigger(struct iio_dev *indio_dev)
83{
84 int ret;
85 struct ade7758_state *st = indio_dev->dev_data;
86
87 st->trig = iio_allocate_trigger();
88 st->trig->name = kasprintf(GFP_KERNEL,
89 "ade7758-dev%d",
90 indio_dev->id);
91 if (!st->trig->name) {
92 ret = -ENOMEM;
93 goto error_free_trig;
94 }
95 st->trig->dev.parent = &st->us->dev;
96 st->trig->owner = THIS_MODULE;
97 st->trig->private_data = st;
98 st->trig->set_trigger_state = &ade7758_data_rdy_trigger_set_state;
99 st->trig->try_reenable = &ade7758_trig_try_reen;
100 st->trig->control_attrs = &ade7758_trigger_attr_group;
101 ret = iio_trigger_register(st->trig);
102
103 /* select default trigger */
104 indio_dev->trig = st->trig;
105 if (ret)
106 goto error_free_trig_name;
107
108 return 0;
109
110error_free_trig_name:
111 kfree(st->trig->name);
112error_free_trig:
113 iio_free_trigger(st->trig);
114
115 return ret;
116}
117
118void ade7758_remove_trigger(struct iio_dev *indio_dev)
119{
120 struct ade7758_state *state = indio_dev->dev_data;
121
122 iio_trigger_unregister(state->trig);
123 kfree(state->trig->name);
124 iio_free_trigger(state->trig);
125}
diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c
new file mode 100644
index 000000000000..fafc3c1e5aaa
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7759.c
@@ -0,0 +1,670 @@
1/*
2 * ADE7759 Active Energy Metering IC with di/dt Sensor Interface Driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/spi/spi.h>
17#include <linux/slab.h>
18#include <linux/sysfs.h>
19#include <linux/list.h>
20
21#include "../iio.h"
22#include "../sysfs.h"
23#include "meter.h"
24#include "ade7759.h"
25
26int ade7759_spi_write_reg_8(struct device *dev,
27 u8 reg_address,
28 u8 val)
29{
30 int ret;
31 struct iio_dev *indio_dev = dev_get_drvdata(dev);
32 struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
33
34 mutex_lock(&st->buf_lock);
35 st->tx[0] = ADE7759_WRITE_REG(reg_address);
36 st->tx[1] = val;
37
38 ret = spi_write(st->us, st->tx, 2);
39 mutex_unlock(&st->buf_lock);
40
41 return ret;
42}
43
44static int ade7759_spi_write_reg_16(struct device *dev,
45 u8 reg_address,
46 u16 value)
47{
48 int ret;
49 struct spi_message msg;
50 struct iio_dev *indio_dev = dev_get_drvdata(dev);
51 struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
52 struct spi_transfer xfers[] = {
53 {
54 .tx_buf = st->tx,
55 .bits_per_word = 8,
56 .len = 3,
57 }
58 };
59
60 mutex_lock(&st->buf_lock);
61 st->tx[0] = ADE7759_WRITE_REG(reg_address);
62 st->tx[1] = (value >> 8) & 0xFF;
63 st->tx[2] = value & 0xFF;
64
65 spi_message_init(&msg);
66 spi_message_add_tail(xfers, &msg);
67 ret = spi_sync(st->us, &msg);
68 mutex_unlock(&st->buf_lock);
69
70 return ret;
71}
72
73static int ade7759_spi_read_reg_8(struct device *dev,
74 u8 reg_address,
75 u8 *val)
76{
77 struct spi_message msg;
78 struct iio_dev *indio_dev = dev_get_drvdata(dev);
79 struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
80 int ret;
81 struct spi_transfer xfers[] = {
82 {
83 .tx_buf = st->tx,
84 .rx_buf = st->rx,
85 .bits_per_word = 8,
86 .len = 2,
87 },
88 };
89
90 mutex_lock(&st->buf_lock);
91 st->tx[0] = ADE7759_READ_REG(reg_address);
92 st->tx[1] = 0;
93
94 spi_message_init(&msg);
95 spi_message_add_tail(xfers, &msg);
96 ret = spi_sync(st->us, &msg);
97 if (ret) {
98 dev_err(&st->us->dev, "problem when reading 8 bit register 0x%02X",
99 reg_address);
100 goto error_ret;
101 }
102 *val = st->rx[1];
103
104error_ret:
105 mutex_unlock(&st->buf_lock);
106 return ret;
107}
108
109static int ade7759_spi_read_reg_16(struct device *dev,
110 u8 reg_address,
111 u16 *val)
112{
113 struct spi_message msg;
114 struct iio_dev *indio_dev = dev_get_drvdata(dev);
115 struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
116 int ret;
117 struct spi_transfer xfers[] = {
118 {
119 .tx_buf = st->tx,
120 .rx_buf = st->rx,
121 .bits_per_word = 8,
122 .len = 3,
123 },
124 };
125
126 mutex_lock(&st->buf_lock);
127 st->tx[0] = ADE7759_READ_REG(reg_address);
128 st->tx[1] = 0;
129 st->tx[2] = 0;
130
131 spi_message_init(&msg);
132 spi_message_add_tail(xfers, &msg);
133 ret = spi_sync(st->us, &msg);
134 if (ret) {
135 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
136 reg_address);
137 goto error_ret;
138 }
139 *val = (st->rx[1] << 8) | st->rx[2];
140
141error_ret:
142 mutex_unlock(&st->buf_lock);
143 return ret;
144}
145
146static int ade7759_spi_read_reg_40(struct device *dev,
147 u8 reg_address,
148 u64 *val)
149{
150 struct spi_message msg;
151 struct iio_dev *indio_dev = dev_get_drvdata(dev);
152 struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
153 int ret;
154 struct spi_transfer xfers[] = {
155 {
156 .tx_buf = st->tx,
157 .rx_buf = st->rx,
158 .bits_per_word = 8,
159 .len = 6,
160 },
161 };
162
163 mutex_lock(&st->buf_lock);
164 st->tx[0] = ADE7759_READ_REG(reg_address);
165 memset(&st->tx[1], 0 , 5);
166
167 spi_message_init(&msg);
168 spi_message_add_tail(xfers, &msg);
169 ret = spi_sync(st->us, &msg);
170 if (ret) {
171 dev_err(&st->us->dev, "problem when reading 40 bit register 0x%02X",
172 reg_address);
173 goto error_ret;
174 }
175 *val = ((u64)st->rx[1] << 32) | (st->rx[2] << 24) |
176 (st->rx[3] << 16) | (st->rx[4] << 8) | st->rx[5];
177
178error_ret:
179 mutex_unlock(&st->buf_lock);
180 return ret;
181}
182
183static ssize_t ade7759_read_8bit(struct device *dev,
184 struct device_attribute *attr,
185 char *buf)
186{
187 int ret;
188 u8 val = 0;
189 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
190
191 ret = ade7759_spi_read_reg_8(dev, this_attr->address, &val);
192 if (ret)
193 return ret;
194
195 return sprintf(buf, "%u\n", val);
196}
197
198static ssize_t ade7759_read_16bit(struct device *dev,
199 struct device_attribute *attr,
200 char *buf)
201{
202 int ret;
203 u16 val = 0;
204 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
205
206 ret = ade7759_spi_read_reg_16(dev, this_attr->address, &val);
207 if (ret)
208 return ret;
209
210 return sprintf(buf, "%u\n", val);
211}
212
213static ssize_t ade7759_read_40bit(struct device *dev,
214 struct device_attribute *attr,
215 char *buf)
216{
217 int ret;
218 u64 val = 0;
219 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
220
221 ret = ade7759_spi_read_reg_40(dev, this_attr->address, &val);
222 if (ret)
223 return ret;
224
225 return sprintf(buf, "%llu\n", val);
226}
227
228static ssize_t ade7759_write_8bit(struct device *dev,
229 struct device_attribute *attr,
230 const char *buf,
231 size_t len)
232{
233 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
234 int ret;
235 long val;
236
237 ret = strict_strtol(buf, 10, &val);
238 if (ret)
239 goto error_ret;
240 ret = ade7759_spi_write_reg_8(dev, this_attr->address, val);
241
242error_ret:
243 return ret ? ret : len;
244}
245
246static ssize_t ade7759_write_16bit(struct device *dev,
247 struct device_attribute *attr,
248 const char *buf,
249 size_t len)
250{
251 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
252 int ret;
253 long val;
254
255 ret = strict_strtol(buf, 10, &val);
256 if (ret)
257 goto error_ret;
258 ret = ade7759_spi_write_reg_16(dev, this_attr->address, val);
259
260error_ret:
261 return ret ? ret : len;
262}
263
264static int ade7759_reset(struct device *dev)
265{
266 int ret;
267 u16 val;
268 ade7759_spi_read_reg_16(dev,
269 ADE7759_MODE,
270 &val);
271 val |= 1 << 6; /* Software Chip Reset */
272 ret = ade7759_spi_write_reg_16(dev,
273 ADE7759_MODE,
274 val);
275
276 return ret;
277}
278
279static ssize_t ade7759_write_reset(struct device *dev,
280 struct device_attribute *attr,
281 const char *buf, size_t len)
282{
283 if (len < 1)
284 return -1;
285 switch (buf[0]) {
286 case '1':
287 case 'y':
288 case 'Y':
289 return ade7759_reset(dev);
290 }
291 return -1;
292}
293
294static IIO_DEV_ATTR_AENERGY(ade7759_read_40bit, ADE7759_AENERGY);
295static IIO_DEV_ATTR_CFDEN(S_IWUSR | S_IRUGO,
296 ade7759_read_16bit,
297 ade7759_write_16bit,
298 ADE7759_CFDEN);
299static IIO_DEV_ATTR_CFNUM(S_IWUSR | S_IRUGO,
300 ade7759_read_8bit,
301 ade7759_write_8bit,
302 ADE7759_CFNUM);
303static IIO_DEV_ATTR_CHKSUM(ade7759_read_8bit, ADE7759_CHKSUM);
304static IIO_DEV_ATTR_PHCAL(S_IWUSR | S_IRUGO,
305 ade7759_read_16bit,
306 ade7759_write_16bit,
307 ADE7759_PHCAL);
308static IIO_DEV_ATTR_APOS(S_IWUSR | S_IRUGO,
309 ade7759_read_16bit,
310 ade7759_write_16bit,
311 ADE7759_APOS);
312static IIO_DEV_ATTR_SAGCYC(S_IWUSR | S_IRUGO,
313 ade7759_read_8bit,
314 ade7759_write_8bit,
315 ADE7759_SAGCYC);
316static IIO_DEV_ATTR_SAGLVL(S_IWUSR | S_IRUGO,
317 ade7759_read_8bit,
318 ade7759_write_8bit,
319 ADE7759_SAGLVL);
320static IIO_DEV_ATTR_LINECYC(S_IWUSR | S_IRUGO,
321 ade7759_read_8bit,
322 ade7759_write_8bit,
323 ADE7759_LINECYC);
324static IIO_DEV_ATTR_LENERGY(ade7759_read_40bit, ADE7759_LENERGY);
325static IIO_DEV_ATTR_PGA_GAIN(S_IWUSR | S_IRUGO,
326 ade7759_read_8bit,
327 ade7759_write_8bit,
328 ADE7759_GAIN);
329static IIO_DEV_ATTR_ACTIVE_POWER_GAIN(S_IWUSR | S_IRUGO,
330 ade7759_read_16bit,
331 ade7759_write_16bit,
332 ADE7759_APGAIN);
333static IIO_DEV_ATTR_CH_OFF(1, S_IWUSR | S_IRUGO,
334 ade7759_read_8bit,
335 ade7759_write_8bit,
336 ADE7759_CH1OS);
337static IIO_DEV_ATTR_CH_OFF(2, S_IWUSR | S_IRUGO,
338 ade7759_read_8bit,
339 ade7759_write_8bit,
340 ADE7759_CH2OS);
341
342static int ade7759_set_irq(struct device *dev, bool enable)
343{
344 int ret;
345 u8 irqen;
346 ret = ade7759_spi_read_reg_8(dev, ADE7759_IRQEN, &irqen);
347 if (ret)
348 goto error_ret;
349
350 if (enable)
351 irqen |= 1 << 3; /* Enables an interrupt when a data is
352 present in the waveform register */
353 else
354 irqen &= ~(1 << 3);
355
356 ret = ade7759_spi_write_reg_8(dev, ADE7759_IRQEN, irqen);
357 if (ret)
358 goto error_ret;
359
360error_ret:
361 return ret;
362}
363
364/* Power down the device */
365int ade7759_stop_device(struct device *dev)
366{
367 int ret;
368 u16 val;
369 ade7759_spi_read_reg_16(dev,
370 ADE7759_MODE,
371 &val);
372 val |= 1 << 4; /* AD converters can be turned off */
373 ret = ade7759_spi_write_reg_16(dev,
374 ADE7759_MODE,
375 val);
376
377 return ret;
378}
379
380static int ade7759_initial_setup(struct ade7759_state *st)
381{
382 int ret;
383 struct device *dev = &st->indio_dev->dev;
384
385 /* use low spi speed for init */
386 st->us->mode = SPI_MODE_3;
387 spi_setup(st->us);
388
389 /* Disable IRQ */
390 ret = ade7759_set_irq(dev, false);
391 if (ret) {
392 dev_err(dev, "disable irq failed");
393 goto err_ret;
394 }
395
396 ade7759_reset(dev);
397 msleep(ADE7759_STARTUP_DELAY);
398
399err_ret:
400 return ret;
401}
402
403static ssize_t ade7759_read_frequency(struct device *dev,
404 struct device_attribute *attr,
405 char *buf)
406{
407 int ret, len = 0;
408 u16 t;
409 int sps;
410 ret = ade7759_spi_read_reg_16(dev,
411 ADE7759_MODE,
412 &t);
413 if (ret)
414 return ret;
415
416 t = (t >> 3) & 0x3;
417 sps = 27900 / (1 + t);
418
419 len = sprintf(buf, "%d SPS\n", sps);
420 return len;
421}
422
423static ssize_t ade7759_write_frequency(struct device *dev,
424 struct device_attribute *attr,
425 const char *buf,
426 size_t len)
427{
428 struct iio_dev *indio_dev = dev_get_drvdata(dev);
429 struct ade7759_state *st = iio_dev_get_devdata(indio_dev);
430 unsigned long val;
431 int ret;
432 u16 reg, t;
433
434 ret = strict_strtol(buf, 10, &val);
435 if (ret)
436 return ret;
437
438 mutex_lock(&indio_dev->mlock);
439
440 t = (27900 / val);
441 if (t > 0)
442 t--;
443
444 if (t > 1)
445 st->us->max_speed_hz = ADE7759_SPI_SLOW;
446 else
447 st->us->max_speed_hz = ADE7759_SPI_FAST;
448
449 ret = ade7759_spi_read_reg_16(dev,
450 ADE7759_MODE,
451 &reg);
452 if (ret)
453 goto out;
454
455 reg &= ~(3 << 13);
456 reg |= t << 13;
457
458 ret = ade7759_spi_write_reg_16(dev,
459 ADE7759_MODE,
460 reg);
461
462out:
463 mutex_unlock(&indio_dev->mlock);
464
465 return ret ? ret : len;
466}
467static IIO_DEV_ATTR_TEMP_RAW(ade7759_read_8bit);
468static IIO_CONST_ATTR(temp_offset, "70 C");
469static IIO_CONST_ATTR(temp_scale, "1 C");
470
471static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
472 ade7759_read_frequency,
473 ade7759_write_frequency);
474
475static IIO_DEV_ATTR_RESET(ade7759_write_reset);
476
477static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("27900 14000 7000 3500");
478
479static IIO_CONST_ATTR(name, "ade7759");
480
481static struct attribute *ade7759_event_attributes[] = {
482 NULL
483};
484
485static struct attribute_group ade7759_event_attribute_group = {
486 .attrs = ade7759_event_attributes,
487};
488
489static struct attribute *ade7759_attributes[] = {
490 &iio_dev_attr_temp_raw.dev_attr.attr,
491 &iio_const_attr_temp_offset.dev_attr.attr,
492 &iio_const_attr_temp_scale.dev_attr.attr,
493 &iio_dev_attr_sampling_frequency.dev_attr.attr,
494 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
495 &iio_dev_attr_reset.dev_attr.attr,
496 &iio_const_attr_name.dev_attr.attr,
497 &iio_dev_attr_phcal.dev_attr.attr,
498 &iio_dev_attr_cfden.dev_attr.attr,
499 &iio_dev_attr_aenergy.dev_attr.attr,
500 &iio_dev_attr_cfnum.dev_attr.attr,
501 &iio_dev_attr_apos.dev_attr.attr,
502 &iio_dev_attr_sagcyc.dev_attr.attr,
503 &iio_dev_attr_saglvl.dev_attr.attr,
504 &iio_dev_attr_linecyc.dev_attr.attr,
505 &iio_dev_attr_lenergy.dev_attr.attr,
506 &iio_dev_attr_chksum.dev_attr.attr,
507 &iio_dev_attr_pga_gain.dev_attr.attr,
508 &iio_dev_attr_active_power_gain.dev_attr.attr,
509 &iio_dev_attr_choff_1.dev_attr.attr,
510 &iio_dev_attr_choff_2.dev_attr.attr,
511 NULL,
512};
513
514static const struct attribute_group ade7759_attribute_group = {
515 .attrs = ade7759_attributes,
516};
517
518static int __devinit ade7759_probe(struct spi_device *spi)
519{
520 int ret, regdone = 0;
521 struct ade7759_state *st = kzalloc(sizeof *st, GFP_KERNEL);
522 if (!st) {
523 ret = -ENOMEM;
524 goto error_ret;
525 }
526 /* this is only used for removal purposes */
527 spi_set_drvdata(spi, st);
528
529 /* Allocate the comms buffers */
530 st->rx = kzalloc(sizeof(*st->rx)*ADE7759_MAX_RX, GFP_KERNEL);
531 if (st->rx == NULL) {
532 ret = -ENOMEM;
533 goto error_free_st;
534 }
535 st->tx = kzalloc(sizeof(*st->tx)*ADE7759_MAX_TX, GFP_KERNEL);
536 if (st->tx == NULL) {
537 ret = -ENOMEM;
538 goto error_free_rx;
539 }
540 st->us = spi;
541 mutex_init(&st->buf_lock);
542 /* setup the industrialio driver allocated elements */
543 st->indio_dev = iio_allocate_device();
544 if (st->indio_dev == NULL) {
545 ret = -ENOMEM;
546 goto error_free_tx;
547 }
548
549 st->indio_dev->dev.parent = &spi->dev;
550 st->indio_dev->num_interrupt_lines = 1;
551 st->indio_dev->event_attrs = &ade7759_event_attribute_group;
552 st->indio_dev->attrs = &ade7759_attribute_group;
553 st->indio_dev->dev_data = (void *)(st);
554 st->indio_dev->driver_module = THIS_MODULE;
555 st->indio_dev->modes = INDIO_DIRECT_MODE;
556
557 ret = ade7759_configure_ring(st->indio_dev);
558 if (ret)
559 goto error_free_dev;
560
561 ret = iio_device_register(st->indio_dev);
562 if (ret)
563 goto error_unreg_ring_funcs;
564 regdone = 1;
565
566 ret = ade7759_initialize_ring(st->indio_dev->ring);
567 if (ret) {
568 printk(KERN_ERR "failed to initialize the ring\n");
569 goto error_unreg_ring_funcs;
570 }
571
572 if (spi->irq) {
573 ret = iio_register_interrupt_line(spi->irq,
574 st->indio_dev,
575 0,
576 IRQF_TRIGGER_FALLING,
577 "ade7759");
578 if (ret)
579 goto error_uninitialize_ring;
580
581 ret = ade7759_probe_trigger(st->indio_dev);
582 if (ret)
583 goto error_unregister_line;
584 }
585
586 /* Get the device into a sane initial state */
587 ret = ade7759_initial_setup(st);
588 if (ret)
589 goto error_remove_trigger;
590 return 0;
591
592error_remove_trigger:
593 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
594 ade7759_remove_trigger(st->indio_dev);
595error_unregister_line:
596 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
597 iio_unregister_interrupt_line(st->indio_dev, 0);
598error_uninitialize_ring:
599 ade7759_uninitialize_ring(st->indio_dev->ring);
600error_unreg_ring_funcs:
601 ade7759_unconfigure_ring(st->indio_dev);
602error_free_dev:
603 if (regdone)
604 iio_device_unregister(st->indio_dev);
605 else
606 iio_free_device(st->indio_dev);
607error_free_tx:
608 kfree(st->tx);
609error_free_rx:
610 kfree(st->rx);
611error_free_st:
612 kfree(st);
613error_ret:
614 return ret;
615}
616
617/* fixme, confirm ordering in this function */
618static int ade7759_remove(struct spi_device *spi)
619{
620 int ret;
621 struct ade7759_state *st = spi_get_drvdata(spi);
622 struct iio_dev *indio_dev = st->indio_dev;
623
624 ret = ade7759_stop_device(&(indio_dev->dev));
625 if (ret)
626 goto err_ret;
627
628 flush_scheduled_work();
629
630 ade7759_remove_trigger(indio_dev);
631 if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0)
632 iio_unregister_interrupt_line(indio_dev, 0);
633
634 ade7759_uninitialize_ring(indio_dev->ring);
635 ade7759_unconfigure_ring(indio_dev);
636 iio_device_unregister(indio_dev);
637 kfree(st->tx);
638 kfree(st->rx);
639 kfree(st);
640
641 return 0;
642
643err_ret:
644 return ret;
645}
646
647static struct spi_driver ade7759_driver = {
648 .driver = {
649 .name = "ade7759",
650 .owner = THIS_MODULE,
651 },
652 .probe = ade7759_probe,
653 .remove = __devexit_p(ade7759_remove),
654};
655
656static __init int ade7759_init(void)
657{
658 return spi_register_driver(&ade7759_driver);
659}
660module_init(ade7759_init);
661
662static __exit void ade7759_exit(void)
663{
664 spi_unregister_driver(&ade7759_driver);
665}
666module_exit(ade7759_exit);
667
668MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
669MODULE_DESCRIPTION("Analog Devices ADE7759 Active Energy Metering IC Driver");
670MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/meter/ade7759.h b/drivers/staging/iio/meter/ade7759.h
new file mode 100644
index 000000000000..813dea2676a9
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7759.h
@@ -0,0 +1,122 @@
1#ifndef _ADE7759_H
2#define _ADE7759_H
3
4#define ADE7759_WAVEFORM 0x01
5#define ADE7759_AENERGY 0x02
6#define ADE7759_RSTENERGY 0x03
7#define ADE7759_STATUS 0x04
8#define ADE7759_RSTSTATUS 0x05
9#define ADE7759_MODE 0x06
10#define ADE7759_CFDEN 0x07
11#define ADE7759_CH1OS 0x08
12#define ADE7759_CH2OS 0x09
13#define ADE7759_GAIN 0x0A
14#define ADE7759_APGAIN 0x0B
15#define ADE7759_PHCAL 0x0C
16#define ADE7759_APOS 0x0D
17#define ADE7759_ZXTOUT 0x0E
18#define ADE7759_SAGCYC 0x0F
19#define ADE7759_IRQEN 0x10
20#define ADE7759_SAGLVL 0x11
21#define ADE7759_TEMP 0x12
22#define ADE7759_LINECYC 0x13
23#define ADE7759_LENERGY 0x14
24#define ADE7759_CFNUM 0x15
25#define ADE7759_CHKSUM 0x1E
26#define ADE7759_DIEREV 0x1F
27
28#define ADE7759_READ_REG(a) a
29#define ADE7759_WRITE_REG(a) ((a) | 0x80)
30
31#define ADE7759_MAX_TX 6
32#define ADE7759_MAX_RX 6
33#define ADE7759_STARTUP_DELAY 1
34
35#define ADE7759_SPI_SLOW (u32)(300 * 1000)
36#define ADE7759_SPI_BURST (u32)(1000 * 1000)
37#define ADE7759_SPI_FAST (u32)(2000 * 1000)
38
39#define DRIVER_NAME "ade7759"
40
41/**
42 * struct ade7759_state - device instance specific data
43 * @us: actual spi_device
44 * @work_trigger_to_ring: bh for triggered event handling
45 * @inter: used to check if new interrupt has been triggered
46 * @last_timestamp: passing timestamp from th to bh of interrupt handler
47 * @indio_dev: industrial I/O device structure
48 * @trig: data ready trigger registered with iio
49 * @tx: transmit buffer
50 * @rx: recieve buffer
51 * @buf_lock: mutex to protect tx and rx
52 **/
53struct ade7759_state {
54 struct spi_device *us;
55 struct work_struct work_trigger_to_ring;
56 s64 last_timestamp;
57 struct iio_dev *indio_dev;
58 struct iio_trigger *trig;
59 u8 *tx;
60 u8 *rx;
61 struct mutex buf_lock;
62};
63#if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
64/* At the moment triggers are only used for ring buffer
65 * filling. This may change!
66 */
67
68enum ade7759_scan {
69 ADE7759_SCAN_ACTIVE_POWER,
70 ADE7759_SCAN_CH1_CH2,
71 ADE7759_SCAN_CH1,
72 ADE7759_SCAN_CH2,
73};
74
75void ade7759_remove_trigger(struct iio_dev *indio_dev);
76int ade7759_probe_trigger(struct iio_dev *indio_dev);
77
78ssize_t ade7759_read_data_from_ring(struct device *dev,
79 struct device_attribute *attr,
80 char *buf);
81
82
83int ade7759_configure_ring(struct iio_dev *indio_dev);
84void ade7759_unconfigure_ring(struct iio_dev *indio_dev);
85
86int ade7759_initialize_ring(struct iio_ring_buffer *ring);
87void ade7759_uninitialize_ring(struct iio_ring_buffer *ring);
88#else /* CONFIG_IIO_RING_BUFFER */
89
90static inline void ade7759_remove_trigger(struct iio_dev *indio_dev)
91{
92}
93static inline int ade7759_probe_trigger(struct iio_dev *indio_dev)
94{
95 return 0;
96}
97
98static inline ssize_t
99ade7759_read_data_from_ring(struct device *dev,
100 struct device_attribute *attr,
101 char *buf)
102{
103 return 0;
104}
105
106static int ade7759_configure_ring(struct iio_dev *indio_dev)
107{
108 return 0;
109}
110static inline void ade7759_unconfigure_ring(struct iio_dev *indio_dev)
111{
112}
113static inline int ade7759_initialize_ring(struct iio_ring_buffer *ring)
114{
115 return 0;
116}
117static inline void ade7759_uninitialize_ring(struct iio_ring_buffer *ring)
118{
119}
120#endif /* CONFIG_IIO_RING_BUFFER */
121
122#endif
diff --git a/drivers/staging/iio/meter/ade7854-i2c.c b/drivers/staging/iio/meter/ade7854-i2c.c
new file mode 100644
index 000000000000..4578e7b7f460
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7854-i2c.c
@@ -0,0 +1,272 @@
1/*
2 * ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver (I2C Bus)
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/device.h>
10#include <linux/kernel.h>
11#include <linux/i2c.h>
12#include <linux/slab.h>
13
14#include "../iio.h"
15#include "ade7854.h"
16
17static int ade7854_i2c_write_reg_8(struct device *dev,
18 u16 reg_address,
19 u8 value)
20{
21 int ret;
22 struct iio_dev *indio_dev = dev_get_drvdata(dev);
23 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
24
25 mutex_lock(&st->buf_lock);
26 st->tx[0] = (reg_address >> 8) & 0xFF;
27 st->tx[1] = reg_address & 0xFF;
28 st->tx[2] = value;
29
30 ret = i2c_master_send(st->i2c, st->tx, 3);
31 mutex_unlock(&st->buf_lock);
32
33 return ret;
34}
35
36static int ade7854_i2c_write_reg_16(struct device *dev,
37 u16 reg_address,
38 u16 value)
39{
40 int ret;
41 struct iio_dev *indio_dev = dev_get_drvdata(dev);
42 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
43
44 mutex_lock(&st->buf_lock);
45 st->tx[0] = (reg_address >> 8) & 0xFF;
46 st->tx[1] = reg_address & 0xFF;
47 st->tx[2] = (value >> 8) & 0xFF;
48 st->tx[3] = value & 0xFF;
49
50 ret = i2c_master_send(st->i2c, st->tx, 4);
51 mutex_unlock(&st->buf_lock);
52
53 return ret;
54}
55
56static int ade7854_i2c_write_reg_24(struct device *dev,
57 u16 reg_address,
58 u32 value)
59{
60 int ret;
61 struct iio_dev *indio_dev = dev_get_drvdata(dev);
62 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
63
64 mutex_lock(&st->buf_lock);
65 st->tx[0] = (reg_address >> 8) & 0xFF;
66 st->tx[1] = reg_address & 0xFF;
67 st->tx[2] = (value >> 16) & 0xFF;
68 st->tx[3] = (value >> 8) & 0xFF;
69 st->tx[4] = value & 0xFF;
70
71 ret = i2c_master_send(st->i2c, st->tx, 5);
72 mutex_unlock(&st->buf_lock);
73
74 return ret;
75}
76
77static int ade7854_i2c_write_reg_32(struct device *dev,
78 u16 reg_address,
79 u32 value)
80{
81 int ret;
82 struct iio_dev *indio_dev = dev_get_drvdata(dev);
83 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
84
85 mutex_lock(&st->buf_lock);
86 st->tx[0] = (reg_address >> 8) & 0xFF;
87 st->tx[1] = reg_address & 0xFF;
88 st->tx[2] = (value >> 24) & 0xFF;
89 st->tx[3] = (value >> 16) & 0xFF;
90 st->tx[4] = (value >> 8) & 0xFF;
91 st->tx[5] = value & 0xFF;
92
93 ret = i2c_master_send(st->i2c, st->tx, 6);
94 mutex_unlock(&st->buf_lock);
95
96 return ret;
97}
98
99static int ade7854_i2c_read_reg_8(struct device *dev,
100 u16 reg_address,
101 u8 *val)
102{
103 struct iio_dev *indio_dev = dev_get_drvdata(dev);
104 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
105 int ret;
106
107 mutex_lock(&st->buf_lock);
108 st->tx[0] = (reg_address >> 8) & 0xFF;
109 st->tx[1] = reg_address & 0xFF;
110
111 ret = i2c_master_send(st->i2c, st->tx, 2);
112 if (ret)
113 goto out;
114
115 ret = i2c_master_recv(st->i2c, st->rx, 1);
116 if (ret)
117 goto out;
118
119 *val = st->rx[0];
120out:
121 mutex_unlock(&st->buf_lock);
122 return ret;
123}
124
125static int ade7854_i2c_read_reg_16(struct device *dev,
126 u16 reg_address,
127 u16 *val)
128{
129 struct iio_dev *indio_dev = dev_get_drvdata(dev);
130 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
131 int ret;
132
133 mutex_lock(&st->buf_lock);
134 st->tx[0] = (reg_address >> 8) & 0xFF;
135 st->tx[1] = reg_address & 0xFF;
136
137 ret = i2c_master_send(st->i2c, st->tx, 2);
138 if (ret)
139 goto out;
140
141 ret = i2c_master_recv(st->i2c, st->rx, 2);
142 if (ret)
143 goto out;
144
145 *val = (st->rx[0] << 8) | st->rx[1];
146out:
147 mutex_unlock(&st->buf_lock);
148 return ret;
149}
150
151static int ade7854_i2c_read_reg_24(struct device *dev,
152 u16 reg_address,
153 u32 *val)
154{
155 struct iio_dev *indio_dev = dev_get_drvdata(dev);
156 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
157 int ret;
158
159 mutex_lock(&st->buf_lock);
160 st->tx[0] = (reg_address >> 8) & 0xFF;
161 st->tx[1] = reg_address & 0xFF;
162
163 ret = i2c_master_send(st->i2c, st->tx, 2);
164 if (ret)
165 goto out;
166
167 ret = i2c_master_recv(st->i2c, st->rx, 3);
168 if (ret)
169 goto out;
170
171 *val = (st->rx[0] << 16) | (st->rx[1] << 8) | st->rx[2];
172out:
173 mutex_unlock(&st->buf_lock);
174 return ret;
175}
176
177static int ade7854_i2c_read_reg_32(struct device *dev,
178 u16 reg_address,
179 u32 *val)
180{
181 struct iio_dev *indio_dev = dev_get_drvdata(dev);
182 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
183 int ret;
184
185 mutex_lock(&st->buf_lock);
186 st->tx[0] = (reg_address >> 8) & 0xFF;
187 st->tx[1] = reg_address & 0xFF;
188
189 ret = i2c_master_send(st->i2c, st->tx, 2);
190 if (ret)
191 goto out;
192
193 ret = i2c_master_recv(st->i2c, st->rx, 3);
194 if (ret)
195 goto out;
196
197 *val = (st->rx[0] << 24) | (st->rx[1] << 16) | (st->rx[2] << 8) | st->rx[3];
198out:
199 mutex_unlock(&st->buf_lock);
200 return ret;
201}
202
203static int __devinit ade7854_i2c_probe(struct i2c_client *client,
204 const struct i2c_device_id *id)
205{
206 int ret;
207 struct ade7854_state *st = kzalloc(sizeof *st, GFP_KERNEL);
208 if (!st) {
209 ret = -ENOMEM;
210 return ret;
211 }
212
213 i2c_set_clientdata(client, st);
214 st->read_reg_8 = ade7854_i2c_read_reg_8;
215 st->read_reg_16 = ade7854_i2c_read_reg_16;
216 st->read_reg_24 = ade7854_i2c_read_reg_24;
217 st->read_reg_32 = ade7854_i2c_read_reg_32;
218 st->write_reg_8 = ade7854_i2c_write_reg_8;
219 st->write_reg_16 = ade7854_i2c_write_reg_16;
220 st->write_reg_24 = ade7854_i2c_write_reg_24;
221 st->write_reg_32 = ade7854_i2c_write_reg_32;
222 st->i2c = client;
223 st->irq = client->irq;
224
225 ret = ade7854_probe(st, &client->dev);
226 if (ret) {
227 kfree(st);
228 return ret;
229 }
230
231 return ret;
232}
233
234static int __devexit ade7854_i2c_remove(struct i2c_client *client)
235{
236 return ade7854_remove(i2c_get_clientdata(client));
237}
238
239static const struct i2c_device_id ade7854_id[] = {
240 { "ade7854", 0 },
241 { "ade7858", 0 },
242 { "ade7868", 0 },
243 { "ade7878", 0 },
244 { }
245};
246MODULE_DEVICE_TABLE(i2c, ade7854_id);
247
248static struct i2c_driver ade7854_i2c_driver = {
249 .driver = {
250 .name = "ade7854",
251 },
252 .probe = ade7854_i2c_probe,
253 .remove = __devexit_p(ade7854_i2c_remove),
254 .id_table = ade7854_id,
255};
256
257static __init int ade7854_i2c_init(void)
258{
259 return i2c_add_driver(&ade7854_i2c_driver);
260}
261module_init(ade7854_i2c_init);
262
263static __exit void ade7854_i2c_exit(void)
264{
265 i2c_del_driver(&ade7854_i2c_driver);
266}
267module_exit(ade7854_i2c_exit);
268
269
270MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
271MODULE_DESCRIPTION("Analog Devices ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC I2C Driver");
272MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/meter/ade7854-spi.c b/drivers/staging/iio/meter/ade7854-spi.c
new file mode 100644
index 000000000000..fe58103ed4ca
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7854-spi.c
@@ -0,0 +1,360 @@
1/*
2 * ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver (SPI Bus)
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/device.h>
10#include <linux/kernel.h>
11#include <linux/spi/spi.h>
12#include <linux/slab.h>
13
14#include "../iio.h"
15#include "ade7854.h"
16
17static int ade7854_spi_write_reg_8(struct device *dev,
18 u16 reg_address,
19 u8 value)
20{
21 int ret;
22 struct spi_message msg;
23 struct iio_dev *indio_dev = dev_get_drvdata(dev);
24 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
25 struct spi_transfer xfers[] = {
26 {
27 .tx_buf = st->tx,
28 .bits_per_word = 8,
29 .len = 4,
30 }
31 };
32
33 mutex_lock(&st->buf_lock);
34 st->tx[0] = ADE7854_WRITE_REG;
35 st->tx[1] = (reg_address >> 8) & 0xFF;
36 st->tx[2] = reg_address & 0xFF;
37 st->tx[3] = value & 0xFF;
38
39 spi_message_init(&msg);
40 spi_message_add_tail(xfers, &msg);
41 ret = spi_sync(st->spi, &msg);
42 mutex_unlock(&st->buf_lock);
43
44 return ret;
45}
46
47static int ade7854_spi_write_reg_16(struct device *dev,
48 u16 reg_address,
49 u16 value)
50{
51 int ret;
52 struct spi_message msg;
53 struct iio_dev *indio_dev = dev_get_drvdata(dev);
54 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
55 struct spi_transfer xfers[] = {
56 {
57 .tx_buf = st->tx,
58 .bits_per_word = 8,
59 .len = 5,
60 }
61 };
62
63 mutex_lock(&st->buf_lock);
64 st->tx[0] = ADE7854_WRITE_REG;
65 st->tx[1] = (reg_address >> 8) & 0xFF;
66 st->tx[2] = reg_address & 0xFF;
67 st->tx[3] = (value >> 8) & 0xFF;
68 st->tx[4] = value & 0xFF;
69
70 spi_message_init(&msg);
71 spi_message_add_tail(xfers, &msg);
72 ret = spi_sync(st->spi, &msg);
73 mutex_unlock(&st->buf_lock);
74
75 return ret;
76}
77
78static int ade7854_spi_write_reg_24(struct device *dev,
79 u16 reg_address,
80 u32 value)
81{
82 int ret;
83 struct spi_message msg;
84 struct iio_dev *indio_dev = dev_get_drvdata(dev);
85 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
86 struct spi_transfer xfers[] = {
87 {
88 .tx_buf = st->tx,
89 .bits_per_word = 8,
90 .len = 6,
91 }
92 };
93
94 mutex_lock(&st->buf_lock);
95 st->tx[0] = ADE7854_WRITE_REG;
96 st->tx[1] = (reg_address >> 8) & 0xFF;
97 st->tx[2] = reg_address & 0xFF;
98 st->tx[3] = (value >> 16) & 0xFF;
99 st->tx[4] = (value >> 8) & 0xFF;
100 st->tx[5] = value & 0xFF;
101
102 spi_message_init(&msg);
103 spi_message_add_tail(xfers, &msg);
104 ret = spi_sync(st->spi, &msg);
105 mutex_unlock(&st->buf_lock);
106
107 return ret;
108}
109
110static int ade7854_spi_write_reg_32(struct device *dev,
111 u16 reg_address,
112 u32 value)
113{
114 int ret;
115 struct spi_message msg;
116 struct iio_dev *indio_dev = dev_get_drvdata(dev);
117 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
118 struct spi_transfer xfers[] = {
119 {
120 .tx_buf = st->tx,
121 .bits_per_word = 8,
122 .len = 7,
123 }
124 };
125
126 mutex_lock(&st->buf_lock);
127 st->tx[0] = ADE7854_WRITE_REG;
128 st->tx[1] = (reg_address >> 8) & 0xFF;
129 st->tx[2] = reg_address & 0xFF;
130 st->tx[3] = (value >> 24) & 0xFF;
131 st->tx[4] = (value >> 16) & 0xFF;
132 st->tx[5] = (value >> 8) & 0xFF;
133 st->tx[6] = value & 0xFF;
134
135 spi_message_init(&msg);
136 spi_message_add_tail(xfers, &msg);
137 ret = spi_sync(st->spi, &msg);
138 mutex_unlock(&st->buf_lock);
139
140 return ret;
141}
142
143static int ade7854_spi_read_reg_8(struct device *dev,
144 u16 reg_address,
145 u8 *val)
146{
147 struct spi_message msg;
148 struct iio_dev *indio_dev = dev_get_drvdata(dev);
149 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
150 int ret;
151 struct spi_transfer xfers[] = {
152 {
153 .tx_buf = st->tx,
154 .bits_per_word = 8,
155 .len = 4,
156 },
157 };
158
159 mutex_lock(&st->buf_lock);
160
161 st->tx[0] = ADE7854_READ_REG;
162 st->tx[1] = (reg_address >> 8) & 0xFF;
163 st->tx[2] = reg_address & 0xFF;
164 st->tx[3] = 0;
165
166 spi_message_init(&msg);
167 spi_message_add_tail(xfers, &msg);
168 ret = spi_sync(st->spi, &msg);
169 if (ret) {
170 dev_err(&st->spi->dev, "problem when reading 8 bit register 0x%02X",
171 reg_address);
172 goto error_ret;
173 }
174 *val = st->rx[3];
175
176error_ret:
177 mutex_unlock(&st->buf_lock);
178 return ret;
179}
180
181static int ade7854_spi_read_reg_16(struct device *dev,
182 u16 reg_address,
183 u16 *val)
184{
185 struct spi_message msg;
186 struct iio_dev *indio_dev = dev_get_drvdata(dev);
187 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
188 int ret;
189 struct spi_transfer xfers[] = {
190 {
191 .tx_buf = st->tx,
192 .bits_per_word = 8,
193 .len = 5,
194 },
195 };
196
197 mutex_lock(&st->buf_lock);
198 st->tx[0] = ADE7854_READ_REG;
199 st->tx[1] = (reg_address >> 8) & 0xFF;
200 st->tx[2] = reg_address & 0xFF;
201 st->tx[3] = 0;
202 st->tx[4] = 0;
203
204 spi_message_init(&msg);
205 spi_message_add_tail(xfers, &msg);
206 ret = spi_sync(st->spi, &msg);
207 if (ret) {
208 dev_err(&st->spi->dev, "problem when reading 16 bit register 0x%02X",
209 reg_address);
210 goto error_ret;
211 }
212 *val = (st->rx[3] << 8) | st->rx[4];
213
214error_ret:
215 mutex_unlock(&st->buf_lock);
216 return ret;
217}
218
219static int ade7854_spi_read_reg_24(struct device *dev,
220 u16 reg_address,
221 u32 *val)
222{
223 struct spi_message msg;
224 struct iio_dev *indio_dev = dev_get_drvdata(dev);
225 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
226 int ret;
227 struct spi_transfer xfers[] = {
228 {
229 .tx_buf = st->tx,
230 .bits_per_word = 8,
231 .len = 6,
232 },
233 };
234
235 mutex_lock(&st->buf_lock);
236
237 st->tx[0] = ADE7854_READ_REG;
238 st->tx[1] = (reg_address >> 8) & 0xFF;
239 st->tx[2] = reg_address & 0xFF;
240 st->tx[3] = 0;
241 st->tx[4] = 0;
242 st->tx[5] = 0;
243
244 spi_message_init(&msg);
245 spi_message_add_tail(xfers, &msg);
246 ret = spi_sync(st->spi, &msg);
247 if (ret) {
248 dev_err(&st->spi->dev, "problem when reading 24 bit register 0x%02X",
249 reg_address);
250 goto error_ret;
251 }
252 *val = (st->rx[3] << 16) | (st->rx[4] << 8) | st->rx[5];
253
254error_ret:
255 mutex_unlock(&st->buf_lock);
256 return ret;
257}
258
259static int ade7854_spi_read_reg_32(struct device *dev,
260 u16 reg_address,
261 u32 *val)
262{
263 struct spi_message msg;
264 struct iio_dev *indio_dev = dev_get_drvdata(dev);
265 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
266 int ret;
267 struct spi_transfer xfers[] = {
268 {
269 .tx_buf = st->tx,
270 .bits_per_word = 8,
271 .len = 7,
272 },
273 };
274
275 mutex_lock(&st->buf_lock);
276
277 st->tx[0] = ADE7854_READ_REG;
278 st->tx[1] = (reg_address >> 8) & 0xFF;
279 st->tx[2] = reg_address & 0xFF;
280 st->tx[3] = 0;
281 st->tx[4] = 0;
282 st->tx[5] = 0;
283 st->tx[6] = 0;
284
285 spi_message_init(&msg);
286 spi_message_add_tail(xfers, &msg);
287 ret = spi_sync(st->spi, &msg);
288 if (ret) {
289 dev_err(&st->spi->dev, "problem when reading 32 bit register 0x%02X",
290 reg_address);
291 goto error_ret;
292 }
293 *val = (st->rx[3] << 24) | (st->rx[4] << 16) | (st->rx[5] << 8) | st->rx[6];
294
295error_ret:
296 mutex_unlock(&st->buf_lock);
297 return ret;
298}
299
300static int __devinit ade7854_spi_probe(struct spi_device *spi)
301{
302 int ret;
303 struct ade7854_state *st = kzalloc(sizeof *st, GFP_KERNEL);
304 if (!st) {
305 ret = -ENOMEM;
306 return ret;
307 }
308
309 spi_set_drvdata(spi, st);
310 st->read_reg_8 = ade7854_spi_read_reg_8;
311 st->read_reg_16 = ade7854_spi_read_reg_16;
312 st->read_reg_24 = ade7854_spi_read_reg_24;
313 st->read_reg_32 = ade7854_spi_read_reg_32;
314 st->write_reg_8 = ade7854_spi_write_reg_8;
315 st->write_reg_16 = ade7854_spi_write_reg_16;
316 st->write_reg_24 = ade7854_spi_write_reg_24;
317 st->write_reg_32 = ade7854_spi_write_reg_32;
318 st->irq = spi->irq;
319 st->spi = spi;
320
321 ret = ade7854_probe(st, &spi->dev);
322 if (ret) {
323 kfree(st);
324 return ret;
325 }
326
327 return 0;
328}
329
330static int ade7854_spi_remove(struct spi_device *spi)
331{
332 ade7854_remove(spi_get_drvdata(spi));
333
334 return 0;
335}
336
337static struct spi_driver ade7854_driver = {
338 .driver = {
339 .name = "ade7854",
340 .owner = THIS_MODULE,
341 },
342 .probe = ade7854_spi_probe,
343 .remove = __devexit_p(ade7854_spi_remove),
344};
345
346static __init int ade7854_init(void)
347{
348 return spi_register_driver(&ade7854_driver);
349}
350module_init(ade7854_init);
351
352static __exit void ade7854_exit(void)
353{
354 spi_unregister_driver(&ade7854_driver);
355}
356module_exit(ade7854_exit);
357
358MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
359MODULE_DESCRIPTION("Analog Devices ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC SPI Driver");
360MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/meter/ade7854.c b/drivers/staging/iio/meter/ade7854.c
new file mode 100644
index 000000000000..a13d5048cf42
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7854.c
@@ -0,0 +1,680 @@
1/*
2 * ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/gpio.h>
12#include <linux/delay.h>
13#include <linux/mutex.h>
14#include <linux/device.h>
15#include <linux/kernel.h>
16#include <linux/slab.h>
17#include <linux/sysfs.h>
18#include <linux/list.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22#include "meter.h"
23#include "ade7854.h"
24
25static ssize_t ade7854_read_8bit(struct device *dev,
26 struct device_attribute *attr,
27 char *buf)
28{
29 int ret;
30 u8 val = 0;
31 struct iio_dev *indio_dev = dev_get_drvdata(dev);
32 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
33 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
34
35 ret = st->read_reg_8(dev, this_attr->address, &val);
36 if (ret)
37 return ret;
38
39 return sprintf(buf, "%u\n", val);
40}
41
42static ssize_t ade7854_read_16bit(struct device *dev,
43 struct device_attribute *attr,
44 char *buf)
45{
46 int ret;
47 u16 val = 0;
48 struct iio_dev *indio_dev = dev_get_drvdata(dev);
49 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
50 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
51
52 ret = st->read_reg_16(dev, this_attr->address, &val);
53 if (ret)
54 return ret;
55
56 return sprintf(buf, "%u\n", val);
57}
58
59static ssize_t ade7854_read_24bit(struct device *dev,
60 struct device_attribute *attr,
61 char *buf)
62{
63 int ret;
64 u32 val = 0;
65 struct iio_dev *indio_dev = dev_get_drvdata(dev);
66 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
67 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
68
69 ret = st->read_reg_24(dev, this_attr->address, &val);
70 if (ret)
71 return ret;
72
73 return sprintf(buf, "%u\n", val & 0xFFFFFF);
74}
75
76static ssize_t ade7854_read_32bit(struct device *dev,
77 struct device_attribute *attr,
78 char *buf)
79{
80 int ret;
81 u32 val = 0;
82 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
83 struct iio_dev *indio_dev = dev_get_drvdata(dev);
84 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
85
86 ret = st->read_reg_32(dev, this_attr->address, &val);
87 if (ret)
88 return ret;
89
90 return sprintf(buf, "%u\n", val);
91}
92
93static ssize_t ade7854_write_8bit(struct device *dev,
94 struct device_attribute *attr,
95 const char *buf,
96 size_t len)
97{
98 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
99 struct iio_dev *indio_dev = dev_get_drvdata(dev);
100 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
101
102 int ret;
103 long val;
104
105 ret = strict_strtol(buf, 10, &val);
106 if (ret)
107 goto error_ret;
108 ret = st->write_reg_8(dev, this_attr->address, val);
109
110error_ret:
111 return ret ? ret : len;
112}
113
114static ssize_t ade7854_write_16bit(struct device *dev,
115 struct device_attribute *attr,
116 const char *buf,
117 size_t len)
118{
119 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
120 struct iio_dev *indio_dev = dev_get_drvdata(dev);
121 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
122
123 int ret;
124 long val;
125
126 ret = strict_strtol(buf, 10, &val);
127 if (ret)
128 goto error_ret;
129 ret = st->write_reg_16(dev, this_attr->address, val);
130
131error_ret:
132 return ret ? ret : len;
133}
134
135static ssize_t ade7854_write_24bit(struct device *dev,
136 struct device_attribute *attr,
137 const char *buf,
138 size_t len)
139{
140 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
141 struct iio_dev *indio_dev = dev_get_drvdata(dev);
142 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
143
144 int ret;
145 long val;
146
147 ret = strict_strtol(buf, 10, &val);
148 if (ret)
149 goto error_ret;
150 ret = st->write_reg_24(dev, this_attr->address, val);
151
152error_ret:
153 return ret ? ret : len;
154}
155
156static ssize_t ade7854_write_32bit(struct device *dev,
157 struct device_attribute *attr,
158 const char *buf,
159 size_t len)
160{
161 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
162 struct iio_dev *indio_dev = dev_get_drvdata(dev);
163 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
164
165 int ret;
166 long val;
167
168 ret = strict_strtol(buf, 10, &val);
169 if (ret)
170 goto error_ret;
171 ret = st->write_reg_32(dev, this_attr->address, val);
172
173error_ret:
174 return ret ? ret : len;
175}
176
177static int ade7854_reset(struct device *dev)
178{
179 struct iio_dev *indio_dev = dev_get_drvdata(dev);
180 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
181
182 int ret;
183 u16 val;
184
185 st->read_reg_16(dev, ADE7854_CONFIG, &val);
186 val |= 1 << 7; /* Software Chip Reset */
187 ret = st->write_reg_16(dev, ADE7854_CONFIG, val);
188
189 return ret;
190}
191
192
193static ssize_t ade7854_write_reset(struct device *dev,
194 struct device_attribute *attr,
195 const char *buf, size_t len)
196{
197 if (len < 1)
198 return -1;
199 switch (buf[0]) {
200 case '1':
201 case 'y':
202 case 'Y':
203 return ade7854_reset(dev);
204 }
205 return -1;
206}
207
208static IIO_DEV_ATTR_AIGAIN(S_IWUSR | S_IRUGO,
209 ade7854_read_24bit,
210 ade7854_write_24bit,
211 ADE7854_AIGAIN);
212static IIO_DEV_ATTR_BIGAIN(S_IWUSR | S_IRUGO,
213 ade7854_read_24bit,
214 ade7854_write_24bit,
215 ADE7854_BIGAIN);
216static IIO_DEV_ATTR_CIGAIN(S_IWUSR | S_IRUGO,
217 ade7854_read_24bit,
218 ade7854_write_24bit,
219 ADE7854_CIGAIN);
220static IIO_DEV_ATTR_NIGAIN(S_IWUSR | S_IRUGO,
221 ade7854_read_24bit,
222 ade7854_write_24bit,
223 ADE7854_NIGAIN);
224static IIO_DEV_ATTR_AVGAIN(S_IWUSR | S_IRUGO,
225 ade7854_read_24bit,
226 ade7854_write_24bit,
227 ADE7854_AVGAIN);
228static IIO_DEV_ATTR_BVGAIN(S_IWUSR | S_IRUGO,
229 ade7854_read_24bit,
230 ade7854_write_24bit,
231 ADE7854_BVGAIN);
232static IIO_DEV_ATTR_CVGAIN(S_IWUSR | S_IRUGO,
233 ade7854_read_24bit,
234 ade7854_write_24bit,
235 ADE7854_CVGAIN);
236static IIO_DEV_ATTR_APPARENT_POWER_A_GAIN(S_IWUSR | S_IRUGO,
237 ade7854_read_24bit,
238 ade7854_write_24bit,
239 ADE7854_AVAGAIN);
240static IIO_DEV_ATTR_APPARENT_POWER_B_GAIN(S_IWUSR | S_IRUGO,
241 ade7854_read_24bit,
242 ade7854_write_24bit,
243 ADE7854_BVAGAIN);
244static IIO_DEV_ATTR_APPARENT_POWER_C_GAIN(S_IWUSR | S_IRUGO,
245 ade7854_read_24bit,
246 ade7854_write_24bit,
247 ADE7854_CVAGAIN);
248static IIO_DEV_ATTR_ACTIVE_POWER_A_OFFSET(S_IWUSR | S_IRUGO,
249 ade7854_read_24bit,
250 ade7854_write_24bit,
251 ADE7854_AWATTOS);
252static IIO_DEV_ATTR_ACTIVE_POWER_B_OFFSET(S_IWUSR | S_IRUGO,
253 ade7854_read_24bit,
254 ade7854_write_24bit,
255 ADE7854_BWATTOS);
256static IIO_DEV_ATTR_ACTIVE_POWER_C_OFFSET(S_IWUSR | S_IRUGO,
257 ade7854_read_24bit,
258 ade7854_write_24bit,
259 ADE7854_CWATTOS);
260static IIO_DEV_ATTR_REACTIVE_POWER_A_GAIN(S_IWUSR | S_IRUGO,
261 ade7854_read_24bit,
262 ade7854_write_24bit,
263 ADE7854_AVARGAIN);
264static IIO_DEV_ATTR_REACTIVE_POWER_B_GAIN(S_IWUSR | S_IRUGO,
265 ade7854_read_24bit,
266 ade7854_write_24bit,
267 ADE7854_BVARGAIN);
268static IIO_DEV_ATTR_REACTIVE_POWER_C_GAIN(S_IWUSR | S_IRUGO,
269 ade7854_read_24bit,
270 ade7854_write_24bit,
271 ADE7854_CVARGAIN);
272static IIO_DEV_ATTR_REACTIVE_POWER_A_OFFSET(S_IWUSR | S_IRUGO,
273 ade7854_read_24bit,
274 ade7854_write_24bit,
275 ADE7854_AVAROS);
276static IIO_DEV_ATTR_REACTIVE_POWER_B_OFFSET(S_IWUSR | S_IRUGO,
277 ade7854_read_24bit,
278 ade7854_write_24bit,
279 ADE7854_BVAROS);
280static IIO_DEV_ATTR_REACTIVE_POWER_C_OFFSET(S_IWUSR | S_IRUGO,
281 ade7854_read_24bit,
282 ade7854_write_24bit,
283 ADE7854_CVAROS);
284static IIO_DEV_ATTR_VPEAK(S_IWUSR | S_IRUGO,
285 ade7854_read_32bit,
286 ade7854_write_32bit,
287 ADE7854_VPEAK);
288static IIO_DEV_ATTR_IPEAK(S_IWUSR | S_IRUGO,
289 ade7854_read_32bit,
290 ade7854_write_32bit,
291 ADE7854_VPEAK);
292static IIO_DEV_ATTR_APHCAL(S_IWUSR | S_IRUGO,
293 ade7854_read_16bit,
294 ade7854_write_16bit,
295 ADE7854_APHCAL);
296static IIO_DEV_ATTR_BPHCAL(S_IWUSR | S_IRUGO,
297 ade7854_read_16bit,
298 ade7854_write_16bit,
299 ADE7854_BPHCAL);
300static IIO_DEV_ATTR_CPHCAL(S_IWUSR | S_IRUGO,
301 ade7854_read_16bit,
302 ade7854_write_16bit,
303 ADE7854_CPHCAL);
304static IIO_DEV_ATTR_CF1DEN(S_IWUSR | S_IRUGO,
305 ade7854_read_16bit,
306 ade7854_write_16bit,
307 ADE7854_CF1DEN);
308static IIO_DEV_ATTR_CF2DEN(S_IWUSR | S_IRUGO,
309 ade7854_read_16bit,
310 ade7854_write_16bit,
311 ADE7854_CF2DEN);
312static IIO_DEV_ATTR_CF3DEN(S_IWUSR | S_IRUGO,
313 ade7854_read_16bit,
314 ade7854_write_16bit,
315 ADE7854_CF3DEN);
316static IIO_DEV_ATTR_LINECYC(S_IWUSR | S_IRUGO,
317 ade7854_read_16bit,
318 ade7854_write_16bit,
319 ADE7854_LINECYC);
320static IIO_DEV_ATTR_SAGCYC(S_IWUSR | S_IRUGO,
321 ade7854_read_8bit,
322 ade7854_write_8bit,
323 ADE7854_SAGCYC);
324static IIO_DEV_ATTR_CFCYC(S_IWUSR | S_IRUGO,
325 ade7854_read_8bit,
326 ade7854_write_8bit,
327 ADE7854_CFCYC);
328static IIO_DEV_ATTR_PEAKCYC(S_IWUSR | S_IRUGO,
329 ade7854_read_8bit,
330 ade7854_write_8bit,
331 ADE7854_PEAKCYC);
332static IIO_DEV_ATTR_CHKSUM(ade7854_read_24bit,
333 ADE7854_CHECKSUM);
334static IIO_DEV_ATTR_ANGLE0(ade7854_read_24bit,
335 ADE7854_ANGLE0);
336static IIO_DEV_ATTR_ANGLE1(ade7854_read_24bit,
337 ADE7854_ANGLE1);
338static IIO_DEV_ATTR_ANGLE2(ade7854_read_24bit,
339 ADE7854_ANGLE2);
340static IIO_DEV_ATTR_AIRMS(S_IRUGO,
341 ade7854_read_24bit,
342 NULL,
343 ADE7854_AIRMS);
344static IIO_DEV_ATTR_BIRMS(S_IRUGO,
345 ade7854_read_24bit,
346 NULL,
347 ADE7854_BIRMS);
348static IIO_DEV_ATTR_CIRMS(S_IRUGO,
349 ade7854_read_24bit,
350 NULL,
351 ADE7854_CIRMS);
352static IIO_DEV_ATTR_NIRMS(S_IRUGO,
353 ade7854_read_24bit,
354 NULL,
355 ADE7854_NIRMS);
356static IIO_DEV_ATTR_AVRMS(S_IRUGO,
357 ade7854_read_24bit,
358 NULL,
359 ADE7854_AVRMS);
360static IIO_DEV_ATTR_BVRMS(S_IRUGO,
361 ade7854_read_24bit,
362 NULL,
363 ADE7854_BVRMS);
364static IIO_DEV_ATTR_CVRMS(S_IRUGO,
365 ade7854_read_24bit,
366 NULL,
367 ADE7854_CVRMS);
368static IIO_DEV_ATTR_AIRMSOS(S_IRUGO,
369 ade7854_read_16bit,
370 ade7854_write_16bit,
371 ADE7854_AIRMSOS);
372static IIO_DEV_ATTR_BIRMSOS(S_IRUGO,
373 ade7854_read_16bit,
374 ade7854_write_16bit,
375 ADE7854_BIRMSOS);
376static IIO_DEV_ATTR_CIRMSOS(S_IRUGO,
377 ade7854_read_16bit,
378 ade7854_write_16bit,
379 ADE7854_CIRMSOS);
380static IIO_DEV_ATTR_AVRMSOS(S_IRUGO,
381 ade7854_read_16bit,
382 ade7854_write_16bit,
383 ADE7854_AVRMSOS);
384static IIO_DEV_ATTR_BVRMSOS(S_IRUGO,
385 ade7854_read_16bit,
386 ade7854_write_16bit,
387 ADE7854_BVRMSOS);
388static IIO_DEV_ATTR_CVRMSOS(S_IRUGO,
389 ade7854_read_16bit,
390 ade7854_write_16bit,
391 ADE7854_CVRMSOS);
392static IIO_DEV_ATTR_VOLT_A(ade7854_read_24bit,
393 ADE7854_VAWV);
394static IIO_DEV_ATTR_VOLT_B(ade7854_read_24bit,
395 ADE7854_VBWV);
396static IIO_DEV_ATTR_VOLT_C(ade7854_read_24bit,
397 ADE7854_VCWV);
398static IIO_DEV_ATTR_CURRENT_A(ade7854_read_24bit,
399 ADE7854_IAWV);
400static IIO_DEV_ATTR_CURRENT_B(ade7854_read_24bit,
401 ADE7854_IBWV);
402static IIO_DEV_ATTR_CURRENT_C(ade7854_read_24bit,
403 ADE7854_ICWV);
404static IIO_DEV_ATTR_AWATTHR(ade7854_read_32bit,
405 ADE7854_AWATTHR);
406static IIO_DEV_ATTR_BWATTHR(ade7854_read_32bit,
407 ADE7854_BWATTHR);
408static IIO_DEV_ATTR_CWATTHR(ade7854_read_32bit,
409 ADE7854_CWATTHR);
410static IIO_DEV_ATTR_AFWATTHR(ade7854_read_32bit,
411 ADE7854_AFWATTHR);
412static IIO_DEV_ATTR_BFWATTHR(ade7854_read_32bit,
413 ADE7854_BFWATTHR);
414static IIO_DEV_ATTR_CFWATTHR(ade7854_read_32bit,
415 ADE7854_CFWATTHR);
416static IIO_DEV_ATTR_AVARHR(ade7854_read_32bit,
417 ADE7854_AVARHR);
418static IIO_DEV_ATTR_BVARHR(ade7854_read_32bit,
419 ADE7854_BVARHR);
420static IIO_DEV_ATTR_CVARHR(ade7854_read_32bit,
421 ADE7854_CVARHR);
422static IIO_DEV_ATTR_AVAHR(ade7854_read_32bit,
423 ADE7854_AVAHR);
424static IIO_DEV_ATTR_BVAHR(ade7854_read_32bit,
425 ADE7854_BVAHR);
426static IIO_DEV_ATTR_CVAHR(ade7854_read_32bit,
427 ADE7854_CVAHR);
428
429static int ade7854_set_irq(struct device *dev, bool enable)
430{
431 struct iio_dev *indio_dev = dev_get_drvdata(dev);
432 struct ade7854_state *st = iio_dev_get_devdata(indio_dev);
433
434 int ret;
435 u32 irqen;
436
437 ret = st->read_reg_32(dev, ADE7854_MASK0, &irqen);
438 if (ret)
439 goto error_ret;
440
441 if (enable)
442 irqen |= 1 << 17; /* 1: interrupt enabled when all periodical
443 (at 8 kHz rate) DSP computations finish. */
444 else
445 irqen &= ~(1 << 17);
446
447 ret = st->write_reg_32(dev, ADE7854_MASK0, irqen);
448 if (ret)
449 goto error_ret;
450
451error_ret:
452 return ret;
453}
454
455static int ade7854_initial_setup(struct ade7854_state *st)
456{
457 int ret;
458 struct device *dev = &st->indio_dev->dev;
459
460 /* Disable IRQ */
461 ret = ade7854_set_irq(dev, false);
462 if (ret) {
463 dev_err(dev, "disable irq failed");
464 goto err_ret;
465 }
466
467 ade7854_reset(dev);
468 msleep(ADE7854_STARTUP_DELAY);
469
470err_ret:
471 return ret;
472}
473
474static IIO_DEV_ATTR_RESET(ade7854_write_reset);
475
476static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("8000");
477
478static IIO_CONST_ATTR(name, "ade7854");
479
480static struct attribute *ade7854_event_attributes[] = {
481 NULL
482};
483
484static struct attribute_group ade7854_event_attribute_group = {
485 .attrs = ade7854_event_attributes,
486};
487
488static struct attribute *ade7854_attributes[] = {
489 &iio_dev_attr_aigain.dev_attr.attr,
490 &iio_dev_attr_bigain.dev_attr.attr,
491 &iio_dev_attr_cigain.dev_attr.attr,
492 &iio_dev_attr_nigain.dev_attr.attr,
493 &iio_dev_attr_avgain.dev_attr.attr,
494 &iio_dev_attr_bvgain.dev_attr.attr,
495 &iio_dev_attr_cvgain.dev_attr.attr,
496 &iio_dev_attr_linecyc.dev_attr.attr,
497 &iio_dev_attr_sagcyc.dev_attr.attr,
498 &iio_dev_attr_cfcyc.dev_attr.attr,
499 &iio_dev_attr_peakcyc.dev_attr.attr,
500 &iio_dev_attr_chksum.dev_attr.attr,
501 &iio_dev_attr_apparent_power_a_gain.dev_attr.attr,
502 &iio_dev_attr_apparent_power_b_gain.dev_attr.attr,
503 &iio_dev_attr_apparent_power_c_gain.dev_attr.attr,
504 &iio_dev_attr_active_power_a_offset.dev_attr.attr,
505 &iio_dev_attr_active_power_b_offset.dev_attr.attr,
506 &iio_dev_attr_active_power_c_offset.dev_attr.attr,
507 &iio_dev_attr_reactive_power_a_gain.dev_attr.attr,
508 &iio_dev_attr_reactive_power_b_gain.dev_attr.attr,
509 &iio_dev_attr_reactive_power_c_gain.dev_attr.attr,
510 &iio_dev_attr_reactive_power_a_offset.dev_attr.attr,
511 &iio_dev_attr_reactive_power_b_offset.dev_attr.attr,
512 &iio_dev_attr_reactive_power_c_offset.dev_attr.attr,
513 &iio_dev_attr_awatthr.dev_attr.attr,
514 &iio_dev_attr_bwatthr.dev_attr.attr,
515 &iio_dev_attr_cwatthr.dev_attr.attr,
516 &iio_dev_attr_afwatthr.dev_attr.attr,
517 &iio_dev_attr_bfwatthr.dev_attr.attr,
518 &iio_dev_attr_cfwatthr.dev_attr.attr,
519 &iio_dev_attr_avarhr.dev_attr.attr,
520 &iio_dev_attr_bvarhr.dev_attr.attr,
521 &iio_dev_attr_cvarhr.dev_attr.attr,
522 &iio_dev_attr_angle0.dev_attr.attr,
523 &iio_dev_attr_angle1.dev_attr.attr,
524 &iio_dev_attr_angle2.dev_attr.attr,
525 &iio_dev_attr_avahr.dev_attr.attr,
526 &iio_dev_attr_bvahr.dev_attr.attr,
527 &iio_dev_attr_cvahr.dev_attr.attr,
528 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
529 &iio_dev_attr_reset.dev_attr.attr,
530 &iio_const_attr_name.dev_attr.attr,
531 &iio_dev_attr_vpeak.dev_attr.attr,
532 &iio_dev_attr_ipeak.dev_attr.attr,
533 &iio_dev_attr_aphcal.dev_attr.attr,
534 &iio_dev_attr_bphcal.dev_attr.attr,
535 &iio_dev_attr_cphcal.dev_attr.attr,
536 &iio_dev_attr_cf1den.dev_attr.attr,
537 &iio_dev_attr_cf2den.dev_attr.attr,
538 &iio_dev_attr_cf3den.dev_attr.attr,
539 &iio_dev_attr_airms.dev_attr.attr,
540 &iio_dev_attr_birms.dev_attr.attr,
541 &iio_dev_attr_cirms.dev_attr.attr,
542 &iio_dev_attr_nirms.dev_attr.attr,
543 &iio_dev_attr_avrms.dev_attr.attr,
544 &iio_dev_attr_bvrms.dev_attr.attr,
545 &iio_dev_attr_cvrms.dev_attr.attr,
546 &iio_dev_attr_airmsos.dev_attr.attr,
547 &iio_dev_attr_birmsos.dev_attr.attr,
548 &iio_dev_attr_cirmsos.dev_attr.attr,
549 &iio_dev_attr_avrmsos.dev_attr.attr,
550 &iio_dev_attr_bvrmsos.dev_attr.attr,
551 &iio_dev_attr_cvrmsos.dev_attr.attr,
552 &iio_dev_attr_volt_a.dev_attr.attr,
553 &iio_dev_attr_volt_b.dev_attr.attr,
554 &iio_dev_attr_volt_c.dev_attr.attr,
555 &iio_dev_attr_current_a.dev_attr.attr,
556 &iio_dev_attr_current_b.dev_attr.attr,
557 &iio_dev_attr_current_c.dev_attr.attr,
558 NULL,
559};
560
561static const struct attribute_group ade7854_attribute_group = {
562 .attrs = ade7854_attributes,
563};
564
565int ade7854_probe(struct ade7854_state *st, struct device *dev)
566{
567 int ret, regdone = 0;
568
569 /* Allocate the comms buffers */
570 st->rx = kzalloc(sizeof(*st->rx)*ADE7854_MAX_RX, GFP_KERNEL);
571 if (st->rx == NULL) {
572 ret = -ENOMEM;
573 goto error_free_st;
574 }
575 st->tx = kzalloc(sizeof(*st->tx)*ADE7854_MAX_TX, GFP_KERNEL);
576 if (st->tx == NULL) {
577 ret = -ENOMEM;
578 goto error_free_rx;
579 }
580 mutex_init(&st->buf_lock);
581 /* setup the industrialio driver allocated elements */
582 st->indio_dev = iio_allocate_device();
583 if (st->indio_dev == NULL) {
584 ret = -ENOMEM;
585 goto error_free_tx;
586 }
587
588 st->indio_dev->dev.parent = dev;
589 st->indio_dev->num_interrupt_lines = 1;
590 st->indio_dev->event_attrs = &ade7854_event_attribute_group;
591 st->indio_dev->attrs = &ade7854_attribute_group;
592 st->indio_dev->dev_data = (void *)(st);
593 st->indio_dev->driver_module = THIS_MODULE;
594 st->indio_dev->modes = INDIO_DIRECT_MODE;
595
596 ret = ade7854_configure_ring(st->indio_dev);
597 if (ret)
598 goto error_free_dev;
599
600 ret = iio_device_register(st->indio_dev);
601 if (ret)
602 goto error_unreg_ring_funcs;
603 regdone = 1;
604
605 ret = ade7854_initialize_ring(st->indio_dev->ring);
606 if (ret) {
607 printk(KERN_ERR "failed to initialize the ring\n");
608 goto error_unreg_ring_funcs;
609 }
610
611 if (st->irq) {
612 ret = iio_register_interrupt_line(st->irq,
613 st->indio_dev,
614 0,
615 IRQF_TRIGGER_FALLING,
616 "ade7854");
617 if (ret)
618 goto error_uninitialize_ring;
619
620 ret = ade7854_probe_trigger(st->indio_dev);
621 if (ret)
622 goto error_unregister_line;
623 }
624 /* Get the device into a sane initial state */
625 ret = ade7854_initial_setup(st);
626 if (ret)
627 goto error_remove_trigger;
628
629 return 0;
630
631error_remove_trigger:
632 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
633 ade7854_remove_trigger(st->indio_dev);
634error_unregister_line:
635 if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
636 iio_unregister_interrupt_line(st->indio_dev, 0);
637error_uninitialize_ring:
638 ade7854_uninitialize_ring(st->indio_dev->ring);
639error_unreg_ring_funcs:
640 ade7854_unconfigure_ring(st->indio_dev);
641error_free_dev:
642 if (regdone)
643 iio_device_unregister(st->indio_dev);
644 else
645 iio_free_device(st->indio_dev);
646error_free_tx:
647 kfree(st->tx);
648error_free_rx:
649 kfree(st->rx);
650error_free_st:
651 kfree(st);
652 return ret;
653
654}
655EXPORT_SYMBOL(ade7854_probe);
656
657int ade7854_remove(struct ade7854_state *st)
658{
659 struct iio_dev *indio_dev = st->indio_dev;
660
661 flush_scheduled_work();
662
663 ade7854_remove_trigger(indio_dev);
664 if (st->irq)
665 iio_unregister_interrupt_line(indio_dev, 0);
666
667 ade7854_uninitialize_ring(indio_dev->ring);
668 ade7854_unconfigure_ring(indio_dev);
669 iio_device_unregister(indio_dev);
670 kfree(st->tx);
671 kfree(st->rx);
672 kfree(st);
673
674 return 0;
675}
676EXPORT_SYMBOL(ade7854_remove);
677
678MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
679MODULE_DESCRIPTION("Analog Devices ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver");
680MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/meter/ade7854.h b/drivers/staging/iio/meter/ade7854.h
new file mode 100644
index 000000000000..47690e521ec1
--- /dev/null
+++ b/drivers/staging/iio/meter/ade7854.h
@@ -0,0 +1,245 @@
1#ifndef _ADE7854_H
2#define _ADE7854_H
3
4#define ADE7854_AIGAIN 0x4380
5#define ADE7854_AVGAIN 0x4381
6#define ADE7854_BIGAIN 0x4382
7#define ADE7854_BVGAIN 0x4383
8#define ADE7854_CIGAIN 0x4384
9#define ADE7854_CVGAIN 0x4385
10#define ADE7854_NIGAIN 0x4386
11#define ADE7854_AIRMSOS 0x4387
12#define ADE7854_AVRMSOS 0x4388
13#define ADE7854_BIRMSOS 0x4389
14#define ADE7854_BVRMSOS 0x438A
15#define ADE7854_CIRMSOS 0x438B
16#define ADE7854_CVRMSOS 0x438C
17#define ADE7854_NIRMSOS 0x438D
18#define ADE7854_AVAGAIN 0x438E
19#define ADE7854_BVAGAIN 0x438F
20#define ADE7854_CVAGAIN 0x4390
21#define ADE7854_AWGAIN 0x4391
22#define ADE7854_AWATTOS 0x4392
23#define ADE7854_BWGAIN 0x4393
24#define ADE7854_BWATTOS 0x4394
25#define ADE7854_CWGAIN 0x4395
26#define ADE7854_CWATTOS 0x4396
27#define ADE7854_AVARGAIN 0x4397
28#define ADE7854_AVAROS 0x4398
29#define ADE7854_BVARGAIN 0x4399
30#define ADE7854_BVAROS 0x439A
31#define ADE7854_CVARGAIN 0x439B
32#define ADE7854_CVAROS 0x439C
33#define ADE7854_AFWGAIN 0x439D
34#define ADE7854_AFWATTOS 0x439E
35#define ADE7854_BFWGAIN 0x439F
36#define ADE7854_BFWATTOS 0x43A0
37#define ADE7854_CFWGAIN 0x43A1
38#define ADE7854_CFWATTOS 0x43A2
39#define ADE7854_AFVARGAIN 0x43A3
40#define ADE7854_AFVAROS 0x43A4
41#define ADE7854_BFVARGAIN 0x43A5
42#define ADE7854_BFVAROS 0x43A6
43#define ADE7854_CFVARGAIN 0x43A7
44#define ADE7854_CFVAROS 0x43A8
45#define ADE7854_VATHR1 0x43A9
46#define ADE7854_VATHR0 0x43AA
47#define ADE7854_WTHR1 0x43AB
48#define ADE7854_WTHR0 0x43AC
49#define ADE7854_VARTHR1 0x43AD
50#define ADE7854_VARTHR0 0x43AE
51#define ADE7854_RSV 0x43AF
52#define ADE7854_VANOLOAD 0x43B0
53#define ADE7854_APNOLOAD 0x43B1
54#define ADE7854_VARNOLOAD 0x43B2
55#define ADE7854_VLEVEL 0x43B3
56#define ADE7854_DICOEFF 0x43B5
57#define ADE7854_HPFDIS 0x43B6
58#define ADE7854_ISUMLVL 0x43B8
59#define ADE7854_ISUM 0x43BF
60#define ADE7854_AIRMS 0x43C0
61#define ADE7854_AVRMS 0x43C1
62#define ADE7854_BIRMS 0x43C2
63#define ADE7854_BVRMS 0x43C3
64#define ADE7854_CIRMS 0x43C4
65#define ADE7854_CVRMS 0x43C5
66#define ADE7854_NIRMS 0x43C6
67#define ADE7854_RUN 0xE228
68#define ADE7854_AWATTHR 0xE400
69#define ADE7854_BWATTHR 0xE401
70#define ADE7854_CWATTHR 0xE402
71#define ADE7854_AFWATTHR 0xE403
72#define ADE7854_BFWATTHR 0xE404
73#define ADE7854_CFWATTHR 0xE405
74#define ADE7854_AVARHR 0xE406
75#define ADE7854_BVARHR 0xE407
76#define ADE7854_CVARHR 0xE408
77#define ADE7854_AFVARHR 0xE409
78#define ADE7854_BFVARHR 0xE40A
79#define ADE7854_CFVARHR 0xE40B
80#define ADE7854_AVAHR 0xE40C
81#define ADE7854_BVAHR 0xE40D
82#define ADE7854_CVAHR 0xE40E
83#define ADE7854_IPEAK 0xE500
84#define ADE7854_VPEAK 0xE501
85#define ADE7854_STATUS0 0xE502
86#define ADE7854_STATUS1 0xE503
87#define ADE7854_OILVL 0xE507
88#define ADE7854_OVLVL 0xE508
89#define ADE7854_SAGLVL 0xE509
90#define ADE7854_MASK0 0xE50A
91#define ADE7854_MASK1 0xE50B
92#define ADE7854_IAWV 0xE50C
93#define ADE7854_IBWV 0xE50D
94#define ADE7854_ICWV 0xE50E
95#define ADE7854_VAWV 0xE510
96#define ADE7854_VBWV 0xE511
97#define ADE7854_VCWV 0xE512
98#define ADE7854_AWATT 0xE513
99#define ADE7854_BWATT 0xE514
100#define ADE7854_CWATT 0xE515
101#define ADE7854_AVA 0xE519
102#define ADE7854_BVA 0xE51A
103#define ADE7854_CVA 0xE51B
104#define ADE7854_CHECKSUM 0xE51F
105#define ADE7854_VNOM 0xE520
106#define ADE7854_PHSTATUS 0xE600
107#define ADE7854_ANGLE0 0xE601
108#define ADE7854_ANGLE1 0xE602
109#define ADE7854_ANGLE2 0xE603
110#define ADE7854_PERIOD 0xE607
111#define ADE7854_PHNOLOAD 0xE608
112#define ADE7854_LINECYC 0xE60C
113#define ADE7854_ZXTOUT 0xE60D
114#define ADE7854_COMPMODE 0xE60E
115#define ADE7854_GAIN 0xE60F
116#define ADE7854_CFMODE 0xE610
117#define ADE7854_CF1DEN 0xE611
118#define ADE7854_CF2DEN 0xE612
119#define ADE7854_CF3DEN 0xE613
120#define ADE7854_APHCAL 0xE614
121#define ADE7854_BPHCAL 0xE615
122#define ADE7854_CPHCAL 0xE616
123#define ADE7854_PHSIGN 0xE617
124#define ADE7854_CONFIG 0xE618
125#define ADE7854_MMODE 0xE700
126#define ADE7854_ACCMODE 0xE701
127#define ADE7854_LCYCMODE 0xE702
128#define ADE7854_PEAKCYC 0xE703
129#define ADE7854_SAGCYC 0xE704
130#define ADE7854_CFCYC 0xE705
131#define ADE7854_HSDC_CFG 0xE706
132#define ADE7854_CONFIG2 0xEC01
133
134#define ADE7854_READ_REG 0x1
135#define ADE7854_WRITE_REG 0x0
136
137#define ADE7854_MAX_TX 7
138#define ADE7854_MAX_RX 7
139#define ADE7854_STARTUP_DELAY 1
140
141#define ADE7854_SPI_SLOW (u32)(300 * 1000)
142#define ADE7854_SPI_BURST (u32)(1000 * 1000)
143#define ADE7854_SPI_FAST (u32)(2000 * 1000)
144
145#define DRIVER_NAME "ade7854"
146
147/**
148 * struct ade7854_state - device instance specific data
149 * @spi: actual spi_device
150 * @work_trigger_to_ring: bh for triggered event handling
151 * @inter: used to check if new interrupt has been triggered
152 * @last_timestamp: passing timestamp from th to bh of interrupt handler
153 * @indio_dev: industrial I/O device structure
154 * @trig: data ready trigger registered with iio
155 * @tx: transmit buffer
156 * @rx: recieve buffer
157 * @buf_lock: mutex to protect tx and rx
158 **/
159struct ade7854_state {
160 struct spi_device *spi;
161 struct i2c_client *i2c;
162 struct work_struct work_trigger_to_ring;
163 s64 last_timestamp;
164 struct iio_dev *indio_dev;
165 struct iio_trigger *trig;
166 u8 *tx;
167 u8 *rx;
168 int (*read_reg_8) (struct device *, u16, u8 *);
169 int (*read_reg_16) (struct device *, u16, u16 *);
170 int (*read_reg_24) (struct device *, u16, u32 *);
171 int (*read_reg_32) (struct device *, u16, u32 *);
172 int (*write_reg_8) (struct device *, u16, u8);
173 int (*write_reg_16) (struct device *, u16, u16);
174 int (*write_reg_24) (struct device *, u16, u32);
175 int (*write_reg_32) (struct device *, u16, u32);
176 int irq;
177 struct mutex buf_lock;
178};
179
180extern int ade7854_probe(struct ade7854_state *st, struct device *dev);
181extern int ade7854_remove(struct ade7854_state *st);
182
183#if defined(CONFIG_IIO_RING_BUFFER) && defined(THIS_HAS_RING_BUFFER_SUPPORT)
184/* At the moment triggers are only used for ring buffer
185 * filling. This may change!
186 */
187
188enum ade7854_scan {
189 ADE7854_SCAN_PHA_V,
190 ADE7854_SCAN_PHB_V,
191 ADE7854_SCAN_PHC_V,
192 ADE7854_SCAN_PHA_I,
193 ADE7854_SCAN_PHB_I,
194 ADE7854_SCAN_PHC_I,
195};
196
197void ade7854_remove_trigger(struct iio_dev *indio_dev);
198int ade7854_probe_trigger(struct iio_dev *indio_dev);
199
200ssize_t ade7854_read_data_from_ring(struct device *dev,
201 struct device_attribute *attr,
202 char *buf);
203
204
205int ade7854_configure_ring(struct iio_dev *indio_dev);
206void ade7854_unconfigure_ring(struct iio_dev *indio_dev);
207
208int ade7854_initialize_ring(struct iio_ring_buffer *ring);
209void ade7854_uninitialize_ring(struct iio_ring_buffer *ring);
210#else /* CONFIG_IIO_RING_BUFFER */
211
212static inline void ade7854_remove_trigger(struct iio_dev *indio_dev)
213{
214}
215static inline int ade7854_probe_trigger(struct iio_dev *indio_dev)
216{
217 return 0;
218}
219
220static inline ssize_t
221ade7854_read_data_from_ring(struct device *dev,
222 struct device_attribute *attr,
223 char *buf)
224{
225 return 0;
226}
227
228static inline int ade7854_configure_ring(struct iio_dev *indio_dev)
229{
230 return 0;
231}
232
233static inline void ade7854_unconfigure_ring(struct iio_dev *indio_dev)
234{
235}
236static inline int ade7854_initialize_ring(struct iio_ring_buffer *ring)
237{
238 return 0;
239}
240static inline void ade7854_uninitialize_ring(struct iio_ring_buffer *ring)
241{
242}
243#endif /* CONFIG_IIO_RING_BUFFER */
244
245#endif
diff --git a/drivers/staging/iio/meter/meter.h b/drivers/staging/iio/meter/meter.h
new file mode 100644
index 000000000000..142c50d71fda
--- /dev/null
+++ b/drivers/staging/iio/meter/meter.h
@@ -0,0 +1,396 @@
1#include "../sysfs.h"
2
3/* metering ic types of attribute */
4
5#define IIO_DEV_ATTR_CURRENT_A_OFFSET(_mode, _show, _store, _addr) \
6 IIO_DEVICE_ATTR(current_a_offset, _mode, _show, _store, _addr)
7
8#define IIO_DEV_ATTR_CURRENT_B_OFFSET(_mode, _show, _store, _addr) \
9 IIO_DEVICE_ATTR(current_b_offset, _mode, _show, _store, _addr)
10
11#define IIO_DEV_ATTR_CURRENT_C_OFFSET(_mode, _show, _store, _addr) \
12 IIO_DEVICE_ATTR(current_c_offset, _mode, _show, _store, _addr)
13
14#define IIO_DEV_ATTR_VOLT_A_OFFSET(_mode, _show, _store, _addr) \
15 IIO_DEVICE_ATTR(volt_a_offset, _mode, _show, _store, _addr)
16
17#define IIO_DEV_ATTR_VOLT_B_OFFSET(_mode, _show, _store, _addr) \
18 IIO_DEVICE_ATTR(volt_b_offset, _mode, _show, _store, _addr)
19
20#define IIO_DEV_ATTR_VOLT_C_OFFSET(_mode, _show, _store, _addr) \
21 IIO_DEVICE_ATTR(volt_c_offset, _mode, _show, _store, _addr)
22
23#define IIO_DEV_ATTR_REACTIVE_POWER_A_OFFSET(_mode, _show, _store, _addr) \
24 IIO_DEVICE_ATTR(reactive_power_a_offset, _mode, _show, _store, _addr)
25
26#define IIO_DEV_ATTR_REACTIVE_POWER_B_OFFSET(_mode, _show, _store, _addr) \
27 IIO_DEVICE_ATTR(reactive_power_b_offset, _mode, _show, _store, _addr)
28
29#define IIO_DEV_ATTR_REACTIVE_POWER_C_OFFSET(_mode, _show, _store, _addr) \
30 IIO_DEVICE_ATTR(reactive_power_c_offset, _mode, _show, _store, _addr)
31
32#define IIO_DEV_ATTR_ACTIVE_POWER_A_OFFSET(_mode, _show, _store, _addr) \
33 IIO_DEVICE_ATTR(active_power_a_offset, _mode, _show, _store, _addr)
34
35#define IIO_DEV_ATTR_ACTIVE_POWER_B_OFFSET(_mode, _show, _store, _addr) \
36 IIO_DEVICE_ATTR(active_power_b_offset, _mode, _show, _store, _addr)
37
38#define IIO_DEV_ATTR_ACTIVE_POWER_C_OFFSET(_mode, _show, _store, _addr) \
39 IIO_DEVICE_ATTR(active_power_c_offset, _mode, _show, _store, _addr)
40
41#define IIO_DEV_ATTR_CURRENT_A_GAIN(_mode, _show, _store, _addr) \
42 IIO_DEVICE_ATTR(current_a_gain, _mode, _show, _store, _addr)
43
44#define IIO_DEV_ATTR_CURRENT_B_GAIN(_mode, _show, _store, _addr) \
45 IIO_DEVICE_ATTR(current_b_gain, _mode, _show, _store, _addr)
46
47#define IIO_DEV_ATTR_CURRENT_C_GAIN(_mode, _show, _store, _addr) \
48 IIO_DEVICE_ATTR(current_c_gain, _mode, _show, _store, _addr)
49
50#define IIO_DEV_ATTR_APPARENT_POWER_A_GAIN(_mode, _show, _store, _addr) \
51 IIO_DEVICE_ATTR(apparent_power_a_gain, _mode, _show, _store, _addr)
52
53#define IIO_DEV_ATTR_APPARENT_POWER_B_GAIN(_mode, _show, _store, _addr) \
54 IIO_DEVICE_ATTR(apparent_power_b_gain, _mode, _show, _store, _addr)
55
56#define IIO_DEV_ATTR_APPARENT_POWER_C_GAIN(_mode, _show, _store, _addr) \
57 IIO_DEVICE_ATTR(apparent_power_c_gain, _mode, _show, _store, _addr)
58
59#define IIO_DEV_ATTR_ACTIVE_POWER_GAIN(_mode, _show, _store, _addr) \
60 IIO_DEVICE_ATTR(active_power_gain, _mode, _show, _store, _addr)
61
62#define IIO_DEV_ATTR_ACTIVE_POWER_A_GAIN(_mode, _show, _store, _addr) \
63 IIO_DEVICE_ATTR(active_power_a_gain, _mode, _show, _store, _addr)
64
65#define IIO_DEV_ATTR_ACTIVE_POWER_B_GAIN(_mode, _show, _store, _addr) \
66 IIO_DEVICE_ATTR(active_power_b_gain, _mode, _show, _store, _addr)
67
68#define IIO_DEV_ATTR_ACTIVE_POWER_C_GAIN(_mode, _show, _store, _addr) \
69 IIO_DEVICE_ATTR(active_power_c_gain, _mode, _show, _store, _addr)
70
71#define IIO_DEV_ATTR_REACTIVE_POWER_A_GAIN(_mode, _show, _store, _addr) \
72 IIO_DEVICE_ATTR(reactive_power_a_gain, _mode, _show, _store, _addr)
73
74#define IIO_DEV_ATTR_REACTIVE_POWER_B_GAIN(_mode, _show, _store, _addr) \
75 IIO_DEVICE_ATTR(reactive_power_b_gain, _mode, _show, _store, _addr)
76
77#define IIO_DEV_ATTR_REACTIVE_POWER_C_GAIN(_mode, _show, _store, _addr) \
78 IIO_DEVICE_ATTR(reactive_power_c_gain, _mode, _show, _store, _addr)
79
80#define IIO_DEV_ATTR_CURRENT_A(_show, _addr) \
81 IIO_DEVICE_ATTR(current_a, S_IRUGO, _show, NULL, _addr)
82
83#define IIO_DEV_ATTR_CURRENT_B(_show, _addr) \
84 IIO_DEVICE_ATTR(current_b, S_IRUGO, _show, NULL, _addr)
85
86#define IIO_DEV_ATTR_CURRENT_C(_show, _addr) \
87 IIO_DEVICE_ATTR(current_c, S_IRUGO, _show, NULL, _addr)
88
89#define IIO_DEV_ATTR_VOLT_A(_show, _addr) \
90 IIO_DEVICE_ATTR(volt_a, S_IRUGO, _show, NULL, _addr)
91
92#define IIO_DEV_ATTR_VOLT_B(_show, _addr) \
93 IIO_DEVICE_ATTR(volt_b, S_IRUGO, _show, NULL, _addr)
94
95#define IIO_DEV_ATTR_VOLT_C(_show, _addr) \
96 IIO_DEVICE_ATTR(volt_c, S_IRUGO, _show, NULL, _addr)
97
98#define IIO_DEV_ATTR_AENERGY(_show, _addr) \
99 IIO_DEVICE_ATTR(aenergy, S_IRUGO, _show, NULL, _addr)
100
101#define IIO_DEV_ATTR_LENERGY(_show, _addr) \
102 IIO_DEVICE_ATTR(lenergy, S_IRUGO, _show, NULL, _addr)
103
104#define IIO_DEV_ATTR_RAENERGY(_show, _addr) \
105 IIO_DEVICE_ATTR(raenergy, S_IRUGO, _show, NULL, _addr)
106
107#define IIO_DEV_ATTR_LAENERGY(_show, _addr) \
108 IIO_DEVICE_ATTR(laenergy, S_IRUGO, _show, NULL, _addr)
109
110#define IIO_DEV_ATTR_VAENERGY(_show, _addr) \
111 IIO_DEVICE_ATTR(vaenergy, S_IRUGO, _show, NULL, _addr)
112
113#define IIO_DEV_ATTR_LVAENERGY(_show, _addr) \
114 IIO_DEVICE_ATTR(lvaenergy, S_IRUGO, _show, NULL, _addr)
115
116#define IIO_DEV_ATTR_RVAENERGY(_show, _addr) \
117 IIO_DEVICE_ATTR(rvaenergy, S_IRUGO, _show, NULL, _addr)
118
119#define IIO_DEV_ATTR_LVARENERGY(_show, _addr) \
120 IIO_DEVICE_ATTR(lvarenergy, S_IRUGO, _show, NULL, _addr)
121
122#define IIO_DEV_ATTR_CHKSUM(_show, _addr) \
123 IIO_DEVICE_ATTR(chksum, S_IRUGO, _show, NULL, _addr)
124
125#define IIO_DEV_ATTR_ANGLE0(_show, _addr) \
126 IIO_DEVICE_ATTR(angle0, S_IRUGO, _show, NULL, _addr)
127
128#define IIO_DEV_ATTR_ANGLE1(_show, _addr) \
129 IIO_DEVICE_ATTR(angle1, S_IRUGO, _show, NULL, _addr)
130
131#define IIO_DEV_ATTR_ANGLE2(_show, _addr) \
132 IIO_DEVICE_ATTR(angle2, S_IRUGO, _show, NULL, _addr)
133
134#define IIO_DEV_ATTR_AWATTHR(_show, _addr) \
135 IIO_DEVICE_ATTR(awatthr, S_IRUGO, _show, NULL, _addr)
136
137#define IIO_DEV_ATTR_BWATTHR(_show, _addr) \
138 IIO_DEVICE_ATTR(bwatthr, S_IRUGO, _show, NULL, _addr)
139
140#define IIO_DEV_ATTR_CWATTHR(_show, _addr) \
141 IIO_DEVICE_ATTR(cwatthr, S_IRUGO, _show, NULL, _addr)
142
143#define IIO_DEV_ATTR_AFWATTHR(_show, _addr) \
144 IIO_DEVICE_ATTR(afwatthr, S_IRUGO, _show, NULL, _addr)
145
146#define IIO_DEV_ATTR_BFWATTHR(_show, _addr) \
147 IIO_DEVICE_ATTR(bfwatthr, S_IRUGO, _show, NULL, _addr)
148
149#define IIO_DEV_ATTR_CFWATTHR(_show, _addr) \
150 IIO_DEVICE_ATTR(cfwatthr, S_IRUGO, _show, NULL, _addr)
151
152#define IIO_DEV_ATTR_AVARHR(_show, _addr) \
153 IIO_DEVICE_ATTR(avarhr, S_IRUGO, _show, NULL, _addr)
154
155#define IIO_DEV_ATTR_BVARHR(_show, _addr) \
156 IIO_DEVICE_ATTR(bvarhr, S_IRUGO, _show, NULL, _addr)
157
158#define IIO_DEV_ATTR_CVARHR(_show, _addr) \
159 IIO_DEVICE_ATTR(cvarhr, S_IRUGO, _show, NULL, _addr)
160
161#define IIO_DEV_ATTR_AVAHR(_show, _addr) \
162 IIO_DEVICE_ATTR(avahr, S_IRUGO, _show, NULL, _addr)
163
164#define IIO_DEV_ATTR_BVAHR(_show, _addr) \
165 IIO_DEVICE_ATTR(bvahr, S_IRUGO, _show, NULL, _addr)
166
167#define IIO_DEV_ATTR_CVAHR(_show, _addr) \
168 IIO_DEVICE_ATTR(cvahr, S_IRUGO, _show, NULL, _addr)
169
170#define IIO_DEV_ATTR_IOS(_mode, _show, _store, _addr) \
171 IIO_DEVICE_ATTR(ios, _mode, _show, _store, _addr)
172
173#define IIO_DEV_ATTR_VOS(_mode, _show, _store, _addr) \
174 IIO_DEVICE_ATTR(vos, _mode, _show, _store, _addr)
175
176#define IIO_DEV_ATTR_PHCAL(_mode, _show, _store, _addr) \
177 IIO_DEVICE_ATTR(phcal, _mode, _show, _store, _addr)
178
179#define IIO_DEV_ATTR_APHCAL(_mode, _show, _store, _addr) \
180 IIO_DEVICE_ATTR(aphcal, _mode, _show, _store, _addr)
181
182#define IIO_DEV_ATTR_BPHCAL(_mode, _show, _store, _addr) \
183 IIO_DEVICE_ATTR(bphcal, _mode, _show, _store, _addr)
184
185#define IIO_DEV_ATTR_CPHCAL(_mode, _show, _store, _addr) \
186 IIO_DEVICE_ATTR(cphcal, _mode, _show, _store, _addr)
187
188#define IIO_DEV_ATTR_APOS(_mode, _show, _store, _addr) \
189 IIO_DEVICE_ATTR(apos, _mode, _show, _store, _addr)
190
191#define IIO_DEV_ATTR_AAPOS(_mode, _show, _store, _addr) \
192 IIO_DEVICE_ATTR(aapos, _mode, _show, _store, _addr)
193
194#define IIO_DEV_ATTR_BAPOS(_mode, _show, _store, _addr) \
195 IIO_DEVICE_ATTR(bapos, _mode, _show, _store, _addr)
196
197#define IIO_DEV_ATTR_CAPOS(_mode, _show, _store, _addr) \
198 IIO_DEVICE_ATTR(capos, _mode, _show, _store, _addr)
199
200#define IIO_DEV_ATTR_AVRMSGAIN(_mode, _show, _store, _addr) \
201 IIO_DEVICE_ATTR(avrmsgain, _mode, _show, _store, _addr)
202
203#define IIO_DEV_ATTR_BVRMSGAIN(_mode, _show, _store, _addr) \
204 IIO_DEVICE_ATTR(bvrmsgain, _mode, _show, _store, _addr)
205
206#define IIO_DEV_ATTR_CVRMSGAIN(_mode, _show, _store, _addr) \
207 IIO_DEVICE_ATTR(cvrmsgain, _mode, _show, _store, _addr)
208
209#define IIO_DEV_ATTR_AIGAIN(_mode, _show, _store, _addr) \
210 IIO_DEVICE_ATTR(aigain, _mode, _show, _store, _addr)
211
212#define IIO_DEV_ATTR_BIGAIN(_mode, _show, _store, _addr) \
213 IIO_DEVICE_ATTR(bigain, _mode, _show, _store, _addr)
214
215#define IIO_DEV_ATTR_CIGAIN(_mode, _show, _store, _addr) \
216 IIO_DEVICE_ATTR(cigain, _mode, _show, _store, _addr)
217
218#define IIO_DEV_ATTR_NIGAIN(_mode, _show, _store, _addr) \
219 IIO_DEVICE_ATTR(nigain, _mode, _show, _store, _addr)
220
221#define IIO_DEV_ATTR_AVGAIN(_mode, _show, _store, _addr) \
222 IIO_DEVICE_ATTR(avgain, _mode, _show, _store, _addr)
223
224#define IIO_DEV_ATTR_BVGAIN(_mode, _show, _store, _addr) \
225 IIO_DEVICE_ATTR(bvgain, _mode, _show, _store, _addr)
226
227#define IIO_DEV_ATTR_CVGAIN(_mode, _show, _store, _addr) \
228 IIO_DEVICE_ATTR(cvgain, _mode, _show, _store, _addr)
229
230#define IIO_DEV_ATTR_WGAIN(_mode, _show, _store, _addr) \
231 IIO_DEVICE_ATTR(wgain, _mode, _show, _store, _addr)
232
233#define IIO_DEV_ATTR_WDIV(_mode, _show, _store, _addr) \
234 IIO_DEVICE_ATTR(wdiv, _mode, _show, _store, _addr)
235
236#define IIO_DEV_ATTR_CFNUM(_mode, _show, _store, _addr) \
237 IIO_DEVICE_ATTR(cfnum, _mode, _show, _store, _addr)
238
239#define IIO_DEV_ATTR_CFDEN(_mode, _show, _store, _addr) \
240 IIO_DEVICE_ATTR(cfden, _mode, _show, _store, _addr)
241
242#define IIO_DEV_ATTR_CF1DEN(_mode, _show, _store, _addr) \
243 IIO_DEVICE_ATTR(cf1den, _mode, _show, _store, _addr)
244
245#define IIO_DEV_ATTR_CF2DEN(_mode, _show, _store, _addr) \
246 IIO_DEVICE_ATTR(cf2den, _mode, _show, _store, _addr)
247
248#define IIO_DEV_ATTR_CF3DEN(_mode, _show, _store, _addr) \
249 IIO_DEVICE_ATTR(cf3den, _mode, _show, _store, _addr)
250
251#define IIO_DEV_ATTR_IRMS(_mode, _show, _store, _addr) \
252 IIO_DEVICE_ATTR(irms, _mode, _show, _store, _addr)
253
254#define IIO_DEV_ATTR_VRMS(_mode, _show, _store, _addr) \
255 IIO_DEVICE_ATTR(vrms, _mode, _show, _store, _addr)
256
257#define IIO_DEV_ATTR_AIRMS(_mode, _show, _store, _addr) \
258 IIO_DEVICE_ATTR(airms, _mode, _show, _store, _addr)
259
260#define IIO_DEV_ATTR_BIRMS(_mode, _show, _store, _addr) \
261 IIO_DEVICE_ATTR(birms, _mode, _show, _store, _addr)
262
263#define IIO_DEV_ATTR_CIRMS(_mode, _show, _store, _addr) \
264 IIO_DEVICE_ATTR(cirms, _mode, _show, _store, _addr)
265
266#define IIO_DEV_ATTR_NIRMS(_mode, _show, _store, _addr) \
267 IIO_DEVICE_ATTR(nirms, _mode, _show, _store, _addr)
268
269#define IIO_DEV_ATTR_AVRMS(_mode, _show, _store, _addr) \
270 IIO_DEVICE_ATTR(avrms, _mode, _show, _store, _addr)
271
272#define IIO_DEV_ATTR_BVRMS(_mode, _show, _store, _addr) \
273 IIO_DEVICE_ATTR(bvrms, _mode, _show, _store, _addr)
274
275#define IIO_DEV_ATTR_CVRMS(_mode, _show, _store, _addr) \
276 IIO_DEVICE_ATTR(cvrms, _mode, _show, _store, _addr)
277
278#define IIO_DEV_ATTR_IRMSOS(_mode, _show, _store, _addr) \
279 IIO_DEVICE_ATTR(irmsos, _mode, _show, _store, _addr)
280
281#define IIO_DEV_ATTR_VRMSOS(_mode, _show, _store, _addr) \
282 IIO_DEVICE_ATTR(vrmsos, _mode, _show, _store, _addr)
283
284#define IIO_DEV_ATTR_AIRMSOS(_mode, _show, _store, _addr) \
285 IIO_DEVICE_ATTR(airmsos, _mode, _show, _store, _addr)
286
287#define IIO_DEV_ATTR_BIRMSOS(_mode, _show, _store, _addr) \
288 IIO_DEVICE_ATTR(birmsos, _mode, _show, _store, _addr)
289
290#define IIO_DEV_ATTR_CIRMSOS(_mode, _show, _store, _addr) \
291 IIO_DEVICE_ATTR(cirmsos, _mode, _show, _store, _addr)
292
293#define IIO_DEV_ATTR_AVRMSOS(_mode, _show, _store, _addr) \
294 IIO_DEVICE_ATTR(avrmsos, _mode, _show, _store, _addr)
295
296#define IIO_DEV_ATTR_BVRMSOS(_mode, _show, _store, _addr) \
297 IIO_DEVICE_ATTR(bvrmsos, _mode, _show, _store, _addr)
298
299#define IIO_DEV_ATTR_CVRMSOS(_mode, _show, _store, _addr) \
300 IIO_DEVICE_ATTR(cvrmsos, _mode, _show, _store, _addr)
301
302#define IIO_DEV_ATTR_VAGAIN(_mode, _show, _store, _addr) \
303 IIO_DEVICE_ATTR(vagain, _mode, _show, _store, _addr)
304
305#define IIO_DEV_ATTR_PGA_GAIN(_mode, _show, _store, _addr) \
306 IIO_DEVICE_ATTR(pga_gain, _mode, _show, _store, _addr)
307
308#define IIO_DEV_ATTR_VADIV(_mode, _show, _store, _addr) \
309 IIO_DEVICE_ATTR(vadiv, _mode, _show, _store, _addr)
310
311#define IIO_DEV_ATTR_LINECYC(_mode, _show, _store, _addr) \
312 IIO_DEVICE_ATTR(linecyc, _mode, _show, _store, _addr)
313
314#define IIO_DEV_ATTR_SAGCYC(_mode, _show, _store, _addr) \
315 IIO_DEVICE_ATTR(sagcyc, _mode, _show, _store, _addr)
316
317#define IIO_DEV_ATTR_CFCYC(_mode, _show, _store, _addr) \
318 IIO_DEVICE_ATTR(cfcyc, _mode, _show, _store, _addr)
319
320#define IIO_DEV_ATTR_PEAKCYC(_mode, _show, _store, _addr) \
321 IIO_DEVICE_ATTR(peakcyc, _mode, _show, _store, _addr)
322
323#define IIO_DEV_ATTR_SAGLVL(_mode, _show, _store, _addr) \
324 IIO_DEVICE_ATTR(saglvl, _mode, _show, _store, _addr)
325
326#define IIO_DEV_ATTR_IPKLVL(_mode, _show, _store, _addr) \
327 IIO_DEVICE_ATTR(ipklvl, _mode, _show, _store, _addr)
328
329#define IIO_DEV_ATTR_VPKLVL(_mode, _show, _store, _addr) \
330 IIO_DEVICE_ATTR(vpklvl, _mode, _show, _store, _addr)
331
332#define IIO_DEV_ATTR_IPEAK(_mode, _show, _store, _addr) \
333 IIO_DEVICE_ATTR(ipeak, _mode, _show, _store, _addr)
334
335#define IIO_DEV_ATTR_RIPEAK(_mode, _show, _store, _addr) \
336 IIO_DEVICE_ATTR(ripeak, _mode, _show, _store, _addr)
337
338#define IIO_DEV_ATTR_VPEAK(_mode, _show, _store, _addr) \
339 IIO_DEVICE_ATTR(vpeak, _mode, _show, _store, _addr)
340
341#define IIO_DEV_ATTR_RVPEAK(_mode, _show, _store, _addr) \
342 IIO_DEVICE_ATTR(rvpeak, _mode, _show, _store, _addr)
343
344#define IIO_DEV_ATTR_VPERIOD(_mode, _show, _store, _addr) \
345 IIO_DEVICE_ATTR(vperiod, _mode, _show, _store, _addr)
346
347#define IIO_DEV_ATTR_CH_OFF(_num, _mode, _show, _store, _addr) \
348 IIO_DEVICE_ATTR(choff_##_num, _mode, _show, _store, _addr)
349
350/* active energy register, AENERGY, is more than half full */
351#define IIO_EVENT_ATTR_AENERGY_HALF_FULL(_evlist, _show, _store, _mask) \
352 IIO_EVENT_ATTR_SH(aenergy_half_full, _evlist, _show, _store, _mask)
353
354/* a SAG on the line voltage */
355#define IIO_EVENT_ATTR_LINE_VOLT_SAG(_evlist, _show, _store, _mask) \
356 IIO_EVENT_ATTR_SH(line_volt_sag, _evlist, _show, _store, _mask)
357
358/*
359 * Indicates the end of energy accumulation over an integer number
360 * of half line cycles
361 */
362#define IIO_EVENT_ATTR_CYCEND(_evlist, _show, _store, _mask) \
363 IIO_EVENT_ATTR_SH(cycend, _evlist, _show, _store, _mask)
364
365/* on the rising and falling edge of the the voltage waveform */
366#define IIO_EVENT_ATTR_ZERO_CROSS(_evlist, _show, _store, _mask) \
367 IIO_EVENT_ATTR_SH(zero_cross, _evlist, _show, _store, _mask)
368
369/* the active energy register has overflowed */
370#define IIO_EVENT_ATTR_AENERGY_OVERFLOW(_evlist, _show, _store, _mask) \
371 IIO_EVENT_ATTR_SH(aenergy_overflow, _evlist, _show, _store, _mask)
372
373/* the apparent energy register has overflowed */
374#define IIO_EVENT_ATTR_VAENERGY_OVERFLOW(_evlist, _show, _store, _mask) \
375 IIO_EVENT_ATTR_SH(vaenergy_overflow, _evlist, _show, _store, _mask)
376
377/* the active energy register, VAENERGY, is more than half full */
378#define IIO_EVENT_ATTR_VAENERGY_HALF_FULL(_evlist, _show, _store, _mask) \
379 IIO_EVENT_ATTR_SH(vaenergy_half_full, _evlist, _show, _store, _mask)
380
381/* the power has gone from negative to positive */
382#define IIO_EVENT_ATTR_PPOS(_evlist, _show, _store, _mask) \
383 IIO_EVENT_ATTR_SH(ppos, _evlist, _show, _store, _mask)
384
385/* the power has gone from positive to negative */
386#define IIO_EVENT_ATTR_PNEG(_evlist, _show, _store, _mask) \
387 IIO_EVENT_ATTR_SH(pneg, _evlist, _show, _store, _mask)
388
389/* waveform sample from Channel 1 has exceeded the IPKLVL value */
390#define IIO_EVENT_ATTR_IPKLVL_EXC(_evlist, _show, _store, _mask) \
391 IIO_EVENT_ATTR_SH(ipklvl_exc, _evlist, _show, _store, _mask)
392
393/* waveform sample from Channel 2 has exceeded the VPKLVL value */
394#define IIO_EVENT_ATTR_VPKLVL_EXC(_evlist, _show, _store, _mask) \
395 IIO_EVENT_ATTR_SH(vpklvl_exc, _evlist, _show, _store, _mask)
396
diff --git a/drivers/staging/iio/resolver/Kconfig b/drivers/staging/iio/resolver/Kconfig
new file mode 100644
index 000000000000..a4a363429355
--- /dev/null
+++ b/drivers/staging/iio/resolver/Kconfig
@@ -0,0 +1,54 @@
1#
2# Resolver/Synchro drivers
3#
4comment "Resolver to digital converters"
5
6config AD2S90
7 tristate "Analog Devices ad2s90 driver"
8 depends on SPI
9 help
10 Say yes here to build support for Analog Devices spi resolver
11 to digital converters, ad2s90, provides direct access via sysfs.
12
13config AD2S120X
14 tristate "Analog Devices ad2s120x driver"
15 depends on SPI
16 help
17 Say yes here to build support for Analog Devices spi resolver
18 to digital converters, ad2s1200 and ad2s1205, provides direct access
19 via sysfs.
20
21config AD2S1210
22 tristate "Analog Devices ad2s1210 driver"
23 depends on SPI
24 help
25 Say yes here to build support for Analog Devices spi resolver
26 to digital converters, ad2s1210, provides direct access via sysfs.
27
28choice
29 prompt "Resolution Control"
30 depends on AD2S1210
31 default AD2S1210_GPIO_NONE
32 help
33 In normal mode, the resolution of the digital output is selected
34 using the RES0 and RES1 input pins. In configuration mode, the
35 resolution is selected by setting the RES0 and RES1 bits in the
36 control regsiter. When switching between normal mode and configuration
37 mode, there are some schemes to keep them matchs.
38
39config AD2S1210_GPIO_INPUT
40 bool "read resolution from gpio pins"
41 help
42 GPIO pins are sampling RES0 and RES1 pins, read the resolution
43 settings from the GPIO pins.
44
45config AD2S1210_GPIO_OUTPUT
46 bool "set gpio pins to set resolution"
47 help
48 RES0 and RES1 pins are controlled by GPIOs, setting GPIO pins to
49 set the resolution.
50
51config AD2S1210_GPIO_NONE
52 bool "take the responsibility by user"
53
54endchoice
diff --git a/drivers/staging/iio/resolver/Makefile b/drivers/staging/iio/resolver/Makefile
new file mode 100644
index 000000000000..0b84a89e6cac
--- /dev/null
+++ b/drivers/staging/iio/resolver/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for Resolver/Synchro drivers
3#
4
5obj-$(CONFIG_AD2S90) += ad2s90.o
6obj-$(CONFIG_AD2S120X) += ad2s120x.o
7obj-$(CONFIG_AD2S1210) += ad2s1210.o
diff --git a/drivers/staging/iio/resolver/ad2s120x.c b/drivers/staging/iio/resolver/ad2s120x.c
new file mode 100644
index 000000000000..8f497a23976c
--- /dev/null
+++ b/drivers/staging/iio/resolver/ad2s120x.c
@@ -0,0 +1,310 @@
1/*
2 * ad2s120x.c simple support for the ADI Resolver to Digital Converters: AD2S1200/1205
3 *
4 * Copyright (c) 2010-2010 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/types.h>
12#include <linux/mutex.h>
13#include <linux/device.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17#include <linux/delay.h>
18#include <linux/gpio.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23#define DRV_NAME "ad2s120x"
24
25/* input pin sample and rdvel is controlled by driver */
26#define AD2S120X_PN 2
27
28/* input clock on serial interface */
29#define AD2S120X_HZ 8192000
30/* clock period in nano second */
31#define AD2S120X_TSCLK (1000000000/AD2S120X_HZ)
32
33struct ad2s120x_state {
34 struct mutex lock;
35 struct iio_dev *idev;
36 struct spi_device *sdev;
37 unsigned short sample;
38 unsigned short rdvel;
39 u8 rx[2];
40 u8 tx[2];
41};
42
43static ssize_t ad2s120x_show_pos_vel(struct device *dev,
44 struct device_attribute *attr, char *buf)
45{
46 struct spi_message msg;
47 struct spi_transfer xfer;
48 int ret = 0;
49 ssize_t len = 0;
50 u16 pos;
51 s16 vel;
52 u8 status;
53 struct iio_dev *idev = dev_get_drvdata(dev);
54 struct ad2s120x_state *st = idev->dev_data;
55
56 xfer.len = 1;
57 xfer.tx_buf = st->tx;
58 xfer.rx_buf = st->rx;
59 mutex_lock(&st->lock);
60
61 gpio_set_value(st->sample, 0);
62 /* delay (6 * AD2S120X_TSCLK + 20) nano seconds */
63 udelay(1);
64 gpio_set_value(st->sample, 1);
65
66 spi_message_init(&msg);
67 spi_message_add_tail(&xfer, &msg);
68 ret = spi_sync(st->sdev, &msg);
69 if (ret)
70 goto error_ret;
71 status = st->rx[1];
72 pos = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
73 len = sprintf(buf, "%d %c%c%c%c ", pos,
74 (status & 0x8) ? 'P' : 'V',
75 (status & 0x4) ? 'd' : '_',
76 (status & 0x2) ? 'l' : '_',
77 (status & 0x1) ? '1' : '0');
78
79 /* delay 18 ns */
80 /* ndelay(18); */
81
82 gpio_set_value(st->rdvel, 0);
83 /* ndelay(5);*/
84
85 spi_message_init(&msg);
86 spi_message_add_tail(&xfer, &msg);
87 ret = spi_sync(st->sdev, &msg);
88 if (ret)
89 goto error_ret;
90 status = st->rx[1];
91 vel = (st->rx[0] & 0x80) ? 0xf000 : 0;
92 vel |= (((s16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
93 len += sprintf(buf + len, "%d %c%c%c%c\n", vel,
94 (status & 0x8) ? 'P' : 'V',
95 (status & 0x4) ? 'd' : '_',
96 (status & 0x2) ? 'l' : '_',
97 (status & 0x1) ? '1' : '0');
98error_ret:
99 gpio_set_value(st->rdvel, 1);
100 /* delay (2 * AD2S120X_TSCLK + 20) ns for sample pulse */
101 udelay(1);
102 mutex_unlock(&st->lock);
103
104 return ret ? ret : len;
105}
106
107static ssize_t ad2s120x_show_pos(struct device *dev,
108 struct device_attribute *attr, char *buf)
109{
110 struct spi_message msg;
111 struct spi_transfer xfer;
112 int ret = 0;
113 ssize_t len = 0;
114 u16 pos;
115 u8 status;
116 struct iio_dev *idev = dev_get_drvdata(dev);
117 struct ad2s120x_state *st = idev->dev_data;
118
119 xfer.len = 1;
120 xfer.tx_buf = st->tx;
121 xfer.rx_buf = st->rx;
122 mutex_lock(&st->lock);
123
124 gpio_set_value(st->sample, 0);
125 /* delay (6 * AD2S120X_TSCLK + 20) nano seconds */
126 udelay(1);
127 gpio_set_value(st->sample, 1);
128 gpio_set_value(st->rdvel, 1);
129
130 spi_message_init(&msg);
131 spi_message_add_tail(&xfer, &msg);
132 ret = spi_sync(st->sdev, &msg);
133 if (ret)
134 goto error_ret;
135 status = st->rx[1];
136 pos = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
137 len = sprintf(buf, "%d %c%c%c%c ", pos,
138 (status & 0x8) ? 'P' : 'V',
139 (status & 0x4) ? 'd' : '_',
140 (status & 0x2) ? 'l' : '_',
141 (status & 0x1) ? '1' : '0');
142error_ret:
143 /* delay (2 * AD2S120X_TSCLK + 20) ns for sample pulse */
144 udelay(1);
145 mutex_unlock(&st->lock);
146
147 return ret ? ret : len;
148}
149
150static ssize_t ad2s120x_show_vel(struct device *dev,
151 struct device_attribute *attr, char *buf)
152{
153 struct spi_message msg;
154 struct spi_transfer xfer;
155 int ret = 0;
156 ssize_t len = 0;
157 s16 vel;
158 u8 status;
159 struct iio_dev *idev = dev_get_drvdata(dev);
160 struct ad2s120x_state *st = idev->dev_data;
161
162 xfer.len = 1;
163 xfer.tx_buf = st->tx;
164 xfer.rx_buf = st->rx;
165 mutex_lock(&st->lock);
166
167 gpio_set_value(st->sample, 0);
168 /* delay (6 * AD2S120X_TSCLK + 20) nano seconds */
169 udelay(1);
170 gpio_set_value(st->sample, 1);
171
172 gpio_set_value(st->rdvel, 0);
173 /* ndelay(5);*/
174
175 spi_message_init(&msg);
176 spi_message_add_tail(&xfer, &msg);
177 ret = spi_sync(st->sdev, &msg);
178 if (ret)
179 goto error_ret;
180 status = st->rx[1];
181 vel = (st->rx[0] & 0x80) ? 0xf000 : 0;
182 vel |= (((s16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
183 len += sprintf(buf + len, "%d %c%c%c%c\n", vel,
184 (status & 0x8) ? 'P' : 'V',
185 (status & 0x4) ? 'd' : '_',
186 (status & 0x2) ? 'l' : '_',
187 (status & 0x1) ? '1' : '0');
188error_ret:
189 gpio_set_value(st->rdvel, 1);
190 /* delay (2 * AD2S120X_TSCLK + 20) ns for sample pulse */
191 udelay(1);
192 mutex_unlock(&st->lock);
193
194 return ret ? ret : len;
195}
196
197static IIO_CONST_ATTR(description,
198 "12-Bit R/D Converter with Reference Oscillator");
199static IIO_DEVICE_ATTR(pos_vel, S_IRUGO, ad2s120x_show_pos_vel, NULL, 0);
200static IIO_DEVICE_ATTR(pos, S_IRUGO, ad2s120x_show_pos, NULL, 0);
201static IIO_DEVICE_ATTR(vel, S_IRUGO, ad2s120x_show_vel, NULL, 0);
202
203static struct attribute *ad2s120x_attributes[] = {
204 &iio_const_attr_description.dev_attr.attr,
205 &iio_dev_attr_pos_vel.dev_attr.attr,
206 &iio_dev_attr_pos.dev_attr.attr,
207 &iio_dev_attr_vel.dev_attr.attr,
208 NULL,
209};
210
211static const struct attribute_group ad2s120x_attribute_group = {
212 .name = DRV_NAME,
213 .attrs = ad2s120x_attributes,
214};
215
216static int __devinit ad2s120x_probe(struct spi_device *spi)
217{
218 struct ad2s120x_state *st;
219 int pn, ret = 0;
220 unsigned short *pins = spi->dev.platform_data;
221
222 for (pn = 0; pn < AD2S120X_PN; pn++) {
223 if (gpio_request(pins[pn], DRV_NAME)) {
224 pr_err("%s: request gpio pin %d failed\n",
225 DRV_NAME, pins[pn]);
226 goto error_ret;
227 }
228 gpio_direction_output(pins[pn], 1);
229 }
230
231 st = kzalloc(sizeof(*st), GFP_KERNEL);
232 if (st == NULL) {
233 ret = -ENOMEM;
234 goto error_ret;
235 }
236 spi_set_drvdata(spi, st);
237
238 mutex_init(&st->lock);
239 st->sdev = spi;
240 st->sample = pins[0];
241 st->rdvel = pins[1];
242
243 st->idev = iio_allocate_device();
244 if (st->idev == NULL) {
245 ret = -ENOMEM;
246 goto error_free_st;
247 }
248 st->idev->dev.parent = &spi->dev;
249 st->idev->num_interrupt_lines = 0;
250 st->idev->event_attrs = NULL;
251
252 st->idev->attrs = &ad2s120x_attribute_group;
253 st->idev->dev_data = (void *)(st);
254 st->idev->driver_module = THIS_MODULE;
255 st->idev->modes = INDIO_DIRECT_MODE;
256
257 ret = iio_device_register(st->idev);
258 if (ret)
259 goto error_free_dev;
260
261 spi->max_speed_hz = AD2S120X_HZ;
262 spi->mode = SPI_MODE_3;
263 spi_setup(spi);
264
265 return 0;
266
267error_free_dev:
268 iio_free_device(st->idev);
269error_free_st:
270 kfree(st);
271error_ret:
272 for (--pn; pn >= 0; pn--)
273 gpio_free(pins[pn]);
274 return ret;
275}
276
277static int __devexit ad2s120x_remove(struct spi_device *spi)
278{
279 struct ad2s120x_state *st = spi_get_drvdata(spi);
280
281 iio_device_unregister(st->idev);
282 kfree(st);
283
284 return 0;
285}
286
287static struct spi_driver ad2s120x_driver = {
288 .driver = {
289 .name = DRV_NAME,
290 .owner = THIS_MODULE,
291 },
292 .probe = ad2s120x_probe,
293 .remove = __devexit_p(ad2s120x_remove),
294};
295
296static __init int ad2s120x_spi_init(void)
297{
298 return spi_register_driver(&ad2s120x_driver);
299}
300module_init(ad2s120x_spi_init);
301
302static __exit void ad2s120x_spi_exit(void)
303{
304 spi_unregister_driver(&ad2s120x_driver);
305}
306module_exit(ad2s120x_spi_exit);
307
308MODULE_AUTHOR("Graff Yang <graff.yang@gmail.com>");
309MODULE_DESCRIPTION("Analog Devices AD2S1200/1205 Resolver to Digital SPI driver");
310MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
new file mode 100644
index 000000000000..c12f64cc40df
--- /dev/null
+++ b/drivers/staging/iio/resolver/ad2s1210.c
@@ -0,0 +1,872 @@
1/*
2 * ad2s1210.c support for the ADI Resolver to Digital Converters: AD2S1210
3 *
4 * Copyright (c) 2010-2010 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/types.h>
12#include <linux/mutex.h>
13#include <linux/device.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17#include <linux/delay.h>
18#include <linux/gpio.h>
19
20#include "../iio.h"
21#include "../sysfs.h"
22
23#define DRV_NAME "ad2s1210"
24
25#define DEF_CONTROL 0x7E
26
27#define MSB_IS_HIGH 0x80
28#define MSB_IS_LOW 0x7F
29#define PHASE_LOCK_RANGE_44 0x20
30#define ENABLE_HYSTERESIS 0x10
31#define SET_ENRES1 0x08
32#define SET_ENRES0 0x04
33#define SET_RES1 0x02
34#define SET_RES0 0x01
35
36#define SET_ENRESOLUTION (SET_ENRES1 | SET_ENRES0)
37#define SET_RESOLUTION (SET_RES1 | SET_RES0)
38
39#define REG_POSITION 0x80
40#define REG_VELOCITY 0x82
41#define REG_LOS_THRD 0x88
42#define REG_DOS_OVR_THRD 0x89
43#define REG_DOS_MIS_THRD 0x8A
44#define REG_DOS_RST_MAX_THRD 0x8B
45#define REG_DOS_RST_MIN_THRD 0x8C
46#define REG_LOT_HIGH_THRD 0x8D
47#define REG_LOT_LOW_THRD 0x8E
48#define REG_EXCIT_FREQ 0x91
49#define REG_CONTROL 0x92
50#define REG_SOFT_RESET 0xF0
51#define REG_FAULT 0xFF
52
53/* pin SAMPLE, A0, A1, RES0, RES1, is controlled by driver */
54#define AD2S1210_SAA 3
55#if defined(CONFIG_AD2S1210_GPIO_INPUT) || defined(CONFIG_AD2S1210_GPIO_OUTPUT)
56# define AD2S1210_RES 2
57#else
58# define AD2S1210_RES 0
59#endif
60#define AD2S1210_PN (AD2S1210_SAA + AD2S1210_RES)
61
62#define AD2S1210_MIN_CLKIN 6144000
63#define AD2S1210_MAX_CLKIN 10240000
64#define AD2S1210_MIN_EXCIT 2000
65#define AD2S1210_MAX_EXCIT 20000
66#define AD2S1210_MIN_FCW 0x4
67#define AD2S1210_MAX_FCW 0x50
68
69/* default input clock on serial interface */
70#define AD2S1210_DEF_CLKIN 8192000
71/* clock period in nano second */
72#define AD2S1210_DEF_TCK (1000000000/AD2S1210_DEF_CLKIN)
73#define AD2S1210_DEF_EXCIT 10000
74
75enum ad2s1210_mode {
76 MOD_POS = 0,
77 MOD_VEL,
78 MOD_RESERVED,
79 MOD_CONFIG,
80};
81
82enum ad2s1210_res {
83 RES_10 = 10,
84 RES_12 = 12,
85 RES_14 = 14,
86 RES_16 = 16,
87};
88
89static unsigned int resolution_value[] = {
90 RES_10, RES_12, RES_14, RES_16};
91
92struct ad2s1210_state {
93 struct mutex lock;
94 struct iio_dev *idev;
95 struct spi_device *sdev;
96 struct spi_transfer xfer;
97 unsigned int hysteresis;
98 unsigned int old_data;
99 enum ad2s1210_mode mode;
100 enum ad2s1210_res resolution;
101 unsigned int fclkin;
102 unsigned int fexcit;
103 unsigned short sample;
104 unsigned short a0;
105 unsigned short a1;
106 unsigned short res0;
107 unsigned short res1;
108 u8 rx[3];
109 u8 tx[3];
110};
111
112static inline void start_sample(struct ad2s1210_state *st)
113{
114 gpio_set_value(st->sample, 0);
115}
116
117static inline void stop_sample(struct ad2s1210_state *st)
118{
119 gpio_set_value(st->sample, 1);
120}
121
122static inline void set_mode(enum ad2s1210_mode mode, struct ad2s1210_state *st)
123{
124 switch (mode) {
125 case MOD_POS:
126 gpio_set_value(st->a0, 0);
127 gpio_set_value(st->a1, 0);
128 break;
129 case MOD_VEL:
130 gpio_set_value(st->a0, 0);
131 gpio_set_value(st->a1, 1);
132 break;
133 case MOD_CONFIG:
134 gpio_set_value(st->a0, 1);
135 gpio_set_value(st->a1, 1);
136 break;
137 default:
138 /* set to reserved mode */
139 gpio_set_value(st->a0, 1);
140 gpio_set_value(st->a1, 0);
141 }
142 st->mode = mode;
143}
144
145/* write 1 bytes (address or data) to the chip */
146static int config_write(struct ad2s1210_state *st,
147 unsigned char data)
148{
149 struct spi_message msg;
150 int ret = 0;
151
152 st->xfer.len = 1;
153 set_mode(MOD_CONFIG, st);
154
155 spi_message_init(&msg);
156 spi_message_add_tail(&st->xfer, &msg);
157 st->tx[0] = data;
158 ret = spi_sync(st->sdev, &msg);
159 if (ret)
160 return ret;
161 st->old_data = 1;
162 return ret;
163}
164
165/* read value from one of the registers */
166static int config_read(struct ad2s1210_state *st,
167 unsigned char address,
168 unsigned char *data)
169{
170 struct spi_message msg;
171 int ret = 0;
172
173 st->xfer.len = 2;
174 set_mode(MOD_CONFIG, st);
175
176 spi_message_init(&msg);
177 spi_message_add_tail(&st->xfer, &msg);
178 st->tx[0] = address | MSB_IS_HIGH;
179 st->tx[1] = REG_FAULT;
180 ret = spi_sync(st->sdev, &msg);
181 if (ret)
182 return ret;
183 *data = st->rx[1];
184 st->old_data = 1;
185 return ret;
186}
187
188static inline void update_frequency_control_word(struct ad2s1210_state *st)
189{
190 unsigned char fcw;
191 fcw = (unsigned char)(st->fexcit * (1 << 15) / st->fclkin);
192 if (fcw >= AD2S1210_MIN_FCW && fcw <= AD2S1210_MAX_FCW) {
193 config_write(st, REG_EXCIT_FREQ);
194 config_write(st, fcw);
195 } else
196 pr_err("ad2s1210: FCW out of range\n");
197}
198
199#if defined(CONFIG_AD2S1210_GPIO_INPUT)
200static inline unsigned char read_resolution_pin(struct ad2s1210_state *st)
201{
202 unsigned int data;
203 data = (gpio_get_value(st->res0) << 1) |
204 gpio_get_value(st->res1);
205 return resolution_value[data];
206}
207#elif defined(CONFIG_AD2S1210_GPIO_OUTPUT)
208static inline void set_resolution_pin(struct ad2s1210_state *st)
209{
210 switch (st->resolution) {
211 case RES_10:
212 gpio_set_value(st->res0, 0);
213 gpio_set_value(st->res1, 0);
214 break;
215 case RES_12:
216 gpio_set_value(st->res0, 0);
217 gpio_set_value(st->res1, 1);
218 break;
219 case RES_14:
220 gpio_set_value(st->res0, 1);
221 gpio_set_value(st->res1, 0);
222 break;
223 case RES_16:
224 gpio_set_value(st->res0, 1);
225 gpio_set_value(st->res1, 1);
226 break;
227 }
228}
229#endif
230
231static inline void soft_reset(struct ad2s1210_state *st)
232{
233 config_write(st, REG_SOFT_RESET);
234 config_write(st, 0x0);
235}
236
237
238/* return the OLD DATA since last spi bus write */
239static ssize_t ad2s1210_show_raw(struct device *dev,
240 struct device_attribute *attr, char *buf)
241{
242 struct iio_dev *idev = dev_get_drvdata(dev);
243 struct ad2s1210_state *st = idev->dev_data;
244 int ret;
245
246 mutex_lock(&st->lock);
247 if (st->old_data) {
248 ret = sprintf(buf, "0x%x\n", st->rx[0]);
249 st->old_data = 0;
250 } else
251 ret = 0;
252 mutex_unlock(&st->lock);
253 return ret;
254}
255
256static ssize_t ad2s1210_store_raw(struct device *dev,
257 struct device_attribute *attr,
258 const char *buf, size_t len)
259{
260 struct iio_dev *idev = dev_get_drvdata(dev);
261 struct ad2s1210_state *st = idev->dev_data;
262 unsigned long udata;
263 unsigned char data;
264 int ret;
265
266 ret = strict_strtoul(buf, 16, &udata);
267 if (ret)
268 return -EINVAL;
269 data = udata & 0xff;
270 mutex_lock(&st->lock);
271 config_write(st, data);
272 mutex_unlock(&st->lock);
273 return 1;
274}
275
276static ssize_t ad2s1210_store_softreset(struct device *dev,
277 struct device_attribute *attr,
278 const char *buf, size_t len)
279{
280 struct iio_dev *idev = dev_get_drvdata(dev);
281 struct ad2s1210_state *st = idev->dev_data;
282 mutex_lock(&st->lock);
283 soft_reset(st);
284 mutex_unlock(&st->lock);
285 return len;
286}
287
288static ssize_t ad2s1210_show_fclkin(struct device *dev,
289 struct device_attribute *attr, char *buf)
290{
291 struct iio_dev *idev = dev_get_drvdata(dev);
292 struct ad2s1210_state *st = idev->dev_data;
293 return sprintf(buf, "%d\n", st->fclkin);
294}
295
296static ssize_t ad2s1210_store_fclkin(struct device *dev,
297 struct device_attribute *attr,
298 const char *buf, size_t len)
299{
300 struct iio_dev *idev = dev_get_drvdata(dev);
301 struct ad2s1210_state *st = idev->dev_data;
302 unsigned long fclkin;
303 int ret;
304
305 ret = strict_strtoul(buf, 10, &fclkin);
306 if (!ret && fclkin >= AD2S1210_MIN_CLKIN &&
307 fclkin <= AD2S1210_MAX_CLKIN) {
308 mutex_lock(&st->lock);
309 st->fclkin = fclkin;
310 } else {
311 pr_err("ad2s1210: fclkin out of range\n");
312 return -EINVAL;
313 }
314 update_frequency_control_word(st);
315 soft_reset(st);
316 mutex_unlock(&st->lock);
317 return len;
318}
319
320static ssize_t ad2s1210_show_fexcit(struct device *dev,
321 struct device_attribute *attr, char *buf)
322{
323 struct iio_dev *idev = dev_get_drvdata(dev);
324 struct ad2s1210_state *st = idev->dev_data;
325 return sprintf(buf, "%d\n", st->fexcit);
326}
327
328static ssize_t ad2s1210_store_fexcit(struct device *dev,
329 struct device_attribute *attr,
330 const char *buf, size_t len)
331{
332 struct iio_dev *idev = dev_get_drvdata(dev);
333 struct ad2s1210_state *st = idev->dev_data;
334 unsigned long fexcit;
335 int ret;
336
337 ret = strict_strtoul(buf, 10, &fexcit);
338 if (!ret && fexcit >= AD2S1210_MIN_EXCIT &&
339 fexcit <= AD2S1210_MAX_EXCIT) {
340 mutex_lock(&st->lock);
341 st->fexcit = fexcit;
342 } else {
343 pr_err("ad2s1210: excitation frequency out of range\n");
344 return -EINVAL;
345 }
346 update_frequency_control_word(st);
347 soft_reset(st);
348 mutex_unlock(&st->lock);
349 return len;
350}
351
352static ssize_t ad2s1210_show_control(struct device *dev,
353 struct device_attribute *attr, char *buf)
354{
355 struct iio_dev *idev = dev_get_drvdata(dev);
356 struct ad2s1210_state *st = idev->dev_data;
357 unsigned char data;
358 mutex_lock(&st->lock);
359 config_read(st, REG_CONTROL, &data);
360 mutex_unlock(&st->lock);
361 return sprintf(buf, "0x%x\n", data);
362}
363
364static ssize_t ad2s1210_store_control(struct device *dev,
365 struct device_attribute *attr,
366 const char *buf, size_t len)
367{
368 struct iio_dev *idev = dev_get_drvdata(dev);
369 struct ad2s1210_state *st = idev->dev_data;
370 unsigned long udata;
371 unsigned char data;
372 int ret;
373
374 ret = strict_strtoul(buf, 16, &udata);
375 if (ret) {
376 ret = -EINVAL;
377 goto error_ret;
378 }
379 mutex_lock(&st->lock);
380 config_write(st, REG_CONTROL);
381 data = udata & MSB_IS_LOW;
382 config_write(st, data);
383 config_read(st, REG_CONTROL, &data);
384 if (data & MSB_IS_HIGH) {
385 ret = -EIO;
386 pr_err("ad2s1210: write control register fail\n");
387 goto error_ret;
388 }
389 st->resolution = resolution_value[data & SET_RESOLUTION];
390#if defined(CONFIG_AD2S1210_GPIO_INPUT)
391 data = read_resolution_pin(st);
392 if (data != st->resolution)
393 pr_warning("ad2s1210: resolution settings not match\n");
394#elif defined(CONFIG_AD2S1210_GPIO_OUTPUT)
395 set_resolution_pin(st);
396#endif
397 ret = len;
398 if (data & ENABLE_HYSTERESIS)
399 st->hysteresis = 1;
400 else
401 st->hysteresis = 0;
402error_ret:
403 mutex_unlock(&st->lock);
404 return ret;
405}
406
407static ssize_t ad2s1210_show_resolution(struct device *dev,
408 struct device_attribute *attr, char *buf)
409{
410 struct iio_dev *idev = dev_get_drvdata(dev);
411 struct ad2s1210_state *st = idev->dev_data;
412 return sprintf(buf, "%d\n", st->resolution);
413}
414
415static ssize_t ad2s1210_store_resolution(struct device *dev,
416 struct device_attribute *attr,
417 const char *buf, size_t len)
418{
419 struct iio_dev *idev = dev_get_drvdata(dev);
420 struct ad2s1210_state *st = idev->dev_data;
421 unsigned char data;
422 unsigned long udata;
423 int ret;
424
425 ret = strict_strtoul(buf, 10, &udata);
426 if (ret || udata < RES_10 || udata > RES_16) {
427 pr_err("ad2s1210: resolution out of range\n");
428 return -EINVAL;
429 }
430 mutex_lock(&st->lock);
431 config_read(st, REG_CONTROL, &data);
432 data &= ~SET_RESOLUTION;
433 data |= (udata - RES_10) >> 1;
434 config_write(st, REG_CONTROL);
435 config_write(st, data & MSB_IS_LOW);
436 config_read(st, REG_CONTROL, &data);
437 if (data & MSB_IS_HIGH) {
438 ret = -EIO;
439 pr_err("ad2s1210: setting resolution fail\n");
440 goto error_ret;
441 }
442 st->resolution = resolution_value[data & SET_RESOLUTION];
443#if defined(CONFIG_AD2S1210_GPIO_INPUT)
444 data = read_resolution_pin(st);
445 if (data != st->resolution)
446 pr_warning("ad2s1210: resolution settings not match\n");
447#elif defined(CONFIG_AD2S1210_GPIO_OUTPUT)
448 set_resolution_pin(st);
449#endif
450 ret = len;
451error_ret:
452 mutex_unlock(&st->lock);
453 return ret;
454}
455/* read the fault register since last sample */
456static ssize_t ad2s1210_show_fault(struct device *dev,
457 struct device_attribute *attr, char *buf)
458{
459 int ret = 0;
460 ssize_t len = 0;
461 unsigned char data;
462 struct iio_dev *idev = dev_get_drvdata(dev);
463 struct ad2s1210_state *st = idev->dev_data;
464
465 mutex_lock(&st->lock);
466 ret = config_read(st, REG_FAULT, &data);
467
468 if (ret)
469 goto error_ret;
470 len = sprintf(buf, "0x%x\n", data);
471error_ret:
472 mutex_unlock(&st->lock);
473 return ret ? ret : len;
474}
475
476static ssize_t ad2s1210_clear_fault(struct device *dev,
477 struct device_attribute *attr,
478 const char *buf, size_t len)
479{
480 struct iio_dev *idev = dev_get_drvdata(dev);
481 struct ad2s1210_state *st = idev->dev_data;
482 unsigned char data;
483
484 mutex_lock(&st->lock);
485 start_sample(st);
486 /* delay (2 * tck + 20) nano seconds */
487 udelay(1);
488 stop_sample(st);
489 config_read(st, REG_FAULT, &data);
490 start_sample(st);
491 stop_sample(st);
492 mutex_unlock(&st->lock);
493
494 return 0;
495}
496
497static ssize_t ad2s1210_show_reg(struct device *dev,
498 struct device_attribute *attr, char *buf)
499{
500 struct iio_dev *idev = dev_get_drvdata(dev);
501 struct ad2s1210_state *st = idev->dev_data;
502 unsigned char data;
503 struct iio_dev_attr *iattr = to_iio_dev_attr(attr);
504
505 mutex_lock(&st->lock);
506 config_read(st, iattr->address, &data);
507 mutex_unlock(&st->lock);
508 return sprintf(buf, "%d\n", data);
509}
510
511static ssize_t ad2s1210_store_reg(struct device *dev,
512 struct device_attribute *attr, const char *buf, size_t len)
513{
514 struct iio_dev *idev = dev_get_drvdata(dev);
515 struct ad2s1210_state *st = idev->dev_data;
516 unsigned long data;
517 int ret;
518 struct iio_dev_attr *iattr = to_iio_dev_attr(attr);
519
520 ret = strict_strtoul(buf, 10, &data);
521 if (ret)
522 return -EINVAL;
523 mutex_lock(&st->lock);
524 config_write(st, iattr->address);
525 config_write(st, data & MSB_IS_LOW);
526 mutex_unlock(&st->lock);
527 return len;
528}
529
530static ssize_t ad2s1210_show_pos(struct device *dev,
531 struct device_attribute *attr, char *buf)
532{
533 struct spi_message msg;
534 int ret = 0;
535 ssize_t len = 0;
536 u16 pos;
537 struct iio_dev *idev = dev_get_drvdata(dev);
538 struct ad2s1210_state *st = idev->dev_data;
539
540 st->xfer.len = 2;
541 mutex_lock(&st->lock);
542 start_sample(st);
543 /* delay (6 * tck + 20) nano seconds */
544 udelay(1);
545
546 set_mode(MOD_POS, st);
547
548 spi_message_init(&msg);
549 spi_message_add_tail(&st->xfer, &msg);
550 ret = spi_sync(st->sdev, &msg);
551 if (ret)
552 goto error_ret;
553 pos = ((((u16)(st->rx[0])) << 8) | (st->rx[1]));
554 if (st->hysteresis)
555 pos >>= 16 - st->resolution;
556 len = sprintf(buf, "%d\n", pos);
557error_ret:
558 stop_sample(st);
559 /* delay (2 * tck + 20) nano seconds */
560 udelay(1);
561 mutex_unlock(&st->lock);
562
563 return ret ? ret : len;
564}
565
566static ssize_t ad2s1210_show_vel(struct device *dev,
567 struct device_attribute *attr, char *buf)
568{
569 struct spi_message msg;
570 unsigned short negative;
571 int ret = 0;
572 ssize_t len = 0;
573 s16 vel;
574 struct iio_dev *idev = dev_get_drvdata(dev);
575 struct ad2s1210_state *st = idev->dev_data;
576
577 st->xfer.len = 2;
578 mutex_lock(&st->lock);
579 start_sample(st);
580 /* delay (6 * tck + 20) nano seconds */
581 udelay(1);
582
583 set_mode(MOD_VEL, st);
584
585 spi_message_init(&msg);
586 spi_message_add_tail(&st->xfer, &msg);
587 ret = spi_sync(st->sdev, &msg);
588 if (ret)
589 goto error_ret;
590 negative = st->rx[0] & 0x80;
591 vel = ((((s16)(st->rx[0])) << 8) | (st->rx[1]));
592 vel >>= 16 - st->resolution;
593 if (negative) {
594 negative = (0xffff >> st->resolution) << st->resolution;
595 vel |= negative;
596 }
597 len = sprintf(buf, "%d\n", vel);
598error_ret:
599 stop_sample(st);
600 /* delay (2 * tck + 20) nano seconds */
601 udelay(1);
602 mutex_unlock(&st->lock);
603
604 return ret ? ret : len;
605}
606
607static ssize_t ad2s1210_show_pos_vel(struct device *dev,
608 struct device_attribute *attr, char *buf)
609{
610 struct spi_message msg;
611 unsigned short negative;
612 int ret = 0;
613 ssize_t len = 0;
614 u16 pos;
615 s16 vel;
616 struct iio_dev *idev = dev_get_drvdata(dev);
617 struct ad2s1210_state *st = idev->dev_data;
618
619 st->xfer.len = 2;
620 mutex_lock(&st->lock);
621 start_sample(st);
622 /* delay (6 * tck + 20) nano seconds */
623 udelay(1);
624
625 set_mode(MOD_POS, st);
626
627 spi_message_init(&msg);
628 spi_message_add_tail(&st->xfer, &msg);
629 ret = spi_sync(st->sdev, &msg);
630 if (ret)
631 goto error_ret;
632 pos = ((((u16)(st->rx[0])) << 8) | (st->rx[1]));
633 if (st->hysteresis)
634 pos >>= 16 - st->resolution;
635 len = sprintf(buf, "%d ", pos);
636
637 st->xfer.len = 2;
638 set_mode(MOD_VEL, st);
639 spi_message_init(&msg);
640 spi_message_add_tail(&st->xfer, &msg);
641 ret = spi_sync(st->sdev, &msg);
642 if (ret)
643 goto error_ret;
644 negative = st->rx[0] & 0x80;
645 vel = ((((s16)(st->rx[0])) << 8) | (st->rx[1]));
646 vel >>= 16 - st->resolution;
647 if (negative) {
648 negative = (0xffff >> st->resolution) << st->resolution;
649 vel |= negative;
650 }
651 len += sprintf(buf + len, "%d\n", vel);
652error_ret:
653 stop_sample(st);
654 /* delay (2 * tck + 20) nano seconds */
655 udelay(1);
656 mutex_unlock(&st->lock);
657
658 return ret ? ret : len;
659}
660
661static IIO_CONST_ATTR(description,
662 "Variable Resolution, 10-Bit to 16Bit R/D\n\
663Converter with Reference Oscillator");
664static IIO_DEVICE_ATTR(raw_io, S_IRUGO | S_IWUSR,
665 ad2s1210_show_raw, ad2s1210_store_raw, 0);
666static IIO_DEVICE_ATTR(reset, S_IWUSR,
667 NULL, ad2s1210_store_softreset, 0);
668static IIO_DEVICE_ATTR(fclkin, S_IRUGO | S_IWUSR,
669 ad2s1210_show_fclkin, ad2s1210_store_fclkin, 0);
670static IIO_DEVICE_ATTR(fexcit, S_IRUGO | S_IWUSR,
671 ad2s1210_show_fexcit, ad2s1210_store_fexcit, 0);
672static IIO_DEVICE_ATTR(control, S_IRUGO | S_IWUSR,
673 ad2s1210_show_control, ad2s1210_store_control, 0);
674static IIO_DEVICE_ATTR(bits, S_IRUGO | S_IWUSR,
675 ad2s1210_show_resolution, ad2s1210_store_resolution, 0);
676static IIO_DEVICE_ATTR(fault, S_IRUGO | S_IWUSR,
677 ad2s1210_show_fault, ad2s1210_clear_fault, 0);
678static IIO_DEVICE_ATTR(pos, S_IRUGO,
679 ad2s1210_show_pos, NULL, 0);
680static IIO_DEVICE_ATTR(vel, S_IRUGO,
681 ad2s1210_show_vel, NULL, 0);
682static IIO_DEVICE_ATTR(pos_vel, S_IRUGO,
683 ad2s1210_show_pos_vel, NULL, 0);
684static IIO_DEVICE_ATTR(los_thrd, S_IRUGO | S_IWUSR,
685 ad2s1210_show_reg, ad2s1210_store_reg, REG_LOS_THRD);
686static IIO_DEVICE_ATTR(dos_ovr_thrd, S_IRUGO | S_IWUSR,
687 ad2s1210_show_reg, ad2s1210_store_reg, REG_DOS_OVR_THRD);
688static IIO_DEVICE_ATTR(dos_mis_thrd, S_IRUGO | S_IWUSR,
689 ad2s1210_show_reg, ad2s1210_store_reg, REG_DOS_MIS_THRD);
690static IIO_DEVICE_ATTR(dos_rst_max_thrd, S_IRUGO | S_IWUSR,
691 ad2s1210_show_reg, ad2s1210_store_reg, REG_DOS_RST_MAX_THRD);
692static IIO_DEVICE_ATTR(dos_rst_min_thrd, S_IRUGO | S_IWUSR,
693 ad2s1210_show_reg, ad2s1210_store_reg, REG_DOS_RST_MIN_THRD);
694static IIO_DEVICE_ATTR(lot_high_thrd, S_IRUGO | S_IWUSR,
695 ad2s1210_show_reg, ad2s1210_store_reg, REG_LOT_HIGH_THRD);
696static IIO_DEVICE_ATTR(lot_low_thrd, S_IRUGO | S_IWUSR,
697 ad2s1210_show_reg, ad2s1210_store_reg, REG_LOT_LOW_THRD);
698
699static struct attribute *ad2s1210_attributes[] = {
700 &iio_const_attr_description.dev_attr.attr,
701 &iio_dev_attr_raw_io.dev_attr.attr,
702 &iio_dev_attr_reset.dev_attr.attr,
703 &iio_dev_attr_fclkin.dev_attr.attr,
704 &iio_dev_attr_fexcit.dev_attr.attr,
705 &iio_dev_attr_control.dev_attr.attr,
706 &iio_dev_attr_bits.dev_attr.attr,
707 &iio_dev_attr_fault.dev_attr.attr,
708 &iio_dev_attr_pos.dev_attr.attr,
709 &iio_dev_attr_vel.dev_attr.attr,
710 &iio_dev_attr_pos_vel.dev_attr.attr,
711 &iio_dev_attr_los_thrd.dev_attr.attr,
712 &iio_dev_attr_dos_ovr_thrd.dev_attr.attr,
713 &iio_dev_attr_dos_mis_thrd.dev_attr.attr,
714 &iio_dev_attr_dos_rst_max_thrd.dev_attr.attr,
715 &iio_dev_attr_dos_rst_min_thrd.dev_attr.attr,
716 &iio_dev_attr_lot_high_thrd.dev_attr.attr,
717 &iio_dev_attr_lot_low_thrd.dev_attr.attr,
718 NULL,
719};
720
721static const struct attribute_group ad2s1210_attribute_group = {
722 .name = DRV_NAME,
723 .attrs = ad2s1210_attributes,
724};
725
726static int __devinit ad2s1210_initial(struct ad2s1210_state *st)
727{
728 unsigned char data;
729 int ret;
730
731 mutex_lock(&st->lock);
732#if defined(CONFIG_AD2S1210_GPIO_INPUT)
733 st->resolution = read_resolution_pin(st);
734#elif defined(CONFIG_AD2S1210_GPIO_OUTPUT)
735 set_resolution_pin(st);
736#endif
737
738 config_write(st, REG_CONTROL);
739 data = DEF_CONTROL & ~(SET_RESOLUTION);
740 data |= (st->resolution - RES_10) >> 1;
741 config_write(st, data);
742 ret = config_read(st, REG_CONTROL, &data);
743 if (ret)
744 goto error_ret;
745
746 if (data & MSB_IS_HIGH) {
747 ret = -EIO;
748 goto error_ret;
749 }
750
751 update_frequency_control_word(st);
752 soft_reset(st);
753error_ret:
754 mutex_unlock(&st->lock);
755 return ret;
756}
757
758static int __devinit ad2s1210_probe(struct spi_device *spi)
759{
760 struct ad2s1210_state *st;
761 int pn, ret = 0;
762 unsigned short *pins = spi->dev.platform_data;
763
764 for (pn = 0; pn < AD2S1210_PN; pn++) {
765 if (gpio_request(pins[pn], DRV_NAME)) {
766 pr_err("%s: request gpio pin %d failed\n",
767 DRV_NAME, pins[pn]);
768 goto error_ret;
769 }
770 if (pn < AD2S1210_SAA)
771 gpio_direction_output(pins[pn], 1);
772 else {
773#if defined(CONFIG_AD2S1210_GPIO_INPUT)
774 gpio_direction_input(pins[pn]);
775#elif defined(CONFIG_AD2S1210_GPIO_OUTPUT)
776 gpio_direction_output(pins[pn], 1);
777#endif
778 }
779 }
780
781 st = kzalloc(sizeof(*st), GFP_KERNEL);
782 if (st == NULL) {
783 ret = -ENOMEM;
784 goto error_ret;
785 }
786 spi_set_drvdata(spi, st);
787
788 mutex_init(&st->lock);
789 st->sdev = spi;
790 st->xfer.tx_buf = st->tx;
791 st->xfer.rx_buf = st->rx;
792 st->hysteresis = 1;
793 st->mode = MOD_CONFIG;
794 st->resolution = RES_12;
795 st->fclkin = AD2S1210_DEF_CLKIN;
796 st->fexcit = AD2S1210_DEF_EXCIT;
797 st->sample = pins[0];
798 st->a0 = pins[1];
799 st->a1 = pins[2];
800 st->res0 = pins[3];
801 st->res1 = pins[4];
802
803 st->idev = iio_allocate_device();
804 if (st->idev == NULL) {
805 ret = -ENOMEM;
806 goto error_free_st;
807 }
808 st->idev->dev.parent = &spi->dev;
809 st->idev->num_interrupt_lines = 0;
810 st->idev->event_attrs = NULL;
811
812 st->idev->attrs = &ad2s1210_attribute_group;
813 st->idev->dev_data = (void *)(st);
814 st->idev->driver_module = THIS_MODULE;
815 st->idev->modes = INDIO_DIRECT_MODE;
816
817 ret = iio_device_register(st->idev);
818 if (ret)
819 goto error_free_dev;
820
821 if (spi->max_speed_hz != AD2S1210_DEF_CLKIN)
822 st->fclkin = spi->max_speed_hz;
823 spi->mode = SPI_MODE_3;
824 spi_setup(spi);
825
826 ad2s1210_initial(st);
827 return 0;
828
829error_free_dev:
830 iio_free_device(st->idev);
831error_free_st:
832 kfree(st);
833error_ret:
834 for (--pn; pn >= 0; pn--)
835 gpio_free(pins[pn]);
836 return ret;
837}
838
839static int __devexit ad2s1210_remove(struct spi_device *spi)
840{
841 struct ad2s1210_state *st = spi_get_drvdata(spi);
842
843 iio_device_unregister(st->idev);
844 kfree(st);
845
846 return 0;
847}
848
849static struct spi_driver ad2s1210_driver = {
850 .driver = {
851 .name = DRV_NAME,
852 .owner = THIS_MODULE,
853 },
854 .probe = ad2s1210_probe,
855 .remove = __devexit_p(ad2s1210_remove),
856};
857
858static __init int ad2s1210_spi_init(void)
859{
860 return spi_register_driver(&ad2s1210_driver);
861}
862module_init(ad2s1210_spi_init);
863
864static __exit void ad2s1210_spi_exit(void)
865{
866 spi_unregister_driver(&ad2s1210_driver);
867}
868module_exit(ad2s1210_spi_exit);
869
870MODULE_AUTHOR("Graff Yang <graff.yang@gmail.com>");
871MODULE_DESCRIPTION("Analog Devices AD2S1210 Resolver to Digital SPI driver");
872MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c
new file mode 100644
index 000000000000..4143535242d9
--- /dev/null
+++ b/drivers/staging/iio/resolver/ad2s90.c
@@ -0,0 +1,159 @@
1/*
2 * ad2s90.c simple support for the ADI Resolver to Digital Converters: AD2S90
3 *
4 * Copyright (c) 2010-2010 Analog Devices Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/types.h>
12#include <linux/mutex.h>
13#include <linux/device.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/sysfs.h>
17
18#include "../iio.h"
19#include "../sysfs.h"
20
21#define DRV_NAME "ad2s90"
22
23struct ad2s90_state {
24 struct mutex lock;
25 struct iio_dev *idev;
26 struct spi_device *sdev;
27 u8 rx[2];
28 u8 tx[2];
29};
30
31static ssize_t ad2s90_show_angular(struct device *dev,
32 struct device_attribute *attr, char *buf)
33{
34 struct spi_message msg;
35 struct spi_transfer xfer;
36 int ret;
37 ssize_t len = 0;
38 u16 val;
39 struct iio_dev *idev = dev_get_drvdata(dev);
40 struct ad2s90_state *st = idev->dev_data;
41
42 xfer.len = 1;
43 xfer.tx_buf = st->tx;
44 xfer.rx_buf = st->rx;
45 mutex_lock(&st->lock);
46
47 spi_message_init(&msg);
48 spi_message_add_tail(&xfer, &msg);
49 ret = spi_sync(st->sdev, &msg);
50 if (ret)
51 goto error_ret;
52 val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
53 len = sprintf(buf, "%d\n", val);
54error_ret:
55 mutex_unlock(&st->lock);
56
57 return ret ? ret : len;
58}
59
60#define IIO_DEV_ATTR_SIMPLE_RESOLVER(_show) \
61 IIO_DEVICE_ATTR(angular, S_IRUGO, _show, NULL, 0)
62
63static IIO_CONST_ATTR(description,
64 "Low Cost, Complete 12-Bit Resolver-to-Digital Converter");
65static IIO_DEV_ATTR_SIMPLE_RESOLVER(ad2s90_show_angular);
66
67static struct attribute *ad2s90_attributes[] = {
68 &iio_const_attr_description.dev_attr.attr,
69 &iio_dev_attr_angular.dev_attr.attr,
70 NULL,
71};
72
73static const struct attribute_group ad2s90_attribute_group = {
74 .name = DRV_NAME,
75 .attrs = ad2s90_attributes,
76};
77
78static int __devinit ad2s90_probe(struct spi_device *spi)
79{
80 struct ad2s90_state *st;
81 int ret = 0;
82
83 st = kzalloc(sizeof(*st), GFP_KERNEL);
84 if (st == NULL) {
85 ret = -ENOMEM;
86 goto error_ret;
87 }
88 spi_set_drvdata(spi, st);
89
90 mutex_init(&st->lock);
91 st->sdev = spi;
92
93 st->idev = iio_allocate_device();
94 if (st->idev == NULL) {
95 ret = -ENOMEM;
96 goto error_free_st;
97 }
98 st->idev->dev.parent = &spi->dev;
99 st->idev->num_interrupt_lines = 0;
100 st->idev->event_attrs = NULL;
101
102 st->idev->attrs = &ad2s90_attribute_group;
103 st->idev->dev_data = (void *)(st);
104 st->idev->driver_module = THIS_MODULE;
105 st->idev->modes = INDIO_DIRECT_MODE;
106
107 ret = iio_device_register(st->idev);
108 if (ret)
109 goto error_free_dev;
110
111 /* need 600ns between CS and the first falling edge of SCLK */
112 spi->max_speed_hz = 830000;
113 spi->mode = SPI_MODE_3;
114 spi_setup(spi);
115
116 return 0;
117
118error_free_dev:
119 iio_free_device(st->idev);
120error_free_st:
121 kfree(st);
122error_ret:
123 return ret;
124}
125
126static int __devexit ad2s90_remove(struct spi_device *spi)
127{
128 struct ad2s90_state *st = spi_get_drvdata(spi);
129
130 iio_device_unregister(st->idev);
131 kfree(st);
132
133 return 0;
134}
135
136static struct spi_driver ad2s90_driver = {
137 .driver = {
138 .name = DRV_NAME,
139 .owner = THIS_MODULE,
140 },
141 .probe = ad2s90_probe,
142 .remove = __devexit_p(ad2s90_remove),
143};
144
145static __init int ad2s90_spi_init(void)
146{
147 return spi_register_driver(&ad2s90_driver);
148}
149module_init(ad2s90_spi_init);
150
151static __exit void ad2s90_spi_exit(void)
152{
153 spi_unregister_driver(&ad2s90_driver);
154}
155module_exit(ad2s90_spi_exit);
156
157MODULE_AUTHOR("Graff Yang <graff.yang@gmail.com>");
158MODULE_DESCRIPTION("Analog Devices AD2S90 Resolver to Digital SPI driver");
159MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/sysfs.h b/drivers/staging/iio/sysfs.h
index ee91a95a8b95..24b74ddcd083 100644
--- a/drivers/staging/iio/sysfs.h
+++ b/drivers/staging/iio/sysfs.h
@@ -108,6 +108,12 @@ struct iio_const_attr {
108 IIO_DEVICE_ATTR(name, S_IRUGO, _show, NULL, 0) 108 IIO_DEVICE_ATTR(name, S_IRUGO, _show, NULL, 0)
109 109
110/** 110/**
111 * IIO_DEV_ATTR_RESET: resets the device
112 **/
113#define IIO_DEV_ATTR_RESET(_store) \
114 IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, _store, 0)
115
116/**
111 * IIO_CONST_ATTR_NAME - constant identifier 117 * IIO_CONST_ATTR_NAME - constant identifier
112 * @_string: the name 118 * @_string: the name
113 **/ 119 **/
diff --git a/drivers/staging/intel_sst/Kconfig b/drivers/staging/intel_sst/Kconfig
index b46bd9d1b324..82391077b384 100644
--- a/drivers/staging/intel_sst/Kconfig
+++ b/drivers/staging/intel_sst/Kconfig
@@ -8,6 +8,7 @@ config SND_INTEL_SST
8 8
9config SND_INTELMID 9config SND_INTELMID
10 tristate "Intel MID sound card driver" 10 tristate "Intel MID sound card driver"
11 depends on SOUND && SND
11 select SND_PCM 12 select SND_PCM
12 select SND_SEQUENCER 13 select SND_SEQUENCER
13 select SND_JACK 14 select SND_JACK
diff --git a/drivers/staging/intel_sst/intel_sst.c b/drivers/staging/intel_sst/intel_sst.c
index 24d3928e7071..ce4a9f79ccd2 100644
--- a/drivers/staging/intel_sst/intel_sst.c
+++ b/drivers/staging/intel_sst/intel_sst.c
@@ -29,11 +29,14 @@
29 * This file contains all init functions 29 * This file contains all init functions
30 */ 30 */
31 31
32#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
32#include <linux/pci.h> 34#include <linux/pci.h>
33#include <linux/fs.h> 35#include <linux/fs.h>
34#include <linux/interrupt.h> 36#include <linux/interrupt.h>
35#include <linux/firmware.h> 37#include <linux/firmware.h>
36#include <linux/miscdevice.h> 38#include <linux/miscdevice.h>
39#include <linux/pm_runtime.h>
37#include <asm/mrst.h> 40#include <asm/mrst.h>
38#include "intel_sst.h" 41#include "intel_sst.h"
39#include "intel_sst_ioctl.h" 42#include "intel_sst_ioctl.h"
@@ -169,17 +172,17 @@ static int __devinit intel_sst_probe(struct pci_dev *pci,
169{ 172{
170 int i, ret = 0; 173 int i, ret = 0;
171 174
172 pr_debug("sst: Probe for DID %x\n", pci->device); 175 pr_debug("Probe for DID %x\n", pci->device);
173 mutex_lock(&drv_ctx_lock); 176 mutex_lock(&drv_ctx_lock);
174 if (sst_drv_ctx) { 177 if (sst_drv_ctx) {
175 pr_err("sst: Only one sst handle is supported\n"); 178 pr_err("Only one sst handle is supported\n");
176 mutex_unlock(&drv_ctx_lock); 179 mutex_unlock(&drv_ctx_lock);
177 return -EBUSY; 180 return -EBUSY;
178 } 181 }
179 182
180 sst_drv_ctx = kzalloc(sizeof(*sst_drv_ctx), GFP_KERNEL); 183 sst_drv_ctx = kzalloc(sizeof(*sst_drv_ctx), GFP_KERNEL);
181 if (!sst_drv_ctx) { 184 if (!sst_drv_ctx) {
182 pr_err("sst: intel_sst malloc fail\n"); 185 pr_err("malloc fail\n");
183 mutex_unlock(&drv_ctx_lock); 186 mutex_unlock(&drv_ctx_lock);
184 return -ENOMEM; 187 return -ENOMEM;
185 } 188 }
@@ -226,7 +229,7 @@ static int __devinit intel_sst_probe(struct pci_dev *pci,
226 spin_lock_init(&sst_drv_ctx->list_spin_lock); 229 spin_lock_init(&sst_drv_ctx->list_spin_lock);
227 230
228 sst_drv_ctx->max_streams = pci_id->driver_data; 231 sst_drv_ctx->max_streams = pci_id->driver_data;
229 pr_debug("sst: Got drv data max stream %d\n", 232 pr_debug("Got drv data max stream %d\n",
230 sst_drv_ctx->max_streams); 233 sst_drv_ctx->max_streams);
231 for (i = 1; i <= sst_drv_ctx->max_streams; i++) { 234 for (i = 1; i <= sst_drv_ctx->max_streams; i++) {
232 struct stream_info *stream = &sst_drv_ctx->streams[i]; 235 struct stream_info *stream = &sst_drv_ctx->streams[i];
@@ -241,18 +244,18 @@ static int __devinit intel_sst_probe(struct pci_dev *pci,
241 sst_drv_ctx->mmap_mem = 244 sst_drv_ctx->mmap_mem =
242 kzalloc(sst_drv_ctx->mmap_len, GFP_KERNEL); 245 kzalloc(sst_drv_ctx->mmap_len, GFP_KERNEL);
243 if (sst_drv_ctx->mmap_mem) { 246 if (sst_drv_ctx->mmap_mem) {
244 pr_debug("sst: Got memory %p size 0x%x\n", 247 pr_debug("Got memory %p size 0x%x\n",
245 sst_drv_ctx->mmap_mem, 248 sst_drv_ctx->mmap_mem,
246 sst_drv_ctx->mmap_len); 249 sst_drv_ctx->mmap_len);
247 break; 250 break;
248 } 251 }
249 if (sst_drv_ctx->mmap_len < (SST_MMAP_STEP*PAGE_SIZE)) { 252 if (sst_drv_ctx->mmap_len < (SST_MMAP_STEP*PAGE_SIZE)) {
250 pr_err("sst: mem alloc fail...abort!!\n"); 253 pr_err("mem alloc fail...abort!!\n");
251 ret = -ENOMEM; 254 ret = -ENOMEM;
252 goto free_process_reply_wq; 255 goto free_process_reply_wq;
253 } 256 }
254 sst_drv_ctx->mmap_len -= (SST_MMAP_STEP * PAGE_SIZE); 257 sst_drv_ctx->mmap_len -= (SST_MMAP_STEP * PAGE_SIZE);
255 pr_debug("sst:mem alloc failed...trying %d\n", 258 pr_debug("mem alloc failed...trying %d\n",
256 sst_drv_ctx->mmap_len); 259 sst_drv_ctx->mmap_len);
257 } 260 }
258 } 261 }
@@ -260,7 +263,7 @@ static int __devinit intel_sst_probe(struct pci_dev *pci,
260 /* Init the device */ 263 /* Init the device */
261 ret = pci_enable_device(pci); 264 ret = pci_enable_device(pci);
262 if (ret) { 265 if (ret) {
263 pr_err("sst: device cant be enabled\n"); 266 pr_err("device cant be enabled\n");
264 goto do_free_mem; 267 goto do_free_mem;
265 } 268 }
266 sst_drv_ctx->pci = pci_dev_get(pci); 269 sst_drv_ctx->pci = pci_dev_get(pci);
@@ -273,25 +276,25 @@ static int __devinit intel_sst_probe(struct pci_dev *pci,
273 sst_drv_ctx->shim = pci_ioremap_bar(pci, 1); 276 sst_drv_ctx->shim = pci_ioremap_bar(pci, 1);
274 if (!sst_drv_ctx->shim) 277 if (!sst_drv_ctx->shim)
275 goto do_release_regions; 278 goto do_release_regions;
276 pr_debug("sst: SST Shim Ptr %p\n", sst_drv_ctx->shim); 279 pr_debug("SST Shim Ptr %p\n", sst_drv_ctx->shim);
277 280
278 /* Shared SRAM */ 281 /* Shared SRAM */
279 sst_drv_ctx->mailbox = pci_ioremap_bar(pci, 2); 282 sst_drv_ctx->mailbox = pci_ioremap_bar(pci, 2);
280 if (!sst_drv_ctx->mailbox) 283 if (!sst_drv_ctx->mailbox)
281 goto do_unmap_shim; 284 goto do_unmap_shim;
282 pr_debug("sst: SRAM Ptr %p\n", sst_drv_ctx->mailbox); 285 pr_debug("SRAM Ptr %p\n", sst_drv_ctx->mailbox);
283 286
284 /* IRAM */ 287 /* IRAM */
285 sst_drv_ctx->iram = pci_ioremap_bar(pci, 3); 288 sst_drv_ctx->iram = pci_ioremap_bar(pci, 3);
286 if (!sst_drv_ctx->iram) 289 if (!sst_drv_ctx->iram)
287 goto do_unmap_sram; 290 goto do_unmap_sram;
288 pr_debug("sst:IRAM Ptr %p\n", sst_drv_ctx->iram); 291 pr_debug("IRAM Ptr %p\n", sst_drv_ctx->iram);
289 292
290 /* DRAM */ 293 /* DRAM */
291 sst_drv_ctx->dram = pci_ioremap_bar(pci, 4); 294 sst_drv_ctx->dram = pci_ioremap_bar(pci, 4);
292 if (!sst_drv_ctx->dram) 295 if (!sst_drv_ctx->dram)
293 goto do_unmap_iram; 296 goto do_unmap_iram;
294 pr_debug("sst: DRAM Ptr %p\n", sst_drv_ctx->dram); 297 pr_debug("DRAM Ptr %p\n", sst_drv_ctx->dram);
295 298
296 mutex_lock(&sst_drv_ctx->sst_lock); 299 mutex_lock(&sst_drv_ctx->sst_lock);
297 sst_drv_ctx->sst_state = SST_UN_INIT; 300 sst_drv_ctx->sst_state = SST_UN_INIT;
@@ -301,26 +304,31 @@ static int __devinit intel_sst_probe(struct pci_dev *pci,
301 IRQF_SHARED, SST_DRV_NAME, sst_drv_ctx); 304 IRQF_SHARED, SST_DRV_NAME, sst_drv_ctx);
302 if (ret) 305 if (ret)
303 goto do_unmap_dram; 306 goto do_unmap_dram;
304 pr_debug("sst: Registered IRQ 0x%x\n", pci->irq); 307 pr_debug("Registered IRQ 0x%x\n", pci->irq);
308
309 /*Register LPE Control as misc driver*/
310 ret = misc_register(&lpe_ctrl);
311 if (ret) {
312 pr_err("couldn't register control device\n");
313 goto do_free_irq;
314 }
305 315
306 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID) { 316 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID) {
307 ret = misc_register(&lpe_dev); 317 ret = misc_register(&lpe_dev);
308 if (ret) { 318 if (ret) {
309 pr_err("sst: couldn't register LPE device\n"); 319 pr_err("couldn't register misc driver\n");
310 goto do_free_irq; 320 goto do_free_misc;
311 } 321 }
312
313 /*Register LPE Control as misc driver*/
314 ret = misc_register(&lpe_ctrl);
315 if (ret) {
316 pr_err("sst: couldn't register misc driver\n");
317 goto do_free_irq;
318 }
319 } 322 }
320 sst_drv_ctx->lpe_stalled = 0; 323 sst_drv_ctx->lpe_stalled = 0;
321 pr_debug("sst: ...successfully done!!!\n"); 324 pm_runtime_set_active(&pci->dev);
325 pm_runtime_enable(&pci->dev);
326 pm_runtime_allow(&pci->dev);
327 pr_debug("...successfully done!!!\n");
322 return ret; 328 return ret;
323 329
330do_free_misc:
331 misc_deregister(&lpe_ctrl);
324do_free_irq: 332do_free_irq:
325 free_irq(pci->irq, sst_drv_ctx); 333 free_irq(pci->irq, sst_drv_ctx);
326do_unmap_dram: 334do_unmap_dram:
@@ -347,7 +355,7 @@ free_mad_wq:
347 destroy_workqueue(sst_drv_ctx->mad_wq); 355 destroy_workqueue(sst_drv_ctx->mad_wq);
348do_free_drv_ctx: 356do_free_drv_ctx:
349 kfree(sst_drv_ctx); 357 kfree(sst_drv_ctx);
350 pr_err("sst: Probe failed with 0x%x\n", ret); 358 pr_err("Probe failed with 0x%x\n", ret);
351 return ret; 359 return ret;
352} 360}
353 361
@@ -365,10 +373,9 @@ static void __devexit intel_sst_remove(struct pci_dev *pci)
365 mutex_lock(&sst_drv_ctx->sst_lock); 373 mutex_lock(&sst_drv_ctx->sst_lock);
366 sst_drv_ctx->sst_state = SST_UN_INIT; 374 sst_drv_ctx->sst_state = SST_UN_INIT;
367 mutex_unlock(&sst_drv_ctx->sst_lock); 375 mutex_unlock(&sst_drv_ctx->sst_lock);
368 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID) { 376 misc_deregister(&lpe_ctrl);
377 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID)
369 misc_deregister(&lpe_dev); 378 misc_deregister(&lpe_dev);
370 misc_deregister(&lpe_ctrl);
371 }
372 free_irq(pci->irq, sst_drv_ctx); 379 free_irq(pci->irq, sst_drv_ctx);
373 iounmap(sst_drv_ctx->dram); 380 iounmap(sst_drv_ctx->dram);
374 iounmap(sst_drv_ctx->iram); 381 iounmap(sst_drv_ctx->iram);
@@ -404,10 +411,12 @@ int intel_sst_suspend(struct pci_dev *pci, pm_message_t state)
404{ 411{
405 union config_status_reg csr; 412 union config_status_reg csr;
406 413
407 pr_debug("sst: intel_sst_suspend called\n"); 414 pr_debug("intel_sst_suspend called\n");
408 415
409 if (sst_drv_ctx->pb_streams != 0 || sst_drv_ctx->cp_streams != 0) 416 if (sst_drv_ctx->stream_cnt) {
410 return -EPERM; 417 pr_err("active streams,not able to suspend\n");
418 return -EBUSY;
419 }
411 /*Assert RESET on LPE Processor*/ 420 /*Assert RESET on LPE Processor*/
412 csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR); 421 csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
413 csr.full = csr.full | 0x2; 422 csr.full = csr.full | 0x2;
@@ -434,17 +443,17 @@ int intel_sst_resume(struct pci_dev *pci)
434{ 443{
435 int ret = 0; 444 int ret = 0;
436 445
437 pr_debug("sst: intel_sst_resume called\n"); 446 pr_debug("intel_sst_resume called\n");
438 if (sst_drv_ctx->sst_state != SST_SUSPENDED) { 447 if (sst_drv_ctx->sst_state != SST_SUSPENDED) {
439 pr_err("sst: SST is not in suspended state\n"); 448 pr_err("SST is not in suspended state\n");
440 return -EPERM; 449 return 0;
441 } 450 }
442 sst_drv_ctx = pci_get_drvdata(pci); 451 sst_drv_ctx = pci_get_drvdata(pci);
443 pci_set_power_state(pci, PCI_D0); 452 pci_set_power_state(pci, PCI_D0);
444 pci_restore_state(pci); 453 pci_restore_state(pci);
445 ret = pci_enable_device(pci); 454 ret = pci_enable_device(pci);
446 if (ret) 455 if (ret)
447 pr_err("sst: device cant be enabled\n"); 456 pr_err("device cant be enabled\n");
448 457
449 mutex_lock(&sst_drv_ctx->sst_lock); 458 mutex_lock(&sst_drv_ctx->sst_lock);
450 sst_drv_ctx->sst_state = SST_UN_INIT; 459 sst_drv_ctx->sst_state = SST_UN_INIT;
@@ -452,6 +461,34 @@ int intel_sst_resume(struct pci_dev *pci)
452 return 0; 461 return 0;
453} 462}
454 463
464static int intel_sst_runtime_suspend(struct device *dev)
465{
466 struct pci_dev *pci_dev = to_pci_dev(dev);
467 pr_debug("runtime_suspend called\n");
468 return intel_sst_suspend(pci_dev, PMSG_SUSPEND);
469}
470
471static int intel_sst_runtime_resume(struct device *dev)
472{
473 struct pci_dev *pci_dev = to_pci_dev(dev);
474 pr_debug("runtime_resume called\n");
475 return intel_sst_resume(pci_dev);
476}
477
478static int intel_sst_runtime_idle(struct device *dev)
479{
480 pr_debug("runtime_idle called\n");
481 if (sst_drv_ctx->stream_cnt == 0 && sst_drv_ctx->am_cnt == 0)
482 pm_schedule_suspend(dev, SST_SUSPEND_DELAY);
483 return -EBUSY;
484}
485
486static const struct dev_pm_ops intel_sst_pm = {
487 .runtime_suspend = intel_sst_runtime_suspend,
488 .runtime_resume = intel_sst_runtime_resume,
489 .runtime_idle = intel_sst_runtime_idle,
490};
491
455/* PCI Routines */ 492/* PCI Routines */
456static struct pci_device_id intel_sst_ids[] = { 493static struct pci_device_id intel_sst_ids[] = {
457 { PCI_VDEVICE(INTEL, SST_MRST_PCI_ID), 3}, 494 { PCI_VDEVICE(INTEL, SST_MRST_PCI_ID), 3},
@@ -468,6 +505,9 @@ static struct pci_driver driver = {
468#ifdef CONFIG_PM 505#ifdef CONFIG_PM
469 .suspend = intel_sst_suspend, 506 .suspend = intel_sst_suspend,
470 .resume = intel_sst_resume, 507 .resume = intel_sst_resume,
508 .driver = {
509 .pm = &intel_sst_pm,
510 },
471#endif 511#endif
472}; 512};
473 513
@@ -482,14 +522,14 @@ static int __init intel_sst_init(void)
482{ 522{
483 /* Init all variables, data structure etc....*/ 523 /* Init all variables, data structure etc....*/
484 int ret = 0; 524 int ret = 0;
485 pr_debug("sst: INFO: ******** SST DRIVER loading.. Ver: %s\n", 525 pr_debug("INFO: ******** SST DRIVER loading.. Ver: %s\n",
486 SST_DRIVER_VERSION); 526 SST_DRIVER_VERSION);
487 527
488 mutex_init(&drv_ctx_lock); 528 mutex_init(&drv_ctx_lock);
489 /* Register with PCI */ 529 /* Register with PCI */
490 ret = pci_register_driver(&driver); 530 ret = pci_register_driver(&driver);
491 if (ret) 531 if (ret)
492 pr_err("sst: PCI register failed\n"); 532 pr_err("PCI register failed\n");
493 return ret; 533 return ret;
494} 534}
495 535
@@ -504,7 +544,7 @@ static void __exit intel_sst_exit(void)
504{ 544{
505 pci_unregister_driver(&driver); 545 pci_unregister_driver(&driver);
506 546
507 pr_debug("sst: driver unloaded\n"); 547 pr_debug("driver unloaded\n");
508 return; 548 return;
509} 549}
510 550
diff --git a/drivers/staging/intel_sst/intel_sst.h b/drivers/staging/intel_sst/intel_sst.h
index 1f19f0d1d316..cb03ff7d1a21 100644
--- a/drivers/staging/intel_sst/intel_sst.h
+++ b/drivers/staging/intel_sst/intel_sst.h
@@ -29,6 +29,7 @@
29 * and middleware. 29 * and middleware.
30 * This file is shared between the SST and MAD drivers 30 * This file is shared between the SST and MAD drivers
31 */ 31 */
32#include "intel_sst_ioctl.h"
32 33
33#define SST_CARD_NAMES "intel_mid_card" 34#define SST_CARD_NAMES "intel_mid_card"
34 35
@@ -107,10 +108,15 @@ struct snd_pmic_ops {
107 int (*power_down_pmic) (void); 108 int (*power_down_pmic) (void);
108}; 109};
109 110
111struct intel_sst_pcm_control {
112 int (*open) (struct snd_sst_params *str_param);
113 int (*device_control) (int cmd, void *arg);
114 int (*close) (unsigned int str_id);
115};
110struct intel_sst_card_ops { 116struct intel_sst_card_ops {
111 char *module_name; 117 char *module_name;
112 unsigned int vendor_id; 118 unsigned int vendor_id;
113 int (*control_set) (int control_element, void *value); 119 struct intel_sst_pcm_control *pcm_control;
114 struct snd_pmic_ops *scard_ops; 120 struct snd_pmic_ops *scard_ops;
115}; 121};
116 122
diff --git a/drivers/staging/intel_sst/intel_sst_app_interface.c b/drivers/staging/intel_sst/intel_sst_app_interface.c
index 991440015e92..a367991d5600 100644
--- a/drivers/staging/intel_sst/intel_sst_app_interface.c
+++ b/drivers/staging/intel_sst/intel_sst_app_interface.c
@@ -27,12 +27,15 @@
27 * Upper layer interfaces (MAD driver, MMF) to SST driver 27 * Upper layer interfaces (MAD driver, MMF) to SST driver
28 */ 28 */
29 29
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
30#include <linux/pci.h> 32#include <linux/pci.h>
31#include <linux/fs.h> 33#include <linux/fs.h>
32#include <linux/uio.h> 34#include <linux/uio.h>
33#include <linux/aio.h> 35#include <linux/aio.h>
34#include <linux/uaccess.h> 36#include <linux/uaccess.h>
35#include <linux/firmware.h> 37#include <linux/firmware.h>
38#include <linux/pm_runtime.h>
36#include <linux/ioctl.h> 39#include <linux/ioctl.h>
37#ifdef CONFIG_MRST_RAR_HANDLER 40#ifdef CONFIG_MRST_RAR_HANDLER
38#include <linux/rar_register.h> 41#include <linux/rar_register.h>
@@ -58,14 +61,14 @@ static int intel_sst_check_device(void)
58{ 61{
59 int retval = 0; 62 int retval = 0;
60 if (sst_drv_ctx->pmic_state != SND_MAD_INIT_DONE) { 63 if (sst_drv_ctx->pmic_state != SND_MAD_INIT_DONE) {
61 pr_warn("sst: Sound card not availble\n "); 64 pr_warn("Sound card not available\n");
62 return -EIO; 65 return -EIO;
63 } 66 }
64 if (sst_drv_ctx->sst_state == SST_SUSPENDED) { 67 if (sst_drv_ctx->sst_state == SST_SUSPENDED) {
65 pr_debug("sst: Resuming from Suspended state\n"); 68 pr_debug("Resuming from Suspended state\n");
66 retval = intel_sst_resume(sst_drv_ctx->pci); 69 retval = intel_sst_resume(sst_drv_ctx->pci);
67 if (retval) { 70 if (retval) {
68 pr_debug("sst: Resume Failed= %#x,abort\n", retval); 71 pr_debug("Resume Failed= %#x,abort\n", retval);
69 return retval; 72 return retval;
70 } 73 }
71 } 74 }
@@ -97,15 +100,22 @@ static int intel_sst_check_device(void)
97 */ 100 */
98int intel_sst_open(struct inode *i_node, struct file *file_ptr) 101int intel_sst_open(struct inode *i_node, struct file *file_ptr)
99{ 102{
100 int retval = intel_sst_check_device(); 103 unsigned int retval;
101 if (retval)
102 return retval;
103 104
104 mutex_lock(&sst_drv_ctx->stream_lock); 105 mutex_lock(&sst_drv_ctx->stream_lock);
106 pm_runtime_get_sync(&sst_drv_ctx->pci->dev);
107 retval = intel_sst_check_device();
108 if (retval) {
109 pm_runtime_put(&sst_drv_ctx->pci->dev);
110 mutex_unlock(&sst_drv_ctx->stream_lock);
111 return retval;
112 }
113
105 if (sst_drv_ctx->encoded_cnt < MAX_ENC_STREAM) { 114 if (sst_drv_ctx->encoded_cnt < MAX_ENC_STREAM) {
106 struct ioctl_pvt_data *data = 115 struct ioctl_pvt_data *data =
107 kzalloc(sizeof(struct ioctl_pvt_data), GFP_KERNEL); 116 kzalloc(sizeof(struct ioctl_pvt_data), GFP_KERNEL);
108 if (!data) { 117 if (!data) {
118 pm_runtime_put(&sst_drv_ctx->pci->dev);
109 mutex_unlock(&sst_drv_ctx->stream_lock); 119 mutex_unlock(&sst_drv_ctx->stream_lock);
110 return -ENOMEM; 120 return -ENOMEM;
111 } 121 }
@@ -115,9 +125,10 @@ int intel_sst_open(struct inode *i_node, struct file *file_ptr)
115 data->pvt_id = sst_assign_pvt_id(sst_drv_ctx); 125 data->pvt_id = sst_assign_pvt_id(sst_drv_ctx);
116 data->str_id = 0; 126 data->str_id = 0;
117 file_ptr->private_data = (void *)data; 127 file_ptr->private_data = (void *)data;
118 pr_debug("sst: pvt_id handle = %d!\n", data->pvt_id); 128 pr_debug("pvt_id handle = %d!\n", data->pvt_id);
119 } else { 129 } else {
120 retval = -EUSERS; 130 retval = -EUSERS;
131 pm_runtime_put(&sst_drv_ctx->pci->dev);
121 mutex_unlock(&sst_drv_ctx->stream_lock); 132 mutex_unlock(&sst_drv_ctx->stream_lock);
122 } 133 }
123 return retval; 134 return retval;
@@ -136,18 +147,26 @@ int intel_sst_open(struct inode *i_node, struct file *file_ptr)
136 */ 147 */
137int intel_sst_open_cntrl(struct inode *i_node, struct file *file_ptr) 148int intel_sst_open_cntrl(struct inode *i_node, struct file *file_ptr)
138{ 149{
139 int retval = intel_sst_check_device(); 150 unsigned int retval;
140 if (retval)
141 return retval;
142 151
143 /* audio manager open */ 152 /* audio manager open */
144 mutex_lock(&sst_drv_ctx->stream_lock); 153 mutex_lock(&sst_drv_ctx->stream_lock);
154 pm_runtime_get_sync(&sst_drv_ctx->pci->dev);
155 retval = intel_sst_check_device();
156 if (retval) {
157 pm_runtime_put(&sst_drv_ctx->pci->dev);
158 mutex_unlock(&sst_drv_ctx->stream_lock);
159 return retval;
160 }
161
145 if (sst_drv_ctx->am_cnt < MAX_AM_HANDLES) { 162 if (sst_drv_ctx->am_cnt < MAX_AM_HANDLES) {
146 sst_drv_ctx->am_cnt++; 163 sst_drv_ctx->am_cnt++;
147 pr_debug("sst: AM handle opened...\n"); 164 pr_debug("AM handle opened...\n");
148 file_ptr->private_data = NULL; 165 file_ptr->private_data = NULL;
149 } else 166 } else {
150 retval = -EACCES; 167 retval = -EACCES;
168 pm_runtime_put(&sst_drv_ctx->pci->dev);
169 }
151 170
152 mutex_unlock(&sst_drv_ctx->stream_lock); 171 mutex_unlock(&sst_drv_ctx->stream_lock);
153 return retval; 172 return retval;
@@ -166,10 +185,11 @@ int intel_sst_release(struct inode *i_node, struct file *file_ptr)
166{ 185{
167 struct ioctl_pvt_data *data = file_ptr->private_data; 186 struct ioctl_pvt_data *data = file_ptr->private_data;
168 187
169 pr_debug("sst: Release called, closing app handle\n"); 188 pr_debug("Release called, closing app handle\n");
170 mutex_lock(&sst_drv_ctx->stream_lock); 189 mutex_lock(&sst_drv_ctx->stream_lock);
171 sst_drv_ctx->encoded_cnt--; 190 sst_drv_ctx->encoded_cnt--;
172 sst_drv_ctx->stream_cnt--; 191 sst_drv_ctx->stream_cnt--;
192 pm_runtime_put(&sst_drv_ctx->pci->dev);
173 mutex_unlock(&sst_drv_ctx->stream_lock); 193 mutex_unlock(&sst_drv_ctx->stream_lock);
174 free_stream_context(data->str_id); 194 free_stream_context(data->str_id);
175 kfree(data); 195 kfree(data);
@@ -181,8 +201,9 @@ int intel_sst_release_cntrl(struct inode *i_node, struct file *file_ptr)
181 /* audio manager close */ 201 /* audio manager close */
182 mutex_lock(&sst_drv_ctx->stream_lock); 202 mutex_lock(&sst_drv_ctx->stream_lock);
183 sst_drv_ctx->am_cnt--; 203 sst_drv_ctx->am_cnt--;
204 pm_runtime_put(&sst_drv_ctx->pci->dev);
184 mutex_unlock(&sst_drv_ctx->stream_lock); 205 mutex_unlock(&sst_drv_ctx->stream_lock);
185 pr_debug("sst: AM handle closed\n"); 206 pr_debug("AM handle closed\n");
186 return 0; 207 return 0;
187} 208}
188 209
@@ -208,7 +229,7 @@ int intel_sst_mmap(struct file *file_ptr, struct vm_area_struct *vma)
208 return -EINVAL; 229 return -EINVAL;
209 230
210 length = vma->vm_end - vma->vm_start; 231 length = vma->vm_end - vma->vm_start;
211 pr_debug("sst: called for stream %d length 0x%x\n", str_id, length); 232 pr_debug("called for stream %d length 0x%x\n", str_id, length);
212 233
213 if (length > sst_drv_ctx->mmap_len) 234 if (length > sst_drv_ctx->mmap_len)
214 return -ENOMEM; 235 return -ENOMEM;
@@ -231,7 +252,7 @@ int intel_sst_mmap(struct file *file_ptr, struct vm_area_struct *vma)
231 else 252 else
232 sst_drv_ctx->streams[str_id].mmapped = true; 253 sst_drv_ctx->streams[str_id].mmapped = true;
233 254
234 pr_debug("sst: mmap ret 0x%x\n", retval); 255 pr_debug("mmap ret 0x%x\n", retval);
235 return retval; 256 return retval;
236} 257}
237 258
@@ -245,7 +266,7 @@ static int intel_sst_mmap_play_capture(u32 str_id,
245 struct snd_sst_mmap_buff_entry *buf_entry; 266 struct snd_sst_mmap_buff_entry *buf_entry;
246 struct snd_sst_mmap_buff_entry *tmp_buf; 267 struct snd_sst_mmap_buff_entry *tmp_buf;
247 268
248 pr_debug("sst:called for str_id %d\n", str_id); 269 pr_debug("called for str_id %d\n", str_id);
249 retval = sst_validate_strid(str_id); 270 retval = sst_validate_strid(str_id);
250 if (retval) 271 if (retval)
251 return -EINVAL; 272 return -EINVAL;
@@ -270,7 +291,7 @@ static int intel_sst_mmap_play_capture(u32 str_id,
270 goto out_free; 291 goto out_free;
271 } 292 }
272 293
273 pr_debug("sst:new buffers count %d status %d\n", 294 pr_debug("new buffers count %d status %d\n",
274 mmap_buf->entries, stream->status); 295 mmap_buf->entries, stream->status);
275 buf_entry = tmp_buf; 296 buf_entry = tmp_buf;
276 for (i = 0; i < mmap_buf->entries; i++) { 297 for (i = 0; i < mmap_buf->entries; i++) {
@@ -300,14 +321,14 @@ static int intel_sst_mmap_play_capture(u32 str_id,
300 stream->status = STREAM_RUNNING; 321 stream->status = STREAM_RUNNING;
301 if (stream->ops == STREAM_OPS_PLAYBACK) { 322 if (stream->ops == STREAM_OPS_PLAYBACK) {
302 if (sst_play_frame(str_id) < 0) { 323 if (sst_play_frame(str_id) < 0) {
303 pr_warn("sst: play frames fail\n"); 324 pr_warn("play frames fail\n");
304 mutex_unlock(&stream->lock); 325 mutex_unlock(&stream->lock);
305 retval = -EIO; 326 retval = -EIO;
306 goto out_free; 327 goto out_free;
307 } 328 }
308 } else if (stream->ops == STREAM_OPS_CAPTURE) { 329 } else if (stream->ops == STREAM_OPS_CAPTURE) {
309 if (sst_capture_frame(str_id) < 0) { 330 if (sst_capture_frame(str_id) < 0) {
310 pr_warn("sst: capture frame fail\n"); 331 pr_warn("capture frame fail\n");
311 mutex_unlock(&stream->lock); 332 mutex_unlock(&stream->lock);
312 retval = -EIO; 333 retval = -EIO;
313 goto out_free; 334 goto out_free;
@@ -324,7 +345,7 @@ static int intel_sst_mmap_play_capture(u32 str_id,
324 345
325 if (retval >= 0) 346 if (retval >= 0)
326 retval = stream->cumm_bytes; 347 retval = stream->cumm_bytes;
327 pr_debug("sst:end of play/rec ioctl bytes = %d!!\n", retval); 348 pr_debug("end of play/rec ioctl bytes = %d!!\n", retval);
328 349
329out_free: 350out_free:
330 kfree(tmp_buf); 351 kfree(tmp_buf);
@@ -349,7 +370,7 @@ static int intel_sst_play_capture(struct stream_info *stream, int str_id)
349 370
350 if (stream->status == STREAM_INIT && stream->prev == STREAM_UN_INIT) { 371 if (stream->status == STREAM_INIT && stream->prev == STREAM_UN_INIT) {
351 /* stream is not started yet */ 372 /* stream is not started yet */
352 pr_debug("sst: Stream isn't in started state %d, prev %d\n", 373 pr_debug("Stream isn't in started state %d, prev %d\n",
353 stream->status, stream->prev); 374 stream->status, stream->prev);
354 } else if ((stream->status == STREAM_RUNNING || 375 } else if ((stream->status == STREAM_RUNNING ||
355 stream->status == STREAM_PAUSED) && 376 stream->status == STREAM_PAUSED) &&
@@ -358,13 +379,13 @@ static int intel_sst_play_capture(struct stream_info *stream, int str_id)
358 if (stream->ops == STREAM_OPS_PLAYBACK || 379 if (stream->ops == STREAM_OPS_PLAYBACK ||
359 stream->ops == STREAM_OPS_PLAYBACK_DRM) { 380 stream->ops == STREAM_OPS_PLAYBACK_DRM) {
360 if (sst_play_frame(str_id) < 0) { 381 if (sst_play_frame(str_id) < 0) {
361 pr_warn("sst: play frames failed\n"); 382 pr_warn("play frames failed\n");
362 mutex_unlock(&stream->lock); 383 mutex_unlock(&stream->lock);
363 return -EIO; 384 return -EIO;
364 } 385 }
365 } else if (stream->ops == STREAM_OPS_CAPTURE) { 386 } else if (stream->ops == STREAM_OPS_CAPTURE) {
366 if (sst_capture_frame(str_id) < 0) { 387 if (sst_capture_frame(str_id) < 0) {
367 pr_warn("sst: capture frames failed\n "); 388 pr_warn("capture frames failed\n");
368 mutex_unlock(&stream->lock); 389 mutex_unlock(&stream->lock);
369 return -EIO; 390 return -EIO;
370 } 391 }
@@ -379,7 +400,7 @@ static int intel_sst_play_capture(struct stream_info *stream, int str_id)
379 retval = sst_wait_interruptible(sst_drv_ctx, &stream->data_blk); 400 retval = sst_wait_interruptible(sst_drv_ctx, &stream->data_blk);
380 if (retval) { 401 if (retval) {
381 stream->status = STREAM_INIT; 402 stream->status = STREAM_INIT;
382 pr_debug("sst: wait returned error...\n"); 403 pr_debug("wait returned error...\n");
383 } 404 }
384 return retval; 405 return retval;
385} 406}
@@ -477,7 +498,7 @@ static int snd_sst_fill_kernel_list(struct stream_info *stream,
477 if (((unsigned long)iovec[index].iov_base 498 if (((unsigned long)iovec[index].iov_base
478 + iovec[index].iov_len) < 499 + iovec[index].iov_len) <
479 ((unsigned long)iovec[index].iov_base)) { 500 ((unsigned long)iovec[index].iov_base)) {
480 pr_debug("sst: Buffer overflows"); 501 pr_debug("Buffer overflows\n");
481 kfree(stream_bufs); 502 kfree(stream_bufs);
482 return -EINVAL; 503 return -EINVAL;
483 } 504 }
@@ -490,7 +511,7 @@ static int snd_sst_fill_kernel_list(struct stream_info *stream,
490 } 511 }
491 512
492 copied_size += size; 513 copied_size += size;
493 pr_debug("sst: copied_size - %lx\n", copied_size); 514 pr_debug("copied_size - %lx\n", copied_size);
494 if ((copied_size >= mmap_len) || 515 if ((copied_size >= mmap_len) ||
495 (stream->sg_index == nr_segs)) { 516 (stream->sg_index == nr_segs)) {
496 add_to_list = 1; 517 add_to_list = 1;
@@ -520,7 +541,7 @@ static int snd_sst_copy_userbuf_capture(struct stream_info *stream,
520 int retval = 0; 541 int retval = 0;
521 542
522 /* copy sent buffers */ 543 /* copy sent buffers */
523 pr_debug("sst: capture stream copying to user now...\n"); 544 pr_debug("capture stream copying to user now...\n");
524 list_for_each_entry_safe(kbufs, _kbufs, &stream->bufs, node) { 545 list_for_each_entry_safe(kbufs, _kbufs, &stream->bufs, node) {
525 if (kbufs->in_use == true) { 546 if (kbufs->in_use == true) {
526 /* copy to user */ 547 /* copy to user */
@@ -538,7 +559,7 @@ static int snd_sst_copy_userbuf_capture(struct stream_info *stream,
538 } 559 }
539 } 560 }
540 } 561 }
541 pr_debug("sst: end of cap copy\n"); 562 pr_debug("end of cap copy\n");
542 return retval; 563 return retval;
543} 564}
544 565
@@ -590,7 +611,7 @@ static int intel_sst_read_write(unsigned int str_id, char __user *buf,
590 return -EINVAL; 611 return -EINVAL;
591 stream = &sst_drv_ctx->streams[str_id]; 612 stream = &sst_drv_ctx->streams[str_id];
592 if (stream->mmapped == true) { 613 if (stream->mmapped == true) {
593 pr_warn("sst: user write and stream is mapped"); 614 pr_warn("user write and stream is mapped\n");
594 return -EIO; 615 return -EIO;
595 } 616 }
596 if (!count) 617 if (!count)
@@ -598,7 +619,7 @@ static int intel_sst_read_write(unsigned int str_id, char __user *buf,
598 stream->curr_bytes = 0; 619 stream->curr_bytes = 0;
599 stream->cumm_bytes = 0; 620 stream->cumm_bytes = 0;
600 /* copy user buf details */ 621 /* copy user buf details */
601 pr_debug("sst: new buffers %p, copy size %d, status %d\n" , 622 pr_debug("new buffers %p, copy size %d, status %d\n" ,
602 buf, (int) count, (int) stream->status); 623 buf, (int) count, (int) stream->status);
603 624
604 stream->buf_type = SST_BUF_USER_STATIC; 625 stream->buf_type = SST_BUF_USER_STATIC;
@@ -618,7 +639,7 @@ static int intel_sst_read_write(unsigned int str_id, char __user *buf,
618 stream->cur_ptr = NULL; 639 stream->cur_ptr = NULL;
619 if (retval >= 0) 640 if (retval >= 0)
620 retval = stream->cumm_bytes; 641 retval = stream->cumm_bytes;
621 pr_debug("sst: end of play/rec bytes = %d!!\n", retval); 642 pr_debug("end of play/rec bytes = %d!!\n", retval);
622 return retval; 643 return retval;
623} 644}
624 645
@@ -639,7 +660,7 @@ int intel_sst_write(struct file *file_ptr, const char __user *buf,
639 int str_id = data->str_id; 660 int str_id = data->str_id;
640 struct stream_info *stream = &sst_drv_ctx->streams[str_id]; 661 struct stream_info *stream = &sst_drv_ctx->streams[str_id];
641 662
642 pr_debug("sst: called for %d\n", str_id); 663 pr_debug("called for %d\n", str_id);
643 if (stream->status == STREAM_UN_INIT || 664 if (stream->status == STREAM_UN_INIT ||
644 stream->status == STREAM_DECODE) { 665 stream->status == STREAM_DECODE) {
645 return -EBADRQC; 666 return -EBADRQC;
@@ -665,12 +686,12 @@ ssize_t intel_sst_aio_write(struct kiocb *kiocb, const struct iovec *iov,
665 int str_id = data->str_id; 686 int str_id = data->str_id;
666 struct stream_info *stream; 687 struct stream_info *stream;
667 688
668 pr_debug("sst: entry - %ld\n", nr_segs); 689 pr_debug("entry - %ld\n", nr_segs);
669 690
670 if (is_sync_kiocb(kiocb) == false) 691 if (is_sync_kiocb(kiocb) == false)
671 return -EINVAL; 692 return -EINVAL;
672 693
673 pr_debug("sst: called for str_id %d\n", str_id); 694 pr_debug("called for str_id %d\n", str_id);
674 retval = sst_validate_strid(str_id); 695 retval = sst_validate_strid(str_id);
675 if (retval) 696 if (retval)
676 return -EINVAL; 697 return -EINVAL;
@@ -683,7 +704,7 @@ ssize_t intel_sst_aio_write(struct kiocb *kiocb, const struct iovec *iov,
683 } 704 }
684 stream->curr_bytes = 0; 705 stream->curr_bytes = 0;
685 stream->cumm_bytes = 0; 706 stream->cumm_bytes = 0;
686 pr_debug("sst: new segs %ld, offset %d, status %d\n" , 707 pr_debug("new segs %ld, offset %d, status %d\n" ,
687 nr_segs, (int) offset, (int) stream->status); 708 nr_segs, (int) offset, (int) stream->status);
688 stream->buf_type = SST_BUF_USER_STATIC; 709 stream->buf_type = SST_BUF_USER_STATIC;
689 do { 710 do {
@@ -698,7 +719,7 @@ ssize_t intel_sst_aio_write(struct kiocb *kiocb, const struct iovec *iov,
698 stream->cur_ptr = NULL; 719 stream->cur_ptr = NULL;
699 if (retval >= 0) 720 if (retval >= 0)
700 retval = stream->cumm_bytes; 721 retval = stream->cumm_bytes;
701 pr_debug("sst: end of play/rec bytes = %d!!\n", retval); 722 pr_debug("end of play/rec bytes = %d!!\n", retval);
702 return retval; 723 return retval;
703} 724}
704 725
@@ -719,7 +740,7 @@ int intel_sst_read(struct file *file_ptr, char __user *buf,
719 int str_id = data->str_id; 740 int str_id = data->str_id;
720 struct stream_info *stream = &sst_drv_ctx->streams[str_id]; 741 struct stream_info *stream = &sst_drv_ctx->streams[str_id];
721 742
722 pr_debug("sst: called for %d\n", str_id); 743 pr_debug("called for %d\n", str_id);
723 if (stream->status == STREAM_UN_INIT || 744 if (stream->status == STREAM_UN_INIT ||
724 stream->status == STREAM_DECODE) 745 stream->status == STREAM_DECODE)
725 return -EBADRQC; 746 return -EBADRQC;
@@ -744,14 +765,14 @@ ssize_t intel_sst_aio_read(struct kiocb *kiocb, const struct iovec *iov,
744 int str_id = data->str_id; 765 int str_id = data->str_id;
745 struct stream_info *stream; 766 struct stream_info *stream;
746 767
747 pr_debug("sst: entry - %ld\n", nr_segs); 768 pr_debug("entry - %ld\n", nr_segs);
748 769
749 if (is_sync_kiocb(kiocb) == false) { 770 if (is_sync_kiocb(kiocb) == false) {
750 pr_debug("sst: aio_read from user space is not allowed\n"); 771 pr_debug("aio_read from user space is not allowed\n");
751 return -EINVAL; 772 return -EINVAL;
752 } 773 }
753 774
754 pr_debug("sst: called for str_id %d\n", str_id); 775 pr_debug("called for str_id %d\n", str_id);
755 retval = sst_validate_strid(str_id); 776 retval = sst_validate_strid(str_id);
756 if (retval) 777 if (retval)
757 return -EINVAL; 778 return -EINVAL;
@@ -764,7 +785,7 @@ ssize_t intel_sst_aio_read(struct kiocb *kiocb, const struct iovec *iov,
764 stream->curr_bytes = 0; 785 stream->curr_bytes = 0;
765 stream->cumm_bytes = 0; 786 stream->cumm_bytes = 0;
766 787
767 pr_debug("sst: new segs %ld, offset %d, status %d\n" , 788 pr_debug("new segs %ld, offset %d, status %d\n" ,
768 nr_segs, (int) offset, (int) stream->status); 789 nr_segs, (int) offset, (int) stream->status);
769 stream->buf_type = SST_BUF_USER_STATIC; 790 stream->buf_type = SST_BUF_USER_STATIC;
770 do { 791 do {
@@ -779,34 +800,169 @@ ssize_t intel_sst_aio_read(struct kiocb *kiocb, const struct iovec *iov,
779 stream->cur_ptr = NULL; 800 stream->cur_ptr = NULL;
780 if (retval >= 0) 801 if (retval >= 0)
781 retval = stream->cumm_bytes; 802 retval = stream->cumm_bytes;
782 pr_debug("sst: end of play/rec bytes = %d!!\n", retval); 803 pr_debug("end of play/rec bytes = %d!!\n", retval);
783 return retval; 804 return retval;
784} 805}
785 806
786/* sst_print_stream_params - prints the stream parameters (debug fn)*/ 807/* sst_print_stream_params - prints the stream parameters (debug fn)*/
787static void sst_print_stream_params(struct snd_sst_get_stream_params *get_prm) 808static void sst_print_stream_params(struct snd_sst_get_stream_params *get_prm)
788{ 809{
789 pr_debug("sst: codec params:result =%d\n", 810 pr_debug("codec params:result = %d\n",
790 get_prm->codec_params.result); 811 get_prm->codec_params.result);
791 pr_debug("sst: codec params:stream = %d\n", 812 pr_debug("codec params:stream = %d\n",
792 get_prm->codec_params.stream_id); 813 get_prm->codec_params.stream_id);
793 pr_debug("sst: codec params:codec = %d\n", 814 pr_debug("codec params:codec = %d\n",
794 get_prm->codec_params.codec); 815 get_prm->codec_params.codec);
795 pr_debug("sst: codec params:ops = %d\n", 816 pr_debug("codec params:ops = %d\n",
796 get_prm->codec_params.ops); 817 get_prm->codec_params.ops);
797 pr_debug("sst: codec params:stream_type= %d\n", 818 pr_debug("codec params:stream_type = %d\n",
798 get_prm->codec_params.stream_type); 819 get_prm->codec_params.stream_type);
799 pr_debug("sst: pcmparams:sfreq= %d\n", 820 pr_debug("pcmparams:sfreq = %d\n",
800 get_prm->pcm_params.sfreq); 821 get_prm->pcm_params.sfreq);
801 pr_debug("sst: pcmparams:num_chan= %d\n", 822 pr_debug("pcmparams:num_chan = %d\n",
802 get_prm->pcm_params.num_chan); 823 get_prm->pcm_params.num_chan);
803 pr_debug("sst: pcmparams:pcm_wd_sz= %d\n", 824 pr_debug("pcmparams:pcm_wd_sz = %d\n",
804 get_prm->pcm_params.pcm_wd_sz); 825 get_prm->pcm_params.pcm_wd_sz);
805 return; 826 return;
806} 827}
807 828
808/** 829/**
809 * intel_sst_ioctl - recieves the device ioctl's 830 * sst_create_algo_ipc - create ipc msg for algorithm parameters
831 *
832 * @algo_params: Algorithm parameters
833 * @msg: post msg pointer
834 *
835 * This function is called to create ipc msg
836 */
837int sst_create_algo_ipc(struct snd_ppp_params *algo_params,
838 struct ipc_post **msg)
839{
840 if (sst_create_large_msg(msg))
841 return -ENOMEM;
842 sst_fill_header(&(*msg)->header,
843 IPC_IA_ALG_PARAMS, 1, algo_params->str_id);
844 (*msg)->header.part.data = sizeof(u32) +
845 sizeof(*algo_params) + algo_params->size;
846 memcpy((*msg)->mailbox_data, &(*msg)->header, sizeof(u32));
847 memcpy((*msg)->mailbox_data + sizeof(u32),
848 algo_params, sizeof(*algo_params));
849 return 0;
850}
851
852/**
853 * sst_send_algo_ipc - send ipc msg for algorithm parameters
854 *
855 * @msg: post msg pointer
856 *
857 * This function is called to send ipc msg
858 */
859int sst_send_algo_ipc(struct ipc_post **msg)
860{
861 sst_drv_ctx->ppp_params_blk.condition = false;
862 sst_drv_ctx->ppp_params_blk.ret_code = 0;
863 sst_drv_ctx->ppp_params_blk.on = true;
864 sst_drv_ctx->ppp_params_blk.data = NULL;
865 spin_lock(&sst_drv_ctx->list_spin_lock);
866 list_add_tail(&(*msg)->node, &sst_drv_ctx->ipc_dispatch_list);
867 spin_unlock(&sst_drv_ctx->list_spin_lock);
868 sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
869 return sst_wait_interruptible_timeout(sst_drv_ctx,
870 &sst_drv_ctx->ppp_params_blk, SST_BLOCK_TIMEOUT);
871}
872
873/**
874 * intel_sst_ioctl_dsp - recieves the device ioctl's
875 *
876 * @cmd:Ioctl cmd
877 * @arg:data
878 *
879 * This function is called when a user space component
880 * sends a DSP Ioctl to SST driver
881 */
882long intel_sst_ioctl_dsp(unsigned int cmd, unsigned long arg)
883{
884 int retval = 0;
885 struct snd_ppp_params algo_params;
886 struct snd_ppp_params *algo_params_copied;
887 struct ipc_post *msg;
888
889 switch (_IOC_NR(cmd)) {
890 case _IOC_NR(SNDRV_SST_SET_ALGO):
891 if (copy_from_user(&algo_params, (void __user *)arg,
892 sizeof(algo_params)))
893 return -EFAULT;
894 if (algo_params.size > SST_MAILBOX_SIZE)
895 return -EMSGSIZE;
896
897 pr_debug("Algo ID %d Str id %d Enable %d Size %d\n",
898 algo_params.algo_id, algo_params.str_id,
899 algo_params.enable, algo_params.size);
900 retval = sst_create_algo_ipc(&algo_params, &msg);
901 if (retval)
902 break;
903 algo_params.reserved = 0;
904 if (copy_from_user(msg->mailbox_data + sizeof(algo_params),
905 algo_params.params, algo_params.size))
906 return -EFAULT;
907
908 retval = sst_send_algo_ipc(&msg);
909 if (retval) {
910 pr_debug("Error in sst_set_algo = %d\n", retval);
911 retval = -EIO;
912 }
913 break;
914
915 case _IOC_NR(SNDRV_SST_GET_ALGO):
916 if (copy_from_user(&algo_params, (void __user *)arg,
917 sizeof(algo_params)))
918 return -EFAULT;
919 pr_debug("Algo ID %d Str id %d Enable %d Size %d\n",
920 algo_params.algo_id, algo_params.str_id,
921 algo_params.enable, algo_params.size);
922 retval = sst_create_algo_ipc(&algo_params, &msg);
923 if (retval)
924 break;
925 algo_params.reserved = 1;
926 retval = sst_send_algo_ipc(&msg);
927 if (retval) {
928 pr_debug("Error in sst_get_algo = %d\n", retval);
929 retval = -EIO;
930 break;
931 }
932 algo_params_copied = (struct snd_ppp_params *)
933 sst_drv_ctx->ppp_params_blk.data;
934 if (algo_params_copied->size > algo_params.size) {
935 pr_debug("mem insufficient to copy\n");
936 retval = -EMSGSIZE;
937 goto free_mem;
938 } else {
939 char __user *tmp;
940
941 if (copy_to_user(algo_params.params,
942 algo_params_copied->params,
943 algo_params_copied->size)) {
944 retval = -EFAULT;
945 goto free_mem;
946 }
947 tmp = (char __user *)arg + offsetof(
948 struct snd_ppp_params, size);
949 if (copy_to_user(tmp, &algo_params_copied->size,
950 sizeof(__u32))) {
951 retval = -EFAULT;
952 goto free_mem;
953 }
954
955 }
956free_mem:
957 kfree(algo_params_copied->params);
958 kfree(algo_params_copied);
959 break;
960 }
961 return retval;
962}
963
964/**
965 * intel_sst_ioctl - receives the device ioctl's
810 * @file_ptr:pointer to file 966 * @file_ptr:pointer to file
811 * @cmd:Ioctl cmd 967 * @cmd:Ioctl cmd
812 * @arg:data 968 * @arg:data
@@ -832,7 +988,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
832 988
833 switch (_IOC_NR(cmd)) { 989 switch (_IOC_NR(cmd)) {
834 case _IOC_NR(SNDRV_SST_STREAM_PAUSE): 990 case _IOC_NR(SNDRV_SST_STREAM_PAUSE):
835 pr_debug("sst: IOCTL_PAUSE recieved for %d!\n", str_id); 991 pr_debug("IOCTL_PAUSE received for %d!\n", str_id);
836 if (minor != STREAM_MODULE) { 992 if (minor != STREAM_MODULE) {
837 retval = -EBADRQC; 993 retval = -EBADRQC;
838 break; 994 break;
@@ -841,7 +997,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
841 break; 997 break;
842 998
843 case _IOC_NR(SNDRV_SST_STREAM_RESUME): 999 case _IOC_NR(SNDRV_SST_STREAM_RESUME):
844 pr_debug("sst: SNDRV_SST_IOCTL_RESUME recieved!\n"); 1000 pr_debug("SNDRV_SST_IOCTL_RESUME received!\n");
845 if (minor != STREAM_MODULE) { 1001 if (minor != STREAM_MODULE) {
846 retval = -EBADRQC; 1002 retval = -EBADRQC;
847 break; 1003 break;
@@ -852,7 +1008,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
852 case _IOC_NR(SNDRV_SST_STREAM_SET_PARAMS): { 1008 case _IOC_NR(SNDRV_SST_STREAM_SET_PARAMS): {
853 struct snd_sst_params str_param; 1009 struct snd_sst_params str_param;
854 1010
855 pr_debug("sst: IOCTL_SET_PARAMS recieved!\n"); 1011 pr_debug("IOCTL_SET_PARAMS received!\n");
856 if (minor != STREAM_MODULE) { 1012 if (minor != STREAM_MODULE) {
857 retval = -EBADRQC; 1013 retval = -EBADRQC;
858 break; 1014 break;
@@ -884,7 +1040,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
884 retval = -EINVAL; 1040 retval = -EINVAL;
885 } 1041 }
886 } else { 1042 } else {
887 pr_debug("sst: SET_STREAM_PARAMS recieved!\n"); 1043 pr_debug("SET_STREAM_PARAMS received!\n");
888 /* allocated set params only */ 1044 /* allocated set params only */
889 retval = sst_set_stream_param(str_id, &str_param); 1045 retval = sst_set_stream_param(str_id, &str_param);
890 /* Block the call for reply */ 1046 /* Block the call for reply */
@@ -907,14 +1063,14 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
907 1063
908 if (copy_from_user(&set_vol, (void __user *)arg, 1064 if (copy_from_user(&set_vol, (void __user *)arg,
909 sizeof(set_vol))) { 1065 sizeof(set_vol))) {
910 pr_debug("sst: copy failed\n"); 1066 pr_debug("copy failed\n");
911 retval = -EFAULT; 1067 retval = -EFAULT;
912 break; 1068 break;
913 } 1069 }
914 pr_debug("sst: SET_VOLUME recieved for %d!\n", 1070 pr_debug("SET_VOLUME recieved for %d!\n",
915 set_vol.stream_id); 1071 set_vol.stream_id);
916 if (minor == STREAM_MODULE && set_vol.stream_id == 0) { 1072 if (minor == STREAM_MODULE && set_vol.stream_id == 0) {
917 pr_debug("sst: invalid operation!\n"); 1073 pr_debug("invalid operation!\n");
918 retval = -EPERM; 1074 retval = -EPERM;
919 break; 1075 break;
920 } 1076 }
@@ -929,10 +1085,10 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
929 retval = -EFAULT; 1085 retval = -EFAULT;
930 break; 1086 break;
931 } 1087 }
932 pr_debug("sst: IOCTL_GET_VOLUME recieved for stream = %d!\n", 1088 pr_debug("IOCTL_GET_VOLUME recieved for stream = %d!\n",
933 get_vol.stream_id); 1089 get_vol.stream_id);
934 if (minor == STREAM_MODULE && get_vol.stream_id == 0) { 1090 if (minor == STREAM_MODULE && get_vol.stream_id == 0) {
935 pr_debug("sst: invalid operation!\n"); 1091 pr_debug("invalid operation!\n");
936 retval = -EPERM; 1092 retval = -EPERM;
937 break; 1093 break;
938 } 1094 }
@@ -941,7 +1097,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
941 retval = -EIO; 1097 retval = -EIO;
942 break; 1098 break;
943 } 1099 }
944 pr_debug("sst: id:%d\n, vol:%d, ramp_dur:%d, ramp_type:%d\n", 1100 pr_debug("id:%d\n, vol:%d, ramp_dur:%d, ramp_type:%d\n",
945 get_vol.stream_id, get_vol.volume, 1101 get_vol.stream_id, get_vol.volume,
946 get_vol.ramp_duration, get_vol.ramp_type); 1102 get_vol.ramp_duration, get_vol.ramp_type);
947 if (copy_to_user((struct snd_sst_vol __user *)arg, 1103 if (copy_to_user((struct snd_sst_vol __user *)arg,
@@ -961,7 +1117,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
961 retval = -EFAULT; 1117 retval = -EFAULT;
962 break; 1118 break;
963 } 1119 }
964 pr_debug("sst: SNDRV_SST_SET_VOLUME recieved for %d!\n", 1120 pr_debug("SNDRV_SST_SET_VOLUME recieved for %d!\n",
965 set_mute.stream_id); 1121 set_mute.stream_id);
966 if (minor == STREAM_MODULE && set_mute.stream_id == 0) { 1122 if (minor == STREAM_MODULE && set_mute.stream_id == 0) {
967 retval = -EPERM; 1123 retval = -EPERM;
@@ -973,7 +1129,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
973 case _IOC_NR(SNDRV_SST_STREAM_GET_PARAMS): { 1129 case _IOC_NR(SNDRV_SST_STREAM_GET_PARAMS): {
974 struct snd_sst_get_stream_params get_params; 1130 struct snd_sst_get_stream_params get_params;
975 1131
976 pr_debug("sst: IOCTL_GET_PARAMS recieved!\n"); 1132 pr_debug("IOCTL_GET_PARAMS received!\n");
977 if (minor != 0) { 1133 if (minor != 0) {
978 retval = -EBADRQC; 1134 retval = -EBADRQC;
979 break; 1135 break;
@@ -997,7 +1153,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
997 case _IOC_NR(SNDRV_SST_MMAP_CAPTURE): { 1153 case _IOC_NR(SNDRV_SST_MMAP_CAPTURE): {
998 struct snd_sst_mmap_buffs mmap_buf; 1154 struct snd_sst_mmap_buffs mmap_buf;
999 1155
1000 pr_debug("sst: SNDRV_SST_MMAP_PLAY/CAPTURE recieved!\n"); 1156 pr_debug("SNDRV_SST_MMAP_PLAY/CAPTURE recieved!\n");
1001 if (minor != STREAM_MODULE) { 1157 if (minor != STREAM_MODULE) {
1002 retval = -EBADRQC; 1158 retval = -EBADRQC;
1003 break; 1159 break;
@@ -1011,7 +1167,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1011 break; 1167 break;
1012 } 1168 }
1013 case _IOC_NR(SNDRV_SST_STREAM_DROP): 1169 case _IOC_NR(SNDRV_SST_STREAM_DROP):
1014 pr_debug("sst: SNDRV_SST_IOCTL_DROP recieved!\n"); 1170 pr_debug("SNDRV_SST_IOCTL_DROP received!\n");
1015 if (minor != STREAM_MODULE) { 1171 if (minor != STREAM_MODULE) {
1016 retval = -EINVAL; 1172 retval = -EINVAL;
1017 break; 1173 break;
@@ -1023,7 +1179,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1023 struct snd_sst_tstamp tstamp = {0}; 1179 struct snd_sst_tstamp tstamp = {0};
1024 unsigned long long time, freq, mod; 1180 unsigned long long time, freq, mod;
1025 1181
1026 pr_debug("sst: SNDRV_SST_STREAM_GET_TSTAMP recieved!\n"); 1182 pr_debug("SNDRV_SST_STREAM_GET_TSTAMP received!\n");
1027 if (minor != STREAM_MODULE) { 1183 if (minor != STREAM_MODULE) {
1028 retval = -EBADRQC; 1184 retval = -EBADRQC;
1029 break; 1185 break;
@@ -1044,7 +1200,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1044 case _IOC_NR(SNDRV_SST_STREAM_START):{ 1200 case _IOC_NR(SNDRV_SST_STREAM_START):{
1045 struct stream_info *stream; 1201 struct stream_info *stream;
1046 1202
1047 pr_debug("sst: SNDRV_SST_STREAM_START recieved!\n"); 1203 pr_debug("SNDRV_SST_STREAM_START received!\n");
1048 if (minor != STREAM_MODULE) { 1204 if (minor != STREAM_MODULE) {
1049 retval = -EINVAL; 1205 retval = -EINVAL;
1050 break; 1206 break;
@@ -1083,7 +1239,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1083 case _IOC_NR(SNDRV_SST_SET_TARGET_DEVICE): { 1239 case _IOC_NR(SNDRV_SST_SET_TARGET_DEVICE): {
1084 struct snd_sst_target_device target_device; 1240 struct snd_sst_target_device target_device;
1085 1241
1086 pr_debug("sst: SET_TARGET_DEVICE recieved!\n"); 1242 pr_debug("SET_TARGET_DEVICE recieved!\n");
1087 if (copy_from_user(&target_device, (void __user *)arg, 1243 if (copy_from_user(&target_device, (void __user *)arg,
1088 sizeof(target_device))) { 1244 sizeof(target_device))) {
1089 retval = -EFAULT; 1245 retval = -EFAULT;
@@ -1100,7 +1256,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1100 case _IOC_NR(SNDRV_SST_DRIVER_INFO): { 1256 case _IOC_NR(SNDRV_SST_DRIVER_INFO): {
1101 struct snd_sst_driver_info info; 1257 struct snd_sst_driver_info info;
1102 1258
1103 pr_debug("sst: SNDRV_SST_DRIVER_INFO recived\n"); 1259 pr_debug("SNDRV_SST_DRIVER_INFO recived\n");
1104 info.version = SST_VERSION_NUM; 1260 info.version = SST_VERSION_NUM;
1105 /* hard coding, shud get sumhow later */ 1261 /* hard coding, shud get sumhow later */
1106 info.active_pcm_streams = sst_drv_ctx->stream_cnt - 1262 info.active_pcm_streams = sst_drv_ctx->stream_cnt -
@@ -1122,7 +1278,7 @@ long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd, unsigned long arg)
1122 struct snd_sst_buff_entry *ibuf_tmp, *obuf_tmp; 1278 struct snd_sst_buff_entry *ibuf_tmp, *obuf_tmp;
1123 char __user *dest; 1279 char __user *dest;
1124 1280
1125 pr_debug("sst: SNDRV_SST_STREAM_DECODE recived\n"); 1281 pr_debug("SNDRV_SST_STREAM_DECODE received\n");
1126 if (minor != STREAM_MODULE) { 1282 if (minor != STREAM_MODULE) {
1127 retval = -EBADRQC; 1283 retval = -EBADRQC;
1128 break; 1284 break;
@@ -1197,7 +1353,7 @@ free_iobufs:
1197 } 1353 }
1198 1354
1199 case _IOC_NR(SNDRV_SST_STREAM_DRAIN): 1355 case _IOC_NR(SNDRV_SST_STREAM_DRAIN):
1200 pr_debug("sst: SNDRV_SST_STREAM_DRAIN recived\n"); 1356 pr_debug("SNDRV_SST_STREAM_DRAIN received\n");
1201 if (minor != STREAM_MODULE) { 1357 if (minor != STREAM_MODULE) {
1202 retval = -EINVAL; 1358 retval = -EINVAL;
1203 break; 1359 break;
@@ -1209,7 +1365,7 @@ free_iobufs:
1209 unsigned long long __user *bytes = (unsigned long long __user *)arg; 1365 unsigned long long __user *bytes = (unsigned long long __user *)arg;
1210 struct snd_sst_tstamp tstamp = {0}; 1366 struct snd_sst_tstamp tstamp = {0};
1211 1367
1212 pr_debug("sst: STREAM_BYTES_DECODED recieved!\n"); 1368 pr_debug("STREAM_BYTES_DECODED received!\n");
1213 if (minor != STREAM_MODULE) { 1369 if (minor != STREAM_MODULE) {
1214 retval = -EINVAL; 1370 retval = -EINVAL;
1215 break; 1371 break;
@@ -1225,7 +1381,7 @@ free_iobufs:
1225 case _IOC_NR(SNDRV_SST_FW_INFO): { 1381 case _IOC_NR(SNDRV_SST_FW_INFO): {
1226 struct snd_sst_fw_info *fw_info; 1382 struct snd_sst_fw_info *fw_info;
1227 1383
1228 pr_debug("sst: SNDRV_SST_FW_INFO recived\n"); 1384 pr_debug("SNDRV_SST_FW_INFO received\n");
1229 1385
1230 fw_info = kzalloc(sizeof(*fw_info), GFP_ATOMIC); 1386 fw_info = kzalloc(sizeof(*fw_info), GFP_ATOMIC);
1231 if (!fw_info) { 1387 if (!fw_info) {
@@ -1248,10 +1404,18 @@ free_iobufs:
1248 kfree(fw_info); 1404 kfree(fw_info);
1249 break; 1405 break;
1250 } 1406 }
1407 case _IOC_NR(SNDRV_SST_GET_ALGO):
1408 case _IOC_NR(SNDRV_SST_SET_ALGO):
1409 if (minor != AM_MODULE) {
1410 retval = -EBADRQC;
1411 break;
1412 }
1413 retval = intel_sst_ioctl_dsp(cmd, arg);
1414 break;
1251 default: 1415 default:
1252 retval = -EINVAL; 1416 retval = -EINVAL;
1253 } 1417 }
1254 pr_debug("sst: intel_sst_ioctl:complete ret code = %d\n", retval); 1418 pr_debug("intel_sst_ioctl:complete ret code = %d\n", retval);
1255 return retval; 1419 return retval;
1256} 1420}
1257 1421
diff --git a/drivers/staging/intel_sst/intel_sst_common.h b/drivers/staging/intel_sst/intel_sst_common.h
index bf0ead78bfae..0a60e865b696 100644
--- a/drivers/staging/intel_sst/intel_sst_common.h
+++ b/drivers/staging/intel_sst/intel_sst_common.h
@@ -28,15 +28,15 @@
28 * Common private declarations for SST 28 * Common private declarations for SST
29 */ 29 */
30 30
31#define SST_DRIVER_VERSION "1.2.05" 31#define SST_DRIVER_VERSION "1.2.09"
32#define SST_VERSION_NUM 0x1205 32#define SST_VERSION_NUM 0x1209
33 33
34/* driver names */ 34/* driver names */
35#define SST_DRV_NAME "intel_sst_driver" 35#define SST_DRV_NAME "intel_sst_driver"
36#define SST_FW_FILENAME_MRST "fw_sst_080a.bin"
37#define SST_FW_FILENAME_MFLD "fw_sst_082f.bin"
38#define SST_MRST_PCI_ID 0x080A 36#define SST_MRST_PCI_ID 0x080A
39#define SST_MFLD_PCI_ID 0x082F 37#define SST_MFLD_PCI_ID 0x082F
38#define PCI_ID_LENGTH 4
39#define SST_SUSPEND_DELAY 2000
40 40
41enum sst_states { 41enum sst_states {
42 SST_FW_LOADED = 1, 42 SST_FW_LOADED = 1,
@@ -392,7 +392,7 @@ struct intel_sst_drv {
392 392
393 struct stream_info streams[MAX_NUM_STREAMS]; 393 struct stream_info streams[MAX_NUM_STREAMS];
394 struct stream_alloc_block alloc_block[MAX_ACTIVE_STREAM]; 394 struct stream_alloc_block alloc_block[MAX_ACTIVE_STREAM];
395 struct sst_block tgt_dev_blk, fw_info_blk, 395 struct sst_block tgt_dev_blk, fw_info_blk, ppp_params_blk,
396 vol_info_blk, mute_info_blk, hs_info_blk; 396 vol_info_blk, mute_info_blk, hs_info_blk;
397 struct mutex list_lock;/* mutex for IPC list locking */ 397 struct mutex list_lock;/* mutex for IPC list locking */
398 spinlock_t list_spin_lock; /* mutex for IPC list locking */ 398 spinlock_t list_spin_lock; /* mutex for IPC list locking */
diff --git a/drivers/staging/intel_sst/intel_sst_drv_interface.c b/drivers/staging/intel_sst/intel_sst_drv_interface.c
index 669e298016f2..ea8e251b5099 100644
--- a/drivers/staging/intel_sst/intel_sst_drv_interface.c
+++ b/drivers/staging/intel_sst/intel_sst_drv_interface.c
@@ -26,10 +26,13 @@
26 * Upper layer interfaces (MAD driver, MMF) to SST driver 26 * Upper layer interfaces (MAD driver, MMF) to SST driver
27 */ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/delay.h> 31#include <linux/delay.h>
30#include <linux/pci.h> 32#include <linux/pci.h>
31#include <linux/fs.h> 33#include <linux/fs.h>
32#include <linux/firmware.h> 34#include <linux/firmware.h>
35#include <linux/pm_runtime.h>
33#include "intel_sst.h" 36#include "intel_sst.h"
34#include "intel_sst_ioctl.h" 37#include "intel_sst_ioctl.h"
35#include "intel_sst_fw_ipc.h" 38#include "intel_sst_fw_ipc.h"
@@ -45,17 +48,18 @@ int sst_download_fw(void)
45{ 48{
46 int retval; 49 int retval;
47 const struct firmware *fw_sst; 50 const struct firmware *fw_sst;
48 const char *name; 51 char name[20];
52
49 if (sst_drv_ctx->sst_state != SST_UN_INIT) 53 if (sst_drv_ctx->sst_state != SST_UN_INIT)
50 return -EPERM; 54 return -EPERM;
51 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID) 55
52 name = SST_FW_FILENAME_MRST; 56 snprintf(name, sizeof(name), "%s%04x%s", "fw_sst_",
53 else 57 sst_drv_ctx->pci_id, ".bin");
54 name = SST_FW_FILENAME_MFLD; 58
55 pr_debug("sst: Downloading %s FW now...\n", name); 59 pr_debug("Downloading %s FW now...\n", name);
56 retval = request_firmware(&fw_sst, name, &sst_drv_ctx->pci->dev); 60 retval = request_firmware(&fw_sst, name, &sst_drv_ctx->pci->dev);
57 if (retval) { 61 if (retval) {
58 pr_err("sst: request fw failed %d\n", retval); 62 pr_err("request fw failed %d\n", retval);
59 return retval; 63 return retval;
60 } 64 }
61 sst_drv_ctx->alloc_block[0].sst_id = FW_DWNL_ID; 65 sst_drv_ctx->alloc_block[0].sst_id = FW_DWNL_ID;
@@ -66,7 +70,7 @@ int sst_download_fw(void)
66 70
67 retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[0]); 71 retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[0]);
68 if (retval) 72 if (retval)
69 pr_err("sst: fw download failed %d\n" , retval); 73 pr_err("fw download failed %d\n" , retval);
70end_restore: 74end_restore:
71 release_firmware(fw_sst); 75 release_firmware(fw_sst);
72 sst_drv_ctx->alloc_block[0].sst_id = BLOCK_UNINIT; 76 sst_drv_ctx->alloc_block[0].sst_id = BLOCK_UNINIT;
@@ -90,7 +94,7 @@ int sst_stalled(void)
90 94
91 retry--; 95 retry--;
92 } 96 }
93 pr_debug("sst: in Stalled State\n"); 97 pr_debug("in Stalled State\n");
94 return retval; 98 return retval;
95} 99}
96 100
@@ -138,23 +142,23 @@ int sst_get_stream_allocated(struct snd_sst_params *str_param,
138 retval = sst_alloc_stream((char *) &str_param->sparams, str_param->ops, 142 retval = sst_alloc_stream((char *) &str_param->sparams, str_param->ops,
139 str_param->codec, str_param->device_type); 143 str_param->codec, str_param->device_type);
140 if (retval < 0) { 144 if (retval < 0) {
141 pr_err("sst: sst_alloc_stream failed %d\n", retval); 145 pr_err("sst_alloc_stream failed %d\n", retval);
142 return retval; 146 return retval;
143 } 147 }
144 pr_debug("sst: Stream allocated %d\n", retval); 148 pr_debug("Stream allocated %d\n", retval);
145 str_id = retval; 149 str_id = retval;
146 str_info = &sst_drv_ctx->streams[str_id]; 150 str_info = &sst_drv_ctx->streams[str_id];
147 /* Block the call for reply */ 151 /* Block the call for reply */
148 retval = sst_wait_interruptible_timeout(sst_drv_ctx, 152 retval = sst_wait_interruptible_timeout(sst_drv_ctx,
149 &str_info->ctrl_blk, SST_BLOCK_TIMEOUT); 153 &str_info->ctrl_blk, SST_BLOCK_TIMEOUT);
150 if ((retval != 0) || (str_info->ctrl_blk.ret_code != 0)) { 154 if ((retval != 0) || (str_info->ctrl_blk.ret_code != 0)) {
151 pr_debug("sst: FW alloc failed retval %d, ret_code %d\n", 155 pr_debug("FW alloc failed retval %d, ret_code %d\n",
152 retval, str_info->ctrl_blk.ret_code); 156 retval, str_info->ctrl_blk.ret_code);
153 str_id = -str_info->ctrl_blk.ret_code; /*return error*/ 157 str_id = -str_info->ctrl_blk.ret_code; /*return error*/
154 *lib_dnld = str_info->ctrl_blk.data; 158 *lib_dnld = str_info->ctrl_blk.data;
155 sst_clean_stream(str_info); 159 sst_clean_stream(str_info);
156 } else 160 } else
157 pr_debug("sst: FW Stream allocated sucess\n"); 161 pr_debug("FW Stream allocated success\n");
158 return str_id; /*will ret either error (in above if) or correct str id*/ 162 return str_id; /*will ret either error (in above if) or correct str id*/
159} 163}
160 164
@@ -171,9 +175,9 @@ static int sst_get_sfreq(struct snd_sst_params *str_param)
171 case SST_CODEC_TYPE_MP3: 175 case SST_CODEC_TYPE_MP3:
172 return str_param->sparams.uc.mp3_params.sfreq; 176 return str_param->sparams.uc.mp3_params.sfreq;
173 case SST_CODEC_TYPE_AAC: 177 case SST_CODEC_TYPE_AAC:
174 return str_param->sparams.uc.aac_params.sfreq;; 178 return str_param->sparams.uc.aac_params.sfreq;
175 case SST_CODEC_TYPE_WMA9: 179 case SST_CODEC_TYPE_WMA9:
176 return str_param->sparams.uc.wma_params.sfreq;; 180 return str_param->sparams.uc.wma_params.sfreq;
177 default: 181 default:
178 return 0; 182 return 0;
179 } 183 }
@@ -196,14 +200,14 @@ int sst_get_stream(struct snd_sst_params *str_param)
196 /* codec download is required */ 200 /* codec download is required */
197 struct snd_sst_alloc_response *response; 201 struct snd_sst_alloc_response *response;
198 202
199 pr_debug("sst: Codec is required.... trying that\n"); 203 pr_debug("Codec is required.... trying that\n");
200 if (lib_dnld == NULL) { 204 if (lib_dnld == NULL) {
201 pr_err("sst: lib download null!!! abort\n"); 205 pr_err("lib download null!!! abort\n");
202 return -EIO; 206 return -EIO;
203 } 207 }
204 i = sst_get_block_stream(sst_drv_ctx); 208 i = sst_get_block_stream(sst_drv_ctx);
205 response = sst_drv_ctx->alloc_block[i].ops_block.data; 209 response = sst_drv_ctx->alloc_block[i].ops_block.data;
206 pr_debug("sst: alloc block allocated = %d\n", i); 210 pr_debug("alloc block allocated = %d\n", i);
207 if (i < 0) { 211 if (i < 0) {
208 kfree(lib_dnld); 212 kfree(lib_dnld);
209 return -ENOMEM; 213 return -ENOMEM;
@@ -213,15 +217,15 @@ int sst_get_stream(struct snd_sst_params *str_param)
213 217
214 sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT; 218 sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
215 if (!retval) { 219 if (!retval) {
216 pr_debug("sst: codec was downloaded sucesfully\n"); 220 pr_debug("codec was downloaded successfully\n");
217 221
218 retval = sst_get_stream_allocated(str_param, &lib_dnld); 222 retval = sst_get_stream_allocated(str_param, &lib_dnld);
219 if (retval <= 0) 223 if (retval <= 0)
220 goto err; 224 goto err;
221 225
222 pr_debug("sst: Alloc done stream id %d\n", retval); 226 pr_debug("Alloc done stream id %d\n", retval);
223 } else { 227 } else {
224 pr_debug("sst: codec download failed\n"); 228 pr_debug("codec download failed\n");
225 retval = -EIO; 229 retval = -EIO;
226 goto err; 230 goto err;
227 } 231 }
@@ -279,97 +283,138 @@ void sst_process_mad_ops(struct work_struct *work)
279 retval = sst_start_stream(mad_ops->stream_id); 283 retval = sst_start_stream(mad_ops->stream_id);
280 break; 284 break;
281 case SST_SND_STREAM_PROCESS: 285 case SST_SND_STREAM_PROCESS:
282 pr_debug("sst: play/capt frames...\n"); 286 pr_debug("play/capt frames...\n");
283 break; 287 break;
284 default: 288 default:
285 pr_err("sst: wrong control_ops reported\n"); 289 pr_err(" wrong control_ops reported\n");
286 } 290 }
287 return; 291 return;
288} 292}
293
294void send_intial_rx_timeslot(void)
295{
296 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID &&
297 sst_drv_ctx->rx_time_slot_status != RX_TIMESLOT_UNINIT
298 && sst_drv_ctx->pmic_vendor != SND_NC)
299 sst_enable_rx_timeslot(sst_drv_ctx->rx_time_slot_status);
300}
301
289/* 302/*
290 * sst_control_set - Set Control params 303 * sst_open_pcm_stream - Open PCM interface
291 * 304 *
292 * @control_list: list of controls to be set 305 * @str_param: parameters of pcm stream
293 * 306 *
294 * This function is called by MID sound card driver to set 307 * This function is called by MID sound card driver to open
295 * SST/Sound card controls. This is registered with MID driver 308 * a new pcm interface
296 */ 309 */
297int sst_control_set(int control_element, void *value) 310int sst_open_pcm_stream(struct snd_sst_params *str_param)
298{ 311{
299 int retval = 0, str_id = 0; 312 struct stream_info *str_info;
300 struct stream_info *stream; 313 int retval;
314
315 pm_runtime_get_sync(&sst_drv_ctx->pci->dev);
301 316
302 if (sst_drv_ctx->sst_state == SST_SUSPENDED) { 317 if (sst_drv_ctx->sst_state == SST_SUSPENDED) {
303 /*LPE is suspended, resume it before proceding*/ 318 /* LPE is suspended, resume it before proceding*/
304 pr_debug("sst: Resuming from Suspended state\n"); 319 pr_debug("Resuming from Suspended state\n");
305 retval = intel_sst_resume(sst_drv_ctx->pci); 320 retval = intel_sst_resume(sst_drv_ctx->pci);
306 if (retval) { 321 if (retval) {
307 pr_err("sst: Resume Failed = %#x, abort\n", retval); 322 pr_err("Resume Failed = %#x, abort\n", retval);
323 pm_runtime_put(&sst_drv_ctx->pci->dev);
308 return retval; 324 return retval;
309 } 325 }
310 } 326 }
311 if (sst_drv_ctx->sst_state == SST_UN_INIT) { 327 if (sst_drv_ctx->sst_state == SST_UN_INIT) {
312 /* FW is not downloaded */ 328 /* FW is not downloaded */
313 pr_debug("sst: DSP Downloading FW now...\n"); 329 pr_debug("DSP Downloading FW now...\n");
314 retval = sst_download_fw(); 330 retval = sst_download_fw();
315 if (retval) { 331 if (retval) {
316 pr_err("sst: FW download fail %x, abort\n", retval); 332 pr_err("FW download fail %x, abort\n", retval);
333 pm_runtime_put(&sst_drv_ctx->pci->dev);
317 return retval; 334 return retval;
318 } 335 }
319 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID && 336 send_intial_rx_timeslot();
320 sst_drv_ctx->rx_time_slot_status != RX_TIMESLOT_UNINIT
321 && sst_drv_ctx->pmic_vendor != SND_NC)
322 sst_enable_rx_timeslot(
323 sst_drv_ctx->rx_time_slot_status);
324 } 337 }
325 338
326 switch (control_element) { 339 if (!str_param) {
327 case SST_SND_ALLOC: { 340 pm_runtime_put(&sst_drv_ctx->pci->dev);
328 struct snd_sst_params *str_param; 341 return -EINVAL;
329 struct stream_info *str_info; 342 }
330 343
331 str_param = (struct snd_sst_params *)value; 344 retval = sst_get_stream(str_param);
332 BUG_ON(!str_param); 345 if (retval > 0) {
333 retval = sst_get_stream(str_param); 346 sst_drv_ctx->stream_cnt++;
334 if (retval >= 0)
335 sst_drv_ctx->stream_cnt++;
336 str_info = &sst_drv_ctx->streams[retval]; 347 str_info = &sst_drv_ctx->streams[retval];
337 str_info->src = MAD_DRV; 348 str_info->src = MAD_DRV;
338 break; 349 } else
339 } 350 pm_runtime_put(&sst_drv_ctx->pci->dev);
351
352 return retval;
353}
340 354
355/*
356 * sst_close_pcm_stream - Close PCM interface
357 *
358 * @str_id: stream id to be closed
359 *
360 * This function is called by MID sound card driver to close
361 * an existing pcm interface
362 */
363int sst_close_pcm_stream(unsigned int str_id)
364{
365 struct stream_info *stream;
366
367 pr_debug("sst: stream free called\n");
368 if (sst_validate_strid(str_id))
369 return -EINVAL;
370 stream = &sst_drv_ctx->streams[str_id];
371 free_stream_context(str_id);
372 stream->pcm_substream = NULL;
373 stream->status = STREAM_UN_INIT;
374 stream->period_elapsed = NULL;
375 sst_drv_ctx->stream_cnt--;
376 pr_debug("sst: will call runtime put now\n");
377 pm_runtime_put(&sst_drv_ctx->pci->dev);
378 return 0;
379}
380
381/*
382 * sst_device_control - Set Control params
383 *
384 * @cmd: control cmd to be set
385 * @arg: command argument
386 *
387 * This function is called by MID sound card driver to set
388 * SST/Sound card controls for an opened stream.
389 * This is registered with MID driver
390 */
391int sst_device_control(int cmd, void *arg)
392{
393 int retval = 0, str_id = 0;
394
395 switch (cmd) {
341 case SST_SND_PAUSE: 396 case SST_SND_PAUSE:
342 case SST_SND_RESUME: 397 case SST_SND_RESUME:
343 case SST_SND_DROP: 398 case SST_SND_DROP:
344 case SST_SND_START: 399 case SST_SND_START:
345 sst_drv_ctx->mad_ops.control_op = control_element; 400 sst_drv_ctx->mad_ops.control_op = cmd;
346 sst_drv_ctx->mad_ops.stream_id = *(int *)value; 401 sst_drv_ctx->mad_ops.stream_id = *(int *)arg;
347 queue_work(sst_drv_ctx->mad_wq, &sst_drv_ctx->mad_ops.wq); 402 queue_work(sst_drv_ctx->mad_wq, &sst_drv_ctx->mad_ops.wq);
348 break; 403 break;
349 404
350 case SST_SND_FREE:
351 str_id = *(int *)value;
352 stream = &sst_drv_ctx->streams[str_id];
353 free_stream_context(str_id);
354 stream->pcm_substream = NULL;
355 stream->status = STREAM_UN_INIT;
356 stream->period_elapsed = NULL;
357 sst_drv_ctx->stream_cnt--;
358 break;
359
360 case SST_SND_STREAM_INIT: { 405 case SST_SND_STREAM_INIT: {
361 struct pcm_stream_info *str_info; 406 struct pcm_stream_info *str_info;
362 struct stream_info *stream; 407 struct stream_info *stream;
363 408
364 pr_debug("sst: stream init called\n"); 409 pr_debug("stream init called\n");
365 str_info = (struct pcm_stream_info *)value; 410 str_info = (struct pcm_stream_info *)arg;
366 str_id = str_info->str_id; 411 str_id = str_info->str_id;
367 retval = sst_validate_strid(str_id); 412 retval = sst_validate_strid(str_id);
368 if (retval) 413 if (retval)
369 break; 414 break;
370 415
371 stream = &sst_drv_ctx->streams[str_id]; 416 stream = &sst_drv_ctx->streams[str_id];
372 pr_debug("sst: setting the period ptrs\n"); 417 pr_debug("setting the period ptrs\n");
373 stream->pcm_substream = str_info->mad_substream; 418 stream->pcm_substream = str_info->mad_substream;
374 stream->period_elapsed = str_info->period_elapsed; 419 stream->period_elapsed = str_info->period_elapsed;
375 stream->sfreq = str_info->sfreq; 420 stream->sfreq = str_info->sfreq;
@@ -384,7 +429,7 @@ int sst_control_set(int control_element, void *value)
384 struct stream_info *stream; 429 struct stream_info *stream;
385 430
386 431
387 stream_info = (struct pcm_stream_info *)value; 432 stream_info = (struct pcm_stream_info *)arg;
388 str_id = stream_info->str_id; 433 str_id = stream_info->str_id;
389 retval = sst_validate_strid(str_id); 434 retval = sst_validate_strid(str_id);
390 if (retval) 435 if (retval)
@@ -398,26 +443,26 @@ int sst_control_set(int control_element, void *value)
398 +(str_id * sizeof(fw_tstamp))), 443 +(str_id * sizeof(fw_tstamp))),
399 sizeof(fw_tstamp)); 444 sizeof(fw_tstamp));
400 445
401 pr_debug("sst: Pointer Query on strid = %d ops %d\n", 446 pr_debug("Pointer Query on strid = %d ops %d\n",
402 str_id, stream->ops); 447 str_id, stream->ops);
403 448
404 if (stream->ops == STREAM_OPS_PLAYBACK) 449 if (stream->ops == STREAM_OPS_PLAYBACK)
405 stream_info->buffer_ptr = fw_tstamp.samples_rendered; 450 stream_info->buffer_ptr = fw_tstamp.samples_rendered;
406 else 451 else
407 stream_info->buffer_ptr = fw_tstamp.samples_processed; 452 stream_info->buffer_ptr = fw_tstamp.samples_processed;
408 pr_debug("sst: Samples rendered = %llu, buffer ptr %llu\n", 453 pr_debug("Samples rendered = %llu, buffer ptr %llu\n",
409 fw_tstamp.samples_rendered, stream_info->buffer_ptr); 454 fw_tstamp.samples_rendered, stream_info->buffer_ptr);
410 break; 455 break;
411 } 456 }
412 case SST_ENABLE_RX_TIME_SLOT: { 457 case SST_ENABLE_RX_TIME_SLOT: {
413 int status = *(int *)value; 458 int status = *(int *)arg;
414 sst_drv_ctx->rx_time_slot_status = status ; 459 sst_drv_ctx->rx_time_slot_status = status ;
415 sst_enable_rx_timeslot(status); 460 sst_enable_rx_timeslot(status);
416 break; 461 break;
417 } 462 }
418 default: 463 default:
419 /* Illegal case */ 464 /* Illegal case */
420 pr_warn("sst: illegal req\n"); 465 pr_warn("illegal req\n");
421 return -EINVAL; 466 return -EINVAL;
422 } 467 }
423 468
@@ -425,8 +470,14 @@ int sst_control_set(int control_element, void *value)
425} 470}
426 471
427 472
473struct intel_sst_pcm_control pcm_ops = {
474 .open = sst_open_pcm_stream,
475 .device_control = sst_device_control,
476 .close = sst_close_pcm_stream,
477};
478
428struct intel_sst_card_ops sst_pmic_ops = { 479struct intel_sst_card_ops sst_pmic_ops = {
429 .control_set = sst_control_set, 480 .pcm_control = &pcm_ops,
430}; 481};
431 482
432/* 483/*
@@ -439,12 +490,12 @@ struct intel_sst_card_ops sst_pmic_ops = {
439int register_sst_card(struct intel_sst_card_ops *card) 490int register_sst_card(struct intel_sst_card_ops *card)
440{ 491{
441 if (!sst_drv_ctx) { 492 if (!sst_drv_ctx) {
442 pr_err("sst: No SST driver register card reject\n"); 493 pr_err("No SST driver register card reject\n");
443 return -ENODEV; 494 return -ENODEV;
444 } 495 }
445 496
446 if (!card || !card->module_name) { 497 if (!card || !card->module_name) {
447 pr_err("sst: Null Pointer Passed\n"); 498 pr_err("Null Pointer Passed\n");
448 return -EINVAL; 499 return -EINVAL;
449 } 500 }
450 if (sst_drv_ctx->pmic_state == SND_MAD_UN_INIT) { 501 if (sst_drv_ctx->pmic_state == SND_MAD_UN_INIT) {
@@ -456,17 +507,17 @@ int register_sst_card(struct intel_sst_card_ops *card)
456 sst_pmic_ops.module_name = card->module_name; 507 sst_pmic_ops.module_name = card->module_name;
457 sst_drv_ctx->pmic_state = SND_MAD_INIT_DONE; 508 sst_drv_ctx->pmic_state = SND_MAD_INIT_DONE;
458 sst_drv_ctx->rx_time_slot_status = 0; /*default AMIC*/ 509 sst_drv_ctx->rx_time_slot_status = 0; /*default AMIC*/
459 card->control_set = sst_pmic_ops.control_set; 510 card->pcm_control = sst_pmic_ops.pcm_control;
460 sst_drv_ctx->scard_ops->card_status = SND_CARD_UN_INIT; 511 sst_drv_ctx->scard_ops->card_status = SND_CARD_UN_INIT;
461 return 0; 512 return 0;
462 } else { 513 } else {
463 pr_err("sst: strcmp fail %s\n", card->module_name); 514 pr_err("strcmp fail %s\n", card->module_name);
464 return -EINVAL; 515 return -EINVAL;
465 } 516 }
466 517
467 } else { 518 } else {
468 /* already registered a driver */ 519 /* already registered a driver */
469 pr_err("sst: Repeat for registeration..denied\n"); 520 pr_err("Repeat for registration..denied\n");
470 return -EBADRQC; 521 return -EBADRQC;
471 } 522 }
472 return 0; 523 return 0;
@@ -482,11 +533,11 @@ EXPORT_SYMBOL_GPL(register_sst_card);
482 */ 533 */
483void unregister_sst_card(struct intel_sst_card_ops *card) 534void unregister_sst_card(struct intel_sst_card_ops *card)
484{ 535{
485 if (sst_pmic_ops.control_set == card->control_set) { 536 if (sst_pmic_ops.pcm_control == card->pcm_control) {
486 /* unreg */ 537 /* unreg */
487 sst_pmic_ops.module_name = ""; 538 sst_pmic_ops.module_name = "";
488 sst_drv_ctx->pmic_state = SND_MAD_UN_INIT; 539 sst_drv_ctx->pmic_state = SND_MAD_UN_INIT;
489 pr_debug("sst: Unregistered %s\n", card->module_name); 540 pr_debug("Unregistered %s\n", card->module_name);
490 } 541 }
491 return; 542 return;
492} 543}
diff --git a/drivers/staging/intel_sst/intel_sst_dsp.c b/drivers/staging/intel_sst/intel_sst_dsp.c
index d80a6ee2deb8..6e5c9152da9f 100644
--- a/drivers/staging/intel_sst/intel_sst_dsp.c
+++ b/drivers/staging/intel_sst/intel_sst_dsp.c
@@ -29,6 +29,9 @@
29 * This file contains all dsp controlling functions like firmware download, 29 * This file contains all dsp controlling functions like firmware download,
30 * setting/resetting dsp cores, etc 30 * setting/resetting dsp cores, etc
31 */ 31 */
32
33#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34
32#include <linux/pci.h> 35#include <linux/pci.h>
33#include <linux/fs.h> 36#include <linux/fs.h>
34#include <linux/firmware.h> 37#include <linux/firmware.h>
@@ -47,8 +50,9 @@ static int intel_sst_reset_dsp_mrst(void)
47{ 50{
48 union config_status_reg csr; 51 union config_status_reg csr;
49 52
50 pr_debug("sst: Resetting the DSP in mrst\n"); 53 pr_debug("Resetting the DSP in mrst\n");
51 csr.full = 0x3a2; 54 csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
55 csr.full |= 0x382;
52 sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full); 56 sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
53 csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR); 57 csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR);
54 csr.part.strb_cntr_rst = 0; 58 csr.part.strb_cntr_rst = 0;
@@ -68,7 +72,7 @@ static int intel_sst_reset_dsp_medfield(void)
68{ 72{
69 union config_status_reg csr; 73 union config_status_reg csr;
70 74
71 pr_debug("sst: Resetting the DSP in medfield\n"); 75 pr_debug("Resetting the DSP in medfield\n");
72 csr.full = 0x048303E2; 76 csr.full = 0x048303E2;
73 sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full); 77 sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
74 78
@@ -90,7 +94,7 @@ static int sst_start_mrst(void)
90 csr.part.run_stall = 0; 94 csr.part.run_stall = 0;
91 csr.part.sst_reset = 0; 95 csr.part.sst_reset = 0;
92 csr.part.strb_cntr_rst = 1; 96 csr.part.strb_cntr_rst = 1;
93 pr_debug("sst: Setting SST to execute_mrst 0x%x\n", csr.full); 97 pr_debug("Setting SST to execute_mrst 0x%x\n", csr.full);
94 sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full); 98 sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
95 99
96 return 0; 100 return 0;
@@ -111,7 +115,7 @@ static int sst_start_medfield(void)
111 sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full); 115 sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
112 csr.full = 0x04830061; 116 csr.full = 0x04830061;
113 sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full); 117 sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full);
114 pr_debug("sst: Starting the DSP_medfld\n"); 118 pr_debug("Starting the DSP_medfld\n");
115 119
116 return 0; 120 return 0;
117} 121}
@@ -130,16 +134,16 @@ static int sst_parse_module(struct fw_module_header *module)
130 u32 count; 134 u32 count;
131 void __iomem *ram; 135 void __iomem *ram;
132 136
133 pr_debug("sst: module sign %s size %x blocks %x type %x\n", 137 pr_debug("module sign %s size %x blocks %x type %x\n",
134 module->signature, module->mod_size, 138 module->signature, module->mod_size,
135 module->blocks, module->type); 139 module->blocks, module->type);
136 pr_debug("sst: module entrypoint 0x%x\n", module->entry_point); 140 pr_debug("module entrypoint 0x%x\n", module->entry_point);
137 141
138 block = (void *)module + sizeof(*module); 142 block = (void *)module + sizeof(*module);
139 143
140 for (count = 0; count < module->blocks; count++) { 144 for (count = 0; count < module->blocks; count++) {
141 if (block->size <= 0) { 145 if (block->size <= 0) {
142 pr_err("sst: block size invalid\n"); 146 pr_err("block size invalid\n");
143 return -EINVAL; 147 return -EINVAL;
144 } 148 }
145 switch (block->type) { 149 switch (block->type) {
@@ -150,7 +154,7 @@ static int sst_parse_module(struct fw_module_header *module)
150 ram = sst_drv_ctx->dram; 154 ram = sst_drv_ctx->dram;
151 break; 155 break;
152 default: 156 default:
153 pr_err("sst: wrong ram type0x%x in block0x%x\n", 157 pr_err("wrong ram type0x%x in block0x%x\n",
154 block->type, count); 158 block->type, count);
155 return -EINVAL; 159 return -EINVAL;
156 } 160 }
@@ -184,10 +188,10 @@ static int sst_parse_fw_image(const struct firmware *sst_fw)
184 if ((strncmp(header->signature, SST_FW_SIGN, 4) != 0) || 188 if ((strncmp(header->signature, SST_FW_SIGN, 4) != 0) ||
185 (sst_fw->size != header->file_size + sizeof(*header))) { 189 (sst_fw->size != header->file_size + sizeof(*header))) {
186 /* Invalid FW signature */ 190 /* Invalid FW signature */
187 pr_err("sst: InvalidFW sign/filesize mismatch\n"); 191 pr_err("Invalid FW sign/filesize mismatch\n");
188 return -EINVAL; 192 return -EINVAL;
189 } 193 }
190 pr_debug("sst: header sign=%s size=%x modules=%x fmt=%x size=%x\n", 194 pr_debug("header sign=%s size=%x modules=%x fmt=%x size=%x\n",
191 header->signature, header->file_size, header->modules, 195 header->signature, header->file_size, header->modules,
192 header->file_format, sizeof(*header)); 196 header->file_format, sizeof(*header));
193 module = (void *)sst_fw->data + sizeof(*header); 197 module = (void *)sst_fw->data + sizeof(*header);
@@ -214,7 +218,7 @@ int sst_load_fw(const struct firmware *fw, void *context)
214{ 218{
215 int ret_val; 219 int ret_val;
216 220
217 pr_debug("sst: load_fw called\n"); 221 pr_debug("load_fw called\n");
218 BUG_ON(!fw); 222 BUG_ON(!fw);
219 223
220 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID) 224 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID)
@@ -239,7 +243,7 @@ int sst_load_fw(const struct firmware *fw, void *context)
239 if (ret_val) 243 if (ret_val)
240 return ret_val; 244 return ret_val;
241 245
242 pr_debug("sst: fw loaded successful!!!\n"); 246 pr_debug("fw loaded successful!!!\n");
243 return ret_val; 247 return ret_val;
244} 248}
245 249
@@ -261,7 +265,7 @@ static int sst_download_library(const struct firmware *fw_lib,
261 265
262 pvt_id = sst_assign_pvt_id(sst_drv_ctx); 266 pvt_id = sst_assign_pvt_id(sst_drv_ctx);
263 i = sst_get_block_stream(sst_drv_ctx); 267 i = sst_get_block_stream(sst_drv_ctx);
264 pr_debug("sst: alloc block allocated = %d, pvt_id %d\n", i, pvt_id); 268 pr_debug("alloc block allocated = %d, pvt_id %d\n", i, pvt_id);
265 if (i < 0) { 269 if (i < 0) {
266 kfree(msg); 270 kfree(msg);
267 return -ENOMEM; 271 return -ENOMEM;
@@ -281,11 +285,11 @@ static int sst_download_library(const struct firmware *fw_lib,
281 if (retval) { 285 if (retval) {
282 /* error */ 286 /* error */
283 sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT; 287 sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
284 pr_err("sst: Prep codec downloaded failed %d\n", 288 pr_err("Prep codec downloaded failed %d\n",
285 retval); 289 retval);
286 return -EIO; 290 return -EIO;
287 } 291 }
288 pr_debug("sst: FW responded, ready for download now...\n"); 292 pr_debug("FW responded, ready for download now...\n");
289 /* downloading on success */ 293 /* downloading on success */
290 mutex_lock(&sst_drv_ctx->sst_lock); 294 mutex_lock(&sst_drv_ctx->sst_lock);
291 sst_drv_ctx->sst_state = SST_FW_LOADED; 295 sst_drv_ctx->sst_state = SST_FW_LOADED;
@@ -325,7 +329,7 @@ static int sst_download_library(const struct firmware *fw_lib,
325 list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list); 329 list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
326 spin_unlock(&sst_drv_ctx->list_spin_lock); 330 spin_unlock(&sst_drv_ctx->list_spin_lock);
327 sst_post_message(&sst_drv_ctx->ipc_post_msg_wq); 331 sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
328 pr_debug("sst: Waiting for FW response Download complete\n"); 332 pr_debug("Waiting for FW response Download complete\n");
329 sst_drv_ctx->alloc_block[i].ops_block.condition = false; 333 sst_drv_ctx->alloc_block[i].ops_block.condition = false;
330 retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[i]); 334 retval = sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[i]);
331 if (retval) { 335 if (retval) {
@@ -337,7 +341,7 @@ static int sst_download_library(const struct firmware *fw_lib,
337 return -EIO; 341 return -EIO;
338 } 342 }
339 343
340 pr_debug("sst: FW sucess on Download complete\n"); 344 pr_debug("FW success on Download complete\n");
341 sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT; 345 sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT;
342 mutex_lock(&sst_drv_ctx->sst_lock); 346 mutex_lock(&sst_drv_ctx->sst_lock);
343 sst_drv_ctx->sst_state = SST_FW_RUNNING; 347 sst_drv_ctx->sst_state = SST_FW_RUNNING;
@@ -360,14 +364,14 @@ static int sst_validate_library(const struct firmware *fw_lib,
360 364
361 header = (struct fw_header *)fw_lib->data; 365 header = (struct fw_header *)fw_lib->data;
362 if (header->modules != 1) { 366 if (header->modules != 1) {
363 pr_err("sst: Module no mismatch found\n "); 367 pr_err("Module no mismatch found\n");
364 err = -EINVAL; 368 err = -EINVAL;
365 goto exit; 369 goto exit;
366 } 370 }
367 module = (void *)fw_lib->data + sizeof(*header); 371 module = (void *)fw_lib->data + sizeof(*header);
368 *entry_point = module->entry_point; 372 *entry_point = module->entry_point;
369 pr_debug("sst: Module entry point 0x%x\n", *entry_point); 373 pr_debug("Module entry point 0x%x\n", *entry_point);
370 pr_debug("sst: Module Sign %s, Size 0x%x, Blocks 0x%x Type 0x%x\n", 374 pr_debug("Module Sign %s, Size 0x%x, Blocks 0x%x Type 0x%x\n",
371 module->signature, module->mod_size, 375 module->signature, module->mod_size,
372 module->blocks, module->type); 376 module->blocks, module->type);
373 377
@@ -381,20 +385,20 @@ static int sst_validate_library(const struct firmware *fw_lib,
381 dsize += block->size; 385 dsize += block->size;
382 break; 386 break;
383 default: 387 default:
384 pr_err("sst: Invalid block type for 0x%x\n", n_blk); 388 pr_err("Invalid block type for 0x%x\n", n_blk);
385 err = -EINVAL; 389 err = -EINVAL;
386 goto exit; 390 goto exit;
387 } 391 }
388 block = (void *)block + sizeof(*block) + block->size; 392 block = (void *)block + sizeof(*block) + block->size;
389 } 393 }
390 if (isize > slot->iram_size || dsize > slot->dram_size) { 394 if (isize > slot->iram_size || dsize > slot->dram_size) {
391 pr_err("sst: library exceeds size allocated\n"); 395 pr_err("library exceeds size allocated\n");
392 err = -EINVAL; 396 err = -EINVAL;
393 goto exit; 397 goto exit;
394 } else 398 } else
395 pr_debug("sst: Library is safe for download...\n"); 399 pr_debug("Library is safe for download...\n");
396 400
397 pr_debug("sst: iram 0x%x, dram 0x%x, iram 0x%x, dram 0x%x\n", 401 pr_debug("iram 0x%x, dram 0x%x, iram 0x%x, dram 0x%x\n",
398 isize, dsize, slot->iram_size, slot->dram_size); 402 isize, dsize, slot->iram_size, slot->dram_size);
399exit: 403exit:
400 return err; 404 return err;
@@ -414,15 +418,15 @@ int sst_load_library(struct snd_sst_lib_download *lib, u8 ops)
414 418
415 memset(buf, 0, sizeof(buf)); 419 memset(buf, 0, sizeof(buf));
416 420
417 pr_debug("sst: Lib Type 0x%x, Slot 0x%x, ops 0x%x\n", 421 pr_debug("Lib Type 0x%x, Slot 0x%x, ops 0x%x\n",
418 lib->lib_info.lib_type, lib->slot_info.slot_num, ops); 422 lib->lib_info.lib_type, lib->slot_info.slot_num, ops);
419 pr_debug("sst: Version 0x%x, name %s, caps 0x%x media type 0x%x\n", 423 pr_debug("Version 0x%x, name %s, caps 0x%x media type 0x%x\n",
420 lib->lib_info.lib_version, lib->lib_info.lib_name, 424 lib->lib_info.lib_version, lib->lib_info.lib_name,
421 lib->lib_info.lib_caps, lib->lib_info.media_type); 425 lib->lib_info.lib_caps, lib->lib_info.media_type);
422 426
423 pr_debug("sst: IRAM Size 0x%x, offset 0x%x\n", 427 pr_debug("IRAM Size 0x%x, offset 0x%x\n",
424 lib->slot_info.iram_size, lib->slot_info.iram_offset); 428 lib->slot_info.iram_size, lib->slot_info.iram_offset);
425 pr_debug("sst: DRAM Size 0x%x, offset 0x%x\n", 429 pr_debug("DRAM Size 0x%x, offset 0x%x\n",
426 lib->slot_info.dram_size, lib->slot_info.dram_offset); 430 lib->slot_info.dram_size, lib->slot_info.dram_offset);
427 431
428 switch (lib->lib_info.lib_type) { 432 switch (lib->lib_info.lib_type) {
@@ -442,7 +446,7 @@ int sst_load_library(struct snd_sst_lib_download *lib, u8 ops)
442 type = "wma9_"; 446 type = "wma9_";
443 break; 447 break;
444 default: 448 default:
445 pr_err("sst: Invalid codec type\n"); 449 pr_err("Invalid codec type\n");
446 error = -EINVAL; 450 error = -EINVAL;
447 goto wake; 451 goto wake;
448 } 452 }
@@ -458,11 +462,11 @@ int sst_load_library(struct snd_sst_lib_download *lib, u8 ops)
458 lib->slot_info.slot_num); 462 lib->slot_info.slot_num);
459 len += snprintf(buf + len, sizeof(buf) - len, ".bin"); 463 len += snprintf(buf + len, sizeof(buf) - len, ".bin");
460 464
461 pr_debug("sst: Requesting %s\n", buf); 465 pr_debug("Requesting %s\n", buf);
462 466
463 error = request_firmware(&fw_lib, buf, &sst_drv_ctx->pci->dev); 467 error = request_firmware(&fw_lib, buf, &sst_drv_ctx->pci->dev);
464 if (error) { 468 if (error) {
465 pr_err("sst: library load failed %d\n", error); 469 pr_err("library load failed %d\n", error);
466 goto wake; 470 goto wake;
467 } 471 }
468 error = sst_validate_library(fw_lib, &lib->slot_info, &entry_point); 472 error = sst_validate_library(fw_lib, &lib->slot_info, &entry_point);
@@ -476,7 +480,7 @@ int sst_load_library(struct snd_sst_lib_download *lib, u8 ops)
476 goto wake_free; 480 goto wake_free;
477 481
478 /* lib is downloaded and init send alloc again */ 482 /* lib is downloaded and init send alloc again */
479 pr_debug("sst: Library is downloaded now...\n"); 483 pr_debug("Library is downloaded now...\n");
480wake_free: 484wake_free:
481 /* sst_wake_up_alloc_block(sst_drv_ctx, pvt_id, error, NULL); */ 485 /* sst_wake_up_alloc_block(sst_drv_ctx, pvt_id, error, NULL); */
482 release_firmware(fw_lib); 486 release_firmware(fw_lib);
diff --git a/drivers/staging/intel_sst/intel_sst_fw_ipc.h b/drivers/staging/intel_sst/intel_sst_fw_ipc.h
index 9d3c36807e07..8df313d10d2a 100644
--- a/drivers/staging/intel_sst/intel_sst_fw_ipc.h
+++ b/drivers/staging/intel_sst/intel_sst_fw_ipc.h
@@ -31,6 +31,7 @@
31*/ 31*/
32 32
33#define MAX_NUM_STREAMS_MRST 3 33#define MAX_NUM_STREAMS_MRST 3
34#define MAX_NUM_STREAMS_MFLD 6
34#define MAX_NUM_STREAMS 6 35#define MAX_NUM_STREAMS 6
35#define MAX_DBG_RW_BYTES 80 36#define MAX_DBG_RW_BYTES 80
36#define MAX_NUM_SCATTER_BUFFERS 8 37#define MAX_NUM_SCATTER_BUFFERS 8
@@ -67,6 +68,8 @@
67#define IPC_IA_CAPT_VOICE 0x17 68#define IPC_IA_CAPT_VOICE 0x17
68#define IPC_IA_DECODE_FRAMES 0x18 69#define IPC_IA_DECODE_FRAMES 0x18
69 70
71#define IPC_IA_ALG_PARAMS 0x1A
72
70/* I2L Stream config/control msgs */ 73/* I2L Stream config/control msgs */
71#define IPC_IA_ALLOC_STREAM 0x20 /* Allocate a stream ID */ 74#define IPC_IA_ALLOC_STREAM 0x20 /* Allocate a stream ID */
72#define IPC_IA_FREE_STREAM 0x21 /* Free the stream ID */ 75#define IPC_IA_FREE_STREAM 0x21 /* Free the stream ID */
@@ -141,73 +144,87 @@ enum sst_error_codes {
141 /* Error code,response to msgId: Description */ 144 /* Error code,response to msgId: Description */
142 /* Common error codes */ 145 /* Common error codes */
143 SST_SUCCESS = 0, /* Success */ 146 SST_SUCCESS = 0, /* Success */
144 SST_ERR_INVALID_STREAM_ID, /* Invalid stream ID */ 147 SST_ERR_INVALID_STREAM_ID = 1,
145 SST_ERR_INVALID_MSG_ID, /* Invalid message ID */ 148 SST_ERR_INVALID_MSG_ID = 2,
146 SST_ERR_INVALID_STREAM_OP, /* Invalid stream operation request */ 149 SST_ERR_INVALID_STREAM_OP = 3,
147 SST_ERR_INVALID_PARAMS, /* Invalid params */ 150 SST_ERR_INVALID_PARAMS = 4,
148 SST_ERR_INVALID_CODEC, /* Invalid codec type */ 151 SST_ERR_INVALID_CODEC = 5,
149 SST_ERR_INVALID_MEDIA_TYPE, /* Invalid media type */ 152 SST_ERR_INVALID_MEDIA_TYPE = 6,
150 SST_ERR_STREAM_ERR, /* ANY: Stream control or config or 153 SST_ERR_STREAM_ERR = 7,
151 processing error */
152 154
153 /* IPC specific error codes */ 155 /* IPC specific error codes */
154 SST_IPC_ERR_CALL_BACK_NOT_REGD, /* Call back for msg not regd */ 156 SST_IPC_ERR_CALL_BACK_NOT_REGD = 8,
155 SST_IPC_ERR_STREAM_NOT_ALLOCATED, /* Stream is not allocated */ 157 SST_IPC_ERR_STREAM_NOT_ALLOCATED = 9,
156 SST_IPC_ERR_STREAM_ALLOC_FAILED, /* ALLOC:Stream alloc failed */ 158 SST_IPC_ERR_STREAM_ALLOC_FAILED = 10,
157 SST_IPC_ERR_GET_STREAM_FAILED, /* ALLOC:Get stream id failed*/ 159 SST_IPC_ERR_GET_STREAM_FAILED = 11,
158 SST_ERR_MOD_NOT_AVAIL, /* SET/GET: Mod(AEC/AGC/ALC) not available */ 160 SST_ERR_MOD_NOT_AVAIL = 12,
159 SST_ERR_MOD_DNLD_RQD, /* SET/GET: Mod(AEC/AGC/ALC) download required */ 161 SST_ERR_MOD_DNLD_RQD = 13,
160 SST_ERR_STREAM_STOPPED, /* ANY: Stream is in stopped state */ 162 SST_ERR_STREAM_STOPPED = 14,
161 SST_ERR_STREAM_IN_USE, /* ANY: Stream is already in use */ 163 SST_ERR_STREAM_IN_USE = 15,
162 164
163 /* Capture specific error codes */ 165 /* Capture specific error codes */
164 SST_CAP_ERR_INCMPLTE_CAPTURE_MSG,/* ANY:Incomplete message */ 166 SST_CAP_ERR_INCMPLTE_CAPTURE_MSG = 16,
165 SST_CAP_ERR_CAPTURE_FAIL, /* ANY:Capture op failed */ 167 SST_CAP_ERR_CAPTURE_FAIL = 17,
166 SST_CAP_ERR_GET_DDR_NEW_SGLIST, 168 SST_CAP_ERR_GET_DDR_NEW_SGLIST = 18,
167 SST_CAP_ERR_UNDER_RUN, /* lack of input data */ 169 SST_CAP_ERR_UNDER_RUN = 19,
168 SST_CAP_ERR_OVERFLOW, /* lack of output space */ 170 SST_CAP_ERR_OVERFLOW = 20,
169 171
170 /* Playback specific error codes*/ 172 /* Playback specific error codes*/
171 SST_PB_ERR_INCMPLTE_PLAY_MSG, /* ANY: Incomplete message */ 173 SST_PB_ERR_INCMPLTE_PLAY_MSG = 21,
172 SST_PB_ERR_PLAY_FAIL, /* ANY: Playback operation failed */ 174 SST_PB_ERR_PLAY_FAIL = 22,
173 SST_PB_ERR_GET_DDR_NEW_SGLIST, 175 SST_PB_ERR_GET_DDR_NEW_SGLIST = 23,
174 176
175 /* Codec manager specific error codes */ 177 /* Codec manager specific error codes */
176 SST_LIB_ERR_LIB_DNLD_REQUIRED, /* ALLOC: Codec download required */ 178 SST_LIB_ERR_LIB_DNLD_REQUIRED = 24,
177 SST_LIB_ERR_LIB_NOT_SUPPORTED, /* Library is not supported */ 179 SST_LIB_ERR_LIB_NOT_SUPPORTED = 25,
178 180
179 /* Library manager specific error codes */ 181 /* Library manager specific error codes */
180 SST_SCC_ERR_PREP_DNLD_FAILED, /* Failed to prepare for codec download */ 182 SST_SCC_ERR_PREP_DNLD_FAILED = 26,
181 SST_SCC_ERR_LIB_DNLD_RES_FAILED, /* Lib download resume failed */ 183 SST_SCC_ERR_LIB_DNLD_RES_FAILED = 27,
182 /* Scheduler specific error codes */ 184 /* Scheduler specific error codes */
183 SST_SCH_ERR_FAIL, /* REPORT: */ 185 SST_SCH_ERR_FAIL = 28,
184 186
185 /* DMA specific error codes */ 187 /* DMA specific error codes */
186 SST_DMA_ERR_NO_CHNL_AVAILABLE, /* DMA Ch not available */ 188 SST_DMA_ERR_NO_CHNL_AVAILABLE = 29,
187 SST_DMA_ERR_INVALID_INPUT_PARAMS, /* Invalid input params */ 189 SST_DMA_ERR_INVALID_INPUT_PARAMS = 30,
188 SST_DMA_ERR_CHNL_ALREADY_SUSPENDED, /* Ch is suspended */ 190 SST_DMA_ERR_CHNL_ALREADY_SUSPENDED = 31,
189 SST_DMA_ERR_CHNL_ALREADY_STARTED, /* Ch already started */ 191 SST_DMA_ERR_CHNL_ALREADY_STARTED = 32,
190 SST_DMA_ERR_CHNL_NOT_ENABLED, /* Ch not enabled */ 192 SST_DMA_ERR_CHNL_NOT_ENABLED = 33,
191 SST_DMA_ERR_TRANSFER_FAILED, /* Transfer failed */ 193 SST_DMA_ERR_TRANSFER_FAILED = 34,
192 SST_SSP_ERR_ALREADY_ENABLED, /* REPORT: SSP already enabled */ 194
193 SST_SSP_ERR_ALREADY_DISABLED, /* REPORT: SSP already disabled */ 195 SST_SSP_ERR_ALREADY_ENABLED = 35,
194 SST_SSP_ERR_NOT_INITIALIZED, 196 SST_SSP_ERR_ALREADY_DISABLED = 36,
197 SST_SSP_ERR_NOT_INITIALIZED = 37,
198 SST_SSP_ERR_SRAM_NO_DMA_DATA = 38,
195 199
196 /* Other error codes */ 200 /* Other error codes */
197 SST_ERR_MOD_INIT_FAIL, /* Firmware Module init failed */ 201 SST_ERR_MOD_INIT_FAIL = 39,
198 202
199 /* FW init error codes */ 203 /* FW init error codes */
200 SST_RDR_ERR_IO_DEV_SEL_NOT_ALLOWED, 204 SST_RDR_ERR_IO_DEV_SEL_NOT_ALLOWED = 40,
201 SST_RDR_ERR_ROUTE_ALREADY_STARTED, 205 SST_RDR_ERR_ROUTE_ALREADY_STARTED = 41,
202 SST_RDR_PREP_CODEC_DNLD_FAILED, 206 SST_RDR_ERR_IO_DEV_SEL_FAILED = 42,
207 SST_RDR_PREP_CODEC_DNLD_FAILED = 43,
203 208
204 /* Memory debug error codes */ 209 /* Memory debug error codes */
205 SST_ERR_DBG_MEM_READ_FAIL, 210 SST_ERR_DBG_MEM_READ_FAIL = 44,
206 SST_ERR_DBG_MEM_WRITE_FAIL, 211 SST_ERR_DBG_MEM_WRITE_FAIL = 45,
207 212 SST_ERR_INSUFFICIENT_INPUT_SG_LIST = 46,
208 /* Decode error codes */ 213 SST_ERR_INSUFFICIENT_OUTPUT_SG_LIST = 47,
209 SST_ERR_DEC_NEED_INPUT_BUF, 214
210 215 SST_ERR_BUFFER_NOT_AVAILABLE = 48,
216 SST_ERR_BUFFER_NOT_ALLOCATED = 49,
217 SST_ERR_INVALID_REGION_TYPE = 50,
218 SST_ERR_NULL_PTR = 51,
219 SST_ERR_INVALID_BUFFER_SIZE = 52,
220 SST_ERR_INVALID_BUFFER_INDEX = 53,
221
222 /*IIPC specific error codes */
223 SST_IIPC_QUEUE_FULL = 54,
224 SST_IIPC_ERR_MSG_SND_FAILED = 55,
225 SST_PB_ERR_UNDERRUN_OCCURED = 56,
226 SST_RDR_INSUFFICIENT_MIXER_BUFFER = 57,
227 SST_INVALID_TIME_SLOTS = 58,
211}; 228};
212 229
213enum dbg_mem_data_type { 230enum dbg_mem_data_type {
diff --git a/drivers/staging/intel_sst/intel_sst_ioctl.h b/drivers/staging/intel_sst/intel_sst_ioctl.h
index 03b931619a3e..bebc395a3c1f 100644
--- a/drivers/staging/intel_sst/intel_sst_ioctl.h
+++ b/drivers/staging/intel_sst/intel_sst_ioctl.h
@@ -190,21 +190,15 @@ struct snd_prp_params {
190 __u32 reserved; /* No pre-processing defined yet */ 190 __u32 reserved; /* No pre-processing defined yet */
191}; 191};
192 192
193struct snd_params_block {
194 __u32 type; /*Type of the parameter*/
195 __u32 size; /*size of the parameters in the block*/
196 __u8 params[0]; /*Parameters of the algorithm*/
197};
198
199/* Pre and post processing params structure */ 193/* Pre and post processing params structure */
200struct snd_ppp_params { 194struct snd_ppp_params {
201 enum sst_algo_types algo_id;/* Post/Pre processing algorithm ID */ 195 __u8 algo_id;/* Post/Pre processing algorithm ID */
202 __u8 str_id; /*Only 5 bits used 0 - 31 are valid*/ 196 __u8 str_id; /*Only 5 bits used 0 - 31 are valid*/
203 __u8 enable; /* 0= disable, 1= enable*/ 197 __u8 enable; /* 0= disable, 1= enable*/
204 __u8 reserved; 198 __u8 reserved;
205 __u32 size; /*Size of parameters for all blocks*/ 199 __u32 size; /*Size of parameters for all blocks*/
206 struct snd_params_block params[0]; 200 void *params;
207}; 201} __attribute__ ((packed));
208 202
209struct snd_sst_postproc_info { 203struct snd_sst_postproc_info {
210 __u32 src_min; /* Supported SRC Min sampling freq */ 204 __u32 src_min; /* Supported SRC Min sampling freq */
@@ -431,5 +425,8 @@ struct snd_sst_dbufs {
431#define SNDRV_SST_FW_INFO _IOR('L', 0x20, struct snd_sst_fw_info *) 425#define SNDRV_SST_FW_INFO _IOR('L', 0x20, struct snd_sst_fw_info *)
432#define SNDRV_SST_SET_TARGET_DEVICE _IOW('L', 0x21, \ 426#define SNDRV_SST_SET_TARGET_DEVICE _IOW('L', 0x21, \
433 struct snd_sst_target_device *) 427 struct snd_sst_target_device *)
428/*DSP Ioctls on /dev/intel_sst_ctrl only*/
429#define SNDRV_SST_SET_ALGO _IOW('L', 0x30, struct snd_ppp_params *)
430#define SNDRV_SST_GET_ALGO _IOWR('L', 0x31, struct snd_ppp_params *)
434 431
435#endif /* __INTEL_SST_IOCTL_H__ */ 432#endif /* __INTEL_SST_IOCTL_H__ */
diff --git a/drivers/staging/intel_sst/intel_sst_ipc.c b/drivers/staging/intel_sst/intel_sst_ipc.c
index 39c67fa0bd0c..0742dde2685d 100644
--- a/drivers/staging/intel_sst/intel_sst_ipc.c
+++ b/drivers/staging/intel_sst/intel_sst_ipc.c
@@ -26,6 +26,8 @@
26 * This file defines all ipc functions 26 * This file defines all ipc functions
27 */ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/pci.h> 31#include <linux/pci.h>
30#include <linux/firmware.h> 32#include <linux/firmware.h>
31#include <linux/sched.h> 33#include <linux/sched.h>
@@ -75,16 +77,16 @@ void sst_post_message(struct work_struct *work)
75 /*To check if LPE is in stalled state.*/ 77 /*To check if LPE is in stalled state.*/
76 retval = sst_stalled(); 78 retval = sst_stalled();
77 if (retval < 0) { 79 if (retval < 0) {
78 pr_err("sst: in stalled state\n"); 80 pr_err("in stalled state\n");
79 return; 81 return;
80 } 82 }
81 pr_debug("sst: post message called\n"); 83 pr_debug("post message called\n");
82 spin_lock(&sst_drv_ctx->list_spin_lock); 84 spin_lock(&sst_drv_ctx->list_spin_lock);
83 85
84 /* check list */ 86 /* check list */
85 if (list_empty(&sst_drv_ctx->ipc_dispatch_list)) { 87 if (list_empty(&sst_drv_ctx->ipc_dispatch_list)) {
86 /* list is empty, mask imr */ 88 /* list is empty, mask imr */
87 pr_debug("sst: Empty msg queue... masking\n"); 89 pr_debug("Empty msg queue... masking\n");
88 imr.full = readl(sst_drv_ctx->shim + SST_IMRX); 90 imr.full = readl(sst_drv_ctx->shim + SST_IMRX);
89 imr.part.done_interrupt = 1; 91 imr.part.done_interrupt = 1;
90 /* dummy register for shim workaround */ 92 /* dummy register for shim workaround */
@@ -97,7 +99,7 @@ void sst_post_message(struct work_struct *work)
97 header.full = sst_shim_read(sst_drv_ctx->shim, SST_IPCX); 99 header.full = sst_shim_read(sst_drv_ctx->shim, SST_IPCX);
98 if (header.part.busy) { 100 if (header.part.busy) {
99 /* busy, unmask */ 101 /* busy, unmask */
100 pr_debug("sst: Busy not free... unmasking\n"); 102 pr_debug("Busy not free... unmasking\n");
101 imr.full = readl(sst_drv_ctx->shim + SST_IMRX); 103 imr.full = readl(sst_drv_ctx->shim + SST_IMRX);
102 imr.part.done_interrupt = 0; 104 imr.part.done_interrupt = 0;
103 /* dummy register for shim workaround */ 105 /* dummy register for shim workaround */
@@ -109,8 +111,8 @@ void sst_post_message(struct work_struct *work)
109 msg = list_entry(sst_drv_ctx->ipc_dispatch_list.next, 111 msg = list_entry(sst_drv_ctx->ipc_dispatch_list.next,
110 struct ipc_post, node); 112 struct ipc_post, node);
111 list_del(&msg->node); 113 list_del(&msg->node);
112 pr_debug("sst: Post message: header = %x\n", msg->header.full); 114 pr_debug("Post message: header = %x\n", msg->header.full);
113 pr_debug("sst: size: = %x\n", msg->header.part.data); 115 pr_debug("size: = %x\n", msg->header.part.data);
114 if (msg->header.part.large) 116 if (msg->header.part.large)
115 memcpy_toio(sst_drv_ctx->mailbox + SST_MAILBOX_SEND, 117 memcpy_toio(sst_drv_ctx->mailbox + SST_MAILBOX_SEND,
116 msg->mailbox_data, msg->header.part.data); 118 msg->mailbox_data, msg->header.part.data);
@@ -166,13 +168,13 @@ int process_fw_init(struct sst_ipc_msg_wq *msg)
166 (struct ipc_header_fw_init *)msg->mailbox; 168 (struct ipc_header_fw_init *)msg->mailbox;
167 int retval = 0; 169 int retval = 0;
168 170
169 pr_debug("sst: *** FW Init msg came***\n"); 171 pr_debug("*** FW Init msg came***\n");
170 if (init->result) { 172 if (init->result) {
171 mutex_lock(&sst_drv_ctx->sst_lock); 173 mutex_lock(&sst_drv_ctx->sst_lock);
172 sst_drv_ctx->sst_state = SST_ERROR; 174 sst_drv_ctx->sst_state = SST_ERROR;
173 mutex_unlock(&sst_drv_ctx->sst_lock); 175 mutex_unlock(&sst_drv_ctx->sst_lock);
174 pr_debug("sst: FW Init failed, Error %x\n", init->result); 176 pr_debug("FW Init failed, Error %x\n", init->result);
175 pr_err("sst: FW Init failed, Error %x\n", init->result); 177 pr_err("FW Init failed, Error %x\n", init->result);
176 retval = -init->result; 178 retval = -init->result;
177 return retval; 179 return retval;
178 } 180 }
@@ -180,12 +182,13 @@ int process_fw_init(struct sst_ipc_msg_wq *msg)
180 sst_send_sound_card_type(); 182 sst_send_sound_card_type();
181 mutex_lock(&sst_drv_ctx->sst_lock); 183 mutex_lock(&sst_drv_ctx->sst_lock);
182 sst_drv_ctx->sst_state = SST_FW_RUNNING; 184 sst_drv_ctx->sst_state = SST_FW_RUNNING;
185 sst_drv_ctx->lpe_stalled = 0;
183 mutex_unlock(&sst_drv_ctx->sst_lock); 186 mutex_unlock(&sst_drv_ctx->sst_lock);
184 pr_debug("sst: FW Version %x.%x\n", 187 pr_debug("FW Version %x.%x\n",
185 init->fw_version.major, init->fw_version.minor); 188 init->fw_version.major, init->fw_version.minor);
186 pr_debug("sst: Build No %x Type %x\n", 189 pr_debug("Build No %x Type %x\n",
187 init->fw_version.build, init->fw_version.type); 190 init->fw_version.build, init->fw_version.type);
188 pr_debug("sst: Build date %s Time %s\n", 191 pr_debug(" Build date %s Time %s\n",
189 init->build_info.date, init->build_info.time); 192 init->build_info.date, init->build_info.time);
190 sst_wake_up_alloc_block(sst_drv_ctx, FW_DWNL_ID, retval, NULL); 193 sst_wake_up_alloc_block(sst_drv_ctx, FW_DWNL_ID, retval, NULL);
191 return retval; 194 return retval;
@@ -204,19 +207,19 @@ void sst_process_message(struct work_struct *work)
204 container_of(work, struct sst_ipc_msg_wq, wq); 207 container_of(work, struct sst_ipc_msg_wq, wq);
205 int str_id = msg->header.part.str_id; 208 int str_id = msg->header.part.str_id;
206 209
207 pr_debug("sst: IPC process for %x\n", msg->header.full); 210 pr_debug("IPC process for %x\n", msg->header.full);
208 211
209 /* based on msg in list call respective handler */ 212 /* based on msg in list call respective handler */
210 switch (msg->header.part.msg_id) { 213 switch (msg->header.part.msg_id) {
211 case IPC_SST_BUF_UNDER_RUN: 214 case IPC_SST_BUF_UNDER_RUN:
212 case IPC_SST_BUF_OVER_RUN: 215 case IPC_SST_BUF_OVER_RUN:
213 if (sst_validate_strid(str_id)) { 216 if (sst_validate_strid(str_id)) {
214 pr_err("sst: stream id %d invalid\n", str_id); 217 pr_err("stream id %d invalid\n", str_id);
215 break; 218 break;
216 } 219 }
217 pr_err("sst: Buffer under/overrun for%d\n", 220 pr_err("Buffer under/overrun for %d\n",
218 msg->header.part.str_id); 221 msg->header.part.str_id);
219 pr_err("sst: Got Underrun & not to send data...ignore\n"); 222 pr_err("Got Underrun & not to send data...ignore\n");
220 break; 223 break;
221 224
222 case IPC_SST_GET_PLAY_FRAMES: 225 case IPC_SST_GET_PLAY_FRAMES:
@@ -224,35 +227,35 @@ void sst_process_message(struct work_struct *work)
224 struct stream_info *stream ; 227 struct stream_info *stream ;
225 228
226 if (sst_validate_strid(str_id)) { 229 if (sst_validate_strid(str_id)) {
227 pr_err("sst: strid %d invalid\n", str_id); 230 pr_err("strid %d invalid\n", str_id);
228 break; 231 break;
229 } 232 }
230 /* call sst_play_frame */ 233 /* call sst_play_frame */
231 stream = &sst_drv_ctx->streams[str_id]; 234 stream = &sst_drv_ctx->streams[str_id];
232 pr_debug("sst: sst_play_frames for %d\n", 235 pr_debug("sst_play_frames for %d\n",
233 msg->header.part.str_id); 236 msg->header.part.str_id);
234 mutex_lock(&sst_drv_ctx->streams[str_id].lock); 237 mutex_lock(&sst_drv_ctx->streams[str_id].lock);
235 sst_play_frame(msg->header.part.str_id); 238 sst_play_frame(msg->header.part.str_id);
236 mutex_unlock(&sst_drv_ctx->streams[str_id].lock); 239 mutex_unlock(&sst_drv_ctx->streams[str_id].lock);
237 break; 240 break;
238 } else 241 } else
239 pr_err("sst: sst_play_frames for Penwell!!\n"); 242 pr_err("sst_play_frames for Penwell!!\n");
240 243
241 case IPC_SST_GET_CAPT_FRAMES: 244 case IPC_SST_GET_CAPT_FRAMES:
242 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID) { 245 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID) {
243 struct stream_info *stream; 246 struct stream_info *stream;
244 /* call sst_capture_frame */ 247 /* call sst_capture_frame */
245 if (sst_validate_strid(str_id)) { 248 if (sst_validate_strid(str_id)) {
246 pr_err("sst: str id %d invalid\n", str_id); 249 pr_err("str id %d invalid\n", str_id);
247 break; 250 break;
248 } 251 }
249 stream = &sst_drv_ctx->streams[str_id]; 252 stream = &sst_drv_ctx->streams[str_id];
250 pr_debug("sst: sst_capture_frames for %d\n", 253 pr_debug("sst_capture_frames for %d\n",
251 msg->header.part.str_id); 254 msg->header.part.str_id);
252 mutex_lock(&stream->lock); 255 mutex_lock(&stream->lock);
253 if (stream->mmapped == false && 256 if (stream->mmapped == false &&
254 stream->src == SST_DRV) { 257 stream->src == SST_DRV) {
255 pr_debug("sst: waking up block for copy.\n"); 258 pr_debug("waking up block for copy.\n");
256 stream->data_blk.ret_code = 0; 259 stream->data_blk.ret_code = 0;
257 stream->data_blk.condition = true; 260 stream->data_blk.condition = true;
258 stream->data_blk.on = false; 261 stream->data_blk.on = false;
@@ -261,11 +264,11 @@ void sst_process_message(struct work_struct *work)
261 sst_capture_frame(msg->header.part.str_id); 264 sst_capture_frame(msg->header.part.str_id);
262 mutex_unlock(&stream->lock); 265 mutex_unlock(&stream->lock);
263 } else 266 } else
264 pr_err("sst: sst_play_frames for Penwell!!\n"); 267 pr_err("sst_play_frames for Penwell!!\n");
265 break; 268 break;
266 269
267 case IPC_IA_PRINT_STRING: 270 case IPC_IA_PRINT_STRING:
268 pr_debug("sst: been asked to print something by fw\n"); 271 pr_debug("been asked to print something by fw\n");
269 /* TBD */ 272 /* TBD */
270 break; 273 break;
271 274
@@ -277,12 +280,12 @@ void sst_process_message(struct work_struct *work)
277 280
278 case IPC_SST_STREAM_PROCESS_FATAL_ERR: 281 case IPC_SST_STREAM_PROCESS_FATAL_ERR:
279 if (sst_validate_strid(str_id)) { 282 if (sst_validate_strid(str_id)) {
280 pr_err("sst: stream id %d invalid\n", str_id); 283 pr_err("stream id %d invalid\n", str_id);
281 break; 284 break;
282 } 285 }
283 pr_err("sst: codec fatal error %x stream %d...\n", 286 pr_err("codec fatal error %x stream %d...\n",
284 msg->header.full, msg->header.part.str_id); 287 msg->header.full, msg->header.part.str_id);
285 pr_err("sst: Dropping the stream\n"); 288 pr_err("Dropping the stream\n");
286 sst_drop_stream(msg->header.part.str_id); 289 sst_drop_stream(msg->header.part.str_id);
287 break; 290 break;
288 case IPC_IA_LPE_GETTING_STALLED: 291 case IPC_IA_LPE_GETTING_STALLED:
@@ -293,7 +296,7 @@ void sst_process_message(struct work_struct *work)
293 break; 296 break;
294 default: 297 default:
295 /* Illegal case */ 298 /* Illegal case */
296 pr_err("sst: Unhandled msg %x header %x\n", 299 pr_err("Unhandled msg %x header %x\n",
297 msg->header.part.msg_id, msg->header.full); 300 msg->header.part.msg_id, msg->header.full);
298 } 301 }
299 sst_clear_interrupt(); 302 sst_clear_interrupt();
@@ -322,7 +325,7 @@ void sst_process_reply(struct work_struct *work)
322 if (!msg->header.part.data) { 325 if (!msg->header.part.data) {
323 sst_drv_ctx->tgt_dev_blk.ret_code = 0; 326 sst_drv_ctx->tgt_dev_blk.ret_code = 0;
324 } else { 327 } else {
325 pr_err("sst: Msg %x reply error %x\n", 328 pr_err(" Msg %x reply error %x\n",
326 msg->header.part.msg_id, msg->header.part.data); 329 msg->header.part.msg_id, msg->header.part.data);
327 sst_drv_ctx->tgt_dev_blk.ret_code = 330 sst_drv_ctx->tgt_dev_blk.ret_code =
328 -msg->header.part.data; 331 -msg->header.part.data;
@@ -333,6 +336,55 @@ void sst_process_reply(struct work_struct *work)
333 wake_up(&sst_drv_ctx->wait_queue); 336 wake_up(&sst_drv_ctx->wait_queue);
334 } 337 }
335 break; 338 break;
339 case IPC_IA_ALG_PARAMS: {
340 pr_debug("sst:IPC_ALG_PARAMS response %x\n", msg->header.full);
341 pr_debug("sst: data value %x\n", msg->header.part.data);
342 pr_debug("sst: large value %x\n", msg->header.part.large);
343
344 if (!msg->header.part.large) {
345 if (!msg->header.part.data) {
346 pr_debug("sst: alg set success\n");
347 sst_drv_ctx->ppp_params_blk.ret_code = 0;
348 } else {
349 pr_debug("sst: alg set failed\n");
350 sst_drv_ctx->ppp_params_blk.ret_code =
351 -msg->header.part.data;
352 }
353
354 } else if (msg->header.part.data) {
355 struct snd_ppp_params *mailbox_params, *get_params;
356 char *params;
357
358 pr_debug("sst: alg get success\n");
359 mailbox_params = (struct snd_ppp_params *)msg->mailbox;
360 get_params = kzalloc(sizeof(*get_params), GFP_KERNEL);
361 if (get_params == NULL) {
362 pr_err("sst: out of memory for ALG PARAMS");
363 break;
364 }
365 memcpy_fromio(get_params, mailbox_params,
366 sizeof(*get_params));
367 get_params->params = kzalloc(mailbox_params->size,
368 GFP_KERNEL);
369 if (get_params->params == NULL) {
370 kfree(get_params);
371 pr_err("sst: out of memory for ALG PARAMS block");
372 break;
373 }
374 params = msg->mailbox;
375 params = params + sizeof(*mailbox_params) - sizeof(u32);
376 memcpy_fromio(get_params->params, params,
377 get_params->size);
378 sst_drv_ctx->ppp_params_blk.ret_code = 0;
379 sst_drv_ctx->ppp_params_blk.data = get_params;
380 }
381
382 if (sst_drv_ctx->ppp_params_blk.on == true) {
383 sst_drv_ctx->ppp_params_blk.condition = true;
384 wake_up(&sst_drv_ctx->wait_queue);
385 }
386 break;
387 }
336 case IPC_IA_GET_FW_INFO: { 388 case IPC_IA_GET_FW_INFO: {
337 struct snd_sst_fw_info *fw_info = 389 struct snd_sst_fw_info *fw_info =
338 (struct snd_sst_fw_info *)msg->mailbox; 390 (struct snd_sst_fw_info *)msg->mailbox;
@@ -340,7 +392,7 @@ void sst_process_reply(struct work_struct *work)
340 int major = fw_info->fw_version.major; 392 int major = fw_info->fw_version.major;
341 int minor = fw_info->fw_version.minor; 393 int minor = fw_info->fw_version.minor;
342 int build = fw_info->fw_version.build; 394 int build = fw_info->fw_version.build;
343 pr_debug("sst: Msg succedded %x\n", 395 pr_debug("Msg succeeded %x\n",
344 msg->header.part.msg_id); 396 msg->header.part.msg_id);
345 pr_debug("INFO: ***FW*** = %02d.%02d.%02d\n", 397 pr_debug("INFO: ***FW*** = %02d.%02d.%02d\n",
346 major, minor, build); 398 major, minor, build);
@@ -349,13 +401,13 @@ void sst_process_reply(struct work_struct *work)
349 sizeof(struct snd_sst_fw_info)); 401 sizeof(struct snd_sst_fw_info));
350 sst_drv_ctx->fw_info_blk.ret_code = 0; 402 sst_drv_ctx->fw_info_blk.ret_code = 0;
351 } else { 403 } else {
352 pr_err("sst: Msg %x reply error %x\n", 404 pr_err(" Msg %x reply error %x\n",
353 msg->header.part.msg_id, msg->header.part.data); 405 msg->header.part.msg_id, msg->header.part.data);
354 sst_drv_ctx->fw_info_blk.ret_code = 406 sst_drv_ctx->fw_info_blk.ret_code =
355 -msg->header.part.data; 407 -msg->header.part.data;
356 } 408 }
357 if (sst_drv_ctx->fw_info_blk.on == true) { 409 if (sst_drv_ctx->fw_info_blk.on == true) {
358 pr_debug("sst: Memcopy succedded\n"); 410 pr_debug("Memcopy succeeded\n");
359 sst_drv_ctx->fw_info_blk.on = false; 411 sst_drv_ctx->fw_info_blk.on = false;
360 sst_drv_ctx->fw_info_blk.condition = true; 412 sst_drv_ctx->fw_info_blk.condition = true;
361 wake_up(&sst_drv_ctx->wait_queue); 413 wake_up(&sst_drv_ctx->wait_queue);
@@ -364,11 +416,11 @@ void sst_process_reply(struct work_struct *work)
364 } 416 }
365 case IPC_IA_SET_STREAM_MUTE: 417 case IPC_IA_SET_STREAM_MUTE:
366 if (!msg->header.part.data) { 418 if (!msg->header.part.data) {
367 pr_debug("sst: Msg succedded %x\n", 419 pr_debug("Msg succeeded %x\n",
368 msg->header.part.msg_id); 420 msg->header.part.msg_id);
369 sst_drv_ctx->mute_info_blk.ret_code = 0; 421 sst_drv_ctx->mute_info_blk.ret_code = 0;
370 } else { 422 } else {
371 pr_err("sst: Msg %x reply error %x\n", 423 pr_err(" Msg %x reply error %x\n",
372 msg->header.part.msg_id, msg->header.part.data); 424 msg->header.part.msg_id, msg->header.part.data);
373 sst_drv_ctx->mute_info_blk.ret_code = 425 sst_drv_ctx->mute_info_blk.ret_code =
374 -msg->header.part.data; 426 -msg->header.part.data;
@@ -382,11 +434,11 @@ void sst_process_reply(struct work_struct *work)
382 break; 434 break;
383 case IPC_IA_SET_STREAM_VOL: 435 case IPC_IA_SET_STREAM_VOL:
384 if (!msg->header.part.data) { 436 if (!msg->header.part.data) {
385 pr_debug("sst: Msg succedded %x\n", 437 pr_debug("Msg succeeded %x\n",
386 msg->header.part.msg_id); 438 msg->header.part.msg_id);
387 sst_drv_ctx->vol_info_blk.ret_code = 0; 439 sst_drv_ctx->vol_info_blk.ret_code = 0;
388 } else { 440 } else {
389 pr_err("sst: Msg %x reply error %x\n", 441 pr_err(" Msg %x reply error %x\n",
390 msg->header.part.msg_id, 442 msg->header.part.msg_id,
391 msg->header.part.data); 443 msg->header.part.data);
392 sst_drv_ctx->vol_info_blk.ret_code = 444 sst_drv_ctx->vol_info_blk.ret_code =
@@ -402,15 +454,15 @@ void sst_process_reply(struct work_struct *work)
402 break; 454 break;
403 case IPC_IA_GET_STREAM_VOL: 455 case IPC_IA_GET_STREAM_VOL:
404 if (msg->header.part.large) { 456 if (msg->header.part.large) {
405 pr_debug("sst: Large Msg Received Successfully\n"); 457 pr_debug("Large Msg Received Successfully\n");
406 pr_debug("sst: Msg succedded %x\n", 458 pr_debug("Msg succeeded %x\n",
407 msg->header.part.msg_id); 459 msg->header.part.msg_id);
408 memcpy_fromio(sst_drv_ctx->vol_info_blk.data, 460 memcpy_fromio(sst_drv_ctx->vol_info_blk.data,
409 (void *) msg->mailbox, 461 (void *) msg->mailbox,
410 sizeof(struct snd_sst_vol)); 462 sizeof(struct snd_sst_vol));
411 sst_drv_ctx->vol_info_blk.ret_code = 0; 463 sst_drv_ctx->vol_info_blk.ret_code = 0;
412 } else { 464 } else {
413 pr_err("sst: Msg %x reply error %x\n", 465 pr_err("Msg %x reply error %x\n",
414 msg->header.part.msg_id, msg->header.part.data); 466 msg->header.part.msg_id, msg->header.part.data);
415 sst_drv_ctx->vol_info_blk.ret_code = 467 sst_drv_ctx->vol_info_blk.ret_code =
416 -msg->header.part.data; 468 -msg->header.part.data;
@@ -424,18 +476,18 @@ void sst_process_reply(struct work_struct *work)
424 476
425 case IPC_IA_GET_STREAM_PARAMS: 477 case IPC_IA_GET_STREAM_PARAMS:
426 if (sst_validate_strid(str_id)) { 478 if (sst_validate_strid(str_id)) {
427 pr_err("sst: stream id %d invalid\n", str_id); 479 pr_err("stream id %d invalid\n", str_id);
428 break; 480 break;
429 } 481 }
430 str_info = &sst_drv_ctx->streams[str_id]; 482 str_info = &sst_drv_ctx->streams[str_id];
431 if (msg->header.part.large) { 483 if (msg->header.part.large) {
432 pr_debug("sst: Get stream large success\n"); 484 pr_debug("Get stream large success\n");
433 memcpy_fromio(str_info->ctrl_blk.data, 485 memcpy_fromio(str_info->ctrl_blk.data,
434 ((void *)(msg->mailbox)), 486 ((void *)(msg->mailbox)),
435 sizeof(struct snd_sst_fw_get_stream_params)); 487 sizeof(struct snd_sst_fw_get_stream_params));
436 str_info->ctrl_blk.ret_code = 0; 488 str_info->ctrl_blk.ret_code = 0;
437 } else { 489 } else {
438 pr_err("sst: Msg %x reply error %x\n", 490 pr_err("Msg %x reply error %x\n",
439 msg->header.part.msg_id, msg->header.part.data); 491 msg->header.part.msg_id, msg->header.part.data);
440 str_info->ctrl_blk.ret_code = -msg->header.part.data; 492 str_info->ctrl_blk.ret_code = -msg->header.part.data;
441 } 493 }
@@ -447,19 +499,19 @@ void sst_process_reply(struct work_struct *work)
447 break; 499 break;
448 case IPC_IA_DECODE_FRAMES: 500 case IPC_IA_DECODE_FRAMES:
449 if (sst_validate_strid(str_id)) { 501 if (sst_validate_strid(str_id)) {
450 pr_err("sst: stream id %d invalid\n", str_id); 502 pr_err("stream id %d invalid\n", str_id);
451 break; 503 break;
452 } 504 }
453 str_info = &sst_drv_ctx->streams[str_id]; 505 str_info = &sst_drv_ctx->streams[str_id];
454 if (msg->header.part.large) { 506 if (msg->header.part.large) {
455 pr_debug("sst: Msg succedded %x\n", 507 pr_debug("Msg succeeded %x\n",
456 msg->header.part.msg_id); 508 msg->header.part.msg_id);
457 memcpy_fromio(str_info->data_blk.data, 509 memcpy_fromio(str_info->data_blk.data,
458 ((void *)(msg->mailbox)), 510 ((void *)(msg->mailbox)),
459 sizeof(struct snd_sst_decode_info)); 511 sizeof(struct snd_sst_decode_info));
460 str_info->data_blk.ret_code = 0; 512 str_info->data_blk.ret_code = 0;
461 } else { 513 } else {
462 pr_err("sst: Msg %x reply error %x\n", 514 pr_err("Msg %x reply error %x\n",
463 msg->header.part.msg_id, msg->header.part.data); 515 msg->header.part.msg_id, msg->header.part.data);
464 str_info->data_blk.ret_code = -msg->header.part.data; 516 str_info->data_blk.ret_code = -msg->header.part.data;
465 } 517 }
@@ -471,17 +523,17 @@ void sst_process_reply(struct work_struct *work)
471 break; 523 break;
472 case IPC_IA_DRAIN_STREAM: 524 case IPC_IA_DRAIN_STREAM:
473 if (sst_validate_strid(str_id)) { 525 if (sst_validate_strid(str_id)) {
474 pr_err("sst: stream id %d invalid\n", str_id); 526 pr_err("stream id %d invalid\n", str_id);
475 break; 527 break;
476 } 528 }
477 str_info = &sst_drv_ctx->streams[str_id]; 529 str_info = &sst_drv_ctx->streams[str_id];
478 if (!msg->header.part.data) { 530 if (!msg->header.part.data) {
479 pr_debug("sst: Msg succedded %x\n", 531 pr_debug("Msg succeeded %x\n",
480 msg->header.part.msg_id); 532 msg->header.part.msg_id);
481 str_info->ctrl_blk.ret_code = 0; 533 str_info->ctrl_blk.ret_code = 0;
482 534
483 } else { 535 } else {
484 pr_err("sst: Msg %x reply error %x\n", 536 pr_err(" Msg %x reply error %x\n",
485 msg->header.part.msg_id, msg->header.part.data); 537 msg->header.part.msg_id, msg->header.part.data);
486 str_info->ctrl_blk.ret_code = -msg->header.part.data; 538 str_info->ctrl_blk.ret_code = -msg->header.part.data;
487 539
@@ -496,7 +548,7 @@ void sst_process_reply(struct work_struct *work)
496 548
497 case IPC_IA_DROP_STREAM: 549 case IPC_IA_DROP_STREAM:
498 if (sst_validate_strid(str_id)) { 550 if (sst_validate_strid(str_id)) {
499 pr_err("sst: str id %d invalid\n", str_id); 551 pr_err("str id %d invalid\n", str_id);
500 break; 552 break;
501 } 553 }
502 str_info = &sst_drv_ctx->streams[str_id]; 554 str_info = &sst_drv_ctx->streams[str_id];
@@ -504,12 +556,12 @@ void sst_process_reply(struct work_struct *work)
504 struct snd_sst_drop_response *drop_resp = 556 struct snd_sst_drop_response *drop_resp =
505 (struct snd_sst_drop_response *)msg->mailbox; 557 (struct snd_sst_drop_response *)msg->mailbox;
506 558
507 pr_debug("sst: Drop ret bytes %x\n", drop_resp->bytes); 559 pr_debug("Drop ret bytes %x\n", drop_resp->bytes);
508 560
509 str_info->curr_bytes = drop_resp->bytes; 561 str_info->curr_bytes = drop_resp->bytes;
510 str_info->ctrl_blk.ret_code = 0; 562 str_info->ctrl_blk.ret_code = 0;
511 } else { 563 } else {
512 pr_err("sst: Msg %x reply error %x\n", 564 pr_err(" Msg %x reply error %x\n",
513 msg->header.part.msg_id, msg->header.part.data); 565 msg->header.part.msg_id, msg->header.part.data);
514 str_info->ctrl_blk.ret_code = -msg->header.part.data; 566 str_info->ctrl_blk.ret_code = -msg->header.part.data;
515 } 567 }
@@ -521,10 +573,10 @@ void sst_process_reply(struct work_struct *work)
521 break; 573 break;
522 case IPC_IA_ENABLE_RX_TIME_SLOT: 574 case IPC_IA_ENABLE_RX_TIME_SLOT:
523 if (!msg->header.part.data) { 575 if (!msg->header.part.data) {
524 pr_debug("sst: RX_TIME_SLOT success\n"); 576 pr_debug("RX_TIME_SLOT success\n");
525 sst_drv_ctx->hs_info_blk.ret_code = 0; 577 sst_drv_ctx->hs_info_blk.ret_code = 0;
526 } else { 578 } else {
527 pr_err("sst: Msg %x reply error %x\n", 579 pr_err(" Msg %x reply error %x\n",
528 msg->header.part.msg_id, 580 msg->header.part.msg_id,
529 msg->header.part.data); 581 msg->header.part.data);
530 sst_drv_ctx->hs_info_blk.ret_code = 582 sst_drv_ctx->hs_info_blk.ret_code =
@@ -541,17 +593,17 @@ void sst_process_reply(struct work_struct *work)
541 case IPC_IA_SET_STREAM_PARAMS: 593 case IPC_IA_SET_STREAM_PARAMS:
542 str_info = &sst_drv_ctx->streams[str_id]; 594 str_info = &sst_drv_ctx->streams[str_id];
543 if (!msg->header.part.data) { 595 if (!msg->header.part.data) {
544 pr_debug("sst: Msg succedded %x\n", 596 pr_debug("Msg succeeded %x\n",
545 msg->header.part.msg_id); 597 msg->header.part.msg_id);
546 str_info->ctrl_blk.ret_code = 0; 598 str_info->ctrl_blk.ret_code = 0;
547 } else { 599 } else {
548 pr_err("sst: Msg %x reply error %x\n", 600 pr_err(" Msg %x reply error %x\n",
549 msg->header.part.msg_id, 601 msg->header.part.msg_id,
550 msg->header.part.data); 602 msg->header.part.data);
551 str_info->ctrl_blk.ret_code = -msg->header.part.data; 603 str_info->ctrl_blk.ret_code = -msg->header.part.data;
552 } 604 }
553 if (sst_validate_strid(str_id)) { 605 if (sst_validate_strid(str_id)) {
554 pr_err("sst: stream id %d invalid\n", str_id); 606 pr_err(" stream id %d invalid\n", str_id);
555 break; 607 break;
556 } 608 }
557 609
@@ -564,9 +616,9 @@ void sst_process_reply(struct work_struct *work)
564 616
565 case IPC_IA_FREE_STREAM: 617 case IPC_IA_FREE_STREAM:
566 if (!msg->header.part.data) { 618 if (!msg->header.part.data) {
567 pr_debug("sst: Stream %d freed\n", str_id); 619 pr_debug("Stream %d freed\n", str_id);
568 } else { 620 } else {
569 pr_err("sst: Free for %d ret error %x\n", 621 pr_err("Free for %d ret error %x\n",
570 str_id, msg->header.part.data); 622 str_id, msg->header.part.data);
571 } 623 }
572 break; 624 break;
@@ -575,7 +627,7 @@ void sst_process_reply(struct work_struct *work)
575 struct snd_sst_alloc_response *resp = 627 struct snd_sst_alloc_response *resp =
576 (struct snd_sst_alloc_response *)msg->mailbox; 628 (struct snd_sst_alloc_response *)msg->mailbox;
577 if (resp->str_type.result) 629 if (resp->str_type.result)
578 pr_err("sst: error alloc stream = %x\n", 630 pr_err("error alloc stream = %x\n",
579 resp->str_type.result); 631 resp->str_type.result);
580 sst_alloc_stream_response(str_id, resp); 632 sst_alloc_stream_response(str_id, resp);
581 break; 633 break;
@@ -584,21 +636,21 @@ void sst_process_reply(struct work_struct *work)
584 case IPC_IA_PLAY_FRAMES: 636 case IPC_IA_PLAY_FRAMES:
585 case IPC_IA_CAPT_FRAMES: 637 case IPC_IA_CAPT_FRAMES:
586 if (sst_validate_strid(str_id)) { 638 if (sst_validate_strid(str_id)) {
587 pr_err("sst: stream id %d invalid\n" , str_id); 639 pr_err("stream id %d invalid\n", str_id);
588 break; 640 break;
589 } 641 }
590 pr_debug("sst: Ack for play/capt frames recived\n"); 642 pr_debug("Ack for play/capt frames received\n");
591 break; 643 break;
592 644
593 case IPC_IA_PREP_LIB_DNLD: { 645 case IPC_IA_PREP_LIB_DNLD: {
594 struct snd_sst_str_type *str_type = 646 struct snd_sst_str_type *str_type =
595 (struct snd_sst_str_type *)msg->mailbox; 647 (struct snd_sst_str_type *)msg->mailbox;
596 pr_debug("sst: Prep Lib download %x\n", 648 pr_debug("Prep Lib download %x\n",
597 msg->header.part.msg_id); 649 msg->header.part.msg_id);
598 if (str_type->result) 650 if (str_type->result)
599 pr_err("sst: Prep lib download %x\n", str_type->result); 651 pr_err("Prep lib download %x\n", str_type->result);
600 else 652 else
601 pr_debug("sst: Can download codec now...\n"); 653 pr_debug("Can download codec now...\n");
602 sst_wake_up_alloc_block(sst_drv_ctx, str_id, 654 sst_wake_up_alloc_block(sst_drv_ctx, str_id,
603 str_type->result, NULL); 655 str_type->result, NULL);
604 break; 656 break;
@@ -609,12 +661,12 @@ void sst_process_reply(struct work_struct *work)
609 (struct snd_sst_lib_download_info *)msg->mailbox; 661 (struct snd_sst_lib_download_info *)msg->mailbox;
610 int retval = resp->result; 662 int retval = resp->result;
611 663
612 pr_debug("sst: Lib downloaded %x\n", msg->header.part.msg_id); 664 pr_debug("Lib downloaded %x\n", msg->header.part.msg_id);
613 if (resp->result) { 665 if (resp->result) {
614 pr_err("sst: err in lib dload %x\n", resp->result); 666 pr_err("err in lib dload %x\n", resp->result);
615 } else { 667 } else {
616 pr_debug("sst: Codec download complete...\n"); 668 pr_debug("Codec download complete...\n");
617 pr_debug("sst: codec Type %d Ver %d Built %s: %s\n", 669 pr_debug("codec Type %d Ver %d Built %s: %s\n",
618 resp->dload_lib.lib_info.lib_type, 670 resp->dload_lib.lib_info.lib_type,
619 resp->dload_lib.lib_info.lib_version, 671 resp->dload_lib.lib_info.lib_version,
620 resp->dload_lib.lib_info.b_date, 672 resp->dload_lib.lib_info.b_date,
@@ -639,17 +691,17 @@ void sst_process_reply(struct work_struct *work)
639 case IPC_IA_GET_FW_BUILD_INF: { 691 case IPC_IA_GET_FW_BUILD_INF: {
640 struct sst_fw_build_info *build = 692 struct sst_fw_build_info *build =
641 (struct sst_fw_build_info *)msg->mailbox; 693 (struct sst_fw_build_info *)msg->mailbox;
642 pr_debug("sst: Build date:%sTime:%s", build->date, build->time); 694 pr_debug("Build date:%sTime:%s", build->date, build->time);
643 break; 695 break;
644 } 696 }
645 case IPC_IA_SET_PMIC_TYPE: 697 case IPC_IA_SET_PMIC_TYPE:
646 break; 698 break;
647 case IPC_IA_START_STREAM: 699 case IPC_IA_START_STREAM:
648 pr_debug("sst: reply for START STREAM %x\n", msg->header.full); 700 pr_debug("reply for START STREAM %x\n", msg->header.full);
649 break; 701 break;
650 default: 702 default:
651 /* Illegal case */ 703 /* Illegal case */
652 pr_err("sst: process reply:default = %x\n", msg->header.full); 704 pr_err("process reply:default = %x\n", msg->header.full);
653 } 705 }
654 sst_clear_interrupt(); 706 sst_clear_interrupt();
655 return; 707 return;
diff --git a/drivers/staging/intel_sst/intel_sst_pvt.c b/drivers/staging/intel_sst/intel_sst_pvt.c
index 6487e192bf93..01f8c3b1cf74 100644
--- a/drivers/staging/intel_sst/intel_sst_pvt.c
+++ b/drivers/staging/intel_sst/intel_sst_pvt.c
@@ -29,6 +29,8 @@
29 * This file contains all private functions 29 * This file contains all private functions
30 */ 30 */
31 31
32#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
32#include <linux/pci.h> 34#include <linux/pci.h>
33#include <linux/fs.h> 35#include <linux/fs.h>
34#include <linux/firmware.h> 36#include <linux/firmware.h>
@@ -60,7 +62,7 @@ int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx)
60 } 62 }
61 } 63 }
62 if (i == MAX_ACTIVE_STREAM) { 64 if (i == MAX_ACTIVE_STREAM) {
63 pr_err("sst: max alloc_stream reached"); 65 pr_err("max alloc_stream reached\n");
64 i = -EBUSY; /* active stream limit reached */ 66 i = -EBUSY; /* active stream limit reached */
65 } 67 }
66 return i; 68 return i;
@@ -84,14 +86,14 @@ int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
84 block->condition)) { 86 block->condition)) {
85 /* event wake */ 87 /* event wake */
86 if (block->ret_code < 0) { 88 if (block->ret_code < 0) {
87 pr_err("sst: stream failed %d\n", block->ret_code); 89 pr_err("stream failed %d\n", block->ret_code);
88 retval = -EBUSY; 90 retval = -EBUSY;
89 } else { 91 } else {
90 pr_debug("sst: event up\n"); 92 pr_debug("event up\n");
91 retval = 0; 93 retval = 0;
92 } 94 }
93 } else { 95 } else {
94 pr_err("sst: signal interrupted\n"); 96 pr_err("signal interrupted\n");
95 retval = -EINTR; 97 retval = -EINTR;
96 } 98 }
97 return retval; 99 return retval;
@@ -115,18 +117,18 @@ int sst_wait_interruptible_timeout(
115{ 117{
116 int retval = 0; 118 int retval = 0;
117 119
118 pr_debug("sst: sst_wait_interruptible_timeout - waiting....\n"); 120 pr_debug("sst_wait_interruptible_timeout - waiting....\n");
119 if (wait_event_interruptible_timeout(sst_drv_ctx->wait_queue, 121 if (wait_event_interruptible_timeout(sst_drv_ctx->wait_queue,
120 block->condition, 122 block->condition,
121 msecs_to_jiffies(timeout))) { 123 msecs_to_jiffies(timeout))) {
122 if (block->ret_code < 0) 124 if (block->ret_code < 0)
123 pr_err("sst: stream failed %d\n", block->ret_code); 125 pr_err("stream failed %d\n", block->ret_code);
124 else 126 else
125 pr_debug("sst: event up\n"); 127 pr_debug("event up\n");
126 retval = block->ret_code; 128 retval = block->ret_code;
127 } else { 129 } else {
128 block->on = false; 130 block->on = false;
129 pr_err("sst: timeout occured...\n"); 131 pr_err("timeout occurred...\n");
130 /*setting firmware state as uninit so that the 132 /*setting firmware state as uninit so that the
131 firmware will get re-downloaded on next request 133 firmware will get re-downloaded on next request
132 this is because firmare not responding for 5 sec 134 this is because firmare not responding for 5 sec
@@ -156,18 +158,18 @@ int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
156 /* NOTE: 158 /* NOTE:
157 Observed that FW processes the alloc msg and replies even 159 Observed that FW processes the alloc msg and replies even
158 before the alloc thread has finished execution */ 160 before the alloc thread has finished execution */
159 pr_debug("sst: waiting for %x, condition %x\n", 161 pr_debug("waiting for %x, condition %x\n",
160 block->sst_id, block->ops_block.condition); 162 block->sst_id, block->ops_block.condition);
161 if (wait_event_interruptible_timeout(sst_drv_ctx->wait_queue, 163 if (wait_event_interruptible_timeout(sst_drv_ctx->wait_queue,
162 block->ops_block.condition, 164 block->ops_block.condition,
163 msecs_to_jiffies(SST_BLOCK_TIMEOUT))) { 165 msecs_to_jiffies(SST_BLOCK_TIMEOUT))) {
164 /* event wake */ 166 /* event wake */
165 pr_debug("sst: Event wake %x\n", block->ops_block.condition); 167 pr_debug("Event wake %x\n", block->ops_block.condition);
166 pr_debug("sst: message ret: %d\n", block->ops_block.ret_code); 168 pr_debug("message ret: %d\n", block->ops_block.ret_code);
167 retval = block->ops_block.ret_code; 169 retval = block->ops_block.ret_code;
168 } else { 170 } else {
169 block->ops_block.on = false; 171 block->ops_block.on = false;
170 pr_err("sst: Wait timed-out %x\n", block->ops_block.condition); 172 pr_err("Wait timed-out %x\n", block->ops_block.condition);
171 /* settign firmware state as uninit so that the 173 /* settign firmware state as uninit so that the
172 firmware will get redownloaded on next request 174 firmware will get redownloaded on next request
173 this is because firmare not responding for 5 sec 175 this is because firmare not responding for 5 sec
@@ -192,14 +194,14 @@ int sst_create_large_msg(struct ipc_post **arg)
192 194
193 msg = kzalloc(sizeof(struct ipc_post), GFP_ATOMIC); 195 msg = kzalloc(sizeof(struct ipc_post), GFP_ATOMIC);
194 if (!msg) { 196 if (!msg) {
195 pr_err("sst: kzalloc msg failed\n"); 197 pr_err("kzalloc msg failed\n");
196 return -ENOMEM; 198 return -ENOMEM;
197 } 199 }
198 200
199 msg->mailbox_data = kzalloc(SST_MAILBOX_SIZE, GFP_ATOMIC); 201 msg->mailbox_data = kzalloc(SST_MAILBOX_SIZE, GFP_ATOMIC);
200 if (!msg->mailbox_data) { 202 if (!msg->mailbox_data) {
201 kfree(msg); 203 kfree(msg);
202 pr_err("sst: kzalloc mailbox_data failed"); 204 pr_err("kzalloc mailbox_data failed");
203 return -ENOMEM; 205 return -ENOMEM;
204 }; 206 };
205 *arg = msg; 207 *arg = msg;
@@ -219,7 +221,7 @@ int sst_create_short_msg(struct ipc_post **arg)
219 221
220 msg = kzalloc(sizeof(*msg), GFP_ATOMIC); 222 msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
221 if (!msg) { 223 if (!msg) {
222 pr_err("sst: kzalloc msg failed\n"); 224 pr_err("kzalloc msg failed\n");
223 return -ENOMEM; 225 return -ENOMEM;
224 } 226 }
225 msg->mailbox_data = NULL; 227 msg->mailbox_data = NULL;
@@ -290,10 +292,10 @@ int sst_enable_rx_timeslot(int status)
290 struct ipc_post *msg = NULL; 292 struct ipc_post *msg = NULL;
291 293
292 if (sst_create_short_msg(&msg)) { 294 if (sst_create_short_msg(&msg)) {
293 pr_err("sst: mem allocation failed\n"); 295 pr_err("mem allocation failed\n");
294 return -ENOMEM; 296 return -ENOMEM;
295 } 297 }
296 pr_debug("sst: ipc message sending: ENABLE_RX_TIME_SLOT\n"); 298 pr_debug("ipc message sending: ENABLE_RX_TIME_SLOT\n");
297 sst_fill_header(&msg->header, IPC_IA_ENABLE_RX_TIME_SLOT, 0, 0); 299 sst_fill_header(&msg->header, IPC_IA_ENABLE_RX_TIME_SLOT, 0, 0);
298 msg->header.part.data = status; 300 msg->header.part.data = status;
299 sst_drv_ctx->hs_info_blk.condition = false; 301 sst_drv_ctx->hs_info_blk.condition = false;
diff --git a/drivers/staging/intel_sst/intel_sst_stream.c b/drivers/staging/intel_sst/intel_sst_stream.c
index b2c4b7067da0..795e42ab7360 100644
--- a/drivers/staging/intel_sst/intel_sst_stream.c
+++ b/drivers/staging/intel_sst/intel_sst_stream.c
@@ -26,6 +26,8 @@
26 * This file contains the stream operations of SST driver 26 * This file contains the stream operations of SST driver
27 */ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/pci.h> 31#include <linux/pci.h>
30#include <linux/firmware.h> 32#include <linux/firmware.h>
31#include <linux/sched.h> 33#include <linux/sched.h>
@@ -45,8 +47,8 @@
45 */ 47 */
46int sst_check_device_type(u32 device, u32 num_chan, u32 *pcm_slot) 48int sst_check_device_type(u32 device, u32 num_chan, u32 *pcm_slot)
47{ 49{
48 if (device >= MAX_NUM_STREAMS) { 50 if (device > MAX_NUM_STREAMS_MFLD) {
49 pr_debug("sst: device type invalid %d\n", device); 51 pr_debug("device type invalid %d\n", device);
50 return -EINVAL; 52 return -EINVAL;
51 } 53 }
52 if (sst_drv_ctx->streams[device].status == STREAM_UN_INIT) { 54 if (sst_drv_ctx->streams[device].status == STREAM_UN_INIT) {
@@ -71,15 +73,15 @@ int sst_check_device_type(u32 device, u32 num_chan, u32 *pcm_slot)
71 else if (device == SND_SST_DEVICE_CAPTURE && num_chan == 4) 73 else if (device == SND_SST_DEVICE_CAPTURE && num_chan == 4)
72 *pcm_slot = 0x0F; 74 *pcm_slot = 0x0F;
73 else { 75 else {
74 pr_debug("sst: No condition satisfied.. ret err\n"); 76 pr_debug("No condition satisfied.. ret err\n");
75 return -EINVAL; 77 return -EINVAL;
76 } 78 }
77 } else { 79 } else {
78 pr_debug("sst: this stream state is not uni-init, is %d\n", 80 pr_debug("this stream state is not uni-init, is %d\n",
79 sst_drv_ctx->streams[device].status); 81 sst_drv_ctx->streams[device].status);
80 return -EBADRQC; 82 return -EBADRQC;
81 } 83 }
82 pr_debug("sst: returning slot %x\n", *pcm_slot); 84 pr_debug("returning slot %x\n", *pcm_slot);
83 return 0; 85 return 0;
84} 86}
85/** 87/**
@@ -96,7 +98,7 @@ static unsigned int get_mrst_stream_id(void)
96 if (sst_drv_ctx->streams[i].status == STREAM_UN_INIT) 98 if (sst_drv_ctx->streams[i].status == STREAM_UN_INIT)
97 return i; 99 return i;
98 } 100 }
99 pr_debug("sst: Didnt find empty stream for mrst\n"); 101 pr_debug("Didnt find empty stream for mrst\n");
100 return -EBUSY; 102 return -EBUSY;
101} 103}
102 104
@@ -305,7 +307,7 @@ int sst_pause_stream(int str_id)
305 if (str_info->prev == STREAM_UN_INIT) 307 if (str_info->prev == STREAM_UN_INIT)
306 return -EBADRQC; 308 return -EBADRQC;
307 if (str_info->ctrl_blk.on == true) { 309 if (str_info->ctrl_blk.on == true) {
308 pr_err("SST ERR: control path is in use\n "); 310 pr_err("SST ERR: control path is in use\n");
309 return -EINVAL; 311 return -EINVAL;
310 } 312 }
311 if (sst_create_short_msg(&msg)) 313 if (sst_create_short_msg(&msg))
@@ -333,7 +335,7 @@ int sst_pause_stream(int str_id)
333 } 335 }
334 } else { 336 } else {
335 retval = -EBADRQC; 337 retval = -EBADRQC;
336 pr_err("SST ERR:BADQRC for stream\n "); 338 pr_err("SST ERR: BADQRC for stream\n");
337 } 339 }
338 340
339 return retval; 341 return retval;
@@ -468,7 +470,7 @@ int sst_drop_stream(int str_id)
468 } 470 }
469 } else { 471 } else {
470 retval = -EBADRQC; 472 retval = -EBADRQC;
471 pr_err("SST ERR:BADQRC for stream\n"); 473 pr_err("SST ERR: BADQRC for stream\n");
472 } 474 }
473 return retval; 475 return retval;
474} 476}
diff --git a/drivers/staging/intel_sst/intel_sst_stream_encoded.c b/drivers/staging/intel_sst/intel_sst_stream_encoded.c
index 5c455608b024..85789ba65186 100644
--- a/drivers/staging/intel_sst/intel_sst_stream_encoded.c
+++ b/drivers/staging/intel_sst/intel_sst_stream_encoded.c
@@ -26,13 +26,15 @@
26 * This file contains the stream operations of SST driver 26 * This file contains the stream operations of SST driver
27 */ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/pci.h> 31#include <linux/pci.h>
30#include <linux/syscalls.h> 32#include <linux/syscalls.h>
31#include <linux/firmware.h> 33#include <linux/firmware.h>
32#include <linux/sched.h> 34#include <linux/sched.h>
33#include <linux/rar_register.h>
34#ifdef CONFIG_MRST_RAR_HANDLER 35#ifdef CONFIG_MRST_RAR_HANDLER
35#include "../../../drivers/staging/memrar/memrar.h" 36#include <linux/rar_register.h>
37#include "../memrar/memrar.h"
36#endif 38#endif
37#include "intel_sst_ioctl.h" 39#include "intel_sst_ioctl.h"
38#include "intel_sst.h" 40#include "intel_sst.h"
@@ -53,7 +55,7 @@ int sst_get_stream_params(int str_id,
53 struct stream_info *str_info; 55 struct stream_info *str_info;
54 struct snd_sst_fw_get_stream_params *fw_params; 56 struct snd_sst_fw_get_stream_params *fw_params;
55 57
56 pr_debug("sst: get_stream for %d\n", str_id); 58 pr_debug("get_stream for %d\n", str_id);
57 retval = sst_validate_strid(str_id); 59 retval = sst_validate_strid(str_id);
58 if (retval) 60 if (retval)
59 return retval; 61 return retval;
@@ -61,16 +63,16 @@ int sst_get_stream_params(int str_id,
61 str_info = &sst_drv_ctx->streams[str_id]; 63 str_info = &sst_drv_ctx->streams[str_id];
62 if (str_info->status != STREAM_UN_INIT) { 64 if (str_info->status != STREAM_UN_INIT) {
63 if (str_info->ctrl_blk.on == true) { 65 if (str_info->ctrl_blk.on == true) {
64 pr_err("sst: control path in use\n"); 66 pr_err("control path in use\n");
65 return -EINVAL; 67 return -EINVAL;
66 } 68 }
67 if (sst_create_short_msg(&msg)) { 69 if (sst_create_short_msg(&msg)) {
68 pr_err("sst: message creation failed\n"); 70 pr_err("message creation failed\n");
69 return -ENOMEM; 71 return -ENOMEM;
70 } 72 }
71 fw_params = kzalloc(sizeof(*fw_params), GFP_ATOMIC); 73 fw_params = kzalloc(sizeof(*fw_params), GFP_ATOMIC);
72 if (!fw_params) { 74 if (!fw_params) {
73 pr_err("sst: mem allcoation failed\n "); 75 pr_err("mem allocation failed\n");
74 kfree(msg); 76 kfree(msg);
75 return -ENOMEM; 77 return -ENOMEM;
76 } 78 }
@@ -104,7 +106,7 @@ int sst_get_stream_params(int str_id,
104 get_params->codec_params.stream_type = str_info->str_type; 106 get_params->codec_params.stream_type = str_info->str_type;
105 kfree(fw_params); 107 kfree(fw_params);
106 } else { 108 } else {
107 pr_debug("sst: Stream is not in the init state\n"); 109 pr_debug("Stream is not in the init state\n");
108 } 110 }
109 return retval; 111 return retval;
110} 112}
@@ -125,17 +127,17 @@ int sst_set_stream_param(int str_id, struct snd_sst_params *str_param)
125 127
126 BUG_ON(!str_param); 128 BUG_ON(!str_param);
127 if (sst_drv_ctx->streams[str_id].ops != str_param->ops) { 129 if (sst_drv_ctx->streams[str_id].ops != str_param->ops) {
128 pr_err("sst: Invalid operation\n"); 130 pr_err("Invalid operation\n");
129 return -EINVAL; 131 return -EINVAL;
130 } 132 }
131 retval = sst_validate_strid(str_id); 133 retval = sst_validate_strid(str_id);
132 if (retval) 134 if (retval)
133 return retval; 135 return retval;
134 pr_debug("sst: set_stream for %d\n", str_id); 136 pr_debug("set_stream for %d\n", str_id);
135 str_info = &sst_drv_ctx->streams[str_id]; 137 str_info = &sst_drv_ctx->streams[str_id];
136 if (sst_drv_ctx->streams[str_id].status == STREAM_INIT) { 138 if (sst_drv_ctx->streams[str_id].status == STREAM_INIT) {
137 if (str_info->ctrl_blk.on == true) { 139 if (str_info->ctrl_blk.on == true) {
138 pr_err("sst: control path in use\n"); 140 pr_err("control path in use\n");
139 return -EAGAIN; 141 return -EAGAIN;
140 } 142 }
141 if (sst_create_large_msg(&msg)) 143 if (sst_create_large_msg(&msg))
@@ -163,7 +165,7 @@ int sst_set_stream_param(int str_id, struct snd_sst_params *str_param)
163 } 165 }
164 } else { 166 } else {
165 retval = -EBADRQC; 167 retval = -EBADRQC;
166 pr_err("sst: BADQRC for stream\n"); 168 pr_err("BADQRC for stream\n");
167 } 169 }
168 return retval; 170 return retval;
169} 171}
@@ -183,7 +185,7 @@ int sst_get_vol(struct snd_sst_vol *get_vol)
183 struct snd_sst_vol *fw_get_vol; 185 struct snd_sst_vol *fw_get_vol;
184 int str_id = get_vol->stream_id; 186 int str_id = get_vol->stream_id;
185 187
186 pr_debug("sst: get vol called\n"); 188 pr_debug("get vol called\n");
187 189
188 if (sst_create_short_msg(&msg)) 190 if (sst_create_short_msg(&msg))
189 return -ENOMEM; 191 return -ENOMEM;
@@ -195,7 +197,7 @@ int sst_get_vol(struct snd_sst_vol *get_vol)
195 sst_drv_ctx->vol_info_blk.on = true; 197 sst_drv_ctx->vol_info_blk.on = true;
196 fw_get_vol = kzalloc(sizeof(*fw_get_vol), GFP_ATOMIC); 198 fw_get_vol = kzalloc(sizeof(*fw_get_vol), GFP_ATOMIC);
197 if (!fw_get_vol) { 199 if (!fw_get_vol) {
198 pr_err("sst: mem allocation failed\n"); 200 pr_err("mem allocation failed\n");
199 kfree(msg); 201 kfree(msg);
200 return -ENOMEM; 202 return -ENOMEM;
201 } 203 }
@@ -209,10 +211,10 @@ int sst_get_vol(struct snd_sst_vol *get_vol)
209 if (retval) 211 if (retval)
210 retval = -EIO; 212 retval = -EIO;
211 else { 213 else {
212 pr_debug("sst: stream id %d\n", fw_get_vol->stream_id); 214 pr_debug("stream id %d\n", fw_get_vol->stream_id);
213 pr_debug("sst: volume %d\n", fw_get_vol->volume); 215 pr_debug("volume %d\n", fw_get_vol->volume);
214 pr_debug("sst: ramp duration %d\n", fw_get_vol->ramp_duration); 216 pr_debug("ramp duration %d\n", fw_get_vol->ramp_duration);
215 pr_debug("sst: ramp_type %d\n", fw_get_vol->ramp_type); 217 pr_debug("ramp_type %d\n", fw_get_vol->ramp_type);
216 memcpy(get_vol, fw_get_vol, sizeof(*fw_get_vol)); 218 memcpy(get_vol, fw_get_vol, sizeof(*fw_get_vol));
217 } 219 }
218 return retval; 220 return retval;
@@ -231,10 +233,10 @@ int sst_set_vol(struct snd_sst_vol *set_vol)
231 int retval = 0; 233 int retval = 0;
232 struct ipc_post *msg = NULL; 234 struct ipc_post *msg = NULL;
233 235
234 pr_debug("sst: set vol called\n"); 236 pr_debug("set vol called\n");
235 237
236 if (sst_create_large_msg(&msg)) { 238 if (sst_create_large_msg(&msg)) {
237 pr_err("sst: message creation failed\n"); 239 pr_err("message creation failed\n");
238 return -ENOMEM; 240 return -ENOMEM;
239 } 241 }
240 sst_fill_header(&msg->header, IPC_IA_SET_STREAM_VOL, 1, 242 sst_fill_header(&msg->header, IPC_IA_SET_STREAM_VOL, 1,
@@ -254,7 +256,7 @@ int sst_set_vol(struct snd_sst_vol *set_vol)
254 retval = sst_wait_interruptible_timeout(sst_drv_ctx, 256 retval = sst_wait_interruptible_timeout(sst_drv_ctx,
255 &sst_drv_ctx->vol_info_blk, SST_BLOCK_TIMEOUT); 257 &sst_drv_ctx->vol_info_blk, SST_BLOCK_TIMEOUT);
256 if (retval) { 258 if (retval) {
257 pr_err("sst: error in set_vol = %d\n", retval); 259 pr_err("error in set_vol = %d\n", retval);
258 retval = -EIO; 260 retval = -EIO;
259 } 261 }
260 return retval; 262 return retval;
@@ -273,10 +275,10 @@ int sst_set_mute(struct snd_sst_mute *set_mute)
273 int retval = 0; 275 int retval = 0;
274 struct ipc_post *msg = NULL; 276 struct ipc_post *msg = NULL;
275 277
276 pr_debug("sst: set mute called\n"); 278 pr_debug("set mute called\n");
277 279
278 if (sst_create_large_msg(&msg)) { 280 if (sst_create_large_msg(&msg)) {
279 pr_err("sst: message creation failed\n"); 281 pr_err("message creation failed\n");
280 return -ENOMEM; 282 return -ENOMEM;
281 } 283 }
282 sst_fill_header(&msg->header, IPC_IA_SET_STREAM_MUTE, 1, 284 sst_fill_header(&msg->header, IPC_IA_SET_STREAM_MUTE, 1,
@@ -297,7 +299,7 @@ int sst_set_mute(struct snd_sst_mute *set_mute)
297 retval = sst_wait_interruptible_timeout(sst_drv_ctx, 299 retval = sst_wait_interruptible_timeout(sst_drv_ctx,
298 &sst_drv_ctx->mute_info_blk, SST_BLOCK_TIMEOUT); 300 &sst_drv_ctx->mute_info_blk, SST_BLOCK_TIMEOUT);
299 if (retval) { 301 if (retval) {
300 pr_err("sst: error in set_mute = %d\n", retval); 302 pr_err("error in set_mute = %d\n", retval);
301 retval = -EIO; 303 retval = -EIO;
302 } 304 }
303 return retval; 305 return retval;
@@ -358,20 +360,20 @@ int sst_parse_target(struct snd_sst_slot_info *slot)
358 slot->device_type == SND_SST_DEVICE_PCM) { 360 slot->device_type == SND_SST_DEVICE_PCM) {
359 retval = sst_activate_target(slot); 361 retval = sst_activate_target(slot);
360 if (retval) 362 if (retval)
361 pr_err("sst: SST_Activate_target_fail\n"); 363 pr_err("SST_Activate_target_fail\n");
362 else 364 else
363 pr_err("sst: SST_Activate_target_pass\n"); 365 pr_err("SST_Activate_target_pass\n");
364 return retval; 366 return retval;
365 } else if (slot->action == SND_SST_PORT_PREPARE && 367 } else if (slot->action == SND_SST_PORT_PREPARE &&
366 slot->device_type == SND_SST_DEVICE_PCM) { 368 slot->device_type == SND_SST_DEVICE_PCM) {
367 retval = sst_prepare_target(slot); 369 retval = sst_prepare_target(slot);
368 if (retval) 370 if (retval)
369 pr_err("sst: SST_prepare_target_fail\n"); 371 pr_err("SST_prepare_target_fail\n");
370 else 372 else
371 pr_err("sst: SST_prepare_target_pass\n"); 373 pr_err("SST_prepare_target_pass\n");
372 return retval; 374 return retval;
373 } else { 375 } else {
374 pr_err("sst: slot_action : %d, device_type: %d\n", 376 pr_err("slot_action : %d, device_type: %d\n",
375 slot->action, slot->device_type); 377 slot->action, slot->device_type);
376 return retval; 378 return retval;
377 } 379 }
@@ -383,7 +385,7 @@ int sst_send_target(struct snd_sst_target_device *target)
383 struct ipc_post *msg; 385 struct ipc_post *msg;
384 386
385 if (sst_create_large_msg(&msg)) { 387 if (sst_create_large_msg(&msg)) {
386 pr_err("sst: message creation failed\n"); 388 pr_err("message creation failed\n");
387 return -ENOMEM; 389 return -ENOMEM;
388 } 390 }
389 sst_fill_header(&msg->header, IPC_IA_TARGET_DEV_SELECT, 1, 0); 391 sst_fill_header(&msg->header, IPC_IA_TARGET_DEV_SELECT, 1, 0);
@@ -399,11 +401,11 @@ int sst_send_target(struct snd_sst_target_device *target)
399 list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list); 401 list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list);
400 spin_unlock(&sst_drv_ctx->list_spin_lock); 402 spin_unlock(&sst_drv_ctx->list_spin_lock);
401 sst_post_message(&sst_drv_ctx->ipc_post_msg_wq); 403 sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
402 pr_debug("sst: message sent- waiting\n"); 404 pr_debug("message sent- waiting\n");
403 retval = sst_wait_interruptible_timeout(sst_drv_ctx, 405 retval = sst_wait_interruptible_timeout(sst_drv_ctx,
404 &sst_drv_ctx->tgt_dev_blk, TARGET_DEV_BLOCK_TIMEOUT); 406 &sst_drv_ctx->tgt_dev_blk, TARGET_DEV_BLOCK_TIMEOUT);
405 if (retval) 407 if (retval)
406 pr_err("sst: target device ipc failed = 0x%x\n", retval); 408 pr_err("target device ipc failed = 0x%x\n", retval);
407 return retval; 409 return retval;
408 410
409} 411}
@@ -439,7 +441,7 @@ int sst_target_device_validate(struct snd_sst_target_device *target)
439 goto err; 441 goto err;
440 } else { 442 } else {
441err: 443err:
442 pr_err("sst: i/p params incorrect\n"); 444 pr_err("i/p params incorrect\n");
443 return -EINVAL; 445 return -EINVAL;
444 } 446 }
445 } 447 }
@@ -460,15 +462,15 @@ int sst_target_device_select(struct snd_sst_target_device *target)
460{ 462{
461 int retval, i, prepare_count = 0; 463 int retval, i, prepare_count = 0;
462 464
463 pr_debug("sst: Target Device Select\n"); 465 pr_debug("Target Device Select\n");
464 466
465 if (target->device_route < 0 || target->device_route > 2) { 467 if (target->device_route < 0 || target->device_route > 2) {
466 pr_err("sst: device route is invalid\n"); 468 pr_err("device route is invalid\n");
467 return -EINVAL; 469 return -EINVAL;
468 } 470 }
469 471
470 if (target->device_route != 0) { 472 if (target->device_route != 0) {
471 pr_err("sst: Unsupported config\n"); 473 pr_err("Unsupported config\n");
472 return -EIO; 474 return -EIO;
473 } 475 }
474 retval = sst_target_device_validate(target); 476 retval = sst_target_device_validate(target);
@@ -480,18 +482,18 @@ int sst_target_device_select(struct snd_sst_target_device *target)
480 return retval; 482 return retval;
481 for (i = 0; i < SST_MAX_TARGET_DEVICES; i++) { 483 for (i = 0; i < SST_MAX_TARGET_DEVICES; i++) {
482 if (target->devices[i].action == SND_SST_PORT_ACTIVATE) { 484 if (target->devices[i].action == SND_SST_PORT_ACTIVATE) {
483 pr_debug("sst: activate called in %d\n", i); 485 pr_debug("activate called in %d\n", i);
484 retval = sst_parse_target(&target->devices[i]); 486 retval = sst_parse_target(&target->devices[i]);
485 if (retval) 487 if (retval)
486 return retval; 488 return retval;
487 } else if (target->devices[i].action == SND_SST_PORT_PREPARE) { 489 } else if (target->devices[i].action == SND_SST_PORT_PREPARE) {
488 pr_debug("sst: PREPARE in %d, Forwading\n", i); 490 pr_debug("PREPARE in %d, Forwarding\n", i);
489 retval = sst_parse_target(&target->devices[i]); 491 retval = sst_parse_target(&target->devices[i]);
490 if (retval) { 492 if (retval) {
491 pr_err("sst: Parse Target fail %d", retval); 493 pr_err("Parse Target fail %d\n", retval);
492 return retval; 494 return retval;
493 } 495 }
494 pr_debug("sst: Parse Target successful %d", retval); 496 pr_debug("Parse Target successful %d\n", retval);
495 if (target->devices[i].device_type == 497 if (target->devices[i].device_type ==
496 SND_SST_DEVICE_PCM) 498 SND_SST_DEVICE_PCM)
497 prepare_count++; 499 prepare_count++;
@@ -512,11 +514,11 @@ static inline int sst_get_RAR(struct RAR_buffer *buffers, int count)
512 rar_status = rar_handle_to_bus(buffers, count); 514 rar_status = rar_handle_to_bus(buffers, count);
513 515
514 if (count != rar_status) { 516 if (count != rar_status) {
515 pr_err("sst: The rar CALL Failed"); 517 pr_err("The rar CALL Failed");
516 retval = -EIO; 518 retval = -EIO;
517 } 519 }
518 if (buffers->info.type != RAR_TYPE_AUDIO) { 520 if (buffers->info.type != RAR_TYPE_AUDIO) {
519 pr_err("sst: Invalid RAR type\n"); 521 pr_err("Invalid RAR type\n");
520 return -EINVAL; 522 return -EINVAL;
521 } 523 }
522 return retval; 524 return retval;
@@ -539,10 +541,10 @@ static int sst_create_sg_list(struct stream_info *stream,
539 if (kbufs->in_use == false) { 541 if (kbufs->in_use == false) {
540#ifdef CONFIG_MRST_RAR_HANDLER 542#ifdef CONFIG_MRST_RAR_HANDLER
541 if (stream->ops == STREAM_OPS_PLAYBACK_DRM) { 543 if (stream->ops == STREAM_OPS_PLAYBACK_DRM) {
542 pr_debug("sst: DRM playback handling\n"); 544 pr_debug("DRM playback handling\n");
543 rar_buffers.info.handle = (__u32)kbufs->addr; 545 rar_buffers.info.handle = (__u32)kbufs->addr;
544 rar_buffers.info.size = kbufs->size; 546 rar_buffers.info.size = kbufs->size;
545 pr_debug("sst: rar handle 0x%x size=0x%x", 547 pr_debug("rar handle 0x%x size=0x%x\n",
546 rar_buffers.info.handle, 548 rar_buffers.info.handle,
547 rar_buffers.info.size); 549 rar_buffers.info.size);
548 retval = sst_get_RAR(&rar_buffers, 1); 550 retval = sst_get_RAR(&rar_buffers, 1);
@@ -552,7 +554,7 @@ static int sst_create_sg_list(struct stream_info *stream,
552 sg_list->addr[i].addr = rar_buffers.bus_address; 554 sg_list->addr[i].addr = rar_buffers.bus_address;
553 /* rar_buffers.info.size; */ 555 /* rar_buffers.info.size; */
554 sg_list->addr[i].size = (__u32)kbufs->size; 556 sg_list->addr[i].size = (__u32)kbufs->size;
555 pr_debug("sst: phyaddr[%d] 0x%x Size:0x%x\n" 557 pr_debug("phyaddr[%d] 0x%x Size:0x%x\n"
556 , i, sg_list->addr[i].addr, 558 , i, sg_list->addr[i].addr,
557 sg_list->addr[i].size); 559 sg_list->addr[i].size);
558 } 560 }
@@ -562,7 +564,7 @@ static int sst_create_sg_list(struct stream_info *stream,
562 virt_to_phys((void *) 564 virt_to_phys((void *)
563 kbufs->addr + kbufs->offset); 565 kbufs->addr + kbufs->offset);
564 sg_list->addr[i].size = kbufs->size; 566 sg_list->addr[i].size = kbufs->size;
565 pr_debug("sst: phyaddr[%d]:0x%x Size:0x%x\n" 567 pr_debug("phyaddr[%d]:0x%x Size:0x%x\n"
566 , i , sg_list->addr[i].addr, kbufs->size); 568 , i , sg_list->addr[i].addr, kbufs->size);
567 } 569 }
568 stream->curr_bytes += sg_list->addr[i].size; 570 stream->curr_bytes += sg_list->addr[i].size;
@@ -574,7 +576,7 @@ static int sst_create_sg_list(struct stream_info *stream,
574 } 576 }
575 577
576 sg_list->num_entries = i; 578 sg_list->num_entries = i;
577 pr_debug("sst:sg list entries = %d\n", sg_list->num_entries); 579 pr_debug("sg list entries = %d\n", sg_list->num_entries);
578 return i; 580 return i;
579} 581}
580 582
@@ -595,7 +597,7 @@ int sst_play_frame(int str_id)
595 struct sst_stream_bufs *kbufs = NULL, *_kbufs; 597 struct sst_stream_bufs *kbufs = NULL, *_kbufs;
596 struct stream_info *stream; 598 struct stream_info *stream;
597 599
598 pr_debug("sst: play frame for %d\n", str_id); 600 pr_debug("play frame for %d\n", str_id);
599 retval = sst_validate_strid(str_id); 601 retval = sst_validate_strid(str_id);
600 if (retval) 602 if (retval)
601 return retval; 603 return retval;
@@ -615,14 +617,14 @@ int sst_play_frame(int str_id)
615 stream->curr_bytes = 0; 617 stream->curr_bytes = 0;
616 if (list_empty(&stream->bufs)) { 618 if (list_empty(&stream->bufs)) {
617 /* no user buffer available */ 619 /* no user buffer available */
618 pr_debug("sst: Null buffer stream status %d\n", stream->status); 620 pr_debug("Null buffer stream status %d\n", stream->status);
619 stream->prev = stream->status; 621 stream->prev = stream->status;
620 stream->status = STREAM_INIT; 622 stream->status = STREAM_INIT;
621 pr_debug("sst:new stream status = %d\n", stream->status); 623 pr_debug("new stream status = %d\n", stream->status);
622 if (stream->need_draining == true) { 624 if (stream->need_draining == true) {
623 pr_debug("sst:draining stream\n"); 625 pr_debug("draining stream\n");
624 if (sst_create_short_msg(&msg)) { 626 if (sst_create_short_msg(&msg)) {
625 pr_err("sst: mem alloc failed\n"); 627 pr_err("mem allocation failed\n");
626 return -ENOMEM; 628 return -ENOMEM;
627 } 629 }
628 sst_fill_header(&msg->header, IPC_IA_DRAIN_STREAM, 630 sst_fill_header(&msg->header, IPC_IA_DRAIN_STREAM,
@@ -633,7 +635,7 @@ int sst_play_frame(int str_id)
633 spin_unlock(&sst_drv_ctx->list_spin_lock); 635 spin_unlock(&sst_drv_ctx->list_spin_lock);
634 sst_post_message(&sst_drv_ctx->ipc_post_msg_wq); 636 sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
635 } else if (stream->data_blk.on == true) { 637 } else if (stream->data_blk.on == true) {
636 pr_debug("sst:user list empty.. wake\n"); 638 pr_debug("user list empty.. wake\n");
637 /* unblock */ 639 /* unblock */
638 stream->data_blk.ret_code = 0; 640 stream->data_blk.ret_code = 0;
639 stream->data_blk.condition = true; 641 stream->data_blk.condition = true;
@@ -678,7 +680,7 @@ int sst_capture_frame(int str_id)
678 struct stream_info *stream; 680 struct stream_info *stream;
679 681
680 682
681 pr_debug("sst:capture frame for %d\n", str_id); 683 pr_debug("capture frame for %d\n", str_id);
682 retval = sst_validate_strid(str_id); 684 retval = sst_validate_strid(str_id);
683 if (retval) 685 if (retval)
684 return retval; 686 return retval;
@@ -688,19 +690,19 @@ int sst_capture_frame(int str_id)
688 if (kbufs->in_use == true) { 690 if (kbufs->in_use == true) {
689 list_del(&kbufs->node); 691 list_del(&kbufs->node);
690 kfree(kbufs); 692 kfree(kbufs);
691 pr_debug("sst:del node\n"); 693 pr_debug("del node\n");
692 } 694 }
693 } 695 }
694 if (list_empty(&stream->bufs)) { 696 if (list_empty(&stream->bufs)) {
695 /* no user buffer available */ 697 /* no user buffer available */
696 pr_debug("sst:Null buffer!!!!stream status %d\n", 698 pr_debug("Null buffer!!!!stream status %d\n",
697 stream->status); 699 stream->status);
698 stream->prev = stream->status; 700 stream->prev = stream->status;
699 stream->status = STREAM_INIT; 701 stream->status = STREAM_INIT;
700 pr_debug("sst:new stream status = %d\n", 702 pr_debug("new stream status = %d\n",
701 stream->status); 703 stream->status);
702 if (stream->data_blk.on == true) { 704 if (stream->data_blk.on == true) {
703 pr_debug("sst:user list empty.. wake\n"); 705 pr_debug("user list empty.. wake\n");
704 /* unblock */ 706 /* unblock */
705 stream->data_blk.ret_code = 0; 707 stream->data_blk.ret_code = 0;
706 stream->data_blk.condition = true; 708 stream->data_blk.condition = true;
@@ -731,7 +733,7 @@ int sst_capture_frame(int str_id)
731 stream->cumm_bytes += stream->curr_bytes; 733 stream->cumm_bytes += stream->curr_bytes;
732 stream->curr_bytes = 0; 734 stream->curr_bytes = 0;
733 735
734 pr_debug("sst:Cum bytes = %d\n", stream->cumm_bytes); 736 pr_debug("Cum bytes = %d\n", stream->cumm_bytes);
735 return 0; 737 return 0;
736} 738}
737 739
@@ -743,7 +745,7 @@ static unsigned int calculate_min_size(struct snd_sst_buffs *bufs)
743 if (bufs->buff_entry[i].size < min_val) 745 if (bufs->buff_entry[i].size < min_val)
744 min_val = bufs->buff_entry[i].size; 746 min_val = bufs->buff_entry[i].size;
745 } 747 }
746 pr_debug("sst:min_val = %d\n", min_val); 748 pr_debug("min_val = %d\n", min_val);
747 return min_val; 749 return min_val;
748} 750}
749 751
@@ -754,7 +756,7 @@ static unsigned int calculate_max_size(struct snd_sst_buffs *bufs)
754 if (bufs->buff_entry[i].size > max_val) 756 if (bufs->buff_entry[i].size > max_val)
755 max_val = bufs->buff_entry[i].size; 757 max_val = bufs->buff_entry[i].size;
756 } 758 }
757 pr_debug("sst:max_val = %d\n", max_val); 759 pr_debug("max_val = %d\n", max_val);
758 return max_val; 760 return max_val;
759} 761}
760 762
@@ -773,7 +775,7 @@ static int sst_allocate_decode_buf(struct stream_info *str_info,
773 if (dbufs->ibufs->entries == dbufs->obufs->entries) 775 if (dbufs->ibufs->entries == dbufs->obufs->entries)
774 return 0; 776 return 0;
775 else { 777 else {
776 pr_err("sst: RAR entries dont match\n"); 778 pr_err("RAR entries dont match\n");
777 return -EINVAL; 779 return -EINVAL;
778 } 780 }
779 } else 781 } else
@@ -783,26 +785,26 @@ static int sst_allocate_decode_buf(struct stream_info *str_info,
783 } 785 }
784#endif 786#endif
785 if (!str_info->decode_ibuf) { 787 if (!str_info->decode_ibuf) {
786 pr_debug("sst:no i/p buffers, trying full size\n"); 788 pr_debug("no i/p buffers, trying full size\n");
787 str_info->decode_isize = cum_input_given; 789 str_info->decode_isize = cum_input_given;
788 str_info->decode_ibuf = kzalloc(str_info->decode_isize, 790 str_info->decode_ibuf = kzalloc(str_info->decode_isize,
789 GFP_KERNEL); 791 GFP_KERNEL);
790 str_info->idecode_alloc = str_info->decode_isize; 792 str_info->idecode_alloc = str_info->decode_isize;
791 } 793 }
792 if (!str_info->decode_ibuf) { 794 if (!str_info->decode_ibuf) {
793 pr_debug("sst:buff alloc failed, try max size\n"); 795 pr_debug("buff alloc failed, try max size\n");
794 str_info->decode_isize = calculate_max_size(dbufs->ibufs); 796 str_info->decode_isize = calculate_max_size(dbufs->ibufs);
795 str_info->decode_ibuf = kzalloc( 797 str_info->decode_ibuf = kzalloc(
796 str_info->decode_isize, GFP_KERNEL); 798 str_info->decode_isize, GFP_KERNEL);
797 str_info->idecode_alloc = str_info->decode_isize; 799 str_info->idecode_alloc = str_info->decode_isize;
798 } 800 }
799 if (!str_info->decode_ibuf) { 801 if (!str_info->decode_ibuf) {
800 pr_debug("sst:buff alloc failed, try min size\n"); 802 pr_debug("buff alloc failed, try min size\n");
801 str_info->decode_isize = calculate_min_size(dbufs->ibufs); 803 str_info->decode_isize = calculate_min_size(dbufs->ibufs);
802 str_info->decode_ibuf = kzalloc(str_info->decode_isize, 804 str_info->decode_ibuf = kzalloc(str_info->decode_isize,
803 GFP_KERNEL); 805 GFP_KERNEL);
804 if (!str_info->decode_ibuf) { 806 if (!str_info->decode_ibuf) {
805 pr_err("sst: mem allocation failed\n"); 807 pr_err("mem allocation failed\n");
806 return -ENOMEM; 808 return -ENOMEM;
807 } 809 }
808 str_info->idecode_alloc = str_info->decode_isize; 810 str_info->idecode_alloc = str_info->decode_isize;
@@ -820,7 +822,7 @@ static int sst_send_decode_mess(int str_id, struct stream_info *str_info,
820 struct ipc_post *msg = NULL; 822 struct ipc_post *msg = NULL;
821 int retval = 0; 823 int retval = 0;
822 824
823 pr_debug("SST DBGsst_set_mute:called\n"); 825 pr_debug("SST DBG:sst_set_mute:called\n");
824 826
825 if (str_info->decode_ibuf_type == SST_BUF_RAR) { 827 if (str_info->decode_ibuf_type == SST_BUF_RAR) {
826#ifdef CONFIG_MRST_RAR_HANDLER 828#ifdef CONFIG_MRST_RAR_HANDLER
@@ -857,7 +859,7 @@ static int sst_send_decode_mess(int str_id, struct stream_info *str_info,
857 dec_info->input_bytes_consumed = 0; 859 dec_info->input_bytes_consumed = 0;
858 dec_info->output_bytes_produced = 0; 860 dec_info->output_bytes_produced = 0;
859 if (sst_create_large_msg(&msg)) { 861 if (sst_create_large_msg(&msg)) {
860 pr_err("sst: message creation failed\n"); 862 pr_err("message creation failed\n");
861 return -ENOMEM; 863 return -ENOMEM;
862 } 864 }
863 865
@@ -878,13 +880,13 @@ static int sst_send_decode_mess(int str_id, struct stream_info *str_info,
878 return retval; 880 return retval;
879} 881}
880 882
883#ifdef CONFIG_MRST_RAR_HANDLER
881static int sst_prepare_input_buffers_rar(struct stream_info *str_info, 884static int sst_prepare_input_buffers_rar(struct stream_info *str_info,
882 struct snd_sst_dbufs *dbufs, 885 struct snd_sst_dbufs *dbufs,
883 int *input_index, int *in_copied, 886 int *input_index, int *in_copied,
884 int *input_index_valid_size, int *new_entry_flag) 887 int *input_index_valid_size, int *new_entry_flag)
885{ 888{
886 int retval = 0; 889 int retval = 0;
887#ifdef CONFIG_MRST_RAR_HANDLER
888 int i; 890 int i;
889 891
890 if (str_info->ops == STREAM_OPS_PLAYBACK_DRM) { 892 if (str_info->ops == STREAM_OPS_PLAYBACK_DRM) {
@@ -894,7 +896,7 @@ static int sst_prepare_input_buffers_rar(struct stream_info *str_info,
894 dbufs->ibufs->buff_entry[i].buffer, 896 dbufs->ibufs->buff_entry[i].buffer,
895 sizeof(__u32)); 897 sizeof(__u32));
896 if (retval) { 898 if (retval) {
897 pr_err("sst:cpy from user fail\n"); 899 pr_err("cpy from user fail\n");
898 return -EAGAIN; 900 return -EAGAIN;
899 } 901 }
900 rar_buffers.info.type = dbufs->ibufs->type; 902 rar_buffers.info.type = dbufs->ibufs->type;
@@ -919,9 +921,10 @@ static int sst_prepare_input_buffers_rar(struct stream_info *str_info,
919 str_info->decode_ibuf_type = dbufs->ibufs->type; 921 str_info->decode_ibuf_type = dbufs->ibufs->type;
920 *in_copied = str_info->decode_isize; 922 *in_copied = str_info->decode_isize;
921 } 923 }
922#endif
923 return retval; 924 return retval;
924} 925}
926#endif
927
925/*This function is used to prepare the kernel input buffers with contents 928/*This function is used to prepare the kernel input buffers with contents
926before sending for decode*/ 929before sending for decode*/
927static int sst_prepare_input_buffers(struct stream_info *str_info, 930static int sst_prepare_input_buffers(struct stream_info *str_info,
@@ -931,7 +934,7 @@ static int sst_prepare_input_buffers(struct stream_info *str_info,
931{ 934{
932 int i, cpy_size, retval = 0; 935 int i, cpy_size, retval = 0;
933 936
934 pr_debug("sst:input_index = %d, input entries = %d\n", 937 pr_debug("input_index = %d, input entries = %d\n",
935 *input_index, dbufs->ibufs->entries); 938 *input_index, dbufs->ibufs->entries);
936 for (i = *input_index; i < dbufs->ibufs->entries; i++) { 939 for (i = *input_index; i < dbufs->ibufs->entries; i++) {
937#ifdef CONFIG_MRST_RAR_HANDLER 940#ifdef CONFIG_MRST_RAR_HANDLER
@@ -939,7 +942,7 @@ static int sst_prepare_input_buffers(struct stream_info *str_info,
939 dbufs, input_index, in_copied, 942 dbufs, input_index, in_copied,
940 input_index_valid_size, new_entry_flag); 943 input_index_valid_size, new_entry_flag);
941 if (retval) { 944 if (retval) {
942 pr_err("sst: In prepare input buffers for RAR\n"); 945 pr_err("In prepare input buffers for RAR\n");
943 return -EIO; 946 return -EIO;
944 } 947 }
945#endif 948#endif
@@ -947,10 +950,10 @@ static int sst_prepare_input_buffers(struct stream_info *str_info,
947 if (*input_index_valid_size == 0) 950 if (*input_index_valid_size == 0)
948 *input_index_valid_size = 951 *input_index_valid_size =
949 dbufs->ibufs->buff_entry[i].size; 952 dbufs->ibufs->buff_entry[i].size;
950 pr_debug("sst:inout addr = %p, size = %d\n", 953 pr_debug("inout addr = %p, size = %d\n",
951 dbufs->ibufs->buff_entry[i].buffer, 954 dbufs->ibufs->buff_entry[i].buffer,
952 *input_index_valid_size); 955 *input_index_valid_size);
953 pr_debug("sst:decode_isize = %d, in_copied %d\n", 956 pr_debug("decode_isize = %d, in_copied %d\n",
954 str_info->decode_isize, *in_copied); 957 str_info->decode_isize, *in_copied);
955 if (*input_index_valid_size <= 958 if (*input_index_valid_size <=
956 (str_info->decode_isize - *in_copied)) 959 (str_info->decode_isize - *in_copied))
@@ -958,12 +961,12 @@ static int sst_prepare_input_buffers(struct stream_info *str_info,
958 else 961 else
959 cpy_size = str_info->decode_isize - *in_copied; 962 cpy_size = str_info->decode_isize - *in_copied;
960 963
961 pr_debug("sst:cpy size = %d\n", cpy_size); 964 pr_debug("cpy size = %d\n", cpy_size);
962 if (!dbufs->ibufs->buff_entry[i].buffer) { 965 if (!dbufs->ibufs->buff_entry[i].buffer) {
963 pr_err("sst: i/p buffer is null\n"); 966 pr_err("i/p buffer is null\n");
964 return -EINVAL; 967 return -EINVAL;
965 } 968 }
966 pr_debug("sst:Try copy To %p, From %p, size %d\n", 969 pr_debug("Try copy To %p, From %p, size %d\n",
967 str_info->decode_ibuf + *in_copied, 970 str_info->decode_ibuf + *in_copied,
968 dbufs->ibufs->buff_entry[i].buffer, cpy_size); 971 dbufs->ibufs->buff_entry[i].buffer, cpy_size);
969 972
@@ -972,22 +975,22 @@ static int sst_prepare_input_buffers(struct stream_info *str_info,
972 (void *) dbufs->ibufs->buff_entry[i].buffer, 975 (void *) dbufs->ibufs->buff_entry[i].buffer,
973 cpy_size); 976 cpy_size);
974 if (retval) { 977 if (retval) {
975 pr_err("sst: copy from user failed\n"); 978 pr_err("copy from user failed\n");
976 return -EIO; 979 return -EIO;
977 } 980 }
978 *in_copied += cpy_size; 981 *in_copied += cpy_size;
979 *input_index_valid_size -= cpy_size; 982 *input_index_valid_size -= cpy_size;
980 pr_debug("sst:in buff size = %d, in_copied = %d\n", 983 pr_debug("in buff size = %d, in_copied = %d\n",
981 *input_index_valid_size, *in_copied); 984 *input_index_valid_size, *in_copied);
982 if (*input_index_valid_size != 0) { 985 if (*input_index_valid_size != 0) {
983 pr_debug("sst:more input buffers left\n"); 986 pr_debug("more input buffers left\n");
984 dbufs->ibufs->buff_entry[i].buffer += cpy_size; 987 dbufs->ibufs->buff_entry[i].buffer += cpy_size;
985 break; 988 break;
986 } 989 }
987 if (*in_copied == str_info->decode_isize && 990 if (*in_copied == str_info->decode_isize &&
988 *input_index_valid_size == 0 && 991 *input_index_valid_size == 0 &&
989 (i+1) <= dbufs->ibufs->entries) { 992 (i+1) <= dbufs->ibufs->entries) {
990 pr_debug("sst:all input buffers copied\n"); 993 pr_debug("all input buffers copied\n");
991 *new_entry_flag = true; 994 *new_entry_flag = true;
992 *input_index = i + 1; 995 *input_index = i + 1;
993 break; 996 break;
@@ -1005,23 +1008,23 @@ static int sst_prepare_output_buffers(struct stream_info *str_info,
1005 1008
1006{ 1009{
1007 int i, cpy_size, retval = 0; 1010 int i, cpy_size, retval = 0;
1008 pr_debug("sst:output_index = %d, output entries = %d\n", 1011 pr_debug("output_index = %d, output entries = %d\n",
1009 *output_index, 1012 *output_index,
1010 dbufs->obufs->entries); 1013 dbufs->obufs->entries);
1011 for (i = *output_index; i < dbufs->obufs->entries; i++) { 1014 for (i = *output_index; i < dbufs->obufs->entries; i++) {
1012 *output_index = i; 1015 *output_index = i;
1013 pr_debug("sst:output addr = %p, size = %d\n", 1016 pr_debug("output addr = %p, size = %d\n",
1014 dbufs->obufs->buff_entry[i].buffer, 1017 dbufs->obufs->buff_entry[i].buffer,
1015 dbufs->obufs->buff_entry[i].size); 1018 dbufs->obufs->buff_entry[i].size);
1016 pr_debug("sst:output_size = %d, out_copied = %d\n", 1019 pr_debug("output_size = %d, out_copied = %d\n",
1017 output_size, *out_copied); 1020 output_size, *out_copied);
1018 if (dbufs->obufs->buff_entry[i].size < 1021 if (dbufs->obufs->buff_entry[i].size <
1019 (output_size - *out_copied)) 1022 (output_size - *out_copied))
1020 cpy_size = dbufs->obufs->buff_entry[i].size; 1023 cpy_size = dbufs->obufs->buff_entry[i].size;
1021 else 1024 else
1022 cpy_size = output_size - *out_copied; 1025 cpy_size = output_size - *out_copied;
1023 pr_debug("sst:cpy size = %d\n", cpy_size); 1026 pr_debug("cpy size = %d\n", cpy_size);
1024 pr_debug("sst:Try copy To: %p, From %p, size %d\n", 1027 pr_debug("Try copy To: %p, From %p, size %d\n",
1025 dbufs->obufs->buff_entry[i].buffer, 1028 dbufs->obufs->buff_entry[i].buffer,
1026 sst_drv_ctx->mmap_mem + *out_copied, 1029 sst_drv_ctx->mmap_mem + *out_copied,
1027 cpy_size); 1030 cpy_size);
@@ -1029,13 +1032,13 @@ static int sst_prepare_output_buffers(struct stream_info *str_info,
1029 sst_drv_ctx->mmap_mem + *out_copied, 1032 sst_drv_ctx->mmap_mem + *out_copied,
1030 cpy_size); 1033 cpy_size);
1031 if (retval) { 1034 if (retval) {
1032 pr_err("sst: copy to user failed\n"); 1035 pr_err("copy to user failed\n");
1033 return -EIO; 1036 return -EIO;
1034 } else 1037 } else
1035 pr_debug("sst:copy to user passed\n"); 1038 pr_debug("copy to user passed\n");
1036 *out_copied += cpy_size; 1039 *out_copied += cpy_size;
1037 dbufs->obufs->buff_entry[i].size -= cpy_size; 1040 dbufs->obufs->buff_entry[i].size -= cpy_size;
1038 pr_debug("sst:o/p buff size %d, out_copied %d\n", 1041 pr_debug("o/p buff size %d, out_copied %d\n",
1039 dbufs->obufs->buff_entry[i].size, *out_copied); 1042 dbufs->obufs->buff_entry[i].size, *out_copied);
1040 if (dbufs->obufs->buff_entry[i].size != 0) { 1043 if (dbufs->obufs->buff_entry[i].size != 0) {
1041 *output_index = i; 1044 *output_index = i;
@@ -1073,7 +1076,7 @@ int sst_decode(int str_id, struct snd_sst_dbufs *dbufs)
1073 unsigned long long input_bytes, output_bytes; 1076 unsigned long long input_bytes, output_bytes;
1074 1077
1075 sst_drv_ctx->scard_ops->power_down_pmic(); 1078 sst_drv_ctx->scard_ops->power_down_pmic();
1076 pr_debug("sst: Powering_down_PMIC...\n"); 1079 pr_debug("Powering_down_PMIC...\n");
1077 1080
1078 retval = sst_validate_strid(str_id); 1081 retval = sst_validate_strid(str_id);
1079 if (retval) 1082 if (retval)
@@ -1081,7 +1084,7 @@ int sst_decode(int str_id, struct snd_sst_dbufs *dbufs)
1081 1084
1082 str_info = &sst_drv_ctx->streams[str_id]; 1085 str_info = &sst_drv_ctx->streams[str_id];
1083 if (str_info->status != STREAM_INIT) { 1086 if (str_info->status != STREAM_INIT) {
1084 pr_err("sst: invalid stream state = %d\n", 1087 pr_err("invalid stream state = %d\n",
1085 str_info->status); 1088 str_info->status);
1086 return -EINVAL; 1089 return -EINVAL;
1087 } 1090 }
@@ -1098,7 +1101,7 @@ int sst_decode(int str_id, struct snd_sst_dbufs *dbufs)
1098 retval = sst_allocate_decode_buf(str_info, dbufs, 1101 retval = sst_allocate_decode_buf(str_info, dbufs,
1099 cum_input_given, cum_output_given); 1102 cum_input_given, cum_output_given);
1100 if (retval) { 1103 if (retval) {
1101 pr_err("sst: mem allocation failed, abort!!!\n"); 1104 pr_err("mem allocation failed, abort!!!\n");
1102 retval = -ENOMEM; 1105 retval = -ENOMEM;
1103 goto finish; 1106 goto finish;
1104 } 1107 }
@@ -1114,7 +1117,7 @@ int sst_decode(int str_id, struct snd_sst_dbufs *dbufs)
1114 dbufs, &input_index, &in_copied, 1117 dbufs, &input_index, &in_copied,
1115 &input_index_valid_size, &new_entry_flag); 1118 &input_index_valid_size, &new_entry_flag);
1116 if (retval) { 1119 if (retval) {
1117 pr_err("sst: prepare in buffers failed\n"); 1120 pr_err("prepare in buffers failed\n");
1118 goto finish; 1121 goto finish;
1119 } 1122 }
1120 1123
@@ -1145,8 +1148,8 @@ int sst_decode(int str_id, struct snd_sst_dbufs *dbufs)
1145 str_info->decode_osize = dbufs->obufs-> 1148 str_info->decode_osize = dbufs->obufs->
1146 buff_entry[output_index].size; 1149 buff_entry[output_index].size;
1147 str_info->decode_obuf_type = dbufs->obufs->type; 1150 str_info->decode_obuf_type = dbufs->obufs->type;
1148 pr_debug("sst:DRM handling\n"); 1151 pr_debug("DRM handling\n");
1149 pr_debug("o/p_add=0x%lu Size=0x%x", 1152 pr_debug("o/p_add=0x%lu Size=0x%x\n",
1150 (unsigned long) str_info->decode_obuf, 1153 (unsigned long) str_info->decode_obuf,
1151 str_info->decode_osize); 1154 str_info->decode_osize);
1152 } else { 1155 } else {
@@ -1160,7 +1163,7 @@ int sst_decode(int str_id, struct snd_sst_dbufs *dbufs)
1160 if (str_info->ops != STREAM_OPS_PLAYBACK_DRM) { 1163 if (str_info->ops != STREAM_OPS_PLAYBACK_DRM) {
1161 if (str_info->decode_isize > in_copied) { 1164 if (str_info->decode_isize > in_copied) {
1162 str_info->decode_isize = in_copied; 1165 str_info->decode_isize = in_copied;
1163 pr_debug("sst:i/p size = %d\n", 1166 pr_debug("i/p size = %d\n",
1164 str_info->decode_isize); 1167 str_info->decode_isize);
1165 } 1168 }
1166 } 1169 }
@@ -1168,20 +1171,19 @@ int sst_decode(int str_id, struct snd_sst_dbufs *dbufs)
1168 1171
1169 retval = sst_send_decode_mess(str_id, str_info, &dec_info); 1172 retval = sst_send_decode_mess(str_id, str_info, &dec_info);
1170 if (retval || dec_info.input_bytes_consumed == 0) { 1173 if (retval || dec_info.input_bytes_consumed == 0) {
1171 pr_err( 1174 pr_err("SST ERR: mess failed or no input consumed\n");
1172 "SST ERR: mess failed or no input consumed\n");
1173 goto finish; 1175 goto finish;
1174 } 1176 }
1175 input_bytes = dec_info.input_bytes_consumed; 1177 input_bytes = dec_info.input_bytes_consumed;
1176 output_bytes = dec_info.output_bytes_produced; 1178 output_bytes = dec_info.output_bytes_produced;
1177 1179
1178 pr_debug("sst:in_copied=%d, con=%lld, prod=%lld\n", 1180 pr_debug("in_copied=%d, con=%lld, prod=%lld\n",
1179 in_copied, input_bytes, output_bytes); 1181 in_copied, input_bytes, output_bytes);
1180 if (dbufs->obufs->type == SST_BUF_RAR) { 1182 if (dbufs->obufs->type == SST_BUF_RAR) {
1181 output_index += 1; 1183 output_index += 1;
1182 if (output_index == dbufs->obufs->entries) { 1184 if (output_index == dbufs->obufs->entries) {
1183 copy_in_done = true; 1185 copy_in_done = true;
1184 pr_debug("sst:all i/p cpy done\n"); 1186 pr_debug("all i/p cpy done\n");
1185 } 1187 }
1186 total_output += output_bytes; 1188 total_output += output_bytes;
1187 } else { 1189 } else {
@@ -1190,14 +1192,14 @@ int sst_decode(int str_id, struct snd_sst_dbufs *dbufs)
1190 retval = sst_prepare_output_buffers(str_info, dbufs, 1192 retval = sst_prepare_output_buffers(str_info, dbufs,
1191 &output_index, output_size, &out_copied); 1193 &output_index, output_size, &out_copied);
1192 if (retval) { 1194 if (retval) {
1193 pr_err("sst:prep out buff fail\n"); 1195 pr_err("prep out buff fail\n");
1194 goto finish; 1196 goto finish;
1195 } 1197 }
1196 if (str_info->ops != STREAM_OPS_PLAYBACK_DRM) { 1198 if (str_info->ops != STREAM_OPS_PLAYBACK_DRM) {
1197 if (in_copied != input_bytes) { 1199 if (in_copied != input_bytes) {
1198 int bytes_left = in_copied - 1200 int bytes_left = in_copied -
1199 input_bytes; 1201 input_bytes;
1200 pr_debug("sst:bytes %d\n", 1202 pr_debug("bytes %d\n",
1201 bytes_left); 1203 bytes_left);
1202 if (new_entry_flag == true) 1204 if (new_entry_flag == true)
1203 input_index--; 1205 input_index--;
@@ -1237,7 +1239,7 @@ int sst_decode(int str_id, struct snd_sst_dbufs *dbufs)
1237 total_output += out_copied; 1239 total_output += out_copied;
1238 if (str_info->decode_osize != out_copied) { 1240 if (str_info->decode_osize != out_copied) {
1239 str_info->decode_osize -= out_copied; 1241 str_info->decode_osize -= out_copied;
1240 pr_debug("sst:output size modified = %d\n", 1242 pr_debug("output size modified = %d\n",
1241 str_info->decode_osize); 1243 str_info->decode_osize);
1242 } 1244 }
1243 } 1245 }
@@ -1251,16 +1253,16 @@ int sst_decode(int str_id, struct snd_sst_dbufs *dbufs)
1251 } else { 1253 } else {
1252 if (total_output == cum_output_given) { 1254 if (total_output == cum_output_given) {
1253 copy_out_done = true; 1255 copy_out_done = true;
1254 pr_debug("sst:all o/p cpy done\n"); 1256 pr_debug("all o/p cpy done\n");
1255 } 1257 }
1256 1258
1257 if (total_input == cum_input_given) { 1259 if (total_input == cum_input_given) {
1258 copy_in_done = true; 1260 copy_in_done = true;
1259 pr_debug("sst:all i/p cpy done\n"); 1261 pr_debug("all i/p cpy done\n");
1260 } 1262 }
1261 } 1263 }
1262 1264
1263 pr_debug("sst:copy_out = %d, copy_in = %d\n", 1265 pr_debug("copy_out = %d, copy_in = %d\n",
1264 copy_out_done, copy_in_done); 1266 copy_out_done, copy_in_done);
1265 } 1267 }
1266 1268
diff --git a/drivers/staging/intel_sst/intelmid.c b/drivers/staging/intel_sst/intelmid.c
index 4c0264ceaa88..fb2292186703 100644
--- a/drivers/staging/intel_sst/intelmid.c
+++ b/drivers/staging/intel_sst/intelmid.c
@@ -24,6 +24,9 @@
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 * ALSA driver for Intel MID sound card chipset 25 * ALSA driver for Intel MID sound card chipset
26 */ 26 */
27
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
27#include <linux/slab.h> 30#include <linux/slab.h>
28#include <linux/io.h> 31#include <linux/io.h>
29#include <linux/platform_device.h> 32#include <linux/platform_device.h>
@@ -101,12 +104,10 @@ static struct snd_pcm_hardware snd_intelmad_stream = {
101static int snd_intelmad_pcm_trigger(struct snd_pcm_substream *substream, 104static int snd_intelmad_pcm_trigger(struct snd_pcm_substream *substream,
102 int cmd) 105 int cmd)
103{ 106{
104 int ret_val = 0; 107 int ret_val = 0, str_id;
105 struct snd_intelmad *intelmaddata; 108 struct snd_intelmad *intelmaddata;
106 struct mad_stream_pvt *stream; 109 struct mad_stream_pvt *stream;
107 /*struct stream_buffer buffer_to_sst;*/ 110 struct intel_sst_pcm_control *sst_ops;
108
109
110 111
111 WARN_ON(!substream); 112 WARN_ON(!substream);
112 113
@@ -115,38 +116,35 @@ static int snd_intelmad_pcm_trigger(struct snd_pcm_substream *substream,
115 116
116 WARN_ON(!intelmaddata->sstdrv_ops); 117 WARN_ON(!intelmaddata->sstdrv_ops);
117 WARN_ON(!intelmaddata->sstdrv_ops->scard_ops); 118 WARN_ON(!intelmaddata->sstdrv_ops->scard_ops);
119 sst_ops = intelmaddata->sstdrv_ops->pcm_control;
120 str_id = stream->stream_info.str_id;
118 121
119 switch (cmd) { 122 switch (cmd) {
120 case SNDRV_PCM_TRIGGER_START: 123 case SNDRV_PCM_TRIGGER_START:
121 pr_debug("sst: Trigger Start\n"); 124 pr_debug("Trigger Start\n");
122 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_START, 125 ret_val = sst_ops->device_control(SST_SND_START, &str_id);
123 &stream->stream_info.str_id);
124 if (ret_val) 126 if (ret_val)
125 return ret_val; 127 return ret_val;
126 stream->stream_status = RUNNING; 128 stream->stream_status = RUNNING;
127 stream->substream = substream; 129 stream->substream = substream;
128 stream->stream_status = RUNNING;
129 break; 130 break;
130 case SNDRV_PCM_TRIGGER_STOP: 131 case SNDRV_PCM_TRIGGER_STOP:
131 pr_debug("sst: in stop\n"); 132 pr_debug("in stop\n");
132 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_DROP, 133 ret_val = sst_ops->device_control(SST_SND_DROP, &str_id);
133 &stream->stream_info.str_id);
134 if (ret_val) 134 if (ret_val)
135 return ret_val; 135 return ret_val;
136 stream->stream_status = DROPPED; 136 stream->stream_status = DROPPED;
137 break; 137 break;
138 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 138 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
139 pr_debug("sst: in pause\n"); 139 pr_debug("in pause\n");
140 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_PAUSE, 140 ret_val = sst_ops->device_control(SST_SND_PAUSE, &str_id);
141 &stream->stream_info.str_id);
142 if (ret_val) 141 if (ret_val)
143 return ret_val; 142 return ret_val;
144 stream->stream_status = PAUSED; 143 stream->stream_status = PAUSED;
145 break; 144 break;
146 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 145 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
147 pr_debug("sst: in pause release\n"); 146 pr_debug("in pause release\n");
148 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_RESUME, 147 ret_val = sst_ops->device_control(SST_SND_RESUME, &str_id);
149 &stream->stream_info.str_id);
150 if (ret_val) 148 if (ret_val)
151 return ret_val; 149 return ret_val;
152 stream->stream_status = RUNNING; 150 stream->stream_status = RUNNING;
@@ -170,19 +168,19 @@ static int snd_intelmad_pcm_prepare(struct snd_pcm_substream *substream)
170 int ret_val = 0; 168 int ret_val = 0;
171 struct snd_intelmad *intelmaddata; 169 struct snd_intelmad *intelmaddata;
172 170
173 pr_debug("sst: pcm_prepare called\n"); 171 pr_debug("pcm_prepare called\n");
174 172
175 WARN_ON(!substream); 173 WARN_ON(!substream);
176 stream = substream->runtime->private_data; 174 stream = substream->runtime->private_data;
177 intelmaddata = snd_pcm_substream_chip(substream); 175 intelmaddata = snd_pcm_substream_chip(substream);
178 pr_debug("sst: pb cnt = %d cap cnt = %d\n",\ 176 pr_debug("pb cnt = %d cap cnt = %d\n",\
179 intelmaddata->playback_cnt, 177 intelmaddata->playback_cnt,
180 intelmaddata->capture_cnt); 178 intelmaddata->capture_cnt);
181 179
182 if (stream->stream_info.str_id) { 180 if (stream->stream_info.str_id) {
183 pr_debug("sst: Prepare called for already set stream\n"); 181 pr_debug("Prepare called for already set stream\n");
184 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_DROP, 182 ret_val = intelmaddata->sstdrv_ops->pcm_control->device_control(
185 &stream->stream_info.str_id); 183 SST_SND_DROP, &stream->stream_info.str_id);
186 return ret_val; 184 return ret_val;
187 } 185 }
188 186
@@ -197,7 +195,7 @@ static int snd_intelmad_pcm_prepare(struct snd_pcm_substream *substream)
197 /* return back the stream id */ 195 /* return back the stream id */
198 snprintf(substream->pcm->id, sizeof(substream->pcm->id), 196 snprintf(substream->pcm->id, sizeof(substream->pcm->id),
199 "%d", stream->stream_info.str_id); 197 "%d", stream->stream_info.str_id);
200 pr_debug("sst: stream id to user = %s\n", 198 pr_debug("stream id to user = %s\n",
201 substream->pcm->id); 199 substream->pcm->id);
202 200
203 ret_val = snd_intelmad_init_stream(substream); 201 ret_val = snd_intelmad_init_stream(substream);
@@ -212,7 +210,7 @@ static int snd_intelmad_hw_params(struct snd_pcm_substream *substream,
212{ 210{
213 int ret_val; 211 int ret_val;
214 212
215 pr_debug("sst: snd_intelmad_hw_params called\n"); 213 pr_debug("snd_intelmad_hw_params called\n");
216 ret_val = snd_pcm_lib_malloc_pages(substream, 214 ret_val = snd_pcm_lib_malloc_pages(substream,
217 params_buffer_bytes(hw_params)); 215 params_buffer_bytes(hw_params));
218 memset(substream->runtime->dma_area, 0, 216 memset(substream->runtime->dma_area, 0,
@@ -223,7 +221,7 @@ static int snd_intelmad_hw_params(struct snd_pcm_substream *substream,
223 221
224static int snd_intelmad_hw_free(struct snd_pcm_substream *substream) 222static int snd_intelmad_hw_free(struct snd_pcm_substream *substream)
225{ 223{
226 pr_debug("sst: snd_intelmad_hw_free called\n"); 224 pr_debug("snd_intelmad_hw_free called\n");
227 return snd_pcm_lib_free_pages(substream); 225 return snd_pcm_lib_free_pages(substream);
228} 226}
229 227
@@ -250,15 +248,15 @@ static snd_pcm_uframes_t snd_intelmad_pcm_pointer
250 if (stream->stream_status == INIT) 248 if (stream->stream_status == INIT)
251 return 0; 249 return 0;
252 250
253 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_BUFFER_POINTER, 251 ret_val = intelmaddata->sstdrv_ops->pcm_control->device_control(
254 &stream->stream_info); 252 SST_SND_BUFFER_POINTER, &stream->stream_info);
255 if (ret_val) { 253 if (ret_val) {
256 pr_err("sst: error code = 0x%x\n", ret_val); 254 pr_err("error code = 0x%x\n", ret_val);
257 return ret_val; 255 return ret_val;
258 } 256 }
259 pr_debug("sst: samples reported out 0x%llx\n", 257 pr_debug("samples reported out 0x%llx\n",
260 stream->stream_info.buffer_ptr); 258 stream->stream_info.buffer_ptr);
261 pr_debug("sst: Frame bits:: %d period_count :: %d\n", 259 pr_debug("Frame bits:: %d period_count :: %d\n",
262 (int)substream->runtime->frame_bits, 260 (int)substream->runtime->frame_bits,
263 (int)substream->runtime->period_size); 261 (int)substream->runtime->period_size);
264 262
@@ -277,26 +275,26 @@ static int snd_intelmad_close(struct snd_pcm_substream *substream)
277{ 275{
278 struct snd_intelmad *intelmaddata; 276 struct snd_intelmad *intelmaddata;
279 struct mad_stream_pvt *stream; 277 struct mad_stream_pvt *stream;
280 int ret_val = 0; 278 int ret_val = 0, str_id;
281 279
282 WARN_ON(!substream); 280 WARN_ON(!substream);
283 281
284 stream = substream->runtime->private_data; 282 stream = substream->runtime->private_data;
283 str_id = stream->stream_info.str_id;
285 284
286 pr_debug("sst: snd_intelmad_close called\n"); 285 pr_debug("sst: snd_intelmad_close called for %d\n", str_id);
287 intelmaddata = snd_pcm_substream_chip(substream); 286 intelmaddata = snd_pcm_substream_chip(substream);
288 287
289 pr_debug("sst: str id = %d\n", stream->stream_info.str_id); 288 pr_debug("str id = %d\n", stream->stream_info.str_id);
290 if (stream->stream_info.str_id) { 289 if (stream->stream_info.str_id) {
291 /* SST API to actually stop/free the stream */ 290 /* SST API to actually stop/free the stream */
292 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_FREE, 291 ret_val = intelmaddata->sstdrv_ops->pcm_control->close(str_id);
293 &stream->stream_info.str_id);
294 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 292 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
295 intelmaddata->playback_cnt--; 293 intelmaddata->playback_cnt--;
296 else 294 else
297 intelmaddata->capture_cnt--; 295 intelmaddata->capture_cnt--;
298 } 296 }
299 pr_debug("sst: snd_intelmad_close : pb cnt = %d cap cnt = %d\n", 297 pr_debug("snd_intelmad_close : pb cnt = %d cap cnt = %d\n",
300 intelmaddata->playback_cnt, intelmaddata->capture_cnt); 298 intelmaddata->playback_cnt, intelmaddata->capture_cnt);
301 kfree(substream->runtime->private_data); 299 kfree(substream->runtime->private_data);
302 return ret_val; 300 return ret_val;
@@ -319,7 +317,7 @@ static int snd_intelmad_open(struct snd_pcm_substream *substream,
319 317
320 WARN_ON(!substream); 318 WARN_ON(!substream);
321 319
322 pr_debug("sst: snd_intelmad_open called\n"); 320 pr_debug("snd_intelmad_open called\n");
323 321
324 intelmaddata = snd_pcm_substream_chip(substream); 322 intelmaddata = snd_pcm_substream_chip(substream);
325 runtime = substream->runtime; 323 runtime = substream->runtime;
@@ -456,17 +454,17 @@ void sst_mad_send_jack_report(struct snd_jack *jack,
456{ 454{
457 455
458 if (!jack) { 456 if (!jack) {
459 pr_debug("sst: MAD error jack empty\n"); 457 pr_debug("MAD error jack empty\n");
460 458
461 } else { 459 } else {
462 pr_debug("sst: MAD send jack report for = %d!!!\n", status); 460 pr_debug("MAD send jack report for = %d!!!\n", status);
463 pr_debug("sst: MAD send jack report %d\n", jack->type); 461 pr_debug("MAD send jack report %d\n", jack->type);
464 snd_jack_report(jack, status); 462 snd_jack_report(jack, status);
465 463
466 /*button pressed and released */ 464 /*button pressed and released */
467 if (buttonpressevent) 465 if (buttonpressevent)
468 snd_jack_report(jack, 0); 466 snd_jack_report(jack, 0);
469 pr_debug("sst: MAD sending jack report Done !!!\n"); 467 pr_debug("MAD sending jack report Done !!!\n");
470 } 468 }
471 469
472 470
@@ -490,7 +488,7 @@ void sst_mad_jackdetection_fs(u8 intsts , struct snd_intelmad *intelmaddata)
490 if (intsts & 0x4) { 488 if (intsts & 0x4) {
491 489
492 if (!(intelmid_audio_interrupt_enable)) { 490 if (!(intelmid_audio_interrupt_enable)) {
493 pr_debug("sst: Audio interrupt enable\n"); 491 pr_debug("Audio interrupt enable\n");
494 sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 3); 492 sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 3);
495 493
496 sst_sc_reg_access(sc_access_write, PMIC_WRITE, 1); 494 sst_sc_reg_access(sc_access_write, PMIC_WRITE, 1);
@@ -500,7 +498,7 @@ void sst_mad_jackdetection_fs(u8 intsts , struct snd_intelmad *intelmaddata)
500 498
501 } 499 }
502 /* send headphone detect */ 500 /* send headphone detect */
503 pr_debug("sst: MAD headphone %d\n", intsts & 0x4); 501 pr_debug("MAD headphone %d\n", intsts & 0x4);
504 jack = &intelmaddata->jack[0].jack; 502 jack = &intelmaddata->jack[0].jack;
505 present = !(intelmaddata->jack[0].jack_status); 503 present = !(intelmaddata->jack[0].jack_status);
506 intelmaddata->jack[0].jack_status = present; 504 intelmaddata->jack[0].jack_status = present;
@@ -510,7 +508,7 @@ void sst_mad_jackdetection_fs(u8 intsts , struct snd_intelmad *intelmaddata)
510 508
511 if (intsts & 0x2) { 509 if (intsts & 0x2) {
512 /* send short push */ 510 /* send short push */
513 pr_debug("sst: MAD short push %d\n", intsts & 0x2); 511 pr_debug("MAD short push %d\n", intsts & 0x2);
514 jack = &intelmaddata->jack[2].jack; 512 jack = &intelmaddata->jack[2].jack;
515 present = 1; 513 present = 1;
516 jack_event_flag = 1; 514 jack_event_flag = 1;
@@ -518,7 +516,7 @@ void sst_mad_jackdetection_fs(u8 intsts , struct snd_intelmad *intelmaddata)
518 } 516 }
519 if (intsts & 0x1) { 517 if (intsts & 0x1) {
520 /* send long push */ 518 /* send long push */
521 pr_debug("sst: MAD long push %d\n", intsts & 0x1); 519 pr_debug("MAD long push %d\n", intsts & 0x1);
522 jack = &intelmaddata->jack[3].jack; 520 jack = &intelmaddata->jack[3].jack;
523 present = 1; 521 present = 1;
524 jack_event_flag = 1; 522 jack_event_flag = 1;
@@ -526,7 +524,7 @@ void sst_mad_jackdetection_fs(u8 intsts , struct snd_intelmad *intelmaddata)
526 } 524 }
527 if (intsts & 0x8) { 525 if (intsts & 0x8) {
528 if (!(intelmid_audio_interrupt_enable)) { 526 if (!(intelmid_audio_interrupt_enable)) {
529 pr_debug("sst: Audio interrupt enable\n"); 527 pr_debug("Audio interrupt enable\n");
530 sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 3); 528 sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 3);
531 529
532 sst_sc_reg_access(sc_access_write, PMIC_WRITE, 1); 530 sst_sc_reg_access(sc_access_write, PMIC_WRITE, 1);
@@ -535,7 +533,7 @@ void sst_mad_jackdetection_fs(u8 intsts , struct snd_intelmad *intelmaddata)
535 intelmaddata->jack[1].jack_status = 0; 533 intelmaddata->jack[1].jack_status = 0;
536 } 534 }
537 /* send headset detect */ 535 /* send headset detect */
538 pr_debug("sst: MAD headset = %d\n", intsts & 0x8); 536 pr_debug("MAD headset = %d\n", intsts & 0x8);
539 jack = &intelmaddata->jack[1].jack; 537 jack = &intelmaddata->jack[1].jack;
540 present = !(intelmaddata->jack[1].jack_status); 538 present = !(intelmaddata->jack[1].jack_status);
541 intelmaddata->jack[1].jack_status = present; 539 intelmaddata->jack[1].jack_status = present;
@@ -558,10 +556,10 @@ void sst_mad_jackdetection_mx(u8 intsts, struct snd_intelmad *intelmaddata)
558 556
559 scard_ops = intelmaddata->sstdrv_ops->scard_ops; 557 scard_ops = intelmaddata->sstdrv_ops->scard_ops;
560 558
561 pr_debug("sst: previous value: %x\n", intelmaddata->jack_prev_state); 559 pr_debug("previous value: %x\n", intelmaddata->jack_prev_state);
562 560
563 if (!(intelmid_audio_interrupt_enable)) { 561 if (!(intelmid_audio_interrupt_enable)) {
564 pr_debug("sst: Audio interrupt enable\n"); 562 pr_debug("Audio interrupt enable\n");
565 intelmaddata->jack_prev_state = 0xC0; 563 intelmaddata->jack_prev_state = 0xC0;
566 intelmid_audio_interrupt_enable = 1; 564 intelmid_audio_interrupt_enable = 1;
567 } 565 }
@@ -572,12 +570,12 @@ void sst_mad_jackdetection_mx(u8 intsts, struct snd_intelmad *intelmaddata)
572 sc_access_read.reg_addr = 0x201; 570 sc_access_read.reg_addr = 0x201;
573 sst_sc_reg_access(&sc_access_read, PMIC_READ, 1); 571 sst_sc_reg_access(&sc_access_read, PMIC_READ, 1);
574 value = (sc_access_read.value); 572 value = (sc_access_read.value);
575 pr_debug("sst: value returned = 0x%x\n", value); 573 pr_debug("value returned = 0x%x\n", value);
576 } 574 }
577 575
578 if (jack_prev_state == 0xc0 && value == 0x40) { 576 if (jack_prev_state == 0xc0 && value == 0x40) {
579 /*headset detected. */ 577 /*headset detected. */
580 pr_debug("sst: MAD headset inserted\n"); 578 pr_debug("MAD headset inserted\n");
581 jack = &intelmaddata->jack[1].jack; 579 jack = &intelmaddata->jack[1].jack;
582 present = 1; 580 present = 1;
583 jack_event_flag = 1; 581 jack_event_flag = 1;
@@ -587,7 +585,7 @@ void sst_mad_jackdetection_mx(u8 intsts, struct snd_intelmad *intelmaddata)
587 585
588 if (jack_prev_state == 0xc0 && value == 0x00) { 586 if (jack_prev_state == 0xc0 && value == 0x00) {
589 /* headphone detected. */ 587 /* headphone detected. */
590 pr_debug("sst: MAD headphone inserted\n"); 588 pr_debug("MAD headphone inserted\n");
591 jack = &intelmaddata->jack[0].jack; 589 jack = &intelmaddata->jack[0].jack;
592 present = 1; 590 present = 1;
593 jack_event_flag = 1; 591 jack_event_flag = 1;
@@ -596,9 +594,9 @@ void sst_mad_jackdetection_mx(u8 intsts, struct snd_intelmad *intelmaddata)
596 594
597 if (jack_prev_state == 0x40 && value == 0xc0) { 595 if (jack_prev_state == 0x40 && value == 0xc0) {
598 /*headset removed*/ 596 /*headset removed*/
599 pr_debug("sst: Jack headset status %d\n", 597 pr_debug("Jack headset status %d\n",
600 intelmaddata->jack[1].jack_status); 598 intelmaddata->jack[1].jack_status);
601 pr_debug("sst: MAD headset removed\n"); 599 pr_debug("MAD headset removed\n");
602 jack = &intelmaddata->jack[1].jack; 600 jack = &intelmaddata->jack[1].jack;
603 present = 0; 601 present = 0;
604 jack_event_flag = 1; 602 jack_event_flag = 1;
@@ -607,9 +605,9 @@ void sst_mad_jackdetection_mx(u8 intsts, struct snd_intelmad *intelmaddata)
607 605
608 if (jack_prev_state == 0x00 && value == 0xc0) { 606 if (jack_prev_state == 0x00 && value == 0xc0) {
609 /* headphone detected. */ 607 /* headphone detected. */
610 pr_debug("sst: Jack headphone status %d\n", 608 pr_debug("Jack headphone status %d\n",
611 intelmaddata->jack[0].jack_status); 609 intelmaddata->jack[0].jack_status);
612 pr_debug("sst: headphone removed\n"); 610 pr_debug("headphone removed\n");
613 jack = &intelmaddata->jack[0].jack; 611 jack = &intelmaddata->jack[0].jack;
614 present = 0; 612 present = 0;
615 jack_event_flag = 1; 613 jack_event_flag = 1;
@@ -618,7 +616,7 @@ void sst_mad_jackdetection_mx(u8 intsts, struct snd_intelmad *intelmaddata)
618 if (jack_prev_state == 0x40 && value == 0x00) { 616 if (jack_prev_state == 0x40 && value == 0x00) {
619 /*button pressed*/ 617 /*button pressed*/
620 do_gettimeofday(&intelmaddata->jack[1].buttonpressed); 618 do_gettimeofday(&intelmaddata->jack[1].buttonpressed);
621 pr_debug("sst: MAD button press detected n"); 619 pr_debug("MAD button press detected\n");
622 } 620 }
623 621
624 622
@@ -628,19 +626,19 @@ void sst_mad_jackdetection_mx(u8 intsts, struct snd_intelmad *intelmaddata)
628 do_gettimeofday( 626 do_gettimeofday(
629 &intelmaddata->jack[1].buttonreleased); 627 &intelmaddata->jack[1].buttonreleased);
630 /*button pressed */ 628 /*button pressed */
631 pr_debug("sst: Button Released detected\n"); 629 pr_debug("Button Released detected\n");
632 timediff = intelmaddata->jack[1]. 630 timediff = intelmaddata->jack[1].
633 buttonreleased.tv_sec - intelmaddata-> 631 buttonreleased.tv_sec - intelmaddata->
634 jack[1].buttonpressed.tv_sec; 632 jack[1].buttonpressed.tv_sec;
635 buttonpressflag = 1; 633 buttonpressflag = 1;
636 if (timediff > 1) { 634 if (timediff > 1) {
637 pr_debug("sst: long press detected\n"); 635 pr_debug("long press detected\n");
638 /* send headphone detect/undetect */ 636 /* send headphone detect/undetect */
639 jack = &intelmaddata->jack[3].jack; 637 jack = &intelmaddata->jack[3].jack;
640 present = 1; 638 present = 1;
641 jack_event_flag = 1; 639 jack_event_flag = 1;
642 } else { 640 } else {
643 pr_debug("sst: short press detected\n"); 641 pr_debug("short press detected\n");
644 /* send headphone detect/undetect */ 642 /* send headphone detect/undetect */
645 jack = &intelmaddata->jack[2].jack; 643 jack = &intelmaddata->jack[2].jack;
646 present = 1; 644 present = 1;
@@ -667,24 +665,24 @@ void sst_mad_jackdetection_nec(u8 intsts, struct snd_intelmad *intelmaddata)
667 sc_access_read.reg_addr = 0x132; 665 sc_access_read.reg_addr = 0x132;
668 sst_sc_reg_access(&sc_access_read, PMIC_READ, 1); 666 sst_sc_reg_access(&sc_access_read, PMIC_READ, 1);
669 value = (sc_access_read.value); 667 value = (sc_access_read.value);
670 pr_debug("sst: value returned = 0x%x\n", value); 668 pr_debug("value returned = 0x%x\n", value);
671 } 669 }
672 if (intsts & 0x1) { 670 if (intsts & 0x1) {
673 pr_debug("sst: headset detected\n"); 671 pr_debug("headset detected\n");
674 /* send headset detect/undetect */ 672 /* send headset detect/undetect */
675 jack = &intelmaddata->jack[1].jack; 673 jack = &intelmaddata->jack[1].jack;
676 present = (value == 0x1) ? 1 : 0; 674 present = (value == 0x1) ? 1 : 0;
677 jack_event_flag = 1; 675 jack_event_flag = 1;
678 } 676 }
679 if (intsts & 0x2) { 677 if (intsts & 0x2) {
680 pr_debug("sst: headphone detected\n"); 678 pr_debug("headphone detected\n");
681 /* send headphone detect/undetect */ 679 /* send headphone detect/undetect */
682 jack = &intelmaddata->jack[0].jack; 680 jack = &intelmaddata->jack[0].jack;
683 present = (value == 0x2) ? 1 : 0; 681 present = (value == 0x2) ? 1 : 0;
684 jack_event_flag = 1; 682 jack_event_flag = 1;
685 } 683 }
686 if (intsts & 0x4) { 684 if (intsts & 0x4) {
687 pr_debug("sst: short push detected\n"); 685 pr_debug("short push detected\n");
688 /* send short push */ 686 /* send short push */
689 jack = &intelmaddata->jack[2].jack; 687 jack = &intelmaddata->jack[2].jack;
690 present = 1; 688 present = 1;
@@ -692,7 +690,7 @@ void sst_mad_jackdetection_nec(u8 intsts, struct snd_intelmad *intelmaddata)
692 buttonpressflag = 1; 690 buttonpressflag = 1;
693 } 691 }
694 if (intsts & 0x8) { 692 if (intsts & 0x8) {
695 pr_debug("sst: long push detected\n"); 693 pr_debug("long push detected\n");
696 /* send long push */ 694 /* send long push */
697 jack = &intelmaddata->jack[3].jack; 695 jack = &intelmaddata->jack[3].jack;
698 present = 1; 696 present = 1;
@@ -738,12 +736,12 @@ static int __devinit snd_intelmad_register_irq(
738 u32 regbase = AUDINT_BASE, regsize = 8; 736 u32 regbase = AUDINT_BASE, regsize = 8;
739 char *drv_name; 737 char *drv_name;
740 738
741 pr_debug("sst: irq reg done, regbase 0x%x, regsize 0x%x\n", 739 pr_debug("irq reg done, regbase 0x%x, regsize 0x%x\n",
742 regbase, regsize); 740 regbase, regsize);
743 intelmaddata->int_base = ioremap_nocache(regbase, regsize); 741 intelmaddata->int_base = ioremap_nocache(regbase, regsize);
744 if (!intelmaddata->int_base) 742 if (!intelmaddata->int_base)
745 pr_err("sst: Mapping of cache failed\n"); 743 pr_err("Mapping of cache failed\n");
746 pr_debug("sst: irq = 0x%x\n", intelmaddata->irq); 744 pr_debug("irq = 0x%x\n", intelmaddata->irq);
747 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL) 745 if (intelmaddata->cpu_id == CPU_CHIP_PENWELL)
748 drv_name = DRIVER_NAME_MFLD; 746 drv_name = DRIVER_NAME_MFLD;
749 else 747 else
@@ -753,7 +751,7 @@ static int __devinit snd_intelmad_register_irq(
753 IRQF_SHARED, drv_name, 751 IRQF_SHARED, drv_name,
754 intelmaddata); 752 intelmaddata);
755 if (ret_val) 753 if (ret_val)
756 pr_err("sst: cannot register IRQ\n"); 754 pr_err("cannot register IRQ\n");
757 return ret_val; 755 return ret_val;
758} 756}
759 757
@@ -775,10 +773,10 @@ static int __devinit snd_intelmad_sst_register(
775 if (ret_val) 773 if (ret_val)
776 return ret_val; 774 return ret_val;
777 sst_card_vendor_id = (vendor_addr.value & (MASK2|MASK1|MASK0)); 775 sst_card_vendor_id = (vendor_addr.value & (MASK2|MASK1|MASK0));
778 pr_debug("sst: orginal n extrated vendor id = 0x%x %d\n", 776 pr_debug("orginal n extrated vendor id = 0x%x %d\n",
779 vendor_addr.value, sst_card_vendor_id); 777 vendor_addr.value, sst_card_vendor_id);
780 if (sst_card_vendor_id < 0 || sst_card_vendor_id > 2) { 778 if (sst_card_vendor_id < 0 || sst_card_vendor_id > 2) {
781 pr_err("sst: vendor card not supported!!\n"); 779 pr_err("vendor card not supported!!\n");
782 return -EIO; 780 return -EIO;
783 } 781 }
784 } else 782 } else
@@ -801,7 +799,7 @@ static int __devinit snd_intelmad_sst_register(
801 /* registering with SST driver to get access to SST APIs to use */ 799 /* registering with SST driver to get access to SST APIs to use */
802 ret_val = register_sst_card(intelmaddata->sstdrv_ops); 800 ret_val = register_sst_card(intelmaddata->sstdrv_ops);
803 if (ret_val) { 801 if (ret_val) {
804 pr_err("sst: sst card registration failed\n"); 802 pr_err("sst card registration failed\n");
805 return ret_val; 803 return ret_val;
806 } 804 }
807 805
@@ -832,7 +830,7 @@ static int __devinit snd_intelmad_pcm_new(struct snd_card *card,
832 char name[32] = INTEL_MAD; 830 char name[32] = INTEL_MAD;
833 struct snd_pcm_ops *pb_ops = NULL, *cap_ops = NULL; 831 struct snd_pcm_ops *pb_ops = NULL, *cap_ops = NULL;
834 832
835 pr_debug("sst: called for pb %d, cp %d, idx %d\n", pb, cap, index); 833 pr_debug("called for pb %d, cp %d, idx %d\n", pb, cap, index);
836 ret_val = snd_pcm_new(card, name, index, pb, cap, &pcm); 834 ret_val = snd_pcm_new(card, name, index, pb, cap, &pcm);
837 if (ret_val) 835 if (ret_val)
838 return ret_val; 836 return ret_val;
@@ -878,7 +876,7 @@ static int __devinit snd_intelmad_pcm(struct snd_card *card,
878 876
879 WARN_ON(!card); 877 WARN_ON(!card);
880 WARN_ON(!intelmaddata); 878 WARN_ON(!intelmaddata);
881 pr_debug("sst: snd_intelmad_pcm called\n"); 879 pr_debug("snd_intelmad_pcm called\n");
882 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 1, 0); 880 ret_val = snd_intelmad_pcm_new(card, intelmaddata, 1, 1, 0);
883 if (intelmaddata->cpu_id == CPU_CHIP_LINCROFT) 881 if (intelmaddata->cpu_id == CPU_CHIP_LINCROFT)
884 return ret_val; 882 return ret_val;
@@ -903,7 +901,7 @@ static int snd_intelmad_jack(struct snd_intelmad *intelmaddata)
903 struct snd_jack *jack; 901 struct snd_jack *jack;
904 int retval; 902 int retval;
905 903
906 pr_debug("sst: snd_intelmad_jack called\n"); 904 pr_debug("snd_intelmad_jack called\n");
907 jack = &intelmaddata->jack[0].jack; 905 jack = &intelmaddata->jack[0].jack;
908 retval = snd_jack_new(intelmaddata->card, "Headphone", 906 retval = snd_jack_new(intelmaddata->card, "Headphone",
909 SND_JACK_HEADPHONE, &jack); 907 SND_JACK_HEADPHONE, &jack);
@@ -982,9 +980,9 @@ static int __devinit snd_intelmad_mixer(struct snd_intelmad *intelmaddata)
982 ret_val = snd_ctl_add(card, 980 ret_val = snd_ctl_add(card,
983 snd_ctl_new1(&controls[idx], 981 snd_ctl_new1(&controls[idx],
984 intelmaddata)); 982 intelmaddata));
985 pr_debug("sst: mixer[idx]=%d added\n", idx); 983 pr_debug("mixer[idx]=%d added\n", idx);
986 if (ret_val) { 984 if (ret_val) {
987 pr_err("sst: in adding of control index = %d\n", idx); 985 pr_err("in adding of control index = %d\n", idx);
988 break; 986 break;
989 } 987 }
990 } 988 }
@@ -999,7 +997,7 @@ static int snd_intelmad_dev_free(struct snd_device *device)
999 997
1000 intelmaddata = device->device_data; 998 intelmaddata = device->device_data;
1001 999
1002 pr_debug("sst: snd_intelmad_dev_free called\n"); 1000 pr_debug("snd_intelmad_dev_free called\n");
1003 snd_card_free(intelmaddata->card); 1001 snd_card_free(intelmaddata->card);
1004 /*genl_unregister_family(&audio_event_genl_family);*/ 1002 /*genl_unregister_family(&audio_event_genl_family);*/
1005 unregister_sst_card(intelmaddata->sstdrv_ops); 1003 unregister_sst_card(intelmaddata->sstdrv_ops);
@@ -1040,23 +1038,23 @@ int __devinit snd_intelmad_probe(struct platform_device *pdev)
1040 const struct platform_device_id *id = platform_get_device_id(pdev); 1038 const struct platform_device_id *id = platform_get_device_id(pdev);
1041 unsigned int cpu_id = (unsigned int)id->driver_data; 1039 unsigned int cpu_id = (unsigned int)id->driver_data;
1042 1040
1043 pr_debug("sst: probe for %s cpu_id %d\n", pdev->name, cpu_id); 1041 pr_debug("probe for %s cpu_id %d\n", pdev->name, cpu_id);
1044 if (!strcmp(pdev->name, DRIVER_NAME_MRST)) 1042 if (!strcmp(pdev->name, DRIVER_NAME_MRST))
1045 pr_debug("sst: detected MRST\n"); 1043 pr_debug("detected MRST\n");
1046 else if (!strcmp(pdev->name, DRIVER_NAME_MFLD)) 1044 else if (!strcmp(pdev->name, DRIVER_NAME_MFLD))
1047 pr_debug("sst: detected MFLD\n"); 1045 pr_debug("detected MFLD\n");
1048 else { 1046 else {
1049 pr_err("sst: detected unknown device abort!!\n"); 1047 pr_err("detected unknown device abort!!\n");
1050 return -EIO; 1048 return -EIO;
1051 } 1049 }
1052 if ((cpu_id < CPU_CHIP_LINCROFT) || (cpu_id > CPU_CHIP_PENWELL)) { 1050 if ((cpu_id < CPU_CHIP_LINCROFT) || (cpu_id > CPU_CHIP_PENWELL)) {
1053 pr_err("sst: detected unknown cpu_id abort!!\n"); 1051 pr_err("detected unknown cpu_id abort!!\n");
1054 return -EIO; 1052 return -EIO;
1055 } 1053 }
1056 /* allocate memory for saving internal context and working */ 1054 /* allocate memory for saving internal context and working */
1057 intelmaddata = kzalloc(sizeof(*intelmaddata), GFP_KERNEL); 1055 intelmaddata = kzalloc(sizeof(*intelmaddata), GFP_KERNEL);
1058 if (!intelmaddata) { 1056 if (!intelmaddata) {
1059 pr_debug("sst: mem alloctn fail\n"); 1057 pr_debug("mem alloctn fail\n");
1060 return -ENOMEM; 1058 return -ENOMEM;
1061 } 1059 }
1062 1060
@@ -1064,7 +1062,7 @@ int __devinit snd_intelmad_probe(struct platform_device *pdev)
1064 intelmaddata->sstdrv_ops = kzalloc(sizeof(struct intel_sst_card_ops), 1062 intelmaddata->sstdrv_ops = kzalloc(sizeof(struct intel_sst_card_ops),
1065 GFP_KERNEL); 1063 GFP_KERNEL);
1066 if (!intelmaddata->sstdrv_ops) { 1064 if (!intelmaddata->sstdrv_ops) {
1067 pr_err("sst: mem allocation for ops fail\n"); 1065 pr_err("mem allocation for ops fail\n");
1068 kfree(intelmaddata); 1066 kfree(intelmaddata);
1069 return -ENOMEM; 1067 return -ENOMEM;
1070 } 1068 }
@@ -1073,7 +1071,7 @@ int __devinit snd_intelmad_probe(struct platform_device *pdev)
1073 /* create a card instance with ALSA framework */ 1071 /* create a card instance with ALSA framework */
1074 ret_val = snd_card_create(card_index, card_id, THIS_MODULE, 0, &card); 1072 ret_val = snd_card_create(card_index, card_id, THIS_MODULE, 0, &card);
1075 if (ret_val) { 1073 if (ret_val) {
1076 pr_err("sst: snd_card_create fail\n"); 1074 pr_err("snd_card_create fail\n");
1077 goto free_allocs; 1075 goto free_allocs;
1078 } 1076 }
1079 1077
@@ -1092,7 +1090,7 @@ int __devinit snd_intelmad_probe(struct platform_device *pdev)
1092 /* registering with LPE driver to get access to SST APIs to use */ 1090 /* registering with LPE driver to get access to SST APIs to use */
1093 ret_val = snd_intelmad_sst_register(intelmaddata); 1091 ret_val = snd_intelmad_sst_register(intelmaddata);
1094 if (ret_val) { 1092 if (ret_val) {
1095 pr_err("sst: snd_intelmad_sst_register failed\n"); 1093 pr_err("snd_intelmad_sst_register failed\n");
1096 goto free_allocs; 1094 goto free_allocs;
1097 } 1095 }
1098 1096
@@ -1100,19 +1098,19 @@ int __devinit snd_intelmad_probe(struct platform_device *pdev)
1100 1098
1101 ret_val = snd_intelmad_pcm(card, intelmaddata); 1099 ret_val = snd_intelmad_pcm(card, intelmaddata);
1102 if (ret_val) { 1100 if (ret_val) {
1103 pr_err("sst: snd_intelmad_pcm failed\n"); 1101 pr_err("snd_intelmad_pcm failed\n");
1104 goto free_allocs; 1102 goto free_allocs;
1105 } 1103 }
1106 1104
1107 ret_val = snd_intelmad_mixer(intelmaddata); 1105 ret_val = snd_intelmad_mixer(intelmaddata);
1108 if (ret_val) { 1106 if (ret_val) {
1109 pr_err("sst: snd_intelmad_mixer failed\n"); 1107 pr_err("snd_intelmad_mixer failed\n");
1110 goto free_allocs; 1108 goto free_allocs;
1111 } 1109 }
1112 1110
1113 ret_val = snd_intelmad_jack(intelmaddata); 1111 ret_val = snd_intelmad_jack(intelmaddata);
1114 if (ret_val) { 1112 if (ret_val) {
1115 pr_err("sst: snd_intelmad_jack failed\n"); 1113 pr_err("snd_intelmad_jack failed\n");
1116 goto free_allocs; 1114 goto free_allocs;
1117 } 1115 }
1118 1116
@@ -1126,31 +1124,31 @@ int __devinit snd_intelmad_probe(struct platform_device *pdev)
1126 1124
1127 ret_val = snd_intelmad_register_irq(intelmaddata); 1125 ret_val = snd_intelmad_register_irq(intelmaddata);
1128 if (ret_val) { 1126 if (ret_val) {
1129 pr_err("sst: snd_intelmad_register_irq fail\n"); 1127 pr_err("snd_intelmad_register_irq fail\n");
1130 goto free_allocs; 1128 goto free_allocs;
1131 } 1129 }
1132 1130
1133 /* internal function call to register device with ALSA */ 1131 /* internal function call to register device with ALSA */
1134 ret_val = snd_intelmad_create(intelmaddata, card); 1132 ret_val = snd_intelmad_create(intelmaddata, card);
1135 if (ret_val) { 1133 if (ret_val) {
1136 pr_err("sst: snd_intelmad_create failed\n"); 1134 pr_err("snd_intelmad_create failed\n");
1137 goto free_allocs; 1135 goto free_allocs;
1138 } 1136 }
1139 card->private_data = &intelmaddata; 1137 card->private_data = &intelmaddata;
1140 snd_card_set_dev(card, &pdev->dev); 1138 snd_card_set_dev(card, &pdev->dev);
1141 ret_val = snd_card_register(card); 1139 ret_val = snd_card_register(card);
1142 if (ret_val) { 1140 if (ret_val) {
1143 pr_err("sst: snd_card_register failed\n"); 1141 pr_err("snd_card_register failed\n");
1144 goto free_allocs; 1142 goto free_allocs;
1145 } 1143 }
1146 1144
1147 pr_debug("sst:snd_intelmad_probe complete\n"); 1145 pr_debug("snd_intelmad_probe complete\n");
1148 return ret_val; 1146 return ret_val;
1149 1147
1150free_mad_jack_wq: 1148free_mad_jack_wq:
1151 destroy_workqueue(intelmaddata->mad_jack_wq); 1149 destroy_workqueue(intelmaddata->mad_jack_wq);
1152free_allocs: 1150free_allocs:
1153 pr_err("sst: probe failed\n"); 1151 pr_err("probe failed\n");
1154 snd_card_free(card); 1152 snd_card_free(card);
1155 kfree(intelmaddata->sstdrv_ops); 1153 kfree(intelmaddata->sstdrv_ops);
1156 kfree(intelmaddata); 1154 kfree(intelmaddata);
@@ -1200,7 +1198,7 @@ static struct platform_driver snd_intelmad_driver = {
1200 */ 1198 */
1201static int __init alsa_card_intelmad_init(void) 1199static int __init alsa_card_intelmad_init(void)
1202{ 1200{
1203 pr_debug("sst: mad_init called\n"); 1201 pr_debug("mad_init called\n");
1204 return platform_driver_register(&snd_intelmad_driver); 1202 return platform_driver_register(&snd_intelmad_driver);
1205} 1203}
1206 1204
@@ -1211,7 +1209,7 @@ static int __init alsa_card_intelmad_init(void)
1211 */ 1209 */
1212static void __exit alsa_card_intelmad_exit(void) 1210static void __exit alsa_card_intelmad_exit(void)
1213{ 1211{
1214 pr_debug("sst:mad_exit called\n"); 1212 pr_debug("mad_exit called\n");
1215 return platform_driver_unregister(&snd_intelmad_driver); 1213 return platform_driver_unregister(&snd_intelmad_driver);
1216} 1214}
1217 1215
diff --git a/drivers/staging/intel_sst/intelmid.h b/drivers/staging/intel_sst/intelmid.h
index 81e744816765..0ce103185848 100644
--- a/drivers/staging/intel_sst/intelmid.h
+++ b/drivers/staging/intel_sst/intelmid.h
@@ -178,9 +178,4 @@ extern struct snd_kcontrol_new snd_intelmad_controls_mrst[];
178extern struct snd_kcontrol_new snd_intelmad_controls_mfld[]; 178extern struct snd_kcontrol_new snd_intelmad_controls_mfld[];
179extern struct snd_pmic_ops *intelmad_vendor_ops[]; 179extern struct snd_pmic_ops *intelmad_vendor_ops[];
180 180
181/* This is an enabler hook as the platform detection logic isn't yet
182 present and depends on some firmware and DMI support to detect AAVA
183 devices. It will vanish once the AAVA platform support is merged */
184#define is_aava() 0
185
186#endif /* __INTELMID_H */ 181#endif /* __INTELMID_H */
diff --git a/drivers/staging/intel_sst/intelmid_ctrl.c b/drivers/staging/intel_sst/intelmid_ctrl.c
index 03b4ece02f91..69af0704ce94 100644
--- a/drivers/staging/intel_sst/intelmid_ctrl.c
+++ b/drivers/staging/intel_sst/intelmid_ctrl.c
@@ -24,6 +24,9 @@
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 * ALSA driver handling mixer controls for Intel MAD chipset 25 * ALSA driver handling mixer controls for Intel MAD chipset
26 */ 26 */
27
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
27#include <sound/core.h> 30#include <sound/core.h>
28#include <sound/control.h> 31#include <sound/control.h>
29#include "jack.h" 32#include "jack.h"
@@ -216,7 +219,7 @@ static int snd_intelmad_volume_get(struct snd_kcontrol *kcontrol,
216 struct snd_intelmad *intelmaddata; 219 struct snd_intelmad *intelmaddata;
217 struct snd_pmic_ops *scard_ops; 220 struct snd_pmic_ops *scard_ops;
218 221
219 pr_debug("sst: snd_intelmad_volume_get called\n"); 222 pr_debug("snd_intelmad_volume_get called\n");
220 223
221 WARN_ON(!uval); 224 WARN_ON(!uval);
222 WARN_ON(!kcontrol); 225 WARN_ON(!kcontrol);
@@ -273,7 +276,7 @@ static int snd_intelmad_mute_get(struct snd_kcontrol *kcontrol,
273 struct snd_intelmad *intelmaddata; 276 struct snd_intelmad *intelmaddata;
274 struct snd_pmic_ops *scard_ops; 277 struct snd_pmic_ops *scard_ops;
275 278
276 pr_debug("sst: Mute_get called\n"); 279 pr_debug("Mute_get called\n");
277 280
278 WARN_ON(!uval); 281 WARN_ON(!uval);
279 WARN_ON(!kcontrol); 282 WARN_ON(!kcontrol);
@@ -332,7 +335,7 @@ static int snd_intelmad_volume_set(struct snd_kcontrol *kcontrol,
332 struct snd_intelmad *intelmaddata; 335 struct snd_intelmad *intelmaddata;
333 struct snd_pmic_ops *scard_ops; 336 struct snd_pmic_ops *scard_ops;
334 337
335 pr_debug("sst: volume set called:%ld %ld\n", 338 pr_debug("volume set called:%ld %ld\n",
336 uval->value.integer.value[0], 339 uval->value.integer.value[0],
337 uval->value.integer.value[1]); 340 uval->value.integer.value[1]);
338 341
@@ -387,7 +390,7 @@ static int snd_intelmad_mute_set(struct snd_kcontrol *kcontrol,
387 struct snd_intelmad *intelmaddata; 390 struct snd_intelmad *intelmaddata;
388 struct snd_pmic_ops *scard_ops; 391 struct snd_pmic_ops *scard_ops;
389 392
390 pr_debug("sst: snd_intelmad_mute_set called\n"); 393 pr_debug("snd_intelmad_mute_set called\n");
391 394
392 WARN_ON(!uval); 395 WARN_ON(!uval);
393 WARN_ON(!kcontrol); 396 WARN_ON(!kcontrol);
@@ -455,7 +458,7 @@ static int snd_intelmad_device_get(struct snd_kcontrol *kcontrol,
455{ 458{
456 struct snd_intelmad *intelmaddata; 459 struct snd_intelmad *intelmaddata;
457 struct snd_pmic_ops *scard_ops; 460 struct snd_pmic_ops *scard_ops;
458 pr_debug("sst: device_get called\n"); 461 pr_debug("device_get called\n");
459 462
460 WARN_ON(!uval); 463 WARN_ON(!uval);
461 WARN_ON(!kcontrol); 464 WARN_ON(!kcontrol);
@@ -491,8 +494,9 @@ static int snd_intelmad_device_set(struct snd_kcontrol *kcontrol,
491 struct snd_intelmad *intelmaddata; 494 struct snd_intelmad *intelmaddata;
492 struct snd_pmic_ops *scard_ops; 495 struct snd_pmic_ops *scard_ops;
493 int ret_val = 0, vendor, status; 496 int ret_val = 0, vendor, status;
497 struct intel_sst_pcm_control *pcm_control;
494 498
495 pr_debug("sst: snd_intelmad_device_set called\n"); 499 pr_debug("snd_intelmad_device_set called\n");
496 500
497 WARN_ON(!uval); 501 WARN_ON(!uval);
498 WARN_ON(!kcontrol); 502 WARN_ON(!kcontrol);
@@ -518,15 +522,13 @@ static int snd_intelmad_device_set(struct snd_kcontrol *kcontrol,
518 case INPUT_SEL: 522 case INPUT_SEL:
519 vendor = intelmaddata->sstdrv_ops->vendor_id; 523 vendor = intelmaddata->sstdrv_ops->vendor_id;
520 if ((vendor == SND_MX) || (vendor == SND_FS)) { 524 if ((vendor == SND_MX) || (vendor == SND_FS)) {
521 if (uval->value.enumerated.item[0] == HS_MIC) { 525 pcm_control = intelmaddata->sstdrv_ops->pcm_control;
526 if (uval->value.enumerated.item[0] == HS_MIC)
522 status = 1; 527 status = 1;
523 intelmaddata->sstdrv_ops-> 528 else
524 control_set(SST_ENABLE_RX_TIME_SLOT, &status);
525 } else {
526 status = 0; 529 status = 0;
527 intelmaddata->sstdrv_ops-> 530 pcm_control->device_control(
528 control_set(SST_ENABLE_RX_TIME_SLOT, &status); 531 SST_ENABLE_RX_TIME_SLOT, &status);
529 }
530 } 532 }
531 ret_val = scard_ops->set_input_dev( 533 ret_val = scard_ops->set_input_dev(
532 uval->value.enumerated.item[0]); 534 uval->value.enumerated.item[0]);
diff --git a/drivers/staging/intel_sst/intelmid_msic_control.c b/drivers/staging/intel_sst/intelmid_msic_control.c
index 4d1755efceef..da093ed0cd88 100644
--- a/drivers/staging/intel_sst/intelmid_msic_control.c
+++ b/drivers/staging/intel_sst/intelmid_msic_control.c
@@ -24,6 +24,8 @@
24 * This file contains the control operations of msic vendors 24 * This file contains the control operations of msic vendors
25 */ 25 */
26 26
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
27#include <linux/pci.h> 29#include <linux/pci.h>
28#include <linux/file.h> 30#include <linux/file.h>
29#include "intel_sst.h" 31#include "intel_sst.h"
@@ -83,7 +85,7 @@ static int msic_init_card(void)
83 snd_msic_ops.cap_on = 0; 85 snd_msic_ops.cap_on = 0;
84 snd_msic_ops.input_dev_id = DMIC; /*def dev*/ 86 snd_msic_ops.input_dev_id = DMIC; /*def dev*/
85 snd_msic_ops.output_dev_id = STEREO_HEADPHONE; 87 snd_msic_ops.output_dev_id = STEREO_HEADPHONE;
86 pr_debug("sst: msic init complete!!\n"); 88 pr_debug("msic init complete!!\n");
87 return 0; 89 return 0;
88} 90}
89 91
@@ -173,7 +175,7 @@ static int msic_power_up_pb(unsigned int device)
173 return retval; 175 return retval;
174 } 176 }
175 177
176 pr_debug("sst: powering up pb.... Device %d\n", device); 178 pr_debug("powering up pb.... Device %d\n", device);
177 sst_sc_reg_access(sc_access1, PMIC_WRITE, 4); 179 sst_sc_reg_access(sc_access1, PMIC_WRITE, 4);
178 switch (device) { 180 switch (device) {
179 case SND_SST_DEVICE_HEADSET: 181 case SND_SST_DEVICE_HEADSET:
@@ -205,7 +207,7 @@ static int msic_power_up_pb(unsigned int device)
205 break; 207 break;
206 208
207 default: 209 default:
208 pr_warn("sst: Wrong Device %d, selected %d\n", 210 pr_warn("Wrong Device %d, selected %d\n",
209 device, snd_msic_ops.output_dev_id); 211 device, snd_msic_ops.output_dev_id);
210 } 212 }
211 return sst_sc_reg_access(sc_access_pcm2, PMIC_READ_MODIFY, 1); 213 return sst_sc_reg_access(sc_access_pcm2, PMIC_READ_MODIFY, 1);
@@ -268,7 +270,7 @@ static int msic_power_up_cp(unsigned int device)
268 return retval; 270 return retval;
269 } 271 }
270 272
271 pr_debug("sst: powering up cp....%d\n", snd_msic_ops.input_dev_id); 273 pr_debug("powering up cp....%d\n", snd_msic_ops.input_dev_id);
272 sst_sc_reg_access(sc_access2, PMIC_READ_MODIFY, 1); 274 sst_sc_reg_access(sc_access2, PMIC_READ_MODIFY, 1);
273 snd_msic_ops.cap_on = 1; 275 snd_msic_ops.cap_on = 1;
274 if (snd_msic_ops.input_dev_id == AMIC) 276 if (snd_msic_ops.input_dev_id == AMIC)
@@ -283,7 +285,7 @@ static int msic_power_down(void)
283{ 285{
284 int retval = 0; 286 int retval = 0;
285 287
286 pr_debug("sst: powering dn msic\n"); 288 pr_debug("powering dn msic\n");
287 snd_msic_ops.pb_on = 0; 289 snd_msic_ops.pb_on = 0;
288 snd_msic_ops.cap_on = 0; 290 snd_msic_ops.cap_on = 0;
289 return retval; 291 return retval;
@@ -293,7 +295,7 @@ static int msic_power_down_pb(void)
293{ 295{
294 int retval = 0; 296 int retval = 0;
295 297
296 pr_debug("sst: powering dn pb....\n"); 298 pr_debug("powering dn pb....\n");
297 snd_msic_ops.pb_on = 0; 299 snd_msic_ops.pb_on = 0;
298 return retval; 300 return retval;
299} 301}
@@ -302,7 +304,7 @@ static int msic_power_down_cp(void)
302{ 304{
303 int retval = 0; 305 int retval = 0;
304 306
305 pr_debug("sst: powering dn cp....\n"); 307 pr_debug("powering dn cp....\n");
306 snd_msic_ops.cap_on = 0; 308 snd_msic_ops.cap_on = 0;
307 return retval; 309 return retval;
308} 310}
@@ -311,7 +313,7 @@ static int msic_set_selected_output_dev(u8 value)
311{ 313{
312 int retval = 0; 314 int retval = 0;
313 315
314 pr_debug("sst: msic set selected output:%d\n", value); 316 pr_debug("msic set selected output:%d\n", value);
315 snd_msic_ops.output_dev_id = value; 317 snd_msic_ops.output_dev_id = value;
316 if (snd_msic_ops.pb_on) 318 if (snd_msic_ops.pb_on)
317 msic_power_up_pb(SND_SST_DEVICE_HEADSET); 319 msic_power_up_pb(SND_SST_DEVICE_HEADSET);
@@ -330,15 +332,15 @@ static int msic_set_selected_input_dev(u8 value)
330 }; 332 };
331 int retval = 0; 333 int retval = 0;
332 334
333 pr_debug("sst: msic_set_selected_input_dev:%d\n", value); 335 pr_debug("msic_set_selected_input_dev:%d\n", value);
334 snd_msic_ops.input_dev_id = value; 336 snd_msic_ops.input_dev_id = value;
335 switch (value) { 337 switch (value) {
336 case AMIC: 338 case AMIC:
337 pr_debug("sst: Selecting AMIC1\n"); 339 pr_debug("Selecting AMIC1\n");
338 retval = sst_sc_reg_access(sc_access_amic, PMIC_WRITE, 1); 340 retval = sst_sc_reg_access(sc_access_amic, PMIC_WRITE, 1);
339 break; 341 break;
340 case DMIC: 342 case DMIC:
341 pr_debug("sst: Selecting DMIC1\n"); 343 pr_debug("Selecting DMIC1\n");
342 retval = sst_sc_reg_access(sc_access_dmic, PMIC_WRITE, 1); 344 retval = sst_sc_reg_access(sc_access_dmic, PMIC_WRITE, 1);
343 break; 345 break;
344 default: 346 default:
diff --git a/drivers/staging/intel_sst/intelmid_pvt.c b/drivers/staging/intel_sst/intelmid_pvt.c
index 9ed9475ccc7b..3ba9daf67526 100644
--- a/drivers/staging/intel_sst/intelmid_pvt.c
+++ b/drivers/staging/intel_sst/intelmid_pvt.c
@@ -23,6 +23,9 @@
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 * ALSA driver for Intel MID sound card chipset - holding private functions 24 * ALSA driver for Intel MID sound card chipset - holding private functions
25 */ 25 */
26
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
26#include <linux/io.h> 29#include <linux/io.h>
27#include <asm/intel_scu_ipc.h> 30#include <asm/intel_scu_ipc.h>
28#include <sound/core.h> 31#include <sound/core.h>
@@ -50,7 +53,7 @@ void period_elapsed(void *mad_substream)
50 53
51 if (stream->stream_status != RUNNING) 54 if (stream->stream_status != RUNNING)
52 return; 55 return;
53 pr_debug("sst: calling period elapsed\n"); 56 pr_debug("calling period elapsed\n");
54 snd_pcm_period_elapsed(substream); 57 snd_pcm_period_elapsed(substream);
55 return; 58 return;
56} 59}
@@ -76,8 +79,8 @@ int snd_intelmad_alloc_stream(struct snd_pcm_substream *substream)
76 param.uc.pcm_params.period_count = substream->runtime->period_size; 79 param.uc.pcm_params.period_count = substream->runtime->period_size;
77 param.uc.pcm_params.ring_buffer_addr = 80 param.uc.pcm_params.ring_buffer_addr =
78 virt_to_phys(substream->runtime->dma_area); 81 virt_to_phys(substream->runtime->dma_area);
79 pr_debug("sst: period_cnt = %d\n", param.uc.pcm_params.period_count); 82 pr_debug("period_cnt = %d\n", param.uc.pcm_params.period_count);
80 pr_debug("sst: sfreq= %d, wd_sz = %d\n", 83 pr_debug("sfreq= %d, wd_sz = %d\n",
81 param.uc.pcm_params.sfreq, param.uc.pcm_params.pcm_wd_sz); 84 param.uc.pcm_params.sfreq, param.uc.pcm_params.pcm_wd_sz);
82 85
83 str_params.sparams = param; 86 str_params.sparams = param;
@@ -85,24 +88,22 @@ int snd_intelmad_alloc_stream(struct snd_pcm_substream *substream)
85 88
86 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 89 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
87 str_params.ops = STREAM_OPS_PLAYBACK; 90 str_params.ops = STREAM_OPS_PLAYBACK;
88 pr_debug("sst: Playbck stream,Device %d\n", stream->device); 91 pr_debug("Playbck stream,Device %d\n", stream->device);
89 } else { 92 } else {
90 str_params.ops = STREAM_OPS_CAPTURE; 93 str_params.ops = STREAM_OPS_CAPTURE;
91 stream->device = SND_SST_DEVICE_CAPTURE; 94 stream->device = SND_SST_DEVICE_CAPTURE;
92 pr_debug("sst: Capture stream,Device %d\n", stream->device); 95 pr_debug("Capture stream,Device %d\n", stream->device);
93 } 96 }
94 str_params.device_type = stream->device; 97 str_params.device_type = stream->device;
95 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_ALLOC, 98 ret_val = intelmaddata->sstdrv_ops->pcm_control->open(&str_params);
96 &str_params); 99 pr_debug("sst: SST_SND_PLAY/CAPTURE ret_val = %x\n", ret_val);
97 pr_debug("sst: SST_SND_PLAY/CAPTURE ret_val = %x\n",
98 ret_val);
99 if (ret_val < 0) 100 if (ret_val < 0)
100 return ret_val; 101 return ret_val;
101 102
102 stream->stream_info.str_id = ret_val; 103 stream->stream_info.str_id = ret_val;
103 stream->stream_status = INIT; 104 stream->stream_status = INIT;
104 stream->stream_info.buffer_ptr = 0; 105 stream->stream_info.buffer_ptr = 0;
105 pr_debug("sst: str id : %d\n", stream->stream_info.str_id); 106 pr_debug("str id : %d\n", stream->stream_info.str_id);
106 107
107 return ret_val; 108 return ret_val;
108} 109}
@@ -113,15 +114,15 @@ int snd_intelmad_init_stream(struct snd_pcm_substream *substream)
113 struct snd_intelmad *intelmaddata = snd_pcm_substream_chip(substream); 114 struct snd_intelmad *intelmaddata = snd_pcm_substream_chip(substream);
114 int ret_val; 115 int ret_val;
115 116
116 pr_debug("sst: setting buffer ptr param\n"); 117 pr_debug("setting buffer ptr param\n");
117 stream->stream_info.period_elapsed = period_elapsed; 118 stream->stream_info.period_elapsed = period_elapsed;
118 stream->stream_info.mad_substream = substream; 119 stream->stream_info.mad_substream = substream;
119 stream->stream_info.buffer_ptr = 0; 120 stream->stream_info.buffer_ptr = 0;
120 stream->stream_info.sfreq = substream->runtime->rate; 121 stream->stream_info.sfreq = substream->runtime->rate;
121 ret_val = intelmaddata->sstdrv_ops->control_set(SST_SND_STREAM_INIT, 122 ret_val = intelmaddata->sstdrv_ops->pcm_control->device_control(
122 &stream->stream_info); 123 SST_SND_STREAM_INIT, &stream->stream_info);
123 if (ret_val) 124 if (ret_val)
124 pr_err("sst: control_set ret error %d\n", ret_val); 125 pr_err("control_set ret error %d\n", ret_val);
125 return ret_val; 126 return ret_val;
126 127
127} 128}
@@ -145,30 +146,29 @@ int sst_sc_reg_access(struct sc_reg_access *sc_access,
145 for (i = 0; i < num_val; i++) { 146 for (i = 0; i < num_val; i++) {
146 retval = intel_scu_ipc_iowrite8(sc_access[i].reg_addr, 147 retval = intel_scu_ipc_iowrite8(sc_access[i].reg_addr,
147 sc_access[i].value); 148 sc_access[i].value);
148 if (retval) { 149 if (retval)
149 pr_err("sst: IPC write failed!!! %d\n", retval); 150 goto err;
150 return retval;
151 }
152 } 151 }
153 } else if (type == PMIC_READ) { 152 } else if (type == PMIC_READ) {
154 for (i = 0; i < num_val; i++) { 153 for (i = 0; i < num_val; i++) {
155 retval = intel_scu_ipc_ioread8(sc_access[i].reg_addr, 154 retval = intel_scu_ipc_ioread8(sc_access[i].reg_addr,
156 &(sc_access[i].value)); 155 &(sc_access[i].value));
157 if (retval) { 156 if (retval)
158 pr_err("sst: IPC read failed!!!!!%d\n", retval); 157 goto err;
159 return retval;
160 }
161 } 158 }
162 } else { 159 } else {
163 for (i = 0; i < num_val; i++) { 160 for (i = 0; i < num_val; i++) {
164 retval = intel_scu_ipc_update_register( 161 retval = intel_scu_ipc_update_register(
165 sc_access[i].reg_addr, sc_access[i].value, 162 sc_access[i].reg_addr, sc_access[i].value,
166 sc_access[i].mask); 163 sc_access[i].mask);
167 if (retval) { 164 if (retval)
168 pr_err("sst: IPC Modify failed!!!%d\n", retval); 165 goto err;
169 return retval;
170 }
171 } 166 }
172 } 167 }
173 return retval; 168 return 0;
169err:
170 pr_err("IPC failed for cmd %d, %d\n", retval, type);
171 pr_err("reg:0x%2x addr:0x%2x\n",
172 sc_access[i].reg_addr, sc_access[i].value);
173 return retval;
174} 174}
diff --git a/drivers/staging/intel_sst/intelmid_v0_control.c b/drivers/staging/intel_sst/intelmid_v0_control.c
index f586d62ac9af..7859225e3d60 100644
--- a/drivers/staging/intel_sst/intelmid_v0_control.c
+++ b/drivers/staging/intel_sst/intelmid_v0_control.c
@@ -26,6 +26,8 @@
26 * This file contains the control operations of vendor 1 26 * This file contains the control operations of vendor 1
27 */ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/pci.h> 31#include <linux/pci.h>
30#include <linux/file.h> 32#include <linux/file.h>
31#include "intel_sst.h" 33#include "intel_sst.h"
@@ -151,7 +153,7 @@ static int fs_power_up_pb(unsigned int port)
151 if (retval) 153 if (retval)
152 return retval; 154 return retval;
153 155
154 pr_debug("sst: in fs power up pb\n"); 156 pr_debug("in fs power up pb\n");
155 return fs_enable_audiodac(UNMUTE); 157 return fs_enable_audiodac(UNMUTE);
156} 158}
157 159
@@ -173,7 +175,7 @@ static int fs_power_down_pb(void)
173 if (retval) 175 if (retval)
174 return retval; 176 return retval;
175 177
176 pr_debug("sst: in fsl power down pb\n"); 178 pr_debug("in fsl power down pb\n");
177 return fs_enable_audiodac(UNMUTE); 179 return fs_enable_audiodac(UNMUTE);
178} 180}
179 181
@@ -380,7 +382,7 @@ static int fs_set_pcm_audio_params(int sfreq, int word_size, int num_channel)
380 sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 2); 382 sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 2);
381 383
382 } 384 }
383 pr_debug("sst: sfreq:%d,Register value = %x\n", sfreq, config1); 385 pr_debug("sfreq:%d,Register value = %x\n", sfreq, config1);
384 386
385 if (word_size == 24) { 387 if (word_size == 24) {
386 sc_access[0].reg_addr = AUDIOPORT1; 388 sc_access[0].reg_addr = AUDIOPORT1;
@@ -438,18 +440,18 @@ static int fs_set_selected_input_dev(u8 value)
438 440
439 switch (value) { 441 switch (value) {
440 case AMIC: 442 case AMIC:
441 pr_debug("sst: Selecting amic not supported in mono cfg\n"); 443 pr_debug("Selecting amic not supported in mono cfg\n");
442 return sst_sc_reg_access(sc_access_mic, PMIC_READ_MODIFY, 2); 444 return sst_sc_reg_access(sc_access_mic, PMIC_READ_MODIFY, 2);
443 break; 445 break;
444 446
445 case HS_MIC: 447 case HS_MIC:
446 pr_debug("sst: Selecting hsmic\n"); 448 pr_debug("Selecting hsmic\n");
447 return sst_sc_reg_access(sc_access_hsmic, 449 return sst_sc_reg_access(sc_access_hsmic,
448 PMIC_READ_MODIFY, 2); 450 PMIC_READ_MODIFY, 2);
449 break; 451 break;
450 452
451 case DMIC: 453 case DMIC:
452 pr_debug("sst: Selecting dmic\n"); 454 pr_debug("Selecting dmic\n");
453 return sst_sc_reg_access(sc_access_dmic, PMIC_READ_MODIFY, 2); 455 return sst_sc_reg_access(sc_access_dmic, PMIC_READ_MODIFY, 2);
454 break; 456 break;
455 457
@@ -505,7 +507,7 @@ static int fs_set_mute(int dev_id, u8 value)
505 return retval; 507 return retval;
506 508
507 509
508 pr_debug("sst: dev_id:0x%x value:0x%x\n", dev_id, value); 510 pr_debug("dev_id:0x%x value:0x%x\n", dev_id, value);
509 switch (dev_id) { 511 switch (dev_id) {
510 case PMIC_SND_DMIC_MUTE: 512 case PMIC_SND_DMIC_MUTE:
511 sc_access[0].reg_addr = MICCTRL; 513 sc_access[0].reg_addr = MICCTRL;
@@ -606,7 +608,7 @@ static int fs_set_vol(int dev_id, int value)
606 608
607 switch (dev_id) { 609 switch (dev_id) {
608 case PMIC_SND_LEFT_PB_VOL: 610 case PMIC_SND_LEFT_PB_VOL:
609 pr_debug("sst: PMIC_SND_LEFT_PB_VOL:%d\n", value); 611 pr_debug("PMIC_SND_LEFT_PB_VOL:%d\n", value);
610 sc_access[0].value = sc_access[1].value = value; 612 sc_access[0].value = sc_access[1].value = value;
611 sc_access[0].reg_addr = AUD16; 613 sc_access[0].reg_addr = AUD16;
612 sc_access[1].reg_addr = AUD15; 614 sc_access[1].reg_addr = AUD15;
@@ -616,7 +618,7 @@ static int fs_set_vol(int dev_id, int value)
616 break; 618 break;
617 619
618 case PMIC_SND_RIGHT_PB_VOL: 620 case PMIC_SND_RIGHT_PB_VOL:
619 pr_debug("sst: PMIC_SND_RIGHT_PB_VOL:%d\n", value); 621 pr_debug("PMIC_SND_RIGHT_PB_VOL:%d\n", value);
620 sc_access[0].value = sc_access[1].value = value; 622 sc_access[0].value = sc_access[1].value = value;
621 sc_access[0].reg_addr = AUD17; 623 sc_access[0].reg_addr = AUD17;
622 sc_access[1].reg_addr = AUD15; 624 sc_access[1].reg_addr = AUD15;
@@ -629,7 +631,7 @@ static int fs_set_vol(int dev_id, int value)
629 reg_num = 2; 631 reg_num = 2;
630 break; 632 break;
631 case PMIC_SND_CAPTURE_VOL: 633 case PMIC_SND_CAPTURE_VOL:
632 pr_debug("sst: PMIC_SND_CAPTURE_VOL:%d\n", value); 634 pr_debug("PMIC_SND_CAPTURE_VOL:%d\n", value);
633 sc_access[0].reg_addr = MICLICTRL1; 635 sc_access[0].reg_addr = MICLICTRL1;
634 sc_access[1].reg_addr = MICLICTRL2; 636 sc_access[1].reg_addr = MICLICTRL2;
635 sc_access[2].reg_addr = DMICCTRL1; 637 sc_access[2].reg_addr = DMICCTRL1;
@@ -726,17 +728,17 @@ static int fs_get_vol(int dev_id, int *value)
726 728
727 switch (dev_id) { 729 switch (dev_id) {
728 case PMIC_SND_CAPTURE_VOL: 730 case PMIC_SND_CAPTURE_VOL:
729 pr_debug("sst: PMIC_SND_CAPTURE_VOL\n"); 731 pr_debug("PMIC_SND_CAPTURE_VOL\n");
730 sc_access.reg_addr = MICLICTRL1; 732 sc_access.reg_addr = MICLICTRL1;
731 mask = (MASK5|MASK4|MASK3|MASK2|MASK1|MASK0); 733 mask = (MASK5|MASK4|MASK3|MASK2|MASK1|MASK0);
732 break; 734 break;
733 case PMIC_SND_LEFT_PB_VOL: 735 case PMIC_SND_LEFT_PB_VOL:
734 pr_debug("sst: PMIC_SND_LEFT_PB_VOL\n"); 736 pr_debug("PMIC_SND_LEFT_PB_VOL\n");
735 sc_access.reg_addr = AUD16; 737 sc_access.reg_addr = AUD16;
736 mask = (MASK5|MASK4|MASK3|MASK2|MASK1|MASK0); 738 mask = (MASK5|MASK4|MASK3|MASK2|MASK1|MASK0);
737 break; 739 break;
738 case PMIC_SND_RIGHT_PB_VOL: 740 case PMIC_SND_RIGHT_PB_VOL:
739 pr_debug("sst: PMIC_SND_RT_PB_VOL\n"); 741 pr_debug("PMIC_SND_RT_PB_VOL\n");
740 sc_access.reg_addr = AUD17; 742 sc_access.reg_addr = AUD17;
741 mask = (MASK5|MASK4|MASK3|MASK2|MASK1|MASK0); 743 mask = (MASK5|MASK4|MASK3|MASK2|MASK1|MASK0);
742 break; 744 break;
@@ -745,9 +747,9 @@ static int fs_get_vol(int dev_id, int *value)
745 } 747 }
746 748
747 retval = sst_sc_reg_access(&sc_access, PMIC_READ, 1); 749 retval = sst_sc_reg_access(&sc_access, PMIC_READ, 1);
748 pr_debug("sst: value read = 0x%x\n", sc_access.value); 750 pr_debug("value read = 0x%x\n", sc_access.value);
749 *value = (int) (sc_access.value & mask); 751 *value = (int) (sc_access.value & mask);
750 pr_debug("sst: value returned = 0x%x\n", *value); 752 pr_debug("value returned = 0x%x\n", *value);
751 return retval; 753 return retval;
752} 754}
753 755
diff --git a/drivers/staging/intel_sst/intelmid_v1_control.c b/drivers/staging/intel_sst/intelmid_v1_control.c
index 9de86b2f6b08..478cfecdefd7 100644
--- a/drivers/staging/intel_sst/intelmid_v1_control.c
+++ b/drivers/staging/intel_sst/intelmid_v1_control.c
@@ -25,6 +25,8 @@
25 * This file contains the control operations of vendor 2 25 * This file contains the control operations of vendor 2
26 */ 26 */
27 27
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
28#include <linux/pci.h> 30#include <linux/pci.h>
29#include <linux/file.h> 31#include <linux/file.h>
30#include <asm/mrst.h> 32#include <asm/mrst.h>
@@ -132,56 +134,6 @@ static int mx_init_card(void)
132 return sst_sc_reg_access(sc_access, PMIC_WRITE, 47); 134 return sst_sc_reg_access(sc_access, PMIC_WRITE, 47);
133} 135}
134 136
135static int mx_init_capture_card(void)
136{
137 struct sc_reg_access sc_access[] = {
138 {0x206, 0x5a, 0x0},
139 {0x207, 0xbe, 0x0},
140 {0x208, 0x90, 0x0},
141 {0x209, 0x32, 0x0},
142 {0x20e, 0x22, 0x0},
143 {0x210, 0x84, 0x0},
144 {0x223, 0x20, 0x0},
145 {0x226, 0xC0, 0x0},
146 };
147
148 int retval = 0;
149
150 retval = sst_sc_reg_access(sc_access, PMIC_WRITE, 8);
151 if (0 != retval) {
152 /* pmic communication fails */
153 pr_debug("sst: pmic commn failed\n");
154 return retval;
155 }
156
157 pr_debug("sst: Capture configuration complete!!\n");
158 return 0;
159}
160
161static int mx_init_playback_card(void)
162{
163 struct sc_reg_access sc_access[] = {
164 {0x206, 0x00, 0x0},
165 {0x207, 0x00, 0x0},
166 {0x208, 0x00, 0x0},
167 {0x209, 0x51, 0x0},
168 {0x20e, 0x51, 0x0},
169 {0x210, 0x21, 0x0},
170 {0x223, 0x01, 0x0},
171 };
172 int retval = 0;
173
174 retval = sst_sc_reg_access(sc_access, PMIC_WRITE, 9);
175 if (0 != retval) {
176 /* pmic communication fails */
177 pr_debug("sst: pmic commn failed\n");
178 return retval;
179 }
180
181 pr_debug("sst: Playback configuration complete!!\n");
182 return 0;
183}
184
185static int mx_enable_audiodac(int value) 137static int mx_enable_audiodac(int value)
186{ 138{
187 struct sc_reg_access sc_access[3]; 139 struct sc_reg_access sc_access[3];
@@ -204,7 +156,7 @@ static int mx_enable_audiodac(int value)
204 retval = sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 2); 156 retval = sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 2);
205 if (retval) 157 if (retval)
206 return retval; 158 return retval;
207 pr_debug("sst: mute status = %d", snd_pmic_ops_mx.mute_status); 159 pr_debug("mute status = %d\n", snd_pmic_ops_mx.mute_status);
208 if (snd_pmic_ops_mx.mute_status == MUTE || 160 if (snd_pmic_ops_mx.mute_status == MUTE ||
209 snd_pmic_ops_mx.master_mute == MUTE) 161 snd_pmic_ops_mx.master_mute == MUTE)
210 return retval; 162 return retval;
@@ -412,7 +364,7 @@ static int mx_set_pcm_voice_params(void)
412 if (retval) 364 if (retval)
413 return retval; 365 return retval;
414 } 366 }
415 pr_debug("sst: SST DBG mx_set_pcm_voice_params called\n"); 367 pr_debug("SST DBG:mx_set_pcm_voice_params called\n");
416 return sst_sc_reg_access(sc_access, PMIC_WRITE, 44); 368 return sst_sc_reg_access(sc_access, PMIC_WRITE, 44);
417} 369}
418 370
@@ -529,7 +481,7 @@ static int mx_set_selected_output_dev(u8 dev_id)
529 return retval; 481 return retval;
530 } 482 }
531 483
532 pr_debug("sst: mx_set_selected_output_dev dev_id:0x%x\n", dev_id); 484 pr_debug("mx_set_selected_output_dev dev_id:0x%x\n", dev_id);
533 snd_pmic_ops_mx.output_dev_id = dev_id; 485 snd_pmic_ops_mx.output_dev_id = dev_id;
534 switch (dev_id) { 486 switch (dev_id) {
535 case STEREO_HEADPHONE: 487 case STEREO_HEADPHONE:
@@ -549,7 +501,7 @@ static int mx_set_selected_output_dev(u8 dev_id)
549 num_reg = 1; 501 num_reg = 1;
550 break; 502 break;
551 case RECEIVER: 503 case RECEIVER:
552 pr_debug("sst: RECEIVER Koski selected\n"); 504 pr_debug("RECEIVER Koski selected\n");
553 505
554 /* configuration - AS enable, receiver enable */ 506 /* configuration - AS enable, receiver enable */
555 sc_access[0].reg_addr = 0xFF; 507 sc_access[0].reg_addr = 0xFF;
@@ -559,7 +511,7 @@ static int mx_set_selected_output_dev(u8 dev_id)
559 num_reg = 1; 511 num_reg = 1;
560 break; 512 break;
561 default: 513 default:
562 pr_err("sst: Not a valid output dev\n"); 514 pr_err("Not a valid output dev\n");
563 return 0; 515 return 0;
564 } 516 }
565 return sst_sc_reg_access(sc_access, PMIC_WRITE, num_reg); 517 return sst_sc_reg_access(sc_access, PMIC_WRITE, num_reg);
@@ -598,7 +550,7 @@ static int mx_set_selected_input_dev(u8 dev_id)
598 return retval; 550 return retval;
599 } 551 }
600 snd_pmic_ops_mx.input_dev_id = dev_id; 552 snd_pmic_ops_mx.input_dev_id = dev_id;
601 pr_debug("sst: mx_set_selected_input_dev dev_id:0x%x\n", dev_id); 553 pr_debug("mx_set_selected_input_dev dev_id:0x%x\n", dev_id);
602 554
603 switch (dev_id) { 555 switch (dev_id) {
604 case AMIC: 556 case AMIC:
@@ -646,7 +598,7 @@ static int mx_set_mute(int dev_id, u8 value)
646 } 598 }
647 599
648 600
649 pr_debug("sst: set_mute dev_id:0x%x , value:%d\n", dev_id, value); 601 pr_debug("set_mute dev_id:0x%x , value:%d\n", dev_id, value);
650 602
651 switch (dev_id) { 603 switch (dev_id) {
652 case PMIC_SND_DMIC_MUTE: 604 case PMIC_SND_DMIC_MUTE:
@@ -760,7 +712,7 @@ static int mx_set_vol(int dev_id, int value)
760 if (retval) 712 if (retval)
761 return retval; 713 return retval;
762 } 714 }
763 pr_debug("sst: set_vol dev_id:0x%x ,value:%d\n", dev_id, value); 715 pr_debug("set_vol dev_id:0x%x ,value:%d\n", dev_id, value);
764 switch (dev_id) { 716 switch (dev_id) {
765 case PMIC_SND_RECEIVER_VOL: 717 case PMIC_SND_RECEIVER_VOL:
766 return 0; 718 return 0;
@@ -875,7 +827,7 @@ static int mx_get_vol(int dev_id, int *value)
875 if (retval) 827 if (retval)
876 return retval; 828 return retval;
877 *value = -(sc_access.value & mask); 829 *value = -(sc_access.value & mask);
878 pr_debug("sst: get volume value extracted %d\n", *value); 830 pr_debug("get volume value extracted %d\n", *value);
879 return retval; 831 return retval;
880} 832}
881 833
diff --git a/drivers/staging/intel_sst/intelmid_v2_control.c b/drivers/staging/intel_sst/intelmid_v2_control.c
index 3a7de769842a..e38e89df6e84 100644
--- a/drivers/staging/intel_sst/intelmid_v2_control.c
+++ b/drivers/staging/intel_sst/intelmid_v2_control.c
@@ -26,6 +26,8 @@
26 * This file contains the control operations of vendor 3 26 * This file contains the control operations of vendor 3
27 */ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/pci.h> 31#include <linux/pci.h>
30#include <linux/file.h> 32#include <linux/file.h>
31#include "intel_sst.h" 33#include "intel_sst.h"
@@ -120,7 +122,7 @@ static int nc_init_card(void)
120 snd_pmic_ops_nc.master_mute = UNMUTE; 122 snd_pmic_ops_nc.master_mute = UNMUTE;
121 snd_pmic_ops_nc.mute_status = UNMUTE; 123 snd_pmic_ops_nc.mute_status = UNMUTE;
122 sst_sc_reg_access(sc_access, PMIC_WRITE, 26); 124 sst_sc_reg_access(sc_access, PMIC_WRITE, 26);
123 pr_debug("sst: init complete!!\n"); 125 pr_debug("init complete!!\n");
124 return 0; 126 return 0;
125} 127}
126 128
@@ -169,7 +171,7 @@ static int nc_power_up_pb(unsigned int port)
169 nc_enable_audiodac(MUTE); 171 nc_enable_audiodac(MUTE);
170 msleep(30); 172 msleep(30);
171 173
172 pr_debug("sst: powering up pb....\n"); 174 pr_debug("powering up pb....\n");
173 175
174 sc_access[0].reg_addr = VAUDIOCNT; 176 sc_access[0].reg_addr = VAUDIOCNT;
175 sc_access[0].value = 0x27; 177 sc_access[0].value = 0x27;
@@ -222,7 +224,7 @@ static int nc_power_up_cp(unsigned int port)
222 return retval; 224 return retval;
223 225
224 226
225 pr_debug("sst: powering up cp....\n"); 227 pr_debug("powering up cp....\n");
226 228
227 if (port == 0xFF) 229 if (port == 0xFF)
228 return 0; 230 return 0;
@@ -275,7 +277,7 @@ static int nc_power_down(void)
275 nc_enable_audiodac(MUTE); 277 nc_enable_audiodac(MUTE);
276 278
277 279
278 pr_debug("sst: powering dn nc_power_down ....\n"); 280 pr_debug("powering dn nc_power_down ....\n");
279 281
280 msleep(30); 282 msleep(30);
281 283
@@ -324,7 +326,7 @@ static int nc_power_down_pb(void)
324 if (retval) 326 if (retval)
325 return retval; 327 return retval;
326 328
327 pr_debug("sst: powering dn pb....\n"); 329 pr_debug("powering dn pb....\n");
328 330
329 nc_enable_audiodac(MUTE); 331 nc_enable_audiodac(MUTE);
330 332
@@ -370,7 +372,7 @@ static int nc_power_down_cp(void)
370 if (retval) 372 if (retval)
371 return retval; 373 return retval;
372 374
373 pr_debug("sst: powering dn cp....\n"); 375 pr_debug("powering dn cp....\n");
374 return sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 1); 376 return sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 1);
375} 377}
376 378
@@ -400,7 +402,7 @@ static int nc_set_pcm_voice_params(void)
400 return retval; 402 return retval;
401 403
402 sst_sc_reg_access(sc_access, PMIC_WRITE, 14); 404 sst_sc_reg_access(sc_access, PMIC_WRITE, 14);
403 pr_debug("sst: Voice parameters set successfully!!\n"); 405 pr_debug("Voice parameters set successfully!!\n");
404 return 0; 406 return 0;
405} 407}
406 408
@@ -451,20 +453,20 @@ static int nc_set_pcm_audio_params(int sfreq, int word_size, int num_channel)
451 453
452 sc_access.value = 0x07; 454 sc_access.value = 0x07;
453 sc_access.reg_addr = RMUTE; 455 sc_access.reg_addr = RMUTE;
454 pr_debug("sst: RIGHT_HP_MUTE value%d\n", sc_access.value); 456 pr_debug("RIGHT_HP_MUTE value%d\n", sc_access.value);
455 sc_access.mask = MASK2; 457 sc_access.mask = MASK2;
456 sst_sc_reg_access(&sc_access, PMIC_READ_MODIFY, 1); 458 sst_sc_reg_access(&sc_access, PMIC_READ_MODIFY, 1);
457 } else { 459 } else {
458 sc_access.value = 0x00; 460 sc_access.value = 0x00;
459 sc_access.reg_addr = RMUTE; 461 sc_access.reg_addr = RMUTE;
460 pr_debug("sst: RIGHT_HP_MUTE value %d\n", sc_access.value); 462 pr_debug("RIGHT_HP_MUTE value %d\n", sc_access.value);
461 sc_access.mask = MASK2; 463 sc_access.mask = MASK2;
462 sst_sc_reg_access(&sc_access, PMIC_READ_MODIFY, 1); 464 sst_sc_reg_access(&sc_access, PMIC_READ_MODIFY, 1);
463 465
464 466
465 } 467 }
466 468
467 pr_debug("sst: word_size = %d\n", word_size); 469 pr_debug("word_size = %d\n", word_size);
468 470
469 if (word_size == 24) { 471 if (word_size == 24) {
470 sc_access.reg_addr = AUDIOPORT2; 472 sc_access.reg_addr = AUDIOPORT2;
@@ -477,7 +479,7 @@ static int nc_set_pcm_audio_params(int sfreq, int word_size, int num_channel)
477 } 479 }
478 sst_sc_reg_access(&sc_access, PMIC_READ_MODIFY, 1); 480 sst_sc_reg_access(&sc_access, PMIC_READ_MODIFY, 1);
479 481
480 pr_debug("sst: word_size = %d\n", word_size); 482 pr_debug("word_size = %d\n", word_size);
481 sc_access.reg_addr = AUDIOPORT1; 483 sc_access.reg_addr = AUDIOPORT1;
482 sc_access.mask = MASK5|MASK4|MASK1|MASK0; 484 sc_access.mask = MASK5|MASK4|MASK1|MASK0;
483 if (word_size == 16) 485 if (word_size == 16)
@@ -508,7 +510,7 @@ static int nc_set_selected_output_dev(u8 value)
508 retval = nc_init_card(); 510 retval = nc_init_card();
509 if (retval) 511 if (retval)
510 return retval; 512 return retval;
511 pr_debug("sst: nc set selected output:%d\n", value); 513 pr_debug("nc set selected output:%d\n", value);
512 switch (value) { 514 switch (value) {
513 case STEREO_HEADPHONE: 515 case STEREO_HEADPHONE:
514 retval = sst_sc_reg_access(sc_access_HP, PMIC_WRITE, 2); 516 retval = sst_sc_reg_access(sc_access_HP, PMIC_WRITE, 2);
@@ -517,7 +519,7 @@ static int nc_set_selected_output_dev(u8 value)
517 retval = sst_sc_reg_access(sc_access_IS, PMIC_WRITE, 2); 519 retval = sst_sc_reg_access(sc_access_IS, PMIC_WRITE, 2);
518 break; 520 break;
519 default: 521 default:
520 pr_err("sst: rcvd illegal request: %d\n", value); 522 pr_err("rcvd illegal request: %d\n", value);
521 return -EINVAL; 523 return -EINVAL;
522 } 524 }
523 return retval; 525 return retval;
@@ -541,7 +543,7 @@ static int nc_audio_init(void)
541 }; 543 };
542 544
543 sst_sc_reg_access(sc_access, PMIC_WRITE, 12); 545 sst_sc_reg_access(sc_access, PMIC_WRITE, 12);
544 pr_debug("sst: Audio Init successfully!!\n"); 546 pr_debug("Audio Init successfully!!\n");
545 547
546 /*set output device */ 548 /*set output device */
547 nc_set_selected_output_dev(snd_pmic_ops_nc.output_dev_id); 549 nc_set_selected_output_dev(snd_pmic_ops_nc.output_dev_id);
@@ -549,13 +551,13 @@ static int nc_audio_init(void)
549 if (snd_pmic_ops_nc.num_channel == 1) { 551 if (snd_pmic_ops_nc.num_channel == 1) {
550 sc_acces.value = 0x07; 552 sc_acces.value = 0x07;
551 sc_acces.reg_addr = RMUTE; 553 sc_acces.reg_addr = RMUTE;
552 pr_debug("sst: RIGHT_HP_MUTE value%d\n", sc_acces.value); 554 pr_debug("RIGHT_HP_MUTE value%d\n", sc_acces.value);
553 sc_acces.mask = MASK2; 555 sc_acces.mask = MASK2;
554 sst_sc_reg_access(&sc_acces, PMIC_READ_MODIFY, 1); 556 sst_sc_reg_access(&sc_acces, PMIC_READ_MODIFY, 1);
555 } else { 557 } else {
556 sc_acces.value = 0x00; 558 sc_acces.value = 0x00;
557 sc_acces.reg_addr = RMUTE; 559 sc_acces.reg_addr = RMUTE;
558 pr_debug("sst: RIGHT_HP_MUTE value%d\n", sc_acces.value); 560 pr_debug("RIGHT_HP_MUTE value%d\n", sc_acces.value);
559 sc_acces.mask = MASK2; 561 sc_acces.mask = MASK2;
560 sst_sc_reg_access(&sc_acces, PMIC_READ_MODIFY, 1); 562 sst_sc_reg_access(&sc_acces, PMIC_READ_MODIFY, 1);
561 } 563 }
@@ -629,11 +631,11 @@ static int nc_set_mute(int dev_id, u8 value)
629 if (retval) 631 if (retval)
630 return retval; 632 return retval;
631 633
632 pr_debug("sst: set device id::%d, value %d\n", dev_id, value); 634 pr_debug("set device id::%d, value %d\n", dev_id, value);
633 635
634 switch (dev_id) { 636 switch (dev_id) {
635 case PMIC_SND_MUTE_ALL: 637 case PMIC_SND_MUTE_ALL:
636 pr_debug("sst: PMIC_SND_MUTE_ALL value %d\n", value); 638 pr_debug("PMIC_SND_MUTE_ALL value %d\n", value);
637 snd_pmic_ops_nc.mute_status = value; 639 snd_pmic_ops_nc.mute_status = value;
638 snd_pmic_ops_nc.master_mute = value; 640 snd_pmic_ops_nc.master_mute = value;
639 if (value == UNMUTE) { 641 if (value == UNMUTE) {
@@ -669,7 +671,7 @@ static int nc_set_mute(int dev_id, u8 value)
669 } 671 }
670 break; 672 break;
671 case PMIC_SND_HP_MIC_MUTE: 673 case PMIC_SND_HP_MIC_MUTE:
672 pr_debug("sst: PMIC_SND_HPMIC_MUTE value %d\n", value); 674 pr_debug("PMIC_SND_HPMIC_MUTE value %d\n", value);
673 if (value == UNMUTE) { 675 if (value == UNMUTE) {
674 /* unmute the system, set the 6th bit to one */ 676 /* unmute the system, set the 6th bit to one */
675 sc_access[0].value = 0x00; 677 sc_access[0].value = 0x00;
@@ -682,7 +684,7 @@ static int nc_set_mute(int dev_id, u8 value)
682 retval = sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 1); 684 retval = sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 1);
683 break; 685 break;
684 case PMIC_SND_AMIC_MUTE: 686 case PMIC_SND_AMIC_MUTE:
685 pr_debug("sst: PMIC_SND_AMIC_MUTE value %d\n", value); 687 pr_debug("PMIC_SND_AMIC_MUTE value %d\n", value);
686 if (value == UNMUTE) { 688 if (value == UNMUTE) {
687 /* unmute the system, set the 6th bit to one */ 689 /* unmute the system, set the 6th bit to one */
688 sc_access[0].value = 0x00; 690 sc_access[0].value = 0x00;
@@ -696,7 +698,7 @@ static int nc_set_mute(int dev_id, u8 value)
696 break; 698 break;
697 699
698 case PMIC_SND_DMIC_MUTE: 700 case PMIC_SND_DMIC_MUTE:
699 pr_debug("sst: INPUT_MUTE_DMIC value%d\n", value); 701 pr_debug("INPUT_MUTE_DMIC value%d\n", value);
700 if (value == UNMUTE) { 702 if (value == UNMUTE) {
701 /* unmute the system, set the 6th bit to one */ 703 /* unmute the system, set the 6th bit to one */
702 sc_access[1].value = 0x00; 704 sc_access[1].value = 0x00;
@@ -724,13 +726,13 @@ static int nc_set_mute(int dev_id, u8 value)
724 726
725 if (dev_id == PMIC_SND_LEFT_HP_MUTE) { 727 if (dev_id == PMIC_SND_LEFT_HP_MUTE) {
726 sc_access[0].reg_addr = LMUTE; 728 sc_access[0].reg_addr = LMUTE;
727 pr_debug("sst: LEFT_HP_MUTE value %d\n", 729 pr_debug("LEFT_HP_MUTE value %d\n",
728 sc_access[0].value); 730 sc_access[0].value);
729 } else { 731 } else {
730 if (snd_pmic_ops_nc.num_channel == 1) 732 if (snd_pmic_ops_nc.num_channel == 1)
731 sc_access[0].value = 0x04; 733 sc_access[0].value = 0x04;
732 sc_access[0].reg_addr = RMUTE; 734 sc_access[0].reg_addr = RMUTE;
733 pr_debug("sst: RIGHT_HP_MUTE value %d\n", 735 pr_debug("RIGHT_HP_MUTE value %d\n",
734 sc_access[0].value); 736 sc_access[0].value);
735 } 737 }
736 sc_access[0].mask = MASK2; 738 sc_access[0].mask = MASK2;
@@ -743,7 +745,7 @@ static int nc_set_mute(int dev_id, u8 value)
743 else 745 else
744 sc_access[0].value = 0x03; 746 sc_access[0].value = 0x03;
745 sc_access[0].reg_addr = LMUTE; 747 sc_access[0].reg_addr = LMUTE;
746 pr_debug("sst: SPEAKER_MUTE %d\n", sc_access[0].value); 748 pr_debug("SPEAKER_MUTE %d\n", sc_access[0].value);
747 sc_access[0].mask = MASK1; 749 sc_access[0].mask = MASK1;
748 retval = sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 1); 750 retval = sst_sc_reg_access(sc_access, PMIC_READ_MODIFY, 1);
749 break; 751 break;
@@ -764,10 +766,10 @@ static int nc_set_vol(int dev_id, int value)
764 if (retval) 766 if (retval)
765 return retval; 767 return retval;
766 768
767 pr_debug("sst: set volume:%d\n", dev_id); 769 pr_debug("set volume:%d\n", dev_id);
768 switch (dev_id) { 770 switch (dev_id) {
769 case PMIC_SND_CAPTURE_VOL: 771 case PMIC_SND_CAPTURE_VOL:
770 pr_debug("sst: PMIC_SND_CAPTURE_VOL:value::%d\n", value); 772 pr_debug("PMIC_SND_CAPTURE_VOL:value::%d\n", value);
771 sc_access[0].value = sc_access[1].value = 773 sc_access[0].value = sc_access[1].value =
772 sc_access[2].value = -value; 774 sc_access[2].value = -value;
773 sc_access[0].mask = sc_access[1].mask = sc_access[2].mask = 775 sc_access[0].mask = sc_access[1].mask = sc_access[2].mask =
@@ -779,7 +781,7 @@ static int nc_set_vol(int dev_id, int value)
779 break; 781 break;
780 782
781 case PMIC_SND_LEFT_PB_VOL: 783 case PMIC_SND_LEFT_PB_VOL:
782 pr_debug("sst: PMIC_SND_LEFT_HP_VOL %d\n", value); 784 pr_debug("PMIC_SND_LEFT_HP_VOL %d\n", value);
783 sc_access[0].value = -value; 785 sc_access[0].value = -value;
784 sc_access[0].reg_addr = AUDIOLVOL; 786 sc_access[0].reg_addr = AUDIOLVOL;
785 sc_access[0].mask = 787 sc_access[0].mask =
@@ -788,7 +790,7 @@ static int nc_set_vol(int dev_id, int value)
788 break; 790 break;
789 791
790 case PMIC_SND_RIGHT_PB_VOL: 792 case PMIC_SND_RIGHT_PB_VOL:
791 pr_debug("sst: PMIC_SND_RIGHT_HP_VOL value %d\n", value); 793 pr_debug("PMIC_SND_RIGHT_HP_VOL value %d\n", value);
792 if (snd_pmic_ops_nc.num_channel == 1) { 794 if (snd_pmic_ops_nc.num_channel == 1) {
793 sc_access[0].value = 0x04; 795 sc_access[0].value = 0x04;
794 sc_access[0].reg_addr = RMUTE; 796 sc_access[0].reg_addr = RMUTE;
@@ -821,11 +823,11 @@ static int nc_set_selected_input_dev(u8 value)
821 return retval; 823 return retval;
822 snd_pmic_ops_nc.input_dev_id = value; 824 snd_pmic_ops_nc.input_dev_id = value;
823 825
824 pr_debug("sst: nc set selected input:%d\n", value); 826 pr_debug("nc set selected input:%d\n", value);
825 827
826 switch (value) { 828 switch (value) {
827 case AMIC: 829 case AMIC:
828 pr_debug("sst: Selecting AMIC\n"); 830 pr_debug("Selecting AMIC\n");
829 sc_access[0].reg_addr = 0x107; 831 sc_access[0].reg_addr = 0x107;
830 sc_access[0].value = 0x40; 832 sc_access[0].value = 0x40;
831 sc_access[0].mask = MASK6|MASK4|MASK3|MASK1|MASK0; 833 sc_access[0].mask = MASK6|MASK4|MASK3|MASK1|MASK0;
@@ -842,7 +844,7 @@ static int nc_set_selected_input_dev(u8 value)
842 break; 844 break;
843 845
844 case HS_MIC: 846 case HS_MIC:
845 pr_debug("sst: Selecting HS_MIC\n"); 847 pr_debug("Selecting HS_MIC\n");
846 sc_access[0].reg_addr = 0x107; 848 sc_access[0].reg_addr = 0x107;
847 sc_access[0].mask = MASK6|MASK4|MASK3|MASK1|MASK0; 849 sc_access[0].mask = MASK6|MASK4|MASK3|MASK1|MASK0;
848 sc_access[0].value = 0x10; 850 sc_access[0].value = 0x10;
@@ -859,7 +861,7 @@ static int nc_set_selected_input_dev(u8 value)
859 break; 861 break;
860 862
861 case DMIC: 863 case DMIC:
862 pr_debug("sst: DMIC\n"); 864 pr_debug("DMIC\n");
863 sc_access[0].reg_addr = 0x107; 865 sc_access[0].reg_addr = 0x107;
864 sc_access[0].mask = MASK6|MASK4|MASK3|MASK1|MASK0; 866 sc_access[0].mask = MASK6|MASK4|MASK3|MASK1|MASK0;
865 sc_access[0].value = 0x0B; 867 sc_access[0].value = 0x0B;
@@ -871,7 +873,7 @@ static int nc_set_selected_input_dev(u8 value)
871 sc_access[2].mask = MASK6; 873 sc_access[2].mask = MASK6;
872 sc_access[3].reg_addr = 0x109; 874 sc_access[3].reg_addr = 0x109;
873 sc_access[3].mask = MASK6; 875 sc_access[3].mask = MASK6;
874 sc_access[3].value = 0x40; 876 sc_access[3].value = 0x00;
875 num_val = 4; 877 num_val = 4;
876 break; 878 break;
877 default: 879 default:
@@ -890,23 +892,23 @@ static int nc_get_mute(int dev_id, u8 *value)
890 if (retval) 892 if (retval)
891 return retval; 893 return retval;
892 894
893 pr_debug("sst: get mute::%d\n", dev_id); 895 pr_debug("get mute::%d\n", dev_id);
894 896
895 switch (dev_id) { 897 switch (dev_id) {
896 case PMIC_SND_AMIC_MUTE: 898 case PMIC_SND_AMIC_MUTE:
897 pr_debug("sst: PMIC_SND_INPUT_MUTE_MIC1\n"); 899 pr_debug("PMIC_SND_INPUT_MUTE_MIC1\n");
898 sc_access.reg_addr = LILSEL; 900 sc_access.reg_addr = LILSEL;
899 mask = MASK6; 901 mask = MASK6;
900 break; 902 break;
901 case PMIC_SND_HP_MIC_MUTE: 903 case PMIC_SND_HP_MIC_MUTE:
902 pr_debug("sst: PMIC_SND_INPUT_MUTE_MIC2\n"); 904 pr_debug("PMIC_SND_INPUT_MUTE_MIC2\n");
903 sc_access.reg_addr = LIRSEL; 905 sc_access.reg_addr = LIRSEL;
904 mask = MASK6; 906 mask = MASK6;
905 break; 907 break;
906 case PMIC_SND_LEFT_HP_MUTE: 908 case PMIC_SND_LEFT_HP_MUTE:
907 case PMIC_SND_RIGHT_HP_MUTE: 909 case PMIC_SND_RIGHT_HP_MUTE:
908 mask = MASK2; 910 mask = MASK2;
909 pr_debug("sst: PMIC_SN_LEFT/RIGHT_HP_MUTE\n"); 911 pr_debug("PMIC_SN_LEFT/RIGHT_HP_MUTE\n");
910 if (dev_id == PMIC_SND_RIGHT_HP_MUTE) 912 if (dev_id == PMIC_SND_RIGHT_HP_MUTE)
911 sc_access.reg_addr = RMUTE; 913 sc_access.reg_addr = RMUTE;
912 else 914 else
@@ -914,12 +916,12 @@ static int nc_get_mute(int dev_id, u8 *value)
914 break; 916 break;
915 917
916 case PMIC_SND_LEFT_SPEAKER_MUTE: 918 case PMIC_SND_LEFT_SPEAKER_MUTE:
917 pr_debug("sst: PMIC_MONO_EARPIECE_MUTE\n"); 919 pr_debug("PMIC_MONO_EARPIECE_MUTE\n");
918 sc_access.reg_addr = RMUTE; 920 sc_access.reg_addr = RMUTE;
919 mask = MASK1; 921 mask = MASK1;
920 break; 922 break;
921 case PMIC_SND_DMIC_MUTE: 923 case PMIC_SND_DMIC_MUTE:
922 pr_debug("sst: PMIC_SND_INPUT_MUTE_DMIC\n"); 924 pr_debug("PMIC_SND_INPUT_MUTE_DMIC\n");
923 sc_access.reg_addr = 0x105; 925 sc_access.reg_addr = 0x105;
924 mask = MASK6; 926 mask = MASK6;
925 break; 927 break;
@@ -928,16 +930,16 @@ static int nc_get_mute(int dev_id, u8 *value)
928 930
929 } 931 }
930 retval = sst_sc_reg_access(&sc_access, PMIC_READ, 1); 932 retval = sst_sc_reg_access(&sc_access, PMIC_READ, 1);
931 pr_debug("sst: reg value = %d\n", sc_access.value); 933 pr_debug("reg value = %d\n", sc_access.value);
932 if (retval) 934 if (retval)
933 return retval; 935 return retval;
934 *value = (sc_access.value) & mask; 936 *value = (sc_access.value) & mask;
935 pr_debug("sst: masked value = %d\n", *value); 937 pr_debug("masked value = %d\n", *value);
936 if (*value) 938 if (*value)
937 *value = 0; 939 *value = 0;
938 else 940 else
939 *value = 1; 941 *value = 1;
940 pr_debug("sst: value returned = 0x%x\n", *value); 942 pr_debug("value returned = 0x%x\n", *value);
941 return retval; 943 return retval;
942} 944}
943 945
@@ -953,19 +955,19 @@ static int nc_get_vol(int dev_id, int *value)
953 955
954 switch (dev_id) { 956 switch (dev_id) {
955 case PMIC_SND_CAPTURE_VOL: 957 case PMIC_SND_CAPTURE_VOL:
956 pr_debug("sst: PMIC_SND_INPUT_CAPTURE_VOL\n"); 958 pr_debug("PMIC_SND_INPUT_CAPTURE_VOL\n");
957 sc_access.reg_addr = LILSEL; 959 sc_access.reg_addr = LILSEL;
958 mask = (MASK0|MASK1|MASK2|MASK3|MASK4|MASK5); 960 mask = (MASK0|MASK1|MASK2|MASK3|MASK4|MASK5);
959 break; 961 break;
960 962
961 case PMIC_SND_RIGHT_PB_VOL: 963 case PMIC_SND_RIGHT_PB_VOL:
962 pr_debug("sst: GET_VOLUME_PMIC_LEFT_HP_VOL\n"); 964 pr_debug("GET_VOLUME_PMIC_LEFT_HP_VOL\n");
963 sc_access.reg_addr = AUDIOLVOL; 965 sc_access.reg_addr = AUDIOLVOL;
964 mask = (MASK0|MASK1|MASK2|MASK3|MASK4|MASK5|MASK6); 966 mask = (MASK0|MASK1|MASK2|MASK3|MASK4|MASK5|MASK6);
965 break; 967 break;
966 968
967 case PMIC_SND_LEFT_PB_VOL: 969 case PMIC_SND_LEFT_PB_VOL:
968 pr_debug("sst: GET_VOLUME_PMIC_RIGHT_HP_VOL\n"); 970 pr_debug("GET_VOLUME_PMIC_RIGHT_HP_VOL\n");
969 sc_access.reg_addr = AUDIORVOL; 971 sc_access.reg_addr = AUDIORVOL;
970 mask = (MASK0|MASK1|MASK2|MASK3|MASK4|MASK5|MASK6); 972 mask = (MASK0|MASK1|MASK2|MASK3|MASK4|MASK5|MASK6);
971 break; 973 break;
@@ -975,9 +977,9 @@ static int nc_get_vol(int dev_id, int *value)
975 977
976 } 978 }
977 retval = sst_sc_reg_access(&sc_access, PMIC_READ, 1); 979 retval = sst_sc_reg_access(&sc_access, PMIC_READ, 1);
978 pr_debug("sst: value read = 0x%x\n", sc_access.value); 980 pr_debug("value read = 0x%x\n", sc_access.value);
979 *value = -((sc_access.value) & mask); 981 *value = -((sc_access.value) & mask);
980 pr_debug("sst: get vol value returned = %d\n", *value); 982 pr_debug("get vol value returned = %d\n", *value);
981 return retval; 983 return retval;
982} 984}
983 985
diff --git a/drivers/staging/keucr/init.c b/drivers/staging/keucr/init.c
index 978bf87ff13d..515e448852a0 100644
--- a/drivers/staging/keucr/init.c
+++ b/drivers/staging/keucr/init.c
@@ -11,43 +11,37 @@
11#include "transport.h" 11#include "transport.h"
12#include "init.h" 12#include "init.h"
13 13
14BYTE IsSSFDCCompliance; 14BYTE IsSSFDCCompliance;
15BYTE IsXDCompliance; 15BYTE IsXDCompliance;
16extern DWORD MediaChange;
17extern int Check_D_MediaFmt(struct us_data *);
18 16
19//----- ENE_InitMedia() ---------------------------------------- 17/*
18 * ENE_InitMedia():
19 */
20int ENE_InitMedia(struct us_data *us) 20int ENE_InitMedia(struct us_data *us)
21{ 21{
22 int result; 22 int result;
23 BYTE MiscReg03 = 0; 23 BYTE MiscReg03 = 0;
24 24
25 printk("--- Init Media ---\n"); 25 printk(KERN_INFO "--- Init Media ---\n");
26 result = ENE_Read_BYTE(us, REG_CARD_STATUS, &MiscReg03); 26 result = ENE_Read_BYTE(us, REG_CARD_STATUS, &MiscReg03);
27 if (result != USB_STOR_XFER_GOOD) 27 if (result != USB_STOR_XFER_GOOD) {
28 { 28 printk(KERN_ERR "Read register fail !!\n");
29 printk("Read register fail !!\n");
30 return USB_STOR_TRANSPORT_ERROR; 29 return USB_STOR_TRANSPORT_ERROR;
31 } 30 }
32 printk("MiscReg03 = %x\n", MiscReg03); 31 printk(KERN_INFO "MiscReg03 = %x\n", MiscReg03);
33 32
34 if (MiscReg03 & 0x01) 33 if (MiscReg03 & 0x01) {
35 { 34 if (!us->SD_Status.Ready) {
36 if (!us->SD_Status.Ready)
37 {
38 result = ENE_SDInit(us); 35 result = ENE_SDInit(us);
39 if (result != USB_STOR_XFER_GOOD) 36 if (result != USB_STOR_XFER_GOOD)
40 return USB_STOR_TRANSPORT_ERROR; 37 return USB_STOR_TRANSPORT_ERROR;
41 } 38 }
42 } 39 }
43 40
44 if (MiscReg03 & 0x02) 41 if (MiscReg03 & 0x02) {
45 { 42 if (!us->SM_Status.Ready && !us->MS_Status.Ready) {
46 if (!us->SM_Status.Ready && !us->MS_Status.Ready)
47 {
48 result = ENE_SMInit(us); 43 result = ENE_SMInit(us);
49 if (result != USB_STOR_XFER_GOOD) 44 if (result != USB_STOR_XFER_GOOD) {
50 {
51 result = ENE_MSInit(us); 45 result = ENE_MSInit(us);
52 if (result != USB_STOR_XFER_GOOD) 46 if (result != USB_STOR_XFER_GOOD)
53 return USB_STOR_TRANSPORT_ERROR; 47 return USB_STOR_TRANSPORT_ERROR;
@@ -58,7 +52,9 @@ int ENE_InitMedia(struct us_data *us)
58 return result; 52 return result;
59} 53}
60 54
61//----- ENE_Read_BYTE() ---------------------------------------- 55/*
56 * ENE_Read_BYTE() :
57 */
62int ENE_Read_BYTE(struct us_data *us, WORD index, void *buf) 58int ENE_Read_BYTE(struct us_data *us, WORD index, void *buf)
63{ 59{
64 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 60 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
@@ -76,19 +72,20 @@ int ENE_Read_BYTE(struct us_data *us, WORD index, void *buf)
76 return result; 72 return result;
77} 73}
78 74
79//----- ENE_SDInit() --------------------- 75/*
76 * ENE_SDInit():
77 */
80int ENE_SDInit(struct us_data *us) 78int ENE_SDInit(struct us_data *us)
81{ 79{
82 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 80 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
83 int result; 81 int result;
84 BYTE buf[0x200]; 82 BYTE buf[0x200];
85 83
86 printk("transport --- ENE_SDInit\n"); 84 printk(KERN_INFO "transport --- ENE_SDInit\n");
87 // SD Init Part-1 85 /* SD Init Part-1 */
88 result = ENE_LoadBinCode(us, SD_INIT1_PATTERN); 86 result = ENE_LoadBinCode(us, SD_INIT1_PATTERN);
89 if (result != USB_STOR_XFER_GOOD) 87 if (result != USB_STOR_XFER_GOOD) {
90 { 88 printk(KERN_ERR "Load SD Init Code Part-1 Fail !!\n");
91 printk("Load SD Init Code Part-1 Fail !!\n");
92 return USB_STOR_TRANSPORT_ERROR; 89 return USB_STOR_TRANSPORT_ERROR;
93 } 90 }
94 91
@@ -98,17 +95,15 @@ int ENE_SDInit(struct us_data *us)
98 bcb->CDB[0] = 0xF2; 95 bcb->CDB[0] = 0xF2;
99 96
100 result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0); 97 result = ENE_SendScsiCmd(us, FDIR_READ, NULL, 0);
101 if (result != USB_STOR_XFER_GOOD) 98 if (result != USB_STOR_XFER_GOOD) {
102 { 99 printk(KERN_ERR "Exection SD Init Code Fail !!\n");
103 printk("Exection SD Init Code Fail !!\n");
104 return USB_STOR_TRANSPORT_ERROR; 100 return USB_STOR_TRANSPORT_ERROR;
105 } 101 }
106 102
107 // SD Init Part-2 103 /* SD Init Part-2 */
108 result = ENE_LoadBinCode(us, SD_INIT2_PATTERN); 104 result = ENE_LoadBinCode(us, SD_INIT2_PATTERN);
109 if (result != USB_STOR_XFER_GOOD) 105 if (result != USB_STOR_XFER_GOOD) {
110 { 106 printk(KERN_ERR "Load SD Init Code Part-2 Fail !!\n");
111 printk("Load SD Init Code Part-2 Fail !!\n");
112 return USB_STOR_TRANSPORT_ERROR; 107 return USB_STOR_TRANSPORT_ERROR;
113 } 108 }
114 109
@@ -119,45 +114,41 @@ int ENE_SDInit(struct us_data *us)
119 bcb->CDB[0] = 0xF1; 114 bcb->CDB[0] = 0xF1;
120 115
121 result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0); 116 result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0);
122 if (result != USB_STOR_XFER_GOOD) 117 if (result != USB_STOR_XFER_GOOD) {
123 { 118 printk(KERN_ERR "Exection SD Init Code Fail !!\n");
124 printk("Exection SD Init Code Fail !!\n");
125 return USB_STOR_TRANSPORT_ERROR; 119 return USB_STOR_TRANSPORT_ERROR;
126 } 120 }
127 121
128 us->SD_Status = *(PSD_STATUS)&buf[0]; 122 us->SD_Status = *(PSD_STATUS)&buf[0];
129 if (us->SD_Status.Insert && us->SD_Status.Ready) 123 if (us->SD_Status.Insert && us->SD_Status.Ready) {
130 {
131 ENE_ReadSDReg(us, (PBYTE)&buf); 124 ENE_ReadSDReg(us, (PBYTE)&buf);
132 printk("Insert = %x\n", us->SD_Status.Insert); 125 printk(KERN_INFO "Insert = %x\n", us->SD_Status.Insert);
133 printk("Ready = %x\n", us->SD_Status.Ready); 126 printk(KERN_INFO "Ready = %x\n", us->SD_Status.Ready);
134 printk("IsMMC = %x\n", us->SD_Status.IsMMC); 127 printk(KERN_INFO "IsMMC = %x\n", us->SD_Status.IsMMC);
135 printk("HiCapacity = %x\n", us->SD_Status.HiCapacity); 128 printk(KERN_INFO "HiCapacity = %x\n", us->SD_Status.HiCapacity);
136 printk("HiSpeed = %x\n", us->SD_Status.HiSpeed); 129 printk(KERN_INFO "HiSpeed = %x\n", us->SD_Status.HiSpeed);
137 printk("WtP = %x\n", us->SD_Status.WtP); 130 printk(KERN_INFO "WtP = %x\n", us->SD_Status.WtP);
138 } 131 } else {
139 else 132 printk(KERN_ERR "SD Card Not Ready --- %x\n", buf[0]);
140 {
141 printk("SD Card Not Ready --- %x\n", buf[0]);
142 return USB_STOR_TRANSPORT_ERROR; 133 return USB_STOR_TRANSPORT_ERROR;
143 } 134 }
144 return USB_STOR_TRANSPORT_GOOD; 135 return USB_STOR_TRANSPORT_GOOD;
145} 136}
146 137
147//----- ENE_MSInit() ---------------------------------------- 138/*
139 * ENE_MSInit():
140 */
148int ENE_MSInit(struct us_data *us) 141int ENE_MSInit(struct us_data *us)
149{ 142{
150 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 143 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
151 int result; 144 int result;
152 BYTE buf[0x200]; 145 BYTE buf[0x200];
153 WORD MSP_BlockSize, MSP_UserAreaBlocks; 146 WORD MSP_BlockSize, MSP_UserAreaBlocks;
154
155 147
156 printk("transport --- ENE_MSInit\n"); 148 printk(KERN_INFO "transport --- ENE_MSInit\n");
157 result = ENE_LoadBinCode(us, MS_INIT_PATTERN); 149 result = ENE_LoadBinCode(us, MS_INIT_PATTERN);
158 if (result != USB_STOR_XFER_GOOD) 150 if (result != USB_STOR_XFER_GOOD) {
159 { 151 printk(KERN_ERR "Load MS Init Code Fail !!\n");
160 printk("Load MS Init Code Fail !!\n");
161 return USB_STOR_TRANSPORT_ERROR; 152 return USB_STOR_TRANSPORT_ERROR;
162 } 153 }
163 154
@@ -169,53 +160,49 @@ int ENE_MSInit(struct us_data *us)
169 bcb->CDB[1] = 0x01; 160 bcb->CDB[1] = 0x01;
170 161
171 result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0); 162 result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0);
172 if (result != USB_STOR_XFER_GOOD) 163 if (result != USB_STOR_XFER_GOOD) {
173 { 164 printk(KERN_ERR "Exection MS Init Code Fail !!\n");
174 printk("Exection MS Init Code Fail !!\n");
175 return USB_STOR_TRANSPORT_ERROR; 165 return USB_STOR_TRANSPORT_ERROR;
176 } 166 }
177 167
178 us->MS_Status = *(PMS_STATUS)&buf[0]; 168 us->MS_Status = *(PMS_STATUS)&buf[0];
179 169
180 if (us->MS_Status.Insert && us->MS_Status.Ready) 170 if (us->MS_Status.Insert && us->MS_Status.Ready) {
181 { 171 printk(KERN_INFO "Insert = %x\n", us->MS_Status.Insert);
182 printk("Insert = %x\n", us->MS_Status.Insert); 172 printk(KERN_INFO "Ready = %x\n", us->MS_Status.Ready);
183 printk("Ready = %x\n", us->MS_Status.Ready); 173 printk(KERN_INFO "IsMSPro = %x\n", us->MS_Status.IsMSPro);
184 printk("IsMSPro = %x\n", us->MS_Status.IsMSPro); 174 printk(KERN_INFO "IsMSPHG = %x\n", us->MS_Status.IsMSPHG);
185 printk("IsMSPHG = %x\n", us->MS_Status.IsMSPHG); 175 printk(KERN_INFO "WtP = %x\n", us->MS_Status.WtP);
186 printk("WtP = %x\n", us->MS_Status.WtP); 176 if (us->MS_Status.IsMSPro) {
187 if (us->MS_Status.IsMSPro) 177 MSP_BlockSize = (buf[6] << 8) | buf[7];
188 { 178 MSP_UserAreaBlocks = (buf[10] << 8) | buf[11];
189 MSP_BlockSize = (buf[6] <<8) | buf[7];
190 MSP_UserAreaBlocks = (buf[10]<<8) | buf[11];
191 us->MSP_TotalBlock = MSP_BlockSize * MSP_UserAreaBlocks; 179 us->MSP_TotalBlock = MSP_BlockSize * MSP_UserAreaBlocks;
192 } 180 } else {
193 else
194 MS_CardInit(us); 181 MS_CardInit(us);
195 printk("MS Init Code OK !!\n"); 182 }
196 } 183 printk(KERN_INFO "MS Init Code OK !!\n");
197 else 184 } else {
198 { 185 printk(KERN_INFO "MS Card Not Ready --- %x\n", buf[0]);
199 printk("MS Card Not Ready --- %x\n", buf[0]);
200 return USB_STOR_TRANSPORT_ERROR; 186 return USB_STOR_TRANSPORT_ERROR;
201 } 187 }
202 188
203 return USB_STOR_TRANSPORT_GOOD; 189 return USB_STOR_TRANSPORT_GOOD;
204} 190}
205 191
206//----- ENE_SMInit() ---------------------------------------- 192/*
193 *ENE_SMInit()
194 */
207int ENE_SMInit(struct us_data *us) 195int ENE_SMInit(struct us_data *us)
208{ 196{
209 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 197 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
210 int result; 198 int result;
211 BYTE buf[0x200]; 199 BYTE buf[0x200];
212 200
213 printk("transport --- ENE_SMInit\n"); 201 printk(KERN_INFO "transport --- ENE_SMInit\n");
214 202
215 result = ENE_LoadBinCode(us, SM_INIT_PATTERN); 203 result = ENE_LoadBinCode(us, SM_INIT_PATTERN);
216 if (result != USB_STOR_XFER_GOOD) 204 if (result != USB_STOR_XFER_GOOD) {
217 { 205 printk(KERN_INFO "Load SM Init Code Fail !!\n");
218 printk("Load SM Init Code Fail !!\n");
219 return USB_STOR_TRANSPORT_ERROR; 206 return USB_STOR_TRANSPORT_ERROR;
220 } 207 }
221 208
@@ -227,9 +214,9 @@ int ENE_SMInit(struct us_data *us)
227 bcb->CDB[1] = 0x01; 214 bcb->CDB[1] = 0x01;
228 215
229 result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0); 216 result = ENE_SendScsiCmd(us, FDIR_READ, &buf, 0);
230 if (result != USB_STOR_XFER_GOOD) 217 if (result != USB_STOR_XFER_GOOD) {
231 { 218 printk(KERN_ERR
232 printk("Exection SM Init Code Fail !! result = %x\n", result); 219 "Exection SM Init Code Fail !! result = %x\n", result);
233 return USB_STOR_TRANSPORT_ERROR; 220 return USB_STOR_TRANSPORT_ERROR;
234 } 221 }
235 222
@@ -238,32 +225,31 @@ int ENE_SMInit(struct us_data *us)
238 us->SM_DeviceID = buf[1]; 225 us->SM_DeviceID = buf[1];
239 us->SM_CardID = buf[2]; 226 us->SM_CardID = buf[2];
240 227
241 if (us->SM_Status.Insert && us->SM_Status.Ready) 228 if (us->SM_Status.Insert && us->SM_Status.Ready) {
242 { 229 printk(KERN_INFO "Insert = %x\n", us->SM_Status.Insert);
243 printk("Insert = %x\n", us->SM_Status.Insert); 230 printk(KERN_INFO "Ready = %x\n", us->SM_Status.Ready);
244 printk("Ready = %x\n", us->SM_Status.Ready); 231 printk(KERN_INFO "WtP = %x\n", us->SM_Status.WtP);
245 printk("WtP = %x\n", us->SM_Status.WtP); 232 printk(KERN_INFO "DeviceID = %x\n", us->SM_DeviceID);
246 printk("DeviceID = %x\n", us->SM_DeviceID); 233 printk(KERN_INFO "CardID = %x\n", us->SM_CardID);
247 printk("CardID = %x\n", us->SM_CardID);
248 MediaChange = 1; 234 MediaChange = 1;
249 Check_D_MediaFmt(us); 235 Check_D_MediaFmt(us);
250 } 236 } else {
251 else 237 printk(KERN_ERR "SM Card Not Ready --- %x\n", buf[0]);
252 {
253 printk("SM Card Not Ready --- %x\n", buf[0]);
254 return USB_STOR_TRANSPORT_ERROR; 238 return USB_STOR_TRANSPORT_ERROR;
255 } 239 }
256 240
257 return USB_STOR_TRANSPORT_GOOD; 241 return USB_STOR_TRANSPORT_GOOD;
258} 242}
259 243
260//----- ENE_ReadSDReg() ---------------------------------------------- 244/*
245 * ENE_ReadSDReg()
246 */
261int ENE_ReadSDReg(struct us_data *us, u8 *RdBuf) 247int ENE_ReadSDReg(struct us_data *us, u8 *RdBuf)
262{ 248{
263 WORD tmpreg; 249 WORD tmpreg;
264 DWORD reg4b; 250 DWORD reg4b;
265 251
266 //printk("transport --- ENE_ReadSDReg\n"); 252 /* printk(KERN_INFO "transport --- ENE_ReadSDReg\n"); */
267 reg4b = *(PDWORD)&RdBuf[0x18]; 253 reg4b = *(PDWORD)&RdBuf[0x18];
268 us->SD_READ_BL_LEN = (BYTE)((reg4b >> 8) & 0x0f); 254 us->SD_READ_BL_LEN = (BYTE)((reg4b >> 8) & 0x0f);
269 255
@@ -277,74 +263,75 @@ int ENE_ReadSDReg(struct us_data *us, u8 *RdBuf)
277 if (us->SD_Status.HiCapacity && us->SD_Status.IsMMC) 263 if (us->SD_Status.HiCapacity && us->SD_Status.IsMMC)
278 us->HC_C_SIZE = *(PDWORD)(&RdBuf[0x100]); 264 us->HC_C_SIZE = *(PDWORD)(&RdBuf[0x100]);
279 265
280 if (us->SD_READ_BL_LEN > SD_BLOCK_LEN) 266 if (us->SD_READ_BL_LEN > SD_BLOCK_LEN) {
281 { 267 us->SD_Block_Mult =
282 us->SD_Block_Mult = 1 << (us->SD_READ_BL_LEN - SD_BLOCK_LEN); us->SD_READ_BL_LEN = SD_BLOCK_LEN; 268 1 << (us->SD_READ_BL_LEN - SD_BLOCK_LEN);
283 } 269 us->SD_READ_BL_LEN = SD_BLOCK_LEN;
284 else 270 } else {
285 { us->SD_Block_Mult = 1; 271 us->SD_Block_Mult = 1;
286 } 272 }
287 return USB_STOR_TRANSPORT_GOOD; 273 return USB_STOR_TRANSPORT_GOOD;
288} 274}
289 275
290//----- ENE_LoadBinCode() --------------------- 276/*
277 * ENE_LoadBinCode()
278 */
291int ENE_LoadBinCode(struct us_data *us, BYTE flag) 279int ENE_LoadBinCode(struct us_data *us, BYTE flag)
292{ 280{
293 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 281 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
294 int result; 282 int result;
295 //void *buf; 283 /* void *buf; */
296 PBYTE buf; 284 PBYTE buf;
297 285
298 //printk("transport --- ENE_LoadBinCode\n"); 286 /* printk(KERN_INFO "transport --- ENE_LoadBinCode\n"); */
299 if (us->BIN_FLAG == flag) 287 if (us->BIN_FLAG == flag)
300 return USB_STOR_TRANSPORT_GOOD; 288 return USB_STOR_TRANSPORT_GOOD;
301 289
302 buf = kmalloc(0x800, GFP_KERNEL); 290 buf = kmalloc(0x800, GFP_KERNEL);
303 if (buf == NULL) 291 if (buf == NULL)
304 return USB_STOR_TRANSPORT_ERROR; 292 return USB_STOR_TRANSPORT_ERROR;
305 switch ( flag ) 293 switch (flag) {
306 { 294 /* For SD */
307 // For SD 295 case SD_INIT1_PATTERN:
308 case SD_INIT1_PATTERN: 296 printk(KERN_INFO "SD_INIT1_PATTERN\n");
309 printk("SD_INIT1_PATTERN\n"); 297 memcpy(buf, SD_Init1, 0x800);
310 memcpy(buf, SD_Init1, 0x800);
311 break; 298 break;
312 case SD_INIT2_PATTERN: 299 case SD_INIT2_PATTERN:
313 printk("SD_INIT2_PATTERN\n"); 300 printk(KERN_INFO "SD_INIT2_PATTERN\n");
314 memcpy(buf, SD_Init2, 0x800); 301 memcpy(buf, SD_Init2, 0x800);
315 break; 302 break;
316 case SD_RW_PATTERN: 303 case SD_RW_PATTERN:
317 printk("SD_RW_PATTERN\n"); 304 printk(KERN_INFO "SD_RW_PATTERN\n");
318 memcpy(buf, SD_Rdwr, 0x800); 305 memcpy(buf, SD_Rdwr, 0x800);
319 break; 306 break;
320 // For MS 307 /* For MS */
321 case MS_INIT_PATTERN: 308 case MS_INIT_PATTERN:
322 printk("MS_INIT_PATTERN\n"); 309 printk(KERN_INFO "MS_INIT_PATTERN\n");
323 memcpy(buf, MS_Init, 0x800); 310 memcpy(buf, MS_Init, 0x800);
324 break; 311 break;
325 case MSP_RW_PATTERN: 312 case MSP_RW_PATTERN:
326 printk("MSP_RW_PATTERN\n"); 313 printk(KERN_INFO "MSP_RW_PATTERN\n");
327 memcpy(buf, MSP_Rdwr, 0x800); 314 memcpy(buf, MSP_Rdwr, 0x800);
328 break; 315 break;
329 case MS_RW_PATTERN: 316 case MS_RW_PATTERN:
330 printk("MS_RW_PATTERN\n"); 317 printk(KERN_INFO "MS_RW_PATTERN\n");
331 memcpy(buf, MS_Rdwr, 0x800); 318 memcpy(buf, MS_Rdwr, 0x800);
332 break; 319 break;
333 // For SS 320 /* For SS */
334 case SM_INIT_PATTERN: 321 case SM_INIT_PATTERN:
335 printk("SM_INIT_PATTERN\n"); 322 printk(KERN_INFO "SM_INIT_PATTERN\n");
336 memcpy(buf, SM_Init, 0x800); 323 memcpy(buf, SM_Init, 0x800);
337 break; 324 break;
338 case SM_RW_PATTERN: 325 case SM_RW_PATTERN:
339 printk("SM_RW_PATTERN\n"); 326 printk(KERN_INFO "SM_RW_PATTERN\n");
340 memcpy(buf, SM_Rdwr, 0x800); 327 memcpy(buf, SM_Rdwr, 0x800);
341 break; 328 break;
342 } 329 }
343 330
344 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 331 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
345 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 332 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
346 bcb->DataTransferLength = 0x800; 333 bcb->DataTransferLength = 0x800;
347 bcb->Flags =0x00; 334 bcb->Flags = 0x00;
348 bcb->CDB[0] = 0xEF; 335 bcb->CDB[0] = 0xEF;
349 336
350 result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); 337 result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0);
@@ -354,54 +341,63 @@ int ENE_LoadBinCode(struct us_data *us, BYTE flag)
354 return result; 341 return result;
355} 342}
356 343
357//----- ENE_SendScsiCmd() --------------------- 344/*
345 * ENE_SendScsiCmd():
346 */
358int ENE_SendScsiCmd(struct us_data *us, BYTE fDir, void *buf, int use_sg) 347int ENE_SendScsiCmd(struct us_data *us, BYTE fDir, void *buf, int use_sg)
359{ 348{
360 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 349 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
361 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; 350 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
362 351
363 int result; 352 int result;
364 unsigned int transfer_length=bcb->DataTransferLength, cswlen=0, partial=0; 353 unsigned int transfer_length = bcb->DataTransferLength,
354 cswlen = 0, partial = 0;
365 unsigned int residue; 355 unsigned int residue;
366 356
367 //printk("transport --- ENE_SendScsiCmd\n"); 357 /* printk(KERN_INFO "transport --- ENE_SendScsiCmd\n"); */
368 // send cmd to out endpoint 358 /* send cmd to out endpoint */
369 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, US_BULK_CB_WRAP_LEN, NULL); 359 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
370 if (result != USB_STOR_XFER_GOOD) 360 bcb, US_BULK_CB_WRAP_LEN, NULL);
371 { 361 if (result != USB_STOR_XFER_GOOD) {
372 printk("send cmd to out endpoint fail ---\n"); 362 printk(KERN_ERR "send cmd to out endpoint fail ---\n");
373 return USB_STOR_TRANSPORT_ERROR; 363 return USB_STOR_TRANSPORT_ERROR;
374 } 364 }
375 365
376 if (buf) 366 if (buf) {
377 { 367 unsigned int pipe = fDir;
378 unsigned int pipe = fDir == FDIR_READ ? us->recv_bulk_pipe : us->send_bulk_pipe; 368
379 // Bulk 369 if (fDir == FDIR_READ)
370 pipe = us->recv_bulk_pipe;
371 else
372 pipe = us->send_bulk_pipe;
373
374 /* Bulk */
380 if (use_sg) 375 if (use_sg)
381 result = usb_stor_bulk_srb(us, pipe, us->srb); 376 result = usb_stor_bulk_srb(us, pipe, us->srb);
382 else 377 else
383 result = usb_stor_bulk_transfer_sg(us, pipe, buf, transfer_length, 0, &partial); 378 result = usb_stor_bulk_transfer_sg(us, pipe, buf,
384 if (result != USB_STOR_XFER_GOOD) 379 transfer_length, 0, &partial);
385 { 380 if (result != USB_STOR_XFER_GOOD) {
386 printk("data transfer fail ---\n"); 381 printk(KERN_ERR "data transfer fail ---\n");
387 return USB_STOR_TRANSPORT_ERROR; 382 return USB_STOR_TRANSPORT_ERROR;
388 } 383 }
389 } 384 }
390 385
391 // Get CSW for device status 386 /* Get CSW for device status */
392 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, &cswlen); 387 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
388 US_BULK_CS_WRAP_LEN, &cswlen);
393 389
394 if (result == USB_STOR_XFER_SHORT && cswlen == 0) 390 if (result == USB_STOR_XFER_SHORT && cswlen == 0) {
395 { 391 printk(KERN_WARNING "Received 0-length CSW; retrying...\n");
396 printk("Received 0-length CSW; retrying...\n"); 392 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
397 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, &cswlen); 393 bcs, US_BULK_CS_WRAP_LEN, &cswlen);
398 } 394 }
399 395
400 if (result == USB_STOR_XFER_STALLED) 396 if (result == USB_STOR_XFER_STALLED) {
401 {
402 /* get the status again */ 397 /* get the status again */
403 printk("Attempting to get CSW (2nd try)...\n"); 398 printk(KERN_WARNING "Attempting to get CSW (2nd try)...\n");
404 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, NULL); 399 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
400 bcs, US_BULK_CS_WRAP_LEN, NULL);
405 } 401 }
406 402
407 if (result != USB_STOR_XFER_GOOD) 403 if (result != USB_STOR_XFER_GOOD)
@@ -410,12 +406,14 @@ int ENE_SendScsiCmd(struct us_data *us, BYTE fDir, void *buf, int use_sg)
410 /* check bulk status */ 406 /* check bulk status */
411 residue = le32_to_cpu(bcs->Residue); 407 residue = le32_to_cpu(bcs->Residue);
412 408
413 /* try to compute the actual residue, based on how much data 409 /*
414 * was really transferred and what the device tells us */ 410 * try to compute the actual residue, based on how much data
415 if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) 411 * was really transferred and what the device tells us
416 { 412 */
413 if (residue && !(us->fflags & US_FL_IGNORE_RESIDUE)) {
417 residue = min(residue, transfer_length); 414 residue = min(residue, transfer_length);
418 scsi_set_resid(us->srb, max(scsi_get_resid(us->srb), (int) residue)); 415 scsi_set_resid(us->srb, max(scsi_get_resid(us->srb),
416 (int) residue));
419 } 417 }
420 418
421 if (bcs->Status != US_BULK_STAT_OK) 419 if (bcs->Status != US_BULK_STAT_OK)
@@ -424,35 +422,40 @@ int ENE_SendScsiCmd(struct us_data *us, BYTE fDir, void *buf, int use_sg)
424 return USB_STOR_TRANSPORT_GOOD; 422 return USB_STOR_TRANSPORT_GOOD;
425} 423}
426 424
427//----- ENE_Read_Data() --------------------- 425/*
426 * ENE_Read_Data()
427 */
428int ENE_Read_Data(struct us_data *us, void *buf, unsigned int length) 428int ENE_Read_Data(struct us_data *us, void *buf, unsigned int length)
429{ 429{
430 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 430 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
431 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; 431 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
432 int result; 432 int result;
433 433
434 //printk("transport --- ENE_Read_Data\n"); 434 /* printk(KERN_INFO "transport --- ENE_Read_Data\n"); */
435 // set up the command wrapper 435 /* set up the command wrapper */
436 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 436 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
437 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 437 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
438 bcb->DataTransferLength = length; 438 bcb->DataTransferLength = length;
439 bcb->Flags =0x80; 439 bcb->Flags = 0x80;
440 bcb->CDB[0] = 0xED; 440 bcb->CDB[0] = 0xED;
441 bcb->CDB[2] = 0xFF; 441 bcb->CDB[2] = 0xFF;
442 bcb->CDB[3] = 0x81; 442 bcb->CDB[3] = 0x81;
443 443
444 // send cmd to out endpoint 444 /* send cmd to out endpoint */
445 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, US_BULK_CB_WRAP_LEN, NULL); 445 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb,
446 US_BULK_CB_WRAP_LEN, NULL);
446 if (result != USB_STOR_XFER_GOOD) 447 if (result != USB_STOR_XFER_GOOD)
447 return USB_STOR_TRANSPORT_ERROR; 448 return USB_STOR_TRANSPORT_ERROR;
448 449
449 // R/W data 450 /* R/W data */
450 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, buf, length, NULL); 451 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
452 buf, length, NULL);
451 if (result != USB_STOR_XFER_GOOD) 453 if (result != USB_STOR_XFER_GOOD)
452 return USB_STOR_TRANSPORT_ERROR; 454 return USB_STOR_TRANSPORT_ERROR;
453 455
454 // Get CSW for device status 456 /* Get CSW for device status */
455 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, NULL); 457 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
458 US_BULK_CS_WRAP_LEN, NULL);
456 if (result != USB_STOR_XFER_GOOD) 459 if (result != USB_STOR_XFER_GOOD)
457 return USB_STOR_TRANSPORT_ERROR; 460 return USB_STOR_TRANSPORT_ERROR;
458 if (bcs->Status != US_BULK_STAT_OK) 461 if (bcs->Status != US_BULK_STAT_OK)
@@ -461,35 +464,40 @@ int ENE_Read_Data(struct us_data *us, void *buf, unsigned int length)
461 return USB_STOR_TRANSPORT_GOOD; 464 return USB_STOR_TRANSPORT_GOOD;
462} 465}
463 466
464//----- ENE_Write_Data() --------------------- 467/*
468 * ENE_Write_Data():
469 */
465int ENE_Write_Data(struct us_data *us, void *buf, unsigned int length) 470int ENE_Write_Data(struct us_data *us, void *buf, unsigned int length)
466{ 471{
467 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 472 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
468 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf; 473 struct bulk_cs_wrap *bcs = (struct bulk_cs_wrap *) us->iobuf;
469 int result; 474 int result;
470 475
471 //printk("transport --- ENE_Write_Data\n"); 476 /* printk("transport --- ENE_Write_Data\n"); */
472 // set up the command wrapper 477 /* set up the command wrapper */
473 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 478 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
474 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 479 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
475 bcb->DataTransferLength = length; 480 bcb->DataTransferLength = length;
476 bcb->Flags =0x00; 481 bcb->Flags = 0x00;
477 bcb->CDB[0] = 0xEE; 482 bcb->CDB[0] = 0xEE;
478 bcb->CDB[2] = 0xFF; 483 bcb->CDB[2] = 0xFF;
479 bcb->CDB[3] = 0x81; 484 bcb->CDB[3] = 0x81;
480 485
481 // send cmd to out endpoint 486 /* send cmd to out endpoint */
482 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, US_BULK_CB_WRAP_LEN, NULL); 487 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb,
488 US_BULK_CB_WRAP_LEN, NULL);
483 if (result != USB_STOR_XFER_GOOD) 489 if (result != USB_STOR_XFER_GOOD)
484 return USB_STOR_TRANSPORT_ERROR; 490 return USB_STOR_TRANSPORT_ERROR;
485 491
486 // R/W data 492 /* R/W data */
487 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, buf, length, NULL); 493 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
494 buf, length, NULL);
488 if (result != USB_STOR_XFER_GOOD) 495 if (result != USB_STOR_XFER_GOOD)
489 return USB_STOR_TRANSPORT_ERROR; 496 return USB_STOR_TRANSPORT_ERROR;
490 497
491 // Get CSW for device status 498 /* Get CSW for device status */
492 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, NULL); 499 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
500 US_BULK_CS_WRAP_LEN, NULL);
493 if (result != USB_STOR_XFER_GOOD) 501 if (result != USB_STOR_XFER_GOOD)
494 return USB_STOR_TRANSPORT_ERROR; 502 return USB_STOR_TRANSPORT_ERROR;
495 if (bcs->Status != US_BULK_STAT_OK) 503 if (bcs->Status != US_BULK_STAT_OK)
@@ -498,42 +506,52 @@ int ENE_Write_Data(struct us_data *us, void *buf, unsigned int length)
498 return USB_STOR_TRANSPORT_GOOD; 506 return USB_STOR_TRANSPORT_GOOD;
499} 507}
500 508
501//----- usb_stor_print_cmd() --------------------- 509/*
510 * usb_stor_print_cmd():
511 */
502void usb_stor_print_cmd(struct scsi_cmnd *srb) 512void usb_stor_print_cmd(struct scsi_cmnd *srb)
503{ 513{
504 PBYTE Cdb = srb->cmnd; 514 PBYTE Cdb = srb->cmnd;
505 DWORD cmd = Cdb[0]; 515 DWORD cmd = Cdb[0];
506 DWORD bn = ((Cdb[2]<<24) & 0xff000000) | ((Cdb[3]<<16) & 0x00ff0000) | 516 DWORD bn = ((Cdb[2] << 24) & 0xff000000) |
507 ((Cdb[4]<< 8) & 0x0000ff00) | ((Cdb[5]<< 0) & 0x000000ff); 517 ((Cdb[3] << 16) & 0x00ff0000) |
508 WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff); 518 ((Cdb[4] << 8) & 0x0000ff00) |
519 ((Cdb[5] << 0) & 0x000000ff);
520 WORD blen = ((Cdb[7] << 8) & 0xff00) | ((Cdb[8] << 0) & 0x00ff);
509 521
510 switch (cmd) { 522 switch (cmd) {
511 case TEST_UNIT_READY: 523 case TEST_UNIT_READY:
512 //printk("scsi cmd %X --- SCSIOP_TEST_UNIT_READY\n", cmd); 524 /* printk(KERN_INFO
525 "scsi cmd %X --- SCSIOP_TEST_UNIT_READY\n", cmd); */
513 break; 526 break;
514 case INQUIRY: 527 case INQUIRY:
515 printk("scsi cmd %X --- SCSIOP_INQUIRY\n", cmd); 528 printk(KERN_INFO "scsi cmd %X --- SCSIOP_INQUIRY\n", cmd);
516 break; 529 break;
517 case MODE_SENSE: 530 case MODE_SENSE:
518 printk("scsi cmd %X --- SCSIOP_MODE_SENSE\n", cmd); 531 printk(KERN_INFO "scsi cmd %X --- SCSIOP_MODE_SENSE\n", cmd);
519 break; 532 break;
520 case START_STOP: 533 case START_STOP:
521 printk("scsi cmd %X --- SCSIOP_START_STOP\n", cmd); 534 printk(KERN_INFO "scsi cmd %X --- SCSIOP_START_STOP\n", cmd);
522 break; 535 break;
523 case READ_CAPACITY: 536 case READ_CAPACITY:
524 printk("scsi cmd %X --- SCSIOP_READ_CAPACITY\n", cmd); 537 printk(KERN_INFO "scsi cmd %X --- SCSIOP_READ_CAPACITY\n", cmd);
525 break; 538 break;
526 case READ_10: 539 case READ_10:
527 //printk("scsi cmd %X --- SCSIOP_READ, bn = %X, blen = %X\n", cmd, bn, blen); 540 /* printk(KERN_INFO
541 "scsi cmd %X --- SCSIOP_READ,bn = %X, blen = %X\n"
542 ,cmd, bn, blen); */
528 break; 543 break;
529 case WRITE_10: 544 case WRITE_10:
530 //printk("scsi cmd %X --- SCSIOP_WRITE, bn = %X, blen = %X\n", cmd, bn, blen); 545 /* printk(KERN_INFO
546 "scsi cmd %X --- SCSIOP_WRITE,
547 bn = %X, blen = %X\n" , cmd, bn, blen); */
531 break; 548 break;
532 case ALLOW_MEDIUM_REMOVAL: 549 case ALLOW_MEDIUM_REMOVAL:
533 printk("scsi cmd %X --- SCSIOP_ALLOW_MEDIUM_REMOVAL\n", cmd); 550 printk(KERN_INFO
551 "scsi cmd %X --- SCSIOP_ALLOW_MEDIUM_REMOVAL\n", cmd);
534 break; 552 break;
535 default: 553 default:
536 printk("scsi cmd %X --- Other cmd\n", cmd); 554 printk(KERN_INFO "scsi cmd %X --- Other cmd\n", cmd);
537 break; 555 break;
538 } 556 }
539 bn = 0; 557 bn = 0;
diff --git a/drivers/staging/keucr/init.h b/drivers/staging/keucr/init.h
index cd199fc1e6d5..5223132a6c24 100644
--- a/drivers/staging/keucr/init.h
+++ b/drivers/staging/keucr/init.h
@@ -1,5 +1,8 @@
1#include "common.h" 1#include "common.h"
2 2
3extern DWORD MediaChange;
4extern int Check_D_MediaFmt(struct us_data *);
5
3BYTE SD_Init1[] = { 6BYTE SD_Init1[] = {
40x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90, 70x90, 0xFF, 0x09, 0xE0, 0x30, 0xE1, 0x06, 0x90,
50xFF, 0x23, 0x74, 0x80, 0xF0, 0x90, 0xFF, 0x09, 80xFF, 0x23, 0x74, 0x80, 0xF0, 0x90, 0xFF, 0x09,
diff --git a/drivers/staging/keucr/ms.c b/drivers/staging/keucr/ms.c
index 9a3fdb4e4fe4..452ea8f54f67 100644
--- a/drivers/staging/keucr/ms.c
+++ b/drivers/staging/keucr/ms.c
@@ -347,7 +347,7 @@ int MS_LibProcessBootBlock(struct us_data *us, WORD PhyBlock, BYTE *PageData)
347 BYTE *PageBuffer; 347 BYTE *PageBuffer;
348 MS_LibTypeExtdat ExtraData; 348 MS_LibTypeExtdat ExtraData;
349 349
350 if ((PageBuffer = (BYTE *)kmalloc(MS_BYTES_PER_PAGE, GFP_KERNEL))==NULL) 350 if ((PageBuffer = kmalloc(MS_BYTES_PER_PAGE, GFP_KERNEL))==NULL)
351 return (DWORD)-1; 351 return (DWORD)-1;
352 352
353 result = (DWORD)-1; 353 result = (DWORD)-1;
@@ -480,8 +480,8 @@ int MS_LibAllocLogicalMap(struct us_data *us)
480 DWORD i; 480 DWORD i;
481 481
482 482
483 us->MS_Lib.Phy2LogMap = (WORD *)kmalloc(us->MS_Lib.NumberOfPhyBlock * sizeof(WORD), GFP_KERNEL); 483 us->MS_Lib.Phy2LogMap = kmalloc(us->MS_Lib.NumberOfPhyBlock * sizeof(WORD), GFP_KERNEL);
484 us->MS_Lib.Log2PhyMap = (WORD *)kmalloc(us->MS_Lib.NumberOfLogBlock * sizeof(WORD), GFP_KERNEL); 484 us->MS_Lib.Log2PhyMap = kmalloc(us->MS_Lib.NumberOfLogBlock * sizeof(WORD), GFP_KERNEL);
485 485
486 if ((us->MS_Lib.Phy2LogMap == NULL) || (us->MS_Lib.Log2PhyMap == NULL)) 486 if ((us->MS_Lib.Phy2LogMap == NULL) || (us->MS_Lib.Log2PhyMap == NULL))
487 { 487 {
@@ -610,8 +610,8 @@ int MS_LibAllocWriteBuf(struct us_data *us)
610{ 610{
611 us->MS_Lib.wrtblk = (WORD)-1; 611 us->MS_Lib.wrtblk = (WORD)-1;
612 612
613 us->MS_Lib.blkpag = (BYTE *)kmalloc(us->MS_Lib.PagesPerBlock * us->MS_Lib.BytesPerSector, GFP_KERNEL); 613 us->MS_Lib.blkpag = kmalloc(us->MS_Lib.PagesPerBlock * us->MS_Lib.BytesPerSector, GFP_KERNEL);
614 us->MS_Lib.blkext = (MS_LibTypeExtdat *)kmalloc(us->MS_Lib.PagesPerBlock * sizeof(MS_LibTypeExtdat), GFP_KERNEL); 614 us->MS_Lib.blkext = kmalloc(us->MS_Lib.PagesPerBlock * sizeof(MS_LibTypeExtdat), GFP_KERNEL);
615 615
616 if ((us->MS_Lib.blkpag == NULL) || (us->MS_Lib.blkext == NULL)) 616 if ((us->MS_Lib.blkpag == NULL) || (us->MS_Lib.blkext == NULL))
617 { 617 {
diff --git a/drivers/staging/keucr/smilmain.c b/drivers/staging/keucr/smilmain.c
index bdfbf76f8df9..2cbe9f897eef 100644
--- a/drivers/staging/keucr/smilmain.c
+++ b/drivers/staging/keucr/smilmain.c
@@ -153,9 +153,9 @@ int Media_D_ReadSector(struct us_data *us, DWORD start,WORD count,BYTE *buf)
153 WORD len, bn; 153 WORD len, bn;
154 154
155 //if (Check_D_MediaPower()) ; ¦b 6250 don't care 155 //if (Check_D_MediaPower()) ; ¦b 6250 don't care
156 // return(ErrCode); ; 156 // return(ErrCode);
157 //if (Check_D_MediaFmt(fdoExt)) ; 157 //if (Check_D_MediaFmt(fdoExt)) ;
158 // return(ErrCode); ; 158 // return(ErrCode);
159 if (Conv_D_MediaAddr(us, start)) 159 if (Conv_D_MediaAddr(us, start))
160 return(ErrCode); 160 return(ErrCode);
161 161
diff --git a/drivers/staging/keucr/smilsub.c b/drivers/staging/keucr/smilsub.c
index 1b52535a388f..ce10cf215f51 100644
--- a/drivers/staging/keucr/smilsub.c
+++ b/drivers/staging/keucr/smilsub.c
@@ -763,8 +763,8 @@ int Ssfdc_D_WriteSectForCopy(struct us_data *us, BYTE *buf, BYTE *redundant)
763 bcb->CDB[7] = (BYTE)addr; 763 bcb->CDB[7] = (BYTE)addr;
764 bcb->CDB[6] = (BYTE)(addr/0x0100); 764 bcb->CDB[6] = (BYTE)(addr/0x0100);
765 bcb->CDB[5] = Media.Zone/2; 765 bcb->CDB[5] = Media.Zone/2;
766 bcb->CDB[8] = *(redundant+REDT_ADDR1H);; 766 bcb->CDB[8] = *(redundant+REDT_ADDR1H);
767 bcb->CDB[9] = *(redundant+REDT_ADDR1L);; 767 bcb->CDB[9] = *(redundant+REDT_ADDR1L);
768 768
769 result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0); 769 result = ENE_SendScsiCmd(us, FDIR_WRITE, buf, 0);
770 if (result != USB_STOR_XFER_GOOD) 770 if (result != USB_STOR_XFER_GOOD)
diff --git a/drivers/staging/line6/capture.c b/drivers/staging/line6/capture.c
index 1e3bb1406331..9647154a4923 100644
--- a/drivers/staging/line6/capture.c
+++ b/drivers/staging/line6/capture.c
@@ -147,7 +147,7 @@ void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, int fsize)
147 const int bytes_per_frame = line6pcm->properties->bytes_per_frame; 147 const int bytes_per_frame = line6pcm->properties->bytes_per_frame;
148 int frames = fsize / bytes_per_frame; 148 int frames = fsize / bytes_per_frame;
149 149
150 if (runtime == 0) 150 if (runtime == NULL)
151 return; 151 return;
152 152
153 if (line6pcm->pos_in_done + frames > runtime->buffer_size) { 153 if (line6pcm->pos_in_done + frames > runtime->buffer_size) {
diff --git a/drivers/staging/line6/midi.c b/drivers/staging/line6/midi.c
index ab67e889d2c4..e554a2da643a 100644
--- a/drivers/staging/line6/midi.c
+++ b/drivers/staging/line6/midi.c
@@ -127,7 +127,7 @@ static int send_midi_async(struct usb_line6 *line6, unsigned char *data,
127 127
128 urb = usb_alloc_urb(0, GFP_ATOMIC); 128 urb = usb_alloc_urb(0, GFP_ATOMIC);
129 129
130 if (urb == 0) { 130 if (urb == NULL) {
131 dev_err(line6->ifcdev, "Out of memory\n"); 131 dev_err(line6->ifcdev, "Out of memory\n");
132 return -ENOMEM; 132 return -ENOMEM;
133 } 133 }
@@ -137,7 +137,7 @@ static int send_midi_async(struct usb_line6 *line6, unsigned char *data,
137 137
138 transfer_buffer = kmalloc(length, GFP_ATOMIC); 138 transfer_buffer = kmalloc(length, GFP_ATOMIC);
139 139
140 if (transfer_buffer == 0) { 140 if (transfer_buffer == NULL) {
141 usb_free_urb(urb); 141 usb_free_urb(urb);
142 dev_err(line6->ifcdev, "Out of memory\n"); 142 dev_err(line6->ifcdev, "Out of memory\n");
143 return -ENOMEM; 143 return -ENOMEM;
diff --git a/drivers/staging/line6/playback.c b/drivers/staging/line6/playback.c
index 29940fd1671b..10c543836583 100644
--- a/drivers/staging/line6/playback.c
+++ b/drivers/staging/line6/playback.c
@@ -246,7 +246,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)
246 246
247 change_volume(urb_out, line6pcm->volume_playback, bytes_per_frame); 247 change_volume(urb_out, line6pcm->volume_playback, bytes_per_frame);
248 248
249 if (line6pcm->prev_fbuf != 0) { 249 if (line6pcm->prev_fbuf != NULL) {
250#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE 250#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
251 if (line6pcm->flags & MASK_PCM_IMPULSE) { 251 if (line6pcm->flags & MASK_PCM_IMPULSE) {
252 create_impulse_test_signal(line6pcm, urb_out, 252 create_impulse_test_signal(line6pcm, urb_out,
diff --git a/drivers/staging/memrar/memrar.h b/drivers/staging/memrar/memrar.h
index 0b735b827c09..0feb73b94c91 100644
--- a/drivers/staging/memrar/memrar.h
+++ b/drivers/staging/memrar/memrar.h
@@ -95,6 +95,7 @@ struct RAR_buffer {
95 dma_addr_t bus_address; 95 dma_addr_t bus_address;
96}; 96};
97 97
98#if defined(CONFIG_MRST_RAR_HANDLER)
98/** 99/**
99 * rar_reserve() - reserve RAR buffers 100 * rar_reserve() - reserve RAR buffers
100 * @buffers: array of RAR_buffers where type and size of buffers to 101 * @buffers: array of RAR_buffers where type and size of buffers to
@@ -149,7 +150,25 @@ extern size_t rar_release(struct RAR_buffer *buffers,
149extern size_t rar_handle_to_bus(struct RAR_buffer *buffers, 150extern size_t rar_handle_to_bus(struct RAR_buffer *buffers,
150 size_t count); 151 size_t count);
151 152
153#else
152 154
155extern inline size_t rar_reserve(struct RAR_buffer *buffers, size_t count)
156{
157 return 0;
158}
159
160extern inline size_t rar_release(struct RAR_buffer *buffers, size_t count)
161{
162 return 0;
163}
164
165extern inline size_t rar_handle_to_bus(struct RAR_buffer *buffers,
166 size_t count)
167{
168 return 0;
169}
170
171#endif /* MRST_RAR_HANDLER */
153#endif /* __KERNEL__ */ 172#endif /* __KERNEL__ */
154 173
155#endif /* _MEMRAR_H */ 174#endif /* _MEMRAR_H */
diff --git a/drivers/staging/msm/Makefile b/drivers/staging/msm/Makefile
index bb3606faf20e..07a89ecfcc2b 100644
--- a/drivers/staging/msm/Makefile
+++ b/drivers/staging/msm/Makefile
@@ -41,11 +41,11 @@ obj-$(CONFIG_FB_MSM_EBI2) += ebi2_lcd.o
41obj-$(CONFIG_FB_MSM_LCDC) += lcdc.o 41obj-$(CONFIG_FB_MSM_LCDC) += lcdc.o
42 42
43# MDDI 43# MDDI
44msm_mddi-objs := mddi.o mddihost.o mddihosti.o 44msm_mddi-y := mddi.o mddihost.o mddihosti.o
45obj-$(CONFIG_FB_MSM_MDDI) += msm_mddi.o 45obj-$(CONFIG_FB_MSM_MDDI) += msm_mddi.o
46 46
47# External MDDI 47# External MDDI
48msm_mddi_ext-objs := mddihost_e.o mddi_ext.o 48msm_mddi_ext-y := mddihost_e.o mddi_ext.o
49obj-$(CONFIG_FB_MSM_EXTMDDI) += msm_mddi_ext.o 49obj-$(CONFIG_FB_MSM_EXTMDDI) += msm_mddi_ext.o
50 50
51# TVEnc 51# TVEnc
diff --git a/drivers/staging/msm/lcdc_toshiba_wvga_pt.c b/drivers/staging/msm/lcdc_toshiba_wvga_pt.c
index 864d7c18913d..edba78a3afcf 100644
--- a/drivers/staging/msm/lcdc_toshiba_wvga_pt.c
+++ b/drivers/staging/msm/lcdc_toshiba_wvga_pt.c
@@ -77,7 +77,7 @@ static void toshiba_spi_write(char cmd, uint32 data, int num)
77 77
78 /* followed by parameter bytes */ 78 /* followed by parameter bytes */
79 if (num) { 79 if (num) {
80 bp = (char *)&data;; 80 bp = (char *)&data;
81 bp += (num - 1); 81 bp += (num - 1);
82 while (num) { 82 while (num) {
83 toshiba_spi_write_byte(1, *bp); 83 toshiba_spi_write_byte(1, *bp);
diff --git a/drivers/staging/msm/tvenc.c b/drivers/staging/msm/tvenc.c
index f41c5ac22f25..4fbb77b253d3 100644
--- a/drivers/staging/msm/tvenc.c
+++ b/drivers/staging/msm/tvenc.c
@@ -279,12 +279,13 @@ static int __init tvenc_driver_init(void)
279 279
280 if (IS_ERR(tvenc_clk)) { 280 if (IS_ERR(tvenc_clk)) {
281 printk(KERN_ERR "error: can't get tvenc_clk!\n"); 281 printk(KERN_ERR "error: can't get tvenc_clk!\n");
282 return IS_ERR(tvenc_clk); 282 return PTR_ERR(tvenc_clk);
283 } 283 }
284 284
285 if (IS_ERR(tvdac_clk)) { 285 if (IS_ERR(tvdac_clk)) {
286 printk(KERN_ERR "error: can't get tvdac_clk!\n"); 286 printk(KERN_ERR "error: can't get tvdac_clk!\n");
287 return IS_ERR(tvdac_clk); 287 clk_put(tvenc_clk);
288 return PTR_ERR(tvdac_clk);
288 } 289 }
289 290
290// pm_qos_add_requirement(PM_QOS_SYSTEM_BUS_FREQ , "tvenc", 291// pm_qos_add_requirement(PM_QOS_SYSTEM_BUS_FREQ , "tvenc",
diff --git a/drivers/staging/phison/phison.c b/drivers/staging/phison/phison.c
index 677152044f45..683657cb21f5 100644
--- a/drivers/staging/phison/phison.c
+++ b/drivers/staging/phison/phison.c
@@ -69,7 +69,7 @@ static int phison_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
69 return ret; 69 return ret;
70} 70}
71 71
72static const struct pci_device_id phison_pci_tbl[] = { 72static DEFINE_PCI_DEVICE_TABLE(phison_pci_tbl) = {
73 { PCI_VENDOR_ID_PHISON, PCI_DEVICE_ID_PS5000, PCI_ANY_ID, PCI_ANY_ID, 73 { PCI_VENDOR_ID_PHISON, PCI_DEVICE_ID_PS5000, PCI_ANY_ID, PCI_ANY_ID,
74 PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 }, 74 PCI_CLASS_STORAGE_IDE << 8, 0xffff00, 0 },
75 { 0, }, 75 { 0, },
diff --git a/drivers/staging/pohmelfs/crypto.c b/drivers/staging/pohmelfs/crypto.c
index 2fdb3e01460d..6540864216c8 100644
--- a/drivers/staging/pohmelfs/crypto.c
+++ b/drivers/staging/pohmelfs/crypto.c
@@ -130,10 +130,8 @@ err_out_exit:
130 130
131void pohmelfs_crypto_engine_exit(struct pohmelfs_crypto_engine *e) 131void pohmelfs_crypto_engine_exit(struct pohmelfs_crypto_engine *e)
132{ 132{
133 if (e->hash) 133 crypto_free_hash(e->hash);
134 crypto_free_hash(e->hash); 134 crypto_free_ablkcipher(e->cipher);
135 if (e->cipher)
136 crypto_free_ablkcipher(e->cipher);
137 kfree(e->data); 135 kfree(e->data);
138} 136}
139 137
diff --git a/drivers/staging/rt2860/chip/mac_pci.h b/drivers/staging/rt2860/chip/mac_pci.h
index 9f25ef047f59..b8868a5b9e04 100644
--- a/drivers/staging/rt2860/chip/mac_pci.h
+++ b/drivers/staging/rt2860/chip/mac_pci.h
@@ -30,7 +30,8 @@
30 Abstract: 30 Abstract:
31 31
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 Justin P. Mattock 11/07/2010 Fix some typos
34 --------- ---------- ---------------------------------------------- 35 --------- ---------- ----------------------------------------------
35 */ 36 */
36 37
@@ -45,7 +46,7 @@
45 46
46/* */ 47/* */
47/* Device ID & Vendor ID related definitions, */ 48/* Device ID & Vendor ID related definitions, */
48/* NOTE: you should not add the new VendorID/DeviceID here unless you not sure it belongs to what chip. */ 49/* NOTE: you should not add the new VendorID/DeviceID here unless you know for sure what chip it belongs too. */
49/* */ 50/* */
50#define NIC_PCI_VENDOR_ID 0x1814 51#define NIC_PCI_VENDOR_ID 0x1814
51#define PCIBUS_INTEL_VENDOR 0x8086 52#define PCIBUS_INTEL_VENDOR 0x8086
@@ -83,7 +84,7 @@ struct PACKED rt_txd {
83 u32 SDPtr1; 84 u32 SDPtr1;
84 /*Word3 */ 85 /*Word3 */
85 u32 rsv2:24; 86 u32 rsv2:24;
86 u32 WIV:1; /* Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition */ 87 u32 WIV:1; /* Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correct position */
87 u32 QSEL:2; /* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */ 88 u32 QSEL:2; /* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */
88 u32 rsv:2; 89 u32 rsv:2;
89 u32 TCO:1; /* */ 90 u32 TCO:1; /* */
diff --git a/drivers/staging/rt2860/chip/mac_usb.h b/drivers/staging/rt2860/chip/mac_usb.h
index ed0c0b43b05e..e8158fb58648 100644
--- a/drivers/staging/rt2860/chip/mac_usb.h
+++ b/drivers/staging/rt2860/chip/mac_usb.h
@@ -30,7 +30,8 @@
30 Abstract: 30 Abstract:
31 31
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 Justin P. Mattock 11/07/2010 Fix a typo
34 --------- ---------- ---------------------------------------------- 35 --------- ---------- ----------------------------------------------
35 */ 36 */
36 37
@@ -93,7 +94,7 @@ struct rt_txinfo {
93 /* Word 0 */ 94 /* Word 0 */
94 u32 USBDMATxPktLen:16; /*used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame. */ 95 u32 USBDMATxPktLen:16; /*used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame. */
95 u32 rsv:8; 96 u32 rsv:8;
96 u32 WIV:1; /* Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correctposition */ 97 u32 WIV:1; /* Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correct position */
97 u32 QSEL:2; /* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */ 98 u32 QSEL:2; /* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */
98 u32 SwUseLastRound:1; /* Software use. */ 99 u32 SwUseLastRound:1; /* Software use. */
99 u32 rsv2:2; /* Software use. */ 100 u32 rsv2:2; /* Software use. */
diff --git a/drivers/staging/rt2860/chip/rtmp_mac.h b/drivers/staging/rt2860/chip/rtmp_mac.h
index e8f7172ce42a..3d1e4915b956 100644
--- a/drivers/staging/rt2860/chip/rtmp_mac.h
+++ b/drivers/staging/rt2860/chip/rtmp_mac.h
@@ -32,6 +32,7 @@
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 Justin P. Mattock 11/07/2010 Fix a comments, and typos
35 -------- ---------- ---------------------------------------------- 36 -------- ---------- ----------------------------------------------
36*/ 37*/
37 38
@@ -43,7 +44,7 @@
43/* ================================================================================= */ 44/* ================================================================================= */
44 45
45/* the first 24-byte in TXD is called TXINFO and will be DMAed to MAC block through TXFIFO. */ 46/* the first 24-byte in TXD is called TXINFO and will be DMAed to MAC block through TXFIFO. */
46/* MAC block use this TXINFO to control the transmission behavior of this frame. */ 47/* MAC block uses this TXINFO to control the transmission behavior of this frame. */
47#define FIFO_MGMT 0 48#define FIFO_MGMT 0
48#define FIFO_HCCA 1 49#define FIFO_HCCA 1
49#define FIFO_EDCA 2 50#define FIFO_EDCA 2
@@ -458,8 +459,8 @@ typedef union _BBP_CSR_CFG_STRUC {
458/* */ 459/* */
459typedef union _RF_CSR_CFG0_STRUC { 460typedef union _RF_CSR_CFG0_STRUC {
460 struct { 461 struct {
461 u32 RegIdAndContent:24; /* Register value to program into BBP */ 462 u32 RegIdAndContent:24; /* Register value to program into BBP */
462 u32 bitwidth:5; /* Selected BBP register */ 463 u32 bitwidth:5; /* Selected BBP register */
463 u32 StandbyMode:1; /* 0: high when stand by 1: low when standby */ 464 u32 StandbyMode:1; /* 0: high when stand by 1: low when standby */
464 u32 Sel:1; /* 0:RF_LE0 activate 1:RF_LE1 activate */ 465 u32 Sel:1; /* 0:RF_LE0 activate 1:RF_LE1 activate */
465 u32 Busy:1; /* 0: idle 1: 8busy */ 466 u32 Busy:1; /* 0: idle 1: 8busy */
@@ -469,7 +470,7 @@ typedef union _RF_CSR_CFG0_STRUC {
469#define RF_CSR_CFG1 0x1024 470#define RF_CSR_CFG1 0x1024
470typedef union _RF_CSR_CFG1_STRUC { 471typedef union _RF_CSR_CFG1_STRUC {
471 struct { 472 struct {
472 u32 RegIdAndContent:24; /* Register value to program into BBP */ 473 u32 RegIdAndContent:24; /* Register value to program into BBP */
473 u32 RFGap:5; /* Gap between BB_CONTROL_RF and RF_LE. 0: 3 system clock cycle (37.5usec) 1: 5 system clock cycle (62.5usec) */ 474 u32 RFGap:5; /* Gap between BB_CONTROL_RF and RF_LE. 0: 3 system clock cycle (37.5usec) 1: 5 system clock cycle (62.5usec) */
474 u32 rsv:7; /* 0: idle 1: 8busy */ 475 u32 rsv:7; /* 0: idle 1: 8busy */
475 } field; 476 } field;
@@ -478,7 +479,7 @@ typedef union _RF_CSR_CFG1_STRUC {
478#define RF_CSR_CFG2 0x1028 /* */ 479#define RF_CSR_CFG2 0x1028 /* */
479typedef union _RF_CSR_CFG2_STRUC { 480typedef union _RF_CSR_CFG2_STRUC {
480 struct { 481 struct {
481 u32 RegIdAndContent:24; /* Register value to program into BBP */ 482 u32 RegIdAndContent:24; /* Register value to program into BBP */
482 u32 rsv:8; /* 0: idle 1: 8busy */ 483 u32 rsv:8; /* 0: idle 1: 8busy */
483 } field; 484 } field;
484 u32 word; 485 u32 word;
@@ -490,7 +491,7 @@ typedef union _LED_CFG_STRUC {
490 u32 OffPeriod:8; /* blinking off period unit 1ms */ 491 u32 OffPeriod:8; /* blinking off period unit 1ms */
491 u32 SlowBlinkPeriod:6; /* slow blinking period. unit:1ms */ 492 u32 SlowBlinkPeriod:6; /* slow blinking period. unit:1ms */
492 u32 rsv:2; 493 u32 rsv:2;
493 u32 RLedMode:2; /* red Led Mode 0: off1: blinking upon TX2: periodic slow blinking3: always on */ 494 u32 RLedMode:2; /* red Led Mode 0: off1: blinking upon TX2: periodic slow blinking3: always on */
494 u32 GLedMode:2; /* green Led Mode */ 495 u32 GLedMode:2; /* green Led Mode */
495 u32 YLedMode:2; /* yellow Led Mode */ 496 u32 YLedMode:2; /* yellow Led Mode */
496 u32 LedPolar:1; /* Led Polarity. 0: active low1: active high */ 497 u32 LedPolar:1; /* Led Polarity. 0: active low1: active high */
@@ -621,9 +622,9 @@ typedef union _TX_TIMEOUT_CFG_STRUC {
621#define TX_RTY_CFG 0x134c 622#define TX_RTY_CFG 0x134c
622typedef union PACKED _TX_RTY_CFG_STRUC { 623typedef union PACKED _TX_RTY_CFG_STRUC {
623 struct { 624 struct {
624 u32 ShortRtyLimit:8; /* short retry limit */ 625 u32 ShortRtyLimit:8; /* short retry limit */
625 u32 LongRtyLimit:8; /*long retry limit */ 626 u32 LongRtyLimit:8; /* long retry limit */
626 u32 LongRtyThre:12; /* Long retry threshoold */ 627 u32 LongRtyThre:12; /* Long retry threshold */
627 u32 NonAggRtyMode:1; /* Non-Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer */ 628 u32 NonAggRtyMode:1; /* Non-Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer */
628 u32 AggRtyMode:1; /* Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer */ 629 u32 AggRtyMode:1; /* Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer */
629 u32 TxautoFBEnable:1; /* Tx retry PHY rate auto fallback enable */ 630 u32 TxautoFBEnable:1; /* Tx retry PHY rate auto fallback enable */
diff --git a/drivers/staging/rt2860/chip/rtmp_phy.h b/drivers/staging/rt2860/chip/rtmp_phy.h
index 9f924ea6ca35..98454df30a22 100644
--- a/drivers/staging/rt2860/chip/rtmp_phy.h
+++ b/drivers/staging/rt2860/chip/rtmp_phy.h
@@ -247,7 +247,7 @@
247 } \ 247 } \
248 } \ 248 } \
249 if (BbpCsr.field.Busy == BUSY) { \ 249 if (BbpCsr.field.Busy == BUSY) { \
250 DBGPRINT_ERR(("BBP(viaMCU=%d) read R%d fail\n", (_bViaMCU), _bbpID)); \ 250 DBGPRINT_ERR("BBP(viaMCU=%d) read R%d fail\n", (_bViaMCU), _bbpID); \
251 *(_pV) = (_pAd)->BbpWriteLatch[_bbpID]; \ 251 *(_pV) = (_pAd)->BbpWriteLatch[_bbpID]; \
252 if ((_bViaMCU) == TRUE) { \ 252 if ((_bViaMCU) == TRUE) { \
253 RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \ 253 RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \
@@ -336,11 +336,11 @@
336 } \ 336 } \
337 } \ 337 } \
338 } else { \ 338 } else { \
339 DBGPRINT_ERR((" , brt30xxBanMcuCmd = %d, Read BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I))); \ 339 DBGPRINT_ERR(" , brt30xxBanMcuCmd = %d, Read BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I)); \
340 *(_pV) = (_A)->BbpWriteLatch[_I]; \ 340 *(_pV) = (_A)->BbpWriteLatch[_I]; \
341 } \ 341 } \
342 if ((BbpCsr.field.Busy == BUSY) || ((_A)->bPCIclkOff == TRUE)) { \ 342 if ((BbpCsr.field.Busy == BUSY) || ((_A)->bPCIclkOff == TRUE)) { \
343 DBGPRINT_ERR(("BBP read R%d=0x%x fail\n", _I, BbpCsr.word)); \ 343 DBGPRINT_ERR("BBP read R%d=0x%x fail\n", _I, BbpCsr.word); \
344 *(_pV) = (_A)->BbpWriteLatch[_I]; \ 344 *(_pV) = (_A)->BbpWriteLatch[_I]; \
345 } \ 345 } \
346} 346}
@@ -378,7 +378,7 @@
378 break; \ 378 break; \
379 } \ 379 } \
380 if (_busyCnt == MAX_BUSY_COUNT) { \ 380 if (_busyCnt == MAX_BUSY_COUNT) { \
381 DBGPRINT_ERR(("BBP write R%d fail\n", _bbpID)); \ 381 DBGPRINT_ERR("BBP write R%d fail\n", _bbpID); \
382 if ((_bViaMCU) == TRUE) { \ 382 if ((_bViaMCU) == TRUE) { \
383 RTMP_IO_READ32(_pAd, H2M_BBP_AGENT, &BbpCsr.word); \ 383 RTMP_IO_READ32(_pAd, H2M_BBP_AGENT, &BbpCsr.word); \
384 BbpCsr.field.Busy = 0; \ 384 BbpCsr.field.Busy = 0; \
@@ -459,15 +459,15 @@
459 break; \ 459 break; \
460 } \ 460 } \
461 } else { \ 461 } else { \
462 DBGPRINT_ERR((" brt30xxBanMcuCmd = %d. Write BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I))); \ 462 DBGPRINT_ERR(" brt30xxBanMcuCmd = %d. Write BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I)); \
463 } \ 463 } \
464 if ((BusyCnt == MAX_BUSY_COUNT) || ((_A)->bPCIclkOff == TRUE)) { \ 464 if ((BusyCnt == MAX_BUSY_COUNT) || ((_A)->bPCIclkOff == TRUE)) { \
465 if (BusyCnt == MAX_BUSY_COUNT) \ 465 if (BusyCnt == MAX_BUSY_COUNT) \
466 (_A)->AccessBBPFailCount++; \ 466 (_A)->AccessBBPFailCount++; \
467 DBGPRINT_ERR(("BBP write R%d=0x%x fail. BusyCnt= %d.bPCIclkOff = %d. \n", _I, BbpCsr.word, BusyCnt, (_A)->bPCIclkOff)); \ 467 DBGPRINT_ERR("BBP write R%d=0x%x fail. BusyCnt= %d.bPCIclkOff = %d. \n", _I, BbpCsr.word, BusyCnt, (_A)->bPCIclkOff); \
468 } \ 468 } \
469 } else { \ 469 } else { \
470 DBGPRINT_ERR(("****** BBP_Write_Latch Buffer exceeds max boundry ****** \n")); \ 470 DBGPRINT_ERR("****** BBP_Write_Latch Buffer exceeds max boundry ****** \n"); \
471 } \ 471 } \
472} 472}
473#endif /* RTMP_MAC_PCI // */ 473#endif /* RTMP_MAC_PCI // */
diff --git a/drivers/staging/rt2860/chips/rt3090.c b/drivers/staging/rt2860/chips/rt3090.c
index c2933c69bc04..334720ee1345 100644
--- a/drivers/staging/rt2860/chips/rt3090.c
+++ b/drivers/staging/rt2860/chips/rt3090.c
@@ -28,10 +28,11 @@
28 rt3090.c 28 rt3090.c
29 29
30 Abstract: 30 Abstract:
31 Specific funcitons and variables for RT3070 31 Specific functions and variables for RT3070
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 Justin P. Mattock 11/07/2010 Fix a typo
35 -------- ---------- ---------------------------------------------- 36 -------- ---------- ----------------------------------------------
36*/ 37*/
37 38
@@ -51,7 +52,8 @@ void NICInitRT3090RFRegisters(struct rt_rtmp_adapter *pAd)
51 if (IS_RT3090(pAd)) { 52 if (IS_RT3090(pAd)) {
52 /* Init RF calibration */ 53 /* Init RF calibration */
53 /* Driver should toggle RF R30 bit7 before init RF registers */ 54 /* Driver should toggle RF R30 bit7 before init RF registers */
54 u32 RfReg = 0, data; 55 u8 RfReg;
56 u32 data;
55 57
56 RT30xxReadRFRegister(pAd, RF_R30, (u8 *)&RfReg); 58 RT30xxReadRFRegister(pAd, RF_R30, (u8 *)&RfReg);
57 RfReg |= 0x80; 59 RfReg |= 0x80;
diff --git a/drivers/staging/rt2860/chips/rt30xx.c b/drivers/staging/rt2860/chips/rt30xx.c
index 4367a196aeff..354debfe1477 100644
--- a/drivers/staging/rt2860/chips/rt30xx.c
+++ b/drivers/staging/rt2860/chips/rt30xx.c
@@ -28,10 +28,11 @@
28 rt30xx.c 28 rt30xx.c
29 29
30 Abstract: 30 Abstract:
31 Specific funcitons and variables for RT30xx. 31 Specific functions and variables for RT30xx.
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 Justin P. Mattock 11/07/2010 Fix some typos
35 -------- ---------- ---------------------------------------------- 36 -------- ---------- ----------------------------------------------
36*/ 37*/
37 38
@@ -53,7 +54,7 @@ struct rt_reg_pair RT30xx_RFRegTable[] = {
53 , 54 ,
54 {RF_R06, 0x02} 55 {RF_R06, 0x02}
55 , 56 ,
56 {RF_R07, 0x70} 57 {RF_R07, 0x60}
57 , 58 ,
58 {RF_R09, 0x0F} 59 {RF_R09, 0x0F}
59 , 60 ,
@@ -89,7 +90,7 @@ struct rt_reg_pair RT30xx_RFRegTable[] = {
89 90
90u8 NUM_RF_REG_PARMS = (sizeof(RT30xx_RFRegTable) / sizeof(struct rt_reg_pair)); 91u8 NUM_RF_REG_PARMS = (sizeof(RT30xx_RFRegTable) / sizeof(struct rt_reg_pair));
91 92
92/* Antenna divesity use GPIO3 and EESK pin for control */ 93/* Antenna diversity use GPIO3 and EESK pin for control */
93/* Antenna and EEPROM access are both using EESK pin, */ 94/* Antenna and EEPROM access are both using EESK pin, */
94/* Therefor we should avoid accessing EESK at the same time */ 95/* Therefor we should avoid accessing EESK at the same time */
95/* Then restore antenna after EEPROM access */ 96/* Then restore antenna after EEPROM access */
@@ -243,7 +244,7 @@ void RTMPFilterCalibration(struct rt_rtmp_adapter *pAd)
243 break; 244 break;
244 } 245 }
245 246
246 /* prevent infinite loop cause driver hang. */ 247 /* prevent infinite loop; causes driver hang. */
247 if (loopcnt++ > 100) { 248 if (loopcnt++ > 100) {
248 DBGPRINT(RT_DEBUG_ERROR, 249 DBGPRINT(RT_DEBUG_ERROR,
249 ("RTMPFilterCalibration - can't find a valid value, loopcnt=%d stop calibrating", 250 ("RTMPFilterCalibration - can't find a valid value, loopcnt=%d stop calibrating",
@@ -441,7 +442,7 @@ void RT30xxReverseRFSleepModeSetup(struct rt_rtmp_adapter *pAd)
441 442
442 /* VCO_IC, RF R7 register Bit 4 & Bit 5 to 1 */ 443 /* VCO_IC, RF R7 register Bit 4 & Bit 5 to 1 */
443 RT30xxReadRFRegister(pAd, RF_R07, &RFValue); 444 RT30xxReadRFRegister(pAd, RF_R07, &RFValue);
444 RFValue |= 0x30; 445 RFValue |= 0x20;
445 RT30xxWriteRFRegister(pAd, RF_R07, RFValue); 446 RT30xxWriteRFRegister(pAd, RF_R07, RFValue);
446 447
447 /* Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 1 */ 448 /* Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 1 */
diff --git a/drivers/staging/rt2860/common/ba_action.c b/drivers/staging/rt2860/common/ba_action.c
index 8eef82d92621..b046c2b814c5 100644
--- a/drivers/staging/rt2860/common/ba_action.c
+++ b/drivers/staging/rt2860/common/ba_action.c
@@ -799,8 +799,8 @@ void BAOriSessionTearDown(struct rt_rtmp_adapter *pAd,
799 /* force send specified TID DelBA */ 799 /* force send specified TID DelBA */
800 struct rt_mlme_delba_req DelbaReq; 800 struct rt_mlme_delba_req DelbaReq;
801 struct rt_mlme_queue_elem *Elem = 801 struct rt_mlme_queue_elem *Elem =
802 (struct rt_mlme_queue_elem *)kmalloc(sizeof(struct rt_mlme_queue_elem), 802 kmalloc(sizeof(struct rt_mlme_queue_elem),
803 MEM_ALLOC_FLAG); 803 MEM_ALLOC_FLAG);
804 if (Elem != NULL) { 804 if (Elem != NULL) {
805 NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); 805 NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
806 NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem)); 806 NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem));
@@ -839,8 +839,8 @@ void BAOriSessionTearDown(struct rt_rtmp_adapter *pAd,
839 && (pBAEntry->ORI_BA_Status == Originator_Done)) { 839 && (pBAEntry->ORI_BA_Status == Originator_Done)) {
840 struct rt_mlme_delba_req DelbaReq; 840 struct rt_mlme_delba_req DelbaReq;
841 struct rt_mlme_queue_elem *Elem = 841 struct rt_mlme_queue_elem *Elem =
842 (struct rt_mlme_queue_elem *)kmalloc(sizeof(struct rt_mlme_queue_elem), 842 kmalloc(sizeof(struct rt_mlme_queue_elem),
843 MEM_ALLOC_FLAG); 843 MEM_ALLOC_FLAG);
844 if (Elem != NULL) { 844 if (Elem != NULL) {
845 NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); 845 NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
846 NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem)); 846 NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem));
@@ -908,8 +908,8 @@ void BARecSessionTearDown(struct rt_rtmp_adapter *pAd,
908 /* */ 908 /* */
909 if (bPassive == FALSE) { 909 if (bPassive == FALSE) {
910 struct rt_mlme_queue_elem *Elem = 910 struct rt_mlme_queue_elem *Elem =
911 (struct rt_mlme_queue_elem *)kmalloc(sizeof(struct rt_mlme_queue_elem), 911 kmalloc(sizeof(struct rt_mlme_queue_elem),
912 MEM_ALLOC_FLAG); 912 MEM_ALLOC_FLAG);
913 if (Elem != NULL) { 913 if (Elem != NULL) {
914 NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); 914 NdisZeroMemory(&DelbaReq, sizeof(DelbaReq));
915 NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem)); 915 NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem));
@@ -1270,13 +1270,13 @@ BOOLEAN CntlEnqueueForRecv(struct rt_rtmp_adapter *pAd,
1270 1270
1271 /* First check the size, it MUST not exceed the mlme queue size */ 1271 /* First check the size, it MUST not exceed the mlme queue size */
1272 if (MsgLen > MGMT_DMA_BUFFER_SIZE) { 1272 if (MsgLen > MGMT_DMA_BUFFER_SIZE) {
1273 DBGPRINT_ERR(("CntlEnqueueForRecv: frame too large, size = %ld \n", MsgLen)); 1273 DBGPRINT_ERR("CntlEnqueueForRecv: frame too large, size = %ld \n", MsgLen);
1274 return FALSE; 1274 return FALSE;
1275 } else if (MsgLen != sizeof(struct rt_frame_ba_req)) { 1275 } else if (MsgLen != sizeof(struct rt_frame_ba_req)) {
1276 DBGPRINT_ERR(("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen)); 1276 DBGPRINT_ERR("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen);
1277 return FALSE; 1277 return FALSE;
1278 } else if (MsgLen != sizeof(struct rt_frame_ba_req)) { 1278 } else if (MsgLen != sizeof(struct rt_frame_ba_req)) {
1279 DBGPRINT_ERR(("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen)); 1279 DBGPRINT_ERR("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen);
1280 return FALSE; 1280 return FALSE;
1281 } 1281 }
1282 1282
diff --git a/drivers/staging/rt2860/common/cmm_data.c b/drivers/staging/rt2860/common/cmm_data.c
index 93a53479d766..2204c2bda386 100644
--- a/drivers/staging/rt2860/common/cmm_data.c
+++ b/drivers/staging/rt2860/common/cmm_data.c
@@ -1366,7 +1366,7 @@ void RTMPResumeMsduTransmission(struct rt_rtmp_adapter *pAd)
1366 /* R66 should not be 0 */ 1366 /* R66 should not be 0 */
1367 if (pAd->BbpTuning.R66CurrentValue == 0) { 1367 if (pAd->BbpTuning.R66CurrentValue == 0) {
1368 pAd->BbpTuning.R66CurrentValue = 0x38; 1368 pAd->BbpTuning.R66CurrentValue = 0x38;
1369 DBGPRINT_ERR(("RTMPResumeMsduTransmission, R66CurrentValue=0...\n")); 1369 DBGPRINT_ERR("RTMPResumeMsduTransmission, R66CurrentValue=0...\n");
1370 } 1370 }
1371 1371
1372 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, 1372 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66,
diff --git a/drivers/staging/rt2860/common/cmm_data_pci.c b/drivers/staging/rt2860/common/cmm_data_pci.c
index 43d73a05c8eb..7af59ff9e220 100644
--- a/drivers/staging/rt2860/common/cmm_data_pci.c
+++ b/drivers/staging/rt2860/common/cmm_data_pci.c
@@ -137,7 +137,7 @@ u16 RtmpPCI_WriteSingleTxResource(struct rt_rtmp_adapter *pAd,
137 137
138 pTxD->SDPtr0 = BufBasePaLow; 138 pTxD->SDPtr0 = BufBasePaLow;
139 pTxD->SDLen0 = TXINFO_SIZE + TXWI_SIZE + hwHeaderLen; /* include padding */ 139 pTxD->SDLen0 = TXINFO_SIZE + TXWI_SIZE + hwHeaderLen; /* include padding */
140 pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE);; 140 pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE);
141 pTxD->SDLen1 = pTxBlk->SrcBufLen; 141 pTxD->SDLen1 = pTxBlk->SrcBufLen;
142 pTxD->LastSec0 = 0; 142 pTxD->LastSec0 = 0;
143 pTxD->LastSec1 = (bIsLast) ? 1 : 0; 143 pTxD->LastSec1 = (bIsLast) ? 1 : 0;
@@ -215,7 +215,7 @@ u16 RtmpPCI_WriteMultiTxResource(struct rt_rtmp_adapter *pAd,
215 215
216 pTxD->SDPtr0 = BufBasePaLow; 216 pTxD->SDPtr0 = BufBasePaLow;
217 pTxD->SDLen0 = firstDMALen; /* include padding */ 217 pTxD->SDLen0 = firstDMALen; /* include padding */
218 pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE);; 218 pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE);
219 pTxD->SDLen1 = pTxBlk->SrcBufLen; 219 pTxD->SDLen1 = pTxBlk->SrcBufLen;
220 pTxD->LastSec0 = 0; 220 pTxD->LastSec0 = 0;
221 pTxD->LastSec1 = (bIsLast) ? 1 : 0; 221 pTxD->LastSec1 = (bIsLast) ? 1 : 0;
diff --git a/drivers/staging/rt2860/common/cmm_mac_pci.c b/drivers/staging/rt2860/common/cmm_mac_pci.c
index e26ba4942877..850f0fbc6d90 100644
--- a/drivers/staging/rt2860/common/cmm_mac_pci.c
+++ b/drivers/staging/rt2860/common/cmm_mac_pci.c
@@ -89,7 +89,7 @@ int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd)
89 89
90 if (pAd->TxDescRing[num].AllocVa == NULL) { 90 if (pAd->TxDescRing[num].AllocVa == NULL) {
91 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; 91 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;
92 DBGPRINT_ERR(("Failed to allocate a big buffer\n")); 92 DBGPRINT_ERR("Failed to allocate a big buffer\n");
93 Status = NDIS_STATUS_RESOURCES; 93 Status = NDIS_STATUS_RESOURCES;
94 break; 94 break;
95 } 95 }
@@ -121,7 +121,7 @@ int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd)
121 121
122 if (pAd->TxBufSpace[num].AllocVa == NULL) { 122 if (pAd->TxBufSpace[num].AllocVa == NULL) {
123 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; 123 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;
124 DBGPRINT_ERR(("Failed to allocate a big buffer\n")); 124 DBGPRINT_ERR("Failed to allocate a big buffer\n");
125 Status = NDIS_STATUS_RESOURCES; 125 Status = NDIS_STATUS_RESOURCES;
126 break; 126 break;
127 } 127 }
@@ -197,7 +197,7 @@ int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd)
197 197
198 if (pAd->MgmtDescRing.AllocVa == NULL) { 198 if (pAd->MgmtDescRing.AllocVa == NULL) {
199 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; 199 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;
200 DBGPRINT_ERR(("Failed to allocate a big buffer\n")); 200 DBGPRINT_ERR("Failed to allocate a big buffer\n");
201 Status = NDIS_STATUS_RESOURCES; 201 Status = NDIS_STATUS_RESOURCES;
202 break; 202 break;
203 } 203 }
@@ -251,7 +251,7 @@ int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd)
251 251
252 if (pAd->RxDescRing.AllocVa == NULL) { 252 if (pAd->RxDescRing.AllocVa == NULL) {
253 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; 253 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;
254 DBGPRINT_ERR(("Failed to allocate a big buffer\n")); 254 DBGPRINT_ERR("Failed to allocate a big buffer\n");
255 Status = NDIS_STATUS_RESOURCES; 255 Status = NDIS_STATUS_RESOURCES;
256 break; 256 break;
257 } 257 }
@@ -304,7 +304,7 @@ int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd)
304 /* Error handling */ 304 /* Error handling */
305 if (pDmaBuf->AllocVa == NULL) { 305 if (pDmaBuf->AllocVa == NULL) {
306 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; 306 ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY;
307 DBGPRINT_ERR(("Failed to allocate RxRing's 1st buffer\n")); 307 DBGPRINT_ERR("Failed to allocate RxRing's 1st buffer\n");
308 Status = NDIS_STATUS_RESOURCES; 308 Status = NDIS_STATUS_RESOURCES;
309 break; 309 break;
310 } 310 }
diff --git a/drivers/staging/rt2860/common/cmm_mac_usb.c b/drivers/staging/rt2860/common/cmm_mac_usb.c
index 72731cbb81df..64a65a460c29 100644
--- a/drivers/staging/rt2860/common/cmm_mac_usb.c
+++ b/drivers/staging/rt2860/common/cmm_mac_usb.c
@@ -236,7 +236,7 @@ int NICInitTransmit(struct rt_rtmp_adapter *pAd)
236 os_alloc_mem(pAd, (u8 **) (&pAd->MgmtDescRing.AllocVa), 236 os_alloc_mem(pAd, (u8 **) (&pAd->MgmtDescRing.AllocVa),
237 pAd->MgmtDescRing.AllocSize); 237 pAd->MgmtDescRing.AllocSize);
238 if (pAd->MgmtDescRing.AllocVa == NULL) { 238 if (pAd->MgmtDescRing.AllocVa == NULL) {
239 DBGPRINT_ERR(("Failed to allocate a big buffer for MgmtDescRing!\n")); 239 DBGPRINT_ERR("Failed to allocate a big buffer for MgmtDescRing!\n");
240 Status = NDIS_STATUS_RESOURCES; 240 Status = NDIS_STATUS_RESOURCES;
241 goto out1; 241 goto out1;
242 } 242 }
diff --git a/drivers/staging/rt2860/common/cmm_wpa.c b/drivers/staging/rt2860/common/cmm_wpa.c
index e37b64b6a608..0040f45b629b 100644
--- a/drivers/staging/rt2860/common/cmm_wpa.c
+++ b/drivers/staging/rt2860/common/cmm_wpa.c
@@ -2794,7 +2794,7 @@ u8 *GetSuiteFromRSNIE(u8 *rsnie,
2794 2794
2795 /* Check length */ 2795 /* Check length */
2796 if ((len <= 0) || (pEid->Len != len)) { 2796 if ((len <= 0) || (pEid->Len != len)) {
2797 DBGPRINT_ERR(("%s : The length is invalid\n", __func__)); 2797 DBGPRINT_ERR("%s : The length is invalid\n", __func__);
2798 return NULL; 2798 return NULL;
2799 } 2799 }
2800 /* Check WPA or WPA2 */ 2800 /* Check WPA or WPA2 */
@@ -2803,14 +2803,13 @@ u8 *GetSuiteFromRSNIE(u8 *rsnie,
2803 u16 ucount; 2803 u16 ucount;
2804 2804
2805 if (len < sizeof(struct rt_rsnie)) { 2805 if (len < sizeof(struct rt_rsnie)) {
2806 DBGPRINT_ERR(("%s : The length is too short for WPA\n", 2806 DBGPRINT_ERR("%s : The length is too short for WPA\n", __func__);
2807 __func__));
2808 return NULL; 2807 return NULL;
2809 } 2808 }
2810 /* Get the count of pairwise cipher */ 2809 /* Get the count of pairwise cipher */
2811 ucount = cpu2le16(pRsnie->ucount); 2810 ucount = cpu2le16(pRsnie->ucount);
2812 if (ucount > 2) { 2811 if (ucount > 2) {
2813 DBGPRINT_ERR(("%s : The count(%d) of pairwise cipher is invlaid\n", __func__, ucount)); 2812 DBGPRINT_ERR("%s : The count(%d) of pairwise cipher is invlaid\n", __func__, ucount);
2814 return NULL; 2813 return NULL;
2815 } 2814 }
2816 /* Get the group cipher */ 2815 /* Get the group cipher */
@@ -2836,14 +2835,13 @@ u8 *GetSuiteFromRSNIE(u8 *rsnie,
2836 isWPA2 = TRUE; 2835 isWPA2 = TRUE;
2837 2836
2838 if (len < sizeof(struct rt_rsnie2)) { 2837 if (len < sizeof(struct rt_rsnie2)) {
2839 DBGPRINT_ERR(("%s : The length is too short for WPA2\n", 2838 DBGPRINT_ERR("%s : The length is too short for WPA2\n", __func__);
2840 __func__));
2841 return NULL; 2839 return NULL;
2842 } 2840 }
2843 /* Get the count of pairwise cipher */ 2841 /* Get the count of pairwise cipher */
2844 ucount = cpu2le16(pRsnie->ucount); 2842 ucount = cpu2le16(pRsnie->ucount);
2845 if (ucount > 2) { 2843 if (ucount > 2) {
2846 DBGPRINT_ERR(("%s : The count(%d) of pairwise cipher is invlaid\n", __func__, ucount)); 2844 DBGPRINT_ERR("%s : The count(%d) of pairwise cipher is invlaid\n", __func__, ucount);
2847 return NULL; 2845 return NULL;
2848 } 2846 }
2849 /* Get the group cipher */ 2847 /* Get the group cipher */
@@ -2863,7 +2861,7 @@ u8 *GetSuiteFromRSNIE(u8 *rsnie,
2863 offset = sizeof(struct rt_rsnie2) + (4 * (ucount - 1)); 2861 offset = sizeof(struct rt_rsnie2) + (4 * (ucount - 1));
2864 2862
2865 } else { 2863 } else {
2866 DBGPRINT_ERR(("%s : Unknown IE (%d)\n", __func__, pEid->Eid)); 2864 DBGPRINT_ERR("%s : Unknown IE (%d)\n", __func__, pEid->Eid);
2867 return NULL; 2865 return NULL;
2868 } 2866 }
2869 2867
@@ -2872,8 +2870,7 @@ u8 *GetSuiteFromRSNIE(u8 *rsnie,
2872 len -= offset; 2870 len -= offset;
2873 2871
2874 if (len < sizeof(struct rt_rsnie_auth)) { 2872 if (len < sizeof(struct rt_rsnie_auth)) {
2875 DBGPRINT_ERR(("%s : The length of RSNIE is too short\n", 2873 DBGPRINT_ERR("%s : The length of RSNIE is too short\n", __func__);
2876 __func__));
2877 return NULL; 2874 return NULL;
2878 } 2875 }
2879 /* pointer to AKM count */ 2876 /* pointer to AKM count */
@@ -2882,8 +2879,7 @@ u8 *GetSuiteFromRSNIE(u8 *rsnie,
2882 /* Get the count of pairwise cipher */ 2879 /* Get the count of pairwise cipher */
2883 acount = cpu2le16(pAkm->acount); 2880 acount = cpu2le16(pAkm->acount);
2884 if (acount > 2) { 2881 if (acount > 2) {
2885 DBGPRINT_ERR(("%s : The count(%d) of AKM is invlaid\n", 2882 DBGPRINT_ERR("%s : The count(%d) of AKM is invlaid\n", __func__, acount);
2886 __func__, acount));
2887 return NULL; 2883 return NULL;
2888 } 2884 }
2889 /* Get the AKM suite */ 2885 /* Get the AKM suite */
@@ -2910,7 +2906,7 @@ u8 *GetSuiteFromRSNIE(u8 *rsnie,
2910 return pBuf; 2906 return pBuf;
2911 } 2907 }
2912 } else { 2908 } else {
2913 DBGPRINT_ERR(("%s : it can't get any more information beyond AKM \n", __func__)); 2909 DBGPRINT_ERR("%s : it can't get any more information beyond AKM \n", __func__);
2914 return NULL; 2910 return NULL;
2915 } 2911 }
2916 2912
diff --git a/drivers/staging/rt2860/common/ee_efuse.c b/drivers/staging/rt2860/common/ee_efuse.c
index 03412f5bc990..fed0ba452271 100644
--- a/drivers/staging/rt2860/common/ee_efuse.c
+++ b/drivers/staging/rt2860/common/ee_efuse.c
@@ -264,7 +264,7 @@ int set_eFuseGetFreeBlockCount_Proc(struct rt_rtmp_adapter *pAd, char *arg)
264 if (i == EFUSE_USAGE_MAP_END) 264 if (i == EFUSE_USAGE_MAP_END)
265 efusefreenum = 0; 265 efusefreenum = 0;
266 } 266 }
267 printk("efuseFreeNumber is %d\n", efusefreenum); 267 printk(KERN_DEBUG "efuseFreeNumber is %d\n", efusefreenum);
268 return TRUE; 268 return TRUE;
269} 269}
270 270
@@ -274,16 +274,23 @@ int set_eFusedump_Proc(struct rt_rtmp_adapter *pAd, char *arg)
274 int i = 0; 274 int i = 0;
275 if (!pAd->bUseEfuse) 275 if (!pAd->bUseEfuse)
276 return FALSE; 276 return FALSE;
277
278 printk(KERN_DEBUG "Block 0: ");
279
277 for (i = 0; i < EFUSE_USAGE_MAP_END / 2; i++) { 280 for (i = 0; i < EFUSE_USAGE_MAP_END / 2; i++) {
278 InBuf[0] = 2 * i; 281 InBuf[0] = 2 * i;
279 InBuf[1] = 2; 282 InBuf[1] = 2;
280 InBuf[2] = 0x0; 283 InBuf[2] = 0x0;
281 284
282 eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2); 285 eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2);
283 if (i % 4 == 0) 286 if (i && i % 4 == 0) {
284 printk("\nBlock %x:", i / 8); 287 printk(KERN_CONT "\n");
285 printk("%04x ", InBuf[2]); 288 printk(KERN_DEBUG "Block %x:", i / 8);
289 }
290 printk(KERN_CONT "%04x ", InBuf[2]);
286 } 291 }
292 printk(KERN_CONT "\n");
293
287 return TRUE; 294 return TRUE;
288} 295}
289 296
diff --git a/drivers/staging/rt2860/common/mlme.c b/drivers/staging/rt2860/common/mlme.c
index 7300c6e9c175..d9c3fd5c2166 100644
--- a/drivers/staging/rt2860/common/mlme.c
+++ b/drivers/staging/rt2860/common/mlme.c
@@ -550,7 +550,7 @@ void MlmeHandler(struct rt_rtmp_adapter *pAd)
550 Elem->MsgLen = 0; 550 Elem->MsgLen = 0;
551 551
552 } else { 552 } else {
553 DBGPRINT_ERR(("MlmeHandler: MlmeQueue empty\n")); 553 DBGPRINT_ERR("MlmeHandler: MlmeQueue empty\n");
554 } 554 }
555 } 555 }
556 556
@@ -4698,8 +4698,7 @@ BOOLEAN MlmeEnqueue(struct rt_rtmp_adapter *pAd,
4698 4698
4699 /* First check the size, it MUST not exceed the mlme queue size */ 4699 /* First check the size, it MUST not exceed the mlme queue size */
4700 if (MsgLen > MGMT_DMA_BUFFER_SIZE) { 4700 if (MsgLen > MGMT_DMA_BUFFER_SIZE) {
4701 DBGPRINT_ERR(("MlmeEnqueue: msg too large, size = %ld \n", 4701 DBGPRINT_ERR("MlmeEnqueue: msg too large, size = %ld \n", MsgLen);
4702 MsgLen));
4703 return FALSE; 4702 return FALSE;
4704 } 4703 }
4705 4704
@@ -4762,12 +4761,12 @@ BOOLEAN MlmeEnqueueForRecv(struct rt_rtmp_adapter *pAd,
4762 if (RTMP_TEST_FLAG 4761 if (RTMP_TEST_FLAG
4763 (pAd, 4762 (pAd,
4764 fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) { 4763 fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) {
4765 DBGPRINT_ERR(("MlmeEnqueueForRecv: fRTMP_ADAPTER_HALT_IN_PROGRESS\n")); 4764 DBGPRINT_ERR("MlmeEnqueueForRecv: fRTMP_ADAPTER_HALT_IN_PROGRESS\n");
4766 return FALSE; 4765 return FALSE;
4767 } 4766 }
4768 /* First check the size, it MUST not exceed the mlme queue size */ 4767 /* First check the size, it MUST not exceed the mlme queue size */
4769 if (MsgLen > MGMT_DMA_BUFFER_SIZE) { 4768 if (MsgLen > MGMT_DMA_BUFFER_SIZE) {
4770 DBGPRINT_ERR(("MlmeEnqueueForRecv: frame too large, size = %ld \n", MsgLen)); 4769 DBGPRINT_ERR("MlmeEnqueueForRecv: frame too large, size = %ld \n", MsgLen);
4771 return FALSE; 4770 return FALSE;
4772 } 4771 }
4773 4772
@@ -4777,7 +4776,7 @@ BOOLEAN MlmeEnqueueForRecv(struct rt_rtmp_adapter *pAd,
4777 4776
4778 { 4777 {
4779 if (!MsgTypeSubst(pAd, pFrame, &Machine, &MsgType)) { 4778 if (!MsgTypeSubst(pAd, pFrame, &Machine, &MsgType)) {
4780 DBGPRINT_ERR(("MlmeEnqueueForRecv: un-recongnized mgmt->subtype=%d\n", pFrame->Hdr.FC.SubType)); 4779 DBGPRINT_ERR("MlmeEnqueueForRecv: un-recongnized mgmt->subtype=%d\n", pFrame->Hdr.FC.SubType);
4781 return FALSE; 4780 return FALSE;
4782 } 4781 }
4783 } 4782 }
@@ -4867,7 +4866,7 @@ void MlmeRestartStateMachine(struct rt_rtmp_adapter *pAd)
4867 Elem->MsgLen = 0; 4866 Elem->MsgLen = 0;
4868 4867
4869 } else { 4868 } else {
4870 DBGPRINT_ERR(("MlmeRestartStateMachine: MlmeQueue empty\n")); 4869 DBGPRINT_ERR("MlmeRestartStateMachine: MlmeQueue empty\n");
4871 } 4870 }
4872 } 4871 }
4873#endif /* RTMP_MAC_PCI // */ 4872#endif /* RTMP_MAC_PCI // */
diff --git a/drivers/staging/rt2860/common/rt_rf.c b/drivers/staging/rt2860/common/rt_rf.c
index 519121d81040..2895447ffc48 100644
--- a/drivers/staging/rt2860/common/rt_rf.c
+++ b/drivers/staging/rt2860/common/rt_rf.c
@@ -131,8 +131,7 @@ int RT30xxReadRFRegister(struct rt_rtmp_adapter *pAd,
131 } 131 }
132 } 132 }
133 if (rfcsr.field.RF_CSR_KICK == BUSY) { 133 if (rfcsr.field.RF_CSR_KICK == BUSY) {
134 DBGPRINT_ERR(("RF read R%d=0x%x fail, i[%d], k[%d]\n", regID, 134 DBGPRINT_ERR("RF read R%d=0x%x fail, i[%d], k[%d]\n", regID, rfcsr.word, i, k);
135 rfcsr.word, i, k));
136 return STATUS_UNSUCCESSFUL; 135 return STATUS_UNSUCCESSFUL;
137 } 136 }
138 137
diff --git a/drivers/staging/rt2860/common/rtmp_init.c b/drivers/staging/rt2860/common/rtmp_init.c
index 3628e85802e3..d359a14f5d4d 100644
--- a/drivers/staging/rt2860/common/rtmp_init.c
+++ b/drivers/staging/rt2860/common/rtmp_init.c
@@ -169,14 +169,14 @@ int RTMPAllocAdapterBlock(void *handle,
169 pBeaconBuf = kmalloc(MAX_BEACON_SIZE, MEM_ALLOC_FLAG); 169 pBeaconBuf = kmalloc(MAX_BEACON_SIZE, MEM_ALLOC_FLAG);
170 if (pBeaconBuf == NULL) { 170 if (pBeaconBuf == NULL) {
171 Status = NDIS_STATUS_FAILURE; 171 Status = NDIS_STATUS_FAILURE;
172 DBGPRINT_ERR(("Failed to allocate memory - BeaconBuf!\n")); 172 DBGPRINT_ERR("Failed to allocate memory - BeaconBuf!\n");
173 break; 173 break;
174 } 174 }
175 NdisZeroMemory(pBeaconBuf, MAX_BEACON_SIZE); 175 NdisZeroMemory(pBeaconBuf, MAX_BEACON_SIZE);
176 176
177 Status = AdapterBlockAllocateMemory(handle, (void **) & pAd); 177 Status = AdapterBlockAllocateMemory(handle, (void **) & pAd);
178 if (Status != NDIS_STATUS_SUCCESS) { 178 if (Status != NDIS_STATUS_SUCCESS) {
179 DBGPRINT_ERR(("Failed to allocate memory - ADAPTER\n")); 179 DBGPRINT_ERR("Failed to allocate memory - ADAPTER\n");
180 break; 180 break;
181 } 181 }
182 pAd->BeaconBuf = pBeaconBuf; 182 pAd->BeaconBuf = pBeaconBuf;
@@ -785,8 +785,7 @@ void NICReadEEPROMParameters(struct rt_rtmp_adapter *pAd, u8 *mac_addr)
785 Version.field.Version, Version.field.FaeReleaseNumber)); 785 Version.field.Version, Version.field.FaeReleaseNumber));
786 786
787 if (Version.field.Version > VALID_EEPROM_VERSION) { 787 if (Version.field.Version > VALID_EEPROM_VERSION) {
788 DBGPRINT_ERR(("E2PROM: WRONG VERSION 0x%x, should be %d\n", 788 DBGPRINT_ERR("E2PROM: WRONG VERSION 0x%x, should be %d\n", Version.field.Version, VALID_EEPROM_VERSION);
789 Version.field.Version, VALID_EEPROM_VERSION));
790 /*pAd->SystemErrorBitmap |= 0x00000001; 789 /*pAd->SystemErrorBitmap |= 0x00000001;
791 790
792 // hard-code default value when no proper E2PROM installed 791 // hard-code default value when no proper E2PROM installed
@@ -2911,7 +2910,7 @@ void RTMPSetTimer(struct rt_ralink_timer *pTimer, unsigned long Value)
2911 RTMP_OS_Add_Timer(&pTimer->TimerObj, Value); 2910 RTMP_OS_Add_Timer(&pTimer->TimerObj, Value);
2912 } 2911 }
2913 } else { 2912 } else {
2914 DBGPRINT_ERR(("RTMPSetTimer failed, Timer hasn't been initialize!\n")); 2913 DBGPRINT_ERR("RTMPSetTimer failed, Timer hasn't been initialize!\n");
2915 } 2914 }
2916} 2915}
2917 2916
@@ -2947,7 +2946,7 @@ void RTMPModTimer(struct rt_ralink_timer *pTimer, unsigned long Value)
2947 RTMP_OS_Mod_Timer(&pTimer->TimerObj, Value); 2946 RTMP_OS_Mod_Timer(&pTimer->TimerObj, Value);
2948 } 2947 }
2949 } else { 2948 } else {
2950 DBGPRINT_ERR(("RTMPModTimer failed, Timer hasn't been initialize!\n")); 2949 DBGPRINT_ERR("RTMPModTimer failed, Timer hasn't been initialize!\n");
2951 } 2950 }
2952} 2951}
2953 2952
@@ -2989,7 +2988,7 @@ void RTMPCancelTimer(struct rt_ralink_timer *pTimer, OUT BOOLEAN * pCancelled)
2989 RtmpTimerQRemove(pTimer->pAd, pTimer); 2988 RtmpTimerQRemove(pTimer->pAd, pTimer);
2990#endif /* RTMP_TIMER_TASK_SUPPORT // */ 2989#endif /* RTMP_TIMER_TASK_SUPPORT // */
2991 } else { 2990 } else {
2992 DBGPRINT_ERR(("RTMPCancelTimer failed, Timer hasn't been initialize!\n")); 2991 DBGPRINT_ERR("RTMPCancelTimer failed, Timer hasn't been initialize!\n");
2993 } 2992 }
2994} 2993}
2995 2994
@@ -3251,8 +3250,7 @@ int rt28xx_init(struct rt_rtmp_adapter *pAd,
3251 /* Load 8051 firmware */ 3250 /* Load 8051 firmware */
3252 Status = NICLoadFirmware(pAd); 3251 Status = NICLoadFirmware(pAd);
3253 if (Status != NDIS_STATUS_SUCCESS) { 3252 if (Status != NDIS_STATUS_SUCCESS) {
3254 DBGPRINT_ERR(("NICLoadFirmware failed, Status[=0x%08x]\n", 3253 DBGPRINT_ERR("NICLoadFirmware failed, Status[=0x%08x]\n", Status);
3255 Status));
3256 goto err1; 3254 goto err1;
3257 } 3255 }
3258 3256
@@ -3268,8 +3266,7 @@ int rt28xx_init(struct rt_rtmp_adapter *pAd,
3268 3266
3269 Status = RTMPAllocTxRxRingMemory(pAd); 3267 Status = RTMPAllocTxRxRingMemory(pAd);
3270 if (Status != NDIS_STATUS_SUCCESS) { 3268 if (Status != NDIS_STATUS_SUCCESS) {
3271 DBGPRINT_ERR(("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", 3269 DBGPRINT_ERR("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status);
3272 Status));
3273 goto err1; 3270 goto err1;
3274 } 3271 }
3275 3272
@@ -3284,7 +3281,7 @@ int rt28xx_init(struct rt_rtmp_adapter *pAd,
3284 3281
3285 Status = MlmeInit(pAd); 3282 Status = MlmeInit(pAd);
3286 if (Status != NDIS_STATUS_SUCCESS) { 3283 if (Status != NDIS_STATUS_SUCCESS) {
3287 DBGPRINT_ERR(("MlmeInit failed, Status[=0x%08x]\n", Status)); 3284 DBGPRINT_ERR("MlmeInit failed, Status[=0x%08x]\n", Status);
3288 goto err2; 3285 goto err2;
3289 } 3286 }
3290 /* Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default */ 3287 /* Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default */
@@ -3309,8 +3306,7 @@ int rt28xx_init(struct rt_rtmp_adapter *pAd,
3309 /* */ 3306 /* */
3310 Status = NICInitializeAdapter(pAd, TRUE); 3307 Status = NICInitializeAdapter(pAd, TRUE);
3311 if (Status != NDIS_STATUS_SUCCESS) { 3308 if (Status != NDIS_STATUS_SUCCESS) {
3312 DBGPRINT_ERR(("NICInitializeAdapter failed, Status[=0x%08x]\n", 3309 DBGPRINT_ERR("NICInitializeAdapter failed, Status[=0x%08x]\n", Status);
3313 Status));
3314 if (Status != NDIS_STATUS_SUCCESS) 3310 if (Status != NDIS_STATUS_SUCCESS)
3315 goto err3; 3311 goto err3;
3316 } 3312 }
diff --git a/drivers/staging/rt2860/common/rtmp_mcu.c b/drivers/staging/rt2860/common/rtmp_mcu.c
index 844d4b987b78..80fa4160ed62 100644
--- a/drivers/staging/rt2860/common/rtmp_mcu.c
+++ b/drivers/staging/rt2860/common/rtmp_mcu.c
@@ -267,7 +267,7 @@ int RtmpAsicSendCommandToMcu(struct rt_rtmp_adapter *pAd,
267 } while (i++ < 100); 267 } while (i++ < 100);
268 268
269 if (i > 100) { 269 if (i > 100) {
270 DBGPRINT_ERR(("H2M_MAILBOX still hold by MCU. command fail\n")); 270 DBGPRINT_ERR("H2M_MAILBOX still hold by MCU. command fail\n");
271 return FALSE; 271 return FALSE;
272 } 272 }
273 273
@@ -296,7 +296,7 @@ int RtmpAsicSendCommandToMcu(struct rt_rtmp_adapter *pAd,
296#ifdef RTMP_MAC_PCI 296#ifdef RTMP_MAC_PCI
297#endif /* RTMP_MAC_PCI // */ 297#endif /* RTMP_MAC_PCI // */
298 { 298 {
299 DBGPRINT_ERR(("H2M_MAILBOX still hold by MCU. command fail\n")); 299 DBGPRINT_ERR("H2M_MAILBOX still hold by MCU. command fail\n");
300 } 300 }
301 return FALSE; 301 return FALSE;
302 } 302 }
diff --git a/drivers/staging/rt2860/common/spectrum.c b/drivers/staging/rt2860/common/spectrum.c
index 2d5f847e6cc6..1dfb802aab9a 100644
--- a/drivers/staging/rt2860/common/spectrum.c
+++ b/drivers/staging/rt2860/common/spectrum.c
@@ -1837,7 +1837,7 @@ static void PeerChSwAnnAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_
1837 } 1837 }
1838 1838
1839 if (index >= pAd->ChannelListNum) { 1839 if (index >= pAd->ChannelListNum) {
1840 DBGPRINT_ERR(("&&&&&&&&&&&&&&&&&&&&&&&&&&PeerChSwAnnAction(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum)); 1840 DBGPRINT_ERR("&&&&&&&&&&&&&&&&&&&&&&&&&&PeerChSwAnnAction(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum);
1841 } 1841 }
1842 } 1842 }
1843 } 1843 }
diff --git a/drivers/staging/rt2860/mlme.h b/drivers/staging/rt2860/mlme.h
index 01414c3b4889..cd1ee3d7a91d 100644
--- a/drivers/staging/rt2860/mlme.h
+++ b/drivers/staging/rt2860/mlme.h
@@ -32,8 +32,9 @@
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 -------- ---------- ------------------------------ 34 -------- ---------- ------------------------------
35 John Chang 2003-08-28 Created 35 John Chang 2003-08-28 Created
36 John Chang 2004-09-06 modified for RT2600 36 John Chang 2004-09-06 modified for RT2600
37 Justin P. Mattock 11/07/2010 Fix typos in comments
37 38
38*/ 39*/
39#ifndef __MLME_H__ 40#ifndef __MLME_H__
@@ -41,7 +42,7 @@
41 42
42#include "rtmp_dot11.h" 43#include "rtmp_dot11.h"
43 44
44/* maximum supported capability information - */ 45/* maximum supported capability information */
45/* ESS, IBSS, Privacy, Short Preamble, Spectrum mgmt, Short Slot */ 46/* ESS, IBSS, Privacy, Short Preamble, Spectrum mgmt, Short Slot */
46#define SUPPORTED_CAPABILITY_INFO 0x0533 47#define SUPPORTED_CAPABILITY_INFO 0x0533
47 48
@@ -77,7 +78,7 @@
77#define CW_MAX_IN_BITS 10 /* actual CwMax = 2^CW_MAX_IN_BITS - 1 */ 78#define CW_MAX_IN_BITS 10 /* actual CwMax = 2^CW_MAX_IN_BITS - 1 */
78 79
79/* Note: RSSI_TO_DBM_OFFSET has been changed to variable for new RF (2004-0720). */ 80/* Note: RSSI_TO_DBM_OFFSET has been changed to variable for new RF (2004-0720). */
80/* SHould not refer to this constant anymore */ 81/* Should not refer to this constant anymore */
81/*#define RSSI_TO_DBM_OFFSET 120 // for RT2530 RSSI-115 = dBm */ 82/*#define RSSI_TO_DBM_OFFSET 120 // for RT2530 RSSI-115 = dBm */
82#define RSSI_FOR_MID_TX_POWER -55 /* -55 db is considered mid-distance */ 83#define RSSI_FOR_MID_TX_POWER -55 /* -55 db is considered mid-distance */
83#define RSSI_FOR_LOW_TX_POWER -45 /* -45 db is considered very short distance and */ 84#define RSSI_FOR_LOW_TX_POWER -45 /* -45 db is considered very short distance and */
@@ -123,7 +124,7 @@
123#define TID_MAC_HASH_INDEX(Addr, TID) (TID_MAC_HASH(Addr, TID) % HASH_TABLE_SIZE) 124#define TID_MAC_HASH_INDEX(Addr, TID) (TID_MAC_HASH(Addr, TID) % HASH_TABLE_SIZE)
124 125
125/* LED Control */ 126/* LED Control */
126/* assoiation ON. one LED ON. another blinking when TX, OFF when idle */ 127/* association ON. one LED ON. another blinking when TX, OFF when idle */
127/* no association, both LED off */ 128/* no association, both LED off */
128#define ASIC_LED_ACT_ON(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00031e46) 129#define ASIC_LED_ACT_ON(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00031e46)
129#define ASIC_LED_ACT_OFF(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00001e46) 130#define ASIC_LED_ACT_OFF(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00001e46)
@@ -284,8 +285,8 @@ struct PACKED rt_ht_capability_ie {
284 285
285/* 802.11n draft3 related structure definitions. */ 286/* 802.11n draft3 related structure definitions. */
286/* 7.3.2.60 */ 287/* 7.3.2.60 */
287#define dot11OBSSScanPassiveDwell 20 /* in TU. min amount of time that the STA continously scans each channel when performing an active OBSS scan. */ 288#define dot11OBSSScanPassiveDwell 20 /* in TU. min amount of time that the STA continuously scans each channel when performing an active OBSS scan. */
288#define dot11OBSSScanActiveDwell 10 /* in TU.min amount of time that the STA continously scans each channel when performing an passive OBSS scan. */ 289#define dot11OBSSScanActiveDwell 10 /* in TU.min amount of time that the STA continuously scans each channel when performing an passive OBSS scan. */
289#define dot11BSSWidthTriggerScanInterval 300 /* in sec. max interval between scan operations to be performed to detect BSS channel width trigger events. */ 290#define dot11BSSWidthTriggerScanInterval 300 /* in sec. max interval between scan operations to be performed to detect BSS channel width trigger events. */
290#define dot11OBSSScanPassiveTotalPerChannel 200 /* in TU. min total amount of time that the STA scans each channel when performing a passive OBSS scan. */ 291#define dot11OBSSScanPassiveTotalPerChannel 200 /* in TU. min total amount of time that the STA scans each channel when performing a passive OBSS scan. */
291#define dot11OBSSScanActiveTotalPerChannel 20 /*in TU. min total amount of time that the STA scans each channel when performing a active OBSS scan */ 292#define dot11OBSSScanActiveTotalPerChannel 20 /*in TU. min total amount of time that the STA scans each channel when performing a active OBSS scan */
@@ -325,7 +326,7 @@ struct rt_trigger_eventa {
325}; 326};
326 327
327/* 20/40 trigger event table */ 328/* 20/40 trigger event table */
328/* If one Event A delete or created, or if Event B is detected or not detected, STA should send 2040BSSCoexistence to AP. */ 329/* If one Event (A) is deleted or created, or if Event (B) is detected or not detected, STA should send 2040BSSCoexistence to AP. */
329#define MAX_TRIGGER_EVENT 64 330#define MAX_TRIGGER_EVENT 64
330struct rt_trigger_event_tab { 331struct rt_trigger_event_tab {
331 u8 EventANo; 332 u8 EventANo;
@@ -357,14 +358,14 @@ struct PACKED rt_bss_2040_intolerant_ch_report {
357 u8 ChList[0]; 358 u8 ChList[0];
358}; 359};
359 360
360/* The structure for channel switch annoucement IE. This is in 802.11n D3.03 */ 361/* The structure for channel switch announcement IE. This is in 802.11n D3.03 */
361struct PACKED rt_cha_switch_announce_ie { 362struct PACKED rt_cha_switch_announce_ie {
362 u8 SwitchMode; /*channel switch mode */ 363 u8 SwitchMode; /*channel switch mode */
363 u8 NewChannel; /* */ 364 u8 NewChannel; /* */
364 u8 SwitchCount; /* */ 365 u8 SwitchCount; /* */
365}; 366};
366 367
367/* The structure for channel switch annoucement IE. This is in 802.11n D3.03 */ 368/* The structure for channel switch announcement IE. This is in 802.11n D3.03 */
368struct PACKED rt_sec_cha_offset_ie { 369struct PACKED rt_sec_cha_offset_ie {
369 u8 SecondaryChannelOffset; /* 1: Secondary above, 3: Secondary below, 0: no Secondary */ 370 u8 SecondaryChannelOffset; /* 1: Secondary above, 3: Secondary below, 0: no Secondary */
370}; 371};
@@ -377,7 +378,7 @@ struct rt_ht_phy_info {
377 u8 MCSSet[16]; 378 u8 MCSSet[16];
378}; 379};
379 380
380/*This structure substracts ralink supports from all 802.11n-related features. */ 381/*This structure subtracts ralink supports from all 802.11n-related features. */
381/*Features not listed here but contained in 802.11n spec are not supported in rt2860. */ 382/*Features not listed here but contained in 802.11n spec are not supported in rt2860. */
382struct rt_ht_capability { 383struct rt_ht_capability {
383 u16 ChannelWidth:1; 384 u16 ChannelWidth:1;
@@ -387,14 +388,14 @@ struct rt_ht_capability {
387 u16 ShortGIfor40:1; /*for40MHz */ 388 u16 ShortGIfor40:1; /*for40MHz */
388 u16 TxSTBC:1; 389 u16 TxSTBC:1;
389 u16 RxSTBC:2; /* 2 bits */ 390 u16 RxSTBC:2; /* 2 bits */
390 u16 AmsduEnable:1; /* Enable to transmit A-MSDU. Suggest disable. We should use A-MPDU to gain best benifit of 802.11n */ 391 u16 AmsduEnable:1; /* Enable to transmit A-MSDU. Suggest disable. We should use A-MPDU to gain best benefit of 802.11n */
391 u16 AmsduSize:1; /* Max receiving A-MSDU size */ 392 u16 AmsduSize:1; /* Max receiving A-MSDU size */
392 u16 rsv:5; 393 u16 rsv:5;
393 394
394 /*Substract from Addiont HT INFO IE */ 395 /*Substract from Addiont HT INFO IE */
395 u8 MaxRAmpduFactor:2; 396 u8 MaxRAmpduFactor:2;
396 u8 MpduDensity:3; 397 u8 MpduDensity:3;
397 u8 ExtChanOffset:2; /* Please not the difference with following u8 NewExtChannelOffset; from 802.11n */ 398 u8 ExtChanOffset:2; /* Please note the difference with following u8 NewExtChannelOffset; from 802.11n */
398 u8 RecomWidth:1; 399 u8 RecomWidth:1;
399 400
400 u16 OperaionMode:2; 401 u16 OperaionMode:2;
@@ -481,7 +482,7 @@ struct PACKED rt_ba_parm {
481 u16 AMSDUSupported:1; /* 0: not permitted 1: permitted */ 482 u16 AMSDUSupported:1; /* 0: not permitted 1: permitted */
482 u16 BAPolicy:1; /* 1: immediately BA 0:delayed BA */ 483 u16 BAPolicy:1; /* 1: immediately BA 0:delayed BA */
483 u16 TID:4; /* value of TC os TS */ 484 u16 TID:4; /* value of TC os TS */
484 u16 BufSize:10; /* number of buffe of size 2304 octetsr */ 485 u16 BufSize:10; /* number of buffer of size 2304 octetsr */
485}; 486};
486 487
487/* 2-byte BA Starting Seq CONTROL field */ 488/* 2-byte BA Starting Seq CONTROL field */
@@ -551,7 +552,7 @@ struct PACKED rt_frame_mtba_req {
551 BASEQ_CONTROL BAStartingSeq; 552 BASEQ_CONTROL BAStartingSeq;
552}; 553};
553 554
554/* Compressed format is mandantory in HT STA */ 555/* Compressed format is mandatory in HT STA */
555struct PACKED rt_frame_mtba { 556struct PACKED rt_frame_mtba {
556 struct rt_frame_control FC; 557 struct rt_frame_control FC;
557 u16 Duration; 558 u16 Duration;
@@ -647,7 +648,7 @@ struct PACKED rt_frame_ba {
647 u8 bitmask[8]; 648 u8 bitmask[8];
648}; 649};
649 650
650/* Radio Measuement Request Frame Format */ 651/* Radio Measurement Request Frame Format */
651struct PACKED rt_frame_rm_req_action { 652struct PACKED rt_frame_rm_req_action {
652 struct rt_header_802_11 Hdr; 653 struct rt_header_802_11 Hdr;
653 u8 Category; 654 u8 Category;
@@ -709,7 +710,7 @@ struct rt_edca_parm {
709 u8 Cwmin[4]; 710 u8 Cwmin[4];
710 u8 Cwmax[4]; 711 u8 Cwmax[4];
711 u16 Txop[4]; /* in unit of 32-us */ 712 u16 Txop[4]; /* in unit of 32-us */
712 BOOLEAN bACM[4]; /* 1: Admission Control of AC_BK is mandattory */ 713 BOOLEAN bACM[4]; /* 1: Admission Control of AC_BK is mandatory */
713}; 714};
714 715
715/* QBSS LOAD information from QAP's BEACON/ProbeRsp */ 716/* QBSS LOAD information from QAP's BEACON/ProbeRsp */
@@ -757,7 +758,7 @@ struct rt_wpa_ie {
757struct rt_bss_entry { 758struct rt_bss_entry {
758 u8 Bssid[MAC_ADDR_LEN]; 759 u8 Bssid[MAC_ADDR_LEN];
759 u8 Channel; 760 u8 Channel;
760 u8 CentralChannel; /*Store the wide-band central channel for 40MHz. .used in 40MHz AP. Or this is the same as Channel. */ 761 u8 CentralChannel; /*Store the wide-band central channel for 40MHz. used in 40MHz AP. Or this is the same as Channel. */
761 u8 BssType; 762 u8 BssType;
762 u16 AtimWin; 763 u16 AtimWin;
763 u16 BeaconPeriod; 764 u16 BeaconPeriod;
@@ -855,7 +856,7 @@ struct rt_state_machine {
855 STATE_MACHINE_FUNC *TransFunc; 856 STATE_MACHINE_FUNC *TransFunc;
856}; 857};
857 858
858/* MLME AUX data structure that hold temporarliy settings during a connection attempt. */ 859/* MLME AUX data structure that holds temporarliy settings during a connection attempt. */
859/* Once this attemp succeeds, all settings will be copy to pAd->StaActive. */ 860/* Once this attemp succeeds, all settings will be copy to pAd->StaActive. */
860/* A connection attempt (user set OID, roaming, CCX fast roaming,..) consists of */ 861/* A connection attempt (user set OID, roaming, CCX fast roaming,..) consists of */
861/* several steps (JOIN, AUTH, ASSOC or REASSOC) and may fail at any step. We purposely */ 862/* several steps (JOIN, AUTH, ASSOC or REASSOC) and may fail at any step. We purposely */
@@ -996,7 +997,7 @@ struct PACKED rt_rtmp_tx_rate_switch {
996#define MAC_TABLE_ASSOC_TIMEOUT 5 /* unit: sec */ 997#define MAC_TABLE_ASSOC_TIMEOUT 5 /* unit: sec */
997#define MAC_TABLE_FULL(Tab) ((Tab).size == MAX_LEN_OF_MAC_TABLE) 998#define MAC_TABLE_FULL(Tab) ((Tab).size == MAX_LEN_OF_MAC_TABLE)
998 999
999/* AP shall drop the sta if contine Tx fail count reach it. */ 1000/* AP shall drop the sta if continue Tx fail count reach it. */
1000#define MAC_ENTRY_LIFE_CHECK_CNT 20 /* packet cnt. */ 1001#define MAC_ENTRY_LIFE_CHECK_CNT 20 /* packet cnt. */
1001 1002
1002/* Value domain of pMacEntry->Sst */ 1003/* Value domain of pMacEntry->Sst */
diff --git a/drivers/staging/rt2860/oid.h b/drivers/staging/rt2860/oid.h
index 1704c27b2736..5a25f0d3cfeb 100644
--- a/drivers/staging/rt2860/oid.h
+++ b/drivers/staging/rt2860/oid.h
@@ -32,7 +32,8 @@
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 -------- ---------- ---------------------------------------------- 34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs 35 Name Date Modification logs
36 Justin P. Mattock 11/07/2010 Fix typos in comments
36*/ 37*/
37#ifndef _OID_H_ 38#ifndef _OID_H_
38#define _OID_H_ 39#define _OID_H_
@@ -78,7 +79,7 @@
78#define NDIS_802_11_LENGTH_RATES 8 79#define NDIS_802_11_LENGTH_RATES 8
79#define NDIS_802_11_LENGTH_RATES_EX 16 80#define NDIS_802_11_LENGTH_RATES_EX 16
80#define MAC_ADDR_LENGTH 6 81#define MAC_ADDR_LENGTH 6
81/*#define MAX_NUM_OF_CHS 49 // 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL terminationc */ 82/*#define MAX_NUM_OF_CHS 49 // 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL termination */
82#define MAX_NUM_OF_CHS 54 /* 14 channels @2.4G + 12@UNII(lower/middle) + 16@HiperLAN2 + 11@UNII(upper) + 0 @Japan + 1 as NULL termination */ 83#define MAX_NUM_OF_CHS 54 /* 14 channels @2.4G + 12@UNII(lower/middle) + 16@HiperLAN2 + 11@UNII(upper) + 0 @Japan + 1 as NULL termination */
83#define MAX_NUMBER_OF_EVENT 10 /* entry # in EVENT table */ 84#define MAX_NUMBER_OF_EVENT 10 /* entry # in EVENT table */
84#define MAX_NUMBER_OF_MAC 32 /* if MAX_MBSSID_NUM is 8, this value can't be larger than 211 */ 85#define MAX_NUMBER_OF_MAC 32 /* if MAX_MBSSID_NUM is 8, this value can't be larger than 211 */
@@ -87,7 +88,7 @@
87#define MAX_NUMBER_OF_DLS_ENTRY 4 88#define MAX_NUMBER_OF_DLS_ENTRY 4
88 89
89#define RT_QUERY_SIGNAL_CONTEXT 0x0402 90#define RT_QUERY_SIGNAL_CONTEXT 0x0402
90#define RT_SET_IAPP_PID 0x0404 91#define RT_SET_IAPP_PID 0x0404
91#define RT_SET_APD_PID 0x0405 92#define RT_SET_APD_PID 0x0405
92#define RT_SET_DEL_MAC_ENTRY 0x0406 93#define RT_SET_DEL_MAC_ENTRY 0x0406
93#define RT_QUERY_EVENT_TABLE 0x0407 94#define RT_QUERY_EVENT_TABLE 0x0407
@@ -610,7 +611,7 @@ struct rt_802_11_event_log {
610 611
611struct rt_802_11_event_table { 612struct rt_802_11_event_table {
612 unsigned long Num; 613 unsigned long Num;
613 unsigned long Rsv; /* to align Log[] at LARGE_INEGER boundary */ 614 unsigned long Rsv; /* to align Log[] at LARGE_INTEGER boundary */
614 struct rt_802_11_event_log Log[MAX_NUMBER_OF_EVENT]; 615 struct rt_802_11_event_log Log[MAX_NUMBER_OF_EVENT];
615}; 616};
616 617
@@ -721,9 +722,9 @@ struct rt_802_11_tx_rates {
721#define AUTH_FAIL 0x4 /* Open authentication fail */ 722#define AUTH_FAIL 0x4 /* Open authentication fail */
722#define AUTH_FAIL_KEYS 0x5 /* Shared authentication fail */ 723#define AUTH_FAIL_KEYS 0x5 /* Shared authentication fail */
723#define ASSOC_FAIL 0x6 /* Association failed */ 724#define ASSOC_FAIL 0x6 /* Association failed */
724#define EAP_MIC_FAILURE 0x7 /* Deauthencation because MIC failure */ 725#define EAP_MIC_FAILURE 0x7 /* Deauthentication because MIC failure */
725#define EAP_4WAY_TIMEOUT 0x8 /* Deauthencation on 4-way handshake timeout */ 726#define EAP_4WAY_TIMEOUT 0x8 /* Deauthentication on 4-way handshake timeout */
726#define EAP_GROUP_KEY_TIMEOUT 0x9 /* Deauthencation on group key handshake timeout */ 727#define EAP_GROUP_KEY_TIMEOUT 0x9 /* Deauthentication on group key handshake timeout */
727#define EAP_SUCCESS 0xa /* EAP succeed */ 728#define EAP_SUCCESS 0xa /* EAP succeed */
728#define DETECT_RADAR_SIGNAL 0xb /* Radar signal occur in current channel */ 729#define DETECT_RADAR_SIGNAL 0xb /* Radar signal occur in current channel */
729#define EXTRA_INFO_MAX 0xb /* Indicate Last OID */ 730#define EXTRA_INFO_MAX 0xb /* Indicate Last OID */
diff --git a/drivers/staging/rt2860/pci_main_dev.c b/drivers/staging/rt2860/pci_main_dev.c
index 321facd6b0ab..25fbb1880ff2 100644
--- a/drivers/staging/rt2860/pci_main_dev.c
+++ b/drivers/staging/rt2860/pci_main_dev.c
@@ -31,7 +31,8 @@
31 Create and register network interface for PCI based chipsets in Linux platform. 31 Create and register network interface for PCI based chipsets in Linux platform.
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 Justin P. Mattock 11/07/2010 Fix typos in some comments
35 -------- ---------- ---------------------------------------------- 36 -------- ---------- ----------------------------------------------
36*/ 37*/
37 38
@@ -40,8 +41,8 @@
40#include <linux/slab.h> 41#include <linux/slab.h>
41 42
42/* Following information will be show when you run 'modinfo' */ 43/* Following information will be show when you run 'modinfo' */
43/* *** If you have a solution for the bug in current version of driver, please mail to me. */ 44/* If you have a solution for a bug in current version of driver, please e-mail me. */
44/* Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. *** */ 45/* Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. */
45MODULE_AUTHOR("Jett Chen <jett_chen@ralinktech.com>"); 46MODULE_AUTHOR("Jett Chen <jett_chen@ralinktech.com>");
46MODULE_DESCRIPTION("RT2860/RT3090 Wireless Lan Linux Driver"); 47MODULE_DESCRIPTION("RT2860/RT3090 Wireless Lan Linux Driver");
47MODULE_LICENSE("GPL"); 48MODULE_LICENSE("GPL");
@@ -50,9 +51,6 @@ MODULE_ALIAS("rt3090sta");
50/* */ 51/* */
51/* Function declarations */ 52/* Function declarations */
52/* */ 53/* */
53extern int rt28xx_close(IN struct net_device *net_dev);
54extern int rt28xx_open(struct net_device *net_dev);
55
56static void __devexit rt2860_remove_one(struct pci_dev *pci_dev); 54static void __devexit rt2860_remove_one(struct pci_dev *pci_dev);
57static int __devinit rt2860_probe(struct pci_dev *pci_dev, 55static int __devinit rt2860_probe(struct pci_dev *pci_dev,
58 const struct pci_device_id *ent); 56 const struct pci_device_id *ent);
@@ -205,7 +203,7 @@ static int rt2860_resume(struct pci_dev *pci_dev)
205 203
206 /* initialize device before it's used by a driver */ 204 /* initialize device before it's used by a driver */
207 if (pci_enable_device(pci_dev)) { 205 if (pci_enable_device(pci_dev)) {
208 printk("pci enable fail!\n"); 206 printk(KERN_ERR "rt2860: pci enable fail!\n");
209 return 0; 207 return 0;
210 } 208 }
211 209
@@ -599,7 +597,7 @@ void RTMPInitPCIeLinkCtrlValue(struct rt_rtmp_adapter *pAd)
599 DBGPRINT_RAW(RT_DEBUG_ERROR, 597 DBGPRINT_RAW(RT_DEBUG_ERROR,
600 (" AUX_CTRL = 0x%32x\n", MacValue)); 598 (" AUX_CTRL = 0x%32x\n", MacValue));
601 599
602 /* for RT30xx F and after, PCIe infterface, and for power solution 3 */ 600 /* for RT30xx F and after, PCIe interface, and for power solution 3 */
603 if ((IS_VERSION_AFTER_F(pAd)) 601 if ((IS_VERSION_AFTER_F(pAd))
604 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode >= 2) 602 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode >= 2)
605 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode <= 3)) { 603 && (pAd->StaCfg.PSControl.field.rt30xxPowerMode <= 3)) {
@@ -902,7 +900,7 @@ void RTMPPCIeLinkCtrlValueRestore(struct rt_rtmp_adapter *pAd, u8 Level)
902 Configuration); 900 Configuration);
903 if ((Configuration != 0) && (Configuration != 0xFFFF)) { 901 if ((Configuration != 0) && (Configuration != 0xFFFF)) {
904 Configuration &= 0xfefc; 902 Configuration &= 0xfefc;
905 /* If call from interface down, restore to orginial setting. */ 903 /* If call from interface down, restore to original setting. */
906 if (Level == RESTORE_CLOSE) 904 if (Level == RESTORE_CLOSE)
907 Configuration |= pAd->HostLnkCtrlConfiguration; 905 Configuration |= pAd->HostLnkCtrlConfiguration;
908 else 906 else
@@ -924,7 +922,7 @@ void RTMPPCIeLinkCtrlValueRestore(struct rt_rtmp_adapter *pAd, u8 Level)
924 Configuration); 922 Configuration);
925 if ((Configuration != 0) && (Configuration != 0xFFFF)) { 923 if ((Configuration != 0) && (Configuration != 0xFFFF)) {
926 Configuration &= 0xfefc; 924 Configuration &= 0xfefc;
927 /* If call from interface down, restore to orginial setting. */ 925 /* If call from interface down, restore to original setting. */
928 if (Level == RESTORE_CLOSE) 926 if (Level == RESTORE_CLOSE)
929 Configuration |= pAd->RLnkCtrlConfiguration; 927 Configuration |= pAd->RLnkCtrlConfiguration;
930 else 928 else
@@ -1106,12 +1104,12 @@ void RTMPrt3xSetPCIePowerLinkCtrl(struct rt_rtmp_adapter *pAd)
1106 if (pos != 0) 1104 if (pos != 0)
1107 pAd->HostLnkCtrlOffset = pos + PCI_EXP_LNKCTL; 1105 pAd->HostLnkCtrlOffset = pos + PCI_EXP_LNKCTL;
1108 1106
1109 /* If configurared to turn on L1. */ 1107 /* If configured to turn on L1. */
1110 HostConfiguration = 0; 1108 HostConfiguration = 0;
1111 if (pAd->StaCfg.PSControl.field.rt30xxForceASPMTest == 1) { 1109 if (pAd->StaCfg.PSControl.field.rt30xxForceASPMTest == 1) {
1112 DBGPRINT(RT_DEBUG_TRACE, ("Enter,PSM : Force ASPM\n")); 1110 DBGPRINT(RT_DEBUG_TRACE, ("Enter,PSM : Force ASPM\n"));
1113 1111
1114 /* Skip non-exist deice right away */ 1112 /* Skip non-exist device right away */
1115 if ((pAd->HostLnkCtrlOffset != 0)) { 1113 if ((pAd->HostLnkCtrlOffset != 0)) {
1116 PCI_REG_READ_WORD(pObj->parent_pci_dev, 1114 PCI_REG_READ_WORD(pObj->parent_pci_dev,
1117 pAd->HostLnkCtrlOffset, 1115 pAd->HostLnkCtrlOffset,
diff --git a/drivers/staging/rt2860/rt_linux.c b/drivers/staging/rt2860/rt_linux.c
index abfeea11721d..728864e18a18 100644
--- a/drivers/staging/rt2860/rt_linux.c
+++ b/drivers/staging/rt2860/rt_linux.c
@@ -321,7 +321,7 @@ int RTMPCloneNdisPacket(struct rt_rtmp_adapter *pAd,
321 321
322 RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS); 322 RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS);
323 323
324 printk("###Clone###\n"); 324 printk(KERN_DEBUG "###Clone###\n");
325 325
326 return NDIS_STATUS_SUCCESS; 326 return NDIS_STATUS_SUCCESS;
327} 327}
@@ -343,9 +343,8 @@ int RTMPAllocateNdisPacket(struct rt_rtmp_adapter *pAd,
343 RTMP_PKT_TAIL_PADDING); 343 RTMP_PKT_TAIL_PADDING);
344 if (pPacket == NULL) { 344 if (pPacket == NULL) {
345 *ppPacket = NULL; 345 *ppPacket = NULL;
346#ifdef DEBUG 346 pr_devel("RTMPAllocateNdisPacket Fail\n");
347 printk("RTMPAllocateNdisPacket Fail\n"); 347
348#endif
349 return NDIS_STATUS_FAILURE; 348 return NDIS_STATUS_FAILURE;
350 } 349 }
351 /* 2. clone the frame content */ 350 /* 2. clone the frame content */
@@ -601,15 +600,15 @@ void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen)
601 return; 600 return;
602 601
603 pt = pSrcBufVA; 602 pt = pSrcBufVA;
604 printk("%s: %p, len = %d\n", str, pSrcBufVA, SrcBufLen); 603 printk(KERN_DEBUG "%s: %p, len = %d\n", str, pSrcBufVA, SrcBufLen);
605 for (x = 0; x < SrcBufLen; x++) { 604 for (x = 0; x < SrcBufLen; x++) {
606 if (x % 16 == 0) 605 if (x % 16 == 0)
607 printk("0x%04x : ", x); 606 printk(KERN_DEBUG "0x%04x : ", x);
608 printk("%02x ", ((unsigned char)pt[x])); 607 printk(KERN_DEBUG "%02x ", ((unsigned char)pt[x]));
609 if (x % 16 == 15) 608 if (x % 16 == 15)
610 printk("\n"); 609 printk(KERN_DEBUG "\n");
611 } 610 }
612 printk("\n"); 611 printk(KERN_DEBUG "\n");
613} 612}
614 613
615/* 614/*
@@ -767,13 +766,13 @@ void send_monitor_packets(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk)
767 /* QOS */ 766 /* QOS */
768 if (pRxBlk->pHeader->FC.SubType & 0x08) { 767 if (pRxBlk->pHeader->FC.SubType & 0x08) {
769 header_len += 2; 768 header_len += 2;
770 /* Data skip QOS contorl field */ 769 /* Data skip QOS control field */
771 pRxBlk->DataSize -= 2; 770 pRxBlk->DataSize -= 2;
772 } 771 }
773 /* Order bit: A-Ralink or HTC+ */ 772 /* Order bit: A-Ralink or HTC+ */
774 if (pRxBlk->pHeader->FC.Order) { 773 if (pRxBlk->pHeader->FC.Order) {
775 header_len += 4; 774 header_len += 4;
776 /* Data skip HTC contorl field */ 775 /* Data skip HTC control field */
777 pRxBlk->DataSize -= 4; 776 pRxBlk->DataSize -= 4;
778 } 777 }
779 /* Copy Header */ 778 /* Copy Header */
@@ -854,7 +853,7 @@ void send_monitor_packets(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk)
854 RSSI1, 853 RSSI1,
855 RSSI_1), 854 RSSI_1),
856 ConvertToRssi(pAd, pRxBlk->pRxWI->RSSI2, 855 ConvertToRssi(pAd, pRxBlk->pRxWI->RSSI2,
857 RSSI_2));; 856 RSSI_2));
858 857
859 ph->signal.did = DIDmsg_lnxind_wlansniffrm_signal; 858 ph->signal.did = DIDmsg_lnxind_wlansniffrm_signal;
860 ph->signal.status = 0; 859 ph->signal.status = 0;
@@ -926,7 +925,7 @@ int RtmpOSIRQRequest(struct net_device *pNetDev)
926 request_irq(_pObj->pci_dev->irq, rt2860_interrupt, SA_SHIRQ, 925 request_irq(_pObj->pci_dev->irq, rt2860_interrupt, SA_SHIRQ,
927 (net_dev)->name, (net_dev)); 926 (net_dev)->name, (net_dev));
928 if (retval != 0) 927 if (retval != 0)
929 printk("RT2860: request_irq ERROR(%d)\n", retval); 928 printk(KERN_ERR "rt2860: request_irq ERROR(%d)\n", retval);
930 } 929 }
931 930
932 return retval; 931 return retval;
@@ -1022,7 +1021,7 @@ int RtmpOSTaskKill(struct rt_rtmp_os_task *pTask)
1022 } 1021 }
1023#else 1022#else
1024 CHECK_PID_LEGALITY(pTask->taskPID) { 1023 CHECK_PID_LEGALITY(pTask->taskPID) {
1025 printk("Terminate the task(%s) with pid(%d)!\n", 1024 printk(KERN_INFO "Terminate the task(%s) with pid(%d)!\n",
1026 pTask->taskName, GET_PID_NUMBER(pTask->taskPID)); 1025 pTask->taskName, GET_PID_NUMBER(pTask->taskPID));
1027 mb(); 1026 mb();
1028 pTask->task_killed = 1; 1027 pTask->task_killed = 1;
@@ -1175,7 +1174,7 @@ int RtmpOSNetDevAddrSet(struct net_device *pNetDev, u8 *pMacAddr)
1175 net_dev = pNetDev; 1174 net_dev = pNetDev;
1176 GET_PAD_FROM_NET_DEV(pAd, net_dev); 1175 GET_PAD_FROM_NET_DEV(pAd, net_dev);
1177 1176
1178 /* work-around for the SuSE due to it has it's own interface name management system. */ 1177 /* work-around for SuSE, due to them having their own interface name management system. */
1179 { 1178 {
1180 NdisZeroMemory(pAd->StaCfg.dev_name, 16); 1179 NdisZeroMemory(pAd->StaCfg.dev_name, 16);
1181 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, 1180 NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name,
@@ -1300,7 +1299,7 @@ int RtmpOSNetDevAttach(struct net_device *pNetDev,
1300 int ret, rtnl_locked = FALSE; 1299 int ret, rtnl_locked = FALSE;
1301 1300
1302 DBGPRINT(RT_DEBUG_TRACE, ("RtmpOSNetDevAttach()--->\n")); 1301 DBGPRINT(RT_DEBUG_TRACE, ("RtmpOSNetDevAttach()--->\n"));
1303 /* If we need hook some callback function to the net device structrue, now do it. */ 1302 /* If we need hook some callback function to the net device structure, now do it. */
1304 if (pDevOpHook) { 1303 if (pDevOpHook) {
1305 struct rt_rtmp_adapter *pAd = NULL; 1304 struct rt_rtmp_adapter *pAd = NULL;
1306 1305
@@ -1351,10 +1350,10 @@ struct net_device *RtmpOSNetDevCreate(struct rt_rtmp_adapter *pAd,
1351 return NULL; 1350 return NULL;
1352 } 1351 }
1353 1352
1354 /* find a available interface name, max 32 interfaces */ 1353 /* find an available interface name, max 32 interfaces */
1355 status = RtmpOSNetDevRequestName(pAd, pNetDev, pNamePrefix, devNum); 1354 status = RtmpOSNetDevRequestName(pAd, pNetDev, pNamePrefix, devNum);
1356 if (status != NDIS_STATUS_SUCCESS) { 1355 if (status != NDIS_STATUS_SUCCESS) {
1357 /* error! no any available ra name can be used! */ 1356 /* error! no available ra name can be used! */
1358 DBGPRINT(RT_DEBUG_ERROR, 1357 DBGPRINT(RT_DEBUG_ERROR,
1359 ("Assign interface name (%s with suffix 0~32) failed...\n", 1358 ("Assign interface name (%s with suffix 0~32) failed...\n",
1360 pNamePrefix)); 1359 pNamePrefix));
diff --git a/drivers/staging/rt2860/rt_linux.h b/drivers/staging/rt2860/rt_linux.h
index 5acedf18b1ab..92ff5438e777 100644
--- a/drivers/staging/rt2860/rt_linux.h
+++ b/drivers/staging/rt2860/rt_linux.h
@@ -30,7 +30,8 @@
30 Abstract: 30 Abstract:
31 31
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 Justin P. Mattock 11/07/2010 Fix typo in a comment
34 --------- ---------- ---------------------------------------------- 35 --------- ---------- ----------------------------------------------
35*/ 36*/
36 37
@@ -422,11 +423,7 @@ do{ \
422 423
423#define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt) 424#define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt)
424 425
425#define DBGPRINT_ERR(Fmt) \ 426#define DBGPRINT_ERR(fmt, args...) printk(KERN_ERR fmt, ##args)
426{ \
427 printk("ERROR! "); \
428 printk Fmt; \
429}
430 427
431#define DBGPRINT_S(Status, Fmt) \ 428#define DBGPRINT_S(Status, Fmt) \
432{ \ 429{ \
@@ -726,7 +723,7 @@ void linux_pci_unmap_single(struct rt_rtmp_adapter *pAd, dma_addr_t dma_addr,
726#define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7]) 723#define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7])
727 724
728/* */ 725/* */
729/* Sepcific Pakcet Type definition */ 726/* Specific Packet Type definition */
730/* */ 727/* */
731#define RTMP_PACKET_SPECIFIC_CB_OFFSET 11 728#define RTMP_PACKET_SPECIFIC_CB_OFFSET 11
732 729
diff --git a/drivers/staging/rt2860/rt_main_dev.c b/drivers/staging/rt2860/rt_main_dev.c
index ad60ceaf4b88..701561d6b6fd 100644
--- a/drivers/staging/rt2860/rt_main_dev.c
+++ b/drivers/staging/rt2860/rt_main_dev.c
@@ -31,7 +31,8 @@
31 Create and register network interface. 31 Create and register network interface.
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 Justin P. Mattock 11/07/2010 Fix typos in comments
35 -------- ---------- ---------------------------------------------- 36 -------- ---------- ----------------------------------------------
36*/ 37*/
37 38
@@ -101,8 +102,8 @@ int MainVirtualIF_close(IN struct net_device *net_dev)
101 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { 102 (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) {
102 struct rt_mlme_disassoc_req DisReq; 103 struct rt_mlme_disassoc_req DisReq;
103 struct rt_mlme_queue_elem *MsgElem = 104 struct rt_mlme_queue_elem *MsgElem =
104 (struct rt_mlme_queue_elem *)kmalloc(sizeof(struct rt_mlme_queue_elem), 105 kmalloc(sizeof(struct rt_mlme_queue_elem),
105 MEM_ALLOC_FLAG); 106 MEM_ALLOC_FLAG);
106 107
107 if (MsgElem) { 108 if (MsgElem) {
108 COPY_MAC_ADDR(DisReq.Addr, 109 COPY_MAC_ADDR(DisReq.Addr,
@@ -234,7 +235,7 @@ int rt28xx_close(struct net_device *dev)
234 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_CLOSE); 235 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_CLOSE);
235#endif /* RTMP_MAC_PCI // */ 236#endif /* RTMP_MAC_PCI // */
236 237
237 /* If dirver doesn't wake up firmware here, */ 238 /* If driver doesn't wake up firmware here, */
238 /* NICLoadFirmware will hang forever when interface is up again. */ 239 /* NICLoadFirmware will hang forever when interface is up again. */
239 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) { 240 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) {
240 AsicForceWakeup(pAd, TRUE); 241 AsicForceWakeup(pAd, TRUE);
@@ -310,8 +311,8 @@ int rt28xx_close(struct net_device *dev)
310 RTMP_ASIC_INTERRUPT_DISABLE(pAd); 311 RTMP_ASIC_INTERRUPT_DISABLE(pAd);
311 } 312 }
312 /* Receive packets to clear DMA index after disable interrupt. */ 313 /* Receive packets to clear DMA index after disable interrupt. */
313 /*RTMPHandleRxDoneInterrupt(pAd); */ 314 /* RTMPHandleRxDoneInterrupt(pAd); */
314 /* put to radio off to save power when driver unload. After radiooff, can't write /read register. So need to finish all */ 315 /* put radio off to save power when driver unloads. After radiooff, can't write/read register, so need to finish all. */
315 /* register access before Radio off. */ 316 /* register access before Radio off. */
316 317
317 brc = RT28xxPciAsicRadioOff(pAd, RTMP_HALT, 0); 318 brc = RT28xxPciAsicRadioOff(pAd, RTMP_HALT, 0);
@@ -420,7 +421,7 @@ int rt28xx_open(struct net_device *dev)
420 { 421 {
421 u32 reg = 0; 422 u32 reg = 0;
422 RTMP_IO_READ32(pAd, 0x1300, &reg); /* clear garbage interrupts */ 423 RTMP_IO_READ32(pAd, 0x1300, &reg); /* clear garbage interrupts */
423 printk("0x1300 = %08x\n", reg); 424 printk(KERN_DEBUG "0x1300 = %08x\n", reg);
424 } 425 }
425 426
426 { 427 {
@@ -724,7 +725,8 @@ Note:
724int AdapterBlockAllocateMemory(void *handle, void ** ppAd) 725int AdapterBlockAllocateMemory(void *handle, void ** ppAd)
725{ 726{
726 727
727 *ppAd = (void *)vmalloc(sizeof(struct rt_rtmp_adapter)); /*pci_alloc_consistent(pci_dev, sizeof(struct rt_rtmp_adapter), phy_addr); */ 728 *ppAd = vmalloc(sizeof(struct rt_rtmp_adapter));
729 /* pci_alloc_consistent(pci_dev, sizeof(struct rt_rtmp_adapter), phy_addr); */
728 730
729 if (*ppAd) { 731 if (*ppAd) {
730 NdisZeroMemory(*ppAd, sizeof(struct rt_rtmp_adapter)); 732 NdisZeroMemory(*ppAd, sizeof(struct rt_rtmp_adapter));
diff --git a/drivers/staging/rt2860/rt_pci_rbus.c b/drivers/staging/rt2860/rt_pci_rbus.c
index 3004be6da003..e5fb67cd9a68 100644
--- a/drivers/staging/rt2860/rt_pci_rbus.c
+++ b/drivers/staging/rt2860/rt_pci_rbus.c
@@ -31,7 +31,8 @@
31 Create and register network interface. 31 Create and register network interface.
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 Justin P. Mattock 11/07/2010 Fix a typo
35 -------- ---------- ---------------------------------------------- 36 -------- ---------- ----------------------------------------------
36*/ 37*/
37 38
@@ -356,7 +357,7 @@ static void mgmt_dma_done_tasklet(unsigned long data)
356 357
357 RTMPHandleMgmtRingDmaDoneInterrupt(pAd); 358 RTMPHandleMgmtRingDmaDoneInterrupt(pAd);
358 359
359 /* if you use RTMP_SEM_LOCK, sometimes kernel will hang up, no any */ 360 /* if you use RTMP_SEM_LOCK, sometimes kernel will hang up, without any */
360 /* bug report output */ 361 /* bug report output */
361 RTMP_INT_LOCK(&pAd->irq_lock, flags); 362 RTMP_INT_LOCK(&pAd->irq_lock, flags);
362 /* 363 /*
@@ -787,7 +788,7 @@ IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance)
787} 788}
788 789
789/* 790/*
790 * invaild or writeback cache 791 * invalid or writeback cache
791 * and convert virtual address to physical address 792 * and convert virtual address to physical address
792 */ 793 */
793dma_addr_t linux_pci_map_single(struct rt_rtmp_adapter *pAd, void *ptr, 794dma_addr_t linux_pci_map_single(struct rt_rtmp_adapter *pAd, void *ptr,
diff --git a/drivers/staging/rt2860/rt_usb.c b/drivers/staging/rt2860/rt_usb.c
index bcfc0f54d2aa..eb037d2e04a2 100644
--- a/drivers/staging/rt2860/rt_usb.c
+++ b/drivers/staging/rt2860/rt_usb.c
@@ -32,7 +32,8 @@
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 -------- ---------- ---------------------------------------------- 34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs 35 Name Date Modification logs
36 Justin P. Mattock 11/07/2010 Fix some typos.
36 37
37*/ 38*/
38 39
@@ -40,25 +41,25 @@
40 41
41void dump_urb(struct urb *purb) 42void dump_urb(struct urb *purb)
42{ 43{
43 printk("urb :0x%08lx\n", (unsigned long)purb); 44 printk(KERN_DEBUG "urb :0x%08lx\n", (unsigned long)purb);
44 printk("\tdev :0x%08lx\n", (unsigned long)purb->dev); 45 printk(KERN_DEBUG "\tdev :0x%08lx\n", (unsigned long)purb->dev);
45 printk("\t\tdev->state :0x%d\n", purb->dev->state); 46 printk(KERN_DEBUG "\t\tdev->state :0x%d\n", purb->dev->state);
46 printk("\tpipe :0x%08x\n", purb->pipe); 47 printk(KERN_DEBUG "\tpipe :0x%08x\n", purb->pipe);
47 printk("\tstatus :%d\n", purb->status); 48 printk(KERN_DEBUG "\tstatus :%d\n", purb->status);
48 printk("\ttransfer_flags :0x%08x\n", purb->transfer_flags); 49 printk(KERN_DEBUG "\ttransfer_flags :0x%08x\n", purb->transfer_flags);
49 printk("\ttransfer_buffer :0x%08lx\n", 50 printk(KERN_DEBUG "\ttransfer_buffer :0x%08lx\n",
50 (unsigned long)purb->transfer_buffer); 51 (unsigned long)purb->transfer_buffer);
51 printk("\ttransfer_buffer_length:%d\n", purb->transfer_buffer_length); 52 printk(KERN_DEBUG "\ttransfer_buffer_length:%d\n", purb->transfer_buffer_length);
52 printk("\tactual_length :%d\n", purb->actual_length); 53 printk(KERN_DEBUG "\tactual_length :%d\n", purb->actual_length);
53 printk("\tsetup_packet :0x%08lx\n", 54 printk(KERN_DEBUG "\tsetup_packet :0x%08lx\n",
54 (unsigned long)purb->setup_packet); 55 (unsigned long)purb->setup_packet);
55 printk("\tstart_frame :%d\n", purb->start_frame); 56 printk(KERN_DEBUG "\tstart_frame :%d\n", purb->start_frame);
56 printk("\tnumber_of_packets :%d\n", purb->number_of_packets); 57 printk(KERN_DEBUG "\tnumber_of_packets :%d\n", purb->number_of_packets);
57 printk("\tinterval :%d\n", purb->interval); 58 printk(KERN_DEBUG "\tinterval :%d\n", purb->interval);
58 printk("\terror_count :%d\n", purb->error_count); 59 printk(KERN_DEBUG "\terror_count :%d\n", purb->error_count);
59 printk("\tcontext :0x%08lx\n", 60 printk(KERN_DEBUG "\tcontext :0x%08lx\n",
60 (unsigned long)purb->context); 61 (unsigned long)purb->context);
61 printk("\tcomplete :0x%08lx\n\n", 62 printk(KERN_DEBUG "\tcomplete :0x%08lx\n\n",
62 (unsigned long)purb->complete); 63 (unsigned long)purb->complete);
63} 64}
64 65
@@ -279,7 +280,7 @@ static void rtusb_dataout_complete(unsigned long data)
279 && !RTUSB_TEST_BULK_FLAG(pAd, 280 && !RTUSB_TEST_BULK_FLAG(pAd,
280 (fRTUSB_BULK_OUT_DATA_FRAG << 281 (fRTUSB_BULK_OUT_DATA_FRAG <<
281 BulkOutPipeId))) { 282 BulkOutPipeId))) {
282 /* Indicate There is data avaliable */ 283 /* Indicate There is data available */
283 RTUSB_SET_BULK_FLAG(pAd, 284 RTUSB_SET_BULK_FLAG(pAd,
284 (fRTUSB_BULK_OUT_DATA_NORMAL << 285 (fRTUSB_BULK_OUT_DATA_NORMAL <<
285 BulkOutPipeId)); 286 BulkOutPipeId));
@@ -335,7 +336,7 @@ static void rtusb_null_frame_done_tasklet(unsigned long data)
335 } 336 }
336 337
337 /* Always call Bulk routine, even reset bulk. */ 338 /* Always call Bulk routine, even reset bulk. */
338 /* The protectioon of rest bulk should be in BulkOut routine */ 339 /* The protection of rest bulk should be in BulkOut routine */
339 RTUSBKickBulkOut(pAd); 340 RTUSBKickBulkOut(pAd);
340} 341}
341 342
@@ -383,7 +384,7 @@ static void rtusb_rts_frame_done_tasklet(unsigned long data)
383 RTMP_SEM_UNLOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]); 384 RTMP_SEM_UNLOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]);
384 385
385 /* Always call Bulk routine, even reset bulk. */ 386 /* Always call Bulk routine, even reset bulk. */
386 /* The protectioon of rest bulk should be in BulkOut routine */ 387 /* The protection of rest bulk should be in BulkOut routine */
387 RTUSBKickBulkOut(pAd); 388 RTUSBKickBulkOut(pAd);
388 389
389} 390}
@@ -427,7 +428,7 @@ static void rtusb_pspoll_frame_done_tasklet(unsigned long data)
427 RTMP_SEM_UNLOCK(&pAd->BulkOutLock[0]); 428 RTMP_SEM_UNLOCK(&pAd->BulkOutLock[0]);
428 429
429 /* Always call Bulk routine, even reset bulk. */ 430 /* Always call Bulk routine, even reset bulk. */
430 /* The protectioon of rest bulk should be in BulkOut routine */ 431 /* The protection of rest bulk should be in BulkOut routine */
431 RTUSBKickBulkOut(pAd); 432 RTUSBKickBulkOut(pAd);
432 433
433} 434}
@@ -575,7 +576,7 @@ static void rtusb_mgmt_dma_done_tasklet(unsigned long data)
575 } else { 576 } else {
576 577
577 /* Always call Bulk routine, even reset bulk. */ 578 /* Always call Bulk routine, even reset bulk. */
578 /* The protectioon of rest bulk should be in BulkOut routine */ 579 /* The protection of rest bulk should be in BulkOut routine */
579 if (pAd->MgmtRing.TxSwFreeIdx < 580 if (pAd->MgmtRing.TxSwFreeIdx <
580 MGMT_RING_SIZE 581 MGMT_RING_SIZE
581 /* pMLMEContext->bWaitingBulkOut == TRUE */) { 582 /* pMLMEContext->bWaitingBulkOut == TRUE */) {
diff --git a/drivers/staging/rt2860/rtmp.h b/drivers/staging/rt2860/rtmp.h
index ca54e53b6603..70daaa4f9ac2 100644
--- a/drivers/staging/rt2860/rtmp.h
+++ b/drivers/staging/rt2860/rtmp.h
@@ -31,11 +31,12 @@
31 Miniport generic portion header file 31 Miniport generic portion header file
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 -------- ---------- ---------------------------------------------- 35 -------- ---------- ----------------------------------------------
36 Paul Lin 2002-08-01 created 36 Paul Lin 2002-08-01 created
37 James Tan 2002-09-06 modified (Revise NTCRegTable) 37 James Tan 2002-09-06 modified (Revise NTCRegTable)
38 John Chang 2004-09-06 modified for RT2600 38 John Chang 2004-09-06 modified for RT2600
39 Justin P. Mattock 11/07/2010 Fix some typos
39*/ 40*/
40#ifndef __RTMP_H__ 41#ifndef __RTMP_H__
41#define __RTMP_H__ 42#define __RTMP_H__
@@ -337,7 +338,7 @@ struct rt_rtmp_sg_list {
337#define LEAP_ON(_p) (((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) 338#define LEAP_ON(_p) (((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP)
338#define LEAP_CCKM_ON(_p) ((((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) && ((_p)->StaCfg.LeapAuthInfo.CCKM == TRUE)) 339#define LEAP_CCKM_ON(_p) ((((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) && ((_p)->StaCfg.LeapAuthInfo.CCKM == TRUE))
339 340
340/* if orginal Ethernet frame contains no LLC/SNAP, then an extra LLC/SNAP encap is required */ 341/* if original Ethernet frame contains no LLC/SNAP, then an extra LLC/SNAP encap is required */
341#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(_pBufVA, _pExtraLlcSnapEncap) \ 342#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(_pBufVA, _pExtraLlcSnapEncap) \
342{ \ 343{ \
343 if (((*(_pBufVA + 12) << 8) + *(_pBufVA + 13)) > 1500) { \ 344 if (((*(_pBufVA + 12) << 8) + *(_pBufVA + 13)) > 1500) { \
@@ -466,7 +467,7 @@ struct rt_rtmp_dmabuf {
466/* Control block (Descriptor) for all ring descriptor DMA operation, buffer must be */ 467/* Control block (Descriptor) for all ring descriptor DMA operation, buffer must be */
467/* contiguous physical memory. char stored the binding Rx packet descriptor */ 468/* contiguous physical memory. char stored the binding Rx packet descriptor */
468/* which won't be released, driver has to wait until upper layer return the packet */ 469/* which won't be released, driver has to wait until upper layer return the packet */
469/* before giveing up this rx ring descriptor to ASIC. NDIS_BUFFER is assocaited pair */ 470/* before giving up this rx ring descriptor to ASIC. NDIS_BUFFER is associated pair */
470/* to describe the packet buffer. For Tx, char stored the tx packet descriptor */ 471/* to describe the packet buffer. For Tx, char stored the tx packet descriptor */
471/* which driver should ACK upper layer when the tx is physically done or failed. */ 472/* which driver should ACK upper layer when the tx is physically done or failed. */
472/* */ 473/* */
@@ -602,7 +603,7 @@ struct rt_counter_ralink {
602}; 603};
603 604
604struct rt_counter_drs { 605struct rt_counter_drs {
605 /* to record the each TX rate's quality. 0 is best, the bigger the worse. */ 606 /* record each TX rate's quality. 0 is best, the bigger the worse. */
606 u16 TxQuality[MAX_STEP_OF_TX_RATE_SWITCH]; 607 u16 TxQuality[MAX_STEP_OF_TX_RATE_SWITCH];
607 u8 PER[MAX_STEP_OF_TX_RATE_SWITCH]; 608 u8 PER[MAX_STEP_OF_TX_RATE_SWITCH];
608 u8 TxRateUpPenalty; /* extra # of second penalty due to last unstable condition */ 609 u8 TxRateUpPenalty; /* extra # of second penalty due to last unstable condition */
@@ -719,7 +720,7 @@ struct rt_fragment_frame {
719/* Packet information for NdisQueryPacket */ 720/* Packet information for NdisQueryPacket */
720/* */ 721/* */
721struct rt_packet_info { 722struct rt_packet_info {
722 u32 PhysicalBufferCount; /* Physical breaks of buffer descripor chained */ 723 u32 PhysicalBufferCount; /* Physical breaks of buffer descriptor chained */
723 u32 BufferCount; /* Number of Buffer descriptor chained */ 724 u32 BufferCount; /* Number of Buffer descriptor chained */
724 u32 TotalPacketLength; /* Self explained */ 725 u32 TotalPacketLength; /* Self explained */
725 char *pFirstBuffer; /* Pointer to first buffer descriptor */ 726 char *pFirstBuffer; /* Pointer to first buffer descriptor */
@@ -846,8 +847,8 @@ typedef enum _ABGBAND_STATE_ {
846/* Power save method control */ 847/* Power save method control */
847typedef union _PS_CONTROL { 848typedef union _PS_CONTROL {
848 struct { 849 struct {
849 unsigned long EnablePSinIdle:1; /* Enable radio off when not connect to AP. radio on only when sitesurvey, */ 850 unsigned long EnablePSinIdle:1; /* Enable radio off when not connected to AP. radio on only when sitesurvey, */
850 unsigned long EnableNewPS:1; /* Enable new Chip power save fucntion . New method can only be applied in chip version after 2872. and PCIe. */ 851 unsigned long EnableNewPS:1; /* Enable new Chip power save function . New method can only be applied in chip version after 2872. and PCIe. */
851 unsigned long rt30xxPowerMode:2; /* Power Level Mode for rt30xx chip */ 852 unsigned long rt30xxPowerMode:2; /* Power Level Mode for rt30xx chip */
852 unsigned long rt30xxFollowHostASPM:1; /* Card Follows Host's setting for rt30xx chip. */ 853 unsigned long rt30xxFollowHostASPM:1; /* Card Follows Host's setting for rt30xx chip. */
853 unsigned long rt30xxForceASPMTest:1; /* Force enable L1 for rt30xx chip. This has higher priority than rt30xxFollowHostASPM Mode. */ 854 unsigned long rt30xxForceASPMTest:1; /* Force enable L1 for rt30xx chip. This has higher priority than rt30xxFollowHostASPM Mode. */
@@ -1117,8 +1118,8 @@ struct rt_beacon_sync {
1117 unsigned long TimIELocationInBeacon[HW_BEACON_MAX_COUNT]; 1118 unsigned long TimIELocationInBeacon[HW_BEACON_MAX_COUNT];
1118 unsigned long CapabilityInfoLocationInBeacon[HW_BEACON_MAX_COUNT]; 1119 unsigned long CapabilityInfoLocationInBeacon[HW_BEACON_MAX_COUNT];
1119 BOOLEAN EnableBeacon; /* trigger to enable beacon transmission. */ 1120 BOOLEAN EnableBeacon; /* trigger to enable beacon transmission. */
1120 u8 BeaconBitMap; /* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter need to change. */ 1121 u8 BeaconBitMap; /* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter needs to change. */
1121 u8 DtimBitOn; /* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter need to change. */ 1122 u8 DtimBitOn; /* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter needs to change. */
1122}; 1123};
1123#endif /* RTMP_MAC_USB // */ 1124#endif /* RTMP_MAC_USB // */
1124 1125
@@ -1211,7 +1212,7 @@ struct rt_common_config {
1211 /*BOOLEAN bAutoTxRateSwitch; */ 1212 /*BOOLEAN bAutoTxRateSwitch; */
1212 u8 MinTxRate; /* RATE_1, RATE_2, RATE_5_5, RATE_11 */ 1213 u8 MinTxRate; /* RATE_1, RATE_2, RATE_5_5, RATE_11 */
1213 u8 RtsRate; /* RATE_xxx */ 1214 u8 RtsRate; /* RATE_xxx */
1214 HTTRANSMIT_SETTING MlmeTransmit; /* MGMT frame PHY rate setting when operatin at Ht rate. */ 1215 HTTRANSMIT_SETTING MlmeTransmit; /* MGMT frame PHY rate setting when operation at Ht rate. */
1215 u8 MlmeRate; /* RATE_xxx, used to send MLME frames */ 1216 u8 MlmeRate; /* RATE_xxx, used to send MLME frames */
1216 u8 BasicMlmeRate; /* Default Rate for sending MLME frames */ 1217 u8 BasicMlmeRate; /* Default Rate for sending MLME frames */
1217 1218
@@ -1264,7 +1265,7 @@ struct rt_common_config {
1264 struct rt_ht_capability_ie HtCapability; 1265 struct rt_ht_capability_ie HtCapability;
1265 struct rt_add_ht_info_ie AddHTInfo; /* Useful as AP. */ 1266 struct rt_add_ht_info_ie AddHTInfo; /* Useful as AP. */
1266 /*This IE is used with channel switch announcement element when changing to a new 40MHz. */ 1267 /*This IE is used with channel switch announcement element when changing to a new 40MHz. */
1267 /*This IE is included in channel switch ammouncement frames 7.4.1.5, beacons, probe Rsp. */ 1268 /*This IE is included in channel switch announcement frames 7.4.1.5, beacons, probe Rsp. */
1268 struct rt_new_ext_chan_ie NewExtChanOffset; /*7.3.2.20A, 1 if extension channel is above the control channel, 3 if below, 0 if not present */ 1269 struct rt_new_ext_chan_ie NewExtChanOffset; /*7.3.2.20A, 1 if extension channel is above the control channel, 3 if below, 0 if not present */
1269 1270
1270 BOOLEAN bHTProtect; 1271 BOOLEAN bHTProtect;
@@ -1329,7 +1330,7 @@ struct rt_sta_admin_config {
1329 /* GROUP 1 - */ 1330 /* GROUP 1 - */
1330 /* User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe */ 1331 /* User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe */
1331 /* the user intended configuration, but not necessary fully equal to the final */ 1332 /* the user intended configuration, but not necessary fully equal to the final */
1332 /* settings in ACTIVE BSS after negotiation/compromize with the BSS holder (either */ 1333 /* settings in ACTIVE BSS after negotiation/compromise with the BSS holder (either */
1333 /* AP or IBSS holder). */ 1334 /* AP or IBSS holder). */
1334 /* Once initialized, user configuration can only be changed via OID_xxx */ 1335 /* Once initialized, user configuration can only be changed via OID_xxx */
1335 u8 BssType; /* BSS_INFRA or BSS_ADHOC */ 1336 u8 BssType; /* BSS_INFRA or BSS_ADHOC */
@@ -1386,12 +1387,12 @@ struct rt_sta_admin_config {
1386 1387
1387 /* For WPA countermeasures */ 1388 /* For WPA countermeasures */
1388 unsigned long LastMicErrorTime; /* record last MIC error time */ 1389 unsigned long LastMicErrorTime; /* record last MIC error time */
1389 unsigned long MicErrCnt; /* Should be 0, 1, 2, then reset to zero (after disassoiciation). */ 1390 unsigned long MicErrCnt; /* Should be 0, 1, 2, then reset to zero (after disassociation). */
1390 BOOLEAN bBlockAssoc; /* Block associate attempt for 60 seconds after counter measure occurred. */ 1391 BOOLEAN bBlockAssoc; /* Block associate attempt for 60 seconds after counter measure occurred. */
1391 /* For WPA-PSK supplicant state */ 1392 /* For WPA-PSK supplicant state */
1392 WPA_STATE WpaState; /* Default is SS_NOTUSE and handled by microsoft 802.1x */ 1393 WPA_STATE WpaState; /* Default is SS_NOTUSE and handled by microsoft 802.1x */
1393 u8 ReplayCounter[8]; 1394 u8 ReplayCounter[8];
1394 u8 ANonce[32]; /* ANonce for WPA-PSK from aurhenticator */ 1395 u8 ANonce[32]; /* ANonce for WPA-PSK from auhenticator */
1395 u8 SNonce[32]; /* SNonce for WPA-PSK */ 1396 u8 SNonce[32]; /* SNonce for WPA-PSK */
1396 1397
1397 u8 LastSNR0; /* last received BEACON's SNR */ 1398 u8 LastSNR0; /* last received BEACON's SNR */
@@ -1423,7 +1424,7 @@ struct rt_sta_admin_config {
1423 u8 RSNIE_Len; 1424 u8 RSNIE_Len;
1424 u8 RSN_IE[MAX_LEN_OF_RSNIE]; /* The content saved here should be little-endian format. */ 1425 u8 RSN_IE[MAX_LEN_OF_RSNIE]; /* The content saved here should be little-endian format. */
1425 1426
1426 unsigned long CLBusyBytes; /* Save the total bytes received durning channel load scan time */ 1427 unsigned long CLBusyBytes; /* Save the total bytes received during channel load scan time */
1427 u16 RPIDensity[8]; /* Array for RPI density collection */ 1428 u16 RPIDensity[8]; /* Array for RPI density collection */
1428 1429
1429 u8 RMReqCnt; /* Number of measurement request saved. */ 1430 u8 RMReqCnt; /* Number of measurement request saved. */
@@ -1489,9 +1490,9 @@ struct rt_sta_admin_config {
1489 BOOLEAN bForceTxBurst; /* 1: force enble TX PACKET BURST, 0: disable */ 1490 BOOLEAN bForceTxBurst; /* 1: force enble TX PACKET BURST, 0: disable */
1490}; 1491};
1491 1492
1492/* This data structure keep the current active BSS/IBSS's configuration that this STA */ 1493/* This data structure keeps the current active BSS/IBSS's configuration that this STA */
1493/* had agreed upon joining the network. Which means these parameters are usually decided */ 1494/* had agreed upon joining the network. Which means these parameters are usually decided */
1494/* by the BSS/IBSS creator instead of user configuration. Data in this data structurre */ 1495/* by the BSS/IBSS creator instead of user configuration. Data in this data structure */
1495/* is valid only when either ADHOC_ON(pAd) or INFRA_ON(pAd) is TRUE. */ 1496/* is valid only when either ADHOC_ON(pAd) or INFRA_ON(pAd) is TRUE. */
1496/* Normally, after SCAN or failed roaming attempts, we need to recover back to */ 1497/* Normally, after SCAN or failed roaming attempts, we need to recover back to */
1497/* the current active settings. */ 1498/* the current active settings. */
@@ -1519,7 +1520,7 @@ struct rt_mac_table_entry {
1519 /*Choose 1 from ValidAsWDS and ValidAsCLI to validize. */ 1520 /*Choose 1 from ValidAsWDS and ValidAsCLI to validize. */
1520 BOOLEAN ValidAsCLI; /* Sta mode, set this TRUE after Linkup,too. */ 1521 BOOLEAN ValidAsCLI; /* Sta mode, set this TRUE after Linkup,too. */
1521 BOOLEAN ValidAsWDS; /* This is WDS Entry. only for AP mode. */ 1522 BOOLEAN ValidAsWDS; /* This is WDS Entry. only for AP mode. */
1522 BOOLEAN ValidAsApCli; /*This is a AP-Client entry, only for AP mode which enable AP-Client functions. */ 1523 BOOLEAN ValidAsApCli; /* This is a AP-Client entry, only for AP mode which enable AP-Client functions. */
1523 BOOLEAN ValidAsMesh; 1524 BOOLEAN ValidAsMesh;
1524 BOOLEAN ValidAsDls; /* This is DLS Entry. only for STA mode. */ 1525 BOOLEAN ValidAsDls; /* This is DLS Entry. only for STA mode. */
1525 BOOLEAN isCached; 1526 BOOLEAN isCached;
@@ -1527,7 +1528,7 @@ struct rt_mac_table_entry {
1527 1528
1528 u8 EnqueueEapolStartTimerRunning; /* Enqueue EAPoL-Start for triggering EAP SM */ 1529 u8 EnqueueEapolStartTimerRunning; /* Enqueue EAPoL-Start for triggering EAP SM */
1529 /*jan for wpa */ 1530 /*jan for wpa */
1530 /* record which entry revoke MIC Failure , if it leaves the BSS itself, AP won't update aMICFailTime MIB */ 1531 /* record which entry revoke MIC Failure, if it leaves the BSS itself, AP won't update aMICFailTime MIB */
1531 u8 CMTimerRunning; 1532 u8 CMTimerRunning;
1532 u8 apidx; /* MBSS number */ 1533 u8 apidx; /* MBSS number */
1533 u8 RSNIE_Len; 1534 u8 RSNIE_Len;
@@ -1722,7 +1723,7 @@ struct rt_rtmp_adapter {
1722 unsigned long Rt3xxRalinkLinkCtrl; /* USed for 3090F chip */ 1723 unsigned long Rt3xxRalinkLinkCtrl; /* USed for 3090F chip */
1723 u16 DeviceID; /* Read from PCI config */ 1724 u16 DeviceID; /* Read from PCI config */
1724 unsigned long AccessBBPFailCount; 1725 unsigned long AccessBBPFailCount;
1725 BOOLEAN bPCIclkOff; /* flag that indicate if the PICE power status in Configuration SPace.. */ 1726 BOOLEAN bPCIclkOff; /* flag that indicates if the PICE power status in Configuration Space.. */
1726 BOOLEAN bPCIclkOffDisableTx; /* */ 1727 BOOLEAN bPCIclkOffDisableTx; /* */
1727 1728
1728 BOOLEAN brt30xxBanMcuCmd; /*when = 0xff means all commands are ok to set . */ 1729 BOOLEAN brt30xxBanMcuCmd; /*when = 0xff means all commands are ok to set . */
@@ -1871,9 +1872,9 @@ struct rt_rtmp_adapter {
1871 /* ---------------------------- */ 1872 /* ---------------------------- */
1872 u8 RfIcType; /* RFIC_xxx */ 1873 u8 RfIcType; /* RFIC_xxx */
1873 unsigned long RfFreqOffset; /* Frequency offset for channel switching */ 1874 unsigned long RfFreqOffset; /* Frequency offset for channel switching */
1874 struct rt_rtmp_rf_regs LatchRfRegs; /* latch th latest RF programming value since RF IC doesn't support READ */ 1875 struct rt_rtmp_rf_regs LatchRfRegs; /* latch the latest RF programming value since RF IC doesn't support READ */
1875 1876
1876 EEPROM_ANTENNA_STRUC Antenna; /* Since ANtenna definition is different for a & g. We need to save it for future reference. */ 1877 EEPROM_ANTENNA_STRUC Antenna; /* Since Antenna definition is different for a & g. We need to save it for future reference. */
1877 EEPROM_NIC_CONFIG2_STRUC NicConfig2; 1878 EEPROM_NIC_CONFIG2_STRUC NicConfig2;
1878 1879
1879 /* This soft Rx Antenna Diversity mechanism is used only when user set */ 1880 /* This soft Rx Antenna Diversity mechanism is used only when user set */
@@ -1990,7 +1991,7 @@ struct rt_rtmp_adapter {
1990 struct rt_common_config CommonCfg; 1991 struct rt_common_config CommonCfg;
1991 struct rt_mlme Mlme; 1992 struct rt_mlme Mlme;
1992 1993
1993 /* AP needs those vaiables for site survey feature. */ 1994 /* AP needs those variables for site survey feature. */
1994 struct rt_mlme_aux MlmeAux; /* temporary settings used during MLME state machine */ 1995 struct rt_mlme_aux MlmeAux; /* temporary settings used during MLME state machine */
1995 struct rt_bss_table ScanTab; /* store the latest SCAN result */ 1996 struct rt_bss_table ScanTab; /* store the latest SCAN result */
1996 1997
@@ -2012,7 +2013,7 @@ struct rt_rtmp_adapter {
2012 /* various Counters */ 2013 /* various Counters */
2013 struct rt_counter_802_3 Counters8023; /* 802.3 counters */ 2014 struct rt_counter_802_3 Counters8023; /* 802.3 counters */
2014 struct rt_counter_802_11 WlanCounters; /* 802.11 MIB counters */ 2015 struct rt_counter_802_11 WlanCounters; /* 802.11 MIB counters */
2015 struct rt_counter_ralink RalinkCounters; /* Ralink propriety counters */ 2016 struct rt_counter_ralink RalinkCounters; /* Ralink proprietary counters */
2016 struct rt_counter_drs DrsCounters; /* counters for Dynamic TX Rate Switching */ 2017 struct rt_counter_drs DrsCounters; /* counters for Dynamic TX Rate Switching */
2017 struct rt_private PrivateInfo; /* Private information & counters */ 2018 struct rt_private PrivateInfo; /* Private information & counters */
2018 2019
@@ -2024,7 +2025,7 @@ struct rt_rtmp_adapter {
2024 u16 Sequence; 2025 u16 Sequence;
2025 2026
2026 /* Control disconnect / connect event generation */ 2027 /* Control disconnect / connect event generation */
2027 /*+++Didn't used anymore */ 2028 /*+++Not used anymore */
2028 unsigned long LinkDownTime; 2029 unsigned long LinkDownTime;
2029 /*--- */ 2030 /*--- */
2030 unsigned long LastRxRate; 2031 unsigned long LastRxRate;
@@ -2036,7 +2037,7 @@ struct rt_rtmp_adapter {
2036 unsigned long ExtraInfo; /* Extra information for displaying status */ 2037 unsigned long ExtraInfo; /* Extra information for displaying status */
2037 unsigned long SystemErrorBitmap; /* b0: E2PROM version error */ 2038 unsigned long SystemErrorBitmap; /* b0: E2PROM version error */
2038 2039
2039 /*+++Didn't used anymore */ 2040 /*+++Not used anymore */
2040 unsigned long MacIcVersion; /* MAC/BBP serial interface issue solved after ver.D */ 2041 unsigned long MacIcVersion; /* MAC/BBP serial interface issue solved after ver.D */
2041 /*--- */ 2042 /*--- */
2042 2043
@@ -2089,7 +2090,7 @@ struct rt_rtmp_adapter {
2089 unsigned long BulkOutReq; 2090 unsigned long BulkOutReq;
2090 unsigned long BulkOutComplete; 2091 unsigned long BulkOutComplete;
2091 unsigned long BulkOutCompleteOther; 2092 unsigned long BulkOutCompleteOther;
2092 unsigned long BulkOutCompleteCancel; /* seems not use now? */ 2093 unsigned long BulkOutCompleteCancel; /* seems not used now? */
2093 unsigned long BulkInReq; 2094 unsigned long BulkInReq;
2094 unsigned long BulkInComplete; 2095 unsigned long BulkInComplete;
2095 unsigned long BulkInCompleteFail; 2096 unsigned long BulkInCompleteFail;
@@ -2196,9 +2197,9 @@ struct rt_rx_blk {
2196struct rt_tx_blk { 2197struct rt_tx_blk {
2197 u8 QueIdx; 2198 u8 QueIdx;
2198 u8 TxFrameType; /* Indicate the Transmission type of the all frames in one batch */ 2199 u8 TxFrameType; /* Indicate the Transmission type of the all frames in one batch */
2199 u8 TotalFrameNum; /* Total frame number want to send-out in one batch */ 2200 u8 TotalFrameNum; /* Total frame number that wants to send-out in one batch */
2200 u16 TotalFragNum; /* Total frame fragments required in one batch */ 2201 u16 TotalFragNum; /* Total frame fragments required in one batch */
2201 u16 TotalFrameLen; /* Total length of all frames want to send-out in one batch */ 2202 u16 TotalFrameLen; /* Total length of all frames that wants to send-out in one batch */
2202 2203
2203 struct rt_queue_header TxPacketList; 2204 struct rt_queue_header TxPacketList;
2204 struct rt_mac_table_entry *pMacEntry; /* NULL: packet with 802.11 RA field is multicast/broadcast address */ 2205 struct rt_mac_table_entry *pMacEntry; /* NULL: packet with 802.11 RA field is multicast/broadcast address */
@@ -2207,7 +2208,7 @@ struct rt_tx_blk {
2207 /* Following structure used for the characteristics of a specific packet. */ 2208 /* Following structure used for the characteristics of a specific packet. */
2208 void *pPacket; 2209 void *pPacket;
2209 u8 *pSrcBufHeader; /* Reference to the head of sk_buff->data */ 2210 u8 *pSrcBufHeader; /* Reference to the head of sk_buff->data */
2210 u8 *pSrcBufData; /* Reference to the sk_buff->data, will changed depends on hanlding progresss */ 2211 u8 *pSrcBufData; /* Reference to the sk_buff->data, will change depending on the handling progresss */
2211 u32 SrcBufLen; /* Length of packet payload which not including Layer 2 header */ 2212 u32 SrcBufLen; /* Length of packet payload which not including Layer 2 header */
2212 u8 *pExtraLlcSnapEncap; /* NULL means no extra LLC/SNAP is required */ 2213 u8 *pExtraLlcSnapEncap; /* NULL means no extra LLC/SNAP is required */
2213 u8 HeaderBuf[128]; /* TempBuffer for TX_INFO + TX_WI + 802.11 Header + padding + AMSDU SubHeader + LLC/SNAP */ 2214 u8 HeaderBuf[128]; /* TempBuffer for TX_INFO + TX_WI + 802.11 Header + padding + AMSDU SubHeader + LLC/SNAP */
@@ -2219,7 +2220,7 @@ struct rt_tx_blk {
2219 u8 apidx; /* The interface associated to this packet */ 2220 u8 apidx; /* The interface associated to this packet */
2220 u8 Wcid; /* The MAC entry associated to this packet */ 2221 u8 Wcid; /* The MAC entry associated to this packet */
2221 u8 UserPriority; /* priority class of packet */ 2222 u8 UserPriority; /* priority class of packet */
2222 u8 FrameGap; /* what kind of IFS this packet use */ 2223 u8 FrameGap; /* what kind of IFS does this packet use */
2223 u8 MpduReqNum; /* number of fragments of this frame */ 2224 u8 MpduReqNum; /* number of fragments of this frame */
2224 u8 TxRate; /* TODO: Obsoleted? Should change to MCS? */ 2225 u8 TxRate; /* TODO: Obsoleted? Should change to MCS? */
2225 u8 CipherAlg; /* cipher alogrithm */ 2226 u8 CipherAlg; /* cipher alogrithm */
@@ -2978,7 +2979,7 @@ void LinkDown(struct rt_rtmp_adapter *pAd, IN BOOLEAN IsReqFromAP);
2978 2979
2979void IterateOnBssTab(struct rt_rtmp_adapter *pAd); 2980void IterateOnBssTab(struct rt_rtmp_adapter *pAd);
2980 2981
2981void IterateOnBssTab2(struct rt_rtmp_adapter *pAd);; 2982void IterateOnBssTab2(struct rt_rtmp_adapter *pAd);
2982 2983
2983void JoinParmFill(struct rt_rtmp_adapter *pAd, 2984void JoinParmFill(struct rt_rtmp_adapter *pAd,
2984 struct rt_mlme_join_req *JoinReq, unsigned long BssIdx); 2985 struct rt_mlme_join_req *JoinReq, unsigned long BssIdx);
diff --git a/drivers/staging/rt2860/rtmp_def.h b/drivers/staging/rt2860/rtmp_def.h
index 9c54bacb845b..6ac617e7c9bb 100644
--- a/drivers/staging/rt2860/rtmp_def.h
+++ b/drivers/staging/rt2860/rtmp_def.h
@@ -31,10 +31,11 @@
31 Miniport related definition header 31 Miniport related definition header
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 -------- ---------- ---------------------------------------------- 35 -------- ---------- ----------------------------------------------
36 Paul Lin 08-01-2002 created 36 Paul Lin 08-01-2002 created
37 John Chang 08-05-2003 add definition for 11g & other drafts 37 John Chang 08-05-2003 add definition for 11g & other drafts
38 Justin P. Mattock 11/07/2010 Fix some typos
38*/ 39*/
39#ifndef __RTMP_DEF_H__ 40#ifndef __RTMP_DEF_H__
40#define __RTMP_DEF_H__ 41#define __RTMP_DEF_H__
@@ -111,11 +112,11 @@
111 WMM Note: If memory of your system is not much, please reduce the definition; 112 WMM Note: If memory of your system is not much, please reduce the definition;
112 or when you do WMM test, the queue for low priority AC will be full, i.e. 113 or when you do WMM test, the queue for low priority AC will be full, i.e.
113 TX_RING_SIZE + MAX_PACKETS_IN_QUEUE packets for the AC will be buffered in 114 TX_RING_SIZE + MAX_PACKETS_IN_QUEUE packets for the AC will be buffered in
114 WLAN, maybe no any packet buffer can be got in Ethernet driver. 115 WLAN, maybe no packet buffers can get into the Ethernet driver.
115 116
116 Sometimes no packet buffer can be got in Ethernet driver, the system will 117 Sometimes no packet buffer can be get into the Ethernet driver, the system will
117 send flow control packet to the sender to slow down its sending rate. 118 send flow control packet to the sender to slow down its sending rate.
118 So no WMM can be saw in the air. 119 So no WMM can be seen in the air.
119*/ 120*/
120 121
121/* 122/*
@@ -125,7 +126,7 @@
125 And in rt_main_end.c, clConfig.clNum = RX_RING_SIZE * 3; is changed to 126 And in rt_main_end.c, clConfig.clNum = RX_RING_SIZE * 3; is changed to
126 clConfig.clNum = RX_RING_SIZE * 4; 127 clConfig.clNum = RX_RING_SIZE * 4;
127*/ 128*/
128/* TODO: For VxWorks the size is 256. Shall we cahnge the value as 256 for all OS????? */ 129/* TODO: For VxWorks the size is 256. Shall we change the value as 256 for all OS? */
129#define MAX_PACKETS_IN_QUEUE (512) /*(512) // to pass WMM A5-WPAPSK */ 130#define MAX_PACKETS_IN_QUEUE (512) /*(512) // to pass WMM A5-WPAPSK */
130 131
131#define MAX_PACKETS_IN_MCAST_PS_QUEUE 32 132#define MAX_PACKETS_IN_MCAST_PS_QUEUE 32
@@ -171,7 +172,7 @@
171#define fRTMP_ADAPTER_SCAN_2040 0x04000000 172#define fRTMP_ADAPTER_SCAN_2040 0x04000000
172#define fRTMP_ADAPTER_RADIO_MEASUREMENT 0x08000000 173#define fRTMP_ADAPTER_RADIO_MEASUREMENT 0x08000000
173 174
174#define fRTMP_ADAPTER_START_UP 0x10000000 /*Devive already initialized and enabled Tx/Rx. */ 175#define fRTMP_ADAPTER_START_UP 0x10000000 /*Device already initialized and enabled Tx/Rx. */
175#define fRTMP_ADAPTER_MEDIA_STATE_CHANGE 0x20000000 176#define fRTMP_ADAPTER_MEDIA_STATE_CHANGE 0x20000000
176#define fRTMP_ADAPTER_IDLE_RADIO_OFF 0x40000000 177#define fRTMP_ADAPTER_IDLE_RADIO_OFF 0x40000000
177 178
@@ -205,8 +206,8 @@
205#define fRTMP_PS_SET_PCI_CLK_OFF_COMMAND 0x00000002 206#define fRTMP_PS_SET_PCI_CLK_OFF_COMMAND 0x00000002
206/* Indicate driver should disable kick off hardware to send packets from now. */ 207/* Indicate driver should disable kick off hardware to send packets from now. */
207#define fRTMP_PS_DISABLE_TX 0x00000004 208#define fRTMP_PS_DISABLE_TX 0x00000004
208/* Indicate driver should IMMEDIATELY fo to sleep after receiving AP's beacon in which doesn't indicate unicate nor multicast packets for me */ 209/* Indicate driver should IMMEDIATELY go to sleep after receiving AP's beacon in which doesn't indicate unicate nor multicast packets for me */
209/*. This flag is used ONLY in RTMPHandleRxDoneInterrupt routine. */ 210/* This flag is used ONLY in RTMPHandleRxDoneInterrupt routine. */
210#define fRTMP_PS_GO_TO_SLEEP_NOW 0x00000008 211#define fRTMP_PS_GO_TO_SLEEP_NOW 0x00000008
211#define fRTMP_PS_TOGGLE_L1 0x00000010 /* Use Toggle L1 mechanism for rt28xx PCIe */ 212#define fRTMP_PS_TOGGLE_L1 0x00000010 /* Use Toggle L1 mechanism for rt28xx PCIe */
212 213
@@ -303,7 +304,7 @@
303 304
304/* WDS definition */ 305/* WDS definition */
305#define MAX_WDS_ENTRY 4 306#define MAX_WDS_ENTRY 4
306#define WDS_PAIRWISE_KEY_OFFSET 60 /* WDS links uses pairwise key#60 ~ 63 in ASIC pairwise key table */ 307#define WDS_PAIRWISE_KEY_OFFSET 60 /* WDS links use pairwise key#60 ~ 63 in ASIC pairwise key table */
307 308
308#define WDS_DISABLE_MODE 0 309#define WDS_DISABLE_MODE 0
309#define WDS_RESTRICT_MODE 1 310#define WDS_RESTRICT_MODE 1
@@ -559,7 +560,7 @@
559#define IE_ADD_HT2 53 /* 802.11n d1. ADDITIONAL HT CAPABILITY. ELEMENT ID TBD */ 560#define IE_ADD_HT2 53 /* 802.11n d1. ADDITIONAL HT CAPABILITY. ELEMENT ID TBD */
560 561
561/* For 802.11n D3.03 */ 562/* For 802.11n D3.03 */
562/*#define IE_NEW_EXT_CHA_OFFSET 62 // 802.11n d1. New extension channel offset elemet */ 563/*#define IE_NEW_EXT_CHA_OFFSET 62 // 802.11n d1. New extension channel offset element */
563#define IE_SECONDARY_CH_OFFSET 62 /* 802.11n D3.03 Secondary Channel Offset element */ 564#define IE_SECONDARY_CH_OFFSET 62 /* 802.11n D3.03 Secondary Channel Offset element */
564#define IE_WAPI 68 /* WAPI information element */ 565#define IE_WAPI 68 /* WAPI information element */
565#define IE_2040_BSS_COEXIST 72 /* 802.11n D3.0.3 */ 566#define IE_2040_BSS_COEXIST 72 /* 802.11n D3.0.3 */
@@ -678,7 +679,7 @@
678 679
679#define ACT_MACHINE_BASE 0 680#define ACT_MACHINE_BASE 0
680 681
681/*Those PEER_xx_CATE number is based on real Categary value in IEEE spec. Please don'es modify it by your self. */ 682/*Those PEER_xx_CATE number is based on real Categary value in IEEE spec. Please do not modify it by your self. */
682/*Category */ 683/*Category */
683#define MT2_PEER_SPECTRUM_CATE 0 684#define MT2_PEER_SPECTRUM_CATE 0
684#define MT2_PEER_QOS_CATE 1 685#define MT2_PEER_QOS_CATE 1
@@ -748,7 +749,7 @@
748 749
749#define ACT_FUNC_SIZE (MAX_ACT_STATE * MAX_ACT_MSG) 750#define ACT_FUNC_SIZE (MAX_ACT_STATE * MAX_ACT_MSG)
750/* */ 751/* */
751/* STA's AUTHENTICATION state machine: states, evvents, total function # */ 752/* STA's AUTHENTICATION state machine: states, events, total function # */
752/* */ 753/* */
753#define AUTH_REQ_IDLE 0 754#define AUTH_REQ_IDLE 0
754#define AUTH_WAIT_SEQ2 1 755#define AUTH_WAIT_SEQ2 1
@@ -948,7 +949,7 @@
948#define BLOCK_ACK 0x60 /* b6:5 = 11 */ 949#define BLOCK_ACK 0x60 /* b6:5 = 11 */
949 950
950/* */ 951/* */
951/* rtmp_data.c use these definition */ 952/* rtmp_data.c uses this definition */
952/* */ 953/* */
953#define LENGTH_802_11 24 954#define LENGTH_802_11 24
954#define LENGTH_802_11_AND_H 30 955#define LENGTH_802_11_AND_H 30
@@ -1288,7 +1289,7 @@
1288#define IW_STA_LINKDOWN_EVENT_FLAG 0x0210 1289#define IW_STA_LINKDOWN_EVENT_FLAG 0x0210
1289#define IW_SCAN_COMPLETED_EVENT_FLAG 0x0211 1290#define IW_SCAN_COMPLETED_EVENT_FLAG 0x0211
1290#define IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG 0x0212 1291#define IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG 0x0212
1291/* if add new system event flag, please upadte the IW_SYS_EVENT_FLAG_END */ 1292/* if add new system event flag, please update the IW_SYS_EVENT_FLAG_END */
1292#define IW_SYS_EVENT_FLAG_END 0x0212 1293#define IW_SYS_EVENT_FLAG_END 0x0212
1293#define IW_SYS_EVENT_TYPE_NUM (IW_SYS_EVENT_FLAG_END - IW_SYS_EVENT_FLAG_START + 1) 1294#define IW_SYS_EVENT_TYPE_NUM (IW_SYS_EVENT_FLAG_END - IW_SYS_EVENT_FLAG_START + 1)
1294/* For system event - end */ 1295/* For system event - end */
@@ -1305,7 +1306,7 @@
1305#define IW_SPOOF_DEAUTH_EVENT_FLAG 0x0307 1306#define IW_SPOOF_DEAUTH_EVENT_FLAG 0x0307
1306#define IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG 0x0308 1307#define IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG 0x0308
1307#define IW_REPLAY_ATTACK_EVENT_FLAG 0x0309 1308#define IW_REPLAY_ATTACK_EVENT_FLAG 0x0309
1308/* if add new spoof attack event flag, please upadte the IW_SPOOF_EVENT_FLAG_END */ 1309/* if add new spoof attack event flag, please update the IW_SPOOF_EVENT_FLAG_END */
1309#define IW_SPOOF_EVENT_FLAG_END 0x0309 1310#define IW_SPOOF_EVENT_FLAG_END 0x0309
1310#define IW_SPOOF_EVENT_TYPE_NUM (IW_SPOOF_EVENT_FLAG_END - IW_SPOOF_EVENT_FLAG_START + 1) 1311#define IW_SPOOF_EVENT_TYPE_NUM (IW_SPOOF_EVENT_FLAG_END - IW_SPOOF_EVENT_FLAG_START + 1)
1311/* For spoof attack event - end */ 1312/* For spoof attack event - end */
@@ -1319,7 +1320,7 @@
1319#define IW_FLOOD_DISASSOC_EVENT_FLAG 0x0404 1320#define IW_FLOOD_DISASSOC_EVENT_FLAG 0x0404
1320#define IW_FLOOD_DEAUTH_EVENT_FLAG 0x0405 1321#define IW_FLOOD_DEAUTH_EVENT_FLAG 0x0405
1321#define IW_FLOOD_EAP_REQ_EVENT_FLAG 0x0406 1322#define IW_FLOOD_EAP_REQ_EVENT_FLAG 0x0406
1322/* if add new flooding attack event flag, please upadte the IW_FLOOD_EVENT_FLAG_END */ 1323/* if add new flooding attack event flag, please update the IW_FLOOD_EVENT_FLAG_END */
1323#define IW_FLOOD_EVENT_FLAG_END 0x0406 1324#define IW_FLOOD_EVENT_FLAG_END 0x0406
1324#define IW_FLOOD_EVENT_TYPE_NUM (IW_FLOOD_EVENT_FLAG_END - IW_FLOOD_EVENT_FLAG_START + 1) 1325#define IW_FLOOD_EVENT_TYPE_NUM (IW_FLOOD_EVENT_FLAG_END - IW_FLOOD_EVENT_FLAG_START + 1)
1325/* For flooding attack - end */ 1326/* For flooding attack - end */
diff --git a/drivers/staging/rt2860/rtmp_timer.h b/drivers/staging/rt2860/rtmp_timer.h
index 28b8ac6e8352..15b628743500 100644
--- a/drivers/staging/rt2860/rtmp_timer.h
+++ b/drivers/staging/rt2860/rtmp_timer.h
@@ -28,13 +28,14 @@
28 rtmp_timer.h 28 rtmp_timer.h
29 29
30 Abstract: 30 Abstract:
31 Ralink Wireless Driver timer related data structures and delcarations 31 Ralink Wireless Driver timer related data structures and declarations
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 -------- ---------- ---------------------------------------------- 35 -------- ---------- ----------------------------------------------
36 Name Date Modification logs 36 Name Date Modification logs
37 Shiang Tu Aug-28-2008 init version 37 Shiang Tu Aug-28-2008 init version
38 Justin P. Mattock 11/07/2010 Fix a typo
38 39
39*/ 40*/
40 41
@@ -51,8 +52,8 @@
51 52
52/* ----------------- Timer Related MARCO ---------------*/ 53/* ----------------- Timer Related MARCO ---------------*/
53/* In some os or chipset, we have a lot of timer functions and will read/write register, */ 54/* In some os or chipset, we have a lot of timer functions and will read/write register, */
54/* it's not allowed in Linux USB sub-system to do it ( because of sleep issue when */ 55/* it's not allowed in Linux USB sub-system to do it ( because of sleep issue when */
55/* submit to ctrl pipe). So we need a wrapper function to take care it. */ 56/* submit to ctrl pipe). So we need a wrapper function to take care it. */
56 57
57#ifdef RTMP_TIMER_TASK_SUPPORT 58#ifdef RTMP_TIMER_TASK_SUPPORT
58typedef void(*RTMP_TIMER_TASK_HANDLE) (void *SystemSpecific1, 59typedef void(*RTMP_TIMER_TASK_HANDLE) (void *SystemSpecific1,
diff --git a/drivers/staging/rt2860/spectrum.h b/drivers/staging/rt2860/spectrum.h
index 648fd632b606..4c325ba7ba21 100644
--- a/drivers/staging/rt2860/spectrum.h
+++ b/drivers/staging/rt2860/spectrum.h
@@ -37,7 +37,7 @@ char RTMP_GetTxPwr(struct rt_rtmp_adapter *pAd, IN HTTRANSMIT_SETTING HTTxMode);
37 ========================================================================== 37 ==========================================================================
38 Description: 38 Description:
39 Prepare Measurement request action frame and enqueue it into 39 Prepare Measurement request action frame and enqueue it into
40 management queue waiting for transmition. 40 management queue waiting for transmission.
41 41
42 Parametrs: 42 Parametrs:
43 1. the destination mac address of the frame. 43 1. the destination mac address of the frame.
@@ -60,7 +60,7 @@ void MakeMeasurementReqFrame(struct rt_rtmp_adapter *pAd,
60 ========================================================================== 60 ==========================================================================
61 Description: 61 Description:
62 Prepare Measurement report action frame and enqueue it into 62 Prepare Measurement report action frame and enqueue it into
63 management queue waiting for transmition. 63 management queue waiting for transmission.
64 64
65 Parametrs: 65 Parametrs:
66 1. the destination mac address of the frame. 66 1. the destination mac address of the frame.
@@ -80,7 +80,7 @@ void EnqueueMeasurementRep(struct rt_rtmp_adapter *pAd,
80 ========================================================================== 80 ==========================================================================
81 Description: 81 Description:
82 Prepare TPC Request action frame and enqueue it into 82 Prepare TPC Request action frame and enqueue it into
83 management queue waiting for transmition. 83 management queue waiting for transmission.
84 84
85 Parametrs: 85 Parametrs:
86 1. the destination mac address of the frame. 86 1. the destination mac address of the frame.
@@ -94,7 +94,7 @@ void EnqueueTPCReq(struct rt_rtmp_adapter *pAd, u8 *pDA, u8 DialogToken);
94 ========================================================================== 94 ==========================================================================
95 Description: 95 Description:
96 Prepare TPC Report action frame and enqueue it into 96 Prepare TPC Report action frame and enqueue it into
97 management queue waiting for transmition. 97 management queue waiting for transmission.
98 98
99 Parametrs: 99 Parametrs:
100 1. the destination mac address of the frame. 100 1. the destination mac address of the frame.
@@ -110,7 +110,7 @@ void EnqueueTPCRep(struct rt_rtmp_adapter *pAd,
110 ========================================================================== 110 ==========================================================================
111 Description: 111 Description:
112 Prepare Channel Switch Announcement action frame and enqueue it into 112 Prepare Channel Switch Announcement action frame and enqueue it into
113 management queue waiting for transmition. 113 management queue waiting for transmission.
114 114
115 Parametrs: 115 Parametrs:
116 1. the destination mac address of the frame. 116 1. the destination mac address of the frame.
@@ -126,7 +126,7 @@ void EnqueueChSwAnn(struct rt_rtmp_adapter *pAd,
126/* 126/*
127 ========================================================================== 127 ==========================================================================
128 Description: 128 Description:
129 Spectrun action frames Handler such as channel switch annoucement, 129 Spectrun action frames Handler such as channel switch announcement,
130 measurement report, measurement request actions frames. 130 measurement report, measurement request actions frames.
131 131
132 Parametrs: 132 Parametrs:
diff --git a/drivers/staging/rt2860/sta/assoc.c b/drivers/staging/rt2860/sta/assoc.c
index b7efb0b6b3f0..59e931c3190d 100644
--- a/drivers/staging/rt2860/sta/assoc.c
+++ b/drivers/staging/rt2860/sta/assoc.c
@@ -32,7 +32,8 @@
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 -------- ---------- ---------------------------------------------- 34 -------- ---------- ----------------------------------------------
35 John 2004-9-3 porting from RT2500 35 John 2004-9-3 porting from RT2500
36 Justin P. Mattock 11/07/2010 Fix typos
36*/ 37*/
37#include "../rt_config.h" 38#include "../rt_config.h"
38 39
@@ -277,10 +278,10 @@ void MlmeAssocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *
277 u16 VarIesOffset; 278 u16 VarIesOffset;
278 u16 Status; 279 u16 Status;
279 280
280 /* Block all authentication request durning WPA block period */ 281 /* Block all authentication request during WPA block period */
281 if (pAd->StaCfg.bBlockAssoc == TRUE) { 282 if (pAd->StaCfg.bBlockAssoc == TRUE) {
282 DBGPRINT(RT_DEBUG_TRACE, 283 DBGPRINT(RT_DEBUG_TRACE,
283 ("ASSOC - Block Assoc request durning WPA block period!\n")); 284 ("ASSOC - Block Assoc request during WPA block period!\n"));
284 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; 285 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
285 Status = MLME_STATE_MACHINE_REJECT; 286 Status = MLME_STATE_MACHINE_REJECT;
286 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, 287 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2,
@@ -605,10 +606,10 @@ void MlmeReassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem
605 u8 *pOutBuffer = NULL; 606 u8 *pOutBuffer = NULL;
606 u16 Status; 607 u16 Status;
607 608
608 /* Block all authentication request durning WPA block period */ 609 /* Block all authentication request during WPA block period */
609 if (pAd->StaCfg.bBlockAssoc == TRUE) { 610 if (pAd->StaCfg.bBlockAssoc == TRUE) {
610 DBGPRINT(RT_DEBUG_TRACE, 611 DBGPRINT(RT_DEBUG_TRACE,
611 ("ASSOC - Block ReAssoc request durning WPA block period!\n")); 612 ("ASSOC - Block ReAssoc request during WPA block period!\n"));
612 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; 613 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
613 Status = MLME_STATE_MACHINE_REJECT; 614 Status = MLME_STATE_MACHINE_REJECT;
614 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, 615 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2,
@@ -1001,7 +1002,7 @@ void AssocPostProc(struct rt_rtmp_adapter *pAd, u8 *pAddr2, u16 CapabilityInfo,
1001 pAd->MlmeAux.CapabilityInfo = 1002 pAd->MlmeAux.CapabilityInfo =
1002 CapabilityInfo & SUPPORTED_CAPABILITY_INFO; 1003 CapabilityInfo & SUPPORTED_CAPABILITY_INFO;
1003 1004
1004 /* Some HT AP might lost WMM IE. We add WMM ourselves. beacuase HT requires QoS on. */ 1005 /* Some HT AP might lost WMM IE. We add WMM ourselves. because HT requires QoS on. */
1005 if ((HtCapabilityLen > 0) && (pEdcaParm->bValid == FALSE)) { 1006 if ((HtCapabilityLen > 0) && (pEdcaParm->bValid == FALSE)) {
1006 pEdcaParm->bValid = TRUE; 1007 pEdcaParm->bValid = TRUE;
1007 pEdcaParm->Aifsn[0] = 3; 1008 pEdcaParm->Aifsn[0] = 3;
@@ -1054,7 +1055,7 @@ void AssocPostProc(struct rt_rtmp_adapter *pAd, u8 *pAddr2, u16 CapabilityInfo,
1054 /* Set New WPA information */ 1055 /* Set New WPA information */
1055 Idx = BssTableSearch(&pAd->ScanTab, pAddr2, pAd->MlmeAux.Channel); 1056 Idx = BssTableSearch(&pAd->ScanTab, pAddr2, pAd->MlmeAux.Channel);
1056 if (Idx == BSS_NOT_FOUND) { 1057 if (Idx == BSS_NOT_FOUND) {
1057 DBGPRINT_ERR(("ASSOC - Can't find BSS after receiving Assoc response\n")); 1058 DBGPRINT_ERR("ASSOC - Can't find BSS after receiving Assoc response\n");
1058 } else { 1059 } else {
1059 /* Init variable */ 1060 /* Init variable */
1060 pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = 0; 1061 pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = 0;
diff --git a/drivers/staging/rt2860/sta/auth.c b/drivers/staging/rt2860/sta/auth.c
index 404bd220679d..23ea00b896b0 100644
--- a/drivers/staging/rt2860/sta/auth.c
+++ b/drivers/staging/rt2860/sta/auth.c
@@ -32,7 +32,8 @@
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 -------- ---------- ---------------------------------------------- 34 -------- ---------- ----------------------------------------------
35 John 2004-9-3 porting from RT2500 35 John 2004-9-3 porting from RT2500
36 Justin P. Mattock 11/07/2010 Fix typos
36*/ 37*/
37#include "../rt_config.h" 38#include "../rt_config.h"
38 39
@@ -455,10 +456,10 @@ BOOLEAN AUTH_ReqSend(struct rt_rtmp_adapter *pAd,
455 u8 *pOutBuffer = NULL; 456 u8 *pOutBuffer = NULL;
456 unsigned long FrameLen = 0, tmp = 0; 457 unsigned long FrameLen = 0, tmp = 0;
457 458
458 /* Block all authentication request durning WPA block period */ 459 /* Block all authentication request during WPA block period */
459 if (pAd->StaCfg.bBlockAssoc == TRUE) { 460 if (pAd->StaCfg.bBlockAssoc == TRUE) {
460 DBGPRINT(RT_DEBUG_TRACE, 461 DBGPRINT(RT_DEBUG_TRACE,
461 ("%s - Block Auth request durning WPA block period!\n", 462 ("%s - Block Auth request during WPA block period!\n",
462 pSMName)); 463 pSMName));
463 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; 464 pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE;
464 Status = MLME_STATE_MACHINE_REJECT; 465 Status = MLME_STATE_MACHINE_REJECT;
@@ -508,8 +509,7 @@ BOOLEAN AUTH_ReqSend(struct rt_rtmp_adapter *pAd,
508 RTMPSetTimer(pAuthTimer, Timeout); 509 RTMPSetTimer(pAuthTimer, Timeout);
509 return TRUE; 510 return TRUE;
510 } else { 511 } else {
511 DBGPRINT_ERR(("%s - MlmeAuthReqAction() sanity check failed\n", 512 DBGPRINT_ERR("%s - MlmeAuthReqAction() sanity check failed\n", pSMName);
512 pSMName));
513 return FALSE; 513 return FALSE;
514 } 514 }
515 515
diff --git a/drivers/staging/rt2860/sta/connect.c b/drivers/staging/rt2860/sta/connect.c
index c380551c0354..4996258f6ecd 100644
--- a/drivers/staging/rt2860/sta/connect.c
+++ b/drivers/staging/rt2860/sta/connect.c
@@ -32,7 +32,8 @@
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 -------- ---------- ---------------------------------------------- 34 -------- ---------- ----------------------------------------------
35 John 2004-08-08 Major modification from RT2560 35 John 2004-08-08 Major modification from RT2560
36 Justin P. Mattock 11/07/2010 Fix typos
36*/ 37*/
37#include "../rt_config.h" 38#include "../rt_config.h"
38 39
@@ -64,7 +65,7 @@ u8 CipherSuiteWpaNoneAesLen =
64 65
65/* The following MACRO is called after 1. starting an new IBSS, 2. successfully JOIN an IBSS, */ 66/* The following MACRO is called after 1. starting an new IBSS, 2. successfully JOIN an IBSS, */
66/* or 3. successfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS */ 67/* or 3. successfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS */
67/* All settings successfuly negotiated furing MLME state machines become final settings */ 68/* All settings successfuly negotiated firing MLME state machines become final settings */
68/* and are copied to pAd->StaActive */ 69/* and are copied to pAd->StaActive */
69#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \ 70#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
70{ \ 71{ \
@@ -214,8 +215,7 @@ void MlmeCntlMachinePerformAction(struct rt_rtmp_adapter *pAd,
214 break; 215 break;
215#endif /* RTMP_MAC_USB // */ 216#endif /* RTMP_MAC_USB // */
216 default: 217 default:
217 DBGPRINT_ERR(("ERROR! CNTL - Illegal message type(=%ld)", 218 DBGPRINT_ERR("ERROR! CNTL - Illegal message type(=%ld)", Elem->MsgType);
218 Elem->MsgType));
219 break; 219 break;
220 } 220 }
221} 221}
@@ -553,7 +553,7 @@ void CntlOidRTBssidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *
553 NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0], 553 NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0],
554 &pAd->ScanTab.BssEntry[BssIdx], sizeof(struct rt_bss_entry)); 554 &pAd->ScanTab.BssEntry[BssIdx], sizeof(struct rt_bss_entry));
555 555
556 /* Add SSID into MlmeAux for site surey joining hidden SSID */ 556 /* Add SSID into MlmeAux for site survey joining hidden SSID */
557 pAd->MlmeAux.SsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen; 557 pAd->MlmeAux.SsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;
558 NdisMoveMemory(pAd->MlmeAux.Ssid, pAd->ScanTab.BssEntry[BssIdx].Ssid, 558 NdisMoveMemory(pAd->MlmeAux.Ssid, pAd->ScanTab.BssEntry[BssIdx].Ssid,
559 pAd->MlmeAux.SsidLen); 559 pAd->MlmeAux.SsidLen);
@@ -666,7 +666,7 @@ void CntlOidRTBssidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *
666} 666}
667 667
668/* Roaming is the only external request triggering CNTL state machine */ 668/* Roaming is the only external request triggering CNTL state machine */
669/* despite of other "SET OID" operation. All "SET OID" related oerations */ 669/* despite of other "SET OID" operation. All "SET OID" related operations */
670/* happen in sequence, because no other SET OID will be sent to this device */ 670/* happen in sequence, because no other SET OID will be sent to this device */
671/* until the the previous SET operation is complete (successful o failed). */ 671/* until the the previous SET operation is complete (successful o failed). */
672/* So, how do we quarantee this ROAMING request won't corrupt other "SET OID"? */ 672/* So, how do we quarantee this ROAMING request won't corrupt other "SET OID"? */
@@ -1224,7 +1224,7 @@ void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType)
1224 /* Change to AP channel */ 1224 /* Change to AP channel */
1225 if ((pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel) 1225 if ((pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel)
1226 && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40)) { 1226 && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40)) {
1227 /* Must using 40MHz. */ 1227 /* Must use 40MHz. */
1228 pAd->CommonCfg.BBPCurrentBW = BW_40; 1228 pAd->CommonCfg.BBPCurrentBW = BW_40;
1229 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE); 1229 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
1230 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); 1230 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
@@ -1259,7 +1259,7 @@ void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType)
1259 } else if ((pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel) 1259 } else if ((pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel)
1260 && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == 1260 && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth ==
1261 BW_40)) { 1261 BW_40)) {
1262 /* Must using 40MHz. */ 1262 /* Must use 40MHz. */
1263 pAd->CommonCfg.BBPCurrentBW = BW_40; 1263 pAd->CommonCfg.BBPCurrentBW = BW_40;
1264 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE); 1264 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
1265 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); 1265 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
@@ -1343,12 +1343,12 @@ void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType)
1343 AsicSetSlotTime(pAd, TRUE); 1343 AsicSetSlotTime(pAd, TRUE);
1344 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm); 1344 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1345 1345
1346 /* Call this for RTS protectionfor legacy rate, we will always enable RTS threshold, but normally it will not hit */ 1346 /* Call this for RTS protection for legacy rate, we will always enable RTS threshold, but normally it will not hit */
1347 AsicUpdateProtect(pAd, 0, (OFDMSETPROTECT | CCKSETPROTECT), TRUE, 1347 AsicUpdateProtect(pAd, 0, (OFDMSETPROTECT | CCKSETPROTECT), TRUE,
1348 FALSE); 1348 FALSE);
1349 1349
1350 if ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE)) { 1350 if ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE)) {
1351 /* Update HT protectionfor based on AP's operating mode. */ 1351 /* Update HT protection for based on AP's operating mode. */
1352 if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1) { 1352 if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1) {
1353 AsicUpdateProtect(pAd, 1353 AsicUpdateProtect(pAd,
1354 pAd->MlmeAux.AddHtInfo.AddHtInfo2. 1354 pAd->MlmeAux.AddHtInfo.AddHtInfo2.
@@ -1530,7 +1530,7 @@ void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType)
1530 /* Add BSSID to WCID search table */ 1530 /* Add BSSID to WCID search table */
1531 AsicUpdateRxWCIDTable(pAd, BSSID_WCID, pAd->CommonCfg.Bssid); 1531 AsicUpdateRxWCIDTable(pAd, BSSID_WCID, pAd->CommonCfg.Bssid);
1532 1532
1533 /* If WEP is enabled, add paiewise and shared key */ 1533 /* If WEP is enabled, add pairwise and shared key */
1534 if (((pAd->StaCfg.WpaSupplicantUP) && 1534 if (((pAd->StaCfg.WpaSupplicantUP) &&
1535 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) && 1535 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
1536 (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) || 1536 (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) ||
@@ -1681,9 +1681,9 @@ void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType)
1681 pAd->Mlme.PeriodicRound = 0; 1681 pAd->Mlme.PeriodicRound = 0;
1682 pAd->Mlme.OneSecPeriodicRound = 0; 1682 pAd->Mlme.OneSecPeriodicRound = 0;
1683 pAd->bConfigChanged = FALSE; /* Reset config flag */ 1683 pAd->bConfigChanged = FALSE; /* Reset config flag */
1684 pAd->ExtraInfo = GENERAL_LINK_UP; /* Update extra information to link is up */ 1684 pAd->ExtraInfo = GENERAL_LINK_UP; /* Update extra information after link is up */
1685 1685
1686 /* Set asic auto fall back */ 1686 /* Set basic auto fall back */
1687 { 1687 {
1688 u8 *pTable; 1688 u8 *pTable;
1689 u8 TableSize = 0; 1689 u8 TableSize = 0;
@@ -1854,8 +1854,8 @@ void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType)
1854 Note: 1854 Note:
1855 We need more information to know it's this requst from AP. 1855 We need more information to know it's this requst from AP.
1856 If yes! we need to do extra handling, for example, remove the WPA key. 1856 If yes! we need to do extra handling, for example, remove the WPA key.
1857 Otherwise on 4-way handshaking will faied, since the WPA key didn't be 1857 Otherwise on 4-way handshaking will fail, since the WPA key didn't get
1858 remove while auto reconnect. 1858 removed while auto reconnect.
1859 Disconnect request from AP, it means we will start afresh 4-way handshaking 1859 Disconnect request from AP, it means we will start afresh 4-way handshaking
1860 on WPA mode. 1860 on WPA mode.
1861 1861
@@ -1870,9 +1870,9 @@ void LinkDown(struct rt_rtmp_adapter *pAd, IN BOOLEAN IsReqFromAP)
1870 return; 1870 return;
1871 1871
1872 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW); 1872 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
1873 /*Comment the codes, beasue the line 2291 call the same function. */ 1873 /* Comment the codes, because the line 2291 call the same function. */
1874 /*RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); */ 1874 /* RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); */
1875 /* Not allow go to sleep within linkdown function. */ 1875 /* Not allowed go to sleep within the linkdown function. */
1876 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP); 1876 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
1877 1877
1878 if (pAd->CommonCfg.bWirelessEvent) { 1878 if (pAd->CommonCfg.bWirelessEvent) {
@@ -1970,7 +1970,7 @@ void LinkDown(struct rt_rtmp_adapter *pAd, IN BOOLEAN IsReqFromAP)
1970 /* Set LED */ 1970 /* Set LED */
1971 RTMPSetLED(pAd, LED_LINK_DOWN); 1971 RTMPSetLED(pAd, LED_LINK_DOWN);
1972 pAd->LedIndicatorStrength = 0xF0; 1972 pAd->LedIndicatorStrength = 0xF0;
1973 RTMPSetSignalLED(pAd, -100); /* Force signal strength Led to be turned off, firmware is not done it. */ 1973 RTMPSetSignalLED(pAd, -100); /* Force signal strength Led to be turned off, firmware has not done it. */
1974 1974
1975 AsicDisableSync(pAd); 1975 AsicDisableSync(pAd);
1976 1976
diff --git a/drivers/staging/rt2860/sta/rtmp_data.c b/drivers/staging/rt2860/sta/rtmp_data.c
index 23879b7cd49a..e82c6b669eb2 100644
--- a/drivers/staging/rt2860/sta/rtmp_data.c
+++ b/drivers/staging/rt2860/sta/rtmp_data.c
@@ -31,7 +31,8 @@
31 Data path subroutines 31 Data path subroutines
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 Justin P. Mattock 11/07/2010 Fix typos
35 -------- ---------- ---------------------------------------------- 36 -------- ---------- ----------------------------------------------
36*/ 37*/
37#include "../rt_config.h" 38#include "../rt_config.h"
@@ -257,8 +258,8 @@ void STARxDataFrameAnnounce(struct rt_rtmp_adapter *pAd,
257 && (pAd->CommonCfg.bDisableReordering == 0)) { 258 && (pAd->CommonCfg.bDisableReordering == 0)) {
258 Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID); 259 Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID);
259 } else { 260 } else {
260 /* Determin the destination of the EAP frame */ 261 /* Determine the destination of the EAP frame */
261 /* to WPA state machine or upper layer */ 262 /* to WPA state machine or upper layer */
262 STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, 263 STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk,
263 FromWhichBSSID); 264 FromWhichBSSID);
264 } 265 }
@@ -644,7 +645,7 @@ void STAHandleRxMgmtFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk)
644 645
645 /* First check the size, it MUST not exceed the mlme queue size */ 646 /* First check the size, it MUST not exceed the mlme queue size */
646 if (pRxWI->MPDUtotalByteCount > MGMT_DMA_BUFFER_SIZE) { 647 if (pRxWI->MPDUtotalByteCount > MGMT_DMA_BUFFER_SIZE) {
647 DBGPRINT_ERR(("STAHandleRxMgmtFrame: frame too large, size = %d \n", pRxWI->MPDUtotalByteCount)); 648 DBGPRINT_ERR("STAHandleRxMgmtFrame: frame too large, size = %d \n", pRxWI->MPDUtotalByteCount);
648 break; 649 break;
649 } 650 }
650 651
@@ -853,7 +854,7 @@ Return Value:
853 NONE 854 NONE
854 855
855Note: 856Note:
856 This function do early checking and classification for send-out packet. 857 This function does early checking and classification for send-out packet.
857 You only can put OS-depened & STA related code in here. 858 You only can put OS-depened & STA related code in here.
858======================================================================== 859========================================================================
859*/ 860*/
@@ -943,7 +944,7 @@ int STASendPacket(struct rt_rtmp_adapter *pAd, void *pPacket)
943 DBGPRINT(RT_DEBUG_ERROR, 944 DBGPRINT(RT_DEBUG_ERROR,
944 ("STASendPacket --> pSrcBufVA == NULL !SrcBufLen=%x\n", 945 ("STASendPacket --> pSrcBufVA == NULL !SrcBufLen=%x\n",
945 SrcBufLen)); 946 SrcBufLen));
946 /* Resourece is low, system did not allocate virtual address */ 947 /* Resource is low, system did not allocate virtual address */
947 /* return NDIS_STATUS_FAILURE directly to upper layer */ 948 /* return NDIS_STATUS_FAILURE directly to upper layer */
948 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); 949 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
949 return NDIS_STATUS_FAILURE; 950 return NDIS_STATUS_FAILURE;
@@ -979,7 +980,7 @@ int STASendPacket(struct rt_rtmp_adapter *pAd, void *pPacket)
979 DBGPRINT(RT_DEBUG_ERROR, 980 DBGPRINT(RT_DEBUG_ERROR,
980 ("STASendPacket->Cannot find pEntry(%pM) in MacTab!\n", 981 ("STASendPacket->Cannot find pEntry(%pM) in MacTab!\n",
981 pSrcBufVA)); 982 pSrcBufVA));
982 /* Resourece is low, system did not allocate virtual address */ 983 /* Resource is low, system did not allocate virtual address */
983 /* return NDIS_STATUS_FAILURE directly to upper layer */ 984 /* return NDIS_STATUS_FAILURE directly to upper layer */
984 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); 985 RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE);
985 return NDIS_STATUS_FAILURE; 986 return NDIS_STATUS_FAILURE;
@@ -1057,9 +1058,9 @@ int STASendPacket(struct rt_rtmp_adapter *pAd, void *pPacket)
1057 1058
1058 /* STEP 2. Check the requirement of RTS: */ 1059 /* STEP 2. Check the requirement of RTS: */
1059 /* If multiple fragment required, RTS is required only for the first fragment */ 1060 /* If multiple fragment required, RTS is required only for the first fragment */
1060 /* if the fragment size large than RTS threshold */ 1061 /* if the fragment size is larger than RTS threshold */
1061 /* For RT28xx, Let ASIC send RTS/CTS */ 1062 /* For RT28xx, Let ASIC send RTS/CTS */
1062/* RTMP_SET_PACKET_RTS(pPacket, 0); */ 1063 /* RTMP_SET_PACKET_RTS(pPacket, 0); */
1063 if (NumberOfFrag > 1) 1064 if (NumberOfFrag > 1)
1064 RTSRequired = 1065 RTSRequired =
1065 (pAd->CommonCfg.FragmentThreshold > 1066 (pAd->CommonCfg.FragmentThreshold >
@@ -1171,8 +1172,8 @@ int STASendPacket(struct rt_rtmp_adapter *pAd, void *pPacket)
1171 ======================================================================== 1172 ========================================================================
1172 1173
1173 Routine Description: 1174 Routine Description:
1174 This subroutine will scan through releative ring descriptor to find 1175 This subroutine will scan through relative ring descriptor to find
1175 out avaliable free ring descriptor and compare with request size. 1176 out available free ring descriptor and compare with request size.
1176 1177
1177 Arguments: 1178 Arguments:
1178 pAd Pointer to our adapter 1179 pAd Pointer to our adapter
@@ -1588,7 +1589,7 @@ static inline u8 *STA_Build_ARalink_Frame_Header(struct rt_rtmp_adapter *pAd,
1588 pHeaderBufPtr += 2; 1589 pHeaderBufPtr += 2;
1589 pTxBlk->MpduHeaderLen += 2; 1590 pTxBlk->MpduHeaderLen += 2;
1590 } 1591 }
1591 /* padding at front of LLC header. LLC header should at 4-bytes aligment. */ 1592 /* padding at front of LLC header. LLC header should at 4-bytes alignment. */
1592 pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr; 1593 pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr;
1593 pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4); 1594 pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4);
1594 pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen); 1595 pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen);
@@ -2014,7 +2015,7 @@ void STA_Legacy_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk)
2014 pHeaderBufPtr += 2; 2015 pHeaderBufPtr += 2;
2015 pTxBlk->MpduHeaderLen += 2; 2016 pTxBlk->MpduHeaderLen += 2;
2016 } 2017 }
2017 /* The remaining content of MPDU header should locate at 4-octets aligment */ 2018 /* The remaining content of MPDU header should locate at 4-octets alignment */
2018 pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr; 2019 pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr;
2019 pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4); 2020 pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4);
2020 pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen); 2021 pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen);
@@ -2114,7 +2115,7 @@ void STA_ARalink_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk)
2114 STA_Build_ARalink_Frame_Header(pAd, pTxBlk); 2115 STA_Build_ARalink_Frame_Header(pAd, pTxBlk);
2115 2116
2116 /* It's ok write the TxWI here, because the TxWI->MPDUtotalByteCount */ 2117 /* It's ok write the TxWI here, because the TxWI->MPDUtotalByteCount */
2117 /* will be updated after final frame was handled. */ 2118 /* will be updated after final frame was handled. */
2118 RTMPWriteTxWI_Data(pAd, 2119 RTMPWriteTxWI_Data(pAd,
2119 (struct rt_txwi *) (&pTxBlk-> 2120 (struct rt_txwi *) (&pTxBlk->
2120 HeaderBuf 2121 HeaderBuf
@@ -2291,8 +2292,8 @@ void STA_Fragment_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk
2291 pTxBlk->pExtraLlcSnapEncap, pTxBlk->pKey, 2292 pTxBlk->pExtraLlcSnapEncap, pTxBlk->pKey,
2292 0); 2293 0);
2293 2294
2294 /* NOTE: DON'T refer the skb->len directly after following copy. Becasue the length is not adjust */ 2295 /* NOTE: DON'T refer the skb->len directly after following copy. Because the length is not adjusted */
2295 /* to correct lenght, refer to pTxBlk->SrcBufLen for the packet length in following progress. */ 2296 /* to correct length, refer to pTxBlk->SrcBufLen for the packet length in following progress. */
2296 NdisMoveMemory(pTxBlk->pSrcBufData + pTxBlk->SrcBufLen, 2297 NdisMoveMemory(pTxBlk->pSrcBufData + pTxBlk->SrcBufLen,
2297 &pAd->PrivateInfo.Tx.MIC[0], 8); 2298 &pAd->PrivateInfo.Tx.MIC[0], 8);
2298 /*skb_put((RTPKT_TO_OSPKT(pTxBlk->pPacket))->tail, 8); */ 2299 /*skb_put((RTPKT_TO_OSPKT(pTxBlk->pPacket))->tail, 8); */
@@ -2301,7 +2302,7 @@ void STA_Fragment_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk
2301 pTxBlk->CipherAlg = CIPHER_TKIP_NO_MIC; 2302 pTxBlk->CipherAlg = CIPHER_TKIP_NO_MIC;
2302 } 2303 }
2303 /* */ 2304 /* */
2304 /* calcuate the overhead bytes that encryption algorithm may add. This */ 2305 /* calculate the overhead bytes that encryption algorithm may add. This */
2305 /* affects the calculate of "duration" field */ 2306 /* affects the calculate of "duration" field */
2306 /* */ 2307 /* */
2307 if ((pTxBlk->CipherAlg == CIPHER_WEP64) 2308 if ((pTxBlk->CipherAlg == CIPHER_WEP64)
diff --git a/drivers/staging/rt2860/sta/sanity.c b/drivers/staging/rt2860/sta/sanity.c
index 8f9fd19be151..0c32604f2d3f 100644
--- a/drivers/staging/rt2860/sta/sanity.c
+++ b/drivers/staging/rt2860/sta/sanity.c
@@ -32,7 +32,8 @@
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 -------- ---------- ---------------------------------------------- 34 -------- ---------- ----------------------------------------------
35 John Chang 2004-09-01 add WMM support 35 John Chang 2004-09-01 add WMM support
36 Justin P. Mattock 11/07/2010 Fix typos
36*/ 37*/
37#include "../rt_config.h" 38#include "../rt_config.h"
38 39
@@ -118,7 +119,7 @@ BOOLEAN PeerAssocRspSanity(struct rt_rtmp_adapter *pAd, void * pMsg, unsigned lo
118 NdisMoveMemory(pAid, &pFrame->Octet[4], 2); 119 NdisMoveMemory(pAid, &pFrame->Octet[4], 2);
119 Length += 2; 120 Length += 2;
120 121
121 /* Aid already swaped byte order in RTMPFrameEndianChange() for big endian platform */ 122 /* Aid already swapped byte order in RTMPFrameEndianChange() for big endian platform */
122 *pAid = (*pAid) & 0x3fff; /* AID is low 14-bit */ 123 *pAid = (*pAid) & 0x3fff; /* AID is low 14-bit */
123 124
124 /* -- get supported rates from payload and advance the pointer */ 125 /* -- get supported rates from payload and advance the pointer */
diff --git a/drivers/staging/rt2860/sta/sync.c b/drivers/staging/rt2860/sta/sync.c
index 747d3c6d1851..7054ba1323d0 100644
--- a/drivers/staging/rt2860/sta/sync.c
+++ b/drivers/staging/rt2860/sta/sync.c
@@ -32,8 +32,9 @@
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 -------- ---------- ---------------------------------------------- 34 -------- ---------- ----------------------------------------------
35 John Chang 2004-09-01 modified for rt2561/2661 35 John Chang 2004-09-01 modified for rt2561/2661
36 Jan Lee 2006-08-01 modified for rt2860 for 802.11n 36 Jan Lee 2006-08-01 modified for rt2860 for 802.11n
37 Justin P. Mattock 11/07/2010 Fix typos
37*/ 38*/
38#include "../rt_config.h" 39#include "../rt_config.h"
39 40
@@ -233,9 +234,9 @@ void MlmeScanReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *E
233 RTMPSuspendMsduTransmission(pAd); 234 RTMPSuspendMsduTransmission(pAd);
234 235
235 /* */ 236 /* */
236 /* To prevent data lost. */ 237 /* To prevent data loss. */
237 /* Send an NULL data with turned PSM bit on to current associated AP before SCAN progress. */ 238 /* Send a NULL data with turned PSM bit on to current associated AP before SCAN progress. */
238 /* And should send an NULL data with turned PSM bit off to AP, when scan progress done */ 239 /* And should send a NULL data with turned PSM bit off to AP, when scan progress done */
239 /* */ 240 /* */
240 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) 241 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)
241 && (INFRA_ON(pAd))) { 242 && (INFRA_ON(pAd))) {
@@ -283,7 +284,7 @@ void MlmeScanReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *E
283 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n")); 284 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));
284 ScanNextChannel(pAd); 285 ScanNextChannel(pAd);
285 } else { 286 } else {
286 DBGPRINT_ERR(("SYNC - MlmeScanReqAction() sanity check fail\n")); 287 DBGPRINT_ERR("SYNC - MlmeScanReqAction() sanity check fail\n");
287 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; 288 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
288 Status = MLME_INVALID_FORMAT; 289 Status = MLME_INVALID_FORMAT;
289 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, 290 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2,
@@ -535,7 +536,7 @@ void MlmeStartReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *
535 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, 536 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2,
536 &Status); 537 &Status);
537 } else { 538 } else {
538 DBGPRINT_ERR(("SYNC - MlmeStartReqAction() sanity check fail.\n")); 539 DBGPRINT_ERR("SYNC - MlmeStartReqAction() sanity check fail.\n");
539 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; 540 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
540 Status = MLME_INVALID_FORMAT; 541 Status = MLME_INVALID_FORMAT;
541 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, 542 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2,
@@ -750,9 +751,9 @@ void PeerBeaconAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_el
750 751
751 /* BEACON from desired BSS/IBSS found. We should be able to decide most */ 752 /* BEACON from desired BSS/IBSS found. We should be able to decide most */
752 /* BSS parameters here. */ 753 /* BSS parameters here. */
753 /* Q. But what happen if this JOIN doesn't conclude a successful ASSOCIATEION? */ 754 /* Q. But what happen if this JOIN doesn't conclude a successful ASSOCIATION? */
754 /* Do we need to receover back all parameters belonging to previous BSS? */ 755 /* Do we need to recover back all parameters belonging to previous BSS? */
755 /* A. Should be not. There's no back-door recover to previous AP. It still need */ 756 /* A. Should be not. There's no back-door recover to previous AP. It still needs */
756 /* a new JOIN-AUTH-ASSOC sequence. */ 757 /* a new JOIN-AUTH-ASSOC sequence. */
757 if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Bssid)) { 758 if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Bssid)) {
758 DBGPRINT(RT_DEBUG_TRACE, 759 DBGPRINT(RT_DEBUG_TRACE,
@@ -876,7 +877,7 @@ void PeerBeaconAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_el
876 pAd->MlmeAux.CfpMaxDuration = Cf.CfpMaxDuration; 877 pAd->MlmeAux.CfpMaxDuration = Cf.CfpMaxDuration;
877 pAd->MlmeAux.APRalinkIe = RalinkIe; 878 pAd->MlmeAux.APRalinkIe = RalinkIe;
878 879
879 /* Copy AP's supported rate to MlmeAux for creating assoication request */ 880 /* Copy AP's supported rate to MlmeAux for creating association request */
880 /* Also filter out not supported rate */ 881 /* Also filter out not supported rate */
881 pAd->MlmeAux.SupRateLen = SupRateLen; 882 pAd->MlmeAux.SupRateLen = SupRateLen;
882 NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, 883 NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate,
@@ -1207,7 +1208,7 @@ void PeerBeacon(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1207 } 1208 }
1208 1209
1209 if (index >= pAd->ChannelListNum) { 1210 if (index >= pAd->ChannelListNum) {
1210 DBGPRINT_ERR(("PeerBeacon(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum)); 1211 DBGPRINT_ERR("PeerBeacon(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum);
1211 } 1212 }
1212 } 1213 }
1213 /* if the ssid matched & bssid unmatched, we should select the bssid with large value. */ 1214 /* if the ssid matched & bssid unmatched, we should select the bssid with large value. */
diff --git a/drivers/staging/rt2860/sta/wpa.c b/drivers/staging/rt2860/sta/wpa.c
index 69b8a24daa21..ff348325028b 100644
--- a/drivers/staging/rt2860/sta/wpa.c
+++ b/drivers/staging/rt2860/sta/wpa.c
@@ -33,7 +33,8 @@
33 Who When What 33 Who When What
34 -------- ---------- ---------------------------------------------- 34 -------- ---------- ----------------------------------------------
35 Jan Lee 03-07-22 Initial 35 Jan Lee 03-07-22 Initial
36 Paul Lin 03-11-28 Modify for supplicant 36 Paul Lin 03-11-28 Modify for supplicant
37 Justin P. Mattock 11/07/2010 Fix typos
37*/ 38*/
38#include "../rt_config.h" 39#include "../rt_config.h"
39 40
@@ -86,7 +87,7 @@ void RTMPReportMicError(struct rt_rtmp_adapter *pAd, struct rt_cipher_key *pWpaK
86 /* Violate MIC error counts, MIC countermeasures kicks in */ 87 /* Violate MIC error counts, MIC countermeasures kicks in */
87 pAd->StaCfg.MicErrCnt++; 88 pAd->StaCfg.MicErrCnt++;
88 /* We shall block all reception */ 89 /* We shall block all reception */
89 /* We shall clean all Tx ring and disassoicate from AP after next EAPOL frame */ 90 /* We shall clean all Tx ring and disassociate from AP after next EAPOL frame */
90 /* */ 91 /* */
91 /* No necessary to clean all Tx ring, on RTMPHardTransmit will stop sending non-802.1X EAPOL packets */ 92 /* No necessary to clean all Tx ring, on RTMPHardTransmit will stop sending non-802.1X EAPOL packets */
92 /* if pAd->StaCfg.MicErrCnt greater than 2. */ 93 /* if pAd->StaCfg.MicErrCnt greater than 2. */
diff --git a/drivers/staging/rt2860/sta_ioctl.c b/drivers/staging/rt2860/sta_ioctl.c
index e095a44cbc0e..5717e12a9544 100644
--- a/drivers/staging/rt2860/sta_ioctl.c
+++ b/drivers/staging/rt2860/sta_ioctl.c
@@ -31,10 +31,11 @@
31 IOCTL related subroutines 31 IOCTL related subroutines
32 32
33 Revision History: 33 Revision History:
34 Who When What 34 Who When What
35 -------- ---------- ---------------------------------------------- 35 -------- ---------- ----------------------------------------------
36 Rory Chen 01-03-2003 created 36 Rory Chen 01-03-2003 created
37 Rory Chen 02-14-2005 modify to support RT61 37 Rory Chen 02-14-2005 modify to support RT61
38 Justin P. Mattock 11/07/2010 Fix typos
38*/ 39*/
39 40
40#include "rt_config.h" 41#include "rt_config.h"
@@ -851,7 +852,7 @@ int rt_ioctl_giwscan(struct net_device *dev,
851 852
852 /* 853 /*
853 Protocol: 854 Protocol:
854 it will show scanned AP's WirelessMode . 855 it will show scanned AP's WirelessMode.
855 it might be 856 it might be
856 802.11a 857 802.11a
857 802.11a/n 858 802.11a/n
@@ -875,13 +876,13 @@ int rt_ioctl_giwscan(struct net_device *dev,
875 strcpy(iwe.u.name, "802.11a"); 876 strcpy(iwe.u.name, "802.11a");
876 } else { 877 } else {
877 /* 878 /*
878 if one of non B mode rate is set supported rate . it mean G only. 879 if one of non B mode rate is set supported rate, it means G only.
879 */ 880 */
880 for (rateCnt = 0; 881 for (rateCnt = 0;
881 rateCnt < pBssEntry->SupRateLen; 882 rateCnt < pBssEntry->SupRateLen;
882 rateCnt++) { 883 rateCnt++) {
883 /* 884 /*
884 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate , it mean G only. 885 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate, it means G only.
885 */ 886 */
886 if (pBssEntry->SupRate[rateCnt] == 140 887 if (pBssEntry->SupRate[rateCnt] == 140
887 || pBssEntry->SupRate[rateCnt] == 888 || pBssEntry->SupRate[rateCnt] ==
@@ -1417,7 +1418,7 @@ int rt_ioctl_siwencode(struct net_device *dev,
1417 if ((index >= 0) && (index < 4)) { 1418 if ((index >= 0) && (index < 4)) {
1418 pAdapter->StaCfg.DefaultKeyId = index; 1419 pAdapter->StaCfg.DefaultKeyId = index;
1419 } else 1420 } else
1420 /* Don't complain if only change the mode */ 1421 /* Don't complain if the mode is only changed */
1421 if (!(erq->flags & IW_ENCODE_MODE)) 1422 if (!(erq->flags & IW_ENCODE_MODE))
1422 return -EINVAL; 1423 return -EINVAL;
1423 } 1424 }
@@ -2732,8 +2733,8 @@ int Set_NetworkType_Proc(struct rt_rtmp_adapter *pAdapter, char *arg)
2732 } 2733 }
2733 if (INFRA_ON(pAdapter)) { 2734 if (INFRA_ON(pAdapter)) {
2734 /*BOOLEAN Cancelled; */ 2735 /*BOOLEAN Cancelled; */
2735 /* Set the AutoReconnectSsid to prevent it reconnect to old SSID */ 2736 /* Set the AutoReconnectSsid to prevent it from reconnecting to the old SSID */
2736 /* Since calling this indicate user don't want to connect to that SSID anymore. */ 2737 /* Since calling this indicates users don't want to connect to that SSID anymore. */
2737 pAdapter->MlmeAux.AutoReconnectSsidLen = 32; 2738 pAdapter->MlmeAux.AutoReconnectSsidLen = 32;
2738 NdisZeroMemory(pAdapter->MlmeAux. 2739 NdisZeroMemory(pAdapter->MlmeAux.
2739 AutoReconnectSsid, 2740 AutoReconnectSsid,
@@ -2766,8 +2767,8 @@ int Set_NetworkType_Proc(struct rt_rtmp_adapter *pAdapter, char *arg)
2766 LinkDown(pAdapter, FALSE); 2767 LinkDown(pAdapter, FALSE);
2767 } 2768 }
2768 if (ADHOC_ON(pAdapter)) { 2769 if (ADHOC_ON(pAdapter)) {
2769 /* Set the AutoReconnectSsid to prevent it reconnect to old SSID */ 2770 /* Set the AutoReconnectSsid to prevent it from reconnecting to the old SSID */
2770 /* Since calling this indicate user don't want to connect to that SSID anymore. */ 2771 /* Since calling this indicates users don't want to connect to that SSID anymore. */
2771 pAdapter->MlmeAux.AutoReconnectSsidLen = 32; 2772 pAdapter->MlmeAux.AutoReconnectSsidLen = 32;
2772 NdisZeroMemory(pAdapter->MlmeAux. 2773 NdisZeroMemory(pAdapter->MlmeAux.
2773 AutoReconnectSsid, 2774 AutoReconnectSsid,
@@ -2884,7 +2885,7 @@ int Set_NetworkType_Proc(struct rt_rtmp_adapter *pAdapter, char *arg)
2884 } 2885 }
2885 /* Enable Rx with promiscuous reception */ 2886 /* Enable Rx with promiscuous reception */
2886 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3); 2887 RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3);
2887 /* ASIC supporsts sniffer function with replacing RSSI with timestamp. */ 2888 /* ASIC supports sniffer function with replacing RSSI with timestamp. */
2888 /*RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value); */ 2889 /*RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value); */
2889 /*Value |= (0x80); */ 2890 /*Value |= (0x80); */
2890 /*RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value); */ 2891 /*RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value); */
diff --git a/drivers/staging/rt2860/usb_main_dev.c b/drivers/staging/rt2860/usb_main_dev.c
index cd15daae5412..ee68d51caa4e 100644
--- a/drivers/staging/rt2860/usb_main_dev.c
+++ b/drivers/staging/rt2860/usb_main_dev.c
@@ -27,8 +27,8 @@
27#include "rt_config.h" 27#include "rt_config.h"
28 28
29/* Following information will be show when you run 'modinfo' */ 29/* Following information will be show when you run 'modinfo' */
30/* *** If you have a solution for the bug in current version of driver, please mail to me. */ 30/* If you have a solution for the bug in current version of driver, please e-mail me. */
31/* Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. *** */ 31/* Otherwise post to the forum at ralinktech's web site(www.ralinktech.com) and let all users help you. */
32MODULE_AUTHOR("Paul Lin <paul_lin@ralinktech.com>"); 32MODULE_AUTHOR("Paul Lin <paul_lin@ralinktech.com>");
33MODULE_DESCRIPTION("RT2870/RT3070 Wireless Lan Linux Driver"); 33MODULE_DESCRIPTION("RT2870/RT3070 Wireless Lan Linux Driver");
34MODULE_LICENSE("GPL"); 34MODULE_LICENSE("GPL");
@@ -233,7 +233,7 @@ BOOLEAN RT28XXChipsetCheck(IN void *_dev_p)
233 for (i = 0; i < rtusb_usb_id_len; i++) { 233 for (i = 0; i < rtusb_usb_id_len; i++) {
234 if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor && 234 if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor &&
235 dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct) { 235 dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct) {
236 printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n", 236 printk(KERN_INFO "rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
237 dev_p->descriptor.idVendor, 237 dev_p->descriptor.idVendor,
238 dev_p->descriptor.idProduct); 238 dev_p->descriptor.idProduct);
239 break; 239 break;
@@ -241,7 +241,7 @@ BOOLEAN RT28XXChipsetCheck(IN void *_dev_p)
241 } 241 }
242 242
243 if (i == rtusb_usb_id_len) { 243 if (i == rtusb_usb_id_len) {
244 printk("rt2870: Error! Device Descriptor not matching!\n"); 244 printk(KERN_ERR "rt2870: Error! Device Descriptor not matching!\n");
245 return FALSE; 245 return FALSE;
246 } 246 }
247 247
@@ -323,7 +323,7 @@ static BOOLEAN USBDevConfigInit(IN struct usb_device *dev,
323 323
324 if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0])) { 324 if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0])) {
325 printk 325 printk
326 ("%s: Could not find both bulk-in and bulk-out endpoints\n", 326 (KERN_ERR "%s: Could not find both bulk-in and bulk-out endpoints\n",
327 __FUNCTION__); 327 __FUNCTION__);
328 return FALSE; 328 return FALSE;
329 } 329 }
@@ -423,7 +423,7 @@ static int rt2870_resume(struct usb_interface *intf)
423/* Init driver module */ 423/* Init driver module */
424int __init rtusb_init(void) 424int __init rtusb_init(void)
425{ 425{
426 printk("rtusb init --->\n"); 426 printk(KERN_DEBUG "rtusb init --->\n");
427 return usb_register(&rtusb_driver); 427 return usb_register(&rtusb_driver);
428} 428}
429 429
@@ -431,7 +431,7 @@ int __init rtusb_init(void)
431void __exit rtusb_exit(void) 431void __exit rtusb_exit(void)
432{ 432{
433 usb_deregister(&rtusb_driver); 433 usb_deregister(&rtusb_driver);
434 printk("<--- rtusb exit\n"); 434 printk(KERN_DEBUG "<--- rtusb exit\n");
435} 435}
436 436
437module_init(rtusb_init); 437module_init(rtusb_init);
@@ -814,7 +814,7 @@ static void rt2870_disconnect(struct usb_device *dev, struct rt_rtmp_adapter *pA
814 dev->bus->bus_name, dev->devpath)); 814 dev->bus->bus_name, dev->devpath));
815 if (!pAd) { 815 if (!pAd) {
816 usb_put_dev(dev); 816 usb_put_dev(dev);
817 printk("rtusb_disconnect: pAd == NULL!\n"); 817 printk(KERN_ERR "rtusb_disconnect: pAd == NULL!\n");
818 return; 818 return;
819 } 819 }
820 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST); 820 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
@@ -884,8 +884,8 @@ static int __devinit rt2870_probe(IN struct usb_interface *intf,
884 if (net_dev == NULL) 884 if (net_dev == NULL)
885 goto err_out_free_radev; 885 goto err_out_free_radev;
886 886
887 /* Here are the net_device structure with usb specific parameters. */ 887 /* Here are the net_device structure with usb specific parameters.
888 /* for supporting Network Manager. 888 * for supporting Network Manager.
889 * Set the sysfs physical device reference for the network logical device if set prior to registration will 889 * Set the sysfs physical device reference for the network logical device if set prior to registration will
890 * cause a symlink during initialization. 890 * cause a symlink during initialization.
891 */ 891 */
diff --git a/drivers/staging/rt2860/wpa.h b/drivers/staging/rt2860/wpa.h
index 6199ae6cdcd0..116fc2caa886 100644
--- a/drivers/staging/rt2860/wpa.h
+++ b/drivers/staging/rt2860/wpa.h
@@ -32,13 +32,14 @@
32 Revision History: 32 Revision History:
33 Who When What 33 Who When What
34 -------- ---------- ---------------------------------------------- 34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs 35 Name Date Modification logs
36 Justin P. Mattock 11/07/2010 Fix a typo
36*/ 37*/
37 38
38#ifndef __WPA_H__ 39#ifndef __WPA_H__
39#define __WPA_H__ 40#define __WPA_H__
40 41
41/* EAPOL Key descripter frame format related length */ 42/* EAPOL Key descriptor frame format related length */
42#define LEN_KEY_DESC_NONCE 32 43#define LEN_KEY_DESC_NONCE 32
43#define LEN_KEY_DESC_IV 16 44#define LEN_KEY_DESC_IV 16
44#define LEN_KEY_DESC_RSC 8 45#define LEN_KEY_DESC_RSC 8
diff --git a/drivers/staging/rtl8192e/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192e/ieee80211/ieee80211_tx.c
index dd8a221e21ae..b26b5a8b5f6b 100644
--- a/drivers/staging/rtl8192e/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192e/ieee80211/ieee80211_tx.c
@@ -822,7 +822,7 @@ int ieee80211_rtl_xmit(struct sk_buff *skb, struct net_device *dev)
822 { 822 {
823 txb->queue_index = UP2AC(skb->priority); 823 txb->queue_index = UP2AC(skb->priority);
824 } else { 824 } else {
825 txb->queue_index = WME_AC_BK;; 825 txb->queue_index = WME_AC_BK;
826 } 826 }
827 827
828 828
diff --git a/drivers/staging/rtl8192e/r8192E_core.c b/drivers/staging/rtl8192e/r8192E_core.c
index b1786dcac245..fac4eee28e4e 100644
--- a/drivers/staging/rtl8192e/r8192E_core.c
+++ b/drivers/staging/rtl8192e/r8192E_core.c
@@ -89,7 +89,7 @@ u32 rt_global_debug_component =
89 // COMP_INTR | 89 // COMP_INTR |
90 COMP_ERR ; //always open err flags on 90 COMP_ERR ; //always open err flags on
91 91
92static const struct pci_device_id rtl8192_pci_id_tbl[] __devinitdata = { 92static DEFINE_PCI_DEVICE_TABLE(rtl8192_pci_id_tbl) = {
93#ifdef RTL8190P 93#ifdef RTL8190P
94 /* Realtek */ 94 /* Realtek */
95 /* Dlink */ 95 /* Dlink */
@@ -2283,9 +2283,7 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
2283 IMR_TXFOVW | IMR_BcnInt | IMR_TBDOK | IMR_TBDER); 2283 IMR_TXFOVW | IMR_BcnInt | IMR_TBDOK | IMR_TBDER);
2284 2284
2285 priv->AcmControl = 0; 2285 priv->AcmControl = 0;
2286 priv->pFirmware = (rt_firmware*)vmalloc(sizeof(rt_firmware)); 2286 priv->pFirmware = vzalloc(sizeof(rt_firmware));
2287 if (priv->pFirmware)
2288 memset(priv->pFirmware, 0, sizeof(rt_firmware));
2289 2287
2290 /* rx related queue */ 2288 /* rx related queue */
2291 skb_queue_head_init(&priv->rx_queue); 2289 skb_queue_head_init(&priv->rx_queue);
diff --git a/drivers/staging/rtl8192e/r819xE_phy.c b/drivers/staging/rtl8192e/r819xE_phy.c
index d83bcbcb20bd..50cd0e52b921 100644
--- a/drivers/staging/rtl8192e/r819xE_phy.c
+++ b/drivers/staging/rtl8192e/r819xE_phy.c
@@ -2596,7 +2596,7 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E
2596 break; 2596 break;
2597 } 2597 }
2598 2598
2599 return ret;; 2599 return ret;
2600 2600
2601} 2601}
2602/****************************************************************************** 2602/******************************************************************************
diff --git a/drivers/staging/rtl8192u/Makefile b/drivers/staging/rtl8192u/Makefile
index 206d924a707c..eefc657ce99e 100644
--- a/drivers/staging/rtl8192u/Makefile
+++ b/drivers/staging/rtl8192u/Makefile
@@ -9,7 +9,6 @@ ccflags-y += -DTHOMAS_BEACON -DTHOMAS_TASKLET -DTHOMAS_SKB -DTHOMAS_TURBO
9#ccflags-y += -DUSB_TX_DRIVER_AGGREGATION_ENABLE 9#ccflags-y += -DUSB_TX_DRIVER_AGGREGATION_ENABLE
10#ccflags-y += -DUSB_RX_AGGREGATION_SUPPORT 10#ccflags-y += -DUSB_RX_AGGREGATION_SUPPORT
11ccflags-y += -DUSE_ONE_PIPE 11ccflags-y += -DUSE_ONE_PIPE
12ccflags-y += -DENABLE_DOT11D
13ccflags-y += -Idrivers/staging/rtl8192u/ieee80211 12ccflags-y += -Idrivers/staging/rtl8192u/ieee80211
14 13
15r8192u_usb-y := r8192U_core.o r8180_93cx6.o r8192U_wx.o \ 14r8192u_usb-y := r8192U_core.o r8180_93cx6.o r8192U_wx.o \
diff --git a/drivers/staging/rtl8192u/dot11d.h b/drivers/staging/rtl8192u/dot11d.h
index d99cc030ec7a..92e7a00f3ee1 100644
--- a/drivers/staging/rtl8192u/dot11d.h
+++ b/drivers/staging/rtl8192u/dot11d.h
@@ -1,7 +1,6 @@
1#ifndef __INC_DOT11D_H 1#ifndef __INC_DOT11D_H
2#define __INC_DOT11D_H 2#define __INC_DOT11D_H
3 3
4#ifdef ENABLE_DOT11D
5#include "ieee80211/ieee80211.h" 4#include "ieee80211/ieee80211.h"
6 5
7 6
@@ -98,5 +97,4 @@ int ToLegalChannel(
98 struct ieee80211_device *dev, 97 struct ieee80211_device *dev,
99 u8 channel 98 u8 channel
100); 99);
101#endif /* ENABLE_DOT11D */
102#endif /* #ifndef __INC_DOT11D_H */ 100#endif /* #ifndef __INC_DOT11D_H */
diff --git a/drivers/staging/rtl8192u/ieee80211/Makefile b/drivers/staging/rtl8192u/ieee80211/Makefile
index 45704f85ef0b..0775c5599d69 100644
--- a/drivers/staging/rtl8192u/ieee80211/Makefile
+++ b/drivers/staging/rtl8192u/ieee80211/Makefile
@@ -20,7 +20,6 @@ ifeq ($(NIC_SELECT),RTL8192U)
20endif 20endif
21#ccflags-y := -DJOHN_NOCPY 21#ccflags-y := -DJOHN_NOCPY
22#flags to enable or disble 80211D feature 22#flags to enable or disble 80211D feature
23ccflags-y += -DENABLE_DOT11D
24ieee80211-rsl-objs := ieee80211_rx.o \ 23ieee80211-rsl-objs := ieee80211_rx.o \
25 ieee80211_softmac.o \ 24 ieee80211_softmac.o \
26 ieee80211_tx.o \ 25 ieee80211_tx.o \
@@ -75,7 +74,6 @@ CFLAGS += -I$(KSRC)/include -I.
75CFLAGS += -DMODVERSIONS -DEXPORT_SYMTAB -include $(KSRC)/include/linux/modversions.h 74CFLAGS += -DMODVERSIONS -DEXPORT_SYMTAB -include $(KSRC)/include/linux/modversions.h
76#Kernel 2.4.20 75#Kernel 2.4.20
77#CFLAGS += -D__NO_VERSION__ -DEXPORT_SYMTAB 76#CFLAGS += -D__NO_VERSION__ -DEXPORT_SYMTAB
78#CFLAGS += -DENABLE_DOT11D
79SMP := $(shell $(CC) $(MODCFLAGS) -E -dM $(CONFIG_FILE) | \ 77SMP := $(shell $(CC) $(MODCFLAGS) -E -dM $(CONFIG_FILE) | \
80 grep CONFIG_SMP | awk '{print $$3}') 78 grep CONFIG_SMP | awk '{print $$3}')
81ifneq ($(SMP),1) 79ifneq ($(SMP),1)
diff --git a/drivers/staging/rtl8192u/ieee80211/dot11d.c b/drivers/staging/rtl8192u/ieee80211/dot11d.c
index b91cbfcfa71f..ce63fc341c6e 100644
--- a/drivers/staging/rtl8192u/ieee80211/dot11d.c
+++ b/drivers/staging/rtl8192u/ieee80211/dot11d.c
@@ -1,4 +1,3 @@
1#ifdef ENABLE_DOT11D
2//----------------------------------------------------------------------------- 1//-----------------------------------------------------------------------------
3// File: 2// File:
4// Dot11d.c 3// Dot11d.c
@@ -220,4 +219,3 @@ EXPORT_SYMBOL(DOT11D_ScanComplete);
220EXPORT_SYMBOL(IsLegalChannel); 219EXPORT_SYMBOL(IsLegalChannel);
221EXPORT_SYMBOL(ToLegalChannel); 220EXPORT_SYMBOL(ToLegalChannel);
222 221
223#endif
diff --git a/drivers/staging/rtl8192u/ieee80211/dot11d.h b/drivers/staging/rtl8192u/ieee80211/dot11d.h
index 15b7a4ba37b6..54f2b4c434ff 100644
--- a/drivers/staging/rtl8192u/ieee80211/dot11d.h
+++ b/drivers/staging/rtl8192u/ieee80211/dot11d.h
@@ -1,10 +1,8 @@
1#ifndef __INC_DOT11D_H 1#ifndef __INC_DOT11D_H
2#define __INC_DOT11D_H 2#define __INC_DOT11D_H
3 3
4#ifdef ENABLE_DOT11D
5#include "ieee80211.h" 4#include "ieee80211.h"
6 5
7//#define ENABLE_DOT11D
8 6
9//#define DOT11D_MAX_CHNL_NUM 83 7//#define DOT11D_MAX_CHNL_NUM 83
10 8
@@ -98,5 +96,4 @@ int ToLegalChannel(
98 struct ieee80211_device * dev, 96 struct ieee80211_device * dev,
99 u8 channel 97 u8 channel
100); 98);
101#endif //ENABLE_DOT11D
102#endif // #ifndef __INC_DOT11D_H 99#endif // #ifndef __INC_DOT11D_H
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index e1216b704959..c0b844d75c0d 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -1572,10 +1572,8 @@ struct ieee80211_network {
1572#ifdef THOMAS_TURBO 1572#ifdef THOMAS_TURBO
1573 u8 Turbo_Enable;//enable turbo mode, added by thomas 1573 u8 Turbo_Enable;//enable turbo mode, added by thomas
1574#endif 1574#endif
1575#ifdef ENABLE_DOT11D
1576 u16 CountryIeLen; 1575 u16 CountryIeLen;
1577 u8 CountryIeBuf[MAX_IE_LEN]; 1576 u8 CountryIeBuf[MAX_IE_LEN];
1578#endif
1579 // HT Related, by amy, 2008.04.29 1577 // HT Related, by amy, 2008.04.29
1580 BSS_HT bssht; 1578 BSS_HT bssht;
1581 // Add to handle broadcom AP management frame CCK rate. 1579 // Add to handle broadcom AP management frame CCK rate.
@@ -1769,7 +1767,6 @@ typedef u32 RT_RF_CHANGE_SOURCE;
1769#define RF_CHANGE_BY_IPS BIT28 1767#define RF_CHANGE_BY_IPS BIT28
1770#define RF_CHANGE_BY_INIT 0 // Do not change the RFOff reason. Defined by Bruce, 2008-01-17. 1768#define RF_CHANGE_BY_INIT 0 // Do not change the RFOff reason. Defined by Bruce, 2008-01-17.
1771 1769
1772#ifdef ENABLE_DOT11D
1773typedef enum 1770typedef enum
1774{ 1771{
1775 COUNTRY_CODE_FCC = 0, 1772 COUNTRY_CODE_FCC = 0,
@@ -1784,7 +1781,6 @@ typedef enum
1784 COUNTRY_CODE_MIC, 1781 COUNTRY_CODE_MIC,
1785 COUNTRY_CODE_GLOBAL_DOMAIN 1782 COUNTRY_CODE_GLOBAL_DOMAIN
1786}country_code_type_t; 1783}country_code_type_t;
1787#endif
1788 1784
1789#define RT_MAX_LD_SLOT_NUM 10 1785#define RT_MAX_LD_SLOT_NUM 10
1790typedef struct _RT_LINK_DETECT_T{ 1786typedef struct _RT_LINK_DETECT_T{
@@ -1970,12 +1966,8 @@ struct ieee80211_device {
1970 1966
1971 /* map of allowed channels. 0 is dummy */ 1967 /* map of allowed channels. 0 is dummy */
1972 // FIXME: remeber to default to a basic channel plan depending of the PHY type 1968 // FIXME: remeber to default to a basic channel plan depending of the PHY type
1973#ifdef ENABLE_DOT11D
1974 void* pDot11dInfo; 1969 void* pDot11dInfo;
1975 bool bGlobalDomain; 1970 bool bGlobalDomain;
1976#else
1977 int channel_map[MAX_CHANNEL_NUMBER+1];
1978#endif
1979 int rate; /* current rate */ 1971 int rate; /* current rate */
1980 int basic_rate; 1972 int basic_rate;
1981 //FIXME: pleace callback, see if redundant with softmac_features 1973 //FIXME: pleace callback, see if redundant with softmac_features
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index c8ca9d8ed5d2..1ea8da3655ec 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -44,9 +44,7 @@
44#include <linux/ctype.h> 44#include <linux/ctype.h>
45 45
46#include "ieee80211.h" 46#include "ieee80211.h"
47#ifdef ENABLE_DOT11D
48#include "dot11d.h" 47#include "dot11d.h"
49#endif
50static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee, 48static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
51 struct sk_buff *skb, 49 struct sk_buff *skb,
52 struct ieee80211_rx_stats *rx_stats) 50 struct ieee80211_rx_stats *rx_stats)
@@ -1599,7 +1597,6 @@ static const char *get_info_element_string(u16 id)
1599} 1597}
1600#endif 1598#endif
1601 1599
1602#ifdef ENABLE_DOT11D
1603static inline void ieee80211_extract_country_ie( 1600static inline void ieee80211_extract_country_ie(
1604 struct ieee80211_device *ieee, 1601 struct ieee80211_device *ieee,
1605 struct ieee80211_info_element *info_element, 1602 struct ieee80211_info_element *info_element,
@@ -1632,7 +1629,6 @@ static inline void ieee80211_extract_country_ie(
1632 } 1629 }
1633 1630
1634} 1631}
1635#endif
1636 1632
1637int ieee80211_parse_info_param(struct ieee80211_device *ieee, 1633int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1638 struct ieee80211_info_element *info_element, 1634 struct ieee80211_info_element *info_element,
@@ -2086,14 +2082,12 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
2086 "QoS Error need to parse QOS_PARAMETER IE\n"); 2082 "QoS Error need to parse QOS_PARAMETER IE\n");
2087 break; 2083 break;
2088 2084
2089#ifdef ENABLE_DOT11D
2090 case MFIE_TYPE_COUNTRY: 2085 case MFIE_TYPE_COUNTRY:
2091 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n", 2086 IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
2092 info_element->len); 2087 info_element->len);
2093 //printk("=====>Receive <%s> Country IE\n",network->ssid); 2088 //printk("=====>Receive <%s> Country IE\n",network->ssid);
2094 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP 2089 ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
2095 break; 2090 break;
2096#endif
2097/* TODO */ 2091/* TODO */
2098 default: 2092 default:
2099 IEEE80211_DEBUG_MGMT 2093 IEEE80211_DEBUG_MGMT
@@ -2229,10 +2223,8 @@ static inline int ieee80211_network_init(
2229#ifdef THOMAS_TURBO 2223#ifdef THOMAS_TURBO
2230 network->Turbo_Enable = 0; 2224 network->Turbo_Enable = 0;
2231#endif 2225#endif
2232#ifdef ENABLE_DOT11D
2233 network->CountryIeLen = 0; 2226 network->CountryIeLen = 0;
2234 memset(network->CountryIeBuf, 0, MAX_IE_LEN); 2227 memset(network->CountryIeBuf, 0, MAX_IE_LEN);
2235#endif
2236//Initialize HT parameters 2228//Initialize HT parameters
2237 //ieee80211_ht_initialize(&network->bssht); 2229 //ieee80211_ht_initialize(&network->bssht);
2238 HTInitializeBssDesc(&network->bssht); 2230 HTInitializeBssDesc(&network->bssht);
@@ -2399,10 +2391,8 @@ static inline void update_network(struct ieee80211_network *dst,
2399 dst->Turbo_Enable = src->Turbo_Enable; 2391 dst->Turbo_Enable = src->Turbo_Enable;
2400#endif 2392#endif
2401 2393
2402#ifdef ENABLE_DOT11D
2403 dst->CountryIeLen = src->CountryIeLen; 2394 dst->CountryIeLen = src->CountryIeLen;
2404 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen); 2395 memcpy(dst->CountryIeBuf, src->CountryIeBuf, src->CountryIeLen);
2405#endif
2406 2396
2407 //added by amy for LEAP 2397 //added by amy for LEAP
2408 dst->bWithAironetIE = src->bWithAironetIE; 2398 dst->bWithAironetIE = src->bWithAironetIE;
@@ -2470,7 +2460,6 @@ static inline void ieee80211_process_probe_response(
2470 return; 2460 return;
2471 } 2461 }
2472 2462
2473#ifdef ENABLE_DOT11D
2474 // For Asus EeePc request, 2463 // For Asus EeePc request,
2475 // (1) if wireless adapter receive get any 802.11d country code in AP beacon, 2464 // (1) if wireless adapter receive get any 802.11d country code in AP beacon,
2476 // wireless adapter should follow the country code. 2465 // wireless adapter should follow the country code.
@@ -2527,7 +2516,6 @@ static inline void ieee80211_process_probe_response(
2527 } 2516 }
2528 } 2517 }
2529 } 2518 }
2530#endif
2531 2519
2532 /* The network parsed correctly -- so now we scan our known networks 2520 /* The network parsed correctly -- so now we scan our known networks
2533 * to see if we can find it in our list. 2521 * to see if we can find it in our list.
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index bc8c42533693..20f8c347cae4 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -21,9 +21,7 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/version.h> 22#include <linux/version.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#ifdef ENABLE_DOT11D
25#include "dot11d.h" 24#include "dot11d.h"
26#endif
27 25
28u8 rsn_authen_cipher_suite[16][4] = { 26u8 rsn_authen_cipher_suite[16][4] = {
29 {0x00,0x0F,0xAC,0x00}, //Use group key, //Reserved 27 {0x00,0x0F,0xAC,0x00}, //Use group key, //Reserved
@@ -430,10 +428,8 @@ void ieee80211_send_probe_requests(struct ieee80211_device *ieee)
430void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee) 428void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
431{ 429{
432 short ch = 0; 430 short ch = 0;
433#ifdef ENABLE_DOT11D
434 u8 channel_map[MAX_CHANNEL_NUMBER+1]; 431 u8 channel_map[MAX_CHANNEL_NUMBER+1];
435 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); 432 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
436#endif
437 down(&ieee->scan_sem); 433 down(&ieee->scan_sem);
438 434
439 while(1) 435 while(1)
@@ -443,11 +439,7 @@ void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
443 ch++; 439 ch++;
444 if (ch > MAX_CHANNEL_NUMBER) 440 if (ch > MAX_CHANNEL_NUMBER)
445 goto out; /* scan completed */ 441 goto out; /* scan completed */
446#ifdef ENABLE_DOT11D
447 }while(!channel_map[ch]); 442 }while(!channel_map[ch]);
448#else
449 }while(!ieee->channel_map[ch]);
450#endif
451 443
452 /* this function can be called in two situations 444 /* this function can be called in two situations
453 * 1- We have switched to ad-hoc mode and we are 445 * 1- We have switched to ad-hoc mode and we are
@@ -471,9 +463,7 @@ void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
471 if (ieee->state == IEEE80211_LINKED) 463 if (ieee->state == IEEE80211_LINKED)
472 goto out; 464 goto out;
473 ieee->set_chan(ieee->dev, ch); 465 ieee->set_chan(ieee->dev, ch);
474#ifdef ENABLE_DOT11D
475 if(channel_map[ch] == 1) 466 if(channel_map[ch] == 1)
476#endif
477 ieee80211_send_probe_requests(ieee); 467 ieee80211_send_probe_requests(ieee);
478 468
479 /* this prevent excessive time wait when we 469 /* this prevent excessive time wait when we
@@ -496,10 +486,8 @@ out:
496 } 486 }
497 else{ 487 else{
498 ieee->sync_scan_hurryup = 0; 488 ieee->sync_scan_hurryup = 0;
499#ifdef ENABLE_DOT11D
500 if(IS_DOT11D_ENABLE(ieee)) 489 if(IS_DOT11D_ENABLE(ieee))
501 DOT11D_ScanComplete(ieee); 490 DOT11D_ScanComplete(ieee);
502#endif
503 up(&ieee->scan_sem); 491 up(&ieee->scan_sem);
504} 492}
505} 493}
@@ -510,10 +498,8 @@ void ieee80211_softmac_scan_wq(struct work_struct *work)
510 struct delayed_work *dwork = container_of(work, struct delayed_work, work); 498 struct delayed_work *dwork = container_of(work, struct delayed_work, work);
511 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq); 499 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq);
512 static short watchdog = 0; 500 static short watchdog = 0;
513#ifdef ENABLE_DOT11D
514 u8 channel_map[MAX_CHANNEL_NUMBER+1]; 501 u8 channel_map[MAX_CHANNEL_NUMBER+1];
515 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); 502 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
516#endif
517 if(!ieee->ieee_up) 503 if(!ieee->ieee_up)
518 return; 504 return;
519 down(&ieee->scan_sem); 505 down(&ieee->scan_sem);
@@ -523,25 +509,16 @@ void ieee80211_softmac_scan_wq(struct work_struct *work)
523 if (watchdog++ > MAX_CHANNEL_NUMBER) 509 if (watchdog++ > MAX_CHANNEL_NUMBER)
524 { 510 {
525 //if current channel is not in channel map, set to default channel. 511 //if current channel is not in channel map, set to default channel.
526 #ifdef ENABLE_DOT11D 512 if (!channel_map[ieee->current_network.channel]) {
527 if (!channel_map[ieee->current_network.channel]);
528 #else
529 if (!ieee->channel_map[ieee->current_network.channel]);
530 #endif
531 ieee->current_network.channel = 6; 513 ieee->current_network.channel = 6;
532 goto out; /* no good chans */ 514 goto out; /* no good chans */
515 }
533 } 516 }
534#ifdef ENABLE_DOT11D
535 }while(!channel_map[ieee->current_network.channel]); 517 }while(!channel_map[ieee->current_network.channel]);
536#else
537 }while(!ieee->channel_map[ieee->current_network.channel]);
538#endif
539 if (ieee->scanning == 0 ) 518 if (ieee->scanning == 0 )
540 goto out; 519 goto out;
541 ieee->set_chan(ieee->dev, ieee->current_network.channel); 520 ieee->set_chan(ieee->dev, ieee->current_network.channel);
542#ifdef ENABLE_DOT11D
543 if(channel_map[ieee->current_network.channel] == 1) 521 if(channel_map[ieee->current_network.channel] == 1)
544#endif
545 ieee80211_send_probe_requests(ieee); 522 ieee80211_send_probe_requests(ieee);
546 523
547 524
@@ -550,10 +527,8 @@ void ieee80211_softmac_scan_wq(struct work_struct *work)
550 up(&ieee->scan_sem); 527 up(&ieee->scan_sem);
551 return; 528 return;
552out: 529out:
553#ifdef ENABLE_DOT11D
554 if(IS_DOT11D_ENABLE(ieee)) 530 if(IS_DOT11D_ENABLE(ieee))
555 DOT11D_ScanComplete(ieee); 531 DOT11D_ScanComplete(ieee);
556#endif
557 ieee->actscanning = false; 532 ieee->actscanning = false;
558 watchdog = 0; 533 watchdog = 0;
559 ieee->scanning = 0; 534 ieee->scanning = 0;
@@ -635,7 +610,6 @@ void ieee80211_stop_scan(struct ieee80211_device *ieee)
635/* called with ieee->lock held */ 610/* called with ieee->lock held */
636void ieee80211_start_scan(struct ieee80211_device *ieee) 611void ieee80211_start_scan(struct ieee80211_device *ieee)
637{ 612{
638#ifdef ENABLE_DOT11D
639 if(IS_DOT11D_ENABLE(ieee) ) 613 if(IS_DOT11D_ENABLE(ieee) )
640 { 614 {
641 if(IS_COUNTRY_IE_VALID(ieee)) 615 if(IS_COUNTRY_IE_VALID(ieee))
@@ -643,7 +617,6 @@ void ieee80211_start_scan(struct ieee80211_device *ieee)
643 RESET_CIE_WATCHDOG(ieee); 617 RESET_CIE_WATCHDOG(ieee);
644 } 618 }
645 } 619 }
646#endif
647 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN){ 620 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN){
648 if (ieee->scanning == 0){ 621 if (ieee->scanning == 0){
649 ieee->scanning = 1; 622 ieee->scanning = 1;
@@ -657,7 +630,6 @@ void ieee80211_start_scan(struct ieee80211_device *ieee)
657/* called with wx_sem held */ 630/* called with wx_sem held */
658void ieee80211_start_scan_syncro(struct ieee80211_device *ieee) 631void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
659{ 632{
660#ifdef ENABLE_DOT11D
661 if(IS_DOT11D_ENABLE(ieee) ) 633 if(IS_DOT11D_ENABLE(ieee) )
662 { 634 {
663 if(IS_COUNTRY_IE_VALID(ieee)) 635 if(IS_COUNTRY_IE_VALID(ieee))
@@ -665,7 +637,6 @@ void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
665 RESET_CIE_WATCHDOG(ieee); 637 RESET_CIE_WATCHDOG(ieee);
666 } 638 }
667 } 639 }
668#endif
669 ieee->sync_scan_hurryup = 0; 640 ieee->sync_scan_hurryup = 0;
670 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) 641 if (ieee->softmac_features & IEEE_SOFTMAC_SCAN)
671 ieee80211_softmac_scan_syncro(ieee); 642 ieee80211_softmac_scan_syncro(ieee);
@@ -2390,11 +2361,9 @@ void ieee80211_start_ibss_wq(struct work_struct *work)
2390 ieee80211_softmac_check_all_nets(ieee); 2361 ieee80211_softmac_check_all_nets(ieee);
2391 2362
2392 2363
2393#ifdef ENABLE_DOT11D //if creating an ad-hoc, set its channel to 10 temporarily--this is the requirement for ASUS, not 11D, so disable 11d.
2394// if((IS_DOT11D_ENABLE(ieee)) && (ieee->state == IEEE80211_NOLINK)) 2364// if((IS_DOT11D_ENABLE(ieee)) && (ieee->state == IEEE80211_NOLINK))
2395 if (ieee->state == IEEE80211_NOLINK) 2365 if (ieee->state == IEEE80211_NOLINK)
2396 ieee->current_network.channel = 6; 2366 ieee->current_network.channel = 6;
2397#endif
2398 /* if not then the state is not linked. Maybe the user swithced to 2367 /* if not then the state is not linked. Maybe the user swithced to
2399 * ad-hoc mode just after being in monitor mode, or just after 2368 * ad-hoc mode just after being in monitor mode, or just after
2400 * being very few time in managed mode (so the card have had no 2369 * being very few time in managed mode (so the card have had no
@@ -2483,7 +2452,6 @@ inline void ieee80211_start_ibss(struct ieee80211_device *ieee)
2483void ieee80211_start_bss(struct ieee80211_device *ieee) 2452void ieee80211_start_bss(struct ieee80211_device *ieee)
2484{ 2453{
2485 unsigned long flags; 2454 unsigned long flags;
2486#ifdef ENABLE_DOT11D
2487 // 2455 //
2488 // Ref: 802.11d 11.1.3.3 2456 // Ref: 802.11d 11.1.3.3
2489 // STA shall not start a BSS unless properly formed Beacon frame including a Country IE. 2457 // STA shall not start a BSS unless properly formed Beacon frame including a Country IE.
@@ -2495,7 +2463,6 @@ void ieee80211_start_bss(struct ieee80211_device *ieee)
2495 return; 2463 return;
2496 } 2464 }
2497 } 2465 }
2498#endif
2499 /* check if we have already found the net we 2466 /* check if we have already found the net we
2500 * are interested in (if any). 2467 * are interested in (if any).
2501 * if not (we are disassociated and we are not 2468 * if not (we are disassociated and we are not
@@ -2530,10 +2497,8 @@ void ieee80211_disassociate(struct ieee80211_device *ieee)
2530 2497
2531 if (ieee->data_hard_stop) 2498 if (ieee->data_hard_stop)
2532 ieee->data_hard_stop(ieee->dev); 2499 ieee->data_hard_stop(ieee->dev);
2533#ifdef ENABLE_DOT11D
2534 if(IS_DOT11D_ENABLE(ieee)) 2500 if(IS_DOT11D_ENABLE(ieee))
2535 Dot11d_Reset(ieee); 2501 Dot11d_Reset(ieee);
2536#endif
2537 ieee->state = IEEE80211_NOLINK; 2502 ieee->state = IEEE80211_NOLINK;
2538 ieee->is_set_key = false; 2503 ieee->is_set_key = false;
2539 ieee->link_change(ieee->dev); 2504 ieee->link_change(ieee->dev);
@@ -2669,11 +2634,7 @@ void ieee80211_start_protocol(struct ieee80211_device *ieee)
2669 ch++; 2634 ch++;
2670 if (ch > MAX_CHANNEL_NUMBER) 2635 if (ch > MAX_CHANNEL_NUMBER)
2671 return; /* no channel found */ 2636 return; /* no channel found */
2672#ifdef ENABLE_DOT11D
2673 }while(!GET_DOT11D_INFO(ieee)->channel_map[ch]); 2637 }while(!GET_DOT11D_INFO(ieee)->channel_map[ch]);
2674#else
2675 }while(!ieee->channel_map[ch]);
2676#endif
2677 ieee->current_network.channel = ch; 2638 ieee->current_network.channel = ch;
2678 } 2639 }
2679 2640
@@ -2721,11 +2682,9 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee)
2721 for(i = 0; i < 5; i++) { 2682 for(i = 0; i < 5; i++) {
2722 ieee->seq_ctrl[i] = 0; 2683 ieee->seq_ctrl[i] = 0;
2723 } 2684 }
2724#ifdef ENABLE_DOT11D
2725 ieee->pDot11dInfo = kzalloc(sizeof(RT_DOT11D_INFO), GFP_ATOMIC); 2685 ieee->pDot11dInfo = kzalloc(sizeof(RT_DOT11D_INFO), GFP_ATOMIC);
2726 if (!ieee->pDot11dInfo) 2686 if (!ieee->pDot11dInfo)
2727 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for DOT11D\n"); 2687 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc memory for DOT11D\n");
2728#endif
2729 //added for AP roaming 2688 //added for AP roaming
2730 ieee->LinkDetectInfo.SlotNum = 2; 2689 ieee->LinkDetectInfo.SlotNum = 2;
2731 ieee->LinkDetectInfo.NumRecvBcnInPeriod=0; 2690 ieee->LinkDetectInfo.NumRecvBcnInPeriod=0;
@@ -2796,13 +2755,11 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee)
2796void ieee80211_softmac_free(struct ieee80211_device *ieee) 2755void ieee80211_softmac_free(struct ieee80211_device *ieee)
2797{ 2756{
2798 down(&ieee->wx_sem); 2757 down(&ieee->wx_sem);
2799#ifdef ENABLE_DOT11D
2800 if(NULL != ieee->pDot11dInfo) 2758 if(NULL != ieee->pDot11dInfo)
2801 { 2759 {
2802 kfree(ieee->pDot11dInfo); 2760 kfree(ieee->pDot11dInfo);
2803 ieee->pDot11dInfo = NULL; 2761 ieee->pDot11dInfo = NULL;
2804 } 2762 }
2805#endif
2806 del_timer_sync(&ieee->associate_timer); 2763 del_timer_sync(&ieee->associate_timer);
2807 2764
2808 cancel_delayed_work(&ieee->associate_retry_wq); 2765 cancel_delayed_work(&ieee->associate_retry_wq);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
index f335c258ba84..cb5a3c32974e 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
@@ -15,9 +15,7 @@
15 15
16 16
17#include "ieee80211.h" 17#include "ieee80211.h"
18#ifdef ENABLE_DOT11D
19#include "dot11d.h" 18#include "dot11d.h"
20#endif
21/* FIXME: add A freqs */ 19/* FIXME: add A freqs */
22 20
23const long ieee80211_wlan_frequencies[] = { 21const long ieee80211_wlan_frequencies[] = {
@@ -63,12 +61,10 @@ int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info
63 61
64 }else { /* Set the channel */ 62 }else { /* Set the channel */
65 63
66#ifdef ENABLE_DOT11D
67 if (!(GET_DOT11D_INFO(ieee)->channel_map)[fwrq->m]) { 64 if (!(GET_DOT11D_INFO(ieee)->channel_map)[fwrq->m]) {
68 ret = -EINVAL; 65 ret = -EINVAL;
69 goto out; 66 goto out;
70 } 67 }
71#endif
72 ieee->current_network.channel = fwrq->m; 68 ieee->current_network.channel = fwrq->m;
73 ieee->set_chan(ieee->dev, ieee->current_network.channel); 69 ieee->set_chan(ieee->dev, ieee->current_network.channel);
74 70
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index 81aa2ed226ac..ec7845ecdb7e 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -754,7 +754,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
754 { 754 {
755 txb->queue_index = UP2AC(skb->priority); 755 txb->queue_index = UP2AC(skb->priority);
756 } else { 756 } else {
757 txb->queue_index = WME_AC_BK;; 757 txb->queue_index = WME_AC_BK;
758 } 758 }
759 759
760 760
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index 494f180acc26..ae4f2b9d9e8f 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -77,9 +77,7 @@ double __extendsfdf2(float a) {return a;}
77#include "r8192_pm.h" 77#include "r8192_pm.h"
78#endif 78#endif
79 79
80#ifdef ENABLE_DOT11D
81#include "dot11d.h" 80#include "dot11d.h"
82#endif
83//set here to open your trace code. //WB 81//set here to open your trace code. //WB
84u32 rt_global_debug_component = \ 82u32 rt_global_debug_component = \
85 // COMP_INIT | 83 // COMP_INIT |
@@ -166,7 +164,6 @@ static struct usb_driver rtl8192_usb_driver = {
166#endif 164#endif
167}; 165};
168 166
169#ifdef ENABLE_DOT11D
170 167
171typedef struct _CHANNEL_LIST 168typedef struct _CHANNEL_LIST
172{ 169{
@@ -242,9 +239,7 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv)
242 } 239 }
243 return; 240 return;
244} 241}
245#endif
246 242
247#define eqMacAddr(a,b) ( ((a)[0]==(b)[0] && (a)[1]==(b)[1] && (a)[2]==(b)[2] && (a)[3]==(b)[3] && (a)[4]==(b)[4] && (a)[5]==(b)[5]) ? 1:0 )
248 243
249#define rx_hal_is_cck_rate(_pdrvinfo)\ 244#define rx_hal_is_cck_rate(_pdrvinfo)\
250 (_pdrvinfo->RxRate == DESC90_RATE1M ||\ 245 (_pdrvinfo->RxRate == DESC90_RATE1M ||\
@@ -1507,7 +1502,7 @@ static void rtl8192_tx_isr(struct urb *tx_urb)
1507 { 1502 {
1508 // 1503 //
1509 // Handle HW Beacon: 1504 // Handle HW Beacon:
1510 // We had transfer our beacon frame to host controler at this moment. 1505 // We had transfer our beacon frame to host controller at this moment.
1511 // 1506 //
1512 // 1507 //
1513 // Caution: 1508 // Caution:
@@ -2203,6 +2198,8 @@ short rtl8192_usb_initendpoints(struct net_device *dev)
2203 2198
2204 priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB+1), 2199 priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB+1),
2205 GFP_KERNEL); 2200 GFP_KERNEL);
2201 if (priv->rx_urb == NULL)
2202 return -ENOMEM;
2206 2203
2207#ifndef JACKSON_NEW_RX 2204#ifndef JACKSON_NEW_RX
2208 for(i=0;i<(MAX_RX_URB+1);i++){ 2205 for(i=0;i<(MAX_RX_URB+1);i++){
@@ -3155,7 +3152,6 @@ static void rtl8192_read_eeprom_info(struct net_device* dev)
3155short rtl8192_get_channel_map(struct net_device * dev) 3152short rtl8192_get_channel_map(struct net_device * dev)
3156{ 3153{
3157 struct r8192_priv *priv = ieee80211_priv(dev); 3154 struct r8192_priv *priv = ieee80211_priv(dev);
3158#ifdef ENABLE_DOT11D
3159 if(priv->ChannelPlan > COUNTRY_CODE_GLOBAL_DOMAIN){ 3155 if(priv->ChannelPlan > COUNTRY_CODE_GLOBAL_DOMAIN){
3160 printk("rtl8180_init:Error channel plan! Set to default.\n"); 3156 printk("rtl8180_init:Error channel plan! Set to default.\n");
3161 priv->ChannelPlan= 0; 3157 priv->ChannelPlan= 0;
@@ -3163,21 +3159,6 @@ short rtl8192_get_channel_map(struct net_device * dev)
3163 RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan); 3159 RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan);
3164 3160
3165 rtl819x_set_channel_map(priv->ChannelPlan, priv); 3161 rtl819x_set_channel_map(priv->ChannelPlan, priv);
3166#else
3167 int ch,i;
3168 //Set Default Channel Plan
3169 if(!channels){
3170 DMESG("No channels, aborting");
3171 return -1;
3172 }
3173 ch=channels;
3174 priv->ChannelPlan= 0;//hikaru
3175 // set channels 1..14 allowed in given locale
3176 for (i=1; i<=14; i++) {
3177 (priv->ieee80211->channel_map)[i] = (u8)(ch & 0x01);
3178 ch >>= 1;
3179 }
3180#endif
3181 return 0; 3162 return 0;
3182} 3163}
3183 3164
@@ -5085,7 +5066,7 @@ static void rtl8192_query_rxphystatus(
5085 //Get Rx snr value in DB 5066 //Get Rx snr value in DB
5086 tmp_rxsnr = pofdm_buf->rxsnr_X[i]; 5067 tmp_rxsnr = pofdm_buf->rxsnr_X[i];
5087 rx_snrX = (char)(tmp_rxsnr); 5068 rx_snrX = (char)(tmp_rxsnr);
5088 //rx_snrX >>= 1;; 5069 //rx_snrX >>= 1;
5089 rx_snrX /= 2; 5070 rx_snrX /= 2;
5090 priv->stats.rxSNRdB[i] = (long)rx_snrX; 5071 priv->stats.rxSNRdB[i] = (long)rx_snrX;
5091 5072
diff --git a/drivers/staging/rtl8192u/r8192U_wx.c b/drivers/staging/rtl8192u/r8192U_wx.c
index 25d5c870b0fb..f6408f98ede6 100644
--- a/drivers/staging/rtl8192u/r8192U_wx.c
+++ b/drivers/staging/rtl8192u/r8192U_wx.c
@@ -21,9 +21,7 @@
21#include "r8192U.h" 21#include "r8192U.h"
22#include "r8192U_hw.h" 22#include "r8192U_hw.h"
23 23
24#ifdef ENABLE_DOT11D
25#include "dot11d.h" 24#include "dot11d.h"
26#endif
27 25
28#define RATE_COUNT 12 26#define RATE_COUNT 12
29u32 rtl8180_rates[] = {1000000,2000000,5500000,11000000, 27u32 rtl8180_rates[] = {1000000,2000000,5500000,11000000,
@@ -458,11 +456,7 @@ static int rtl8180_wx_get_range(struct net_device *dev,
458 for (i = 0, val = 0; i < 14; i++) { 456 for (i = 0, val = 0; i < 14; i++) {
459 457
460 // Include only legal frequencies for some countries 458 // Include only legal frequencies for some countries
461#ifdef ENABLE_DOT11D
462 if ((GET_DOT11D_INFO(priv->ieee80211)->channel_map)[i+1]) { 459 if ((GET_DOT11D_INFO(priv->ieee80211)->channel_map)[i+1]) {
463#else
464 if ((priv->ieee80211->channel_map)[i+1]) {
465#endif
466 range->freq[val].i = i + 1; 460 range->freq[val].i = i + 1;
467 range->freq[val].m = ieee80211_wlan_frequencies[i] * 100000; 461 range->freq[val].m = ieee80211_wlan_frequencies[i] * 100000;
468 range->freq[val].e = 1; 462 range->freq[val].e = 1;
diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c
index a3adaedece9a..41684e8fcf4c 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -6,9 +6,7 @@
6#include "r8192U_dm.h" 6#include "r8192U_dm.h"
7#include "r819xU_firmware_img.h" 7#include "r819xU_firmware_img.h"
8 8
9#ifdef ENABLE_DOT11D
10#include "dot11d.h" 9#include "dot11d.h"
11#endif
12static u32 RF_CHANNEL_TABLE_ZEBRA[] = { 10static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
13 0, 11 0,
14 0x085c, //2412 1 12 0x085c, //2412 1
@@ -1011,7 +1009,7 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E
1011 break; 1009 break;
1012 } 1010 }
1013 1011
1014 return ret;; 1012 return ret;
1015 1013
1016} 1014}
1017/****************************************************************************** 1015/******************************************************************************
@@ -1257,13 +1255,11 @@ u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel, u8* stage, u
1257 1255
1258 RT_TRACE(COMP_CH, "====>%s()====stage:%d, step:%d, channel:%d\n", __FUNCTION__, *stage, *step, channel); 1256 RT_TRACE(COMP_CH, "====>%s()====stage:%d, step:%d, channel:%d\n", __FUNCTION__, *stage, *step, channel);
1259// RT_ASSERT(IsLegalChannel(Adapter, channel), ("illegal channel: %d\n", channel)); 1257// RT_ASSERT(IsLegalChannel(Adapter, channel), ("illegal channel: %d\n", channel));
1260#ifdef ENABLE_DOT11D
1261 if (!IsLegalChannel(priv->ieee80211, channel)) 1258 if (!IsLegalChannel(priv->ieee80211, channel))
1262 { 1259 {
1263 RT_TRACE(COMP_ERR, "=============>set to illegal channel:%d\n", channel); 1260 RT_TRACE(COMP_ERR, "=============>set to illegal channel:%d\n", channel);
1264 return true; //return true to tell upper caller function this channel setting is finished! Or it will in while loop. 1261 return true; //return true to tell upper caller function this channel setting is finished! Or it will in while loop.
1265 } 1262 }
1266#endif
1267//FIXME:need to check whether channel is legal or not here.WB 1263//FIXME:need to check whether channel is legal or not here.WB
1268 1264
1269 1265
diff --git a/drivers/staging/rtl8712/TODO b/drivers/staging/rtl8712/TODO
index 5c888214666e..2aa5deb3af7b 100644
--- a/drivers/staging/rtl8712/TODO
+++ b/drivers/staging/rtl8712/TODO
@@ -3,7 +3,6 @@ TODO:
3- switch to use LIB80211 3- switch to use LIB80211
4- switch to use MAC80211 4- switch to use MAC80211
5- checkpatch.pl fixes - only a few remain 5- checkpatch.pl fixes - only a few remain
6- sparse fixes
7- switch from large inline firmware file to use the firmware interface 6- switch from large inline firmware file to use the firmware interface
8 and add the file to the linux-firmware package. 7 and add the file to the linux-firmware package.
9 8
diff --git a/drivers/staging/rtl8712/osdep_service.h b/drivers/staging/rtl8712/osdep_service.h
index 831d81e0e429..36eeb5a1b5a5 100644
--- a/drivers/staging/rtl8712/osdep_service.h
+++ b/drivers/staging/rtl8712/osdep_service.h
@@ -195,10 +195,7 @@ static inline void sleep_schedulable(int ms)
195 195
196static inline u8 *_malloc(u32 sz) 196static inline u8 *_malloc(u32 sz)
197{ 197{
198 u8 *pbuf; 198 return kmalloc(sz, GFP_ATOMIC);
199
200 pbuf = kmalloc(sz, GFP_ATOMIC);
201 return pbuf;
202} 199}
203 200
204static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer) 201static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
@@ -220,34 +217,22 @@ static inline void flush_signals_thread(void)
220 217
221static inline u32 _RND8(u32 sz) 218static inline u32 _RND8(u32 sz)
222{ 219{
223 u32 val; 220 return ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
224
225 val = ((sz >> 3) + ((sz & 7) ? 1 : 0)) << 3;
226 return val;
227} 221}
228 222
229static inline u32 _RND128(u32 sz) 223static inline u32 _RND128(u32 sz)
230{ 224{
231 u32 val; 225 return ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
232
233 val = ((sz >> 7) + ((sz & 127) ? 1 : 0)) << 7;
234 return val;
235} 226}
236 227
237static inline u32 _RND256(u32 sz) 228static inline u32 _RND256(u32 sz)
238{ 229{
239 u32 val; 230 return ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
240
241 val = ((sz >> 8) + ((sz & 255) ? 1 : 0)) << 8;
242 return val;
243} 231}
244 232
245static inline u32 _RND512(u32 sz) 233static inline u32 _RND512(u32 sz)
246{ 234{
247 u32 val; 235 return ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
248
249 val = ((sz >> 9) + ((sz & 511) ? 1 : 0)) << 9;
250 return val;
251} 236}
252 237
253#define STRUCT_PACKED __attribute__ ((packed)) 238#define STRUCT_PACKED __attribute__ ((packed))
diff --git a/drivers/staging/rtl8712/rtl8712_efuse.c b/drivers/staging/rtl8712/rtl8712_efuse.c
index 9730ae1c58d5..1dc12b7a2f52 100644
--- a/drivers/staging/rtl8712/rtl8712_efuse.c
+++ b/drivers/staging/rtl8712/rtl8712_efuse.c
@@ -428,7 +428,7 @@ u8 r8712_efuse_access(struct _adapter *padapter, u8 bRead, u16 start_addr,
428 u16 cnts, u8 *data) 428 u16 cnts, u8 *data)
429{ 429{
430 int i; 430 int i;
431 u8 res = true;; 431 u8 res = true;
432 432
433 if (start_addr > EFUSE_MAX_SIZE) 433 if (start_addr > EFUSE_MAX_SIZE)
434 return false; 434 return false;
diff --git a/drivers/staging/rtl8712/rtl8712_xmit.c b/drivers/staging/rtl8712/rtl8712_xmit.c
index 8edc518536f9..88a15049bc2a 100644
--- a/drivers/staging/rtl8712/rtl8712_xmit.c
+++ b/drivers/staging/rtl8712/rtl8712_xmit.c
@@ -148,7 +148,7 @@ static u32 get_ff_hwaddr(struct xmit_frame *pxmitframe)
148 case 0x11: 148 case 0x11:
149 case 0x12: 149 case 0x12:
150 case 0x13: 150 case 0x13:
151 addr = RTL8712_DMA_H2CCMD;; 151 addr = RTL8712_DMA_H2CCMD;
152 break; 152 break;
153 default: 153 default:
154 addr = RTL8712_DMA_BEQ;/*RTL8712_EP_LO;*/ 154 addr = RTL8712_DMA_BEQ;/*RTL8712_EP_LO;*/
diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c b/drivers/staging/rtl8712/rtl871x_xmit.c
index b8195e3a72d4..75f1a6bba2f6 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.c
+++ b/drivers/staging/rtl8712/rtl871x_xmit.c
@@ -372,7 +372,7 @@ static sint xmitframe_addmic(struct _adapter *padapter,
372 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 372 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
373 0x0, 0x0}; 373 0x0, 0x0};
374 datalen = pattrib->pktlen - pattrib->hdrlen; 374 datalen = pattrib->pktlen - pattrib->hdrlen;
375 pframe = pxmitframe->buf_addr + TXDESC_OFFSET;; 375 pframe = pxmitframe->buf_addr + TXDESC_OFFSET;
376 if (bmcst) { 376 if (bmcst) {
377 if (!memcmp(psecuritypriv->XGrptxmickey 377 if (!memcmp(psecuritypriv->XGrptxmickey
378 [psecuritypriv->XGrpKeyid].skey, 378 [psecuritypriv->XGrpKeyid].skey,
diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c
index f1f0c63e5bbc..a692ee88b9e9 100644
--- a/drivers/staging/rtl8712/usb_intf.c
+++ b/drivers/staging/rtl8712/usb_intf.c
@@ -527,7 +527,7 @@ error:
527static void r871xu_dev_remove(struct usb_interface *pusb_intf) 527static void r871xu_dev_remove(struct usb_interface *pusb_intf)
528{ 528{
529 struct net_device *pnetdev = usb_get_intfdata(pusb_intf); 529 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
530 struct _adapter *padapter = (struct _adapter *)netdev_priv(pnetdev); 530 struct _adapter *padapter = netdev_priv(pnetdev);
531 struct usb_device *udev = interface_to_usbdev(pusb_intf); 531 struct usb_device *udev = interface_to_usbdev(pusb_intf);
532 532
533 if (padapter) { 533 if (padapter) {
diff --git a/drivers/staging/sep/Kconfig b/drivers/staging/sep/Kconfig
new file mode 100644
index 000000000000..92bf16667d04
--- /dev/null
+++ b/drivers/staging/sep/Kconfig
@@ -0,0 +1,10 @@
1config DX_SEP
2 tristate "Discretix SEP driver"
3 depends on PCI
4 help
5 Discretix SEP driver; used for the security processor subsystem
6 on bard the Intel Mobile Internet Device.
7
8 The driver's name is sep_driver.
9
10 If unsure, select N.
diff --git a/drivers/staging/sep/Makefile b/drivers/staging/sep/Makefile
new file mode 100644
index 000000000000..628d5f919414
--- /dev/null
+++ b/drivers/staging/sep/Makefile
@@ -0,0 +1,2 @@
1obj-$(CONFIG_DX_SEP) := sep_driver.o
2
diff --git a/drivers/staging/sep/TODO b/drivers/staging/sep/TODO
new file mode 100644
index 000000000000..089c2406345e
--- /dev/null
+++ b/drivers/staging/sep/TODO
@@ -0,0 +1,5 @@
1Todo's so far (from Alan Cox)
2- Check whether it can be plugged into any of the kernel crypto API
3 interfaces - Crypto API 'glue' is still not ready to submit
4- Clean up unused ioctls - Needs vendor help
5- Clean up unused fields in ioctl structures - Needs vendor help
diff --git a/drivers/staging/sep/sep_dev.h b/drivers/staging/sep/sep_dev.h
new file mode 100644
index 000000000000..0ffe68cb7140
--- /dev/null
+++ b/drivers/staging/sep/sep_dev.h
@@ -0,0 +1,156 @@
1#ifndef __SEP_DEV_H__
2#define __SEP_DEV_H__
3
4/*
5 *
6 * sep_dev.h - Security Processor Device Structures
7 *
8 * Copyright(c) 2009,2010 Intel Corporation. All rights reserved.
9 * Contributions(c) 2009,2010 Discretix. All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * this program; if not, write to the Free Software Foundation, Inc., 59
22 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 * CONTACTS:
25 *
26 * Mark Allyn mark.a.allyn@intel.com
27 * Jayant Mangalampalli jayant.mangalampalli@intel.com
28 *
29 * CHANGES
30 * 2010.09.14 upgrade to Medfield
31 */
32
33struct sep_device {
34 /* pointer to pci dev */
35 struct pci_dev *pdev;
36
37 /* character device file */
38 struct cdev sep_cdev;
39 struct cdev sep_daemon_cdev;
40 struct cdev sep_singleton_cdev;
41
42 /* devices (using misc dev) */
43 struct miscdevice miscdev_sep;
44 struct miscdevice miscdev_singleton;
45 struct miscdevice miscdev_daemon;
46
47 /* major / minor numbers of device */
48 dev_t sep_devno;
49 dev_t sep_daemon_devno;
50 dev_t sep_singleton_devno;
51
52 struct mutex sep_mutex;
53 struct mutex ioctl_mutex;
54 spinlock_t snd_rply_lck;
55
56 /* flags to indicate use and lock status of sep */
57 u32 pid_doing_transaction;
58 unsigned long in_use_flags;
59
60 /* request daemon alread open */
61 unsigned long request_daemon_open;
62
63 /* 1 = Moorestown; 0 = Medfield */
64 int mrst;
65
66 /* address of the shared memory allocated during init for SEP driver
67 (coherent alloc) */
68 dma_addr_t shared_bus;
69 size_t shared_size;
70 void *shared_addr;
71
72 /* restricted access region (coherent alloc) */
73 dma_addr_t rar_bus;
74 size_t rar_size;
75 void *rar_addr;
76
77 /* Firmware regions; cache is at rar for Moorestown and
78 resident is at rar for Medfield */
79 dma_addr_t cache_bus;
80 size_t cache_size;
81 void *cache_addr;
82
83 dma_addr_t resident_bus;
84 size_t resident_size;
85 void *resident_addr;
86
87 /* sep's scratchpad */
88 dma_addr_t dcache_bus;
89 size_t dcache_size;
90 void *dcache_addr;
91
92 /* Only used on Medfield */
93 dma_addr_t extapp_bus;
94 size_t extapp_size;
95 void *extapp_addr;
96
97 /* start address of the access to the SEP registers from driver */
98 dma_addr_t reg_physical_addr;
99 dma_addr_t reg_physical_end;
100 void __iomem *reg_addr;
101
102 /* wait queue head (event) of the driver */
103 wait_queue_head_t event;
104 wait_queue_head_t event_request_daemon;
105 wait_queue_head_t event_mmap;
106
107 struct sep_caller_id_entry
108 caller_id_table[SEP_CALLER_ID_TABLE_NUM_ENTRIES];
109
110 /* access flag for singleton device */
111 unsigned long singleton_access_flag;
112
113 /* transaction counter that coordinates the
114 transactions between SEP and HOST */
115 unsigned long send_ct;
116 /* counter for the messages from sep */
117 unsigned long reply_ct;
118 /* counter for the number of bytes allocated in the pool for the
119 current transaction */
120 long data_pool_bytes_allocated;
121
122 u32 num_of_data_allocations;
123
124 /* number of the lli tables created in the current transaction */
125 u32 num_lli_tables_created;
126
127 /* number of data control blocks */
128 u32 nr_dcb_creat;
129
130 struct sep_dma_resource dma_res_arr[SEP_MAX_NUM_SYNC_DMA_OPS];
131
132};
133
134static inline void sep_write_reg(struct sep_device *dev, int reg, u32 value)
135{
136 void __iomem *addr = dev->reg_addr + reg;
137 writel(value, addr);
138}
139
140static inline u32 sep_read_reg(struct sep_device *dev, int reg)
141{
142 void __iomem *addr = dev->reg_addr + reg;
143 return readl(addr);
144}
145
146/* wait for SRAM write complete(indirect write */
147static inline void sep_wait_sram_write(struct sep_device *dev)
148{
149 u32 reg_val;
150 do {
151 reg_val = sep_read_reg(dev, HW_SRAM_DATA_READY_REG_ADDR);
152 } while (!(reg_val & 1));
153}
154
155
156#endif
diff --git a/drivers/staging/sep/sep_driver.c b/drivers/staging/sep/sep_driver.c
new file mode 100644
index 000000000000..ac5d56943d4b
--- /dev/null
+++ b/drivers/staging/sep/sep_driver.c
@@ -0,0 +1,3577 @@
1/*
2 *
3 * sep_driver.c - Security Processor Driver main group of functions
4 *
5 * Copyright(c) 2009,2010 Intel Corporation. All rights reserved.
6 * Contributions(c) 2009,2010 Discretix. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * CONTACTS:
22 *
23 * Mark Allyn mark.a.allyn@intel.com
24 * Jayant Mangalampalli jayant.mangalampalli@intel.com
25 *
26 * CHANGES:
27 *
28 * 2009.06.26 Initial publish
29 * 2010.09.14 Upgrade to Medfield
30 *
31 */
32#define DEBUG
33#include <linux/init.h>
34#include <linux/module.h>
35#include <linux/miscdevice.h>
36#include <linux/fs.h>
37#include <linux/cdev.h>
38#include <linux/kdev_t.h>
39#include <linux/mutex.h>
40#include <linux/sched.h>
41#include <linux/mm.h>
42#include <linux/poll.h>
43#include <linux/wait.h>
44#include <linux/pci.h>
45#include <linux/firmware.h>
46#include <linux/slab.h>
47#include <linux/ioctl.h>
48#include <asm/current.h>
49#include <linux/ioport.h>
50#include <linux/io.h>
51#include <linux/interrupt.h>
52#include <linux/pagemap.h>
53#include <asm/cacheflush.h>
54#include <linux/sched.h>
55#include <linux/delay.h>
56#include <linux/jiffies.h>
57#include <linux/rar_register.h>
58
59#include "../memrar/memrar.h"
60
61#include "sep_driver_hw_defs.h"
62#include "sep_driver_config.h"
63#include "sep_driver_api.h"
64#include "sep_dev.h"
65
66/*----------------------------------------
67 DEFINES
68-----------------------------------------*/
69
70#define SEP_RAR_IO_MEM_REGION_SIZE 0x40000
71
72/*--------------------------------------------
73 GLOBAL variables
74--------------------------------------------*/
75
76/* Keep this a single static object for now to keep the conversion easy */
77
78static struct sep_device *sep_dev;
79
80/**
81 * sep_load_firmware - copy firmware cache/resident
82 * @sep: pointer to struct sep_device we are loading
83 *
84 * This functions copies the cache and resident from their source
85 * location into destination shared memory.
86 */
87static int sep_load_firmware(struct sep_device *sep)
88{
89 const struct firmware *fw;
90 char *cache_name = "cache.image.bin";
91 char *res_name = "resident.image.bin";
92 char *extapp_name = "extapp.image.bin";
93 int error ;
94 unsigned long work1, work2, work3;
95
96 /* Set addresses and load resident */
97 sep->resident_bus = sep->rar_bus;
98 sep->resident_addr = sep->rar_addr;
99
100 error = request_firmware(&fw, res_name, &sep->pdev->dev);
101 if (error) {
102 dev_warn(&sep->pdev->dev, "can't request resident fw\n");
103 return error;
104 }
105
106 memcpy(sep->resident_addr, (void *)fw->data, fw->size);
107 sep->resident_size = fw->size;
108 release_firmware(fw);
109
110 dev_dbg(&sep->pdev->dev, "resident virtual is %p\n",
111 sep->resident_addr);
112 dev_dbg(&sep->pdev->dev, "resident bus is %lx\n",
113 (unsigned long)sep->resident_bus);
114 dev_dbg(&sep->pdev->dev, "resident size is %08zx\n",
115 sep->resident_size);
116
117 /* Set addresses for dcache (no loading needed) */
118 work1 = (unsigned long)sep->resident_bus;
119 work2 = (unsigned long)sep->resident_size;
120 work3 = (work1 + work2 + (1024 * 4)) & 0xfffff000;
121 sep->dcache_bus = (dma_addr_t)work3;
122
123 work1 = (unsigned long)sep->resident_addr;
124 work2 = (unsigned long)sep->resident_size;
125 work3 = (work1 + work2 + (1024 * 4)) & 0xfffff000;
126 sep->dcache_addr = (void *)work3;
127
128 sep->dcache_size = 1024 * 128;
129
130 /* Set addresses and load cache */
131 sep->cache_bus = sep->dcache_bus + sep->dcache_size;
132 sep->cache_addr = sep->dcache_addr + sep->dcache_size;
133
134 error = request_firmware(&fw, cache_name, &sep->pdev->dev);
135 if (error) {
136 dev_warn(&sep->pdev->dev, "Unable to request cache firmware\n");
137 return error;
138 }
139
140 memcpy(sep->cache_addr, (void *)fw->data, fw->size);
141 sep->cache_size = fw->size;
142 release_firmware(fw);
143
144 dev_dbg(&sep->pdev->dev, "cache virtual is %p\n",
145 sep->cache_addr);
146 dev_dbg(&sep->pdev->dev, "cache bus is %08lx\n",
147 (unsigned long)sep->cache_bus);
148 dev_dbg(&sep->pdev->dev, "cache size is %08zx\n",
149 sep->cache_size);
150
151 /* Set addresses and load extapp */
152 sep->extapp_bus = sep->cache_bus + (1024 * 370);
153 sep->extapp_addr = sep->cache_addr + (1024 * 370);
154
155 error = request_firmware(&fw, extapp_name, &sep->pdev->dev);
156 if (error) {
157 dev_warn(&sep->pdev->dev, "Unable to request extapp firmware\n");
158 return error;
159 }
160
161 memcpy(sep->extapp_addr, (void *)fw->data, fw->size);
162 sep->extapp_size = fw->size;
163 release_firmware(fw);
164
165 dev_dbg(&sep->pdev->dev, "extapp virtual is %p\n",
166 sep->extapp_addr);
167 dev_dbg(&sep->pdev->dev, "extapp bus is %08llx\n",
168 (unsigned long long)sep->extapp_bus);
169 dev_dbg(&sep->pdev->dev, "extapp size is %08zx\n",
170 sep->extapp_size);
171
172 return error;
173}
174
175MODULE_FIRMWARE("sep/cache.image.bin");
176MODULE_FIRMWARE("sep/resident.image.bin");
177MODULE_FIRMWARE("sep/extapp.image.bin");
178
179/**
180 * sep_dump_message - dump the message that is pending
181 * @sep: SEP device
182 */
183static void sep_dump_message(struct sep_device *sep)
184{
185 int count;
186 u32 *p = sep->shared_addr;
187 for (count = 0; count < 12 * 4; count += 4)
188 dev_dbg(&sep->pdev->dev, "Word %d of the message is %x\n",
189 count, *p++);
190}
191
192/**
193 * sep_map_and_alloc_shared_area - allocate shared block
194 * @sep: security processor
195 * @size: size of shared area
196 */
197static int sep_map_and_alloc_shared_area(struct sep_device *sep)
198{
199 sep->shared_addr = dma_alloc_coherent(&sep->pdev->dev,
200 sep->shared_size,
201 &sep->shared_bus, GFP_KERNEL);
202
203 if (!sep->shared_addr) {
204 dev_warn(&sep->pdev->dev,
205 "shared memory dma_alloc_coherent failed\n");
206 return -ENOMEM;
207 }
208 dev_dbg(&sep->pdev->dev,
209 "shared_addr %zx bytes @%p (bus %llx)\n",
210 sep->shared_size, sep->shared_addr,
211 (unsigned long long)sep->shared_bus);
212 return 0;
213}
214
215/**
216 * sep_unmap_and_free_shared_area - free shared block
217 * @sep: security processor
218 */
219static void sep_unmap_and_free_shared_area(struct sep_device *sep)
220{
221 dev_dbg(&sep->pdev->dev, "shared area unmap and free\n");
222 dma_free_coherent(&sep->pdev->dev, sep->shared_size,
223 sep->shared_addr, sep->shared_bus);
224}
225
226/**
227 * sep_shared_bus_to_virt - convert bus/virt addresses
228 * @sep: pointer to struct sep_device
229 * @bus_address: address to convert
230 *
231 * Returns virtual address inside the shared area according
232 * to the bus address.
233 */
234static void *sep_shared_bus_to_virt(struct sep_device *sep,
235 dma_addr_t bus_address)
236{
237 return sep->shared_addr + (bus_address - sep->shared_bus);
238}
239
240/**
241 * open function for the singleton driver
242 * @inode_ptr struct inode *
243 * @file_ptr struct file *
244 *
245 * Called when the user opens the singleton device interface
246 */
247static int sep_singleton_open(struct inode *inode_ptr, struct file *file_ptr)
248{
249 int error = 0;
250 struct sep_device *sep;
251
252 /*
253 * Get the SEP device structure and use it for the
254 * private_data field in filp for other methods
255 */
256 sep = sep_dev;
257
258 file_ptr->private_data = sep;
259
260 dev_dbg(&sep->pdev->dev, "Singleton open for pid %d\n", current->pid);
261
262 dev_dbg(&sep->pdev->dev, "calling test and set for singleton 0\n");
263 if (test_and_set_bit(0, &sep->singleton_access_flag)) {
264 error = -EBUSY;
265 goto end_function;
266 }
267
268 dev_dbg(&sep->pdev->dev, "sep_singleton_open end\n");
269end_function:
270 return error;
271}
272
273/**
274 * sep_open - device open method
275 * @inode: inode of SEP device
276 * @filp: file handle to SEP device
277 *
278 * Open method for the SEP device. Called when userspace opens
279 * the SEP device node.
280 *
281 * Returns zero on success otherwise an error code.
282 */
283static int sep_open(struct inode *inode, struct file *filp)
284{
285 struct sep_device *sep;
286
287 /*
288 * Get the SEP device structure and use it for the
289 * private_data field in filp for other methods
290 */
291 sep = sep_dev;
292 filp->private_data = sep;
293
294 dev_dbg(&sep->pdev->dev, "Open for pid %d\n", current->pid);
295
296 /* Anyone can open; locking takes place at transaction level */
297 return 0;
298}
299
300/**
301 * sep_singleton_release - close a SEP singleton device
302 * @inode: inode of SEP device
303 * @filp: file handle being closed
304 *
305 * Called on the final close of a SEP device. As the open protects against
306 * multiple simultaenous opens that means this method is called when the
307 * final reference to the open handle is dropped.
308 */
309static int sep_singleton_release(struct inode *inode, struct file *filp)
310{
311 struct sep_device *sep = filp->private_data;
312
313 dev_dbg(&sep->pdev->dev, "Singleton release for pid %d\n",
314 current->pid);
315 clear_bit(0, &sep->singleton_access_flag);
316 return 0;
317}
318
319/**
320 * sep_request_daemonopen - request daemon open method
321 * @inode: inode of SEP device
322 * @filp: file handle to SEP device
323 *
324 * Open method for the SEP request daemon. Called when
325 * request daemon in userspace opens the SEP device node.
326 *
327 * Returns zero on success otherwise an error code.
328 */
329static int sep_request_daemon_open(struct inode *inode, struct file *filp)
330{
331 struct sep_device *sep = sep_dev;
332 int error = 0;
333
334 filp->private_data = sep;
335
336 dev_dbg(&sep->pdev->dev, "Request daemon open for pid %d\n",
337 current->pid);
338
339 /* There is supposed to be only one request daemon */
340 dev_dbg(&sep->pdev->dev, "calling test and set for req_dmon open 0\n");
341 if (test_and_set_bit(0, &sep->request_daemon_open))
342 error = -EBUSY;
343 return error;
344}
345
346/**
347 * sep_request_daemon_release - close a SEP daemon
348 * @inode: inode of SEP device
349 * @filp: file handle being closed
350 *
351 * Called on the final close of a SEP daemon.
352 */
353static int sep_request_daemon_release(struct inode *inode, struct file *filp)
354{
355 struct sep_device *sep = filp->private_data;
356
357 dev_dbg(&sep->pdev->dev, "Reques daemon release for pid %d\n",
358 current->pid);
359
360 /* Clear the request_daemon_open flag */
361 clear_bit(0, &sep->request_daemon_open);
362 return 0;
363}
364
365/**
366 * sep_req_daemon_send_reply_command_handler - poke the SEP
367 * @sep: struct sep_device *
368 *
369 * This function raises interrupt to SEPm that signals that is has a
370 * new command from HOST
371 */
372static int sep_req_daemon_send_reply_command_handler(struct sep_device *sep)
373{
374 unsigned long lck_flags;
375
376 dev_dbg(&sep->pdev->dev,
377 "sep_req_daemon_send_reply_command_handler start\n");
378
379 sep_dump_message(sep);
380
381 /* Counters are lockable region */
382 spin_lock_irqsave(&sep->snd_rply_lck, lck_flags);
383 sep->send_ct++;
384 sep->reply_ct++;
385
386 /* Send the interrupt to SEP */
387 sep_write_reg(sep, HW_HOST_HOST_SEP_GPR2_REG_ADDR, sep->send_ct);
388 sep->send_ct++;
389
390 spin_unlock_irqrestore(&sep->snd_rply_lck, lck_flags);
391
392 dev_dbg(&sep->pdev->dev,
393 "sep_req_daemon_send_reply send_ct %lx reply_ct %lx\n",
394 sep->send_ct, sep->reply_ct);
395
396 dev_dbg(&sep->pdev->dev,
397 "sep_req_daemon_send_reply_command_handler end\n");
398
399 return 0;
400}
401
402
403/**
404 * sep_free_dma_table_data_handler - free DMA table
405 * @sep: pointere to struct sep_device
406 *
407 * Handles the request to free DMA table for synchronic actions
408 */
409static int sep_free_dma_table_data_handler(struct sep_device *sep)
410{
411 int count;
412 int dcb_counter;
413 /* Pointer to the current dma_resource struct */
414 struct sep_dma_resource *dma;
415
416 dev_dbg(&sep->pdev->dev, "sep_free_dma_table_data_handler start\n");
417
418 for (dcb_counter = 0; dcb_counter < sep->nr_dcb_creat; dcb_counter++) {
419 dma = &sep->dma_res_arr[dcb_counter];
420
421 /* Unmap and free input map array */
422 if (dma->in_map_array) {
423 for (count = 0; count < dma->in_num_pages; count++) {
424 dma_unmap_page(&sep->pdev->dev,
425 dma->in_map_array[count].dma_addr,
426 dma->in_map_array[count].size,
427 DMA_TO_DEVICE);
428 }
429 kfree(dma->in_map_array);
430 }
431
432 /* Unmap output map array, DON'T free it yet */
433 if (dma->out_map_array) {
434 for (count = 0; count < dma->out_num_pages; count++) {
435 dma_unmap_page(&sep->pdev->dev,
436 dma->out_map_array[count].dma_addr,
437 dma->out_map_array[count].size,
438 DMA_FROM_DEVICE);
439 }
440 kfree(dma->out_map_array);
441 }
442
443 /* Free page cache for output */
444 if (dma->in_page_array) {
445 for (count = 0; count < dma->in_num_pages; count++) {
446 flush_dcache_page(dma->in_page_array[count]);
447 page_cache_release(dma->in_page_array[count]);
448 }
449 kfree(dma->in_page_array);
450 }
451
452 if (dma->out_page_array) {
453 for (count = 0; count < dma->out_num_pages; count++) {
454 if (!PageReserved(dma->out_page_array[count]))
455 SetPageDirty(dma->out_page_array[count]);
456 flush_dcache_page(dma->out_page_array[count]);
457 page_cache_release(dma->out_page_array[count]);
458 }
459 kfree(dma->out_page_array);
460 }
461
462 /* Reset all the values */
463 dma->in_page_array = NULL;
464 dma->out_page_array = NULL;
465 dma->in_num_pages = 0;
466 dma->out_num_pages = 0;
467 dma->in_map_array = NULL;
468 dma->out_map_array = NULL;
469 dma->in_map_num_entries = 0;
470 dma->out_map_num_entries = 0;
471 }
472
473 sep->nr_dcb_creat = 0;
474 sep->num_lli_tables_created = 0;
475
476 dev_dbg(&sep->pdev->dev, "sep_free_dma_table_data_handler end\n");
477 return 0;
478}
479
480/**
481 * sep_request_daemon_mmap - maps the shared area to user space
482 * @filp: pointer to struct file
483 * @vma: pointer to vm_area_struct
484 *
485 * Called by the kernel when the daemon attempts an mmap() syscall
486 * using our handle.
487 */
488static int sep_request_daemon_mmap(struct file *filp,
489 struct vm_area_struct *vma)
490{
491 struct sep_device *sep = filp->private_data;
492 dma_addr_t bus_address;
493 int error = 0;
494
495 dev_dbg(&sep->pdev->dev, "daemon mmap start\n");
496
497 if ((vma->vm_end - vma->vm_start) > SEP_DRIVER_MMMAP_AREA_SIZE) {
498 error = -EINVAL;
499 goto end_function;
500 }
501
502 /* Get physical address */
503 bus_address = sep->shared_bus;
504
505 dev_dbg(&sep->pdev->dev, "bus_address is %08lx\n",
506 (unsigned long)bus_address);
507
508 if (remap_pfn_range(vma, vma->vm_start, bus_address >> PAGE_SHIFT,
509 vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
510
511 dev_warn(&sep->pdev->dev, "remap_page_range failed\n");
512 error = -EAGAIN;
513 goto end_function;
514 }
515
516end_function:
517 dev_dbg(&sep->pdev->dev, "daemon mmap end\n");
518 return error;
519}
520
521/**
522 * sep_request_daemon_poll - poll implementation
523 * @sep: struct sep_device * for current SEP device
524 * @filp: struct file * for open file
525 * @wait: poll_table * for poll
526 *
527 * Called when our device is part of a poll() or select() syscall
528 */
529static unsigned int sep_request_daemon_poll(struct file *filp,
530 poll_table *wait)
531{
532 u32 mask = 0;
533 /* GPR2 register */
534 u32 retval2;
535 unsigned long lck_flags;
536 struct sep_device *sep = filp->private_data;
537
538 dev_dbg(&sep->pdev->dev, "daemon poll: start\n");
539
540 poll_wait(filp, &sep->event_request_daemon, wait);
541
542 dev_dbg(&sep->pdev->dev, "daemon poll: send_ct is %lx reply ct is %lx\n",
543 sep->send_ct, sep->reply_ct);
544
545 spin_lock_irqsave(&sep->snd_rply_lck, lck_flags);
546 /* Check if the data is ready */
547 if (sep->send_ct == sep->reply_ct) {
548 spin_unlock_irqrestore(&sep->snd_rply_lck, lck_flags);
549
550 retval2 = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR2_REG_ADDR);
551 dev_dbg(&sep->pdev->dev,
552 "daemon poll: data check (GPR2) is %x\n", retval2);
553
554 /* Check if PRINT request */
555 if ((retval2 >> 30) & 0x1) {
556 dev_dbg(&sep->pdev->dev, "daemon poll: PRINTF request in\n");
557 mask |= POLLIN;
558 goto end_function;
559 }
560 /* Check if NVS request */
561 if (retval2 >> 31) {
562 dev_dbg(&sep->pdev->dev, "daemon poll: NVS request in\n");
563 mask |= POLLPRI | POLLWRNORM;
564 }
565 } else {
566 spin_unlock_irqrestore(&sep->snd_rply_lck, lck_flags);
567 dev_dbg(&sep->pdev->dev,
568 "daemon poll: no reply received; returning 0\n");
569 mask = 0;
570 }
571end_function:
572 dev_dbg(&sep->pdev->dev, "daemon poll: exit\n");
573 return mask;
574}
575
576/**
577 * sep_release - close a SEP device
578 * @inode: inode of SEP device
579 * @filp: file handle being closed
580 *
581 * Called on the final close of a SEP device.
582 */
583static int sep_release(struct inode *inode, struct file *filp)
584{
585 struct sep_device *sep = filp->private_data;
586
587 dev_dbg(&sep->pdev->dev, "Release for pid %d\n", current->pid);
588
589 mutex_lock(&sep->sep_mutex);
590 /* Is this the process that has a transaction open?
591 * If so, lets reset pid_doing_transaction to 0 and
592 * clear the in use flags, and then wake up sep_event
593 * so that other processes can do transactions
594 */
595 dev_dbg(&sep->pdev->dev, "waking up event and mmap_event\n");
596 if (sep->pid_doing_transaction == current->pid) {
597 clear_bit(SEP_MMAP_LOCK_BIT, &sep->in_use_flags);
598 clear_bit(SEP_SEND_MSG_LOCK_BIT, &sep->in_use_flags);
599 sep_free_dma_table_data_handler(sep);
600 wake_up(&sep->event);
601 sep->pid_doing_transaction = 0;
602 }
603
604 mutex_unlock(&sep->sep_mutex);
605 return 0;
606}
607
608/**
609 * sep_mmap - maps the shared area to user space
610 * @filp: pointer to struct file
611 * @vma: pointer to vm_area_struct
612 *
613 * Called on an mmap of our space via the normal SEP device
614 */
615static int sep_mmap(struct file *filp, struct vm_area_struct *vma)
616{
617 dma_addr_t bus_addr;
618 struct sep_device *sep = filp->private_data;
619 unsigned long error = 0;
620
621 dev_dbg(&sep->pdev->dev, "mmap start\n");
622
623 /* Set the transaction busy (own the device) */
624 wait_event_interruptible(sep->event,
625 test_and_set_bit(SEP_MMAP_LOCK_BIT,
626 &sep->in_use_flags) == 0);
627
628 if (signal_pending(current)) {
629 error = -EINTR;
630 goto end_function_with_error;
631 }
632 /*
633 * The pid_doing_transaction indicates that this process
634 * now owns the facilities to performa a transaction with
635 * the SEP. While this process is performing a transaction,
636 * no other process who has the SEP device open can perform
637 * any transactions. This method allows more than one process
638 * to have the device open at any given time, which provides
639 * finer granularity for device utilization by multiple
640 * processes.
641 */
642 mutex_lock(&sep->sep_mutex);
643 sep->pid_doing_transaction = current->pid;
644 mutex_unlock(&sep->sep_mutex);
645
646 /* Zero the pools and the number of data pool alocation pointers */
647 sep->data_pool_bytes_allocated = 0;
648 sep->num_of_data_allocations = 0;
649
650 /*
651 * Check that the size of the mapped range is as the size of the message
652 * shared area
653 */
654 if ((vma->vm_end - vma->vm_start) > SEP_DRIVER_MMMAP_AREA_SIZE) {
655 error = -EINVAL;
656 goto end_function_with_error;
657 }
658
659 dev_dbg(&sep->pdev->dev, "shared_addr is %p\n", sep->shared_addr);
660
661 /* Get bus address */
662 bus_addr = sep->shared_bus;
663
664 dev_dbg(&sep->pdev->dev,
665 "bus_address is %lx\n", (unsigned long)bus_addr);
666
667 if (remap_pfn_range(vma, vma->vm_start, bus_addr >> PAGE_SHIFT,
668 vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
669 dev_warn(&sep->pdev->dev, "remap_page_range failed\n");
670 error = -EAGAIN;
671 goto end_function_with_error;
672 }
673 dev_dbg(&sep->pdev->dev, "mmap end\n");
674 goto end_function;
675
676end_function_with_error:
677 /* Clear the bit */
678 clear_bit(SEP_MMAP_LOCK_BIT, &sep->in_use_flags);
679 mutex_lock(&sep->sep_mutex);
680 sep->pid_doing_transaction = 0;
681 mutex_unlock(&sep->sep_mutex);
682
683 /* Raise event for stuck contextes */
684
685 dev_warn(&sep->pdev->dev, "mmap error - waking up event\n");
686 wake_up(&sep->event);
687
688end_function:
689 return error;
690}
691
692/**
693 * sep_poll - poll handler
694 * @filp: pointer to struct file
695 * @wait: pointer to poll_table
696 *
697 * Called by the OS when the kernel is asked to do a poll on
698 * a SEP file handle.
699 */
700static unsigned int sep_poll(struct file *filp, poll_table *wait)
701{
702 u32 mask = 0;
703 u32 retval = 0;
704 u32 retval2 = 0;
705 unsigned long lck_flags;
706
707 struct sep_device *sep = filp->private_data;
708
709 dev_dbg(&sep->pdev->dev, "poll: start\n");
710
711 /* Am I the process that owns the transaction? */
712 mutex_lock(&sep->sep_mutex);
713 if (current->pid != sep->pid_doing_transaction) {
714 dev_warn(&sep->pdev->dev, "poll; wrong pid\n");
715 mask = POLLERR;
716 mutex_unlock(&sep->sep_mutex);
717 goto end_function;
718 }
719 mutex_unlock(&sep->sep_mutex);
720
721 /* Check if send command or send_reply were activated previously */
722 if (!test_bit(SEP_SEND_MSG_LOCK_BIT, &sep->in_use_flags)) {
723 dev_warn(&sep->pdev->dev, "poll; lock bit set\n");
724 mask = POLLERR;
725 goto end_function;
726 }
727
728 /* Add the event to the polling wait table */
729 dev_dbg(&sep->pdev->dev, "poll: calling wait sep_event\n");
730
731 poll_wait(filp, &sep->event, wait);
732
733 dev_dbg(&sep->pdev->dev, "poll: send_ct is %lx reply ct is %lx\n",
734 sep->send_ct, sep->reply_ct);
735
736 /* Check if error occured during poll */
737 retval2 = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR);
738 if (retval2 != 0x0) {
739 dev_warn(&sep->pdev->dev, "poll; poll error %x\n", retval2);
740 mask |= POLLERR;
741 goto end_function;
742 }
743
744 spin_lock_irqsave(&sep->snd_rply_lck, lck_flags);
745
746 if (sep->send_ct == sep->reply_ct) {
747 spin_unlock_irqrestore(&sep->snd_rply_lck, lck_flags);
748 retval = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR2_REG_ADDR);
749 dev_dbg(&sep->pdev->dev, "poll: data ready check (GPR2) %x\n",
750 retval);
751
752 /* Check if printf request */
753 if ((retval >> 30) & 0x1) {
754 dev_dbg(&sep->pdev->dev, "poll: SEP printf request\n");
755 wake_up(&sep->event_request_daemon);
756 goto end_function;
757 }
758
759 /* Check if the this is SEP reply or request */
760 if (retval >> 31) {
761 dev_dbg(&sep->pdev->dev, "poll: SEP request\n");
762 wake_up(&sep->event_request_daemon);
763 } else {
764 dev_dbg(&sep->pdev->dev, "poll: normal return\n");
765 /* In case it is again by send_reply_comand */
766 clear_bit(SEP_SEND_MSG_LOCK_BIT, &sep->in_use_flags);
767 sep_dump_message(sep);
768 dev_dbg(&sep->pdev->dev,
769 "poll; SEP reply POLLIN | POLLRDNORM\n");
770 mask |= POLLIN | POLLRDNORM;
771 }
772 } else {
773 spin_unlock_irqrestore(&sep->snd_rply_lck, lck_flags);
774 dev_dbg(&sep->pdev->dev,
775 "poll; no reply received; returning mask of 0\n");
776 mask = 0;
777 }
778
779end_function:
780 dev_dbg(&sep->pdev->dev, "poll: end\n");
781 return mask;
782}
783
784/**
785 * sep_time_address - address in SEP memory of time
786 * @sep: SEP device we want the address from
787 *
788 * Return the address of the two dwords in memory used for time
789 * setting.
790 */
791static u32 *sep_time_address(struct sep_device *sep)
792{
793 return sep->shared_addr + SEP_DRIVER_SYSTEM_TIME_MEMORY_OFFSET_IN_BYTES;
794}
795
796/**
797 * sep_set_time - set the SEP time
798 * @sep: the SEP we are setting the time for
799 *
800 * Calculates time and sets it at the predefined address.
801 * Called with the SEP mutex held.
802 */
803static unsigned long sep_set_time(struct sep_device *sep)
804{
805 struct timeval time;
806 u32 *time_addr; /* Address of time as seen by the kernel */
807
808
809 dev_dbg(&sep->pdev->dev, "sep_set_time start\n");
810
811 do_gettimeofday(&time);
812
813 /* Set value in the SYSTEM MEMORY offset */
814 time_addr = sep_time_address(sep);
815
816 time_addr[0] = SEP_TIME_VAL_TOKEN;
817 time_addr[1] = time.tv_sec;
818
819 dev_dbg(&sep->pdev->dev, "time.tv_sec is %lu\n", time.tv_sec);
820 dev_dbg(&sep->pdev->dev, "time_addr is %p\n", time_addr);
821 dev_dbg(&sep->pdev->dev, "sep->shared_addr is %p\n", sep->shared_addr);
822
823 return time.tv_sec;
824}
825
826/**
827 * sep_set_caller_id_handler - insert caller id entry
828 * @sep: SEP device
829 * @arg: pointer to struct caller_id_struct
830 *
831 * Inserts the data into the caller id table. Note that this function
832 * falls under the ioctl lock
833 */
834static int sep_set_caller_id_handler(struct sep_device *sep, unsigned long arg)
835{
836 void __user *hash;
837 int error = 0;
838 int i;
839 struct caller_id_struct command_args;
840
841 dev_dbg(&sep->pdev->dev, "sep_set_caller_id_handler start\n");
842
843 for (i = 0; i < SEP_CALLER_ID_TABLE_NUM_ENTRIES; i++) {
844 if (sep->caller_id_table[i].pid == 0)
845 break;
846 }
847
848 if (i == SEP_CALLER_ID_TABLE_NUM_ENTRIES) {
849 dev_warn(&sep->pdev->dev, "no more caller id entries left\n");
850 dev_warn(&sep->pdev->dev, "maximum number is %d\n",
851 SEP_CALLER_ID_TABLE_NUM_ENTRIES);
852 error = -EUSERS;
853 goto end_function;
854 }
855
856 /* Copy the data */
857 if (copy_from_user(&command_args, (void __user *)arg,
858 sizeof(command_args))) {
859 error = -EFAULT;
860 goto end_function;
861 }
862
863 hash = (void __user *)(unsigned long)command_args.callerIdAddress;
864
865 if (!command_args.pid || !command_args.callerIdSizeInBytes) {
866 error = -EINVAL;
867 goto end_function;
868 }
869
870 dev_dbg(&sep->pdev->dev, "pid is %x\n", command_args.pid);
871 dev_dbg(&sep->pdev->dev, "callerIdSizeInBytes is %x\n",
872 command_args.callerIdSizeInBytes);
873
874 if (command_args.callerIdSizeInBytes >
875 SEP_CALLER_ID_HASH_SIZE_IN_BYTES) {
876 error = -EMSGSIZE;
877 goto end_function;
878 }
879
880 sep->caller_id_table[i].pid = command_args.pid;
881
882 if (copy_from_user(sep->caller_id_table[i].callerIdHash,
883 hash, command_args.callerIdSizeInBytes))
884 error = -EFAULT;
885end_function:
886 dev_dbg(&sep->pdev->dev, "sep_set_caller_id_handler end\n");
887 return error;
888}
889
890/**
891 * sep_set_current_caller_id - set the caller id
892 * @sep: pointer to struct_sep_device
893 *
894 * Set the caller ID (if it exists) to the SEP. Note that this
895 * function falls under the ioctl lock
896 */
897static int sep_set_current_caller_id(struct sep_device *sep)
898{
899 int i;
900 u32 *hash_buf_ptr;
901
902 dev_dbg(&sep->pdev->dev, "sep_set_current_caller_id start\n");
903 dev_dbg(&sep->pdev->dev, "current process is %d\n", current->pid);
904
905 /* Zero the previous value */
906 memset(sep->shared_addr + SEP_CALLER_ID_OFFSET_BYTES,
907 0, SEP_CALLER_ID_HASH_SIZE_IN_BYTES);
908
909 for (i = 0; i < SEP_CALLER_ID_TABLE_NUM_ENTRIES; i++) {
910 if (sep->caller_id_table[i].pid == current->pid) {
911 dev_dbg(&sep->pdev->dev, "Caller Id found\n");
912
913 memcpy(sep->shared_addr + SEP_CALLER_ID_OFFSET_BYTES,
914 (void *)(sep->caller_id_table[i].callerIdHash),
915 SEP_CALLER_ID_HASH_SIZE_IN_BYTES);
916 break;
917 }
918 }
919 /* Ensure data is in little endian */
920 hash_buf_ptr = (u32 *)sep->shared_addr +
921 SEP_CALLER_ID_OFFSET_BYTES;
922
923 for (i = 0; i < SEP_CALLER_ID_HASH_SIZE_IN_WORDS; i++)
924 hash_buf_ptr[i] = cpu_to_le32(hash_buf_ptr[i]);
925
926 dev_dbg(&sep->pdev->dev, "sep_set_current_caller_id end\n");
927 return 0;
928}
929
930/**
931 * sep_send_command_handler - kick off a command
932 * @sep: SEP being signalled
933 *
934 * This function raises interrupt to SEP that signals that is has a new
935 * command from the host
936 *
937 * Note that this function does fall under the ioctl lock
938 */
939static int sep_send_command_handler(struct sep_device *sep)
940{
941 unsigned long lck_flags;
942 int error = 0;
943
944 dev_dbg(&sep->pdev->dev, "sep_send_command_handler start\n");
945
946 if (test_and_set_bit(SEP_SEND_MSG_LOCK_BIT, &sep->in_use_flags)) {
947 error = -EPROTO;
948 goto end_function;
949 }
950 sep_set_time(sep);
951
952 sep_set_current_caller_id(sep);
953
954 sep_dump_message(sep);
955
956 /* Update counter */
957 spin_lock_irqsave(&sep->snd_rply_lck, lck_flags);
958 sep->send_ct++;
959 spin_unlock_irqrestore(&sep->snd_rply_lck, lck_flags);
960
961 dev_dbg(&sep->pdev->dev,
962 "sep_send_command_handler send_ct %lx reply_ct %lx\n",
963 sep->send_ct, sep->reply_ct);
964
965 /* Send interrupt to SEP */
966 sep_write_reg(sep, HW_HOST_HOST_SEP_GPR0_REG_ADDR, 0x2);
967
968end_function:
969 dev_dbg(&sep->pdev->dev, "sep_send_command_handler end\n");
970 return error;
971}
972
973/**
974 * sep_allocate_data_pool_memory_handler -allocate pool memory
975 * @sep: pointer to struct sep_device
976 * @arg: pointer to struct alloc_struct
977 *
978 * This function handles the allocate data pool memory request
979 * This function returns calculates the bus address of the
980 * allocated memory, and the offset of this area from the mapped address.
981 * Therefore, the FVOs in user space can calculate the exact virtual
982 * address of this allocated memory
983 */
984static int sep_allocate_data_pool_memory_handler(struct sep_device *sep,
985 unsigned long arg)
986{
987 int error = 0;
988 struct alloc_struct command_args;
989
990 /* Holds the allocated buffer address in the system memory pool */
991 u32 *token_addr;
992
993 dev_dbg(&sep->pdev->dev,
994 "sep_allocate_data_pool_memory_handler start\n");
995
996 if (copy_from_user(&command_args, (void __user *)arg,
997 sizeof(struct alloc_struct))) {
998 error = -EFAULT;
999 goto end_function;
1000 }
1001
1002 /* Allocate memory */
1003 if ((sep->data_pool_bytes_allocated + command_args.num_bytes) >
1004 SEP_DRIVER_DATA_POOL_SHARED_AREA_SIZE_IN_BYTES) {
1005 error = -ENOMEM;
1006 goto end_function;
1007 }
1008
1009 dev_dbg(&sep->pdev->dev,
1010 "bytes_allocated: %x\n", (int)sep->data_pool_bytes_allocated);
1011 dev_dbg(&sep->pdev->dev,
1012 "offset: %x\n", SEP_DRIVER_DATA_POOL_AREA_OFFSET_IN_BYTES);
1013 /* Set the virtual and bus address */
1014 command_args.offset = SEP_DRIVER_DATA_POOL_AREA_OFFSET_IN_BYTES +
1015 sep->data_pool_bytes_allocated;
1016
1017 dev_dbg(&sep->pdev->dev,
1018 "command_args.offset: %x\n", command_args.offset);
1019
1020 /* Place in the shared area that is known by the SEP */
1021 token_addr = (u32 *)(sep->shared_addr +
1022 SEP_DRIVER_DATA_POOL_ALLOCATION_OFFSET_IN_BYTES +
1023 (sep->num_of_data_allocations)*2*sizeof(u32));
1024
1025 dev_dbg(&sep->pdev->dev, "allocation offset: %x\n",
1026 SEP_DRIVER_DATA_POOL_ALLOCATION_OFFSET_IN_BYTES);
1027 dev_dbg(&sep->pdev->dev, "data pool token addr is %p\n", token_addr);
1028
1029 token_addr[0] = SEP_DATA_POOL_POINTERS_VAL_TOKEN;
1030 token_addr[1] = (u32)sep->shared_bus +
1031 SEP_DRIVER_DATA_POOL_AREA_OFFSET_IN_BYTES +
1032 sep->data_pool_bytes_allocated;
1033
1034 dev_dbg(&sep->pdev->dev, "data pool token [0] %x\n", token_addr[0]);
1035 dev_dbg(&sep->pdev->dev, "data pool token [1] %x\n", token_addr[1]);
1036
1037 /* Write the memory back to the user space */
1038 error = copy_to_user((void *)arg, (void *)&command_args,
1039 sizeof(struct alloc_struct));
1040 if (error) {
1041 error = -EFAULT;
1042 goto end_function;
1043 }
1044
1045 /* Update the allocation */
1046 sep->data_pool_bytes_allocated += command_args.num_bytes;
1047 sep->num_of_data_allocations += 1;
1048
1049 dev_dbg(&sep->pdev->dev, "data_allocations %d\n",
1050 sep->num_of_data_allocations);
1051 dev_dbg(&sep->pdev->dev, "bytes allocated %d\n",
1052 (int)sep->data_pool_bytes_allocated);
1053
1054end_function:
1055 dev_dbg(&sep->pdev->dev, "sep_allocate_data_pool_memory_handler end\n");
1056 return error;
1057}
1058
1059/**
1060 * sep_lock_kernel_pages - map kernel pages for DMA
1061 * @sep: pointer to struct sep_device
1062 * @kernel_virt_addr: address of data buffer in kernel
1063 * @data_size: size of data
1064 * @lli_array_ptr: lli array
1065 * @in_out_flag: input into device or output from device
1066 *
1067 * This function locks all the physical pages of the kernel virtual buffer
1068 * and construct a basic lli array, where each entry holds the physical
1069 * page address and the size that application data holds in this page
1070 * This function is used only during kernel crypto mod calls from within
1071 * the kernel (when ioctl is not used)
1072 */
1073static int sep_lock_kernel_pages(struct sep_device *sep,
1074 unsigned long kernel_virt_addr,
1075 u32 data_size,
1076 struct sep_lli_entry **lli_array_ptr,
1077 int in_out_flag)
1078
1079{
1080 int error = 0;
1081 /* Array of lli */
1082 struct sep_lli_entry *lli_array;
1083 /* Map array */
1084 struct sep_dma_map *map_array;
1085
1086 dev_dbg(&sep->pdev->dev, "sep_lock_kernel_pages start\n");
1087 dev_dbg(&sep->pdev->dev, "kernel_virt_addr is %08lx\n",
1088 (unsigned long)kernel_virt_addr);
1089 dev_dbg(&sep->pdev->dev, "data_size is %x\n", data_size);
1090
1091 lli_array = kmalloc(sizeof(struct sep_lli_entry), GFP_ATOMIC);
1092 if (!lli_array) {
1093 error = -ENOMEM;
1094 goto end_function;
1095 }
1096 map_array = kmalloc(sizeof(struct sep_dma_map), GFP_ATOMIC);
1097 if (!map_array) {
1098 error = -ENOMEM;
1099 goto end_function_with_error;
1100 }
1101
1102 map_array[0].dma_addr =
1103 dma_map_single(&sep->pdev->dev, (void *)kernel_virt_addr,
1104 data_size, DMA_BIDIRECTIONAL);
1105 map_array[0].size = data_size;
1106
1107
1108 /*
1109 * Set the start address of the first page - app data may start not at
1110 * the beginning of the page
1111 */
1112 lli_array[0].bus_address = (u32)map_array[0].dma_addr;
1113 lli_array[0].block_size = map_array[0].size;
1114
1115 dev_dbg(&sep->pdev->dev,
1116 "lli_array[0].bus_address is %08lx, lli_array[0].block_size is %x\n",
1117 (unsigned long)lli_array[0].bus_address,
1118 lli_array[0].block_size);
1119
1120 /* Set the output parameters */
1121 if (in_out_flag == SEP_DRIVER_IN_FLAG) {
1122 *lli_array_ptr = lli_array;
1123 sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages = 1;
1124 sep->dma_res_arr[sep->nr_dcb_creat].in_page_array = NULL;
1125 sep->dma_res_arr[sep->nr_dcb_creat].in_map_array = map_array;
1126 sep->dma_res_arr[sep->nr_dcb_creat].in_map_num_entries = 1;
1127 } else {
1128 *lli_array_ptr = lli_array;
1129 sep->dma_res_arr[sep->nr_dcb_creat].out_num_pages = 1;
1130 sep->dma_res_arr[sep->nr_dcb_creat].out_page_array = NULL;
1131 sep->dma_res_arr[sep->nr_dcb_creat].out_map_array = map_array;
1132 sep->dma_res_arr[sep->nr_dcb_creat].out_map_num_entries = 1;
1133 }
1134 goto end_function;
1135
1136end_function_with_error:
1137 kfree(lli_array);
1138
1139end_function:
1140 dev_dbg(&sep->pdev->dev, "sep_lock_kernel_pages end\n");
1141 return error;
1142}
1143
1144/**
1145 * sep_lock_user_pages - lock and map user pages for DMA
1146 * @sep: pointer to struct sep_device
1147 * @app_virt_addr: user memory data buffer
1148 * @data_size: size of data buffer
1149 * @lli_array_ptr: lli array
1150 * @in_out_flag: input or output to device
1151 *
1152 * This function locks all the physical pages of the application
1153 * virtual buffer and construct a basic lli array, where each entry
1154 * holds the physical page address and the size that application
1155 * data holds in this physical pages
1156 */
1157static int sep_lock_user_pages(struct sep_device *sep,
1158 u32 app_virt_addr,
1159 u32 data_size,
1160 struct sep_lli_entry **lli_array_ptr,
1161 int in_out_flag)
1162
1163{
1164 int error = 0;
1165 u32 count;
1166 int result;
1167 /* The the page of the end address of the user space buffer */
1168 u32 end_page;
1169 /* The page of the start address of the user space buffer */
1170 u32 start_page;
1171 /* The range in pages */
1172 u32 num_pages;
1173 /* Array of pointers to page */
1174 struct page **page_array;
1175 /* Array of lli */
1176 struct sep_lli_entry *lli_array;
1177 /* Map array */
1178 struct sep_dma_map *map_array;
1179 /* Direction of the DMA mapping for locked pages */
1180 enum dma_data_direction dir;
1181
1182 dev_dbg(&sep->pdev->dev, "sep_lock_user_pages start\n");
1183
1184 /* Set start and end pages and num pages */
1185 end_page = (app_virt_addr + data_size - 1) >> PAGE_SHIFT;
1186 start_page = app_virt_addr >> PAGE_SHIFT;
1187 num_pages = end_page - start_page + 1;
1188
1189 dev_dbg(&sep->pdev->dev, "app_virt_addr is %x\n", app_virt_addr);
1190 dev_dbg(&sep->pdev->dev, "data_size is %x\n", data_size);
1191 dev_dbg(&sep->pdev->dev, "start_page is %x\n", start_page);
1192 dev_dbg(&sep->pdev->dev, "end_page is %x\n", end_page);
1193 dev_dbg(&sep->pdev->dev, "num_pages is %x\n", num_pages);
1194
1195 dev_dbg(&sep->pdev->dev, "starting page_array malloc\n");
1196
1197 /* Allocate array of pages structure pointers */
1198 page_array = kmalloc(sizeof(struct page *) * num_pages, GFP_ATOMIC);
1199 if (!page_array) {
1200 error = -ENOMEM;
1201 goto end_function;
1202 }
1203 map_array = kmalloc(sizeof(struct sep_dma_map) * num_pages, GFP_ATOMIC);
1204 if (!map_array) {
1205 dev_warn(&sep->pdev->dev, "kmalloc for map_array failed\n");
1206 error = -ENOMEM;
1207 goto end_function_with_error1;
1208 }
1209
1210 lli_array = kmalloc(sizeof(struct sep_lli_entry) * num_pages,
1211 GFP_ATOMIC);
1212
1213 if (!lli_array) {
1214 dev_warn(&sep->pdev->dev, "kmalloc for lli_array failed\n");
1215 error = -ENOMEM;
1216 goto end_function_with_error2;
1217 }
1218
1219 dev_dbg(&sep->pdev->dev, "starting get_user_pages\n");
1220
1221 /* Convert the application virtual address into a set of physical */
1222 down_read(&current->mm->mmap_sem);
1223 result = get_user_pages(current, current->mm, app_virt_addr,
1224 num_pages,
1225 ((in_out_flag == SEP_DRIVER_IN_FLAG) ? 0 : 1),
1226 0, page_array, NULL);
1227
1228 up_read(&current->mm->mmap_sem);
1229
1230 /* Check the number of pages locked - if not all then exit with error */
1231 if (result != num_pages) {
1232 dev_warn(&sep->pdev->dev,
1233 "not all pages locked by get_user_pages\n");
1234 error = -ENOMEM;
1235 goto end_function_with_error3;
1236 }
1237
1238 dev_dbg(&sep->pdev->dev, "get_user_pages succeeded\n");
1239
1240 /* Set direction */
1241 if (in_out_flag == SEP_DRIVER_IN_FLAG)
1242 dir = DMA_TO_DEVICE;
1243 else
1244 dir = DMA_FROM_DEVICE;
1245
1246 /*
1247 * Fill the array using page array data and
1248 * map the pages - this action will also flush the cache as needed
1249 */
1250 for (count = 0; count < num_pages; count++) {
1251 /* Fill the map array */
1252 map_array[count].dma_addr =
1253 dma_map_page(&sep->pdev->dev, page_array[count],
1254 0, PAGE_SIZE, /*dir*/DMA_BIDIRECTIONAL);
1255
1256 map_array[count].size = PAGE_SIZE;
1257
1258 /* Fill the lli array entry */
1259 lli_array[count].bus_address = (u32)map_array[count].dma_addr;
1260 lli_array[count].block_size = PAGE_SIZE;
1261
1262 dev_warn(&sep->pdev->dev, "lli_array[%x].bus_address is %08lx, lli_array[%x].block_size is %x\n",
1263 count, (unsigned long)lli_array[count].bus_address,
1264 count, lli_array[count].block_size);
1265 }
1266
1267 /* Check the offset for the first page */
1268 lli_array[0].bus_address =
1269 lli_array[0].bus_address + (app_virt_addr & (~PAGE_MASK));
1270
1271 /* Check that not all the data is in the first page only */
1272 if ((PAGE_SIZE - (app_virt_addr & (~PAGE_MASK))) >= data_size)
1273 lli_array[0].block_size = data_size;
1274 else
1275 lli_array[0].block_size =
1276 PAGE_SIZE - (app_virt_addr & (~PAGE_MASK));
1277
1278 dev_dbg(&sep->pdev->dev,
1279 "lli_array[0].bus_address is %08lx, lli_array[0].block_size is %x\n",
1280 (unsigned long)lli_array[count].bus_address,
1281 lli_array[count].block_size);
1282
1283 /* Check the size of the last page */
1284 if (num_pages > 1) {
1285 lli_array[num_pages - 1].block_size =
1286 (app_virt_addr + data_size) & (~PAGE_MASK);
1287
1288 dev_warn(&sep->pdev->dev,
1289 "lli_array[%x].bus_address is %08lx, lli_array[%x].block_size is %x\n",
1290 num_pages - 1,
1291 (unsigned long)lli_array[count].bus_address,
1292 num_pages - 1,
1293 lli_array[count].block_size);
1294 }
1295
1296 /* Set output params acording to the in_out flag */
1297 if (in_out_flag == SEP_DRIVER_IN_FLAG) {
1298 *lli_array_ptr = lli_array;
1299 sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages = num_pages;
1300 sep->dma_res_arr[sep->nr_dcb_creat].in_page_array = page_array;
1301 sep->dma_res_arr[sep->nr_dcb_creat].in_map_array = map_array;
1302 sep->dma_res_arr[sep->nr_dcb_creat].in_map_num_entries =
1303 num_pages;
1304 } else {
1305 *lli_array_ptr = lli_array;
1306 sep->dma_res_arr[sep->nr_dcb_creat].out_num_pages = num_pages;
1307 sep->dma_res_arr[sep->nr_dcb_creat].out_page_array =
1308 page_array;
1309 sep->dma_res_arr[sep->nr_dcb_creat].out_map_array = map_array;
1310 sep->dma_res_arr[sep->nr_dcb_creat].out_map_num_entries =
1311 num_pages;
1312 }
1313 goto end_function;
1314
1315end_function_with_error3:
1316 /* Free lli array */
1317 kfree(lli_array);
1318
1319end_function_with_error2:
1320 kfree(map_array);
1321
1322end_function_with_error1:
1323 /* Free page array */
1324 kfree(page_array);
1325
1326end_function:
1327 dev_dbg(&sep->pdev->dev, "sep_lock_user_pages end\n");
1328 return error;
1329}
1330
1331/**
1332 * u32 sep_calculate_lli_table_max_size - size the LLI table
1333 * @sep: pointer to struct sep_device
1334 * @lli_in_array_ptr
1335 * @num_array_entries
1336 * @last_table_flag
1337 *
1338 * This function calculates the size of data that can be inserted into
1339 * the lli table from this array, such that either the table is full
1340 * (all entries are entered), or there are no more entries in the
1341 * lli array
1342 */
1343static u32 sep_calculate_lli_table_max_size(struct sep_device *sep,
1344 struct sep_lli_entry *lli_in_array_ptr,
1345 u32 num_array_entries,
1346 u32 *last_table_flag)
1347{
1348 u32 counter;
1349 /* Table data size */
1350 u32 table_data_size = 0;
1351 /* Data size for the next table */
1352 u32 next_table_data_size;
1353
1354 *last_table_flag = 0;
1355
1356 /*
1357 * Calculate the data in the out lli table till we fill the whole
1358 * table or till the data has ended
1359 */
1360 for (counter = 0;
1361 (counter < (SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP - 1)) &&
1362 (counter < num_array_entries); counter++)
1363 table_data_size += lli_in_array_ptr[counter].block_size;
1364
1365 /*
1366 * Check if we reached the last entry,
1367 * meaning this ia the last table to build,
1368 * and no need to check the block alignment
1369 */
1370 if (counter == num_array_entries) {
1371 /* Set the last table flag */
1372 *last_table_flag = 1;
1373 goto end_function;
1374 }
1375
1376 /*
1377 * Calculate the data size of the next table.
1378 * Stop if no entries left or if data size is more the DMA restriction
1379 */
1380 next_table_data_size = 0;
1381 for (; counter < num_array_entries; counter++) {
1382 next_table_data_size += lli_in_array_ptr[counter].block_size;
1383 if (next_table_data_size >= SEP_DRIVER_MIN_DATA_SIZE_PER_TABLE)
1384 break;
1385 }
1386
1387 /*
1388 * Check if the next table data size is less then DMA rstriction.
1389 * if it is - recalculate the current table size, so that the next
1390 * table data size will be adaquete for DMA
1391 */
1392 if (next_table_data_size &&
1393 next_table_data_size < SEP_DRIVER_MIN_DATA_SIZE_PER_TABLE)
1394
1395 table_data_size -= (SEP_DRIVER_MIN_DATA_SIZE_PER_TABLE -
1396 next_table_data_size);
1397
1398 dev_dbg(&sep->pdev->dev, "table data size is %x\n",
1399 table_data_size);
1400end_function:
1401 return table_data_size;
1402}
1403
1404/**
1405 * sep_build_lli_table - build an lli array for the given table
1406 * @sep: pointer to struct sep_device
1407 * @lli_array_ptr: pointer to lli array
1408 * @lli_table_ptr: pointer to lli table
1409 * @num_processed_entries_ptr: pointer to number of entries
1410 * @num_table_entries_ptr: pointer to number of tables
1411 * @table_data_size: total data size
1412 *
1413 * Builds ant lli table from the lli_array according to
1414 * the given size of data
1415 */
1416static void sep_build_lli_table(struct sep_device *sep,
1417 struct sep_lli_entry *lli_array_ptr,
1418 struct sep_lli_entry *lli_table_ptr,
1419 u32 *num_processed_entries_ptr,
1420 u32 *num_table_entries_ptr,
1421 u32 table_data_size)
1422{
1423 /* Current table data size */
1424 u32 curr_table_data_size;
1425 /* Counter of lli array entry */
1426 u32 array_counter;
1427
1428 dev_dbg(&sep->pdev->dev, "sep_build_lli_table start\n");
1429
1430 /* Init currrent table data size and lli array entry counter */
1431 curr_table_data_size = 0;
1432 array_counter = 0;
1433 *num_table_entries_ptr = 1;
1434
1435 dev_dbg(&sep->pdev->dev, "table_data_size is %x\n", table_data_size);
1436
1437 /* Fill the table till table size reaches the needed amount */
1438 while (curr_table_data_size < table_data_size) {
1439 /* Update the number of entries in table */
1440 (*num_table_entries_ptr)++;
1441
1442 lli_table_ptr->bus_address =
1443 cpu_to_le32(lli_array_ptr[array_counter].bus_address);
1444
1445 lli_table_ptr->block_size =
1446 cpu_to_le32(lli_array_ptr[array_counter].block_size);
1447
1448 curr_table_data_size += lli_array_ptr[array_counter].block_size;
1449
1450 dev_dbg(&sep->pdev->dev, "lli_table_ptr is %p\n",
1451 lli_table_ptr);
1452 dev_dbg(&sep->pdev->dev, "lli_table_ptr->bus_address is %08lx\n",
1453 (unsigned long)lli_table_ptr->bus_address);
1454 dev_dbg(&sep->pdev->dev, "lli_table_ptr->block_size is %x\n",
1455 lli_table_ptr->block_size);
1456
1457 /* Check for overflow of the table data */
1458 if (curr_table_data_size > table_data_size) {
1459 dev_dbg(&sep->pdev->dev,
1460 "curr_table_data_size too large\n");
1461
1462 /* Update the size of block in the table */
1463 lli_table_ptr->block_size -=
1464 cpu_to_le32((curr_table_data_size - table_data_size));
1465
1466 /* Update the physical address in the lli array */
1467 lli_array_ptr[array_counter].bus_address +=
1468 cpu_to_le32(lli_table_ptr->block_size);
1469
1470 /* Update the block size left in the lli array */
1471 lli_array_ptr[array_counter].block_size =
1472 (curr_table_data_size - table_data_size);
1473 } else
1474 /* Advance to the next entry in the lli_array */
1475 array_counter++;
1476
1477 dev_dbg(&sep->pdev->dev,
1478 "lli_table_ptr->bus_address is %08lx\n",
1479 (unsigned long)lli_table_ptr->bus_address);
1480 dev_dbg(&sep->pdev->dev,
1481 "lli_table_ptr->block_size is %x\n",
1482 lli_table_ptr->block_size);
1483
1484 /* Move to the next entry in table */
1485 lli_table_ptr++;
1486 }
1487
1488 /* Set the info entry to default */
1489 lli_table_ptr->bus_address = 0xffffffff;
1490 lli_table_ptr->block_size = 0;
1491
1492 dev_dbg(&sep->pdev->dev, "lli_table_ptr is %p\n", lli_table_ptr);
1493 dev_dbg(&sep->pdev->dev, "lli_table_ptr->bus_address is %08lx\n",
1494 (unsigned long)lli_table_ptr->bus_address);
1495 dev_dbg(&sep->pdev->dev, "lli_table_ptr->block_size is %x\n",
1496 lli_table_ptr->block_size);
1497
1498 /* Set the output parameter */
1499 *num_processed_entries_ptr += array_counter;
1500
1501 dev_dbg(&sep->pdev->dev, "num_processed_entries_ptr is %x\n",
1502 *num_processed_entries_ptr);
1503
1504 dev_dbg(&sep->pdev->dev, "sep_build_lli_table end\n");
1505}
1506
1507/**
1508 * sep_shared_area_virt_to_bus - map shared area to bus address
1509 * @sep: pointer to struct sep_device
1510 * @virt_address: virtual address to convert
1511 *
1512 * This functions returns the physical address inside shared area according
1513 * to the virtual address. It can be either on the externa RAM device
1514 * (ioremapped), or on the system RAM
1515 * This implementation is for the external RAM
1516 */
1517static dma_addr_t sep_shared_area_virt_to_bus(struct sep_device *sep,
1518 void *virt_address)
1519{
1520 dev_dbg(&sep->pdev->dev, "sh virt to phys v %p\n", virt_address);
1521 dev_dbg(&sep->pdev->dev, "sh virt to phys p %08lx\n",
1522 (unsigned long)
1523 sep->shared_bus + (virt_address - sep->shared_addr));
1524
1525 return sep->shared_bus + (size_t)(virt_address - sep->shared_addr);
1526}
1527
1528/**
1529 * sep_shared_area_bus_to_virt - map shared area bus address to kernel
1530 * @sep: pointer to struct sep_device
1531 * @bus_address: bus address to convert
1532 *
1533 * This functions returns the virtual address inside shared area
1534 * according to the physical address. It can be either on the
1535 * externa RAM device (ioremapped), or on the system RAM
1536 * This implementation is for the external RAM
1537 */
1538static void *sep_shared_area_bus_to_virt(struct sep_device *sep,
1539 dma_addr_t bus_address)
1540{
1541 dev_dbg(&sep->pdev->dev, "shared bus to virt b=%lx v=%lx\n",
1542 (unsigned long)bus_address, (unsigned long)(sep->shared_addr +
1543 (size_t)(bus_address - sep->shared_bus)));
1544
1545 return sep->shared_addr + (size_t)(bus_address - sep->shared_bus);
1546}
1547
1548/**
1549 * sep_debug_print_lli_tables - dump LLI table
1550 * @sep: pointer to struct sep_device
1551 * @lli_table_ptr: pointer to sep_lli_entry
1552 * @num_table_entries: number of entries
1553 * @table_data_size: total data size
1554 *
1555 * Walk the the list of the print created tables and print all the data
1556 */
1557static void sep_debug_print_lli_tables(struct sep_device *sep,
1558 struct sep_lli_entry *lli_table_ptr,
1559 unsigned long num_table_entries,
1560 unsigned long table_data_size)
1561{
1562 unsigned long table_count = 1;
1563 unsigned long entries_count = 0;
1564
1565 dev_dbg(&sep->pdev->dev, "sep_debug_print_lli_tables start\n");
1566
1567 while ((unsigned long) lli_table_ptr->bus_address != 0xffffffff) {
1568 dev_dbg(&sep->pdev->dev,
1569 "lli table %08lx, table_data_size is %lu\n",
1570 table_count, table_data_size);
1571 dev_dbg(&sep->pdev->dev, "num_table_entries is %lu\n",
1572 num_table_entries);
1573
1574 /* Print entries of the table (without info entry) */
1575 for (entries_count = 0; entries_count < num_table_entries;
1576 entries_count++, lli_table_ptr++) {
1577
1578 dev_dbg(&sep->pdev->dev,
1579 "lli_table_ptr address is %08lx\n",
1580 (unsigned long) lli_table_ptr);
1581
1582 dev_dbg(&sep->pdev->dev,
1583 "phys address is %08lx block size is %x\n",
1584 (unsigned long)lli_table_ptr->bus_address,
1585 lli_table_ptr->block_size);
1586 }
1587 /* Point to the info entry */
1588 lli_table_ptr--;
1589
1590 dev_dbg(&sep->pdev->dev,
1591 "phys lli_table_ptr->block_size is %x\n",
1592 lli_table_ptr->block_size);
1593
1594 dev_dbg(&sep->pdev->dev,
1595 "phys lli_table_ptr->physical_address is %08lu\n",
1596 (unsigned long)lli_table_ptr->bus_address);
1597
1598
1599 table_data_size = lli_table_ptr->block_size & 0xffffff;
1600 num_table_entries = (lli_table_ptr->block_size >> 24) & 0xff;
1601
1602 dev_dbg(&sep->pdev->dev,
1603 "phys table_data_size is %lu num_table_entries is"
1604 " %lu bus_address is%lu\n", table_data_size,
1605 num_table_entries, (unsigned long)lli_table_ptr->bus_address);
1606
1607 if ((unsigned long)lli_table_ptr->bus_address != 0xffffffff)
1608 lli_table_ptr = (struct sep_lli_entry *)
1609 sep_shared_bus_to_virt(sep,
1610 (unsigned long)lli_table_ptr->bus_address);
1611
1612 table_count++;
1613 }
1614 dev_dbg(&sep->pdev->dev, "sep_debug_print_lli_tables end\n");
1615}
1616
1617
1618/**
1619 * sep_prepare_empty_lli_table - create a blank LLI table
1620 * @sep: pointer to struct sep_device
1621 * @lli_table_addr_ptr: pointer to lli table
1622 * @num_entries_ptr: pointer to number of entries
1623 * @table_data_size_ptr: point to table data size
1624 *
1625 * This function creates empty lli tables when there is no data
1626 */
1627static void sep_prepare_empty_lli_table(struct sep_device *sep,
1628 dma_addr_t *lli_table_addr_ptr,
1629 u32 *num_entries_ptr,
1630 u32 *table_data_size_ptr)
1631{
1632 struct sep_lli_entry *lli_table_ptr;
1633
1634 dev_dbg(&sep->pdev->dev, "sep_prepare_empty_lli_table start\n");
1635
1636 /* Find the area for new table */
1637 lli_table_ptr =
1638 (struct sep_lli_entry *)(sep->shared_addr +
1639 SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES +
1640 sep->num_lli_tables_created * sizeof(struct sep_lli_entry) *
1641 SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP);
1642
1643 lli_table_ptr->bus_address = 0;
1644 lli_table_ptr->block_size = 0;
1645
1646 lli_table_ptr++;
1647 lli_table_ptr->bus_address = 0xFFFFFFFF;
1648 lli_table_ptr->block_size = 0;
1649
1650 /* Set the output parameter value */
1651 *lli_table_addr_ptr = sep->shared_bus +
1652 SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES +
1653 sep->num_lli_tables_created *
1654 sizeof(struct sep_lli_entry) *
1655 SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP;
1656
1657 /* Set the num of entries and table data size for empty table */
1658 *num_entries_ptr = 2;
1659 *table_data_size_ptr = 0;
1660
1661 /* Update the number of created tables */
1662 sep->num_lli_tables_created++;
1663
1664 dev_dbg(&sep->pdev->dev, "sep_prepare_empty_lli_table start\n");
1665
1666}
1667
1668/**
1669 * sep_prepare_input_dma_table - prepare input DMA mappings
1670 * @sep: pointer to struct sep_device
1671 * @data_size:
1672 * @block_size:
1673 * @lli_table_ptr:
1674 * @num_entries_ptr:
1675 * @table_data_size_ptr:
1676 * @is_kva: set for kernel data (kernel cryptio call)
1677 *
1678 * This function prepares only input DMA table for synhronic symmetric
1679 * operations (HASH)
1680 * Note that all bus addresses that are passed to the SEP
1681 * are in 32 bit format; the SEP is a 32 bit device
1682 */
1683static int sep_prepare_input_dma_table(struct sep_device *sep,
1684 unsigned long app_virt_addr,
1685 u32 data_size,
1686 u32 block_size,
1687 dma_addr_t *lli_table_ptr,
1688 u32 *num_entries_ptr,
1689 u32 *table_data_size_ptr,
1690 bool is_kva)
1691{
1692 int error = 0;
1693 /* Pointer to the info entry of the table - the last entry */
1694 struct sep_lli_entry *info_entry_ptr;
1695 /* Array of pointers to page */
1696 struct sep_lli_entry *lli_array_ptr;
1697 /* Points to the first entry to be processed in the lli_in_array */
1698 u32 current_entry = 0;
1699 /* Num entries in the virtual buffer */
1700 u32 sep_lli_entries = 0;
1701 /* Lli table pointer */
1702 struct sep_lli_entry *in_lli_table_ptr;
1703 /* The total data in one table */
1704 u32 table_data_size = 0;
1705 /* Flag for last table */
1706 u32 last_table_flag = 0;
1707 /* Number of entries in lli table */
1708 u32 num_entries_in_table = 0;
1709 /* Next table address */
1710 void *lli_table_alloc_addr = 0;
1711
1712 dev_dbg(&sep->pdev->dev, "sep_prepare_input_dma_table start\n");
1713 dev_dbg(&sep->pdev->dev, "data_size is %x\n", data_size);
1714 dev_dbg(&sep->pdev->dev, "block_size is %x\n", block_size);
1715
1716 /* Initialize the pages pointers */
1717 sep->dma_res_arr[sep->nr_dcb_creat].in_page_array = NULL;
1718 sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages = 0;
1719
1720 /* Set the kernel address for first table to be allocated */
1721 lli_table_alloc_addr = (void *)(sep->shared_addr +
1722 SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES +
1723 sep->num_lli_tables_created * sizeof(struct sep_lli_entry) *
1724 SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP);
1725
1726 if (data_size == 0) {
1727 /* Special case - create meptu table - 2 entries, zero data */
1728 sep_prepare_empty_lli_table(sep, lli_table_ptr,
1729 num_entries_ptr, table_data_size_ptr);
1730 goto update_dcb_counter;
1731 }
1732
1733 /* Check if the pages are in Kernel Virtual Address layout */
1734 if (is_kva == true)
1735 /* Lock the pages in the kernel */
1736 error = sep_lock_kernel_pages(sep, app_virt_addr,
1737 data_size, &lli_array_ptr, SEP_DRIVER_IN_FLAG);
1738 else
1739 /*
1740 * Lock the pages of the user buffer
1741 * and translate them to pages
1742 */
1743 error = sep_lock_user_pages(sep, app_virt_addr,
1744 data_size, &lli_array_ptr, SEP_DRIVER_IN_FLAG);
1745
1746 if (error)
1747 goto end_function;
1748
1749 dev_dbg(&sep->pdev->dev, "output sep_in_num_pages is %x\n",
1750 sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages);
1751
1752 current_entry = 0;
1753 info_entry_ptr = NULL;
1754
1755 sep_lli_entries = sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages;
1756
1757 /* Loop till all the entries in in array are not processed */
1758 while (current_entry < sep_lli_entries) {
1759
1760 /* Set the new input and output tables */
1761 in_lli_table_ptr =
1762 (struct sep_lli_entry *)lli_table_alloc_addr;
1763
1764 lli_table_alloc_addr += sizeof(struct sep_lli_entry) *
1765 SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP;
1766
1767 if (lli_table_alloc_addr >
1768 ((void *)sep->shared_addr +
1769 SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES +
1770 SYNCHRONIC_DMA_TABLES_AREA_SIZE_BYTES)) {
1771
1772 error = -ENOMEM;
1773 goto end_function_error;
1774
1775 }
1776
1777 /* Update the number of created tables */
1778 sep->num_lli_tables_created++;
1779
1780 /* Calculate the maximum size of data for input table */
1781 table_data_size = sep_calculate_lli_table_max_size(sep,
1782 &lli_array_ptr[current_entry],
1783 (sep_lli_entries - current_entry),
1784 &last_table_flag);
1785
1786 /*
1787 * If this is not the last table -
1788 * then allign it to the block size
1789 */
1790 if (!last_table_flag)
1791 table_data_size =
1792 (table_data_size / block_size) * block_size;
1793
1794 dev_dbg(&sep->pdev->dev, "output table_data_size is %x\n",
1795 table_data_size);
1796
1797 /* Construct input lli table */
1798 sep_build_lli_table(sep, &lli_array_ptr[current_entry],
1799 in_lli_table_ptr,
1800 &current_entry, &num_entries_in_table, table_data_size);
1801
1802 if (info_entry_ptr == NULL) {
1803
1804 /* Set the output parameters to physical addresses */
1805 *lli_table_ptr = sep_shared_area_virt_to_bus(sep,
1806 in_lli_table_ptr);
1807 *num_entries_ptr = num_entries_in_table;
1808 *table_data_size_ptr = table_data_size;
1809
1810 dev_dbg(&sep->pdev->dev,
1811 "output lli_table_in_ptr is %08lx\n",
1812 (unsigned long)*lli_table_ptr);
1813
1814 } else {
1815 /* Update the info entry of the previous in table */
1816 info_entry_ptr->bus_address =
1817 sep_shared_area_virt_to_bus(sep,
1818 in_lli_table_ptr);
1819 info_entry_ptr->block_size =
1820 ((num_entries_in_table) << 24) |
1821 (table_data_size);
1822 }
1823 /* Save the pointer to the info entry of the current tables */
1824 info_entry_ptr = in_lli_table_ptr + num_entries_in_table - 1;
1825 }
1826 /* Print input tables */
1827 sep_debug_print_lli_tables(sep, (struct sep_lli_entry *)
1828 sep_shared_area_bus_to_virt(sep, *lli_table_ptr),
1829 *num_entries_ptr, *table_data_size_ptr);
1830 /* The array of the pages */
1831 kfree(lli_array_ptr);
1832
1833update_dcb_counter:
1834 /* Update DCB counter */
1835 sep->nr_dcb_creat++;
1836 goto end_function;
1837
1838end_function_error:
1839 /* Free all the allocated resources */
1840 kfree(sep->dma_res_arr[sep->nr_dcb_creat].in_map_array);
1841 kfree(lli_array_ptr);
1842 kfree(sep->dma_res_arr[sep->nr_dcb_creat].in_page_array);
1843
1844end_function:
1845 dev_dbg(&sep->pdev->dev, "sep_prepare_input_dma_table end\n");
1846 return error;
1847
1848}
1849/**
1850 * sep_construct_dma_tables_from_lli - prepare AES/DES mappings
1851 * @sep: pointer to struct sep_device
1852 * @lli_in_array:
1853 * @sep_in_lli_entries:
1854 * @lli_out_array:
1855 * @sep_out_lli_entries
1856 * @block_size
1857 * @lli_table_in_ptr
1858 * @lli_table_out_ptr
1859 * @in_num_entries_ptr
1860 * @out_num_entries_ptr
1861 * @table_data_size_ptr
1862 *
1863 * This function creates the input and output DMA tables for
1864 * symmetric operations (AES/DES) according to the block
1865 * size from LLI arays
1866 * Note that all bus addresses that are passed to the SEP
1867 * are in 32 bit format; the SEP is a 32 bit device
1868 */
1869static int sep_construct_dma_tables_from_lli(
1870 struct sep_device *sep,
1871 struct sep_lli_entry *lli_in_array,
1872 u32 sep_in_lli_entries,
1873 struct sep_lli_entry *lli_out_array,
1874 u32 sep_out_lli_entries,
1875 u32 block_size,
1876 dma_addr_t *lli_table_in_ptr,
1877 dma_addr_t *lli_table_out_ptr,
1878 u32 *in_num_entries_ptr,
1879 u32 *out_num_entries_ptr,
1880 u32 *table_data_size_ptr)
1881{
1882 /* Points to the area where next lli table can be allocated */
1883 void *lli_table_alloc_addr = 0;
1884 /* Input lli table */
1885 struct sep_lli_entry *in_lli_table_ptr = NULL;
1886 /* Output lli table */
1887 struct sep_lli_entry *out_lli_table_ptr = NULL;
1888 /* Pointer to the info entry of the table - the last entry */
1889 struct sep_lli_entry *info_in_entry_ptr = NULL;
1890 /* Pointer to the info entry of the table - the last entry */
1891 struct sep_lli_entry *info_out_entry_ptr = NULL;
1892 /* Points to the first entry to be processed in the lli_in_array */
1893 u32 current_in_entry = 0;
1894 /* Points to the first entry to be processed in the lli_out_array */
1895 u32 current_out_entry = 0;
1896 /* Max size of the input table */
1897 u32 in_table_data_size = 0;
1898 /* Max size of the output table */
1899 u32 out_table_data_size = 0;
1900 /* Flag te signifies if this is the last tables build */
1901 u32 last_table_flag = 0;
1902 /* The data size that should be in table */
1903 u32 table_data_size = 0;
1904 /* Number of etnries in the input table */
1905 u32 num_entries_in_table = 0;
1906 /* Number of etnries in the output table */
1907 u32 num_entries_out_table = 0;
1908
1909 dev_dbg(&sep->pdev->dev, "sep_construct_dma_tables_from_lli start\n");
1910
1911 /* Initiate to point after the message area */
1912 lli_table_alloc_addr = (void *)(sep->shared_addr +
1913 SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES +
1914 (sep->num_lli_tables_created *
1915 (sizeof(struct sep_lli_entry) *
1916 SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP)));
1917
1918 /* Loop till all the entries in in array are not processed */
1919 while (current_in_entry < sep_in_lli_entries) {
1920 /* Set the new input and output tables */
1921 in_lli_table_ptr =
1922 (struct sep_lli_entry *)lli_table_alloc_addr;
1923
1924 lli_table_alloc_addr += sizeof(struct sep_lli_entry) *
1925 SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP;
1926
1927 /* Set the first output tables */
1928 out_lli_table_ptr =
1929 (struct sep_lli_entry *)lli_table_alloc_addr;
1930
1931 /* Check if the DMA table area limit was overrun */
1932 if ((lli_table_alloc_addr + sizeof(struct sep_lli_entry) *
1933 SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP) >
1934 ((void *)sep->shared_addr +
1935 SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES +
1936 SYNCHRONIC_DMA_TABLES_AREA_SIZE_BYTES)) {
1937
1938 dev_warn(&sep->pdev->dev, "dma table limit overrun\n");
1939 return -ENOMEM;
1940 }
1941
1942 /* Update the number of the lli tables created */
1943 sep->num_lli_tables_created += 2;
1944
1945 lli_table_alloc_addr += sizeof(struct sep_lli_entry) *
1946 SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP;
1947
1948 /* Calculate the maximum size of data for input table */
1949 in_table_data_size =
1950 sep_calculate_lli_table_max_size(sep,
1951 &lli_in_array[current_in_entry],
1952 (sep_in_lli_entries - current_in_entry),
1953 &last_table_flag);
1954
1955 /* Calculate the maximum size of data for output table */
1956 out_table_data_size =
1957 sep_calculate_lli_table_max_size(sep,
1958 &lli_out_array[current_out_entry],
1959 (sep_out_lli_entries - current_out_entry),
1960 &last_table_flag);
1961
1962 dev_dbg(&sep->pdev->dev,
1963 "in_table_data_size is %x\n",
1964 in_table_data_size);
1965
1966 dev_dbg(&sep->pdev->dev,
1967 "out_table_data_size is %x\n",
1968 out_table_data_size);
1969
1970 table_data_size = in_table_data_size;
1971
1972 if (!last_table_flag) {
1973 /*
1974 * If this is not the last table,
1975 * then must check where the data is smallest
1976 * and then align it to the block size
1977 */
1978 if (table_data_size > out_table_data_size)
1979 table_data_size = out_table_data_size;
1980
1981 /*
1982 * Now calculate the table size so that
1983 * it will be module block size
1984 */
1985 table_data_size = (table_data_size / block_size) *
1986 block_size;
1987 }
1988
1989 dev_dbg(&sep->pdev->dev, "table_data_size is %x\n",
1990 table_data_size);
1991
1992 /* Construct input lli table */
1993 sep_build_lli_table(sep, &lli_in_array[current_in_entry],
1994 in_lli_table_ptr,
1995 &current_in_entry,
1996 &num_entries_in_table,
1997 table_data_size);
1998
1999 /* Construct output lli table */
2000 sep_build_lli_table(sep, &lli_out_array[current_out_entry],
2001 out_lli_table_ptr,
2002 &current_out_entry,
2003 &num_entries_out_table,
2004 table_data_size);
2005
2006 /* If info entry is null - this is the first table built */
2007 if (info_in_entry_ptr == NULL) {
2008 /* Set the output parameters to physical addresses */
2009 *lli_table_in_ptr =
2010 sep_shared_area_virt_to_bus(sep, in_lli_table_ptr);
2011
2012 *in_num_entries_ptr = num_entries_in_table;
2013
2014 *lli_table_out_ptr =
2015 sep_shared_area_virt_to_bus(sep,
2016 out_lli_table_ptr);
2017
2018 *out_num_entries_ptr = num_entries_out_table;
2019 *table_data_size_ptr = table_data_size;
2020
2021 dev_dbg(&sep->pdev->dev,
2022 "output lli_table_in_ptr is %08lx\n",
2023 (unsigned long)*lli_table_in_ptr);
2024 dev_dbg(&sep->pdev->dev,
2025 "output lli_table_out_ptr is %08lx\n",
2026 (unsigned long)*lli_table_out_ptr);
2027 } else {
2028 /* Update the info entry of the previous in table */
2029 info_in_entry_ptr->bus_address =
2030 sep_shared_area_virt_to_bus(sep,
2031 in_lli_table_ptr);
2032
2033 info_in_entry_ptr->block_size =
2034 ((num_entries_in_table) << 24) |
2035 (table_data_size);
2036
2037 /* Update the info entry of the previous in table */
2038 info_out_entry_ptr->bus_address =
2039 sep_shared_area_virt_to_bus(sep,
2040 out_lli_table_ptr);
2041
2042 info_out_entry_ptr->block_size =
2043 ((num_entries_out_table) << 24) |
2044 (table_data_size);
2045
2046 dev_dbg(&sep->pdev->dev,
2047 "output lli_table_in_ptr:%08lx %08x\n",
2048 (unsigned long)info_in_entry_ptr->bus_address,
2049 info_in_entry_ptr->block_size);
2050
2051 dev_dbg(&sep->pdev->dev,
2052 "output lli_table_out_ptr:%08lx %08x\n",
2053 (unsigned long)info_out_entry_ptr->bus_address,
2054 info_out_entry_ptr->block_size);
2055 }
2056
2057 /* Save the pointer to the info entry of the current tables */
2058 info_in_entry_ptr = in_lli_table_ptr +
2059 num_entries_in_table - 1;
2060 info_out_entry_ptr = out_lli_table_ptr +
2061 num_entries_out_table - 1;
2062
2063 dev_dbg(&sep->pdev->dev,
2064 "output num_entries_out_table is %x\n",
2065 (u32)num_entries_out_table);
2066 dev_dbg(&sep->pdev->dev,
2067 "output info_in_entry_ptr is %lx\n",
2068 (unsigned long)info_in_entry_ptr);
2069 dev_dbg(&sep->pdev->dev,
2070 "output info_out_entry_ptr is %lx\n",
2071 (unsigned long)info_out_entry_ptr);
2072 }
2073
2074 /* Print input tables */
2075 sep_debug_print_lli_tables(sep,
2076 (struct sep_lli_entry *)
2077 sep_shared_area_bus_to_virt(sep, *lli_table_in_ptr),
2078 *in_num_entries_ptr,
2079 *table_data_size_ptr);
2080
2081 /* Print output tables */
2082 sep_debug_print_lli_tables(sep,
2083 (struct sep_lli_entry *)
2084 sep_shared_area_bus_to_virt(sep, *lli_table_out_ptr),
2085 *out_num_entries_ptr,
2086 *table_data_size_ptr);
2087
2088 dev_dbg(&sep->pdev->dev, "sep_construct_dma_tables_from_lli end\n");
2089 return 0;
2090}
2091
2092/**
2093 * sep_prepare_input_output_dma_table - prepare DMA I/O table
2094 * @app_virt_in_addr:
2095 * @app_virt_out_addr:
2096 * @data_size:
2097 * @block_size:
2098 * @lli_table_in_ptr:
2099 * @lli_table_out_ptr:
2100 * @in_num_entries_ptr:
2101 * @out_num_entries_ptr:
2102 * @table_data_size_ptr:
2103 * @is_kva: set for kernel data; used only for kernel crypto module
2104 *
2105 * This function builds input and output DMA tables for synhronic
2106 * symmetric operations (AES, DES, HASH). It also checks that each table
2107 * is of the modular block size
2108 * Note that all bus addresses that are passed to the SEP
2109 * are in 32 bit format; the SEP is a 32 bit device
2110 */
2111static int sep_prepare_input_output_dma_table(struct sep_device *sep,
2112 unsigned long app_virt_in_addr,
2113 unsigned long app_virt_out_addr,
2114 u32 data_size,
2115 u32 block_size,
2116 dma_addr_t *lli_table_in_ptr,
2117 dma_addr_t *lli_table_out_ptr,
2118 u32 *in_num_entries_ptr,
2119 u32 *out_num_entries_ptr,
2120 u32 *table_data_size_ptr,
2121 bool is_kva)
2122
2123{
2124 int error = 0;
2125 /* Array of pointers of page */
2126 struct sep_lli_entry *lli_in_array;
2127 /* Array of pointers of page */
2128 struct sep_lli_entry *lli_out_array;
2129
2130 dev_dbg(&sep->pdev->dev, "sep_prepare_input_output_dma_table start\n");
2131
2132 if (data_size == 0) {
2133 /* Prepare empty table for input and output */
2134 sep_prepare_empty_lli_table(sep, lli_table_in_ptr,
2135 in_num_entries_ptr, table_data_size_ptr);
2136
2137 sep_prepare_empty_lli_table(sep, lli_table_out_ptr,
2138 out_num_entries_ptr, table_data_size_ptr);
2139
2140 goto update_dcb_counter;
2141 }
2142
2143 /* Initialize the pages pointers */
2144 sep->dma_res_arr[sep->nr_dcb_creat].in_page_array = NULL;
2145 sep->dma_res_arr[sep->nr_dcb_creat].out_page_array = NULL;
2146
2147 /* Lock the pages of the buffer and translate them to pages */
2148 if (is_kva == true) {
2149 error = sep_lock_kernel_pages(sep, app_virt_in_addr,
2150 data_size, &lli_in_array, SEP_DRIVER_IN_FLAG);
2151
2152 if (error) {
2153 dev_warn(&sep->pdev->dev,
2154 "lock kernel for in failed\n");
2155 goto end_function;
2156 }
2157
2158 error = sep_lock_kernel_pages(sep, app_virt_out_addr,
2159 data_size, &lli_out_array, SEP_DRIVER_OUT_FLAG);
2160
2161 if (error) {
2162 dev_warn(&sep->pdev->dev,
2163 "lock kernel for out failed\n");
2164 goto end_function;
2165 }
2166 }
2167
2168 else {
2169 error = sep_lock_user_pages(sep, app_virt_in_addr,
2170 data_size, &lli_in_array, SEP_DRIVER_IN_FLAG);
2171 if (error) {
2172 dev_warn(&sep->pdev->dev,
2173 "sep_lock_user_pages for input virtual buffer failed\n");
2174 goto end_function;
2175 }
2176
2177 error = sep_lock_user_pages(sep, app_virt_out_addr,
2178 data_size, &lli_out_array, SEP_DRIVER_OUT_FLAG);
2179
2180 if (error) {
2181 dev_warn(&sep->pdev->dev,
2182 "sep_lock_user_pages for output virtual buffer failed\n");
2183 goto end_function_free_lli_in;
2184 }
2185 }
2186
2187 dev_dbg(&sep->pdev->dev, "sep_in_num_pages is %x\n",
2188 sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages);
2189 dev_dbg(&sep->pdev->dev, "sep_out_num_pages is %x\n",
2190 sep->dma_res_arr[sep->nr_dcb_creat].out_num_pages);
2191 dev_dbg(&sep->pdev->dev, "SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP is %x\n",
2192 SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP);
2193
2194 /* Call the fucntion that creates table from the lli arrays */
2195 error = sep_construct_dma_tables_from_lli(sep, lli_in_array,
2196 sep->dma_res_arr[sep->nr_dcb_creat].in_num_pages,
2197 lli_out_array,
2198 sep->dma_res_arr[sep->nr_dcb_creat].out_num_pages,
2199 block_size, lli_table_in_ptr, lli_table_out_ptr,
2200 in_num_entries_ptr, out_num_entries_ptr, table_data_size_ptr);
2201
2202 if (error) {
2203 dev_warn(&sep->pdev->dev,
2204 "sep_construct_dma_tables_from_lli failed\n");
2205 goto end_function_with_error;
2206 }
2207
2208 kfree(lli_out_array);
2209 kfree(lli_in_array);
2210
2211update_dcb_counter:
2212 /* Update DCB counter */
2213 sep->nr_dcb_creat++;
2214 /* Fall through - free the lli entry arrays */
2215 dev_dbg(&sep->pdev->dev, "in_num_entries_ptr is %08x\n",
2216 *in_num_entries_ptr);
2217 dev_dbg(&sep->pdev->dev, "out_num_entries_ptr is %08x\n",
2218 *out_num_entries_ptr);
2219 dev_dbg(&sep->pdev->dev, "table_data_size_ptr is %08x\n",
2220 *table_data_size_ptr);
2221
2222 goto end_function;
2223
2224end_function_with_error:
2225 kfree(sep->dma_res_arr[sep->nr_dcb_creat].out_map_array);
2226 kfree(sep->dma_res_arr[sep->nr_dcb_creat].out_page_array);
2227 kfree(lli_out_array);
2228
2229
2230end_function_free_lli_in:
2231 kfree(sep->dma_res_arr[sep->nr_dcb_creat].in_map_array);
2232 kfree(sep->dma_res_arr[sep->nr_dcb_creat].in_page_array);
2233 kfree(lli_in_array);
2234
2235end_function:
2236 dev_dbg(&sep->pdev->dev,
2237 "sep_prepare_input_output_dma_table end result = %d\n", error);
2238
2239 return error;
2240
2241}
2242
2243/**
2244 * sep_prepare_input_output_dma_table_in_dcb - prepare control blocks
2245 * @app_in_address: unsigned long; for data buffer in (user space)
2246 * @app_out_address: unsigned long; for data buffer out (user space)
2247 * @data_in_size: u32; for size of data
2248 * @block_size: u32; for block size
2249 * @tail_block_size: u32; for size of tail block
2250 * @isapplet: bool; to indicate external app
2251 * @is_kva: bool; kernel buffer; only used for kernel crypto module
2252 *
2253 * This function prepares the linked DMA tables and puts the
2254 * address for the linked list of tables inta a DCB (data control
2255 * block) the address of which is known by the SEP hardware
2256 * Note that all bus addresses that are passed to the SEP
2257 * are in 32 bit format; the SEP is a 32 bit device
2258 */
2259static int sep_prepare_input_output_dma_table_in_dcb(struct sep_device *sep,
2260 unsigned long app_in_address,
2261 unsigned long app_out_address,
2262 u32 data_in_size,
2263 u32 block_size,
2264 u32 tail_block_size,
2265 bool isapplet,
2266 bool is_kva)
2267{
2268 int error = 0;
2269 /* Size of tail */
2270 u32 tail_size = 0;
2271 /* Address of the created DCB table */
2272 struct sep_dcblock *dcb_table_ptr = NULL;
2273 /* The physical address of the first input DMA table */
2274 dma_addr_t in_first_mlli_address = 0;
2275 /* Number of entries in the first input DMA table */
2276 u32 in_first_num_entries = 0;
2277 /* The physical address of the first output DMA table */
2278 dma_addr_t out_first_mlli_address = 0;
2279 /* Number of entries in the first output DMA table */
2280 u32 out_first_num_entries = 0;
2281 /* Data in the first input/output table */
2282 u32 first_data_size = 0;
2283
2284 dev_dbg(&sep->pdev->dev, "prepare_input_output_dma_table_in_dcb start\n");
2285
2286 if (sep->nr_dcb_creat == SEP_MAX_NUM_SYNC_DMA_OPS) {
2287 /* No more DCBs to allocate */
2288 dev_warn(&sep->pdev->dev, "no more DCBs available\n");
2289 error = -ENOSPC;
2290 goto end_function;
2291 }
2292
2293 /* Allocate new DCB */
2294 dcb_table_ptr = (struct sep_dcblock *)(sep->shared_addr +
2295 SEP_DRIVER_SYSTEM_DCB_MEMORY_OFFSET_IN_BYTES +
2296 (sep->nr_dcb_creat * sizeof(struct sep_dcblock)));
2297
2298 /* Set the default values in the DCB */
2299 dcb_table_ptr->input_mlli_address = 0;
2300 dcb_table_ptr->input_mlli_num_entries = 0;
2301 dcb_table_ptr->input_mlli_data_size = 0;
2302 dcb_table_ptr->output_mlli_address = 0;
2303 dcb_table_ptr->output_mlli_num_entries = 0;
2304 dcb_table_ptr->output_mlli_data_size = 0;
2305 dcb_table_ptr->tail_data_size = 0;
2306 dcb_table_ptr->out_vr_tail_pt = 0;
2307
2308 if (isapplet == true) {
2309 tail_size = data_in_size % block_size;
2310 if (tail_size) {
2311 if (data_in_size < tail_block_size) {
2312 dev_warn(&sep->pdev->dev, "data in size smaller than tail block size\n");
2313 error = -ENOSPC;
2314 goto end_function;
2315 }
2316 if (tail_block_size)
2317 /*
2318 * Case the tail size should be
2319 * bigger than the real block size
2320 */
2321 tail_size = tail_block_size +
2322 ((data_in_size -
2323 tail_block_size) % block_size);
2324 }
2325
2326 /* Check if there is enough data for DMA operation */
2327 if (data_in_size < SEP_DRIVER_MIN_DATA_SIZE_PER_TABLE) {
2328 if (is_kva == true) {
2329 memcpy(dcb_table_ptr->tail_data,
2330 (void *)app_in_address, data_in_size);
2331 } else {
2332 if (copy_from_user(dcb_table_ptr->tail_data,
2333 (void __user *)app_in_address,
2334 data_in_size)) {
2335 error = -EFAULT;
2336 goto end_function;
2337 }
2338 }
2339
2340 dcb_table_ptr->tail_data_size = data_in_size;
2341
2342 /* Set the output user-space address for mem2mem op */
2343 if (app_out_address)
2344 dcb_table_ptr->out_vr_tail_pt =
2345 (u32)app_out_address;
2346
2347 /*
2348 * Update both data length parameters in order to avoid
2349 * second data copy and allow building of empty mlli
2350 * tables
2351 */
2352 tail_size = 0x0;
2353 data_in_size = 0x0;
2354 }
2355 if (tail_size) {
2356 if (is_kva == true) {
2357 memcpy(dcb_table_ptr->tail_data,
2358 (void *)(app_in_address + data_in_size -
2359 tail_size), tail_size);
2360 } else {
2361 /* We have tail data - copy it to DCB */
2362 if (copy_from_user(dcb_table_ptr->tail_data,
2363 (void *)(app_in_address +
2364 data_in_size - tail_size), tail_size)) {
2365 error = -EFAULT;
2366 goto end_function;
2367 }
2368 }
2369 if (app_out_address)
2370 /*
2371 * Calculate the output address
2372 * according to tail data size
2373 */
2374 dcb_table_ptr->out_vr_tail_pt =
2375 (u32)app_out_address + data_in_size
2376 - tail_size;
2377
2378 /* Save the real tail data size */
2379 dcb_table_ptr->tail_data_size = tail_size;
2380 /*
2381 * Update the data size without the tail
2382 * data size AKA data for the dma
2383 */
2384 data_in_size = (data_in_size - tail_size);
2385 }
2386 }
2387 /* Check if we need to build only input table or input/output */
2388 if (app_out_address) {
2389 /* Prepare input/output tables */
2390 error = sep_prepare_input_output_dma_table(sep,
2391 app_in_address,
2392 app_out_address,
2393 data_in_size,
2394 block_size,
2395 &in_first_mlli_address,
2396 &out_first_mlli_address,
2397 &in_first_num_entries,
2398 &out_first_num_entries,
2399 &first_data_size,
2400 is_kva);
2401 } else {
2402 /* Prepare input tables */
2403 error = sep_prepare_input_dma_table(sep,
2404 app_in_address,
2405 data_in_size,
2406 block_size,
2407 &in_first_mlli_address,
2408 &in_first_num_entries,
2409 &first_data_size,
2410 is_kva);
2411 }
2412
2413 if (error) {
2414 dev_warn(&sep->pdev->dev, "prepare DMA table call failed from prepare DCB call\n");
2415 goto end_function;
2416 }
2417
2418 /* Set the DCB values */
2419 dcb_table_ptr->input_mlli_address = in_first_mlli_address;
2420 dcb_table_ptr->input_mlli_num_entries = in_first_num_entries;
2421 dcb_table_ptr->input_mlli_data_size = first_data_size;
2422 dcb_table_ptr->output_mlli_address = out_first_mlli_address;
2423 dcb_table_ptr->output_mlli_num_entries = out_first_num_entries;
2424 dcb_table_ptr->output_mlli_data_size = first_data_size;
2425
2426end_function:
2427 dev_dbg(&sep->pdev->dev,
2428 "sep_prepare_input_output_dma_table_in_dcb end\n");
2429 return error;
2430
2431}
2432
2433
2434/**
2435 * sep_create_sync_dma_tables_handler - create sync DMA tables
2436 * @sep: pointer to struct sep_device
2437 * @arg: pointer to struct bld_syn_tab_struct
2438 *
2439 * Handle the request for creation of the DMA tables for the synchronic
2440 * symmetric operations (AES,DES). Note that all bus addresses that are
2441 * passed to the SEP are in 32 bit format; the SEP is a 32 bit device
2442 */
2443static int sep_create_sync_dma_tables_handler(struct sep_device *sep,
2444 unsigned long arg)
2445{
2446 int error = 0;
2447
2448 /* Command arguments */
2449 struct bld_syn_tab_struct command_args;
2450
2451 dev_dbg(&sep->pdev->dev,
2452 "sep_create_sync_dma_tables_handler start\n");
2453
2454 if (copy_from_user(&command_args, (void __user *)arg,
2455 sizeof(struct bld_syn_tab_struct))) {
2456 error = -EFAULT;
2457 goto end_function;
2458 }
2459
2460 dev_dbg(&sep->pdev->dev, "app_in_address is %08llx\n",
2461 command_args.app_in_address);
2462 dev_dbg(&sep->pdev->dev, "app_out_address is %08llx\n",
2463 command_args.app_out_address);
2464 dev_dbg(&sep->pdev->dev, "data_size is %u\n",
2465 command_args.data_in_size);
2466 dev_dbg(&sep->pdev->dev, "block_size is %u\n",
2467 command_args.block_size);
2468
2469 /* Validate user parameters */
2470 if (!command_args.app_in_address) {
2471 error = -EINVAL;
2472 goto end_function;
2473 }
2474
2475 error = sep_prepare_input_output_dma_table_in_dcb(sep,
2476 (unsigned long)command_args.app_in_address,
2477 (unsigned long)command_args.app_out_address,
2478 command_args.data_in_size,
2479 command_args.block_size,
2480 0x0,
2481 false,
2482 false);
2483
2484end_function:
2485 dev_dbg(&sep->pdev->dev, "sep_create_sync_dma_tables_handler end\n");
2486 return error;
2487}
2488
2489/**
2490 * sep_free_dma_tables_and_dcb - free DMA tables and DCBs
2491 * @sep: pointer to struct sep_device
2492 * @isapplet: indicates external application (used for kernel access)
2493 * @is_kva: indicates kernel addresses (only used for kernel crypto)
2494 *
2495 * This function frees the DMA tables and DCB
2496 */
2497static int sep_free_dma_tables_and_dcb(struct sep_device *sep, bool isapplet,
2498 bool is_kva)
2499{
2500 int i = 0;
2501 int error = 0;
2502 int error_temp = 0;
2503 struct sep_dcblock *dcb_table_ptr;
2504 unsigned long pt_hold;
2505 void *tail_pt;
2506
2507 dev_dbg(&sep->pdev->dev, "sep_free_dma_tables_and_dcb start\n");
2508
2509 if (isapplet == true) {
2510 /* Set pointer to first DCB table */
2511 dcb_table_ptr = (struct sep_dcblock *)
2512 (sep->shared_addr +
2513 SEP_DRIVER_SYSTEM_DCB_MEMORY_OFFSET_IN_BYTES);
2514
2515 /* Go over each DCB and see if tail pointer must be updated */
2516 for (i = 0; i < sep->nr_dcb_creat; i++, dcb_table_ptr++) {
2517 if (dcb_table_ptr->out_vr_tail_pt) {
2518 pt_hold = (unsigned long)dcb_table_ptr->out_vr_tail_pt;
2519 tail_pt = (void *)pt_hold;
2520 if (is_kva == true) {
2521 memcpy(tail_pt,
2522 dcb_table_ptr->tail_data,
2523 dcb_table_ptr->tail_data_size);
2524 } else {
2525 error_temp = copy_to_user(
2526 tail_pt,
2527 dcb_table_ptr->tail_data,
2528 dcb_table_ptr->tail_data_size);
2529 }
2530 if (error_temp) {
2531 /* Release the DMA resource */
2532 error = -EFAULT;
2533 break;
2534 }
2535 }
2536 }
2537 }
2538 /* Free the output pages, if any */
2539 sep_free_dma_table_data_handler(sep);
2540
2541 dev_dbg(&sep->pdev->dev, "sep_free_dma_tables_and_dcb end\n");
2542 return error;
2543}
2544
2545/**
2546 * sep_get_static_pool_addr_handler - get static pool address
2547 * @sep: pointer to struct sep_device
2548 *
2549 * This function sets the bus and virtual addresses of the static pool
2550 */
2551static int sep_get_static_pool_addr_handler(struct sep_device *sep)
2552{
2553 u32 *static_pool_addr = NULL;
2554
2555 dev_dbg(&sep->pdev->dev, "sep_get_static_pool_addr_handler start\n");
2556
2557 static_pool_addr = (u32 *)(sep->shared_addr +
2558 SEP_DRIVER_SYSTEM_RAR_MEMORY_OFFSET_IN_BYTES);
2559
2560 static_pool_addr[0] = SEP_STATIC_POOL_VAL_TOKEN;
2561 static_pool_addr[1] = (u32)sep->shared_bus +
2562 SEP_DRIVER_STATIC_AREA_OFFSET_IN_BYTES;
2563
2564 dev_dbg(&sep->pdev->dev, "static pool: physical %x\n",
2565 (u32)static_pool_addr[1]);
2566
2567 dev_dbg(&sep->pdev->dev, "sep_get_static_pool_addr_handler end\n");
2568
2569 return 0;
2570}
2571
2572/**
2573 * sep_start_handler - start device
2574 * @sep: pointer to struct sep_device
2575 */
2576static int sep_start_handler(struct sep_device *sep)
2577{
2578 unsigned long reg_val;
2579 unsigned long error = 0;
2580
2581 dev_dbg(&sep->pdev->dev, "sep_start_handler start\n");
2582
2583 /* Wait in polling for message from SEP */
2584 do {
2585 reg_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR);
2586 } while (!reg_val);
2587
2588 /* Check the value */
2589 if (reg_val == 0x1)
2590 /* Fatal error - read error status from GPRO */
2591 error = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR0_REG_ADDR);
2592 dev_dbg(&sep->pdev->dev, "sep_start_handler end\n");
2593 return error;
2594}
2595
2596/**
2597 * ep_check_sum_calc - checksum messages
2598 * @data: buffer to checksum
2599 * @length: buffer size
2600 *
2601 * This function performs a checksum for messages that are sent
2602 * to the SEP.
2603 */
2604static u32 sep_check_sum_calc(u8 *data, u32 length)
2605{
2606 u32 sum = 0;
2607 u16 *Tdata = (u16 *)data;
2608
2609 while (length > 1) {
2610 /* This is the inner loop */
2611 sum += *Tdata++;
2612 length -= 2;
2613 }
2614
2615 /* Add left-over byte, if any */
2616 if (length > 0)
2617 sum += *(u8 *)Tdata;
2618
2619 /* Fold 32-bit sum to 16 bits */
2620 while (sum>>16)
2621 sum = (sum & 0xffff) + (sum >> 16);
2622
2623 return ~sum & 0xFFFF;
2624}
2625
2626/**
2627 * sep_init_handler -
2628 * @sep: pointer to struct sep_device
2629 * @arg: parameters from user space application
2630 *
2631 * Handles the request for SEP initialization
2632 * Note that this will go away for Medfield once the SCU
2633 * SEP initialization is complete
2634 * Also note that the message to the SEP has components
2635 * from user space as well as components written by the driver
2636 * This is becuase the portions of the message that pertain to
2637 * physical addresses must be set by the driver after the message
2638 * leaves custody of the user space application for security
2639 * reasons.
2640 */
2641static int sep_init_handler(struct sep_device *sep, unsigned long arg)
2642{
2643 u32 message_buff[14];
2644 u32 counter;
2645 int error = 0;
2646 u32 reg_val;
2647 dma_addr_t new_base_addr;
2648 unsigned long addr_hold;
2649 struct init_struct command_args;
2650
2651 dev_dbg(&sep->pdev->dev, "sep_init_handler start\n");
2652
2653 /* Make sure that we have not initialized already */
2654 reg_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR);
2655
2656 if (reg_val != 0x2) {
2657 error = SEP_ALREADY_INITIALIZED_ERR;
2658 dev_warn(&sep->pdev->dev, "init; device already initialized\n");
2659 goto end_function;
2660 }
2661
2662 /* Only root can initialize */
2663 if (!capable(CAP_SYS_ADMIN)) {
2664 error = -EACCES;
2665 goto end_function;
2666 }
2667
2668 /* Copy in the parameters */
2669 error = copy_from_user(&command_args, (void __user *)arg,
2670 sizeof(struct init_struct));
2671
2672 if (error) {
2673 error = -EFAULT;
2674 goto end_function;
2675 }
2676
2677 /* Validate parameters */
2678 if (!command_args.message_addr || !command_args.sep_sram_addr ||
2679 command_args.message_size_in_words > 14) {
2680 error = -EINVAL;
2681 goto end_function;
2682 }
2683
2684 /* Copy in the SEP init message */
2685 addr_hold = (unsigned long)command_args.message_addr;
2686 error = copy_from_user(message_buff,
2687 (void __user *)addr_hold,
2688 command_args.message_size_in_words*sizeof(u32));
2689
2690 if (error) {
2691 error = -EFAULT;
2692 goto end_function;
2693 }
2694
2695 /* Load resident, cache, and extapp firmware */
2696 error = sep_load_firmware(sep);
2697
2698 if (error) {
2699 dev_warn(&sep->pdev->dev,
2700 "init; copy SEP init message failed %x\n", error);
2701 goto end_function;
2702 }
2703
2704 /* Compute the base address */
2705 new_base_addr = sep->shared_bus;
2706
2707 if (sep->resident_bus < new_base_addr)
2708 new_base_addr = sep->resident_bus;
2709
2710 if (sep->cache_bus < new_base_addr)
2711 new_base_addr = sep->cache_bus;
2712
2713 if (sep->dcache_bus < new_base_addr)
2714 new_base_addr = sep->dcache_bus;
2715
2716 /* Put physical addresses in SEP message */
2717 message_buff[3] = (u32)new_base_addr;
2718 message_buff[4] = (u32)sep->shared_bus;
2719 message_buff[6] = (u32)sep->resident_bus;
2720 message_buff[7] = (u32)sep->cache_bus;
2721 message_buff[8] = (u32)sep->dcache_bus;
2722
2723 message_buff[command_args.message_size_in_words - 1] = 0x0;
2724 message_buff[command_args.message_size_in_words - 1] =
2725 sep_check_sum_calc((u8 *)message_buff,
2726 command_args.message_size_in_words*sizeof(u32));
2727
2728 /* Debug print of message */
2729 for (counter = 0; counter < command_args.message_size_in_words;
2730 counter++)
2731 dev_dbg(&sep->pdev->dev, "init; SEP message word %d is %x\n",
2732 counter, message_buff[counter]);
2733
2734 /* Tell the SEP the sram address */
2735 sep_write_reg(sep, HW_SRAM_ADDR_REG_ADDR, command_args.sep_sram_addr);
2736
2737 /* Push the message to the SEP */
2738 for (counter = 0; counter < command_args.message_size_in_words;
2739 counter++) {
2740 sep_write_reg(sep, HW_SRAM_DATA_REG_ADDR,
2741 message_buff[counter]);
2742 sep_wait_sram_write(sep);
2743 }
2744
2745 /* Signal SEP that message is ready and to init */
2746 sep_write_reg(sep, HW_HOST_HOST_SEP_GPR0_REG_ADDR, 0x1);
2747
2748 /* Wait for acknowledge */
2749 dev_dbg(&sep->pdev->dev, "init; waiting for msg response\n");
2750
2751 do {
2752 reg_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR);
2753 } while (!(reg_val & 0xFFFFFFFD));
2754
2755 if (reg_val == 0x1) {
2756 dev_warn(&sep->pdev->dev, "init; device int failed\n");
2757 error = sep_read_reg(sep, 0x8060);
2758 dev_warn(&sep->pdev->dev, "init; sw monitor is %x\n", error);
2759 error = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR0_REG_ADDR);
2760 dev_warn(&sep->pdev->dev, "init; error is %x\n", error);
2761 goto end_function;
2762 }
2763 dev_dbg(&sep->pdev->dev, "init; end CC INIT, reg_val is %x\n", reg_val);
2764
2765 /* Signal SEP to zero the GPR3 */
2766 sep_write_reg(sep, HW_HOST_HOST_SEP_GPR0_REG_ADDR, 0x10);
2767
2768 /* Wait for response */
2769 dev_dbg(&sep->pdev->dev, "init; waiting for zero set response\n");
2770
2771 do {
2772 reg_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR3_REG_ADDR);
2773 } while (reg_val != 0);
2774
2775end_function:
2776 dev_dbg(&sep->pdev->dev, "init is done\n");
2777 return error;
2778}
2779
2780/**
2781 * sep_end_transaction_handler - end transaction
2782 * @sep: pointer to struct sep_device
2783 *
2784 * This API handles the end transaction request
2785 */
2786static int sep_end_transaction_handler(struct sep_device *sep)
2787{
2788 dev_dbg(&sep->pdev->dev, "sep_end_transaction_handler start\n");
2789
2790 /* Clear the data pool pointers Token */
2791 memset((void *)(sep->shared_addr +
2792 SEP_DRIVER_DATA_POOL_ALLOCATION_OFFSET_IN_BYTES),
2793 0, sep->num_of_data_allocations*2*sizeof(u32));
2794
2795 /* Check that all the DMA resources were freed */
2796 sep_free_dma_table_data_handler(sep);
2797
2798 clear_bit(SEP_MMAP_LOCK_BIT, &sep->in_use_flags);
2799
2800 /*
2801 * We are now through with the transaction. Let's
2802 * allow other processes who have the device open
2803 * to perform transactions
2804 */
2805 mutex_lock(&sep->sep_mutex);
2806 sep->pid_doing_transaction = 0;
2807 mutex_unlock(&sep->sep_mutex);
2808 /* Raise event for stuck contextes */
2809 wake_up(&sep->event);
2810
2811 dev_dbg(&sep->pdev->dev, "waking up event\n");
2812 dev_dbg(&sep->pdev->dev, "sep_end_transaction_handler end\n");
2813
2814 return 0;
2815}
2816
2817/**
2818 * sep_prepare_dcb_handler - prepare a control block
2819 * @sep: pointer to struct sep_device
2820 * @arg: pointer to user parameters
2821 *
2822 * This function will retrieve the RAR buffer physical addresses, type
2823 * & size corresponding to the RAR handles provided in the buffers vector.
2824 */
2825static int sep_prepare_dcb_handler(struct sep_device *sep, unsigned long arg)
2826{
2827 int error;
2828 /* Command arguments */
2829 struct build_dcb_struct command_args;
2830
2831 dev_dbg(&sep->pdev->dev, "sep_prepare_dcb_handler start\n");
2832
2833 /* Get the command arguments */
2834 if (copy_from_user(&command_args, (void __user *)arg,
2835 sizeof(struct build_dcb_struct))) {
2836 error = -EFAULT;
2837 goto end_function;
2838 }
2839
2840 dev_dbg(&sep->pdev->dev, "app_in_address is %08llx\n",
2841 command_args.app_in_address);
2842 dev_dbg(&sep->pdev->dev, "app_out_address is %08llx\n",
2843 command_args.app_out_address);
2844 dev_dbg(&sep->pdev->dev, "data_size is %x\n",
2845 command_args.data_in_size);
2846 dev_dbg(&sep->pdev->dev, "block_size is %x\n",
2847 command_args.block_size);
2848 dev_dbg(&sep->pdev->dev, "tail block_size is %x\n",
2849 command_args.tail_block_size);
2850
2851 error = sep_prepare_input_output_dma_table_in_dcb(sep,
2852 (unsigned long)command_args.app_in_address,
2853 (unsigned long)command_args.app_out_address,
2854 command_args.data_in_size, command_args.block_size,
2855 command_args.tail_block_size, true, false);
2856
2857end_function:
2858 dev_dbg(&sep->pdev->dev, "sep_prepare_dcb_handler end\n");
2859 return error;
2860
2861}
2862
2863/**
2864 * sep_free_dcb_handler - free control block resources
2865 * @sep: pointer to struct sep_device
2866 *
2867 * This function frees the DCB resources and updates the needed
2868 * user-space buffers.
2869 */
2870static int sep_free_dcb_handler(struct sep_device *sep)
2871{
2872 int error ;
2873
2874 dev_dbg(&sep->pdev->dev, "sep_prepare_dcb_handler start\n");
2875 dev_dbg(&sep->pdev->dev, "num of DCBs %x\n", sep->nr_dcb_creat);
2876
2877 error = sep_free_dma_tables_and_dcb(sep, false, false);
2878
2879 dev_dbg(&sep->pdev->dev, "sep_free_dcb_handler end\n");
2880 return error;
2881}
2882
2883/**
2884 * sep_rar_prepare_output_msg_handler - prepare an output message
2885 * @sep: pointer to struct sep_device
2886 * @arg: pointer to user parameters
2887 *
2888 * This function will retrieve the RAR buffer physical addresses, type
2889 * & size corresponding to the RAR handles provided in the buffers vector.
2890 */
2891static int sep_rar_prepare_output_msg_handler(struct sep_device *sep,
2892 unsigned long arg)
2893{
2894 int error = 0;
2895 /* Command args */
2896 struct rar_hndl_to_bus_struct command_args;
2897 struct RAR_buffer rar_buf;
2898 /* Bus address */
2899 dma_addr_t rar_bus = 0;
2900 /* Holds the RAR address in the system memory offset */
2901 u32 *rar_addr;
2902
2903 dev_dbg(&sep->pdev->dev, "sep_rar_prepare_output_msg_handler start\n");
2904
2905 /* Copy the data */
2906 if (copy_from_user(&command_args, (void __user *)arg,
2907 sizeof(command_args))) {
2908 error = -EFAULT;
2909 goto end_function;
2910 }
2911
2912 /* Call to translation function only if user handle is not NULL */
2913 if (command_args.rar_handle) {
2914 memset(&rar_buf, 0, sizeof(rar_buf));
2915 rar_buf.info.handle = (u32)command_args.rar_handle;
2916
2917 if (rar_handle_to_bus(&rar_buf, 1) != 1) {
2918 dev_dbg(&sep->pdev->dev, "rar_handle_to_bus failure\n");
2919 error = -EFAULT;
2920 goto end_function;
2921 }
2922 rar_bus = rar_buf.bus_address;
2923 }
2924 dev_dbg(&sep->pdev->dev, "rar msg; rar_addr_bus = %x\n", (u32)rar_bus);
2925
2926 /* Set value in the SYSTEM MEMORY offset */
2927 rar_addr = (u32 *)(sep->shared_addr +
2928 SEP_DRIVER_SYSTEM_RAR_MEMORY_OFFSET_IN_BYTES);
2929
2930 /* Copy the physical address to the System Area for the SEP */
2931 rar_addr[0] = SEP_RAR_VAL_TOKEN;
2932 rar_addr[1] = rar_bus;
2933
2934end_function:
2935 dev_dbg(&sep->pdev->dev, "sep_rar_prepare_output_msg_handler start\n");
2936 return error;
2937}
2938
2939/**
2940 * sep_realloc_ext_cache_handler - report location of extcache
2941 * @sep: pointer to struct sep_device
2942 * @arg: pointer to user parameters
2943 *
2944 * This function tells the SEP where the extapp is located
2945 */
2946static int sep_realloc_ext_cache_handler(struct sep_device *sep,
2947 unsigned long arg)
2948{
2949 /* Holds the new ext cache address in the system memory offset */
2950 u32 *system_addr;
2951
2952 /* Set value in the SYSTEM MEMORY offset */
2953 system_addr = (u32 *)(sep->shared_addr +
2954 SEP_DRIVER_SYSTEM_EXT_CACHE_ADDR_OFFSET_IN_BYTES);
2955
2956 /* Copy the physical address to the System Area for the SEP */
2957 system_addr[0] = SEP_EXT_CACHE_ADDR_VAL_TOKEN;
2958 dev_dbg(&sep->pdev->dev, "ext cache init; system addr 0 is %x\n",
2959 system_addr[0]);
2960 system_addr[1] = sep->extapp_bus;
2961 dev_dbg(&sep->pdev->dev, "ext cache init; system addr 1 is %x\n",
2962 system_addr[1]);
2963
2964 return 0;
2965}
2966
2967/**
2968 * sep_ioctl - ioctl api
2969 * @filp: pointer to struct file
2970 * @cmd: command
2971 * @arg: pointer to argument structure
2972 *
2973 * Implement the ioctl methods availble on the SEP device.
2974 */
2975static long sep_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2976{
2977 int error = 0;
2978 struct sep_device *sep = filp->private_data;
2979
2980 dev_dbg(&sep->pdev->dev, "ioctl start\n");
2981
2982 dev_dbg(&sep->pdev->dev, "cmd is %x\n", cmd);
2983
2984 /* Make sure we own this device */
2985 mutex_lock(&sep->sep_mutex);
2986 if ((current->pid != sep->pid_doing_transaction) &&
2987 (sep->pid_doing_transaction != 0)) {
2988 dev_dbg(&sep->pdev->dev, "ioctl pid is not owner\n");
2989 mutex_unlock(&sep->sep_mutex);
2990 error = -EACCES;
2991 goto end_function;
2992 }
2993
2994 mutex_unlock(&sep->sep_mutex);
2995
2996 /* Check that the command is for SEP device */
2997 if (_IOC_TYPE(cmd) != SEP_IOC_MAGIC_NUMBER) {
2998 error = -ENOTTY;
2999 goto end_function;
3000 }
3001
3002 /* Lock to prevent the daemon to interfere with operation */
3003 mutex_lock(&sep->ioctl_mutex);
3004
3005 switch (cmd) {
3006 case SEP_IOCSENDSEPCOMMAND:
3007 /* Send command to SEP */
3008 error = sep_send_command_handler(sep);
3009 break;
3010 case SEP_IOCALLOCDATAPOLL:
3011 /* Allocate data pool */
3012 error = sep_allocate_data_pool_memory_handler(sep, arg);
3013 break;
3014 case SEP_IOCCREATESYMDMATABLE:
3015 /* Create DMA table for synhronic operation */
3016 error = sep_create_sync_dma_tables_handler(sep, arg);
3017 break;
3018 case SEP_IOCFREEDMATABLEDATA:
3019 /* Free the pages */
3020 error = sep_free_dma_table_data_handler(sep);
3021 break;
3022 case SEP_IOCSEPSTART:
3023 /* Start command to SEP */
3024 if (sep->pdev->revision == 0) /* Only for old chip */
3025 error = sep_start_handler(sep);
3026 else
3027 error = -EPERM; /* Not permitted on new chip */
3028 break;
3029 case SEP_IOCSEPINIT:
3030 /* Init command to SEP */
3031 if (sep->pdev->revision == 0) /* Only for old chip */
3032 error = sep_init_handler(sep, arg);
3033 else
3034 error = -EPERM; /* Not permitted on new chip */
3035 break;
3036 case SEP_IOCGETSTATICPOOLADDR:
3037 /* Inform the SEP the bus address of the static pool */
3038 error = sep_get_static_pool_addr_handler(sep);
3039 break;
3040 case SEP_IOCENDTRANSACTION:
3041 error = sep_end_transaction_handler(sep);
3042 break;
3043 case SEP_IOCREALLOCEXTCACHE:
3044 if (sep->pdev->revision == 0) /* Only for old chip */
3045 error = sep_realloc_ext_cache_handler(sep, arg);
3046 else
3047 error = -EPERM; /* Not permitted on new chip */
3048 break;
3049 case SEP_IOCRARPREPAREMESSAGE:
3050 error = sep_rar_prepare_output_msg_handler(sep, arg);
3051 break;
3052 case SEP_IOCPREPAREDCB:
3053 error = sep_prepare_dcb_handler(sep, arg);
3054 break;
3055 case SEP_IOCFREEDCB:
3056 error = sep_free_dcb_handler(sep);
3057 break;
3058 default:
3059 dev_dbg(&sep->pdev->dev, "invalid ioctl %x\n", cmd);
3060 error = -ENOTTY;
3061 break;
3062 }
3063 mutex_unlock(&sep->ioctl_mutex);
3064
3065end_function:
3066 dev_dbg(&sep->pdev->dev, "ioctl end\n");
3067 return error;
3068}
3069
3070/**
3071 * sep_singleton_ioctl - ioctl api for singleton interface
3072 * @filp: pointer to struct file
3073 * @cmd: command
3074 * @arg: pointer to argument structure
3075 *
3076 * Implement the additional ioctls for the singleton device
3077 */
3078static long sep_singleton_ioctl(struct file *filp, u32 cmd, unsigned long arg)
3079{
3080 long error = 0;
3081 struct sep_device *sep = filp->private_data;
3082
3083 dev_dbg(&sep->pdev->dev, "singleton_ioctl start\n");
3084 dev_dbg(&sep->pdev->dev, "cmd is %x\n", cmd);
3085
3086 /* Check that the command is for the SEP device */
3087 if (_IOC_TYPE(cmd) != SEP_IOC_MAGIC_NUMBER) {
3088 error = -ENOTTY;
3089 goto end_function;
3090 }
3091
3092 /* Make sure we own this device */
3093 mutex_lock(&sep->sep_mutex);
3094 if ((current->pid != sep->pid_doing_transaction) &&
3095 (sep->pid_doing_transaction != 0)) {
3096 dev_dbg(&sep->pdev->dev, "singleton ioctl pid is not owner\n");
3097 mutex_unlock(&sep->sep_mutex);
3098 error = -EACCES;
3099 goto end_function;
3100 }
3101
3102 mutex_unlock(&sep->sep_mutex);
3103
3104 switch (cmd) {
3105 case SEP_IOCTLSETCALLERID:
3106 mutex_lock(&sep->ioctl_mutex);
3107 error = sep_set_caller_id_handler(sep, arg);
3108 mutex_unlock(&sep->ioctl_mutex);
3109 break;
3110 default:
3111 error = sep_ioctl(filp, cmd, arg);
3112 break;
3113 }
3114
3115end_function:
3116 dev_dbg(&sep->pdev->dev, "singleton ioctl end\n");
3117 return error;
3118}
3119
3120/**
3121 * sep_request_daemon_ioctl - ioctl for daemon
3122 * @filp: pointer to struct file
3123 * @cmd: command
3124 * @arg: pointer to argument structure
3125 *
3126 * Called by the request daemon to perform ioctls on the daemon device
3127 */
3128static long sep_request_daemon_ioctl(struct file *filp, u32 cmd,
3129 unsigned long arg)
3130{
3131
3132 long error;
3133 struct sep_device *sep = filp->private_data;
3134
3135 dev_dbg(&sep->pdev->dev, "daemon ioctl: start\n");
3136 dev_dbg(&sep->pdev->dev, "daemon ioctl: cmd is %x\n", cmd);
3137
3138 /* Check that the command is for SEP device */
3139 if (_IOC_TYPE(cmd) != SEP_IOC_MAGIC_NUMBER) {
3140 error = -ENOTTY;
3141 goto end_function;
3142 }
3143
3144 /* Only one process can access ioctl at any given time */
3145 mutex_lock(&sep->ioctl_mutex);
3146
3147 switch (cmd) {
3148 case SEP_IOCSENDSEPRPLYCOMMAND:
3149 /* Send reply command to SEP */
3150 error = sep_req_daemon_send_reply_command_handler(sep);
3151 break;
3152 case SEP_IOCENDTRANSACTION:
3153 /*
3154 * End req daemon transaction, do nothing
3155 * will be removed upon update in middleware
3156 * API library
3157 */
3158 error = 0;
3159 break;
3160 default:
3161 dev_dbg(&sep->pdev->dev, "daemon ioctl: no such IOCTL\n");
3162 error = -ENOTTY;
3163 }
3164 mutex_unlock(&sep->ioctl_mutex);
3165
3166end_function:
3167 dev_dbg(&sep->pdev->dev, "daemon ioctl: end\n");
3168 return error;
3169
3170}
3171
3172/**
3173 * sep_inthandler - interrupt handler
3174 * @irq: interrupt
3175 * @dev_id: device id
3176 */
3177static irqreturn_t sep_inthandler(int irq, void *dev_id)
3178{
3179 irqreturn_t int_error = IRQ_HANDLED;
3180 unsigned long lck_flags;
3181 u32 reg_val, reg_val2 = 0;
3182 struct sep_device *sep = dev_id;
3183
3184 /* Read the IRR register to check if this is SEP interrupt */
3185 reg_val = sep_read_reg(sep, HW_HOST_IRR_REG_ADDR);
3186 dev_dbg(&sep->pdev->dev, "SEP Interrupt - reg is %08x\n", reg_val);
3187
3188 if (reg_val & (0x1 << 13)) {
3189 /* Lock and update the counter of reply messages */
3190 spin_lock_irqsave(&sep->snd_rply_lck, lck_flags);
3191 sep->reply_ct++;
3192 spin_unlock_irqrestore(&sep->snd_rply_lck, lck_flags);
3193
3194 dev_dbg(&sep->pdev->dev, "sep int: send_ct %lx reply_ct %lx\n",
3195 sep->send_ct, sep->reply_ct);
3196
3197 /* Is this printf or daemon request? */
3198 reg_val2 = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR2_REG_ADDR);
3199 dev_dbg(&sep->pdev->dev,
3200 "SEP Interrupt - reg2 is %08x\n", reg_val2);
3201
3202 if ((reg_val2 >> 30) & 0x1) {
3203 dev_dbg(&sep->pdev->dev, "int: printf request\n");
3204 wake_up(&sep->event_request_daemon);
3205 } else if (reg_val2 >> 31) {
3206 dev_dbg(&sep->pdev->dev, "int: daemon request\n");
3207 wake_up(&sep->event_request_daemon);
3208 } else {
3209 dev_dbg(&sep->pdev->dev, "int: SEP reply\n");
3210 wake_up(&sep->event);
3211 }
3212 } else {
3213 dev_dbg(&sep->pdev->dev, "int: not SEP interrupt\n");
3214 int_error = IRQ_NONE;
3215 }
3216 if (int_error == IRQ_HANDLED)
3217 sep_write_reg(sep, HW_HOST_ICR_REG_ADDR, reg_val);
3218
3219 return int_error;
3220}
3221
3222/**
3223 * sep_reconfig_shared_area - reconfigure shared area
3224 * @sep: pointer to struct sep_device
3225 *
3226 * Reconfig the shared area between HOST and SEP - needed in case
3227 * the DX_CC_Init function was called before OS loading.
3228 */
3229static int sep_reconfig_shared_area(struct sep_device *sep)
3230{
3231 int ret_val;
3232
3233 /* use to limit waiting for SEP */
3234 unsigned long end_time;
3235
3236 dev_dbg(&sep->pdev->dev, "reconfig shared area start\n");
3237
3238 /* Send the new SHARED MESSAGE AREA to the SEP */
3239 dev_dbg(&sep->pdev->dev, "sending %08llx to sep\n",
3240 (unsigned long long)sep->shared_bus);
3241
3242 sep_write_reg(sep, HW_HOST_HOST_SEP_GPR1_REG_ADDR, sep->shared_bus);
3243
3244 /* Poll for SEP response */
3245 ret_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR1_REG_ADDR);
3246
3247 end_time = jiffies + (WAIT_TIME * HZ);
3248
3249 while ((time_before(jiffies, end_time)) && (ret_val != 0xffffffff) &&
3250 (ret_val != sep->shared_bus))
3251 ret_val = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR1_REG_ADDR);
3252
3253 /* Check the return value (register) */
3254 if (ret_val != sep->shared_bus) {
3255 dev_warn(&sep->pdev->dev, "could not reconfig shared area\n");
3256 dev_warn(&sep->pdev->dev, "result was %x\n", ret_val);
3257 ret_val = -ENOMEM;
3258 } else
3259 ret_val = 0;
3260
3261 dev_dbg(&sep->pdev->dev, "reconfig shared area end\n");
3262 return ret_val;
3263}
3264
3265/* File operation for singleton SEP operations */
3266static const struct file_operations singleton_file_operations = {
3267 .owner = THIS_MODULE,
3268 .unlocked_ioctl = sep_singleton_ioctl,
3269 .poll = sep_poll,
3270 .open = sep_singleton_open,
3271 .release = sep_singleton_release,
3272 .mmap = sep_mmap,
3273};
3274
3275/* File operation for daemon operations */
3276static const struct file_operations daemon_file_operations = {
3277 .owner = THIS_MODULE,
3278 .unlocked_ioctl = sep_request_daemon_ioctl,
3279 .poll = sep_request_daemon_poll,
3280 .open = sep_request_daemon_open,
3281 .release = sep_request_daemon_release,
3282 .mmap = sep_request_daemon_mmap,
3283};
3284
3285/* The files operations structure of the driver */
3286static const struct file_operations sep_file_operations = {
3287 .owner = THIS_MODULE,
3288 .unlocked_ioctl = sep_ioctl,
3289 .poll = sep_poll,
3290 .open = sep_open,
3291 .release = sep_release,
3292 .mmap = sep_mmap,
3293};
3294
3295/**
3296 * sep_register_driver_with_fs - register misc devices
3297 * @sep: pointer to struct sep_device
3298 *
3299 * This function registers the driver with the file system
3300 */
3301static int sep_register_driver_with_fs(struct sep_device *sep)
3302{
3303 int ret_val;
3304
3305 sep->miscdev_sep.minor = MISC_DYNAMIC_MINOR;
3306 sep->miscdev_sep.name = SEP_DEV_NAME;
3307 sep->miscdev_sep.fops = &sep_file_operations;
3308
3309 sep->miscdev_singleton.minor = MISC_DYNAMIC_MINOR;
3310 sep->miscdev_singleton.name = SEP_DEV_SINGLETON;
3311 sep->miscdev_singleton.fops = &singleton_file_operations;
3312
3313 sep->miscdev_daemon.minor = MISC_DYNAMIC_MINOR;
3314 sep->miscdev_daemon.name = SEP_DEV_DAEMON;
3315 sep->miscdev_daemon.fops = &daemon_file_operations;
3316
3317 ret_val = misc_register(&sep->miscdev_sep);
3318 if (ret_val) {
3319 dev_warn(&sep->pdev->dev, "misc reg fails for SEP %x\n",
3320 ret_val);
3321 return ret_val;
3322 }
3323
3324 ret_val = misc_register(&sep->miscdev_singleton);
3325 if (ret_val) {
3326 dev_warn(&sep->pdev->dev, "misc reg fails for sing %x\n",
3327 ret_val);
3328 misc_deregister(&sep->miscdev_sep);
3329 return ret_val;
3330 }
3331
3332 ret_val = misc_register(&sep->miscdev_daemon);
3333 if (ret_val) {
3334 dev_warn(&sep->pdev->dev, "misc reg fails for dmn %x\n",
3335 ret_val);
3336 misc_deregister(&sep->miscdev_sep);
3337 misc_deregister(&sep->miscdev_singleton);
3338
3339 return ret_val;
3340 }
3341 return ret_val;
3342}
3343
3344
3345/**
3346 * sep_probe - probe a matching PCI device
3347 * @pdev: pci_device
3348 * @end: pci_device_id
3349 *
3350 * Attempt to set up and configure a SEP device that has been
3351 * discovered by the PCI layer.
3352 */
3353static int __devinit sep_probe(struct pci_dev *pdev,
3354 const struct pci_device_id *ent)
3355{
3356 int error = 0;
3357 struct sep_device *sep;
3358
3359 pr_debug("SEP pci probe starting\n");
3360 if (sep_dev != NULL) {
3361 dev_warn(&pdev->dev, "only one SEP supported.\n");
3362 return -EBUSY;
3363 }
3364
3365 /* Enable the device */
3366 error = pci_enable_device(pdev);
3367 if (error) {
3368 dev_warn(&pdev->dev, "error enabling pci device\n");
3369 goto end_function;
3370 }
3371
3372 /* Allocate the sep_device structure for this device */
3373 sep_dev = kzalloc(sizeof(struct sep_device), GFP_ATOMIC);
3374 if (sep_dev == NULL) {
3375 dev_warn(&pdev->dev,
3376 "can't kmalloc the sep_device structure\n");
3377 error = -ENOMEM;
3378 goto end_function_disable_device;
3379 }
3380
3381 /*
3382 * We're going to use another variable for actually
3383 * working with the device; this way, if we have
3384 * multiple devices in the future, it would be easier
3385 * to make appropriate changes
3386 */
3387 sep = sep_dev;
3388
3389 sep->pdev = pci_dev_get(pdev);
3390
3391 init_waitqueue_head(&sep->event);
3392 init_waitqueue_head(&sep->event_request_daemon);
3393 spin_lock_init(&sep->snd_rply_lck);
3394 mutex_init(&sep->sep_mutex);
3395 mutex_init(&sep->ioctl_mutex);
3396
3397 dev_dbg(&sep->pdev->dev, "PCI obtained, device being prepared\n");
3398 dev_dbg(&sep->pdev->dev, "revision is %d\n", sep->pdev->revision);
3399
3400 /* Set up our register area */
3401 sep->reg_physical_addr = pci_resource_start(sep->pdev, 0);
3402 if (!sep->reg_physical_addr) {
3403 dev_warn(&sep->pdev->dev, "Error getting register start\n");
3404 error = -ENODEV;
3405 goto end_function_free_sep_dev;
3406 }
3407
3408 sep->reg_physical_end = pci_resource_end(sep->pdev, 0);
3409 if (!sep->reg_physical_end) {
3410 dev_warn(&sep->pdev->dev, "Error getting register end\n");
3411 error = -ENODEV;
3412 goto end_function_free_sep_dev;
3413 }
3414
3415 sep->reg_addr = ioremap_nocache(sep->reg_physical_addr,
3416 (size_t)(sep->reg_physical_end - sep->reg_physical_addr + 1));
3417 if (!sep->reg_addr) {
3418 dev_warn(&sep->pdev->dev, "Error getting register virtual\n");
3419 error = -ENODEV;
3420 goto end_function_free_sep_dev;
3421 }
3422
3423 dev_dbg(&sep->pdev->dev,
3424 "Register area start %llx end %llx virtual %p\n",
3425 (unsigned long long)sep->reg_physical_addr,
3426 (unsigned long long)sep->reg_physical_end,
3427 sep->reg_addr);
3428
3429 /* Allocate the shared area */
3430 sep->shared_size = SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES +
3431 SYNCHRONIC_DMA_TABLES_AREA_SIZE_BYTES +
3432 SEP_DRIVER_DATA_POOL_SHARED_AREA_SIZE_IN_BYTES +
3433 SEP_DRIVER_STATIC_AREA_SIZE_IN_BYTES +
3434 SEP_DRIVER_SYSTEM_DATA_MEMORY_SIZE_IN_BYTES;
3435
3436 if (sep_map_and_alloc_shared_area(sep)) {
3437 error = -ENOMEM;
3438 /* Allocation failed */
3439 goto end_function_error;
3440 }
3441
3442 sep->rar_size = FAKE_RAR_SIZE;
3443 sep->rar_addr = dma_alloc_coherent(&sep->pdev->dev,
3444 sep->rar_size, &sep->rar_bus, GFP_KERNEL);
3445 if (sep->rar_addr == NULL) {
3446 dev_warn(&sep->pdev->dev, "can't allocate mfld rar\n");
3447 error = -ENOMEM;
3448 goto end_function_deallocate_sep_shared_area;
3449 }
3450
3451 dev_dbg(&sep->pdev->dev, "rar start is %p, phy is %llx,"
3452 " size is %zx\n", sep->rar_addr,
3453 (unsigned long long)sep->rar_bus,
3454 sep->rar_size);
3455
3456 dev_dbg(&sep->pdev->dev, "about to write IMR and ICR REG_ADDR\n");
3457
3458 /* Clear ICR register */
3459 sep_write_reg(sep, HW_HOST_ICR_REG_ADDR, 0xFFFFFFFF);
3460
3461 /* Set the IMR register - open only GPR 2 */
3462 sep_write_reg(sep, HW_HOST_IMR_REG_ADDR, (~(0x1 << 13)));
3463
3464 /* Read send/receive counters from SEP */
3465 sep->reply_ct = sep_read_reg(sep, HW_HOST_SEP_HOST_GPR2_REG_ADDR);
3466 sep->reply_ct &= 0x3FFFFFFF;
3467 sep->send_ct = sep->reply_ct;
3468
3469 dev_dbg(&sep->pdev->dev, "about to call request_irq\n");
3470 /* Get the interrupt line */
3471 error = request_irq(pdev->irq, sep_inthandler, IRQF_SHARED,
3472 "sep_driver", sep);
3473
3474 if (error)
3475 goto end_function_dealloc_rar;
3476
3477 /* The new chip requires ashared area reconfigure */
3478 if (sep->pdev->revision == 4) { /* Only for new chip */
3479 error = sep_reconfig_shared_area(sep);
3480 if (error)
3481 goto end_function_free_irq;
3482 }
3483 /* Finally magic up the device nodes */
3484 /* Register driver with the fs */
3485 error = sep_register_driver_with_fs(sep);
3486 if (error == 0)
3487 /* Success */
3488 return 0;
3489
3490end_function_free_irq:
3491 free_irq(pdev->irq, sep);
3492
3493end_function_dealloc_rar:
3494 if (sep->rar_addr)
3495 dma_free_coherent(&sep->pdev->dev, sep->rar_size,
3496 sep->rar_addr, sep->rar_bus);
3497 goto end_function;
3498
3499end_function_deallocate_sep_shared_area:
3500 /* De-allocate shared area */
3501 sep_unmap_and_free_shared_area(sep);
3502
3503end_function_error:
3504 iounmap(sep->reg_addr);
3505
3506end_function_free_sep_dev:
3507 pci_dev_put(sep_dev->pdev);
3508 kfree(sep_dev);
3509 sep_dev = NULL;
3510
3511end_function_disable_device:
3512 pci_disable_device(pdev);
3513
3514end_function:
3515 return error;
3516}
3517
3518static void sep_remove(struct pci_dev *pdev)
3519{
3520 struct sep_device *sep = sep_dev;
3521
3522 /* Unregister from fs */
3523 misc_deregister(&sep->miscdev_sep);
3524 misc_deregister(&sep->miscdev_singleton);
3525 misc_deregister(&sep->miscdev_daemon);
3526
3527 /* Free the irq */
3528 free_irq(sep->pdev->irq, sep);
3529
3530 /* Free the shared area */
3531 sep_unmap_and_free_shared_area(sep_dev);
3532 iounmap((void *) sep_dev->reg_addr);
3533}
3534
3535static DEFINE_PCI_DEVICE_TABLE(sep_pci_id_tbl) = {
3536 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, MFLD_PCI_DEVICE_ID)},
3537 {0}
3538};
3539
3540MODULE_DEVICE_TABLE(pci, sep_pci_id_tbl);
3541
3542/* Field for registering driver to PCI device */
3543static struct pci_driver sep_pci_driver = {
3544 .name = "sep_sec_driver",
3545 .id_table = sep_pci_id_tbl,
3546 .probe = sep_probe,
3547 .remove = sep_remove
3548};
3549
3550
3551/**
3552 * sep_init - init function
3553 *
3554 * Module load time. Register the PCI device driver.
3555 */
3556static int __init sep_init(void)
3557{
3558 return pci_register_driver(&sep_pci_driver);
3559}
3560
3561
3562/**
3563 * sep_exit - called to unload driver
3564 *
3565 * Drop the misc devices then remove and unmap the various resources
3566 * that are not released by the driver remove method.
3567 */
3568static void __exit sep_exit(void)
3569{
3570 pci_unregister_driver(&sep_pci_driver);
3571}
3572
3573
3574module_init(sep_init);
3575module_exit(sep_exit);
3576
3577MODULE_LICENSE("GPL");
diff --git a/drivers/staging/sep/sep_driver_api.h b/drivers/staging/sep/sep_driver_api.h
new file mode 100644
index 000000000000..fbbfa2396555
--- /dev/null
+++ b/drivers/staging/sep/sep_driver_api.h
@@ -0,0 +1,297 @@
1/*
2 *
3 * sep_driver_api.h - Security Processor Driver api definitions
4 *
5 * Copyright(c) 2009,2010 Intel Corporation. All rights reserved.
6 * Contributions(c) 2009,2010 Discretix. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * CONTACTS:
22 *
23 * Mark Allyn mark.a.allyn@intel.com
24 * Jayant Mangalampalli jayant.mangalampalli@intel.com
25 *
26 * CHANGES:
27 *
28 * 2010.09.14 Upgrade to Medfield
29 *
30 */
31
32#ifndef __SEP_DRIVER_API_H__
33#define __SEP_DRIVER_API_H__
34
35/* Type of request from device */
36#define SEP_DRIVER_SRC_REPLY 1
37#define SEP_DRIVER_SRC_REQ 2
38#define SEP_DRIVER_SRC_PRINTF 3
39
40
41/*-------------------------------------------
42 TYPEDEFS
43----------------------------------------------*/
44
45/*
46 * Note that several members of these structres are only here
47 * for campatability with the middleware; they are not used
48 * by this driver.
49 * All user space buffer addresses are set to aligned u64
50 * in order to ensure compatibility with 64 bit systems
51 */
52
53/*
54 init command struct; this will go away when SCU does init
55*/
56struct init_struct {
57 /* address that SEP can access for message */
58 aligned_u64 message_addr;
59
60 /* message size */
61 u32 message_size_in_words;
62
63 /* offset of the init message in the sep sram */
64 u32 sep_sram_addr;
65
66 /* -not used- resident size in bytes*/
67 u32 unused_resident_size_in_bytes;
68
69 /* -not used- cache size in bytes*/
70 u32 unused_cache_size_in_bytes;
71
72 /* -not used- ext cache current address */
73 aligned_u64 unused_extcache_addr;
74
75 /* -not used- ext cache size in bytes*/
76 u32 unused_extcache_size_in_bytes;
77};
78
79struct realloc_ext_struct {
80 /* -not used- current external cache address */
81 aligned_u64 unused_ext_cache_addr;
82
83 /* -not used- external cache size in bytes*/
84 u32 unused_ext_cache_size_in_bytes;
85};
86
87struct alloc_struct {
88 /* offset from start of shared pool area */
89 u32 offset;
90 /* number of bytes to allocate */
91 u32 num_bytes;
92};
93
94/*
95 Note that all app addresses are cast as u32; the sep
96 middleware sends them as fixed 32 bit words
97*/
98struct bld_syn_tab_struct {
99 /* address value of the data in (user space addr) */
100 aligned_u64 app_in_address;
101
102 /* size of data in */
103 u32 data_in_size;
104
105 /* address of the data out (user space addr) */
106 aligned_u64 app_out_address;
107
108 /* the size of the block of the operation - if needed,
109 every table will be modulo this parameter */
110 u32 block_size;
111
112 /* -not used- distinct user/kernel layout */
113 bool isKernelVirtualAddress;
114
115};
116
117/* command struct for getting caller id value and address */
118struct caller_id_struct {
119 /* pid of the process */
120 u32 pid;
121 /* virtual address of the caller id hash */
122 aligned_u64 callerIdAddress;
123 /* caller id hash size in bytes */
124 u32 callerIdSizeInBytes;
125};
126
127/*
128 structure that represents DCB
129*/
130struct sep_dcblock {
131 /* physical address of the first input mlli */
132 u32 input_mlli_address;
133 /* num of entries in the first input mlli */
134 u32 input_mlli_num_entries;
135 /* size of data in the first input mlli */
136 u32 input_mlli_data_size;
137 /* physical address of the first output mlli */
138 u32 output_mlli_address;
139 /* num of entries in the first output mlli */
140 u32 output_mlli_num_entries;
141 /* size of data in the first output mlli */
142 u32 output_mlli_data_size;
143 /* pointer to the output virtual tail */
144 u32 out_vr_tail_pt;
145 /* size of tail data */
146 u32 tail_data_size;
147 /* input tail data array */
148 u8 tail_data[64];
149};
150
151struct sep_caller_id_entry {
152 int pid;
153 unsigned char callerIdHash[SEP_CALLER_ID_HASH_SIZE_IN_BYTES];
154};
155
156/*
157 command structure for building dcb block (currently for ext app only
158*/
159struct build_dcb_struct {
160 /* address value of the data in */
161 aligned_u64 app_in_address;
162 /* size of data in */
163 u32 data_in_size;
164 /* address of the data out */
165 aligned_u64 app_out_address;
166 /* the size of the block of the operation - if needed,
167 every table will be modulo this parameter */
168 u32 block_size;
169 /* the size of the block of the operation - if needed,
170 every table will be modulo this parameter */
171 u32 tail_block_size;
172};
173
174/**
175 * @struct sep_dma_map
176 *
177 * Structure that contains all information needed for mapping the user pages
178 * or kernel buffers for dma operations
179 *
180 *
181 */
182struct sep_dma_map {
183 /* mapped dma address */
184 dma_addr_t dma_addr;
185 /* size of the mapped data */
186 size_t size;
187};
188
189struct sep_dma_resource {
190 /* array of pointers to the pages that represent
191 input data for the synchronic DMA action */
192 struct page **in_page_array;
193
194 /* array of pointers to the pages that represent out
195 data for the synchronic DMA action */
196 struct page **out_page_array;
197
198 /* number of pages in the sep_in_page_array */
199 u32 in_num_pages;
200
201 /* number of pages in the sep_out_page_array */
202 u32 out_num_pages;
203
204 /* map array of the input data */
205 struct sep_dma_map *in_map_array;
206
207 /* map array of the output data */
208 struct sep_dma_map *out_map_array;
209
210 /* number of entries of the input mapp array */
211 u32 in_map_num_entries;
212
213 /* number of entries of the output mapp array */
214 u32 out_map_num_entries;
215};
216
217
218/* command struct for translating rar handle to bus address
219 and setting it at predefined location */
220struct rar_hndl_to_bus_struct {
221
222 /* rar handle */
223 aligned_u64 rar_handle;
224};
225
226/*
227 structure that represent one entry in the DMA LLI table
228*/
229struct sep_lli_entry {
230 /* physical address */
231 u32 bus_address;
232
233 /* block size */
234 u32 block_size;
235};
236
237/*----------------------------------------------------------------
238 IOCTL command defines
239 -----------------------------------------------------------------*/
240
241/* magic number 1 of the sep IOCTL command */
242#define SEP_IOC_MAGIC_NUMBER 's'
243
244/* sends interrupt to sep that message is ready */
245#define SEP_IOCSENDSEPCOMMAND \
246 _IO(SEP_IOC_MAGIC_NUMBER, 0)
247
248/* sends interrupt to sep that message is ready */
249#define SEP_IOCSENDSEPRPLYCOMMAND \
250 _IO(SEP_IOC_MAGIC_NUMBER, 1)
251
252/* allocate memory in data pool */
253#define SEP_IOCALLOCDATAPOLL \
254 _IOW(SEP_IOC_MAGIC_NUMBER, 2, struct alloc_struct)
255
256/* create sym dma lli tables */
257#define SEP_IOCCREATESYMDMATABLE \
258 _IOW(SEP_IOC_MAGIC_NUMBER, 5, struct bld_syn_tab_struct)
259
260/* free dynamic data aalocated during table creation */
261#define SEP_IOCFREEDMATABLEDATA \
262 _IO(SEP_IOC_MAGIC_NUMBER, 7)
263
264/* get the static pool area addersses (physical and virtual) */
265#define SEP_IOCGETSTATICPOOLADDR \
266 _IO(SEP_IOC_MAGIC_NUMBER, 8)
267
268/* start sep command */
269#define SEP_IOCSEPSTART \
270 _IO(SEP_IOC_MAGIC_NUMBER, 12)
271
272/* init sep command */
273#define SEP_IOCSEPINIT \
274 _IOW(SEP_IOC_MAGIC_NUMBER, 13, struct init_struct)
275
276/* end transaction command */
277#define SEP_IOCENDTRANSACTION \
278 _IO(SEP_IOC_MAGIC_NUMBER, 15)
279
280/* reallocate external app; unused structure still needed for
281 * compatability with middleware */
282#define SEP_IOCREALLOCEXTCACHE \
283 _IOW(SEP_IOC_MAGIC_NUMBER, 18, struct realloc_ext_struct)
284
285#define SEP_IOCRARPREPAREMESSAGE \
286 _IOW(SEP_IOC_MAGIC_NUMBER, 20, struct rar_hndl_to_bus_struct)
287
288#define SEP_IOCTLSETCALLERID \
289 _IOW(SEP_IOC_MAGIC_NUMBER, 34, struct caller_id_struct)
290
291#define SEP_IOCPREPAREDCB \
292 _IOW(SEP_IOC_MAGIC_NUMBER, 35, struct build_dcb_struct)
293
294#define SEP_IOCFREEDCB \
295 _IO(SEP_IOC_MAGIC_NUMBER, 36)
296
297#endif
diff --git a/drivers/staging/sep/sep_driver_config.h b/drivers/staging/sep/sep_driver_config.h
new file mode 100644
index 000000000000..b18625d2f7f4
--- /dev/null
+++ b/drivers/staging/sep/sep_driver_config.h
@@ -0,0 +1,239 @@
1/*
2 *
3 * sep_driver_config.h - Security Processor Driver configuration
4 *
5 * Copyright(c) 2009,2010 Intel Corporation. All rights reserved.
6 * Contributions(c) 2009,2010 Discretix. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * CONTACTS:
22 *
23 * Mark Allyn mark.a.allyn@intel.com
24 * Jayant Mangalampalli jayant.mangalampalli@intel.com
25 *
26 * CHANGES:
27 *
28 * 2010.06.26 Upgrade to Medfield
29 *
30 */
31
32#ifndef __SEP_DRIVER_CONFIG_H__
33#define __SEP_DRIVER_CONFIG_H__
34
35
36/*--------------------------------------
37 DRIVER CONFIGURATION FLAGS
38 -------------------------------------*/
39
40/* if flag is on , then the driver is running in polling and
41 not interrupt mode */
42#define SEP_DRIVER_POLLING_MODE 0
43
44/* flag which defines if the shared area address should be
45 reconfiged (send to SEP anew) during init of the driver */
46#define SEP_DRIVER_RECONFIG_MESSAGE_AREA 0
47
48/* the mode for running on the ARM1172 Evaluation platform (flag is 1) */
49#define SEP_DRIVER_ARM_DEBUG_MODE 0
50
51/*-------------------------------------------
52 INTERNAL DATA CONFIGURATION
53 -------------------------------------------*/
54
55/* flag for the input array */
56#define SEP_DRIVER_IN_FLAG 0
57
58/* flag for output array */
59#define SEP_DRIVER_OUT_FLAG 1
60
61/* maximum number of entries in one LLI tables */
62#define SEP_DRIVER_ENTRIES_PER_TABLE_IN_SEP 31
63
64/* minimum data size of the MLLI table */
65#define SEP_DRIVER_MIN_DATA_SIZE_PER_TABLE 16
66
67/* flag that signifies tah the lock is
68currently held by the proccess (struct file) */
69#define SEP_DRIVER_OWN_LOCK_FLAG 1
70
71/* flag that signifies tah the lock is currently NOT
72held by the proccess (struct file) */
73#define SEP_DRIVER_DISOWN_LOCK_FLAG 0
74
75/* indicates whether driver has mapped/unmapped shared area */
76#define SEP_REQUEST_DAEMON_MAPPED 1
77#define SEP_REQUEST_DAEMON_UNMAPPED 0
78
79/*--------------------------------------------------------
80 SHARED AREA memory total size is 36K
81 it is divided is following:
82
83 SHARED_MESSAGE_AREA 8K }
84 }
85 STATIC_POOL_AREA 4K } MAPPED AREA ( 24 K)
86 }
87 DATA_POOL_AREA 12K }
88
89 SYNCHRONIC_DMA_TABLES_AREA 5K
90
91 placeholder until drver changes
92 FLOW_DMA_TABLES_AREA 4K
93
94 SYSTEM_MEMORY_AREA 3k
95
96 SYSTEM_MEMORY total size is 3k
97 it is divided as following:
98
99 TIME_MEMORY_AREA 8B
100-----------------------------------------------------------*/
101
102#define SEP_DEV_NAME "sep_sec_driver"
103#define SEP_DEV_SINGLETON "sep_sec_singleton_driver"
104#define SEP_DEV_DAEMON "sep_req_daemon_driver"
105
106
107/*
108 the maximum length of the message - the rest of the message shared
109 area will be dedicated to the dma lli tables
110*/
111#define SEP_DRIVER_MAX_MESSAGE_SIZE_IN_BYTES (8 * 1024)
112
113/* the size of the message shared area in pages */
114#define SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES (8 * 1024)
115
116/* the size of the data pool static area in pages */
117#define SEP_DRIVER_STATIC_AREA_SIZE_IN_BYTES (4 * 1024)
118
119/* the size of the data pool shared area size in pages */
120#define SEP_DRIVER_DATA_POOL_SHARED_AREA_SIZE_IN_BYTES (16 * 1024)
121
122/* the size of the message shared area in pages */
123#define SYNCHRONIC_DMA_TABLES_AREA_SIZE_BYTES (1024 * 5)
124
125/* Placeholder until driver changes */
126#define SEP_DRIVER_FLOW_DMA_TABLES_AREA_SIZE_IN_BYTES (1024 * 4)
127
128/* system data (time, caller id etc') pool */
129#define SEP_DRIVER_SYSTEM_DATA_MEMORY_SIZE_IN_BYTES (1024 * 3)
130
131/* the size in bytes of the time memory */
132#define SEP_DRIVER_TIME_MEMORY_SIZE_IN_BYTES 8
133
134/* the size in bytes of the RAR parameters memory */
135#define SEP_DRIVER_SYSTEM_RAR_MEMORY_SIZE_IN_BYTES 8
136
137/* area size that is mapped - we map the MESSAGE AREA, STATIC POOL and
138 DATA POOL areas. area must be module 4k */
139#define SEP_DRIVER_MMMAP_AREA_SIZE (1024 * 28)
140
141/*-----------------------------------------------
142 offsets of the areas starting from the shared area start address
143*/
144
145/* message area offset */
146#define SEP_DRIVER_MESSAGE_AREA_OFFSET_IN_BYTES 0
147
148/* static pool area offset */
149#define SEP_DRIVER_STATIC_AREA_OFFSET_IN_BYTES \
150 (SEP_DRIVER_MESSAGE_SHARED_AREA_SIZE_IN_BYTES)
151
152/* data pool area offset */
153#define SEP_DRIVER_DATA_POOL_AREA_OFFSET_IN_BYTES \
154 (SEP_DRIVER_STATIC_AREA_OFFSET_IN_BYTES + \
155 SEP_DRIVER_STATIC_AREA_SIZE_IN_BYTES)
156
157/* synhronic dma tables area offset */
158#define SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES \
159 (SEP_DRIVER_DATA_POOL_AREA_OFFSET_IN_BYTES + \
160 SEP_DRIVER_DATA_POOL_SHARED_AREA_SIZE_IN_BYTES)
161
162/* system memory offset in bytes */
163#define SEP_DRIVER_SYSTEM_DATA_MEMORY_OFFSET_IN_BYTES \
164 (SYNCHRONIC_DMA_TABLES_AREA_OFFSET_BYTES + \
165 SYNCHRONIC_DMA_TABLES_AREA_SIZE_BYTES)
166
167/* offset of the time area */
168#define SEP_DRIVER_SYSTEM_TIME_MEMORY_OFFSET_IN_BYTES \
169 (SEP_DRIVER_SYSTEM_DATA_MEMORY_OFFSET_IN_BYTES)
170
171/* offset of the RAR area */
172#define SEP_DRIVER_SYSTEM_RAR_MEMORY_OFFSET_IN_BYTES \
173 (SEP_DRIVER_SYSTEM_TIME_MEMORY_OFFSET_IN_BYTES + \
174 SEP_DRIVER_TIME_MEMORY_SIZE_IN_BYTES)
175
176/* offset of the caller id area */
177#define SEP_CALLER_ID_OFFSET_BYTES \
178 (SEP_DRIVER_SYSTEM_RAR_MEMORY_OFFSET_IN_BYTES + \
179 SEP_DRIVER_SYSTEM_RAR_MEMORY_SIZE_IN_BYTES)
180
181/* offset of the DCB area */
182#define SEP_DRIVER_SYSTEM_DCB_MEMORY_OFFSET_IN_BYTES \
183 (SEP_DRIVER_SYSTEM_DATA_MEMORY_OFFSET_IN_BYTES + \
184 0x400)
185
186/* offset of the ext cache area */
187#define SEP_DRIVER_SYSTEM_EXT_CACHE_ADDR_OFFSET_IN_BYTES \
188 SEP_DRIVER_SYSTEM_RAR_MEMORY_OFFSET_IN_BYTES
189
190/* offset of the allocation data pointer area */
191#define SEP_DRIVER_DATA_POOL_ALLOCATION_OFFSET_IN_BYTES \
192 (SEP_CALLER_ID_OFFSET_BYTES + \
193 SEP_CALLER_ID_HASH_SIZE_IN_BYTES)
194
195/* the token that defines the start of time address */
196#define SEP_TIME_VAL_TOKEN 0x12345678
197
198#define FAKE_RAR_SIZE (1024*1024) /* used only for mfld */
199/* DEBUG LEVEL MASKS */
200
201/* size of the caller id hash (sha2) */
202#define SEP_CALLER_ID_HASH_SIZE_IN_BYTES 32
203
204/* size of the caller id hash (sha2) in 32 bit words */
205#define SEP_CALLER_ID_HASH_SIZE_IN_WORDS 8
206
207/* maximum number of entries in the caller id table */
208#define SEP_CALLER_ID_TABLE_NUM_ENTRIES 20
209
210/* maximum number of symetric operation (that require DMA resource)
211 per one message */
212#define SEP_MAX_NUM_SYNC_DMA_OPS 16
213
214/* the token that defines the start of time address */
215#define SEP_RAR_VAL_TOKEN 0xABABABAB
216
217/* ioctl error that should be returned when trying
218 to realloc the cache/resident second time */
219#define SEP_ALREADY_INITIALIZED_ERR 12
220
221/* bit that locks access to the shared area */
222#define SEP_MMAP_LOCK_BIT 0
223
224/* bit that lock access to the poll - after send_command */
225#define SEP_SEND_MSG_LOCK_BIT 1
226
227/* the token that defines the static pool address address */
228#define SEP_STATIC_POOL_VAL_TOKEN 0xABBAABBA
229
230/* the token that defines the data pool pointers address */
231#define SEP_DATA_POOL_POINTERS_VAL_TOKEN 0xEDDEEDDE
232
233/* the token that defines the data pool pointers address */
234#define SEP_EXT_CACHE_ADDR_VAL_TOKEN 0xBABABABA
235
236/* Time limit for SEP to finish */
237#define WAIT_TIME 10
238
239#endif /* SEP DRIVER CONFIG */
diff --git a/drivers/staging/sep/sep_driver_hw_defs.h b/drivers/staging/sep/sep_driver_hw_defs.h
new file mode 100644
index 000000000000..300f90963de3
--- /dev/null
+++ b/drivers/staging/sep/sep_driver_hw_defs.h
@@ -0,0 +1,233 @@
1/*
2 *
3 * sep_driver_hw_defs.h - Security Processor Driver hardware definitions
4 *
5 * Copyright(c) 2009,2010 Intel Corporation. All rights reserved.
6 * Contributions(c) 2009,2010 Discretix. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59
19 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 * CONTACTS:
22 *
23 * Mark Allyn mark.a.allyn@intel.com
24 * Jayant Mangalampalli jayant.mangalampalli@intel.com
25 *
26 * CHANGES:
27 *
28 * 2010.09.20 Upgrade to Medfield
29 *
30 */
31
32#ifndef SEP_DRIVER_HW_DEFS__H
33#define SEP_DRIVER_HW_DEFS__H
34
35/* PCI ID's */
36#define MFLD_PCI_DEVICE_ID 0x0826
37
38/*----------------------- */
39/* HW Registers Defines. */
40/* */
41/*---------------------- -*/
42
43
44/* cf registers */
45#define HW_R0B_ADDR_0_REG_ADDR 0x0000UL
46#define HW_R0B_ADDR_1_REG_ADDR 0x0004UL
47#define HW_R0B_ADDR_2_REG_ADDR 0x0008UL
48#define HW_R0B_ADDR_3_REG_ADDR 0x000cUL
49#define HW_R0B_ADDR_4_REG_ADDR 0x0010UL
50#define HW_R0B_ADDR_5_REG_ADDR 0x0014UL
51#define HW_R0B_ADDR_6_REG_ADDR 0x0018UL
52#define HW_R0B_ADDR_7_REG_ADDR 0x001cUL
53#define HW_R0B_ADDR_8_REG_ADDR 0x0020UL
54#define HW_R2B_ADDR_0_REG_ADDR 0x0080UL
55#define HW_R2B_ADDR_1_REG_ADDR 0x0084UL
56#define HW_R2B_ADDR_2_REG_ADDR 0x0088UL
57#define HW_R2B_ADDR_3_REG_ADDR 0x008cUL
58#define HW_R2B_ADDR_4_REG_ADDR 0x0090UL
59#define HW_R2B_ADDR_5_REG_ADDR 0x0094UL
60#define HW_R2B_ADDR_6_REG_ADDR 0x0098UL
61#define HW_R2B_ADDR_7_REG_ADDR 0x009cUL
62#define HW_R2B_ADDR_8_REG_ADDR 0x00a0UL
63#define HW_R3B_REG_ADDR 0x00C0UL
64#define HW_R4B_REG_ADDR 0x0100UL
65#define HW_CSA_ADDR_0_REG_ADDR 0x0140UL
66#define HW_CSA_ADDR_1_REG_ADDR 0x0144UL
67#define HW_CSA_ADDR_2_REG_ADDR 0x0148UL
68#define HW_CSA_ADDR_3_REG_ADDR 0x014cUL
69#define HW_CSA_ADDR_4_REG_ADDR 0x0150UL
70#define HW_CSA_ADDR_5_REG_ADDR 0x0154UL
71#define HW_CSA_ADDR_6_REG_ADDR 0x0158UL
72#define HW_CSA_ADDR_7_REG_ADDR 0x015cUL
73#define HW_CSA_ADDR_8_REG_ADDR 0x0160UL
74#define HW_CSA_REG_ADDR 0x0140UL
75#define HW_SINB_REG_ADDR 0x0180UL
76#define HW_SOUTB_REG_ADDR 0x0184UL
77#define HW_PKI_CONTROL_REG_ADDR 0x01C0UL
78#define HW_PKI_STATUS_REG_ADDR 0x01C4UL
79#define HW_PKI_BUSY_REG_ADDR 0x01C8UL
80#define HW_PKI_A_1025_REG_ADDR 0x01CCUL
81#define HW_PKI_SDMA_CTL_REG_ADDR 0x01D0UL
82#define HW_PKI_SDMA_OFFSET_REG_ADDR 0x01D4UL
83#define HW_PKI_SDMA_POINTERS_REG_ADDR 0x01D8UL
84#define HW_PKI_SDMA_DLENG_REG_ADDR 0x01DCUL
85#define HW_PKI_SDMA_EXP_POINTERS_REG_ADDR 0x01E0UL
86#define HW_PKI_SDMA_RES_POINTERS_REG_ADDR 0x01E4UL
87#define HW_PKI_CLR_REG_ADDR 0x01E8UL
88#define HW_PKI_SDMA_BUSY_REG_ADDR 0x01E8UL
89#define HW_PKI_SDMA_FIRST_EXP_N_REG_ADDR 0x01ECUL
90#define HW_PKI_SDMA_MUL_BY1_REG_ADDR 0x01F0UL
91#define HW_PKI_SDMA_RMUL_SEL_REG_ADDR 0x01F4UL
92#define HW_DES_KEY_0_REG_ADDR 0x0208UL
93#define HW_DES_KEY_1_REG_ADDR 0x020CUL
94#define HW_DES_KEY_2_REG_ADDR 0x0210UL
95#define HW_DES_KEY_3_REG_ADDR 0x0214UL
96#define HW_DES_KEY_4_REG_ADDR 0x0218UL
97#define HW_DES_KEY_5_REG_ADDR 0x021CUL
98#define HW_DES_CONTROL_0_REG_ADDR 0x0220UL
99#define HW_DES_CONTROL_1_REG_ADDR 0x0224UL
100#define HW_DES_IV_0_REG_ADDR 0x0228UL
101#define HW_DES_IV_1_REG_ADDR 0x022CUL
102#define HW_AES_KEY_0_ADDR_0_REG_ADDR 0x0400UL
103#define HW_AES_KEY_0_ADDR_1_REG_ADDR 0x0404UL
104#define HW_AES_KEY_0_ADDR_2_REG_ADDR 0x0408UL
105#define HW_AES_KEY_0_ADDR_3_REG_ADDR 0x040cUL
106#define HW_AES_KEY_0_ADDR_4_REG_ADDR 0x0410UL
107#define HW_AES_KEY_0_ADDR_5_REG_ADDR 0x0414UL
108#define HW_AES_KEY_0_ADDR_6_REG_ADDR 0x0418UL
109#define HW_AES_KEY_0_ADDR_7_REG_ADDR 0x041cUL
110#define HW_AES_KEY_0_REG_ADDR 0x0400UL
111#define HW_AES_IV_0_ADDR_0_REG_ADDR 0x0440UL
112#define HW_AES_IV_0_ADDR_1_REG_ADDR 0x0444UL
113#define HW_AES_IV_0_ADDR_2_REG_ADDR 0x0448UL
114#define HW_AES_IV_0_ADDR_3_REG_ADDR 0x044cUL
115#define HW_AES_IV_0_REG_ADDR 0x0440UL
116#define HW_AES_CTR1_ADDR_0_REG_ADDR 0x0460UL
117#define HW_AES_CTR1_ADDR_1_REG_ADDR 0x0464UL
118#define HW_AES_CTR1_ADDR_2_REG_ADDR 0x0468UL
119#define HW_AES_CTR1_ADDR_3_REG_ADDR 0x046cUL
120#define HW_AES_CTR1_REG_ADDR 0x0460UL
121#define HW_AES_SK_REG_ADDR 0x0478UL
122#define HW_AES_MAC_OK_REG_ADDR 0x0480UL
123#define HW_AES_PREV_IV_0_ADDR_0_REG_ADDR 0x0490UL
124#define HW_AES_PREV_IV_0_ADDR_1_REG_ADDR 0x0494UL
125#define HW_AES_PREV_IV_0_ADDR_2_REG_ADDR 0x0498UL
126#define HW_AES_PREV_IV_0_ADDR_3_REG_ADDR 0x049cUL
127#define HW_AES_PREV_IV_0_REG_ADDR 0x0490UL
128#define HW_AES_CONTROL_REG_ADDR 0x04C0UL
129#define HW_HASH_H0_REG_ADDR 0x0640UL
130#define HW_HASH_H1_REG_ADDR 0x0644UL
131#define HW_HASH_H2_REG_ADDR 0x0648UL
132#define HW_HASH_H3_REG_ADDR 0x064CUL
133#define HW_HASH_H4_REG_ADDR 0x0650UL
134#define HW_HASH_H5_REG_ADDR 0x0654UL
135#define HW_HASH_H6_REG_ADDR 0x0658UL
136#define HW_HASH_H7_REG_ADDR 0x065CUL
137#define HW_HASH_H8_REG_ADDR 0x0660UL
138#define HW_HASH_H9_REG_ADDR 0x0664UL
139#define HW_HASH_H10_REG_ADDR 0x0668UL
140#define HW_HASH_H11_REG_ADDR 0x066CUL
141#define HW_HASH_H12_REG_ADDR 0x0670UL
142#define HW_HASH_H13_REG_ADDR 0x0674UL
143#define HW_HASH_H14_REG_ADDR 0x0678UL
144#define HW_HASH_H15_REG_ADDR 0x067CUL
145#define HW_HASH_CONTROL_REG_ADDR 0x07C0UL
146#define HW_HASH_PAD_EN_REG_ADDR 0x07C4UL
147#define HW_HASH_PAD_CFG_REG_ADDR 0x07C8UL
148#define HW_HASH_CUR_LEN_0_REG_ADDR 0x07CCUL
149#define HW_HASH_CUR_LEN_1_REG_ADDR 0x07D0UL
150#define HW_HASH_CUR_LEN_2_REG_ADDR 0x07D4UL
151#define HW_HASH_CUR_LEN_3_REG_ADDR 0x07D8UL
152#define HW_HASH_PARAM_REG_ADDR 0x07DCUL
153#define HW_HASH_INT_BUSY_REG_ADDR 0x07E0UL
154#define HW_HASH_SW_RESET_REG_ADDR 0x07E4UL
155#define HW_HASH_ENDIANESS_REG_ADDR 0x07E8UL
156#define HW_HASH_DATA_REG_ADDR 0x07ECUL
157#define HW_DRNG_CONTROL_REG_ADDR 0x0800UL
158#define HW_DRNG_VALID_REG_ADDR 0x0804UL
159#define HW_DRNG_DATA_REG_ADDR 0x0808UL
160#define HW_RND_SRC_EN_REG_ADDR 0x080CUL
161#define HW_AES_CLK_ENABLE_REG_ADDR 0x0810UL
162#define HW_DES_CLK_ENABLE_REG_ADDR 0x0814UL
163#define HW_HASH_CLK_ENABLE_REG_ADDR 0x0818UL
164#define HW_PKI_CLK_ENABLE_REG_ADDR 0x081CUL
165#define HW_CLK_STATUS_REG_ADDR 0x0824UL
166#define HW_CLK_ENABLE_REG_ADDR 0x0828UL
167#define HW_DRNG_SAMPLE_REG_ADDR 0x0850UL
168#define HW_RND_SRC_CTL_REG_ADDR 0x0858UL
169#define HW_CRYPTO_CTL_REG_ADDR 0x0900UL
170#define HW_CRYPTO_STATUS_REG_ADDR 0x090CUL
171#define HW_CRYPTO_BUSY_REG_ADDR 0x0910UL
172#define HW_AES_BUSY_REG_ADDR 0x0914UL
173#define HW_DES_BUSY_REG_ADDR 0x0918UL
174#define HW_HASH_BUSY_REG_ADDR 0x091CUL
175#define HW_CONTENT_REG_ADDR 0x0924UL
176#define HW_VERSION_REG_ADDR 0x0928UL
177#define HW_CONTEXT_ID_REG_ADDR 0x0930UL
178#define HW_DIN_BUFFER_REG_ADDR 0x0C00UL
179#define HW_DIN_MEM_DMA_BUSY_REG_ADDR 0x0c20UL
180#define HW_SRC_LLI_MEM_ADDR_REG_ADDR 0x0c24UL
181#define HW_SRC_LLI_WORD0_REG_ADDR 0x0C28UL
182#define HW_SRC_LLI_WORD1_REG_ADDR 0x0C2CUL
183#define HW_SRAM_SRC_ADDR_REG_ADDR 0x0c30UL
184#define HW_DIN_SRAM_BYTES_LEN_REG_ADDR 0x0c34UL
185#define HW_DIN_SRAM_DMA_BUSY_REG_ADDR 0x0C38UL
186#define HW_WRITE_ALIGN_REG_ADDR 0x0C3CUL
187#define HW_OLD_DATA_REG_ADDR 0x0C48UL
188#define HW_WRITE_ALIGN_LAST_REG_ADDR 0x0C4CUL
189#define HW_DOUT_BUFFER_REG_ADDR 0x0C00UL
190#define HW_DST_LLI_WORD0_REG_ADDR 0x0D28UL
191#define HW_DST_LLI_WORD1_REG_ADDR 0x0D2CUL
192#define HW_DST_LLI_MEM_ADDR_REG_ADDR 0x0D24UL
193#define HW_DOUT_MEM_DMA_BUSY_REG_ADDR 0x0D20UL
194#define HW_SRAM_DEST_ADDR_REG_ADDR 0x0D30UL
195#define HW_DOUT_SRAM_BYTES_LEN_REG_ADDR 0x0D34UL
196#define HW_DOUT_SRAM_DMA_BUSY_REG_ADDR 0x0D38UL
197#define HW_READ_ALIGN_REG_ADDR 0x0D3CUL
198#define HW_READ_LAST_DATA_REG_ADDR 0x0D44UL
199#define HW_RC4_THRU_CPU_REG_ADDR 0x0D4CUL
200#define HW_AHB_SINGLE_REG_ADDR 0x0E00UL
201#define HW_SRAM_DATA_REG_ADDR 0x0F00UL
202#define HW_SRAM_ADDR_REG_ADDR 0x0F04UL
203#define HW_SRAM_DATA_READY_REG_ADDR 0x0F08UL
204#define HW_HOST_IRR_REG_ADDR 0x0A00UL
205#define HW_HOST_IMR_REG_ADDR 0x0A04UL
206#define HW_HOST_ICR_REG_ADDR 0x0A08UL
207#define HW_HOST_SEP_SRAM_THRESHOLD_REG_ADDR 0x0A10UL
208#define HW_HOST_SEP_BUSY_REG_ADDR 0x0A14UL
209#define HW_HOST_SEP_LCS_REG_ADDR 0x0A18UL
210#define HW_HOST_CC_SW_RST_REG_ADDR 0x0A40UL
211#define HW_HOST_SEP_SW_RST_REG_ADDR 0x0A44UL
212#define HW_HOST_FLOW_DMA_SW_INT0_REG_ADDR 0x0A80UL
213#define HW_HOST_FLOW_DMA_SW_INT1_REG_ADDR 0x0A84UL
214#define HW_HOST_FLOW_DMA_SW_INT2_REG_ADDR 0x0A88UL
215#define HW_HOST_FLOW_DMA_SW_INT3_REG_ADDR 0x0A8cUL
216#define HW_HOST_FLOW_DMA_SW_INT4_REG_ADDR 0x0A90UL
217#define HW_HOST_FLOW_DMA_SW_INT5_REG_ADDR 0x0A94UL
218#define HW_HOST_FLOW_DMA_SW_INT6_REG_ADDR 0x0A98UL
219#define HW_HOST_FLOW_DMA_SW_INT7_REG_ADDR 0x0A9cUL
220#define HW_HOST_SEP_HOST_GPR0_REG_ADDR 0x0B00UL
221#define HW_HOST_SEP_HOST_GPR1_REG_ADDR 0x0B04UL
222#define HW_HOST_SEP_HOST_GPR2_REG_ADDR 0x0B08UL
223#define HW_HOST_SEP_HOST_GPR3_REG_ADDR 0x0B0CUL
224#define HW_HOST_HOST_SEP_GPR0_REG_ADDR 0x0B80UL
225#define HW_HOST_HOST_SEP_GPR1_REG_ADDR 0x0B84UL
226#define HW_HOST_HOST_SEP_GPR2_REG_ADDR 0x0B88UL
227#define HW_HOST_HOST_SEP_GPR3_REG_ADDR 0x0B8CUL
228#define HW_HOST_HOST_ENDIAN_REG_ADDR 0x0B90UL
229#define HW_HOST_HOST_COMM_CLK_EN_REG_ADDR 0x0B94UL
230#define HW_CLR_SRAM_BUSY_REG_REG_ADDR 0x0F0CUL
231#define HW_CC_SRAM_BASE_ADDRESS 0x5800UL
232
233#endif /* ifndef HW_DEFS */
diff --git a/drivers/staging/sm7xx/smtcfb.c b/drivers/staging/sm7xx/smtcfb.c
index 24f47d6388f4..f4b163f7338a 100644
--- a/drivers/staging/sm7xx/smtcfb.c
+++ b/drivers/staging/sm7xx/smtcfb.c
@@ -996,7 +996,7 @@ failed_free:
996 996
997 997
998/* Jason (08/11/2009) PCI_DRV wrapper essential structs */ 998/* Jason (08/11/2009) PCI_DRV wrapper essential structs */
999static const struct pci_device_id smtcfb_pci_table[] = { 999static DEFINE_PCI_DEVICE_TABLE(smtcfb_pci_table) = {
1000 {0x126f, 0x710, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 1000 {0x126f, 0x710, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1001 {0x126f, 0x712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 1001 {0x126f, 0x712, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1002 {0x126f, 0x720, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 1002 {0x126f, 0x720, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
diff --git a/drivers/staging/solo6x10/Kconfig b/drivers/staging/solo6x10/Kconfig
index d96398c701f8..2cf77c940860 100644
--- a/drivers/staging/solo6x10/Kconfig
+++ b/drivers/staging/solo6x10/Kconfig
@@ -1,7 +1,7 @@
1config SOLO6X10 1config SOLO6X10
2 tristate "Softlogic 6x10 MPEG codec cards" 2 tristate "Softlogic 6x10 MPEG codec cards"
3 depends on PCI && VIDEO_DEV && SND 3 depends on PCI && VIDEO_DEV && SND && I2C
4 select VIDEOBUF_DMA_CONTIG 4 select VIDEOBUF_DMA_SG
5 ---help--- 5 ---help---
6 This driver supports the Softlogic based MPEG-4 and h.264 codec 6 This driver supports the Softlogic based MPEG-4 and h.264 codec
7 codec cards. 7 codec cards.
diff --git a/drivers/staging/solo6x10/TODO b/drivers/staging/solo6x10/TODO
index e6a2ee226743..7e6c4fa130df 100644
--- a/drivers/staging/solo6x10/TODO
+++ b/drivers/staging/solo6x10/TODO
@@ -1,7 +1,5 @@
1TODO (staging => main): 1TODO (staging => main):
2 2
3 * checkpatch.pl (haven't run it yet)
4 * Lindent (should be clean, but check)
5 * Motion detection flags need to be moved to v4l2 3 * Motion detection flags need to be moved to v4l2
6 * Some private CIDs need to be moved to v4l2 4 * Some private CIDs need to be moved to v4l2
7 5
@@ -21,8 +19,6 @@ TODO (general):
21 - implement playback via external sound jack 19 - implement playback via external sound jack
22 - implement loopback of external sound jack with incoming audio? 20 - implement loopback of external sound jack with incoming audio?
23 - implement pause/resume 21 - implement pause/resume
24 - check into jacking sound from tx28xx chips directly (to avoid
25 g.723/8khz limitations)
26 22
27Plase send patches to Greg Kroah-Hartman <greg@kroah.com> and Cc Ben Collins 23Plase send patches to Greg Kroah-Hartman <greg@kroah.com> and Cc Ben Collins
28<bcollins@bluecherry.net> 24<bcollins@bluecherry.net>
diff --git a/drivers/staging/solo6x10/solo6010-core.c b/drivers/staging/solo6x10/solo6010-core.c
index 4a051cde55da..c433136f972c 100644
--- a/drivers/staging/solo6x10/solo6010-core.c
+++ b/drivers/staging/solo6x10/solo6010-core.c
@@ -136,6 +136,7 @@ static int __devinit solo6010_pci_probe(struct pci_dev *pdev,
136 int ret; 136 int ret;
137 int sdram; 137 int sdram;
138 u8 chip_id; 138 u8 chip_id;
139
139 solo_dev = kzalloc(sizeof(*solo_dev), GFP_KERNEL); 140 solo_dev = kzalloc(sizeof(*solo_dev), GFP_KERNEL);
140 if (solo_dev == NULL) 141 if (solo_dev == NULL)
141 return -ENOMEM; 142 return -ENOMEM;
@@ -163,21 +164,21 @@ static int __devinit solo6010_pci_probe(struct pci_dev *pdev,
163 chip_id = solo_reg_read(solo_dev, SOLO_CHIP_OPTION) & 164 chip_id = solo_reg_read(solo_dev, SOLO_CHIP_OPTION) &
164 SOLO_CHIP_ID_MASK; 165 SOLO_CHIP_ID_MASK;
165 switch (chip_id) { 166 switch (chip_id) {
166 case 7: 167 case 7:
167 solo_dev->nr_chans = 16; 168 solo_dev->nr_chans = 16;
168 solo_dev->nr_ext = 5; 169 solo_dev->nr_ext = 5;
169 break; 170 break;
170 case 6: 171 case 6:
171 solo_dev->nr_chans = 8; 172 solo_dev->nr_chans = 8;
172 solo_dev->nr_ext = 2; 173 solo_dev->nr_ext = 2;
173 break; 174 break;
174 default: 175 default:
175 dev_warn(&pdev->dev, "Invalid chip_id 0x%02x, " 176 dev_warn(&pdev->dev, "Invalid chip_id 0x%02x, "
176 "defaulting to 4 channels\n", 177 "defaulting to 4 channels\n",
177 chip_id); 178 chip_id);
178 case 5: 179 case 5:
179 solo_dev->nr_chans = 4; 180 solo_dev->nr_chans = 4;
180 solo_dev->nr_ext = 1; 181 solo_dev->nr_ext = 1;
181 } 182 }
182 183
183 /* Disable all interrupts to start */ 184 /* Disable all interrupts to start */
@@ -261,13 +262,18 @@ static void __devexit solo6010_pci_remove(struct pci_dev *pdev)
261} 262}
262 263
263static struct pci_device_id solo6010_id_table[] = { 264static struct pci_device_id solo6010_id_table[] = {
265 /* 6010 based cards */
264 {PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC, PCI_DEVICE_ID_SOLO6010)}, 266 {PCI_DEVICE(PCI_VENDOR_ID_SOFTLOGIC, PCI_DEVICE_ID_SOLO6010)},
265 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_4)}, 267 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_4)},
266 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_9)}, 268 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_9)},
267 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_16)}, 269 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_NEUSOLO_16)},
268 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_COMMSOLO_4)}, 270 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_4)},
269 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_COMMSOLO_9)}, 271 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_9)},
270 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_COMMSOLO_16)}, 272 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_SOLO_16)},
273 /* 6110 based cards */
274 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_4)},
275 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_8)},
276 {PCI_DEVICE(PCI_VENDOR_ID_BLUECHERRY, PCI_DEVICE_ID_BC_6110_16)},
271 {0,} 277 {0,}
272}; 278};
273 279
diff --git a/drivers/staging/solo6x10/solo6010-disp.c b/drivers/staging/solo6x10/solo6010-disp.c
index 555f024f72e7..f866f8438175 100644
--- a/drivers/staging/solo6x10/solo6010-disp.c
+++ b/drivers/staging/solo6x10/solo6010-disp.c
@@ -198,12 +198,12 @@ static void solo_motion_config(struct solo6010_dev *solo_dev)
198 } 198 }
199 199
200 /* Default motion settings */ 200 /* Default motion settings */
201 solo_reg_write(solo_dev, SOLO_VI_MOT_ADR, SOLO_VI_MOTION_EN(0) | 201 solo_reg_write(solo_dev, SOLO_VI_MOT_ADR, SOLO_VI_MOTION_EN(0) |
202 (SOLO_MOTION_EXT_ADDR(solo_dev) >> 16)); 202 (SOLO_MOTION_EXT_ADDR(solo_dev) >> 16));
203 solo_reg_write(solo_dev, SOLO_VI_MOT_CTRL, 203 solo_reg_write(solo_dev, SOLO_VI_MOT_CTRL,
204 SOLO_VI_MOTION_FRAME_COUNT(3) | 204 SOLO_VI_MOTION_FRAME_COUNT(3) |
205 SOLO_VI_MOTION_SAMPLE_LENGTH(solo_dev->video_hsize / 16) 205 SOLO_VI_MOTION_SAMPLE_LENGTH(solo_dev->video_hsize / 16)
206 | //SOLO_VI_MOTION_INTR_START_STOP | 206 | /* SOLO_VI_MOTION_INTR_START_STOP | */
207 SOLO_VI_MOTION_SAMPLE_COUNT(10)); 207 SOLO_VI_MOTION_SAMPLE_COUNT(10));
208 208
209 solo_reg_write(solo_dev, SOLO_VI_MOTION_BORDER, 0); 209 solo_reg_write(solo_dev, SOLO_VI_MOTION_BORDER, 0);
@@ -264,7 +264,7 @@ void solo_disp_exit(struct solo6010_dev *solo_dev)
264 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_CTRL(0), 0); 264 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_CTRL(0), 0);
265 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_START(0), 0); 265 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_START(0), 0);
266 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_STOP(0), 0); 266 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_STOP(0), 0);
267 267
268 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_CTRL(1), 0); 268 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_CTRL(1), 0);
269 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_START(1), 0); 269 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_START(1), 0);
270 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_STOP(1), 0); 270 solo_reg_write(solo_dev, SOLO_VO_RECTANGLE_STOP(1), 0);
diff --git a/drivers/staging/solo6x10/solo6010-enc.c b/drivers/staging/solo6x10/solo6010-enc.c
index a6cf0a8a3f20..481a49277f77 100644
--- a/drivers/staging/solo6x10/solo6010-enc.c
+++ b/drivers/staging/solo6x10/solo6010-enc.c
@@ -22,7 +22,7 @@
22#include "solo6010.h" 22#include "solo6010.h"
23#include "solo6010-osd-font.h" 23#include "solo6010-osd-font.h"
24 24
25#define CAPTURE_MAX_BANDWIDTH 32 // D1 4channel (D1 == 4) 25#define CAPTURE_MAX_BANDWIDTH 32 /* D1 4channel (D1 == 4) */
26#define OSG_BUFFER_SIZE 1024 26#define OSG_BUFFER_SIZE 1024
27 27
28#define VI_PROG_HSIZE (1280 - 16) 28#define VI_PROG_HSIZE (1280 - 16)
@@ -145,8 +145,8 @@ int solo_osd_print(struct solo_enc_dev *solo_enc)
145 145
146 solo_p2m_dma(solo_dev, 0, 1, buf, SOLO_EOSD_EXT_ADDR(solo_dev) + 146 solo_p2m_dma(solo_dev, 0, 1, buf, SOLO_EOSD_EXT_ADDR(solo_dev) +
147 (solo_enc->ch * SOLO_EOSD_EXT_SIZE), SOLO_EOSD_EXT_SIZE); 147 (solo_enc->ch * SOLO_EOSD_EXT_SIZE), SOLO_EOSD_EXT_SIZE);
148 reg |= (1 << solo_enc->ch); 148 reg |= (1 << solo_enc->ch);
149 solo_reg_write(solo_dev, SOLO_VE_OSD_CH, reg); 149 solo_reg_write(solo_dev, SOLO_VE_OSD_CH, reg);
150 150
151 kfree(buf); 151 kfree(buf);
152 152
diff --git a/drivers/staging/solo6x10/solo6010-g723.c b/drivers/staging/solo6x10/solo6010-g723.c
index 82fbcb845878..254b46ab20c5 100644
--- a/drivers/staging/solo6x10/solo6010-g723.c
+++ b/drivers/staging/solo6x10/solo6010-g723.c
@@ -47,7 +47,7 @@
47 * is broken down to 20 * 48 byte regions (one for each channel possible) 47 * is broken down to 20 * 48 byte regions (one for each channel possible)
48 * with the rest of the page being dummy data. */ 48 * with the rest of the page being dummy data. */
49#define MAX_BUFFER (G723_PERIOD_BYTES * PERIODS_MAX) 49#define MAX_BUFFER (G723_PERIOD_BYTES * PERIODS_MAX)
50#define IRQ_PAGES 4 // 0 - 4 50#define IRQ_PAGES 4 /* 0 - 4 */
51#define PERIODS_MIN (1 << IRQ_PAGES) 51#define PERIODS_MIN (1 << IRQ_PAGES)
52#define PERIODS_MAX G723_FDMA_PAGES 52#define PERIODS_MAX G723_FDMA_PAGES
53 53
@@ -158,7 +158,7 @@ static int snd_solo_pcm_close(struct snd_pcm_substream *ss)
158 snd_pcm_substream_chip(ss) = solo_pcm->solo_dev; 158 snd_pcm_substream_chip(ss) = solo_pcm->solo_dev;
159 kfree(solo_pcm); 159 kfree(solo_pcm);
160 160
161 return 0; 161 return 0;
162} 162}
163 163
164static int snd_solo_pcm_trigger(struct snd_pcm_substream *ss, int cmd) 164static int snd_solo_pcm_trigger(struct snd_pcm_substream *ss, int cmd)
@@ -197,7 +197,7 @@ static int snd_solo_pcm_trigger(struct snd_pcm_substream *ss, int cmd)
197 197
198static int snd_solo_pcm_prepare(struct snd_pcm_substream *ss) 198static int snd_solo_pcm_prepare(struct snd_pcm_substream *ss)
199{ 199{
200 return 0; 200 return 0;
201} 201}
202 202
203static snd_pcm_uframes_t snd_solo_pcm_pointer(struct snd_pcm_substream *ss) 203static snd_pcm_uframes_t snd_solo_pcm_pointer(struct snd_pcm_substream *ss)
@@ -271,7 +271,7 @@ static int snd_solo_capture_volume_get(struct snd_kcontrol *kcontrol,
271 271
272 value->value.integer.value[0] = tw28_get_audio_gain(solo_dev, ch); 272 value->value.integer.value[0] = tw28_get_audio_gain(solo_dev, ch);
273 273
274 return 0; 274 return 0;
275} 275}
276 276
277static int snd_solo_capture_volume_put(struct snd_kcontrol *kcontrol, 277static int snd_solo_capture_volume_put(struct snd_kcontrol *kcontrol,
@@ -279,15 +279,15 @@ static int snd_solo_capture_volume_put(struct snd_kcontrol *kcontrol,
279{ 279{
280 struct solo6010_dev *solo_dev = snd_kcontrol_chip(kcontrol); 280 struct solo6010_dev *solo_dev = snd_kcontrol_chip(kcontrol);
281 u8 ch = value->id.numid - 1; 281 u8 ch = value->id.numid - 1;
282 u8 old_val; 282 u8 old_val;
283 283
284 old_val = tw28_get_audio_gain(solo_dev, ch); 284 old_val = tw28_get_audio_gain(solo_dev, ch);
285 if (old_val == value->value.integer.value[0]) 285 if (old_val == value->value.integer.value[0])
286 return 0; 286 return 0;
287 287
288 tw28_set_audio_gain(solo_dev, ch, value->value.integer.value[0]); 288 tw28_set_audio_gain(solo_dev, ch, value->value.integer.value[0]);
289 289
290 return 1; 290 return 1;
291} 291}
292 292
293static struct snd_kcontrol_new snd_solo_capture_volume = { 293static struct snd_kcontrol_new snd_solo_capture_volume = {
@@ -368,14 +368,16 @@ int solo_g723_init(struct solo6010_dev *solo_dev)
368 strcpy(card->mixername, "SOLO-6010"); 368 strcpy(card->mixername, "SOLO-6010");
369 kctl = snd_solo_capture_volume; 369 kctl = snd_solo_capture_volume;
370 kctl.count = solo_dev->nr_chans; 370 kctl.count = solo_dev->nr_chans;
371 ret = snd_ctl_add(card, snd_ctl_new1(&kctl, solo_dev)); 371 ret = snd_ctl_add(card, snd_ctl_new1(&kctl, solo_dev));
372 if (ret < 0) 372 if (ret < 0)
373 return ret; 373 return ret;
374 374
375 if ((ret = solo_snd_pcm_init(solo_dev)) < 0) 375 ret = solo_snd_pcm_init(solo_dev);
376 if (ret < 0)
376 goto snd_error; 377 goto snd_error;
377 378
378 if ((ret = snd_card_register(card)) < 0) 379 ret = snd_card_register(card);
380 if (ret < 0)
379 goto snd_error; 381 goto snd_error;
380 382
381 solo_g723_config(solo_dev); 383 solo_g723_config(solo_dev);
diff --git a/drivers/staging/solo6x10/solo6010-gpio.c b/drivers/staging/solo6x10/solo6010-gpio.c
index 46f7a71edabc..8869b88dc307 100644
--- a/drivers/staging/solo6x10/solo6010-gpio.c
+++ b/drivers/staging/solo6x10/solo6010-gpio.c
@@ -92,8 +92,8 @@ static void solo_gpio_config(struct solo6010_dev *solo_dev)
92 92
93int solo_gpio_init(struct solo6010_dev *solo_dev) 93int solo_gpio_init(struct solo6010_dev *solo_dev)
94{ 94{
95 solo_gpio_config(solo_dev); 95 solo_gpio_config(solo_dev);
96 return 0; 96 return 0;
97} 97}
98 98
99void solo_gpio_exit(struct solo6010_dev *solo_dev) 99void solo_gpio_exit(struct solo6010_dev *solo_dev)
diff --git a/drivers/staging/solo6x10/solo6010-i2c.c b/drivers/staging/solo6x10/solo6010-i2c.c
index cadd5120d575..60b69cd0d09d 100644
--- a/drivers/staging/solo6x10/solo6010-i2c.c
+++ b/drivers/staging/solo6x10/solo6010-i2c.c
@@ -46,7 +46,7 @@ u8 solo_i2c_readbyte(struct solo6010_dev *solo_dev, int id, u8 addr, u8 off)
46 46
47 i2c_transfer(&solo_dev->i2c_adap[id], msgs, 2); 47 i2c_transfer(&solo_dev->i2c_adap[id], msgs, 2);
48 48
49 return data; 49 return data;
50} 50}
51 51
52void solo_i2c_writebyte(struct solo6010_dev *solo_dev, int id, u8 addr, 52void solo_i2c_writebyte(struct solo6010_dev *solo_dev, int id, u8 addr,
@@ -225,9 +225,9 @@ static int solo_i2c_master_xfer(struct i2c_adapter *adap,
225 } 225 }
226 226
227 if (i == SOLO_I2C_ADAPTERS) 227 if (i == SOLO_I2C_ADAPTERS)
228 return num; // XXX Right return value for failure? 228 return num; /* XXX Right return value for failure? */
229 229
230 down(&solo_dev->i2c_sem); 230 mutex_lock(&solo_dev->i2c_mutex);
231 solo_dev->i2c_id = i; 231 solo_dev->i2c_id = i;
232 solo_dev->i2c_msg = msgs; 232 solo_dev->i2c_msg = msgs;
233 solo_dev->i2c_msg_num = num; 233 solo_dev->i2c_msg_num = num;
@@ -258,7 +258,7 @@ static int solo_i2c_master_xfer(struct i2c_adapter *adap,
258 solo_dev->i2c_state = IIC_STATE_IDLE; 258 solo_dev->i2c_state = IIC_STATE_IDLE;
259 solo_dev->i2c_id = -1; 259 solo_dev->i2c_id = -1;
260 260
261 up(&solo_dev->i2c_sem); 261 mutex_unlock(&solo_dev->i2c_mutex);
262 262
263 return ret; 263 return ret;
264} 264}
@@ -284,7 +284,7 @@ int solo_i2c_init(struct solo6010_dev *solo_dev)
284 solo_dev->i2c_id = -1; 284 solo_dev->i2c_id = -1;
285 solo_dev->i2c_state = IIC_STATE_IDLE; 285 solo_dev->i2c_state = IIC_STATE_IDLE;
286 init_waitqueue_head(&solo_dev->i2c_wait); 286 init_waitqueue_head(&solo_dev->i2c_wait);
287 sema_init(&solo_dev->i2c_sem, 1); 287 mutex_init(&solo_dev->i2c_mutex);
288 288
289 for (i = 0; i < SOLO_I2C_ADAPTERS; i++) { 289 for (i = 0; i < SOLO_I2C_ADAPTERS; i++) {
290 struct i2c_adapter *adap = &solo_dev->i2c_adap[i]; 290 struct i2c_adapter *adap = &solo_dev->i2c_adap[i];
@@ -296,7 +296,8 @@ int solo_i2c_init(struct solo6010_dev *solo_dev)
296 adap->retries = 1; 296 adap->retries = 1;
297 adap->dev.parent = &solo_dev->pdev->dev; 297 adap->dev.parent = &solo_dev->pdev->dev;
298 298
299 if ((ret = i2c_add_adapter(adap))) { 299 ret = i2c_add_adapter(adap);
300 if (ret) {
300 adap->algo_data = NULL; 301 adap->algo_data = NULL;
301 break; 302 break;
302 } 303 }
diff --git a/drivers/staging/solo6x10/solo6010-osd-font.h b/drivers/staging/solo6x10/solo6010-osd-font.h
index d6f565bd76cc..d72efbb3bb3d 100644
--- a/drivers/staging/solo6x10/solo6010-osd-font.h
+++ b/drivers/staging/solo6x10/solo6010-osd-font.h
@@ -22,7 +22,7 @@
22 22
23static const unsigned int solo_osd_font[] = { 23static const unsigned int solo_osd_font[] = {
24 0x00000000, 0x0000c0c8, 0xccfefe0c, 0x08000000, 24 0x00000000, 0x0000c0c8, 0xccfefe0c, 0x08000000,
25 0x00000000, 0x10103838, 0x7c7cfefe, 0x00000000, // 0 25 0x00000000, 0x10103838, 0x7c7cfefe, 0x00000000, /* 0 */
26 0x00000000, 0xfefe7c7c, 0x38381010, 0x10000000, 26 0x00000000, 0xfefe7c7c, 0x38381010, 0x10000000,
27 0x00000000, 0x7c82fefe, 0xfefefe7c, 0x00000000, 27 0x00000000, 0x7c82fefe, 0xfefefe7c, 0x00000000,
28 0x00000000, 0x00001038, 0x10000000, 0x00000000, 28 0x00000000, 0x00001038, 0x10000000, 0x00000000,
@@ -54,67 +54,67 @@ static const unsigned int solo_osd_font[] = {
54 0x0000003f, 0x7f404c52, 0x524c407f, 0x00000000, 54 0x0000003f, 0x7f404c52, 0x524c407f, 0x00000000,
55 0x0000007c, 0x82ba82ba, 0x82ba82fe, 0x00000000, 55 0x0000007c, 0x82ba82ba, 0x82ba82fe, 0x00000000,
56 0x00000000, 0x00000000, 0x00000000, 0x00000000, 56 0x00000000, 0x00000000, 0x00000000, 0x00000000,
57 0x00000000, 0x183c3c3c, 0x18180018, 0x18000000, // 32 ! 57 0x00000000, 0x183c3c3c, 0x18180018, 0x18000000, /* 32 ! */
58 0x00000066, 0x66240000, 0x00000000, 0x00000000, 58 0x00000066, 0x66240000, 0x00000000, 0x00000000,
59 0x00000000, 0x6c6cfe6c, 0x6c6cfe6c, 0x6c000000, // 34 " # 59 0x00000000, 0x6c6cfe6c, 0x6c6cfe6c, 0x6c000000, /* 34 " # */
60 0x00001010, 0x7cd6d616, 0x7cd0d6d6, 0x7c101000, 60 0x00001010, 0x7cd6d616, 0x7cd0d6d6, 0x7c101000,
61 0x00000000, 0x0086c660, 0x30180cc6, 0xc2000000, // 36 $ % 61 0x00000000, 0x0086c660, 0x30180cc6, 0xc2000000, /* 36 $ % */
62 0x00000000, 0x386c6c38, 0xdc766666, 0xdc000000, 62 0x00000000, 0x386c6c38, 0xdc766666, 0xdc000000,
63 0x0000000c, 0x0c0c0600, 0x00000000, 0x00000000, // 38 & ' 63 0x0000000c, 0x0c0c0600, 0x00000000, 0x00000000, /* 38 & ' */
64 0x00000000, 0x30180c0c, 0x0c0c0c18, 0x30000000, 64 0x00000000, 0x30180c0c, 0x0c0c0c18, 0x30000000,
65 0x00000000, 0x0c183030, 0x30303018, 0x0c000000, // 40 ( ) 65 0x00000000, 0x0c183030, 0x30303018, 0x0c000000, /* 40 ( ) */
66 0x00000000, 0x0000663c, 0xff3c6600, 0x00000000, 66 0x00000000, 0x0000663c, 0xff3c6600, 0x00000000,
67 0x00000000, 0x00001818, 0x7e181800, 0x00000000, // 42 * + 67 0x00000000, 0x00001818, 0x7e181800, 0x00000000, /* 42 * + */
68 0x00000000, 0x00000000, 0x00000e0e, 0x0c060000, 68 0x00000000, 0x00000000, 0x00000e0e, 0x0c060000,
69 0x00000000, 0x00000000, 0x7e000000, 0x00000000, // 44 , - 69 0x00000000, 0x00000000, 0x7e000000, 0x00000000, /* 44 , - */
70 0x00000000, 0x00000000, 0x00000006, 0x06000000, 70 0x00000000, 0x00000000, 0x00000006, 0x06000000,
71 0x00000000, 0x80c06030, 0x180c0602, 0x00000000, // 46 . / 71 0x00000000, 0x80c06030, 0x180c0602, 0x00000000, /* 46 . / */
72 0x0000007c, 0xc6e6f6de, 0xcec6c67c, 0x00000000, 72 0x0000007c, 0xc6e6f6de, 0xcec6c67c, 0x00000000,
73 0x00000030, 0x383c3030, 0x303030fc, 0x00000000, // 48 0 1 73 0x00000030, 0x383c3030, 0x303030fc, 0x00000000, /* 48 0 1 */
74 0x0000007c, 0xc6c06030, 0x180cc6fe, 0x00000000, 74 0x0000007c, 0xc6c06030, 0x180cc6fe, 0x00000000,
75 0x0000007c, 0xc6c0c07c, 0xc0c0c67c, 0x00000000, // 50 2 3 75 0x0000007c, 0xc6c0c07c, 0xc0c0c67c, 0x00000000, /* 50 2 3 */
76 0x00000060, 0x70786c66, 0xfe6060f0, 0x00000000, 76 0x00000060, 0x70786c66, 0xfe6060f0, 0x00000000,
77 0x000000fe, 0x0606067e, 0xc0c0c67c, 0x00000000, // 52 4 5 77 0x000000fe, 0x0606067e, 0xc0c0c67c, 0x00000000, /* 52 4 5 */
78 0x00000038, 0x0c06067e, 0xc6c6c67c, 0x00000000, 78 0x00000038, 0x0c06067e, 0xc6c6c67c, 0x00000000,
79 0x000000fe, 0xc6c06030, 0x18181818, 0x00000000, // 54 6 7 79 0x000000fe, 0xc6c06030, 0x18181818, 0x00000000, /* 54 6 7 */
80 0x0000007c, 0xc6c6c67c, 0xc6c6c67c, 0x00000000, 80 0x0000007c, 0xc6c6c67c, 0xc6c6c67c, 0x00000000,
81 0x0000007c, 0xc6c6c6fc, 0xc0c06038, 0x00000000, // 56 8 9 81 0x0000007c, 0xc6c6c6fc, 0xc0c06038, 0x00000000, /* 56 8 9 */
82 0x00000000, 0x18180000, 0x00181800, 0x00000000, 82 0x00000000, 0x18180000, 0x00181800, 0x00000000,
83 0x00000000, 0x18180000, 0x0018180c, 0x00000000, // 58 : ; 83 0x00000000, 0x18180000, 0x0018180c, 0x00000000, /* 58 : ; */
84 0x00000060, 0x30180c06, 0x0c183060, 0x00000000, 84 0x00000060, 0x30180c06, 0x0c183060, 0x00000000,
85 0x00000000, 0x007e0000, 0x007e0000, 0x00000000, 85 0x00000000, 0x007e0000, 0x007e0000, 0x00000000,
86 0x00000006, 0x0c183060, 0x30180c06, 0x00000000, 86 0x00000006, 0x0c183060, 0x30180c06, 0x00000000,
87 0x0000007c, 0xc6c66030, 0x30003030, 0x00000000, 87 0x0000007c, 0xc6c66030, 0x30003030, 0x00000000,
88 0x0000007c, 0xc6f6d6d6, 0x7606067c, 0x00000000, 88 0x0000007c, 0xc6f6d6d6, 0x7606067c, 0x00000000,
89 0x00000010, 0x386cc6c6, 0xfec6c6c6, 0x00000000, // 64 @ A 89 0x00000010, 0x386cc6c6, 0xfec6c6c6, 0x00000000, /* 64 @ A */
90 0x0000007e, 0xc6c6c67e, 0xc6c6c67e, 0x00000000, 90 0x0000007e, 0xc6c6c67e, 0xc6c6c67e, 0x00000000,
91 0x00000078, 0xcc060606, 0x0606cc78, 0x00000000, // 66 91 0x00000078, 0xcc060606, 0x0606cc78, 0x00000000, /* 66 */
92 0x0000003e, 0x66c6c6c6, 0xc6c6663e, 0x00000000, 92 0x0000003e, 0x66c6c6c6, 0xc6c6663e, 0x00000000,
93 0x000000fe, 0x0606063e, 0x060606fe, 0x00000000, // 68 93 0x000000fe, 0x0606063e, 0x060606fe, 0x00000000, /* 68 */
94 0x000000fe, 0x0606063e, 0x06060606, 0x00000000, 94 0x000000fe, 0x0606063e, 0x06060606, 0x00000000,
95 0x00000078, 0xcc060606, 0xf6c6ccb8, 0x00000000, // 70 95 0x00000078, 0xcc060606, 0xf6c6ccb8, 0x00000000, /* 70 */
96 0x000000c6, 0xc6c6c6fe, 0xc6c6c6c6, 0x00000000, 96 0x000000c6, 0xc6c6c6fe, 0xc6c6c6c6, 0x00000000,
97 0x0000003c, 0x18181818, 0x1818183c, 0x00000000, // 72 97 0x0000003c, 0x18181818, 0x1818183c, 0x00000000, /* 72 */
98 0x00000060, 0x60606060, 0x6066663c, 0x00000000, 98 0x00000060, 0x60606060, 0x6066663c, 0x00000000,
99 0x000000c6, 0xc666361e, 0x3666c6c6, 0x00000000, // 74 99 0x000000c6, 0xc666361e, 0x3666c6c6, 0x00000000, /* 74 */
100 0x00000006, 0x06060606, 0x060606fe, 0x00000000, 100 0x00000006, 0x06060606, 0x060606fe, 0x00000000,
101 0x000000c6, 0xeefed6c6, 0xc6c6c6c6, 0x00000000, // 76 101 0x000000c6, 0xeefed6c6, 0xc6c6c6c6, 0x00000000, /* 76 */
102 0x000000c6, 0xcedefef6, 0xe6c6c6c6, 0x00000000, 102 0x000000c6, 0xcedefef6, 0xe6c6c6c6, 0x00000000,
103 0x00000038, 0x6cc6c6c6, 0xc6c66c38, 0x00000000, // 78 103 0x00000038, 0x6cc6c6c6, 0xc6c66c38, 0x00000000, /* 78 */
104 0x0000007e, 0xc6c6c67e, 0x06060606, 0x00000000, 104 0x0000007e, 0xc6c6c67e, 0x06060606, 0x00000000,
105 0x00000038, 0x6cc6c6c6, 0xc6d67c38, 0x60000000, // 80 105 0x00000038, 0x6cc6c6c6, 0xc6d67c38, 0x60000000, /* 80 */
106 0x0000007e, 0xc6c6c67e, 0x66c6c6c6, 0x00000000, 106 0x0000007e, 0xc6c6c67e, 0x66c6c6c6, 0x00000000,
107 0x0000007c, 0xc6c60c38, 0x60c6c67c, 0x00000000, // 82 107 0x0000007c, 0xc6c60c38, 0x60c6c67c, 0x00000000, /* 82 */
108 0x0000007e, 0x18181818, 0x18181818, 0x00000000, 108 0x0000007e, 0x18181818, 0x18181818, 0x00000000,
109 0x000000c6, 0xc6c6c6c6, 0xc6c6c67c, 0x00000000, // 84 109 0x000000c6, 0xc6c6c6c6, 0xc6c6c67c, 0x00000000, /* 84 */
110 0x000000c6, 0xc6c6c6c6, 0xc66c3810, 0x00000000, 110 0x000000c6, 0xc6c6c6c6, 0xc66c3810, 0x00000000,
111 0x000000c6, 0xc6c6c6c6, 0xd6d6fe6c, 0x00000000, // 86 111 0x000000c6, 0xc6c6c6c6, 0xd6d6fe6c, 0x00000000, /* 86 */
112 0x000000c6, 0xc6c66c38, 0x6cc6c6c6, 0x00000000, 112 0x000000c6, 0xc6c66c38, 0x6cc6c6c6, 0x00000000,
113 0x00000066, 0x66666666, 0x3c181818, 0x00000000, // 88 113 0x00000066, 0x66666666, 0x3c181818, 0x00000000, /* 88 */
114 0x000000fe, 0xc0603018, 0x0c0606fe, 0x00000000, 114 0x000000fe, 0xc0603018, 0x0c0606fe, 0x00000000,
115 0x0000003c, 0x0c0c0c0c, 0x0c0c0c3c, 0x00000000, // 90 115 0x0000003c, 0x0c0c0c0c, 0x0c0c0c3c, 0x00000000, /* 90 */
116 0x00000002, 0x060c1830, 0x60c08000, 0x00000000, 116 0x00000002, 0x060c1830, 0x60c08000, 0x00000000,
117 0x0000003c, 0x30303030, 0x3030303c, 0x00000000, // 92 117 0x0000003c, 0x30303030, 0x3030303c, 0x00000000, /* 92 */
118 0x00001038, 0x6cc60000, 0x00000000, 0x00000000, 118 0x00001038, 0x6cc60000, 0x00000000, 0x00000000,
119 0x00000000, 0x00000000, 0x00000000, 0x00fe0000, 119 0x00000000, 0x00000000, 0x00000000, 0x00fe0000,
120 0x00001818, 0x30000000, 0x00000000, 0x00000000, 120 0x00001818, 0x30000000, 0x00000000, 0x00000000,
diff --git a/drivers/staging/solo6x10/solo6010-p2m.c b/drivers/staging/solo6x10/solo6010-p2m.c
index 7ed3ed4b8f7e..956dea09348a 100644
--- a/drivers/staging/solo6x10/solo6010-p2m.c
+++ b/drivers/staging/solo6x10/solo6010-p2m.c
@@ -18,10 +18,11 @@
18 */ 18 */
19 19
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/scatterlist.h>
21 22
22#include "solo6010.h" 23#include "solo6010.h"
23 24
24// #define SOLO_TEST_P2M 25/* #define SOLO_TEST_P2M */
25 26
26int solo_p2m_dma(struct solo6010_dev *solo_dev, u8 id, int wr, 27int solo_p2m_dma(struct solo6010_dev *solo_dev, u8 id, int wr,
27 void *sys_addr, u32 ext_addr, u32 size) 28 void *sys_addr, u32 ext_addr, u32 size)
@@ -30,8 +31,9 @@ int solo_p2m_dma(struct solo6010_dev *solo_dev, u8 id, int wr,
30 int ret; 31 int ret;
31 32
32 WARN_ON(!size); 33 WARN_ON(!size);
33 WARN_ON(id >= SOLO_NR_P2M); 34 BUG_ON(id >= SOLO_NR_P2M);
34 if (!size || id >= SOLO_NR_P2M) 35
36 if (!size)
35 return -EINVAL; 37 return -EINVAL;
36 38
37 dma_addr = pci_map_single(solo_dev->pdev, sys_addr, size, 39 dma_addr = pci_map_single(solo_dev->pdev, sys_addr, size,
@@ -48,41 +50,136 @@ int solo_p2m_dma(struct solo6010_dev *solo_dev, u8 id, int wr,
48int solo_p2m_dma_t(struct solo6010_dev *solo_dev, u8 id, int wr, 50int solo_p2m_dma_t(struct solo6010_dev *solo_dev, u8 id, int wr,
49 dma_addr_t dma_addr, u32 ext_addr, u32 size) 51 dma_addr_t dma_addr, u32 ext_addr, u32 size)
50{ 52{
53 struct p2m_desc *desc = kzalloc(sizeof(*desc) * 2, GFP_DMA);
54 int ret;
55
56 if (desc == NULL)
57 return -ENOMEM;
58
59 solo_p2m_push_desc(&desc[1], wr, dma_addr, ext_addr, size, 0, 0);
60 ret = solo_p2m_dma_desc(solo_dev, id, desc, 2);
61 kfree(desc);
62
63 return ret;
64}
65
66void solo_p2m_push_desc(struct p2m_desc *desc, int wr, dma_addr_t dma_addr,
67 u32 ext_addr, u32 size, int repeat, u32 ext_size)
68{
69 desc->ta = dma_addr;
70 desc->fa = ext_addr;
71
72 desc->ext = SOLO_P2M_COPY_SIZE(size >> 2);
73 desc->ctrl = SOLO_P2M_BURST_SIZE(SOLO_P2M_BURST_256) |
74 (wr ? SOLO_P2M_WRITE : 0) | SOLO_P2M_TRANS_ON;
75
76 /* Ext size only matters when we're repeating */
77 if (repeat) {
78 desc->ext |= SOLO_P2M_EXT_INC(ext_size >> 2);
79 desc->ctrl |= SOLO_P2M_PCI_INC(size >> 2) |
80 SOLO_P2M_REPEAT(repeat);
81 }
82}
83
84int solo_p2m_dma_desc(struct solo6010_dev *solo_dev, u8 id,
85 struct p2m_desc *desc, int desc_count)
86{
51 struct solo_p2m_dev *p2m_dev; 87 struct solo_p2m_dev *p2m_dev;
52 unsigned int timeout = 0; 88 unsigned int timeout;
89 int ret = 0;
90 u32 config = 0;
91 dma_addr_t desc_dma = 0;
53 92
54 WARN_ON(!size); 93 BUG_ON(id >= SOLO_NR_P2M);
55 WARN_ON(id >= SOLO_NR_P2M); 94 BUG_ON(!desc_count || desc_count > SOLO_NR_P2M_DESC);
56 if (!size || id >= SOLO_NR_P2M)
57 return -EINVAL;
58 95
59 p2m_dev = &solo_dev->p2m_dev[id]; 96 p2m_dev = &solo_dev->p2m_dev[id];
60 97
61 down(&p2m_dev->sem); 98 mutex_lock(&p2m_dev->mutex);
99
100 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(id), 0);
62 101
63start_dma:
64 INIT_COMPLETION(p2m_dev->completion); 102 INIT_COMPLETION(p2m_dev->completion);
65 p2m_dev->error = 0; 103 p2m_dev->error = 0;
66 solo_reg_write(solo_dev, SOLO_P2M_TAR_ADR(id), dma_addr);
67 solo_reg_write(solo_dev, SOLO_P2M_EXT_ADR(id), ext_addr);
68 solo_reg_write(solo_dev, SOLO_P2M_EXT_CFG(id),
69 SOLO_P2M_COPY_SIZE(size >> 2));
70 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(id),
71 SOLO_P2M_BURST_SIZE(SOLO_P2M_BURST_256) |
72 (wr ? SOLO_P2M_WRITE : 0) | SOLO_P2M_TRANS_ON);
73 104
105 /* Enable the descriptors */
106 config = solo_reg_read(solo_dev, SOLO_P2M_CONFIG(id));
107 desc_dma = pci_map_single(solo_dev->pdev, desc,
108 desc_count * sizeof(*desc),
109 PCI_DMA_TODEVICE);
110 solo_reg_write(solo_dev, SOLO_P2M_DES_ADR(id), desc_dma);
111 solo_reg_write(solo_dev, SOLO_P2M_DESC_ID(id), desc_count - 1);
112 solo_reg_write(solo_dev, SOLO_P2M_CONFIG(id), config |
113 SOLO_P2M_DESC_MODE);
114
115 /* Should have all descriptors completed from one interrupt */
74 timeout = wait_for_completion_timeout(&p2m_dev->completion, HZ); 116 timeout = wait_for_completion_timeout(&p2m_dev->completion, HZ);
75 117
76 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(id), 0); 118 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(id), 0);
77 119
78 /* XXX Really looks to me like we will get stuck here if a 120 /* Reset back to non-descriptor mode */
79 * real PCI P2M error occurs */ 121 solo_reg_write(solo_dev, SOLO_P2M_CONFIG(id), config);
122 solo_reg_write(solo_dev, SOLO_P2M_DESC_ID(id), 0);
123 solo_reg_write(solo_dev, SOLO_P2M_DES_ADR(id), 0);
124 pci_unmap_single(solo_dev->pdev, desc_dma,
125 desc_count * sizeof(*desc),
126 PCI_DMA_TODEVICE);
127
80 if (p2m_dev->error) 128 if (p2m_dev->error)
81 goto start_dma; 129 ret = -EIO;
130 else if (timeout == 0)
131 ret = -EAGAIN;
132
133 mutex_unlock(&p2m_dev->mutex);
134
135 WARN_ON_ONCE(ret);
82 136
83 up(&p2m_dev->sem); 137 return ret;
138}
139
140int solo_p2m_dma_sg(struct solo6010_dev *solo_dev, u8 id,
141 struct p2m_desc *pdesc, int wr,
142 struct scatterlist *sg, u32 sg_off,
143 u32 ext_addr, u32 size)
144{
145 int i;
146 int idx;
147
148 BUG_ON(id >= SOLO_NR_P2M);
149
150 if (WARN_ON_ONCE(!size))
151 return -EINVAL;
152
153 memset(pdesc, 0, sizeof(*pdesc));
154
155 /* Should rewrite this to handle > SOLO_NR_P2M_DESC transactions */
156 for (i = 0, idx = 1; idx < SOLO_NR_P2M_DESC && sg && size > 0;
157 i++, sg = sg_next(sg)) {
158 struct p2m_desc *desc = &pdesc[idx];
159 u32 sg_len = sg_dma_len(sg);
160 u32 len;
84 161
85 return (timeout == 0) ? -EAGAIN : 0; 162 if (sg_off >= sg_len) {
163 sg_off -= sg_len;
164 continue;
165 }
166
167 sg_len -= sg_off;
168 len = min(sg_len, size);
169
170 solo_p2m_push_desc(desc, wr, sg_dma_address(sg) + sg_off,
171 ext_addr, len, 0, 0);
172
173 size -= len;
174 ext_addr += len;
175 idx++;
176
177 sg_off = 0;
178 }
179
180 WARN_ON_ONCE(size || i >= SOLO_NR_P2M_DESC);
181
182 return solo_p2m_dma_desc(solo_dev, id, pdesc, idx);
86} 183}
87 184
88#ifdef SOLO_TEST_P2M 185#ifdef SOLO_TEST_P2M
@@ -147,13 +244,16 @@ static void run_p2m_test(struct solo6010_dev *solo_dev)
147 return; 244 return;
148} 245}
149#else 246#else
150#define run_p2m_test(__solo) do{}while(0) 247#define run_p2m_test(__solo) do {} while (0)
151#endif 248#endif
152 249
153void solo_p2m_isr(struct solo6010_dev *solo_dev, int id) 250void solo_p2m_isr(struct solo6010_dev *solo_dev, int id)
154{ 251{
252 struct solo_p2m_dev *p2m_dev = &solo_dev->p2m_dev[id];
253
155 solo_reg_write(solo_dev, SOLO_IRQ_STAT, SOLO_IRQ_P2M(id)); 254 solo_reg_write(solo_dev, SOLO_IRQ_STAT, SOLO_IRQ_P2M(id));
156 complete(&solo_dev->p2m_dev[id].completion); 255
256 complete(&p2m_dev->completion);
157} 257}
158 258
159void solo_p2m_error_isr(struct solo6010_dev *solo_dev, u32 status) 259void solo_p2m_error_isr(struct solo6010_dev *solo_dev, u32 status)
@@ -188,16 +288,14 @@ int solo_p2m_init(struct solo6010_dev *solo_dev)
188 for (i = 0; i < SOLO_NR_P2M; i++) { 288 for (i = 0; i < SOLO_NR_P2M; i++) {
189 p2m_dev = &solo_dev->p2m_dev[i]; 289 p2m_dev = &solo_dev->p2m_dev[i];
190 290
191 sema_init(&p2m_dev->sem, 1); 291 mutex_init(&p2m_dev->mutex);
192 init_completion(&p2m_dev->completion); 292 init_completion(&p2m_dev->completion);
193 293
194 solo_reg_write(solo_dev, SOLO_P2M_DES_ADR(i),
195 __pa(p2m_dev->desc));
196
197 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(i), 0); 294 solo_reg_write(solo_dev, SOLO_P2M_CONTROL(i), 0);
198 solo_reg_write(solo_dev, SOLO_P2M_CONFIG(i), 295 solo_reg_write(solo_dev, SOLO_P2M_CONFIG(i),
199 SOLO_P2M_CSC_16BIT_565 | 296 SOLO_P2M_CSC_16BIT_565 |
200 SOLO_P2M_DMA_INTERVAL(0) | 297 SOLO_P2M_DMA_INTERVAL(3) |
298 SOLO_P2M_DESC_INTR_OPT |
201 SOLO_P2M_PCI_MASTER_MODE); 299 SOLO_P2M_PCI_MASTER_MODE);
202 solo6010_irq_on(solo_dev, SOLO_IRQ_P2M(i)); 300 solo6010_irq_on(solo_dev, SOLO_IRQ_P2M(i));
203 } 301 }
diff --git a/drivers/staging/solo6x10/solo6010-tw28.c b/drivers/staging/solo6x10/solo6010-tw28.c
index 0159c8392436..905a6ad23a37 100644
--- a/drivers/staging/solo6x10/solo6010-tw28.c
+++ b/drivers/staging/solo6x10/solo6010-tw28.c
@@ -35,107 +35,107 @@
35#define DEFAULT_VACTIVE_PAL (312-DEFAULT_VDELAY_PAL) 35#define DEFAULT_VACTIVE_PAL (312-DEFAULT_VDELAY_PAL)
36 36
37static u8 tbl_tw2864_template[] = { 37static u8 tbl_tw2864_template[] = {
38 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, // 0x00 38 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x00 */
39 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 39 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
40 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, // 0x10 40 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x10 */
41 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 41 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
42 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, // 0x20 42 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x20 */
43 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 43 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
44 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, // 0x30 44 0x00, 0x00, 0x80, 0x10, 0x80, 0x80, 0x00, 0x02, /* 0x30 */
45 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 45 0x12, 0xf5, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x40 46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 */
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x50 48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50 */
49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x60 50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x70 52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x70 */
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA3, 0x00, 53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA3, 0x00,
54 0x00, 0x02, 0x00, 0xcc, 0x00, 0x80, 0x44, 0x50, // 0x80 54 0x00, 0x02, 0x00, 0xcc, 0x00, 0x80, 0x44, 0x50, /* 0x80 */
55 0x22, 0x01, 0xd8, 0xbc, 0xb8, 0x44, 0x38, 0x00, 55 0x22, 0x01, 0xd8, 0xbc, 0xb8, 0x44, 0x38, 0x00,
56 0x00, 0x78, 0x72, 0x3e, 0x14, 0xa5, 0xe4, 0x05, // 0x90 56 0x00, 0x78, 0x72, 0x3e, 0x14, 0xa5, 0xe4, 0x05, /* 0x90 */
57 0x00, 0x28, 0x44, 0x44, 0xa0, 0x88, 0x5a, 0x01, 57 0x00, 0x28, 0x44, 0x44, 0xa0, 0x88, 0x5a, 0x01,
58 0x08, 0x08, 0x08, 0x08, 0x1a, 0x1a, 0x1a, 0x1a, // 0xa0 58 0x08, 0x08, 0x08, 0x08, 0x1a, 0x1a, 0x1a, 0x1a, /* 0xa0 */
59 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x44, 59 0x00, 0x00, 0x00, 0xf0, 0xf0, 0xf0, 0xf0, 0x44,
60 0x44, 0x0a, 0x00, 0xff, 0xef, 0xef, 0xef, 0xef, // 0xb0 60 0x44, 0x0a, 0x00, 0xff, 0xef, 0xef, 0xef, 0xef, /* 0xb0 */
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xc0 62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */
63 0x00, 0x00, 0x55, 0x00, 0xb1, 0xe4, 0x40, 0x00, 63 0x00, 0x00, 0x55, 0x00, 0xb1, 0xe4, 0x40, 0x00,
64 0x77, 0x77, 0x01, 0x13, 0x57, 0x9b, 0xdf, 0x20, // 0xd0 64 0x77, 0x77, 0x01, 0x13, 0x57, 0x9b, 0xdf, 0x20, /* 0xd0 */
65 0x64, 0xa8, 0xec, 0xd1, 0x0f, 0x11, 0x11, 0x81, 65 0x64, 0xa8, 0xec, 0xd1, 0x0f, 0x11, 0x11, 0x81,
66 0x10, 0xe0, 0xbb, 0xbb, 0x00, 0x11, 0x00, 0x00, // 0xe0 66 0x10, 0xe0, 0xbb, 0xbb, 0x00, 0x11, 0x00, 0x00, /* 0xe0 */
67 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00, 67 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00,
68 0x83, 0xb5, 0x09, 0x78, 0x85, 0x00, 0x01, 0x20, // 0xf0 68 0x83, 0xb5, 0x09, 0x78, 0x85, 0x00, 0x01, 0x20, /* 0xf0 */
69 0x64, 0x11, 0x40, 0xaf, 0xff, 0x00, 0x00, 0x00, 69 0x64, 0x11, 0x40, 0xaf, 0xff, 0x00, 0x00, 0x00,
70}; 70};
71 71
72static u8 tbl_tw2865_ntsc_template[] = { 72static u8 tbl_tw2865_ntsc_template[] = {
73 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, // 0x00 73 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x00 */
74 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 74 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
75 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, // 0x10 75 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x10 */
76 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 76 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
77 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, // 0x20 77 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x02, /* 0x20 */
78 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 78 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
79 0x00, 0xf0, 0x70, 0x48, 0x80, 0x80, 0x00, 0x02, // 0x30 79 0x00, 0xf0, 0x70, 0x48, 0x80, 0x80, 0x00, 0x02, /* 0x30 */
80 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f, 80 0x12, 0xff, 0x09, 0xd0, 0x00, 0x00, 0x00, 0x7f,
81 0x00, 0x00, 0x90, 0x68, 0x00, 0x38, 0x80, 0x80, // 0x40 81 0x00, 0x00, 0x90, 0x68, 0x00, 0x38, 0x80, 0x80, /* 0x40 */
82 0x80, 0x80, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 82 0x80, 0x80, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x50 83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50 */
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x45, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x60 85 0x45, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x43, 86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x43,
87 0x08, 0x00, 0x00, 0x01, 0xf1, 0x03, 0xEF, 0x03, // 0x70 87 0x08, 0x00, 0x00, 0x01, 0xf1, 0x03, 0xEF, 0x03, /* 0x70 */
88 0xE9, 0x03, 0xD9, 0x15, 0x15, 0xE4, 0xA3, 0x80, 88 0xE9, 0x03, 0xD9, 0x15, 0x15, 0xE4, 0xA3, 0x80,
89 0x00, 0x02, 0x00, 0xCC, 0x00, 0x80, 0x44, 0x50, // 0x80 89 0x00, 0x02, 0x00, 0xCC, 0x00, 0x80, 0x44, 0x50, /* 0x80 */
90 0x22, 0x01, 0xD8, 0xBC, 0xB8, 0x44, 0x38, 0x00, 90 0x22, 0x01, 0xD8, 0xBC, 0xB8, 0x44, 0x38, 0x00,
91 0x00, 0x78, 0x44, 0x3D, 0x14, 0xA5, 0xE0, 0x05, // 0x90 91 0x00, 0x78, 0x44, 0x3D, 0x14, 0xA5, 0xE0, 0x05, /* 0x90 */
92 0x00, 0x28, 0x44, 0x44, 0xA0, 0x90, 0x52, 0x13, 92 0x00, 0x28, 0x44, 0x44, 0xA0, 0x90, 0x52, 0x13,
93 0x08, 0x08, 0x08, 0x08, 0x1A, 0x1A, 0x1B, 0x1A, // 0xa0 93 0x08, 0x08, 0x08, 0x08, 0x1A, 0x1A, 0x1B, 0x1A, /* 0xa0 */
94 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x44, 94 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x44,
95 0x44, 0x4A, 0x00, 0xFF, 0xEF, 0xEF, 0xEF, 0xEF, // 0xb0 95 0x44, 0x4A, 0x00, 0xFF, 0xEF, 0xEF, 0xEF, 0xEF, /* 0xb0 */
96 0xFF, 0xE7, 0xE9, 0xE9, 0xEB, 0xFF, 0xD6, 0xD8, 96 0xFF, 0xE7, 0xE9, 0xE9, 0xEB, 0xFF, 0xD6, 0xD8,
97 0xD8, 0xD7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xc0 97 0xD8, 0xD7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */
98 0x00, 0x00, 0x55, 0x00, 0xE4, 0x39, 0x00, 0x80, 98 0x00, 0x00, 0x55, 0x00, 0xE4, 0x39, 0x00, 0x80,
99 0x77, 0x77, 0x03, 0x20, 0x57, 0x9b, 0xdf, 0x31, // 0xd0 99 0x77, 0x77, 0x03, 0x20, 0x57, 0x9b, 0xdf, 0x31, /* 0xd0 */
100 0x64, 0xa8, 0xec, 0xd1, 0x0f, 0x11, 0x11, 0x81, 100 0x64, 0xa8, 0xec, 0xd1, 0x0f, 0x11, 0x11, 0x81,
101 0x10, 0xC0, 0xAA, 0xAA, 0x00, 0x11, 0x00, 0x00, // 0xe0 101 0x10, 0xC0, 0xAA, 0xAA, 0x00, 0x11, 0x00, 0x00, /* 0xe0 */
102 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00, 102 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00,
103 0x83, 0xB5, 0x09, 0x78, 0x85, 0x00, 0x01, 0x20, // 0xf0 103 0x83, 0xB5, 0x09, 0x78, 0x85, 0x00, 0x01, 0x20, /* 0xf0 */
104 0x64, 0x51, 0x40, 0xaf, 0xFF, 0xF0, 0x00, 0xC0, 104 0x64, 0x51, 0x40, 0xaf, 0xFF, 0xF0, 0x00, 0xC0,
105}; 105};
106 106
107static u8 tbl_tw2865_pal_template[] = { 107static u8 tbl_tw2865_pal_template[] = {
108 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, // 0x00 108 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x00 */
109 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f, 109 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f,
110 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, // 0x10 110 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x10 */
111 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f, 111 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f,
112 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, // 0x20 112 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x20 */
113 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f, 113 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f,
114 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, // 0x30 114 0x00, 0xf0, 0x70, 0x30, 0x80, 0x80, 0x00, 0x12, /* 0x30 */
115 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f, 115 0x11, 0xff, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x7f,
116 0x00, 0x94, 0x90, 0x48, 0x00, 0x38, 0x7F, 0x80, // 0x40 116 0x00, 0x94, 0x90, 0x48, 0x00, 0x38, 0x7F, 0x80, /* 0x40 */
117 0x80, 0x80, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 117 0x80, 0x80, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00,
118 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x50 118 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x50 */
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120 0x45, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x60 120 0x45, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x60 */
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x43, 121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x43,
122 0x08, 0x00, 0x00, 0x01, 0xf1, 0x03, 0xEF, 0x03, // 0x70 122 0x08, 0x00, 0x00, 0x01, 0xf1, 0x03, 0xEF, 0x03, /* 0x70 */
123 0xEA, 0x03, 0xD9, 0x15, 0x15, 0xE4, 0xA3, 0x80, 123 0xEA, 0x03, 0xD9, 0x15, 0x15, 0xE4, 0xA3, 0x80,
124 0x00, 0x02, 0x00, 0xCC, 0x00, 0x80, 0x44, 0x50, // 0x80 124 0x00, 0x02, 0x00, 0xCC, 0x00, 0x80, 0x44, 0x50, /* 0x80 */
125 0x22, 0x01, 0xD8, 0xBC, 0xB8, 0x44, 0x38, 0x00, 125 0x22, 0x01, 0xD8, 0xBC, 0xB8, 0x44, 0x38, 0x00,
126 0x00, 0x78, 0x44, 0x3D, 0x14, 0xA5, 0xE0, 0x05, // 0x90 126 0x00, 0x78, 0x44, 0x3D, 0x14, 0xA5, 0xE0, 0x05, /* 0x90 */
127 0x00, 0x28, 0x44, 0x44, 0xA0, 0x90, 0x52, 0x13, 127 0x00, 0x28, 0x44, 0x44, 0xA0, 0x90, 0x52, 0x13,
128 0x08, 0x08, 0x08, 0x08, 0x1A, 0x1A, 0x1A, 0x1A, // 0xa0 128 0x08, 0x08, 0x08, 0x08, 0x1A, 0x1A, 0x1A, 0x1A, /* 0xa0 */
129 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x44, 129 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x44,
130 0x44, 0x4A, 0x00, 0xFF, 0xEF, 0xEF, 0xEF, 0xEF, // 0xb0 130 0x44, 0x4A, 0x00, 0xFF, 0xEF, 0xEF, 0xEF, 0xEF, /* 0xb0 */
131 0xFF, 0xE7, 0xE9, 0xE9, 0xE9, 0xFF, 0xD7, 0xD8, 131 0xFF, 0xE7, 0xE9, 0xE9, 0xE9, 0xFF, 0xD7, 0xD8,
132 0xD9, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xc0 132 0xD9, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc0 */
133 0x00, 0x00, 0x55, 0x00, 0xE4, 0x39, 0x00, 0x80, 133 0x00, 0x00, 0x55, 0x00, 0xE4, 0x39, 0x00, 0x80,
134 0x77, 0x77, 0x03, 0x20, 0x57, 0x9b, 0xdf, 0x31, // 0xd0 134 0x77, 0x77, 0x03, 0x20, 0x57, 0x9b, 0xdf, 0x31, /* 0xd0 */
135 0x64, 0xa8, 0xec, 0xd1, 0x0f, 0x11, 0x11, 0x81, 135 0x64, 0xa8, 0xec, 0xd1, 0x0f, 0x11, 0x11, 0x81,
136 0x10, 0xC0, 0xAA, 0xAA, 0x00, 0x11, 0x00, 0x00, // 0xe0 136 0x10, 0xC0, 0xAA, 0xAA, 0x00, 0x11, 0x00, 0x00, /* 0xe0 */
137 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00, 137 0x11, 0x00, 0x00, 0x11, 0x00, 0x00, 0x11, 0x00,
138 0x83, 0xB5, 0x09, 0x00, 0xA0, 0x00, 0x01, 0x20, // 0xf0 138 0x83, 0xB5, 0x09, 0x00, 0xA0, 0x00, 0x01, 0x20, /* 0xf0 */
139 0x64, 0x51, 0x40, 0xaf, 0xFF, 0xF0, 0x00, 0xC0, 139 0x64, 0x51, 0x40, 0xaf, 0xFF, 0xF0, 0x00, 0xC0,
140}; 140};
141 141
@@ -181,8 +181,8 @@ static void tw_write_and_verify(struct solo6010_dev *solo_dev, u8 addr, u8 off,
181 msleep_interruptible(1); 181 msleep_interruptible(1);
182 } 182 }
183 183
184// printk("solo6010/tw28: Error writing register: %02x->%02x [%02x]\n", 184/* printk("solo6010/tw28: Error writing register: %02x->%02x [%02x]\n",
185// addr, off, val); 185 addr, off, val); */
186} 186}
187 187
188static int tw2865_setup(struct solo6010_dev *solo_dev, u8 dev_addr) 188static int tw2865_setup(struct solo6010_dev *solo_dev, u8 dev_addr)
@@ -217,7 +217,7 @@ static int tw2865_setup(struct solo6010_dev *solo_dev, u8 dev_addr)
217 217
218 for (i = 0; i < 0xff; i++) { 218 for (i = 0; i < 0xff; i++) {
219 /* Skip read only registers */ 219 /* Skip read only registers */
220 if (i >= 0xb8 && i <= 0xc1 ) 220 if (i >= 0xb8 && i <= 0xc1)
221 continue; 221 continue;
222 if ((i & ~0x30) == 0x00 || 222 if ((i & ~0x30) == 0x00 ||
223 (i & ~0x30) == 0x0c || 223 (i & ~0x30) == 0x0c ||
@@ -302,7 +302,7 @@ static int tw2864_setup(struct solo6010_dev *solo_dev, u8 dev_addr)
302 302
303 for (i = 0; i < 0xff; i++) { 303 for (i = 0; i < 0xff; i++) {
304 /* Skip read only registers */ 304 /* Skip read only registers */
305 if (i >= 0xb8 && i <= 0xc1 ) 305 if (i >= 0xb8 && i <= 0xc1)
306 continue; 306 continue;
307 if ((i & ~0x30) == 0x00 || 307 if ((i & ~0x30) == 0x00 ||
308 (i & ~0x30) == 0x0c || 308 (i & ~0x30) == 0x0c ||
@@ -334,13 +334,13 @@ static int tw2815_setup(struct solo6010_dev *solo_dev, u8 dev_addr)
334 }; 334 };
335 335
336 u8 tbl_tw2815_sfr[] = { 336 u8 tbl_tw2815_sfr[] = {
337 0x00, 0x00, 0x00, 0xc0, 0x45, 0xa0, 0xd0, 0x2f, // 0x00 337 0x00, 0x00, 0x00, 0xc0, 0x45, 0xa0, 0xd0, 0x2f, /* 0x00 */
338 0x64, 0x80, 0x80, 0x82, 0x82, 0x00, 0x00, 0x00, 338 0x64, 0x80, 0x80, 0x82, 0x82, 0x00, 0x00, 0x00,
339 0x00, 0x0f, 0x05, 0x00, 0x00, 0x80, 0x06, 0x00, // 0x10 339 0x00, 0x0f, 0x05, 0x00, 0x00, 0x80, 0x06, 0x00, /* 0x10 */
340 0x00, 0x00, 0x00, 0xff, 0x8f, 0x00, 0x00, 0x00, 340 0x00, 0x00, 0x00, 0xff, 0x8f, 0x00, 0x00, 0x00,
341 0x88, 0x88, 0xc0, 0x00, 0x20, 0x64, 0xa8, 0xec, // 0x20 341 0x88, 0x88, 0xc0, 0x00, 0x20, 0x64, 0xa8, 0xec, /* 0x20 */
342 0x31, 0x75, 0xb9, 0xfd, 0x00, 0x00, 0x88, 0x88, 342 0x31, 0x75, 0xb9, 0xfd, 0x00, 0x00, 0x88, 0x88,
343 0x88, 0x11, 0x00, 0x88, 0x88, 0x00, // 0x30 343 0x88, 0x11, 0x00, 0x88, 0x88, 0x00, /* 0x30 */
344 }; 344 };
345 u8 *tbl_tw2815_common; 345 u8 *tbl_tw2815_common;
346 int i; 346 int i;
@@ -459,7 +459,7 @@ static int tw2815_setup(struct solo6010_dev *solo_dev, u8 dev_addr)
459 459
460 for (i = 0; i < 0x0f; i++) { 460 for (i = 0; i < 0x0f; i++) {
461 if (i == 0x00) 461 if (i == 0x00)
462 continue; // read-only 462 continue; /* read-only */
463 solo_i2c_writebyte(solo_dev, SOLO_I2C_TW, 463 solo_i2c_writebyte(solo_dev, SOLO_I2C_TW,
464 dev_addr, (ch * 0x10) + i, 464 dev_addr, (ch * 0x10) + i,
465 tbl_tw2815_common[i]); 465 tbl_tw2815_common[i]);
@@ -597,7 +597,7 @@ int solo_tw28_init(struct solo6010_dev *solo_dev)
597 return 0; 597 return 0;
598} 598}
599 599
600/* 600/*
601 * We accessed the video status signal in the Techwell chip through 601 * We accessed the video status signal in the Techwell chip through
602 * iic/i2c because the video status reported by register REG_VI_STATUS1 602 * iic/i2c because the video status reported by register REG_VI_STATUS1
603 * (address 0x012C) of the SOLO6010 chip doesn't give the correct video 603 * (address 0x012C) of the SOLO6010 chip doesn't give the correct video
@@ -751,7 +751,7 @@ int tw28_get_ctrl_val(struct solo6010_dev *solo_dev, u32 ctrl, u8 ch,
751 rval = tw_readbyte(solo_dev, chip_num, 751 rval = tw_readbyte(solo_dev, chip_num,
752 TW286x_BRIGHTNESS_ADDR(ch), 752 TW286x_BRIGHTNESS_ADDR(ch),
753 TW_BRIGHTNESS_ADDR(ch)); 753 TW_BRIGHTNESS_ADDR(ch));
754 if (is_tw286x(solo_dev, chip_num)) 754 if (is_tw286x(solo_dev, chip_num))
755 *val = (s32)((char)rval) + 128; 755 *val = (s32)((char)rval) + 128;
756 else 756 else
757 *val = rval; 757 *val = rval;
diff --git a/drivers/staging/solo6x10/solo6010-v4l2-enc.c b/drivers/staging/solo6x10/solo6010-v4l2-enc.c
index 097e82bc7a63..7bbb94097d29 100644
--- a/drivers/staging/solo6x10/solo6010-v4l2-enc.c
+++ b/drivers/staging/solo6x10/solo6010-v4l2-enc.c
@@ -24,7 +24,7 @@
24 24
25#include <media/v4l2-ioctl.h> 25#include <media/v4l2-ioctl.h>
26#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
27#include <media/videobuf-dma-contig.h> 27#include <media/videobuf-dma-sg.h>
28 28
29#include "solo6010.h" 29#include "solo6010.h"
30#include "solo6010-tw28.h" 30#include "solo6010-tw28.h"
@@ -47,13 +47,14 @@ struct solo_enc_fh {
47 struct videobuf_queue vidq; 47 struct videobuf_queue vidq;
48 struct list_head vidq_active; 48 struct list_head vidq_active;
49 struct task_struct *kthread; 49 struct task_struct *kthread;
50 struct p2m_desc desc[SOLO_NR_P2M_DESC];
50}; 51};
51 52
52static unsigned char vid_vop_header[] = { 53static unsigned char vid_vop_header[] = {
53 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20, 54 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
54 0x02, 0x48, 0x05, 0xc0, 0x00, 0x40, 0x00, 0x40, 55 0x02, 0x48, 0x05, 0xc0, 0x00, 0x40, 0x00, 0x40,
55 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04, 56 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
56 0x1f, 0x4c, 0x58, 0x10, 0x78, 0x51, 0x18, 0x3e, 57 0x1f, 0x4c, 0x58, 0x10, 0x78, 0x51, 0x18, 0x3f,
57}; 58};
58 59
59/* 60/*
@@ -151,6 +152,11 @@ static void solo_motion_toggle(struct solo_enc_dev *solo_enc, int on)
151 else 152 else
152 solo_dev->motion_mask &= ~(1 << ch); 153 solo_dev->motion_mask &= ~(1 << ch);
153 154
155 /* Do this regardless of if we are turning on or off */
156 solo_reg_write(solo_enc->solo_dev, SOLO_VI_MOT_CLEAR,
157 1 << solo_enc->ch);
158 solo_enc->motion_detected = 0;
159
154 solo_reg_write(solo_dev, SOLO_VI_MOT_ADR, 160 solo_reg_write(solo_dev, SOLO_VI_MOT_ADR,
155 SOLO_VI_MOTION_EN(solo_dev->motion_mask) | 161 SOLO_VI_MOTION_EN(solo_dev->motion_mask) |
156 (SOLO_MOTION_EXT_ADDR(solo_dev) >> 16)); 162 (SOLO_MOTION_EXT_ADDR(solo_dev) >> 16));
@@ -184,7 +190,7 @@ static void solo_update_mode(struct solo_enc_dev *solo_enc)
184 solo_enc->bw_weight <<= 2; 190 solo_enc->bw_weight <<= 2;
185 break; 191 break;
186 default: 192 default:
187 WARN(1, "mode is unknown"); 193 WARN(1, "mode is unknown\n");
188 } 194 }
189} 195}
190 196
@@ -211,11 +217,6 @@ static int solo_enc_on(struct solo_enc_fh *fh)
211 solo_dev->enc_bw_remain -= solo_enc->bw_weight; 217 solo_dev->enc_bw_remain -= solo_enc->bw_weight;
212 } 218 }
213 219
214 fh->kthread = kthread_run(solo_enc_thread, fh, SOLO6010_NAME "_enc");
215
216 if (IS_ERR(fh->kthread))
217 return PTR_ERR(fh->kthread);
218
219 fh->enc_on = 1; 220 fh->enc_on = 1;
220 fh->rd_idx = solo_enc->solo_dev->enc_wr_idx; 221 fh->rd_idx = solo_enc->solo_dev->enc_wr_idx;
221 222
@@ -279,6 +280,24 @@ static void solo_enc_off(struct solo_enc_fh *fh)
279 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(solo_enc->ch), 0); 280 solo_reg_write(solo_dev, SOLO_CAP_CH_COMP_ENA_E(solo_enc->ch), 0);
280} 281}
281 282
283static int solo_start_fh_thread(struct solo_enc_fh *fh)
284{
285 struct solo_enc_dev *solo_enc = fh->enc;
286
287 fh->kthread = kthread_run(solo_enc_thread, fh, SOLO6010_NAME "_enc");
288
289 /* Oops, we had a problem */
290 if (IS_ERR(fh->kthread)) {
291 spin_lock(&solo_enc->lock);
292 solo_enc_off(fh);
293 spin_unlock(&solo_enc->lock);
294
295 return PTR_ERR(fh->kthread);
296 }
297
298 return 0;
299}
300
282static void enc_reset_gop(struct solo6010_dev *solo_dev, u8 ch) 301static void enc_reset_gop(struct solo6010_dev *solo_dev, u8 ch)
283{ 302{
284 BUG_ON(ch >= solo_dev->nr_chans); 303 BUG_ON(ch >= solo_dev->nr_chans);
@@ -299,22 +318,68 @@ static int enc_gop_reset(struct solo6010_dev *solo_dev, u8 ch, u8 vop)
299 return 0; 318 return 0;
300} 319}
301 320
302static int enc_get_mpeg_dma_t(struct solo6010_dev *solo_dev, dma_addr_t buf, 321static void enc_write_sg(struct scatterlist *sglist, void *buf, int size)
303 unsigned int off, unsigned int size) 322{
323 struct scatterlist *sg;
324 u8 *src = buf;
325
326 for (sg = sglist; sg && size > 0; sg = sg_next(sg)) {
327 u8 *p = sg_virt(sg);
328 size_t len = sg_dma_len(sg);
329 int i;
330
331 for (i = 0; i < len && size; i++)
332 p[i] = *(src++);
333 }
334}
335
336static int enc_get_mpeg_dma_sg(struct solo6010_dev *solo_dev,
337 struct p2m_desc *desc,
338 struct scatterlist *sglist, int skip,
339 unsigned int off, unsigned int size)
304{ 340{
305 int ret; 341 int ret;
306 342
307 if (off > SOLO_MP4E_EXT_SIZE(solo_dev)) 343 if (off > SOLO_MP4E_EXT_SIZE(solo_dev))
308 return -EINVAL; 344 return -EINVAL;
309 345
310 if (off + size <= SOLO_MP4E_EXT_SIZE(solo_dev)) 346 if (off + size <= SOLO_MP4E_EXT_SIZE(solo_dev)) {
347 return solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_MP4E,
348 desc, 0, sglist, skip,
349 SOLO_MP4E_EXT_ADDR(solo_dev) + off, size);
350 }
351
352 /* Buffer wrap */
353 ret = solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_MP4E, desc, 0,
354 sglist, skip, SOLO_MP4E_EXT_ADDR(solo_dev) + off,
355 SOLO_MP4E_EXT_SIZE(solo_dev) - off);
356
357 ret |= solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_MP4E, desc, 0,
358 sglist, skip + SOLO_MP4E_EXT_SIZE(solo_dev) - off,
359 SOLO_MP4E_EXT_ADDR(solo_dev),
360 size + off - SOLO_MP4E_EXT_SIZE(solo_dev));
361
362 return ret;
363}
364
365static int enc_get_mpeg_dma_t(struct solo6010_dev *solo_dev,
366 dma_addr_t buf, unsigned int off,
367 unsigned int size)
368{
369 int ret;
370
371 if (off > SOLO_MP4E_EXT_SIZE(solo_dev))
372 return -EINVAL;
373
374 if (off + size <= SOLO_MP4E_EXT_SIZE(solo_dev)) {
311 return solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_MP4E, 0, buf, 375 return solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_MP4E, 0, buf,
312 SOLO_MP4E_EXT_ADDR(solo_dev) + off, size); 376 SOLO_MP4E_EXT_ADDR(solo_dev) + off, size);
377 }
313 378
314 /* Buffer wrap */ 379 /* Buffer wrap */
315 ret = solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_MP4E, 0, buf, 380 ret = solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_MP4E, 0, buf,
316 SOLO_MP4E_EXT_ADDR(solo_dev) + off, 381 SOLO_MP4E_EXT_ADDR(solo_dev) + off,
317 SOLO_MP4E_EXT_SIZE(solo_dev) - off); 382 SOLO_MP4E_EXT_SIZE(solo_dev) - off);
318 383
319 ret |= solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_MP4E, 0, 384 ret |= solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_MP4E, 0,
320 buf + SOLO_MP4E_EXT_SIZE(solo_dev) - off, 385 buf + SOLO_MP4E_EXT_SIZE(solo_dev) - off,
@@ -337,70 +402,108 @@ static int enc_get_mpeg_dma(struct solo6010_dev *solo_dev, void *buf,
337 return ret; 402 return ret;
338} 403}
339 404
340static int enc_get_jpeg_dma(struct solo6010_dev *solo_dev, dma_addr_t buf, 405static int enc_get_jpeg_dma_sg(struct solo6010_dev *solo_dev,
341 unsigned int off, unsigned int size) 406 struct p2m_desc *desc,
407 struct scatterlist *sglist, int skip,
408 unsigned int off, unsigned int size)
342{ 409{
343 int ret; 410 int ret;
344 411
345 if (off > SOLO_JPEG_EXT_SIZE(solo_dev)) 412 if (off > SOLO_JPEG_EXT_SIZE(solo_dev))
346 return -EINVAL; 413 return -EINVAL;
347 414
348 if (off + size <= SOLO_JPEG_EXT_SIZE(solo_dev)) 415 if (off + size <= SOLO_JPEG_EXT_SIZE(solo_dev)) {
349 return solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_JPEG, 0, buf, 416 return solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_JPEG,
350 SOLO_JPEG_EXT_ADDR(solo_dev) + off, size); 417 desc, 0, sglist, skip,
418 SOLO_JPEG_EXT_ADDR(solo_dev) + off, size);
419 }
351 420
352 /* Buffer wrap */ 421 /* Buffer wrap */
353 ret = solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_JPEG, 0, buf, 422 ret = solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_JPEG, desc, 0,
354 SOLO_JPEG_EXT_ADDR(solo_dev) + off, 423 sglist, skip, SOLO_JPEG_EXT_ADDR(solo_dev) + off,
355 SOLO_JPEG_EXT_SIZE(solo_dev) - off); 424 SOLO_JPEG_EXT_SIZE(solo_dev) - off);
356 425
357 ret |= solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_JPEG, 0, 426 ret |= solo_p2m_dma_sg(solo_dev, SOLO_P2M_DMA_ID_JPEG, desc, 0,
358 buf + SOLO_JPEG_EXT_SIZE(solo_dev) - off, 427 sglist, skip + SOLO_JPEG_EXT_SIZE(solo_dev) - off,
359 SOLO_JPEG_EXT_ADDR(solo_dev), 428 SOLO_JPEG_EXT_ADDR(solo_dev),
360 size + off - SOLO_JPEG_EXT_SIZE(solo_dev)); 429 size + off - SOLO_JPEG_EXT_SIZE(solo_dev));
361 430
362 return ret; 431 return ret;
363} 432}
364 433
434/* Returns true of __chk is within the first __range bytes of __off */
435#define OFF_IN_RANGE(__off, __range, __chk) \
436 ((__off <= __chk) && ((__off + __range) >= __chk))
437
438static void solo_jpeg_header(struct solo_enc_dev *solo_enc,
439 struct videobuf_dmabuf *vbuf)
440{
441 struct scatterlist *sg;
442 void *src = jpeg_header;
443 size_t copied = 0;
444 size_t to_copy = sizeof(jpeg_header);
445
446 for (sg = vbuf->sglist; sg && copied < to_copy; sg = sg_next(sg)) {
447 size_t this_copy = min(sg_dma_len(sg),
448 (unsigned int)(to_copy - copied));
449 u8 *p = sg_virt(sg);
450
451 memcpy(p, src + copied, this_copy);
452
453 if (OFF_IN_RANGE(copied, this_copy, SOF0_START + 5))
454 p[(SOF0_START + 5) - copied] =
455 0xff & (solo_enc->height >> 8);
456 if (OFF_IN_RANGE(copied, this_copy, SOF0_START + 6))
457 p[(SOF0_START + 6) - copied] = 0xff & solo_enc->height;
458 if (OFF_IN_RANGE(copied, this_copy, SOF0_START + 7))
459 p[(SOF0_START + 7) - copied] =
460 0xff & (solo_enc->width >> 8);
461 if (OFF_IN_RANGE(copied, this_copy, SOF0_START + 8))
462 p[(SOF0_START + 8) - copied] = 0xff & solo_enc->width;
463
464 copied += this_copy;
465 }
466}
467
365static int solo_fill_jpeg(struct solo_enc_fh *fh, struct solo_enc_buf *enc_buf, 468static int solo_fill_jpeg(struct solo_enc_fh *fh, struct solo_enc_buf *enc_buf,
366 struct videobuf_buffer *vb, dma_addr_t vbuf) 469 struct videobuf_buffer *vb,
470 struct videobuf_dmabuf *vbuf)
367{ 471{
368 struct solo_enc_dev *solo_enc = fh->enc; 472 struct solo6010_dev *solo_dev = fh->enc->solo_dev;
369 struct solo6010_dev *solo_dev = solo_enc->solo_dev; 473 int size = enc_buf->jpeg_size;
370 u8 *p = videobuf_queue_to_vaddr(&fh->vidq, vb);
371 474
372 memcpy(p, jpeg_header, sizeof(jpeg_header)); 475 /* Copy the header first (direct write) */
373 p[SOF0_START + 5] = 0xff & (solo_enc->height >> 8); 476 solo_jpeg_header(fh->enc, vbuf);
374 p[SOF0_START + 6] = 0xff & solo_enc->height;
375 p[SOF0_START + 7] = 0xff & (solo_enc->width >> 8);
376 p[SOF0_START + 8] = 0xff & solo_enc->width;
377 477
378 vbuf += sizeof(jpeg_header); 478 vb->size = size + sizeof(jpeg_header);
379 vb->size = enc_buf->jpeg_size + sizeof(jpeg_header);
380 479
381 return enc_get_jpeg_dma(solo_dev, vbuf, enc_buf->jpeg_off, 480 /* Grab the jpeg frame */
382 enc_buf->jpeg_size); 481 return enc_get_jpeg_dma_sg(solo_dev, fh->desc, vbuf->sglist,
482 sizeof(jpeg_header),
483 enc_buf->jpeg_off, size);
383} 484}
384 485
385static int solo_fill_mpeg(struct solo_enc_fh *fh, struct solo_enc_buf *enc_buf, 486static int solo_fill_mpeg(struct solo_enc_fh *fh, struct solo_enc_buf *enc_buf,
386 struct videobuf_buffer *vb, dma_addr_t vbuf) 487 struct videobuf_buffer *vb,
488 struct videobuf_dmabuf *vbuf)
387{ 489{
388 struct solo_enc_dev *solo_enc = fh->enc; 490 struct solo_enc_dev *solo_enc = fh->enc;
389 struct solo6010_dev *solo_dev = solo_enc->solo_dev; 491 struct solo6010_dev *solo_dev = solo_enc->solo_dev;
390 struct vop_header vh; 492 struct vop_header vh;
391 int ret; 493 int ret;
392 int frame_size, frame_off; 494 int frame_size, frame_off;
495 int skip = 0;
393 496
394 if (WARN_ON_ONCE(enc_buf->size <= sizeof(vh))) 497 if (WARN_ON_ONCE(enc_buf->size <= sizeof(vh)))
395 return -1; 498 return -EINVAL;
396 499
397 /* First get the hardware vop header (not real mpeg) */ 500 /* First get the hardware vop header (not real mpeg) */
398 ret = enc_get_mpeg_dma(solo_dev, &vh, enc_buf->off, sizeof(vh)); 501 ret = enc_get_mpeg_dma(solo_dev, &vh, enc_buf->off, sizeof(vh));
399 if (ret) 502 if (WARN_ON_ONCE(ret))
400 return -1; 503 return ret;
401 504
402 if (WARN_ON_ONCE(vh.size > enc_buf->size)) 505 if (WARN_ON_ONCE(vh.size > enc_buf->size))
403 return -1; 506 return -EINVAL;
404 507
405 vb->width = vh.hsize << 4; 508 vb->width = vh.hsize << 4;
406 vb->height = vh.vsize << 4; 509 vb->height = vh.vsize << 4;
@@ -410,9 +513,9 @@ static int solo_fill_mpeg(struct solo_enc_fh *fh, struct solo_enc_buf *enc_buf,
410 if (!enc_buf->vop) { 513 if (!enc_buf->vop) {
411 u16 fps = solo_dev->fps * 1000; 514 u16 fps = solo_dev->fps * 1000;
412 u16 interval = solo_enc->interval * 1000; 515 u16 interval = solo_enc->interval * 1000;
413 u8 *p = videobuf_queue_to_vaddr(&fh->vidq, vb); 516 u8 p[sizeof(vid_vop_header)];
414 517
415 memcpy(p, vid_vop_header, sizeof(vid_vop_header)); 518 memcpy(p, vid_vop_header, sizeof(p));
416 519
417 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) 520 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC)
418 p[10] |= ((XVID_PAR_43_NTSC << 3) & 0x78); 521 p[10] |= ((XVID_PAR_43_NTSC << 3) & 0x78);
@@ -434,43 +537,49 @@ static int solo_fill_mpeg(struct solo_enc_fh *fh, struct solo_enc_buf *enc_buf,
434 if (vh.interlace) 537 if (vh.interlace)
435 p[29] |= 0x20; 538 p[29] |= 0x20;
436 539
540 enc_write_sg(vbuf->sglist, p, sizeof(p));
541
437 /* Adjust the dma buffer past this header */ 542 /* Adjust the dma buffer past this header */
438 vb->size += sizeof(vid_vop_header); 543 vb->size += sizeof(vid_vop_header);
439 vbuf += sizeof(vid_vop_header); 544 skip = sizeof(vid_vop_header);
440 } 545 }
441 546
442 /* Now get the actual mpeg payload */ 547 /* Now get the actual mpeg payload */
443 frame_off = (enc_buf->off + sizeof(vh)) % SOLO_MP4E_EXT_SIZE(solo_dev); 548 frame_off = (enc_buf->off + sizeof(vh)) % SOLO_MP4E_EXT_SIZE(solo_dev);
444 frame_size = enc_buf->size - sizeof(vh); 549 frame_size = enc_buf->size - sizeof(vh);
445 ret = enc_get_mpeg_dma_t(solo_dev, vbuf, frame_off, frame_size);
446 if (WARN_ON_ONCE(ret))
447 return -1;
448 550
449 return 0; 551 ret = enc_get_mpeg_dma_sg(solo_dev, fh->desc, vbuf->sglist,
552 skip, frame_off, frame_size);
553 WARN_ON_ONCE(ret);
554
555 return ret;
450} 556}
451 557
452/* On successful return (0), leaves solo_enc->lock unlocked */ 558static void solo_enc_fillbuf(struct solo_enc_fh *fh,
453static int solo_enc_fillbuf(struct solo_enc_fh *fh,
454 struct videobuf_buffer *vb) 559 struct videobuf_buffer *vb)
455{ 560{
456 struct solo_enc_dev *solo_enc = fh->enc; 561 struct solo_enc_dev *solo_enc = fh->enc;
457 struct solo6010_dev *solo_dev = solo_enc->solo_dev; 562 struct solo6010_dev *solo_dev = solo_enc->solo_dev;
458 struct solo_enc_buf *enc_buf = NULL; 563 struct solo_enc_buf *enc_buf = NULL;
459 dma_addr_t vbuf; 564 struct videobuf_dmabuf *vbuf;
460 int ret; 565 int ret;
566 int error = 1;
461 u16 idx = fh->rd_idx; 567 u16 idx = fh->rd_idx;
462 568
463 while (idx != solo_dev->enc_wr_idx) { 569 while (idx != solo_dev->enc_wr_idx) {
464 struct solo_enc_buf *ebuf = &solo_dev->enc_buf[idx]; 570 struct solo_enc_buf *ebuf = &solo_dev->enc_buf[idx];
571
465 idx = (idx + 1) % SOLO_NR_RING_BUFS; 572 idx = (idx + 1) % SOLO_NR_RING_BUFS;
573
574 if (ebuf->ch != solo_enc->ch)
575 continue;
576
466 if (fh->fmt == V4L2_PIX_FMT_MPEG) { 577 if (fh->fmt == V4L2_PIX_FMT_MPEG) {
467 if (fh->type != ebuf->type) 578 if (fh->type == ebuf->type) {
468 continue;
469 if (ebuf->ch == solo_enc->ch) {
470 enc_buf = ebuf; 579 enc_buf = ebuf;
471 break; 580 break;
472 } 581 }
473 } else if (ebuf->ch == solo_enc->ch) { 582 } else {
474 /* For mjpeg, keep reading to the newest frame */ 583 /* For mjpeg, keep reading to the newest frame */
475 enc_buf = ebuf; 584 enc_buf = ebuf;
476 } 585 }
@@ -478,48 +587,55 @@ static int solo_enc_fillbuf(struct solo_enc_fh *fh,
478 587
479 fh->rd_idx = idx; 588 fh->rd_idx = idx;
480 589
481 if (!enc_buf) 590 if (WARN_ON_ONCE(!enc_buf))
482 return -1; 591 goto buf_err;
483 592
484 if ((fh->fmt == V4L2_PIX_FMT_MPEG && 593 if ((fh->fmt == V4L2_PIX_FMT_MPEG &&
485 vb->bsize < enc_buf->size) || 594 vb->bsize < enc_buf->size) ||
486 (fh->fmt == V4L2_PIX_FMT_MJPEG && 595 (fh->fmt == V4L2_PIX_FMT_MJPEG &&
487 vb->bsize < (enc_buf->jpeg_size + sizeof(jpeg_header)))) { 596 vb->bsize < (enc_buf->jpeg_size + sizeof(jpeg_header)))) {
488 return -1; 597 WARN_ON_ONCE(1);
598 goto buf_err;
489 } 599 }
490 600
491 if (!(vbuf = videobuf_to_dma_contig(vb))) 601 vbuf = videobuf_to_dma(vb);
492 return -1; 602 if (WARN_ON_ONCE(!vbuf))
493 603 goto buf_err;
494 /* Is it ok that we mess with this buffer out of lock? */
495 spin_unlock(&solo_enc->lock);
496 604
497 if (fh->fmt == V4L2_PIX_FMT_MPEG) 605 if (fh->fmt == V4L2_PIX_FMT_MPEG)
498 ret = solo_fill_mpeg(fh, enc_buf, vb, vbuf); 606 ret = solo_fill_mpeg(fh, enc_buf, vb, vbuf);
499 else 607 else
500 ret = solo_fill_jpeg(fh, enc_buf, vb, vbuf); 608 ret = solo_fill_jpeg(fh, enc_buf, vb, vbuf);
501 609
502 if (ret) // Ignore failures 610 if (!ret)
503 return 0; 611 error = 0;
504 612
505 list_del(&vb->queue); 613buf_err:
506 vb->field_count++; 614 if (error) {
507 vb->ts = enc_buf->ts; 615 vb->state = VIDEOBUF_ERROR;
508 vb->state = VIDEOBUF_DONE; 616 } else {
617 vb->field_count++;
618 vb->ts = enc_buf->ts;
619 vb->state = VIDEOBUF_DONE;
620 }
509 621
510 wake_up(&vb->done); 622 wake_up(&vb->done);
511 623
512 return 0; 624 return;
513} 625}
514 626
515static void solo_enc_thread_try(struct solo_enc_fh *fh) 627static void solo_enc_thread_try(struct solo_enc_fh *fh)
516{ 628{
517 struct solo_enc_dev *solo_enc = fh->enc; 629 struct solo_enc_dev *solo_enc = fh->enc;
630 struct solo6010_dev *solo_dev = solo_enc->solo_dev;
518 struct videobuf_buffer *vb; 631 struct videobuf_buffer *vb;
519 632
520 for (;;) { 633 for (;;) {
521 spin_lock(&solo_enc->lock); 634 spin_lock(&solo_enc->lock);
522 635
636 if (fh->rd_idx == solo_dev->enc_wr_idx)
637 break;
638
523 if (list_empty(&fh->vidq_active)) 639 if (list_empty(&fh->vidq_active))
524 break; 640 break;
525 641
@@ -529,9 +645,11 @@ static void solo_enc_thread_try(struct solo_enc_fh *fh)
529 if (!waitqueue_active(&vb->done)) 645 if (!waitqueue_active(&vb->done))
530 break; 646 break;
531 647
532 /* On success, returns with solo_enc->lock unlocked */ 648 list_del(&vb->queue);
533 if (solo_enc_fillbuf(fh, vb)) 649
534 break; 650 spin_unlock(&solo_enc->lock);
651
652 solo_enc_fillbuf(fh, vb);
535 } 653 }
536 654
537 assert_spin_locked(&solo_enc->lock); 655 assert_spin_locked(&solo_enc->lock);
@@ -557,7 +675,7 @@ static int solo_enc_thread(void *data)
557 675
558 remove_wait_queue(&solo_enc->thread_wait, &wait); 676 remove_wait_queue(&solo_enc->thread_wait, &wait);
559 677
560 return 0; 678 return 0;
561} 679}
562 680
563void solo_motion_isr(struct solo6010_dev *solo_dev) 681void solo_motion_isr(struct solo6010_dev *solo_dev)
@@ -614,7 +732,8 @@ void solo_enc_v4l2_isr(struct solo6010_dev *solo_dev)
614 jpeg_next = solo_reg_read(solo_dev, 732 jpeg_next = solo_reg_read(solo_dev,
615 SOLO_VE_JPEG_QUE(solo_dev->enc_idx)); 733 SOLO_VE_JPEG_QUE(solo_dev->enc_idx));
616 734
617 if ((ch = (mpeg_current >> 24) & 0x1f) >= SOLO_MAX_CHANNELS) { 735 ch = (mpeg_current >> 24) & 0x1f;
736 if (ch >= SOLO_MAX_CHANNELS) {
618 ch -= SOLO_MAX_CHANNELS; 737 ch -= SOLO_MAX_CHANNELS;
619 enc_type = SOLO_ENC_TYPE_EXT; 738 enc_type = SOLO_ENC_TYPE_EXT;
620 } else 739 } else
@@ -669,12 +788,12 @@ void solo_enc_v4l2_isr(struct solo6010_dev *solo_dev)
669static int solo_enc_buf_setup(struct videobuf_queue *vq, unsigned int *count, 788static int solo_enc_buf_setup(struct videobuf_queue *vq, unsigned int *count,
670 unsigned int *size) 789 unsigned int *size)
671{ 790{
672 *size = FRAME_BUF_SIZE; 791 *size = FRAME_BUF_SIZE;
673 792
674 if (*count < MIN_VID_BUFFERS) 793 if (*count < MIN_VID_BUFFERS)
675 *count = MIN_VID_BUFFERS; 794 *count = MIN_VID_BUFFERS;
676 795
677 return 0; 796 return 0;
678} 797}
679 798
680static int solo_enc_buf_prepare(struct videobuf_queue *vq, 799static int solo_enc_buf_prepare(struct videobuf_queue *vq,
@@ -696,7 +815,9 @@ static int solo_enc_buf_prepare(struct videobuf_queue *vq,
696 if (vb->state == VIDEOBUF_NEEDS_INIT) { 815 if (vb->state == VIDEOBUF_NEEDS_INIT) {
697 int rc = videobuf_iolock(vq, vb, NULL); 816 int rc = videobuf_iolock(vq, vb, NULL);
698 if (rc < 0) { 817 if (rc < 0) {
699 videobuf_dma_contig_free(vq, vb); 818 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
819 videobuf_dma_unmap(vq->dev, dma);
820 videobuf_dma_free(dma);
700 vb->state = VIDEOBUF_NEEDS_INIT; 821 vb->state = VIDEOBUF_NEEDS_INIT;
701 return rc; 822 return rc;
702 } 823 }
@@ -719,7 +840,10 @@ static void solo_enc_buf_queue(struct videobuf_queue *vq,
719static void solo_enc_buf_release(struct videobuf_queue *vq, 840static void solo_enc_buf_release(struct videobuf_queue *vq,
720 struct videobuf_buffer *vb) 841 struct videobuf_buffer *vb)
721{ 842{
722 videobuf_dma_contig_free(vq, vb); 843 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
844
845 videobuf_dma_unmap(vq->dev, dma);
846 videobuf_dma_free(dma);
723 vb->state = VIDEOBUF_NEEDS_INIT; 847 vb->state = VIDEOBUF_NEEDS_INIT;
724} 848}
725 849
@@ -750,25 +874,22 @@ static int solo_enc_open(struct file *file)
750 struct solo_enc_dev *solo_enc = video_drvdata(file); 874 struct solo_enc_dev *solo_enc = video_drvdata(file);
751 struct solo_enc_fh *fh; 875 struct solo_enc_fh *fh;
752 876
753 if ((fh = kzalloc(sizeof(*fh), GFP_KERNEL)) == NULL) 877 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
878 if (fh == NULL)
754 return -ENOMEM; 879 return -ENOMEM;
755 880
756 spin_lock(&solo_enc->lock);
757
758 fh->enc = solo_enc; 881 fh->enc = solo_enc;
759 file->private_data = fh; 882 file->private_data = fh;
760 INIT_LIST_HEAD(&fh->vidq_active); 883 INIT_LIST_HEAD(&fh->vidq_active);
761 fh->fmt = V4L2_PIX_FMT_MPEG; 884 fh->fmt = V4L2_PIX_FMT_MPEG;
762 fh->type = SOLO_ENC_TYPE_STD; 885 fh->type = SOLO_ENC_TYPE_STD;
763 886
764 videobuf_queue_dma_contig_init(&fh->vidq, &solo_enc_video_qops, 887 videobuf_queue_sg_init(&fh->vidq, &solo_enc_video_qops,
765 &solo_enc->solo_dev->pdev->dev, 888 &solo_enc->solo_dev->pdev->dev,
766 &solo_enc->lock, 889 &solo_enc->lock,
767 V4L2_BUF_TYPE_VIDEO_CAPTURE, 890 V4L2_BUF_TYPE_VIDEO_CAPTURE,
768 V4L2_FIELD_INTERLACED, 891 V4L2_FIELD_INTERLACED,
769 sizeof(struct videobuf_buffer), fh, NULL); 892 sizeof(struct videobuf_buffer), fh, NULL);
770
771 spin_unlock(&solo_enc->lock);
772 893
773 return 0; 894 return 0;
774} 895}
@@ -785,7 +906,11 @@ static ssize_t solo_enc_read(struct file *file, char __user *data,
785 906
786 spin_lock(&solo_enc->lock); 907 spin_lock(&solo_enc->lock);
787 ret = solo_enc_on(fh); 908 ret = solo_enc_on(fh);
788 spin_unlock(&solo_enc->lock); 909 spin_unlock(&solo_enc->lock);
910 if (ret)
911 return ret;
912
913 ret = solo_start_fh_thread(fh);
789 if (ret) 914 if (ret)
790 return ret; 915 return ret;
791 } 916 }
@@ -797,10 +922,15 @@ static ssize_t solo_enc_read(struct file *file, char __user *data,
797static int solo_enc_release(struct file *file) 922static int solo_enc_release(struct file *file)
798{ 923{
799 struct solo_enc_fh *fh = file->private_data; 924 struct solo_enc_fh *fh = file->private_data;
925 struct solo_enc_dev *solo_enc = fh->enc;
800 926
801 videobuf_stop(&fh->vidq); 927 videobuf_stop(&fh->vidq);
802 videobuf_mmap_free(&fh->vidq); 928 videobuf_mmap_free(&fh->vidq);
929
930 spin_lock(&solo_enc->lock);
803 solo_enc_off(fh); 931 solo_enc_off(fh);
932 spin_unlock(&solo_enc->lock);
933
804 kfree(fh); 934 kfree(fh);
805 935
806 return 0; 936 return 0;
@@ -842,7 +972,7 @@ static int solo_enc_enum_input(struct file *file, void *priv,
842 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) 972 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC)
843 input->std = V4L2_STD_NTSC_M; 973 input->std = V4L2_STD_NTSC_M;
844 else 974 else
845 input->std = V4L2_STD_PAL_M; 975 input->std = V4L2_STD_PAL_B;
846 976
847 if (!tw28_get_video_status(solo_dev, solo_enc->ch)) 977 if (!tw28_get_video_status(solo_dev, solo_enc->ch))
848 input->status = V4L2_IN_ST_NO_SIGNAL; 978 input->status = V4L2_IN_ST_NO_SIGNAL;
@@ -915,9 +1045,8 @@ static int solo_enc_try_fmt_cap(struct file *file, void *priv,
915 1045
916 if (pix->field == V4L2_FIELD_ANY) 1046 if (pix->field == V4L2_FIELD_ANY)
917 pix->field = V4L2_FIELD_INTERLACED; 1047 pix->field = V4L2_FIELD_INTERLACED;
918 else if (pix->field != V4L2_FIELD_INTERLACED) { 1048 else if (pix->field != V4L2_FIELD_INTERLACED)
919 pix->field = V4L2_FIELD_INTERLACED; 1049 pix->field = V4L2_FIELD_INTERLACED;
920 }
921 1050
922 /* Just set these */ 1051 /* Just set these */
923 pix->colorspace = V4L2_COLORSPACE_SMPTE170M; 1052 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
@@ -937,7 +1066,8 @@ static int solo_enc_set_fmt_cap(struct file *file, void *priv,
937 1066
938 spin_lock(&solo_enc->lock); 1067 spin_lock(&solo_enc->lock);
939 1068
940 if ((ret = solo_enc_try_fmt_cap(file, priv, f))) { 1069 ret = solo_enc_try_fmt_cap(file, priv, f);
1070 if (ret) {
941 spin_unlock(&solo_enc->lock); 1071 spin_unlock(&solo_enc->lock);
942 return ret; 1072 return ret;
943 } 1073 }
@@ -956,7 +1086,10 @@ static int solo_enc_set_fmt_cap(struct file *file, void *priv,
956 1086
957 spin_unlock(&solo_enc->lock); 1087 spin_unlock(&solo_enc->lock);
958 1088
959 return ret; 1089 if (ret)
1090 return ret;
1091
1092 return solo_start_fh_thread(fh);
960} 1093}
961 1094
962static int solo_enc_get_fmt_cap(struct file *file, void *priv, 1095static int solo_enc_get_fmt_cap(struct file *file, void *priv,
@@ -977,7 +1110,7 @@ static int solo_enc_get_fmt_cap(struct file *file, void *priv,
977 return 0; 1110 return 0;
978} 1111}
979 1112
980static int solo_enc_reqbufs(struct file *file, void *priv, 1113static int solo_enc_reqbufs(struct file *file, void *priv,
981 struct v4l2_requestbuffers *req) 1114 struct v4l2_requestbuffers *req)
982{ 1115{
983 struct solo_enc_fh *fh = priv; 1116 struct solo_enc_fh *fh = priv;
@@ -1014,6 +1147,10 @@ static int solo_enc_dqbuf(struct file *file, void *priv,
1014 spin_unlock(&solo_enc->lock); 1147 spin_unlock(&solo_enc->lock);
1015 if (ret) 1148 if (ret)
1016 return ret; 1149 return ret;
1150
1151 ret = solo_start_fh_thread(fh);
1152 if (ret)
1153 return ret;
1017 } 1154 }
1018 1155
1019 ret = videobuf_dqbuf(&fh->vidq, buf, file->f_flags & O_NONBLOCK); 1156 ret = videobuf_dqbuf(&fh->vidq, buf, file->f_flags & O_NONBLOCK);
@@ -1033,12 +1170,16 @@ static int solo_enc_dqbuf(struct file *file, void *priv,
1033 1170
1034 /* Check for key frame on mpeg data */ 1171 /* Check for key frame on mpeg data */
1035 if (fh->fmt == V4L2_PIX_FMT_MPEG) { 1172 if (fh->fmt == V4L2_PIX_FMT_MPEG) {
1036 struct videobuf_buffer *vb = fh->vidq.bufs[buf->index]; 1173 struct videobuf_dmabuf *vbuf =
1037 u8 *p = videobuf_queue_to_vaddr(&fh->vidq, vb); 1174 videobuf_to_dma(fh->vidq.bufs[buf->index]);
1038 if (p[3] == 0x00) 1175
1039 buf->flags |= V4L2_BUF_FLAG_KEYFRAME; 1176 if (vbuf) {
1040 else 1177 u8 *p = sg_virt(vbuf->sglist);
1041 buf->flags |= V4L2_BUF_FLAG_PFRAME; 1178 if (p[3] == 0x00)
1179 buf->flags |= V4L2_BUF_FLAG_KEYFRAME;
1180 else
1181 buf->flags |= V4L2_BUF_FLAG_PFRAME;
1182 }
1042 } 1183 }
1043 1184
1044 return 0; 1185 return 0;
@@ -1136,7 +1277,7 @@ static int solo_g_parm(struct file *file, void *priv,
1136 /* XXX: Shouldn't we be able to get/set this from videobuf? */ 1277 /* XXX: Shouldn't we be able to get/set this from videobuf? */
1137 cp->readbuffers = 2; 1278 cp->readbuffers = 2;
1138 1279
1139 return 0; 1280 return 0;
1140} 1281}
1141 1282
1142static int solo_s_parm(struct file *file, void *priv, 1283static int solo_s_parm(struct file *file, void *priv,
@@ -1176,7 +1317,7 @@ static int solo_s_parm(struct file *file, void *priv,
1176 1317
1177 spin_unlock(&solo_enc->lock); 1318 spin_unlock(&solo_enc->lock);
1178 1319
1179 return 0; 1320 return 0;
1180} 1321}
1181 1322
1182static int solo_queryctrl(struct file *file, void *priv, 1323static int solo_queryctrl(struct file *file, void *priv,
@@ -1240,7 +1381,7 @@ static int solo_queryctrl(struct file *file, void *priv,
1240 return 0; 1381 return 0;
1241 } 1382 }
1242 1383
1243 return -EINVAL; 1384 return -EINVAL;
1244} 1385}
1245 1386
1246static int solo_querymenu(struct file *file, void *priv, 1387static int solo_querymenu(struct file *file, void *priv,
@@ -1250,7 +1391,8 @@ static int solo_querymenu(struct file *file, void *priv,
1250 int err; 1391 int err;
1251 1392
1252 qctrl.id = qmenu->id; 1393 qctrl.id = qmenu->id;
1253 if ((err = solo_queryctrl(file, priv, &qctrl))) 1394 err = solo_queryctrl(file, priv, &qctrl);
1395 if (err)
1254 return err; 1396 return err;
1255 1397
1256 return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL); 1398 return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL);
@@ -1350,9 +1492,9 @@ static int solo_s_ext_ctrls(struct file *file, void *priv,
1350 switch (ctrl->id) { 1492 switch (ctrl->id) {
1351 case V4L2_CID_RDS_TX_RADIO_TEXT: 1493 case V4L2_CID_RDS_TX_RADIO_TEXT:
1352 if (ctrl->size - 1 > OSD_TEXT_MAX) 1494 if (ctrl->size - 1 > OSD_TEXT_MAX)
1353 err = -ERANGE; 1495 err = -ERANGE;
1354 else { 1496 else {
1355 err = copy_from_user(solo_enc->osd_text, 1497 err = copy_from_user(solo_enc->osd_text,
1356 ctrl->string, 1498 ctrl->string,
1357 OSD_TEXT_MAX); 1499 OSD_TEXT_MAX);
1358 solo_enc->osd_text[OSD_TEXT_MAX] = '\0'; 1500 solo_enc->osd_text[OSD_TEXT_MAX] = '\0';
@@ -1459,7 +1601,7 @@ static struct video_device solo_enc_template = {
1459 .minor = -1, 1601 .minor = -1,
1460 .release = video_device_release, 1602 .release = video_device_release,
1461 1603
1462 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL_M, 1604 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL_B,
1463 .current_norm = V4L2_STD_NTSC_M, 1605 .current_norm = V4L2_STD_NTSC_M,
1464}; 1606};
1465 1607
@@ -1505,7 +1647,7 @@ static struct solo_enc_dev *solo_enc_alloc(struct solo6010_dev *solo_dev, u8 ch)
1505 atomic_set(&solo_enc->readers, 0); 1647 atomic_set(&solo_enc->readers, 0);
1506 1648
1507 solo_enc->qp = SOLO_DEFAULT_QP; 1649 solo_enc->qp = SOLO_DEFAULT_QP;
1508 solo_enc->gop = solo_dev->fps; 1650 solo_enc->gop = solo_dev->fps;
1509 solo_enc->interval = 1; 1651 solo_enc->interval = 1;
1510 solo_enc->mode = SOLO_ENC_MODE_CIF; 1652 solo_enc->mode = SOLO_ENC_MODE_CIF;
1511 solo_enc->motion_thresh = SOLO_DEF_MOT_THRESH; 1653 solo_enc->motion_thresh = SOLO_DEF_MOT_THRESH;
diff --git a/drivers/staging/solo6x10/solo6010-v4l2.c b/drivers/staging/solo6x10/solo6010-v4l2.c
index 6ffd21de837d..a8491dc0e914 100644
--- a/drivers/staging/solo6x10/solo6010-v4l2.c
+++ b/drivers/staging/solo6x10/solo6010-v4l2.c
@@ -24,14 +24,13 @@
24 24
25#include <media/v4l2-ioctl.h> 25#include <media/v4l2-ioctl.h>
26#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
27#include <media/videobuf-dma-contig.h> 27#include <media/videobuf-dma-sg.h>
28 28
29#include "solo6010.h" 29#include "solo6010.h"
30#include "solo6010-tw28.h" 30#include "solo6010-tw28.h"
31 31
32#define SOLO_HW_BPL 2048 32#define SOLO_HW_BPL 2048
33#define SOLO_DISP_PIX_FIELD V4L2_FIELD_INTERLACED 33#define SOLO_DISP_PIX_FIELD V4L2_FIELD_INTERLACED
34#define SOLO_DISP_BUF_SIZE (64 * 1024) // 64k
35 34
36/* Image size is two fields, SOLO_HW_BPL is one horizontal line */ 35/* Image size is two fields, SOLO_HW_BPL is one horizontal line */
37#define solo_vlines(__solo) (__solo->video_vsize * 2) 36#define solo_vlines(__solo) (__solo->video_vsize * 2)
@@ -49,6 +48,8 @@ struct solo_filehandle {
49 spinlock_t slock; 48 spinlock_t slock;
50 int old_write; 49 int old_write;
51 struct list_head vidq_active; 50 struct list_head vidq_active;
51 struct p2m_desc desc[SOLO_NR_P2M_DESC];
52 int desc_idx;
52}; 53};
53 54
54unsigned video_nr = -1; 55unsigned video_nr = -1;
@@ -96,7 +97,7 @@ static void solo_win_setup(struct solo6010_dev *solo_dev, u8 ch,
96 SOLO_VI_WIN_EX(ex) | 97 SOLO_VI_WIN_EX(ex) |
97 SOLO_VI_WIN_SCALE(scale)); 98 SOLO_VI_WIN_SCALE(scale));
98 99
99 solo_reg_write(solo_dev, SOLO_VI_WIN_CTRL1(ch), 100 solo_reg_write(solo_dev, SOLO_VI_WIN_CTRL1(ch),
100 SOLO_VI_WIN_SY(sy) | 101 SOLO_VI_WIN_SY(sy) |
101 SOLO_VI_WIN_EY(ey)); 102 SOLO_VI_WIN_EY(ey));
102} 103}
@@ -203,50 +204,149 @@ static int solo_v4l2_set_ch(struct solo6010_dev *solo_dev, u8 ch)
203 return 0; 204 return 0;
204} 205}
205 206
207static void disp_reset_desc(struct solo_filehandle *fh)
208{
209 /* We use desc mode, which ignores desc 0 */
210 memset(fh->desc, 0, sizeof(*fh->desc));
211 fh->desc_idx = 1;
212}
213
214static int disp_flush_descs(struct solo_filehandle *fh)
215{
216 int ret;
217
218 if (!fh->desc_idx)
219 return 0;
220
221 ret = solo_p2m_dma_desc(fh->solo_dev, SOLO_P2M_DMA_ID_DISP,
222 fh->desc, fh->desc_idx);
223 disp_reset_desc(fh);
224
225 return ret;
226}
227
228static int disp_push_desc(struct solo_filehandle *fh, dma_addr_t dma_addr,
229 u32 ext_addr, int size, int repeat, int ext_size)
230{
231 if (fh->desc_idx >= SOLO_NR_P2M_DESC) {
232 int ret = disp_flush_descs(fh);
233 if (ret)
234 return ret;
235 }
236
237 solo_p2m_push_desc(&fh->desc[fh->desc_idx], 0, dma_addr, ext_addr,
238 size, repeat, ext_size);
239 fh->desc_idx++;
240
241 return 0;
242}
243
206static void solo_fillbuf(struct solo_filehandle *fh, 244static void solo_fillbuf(struct solo_filehandle *fh,
207 struct videobuf_buffer *vb) 245 struct videobuf_buffer *vb)
208{ 246{
209 struct solo6010_dev *solo_dev = fh->solo_dev; 247 struct solo6010_dev *solo_dev = fh->solo_dev;
210 dma_addr_t vbuf; 248 struct videobuf_dmabuf *vbuf;
211 unsigned int fdma_addr; 249 unsigned int fdma_addr;
212 int frame_size;
213 int error = 1; 250 int error = 1;
214 int i; 251 int i;
252 struct scatterlist *sg;
253 dma_addr_t sg_dma;
254 int sg_size_left;
215 255
216 if (!(vbuf = videobuf_to_dma_contig(vb))) 256 vbuf = videobuf_to_dma(vb);
257 if (!vbuf)
217 goto finish_buf; 258 goto finish_buf;
218 259
219 if (erase_off(solo_dev)) { 260 if (erase_off(solo_dev)) {
220 void *p = videobuf_queue_to_vaddr(&fh->vidq, vb); 261 int i;
221 int image_size = solo_image_size(solo_dev); 262
222 for (i = 0; i < image_size; i += 2) { 263 /* Just blit to the entire sg list, ignoring size */
223 ((u8 *)p)[i] = 0x80; 264 for_each_sg(vbuf->sglist, sg, vbuf->sglen, i) {
224 ((u8 *)p)[i + 1] = 0x00; 265 void *p = sg_virt(sg);
266 size_t len = sg_dma_len(sg);
267
268 for (i = 0; i < len; i += 2) {
269 ((u8 *)p)[i] = 0x80;
270 ((u8 *)p)[i + 1] = 0x00;
271 }
225 } 272 }
273
226 error = 0; 274 error = 0;
227 goto finish_buf; 275 goto finish_buf;
228 } 276 }
229 277
230 frame_size = SOLO_HW_BPL * solo_vlines(solo_dev); 278 disp_reset_desc(fh);
231 fdma_addr = SOLO_DISP_EXT_ADDR(solo_dev) + (fh->old_write * frame_size); 279 sg = vbuf->sglist;
280 sg_dma = sg_dma_address(sg);
281 sg_size_left = sg_dma_len(sg);
282
283 fdma_addr = SOLO_DISP_EXT_ADDR(solo_dev) + (fh->old_write *
284 (SOLO_HW_BPL * solo_vlines(solo_dev)));
232 285
233 for (i = 0; i < frame_size / SOLO_DISP_BUF_SIZE; i++) { 286 for (i = 0; i < solo_vlines(solo_dev); i++) {
234 int j; 287 int line_len = solo_bytesperline(solo_dev);
235 for (j = 0; j < (SOLO_DISP_BUF_SIZE / SOLO_HW_BPL); j++) { 288 int lines;
236 if (solo_p2m_dma_t(solo_dev, SOLO_P2M_DMA_ID_DISP, 0, 289
237 vbuf, fdma_addr + (j * SOLO_HW_BPL), 290 if (!sg_size_left) {
238 solo_bytesperline(solo_dev))) 291 sg = sg_next(sg);
292 if (sg == NULL)
239 goto finish_buf; 293 goto finish_buf;
240 vbuf += solo_bytesperline(solo_dev); 294 sg_dma = sg_dma_address(sg);
295 sg_size_left = sg_dma_len(sg);
241 } 296 }
242 fdma_addr += SOLO_DISP_BUF_SIZE; 297
298 /* No room for an entire line, so chunk it up */
299 if (sg_size_left < line_len) {
300 int this_addr = fdma_addr;
301
302 while (line_len > 0) {
303 int this_write;
304
305 if (!sg_size_left) {
306 sg = sg_next(sg);
307 if (sg == NULL)
308 goto finish_buf;
309 sg_dma = sg_dma_address(sg);
310 sg_size_left = sg_dma_len(sg);
311 }
312
313 this_write = min(sg_size_left, line_len);
314
315 if (disp_push_desc(fh, sg_dma, this_addr,
316 this_write, 0, 0))
317 goto finish_buf;
318
319 line_len -= this_write;
320 sg_size_left -= this_write;
321 sg_dma += this_write;
322 this_addr += this_write;
323 }
324
325 fdma_addr += SOLO_HW_BPL;
326 continue;
327 }
328
329 /* Shove as many lines into a repeating descriptor as possible */
330 lines = min(sg_size_left / line_len,
331 solo_vlines(solo_dev) - i);
332
333 if (disp_push_desc(fh, sg_dma, fdma_addr, line_len,
334 lines - 1, SOLO_HW_BPL))
335 goto finish_buf;
336
337 i += lines - 1;
338 fdma_addr += SOLO_HW_BPL * lines;
339 sg_dma += lines * line_len;
340 sg_size_left -= lines * line_len;
243 } 341 }
244 error = 0; 342
343 error = disp_flush_descs(fh);
245 344
246finish_buf: 345finish_buf:
247 if (error) { 346 if (error) {
248 vb->state = VIDEOBUF_ERROR; 347 vb->state = VIDEOBUF_ERROR;
249 } else { 348 } else {
349 vb->size = solo_vlines(solo_dev) * solo_bytesperline(solo_dev);
250 vb->state = VIDEOBUF_DONE; 350 vb->state = VIDEOBUF_DONE;
251 vb->field_count++; 351 vb->field_count++;
252 do_gettimeofday(&vb->ts); 352 do_gettimeofday(&vb->ts);
@@ -275,7 +375,7 @@ static void solo_thread_try(struct solo_filehandle *fh)
275 break; 375 break;
276 376
277 cur_write = SOLO_VI_STATUS0_PAGE(solo_reg_read(fh->solo_dev, 377 cur_write = SOLO_VI_STATUS0_PAGE(solo_reg_read(fh->solo_dev,
278 SOLO_VI_STATUS0)); 378 SOLO_VI_STATUS0));
279 if (cur_write == fh->old_write) 379 if (cur_write == fh->old_write)
280 break; 380 break;
281 381
@@ -310,7 +410,7 @@ static int solo_thread(void *data)
310 410
311 remove_wait_queue(&solo_dev->disp_thread_wait, &wait); 411 remove_wait_queue(&solo_dev->disp_thread_wait, &wait);
312 412
313 return 0; 413 return 0;
314} 414}
315 415
316static int solo_start_thread(struct solo_filehandle *fh) 416static int solo_start_thread(struct solo_filehandle *fh)
@@ -337,12 +437,12 @@ static int solo_buf_setup(struct videobuf_queue *vq, unsigned int *count,
337 struct solo_filehandle *fh = vq->priv_data; 437 struct solo_filehandle *fh = vq->priv_data;
338 struct solo6010_dev *solo_dev = fh->solo_dev; 438 struct solo6010_dev *solo_dev = fh->solo_dev;
339 439
340 *size = solo_image_size(solo_dev); 440 *size = solo_image_size(solo_dev);
341 441
342 if (*count < MIN_VID_BUFFERS) 442 if (*count < MIN_VID_BUFFERS)
343 *count = MIN_VID_BUFFERS; 443 *count = MIN_VID_BUFFERS;
344 444
345 return 0; 445 return 0;
346} 446}
347 447
348static int solo_buf_prepare(struct videobuf_queue *vq, 448static int solo_buf_prepare(struct videobuf_queue *vq,
@@ -364,7 +464,9 @@ static int solo_buf_prepare(struct videobuf_queue *vq,
364 if (vb->state == VIDEOBUF_NEEDS_INIT) { 464 if (vb->state == VIDEOBUF_NEEDS_INIT) {
365 int rc = videobuf_iolock(vq, vb, NULL); 465 int rc = videobuf_iolock(vq, vb, NULL);
366 if (rc < 0) { 466 if (rc < 0) {
367 videobuf_dma_contig_free(vq, vb); 467 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
468 videobuf_dma_unmap(vq->dev, dma);
469 videobuf_dma_free(dma);
368 vb->state = VIDEOBUF_NEEDS_INIT; 470 vb->state = VIDEOBUF_NEEDS_INIT;
369 return rc; 471 return rc;
370 } 472 }
@@ -388,7 +490,10 @@ static void solo_buf_queue(struct videobuf_queue *vq,
388static void solo_buf_release(struct videobuf_queue *vq, 490static void solo_buf_release(struct videobuf_queue *vq,
389 struct videobuf_buffer *vb) 491 struct videobuf_buffer *vb)
390{ 492{
391 videobuf_dma_contig_free(vq, vb); 493 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
494
495 videobuf_dma_unmap(vq->dev, dma);
496 videobuf_dma_free(dma);
392 vb->state = VIDEOBUF_NEEDS_INIT; 497 vb->state = VIDEOBUF_NEEDS_INIT;
393} 498}
394 499
@@ -404,7 +509,7 @@ static unsigned int solo_v4l2_poll(struct file *file,
404{ 509{
405 struct solo_filehandle *fh = file->private_data; 510 struct solo_filehandle *fh = file->private_data;
406 511
407 return videobuf_poll_stream(file, &fh->vidq, wait); 512 return videobuf_poll_stream(file, &fh->vidq, wait);
408} 513}
409 514
410static int solo_v4l2_mmap(struct file *file, struct vm_area_struct *vma) 515static int solo_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
@@ -420,7 +525,8 @@ static int solo_v4l2_open(struct file *file)
420 struct solo_filehandle *fh; 525 struct solo_filehandle *fh;
421 int ret; 526 int ret;
422 527
423 if ((fh = kzalloc(sizeof(*fh), GFP_KERNEL)) == NULL) 528 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
529 if (fh == NULL)
424 return -ENOMEM; 530 return -ENOMEM;
425 531
426 spin_lock_init(&fh->slock); 532 spin_lock_init(&fh->slock);
@@ -428,16 +534,17 @@ static int solo_v4l2_open(struct file *file)
428 fh->solo_dev = solo_dev; 534 fh->solo_dev = solo_dev;
429 file->private_data = fh; 535 file->private_data = fh;
430 536
431 if ((ret = solo_start_thread(fh))) { 537 ret = solo_start_thread(fh);
538 if (ret) {
432 kfree(fh); 539 kfree(fh);
433 return ret; 540 return ret;
434 } 541 }
435 542
436 videobuf_queue_dma_contig_init(&fh->vidq, &solo_video_qops, 543 videobuf_queue_sg_init(&fh->vidq, &solo_video_qops,
437 &solo_dev->pdev->dev, &fh->slock, 544 &solo_dev->pdev->dev, &fh->slock,
438 V4L2_BUF_TYPE_VIDEO_CAPTURE, 545 V4L2_BUF_TYPE_VIDEO_CAPTURE,
439 SOLO_DISP_PIX_FIELD, 546 SOLO_DISP_PIX_FIELD,
440 sizeof(struct videobuf_buffer), fh, NULL); 547 sizeof(struct videobuf_buffer), fh, NULL);
441 548
442 return 0; 549 return 0;
443} 550}
@@ -530,7 +637,7 @@ static int solo_enum_input(struct file *file, void *priv,
530 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC) 637 if (solo_dev->video_type == SOLO_VO_FMT_TYPE_NTSC)
531 input->std = V4L2_STD_NTSC_M; 638 input->std = V4L2_STD_NTSC_M;
532 else 639 else
533 input->std = V4L2_STD_PAL_M; 640 input->std = V4L2_STD_PAL_B;
534 641
535 return 0; 642 return 0;
536} 643}
@@ -622,7 +729,7 @@ static int solo_get_fmt_cap(struct file *file, void *priv,
622 return 0; 729 return 0;
623} 730}
624 731
625static int solo_reqbufs(struct file *file, void *priv, 732static int solo_reqbufs(struct file *file, void *priv,
626 struct v4l2_requestbuffers *req) 733 struct v4l2_requestbuffers *req)
627{ 734{
628 struct solo_filehandle *fh = priv; 735 struct solo_filehandle *fh = priv;
@@ -781,11 +888,11 @@ static const struct v4l2_ioctl_ops solo_v4l2_ioctl_ops = {
781 .vidioc_qbuf = solo_qbuf, 888 .vidioc_qbuf = solo_qbuf,
782 .vidioc_dqbuf = solo_dqbuf, 889 .vidioc_dqbuf = solo_dqbuf,
783 .vidioc_streamon = solo_streamon, 890 .vidioc_streamon = solo_streamon,
784 .vidioc_streamoff = solo_streamoff, 891 .vidioc_streamoff = solo_streamoff,
785 /* Controls */ 892 /* Controls */
786 .vidioc_queryctrl = solo_disp_queryctrl, 893 .vidioc_queryctrl = solo_disp_queryctrl,
787 .vidioc_g_ctrl = solo_disp_g_ctrl, 894 .vidioc_g_ctrl = solo_disp_g_ctrl,
788 .vidioc_s_ctrl = solo_disp_s_ctrl, 895 .vidioc_s_ctrl = solo_disp_s_ctrl,
789}; 896};
790 897
791static struct video_device solo_v4l2_template = { 898static struct video_device solo_v4l2_template = {
@@ -795,7 +902,7 @@ static struct video_device solo_v4l2_template = {
795 .minor = -1, 902 .minor = -1,
796 .release = video_device_release, 903 .release = video_device_release,
797 904
798 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL_M, 905 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL_B,
799 .current_norm = V4L2_STD_NTSC_M, 906 .current_norm = V4L2_STD_NTSC_M,
800}; 907};
801 908
@@ -836,13 +943,13 @@ int solo_v4l2_init(struct solo6010_dev *solo_dev)
836 for (i = 0; i < solo_dev->nr_chans; i++) { 943 for (i = 0; i < solo_dev->nr_chans; i++) {
837 solo_v4l2_set_ch(solo_dev, i); 944 solo_v4l2_set_ch(solo_dev, i);
838 while (erase_off(solo_dev)) 945 while (erase_off(solo_dev))
839 ;// Do nothing 946 ;/* Do nothing */
840 } 947 }
841 948
842 /* Set the default display channel */ 949 /* Set the default display channel */
843 solo_v4l2_set_ch(solo_dev, 0); 950 solo_v4l2_set_ch(solo_dev, 0);
844 while (erase_off(solo_dev)) 951 while (erase_off(solo_dev))
845 ;// Do nothing 952 ;/* Do nothing */
846 953
847 solo6010_irq_on(solo_dev, SOLO_IRQ_VIDEO_IN); 954 solo6010_irq_on(solo_dev, SOLO_IRQ_VIDEO_IN);
848 955
diff --git a/drivers/staging/solo6x10/solo6010.h b/drivers/staging/solo6x10/solo6010.h
index dca8e3e15450..9c930f3a017b 100644
--- a/drivers/staging/solo6x10/solo6010.h
+++ b/drivers/staging/solo6x10/solo6010.h
@@ -26,8 +26,8 @@
26#include <linux/semaphore.h> 26#include <linux/semaphore.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/list.h> 28#include <linux/list.h>
29#include <linux/delay.h>
30#include <linux/wait.h> 29#include <linux/wait.h>
30#include <linux/delay.h>
31#include <asm/io.h> 31#include <asm/io.h>
32#include <asm/atomic.h> 32#include <asm/atomic.h>
33 33
@@ -48,10 +48,14 @@
48#define PCI_DEVICE_ID_NEUSOLO_4 0x4304 48#define PCI_DEVICE_ID_NEUSOLO_4 0x4304
49#define PCI_DEVICE_ID_NEUSOLO_9 0x4309 49#define PCI_DEVICE_ID_NEUSOLO_9 0x4309
50#define PCI_DEVICE_ID_NEUSOLO_16 0x4310 50#define PCI_DEVICE_ID_NEUSOLO_16 0x4310
51/* Commell Softlogic 6010 based cards */ 51/* Bluecherry Softlogic 6010 based cards */
52#define PCI_DEVICE_ID_COMMSOLO_4 0x4E04 52#define PCI_DEVICE_ID_BC_SOLO_4 0x4E04
53#define PCI_DEVICE_ID_COMMSOLO_9 0x4E09 53#define PCI_DEVICE_ID_BC_SOLO_9 0x4E09
54#define PCI_DEVICE_ID_COMMSOLO_16 0x4E10 54#define PCI_DEVICE_ID_BC_SOLO_16 0x4E10
55/* Bluecherry Softlogic 6110 based cards */
56#define PCI_DEVICE_ID_BC_6110_4 0x5304
57#define PCI_DEVICE_ID_BC_6110_8 0x5308
58#define PCI_DEVICE_ID_BC_6110_16 0x5310
55#endif /* Bluecherry */ 59#endif /* Bluecherry */
56 60
57#define SOLO6010_NAME "solo6010" 61#define SOLO6010_NAME "solo6010"
@@ -64,7 +68,7 @@
64#define SOLO6010_VER_MINOR 0 68#define SOLO6010_VER_MINOR 0
65#define SOLO6010_VER_SUB 0 69#define SOLO6010_VER_SUB 0
66#define SOLO6010_VER_NUM \ 70#define SOLO6010_VER_NUM \
67 KERNEL_VERSION(SOLO6010_VER_MAJOR, SOLO6010_VER_MINOR, SOLO6010_VER_SUB) 71 KERNEL_VERSION(SOLO6010_VER_MAJOR, SOLO6010_VER_MINOR, SOLO6010_VER_SUB)
68 72
69/* 73/*
70 * The SOLO6010 actually has 8 i2c channels, but we only use 2. 74 * The SOLO6010 actually has 8 i2c channels, but we only use 2.
@@ -78,7 +82,6 @@
78/* DMA Engine setup */ 82/* DMA Engine setup */
79#define SOLO_NR_P2M 4 83#define SOLO_NR_P2M 4
80#define SOLO_NR_P2M_DESC 256 84#define SOLO_NR_P2M_DESC 256
81#define SOLO_P2M_DESC_SIZE (SOLO_NR_P2M_DESC * 16)
82/* MPEG and JPEG share the same interrupt and locks so they must be together 85/* MPEG and JPEG share the same interrupt and locks so they must be together
83 * in the same dma channel. */ 86 * in the same dma channel. */
84#define SOLO_P2M_DMA_ID_MP4E 0 87#define SOLO_P2M_DMA_ID_MP4E 0
@@ -123,11 +126,17 @@ enum SOLO_I2C_STATE {
123 IIC_STATE_STOP 126 IIC_STATE_STOP
124}; 127};
125 128
129struct p2m_desc {
130 u32 ctrl;
131 u32 ext;
132 u32 ta;
133 u32 fa;
134};
135
126struct solo_p2m_dev { 136struct solo_p2m_dev {
127 struct semaphore sem; 137 struct mutex mutex;
128 struct completion completion; 138 struct completion completion;
129 int error; 139 int error;
130 u8 desc[SOLO_P2M_DESC_SIZE];
131}; 140};
132 141
133#define OSD_TEXT_MAX 30 142#define OSD_TEXT_MAX 30
@@ -185,7 +194,7 @@ struct solo6010_dev {
185 /* i2c related items */ 194 /* i2c related items */
186 struct i2c_adapter i2c_adap[SOLO_I2C_ADAPTERS]; 195 struct i2c_adapter i2c_adap[SOLO_I2C_ADAPTERS];
187 enum SOLO_I2C_STATE i2c_state; 196 enum SOLO_I2C_STATE i2c_state;
188 struct semaphore i2c_sem; 197 struct mutex i2c_mutex;
189 int i2c_id; 198 int i2c_id;
190 wait_queue_head_t i2c_wait; 199 wait_queue_head_t i2c_wait;
191 struct i2c_msg *i2c_msg; 200 struct i2c_msg *i2c_msg;
@@ -212,7 +221,7 @@ struct solo6010_dev {
212 struct solo_enc_buf enc_buf[SOLO_NR_RING_BUFS]; 221 struct solo_enc_buf enc_buf[SOLO_NR_RING_BUFS];
213 222
214 /* Current video settings */ 223 /* Current video settings */
215 u32 video_type; 224 u32 video_type;
216 u16 video_hsize, video_vsize; 225 u16 video_hsize, video_vsize;
217 u16 vout_hstart, vout_vstart; 226 u16 vout_hstart, vout_vstart;
218 u16 vin_hstart, vin_vstart; 227 u16 vin_hstart, vin_vstart;
@@ -306,6 +315,14 @@ int solo_p2m_dma_t(struct solo6010_dev *solo_dev, u8 id, int wr,
306 dma_addr_t dma_addr, u32 ext_addr, u32 size); 315 dma_addr_t dma_addr, u32 ext_addr, u32 size);
307int solo_p2m_dma(struct solo6010_dev *solo_dev, u8 id, int wr, 316int solo_p2m_dma(struct solo6010_dev *solo_dev, u8 id, int wr,
308 void *sys_addr, u32 ext_addr, u32 size); 317 void *sys_addr, u32 ext_addr, u32 size);
318int solo_p2m_dma_sg(struct solo6010_dev *solo_dev, u8 id,
319 struct p2m_desc *pdesc, int wr,
320 struct scatterlist *sglist, u32 sg_off,
321 u32 ext_addr, u32 size);
322void solo_p2m_push_desc(struct p2m_desc *desc, int wr, dma_addr_t dma_addr,
323 u32 ext_addr, u32 size, int repeat, u32 ext_size);
324int solo_p2m_dma_desc(struct solo6010_dev *solo_dev, u8 id,
325 struct p2m_desc *desc, int desc_count);
309 326
310/* Set the threshold for motion detection */ 327/* Set the threshold for motion detection */
311void solo_set_motion_threshold(struct solo6010_dev *solo_dev, u8 ch, u16 val); 328void solo_set_motion_threshold(struct solo6010_dev *solo_dev, u8 ch, u16 val);
diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
index cc79f9edfe9e..408bb9b3303e 100644
--- a/drivers/staging/speakup/kobjects.c
+++ b/drivers/staging/speakup/kobjects.c
@@ -984,8 +984,10 @@ int speakup_kobj_init(void)
984 * not known ahead of time. 984 * not known ahead of time.
985 */ 985 */
986 accessibility_kobj = kobject_create_and_add("accessibility", NULL); 986 accessibility_kobj = kobject_create_and_add("accessibility", NULL);
987 if (!accessibility_kobj) 987 if (!accessibility_kobj) {
988 return -ENOMEM; 988 retval = -ENOMEM;
989 goto out;
990 }
989 991
990 speakup_kobj = kobject_create_and_add("speakup", accessibility_kobj); 992 speakup_kobj = kobject_create_and_add("speakup", accessibility_kobj);
991 if (!speakup_kobj) { 993 if (!speakup_kobj) {
@@ -1002,7 +1004,7 @@ int speakup_kobj_init(void)
1002 if (retval) 1004 if (retval)
1003 goto err_group; 1005 goto err_group;
1004 1006
1005 return 0; 1007 goto out;
1006 1008
1007err_group: 1009err_group:
1008 sysfs_remove_group(speakup_kobj, &main_attr_group); 1010 sysfs_remove_group(speakup_kobj, &main_attr_group);
@@ -1010,6 +1012,7 @@ err_speakup:
1010 kobject_put(speakup_kobj); 1012 kobject_put(speakup_kobj);
1011err_acc: 1013err_acc:
1012 kobject_put(accessibility_kobj); 1014 kobject_put(accessibility_kobj);
1015out:
1013 return retval; 1016 return retval;
1014} 1017}
1015 1018
diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index 4b7a9c2b965f..3cd00396a462 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -2253,17 +2253,17 @@ static int __init speakup_init(void)
2253 2253
2254 err = speakup_add_virtual_keyboard(); 2254 err = speakup_add_virtual_keyboard();
2255 if (err) 2255 if (err)
2256 return err; 2256 goto out;
2257 2257
2258 initialize_msgs(); /* Initialize arrays for i18n. */ 2258 initialize_msgs(); /* Initialize arrays for i18n. */
2259 first_console = kzalloc(sizeof(*first_console), GFP_KERNEL); 2259 first_console = kzalloc(sizeof(*first_console), GFP_KERNEL);
2260 if (!first_console) 2260 if (!first_console) {
2261 return -ENOMEM; 2261 err = -ENOMEM;
2262 err = speakup_kobj_init(); 2262 goto err_cons;
2263 if (err) {
2264 kfree(first_console);
2265 return err;
2266 } 2263 }
2264 err = speakup_kobj_init();
2265 if (err)
2266 goto err_kobject;
2267 2267
2268 reset_default_chars(); 2268 reset_default_chars();
2269 reset_default_chartab(); 2269 reset_default_chartab();
@@ -2299,11 +2299,20 @@ static int __init speakup_init(void)
2299 2299
2300 speakup_task = kthread_create(speakup_thread, NULL, "speakup"); 2300 speakup_task = kthread_create(speakup_thread, NULL, "speakup");
2301 set_user_nice(speakup_task, 10); 2301 set_user_nice(speakup_task, 10);
2302 if (!IS_ERR(speakup_task)) 2302 if (IS_ERR(speakup_task)) {
2303 wake_up_process(speakup_task); 2303 err = -ENOMEM;
2304 else 2304 goto err_kobject;
2305 return -ENOMEM; 2305 }
2306 return 0; 2306 wake_up_process(speakup_task);
2307 goto out;
2308
2309err_kobject:
2310speakup_kobj_exit();
2311 kfree(first_console);
2312err_cons:
2313 speakup_remove_virtual_keyboard();
2314out:
2315 return err;
2307} 2316}
2308 2317
2309module_init(speakup_init); 2318module_init(speakup_init);
diff --git a/drivers/staging/speakup/spk_types.h b/drivers/staging/speakup/spk_types.h
index 840bddb64101..d36c90e30d54 100644
--- a/drivers/staging/speakup/spk_types.h
+++ b/drivers/staging/speakup/spk_types.h
@@ -52,7 +52,7 @@ typedef int (*special_func)(struct vc_data *vc, u_char type, u_char ch,
52 52
53#define COLOR_BUFFER_SIZE 160 53#define COLOR_BUFFER_SIZE 160
54 54
55struct spk_highlight_color_track{ 55struct spk_highlight_color_track {
56 /* Count of each background color */ 56 /* Count of each background color */
57 unsigned int bgcount[8]; 57 unsigned int bgcount[8];
58 /* Buffer for characters drawn with each background color */ 58 /* Buffer for characters drawn with each background color */
diff --git a/drivers/staging/spectra/ffsport.c b/drivers/staging/spectra/ffsport.c
index 63a9d0adf32d..007b24b54e25 100644
--- a/drivers/staging/spectra/ffsport.c
+++ b/drivers/staging/spectra/ffsport.c
@@ -28,6 +28,7 @@
28#include <linux/log2.h> 28#include <linux/log2.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/async.h>
31 32
32/**** Helper functions used for Div, Remainder operation on u64 ****/ 33/**** Helper functions used for Div, Remainder operation on u64 ****/
33 34
@@ -729,34 +730,16 @@ static void create_sysfs_entry(struct device *dev)
729} 730}
730*/ 731*/
731 732
732static int GLOB_SBD_init(void) 733static void register_spectra_ftl_async(void *unused, async_cookie_t cookie)
733{ 734{
734 int i; 735 int i;
735 736
736 /* Set debug output level (0~3) here. 3 is most verbose */
737 printk(KERN_ALERT "Spectra: %s\n", GLOB_version);
738
739 mutex_init(&spectra_lock);
740
741 GLOB_SBD_majornum = register_blkdev(0, GLOB_SBD_NAME);
742 if (GLOB_SBD_majornum <= 0) {
743 printk(KERN_ERR "Unable to get the major %d for Spectra",
744 GLOB_SBD_majornum);
745 return -EBUSY;
746 }
747
748 if (PASS != GLOB_FTL_Flash_Init()) {
749 printk(KERN_ERR "Spectra: Unable to Initialize Flash Device. "
750 "Aborting\n");
751 goto out_flash_register;
752 }
753
754 /* create_sysfs_entry(&dev->dev); */ 737 /* create_sysfs_entry(&dev->dev); */
755 738
756 if (PASS != GLOB_FTL_IdentifyDevice(&IdentifyDeviceData)) { 739 if (PASS != GLOB_FTL_IdentifyDevice(&IdentifyDeviceData)) {
757 printk(KERN_ERR "Spectra: Unable to Read Flash Device. " 740 printk(KERN_ERR "Spectra: Unable to Read Flash Device. "
758 "Aborting\n"); 741 "Aborting\n");
759 goto out_flash_register; 742 return;
760 } else { 743 } else {
761 nand_dbg_print(NAND_DBG_WARN, "In GLOB_SBD_init: " 744 nand_dbg_print(NAND_DBG_WARN, "In GLOB_SBD_init: "
762 "Num blocks=%d, pagesperblock=%d, " 745 "Num blocks=%d, pagesperblock=%d, "
@@ -775,24 +758,50 @@ static int GLOB_SBD_init(void)
775 } 758 }
776 printk(KERN_ALERT "Spectra: block table has been found.\n"); 759 printk(KERN_ALERT "Spectra: block table has been found.\n");
777 760
761 GLOB_SBD_majornum = register_blkdev(0, GLOB_SBD_NAME);
762 if (GLOB_SBD_majornum <= 0) {
763 printk(KERN_ERR "Unable to get the major %d for Spectra",
764 GLOB_SBD_majornum);
765 goto out_ftl_flash_register;
766 }
767
778 for (i = 0; i < NUM_DEVICES; i++) 768 for (i = 0; i < NUM_DEVICES; i++)
779 if (SBD_setup_device(&nand_device[i], i) == -ENOMEM) 769 if (SBD_setup_device(&nand_device[i], i) == -ENOMEM)
780 goto out_ftl_flash_register; 770 goto out_blk_register;
781 771
782 nand_dbg_print(NAND_DBG_DEBUG, 772 nand_dbg_print(NAND_DBG_DEBUG,
783 "Spectra: module loaded with major number %d\n", 773 "Spectra: module loaded with major number %d\n",
784 GLOB_SBD_majornum); 774 GLOB_SBD_majornum);
785 775
786 return 0; 776 return;
787 777
778out_blk_register:
779 unregister_blkdev(GLOB_SBD_majornum, GLOB_SBD_NAME);
788out_ftl_flash_register: 780out_ftl_flash_register:
789 GLOB_FTL_Cache_Release(); 781 GLOB_FTL_Cache_Release();
790out_flash_register:
791 GLOB_FTL_Flash_Release();
792 unregister_blkdev(GLOB_SBD_majornum, GLOB_SBD_NAME);
793 printk(KERN_ERR "Spectra: Module load failed.\n"); 782 printk(KERN_ERR "Spectra: Module load failed.\n");
783}
794 784
795 return -ENOMEM; 785int register_spectra_ftl()
786{
787 async_schedule(register_spectra_ftl_async, NULL);
788 return 0;
789}
790EXPORT_SYMBOL_GPL(register_spectra_ftl);
791
792static int GLOB_SBD_init(void)
793{
794 /* Set debug output level (0~3) here. 3 is most verbose */
795 printk(KERN_ALERT "Spectra: %s\n", GLOB_version);
796
797 mutex_init(&spectra_lock);
798
799 if (PASS != GLOB_FTL_Flash_Init()) {
800 printk(KERN_ERR "Spectra: Unable to Initialize Flash Device. "
801 "Aborting\n");
802 return -ENODEV;
803 }
804 return 0;
796} 805}
797 806
798static void __exit GLOB_SBD_exit(void) 807static void __exit GLOB_SBD_exit(void)
diff --git a/drivers/staging/spectra/ffsport.h b/drivers/staging/spectra/ffsport.h
index 6c5d90c53430..85c0750612f6 100644
--- a/drivers/staging/spectra/ffsport.h
+++ b/drivers/staging/spectra/ffsport.h
@@ -80,5 +80,6 @@ extern int nand_debug_level;
80extern int GLOB_Calc_Used_Bits(u32 n); 80extern int GLOB_Calc_Used_Bits(u32 n);
81extern u64 GLOB_u64_Div(u64 addr, u32 divisor); 81extern u64 GLOB_u64_Div(u64 addr, u32 divisor);
82extern u64 GLOB_u64_Remainder(u64 addr, u32 divisor_type); 82extern u64 GLOB_u64_Remainder(u64 addr, u32 divisor_type);
83extern int register_spectra_ftl(void);
83 84
84#endif /* _FFSPORT_ */ 85#endif /* _FFSPORT_ */
diff --git a/drivers/staging/spectra/flash.c b/drivers/staging/spectra/flash.c
index 4e6e451cd5c8..fb39c8ecf596 100644
--- a/drivers/staging/spectra/flash.c
+++ b/drivers/staging/spectra/flash.c
@@ -1258,9 +1258,7 @@ int GLOB_FTL_Flash_Init(void)
1258 1258
1259 g_SBDCmdIndex = 0; 1259 g_SBDCmdIndex = 0;
1260 1260
1261 GLOB_LLD_Flash_Init(); 1261 status = GLOB_LLD_Flash_Init();
1262
1263 status = GLOB_LLD_Read_Device_ID();
1264 1262
1265 return status; 1263 return status;
1266} 1264}
diff --git a/drivers/staging/spectra/lld_emu.c b/drivers/staging/spectra/lld_emu.c
index 6733bbf8016d..095f2f0c2e5b 100644
--- a/drivers/staging/spectra/lld_emu.c
+++ b/drivers/staging/spectra/lld_emu.c
@@ -180,10 +180,8 @@ u16 emu_Flash_Init(void)
180 nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n", 180 nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
181 __FILE__, __LINE__, __func__); 181 __FILE__, __LINE__, __func__);
182 182
183 flash_memory[0] = (u8 *)vmalloc(GLOB_LLD_PAGE_SIZE * 183 flash_memory[0] = vmalloc(GLOB_LLD_PAGE_SIZE * GLOB_LLD_BLOCKS *
184 GLOB_LLD_BLOCKS * 184 GLOB_LLD_PAGES * sizeof(u8));
185 GLOB_LLD_PAGES *
186 sizeof(u8));
187 if (!flash_memory[0]) { 185 if (!flash_memory[0]) {
188 printk(KERN_ERR "Fail to allocate memory " 186 printk(KERN_ERR "Fail to allocate memory "
189 "for nand emulator!\n"); 187 "for nand emulator!\n");
diff --git a/drivers/staging/spectra/lld_nand.c b/drivers/staging/spectra/lld_nand.c
index 0d647a8fd2b6..2263d3ea5456 100644
--- a/drivers/staging/spectra/lld_nand.c
+++ b/drivers/staging/spectra/lld_nand.c
@@ -2395,14 +2395,94 @@ static int nand_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
2395 unsigned long csr_base; 2395 unsigned long csr_base;
2396 unsigned long csr_len; 2396 unsigned long csr_len;
2397 struct mrst_nand_info *pndev = &info; 2397 struct mrst_nand_info *pndev = &info;
2398 u32 int_mask;
2398 2399
2399 nand_dbg_print(NAND_DBG_WARN, "%s, Line %d, Function: %s\n", 2400 nand_dbg_print(NAND_DBG_WARN, "%s, Line %d, Function: %s\n",
2400 __FILE__, __LINE__, __func__); 2401 __FILE__, __LINE__, __func__);
2401 2402
2403 FlashReg = ioremap_nocache(GLOB_HWCTL_REG_BASE,
2404 GLOB_HWCTL_REG_SIZE);
2405 if (!FlashReg) {
2406 printk(KERN_ERR "Spectra: ioremap_nocache failed!");
2407 return -ENOMEM;
2408 }
2409 nand_dbg_print(NAND_DBG_WARN,
2410 "Spectra: Remapped reg base address: "
2411 "0x%p, len: %d\n",
2412 FlashReg, GLOB_HWCTL_REG_SIZE);
2413
2414 FlashMem = ioremap_nocache(GLOB_HWCTL_MEM_BASE,
2415 GLOB_HWCTL_MEM_SIZE);
2416 if (!FlashMem) {
2417 printk(KERN_ERR "Spectra: ioremap_nocache failed!");
2418 iounmap(FlashReg);
2419 return -ENOMEM;
2420 }
2421 nand_dbg_print(NAND_DBG_WARN,
2422 "Spectra: Remapped flash base address: "
2423 "0x%p, len: %d\n",
2424 (void *)FlashMem, GLOB_HWCTL_MEM_SIZE);
2425
2426 nand_dbg_print(NAND_DBG_DEBUG, "Dump timing register values:"
2427 "acc_clks: %d, re_2_we: %d, we_2_re: %d,"
2428 "addr_2_data: %d, rdwr_en_lo_cnt: %d, "
2429 "rdwr_en_hi_cnt: %d, cs_setup_cnt: %d\n",
2430 ioread32(FlashReg + ACC_CLKS),
2431 ioread32(FlashReg + RE_2_WE),
2432 ioread32(FlashReg + WE_2_RE),
2433 ioread32(FlashReg + ADDR_2_DATA),
2434 ioread32(FlashReg + RDWR_EN_LO_CNT),
2435 ioread32(FlashReg + RDWR_EN_HI_CNT),
2436 ioread32(FlashReg + CS_SETUP_CNT));
2437
2438 NAND_Flash_Reset();
2439
2440 iowrite32(0, FlashReg + GLOBAL_INT_ENABLE);
2441
2442#if CMD_DMA
2443 info.pcmds_num = 0;
2444 info.flash_bank = 0;
2445 info.cdma_num = 0;
2446 int_mask = (DMA_INTR__DESC_COMP_CHANNEL0 |
2447 DMA_INTR__DESC_COMP_CHANNEL1 |
2448 DMA_INTR__DESC_COMP_CHANNEL2 |
2449 DMA_INTR__DESC_COMP_CHANNEL3 |
2450 DMA_INTR__MEMCOPY_DESC_COMP);
2451 iowrite32(int_mask, FlashReg + DMA_INTR_EN);
2452 iowrite32(0xFFFF, FlashReg + DMA_INTR);
2453
2454 int_mask = (INTR_STATUS0__ECC_ERR |
2455 INTR_STATUS0__PROGRAM_FAIL |
2456 INTR_STATUS0__ERASE_FAIL);
2457#else
2458 int_mask = INTR_STATUS0__DMA_CMD_COMP |
2459 INTR_STATUS0__ECC_TRANSACTION_DONE |
2460 INTR_STATUS0__ECC_ERR |
2461 INTR_STATUS0__PROGRAM_FAIL |
2462 INTR_STATUS0__ERASE_FAIL;
2463#endif
2464 iowrite32(int_mask, FlashReg + INTR_EN0);
2465 iowrite32(int_mask, FlashReg + INTR_EN1);
2466 iowrite32(int_mask, FlashReg + INTR_EN2);
2467 iowrite32(int_mask, FlashReg + INTR_EN3);
2468
2469 /* Clear all status bits */
2470 iowrite32(0xFFFF, FlashReg + INTR_STATUS0);
2471 iowrite32(0xFFFF, FlashReg + INTR_STATUS1);
2472 iowrite32(0xFFFF, FlashReg + INTR_STATUS2);
2473 iowrite32(0xFFFF, FlashReg + INTR_STATUS3);
2474
2475 iowrite32(0x0F, FlashReg + RB_PIN_ENABLED);
2476 iowrite32(CHIP_EN_DONT_CARE__FLAG, FlashReg + CHIP_ENABLE_DONT_CARE);
2477
2478 /* Should set value for these registers when init */
2479 iowrite32(0, FlashReg + TWO_ROW_ADDR_CYCLES);
2480 iowrite32(1, FlashReg + ECC_ENABLE);
2481 enable_ecc = 1;
2402 ret = pci_enable_device(dev); 2482 ret = pci_enable_device(dev);
2403 if (ret) { 2483 if (ret) {
2404 printk(KERN_ERR "Spectra: pci_enable_device failed.\n"); 2484 printk(KERN_ERR "Spectra: pci_enable_device failed.\n");
2405 return ret; 2485 goto failed_req_csr;
2406 } 2486 }
2407 2487
2408 pci_set_master(dev); 2488 pci_set_master(dev);
@@ -2461,12 +2541,26 @@ static int nand_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
2461 2541
2462 pci_set_drvdata(dev, pndev); 2542 pci_set_drvdata(dev, pndev);
2463 2543
2544 ret = GLOB_LLD_Read_Device_ID();
2545 if (ret) {
2546 iounmap(pndev->ioaddr);
2547 goto failed_remap_csr;
2548 }
2549
2550 ret = register_spectra_ftl();
2551 if (ret) {
2552 iounmap(pndev->ioaddr);
2553 goto failed_remap_csr;
2554 }
2555
2464 return 0; 2556 return 0;
2465 2557
2466failed_remap_csr: 2558failed_remap_csr:
2467 pci_release_regions(dev); 2559 pci_release_regions(dev);
2468failed_req_csr: 2560failed_req_csr:
2469 pci_disable_device(dev); 2561 pci_disable_device(dev);
2562 iounmap(FlashMem);
2563 iounmap(FlashReg);
2470 2564
2471 return ret; 2565 return ret;
2472} 2566}
@@ -2498,91 +2592,10 @@ static struct pci_driver nand_pci_driver = {
2498int NAND_Flash_Init(void) 2592int NAND_Flash_Init(void)
2499{ 2593{
2500 int retval; 2594 int retval;
2501 u32 int_mask;
2502 2595
2503 nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n", 2596 nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
2504 __FILE__, __LINE__, __func__); 2597 __FILE__, __LINE__, __func__);
2505 2598
2506 FlashReg = ioremap_nocache(GLOB_HWCTL_REG_BASE,
2507 GLOB_HWCTL_REG_SIZE);
2508 if (!FlashReg) {
2509 printk(KERN_ERR "Spectra: ioremap_nocache failed!");
2510 return -ENOMEM;
2511 }
2512 nand_dbg_print(NAND_DBG_WARN,
2513 "Spectra: Remapped reg base address: "
2514 "0x%p, len: %d\n",
2515 FlashReg, GLOB_HWCTL_REG_SIZE);
2516
2517 FlashMem = ioremap_nocache(GLOB_HWCTL_MEM_BASE,
2518 GLOB_HWCTL_MEM_SIZE);
2519 if (!FlashMem) {
2520 printk(KERN_ERR "Spectra: ioremap_nocache failed!");
2521 iounmap(FlashReg);
2522 return -ENOMEM;
2523 }
2524 nand_dbg_print(NAND_DBG_WARN,
2525 "Spectra: Remapped flash base address: "
2526 "0x%p, len: %d\n",
2527 (void *)FlashMem, GLOB_HWCTL_MEM_SIZE);
2528
2529 nand_dbg_print(NAND_DBG_DEBUG, "Dump timing register values:"
2530 "acc_clks: %d, re_2_we: %d, we_2_re: %d,"
2531 "addr_2_data: %d, rdwr_en_lo_cnt: %d, "
2532 "rdwr_en_hi_cnt: %d, cs_setup_cnt: %d\n",
2533 ioread32(FlashReg + ACC_CLKS),
2534 ioread32(FlashReg + RE_2_WE),
2535 ioread32(FlashReg + WE_2_RE),
2536 ioread32(FlashReg + ADDR_2_DATA),
2537 ioread32(FlashReg + RDWR_EN_LO_CNT),
2538 ioread32(FlashReg + RDWR_EN_HI_CNT),
2539 ioread32(FlashReg + CS_SETUP_CNT));
2540
2541 NAND_Flash_Reset();
2542
2543 iowrite32(0, FlashReg + GLOBAL_INT_ENABLE);
2544
2545#if CMD_DMA
2546 info.pcmds_num = 0;
2547 info.flash_bank = 0;
2548 info.cdma_num = 0;
2549 int_mask = (DMA_INTR__DESC_COMP_CHANNEL0 |
2550 DMA_INTR__DESC_COMP_CHANNEL1 |
2551 DMA_INTR__DESC_COMP_CHANNEL2 |
2552 DMA_INTR__DESC_COMP_CHANNEL3 |
2553 DMA_INTR__MEMCOPY_DESC_COMP);
2554 iowrite32(int_mask, FlashReg + DMA_INTR_EN);
2555 iowrite32(0xFFFF, FlashReg + DMA_INTR);
2556
2557 int_mask = (INTR_STATUS0__ECC_ERR |
2558 INTR_STATUS0__PROGRAM_FAIL |
2559 INTR_STATUS0__ERASE_FAIL);
2560#else
2561 int_mask = INTR_STATUS0__DMA_CMD_COMP |
2562 INTR_STATUS0__ECC_TRANSACTION_DONE |
2563 INTR_STATUS0__ECC_ERR |
2564 INTR_STATUS0__PROGRAM_FAIL |
2565 INTR_STATUS0__ERASE_FAIL;
2566#endif
2567 iowrite32(int_mask, FlashReg + INTR_EN0);
2568 iowrite32(int_mask, FlashReg + INTR_EN1);
2569 iowrite32(int_mask, FlashReg + INTR_EN2);
2570 iowrite32(int_mask, FlashReg + INTR_EN3);
2571
2572 /* Clear all status bits */
2573 iowrite32(0xFFFF, FlashReg + INTR_STATUS0);
2574 iowrite32(0xFFFF, FlashReg + INTR_STATUS1);
2575 iowrite32(0xFFFF, FlashReg + INTR_STATUS2);
2576 iowrite32(0xFFFF, FlashReg + INTR_STATUS3);
2577
2578 iowrite32(0x0F, FlashReg + RB_PIN_ENABLED);
2579 iowrite32(CHIP_EN_DONT_CARE__FLAG, FlashReg + CHIP_ENABLE_DONT_CARE);
2580
2581 /* Should set value for these registers when init */
2582 iowrite32(0, FlashReg + TWO_ROW_ADDR_CYCLES);
2583 iowrite32(1, FlashReg + ECC_ENABLE);
2584 enable_ecc = 1;
2585
2586 retval = pci_register_driver(&nand_pci_driver); 2599 retval = pci_register_driver(&nand_pci_driver);
2587 if (retval) 2600 if (retval)
2588 return -ENOMEM; 2601 return -ENOMEM;
diff --git a/drivers/staging/ste_rmi4/Kconfig b/drivers/staging/ste_rmi4/Kconfig
new file mode 100644
index 000000000000..e8679509e525
--- /dev/null
+++ b/drivers/staging/ste_rmi4/Kconfig
@@ -0,0 +1,9 @@
1config TOUCHSCREEN_SYNAPTICS_I2C_RMI4
2 tristate "Synaptics i2c rmi4 touchscreen"
3 depends on I2C && INPUT
4 help
5 Say Y here if you have a Synaptics RMI4 and
6 want to enable support for the built-in touchscreen.
7
8 To compile this driver as a module, choose M here: the
9 module will be called synaptics_rmi4_ts.
diff --git a/drivers/staging/ste_rmi4/Makefile b/drivers/staging/ste_rmi4/Makefile
new file mode 100644
index 000000000000..6cce2ed187ef
--- /dev/null
+++ b/drivers/staging/ste_rmi4/Makefile
@@ -0,0 +1,4 @@
1#
2# Makefile for the RMI4 touchscreen driver.
3#
4obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4) += synaptics_i2c_rmi4.o
diff --git a/drivers/staging/ste_rmi4/TODO b/drivers/staging/ste_rmi4/TODO
new file mode 100644
index 000000000000..9be2437da85f
--- /dev/null
+++ b/drivers/staging/ste_rmi4/TODO
@@ -0,0 +1,7 @@
1TODO
2----
3
4Wait for the official upstream synaptics rmi4 clearpad drivers as promised over the past few months
5Merge any device support needed from this driver into it
6Delete this driver
7
diff --git a/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
new file mode 100644
index 000000000000..e8f047e86a32
--- /dev/null
+++ b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
@@ -0,0 +1,1179 @@
1/**
2 *
3 * Synaptics Register Mapped Interface (RMI4) I2C Physical Layer Driver.
4 * Copyright (c) 2007-2010, Synaptics Incorporated
5 *
6 * Author: Js HA <js.ha@stericsson.com> for ST-Ericsson
7 * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson
8 * Copyright 2010 (c) ST-Ericsson AB
9 */
10/*
11 * This file is licensed under the GPL2 license.
12 *
13 *#############################################################################
14 * GPL
15 *
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License version 2 as published
18 * by the Free Software Foundation.
19 *
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * for more details.
24 *
25 *#############################################################################
26 */
27
28#include <linux/input.h>
29#include <linux/slab.h>
30#include <linux/i2c.h>
31#include <linux/interrupt.h>
32#include <linux/regulator/consumer.h>
33#include "synaptics_i2c_rmi4.h"
34
35/* TODO: for multiple device support will need a per-device mutex */
36#define DRIVER_NAME "synaptics_rmi4_i2c"
37
38#define MAX_ERROR_REPORT 6
39#define MAX_TOUCH_MAJOR 15
40#define MAX_RETRY_COUNT 5
41#define STD_QUERY_LEN 21
42#define PAGE_LEN 2
43#define DATA_BUF_LEN 32
44#define BUF_LEN 37
45#define QUERY_LEN 9
46#define DATA_LEN 12
47#define HAS_TAP 0x01
48#define HAS_PALMDETECT 0x01
49#define HAS_ROTATE 0x02
50#define HAS_TAPANDHOLD 0x02
51#define HAS_DOUBLETAP 0x04
52#define HAS_EARLYTAP 0x08
53#define HAS_RELEASE 0x08
54#define HAS_FLICK 0x10
55#define HAS_PRESS 0x20
56#define HAS_PINCH 0x40
57
58#define MASK_16BIT 0xFFFF
59#define MASK_8BIT 0xFF
60#define MASK_7BIT 0x7F
61#define MASK_5BIT 0x1F
62#define MASK_4BIT 0x0F
63#define MASK_3BIT 0x07
64#define MASK_2BIT 0x03
65#define TOUCHPAD_CTRL_INTR 0x8
66#define PDT_START_SCAN_LOCATION (0x00E9)
67#define PDT_END_SCAN_LOCATION (0x000A)
68#define PDT_ENTRY_SIZE (0x0006)
69#define RMI4_NUMBER_OF_MAX_FINGERS (8)
70#define SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM (0x11)
71#define SYNAPTICS_RMI4_DEVICE_CONTROL_FUNC_NUM (0x01)
72
73/**
74 * struct synaptics_rmi4_fn_desc - contains the funtion descriptor information
75 * @query_base_addr: base address for query
76 * @cmd_base_addr: base address for command
77 * @ctrl_base_addr: base address for control
78 * @data_base_addr: base address for data
79 * @intr_src_count: count for the interrupt source
80 * @fn_number: function number
81 *
82 * This structure is used to gives the function descriptor information
83 * of the particular functionality.
84 */
85struct synaptics_rmi4_fn_desc {
86 unsigned char query_base_addr;
87 unsigned char cmd_base_addr;
88 unsigned char ctrl_base_addr;
89 unsigned char data_base_addr;
90 unsigned char intr_src_count;
91 unsigned char fn_number;
92};
93
94/**
95 * struct synaptics_rmi4_fn - contains the funtion information
96 * @fn_number: function number
97 * @num_of_data_sources: number of data sources
98 * @num_of_data_points: number of fingers touched
99 * @size_of_data_register_block: data register block size
100 * @index_to_intr_reg: index for interrupt register
101 * @intr_mask: interrupt mask value
102 * @fn_desc: variable for function descriptor structure
103 * @link: linked list for function descriptors
104 *
105 * This structure gives information about the number of data sources and
106 * the number of data registers associated with the function.
107 */
108struct synaptics_rmi4_fn {
109 unsigned char fn_number;
110 unsigned char num_of_data_sources;
111 unsigned char num_of_data_points;
112 unsigned char size_of_data_register_block;
113 unsigned char index_to_intr_reg;
114 unsigned char intr_mask;
115 struct synaptics_rmi4_fn_desc fn_desc;
116 struct list_head link;
117};
118
119/**
120 * struct synaptics_rmi4_device_info - contains the rmi4 device information
121 * @version_major: protocol major version number
122 * @version_minor: protocol minor version number
123 * @manufacturer_id: manufacturer identification byte
124 * @product_props: product properties information
125 * @product_info: product info array
126 * @date_code: device manufacture date
127 * @tester_id: tester id array
128 * @serial_number: serial number for that device
129 * @product_id_string: product id for the device
130 * @support_fn_list: linked list for device information
131 *
132 * This structure gives information about the number of data sources and
133 * the number of data registers associated with the function.
134 */
135struct synaptics_rmi4_device_info {
136 unsigned int version_major;
137 unsigned int version_minor;
138 unsigned char manufacturer_id;
139 unsigned char product_props;
140 unsigned char product_info[2];
141 unsigned char date_code[3];
142 unsigned short tester_id;
143 unsigned short serial_number;
144 unsigned char product_id_string[11];
145 struct list_head support_fn_list;
146};
147
148/**
149 * struct synaptics_rmi4_data - contains the rmi4 device data
150 * @rmi4_mod_info: structure variable for rmi4 device info
151 * @input_dev: pointer for input device
152 * @i2c_client: pointer for i2c client
153 * @board: constant pointer for touch platform data
154 * @fn_list_mutex: mutex for funtion list
155 * @rmi4_page_mutex: mutex for rmi4 page
156 * @current_page: variable for integer
157 * @number_of_interrupt_register: interrupt registers count
158 * @fn01_ctrl_base_addr: control base address for fn01
159 * @fn01_query_base_addr: query base address for fn01
160 * @fn01_data_base_addr: data base address for fn01
161 * @sensor_max_x: sensor maximum x value
162 * @sensor_max_y: sensor maximum y value
163 * @regulator: pointer to the regulator structure
164 * @wait: wait queue structure variable
165 * @touch_stopped: flag to stop the thread function
166 *
167 * This structure gives the device data information.
168 */
169struct synaptics_rmi4_data {
170 struct synaptics_rmi4_device_info rmi4_mod_info;
171 struct input_dev *input_dev;
172 struct i2c_client *i2c_client;
173 const struct synaptics_rmi4_platform_data *board;
174 struct mutex fn_list_mutex;
175 struct mutex rmi4_page_mutex;
176 int current_page;
177 unsigned int number_of_interrupt_register;
178 unsigned short fn01_ctrl_base_addr;
179 unsigned short fn01_query_base_addr;
180 unsigned short fn01_data_base_addr;
181 int sensor_max_x;
182 int sensor_max_y;
183 struct regulator *regulator;
184 wait_queue_head_t wait;
185 bool touch_stopped;
186};
187
188/**
189 * synaptics_rmi4_set_page() - sets the page
190 * @pdata: pointer to synaptics_rmi4_data structure
191 * @address: set the address of the page
192 *
193 * This function is used to set the page and returns integer.
194 */
195static int synaptics_rmi4_set_page(struct synaptics_rmi4_data *pdata,
196 unsigned int address)
197{
198 unsigned char txbuf[PAGE_LEN];
199 int retval;
200 unsigned int page;
201 struct i2c_client *i2c = pdata->i2c_client;
202
203 page = ((address >> 8) & MASK_8BIT);
204 if (page != pdata->current_page) {
205 txbuf[0] = MASK_8BIT;
206 txbuf[1] = page;
207 retval = i2c_master_send(i2c, txbuf, PAGE_LEN);
208 if (retval != PAGE_LEN)
209 dev_err(&i2c->dev, "%s:failed:%d\n", __func__, retval);
210 else
211 pdata->current_page = page;
212 } else
213 retval = PAGE_LEN;
214 return retval;
215}
216/**
217 * synaptics_rmi4_i2c_block_read() - read the block of data
218 * @pdata: pointer to synaptics_rmi4_data structure
219 * @address: read the block of data from this offset
220 * @valp: pointer to a buffer containing the data to be read
221 * @size: number of bytes to read
222 *
223 * This function is to read the block of data and returns integer.
224 */
225static int synaptics_rmi4_i2c_block_read(struct synaptics_rmi4_data *pdata,
226 unsigned short address,
227 unsigned char *valp, int size)
228{
229 int retval = 0;
230 int retry_count = 0;
231 int index;
232 struct i2c_client *i2c = pdata->i2c_client;
233
234 mutex_lock(&(pdata->rmi4_page_mutex));
235 retval = synaptics_rmi4_set_page(pdata, address);
236 if (retval != PAGE_LEN)
237 goto exit;
238 index = address & MASK_8BIT;
239retry:
240 retval = i2c_smbus_read_i2c_block_data(i2c, index, size, valp);
241 if (retval != size) {
242 if (++retry_count == MAX_RETRY_COUNT)
243 dev_err(&i2c->dev,
244 "%s:address 0x%04x size %d failed:%d\n",
245 __func__, address, size, retval);
246 else {
247 synaptics_rmi4_set_page(pdata, address);
248 goto retry;
249 }
250 }
251exit:
252 mutex_unlock(&(pdata->rmi4_page_mutex));
253 return retval;
254}
255
256/**
257 * synaptics_rmi4_i2c_byte_write() - write the single byte data
258 * @pdata: pointer to synaptics_rmi4_data structure
259 * @address: write the block of data from this offset
260 * @data: data to be write
261 *
262 * This function is to write the single byte data and returns integer.
263 */
264static int synaptics_rmi4_i2c_byte_write(struct synaptics_rmi4_data *pdata,
265 unsigned short address,
266 unsigned char data)
267{
268 unsigned char txbuf[2];
269 int retval = 0;
270 struct i2c_client *i2c = pdata->i2c_client;
271
272 /* Can't have anyone else changing the page behind our backs */
273 mutex_lock(&(pdata->rmi4_page_mutex));
274
275 retval = synaptics_rmi4_set_page(pdata, address);
276 if (retval != PAGE_LEN)
277 goto exit;
278 txbuf[0] = address & MASK_8BIT;
279 txbuf[1] = data;
280 retval = i2c_master_send(pdata->i2c_client, txbuf, 2);
281 /* Add in retry on writes only in certian error return values */
282 if (retval != 2) {
283 dev_err(&i2c->dev, "%s:failed:%d\n", __func__, retval);
284 retval = -EIO;
285 } else
286 retval = 1;
287exit:
288 mutex_unlock(&(pdata->rmi4_page_mutex));
289 return retval;
290}
291
292/**
293 * synpatics_rmi4_touchpad_report() - reports for the rmi4 touchpad device
294 * @pdata: pointer to synaptics_rmi4_data structure
295 * @rfi: pointer to synaptics_rmi4_fn structure
296 *
297 * This function calls to reports for the rmi4 touchpad device
298 */
299static int synpatics_rmi4_touchpad_report(struct synaptics_rmi4_data *pdata,
300 struct synaptics_rmi4_fn *rfi)
301{
302 /* number of touch points - fingers down in this case */
303 int touch_count = 0;
304 int finger;
305 int fingers_supported;
306 int finger_registers;
307 int reg;
308 int finger_shift;
309 int finger_status;
310 int retval;
311 unsigned short data_base_addr;
312 unsigned short data_offset;
313 unsigned char data_reg_blk_size;
314 unsigned char values[2];
315 unsigned char data[DATA_LEN];
316 int x[RMI4_NUMBER_OF_MAX_FINGERS];
317 int y[RMI4_NUMBER_OF_MAX_FINGERS];
318 int wx[RMI4_NUMBER_OF_MAX_FINGERS];
319 int wy[RMI4_NUMBER_OF_MAX_FINGERS];
320 struct i2c_client *client = pdata->i2c_client;
321
322 /* get 2D sensor finger data */
323 /*
324 * First get the finger status field - the size of the finger status
325 * field is determined by the number of finger supporte - 2 bits per
326 * finger, so the number of registers to read is:
327 * registerCount = ceil(numberOfFingers/4).
328 * Read the required number of registers and check each 2 bit field to
329 * determine if a finger is down:
330 * 00 = finger not present,
331 * 01 = finger present and data accurate,
332 * 10 = finger present but data may not be accurate,
333 * 11 = reserved for product use.
334 */
335 fingers_supported = rfi->num_of_data_points;
336 finger_registers = (fingers_supported + 3)/4;
337 data_base_addr = rfi->fn_desc.data_base_addr;
338 retval = synaptics_rmi4_i2c_block_read(pdata, data_base_addr, values,
339 finger_registers);
340 if (retval != finger_registers) {
341 dev_err(&client->dev, "%s:read status registers failed\n",
342 __func__);
343 return 0;
344 }
345 /*
346 * For each finger present, read the proper number of registers
347 * to get absolute data.
348 */
349 data_reg_blk_size = rfi->size_of_data_register_block;
350 for (finger = 0; finger < fingers_supported; finger++) {
351 /* determine which data byte the finger status is in */
352 reg = finger/4;
353 /* bit shift to get finger's status */
354 finger_shift = (finger % 4) * 2;
355 finger_status = (values[reg] >> finger_shift) & 3;
356 /*
357 * if finger status indicates a finger is present then
358 * read the finger data and report it
359 */
360 if (finger_status == 1 || finger_status == 2) {
361 /* Read the finger data */
362 data_offset = data_base_addr +
363 ((finger * data_reg_blk_size) +
364 finger_registers);
365 retval = synaptics_rmi4_i2c_block_read(pdata,
366 data_offset, data,
367 data_reg_blk_size);
368 if (retval != data_reg_blk_size) {
369 printk(KERN_ERR "%s:read data failed\n",
370 __func__);
371 return 0;
372 } else {
373 x[touch_count] =
374 (data[0] << 4) | (data[2] & MASK_4BIT);
375 y[touch_count] =
376 (data[1] << 4) |
377 ((data[2] >> 4) & MASK_4BIT);
378 wy[touch_count] =
379 (data[3] >> 4) & MASK_4BIT;
380 wx[touch_count] =
381 (data[3] & MASK_4BIT);
382
383 if (pdata->board->x_flip)
384 x[touch_count] =
385 pdata->sensor_max_x -
386 x[touch_count];
387 if (pdata->board->y_flip)
388 y[touch_count] =
389 pdata->sensor_max_y -
390 y[touch_count];
391 }
392 /* number of active touch points */
393 touch_count++;
394 }
395 }
396
397 /* report to input subsystem */
398 if (touch_count) {
399 for (finger = 0; finger < touch_count; finger++) {
400 input_report_abs(pdata->input_dev, ABS_MT_TOUCH_MAJOR,
401 max(wx[finger] , wy[finger]));
402 input_report_abs(pdata->input_dev, ABS_MT_POSITION_X,
403 x[finger]);
404 input_report_abs(pdata->input_dev, ABS_MT_POSITION_Y,
405 y[finger]);
406 input_mt_sync(pdata->input_dev);
407 }
408 } else
409 input_mt_sync(pdata->input_dev);
410
411 /* sync after groups of events */
412 input_sync(pdata->input_dev);
413 /* return the number of touch points */
414 return touch_count;
415}
416
417/**
418 * synaptics_rmi4_report_device() - reports the rmi4 device
419 * @pdata: pointer to synaptics_rmi4_data structure
420 * @rfi: pointer to synaptics_rmi4_fn
421 *
422 * This function is used to call the report function of the rmi4 device.
423 */
424static int synaptics_rmi4_report_device(struct synaptics_rmi4_data *pdata,
425 struct synaptics_rmi4_fn *rfi)
426{
427 int touch = 0;
428 struct i2c_client *client = pdata->i2c_client;
429 static int num_error_reports;
430 if (rfi->fn_number != SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM) {
431 num_error_reports++;
432 if (num_error_reports < MAX_ERROR_REPORT)
433 dev_err(&client->dev, "%s:report not supported\n",
434 __func__);
435 } else
436 touch = synpatics_rmi4_touchpad_report(pdata, rfi);
437 return touch;
438}
439/**
440 * synaptics_rmi4_sensor_report() - reports to input subsystem
441 * @pdata: pointer to synaptics_rmi4_data structure
442 *
443 * This function is used to reads in all data sources and reports
444 * them to the input subsystem.
445 */
446static int synaptics_rmi4_sensor_report(struct synaptics_rmi4_data *pdata)
447{
448 unsigned char intr_status[4];
449 /* number of touch points - fingers or buttons */
450 int touch = 0;
451 unsigned int retval;
452 struct synaptics_rmi4_fn *rfi;
453 struct synaptics_rmi4_device_info *rmi;
454 struct i2c_client *client = pdata->i2c_client;
455
456 /*
457 * Get the interrupt status from the function $01
458 * control register+1 to find which source(s) were interrupting
459 * so we can read the data from the source(s) (2D sensor, buttons..)
460 */
461 retval = synaptics_rmi4_i2c_block_read(pdata,
462 pdata->fn01_data_base_addr + 1,
463 intr_status,
464 pdata->number_of_interrupt_register);
465 if (retval != pdata->number_of_interrupt_register) {
466 dev_err(&client->dev,
467 "could not read interrupt status registers\n");
468 return 0;
469 }
470 /*
471 * check each function that has data sources and if the interrupt for
472 * that triggered then call that RMI4 functions report() function to
473 * gather data and report it to the input subsystem
474 */
475 rmi = &(pdata->rmi4_mod_info);
476 list_for_each_entry(rfi, &rmi->support_fn_list, link) {
477 if (rfi->num_of_data_sources) {
478 if (intr_status[rfi->index_to_intr_reg] &
479 rfi->intr_mask)
480 touch = synaptics_rmi4_report_device(pdata,
481 rfi);
482 }
483 }
484 /* return the number of touch points */
485 return touch;
486}
487
488/**
489 * synaptics_rmi4_irq() - thread function for rmi4 attention line
490 * @irq: irq value
491 * @data: void pointer
492 *
493 * This function is interrupt thread function. It just notifies the
494 * application layer that attention is required.
495 */
496static irqreturn_t synaptics_rmi4_irq(int irq, void *data)
497{
498 struct synaptics_rmi4_data *pdata = data;
499 int touch_count;
500 do {
501 touch_count = synaptics_rmi4_sensor_report(pdata);
502 if (touch_count)
503 wait_event_timeout(pdata->wait, pdata->touch_stopped,
504 msecs_to_jiffies(1));
505 else
506 break;
507 } while (!pdata->touch_stopped);
508 return IRQ_HANDLED;
509}
510
511/**
512 * synpatics_rmi4_touchpad_detect() - detects the rmi4 touchpad device
513 * @pdata: pointer to synaptics_rmi4_data structure
514 * @rfi: pointer to synaptics_rmi4_fn structure
515 * @fd: pointer to synaptics_rmi4_fn_desc structure
516 * @interruptcount: count the number of interrupts
517 *
518 * This function calls to detects the rmi4 touchpad device
519 */
520static int synpatics_rmi4_touchpad_detect(struct synaptics_rmi4_data *pdata,
521 struct synaptics_rmi4_fn *rfi,
522 struct synaptics_rmi4_fn_desc *fd,
523 unsigned int interruptcount)
524{
525 unsigned char queries[QUERY_LEN];
526 unsigned short intr_offset;
527 unsigned char abs_data_size;
528 unsigned char abs_data_blk_size;
529 unsigned char egr_0, egr_1;
530 unsigned int all_data_blk_size;
531 int has_pinch, has_flick, has_tap;
532 int has_tapandhold, has_doubletap;
533 int has_earlytap, has_press;
534 int has_palmdetect, has_rotate;
535 int has_rel;
536 int i;
537 int retval;
538 struct i2c_client *client = pdata->i2c_client;
539
540 rfi->fn_desc.query_base_addr = fd->query_base_addr;
541 rfi->fn_desc.data_base_addr = fd->data_base_addr;
542 rfi->fn_desc.intr_src_count = fd->intr_src_count;
543 rfi->fn_desc.fn_number = fd->fn_number;
544 rfi->fn_number = fd->fn_number;
545 rfi->num_of_data_sources = fd->intr_src_count;
546 rfi->fn_desc.ctrl_base_addr = fd->ctrl_base_addr;
547 rfi->fn_desc.cmd_base_addr = fd->cmd_base_addr;
548
549 /*
550 * need to get number of fingers supported, data size, etc.
551 * to be used when getting data since the number of registers to
552 * read depends on the number of fingers supported and data size.
553 */
554 retval = synaptics_rmi4_i2c_block_read(pdata, fd->query_base_addr,
555 queries,
556 sizeof(queries));
557 if (retval != sizeof(queries)) {
558 dev_err(&client->dev, "%s:read function query registers\n",
559 __func__);
560 return retval;
561 }
562 /*
563 * 2D data sources have only 3 bits for the number of fingers
564 * supported - so the encoding is a bit wierd.
565 */
566 if ((queries[1] & MASK_3BIT) <= 4)
567 /* add 1 since zero based */
568 rfi->num_of_data_points = (queries[1] & MASK_3BIT) + 1;
569 else {
570 /*
571 * a value of 5 is up to 10 fingers - 6 and 7 are reserved
572 * (shouldn't get these i int retval;n a normal 2D source).
573 */
574 if ((queries[1] & MASK_3BIT) == 5)
575 rfi->num_of_data_points = 10;
576 }
577 /* Need to get interrupt info for handling interrupts */
578 rfi->index_to_intr_reg = (interruptcount + 7)/8;
579 if (rfi->index_to_intr_reg != 0)
580 rfi->index_to_intr_reg -= 1;
581 /*
582 * loop through interrupts for each source in fn $11
583 * and or in a bit to the interrupt mask for each.
584 */
585 intr_offset = interruptcount % 8;
586 rfi->intr_mask = 0;
587 for (i = intr_offset;
588 i < ((fd->intr_src_count & MASK_3BIT) + intr_offset); i++)
589 rfi->intr_mask |= 1 << i;
590
591 /* Size of just the absolute data for one finger */
592 abs_data_size = queries[5] & MASK_2BIT;
593 /* One each for X and Y, one for LSB for X & Y, one for W, one for Z */
594 abs_data_blk_size = 3 + (2 * (abs_data_size == 0 ? 1 : 0));
595 rfi->size_of_data_register_block = abs_data_blk_size;
596
597 /*
598 * need to determine the size of data to read - this depends on
599 * conditions such as whether Relative data is reported and if Gesture
600 * data is reported.
601 */
602 egr_0 = queries[7];
603 egr_1 = queries[8];
604
605 /*
606 * Get info about what EGR data is supported, whether it has
607 * Relative data supported, etc.
608 */
609 has_pinch = egr_0 & HAS_PINCH;
610 has_flick = egr_0 & HAS_FLICK;
611 has_tap = egr_0 & HAS_TAP;
612 has_earlytap = egr_0 & HAS_EARLYTAP;
613 has_press = egr_0 & HAS_PRESS;
614 has_rotate = egr_1 & HAS_ROTATE;
615 has_rel = queries[1] & HAS_RELEASE;
616 has_tapandhold = egr_0 & HAS_TAPANDHOLD;
617 has_doubletap = egr_0 & HAS_DOUBLETAP;
618 has_palmdetect = egr_1 & HAS_PALMDETECT;
619
620 /*
621 * Size of all data including finger status, absolute data for each
622 * finger, relative data and EGR data
623 */
624 all_data_blk_size =
625 /* finger status, four fingers per register */
626 ((rfi->num_of_data_points + 3) / 4) +
627 /* absolute data, per finger times number of fingers */
628 (abs_data_blk_size * rfi->num_of_data_points) +
629 /*
630 * two relative registers (if relative is being reported)
631 */
632 2 * has_rel +
633 /*
634 * F11_2D_data8 is only present if the egr_0
635 * register is non-zero.
636 */
637 !!(egr_0) +
638 /*
639 * F11_2D_data9 is only present if either egr_0 or
640 * egr_1 registers are non-zero.
641 */
642 (egr_0 || egr_1) +
643 /*
644 * F11_2D_data10 is only present if EGR_PINCH or EGR_FLICK of
645 * egr_0 reports as 1.
646 */
647 !!(has_pinch | has_flick) +
648 /*
649 * F11_2D_data11 and F11_2D_data12 are only present if
650 * EGR_FLICK of egr_0 reports as 1.
651 */
652 2 * !!(has_flick);
653 return retval;
654}
655
656/**
657 * synpatics_rmi4_touchpad_config() - confiures the rmi4 touchpad device
658 * @pdata: pointer to synaptics_rmi4_data structure
659 * @rfi: pointer to synaptics_rmi4_fn structure
660 *
661 * This function calls to confiures the rmi4 touchpad device
662 */
663int synpatics_rmi4_touchpad_config(struct synaptics_rmi4_data *pdata,
664 struct synaptics_rmi4_fn *rfi)
665{
666 /*
667 * For the data source - print info and do any
668 * source specific configuration.
669 */
670 unsigned char data[BUF_LEN];
671 int retval = 0;
672 struct i2c_client *client = pdata->i2c_client;
673
674 /* Get and print some info about the data source... */
675 /* To Query 2D devices we need to read from the address obtained
676 * from the function descriptor stored in the RMI function info.
677 */
678 retval = synaptics_rmi4_i2c_block_read(pdata,
679 rfi->fn_desc.query_base_addr,
680 data, QUERY_LEN);
681 if (retval != QUERY_LEN)
682 dev_err(&client->dev, "%s:read query registers failed\n",
683 __func__);
684 else {
685 retval = synaptics_rmi4_i2c_block_read(pdata,
686 rfi->fn_desc.ctrl_base_addr,
687 data, DATA_BUF_LEN);
688 if (retval != DATA_BUF_LEN) {
689 dev_err(&client->dev,
690 "%s:read control registers failed\n",
691 __func__);
692 return retval;
693 }
694 /* Store these for use later*/
695 pdata->sensor_max_x = ((data[6] & MASK_8BIT) << 0) |
696 ((data[7] & MASK_4BIT) << 8);
697 pdata->sensor_max_y = ((data[8] & MASK_5BIT) << 0) |
698 ((data[9] & MASK_4BIT) << 8);
699 }
700 return retval;
701}
702
703/**
704 * synaptics_rmi4_i2c_query_device() - query the rmi4 device
705 * @pdata: pointer to synaptics_rmi4_data structure
706 *
707 * This function is used to query the rmi4 device.
708 */
709static int synaptics_rmi4_i2c_query_device(struct synaptics_rmi4_data *pdata)
710{
711 int i;
712 int retval;
713 unsigned char std_queries[STD_QUERY_LEN];
714 unsigned char intr_count = 0;
715 int data_sources = 0;
716 unsigned int ctrl_offset;
717 struct synaptics_rmi4_fn *rfi;
718 struct synaptics_rmi4_fn_desc rmi_fd;
719 struct synaptics_rmi4_device_info *rmi;
720 struct i2c_client *client = pdata->i2c_client;
721
722 /*
723 * init the physical drivers RMI module
724 * info list of functions
725 */
726 INIT_LIST_HEAD(&pdata->rmi4_mod_info.support_fn_list);
727
728 /*
729 * Read the Page Descriptor Table to determine what functions
730 * are present
731 */
732 for (i = PDT_START_SCAN_LOCATION; i > PDT_END_SCAN_LOCATION;
733 i -= PDT_ENTRY_SIZE) {
734 retval = synaptics_rmi4_i2c_block_read(pdata, i,
735 (unsigned char *)&rmi_fd,
736 sizeof(rmi_fd));
737 if (retval != sizeof(rmi_fd)) {
738 /* failed to read next PDT entry */
739 dev_err(&client->dev, "%s: read error\n", __func__);
740 return -EIO;
741 }
742 rfi = NULL;
743 if (rmi_fd.fn_number) {
744 switch (rmi_fd.fn_number & MASK_8BIT) {
745 case SYNAPTICS_RMI4_DEVICE_CONTROL_FUNC_NUM:
746 pdata->fn01_query_base_addr =
747 rmi_fd.query_base_addr;
748 pdata->fn01_ctrl_base_addr =
749 rmi_fd.ctrl_base_addr;
750 pdata->fn01_data_base_addr =
751 rmi_fd.data_base_addr;
752 break;
753 case SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM:
754 if (rmi_fd.intr_src_count) {
755 rfi = kmalloc(sizeof(*rfi),
756 GFP_KERNEL);
757 if (!rfi) {
758 dev_err(&client->dev,
759 "%s:kmalloc failed\n",
760 __func__);
761 return -ENOMEM;
762 }
763 retval = synpatics_rmi4_touchpad_detect
764 (pdata, rfi,
765 &rmi_fd,
766 intr_count);
767 if (retval < 0)
768 return retval;
769 }
770 break;
771 }
772 /* interrupt count for next iteration */
773 intr_count += (rmi_fd.intr_src_count & MASK_3BIT);
774 /*
775 * We only want to add functions to the list
776 * that have data associated with them.
777 */
778 if (rfi && rmi_fd.intr_src_count) {
779 /* link this function info to the RMI module */
780 mutex_lock(&(pdata->fn_list_mutex));
781 list_add_tail(&rfi->link,
782 &pdata->rmi4_mod_info.support_fn_list);
783 mutex_unlock(&(pdata->fn_list_mutex));
784 }
785 } else {
786 /*
787 * A zero in the function number
788 * signals the end of the PDT
789 */
790 dev_dbg(&client->dev,
791 "%s:end of PDT\n", __func__);
792 break;
793 }
794 }
795 /*
796 * calculate the interrupt register count - used in the
797 * ISR to read the correct number of interrupt registers
798 */
799 pdata->number_of_interrupt_register = (intr_count + 7) / 8;
800 /*
801 * Function $01 will be used to query the product properties,
802 * and product ID so we had to read the PDT above first to get
803 * the Fn $01 query address and prior to filling in the product
804 * info. NOTE: Even an unflashed device will still have FN $01.
805 */
806
807 /* Load up the standard queries and get the RMI4 module info */
808 retval = synaptics_rmi4_i2c_block_read(pdata,
809 pdata->fn01_query_base_addr,
810 std_queries,
811 sizeof(std_queries));
812 if (retval != sizeof(std_queries)) {
813 dev_err(&client->dev, "%s:Failed reading queries\n",
814 __func__);
815 return -EIO;
816 }
817
818 /* Currently supported RMI version is 4.0 */
819 pdata->rmi4_mod_info.version_major = 4;
820 pdata->rmi4_mod_info.version_minor = 0;
821 /*
822 * get manufacturer id, product_props, product info,
823 * date code, tester id, serial num and product id (name)
824 */
825 pdata->rmi4_mod_info.manufacturer_id = std_queries[0];
826 pdata->rmi4_mod_info.product_props = std_queries[1];
827 pdata->rmi4_mod_info.product_info[0] = std_queries[2];
828 pdata->rmi4_mod_info.product_info[1] = std_queries[3];
829 /* year - 2001-2032 */
830 pdata->rmi4_mod_info.date_code[0] = std_queries[4] & MASK_5BIT;
831 /* month - 1-12 */
832 pdata->rmi4_mod_info.date_code[1] = std_queries[5] & MASK_4BIT;
833 /* day - 1-31 */
834 pdata->rmi4_mod_info.date_code[2] = std_queries[6] & MASK_5BIT;
835 pdata->rmi4_mod_info.tester_id = ((std_queries[7] & MASK_7BIT) << 8) |
836 (std_queries[8] & MASK_7BIT);
837 pdata->rmi4_mod_info.serial_number =
838 ((std_queries[9] & MASK_7BIT) << 8) |
839 (std_queries[10] & MASK_7BIT);
840 memcpy(pdata->rmi4_mod_info.product_id_string, &std_queries[11], 10);
841
842 /* Check if this is a Synaptics device - report if not. */
843 if (pdata->rmi4_mod_info.manufacturer_id != 1)
844 dev_err(&client->dev, "%s: non-Synaptics mfg id:%d\n",
845 __func__, pdata->rmi4_mod_info.manufacturer_id);
846
847 list_for_each_entry(rfi, &pdata->rmi4_mod_info.support_fn_list, link)
848 data_sources += rfi->num_of_data_sources;
849 if (data_sources) {
850 rmi = &(pdata->rmi4_mod_info);
851 list_for_each_entry(rfi, &rmi->support_fn_list, link) {
852 if (rfi->num_of_data_sources) {
853 if (rfi->fn_number ==
854 SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM) {
855 retval = synpatics_rmi4_touchpad_config
856 (pdata, rfi);
857 if (retval < 0)
858 return retval;
859 } else
860 dev_err(&client->dev,
861 "%s:fn_number not supported\n",
862 __func__);
863 /*
864 * Turn on interrupts for this
865 * function's data sources.
866 */
867 ctrl_offset = pdata->fn01_ctrl_base_addr + 1 +
868 rfi->index_to_intr_reg;
869 retval = synaptics_rmi4_i2c_byte_write(pdata,
870 ctrl_offset,
871 rfi->intr_mask);
872 if (retval < 0)
873 return retval;
874 }
875 }
876 }
877 return 0;
878}
879
880/**
881 * synaptics_rmi4_probe() - Initialze the i2c-client touchscreen driver
882 * @i2c: i2c client structure pointer
883 * @id:i2c device id pointer
884 *
885 * This function will allocate and initialize the instance
886 * data and request the irq and set the instance data as the clients
887 * platform data then register the physical driver which will do a scan of
888 * the rmi4 Physical Device Table and enumerate any rmi4 functions that
889 * have data sources associated with them.
890 */
891static int __devinit synaptics_rmi4_probe
892 (struct i2c_client *client, const struct i2c_device_id *dev_id)
893{
894 int retval;
895 unsigned char intr_status[4];
896 struct synaptics_rmi4_data *rmi4_data;
897 const struct synaptics_rmi4_platform_data *platformdata =
898 client->dev.platform_data;
899
900 if (!i2c_check_functionality(client->adapter,
901 I2C_FUNC_SMBUS_BYTE_DATA)) {
902 dev_err(&client->dev, "i2c smbus byte data not supported\n");
903 return -EIO;
904 }
905
906 if (!platformdata) {
907 dev_err(&client->dev, "%s: no platform data\n", __func__);
908 return -EINVAL;
909 }
910
911 /* Allocate and initialize the instance data for this client */
912 rmi4_data = kzalloc(sizeof(struct synaptics_rmi4_data) * 2,
913 GFP_KERNEL);
914 if (!rmi4_data) {
915 dev_err(&client->dev, "%s: no memory allocated\n", __func__);
916 return -ENOMEM;
917 }
918
919 rmi4_data->input_dev = input_allocate_device();
920 if (rmi4_data->input_dev == NULL) {
921 dev_err(&client->dev, "%s:input device alloc failed\n",
922 __func__);
923 retval = -ENOMEM;
924 goto err_input;
925 }
926
927 dev_set_name(&client->dev, platformdata->name);
928
929 if (platformdata->regulator_en) {
930 rmi4_data->regulator = regulator_get(&client->dev, "v-touch");
931 if (IS_ERR(rmi4_data->regulator)) {
932 dev_err(&client->dev, "%s:get regulator failed\n",
933 __func__);
934 retval = PTR_ERR(rmi4_data->regulator);
935 goto err_regulator;
936 }
937 regulator_enable(rmi4_data->regulator);
938 }
939
940 init_waitqueue_head(&rmi4_data->wait);
941 /*
942 * Copy i2c_client pointer into RTID's i2c_client pointer for
943 * later use in rmi4_read, rmi4_write, etc.
944 */
945 rmi4_data->i2c_client = client;
946 /* So we set the page correctly the first time */
947 rmi4_data->current_page = MASK_16BIT;
948 rmi4_data->board = platformdata;
949 rmi4_data->touch_stopped = false;
950
951 /* init the mutexes for maintain the lists */
952 mutex_init(&(rmi4_data->fn_list_mutex));
953 mutex_init(&(rmi4_data->rmi4_page_mutex));
954
955 /*
956 * Register physical driver - this will call the detect function that
957 * will then scan the device and determine the supported
958 * rmi4 functions.
959 */
960 retval = synaptics_rmi4_i2c_query_device(rmi4_data);
961 if (retval) {
962 dev_err(&client->dev, "%s: rmi4 query device failed\n",
963 __func__);
964 goto err_query_dev;
965 }
966
967 /* Store the instance data in the i2c_client */
968 i2c_set_clientdata(client, rmi4_data);
969
970 /*initialize the input device parameters */
971 rmi4_data->input_dev->name = DRIVER_NAME;
972 rmi4_data->input_dev->phys = "Synaptics_Clearpad";
973 rmi4_data->input_dev->id.bustype = BUS_I2C;
974 rmi4_data->input_dev->dev.parent = &client->dev;
975 input_set_drvdata(rmi4_data->input_dev, rmi4_data);
976
977 /* Initialize the function handlers for rmi4 */
978 set_bit(EV_SYN, rmi4_data->input_dev->evbit);
979 set_bit(EV_KEY, rmi4_data->input_dev->evbit);
980 set_bit(EV_ABS, rmi4_data->input_dev->evbit);
981
982 input_set_abs_params(rmi4_data->input_dev, ABS_MT_POSITION_X, 0,
983 rmi4_data->sensor_max_x, 0, 0);
984 input_set_abs_params(rmi4_data->input_dev, ABS_MT_POSITION_Y, 0,
985 rmi4_data->sensor_max_y, 0, 0);
986 input_set_abs_params(rmi4_data->input_dev, ABS_MT_TOUCH_MAJOR, 0,
987 MAX_TOUCH_MAJOR, 0, 0);
988
989 retval = input_register_device(rmi4_data->input_dev);
990 if (retval) {
991 dev_err(&client->dev, "%s:input register failed\n", __func__);
992 goto err_input_register;
993 }
994
995 /* Clear interrupts */
996 synaptics_rmi4_i2c_block_read(rmi4_data,
997 rmi4_data->fn01_data_base_addr + 1, intr_status,
998 rmi4_data->number_of_interrupt_register);
999 retval = request_threaded_irq(platformdata->irq_number, NULL,
1000 synaptics_rmi4_irq,
1001 platformdata->irq_type,
1002 platformdata->name, rmi4_data);
1003 if (retval) {
1004 dev_err(&client->dev, "%s:Unable to get attn irq %d\n",
1005 __func__, platformdata->irq_number);
1006 goto err_request_irq;
1007 }
1008
1009 return retval;
1010
1011err_request_irq:
1012 free_irq(platformdata->irq_number, rmi4_data);
1013 input_unregister_device(rmi4_data->input_dev);
1014err_input_register:
1015 i2c_set_clientdata(client, NULL);
1016err_query_dev:
1017 if (platformdata->regulator_en) {
1018 regulator_disable(rmi4_data->regulator);
1019 regulator_put(rmi4_data->regulator);
1020 }
1021err_regulator:
1022 input_free_device(rmi4_data->input_dev);
1023 rmi4_data->input_dev = NULL;
1024err_input:
1025 kfree(rmi4_data);
1026
1027 return retval;
1028}
1029/**
1030 * synaptics_rmi4_remove() - Removes the i2c-client touchscreen driver
1031 * @client: i2c client structure pointer
1032 *
1033 * This funtion uses to remove the i2c-client
1034 * touchscreen driver and returns integer.
1035 */
1036static int __devexit synaptics_rmi4_remove(struct i2c_client *client)
1037{
1038 struct synaptics_rmi4_data *rmi4_data = i2c_get_clientdata(client);
1039 const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
1040
1041 rmi4_data->touch_stopped = true;
1042 wake_up(&rmi4_data->wait);
1043 free_irq(pdata->irq_number, rmi4_data);
1044 input_unregister_device(rmi4_data->input_dev);
1045 if (pdata->regulator_en) {
1046 regulator_disable(rmi4_data->regulator);
1047 regulator_put(rmi4_data->regulator);
1048 }
1049 kfree(rmi4_data);
1050
1051 return 0;
1052}
1053
1054#ifdef CONFIG_PM
1055/**
1056 * synaptics_rmi4_suspend() - suspend the touch screen controller
1057 * @dev: pointer to device structure
1058 *
1059 * This funtion is used to suspend the
1060 * touch panel controller and returns integer
1061 */
1062static int synaptics_rmi4_suspend(struct device *dev)
1063{
1064 /* Touch sleep mode */
1065 int retval;
1066 unsigned char intr_status;
1067 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
1068 const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
1069
1070 rmi4_data->touch_stopped = true;
1071 disable_irq(pdata->irq_number);
1072
1073 retval = synaptics_rmi4_i2c_block_read(rmi4_data,
1074 rmi4_data->fn01_data_base_addr + 1,
1075 &intr_status,
1076 rmi4_data->number_of_interrupt_register);
1077 if (retval < 0)
1078 return retval;
1079
1080 retval = synaptics_rmi4_i2c_byte_write(rmi4_data,
1081 rmi4_data->fn01_ctrl_base_addr + 1,
1082 (intr_status & ~TOUCHPAD_CTRL_INTR));
1083 if (retval < 0)
1084 return retval;
1085
1086 if (pdata->regulator_en)
1087 regulator_disable(rmi4_data->regulator);
1088
1089 return 0;
1090}
1091/**
1092 * synaptics_rmi4_resume() - resume the touch screen controller
1093 * @dev: pointer to device structure
1094 *
1095 * This funtion is used to resume the touch panel
1096 * controller and returns integer.
1097 */
1098static int synaptics_rmi4_resume(struct device *dev)
1099{
1100 int retval;
1101 unsigned char intr_status;
1102 struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
1103 const struct synaptics_rmi4_platform_data *pdata = rmi4_data->board;
1104
1105 if (pdata->regulator_en)
1106 regulator_enable(rmi4_data->regulator);
1107
1108 enable_irq(pdata->irq_number);
1109 rmi4_data->touch_stopped = false;
1110
1111 retval = synaptics_rmi4_i2c_block_read(rmi4_data,
1112 rmi4_data->fn01_data_base_addr + 1,
1113 &intr_status,
1114 rmi4_data->number_of_interrupt_register);
1115 if (retval < 0)
1116 return retval;
1117
1118 retval = synaptics_rmi4_i2c_byte_write(rmi4_data,
1119 rmi4_data->fn01_ctrl_base_addr + 1,
1120 (intr_status | TOUCHPAD_CTRL_INTR));
1121 if (retval < 0)
1122 return retval;
1123
1124 return 0;
1125}
1126
1127static const struct dev_pm_ops synaptics_rmi4_dev_pm_ops = {
1128 .suspend = synaptics_rmi4_suspend,
1129 .resume = synaptics_rmi4_resume,
1130};
1131#endif
1132
1133static const struct i2c_device_id synaptics_rmi4_id_table[] = {
1134 { DRIVER_NAME, 0 },
1135 { },
1136};
1137MODULE_DEVICE_TABLE(i2c, synaptics_rmi4_id_table);
1138
1139static struct i2c_driver synaptics_rmi4_driver = {
1140 .driver = {
1141 .name = DRIVER_NAME,
1142 .owner = THIS_MODULE,
1143#ifdef CONFIG_PM
1144 .pm = &synaptics_rmi4_dev_pm_ops,
1145#endif
1146 },
1147 .probe = synaptics_rmi4_probe,
1148 .remove = __devexit_p(synaptics_rmi4_remove),
1149 .id_table = synaptics_rmi4_id_table,
1150};
1151/**
1152 * synaptics_rmi4_init() - Initialize the touchscreen driver
1153 *
1154 * This funtion uses to initializes the synaptics
1155 * touchscreen driver and returns integer.
1156 */
1157static int __init synaptics_rmi4_init(void)
1158{
1159 return i2c_add_driver(&synaptics_rmi4_driver);
1160}
1161/**
1162 * synaptics_rmi4_exit() - De-initialize the touchscreen driver
1163 *
1164 * This funtion uses to de-initialize the synaptics
1165 * touchscreen driver and returns none.
1166 */
1167static void __exit synaptics_rmi4_exit(void)
1168{
1169 i2c_del_driver(&synaptics_rmi4_driver);
1170}
1171
1172
1173module_init(synaptics_rmi4_init);
1174module_exit(synaptics_rmi4_exit);
1175
1176MODULE_LICENSE("GPL v2");
1177MODULE_AUTHOR("naveen.gaddipati@stericsson.com, js.ha@stericsson.com");
1178MODULE_DESCRIPTION("synaptics rmi4 i2c touch Driver");
1179MODULE_ALIAS("i2c:synaptics_rmi4_ts");
diff --git a/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.h b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.h
new file mode 100644
index 000000000000..820ae275fa2b
--- /dev/null
+++ b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.h
@@ -0,0 +1,50 @@
1/**
2 *
3 * Synaptics Register Mapped Interface (RMI4) I2C Physical Layer Driver.
4 * Copyright (c) 2007-2010, Synaptics Incorporated
5 *
6 * Author: Js HA <js.ha@stericsson.com> for ST-Ericsson
7 * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson
8 * Copyright 2010 (c) ST-Ericsson AB
9 */
10/*
11 * This file is licensed under the GPL2 license.
12 *
13 *#############################################################################
14 * GPL
15 *
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License version 2 as published
18 * by the Free Software Foundation.
19 *
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * for more details.
24 *
25 *#############################################################################
26 */
27
28#ifndef _SYNAPTICS_RMI4_H_INCLUDED_
29#define _SYNAPTICS_RMI4_H_INCLUDED_
30
31/**
32 * struct synaptics_rmi4_platform_data - contains the rmi4 platform data
33 * @irq_number: irq number
34 * @irq_type: irq type
35 * @x flip: x flip flag
36 * @y flip: y flip flag
37 * @regulator_en: regulator enable flag
38 *
39 * This structure gives platform data for rmi4.
40 */
41struct synaptics_rmi4_platform_data {
42 const char *name;
43 int irq_number;
44 int irq_type;
45 bool x_flip;
46 bool y_flip;
47 bool regulator_en;
48};
49
50#endif
diff --git a/drivers/staging/tidspbridge/core/tiomap3430.c b/drivers/staging/tidspbridge/core/tiomap3430.c
index 1be081f917a7..a3b0a183d570 100644
--- a/drivers/staging/tidspbridge/core/tiomap3430.c
+++ b/drivers/staging/tidspbridge/core/tiomap3430.c
@@ -596,7 +596,7 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt,
596 dev_dbg(bridge, "DSP c_int00 Address = 0x%x\n", dsp_addr); 596 dev_dbg(bridge, "DSP c_int00 Address = 0x%x\n", dsp_addr);
597 if (dsp_debug) 597 if (dsp_debug)
598 while (__raw_readw(dw_sync_addr)) 598 while (__raw_readw(dw_sync_addr))
599 ;; 599 ;
600 600
601 /* Wait for DSP to clear word in shared memory */ 601 /* Wait for DSP to clear word in shared memory */
602 /* Read the Location */ 602 /* Read the Location */
@@ -1671,7 +1671,7 @@ static int pte_set(struct pg_table_attrs *pt, u32 pa, u32 va,
1671 /* Find a free L2 PT. */ 1671 /* Find a free L2 PT. */
1672 for (i = 0; (i < pt->l2_num_pages) && 1672 for (i = 0; (i < pt->l2_num_pages) &&
1673 (pt->pg_info[i].num_entries != 0); i++) 1673 (pt->pg_info[i].num_entries != 0); i++)
1674 ;; 1674 ;
1675 if (i < pt->l2_num_pages) { 1675 if (i < pt->l2_num_pages) {
1676 l2_page_num = i; 1676 l2_page_num = i;
1677 l2_base_pa = pt->l2_base_pa + (l2_page_num * 1677 l2_base_pa = pt->l2_base_pa + (l2_page_num *
diff --git a/drivers/staging/tidspbridge/rmgr/nldr.c b/drivers/staging/tidspbridge/rmgr/nldr.c
index a6ae007015d0..28354bbf1aeb 100644
--- a/drivers/staging/tidspbridge/rmgr/nldr.c
+++ b/drivers/staging/tidspbridge/rmgr/nldr.c
@@ -943,7 +943,7 @@ static int add_ovly_info(void *handle, struct dbll_sect_info *sect_info,
943 943
944 /* Determine which phase this section belongs to */ 944 /* Determine which phase this section belongs to */
945 for (pch = sect_name + 1; *pch && *pch != seps; pch++) 945 for (pch = sect_name + 1; *pch && *pch != seps; pch++)
946 ;; 946 ;
947 947
948 if (*pch) { 948 if (*pch) {
949 pch++; /* Skip over the ':' */ 949 pch++; /* Skip over the ':' */
diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
index 832608d3e579..08bd26a245d5 100644
--- a/drivers/staging/usbip/vhci_hcd.c
+++ b/drivers/staging/usbip/vhci_hcd.c
@@ -799,20 +799,6 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
799 spin_unlock_irqrestore(&vdev->priv_lock, flags2); 799 spin_unlock_irqrestore(&vdev->priv_lock, flags2);
800 } 800 }
801 801
802
803 if (!vdev->ud.tcp_socket) {
804 /* tcp connection is closed */
805 usbip_uinfo("vhci_hcd: vhci_urb_dequeue() gives back urb %p\n",
806 urb);
807
808 usb_hcd_unlink_urb_from_ep(hcd, urb);
809
810 spin_unlock_irqrestore(&the_controller->lock, flags);
811 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb,
812 urb->status);
813 spin_lock_irqsave(&the_controller->lock, flags);
814 }
815
816 spin_unlock_irqrestore(&the_controller->lock, flags); 802 spin_unlock_irqrestore(&the_controller->lock, flags);
817 803
818 usbip_dbg_vhci_hc("leave\n"); 804 usbip_dbg_vhci_hc("leave\n");
diff --git a/drivers/staging/vme/bridges/Module.symvers b/drivers/staging/vme/bridges/Module.symvers
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/drivers/staging/vme/bridges/Module.symvers
diff --git a/drivers/staging/vme/bridges/vme_ca91cx42.c b/drivers/staging/vme/bridges/vme_ca91cx42.c
index 4d745623211b..42de83e6f1d9 100644
--- a/drivers/staging/vme/bridges/vme_ca91cx42.c
+++ b/drivers/staging/vme/bridges/vme_ca91cx42.c
@@ -44,7 +44,7 @@ static int geoid;
44 44
45static char driver_name[] = "vme_ca91cx42"; 45static char driver_name[] = "vme_ca91cx42";
46 46
47static const struct pci_device_id ca91cx42_ids[] = { 47static DEFINE_PCI_DEVICE_TABLE(ca91cx42_ids) = {
48 { PCI_DEVICE(PCI_VENDOR_ID_TUNDRA, PCI_DEVICE_ID_TUNDRA_CA91C142) }, 48 { PCI_DEVICE(PCI_VENDOR_ID_TUNDRA, PCI_DEVICE_ID_TUNDRA_CA91C142) },
49 { }, 49 { },
50}; 50};
@@ -58,7 +58,7 @@ static struct pci_driver ca91cx42_driver = {
58 58
59static u32 ca91cx42_DMA_irqhandler(struct ca91cx42_driver *bridge) 59static u32 ca91cx42_DMA_irqhandler(struct ca91cx42_driver *bridge)
60{ 60{
61 wake_up(&(bridge->dma_queue)); 61 wake_up(&bridge->dma_queue);
62 62
63 return CA91CX42_LINT_DMA; 63 return CA91CX42_LINT_DMA;
64} 64}
@@ -82,14 +82,14 @@ static u32 ca91cx42_LM_irqhandler(struct ca91cx42_driver *bridge, u32 stat)
82/* XXX This needs to be split into 4 queues */ 82/* XXX This needs to be split into 4 queues */
83static u32 ca91cx42_MB_irqhandler(struct ca91cx42_driver *bridge, int mbox_mask) 83static u32 ca91cx42_MB_irqhandler(struct ca91cx42_driver *bridge, int mbox_mask)
84{ 84{
85 wake_up(&(bridge->mbox_queue)); 85 wake_up(&bridge->mbox_queue);
86 86
87 return CA91CX42_LINT_MBOX; 87 return CA91CX42_LINT_MBOX;
88} 88}
89 89
90static u32 ca91cx42_IACK_irqhandler(struct ca91cx42_driver *bridge) 90static u32 ca91cx42_IACK_irqhandler(struct ca91cx42_driver *bridge)
91{ 91{
92 wake_up(&(bridge->iack_queue)); 92 wake_up(&bridge->iack_queue);
93 93
94 return CA91CX42_LINT_SW_IACK; 94 return CA91CX42_LINT_SW_IACK;
95} 95}
@@ -207,9 +207,9 @@ static int ca91cx42_irq_init(struct vme_bridge *ca91cx42_bridge)
207 pdev = container_of(ca91cx42_bridge->parent, struct pci_dev, dev); 207 pdev = container_of(ca91cx42_bridge->parent, struct pci_dev, dev);
208 208
209 /* Initialise list for VME bus errors */ 209 /* Initialise list for VME bus errors */
210 INIT_LIST_HEAD(&(ca91cx42_bridge->vme_errors)); 210 INIT_LIST_HEAD(&ca91cx42_bridge->vme_errors);
211 211
212 mutex_init(&(ca91cx42_bridge->irq_mtx)); 212 mutex_init(&ca91cx42_bridge->irq_mtx);
213 213
214 /* Disable interrupts from PCI to VME */ 214 /* Disable interrupts from PCI to VME */
215 iowrite32(0, bridge->base + VINT_EN); 215 iowrite32(0, bridge->base + VINT_EN);
@@ -259,8 +259,8 @@ static void ca91cx42_irq_exit(struct ca91cx42_driver *bridge,
259/* 259/*
260 * Set up an VME interrupt 260 * Set up an VME interrupt
261 */ 261 */
262void ca91cx42_irq_set(struct vme_bridge *ca91cx42_bridge, int level, int state, 262static void ca91cx42_irq_set(struct vme_bridge *ca91cx42_bridge, int level,
263 int sync) 263 int state, int sync)
264 264
265{ 265{
266 struct pci_dev *pdev; 266 struct pci_dev *pdev;
@@ -287,7 +287,7 @@ void ca91cx42_irq_set(struct vme_bridge *ca91cx42_bridge, int level, int state,
287 } 287 }
288} 288}
289 289
290int ca91cx42_irq_generate(struct vme_bridge *ca91cx42_bridge, int level, 290static int ca91cx42_irq_generate(struct vme_bridge *ca91cx42_bridge, int level,
291 int statid) 291 int statid)
292{ 292{
293 u32 tmp; 293 u32 tmp;
@@ -299,7 +299,7 @@ int ca91cx42_irq_generate(struct vme_bridge *ca91cx42_bridge, int level,
299 if (statid & 1) 299 if (statid & 1)
300 return -EINVAL; 300 return -EINVAL;
301 301
302 mutex_lock(&(bridge->vme_int)); 302 mutex_lock(&bridge->vme_int);
303 303
304 tmp = ioread32(bridge->base + VINT_EN); 304 tmp = ioread32(bridge->base + VINT_EN);
305 305
@@ -318,12 +318,12 @@ int ca91cx42_irq_generate(struct vme_bridge *ca91cx42_bridge, int level,
318 tmp = tmp & ~(1 << (level + 24)); 318 tmp = tmp & ~(1 << (level + 24));
319 iowrite32(tmp, bridge->base + VINT_EN); 319 iowrite32(tmp, bridge->base + VINT_EN);
320 320
321 mutex_unlock(&(bridge->vme_int)); 321 mutex_unlock(&bridge->vme_int);
322 322
323 return 0; 323 return 0;
324} 324}
325 325
326int ca91cx42_slave_set(struct vme_slave_resource *image, int enabled, 326static int ca91cx42_slave_set(struct vme_slave_resource *image, int enabled,
327 unsigned long long vme_base, unsigned long long size, 327 unsigned long long vme_base, unsigned long long size,
328 dma_addr_t pci_base, vme_address_t aspace, vme_cycle_t cycle) 328 dma_addr_t pci_base, vme_address_t aspace, vme_cycle_t cycle)
329{ 329{
@@ -429,7 +429,7 @@ int ca91cx42_slave_set(struct vme_slave_resource *image, int enabled,
429 return 0; 429 return 0;
430} 430}
431 431
432int ca91cx42_slave_get(struct vme_slave_resource *image, int *enabled, 432static int ca91cx42_slave_get(struct vme_slave_resource *image, int *enabled,
433 unsigned long long *vme_base, unsigned long long *size, 433 unsigned long long *vme_base, unsigned long long *size,
434 dma_addr_t *pci_base, vme_address_t *aspace, vme_cycle_t *cycle) 434 dma_addr_t *pci_base, vme_address_t *aspace, vme_cycle_t *cycle)
435{ 435{
@@ -518,8 +518,8 @@ static int ca91cx42_alloc_resource(struct vme_master_resource *image,
518 image->kern_base = NULL; 518 image->kern_base = NULL;
519 if (image->bus_resource.name != NULL) 519 if (image->bus_resource.name != NULL)
520 kfree(image->bus_resource.name); 520 kfree(image->bus_resource.name);
521 release_resource(&(image->bus_resource)); 521 release_resource(&image->bus_resource);
522 memset(&(image->bus_resource), 0, sizeof(struct resource)); 522 memset(&image->bus_resource, 0, sizeof(struct resource));
523 } 523 }
524 524
525 if (image->bus_resource.name == NULL) { 525 if (image->bus_resource.name == NULL) {
@@ -540,7 +540,7 @@ static int ca91cx42_alloc_resource(struct vme_master_resource *image,
540 image->bus_resource.flags = IORESOURCE_MEM; 540 image->bus_resource.flags = IORESOURCE_MEM;
541 541
542 retval = pci_bus_alloc_resource(pdev->bus, 542 retval = pci_bus_alloc_resource(pdev->bus,
543 &(image->bus_resource), size, size, PCIBIOS_MIN_MEM, 543 &image->bus_resource, size, size, PCIBIOS_MIN_MEM,
544 0, NULL, NULL); 544 0, NULL, NULL);
545 if (retval) { 545 if (retval) {
546 dev_err(ca91cx42_bridge->parent, "Failed to allocate mem " 546 dev_err(ca91cx42_bridge->parent, "Failed to allocate mem "
@@ -563,10 +563,10 @@ static int ca91cx42_alloc_resource(struct vme_master_resource *image,
563 iounmap(image->kern_base); 563 iounmap(image->kern_base);
564 image->kern_base = NULL; 564 image->kern_base = NULL;
565err_remap: 565err_remap:
566 release_resource(&(image->bus_resource)); 566 release_resource(&image->bus_resource);
567err_resource: 567err_resource:
568 kfree(image->bus_resource.name); 568 kfree(image->bus_resource.name);
569 memset(&(image->bus_resource), 0, sizeof(struct resource)); 569 memset(&image->bus_resource, 0, sizeof(struct resource));
570err_name: 570err_name:
571 return retval; 571 return retval;
572} 572}
@@ -578,13 +578,13 @@ static void ca91cx42_free_resource(struct vme_master_resource *image)
578{ 578{
579 iounmap(image->kern_base); 579 iounmap(image->kern_base);
580 image->kern_base = NULL; 580 image->kern_base = NULL;
581 release_resource(&(image->bus_resource)); 581 release_resource(&image->bus_resource);
582 kfree(image->bus_resource.name); 582 kfree(image->bus_resource.name);
583 memset(&(image->bus_resource), 0, sizeof(struct resource)); 583 memset(&image->bus_resource, 0, sizeof(struct resource));
584} 584}
585 585
586 586
587int ca91cx42_master_set(struct vme_master_resource *image, int enabled, 587static int ca91cx42_master_set(struct vme_master_resource *image, int enabled,
588 unsigned long long vme_base, unsigned long long size, 588 unsigned long long vme_base, unsigned long long size,
589 vme_address_t aspace, vme_cycle_t cycle, vme_width_t dwidth) 589 vme_address_t aspace, vme_cycle_t cycle, vme_width_t dwidth)
590{ 590{
@@ -620,7 +620,7 @@ int ca91cx42_master_set(struct vme_master_resource *image, int enabled,
620 goto err_window; 620 goto err_window;
621 } 621 }
622 622
623 spin_lock(&(image->lock)); 623 spin_lock(&image->lock);
624 624
625 /* 625 /*
626 * Let's allocate the resource here rather than further up the stack as 626 * Let's allocate the resource here rather than further up the stack as
@@ -628,7 +628,7 @@ int ca91cx42_master_set(struct vme_master_resource *image, int enabled,
628 */ 628 */
629 retval = ca91cx42_alloc_resource(image, size); 629 retval = ca91cx42_alloc_resource(image, size);
630 if (retval) { 630 if (retval) {
631 spin_unlock(&(image->lock)); 631 spin_unlock(&image->lock);
632 dev_err(ca91cx42_bridge->parent, "Unable to allocate memory " 632 dev_err(ca91cx42_bridge->parent, "Unable to allocate memory "
633 "for resource name\n"); 633 "for resource name\n");
634 retval = -ENOMEM; 634 retval = -ENOMEM;
@@ -672,7 +672,7 @@ int ca91cx42_master_set(struct vme_master_resource *image, int enabled,
672 temp_ctl |= CA91CX42_LSI_CTL_VDW_D64; 672 temp_ctl |= CA91CX42_LSI_CTL_VDW_D64;
673 break; 673 break;
674 default: 674 default:
675 spin_unlock(&(image->lock)); 675 spin_unlock(&image->lock);
676 dev_err(ca91cx42_bridge->parent, "Invalid data width\n"); 676 dev_err(ca91cx42_bridge->parent, "Invalid data width\n");
677 retval = -EINVAL; 677 retval = -EINVAL;
678 goto err_dwidth; 678 goto err_dwidth;
@@ -704,7 +704,7 @@ int ca91cx42_master_set(struct vme_master_resource *image, int enabled,
704 case VME_USER3: 704 case VME_USER3:
705 case VME_USER4: 705 case VME_USER4:
706 default: 706 default:
707 spin_unlock(&(image->lock)); 707 spin_unlock(&image->lock);
708 dev_err(ca91cx42_bridge->parent, "Invalid address space\n"); 708 dev_err(ca91cx42_bridge->parent, "Invalid address space\n");
709 retval = -EINVAL; 709 retval = -EINVAL;
710 goto err_aspace; 710 goto err_aspace;
@@ -730,7 +730,7 @@ int ca91cx42_master_set(struct vme_master_resource *image, int enabled,
730 730
731 iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]); 731 iowrite32(temp_ctl, bridge->base + CA91CX42_LSI_CTL[i]);
732 732
733 spin_unlock(&(image->lock)); 733 spin_unlock(&image->lock);
734 return 0; 734 return 0;
735 735
736err_aspace: 736err_aspace:
@@ -741,8 +741,8 @@ err_window:
741 return retval; 741 return retval;
742} 742}
743 743
744int __ca91cx42_master_get(struct vme_master_resource *image, int *enabled, 744static int __ca91cx42_master_get(struct vme_master_resource *image,
745 unsigned long long *vme_base, unsigned long long *size, 745 int *enabled, unsigned long long *vme_base, unsigned long long *size,
746 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth) 746 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth)
747{ 747{
748 unsigned int i, ctl; 748 unsigned int i, ctl;
@@ -828,24 +828,24 @@ int __ca91cx42_master_get(struct vme_master_resource *image, int *enabled,
828 return 0; 828 return 0;
829} 829}
830 830
831int ca91cx42_master_get(struct vme_master_resource *image, int *enabled, 831static int ca91cx42_master_get(struct vme_master_resource *image, int *enabled,
832 unsigned long long *vme_base, unsigned long long *size, 832 unsigned long long *vme_base, unsigned long long *size,
833 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth) 833 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth)
834{ 834{
835 int retval; 835 int retval;
836 836
837 spin_lock(&(image->lock)); 837 spin_lock(&image->lock);
838 838
839 retval = __ca91cx42_master_get(image, enabled, vme_base, size, aspace, 839 retval = __ca91cx42_master_get(image, enabled, vme_base, size, aspace,
840 cycle, dwidth); 840 cycle, dwidth);
841 841
842 spin_unlock(&(image->lock)); 842 spin_unlock(&image->lock);
843 843
844 return retval; 844 return retval;
845} 845}
846 846
847ssize_t ca91cx42_master_read(struct vme_master_resource *image, void *buf, 847static ssize_t ca91cx42_master_read(struct vme_master_resource *image,
848 size_t count, loff_t offset) 848 void *buf, size_t count, loff_t offset)
849{ 849{
850 ssize_t retval; 850 ssize_t retval;
851 void *addr = image->kern_base + offset; 851 void *addr = image->kern_base + offset;
@@ -855,7 +855,7 @@ ssize_t ca91cx42_master_read(struct vme_master_resource *image, void *buf,
855 if (count == 0) 855 if (count == 0)
856 return 0; 856 return 0;
857 857
858 spin_lock(&(image->lock)); 858 spin_lock(&image->lock);
859 859
860 /* The following code handles VME address alignment problem 860 /* The following code handles VME address alignment problem
861 * in order to assure the maximal data width cycle. 861 * in order to assure the maximal data width cycle.
@@ -899,13 +899,13 @@ ssize_t ca91cx42_master_read(struct vme_master_resource *image, void *buf,
899 } 899 }
900out: 900out:
901 retval = count; 901 retval = count;
902 spin_unlock(&(image->lock)); 902 spin_unlock(&image->lock);
903 903
904 return retval; 904 return retval;
905} 905}
906 906
907ssize_t ca91cx42_master_write(struct vme_master_resource *image, void *buf, 907static ssize_t ca91cx42_master_write(struct vme_master_resource *image,
908 size_t count, loff_t offset) 908 void *buf, size_t count, loff_t offset)
909{ 909{
910 ssize_t retval; 910 ssize_t retval;
911 void *addr = image->kern_base + offset; 911 void *addr = image->kern_base + offset;
@@ -915,7 +915,7 @@ ssize_t ca91cx42_master_write(struct vme_master_resource *image, void *buf,
915 if (count == 0) 915 if (count == 0)
916 return 0; 916 return 0;
917 917
918 spin_lock(&(image->lock)); 918 spin_lock(&image->lock);
919 919
920 /* Here we apply for the same strategy we do in master_read 920 /* Here we apply for the same strategy we do in master_read
921 * function in order to assure D16 cycle when required. 921 * function in order to assure D16 cycle when required.
@@ -954,11 +954,12 @@ ssize_t ca91cx42_master_write(struct vme_master_resource *image, void *buf,
954out: 954out:
955 retval = count; 955 retval = count;
956 956
957 spin_unlock(&(image->lock)); 957 spin_unlock(&image->lock);
958
958 return retval; 959 return retval;
959} 960}
960 961
961unsigned int ca91cx42_master_rmw(struct vme_master_resource *image, 962static unsigned int ca91cx42_master_rmw(struct vme_master_resource *image,
962 unsigned int mask, unsigned int compare, unsigned int swap, 963 unsigned int mask, unsigned int compare, unsigned int swap,
963 loff_t offset) 964 loff_t offset)
964{ 965{
@@ -974,10 +975,10 @@ unsigned int ca91cx42_master_rmw(struct vme_master_resource *image,
974 i = image->number; 975 i = image->number;
975 976
976 /* Locking as we can only do one of these at a time */ 977 /* Locking as we can only do one of these at a time */
977 mutex_lock(&(bridge->vme_rmw)); 978 mutex_lock(&bridge->vme_rmw);
978 979
979 /* Lock image */ 980 /* Lock image */
980 spin_lock(&(image->lock)); 981 spin_lock(&image->lock);
981 982
982 pci_addr = (u32)image->kern_base + offset; 983 pci_addr = (u32)image->kern_base + offset;
983 984
@@ -1007,15 +1008,15 @@ unsigned int ca91cx42_master_rmw(struct vme_master_resource *image,
1007 iowrite32(0, bridge->base + SCYC_CTL); 1008 iowrite32(0, bridge->base + SCYC_CTL);
1008 1009
1009out: 1010out:
1010 spin_unlock(&(image->lock)); 1011 spin_unlock(&image->lock);
1011 1012
1012 mutex_unlock(&(bridge->vme_rmw)); 1013 mutex_unlock(&bridge->vme_rmw);
1013 1014
1014 return result; 1015 return result;
1015} 1016}
1016 1017
1017int ca91cx42_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src, 1018static int ca91cx42_dma_list_add(struct vme_dma_list *list,
1018 struct vme_dma_attr *dest, size_t count) 1019 struct vme_dma_attr *src, struct vme_dma_attr *dest, size_t count)
1019{ 1020{
1020 struct ca91cx42_dma_entry *entry, *prev; 1021 struct ca91cx42_dma_entry *entry, *prev;
1021 struct vme_dma_pci *pci_attr; 1022 struct vme_dma_pci *pci_attr;
@@ -1036,14 +1037,14 @@ int ca91cx42_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
1036 } 1037 }
1037 1038
1038 /* Test descriptor alignment */ 1039 /* Test descriptor alignment */
1039 if ((unsigned long)&(entry->descriptor) & CA91CX42_DCPP_M) { 1040 if ((unsigned long)&entry->descriptor & CA91CX42_DCPP_M) {
1040 dev_err(dev, "Descriptor not aligned to 16 byte boundary as " 1041 dev_err(dev, "Descriptor not aligned to 16 byte boundary as "
1041 "required: %p\n", &(entry->descriptor)); 1042 "required: %p\n", &entry->descriptor);
1042 retval = -EINVAL; 1043 retval = -EINVAL;
1043 goto err_align; 1044 goto err_align;
1044 } 1045 }
1045 1046
1046 memset(&(entry->descriptor), 0, sizeof(struct ca91cx42_dma_descriptor)); 1047 memset(&entry->descriptor, 0, sizeof(struct ca91cx42_dma_descriptor));
1047 1048
1048 if (dest->type == VME_DMA_VME) { 1049 if (dest->type == VME_DMA_VME) {
1049 entry->descriptor.dctl |= CA91CX42_DCTL_L2V; 1050 entry->descriptor.dctl |= CA91CX42_DCTL_L2V;
@@ -1138,14 +1139,14 @@ int ca91cx42_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
1138 entry->descriptor.dcpp = CA91CX42_DCPP_NULL; 1139 entry->descriptor.dcpp = CA91CX42_DCPP_NULL;
1139 1140
1140 /* Add to list */ 1141 /* Add to list */
1141 list_add_tail(&(entry->list), &(list->entries)); 1142 list_add_tail(&entry->list, &list->entries);
1142 1143
1143 /* Fill out previous descriptors "Next Address" */ 1144 /* Fill out previous descriptors "Next Address" */
1144 if (entry->list.prev != &(list->entries)) { 1145 if (entry->list.prev != &list->entries) {
1145 prev = list_entry(entry->list.prev, struct ca91cx42_dma_entry, 1146 prev = list_entry(entry->list.prev, struct ca91cx42_dma_entry,
1146 list); 1147 list);
1147 /* We need the bus address for the pointer */ 1148 /* We need the bus address for the pointer */
1148 desc_ptr = virt_to_bus(&(entry->descriptor)); 1149 desc_ptr = virt_to_bus(&entry->descriptor);
1149 prev->descriptor.dcpp = desc_ptr & ~CA91CX42_DCPP_M; 1150 prev->descriptor.dcpp = desc_ptr & ~CA91CX42_DCPP_M;
1150 } 1151 }
1151 1152
@@ -1175,7 +1176,7 @@ static int ca91cx42_dma_busy(struct vme_bridge *ca91cx42_bridge)
1175 return 1; 1176 return 1;
1176} 1177}
1177 1178
1178int ca91cx42_dma_list_exec(struct vme_dma_list *list) 1179static int ca91cx42_dma_list_exec(struct vme_dma_list *list)
1179{ 1180{
1180 struct vme_dma_resource *ctrlr; 1181 struct vme_dma_resource *ctrlr;
1181 struct ca91cx42_dma_entry *entry; 1182 struct ca91cx42_dma_entry *entry;
@@ -1190,28 +1191,28 @@ int ca91cx42_dma_list_exec(struct vme_dma_list *list)
1190 bridge = ctrlr->parent->driver_priv; 1191 bridge = ctrlr->parent->driver_priv;
1191 dev = ctrlr->parent->parent; 1192 dev = ctrlr->parent->parent;
1192 1193
1193 mutex_lock(&(ctrlr->mtx)); 1194 mutex_lock(&ctrlr->mtx);
1194 1195
1195 if (!(list_empty(&(ctrlr->running)))) { 1196 if (!(list_empty(&ctrlr->running))) {
1196 /* 1197 /*
1197 * XXX We have an active DMA transfer and currently haven't 1198 * XXX We have an active DMA transfer and currently haven't
1198 * sorted out the mechanism for "pending" DMA transfers. 1199 * sorted out the mechanism for "pending" DMA transfers.
1199 * Return busy. 1200 * Return busy.
1200 */ 1201 */
1201 /* Need to add to pending here */ 1202 /* Need to add to pending here */
1202 mutex_unlock(&(ctrlr->mtx)); 1203 mutex_unlock(&ctrlr->mtx);
1203 return -EBUSY; 1204 return -EBUSY;
1204 } else { 1205 } else {
1205 list_add(&(list->list), &(ctrlr->running)); 1206 list_add(&list->list, &ctrlr->running);
1206 } 1207 }
1207 1208
1208 /* Get first bus address and write into registers */ 1209 /* Get first bus address and write into registers */
1209 entry = list_first_entry(&(list->entries), struct ca91cx42_dma_entry, 1210 entry = list_first_entry(&list->entries, struct ca91cx42_dma_entry,
1210 list); 1211 list);
1211 1212
1212 bus_addr = virt_to_bus(&(entry->descriptor)); 1213 bus_addr = virt_to_bus(&entry->descriptor);
1213 1214
1214 mutex_unlock(&(ctrlr->mtx)); 1215 mutex_unlock(&ctrlr->mtx);
1215 1216
1216 iowrite32(0, bridge->base + DTBC); 1217 iowrite32(0, bridge->base + DTBC);
1217 iowrite32(bus_addr & ~CA91CX42_DCPP_M, bridge->base + DCPP); 1218 iowrite32(bus_addr & ~CA91CX42_DCPP_M, bridge->base + DCPP);
@@ -1249,21 +1250,21 @@ int ca91cx42_dma_list_exec(struct vme_dma_list *list)
1249 } 1250 }
1250 1251
1251 /* Remove list from running list */ 1252 /* Remove list from running list */
1252 mutex_lock(&(ctrlr->mtx)); 1253 mutex_lock(&ctrlr->mtx);
1253 list_del(&(list->list)); 1254 list_del(&list->list);
1254 mutex_unlock(&(ctrlr->mtx)); 1255 mutex_unlock(&ctrlr->mtx);
1255 1256
1256 return retval; 1257 return retval;
1257 1258
1258} 1259}
1259 1260
1260int ca91cx42_dma_list_empty(struct vme_dma_list *list) 1261static int ca91cx42_dma_list_empty(struct vme_dma_list *list)
1261{ 1262{
1262 struct list_head *pos, *temp; 1263 struct list_head *pos, *temp;
1263 struct ca91cx42_dma_entry *entry; 1264 struct ca91cx42_dma_entry *entry;
1264 1265
1265 /* detach and free each entry */ 1266 /* detach and free each entry */
1266 list_for_each_safe(pos, temp, &(list->entries)) { 1267 list_for_each_safe(pos, temp, &list->entries) {
1267 list_del(pos); 1268 list_del(pos);
1268 entry = list_entry(pos, struct ca91cx42_dma_entry, list); 1269 entry = list_entry(pos, struct ca91cx42_dma_entry, list);
1269 kfree(entry); 1270 kfree(entry);
@@ -1279,8 +1280,8 @@ int ca91cx42_dma_list_empty(struct vme_dma_list *list)
1279 * This does not enable the LM monitor - that should be done when the first 1280 * This does not enable the LM monitor - that should be done when the first
1280 * callback is attached and disabled when the last callback is removed. 1281 * callback is attached and disabled when the last callback is removed.
1281 */ 1282 */
1282int ca91cx42_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base, 1283static int ca91cx42_lm_set(struct vme_lm_resource *lm,
1283 vme_address_t aspace, vme_cycle_t cycle) 1284 unsigned long long lm_base, vme_address_t aspace, vme_cycle_t cycle)
1284{ 1285{
1285 u32 temp_base, lm_ctl = 0; 1286 u32 temp_base, lm_ctl = 0;
1286 int i; 1287 int i;
@@ -1298,12 +1299,12 @@ int ca91cx42_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1298 return -EINVAL; 1299 return -EINVAL;
1299 } 1300 }
1300 1301
1301 mutex_lock(&(lm->mtx)); 1302 mutex_lock(&lm->mtx);
1302 1303
1303 /* If we already have a callback attached, we can't move it! */ 1304 /* If we already have a callback attached, we can't move it! */
1304 for (i = 0; i < lm->monitors; i++) { 1305 for (i = 0; i < lm->monitors; i++) {
1305 if (bridge->lm_callback[i] != NULL) { 1306 if (bridge->lm_callback[i] != NULL) {
1306 mutex_unlock(&(lm->mtx)); 1307 mutex_unlock(&lm->mtx);
1307 dev_err(dev, "Location monitor callback attached, " 1308 dev_err(dev, "Location monitor callback attached, "
1308 "can't reset\n"); 1309 "can't reset\n");
1309 return -EBUSY; 1310 return -EBUSY;
@@ -1321,7 +1322,7 @@ int ca91cx42_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1321 lm_ctl |= CA91CX42_LM_CTL_AS_A32; 1322 lm_ctl |= CA91CX42_LM_CTL_AS_A32;
1322 break; 1323 break;
1323 default: 1324 default:
1324 mutex_unlock(&(lm->mtx)); 1325 mutex_unlock(&lm->mtx);
1325 dev_err(dev, "Invalid address space\n"); 1326 dev_err(dev, "Invalid address space\n");
1326 return -EINVAL; 1327 return -EINVAL;
1327 break; 1328 break;
@@ -1339,7 +1340,7 @@ int ca91cx42_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1339 iowrite32(lm_base, bridge->base + LM_BS); 1340 iowrite32(lm_base, bridge->base + LM_BS);
1340 iowrite32(lm_ctl, bridge->base + LM_CTL); 1341 iowrite32(lm_ctl, bridge->base + LM_CTL);
1341 1342
1342 mutex_unlock(&(lm->mtx)); 1343 mutex_unlock(&lm->mtx);
1343 1344
1344 return 0; 1345 return 0;
1345} 1346}
@@ -1347,15 +1348,15 @@ int ca91cx42_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1347/* Get configuration of the callback monitor and return whether it is enabled 1348/* Get configuration of the callback monitor and return whether it is enabled
1348 * or disabled. 1349 * or disabled.
1349 */ 1350 */
1350int ca91cx42_lm_get(struct vme_lm_resource *lm, unsigned long long *lm_base, 1351static int ca91cx42_lm_get(struct vme_lm_resource *lm,
1351 vme_address_t *aspace, vme_cycle_t *cycle) 1352 unsigned long long *lm_base, vme_address_t *aspace, vme_cycle_t *cycle)
1352{ 1353{
1353 u32 lm_ctl, enabled = 0; 1354 u32 lm_ctl, enabled = 0;
1354 struct ca91cx42_driver *bridge; 1355 struct ca91cx42_driver *bridge;
1355 1356
1356 bridge = lm->parent->driver_priv; 1357 bridge = lm->parent->driver_priv;
1357 1358
1358 mutex_lock(&(lm->mtx)); 1359 mutex_lock(&lm->mtx);
1359 1360
1360 *lm_base = (unsigned long long)ioread32(bridge->base + LM_BS); 1361 *lm_base = (unsigned long long)ioread32(bridge->base + LM_BS);
1361 lm_ctl = ioread32(bridge->base + LM_CTL); 1362 lm_ctl = ioread32(bridge->base + LM_CTL);
@@ -1380,7 +1381,7 @@ int ca91cx42_lm_get(struct vme_lm_resource *lm, unsigned long long *lm_base,
1380 if (lm_ctl & CA91CX42_LM_CTL_DATA) 1381 if (lm_ctl & CA91CX42_LM_CTL_DATA)
1381 *cycle |= VME_DATA; 1382 *cycle |= VME_DATA;
1382 1383
1383 mutex_unlock(&(lm->mtx)); 1384 mutex_unlock(&lm->mtx);
1384 1385
1385 return enabled; 1386 return enabled;
1386} 1387}
@@ -1390,7 +1391,7 @@ int ca91cx42_lm_get(struct vme_lm_resource *lm, unsigned long long *lm_base,
1390 * 1391 *
1391 * Callback will be passed the monitor triggered. 1392 * Callback will be passed the monitor triggered.
1392 */ 1393 */
1393int ca91cx42_lm_attach(struct vme_lm_resource *lm, int monitor, 1394static int ca91cx42_lm_attach(struct vme_lm_resource *lm, int monitor,
1394 void (*callback)(int)) 1395 void (*callback)(int))
1395{ 1396{
1396 u32 lm_ctl, tmp; 1397 u32 lm_ctl, tmp;
@@ -1400,19 +1401,19 @@ int ca91cx42_lm_attach(struct vme_lm_resource *lm, int monitor,
1400 bridge = lm->parent->driver_priv; 1401 bridge = lm->parent->driver_priv;
1401 dev = lm->parent->parent; 1402 dev = lm->parent->parent;
1402 1403
1403 mutex_lock(&(lm->mtx)); 1404 mutex_lock(&lm->mtx);
1404 1405
1405 /* Ensure that the location monitor is configured - need PGM or DATA */ 1406 /* Ensure that the location monitor is configured - need PGM or DATA */
1406 lm_ctl = ioread32(bridge->base + LM_CTL); 1407 lm_ctl = ioread32(bridge->base + LM_CTL);
1407 if ((lm_ctl & (CA91CX42_LM_CTL_PGM | CA91CX42_LM_CTL_DATA)) == 0) { 1408 if ((lm_ctl & (CA91CX42_LM_CTL_PGM | CA91CX42_LM_CTL_DATA)) == 0) {
1408 mutex_unlock(&(lm->mtx)); 1409 mutex_unlock(&lm->mtx);
1409 dev_err(dev, "Location monitor not properly configured\n"); 1410 dev_err(dev, "Location monitor not properly configured\n");
1410 return -EINVAL; 1411 return -EINVAL;
1411 } 1412 }
1412 1413
1413 /* Check that a callback isn't already attached */ 1414 /* Check that a callback isn't already attached */
1414 if (bridge->lm_callback[monitor] != NULL) { 1415 if (bridge->lm_callback[monitor] != NULL) {
1415 mutex_unlock(&(lm->mtx)); 1416 mutex_unlock(&lm->mtx);
1416 dev_err(dev, "Existing callback attached\n"); 1417 dev_err(dev, "Existing callback attached\n");
1417 return -EBUSY; 1418 return -EBUSY;
1418 } 1419 }
@@ -1431,7 +1432,7 @@ int ca91cx42_lm_attach(struct vme_lm_resource *lm, int monitor,
1431 iowrite32(lm_ctl, bridge->base + LM_CTL); 1432 iowrite32(lm_ctl, bridge->base + LM_CTL);
1432 } 1433 }
1433 1434
1434 mutex_unlock(&(lm->mtx)); 1435 mutex_unlock(&lm->mtx);
1435 1436
1436 return 0; 1437 return 0;
1437} 1438}
@@ -1439,14 +1440,14 @@ int ca91cx42_lm_attach(struct vme_lm_resource *lm, int monitor,
1439/* 1440/*
1440 * Detach a callback function forn a specific location monitor. 1441 * Detach a callback function forn a specific location monitor.
1441 */ 1442 */
1442int ca91cx42_lm_detach(struct vme_lm_resource *lm, int monitor) 1443static int ca91cx42_lm_detach(struct vme_lm_resource *lm, int monitor)
1443{ 1444{
1444 u32 tmp; 1445 u32 tmp;
1445 struct ca91cx42_driver *bridge; 1446 struct ca91cx42_driver *bridge;
1446 1447
1447 bridge = lm->parent->driver_priv; 1448 bridge = lm->parent->driver_priv;
1448 1449
1449 mutex_lock(&(lm->mtx)); 1450 mutex_lock(&lm->mtx);
1450 1451
1451 /* Disable Location Monitor and ensure previous interrupts are clear */ 1452 /* Disable Location Monitor and ensure previous interrupts are clear */
1452 tmp = ioread32(bridge->base + LINT_EN); 1453 tmp = ioread32(bridge->base + LINT_EN);
@@ -1467,12 +1468,12 @@ int ca91cx42_lm_detach(struct vme_lm_resource *lm, int monitor)
1467 iowrite32(tmp, bridge->base + LM_CTL); 1468 iowrite32(tmp, bridge->base + LM_CTL);
1468 } 1469 }
1469 1470
1470 mutex_unlock(&(lm->mtx)); 1471 mutex_unlock(&lm->mtx);
1471 1472
1472 return 0; 1473 return 0;
1473} 1474}
1474 1475
1475int ca91cx42_slot_get(struct vme_bridge *ca91cx42_bridge) 1476static int ca91cx42_slot_get(struct vme_bridge *ca91cx42_bridge)
1476{ 1477{
1477 u32 slot = 0; 1478 u32 slot = 0;
1478 struct ca91cx42_driver *bridge; 1479 struct ca91cx42_driver *bridge;
@@ -1526,7 +1527,7 @@ static int ca91cx42_crcsr_init(struct vme_bridge *ca91cx42_bridge,
1526 1527
1527 /* Allocate mem for CR/CSR image */ 1528 /* Allocate mem for CR/CSR image */
1528 bridge->crcsr_kernel = pci_alloc_consistent(pdev, VME_CRCSR_BUF_SIZE, 1529 bridge->crcsr_kernel = pci_alloc_consistent(pdev, VME_CRCSR_BUF_SIZE,
1529 &(bridge->crcsr_bus)); 1530 &bridge->crcsr_bus);
1530 if (bridge->crcsr_kernel == NULL) { 1531 if (bridge->crcsr_kernel == NULL) {
1531 dev_err(&pdev->dev, "Failed to allocate memory for CR/CSR " 1532 dev_err(&pdev->dev, "Failed to allocate memory for CR/CSR "
1532 "image\n"); 1533 "image\n");
@@ -1632,12 +1633,12 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1632 } 1633 }
1633 1634
1634 /* Initialize wait queues & mutual exclusion flags */ 1635 /* Initialize wait queues & mutual exclusion flags */
1635 init_waitqueue_head(&(ca91cx42_device->dma_queue)); 1636 init_waitqueue_head(&ca91cx42_device->dma_queue);
1636 init_waitqueue_head(&(ca91cx42_device->iack_queue)); 1637 init_waitqueue_head(&ca91cx42_device->iack_queue);
1637 mutex_init(&(ca91cx42_device->vme_int)); 1638 mutex_init(&ca91cx42_device->vme_int);
1638 mutex_init(&(ca91cx42_device->vme_rmw)); 1639 mutex_init(&ca91cx42_device->vme_rmw);
1639 1640
1640 ca91cx42_bridge->parent = &(pdev->dev); 1641 ca91cx42_bridge->parent = &pdev->dev;
1641 strcpy(ca91cx42_bridge->name, driver_name); 1642 strcpy(ca91cx42_bridge->name, driver_name);
1642 1643
1643 /* Setup IRQ */ 1644 /* Setup IRQ */
@@ -1648,7 +1649,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1648 } 1649 }
1649 1650
1650 /* Add master windows to list */ 1651 /* Add master windows to list */
1651 INIT_LIST_HEAD(&(ca91cx42_bridge->master_resources)); 1652 INIT_LIST_HEAD(&ca91cx42_bridge->master_resources);
1652 for (i = 0; i < CA91C142_MAX_MASTER; i++) { 1653 for (i = 0; i < CA91C142_MAX_MASTER; i++) {
1653 master_image = kmalloc(sizeof(struct vme_master_resource), 1654 master_image = kmalloc(sizeof(struct vme_master_resource),
1654 GFP_KERNEL); 1655 GFP_KERNEL);
@@ -1659,7 +1660,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1659 goto err_master; 1660 goto err_master;
1660 } 1661 }
1661 master_image->parent = ca91cx42_bridge; 1662 master_image->parent = ca91cx42_bridge;
1662 spin_lock_init(&(master_image->lock)); 1663 spin_lock_init(&master_image->lock);
1663 master_image->locked = 0; 1664 master_image->locked = 0;
1664 master_image->number = i; 1665 master_image->number = i;
1665 master_image->address_attr = VME_A16 | VME_A24 | VME_A32 | 1666 master_image->address_attr = VME_A16 | VME_A24 | VME_A32 |
@@ -1667,15 +1668,15 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1667 master_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT | 1668 master_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
1668 VME_SUPER | VME_USER | VME_PROG | VME_DATA; 1669 VME_SUPER | VME_USER | VME_PROG | VME_DATA;
1669 master_image->width_attr = VME_D8 | VME_D16 | VME_D32 | VME_D64; 1670 master_image->width_attr = VME_D8 | VME_D16 | VME_D32 | VME_D64;
1670 memset(&(master_image->bus_resource), 0, 1671 memset(&master_image->bus_resource, 0,
1671 sizeof(struct resource)); 1672 sizeof(struct resource));
1672 master_image->kern_base = NULL; 1673 master_image->kern_base = NULL;
1673 list_add_tail(&(master_image->list), 1674 list_add_tail(&master_image->list,
1674 &(ca91cx42_bridge->master_resources)); 1675 &ca91cx42_bridge->master_resources);
1675 } 1676 }
1676 1677
1677 /* Add slave windows to list */ 1678 /* Add slave windows to list */
1678 INIT_LIST_HEAD(&(ca91cx42_bridge->slave_resources)); 1679 INIT_LIST_HEAD(&ca91cx42_bridge->slave_resources);
1679 for (i = 0; i < CA91C142_MAX_SLAVE; i++) { 1680 for (i = 0; i < CA91C142_MAX_SLAVE; i++) {
1680 slave_image = kmalloc(sizeof(struct vme_slave_resource), 1681 slave_image = kmalloc(sizeof(struct vme_slave_resource),
1681 GFP_KERNEL); 1682 GFP_KERNEL);
@@ -1686,7 +1687,7 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1686 goto err_slave; 1687 goto err_slave;
1687 } 1688 }
1688 slave_image->parent = ca91cx42_bridge; 1689 slave_image->parent = ca91cx42_bridge;
1689 mutex_init(&(slave_image->mtx)); 1690 mutex_init(&slave_image->mtx);
1690 slave_image->locked = 0; 1691 slave_image->locked = 0;
1691 slave_image->number = i; 1692 slave_image->number = i;
1692 slave_image->address_attr = VME_A24 | VME_A32 | VME_USER1 | 1693 slave_image->address_attr = VME_A24 | VME_A32 | VME_USER1 |
@@ -1698,12 +1699,12 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1698 1699
1699 slave_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT | 1700 slave_image->cycle_attr = VME_SCT | VME_BLT | VME_MBLT |
1700 VME_SUPER | VME_USER | VME_PROG | VME_DATA; 1701 VME_SUPER | VME_USER | VME_PROG | VME_DATA;
1701 list_add_tail(&(slave_image->list), 1702 list_add_tail(&slave_image->list,
1702 &(ca91cx42_bridge->slave_resources)); 1703 &ca91cx42_bridge->slave_resources);
1703 } 1704 }
1704 1705
1705 /* Add dma engines to list */ 1706 /* Add dma engines to list */
1706 INIT_LIST_HEAD(&(ca91cx42_bridge->dma_resources)); 1707 INIT_LIST_HEAD(&ca91cx42_bridge->dma_resources);
1707 for (i = 0; i < CA91C142_MAX_DMA; i++) { 1708 for (i = 0; i < CA91C142_MAX_DMA; i++) {
1708 dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource), 1709 dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource),
1709 GFP_KERNEL); 1710 GFP_KERNEL);
@@ -1714,19 +1715,19 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1714 goto err_dma; 1715 goto err_dma;
1715 } 1716 }
1716 dma_ctrlr->parent = ca91cx42_bridge; 1717 dma_ctrlr->parent = ca91cx42_bridge;
1717 mutex_init(&(dma_ctrlr->mtx)); 1718 mutex_init(&dma_ctrlr->mtx);
1718 dma_ctrlr->locked = 0; 1719 dma_ctrlr->locked = 0;
1719 dma_ctrlr->number = i; 1720 dma_ctrlr->number = i;
1720 dma_ctrlr->route_attr = VME_DMA_VME_TO_MEM | 1721 dma_ctrlr->route_attr = VME_DMA_VME_TO_MEM |
1721 VME_DMA_MEM_TO_VME; 1722 VME_DMA_MEM_TO_VME;
1722 INIT_LIST_HEAD(&(dma_ctrlr->pending)); 1723 INIT_LIST_HEAD(&dma_ctrlr->pending);
1723 INIT_LIST_HEAD(&(dma_ctrlr->running)); 1724 INIT_LIST_HEAD(&dma_ctrlr->running);
1724 list_add_tail(&(dma_ctrlr->list), 1725 list_add_tail(&dma_ctrlr->list,
1725 &(ca91cx42_bridge->dma_resources)); 1726 &ca91cx42_bridge->dma_resources);
1726 } 1727 }
1727 1728
1728 /* Add location monitor to list */ 1729 /* Add location monitor to list */
1729 INIT_LIST_HEAD(&(ca91cx42_bridge->lm_resources)); 1730 INIT_LIST_HEAD(&ca91cx42_bridge->lm_resources);
1730 lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); 1731 lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL);
1731 if (lm == NULL) { 1732 if (lm == NULL) {
1732 dev_err(&pdev->dev, "Failed to allocate memory for " 1733 dev_err(&pdev->dev, "Failed to allocate memory for "
@@ -1735,11 +1736,11 @@ static int ca91cx42_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1735 goto err_lm; 1736 goto err_lm;
1736 } 1737 }
1737 lm->parent = ca91cx42_bridge; 1738 lm->parent = ca91cx42_bridge;
1738 mutex_init(&(lm->mtx)); 1739 mutex_init(&lm->mtx);
1739 lm->locked = 0; 1740 lm->locked = 0;
1740 lm->number = 1; 1741 lm->number = 1;
1741 lm->monitors = 4; 1742 lm->monitors = 4;
1742 list_add_tail(&(lm->list), &(ca91cx42_bridge->lm_resources)); 1743 list_add_tail(&lm->list, &ca91cx42_bridge->lm_resources);
1743 1744
1744 ca91cx42_bridge->slave_get = ca91cx42_slave_get; 1745 ca91cx42_bridge->slave_get = ca91cx42_slave_get;
1745 ca91cx42_bridge->slave_set = ca91cx42_slave_set; 1746 ca91cx42_bridge->slave_set = ca91cx42_slave_set;
@@ -1786,28 +1787,28 @@ err_reg:
1786 ca91cx42_crcsr_exit(ca91cx42_bridge, pdev); 1787 ca91cx42_crcsr_exit(ca91cx42_bridge, pdev);
1787err_lm: 1788err_lm:
1788 /* resources are stored in link list */ 1789 /* resources are stored in link list */
1789 list_for_each(pos, &(ca91cx42_bridge->lm_resources)) { 1790 list_for_each(pos, &ca91cx42_bridge->lm_resources) {
1790 lm = list_entry(pos, struct vme_lm_resource, list); 1791 lm = list_entry(pos, struct vme_lm_resource, list);
1791 list_del(pos); 1792 list_del(pos);
1792 kfree(lm); 1793 kfree(lm);
1793 } 1794 }
1794err_dma: 1795err_dma:
1795 /* resources are stored in link list */ 1796 /* resources are stored in link list */
1796 list_for_each(pos, &(ca91cx42_bridge->dma_resources)) { 1797 list_for_each(pos, &ca91cx42_bridge->dma_resources) {
1797 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list); 1798 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
1798 list_del(pos); 1799 list_del(pos);
1799 kfree(dma_ctrlr); 1800 kfree(dma_ctrlr);
1800 } 1801 }
1801err_slave: 1802err_slave:
1802 /* resources are stored in link list */ 1803 /* resources are stored in link list */
1803 list_for_each(pos, &(ca91cx42_bridge->slave_resources)) { 1804 list_for_each(pos, &ca91cx42_bridge->slave_resources) {
1804 slave_image = list_entry(pos, struct vme_slave_resource, list); 1805 slave_image = list_entry(pos, struct vme_slave_resource, list);
1805 list_del(pos); 1806 list_del(pos);
1806 kfree(slave_image); 1807 kfree(slave_image);
1807 } 1808 }
1808err_master: 1809err_master:
1809 /* resources are stored in link list */ 1810 /* resources are stored in link list */
1810 list_for_each(pos, &(ca91cx42_bridge->master_resources)) { 1811 list_for_each(pos, &ca91cx42_bridge->master_resources) {
1811 master_image = list_entry(pos, struct vme_master_resource, 1812 master_image = list_entry(pos, struct vme_master_resource,
1812 list); 1813 list);
1813 list_del(pos); 1814 list_del(pos);
@@ -1831,7 +1832,7 @@ err_struct:
1831 1832
1832} 1833}
1833 1834
1834void ca91cx42_remove(struct pci_dev *pdev) 1835static void ca91cx42_remove(struct pci_dev *pdev)
1835{ 1836{
1836 struct list_head *pos = NULL; 1837 struct list_head *pos = NULL;
1837 struct vme_master_resource *master_image; 1838 struct vme_master_resource *master_image;
@@ -1870,28 +1871,28 @@ void ca91cx42_remove(struct pci_dev *pdev)
1870 ca91cx42_crcsr_exit(ca91cx42_bridge, pdev); 1871 ca91cx42_crcsr_exit(ca91cx42_bridge, pdev);
1871 1872
1872 /* resources are stored in link list */ 1873 /* resources are stored in link list */
1873 list_for_each(pos, &(ca91cx42_bridge->lm_resources)) { 1874 list_for_each(pos, &ca91cx42_bridge->lm_resources) {
1874 lm = list_entry(pos, struct vme_lm_resource, list); 1875 lm = list_entry(pos, struct vme_lm_resource, list);
1875 list_del(pos); 1876 list_del(pos);
1876 kfree(lm); 1877 kfree(lm);
1877 } 1878 }
1878 1879
1879 /* resources are stored in link list */ 1880 /* resources are stored in link list */
1880 list_for_each(pos, &(ca91cx42_bridge->dma_resources)) { 1881 list_for_each(pos, &ca91cx42_bridge->dma_resources) {
1881 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list); 1882 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
1882 list_del(pos); 1883 list_del(pos);
1883 kfree(dma_ctrlr); 1884 kfree(dma_ctrlr);
1884 } 1885 }
1885 1886
1886 /* resources are stored in link list */ 1887 /* resources are stored in link list */
1887 list_for_each(pos, &(ca91cx42_bridge->slave_resources)) { 1888 list_for_each(pos, &ca91cx42_bridge->slave_resources) {
1888 slave_image = list_entry(pos, struct vme_slave_resource, list); 1889 slave_image = list_entry(pos, struct vme_slave_resource, list);
1889 list_del(pos); 1890 list_del(pos);
1890 kfree(slave_image); 1891 kfree(slave_image);
1891 } 1892 }
1892 1893
1893 /* resources are stored in link list */ 1894 /* resources are stored in link list */
1894 list_for_each(pos, &(ca91cx42_bridge->master_resources)) { 1895 list_for_each(pos, &ca91cx42_bridge->master_resources) {
1895 master_image = list_entry(pos, struct vme_master_resource, 1896 master_image = list_entry(pos, struct vme_master_resource,
1896 list); 1897 list);
1897 list_del(pos); 1898 list_del(pos);
diff --git a/drivers/staging/vme/bridges/vme_ca91cx42.h b/drivers/staging/vme/bridges/vme_ca91cx42.h
index e72c65b193ec..02a7c794db05 100644
--- a/drivers/staging/vme/bridges/vme_ca91cx42.h
+++ b/drivers/staging/vme/bridges/vme_ca91cx42.h
@@ -39,7 +39,7 @@
39 39
40/* Structure used to hold driver specific information */ 40/* Structure used to hold driver specific information */
41struct ca91cx42_driver { 41struct ca91cx42_driver {
42 void *base; /* Base Address of device registers */ 42 void __iomem *base; /* Base Address of device registers */
43 wait_queue_head_t dma_queue; 43 wait_queue_head_t dma_queue;
44 wait_queue_head_t iack_queue; 44 wait_queue_head_t iack_queue;
45 wait_queue_head_t mbox_queue; 45 wait_queue_head_t mbox_queue;
diff --git a/drivers/staging/vme/bridges/vme_tsi148.c b/drivers/staging/vme/bridges/vme_tsi148.c
index 492ddb2d5108..26ea42fa784d 100644
--- a/drivers/staging/vme/bridges/vme_tsi148.c
+++ b/drivers/staging/vme/bridges/vme_tsi148.c
@@ -46,7 +46,7 @@ static int geoid;
46 46
47static char driver_name[] = "vme_tsi148"; 47static char driver_name[] = "vme_tsi148";
48 48
49static const struct pci_device_id tsi148_ids[] = { 49static DEFINE_PCI_DEVICE_TABLE(tsi148_ids) = {
50 { PCI_DEVICE(PCI_VENDOR_ID_TUNDRA, PCI_DEVICE_ID_TUNDRA_TSI148) }, 50 { PCI_DEVICE(PCI_VENDOR_ID_TUNDRA, PCI_DEVICE_ID_TUNDRA_TSI148) },
51 { }, 51 { },
52}; 52};
@@ -81,11 +81,11 @@ static u32 tsi148_DMA_irqhandler(struct tsi148_driver *bridge,
81 u32 serviced = 0; 81 u32 serviced = 0;
82 82
83 if (channel_mask & TSI148_LCSR_INTS_DMA0S) { 83 if (channel_mask & TSI148_LCSR_INTS_DMA0S) {
84 wake_up(&(bridge->dma_queue[0])); 84 wake_up(&bridge->dma_queue[0]);
85 serviced |= TSI148_LCSR_INTC_DMA0C; 85 serviced |= TSI148_LCSR_INTC_DMA0C;
86 } 86 }
87 if (channel_mask & TSI148_LCSR_INTS_DMA1S) { 87 if (channel_mask & TSI148_LCSR_INTS_DMA1S) {
88 wake_up(&(bridge->dma_queue[1])); 88 wake_up(&bridge->dma_queue[1]);
89 serviced |= TSI148_LCSR_INTC_DMA1C; 89 serviced |= TSI148_LCSR_INTC_DMA1C;
90 } 90 }
91 91
@@ -191,7 +191,7 @@ static u32 tsi148_VERR_irqhandler(struct vme_bridge *tsi148_bridge)
191 if (error) { 191 if (error) {
192 error->address = error_addr; 192 error->address = error_addr;
193 error->attributes = error_attrib; 193 error->attributes = error_attrib;
194 list_add_tail(&(error->list), &(tsi148_bridge->vme_errors)); 194 list_add_tail(&error->list, &tsi148_bridge->vme_errors);
195 } else { 195 } else {
196 dev_err(tsi148_bridge->parent, "Unable to alloc memory for " 196 dev_err(tsi148_bridge->parent, "Unable to alloc memory for "
197 "VMEbus Error reporting\n"); 197 "VMEbus Error reporting\n");
@@ -210,7 +210,7 @@ static u32 tsi148_VERR_irqhandler(struct vme_bridge *tsi148_bridge)
210 */ 210 */
211static u32 tsi148_IACK_irqhandler(struct tsi148_driver *bridge) 211static u32 tsi148_IACK_irqhandler(struct tsi148_driver *bridge)
212{ 212{
213 wake_up(&(bridge->iack_queue)); 213 wake_up(&bridge->iack_queue);
214 214
215 return TSI148_LCSR_INTC_IACKC; 215 return TSI148_LCSR_INTC_IACKC;
216} 216}
@@ -320,9 +320,9 @@ static int tsi148_irq_init(struct vme_bridge *tsi148_bridge)
320 bridge = tsi148_bridge->driver_priv; 320 bridge = tsi148_bridge->driver_priv;
321 321
322 /* Initialise list for VME bus errors */ 322 /* Initialise list for VME bus errors */
323 INIT_LIST_HEAD(&(tsi148_bridge->vme_errors)); 323 INIT_LIST_HEAD(&tsi148_bridge->vme_errors);
324 324
325 mutex_init(&(tsi148_bridge->irq_mtx)); 325 mutex_init(&tsi148_bridge->irq_mtx);
326 326
327 result = request_irq(pdev->irq, 327 result = request_irq(pdev->irq,
328 tsi148_irqhandler, 328 tsi148_irqhandler,
@@ -374,8 +374,11 @@ static int tsi148_irq_init(struct vme_bridge *tsi148_bridge)
374 return 0; 374 return 0;
375} 375}
376 376
377static void tsi148_irq_exit(struct tsi148_driver *bridge, struct pci_dev *pdev) 377static void tsi148_irq_exit(struct vme_bridge *tsi148_bridge,
378 struct pci_dev *pdev)
378{ 379{
380 struct tsi148_driver *bridge = tsi148_bridge->driver_priv;
381
379 /* Turn off interrupts */ 382 /* Turn off interrupts */
380 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTEO); 383 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTEO);
381 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTEN); 384 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTEN);
@@ -384,13 +387,13 @@ static void tsi148_irq_exit(struct tsi148_driver *bridge, struct pci_dev *pdev)
384 iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_INTC); 387 iowrite32be(0xFFFFFFFF, bridge->base + TSI148_LCSR_INTC);
385 388
386 /* Detach interrupt handler */ 389 /* Detach interrupt handler */
387 free_irq(pdev->irq, pdev); 390 free_irq(pdev->irq, tsi148_bridge);
388} 391}
389 392
390/* 393/*
391 * Check to see if an IACk has been received, return true (1) or false (0). 394 * Check to see if an IACk has been received, return true (1) or false (0).
392 */ 395 */
393int tsi148_iack_received(struct tsi148_driver *bridge) 396static int tsi148_iack_received(struct tsi148_driver *bridge)
394{ 397{
395 u32 tmp; 398 u32 tmp;
396 399
@@ -405,7 +408,7 @@ int tsi148_iack_received(struct tsi148_driver *bridge)
405/* 408/*
406 * Configure VME interrupt 409 * Configure VME interrupt
407 */ 410 */
408void tsi148_irq_set(struct vme_bridge *tsi148_bridge, int level, 411static void tsi148_irq_set(struct vme_bridge *tsi148_bridge, int level,
409 int state, int sync) 412 int state, int sync)
410{ 413{
411 struct pci_dev *pdev; 414 struct pci_dev *pdev;
@@ -445,14 +448,15 @@ void tsi148_irq_set(struct vme_bridge *tsi148_bridge, int level,
445 * Generate a VME bus interrupt at the requested level & vector. Wait for 448 * Generate a VME bus interrupt at the requested level & vector. Wait for
446 * interrupt to be acked. 449 * interrupt to be acked.
447 */ 450 */
448int tsi148_irq_generate(struct vme_bridge *tsi148_bridge, int level, int statid) 451static int tsi148_irq_generate(struct vme_bridge *tsi148_bridge, int level,
452 int statid)
449{ 453{
450 u32 tmp; 454 u32 tmp;
451 struct tsi148_driver *bridge; 455 struct tsi148_driver *bridge;
452 456
453 bridge = tsi148_bridge->driver_priv; 457 bridge = tsi148_bridge->driver_priv;
454 458
455 mutex_lock(&(bridge->vme_int)); 459 mutex_lock(&bridge->vme_int);
456 460
457 /* Read VICR register */ 461 /* Read VICR register */
458 tmp = ioread32be(bridge->base + TSI148_LCSR_VICR); 462 tmp = ioread32be(bridge->base + TSI148_LCSR_VICR);
@@ -470,7 +474,7 @@ int tsi148_irq_generate(struct vme_bridge *tsi148_bridge, int level, int statid)
470 wait_event_interruptible(bridge->iack_queue, 474 wait_event_interruptible(bridge->iack_queue,
471 tsi148_iack_received(bridge)); 475 tsi148_iack_received(bridge));
472 476
473 mutex_unlock(&(bridge->vme_int)); 477 mutex_unlock(&bridge->vme_int);
474 478
475 return 0; 479 return 0;
476} 480}
@@ -496,7 +500,7 @@ static struct vme_bus_error *tsi148_find_error(struct vme_bridge *tsi148_bridge,
496 */ 500 */
497 err_pos = NULL; 501 err_pos = NULL;
498 /* Iterate through errors */ 502 /* Iterate through errors */
499 list_for_each(err_pos, &(tsi148_bridge->vme_errors)) { 503 list_for_each(err_pos, &tsi148_bridge->vme_errors) {
500 vme_err = list_entry(err_pos, struct vme_bus_error, list); 504 vme_err = list_entry(err_pos, struct vme_bus_error, list);
501 if ((vme_err->address >= address) && 505 if ((vme_err->address >= address) &&
502 (vme_err->address < bound)) { 506 (vme_err->address < bound)) {
@@ -530,7 +534,7 @@ static void tsi148_clear_errors(struct vme_bridge *tsi148_bridge,
530 */ 534 */
531 err_pos = NULL; 535 err_pos = NULL;
532 /* Iterate through errors */ 536 /* Iterate through errors */
533 list_for_each_safe(err_pos, temp, &(tsi148_bridge->vme_errors)) { 537 list_for_each_safe(err_pos, temp, &tsi148_bridge->vme_errors) {
534 vme_err = list_entry(err_pos, struct vme_bus_error, list); 538 vme_err = list_entry(err_pos, struct vme_bus_error, list);
535 539
536 if ((vme_err->address >= address) && 540 if ((vme_err->address >= address) &&
@@ -545,7 +549,7 @@ static void tsi148_clear_errors(struct vme_bridge *tsi148_bridge,
545/* 549/*
546 * Initialize a slave window with the requested attributes. 550 * Initialize a slave window with the requested attributes.
547 */ 551 */
548int tsi148_slave_set(struct vme_slave_resource *image, int enabled, 552static int tsi148_slave_set(struct vme_slave_resource *image, int enabled,
549 unsigned long long vme_base, unsigned long long size, 553 unsigned long long vme_base, unsigned long long size,
550 dma_addr_t pci_base, vme_address_t aspace, vme_cycle_t cycle) 554 dma_addr_t pci_base, vme_address_t aspace, vme_cycle_t cycle)
551{ 555{
@@ -695,7 +699,7 @@ int tsi148_slave_set(struct vme_slave_resource *image, int enabled,
695/* 699/*
696 * Get slave window configuration. 700 * Get slave window configuration.
697 */ 701 */
698int tsi148_slave_get(struct vme_slave_resource *image, int *enabled, 702static int tsi148_slave_get(struct vme_slave_resource *image, int *enabled,
699 unsigned long long *vme_base, unsigned long long *size, 703 unsigned long long *vme_base, unsigned long long *size,
700 dma_addr_t *pci_base, vme_address_t *aspace, vme_cycle_t *cycle) 704 dma_addr_t *pci_base, vme_address_t *aspace, vme_cycle_t *cycle)
701{ 705{
@@ -819,8 +823,8 @@ static int tsi148_alloc_resource(struct vme_master_resource *image,
819 image->kern_base = NULL; 823 image->kern_base = NULL;
820 if (image->bus_resource.name != NULL) 824 if (image->bus_resource.name != NULL)
821 kfree(image->bus_resource.name); 825 kfree(image->bus_resource.name);
822 release_resource(&(image->bus_resource)); 826 release_resource(&image->bus_resource);
823 memset(&(image->bus_resource), 0, sizeof(struct resource)); 827 memset(&image->bus_resource, 0, sizeof(struct resource));
824 } 828 }
825 829
826 /* Exit here if size is zero */ 830 /* Exit here if size is zero */
@@ -845,7 +849,7 @@ static int tsi148_alloc_resource(struct vme_master_resource *image,
845 image->bus_resource.flags = IORESOURCE_MEM; 849 image->bus_resource.flags = IORESOURCE_MEM;
846 850
847 retval = pci_bus_alloc_resource(pdev->bus, 851 retval = pci_bus_alloc_resource(pdev->bus,
848 &(image->bus_resource), size, size, PCIBIOS_MIN_MEM, 852 &image->bus_resource, size, size, PCIBIOS_MIN_MEM,
849 0, NULL, NULL); 853 0, NULL, NULL);
850 if (retval) { 854 if (retval) {
851 dev_err(tsi148_bridge->parent, "Failed to allocate mem " 855 dev_err(tsi148_bridge->parent, "Failed to allocate mem "
@@ -868,10 +872,10 @@ static int tsi148_alloc_resource(struct vme_master_resource *image,
868 iounmap(image->kern_base); 872 iounmap(image->kern_base);
869 image->kern_base = NULL; 873 image->kern_base = NULL;
870err_remap: 874err_remap:
871 release_resource(&(image->bus_resource)); 875 release_resource(&image->bus_resource);
872err_resource: 876err_resource:
873 kfree(image->bus_resource.name); 877 kfree(image->bus_resource.name);
874 memset(&(image->bus_resource), 0, sizeof(struct resource)); 878 memset(&image->bus_resource, 0, sizeof(struct resource));
875err_name: 879err_name:
876 return retval; 880 return retval;
877} 881}
@@ -883,15 +887,15 @@ static void tsi148_free_resource(struct vme_master_resource *image)
883{ 887{
884 iounmap(image->kern_base); 888 iounmap(image->kern_base);
885 image->kern_base = NULL; 889 image->kern_base = NULL;
886 release_resource(&(image->bus_resource)); 890 release_resource(&image->bus_resource);
887 kfree(image->bus_resource.name); 891 kfree(image->bus_resource.name);
888 memset(&(image->bus_resource), 0, sizeof(struct resource)); 892 memset(&image->bus_resource, 0, sizeof(struct resource));
889} 893}
890 894
891/* 895/*
892 * Set the attributes of an outbound window. 896 * Set the attributes of an outbound window.
893 */ 897 */
894int tsi148_master_set(struct vme_master_resource *image, int enabled, 898static int tsi148_master_set(struct vme_master_resource *image, int enabled,
895 unsigned long long vme_base, unsigned long long size, 899 unsigned long long vme_base, unsigned long long size,
896 vme_address_t aspace, vme_cycle_t cycle, vme_width_t dwidth) 900 vme_address_t aspace, vme_cycle_t cycle, vme_width_t dwidth)
897{ 901{
@@ -924,7 +928,7 @@ int tsi148_master_set(struct vme_master_resource *image, int enabled,
924 goto err_window; 928 goto err_window;
925 } 929 }
926 930
927 spin_lock(&(image->lock)); 931 spin_lock(&image->lock);
928 932
929 /* Let's allocate the resource here rather than further up the stack as 933 /* Let's allocate the resource here rather than further up the stack as
930 * it avoids pushing loads of bus dependant stuff up the stack. If size 934 * it avoids pushing loads of bus dependant stuff up the stack. If size
@@ -932,7 +936,7 @@ int tsi148_master_set(struct vme_master_resource *image, int enabled,
932 */ 936 */
933 retval = tsi148_alloc_resource(image, size); 937 retval = tsi148_alloc_resource(image, size);
934 if (retval) { 938 if (retval) {
935 spin_unlock(&(image->lock)); 939 spin_unlock(&image->lock);
936 dev_err(tsi148_bridge->parent, "Unable to allocate memory for " 940 dev_err(tsi148_bridge->parent, "Unable to allocate memory for "
937 "resource\n"); 941 "resource\n");
938 goto err_res; 942 goto err_res;
@@ -959,19 +963,19 @@ int tsi148_master_set(struct vme_master_resource *image, int enabled,
959 reg_split(vme_offset, &vme_offset_high, &vme_offset_low); 963 reg_split(vme_offset, &vme_offset_high, &vme_offset_low);
960 964
961 if (pci_base_low & 0xFFFF) { 965 if (pci_base_low & 0xFFFF) {
962 spin_unlock(&(image->lock)); 966 spin_unlock(&image->lock);
963 dev_err(tsi148_bridge->parent, "Invalid PCI base alignment\n"); 967 dev_err(tsi148_bridge->parent, "Invalid PCI base alignment\n");
964 retval = -EINVAL; 968 retval = -EINVAL;
965 goto err_gran; 969 goto err_gran;
966 } 970 }
967 if (pci_bound_low & 0xFFFF) { 971 if (pci_bound_low & 0xFFFF) {
968 spin_unlock(&(image->lock)); 972 spin_unlock(&image->lock);
969 dev_err(tsi148_bridge->parent, "Invalid PCI bound alignment\n"); 973 dev_err(tsi148_bridge->parent, "Invalid PCI bound alignment\n");
970 retval = -EINVAL; 974 retval = -EINVAL;
971 goto err_gran; 975 goto err_gran;
972 } 976 }
973 if (vme_offset_low & 0xFFFF) { 977 if (vme_offset_low & 0xFFFF) {
974 spin_unlock(&(image->lock)); 978 spin_unlock(&image->lock);
975 dev_err(tsi148_bridge->parent, "Invalid VME Offset " 979 dev_err(tsi148_bridge->parent, "Invalid VME Offset "
976 "alignment\n"); 980 "alignment\n");
977 retval = -EINVAL; 981 retval = -EINVAL;
@@ -1035,7 +1039,7 @@ int tsi148_master_set(struct vme_master_resource *image, int enabled,
1035 temp_ctl |= TSI148_LCSR_OTAT_DBW_32; 1039 temp_ctl |= TSI148_LCSR_OTAT_DBW_32;
1036 break; 1040 break;
1037 default: 1041 default:
1038 spin_unlock(&(image->lock)); 1042 spin_unlock(&image->lock);
1039 dev_err(tsi148_bridge->parent, "Invalid data width\n"); 1043 dev_err(tsi148_bridge->parent, "Invalid data width\n");
1040 retval = -EINVAL; 1044 retval = -EINVAL;
1041 goto err_dwidth; 1045 goto err_dwidth;
@@ -1072,7 +1076,7 @@ int tsi148_master_set(struct vme_master_resource *image, int enabled,
1072 temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER4; 1076 temp_ctl |= TSI148_LCSR_OTAT_AMODE_USER4;
1073 break; 1077 break;
1074 default: 1078 default:
1075 spin_unlock(&(image->lock)); 1079 spin_unlock(&image->lock);
1076 dev_err(tsi148_bridge->parent, "Invalid address space\n"); 1080 dev_err(tsi148_bridge->parent, "Invalid address space\n");
1077 retval = -EINVAL; 1081 retval = -EINVAL;
1078 goto err_aspace; 1082 goto err_aspace;
@@ -1109,7 +1113,7 @@ int tsi148_master_set(struct vme_master_resource *image, int enabled,
1109 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] + 1113 iowrite32be(temp_ctl, bridge->base + TSI148_LCSR_OT[i] +
1110 TSI148_LCSR_OFFSET_OTAT); 1114 TSI148_LCSR_OFFSET_OTAT);
1111 1115
1112 spin_unlock(&(image->lock)); 1116 spin_unlock(&image->lock);
1113 return 0; 1117 return 0;
1114 1118
1115err_aspace: 1119err_aspace:
@@ -1127,7 +1131,7 @@ err_window:
1127 * 1131 *
1128 * XXX Not parsing prefetch information. 1132 * XXX Not parsing prefetch information.
1129 */ 1133 */
1130int __tsi148_master_get(struct vme_master_resource *image, int *enabled, 1134static int __tsi148_master_get(struct vme_master_resource *image, int *enabled,
1131 unsigned long long *vme_base, unsigned long long *size, 1135 unsigned long long *vme_base, unsigned long long *size,
1132 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth) 1136 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth)
1133{ 1137{
@@ -1237,23 +1241,23 @@ int __tsi148_master_get(struct vme_master_resource *image, int *enabled,
1237} 1241}
1238 1242
1239 1243
1240int tsi148_master_get(struct vme_master_resource *image, int *enabled, 1244static int tsi148_master_get(struct vme_master_resource *image, int *enabled,
1241 unsigned long long *vme_base, unsigned long long *size, 1245 unsigned long long *vme_base, unsigned long long *size,
1242 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth) 1246 vme_address_t *aspace, vme_cycle_t *cycle, vme_width_t *dwidth)
1243{ 1247{
1244 int retval; 1248 int retval;
1245 1249
1246 spin_lock(&(image->lock)); 1250 spin_lock(&image->lock);
1247 1251
1248 retval = __tsi148_master_get(image, enabled, vme_base, size, aspace, 1252 retval = __tsi148_master_get(image, enabled, vme_base, size, aspace,
1249 cycle, dwidth); 1253 cycle, dwidth);
1250 1254
1251 spin_unlock(&(image->lock)); 1255 spin_unlock(&image->lock);
1252 1256
1253 return retval; 1257 return retval;
1254} 1258}
1255 1259
1256ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf, 1260static ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf,
1257 size_t count, loff_t offset) 1261 size_t count, loff_t offset)
1258{ 1262{
1259 int retval, enabled; 1263 int retval, enabled;
@@ -1266,7 +1270,7 @@ ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf,
1266 1270
1267 tsi148_bridge = image->parent; 1271 tsi148_bridge = image->parent;
1268 1272
1269 spin_lock(&(image->lock)); 1273 spin_lock(&image->lock);
1270 1274
1271 memcpy_fromio(buf, image->kern_base + offset, (unsigned int)count); 1275 memcpy_fromio(buf, image->kern_base + offset, (unsigned int)count);
1272 retval = count; 1276 retval = count;
@@ -1289,13 +1293,13 @@ ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf,
1289 } 1293 }
1290 1294
1291skip_chk: 1295skip_chk:
1292 spin_unlock(&(image->lock)); 1296 spin_unlock(&image->lock);
1293 1297
1294 return retval; 1298 return retval;
1295} 1299}
1296 1300
1297 1301
1298ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf, 1302static ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf,
1299 size_t count, loff_t offset) 1303 size_t count, loff_t offset)
1300{ 1304{
1301 int retval = 0, enabled; 1305 int retval = 0, enabled;
@@ -1312,7 +1316,7 @@ ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf,
1312 1316
1313 bridge = tsi148_bridge->driver_priv; 1317 bridge = tsi148_bridge->driver_priv;
1314 1318
1315 spin_lock(&(image->lock)); 1319 spin_lock(&image->lock);
1316 1320
1317 memcpy_toio(image->kern_base + offset, buf, (unsigned int)count); 1321 memcpy_toio(image->kern_base + offset, buf, (unsigned int)count);
1318 retval = count; 1322 retval = count;
@@ -1352,7 +1356,7 @@ ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf,
1352 } 1356 }
1353 1357
1354skip_chk: 1358skip_chk:
1355 spin_unlock(&(image->lock)); 1359 spin_unlock(&image->lock);
1356 1360
1357 return retval; 1361 return retval;
1358} 1362}
@@ -1362,7 +1366,7 @@ skip_chk:
1362 * 1366 *
1363 * Requires a previously configured master window, returns final value. 1367 * Requires a previously configured master window, returns final value.
1364 */ 1368 */
1365unsigned int tsi148_master_rmw(struct vme_master_resource *image, 1369static unsigned int tsi148_master_rmw(struct vme_master_resource *image,
1366 unsigned int mask, unsigned int compare, unsigned int swap, 1370 unsigned int mask, unsigned int compare, unsigned int swap,
1367 loff_t offset) 1371 loff_t offset)
1368{ 1372{
@@ -1378,10 +1382,10 @@ unsigned int tsi148_master_rmw(struct vme_master_resource *image,
1378 i = image->number; 1382 i = image->number;
1379 1383
1380 /* Locking as we can only do one of these at a time */ 1384 /* Locking as we can only do one of these at a time */
1381 mutex_lock(&(bridge->vme_rmw)); 1385 mutex_lock(&bridge->vme_rmw);
1382 1386
1383 /* Lock image */ 1387 /* Lock image */
1384 spin_lock(&(image->lock)); 1388 spin_lock(&image->lock);
1385 1389
1386 pci_addr_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] + 1390 pci_addr_high = ioread32be(bridge->base + TSI148_LCSR_OT[i] +
1387 TSI148_LCSR_OFFSET_OTSAU); 1391 TSI148_LCSR_OFFSET_OTSAU);
@@ -1411,9 +1415,9 @@ unsigned int tsi148_master_rmw(struct vme_master_resource *image,
1411 tmp &= ~TSI148_LCSR_VMCTRL_RMWEN; 1415 tmp &= ~TSI148_LCSR_VMCTRL_RMWEN;
1412 iowrite32be(tmp, bridge->base + TSI148_LCSR_VMCTRL); 1416 iowrite32be(tmp, bridge->base + TSI148_LCSR_VMCTRL);
1413 1417
1414 spin_unlock(&(image->lock)); 1418 spin_unlock(&image->lock);
1415 1419
1416 mutex_unlock(&(bridge->vme_rmw)); 1420 mutex_unlock(&bridge->vme_rmw);
1417 1421
1418 return result; 1422 return result;
1419} 1423}
@@ -1609,8 +1613,8 @@ static int tsi148_dma_set_vme_dest_attributes(struct device *dev, u32 *attr,
1609/* 1613/*
1610 * Add a link list descriptor to the list 1614 * Add a link list descriptor to the list
1611 */ 1615 */
1612int tsi148_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src, 1616static int tsi148_dma_list_add(struct vme_dma_list *list,
1613 struct vme_dma_attr *dest, size_t count) 1617 struct vme_dma_attr *src, struct vme_dma_attr *dest, size_t count)
1614{ 1618{
1615 struct tsi148_dma_entry *entry, *prev; 1619 struct tsi148_dma_entry *entry, *prev;
1616 u32 address_high, address_low; 1620 u32 address_high, address_low;
@@ -1633,10 +1637,10 @@ int tsi148_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
1633 } 1637 }
1634 1638
1635 /* Test descriptor alignment */ 1639 /* Test descriptor alignment */
1636 if ((unsigned long)&(entry->descriptor) & 0x7) { 1640 if ((unsigned long)&entry->descriptor & 0x7) {
1637 dev_err(tsi148_bridge->parent, "Descriptor not aligned to 8 " 1641 dev_err(tsi148_bridge->parent, "Descriptor not aligned to 8 "
1638 "byte boundary as required: %p\n", 1642 "byte boundary as required: %p\n",
1639 &(entry->descriptor)); 1643 &entry->descriptor);
1640 retval = -EINVAL; 1644 retval = -EINVAL;
1641 goto err_align; 1645 goto err_align;
1642 } 1646 }
@@ -1644,7 +1648,7 @@ int tsi148_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
1644 /* Given we are going to fill out the structure, we probably don't 1648 /* Given we are going to fill out the structure, we probably don't
1645 * need to zero it, but better safe than sorry for now. 1649 * need to zero it, but better safe than sorry for now.
1646 */ 1650 */
1647 memset(&(entry->descriptor), 0, sizeof(struct tsi148_dma_descriptor)); 1651 memset(&entry->descriptor, 0, sizeof(struct tsi148_dma_descriptor));
1648 1652
1649 /* Fill out source part */ 1653 /* Fill out source part */
1650 switch (src->type) { 1654 switch (src->type) {
@@ -1681,7 +1685,7 @@ int tsi148_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
1681 entry->descriptor.dsat = TSI148_LCSR_DSAT_TYP_VME; 1685 entry->descriptor.dsat = TSI148_LCSR_DSAT_TYP_VME;
1682 1686
1683 retval = tsi148_dma_set_vme_src_attributes( 1687 retval = tsi148_dma_set_vme_src_attributes(
1684 tsi148_bridge->parent, &(entry->descriptor.dsat), 1688 tsi148_bridge->parent, &entry->descriptor.dsat,
1685 vme_attr->aspace, vme_attr->cycle, vme_attr->dwidth); 1689 vme_attr->aspace, vme_attr->cycle, vme_attr->dwidth);
1686 if (retval < 0) 1690 if (retval < 0)
1687 goto err_source; 1691 goto err_source;
@@ -1719,7 +1723,7 @@ int tsi148_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
1719 entry->descriptor.ddat = TSI148_LCSR_DDAT_TYP_VME; 1723 entry->descriptor.ddat = TSI148_LCSR_DDAT_TYP_VME;
1720 1724
1721 retval = tsi148_dma_set_vme_dest_attributes( 1725 retval = tsi148_dma_set_vme_dest_attributes(
1722 tsi148_bridge->parent, &(entry->descriptor.ddat), 1726 tsi148_bridge->parent, &entry->descriptor.ddat,
1723 vme_attr->aspace, vme_attr->cycle, vme_attr->dwidth); 1727 vme_attr->aspace, vme_attr->cycle, vme_attr->dwidth);
1724 if (retval < 0) 1728 if (retval < 0)
1725 goto err_dest; 1729 goto err_dest;
@@ -1735,16 +1739,16 @@ int tsi148_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
1735 entry->descriptor.dcnt = (u32)count; 1739 entry->descriptor.dcnt = (u32)count;
1736 1740
1737 /* Add to list */ 1741 /* Add to list */
1738 list_add_tail(&(entry->list), &(list->entries)); 1742 list_add_tail(&entry->list, &list->entries);
1739 1743
1740 /* Fill out previous descriptors "Next Address" */ 1744 /* Fill out previous descriptors "Next Address" */
1741 if (entry->list.prev != &(list->entries)) { 1745 if (entry->list.prev != &list->entries) {
1742 prev = list_entry(entry->list.prev, struct tsi148_dma_entry, 1746 prev = list_entry(entry->list.prev, struct tsi148_dma_entry,
1743 list); 1747 list);
1744 /* We need the bus address for the pointer */ 1748 /* We need the bus address for the pointer */
1745 desc_ptr = virt_to_bus(&(entry->descriptor)); 1749 desc_ptr = virt_to_bus(&entry->descriptor);
1746 reg_split(desc_ptr, &(prev->descriptor.dnlau), 1750 reg_split(desc_ptr, &prev->descriptor.dnlau,
1747 &(prev->descriptor.dnlal)); 1751 &prev->descriptor.dnlal);
1748 } 1752 }
1749 1753
1750 return 0; 1754 return 0;
@@ -1782,7 +1786,7 @@ static int tsi148_dma_busy(struct vme_bridge *tsi148_bridge, int channel)
1782 * 1786 *
1783 * XXX Need to provide control register configuration. 1787 * XXX Need to provide control register configuration.
1784 */ 1788 */
1785int tsi148_dma_list_exec(struct vme_dma_list *list) 1789static int tsi148_dma_list_exec(struct vme_dma_list *list)
1786{ 1790{
1787 struct vme_dma_resource *ctrlr; 1791 struct vme_dma_resource *ctrlr;
1788 int channel, retval = 0; 1792 int channel, retval = 0;
@@ -1799,30 +1803,30 @@ int tsi148_dma_list_exec(struct vme_dma_list *list)
1799 1803
1800 bridge = tsi148_bridge->driver_priv; 1804 bridge = tsi148_bridge->driver_priv;
1801 1805
1802 mutex_lock(&(ctrlr->mtx)); 1806 mutex_lock(&ctrlr->mtx);
1803 1807
1804 channel = ctrlr->number; 1808 channel = ctrlr->number;
1805 1809
1806 if (!list_empty(&(ctrlr->running))) { 1810 if (!list_empty(&ctrlr->running)) {
1807 /* 1811 /*
1808 * XXX We have an active DMA transfer and currently haven't 1812 * XXX We have an active DMA transfer and currently haven't
1809 * sorted out the mechanism for "pending" DMA transfers. 1813 * sorted out the mechanism for "pending" DMA transfers.
1810 * Return busy. 1814 * Return busy.
1811 */ 1815 */
1812 /* Need to add to pending here */ 1816 /* Need to add to pending here */
1813 mutex_unlock(&(ctrlr->mtx)); 1817 mutex_unlock(&ctrlr->mtx);
1814 return -EBUSY; 1818 return -EBUSY;
1815 } else { 1819 } else {
1816 list_add(&(list->list), &(ctrlr->running)); 1820 list_add(&list->list, &ctrlr->running);
1817 } 1821 }
1818 1822
1819 /* Get first bus address and write into registers */ 1823 /* Get first bus address and write into registers */
1820 entry = list_first_entry(&(list->entries), struct tsi148_dma_entry, 1824 entry = list_first_entry(&list->entries, struct tsi148_dma_entry,
1821 list); 1825 list);
1822 1826
1823 bus_addr = virt_to_bus(&(entry->descriptor)); 1827 bus_addr = virt_to_bus(&entry->descriptor);
1824 1828
1825 mutex_unlock(&(ctrlr->mtx)); 1829 mutex_unlock(&ctrlr->mtx);
1826 1830
1827 reg_split(bus_addr, &bus_addr_high, &bus_addr_low); 1831 reg_split(bus_addr, &bus_addr_high, &bus_addr_low);
1828 1832
@@ -1850,9 +1854,9 @@ int tsi148_dma_list_exec(struct vme_dma_list *list)
1850 } 1854 }
1851 1855
1852 /* Remove list from running list */ 1856 /* Remove list from running list */
1853 mutex_lock(&(ctrlr->mtx)); 1857 mutex_lock(&ctrlr->mtx);
1854 list_del(&(list->list)); 1858 list_del(&list->list);
1855 mutex_unlock(&(ctrlr->mtx)); 1859 mutex_unlock(&ctrlr->mtx);
1856 1860
1857 return retval; 1861 return retval;
1858} 1862}
@@ -1862,13 +1866,13 @@ int tsi148_dma_list_exec(struct vme_dma_list *list)
1862 * 1866 *
1863 * We have a separate function, don't assume that the chain can't be reused. 1867 * We have a separate function, don't assume that the chain can't be reused.
1864 */ 1868 */
1865int tsi148_dma_list_empty(struct vme_dma_list *list) 1869static int tsi148_dma_list_empty(struct vme_dma_list *list)
1866{ 1870{
1867 struct list_head *pos, *temp; 1871 struct list_head *pos, *temp;
1868 struct tsi148_dma_entry *entry; 1872 struct tsi148_dma_entry *entry;
1869 1873
1870 /* detach and free each entry */ 1874 /* detach and free each entry */
1871 list_for_each_safe(pos, temp, &(list->entries)) { 1875 list_for_each_safe(pos, temp, &list->entries) {
1872 list_del(pos); 1876 list_del(pos);
1873 entry = list_entry(pos, struct tsi148_dma_entry, list); 1877 entry = list_entry(pos, struct tsi148_dma_entry, list);
1874 kfree(entry); 1878 kfree(entry);
@@ -1884,7 +1888,7 @@ int tsi148_dma_list_empty(struct vme_dma_list *list)
1884 * This does not enable the LM monitor - that should be done when the first 1888 * This does not enable the LM monitor - that should be done when the first
1885 * callback is attached and disabled when the last callback is removed. 1889 * callback is attached and disabled when the last callback is removed.
1886 */ 1890 */
1887int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base, 1891static int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1888 vme_address_t aspace, vme_cycle_t cycle) 1892 vme_address_t aspace, vme_cycle_t cycle)
1889{ 1893{
1890 u32 lm_base_high, lm_base_low, lm_ctl = 0; 1894 u32 lm_base_high, lm_base_low, lm_ctl = 0;
@@ -1896,12 +1900,12 @@ int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1896 1900
1897 bridge = tsi148_bridge->driver_priv; 1901 bridge = tsi148_bridge->driver_priv;
1898 1902
1899 mutex_lock(&(lm->mtx)); 1903 mutex_lock(&lm->mtx);
1900 1904
1901 /* If we already have a callback attached, we can't move it! */ 1905 /* If we already have a callback attached, we can't move it! */
1902 for (i = 0; i < lm->monitors; i++) { 1906 for (i = 0; i < lm->monitors; i++) {
1903 if (bridge->lm_callback[i] != NULL) { 1907 if (bridge->lm_callback[i] != NULL) {
1904 mutex_unlock(&(lm->mtx)); 1908 mutex_unlock(&lm->mtx);
1905 dev_err(tsi148_bridge->parent, "Location monitor " 1909 dev_err(tsi148_bridge->parent, "Location monitor "
1906 "callback attached, can't reset\n"); 1910 "callback attached, can't reset\n");
1907 return -EBUSY; 1911 return -EBUSY;
@@ -1922,7 +1926,7 @@ int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1922 lm_ctl |= TSI148_LCSR_LMAT_AS_A64; 1926 lm_ctl |= TSI148_LCSR_LMAT_AS_A64;
1923 break; 1927 break;
1924 default: 1928 default:
1925 mutex_unlock(&(lm->mtx)); 1929 mutex_unlock(&lm->mtx);
1926 dev_err(tsi148_bridge->parent, "Invalid address space\n"); 1930 dev_err(tsi148_bridge->parent, "Invalid address space\n");
1927 return -EINVAL; 1931 return -EINVAL;
1928 break; 1932 break;
@@ -1943,7 +1947,7 @@ int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1943 iowrite32be(lm_base_low, bridge->base + TSI148_LCSR_LMBAL); 1947 iowrite32be(lm_base_low, bridge->base + TSI148_LCSR_LMBAL);
1944 iowrite32be(lm_ctl, bridge->base + TSI148_LCSR_LMAT); 1948 iowrite32be(lm_ctl, bridge->base + TSI148_LCSR_LMAT);
1945 1949
1946 mutex_unlock(&(lm->mtx)); 1950 mutex_unlock(&lm->mtx);
1947 1951
1948 return 0; 1952 return 0;
1949} 1953}
@@ -1951,15 +1955,15 @@ int tsi148_lm_set(struct vme_lm_resource *lm, unsigned long long lm_base,
1951/* Get configuration of the callback monitor and return whether it is enabled 1955/* Get configuration of the callback monitor and return whether it is enabled
1952 * or disabled. 1956 * or disabled.
1953 */ 1957 */
1954int tsi148_lm_get(struct vme_lm_resource *lm, unsigned long long *lm_base, 1958static int tsi148_lm_get(struct vme_lm_resource *lm,
1955 vme_address_t *aspace, vme_cycle_t *cycle) 1959 unsigned long long *lm_base, vme_address_t *aspace, vme_cycle_t *cycle)
1956{ 1960{
1957 u32 lm_base_high, lm_base_low, lm_ctl, enabled = 0; 1961 u32 lm_base_high, lm_base_low, lm_ctl, enabled = 0;
1958 struct tsi148_driver *bridge; 1962 struct tsi148_driver *bridge;
1959 1963
1960 bridge = lm->parent->driver_priv; 1964 bridge = lm->parent->driver_priv;
1961 1965
1962 mutex_lock(&(lm->mtx)); 1966 mutex_lock(&lm->mtx);
1963 1967
1964 lm_base_high = ioread32be(bridge->base + TSI148_LCSR_LMBAU); 1968 lm_base_high = ioread32be(bridge->base + TSI148_LCSR_LMBAU);
1965 lm_base_low = ioread32be(bridge->base + TSI148_LCSR_LMBAL); 1969 lm_base_low = ioread32be(bridge->base + TSI148_LCSR_LMBAL);
@@ -1992,7 +1996,7 @@ int tsi148_lm_get(struct vme_lm_resource *lm, unsigned long long *lm_base,
1992 if (lm_ctl & TSI148_LCSR_LMAT_DATA) 1996 if (lm_ctl & TSI148_LCSR_LMAT_DATA)
1993 *cycle |= VME_DATA; 1997 *cycle |= VME_DATA;
1994 1998
1995 mutex_unlock(&(lm->mtx)); 1999 mutex_unlock(&lm->mtx);
1996 2000
1997 return enabled; 2001 return enabled;
1998} 2002}
@@ -2002,7 +2006,7 @@ int tsi148_lm_get(struct vme_lm_resource *lm, unsigned long long *lm_base,
2002 * 2006 *
2003 * Callback will be passed the monitor triggered. 2007 * Callback will be passed the monitor triggered.
2004 */ 2008 */
2005int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor, 2009static int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor,
2006 void (*callback)(int)) 2010 void (*callback)(int))
2007{ 2011{
2008 u32 lm_ctl, tmp; 2012 u32 lm_ctl, tmp;
@@ -2013,12 +2017,12 @@ int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor,
2013 2017
2014 bridge = tsi148_bridge->driver_priv; 2018 bridge = tsi148_bridge->driver_priv;
2015 2019
2016 mutex_lock(&(lm->mtx)); 2020 mutex_lock(&lm->mtx);
2017 2021
2018 /* Ensure that the location monitor is configured - need PGM or DATA */ 2022 /* Ensure that the location monitor is configured - need PGM or DATA */
2019 lm_ctl = ioread32be(bridge->base + TSI148_LCSR_LMAT); 2023 lm_ctl = ioread32be(bridge->base + TSI148_LCSR_LMAT);
2020 if ((lm_ctl & (TSI148_LCSR_LMAT_PGM | TSI148_LCSR_LMAT_DATA)) == 0) { 2024 if ((lm_ctl & (TSI148_LCSR_LMAT_PGM | TSI148_LCSR_LMAT_DATA)) == 0) {
2021 mutex_unlock(&(lm->mtx)); 2025 mutex_unlock(&lm->mtx);
2022 dev_err(tsi148_bridge->parent, "Location monitor not properly " 2026 dev_err(tsi148_bridge->parent, "Location monitor not properly "
2023 "configured\n"); 2027 "configured\n");
2024 return -EINVAL; 2028 return -EINVAL;
@@ -2026,7 +2030,7 @@ int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor,
2026 2030
2027 /* Check that a callback isn't already attached */ 2031 /* Check that a callback isn't already attached */
2028 if (bridge->lm_callback[monitor] != NULL) { 2032 if (bridge->lm_callback[monitor] != NULL) {
2029 mutex_unlock(&(lm->mtx)); 2033 mutex_unlock(&lm->mtx);
2030 dev_err(tsi148_bridge->parent, "Existing callback attached\n"); 2034 dev_err(tsi148_bridge->parent, "Existing callback attached\n");
2031 return -EBUSY; 2035 return -EBUSY;
2032 } 2036 }
@@ -2049,7 +2053,7 @@ int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor,
2049 iowrite32be(lm_ctl, bridge->base + TSI148_LCSR_LMAT); 2053 iowrite32be(lm_ctl, bridge->base + TSI148_LCSR_LMAT);
2050 } 2054 }
2051 2055
2052 mutex_unlock(&(lm->mtx)); 2056 mutex_unlock(&lm->mtx);
2053 2057
2054 return 0; 2058 return 0;
2055} 2059}
@@ -2057,14 +2061,14 @@ int tsi148_lm_attach(struct vme_lm_resource *lm, int monitor,
2057/* 2061/*
2058 * Detach a callback function forn a specific location monitor. 2062 * Detach a callback function forn a specific location monitor.
2059 */ 2063 */
2060int tsi148_lm_detach(struct vme_lm_resource *lm, int monitor) 2064static int tsi148_lm_detach(struct vme_lm_resource *lm, int monitor)
2061{ 2065{
2062 u32 lm_en, tmp; 2066 u32 lm_en, tmp;
2063 struct tsi148_driver *bridge; 2067 struct tsi148_driver *bridge;
2064 2068
2065 bridge = lm->parent->driver_priv; 2069 bridge = lm->parent->driver_priv;
2066 2070
2067 mutex_lock(&(lm->mtx)); 2071 mutex_lock(&lm->mtx);
2068 2072
2069 /* Disable Location Monitor and ensure previous interrupts are clear */ 2073 /* Disable Location Monitor and ensure previous interrupts are clear */
2070 lm_en = ioread32be(bridge->base + TSI148_LCSR_INTEN); 2074 lm_en = ioread32be(bridge->base + TSI148_LCSR_INTEN);
@@ -2089,7 +2093,7 @@ int tsi148_lm_detach(struct vme_lm_resource *lm, int monitor)
2089 iowrite32be(tmp, bridge->base + TSI148_LCSR_LMAT); 2093 iowrite32be(tmp, bridge->base + TSI148_LCSR_LMAT);
2090 } 2094 }
2091 2095
2092 mutex_unlock(&(lm->mtx)); 2096 mutex_unlock(&lm->mtx);
2093 2097
2094 return 0; 2098 return 0;
2095} 2099}
@@ -2097,7 +2101,7 @@ int tsi148_lm_detach(struct vme_lm_resource *lm, int monitor)
2097/* 2101/*
2098 * Determine Geographical Addressing 2102 * Determine Geographical Addressing
2099 */ 2103 */
2100int tsi148_slot_get(struct vme_bridge *tsi148_bridge) 2104static int tsi148_slot_get(struct vme_bridge *tsi148_bridge)
2101{ 2105{
2102 u32 slot = 0; 2106 u32 slot = 0;
2103 struct tsi148_driver *bridge; 2107 struct tsi148_driver *bridge;
@@ -2142,7 +2146,7 @@ static int tsi148_crcsr_init(struct vme_bridge *tsi148_bridge,
2142 2146
2143 /* Allocate mem for CR/CSR image */ 2147 /* Allocate mem for CR/CSR image */
2144 bridge->crcsr_kernel = pci_alloc_consistent(pdev, VME_CRCSR_BUF_SIZE, 2148 bridge->crcsr_kernel = pci_alloc_consistent(pdev, VME_CRCSR_BUF_SIZE,
2145 &(bridge->crcsr_bus)); 2149 &bridge->crcsr_bus);
2146 if (bridge->crcsr_kernel == NULL) { 2150 if (bridge->crcsr_kernel == NULL) {
2147 dev_err(tsi148_bridge->parent, "Failed to allocate memory for " 2151 dev_err(tsi148_bridge->parent, "Failed to allocate memory for "
2148 "CR/CSR image\n"); 2152 "CR/CSR image\n");
@@ -2280,13 +2284,13 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2280 } 2284 }
2281 2285
2282 /* Initialize wait queues & mutual exclusion flags */ 2286 /* Initialize wait queues & mutual exclusion flags */
2283 init_waitqueue_head(&(tsi148_device->dma_queue[0])); 2287 init_waitqueue_head(&tsi148_device->dma_queue[0]);
2284 init_waitqueue_head(&(tsi148_device->dma_queue[1])); 2288 init_waitqueue_head(&tsi148_device->dma_queue[1]);
2285 init_waitqueue_head(&(tsi148_device->iack_queue)); 2289 init_waitqueue_head(&tsi148_device->iack_queue);
2286 mutex_init(&(tsi148_device->vme_int)); 2290 mutex_init(&tsi148_device->vme_int);
2287 mutex_init(&(tsi148_device->vme_rmw)); 2291 mutex_init(&tsi148_device->vme_rmw);
2288 2292
2289 tsi148_bridge->parent = &(pdev->dev); 2293 tsi148_bridge->parent = &pdev->dev;
2290 strcpy(tsi148_bridge->name, driver_name); 2294 strcpy(tsi148_bridge->name, driver_name);
2291 2295
2292 /* Setup IRQ */ 2296 /* Setup IRQ */
@@ -2314,7 +2318,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2314 goto err_master; 2318 goto err_master;
2315 } 2319 }
2316 tsi148_device->flush_image->parent = tsi148_bridge; 2320 tsi148_device->flush_image->parent = tsi148_bridge;
2317 spin_lock_init(&(tsi148_device->flush_image->lock)); 2321 spin_lock_init(&tsi148_device->flush_image->lock);
2318 tsi148_device->flush_image->locked = 1; 2322 tsi148_device->flush_image->locked = 1;
2319 tsi148_device->flush_image->number = master_num; 2323 tsi148_device->flush_image->number = master_num;
2320 tsi148_device->flush_image->address_attr = VME_A16 | VME_A24 | 2324 tsi148_device->flush_image->address_attr = VME_A16 | VME_A24 |
@@ -2324,13 +2328,13 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2324 VME_2eSST160 | VME_2eSST267 | VME_2eSST320 | VME_SUPER | 2328 VME_2eSST160 | VME_2eSST267 | VME_2eSST320 | VME_SUPER |
2325 VME_USER | VME_PROG | VME_DATA; 2329 VME_USER | VME_PROG | VME_DATA;
2326 tsi148_device->flush_image->width_attr = VME_D16 | VME_D32; 2330 tsi148_device->flush_image->width_attr = VME_D16 | VME_D32;
2327 memset(&(tsi148_device->flush_image->bus_resource), 0, 2331 memset(&tsi148_device->flush_image->bus_resource, 0,
2328 sizeof(struct resource)); 2332 sizeof(struct resource));
2329 tsi148_device->flush_image->kern_base = NULL; 2333 tsi148_device->flush_image->kern_base = NULL;
2330 } 2334 }
2331 2335
2332 /* Add master windows to list */ 2336 /* Add master windows to list */
2333 INIT_LIST_HEAD(&(tsi148_bridge->master_resources)); 2337 INIT_LIST_HEAD(&tsi148_bridge->master_resources);
2334 for (i = 0; i < master_num; i++) { 2338 for (i = 0; i < master_num; i++) {
2335 master_image = kmalloc(sizeof(struct vme_master_resource), 2339 master_image = kmalloc(sizeof(struct vme_master_resource),
2336 GFP_KERNEL); 2340 GFP_KERNEL);
@@ -2341,7 +2345,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2341 goto err_master; 2345 goto err_master;
2342 } 2346 }
2343 master_image->parent = tsi148_bridge; 2347 master_image->parent = tsi148_bridge;
2344 spin_lock_init(&(master_image->lock)); 2348 spin_lock_init(&master_image->lock);
2345 master_image->locked = 0; 2349 master_image->locked = 0;
2346 master_image->number = i; 2350 master_image->number = i;
2347 master_image->address_attr = VME_A16 | VME_A24 | VME_A32 | 2351 master_image->address_attr = VME_A16 | VME_A24 | VME_A32 |
@@ -2351,15 +2355,15 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2351 VME_2eSST267 | VME_2eSST320 | VME_SUPER | VME_USER | 2355 VME_2eSST267 | VME_2eSST320 | VME_SUPER | VME_USER |
2352 VME_PROG | VME_DATA; 2356 VME_PROG | VME_DATA;
2353 master_image->width_attr = VME_D16 | VME_D32; 2357 master_image->width_attr = VME_D16 | VME_D32;
2354 memset(&(master_image->bus_resource), 0, 2358 memset(&master_image->bus_resource, 0,
2355 sizeof(struct resource)); 2359 sizeof(struct resource));
2356 master_image->kern_base = NULL; 2360 master_image->kern_base = NULL;
2357 list_add_tail(&(master_image->list), 2361 list_add_tail(&master_image->list,
2358 &(tsi148_bridge->master_resources)); 2362 &tsi148_bridge->master_resources);
2359 } 2363 }
2360 2364
2361 /* Add slave windows to list */ 2365 /* Add slave windows to list */
2362 INIT_LIST_HEAD(&(tsi148_bridge->slave_resources)); 2366 INIT_LIST_HEAD(&tsi148_bridge->slave_resources);
2363 for (i = 0; i < TSI148_MAX_SLAVE; i++) { 2367 for (i = 0; i < TSI148_MAX_SLAVE; i++) {
2364 slave_image = kmalloc(sizeof(struct vme_slave_resource), 2368 slave_image = kmalloc(sizeof(struct vme_slave_resource),
2365 GFP_KERNEL); 2369 GFP_KERNEL);
@@ -2370,7 +2374,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2370 goto err_slave; 2374 goto err_slave;
2371 } 2375 }
2372 slave_image->parent = tsi148_bridge; 2376 slave_image->parent = tsi148_bridge;
2373 mutex_init(&(slave_image->mtx)); 2377 mutex_init(&slave_image->mtx);
2374 slave_image->locked = 0; 2378 slave_image->locked = 0;
2375 slave_image->number = i; 2379 slave_image->number = i;
2376 slave_image->address_attr = VME_A16 | VME_A24 | VME_A32 | 2380 slave_image->address_attr = VME_A16 | VME_A24 | VME_A32 |
@@ -2380,12 +2384,12 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2380 VME_2eVME | VME_2eSST | VME_2eSSTB | VME_2eSST160 | 2384 VME_2eVME | VME_2eSST | VME_2eSSTB | VME_2eSST160 |
2381 VME_2eSST267 | VME_2eSST320 | VME_SUPER | VME_USER | 2385 VME_2eSST267 | VME_2eSST320 | VME_SUPER | VME_USER |
2382 VME_PROG | VME_DATA; 2386 VME_PROG | VME_DATA;
2383 list_add_tail(&(slave_image->list), 2387 list_add_tail(&slave_image->list,
2384 &(tsi148_bridge->slave_resources)); 2388 &tsi148_bridge->slave_resources);
2385 } 2389 }
2386 2390
2387 /* Add dma engines to list */ 2391 /* Add dma engines to list */
2388 INIT_LIST_HEAD(&(tsi148_bridge->dma_resources)); 2392 INIT_LIST_HEAD(&tsi148_bridge->dma_resources);
2389 for (i = 0; i < TSI148_MAX_DMA; i++) { 2393 for (i = 0; i < TSI148_MAX_DMA; i++) {
2390 dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource), 2394 dma_ctrlr = kmalloc(sizeof(struct vme_dma_resource),
2391 GFP_KERNEL); 2395 GFP_KERNEL);
@@ -2396,21 +2400,21 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2396 goto err_dma; 2400 goto err_dma;
2397 } 2401 }
2398 dma_ctrlr->parent = tsi148_bridge; 2402 dma_ctrlr->parent = tsi148_bridge;
2399 mutex_init(&(dma_ctrlr->mtx)); 2403 mutex_init(&dma_ctrlr->mtx);
2400 dma_ctrlr->locked = 0; 2404 dma_ctrlr->locked = 0;
2401 dma_ctrlr->number = i; 2405 dma_ctrlr->number = i;
2402 dma_ctrlr->route_attr = VME_DMA_VME_TO_MEM | 2406 dma_ctrlr->route_attr = VME_DMA_VME_TO_MEM |
2403 VME_DMA_MEM_TO_VME | VME_DMA_VME_TO_VME | 2407 VME_DMA_MEM_TO_VME | VME_DMA_VME_TO_VME |
2404 VME_DMA_MEM_TO_MEM | VME_DMA_PATTERN_TO_VME | 2408 VME_DMA_MEM_TO_MEM | VME_DMA_PATTERN_TO_VME |
2405 VME_DMA_PATTERN_TO_MEM; 2409 VME_DMA_PATTERN_TO_MEM;
2406 INIT_LIST_HEAD(&(dma_ctrlr->pending)); 2410 INIT_LIST_HEAD(&dma_ctrlr->pending);
2407 INIT_LIST_HEAD(&(dma_ctrlr->running)); 2411 INIT_LIST_HEAD(&dma_ctrlr->running);
2408 list_add_tail(&(dma_ctrlr->list), 2412 list_add_tail(&dma_ctrlr->list,
2409 &(tsi148_bridge->dma_resources)); 2413 &tsi148_bridge->dma_resources);
2410 } 2414 }
2411 2415
2412 /* Add location monitor to list */ 2416 /* Add location monitor to list */
2413 INIT_LIST_HEAD(&(tsi148_bridge->lm_resources)); 2417 INIT_LIST_HEAD(&tsi148_bridge->lm_resources);
2414 lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL); 2418 lm = kmalloc(sizeof(struct vme_lm_resource), GFP_KERNEL);
2415 if (lm == NULL) { 2419 if (lm == NULL) {
2416 dev_err(&pdev->dev, "Failed to allocate memory for " 2420 dev_err(&pdev->dev, "Failed to allocate memory for "
@@ -2419,11 +2423,11 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2419 goto err_lm; 2423 goto err_lm;
2420 } 2424 }
2421 lm->parent = tsi148_bridge; 2425 lm->parent = tsi148_bridge;
2422 mutex_init(&(lm->mtx)); 2426 mutex_init(&lm->mtx);
2423 lm->locked = 0; 2427 lm->locked = 0;
2424 lm->number = 1; 2428 lm->number = 1;
2425 lm->monitors = 4; 2429 lm->monitors = 4;
2426 list_add_tail(&(lm->list), &(tsi148_bridge->lm_resources)); 2430 list_add_tail(&lm->list, &tsi148_bridge->lm_resources);
2427 2431
2428 tsi148_bridge->slave_get = tsi148_slave_get; 2432 tsi148_bridge->slave_get = tsi148_slave_get;
2429 tsi148_bridge->slave_set = tsi148_slave_set; 2433 tsi148_bridge->slave_set = tsi148_slave_set;
@@ -2477,41 +2481,40 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2477 2481
2478 return 0; 2482 return 0;
2479 2483
2480 vme_unregister_bridge(tsi148_bridge);
2481err_reg: 2484err_reg:
2482 tsi148_crcsr_exit(tsi148_bridge, pdev); 2485 tsi148_crcsr_exit(tsi148_bridge, pdev);
2483err_crcsr: 2486err_crcsr:
2484err_lm: 2487err_lm:
2485 /* resources are stored in link list */ 2488 /* resources are stored in link list */
2486 list_for_each(pos, &(tsi148_bridge->lm_resources)) { 2489 list_for_each(pos, &tsi148_bridge->lm_resources) {
2487 lm = list_entry(pos, struct vme_lm_resource, list); 2490 lm = list_entry(pos, struct vme_lm_resource, list);
2488 list_del(pos); 2491 list_del(pos);
2489 kfree(lm); 2492 kfree(lm);
2490 } 2493 }
2491err_dma: 2494err_dma:
2492 /* resources are stored in link list */ 2495 /* resources are stored in link list */
2493 list_for_each(pos, &(tsi148_bridge->dma_resources)) { 2496 list_for_each(pos, &tsi148_bridge->dma_resources) {
2494 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list); 2497 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
2495 list_del(pos); 2498 list_del(pos);
2496 kfree(dma_ctrlr); 2499 kfree(dma_ctrlr);
2497 } 2500 }
2498err_slave: 2501err_slave:
2499 /* resources are stored in link list */ 2502 /* resources are stored in link list */
2500 list_for_each(pos, &(tsi148_bridge->slave_resources)) { 2503 list_for_each(pos, &tsi148_bridge->slave_resources) {
2501 slave_image = list_entry(pos, struct vme_slave_resource, list); 2504 slave_image = list_entry(pos, struct vme_slave_resource, list);
2502 list_del(pos); 2505 list_del(pos);
2503 kfree(slave_image); 2506 kfree(slave_image);
2504 } 2507 }
2505err_master: 2508err_master:
2506 /* resources are stored in link list */ 2509 /* resources are stored in link list */
2507 list_for_each(pos, &(tsi148_bridge->master_resources)) { 2510 list_for_each(pos, &tsi148_bridge->master_resources) {
2508 master_image = list_entry(pos, struct vme_master_resource, 2511 master_image = list_entry(pos, struct vme_master_resource,
2509 list); 2512 list);
2510 list_del(pos); 2513 list_del(pos);
2511 kfree(master_image); 2514 kfree(master_image);
2512 } 2515 }
2513 2516
2514 tsi148_irq_exit(tsi148_device, pdev); 2517 tsi148_irq_exit(tsi148_bridge, pdev);
2515err_irq: 2518err_irq:
2516err_test: 2519err_test:
2517 iounmap(tsi148_device->base); 2520 iounmap(tsi148_device->base);
@@ -2531,6 +2534,7 @@ err_struct:
2531static void tsi148_remove(struct pci_dev *pdev) 2534static void tsi148_remove(struct pci_dev *pdev)
2532{ 2535{
2533 struct list_head *pos = NULL; 2536 struct list_head *pos = NULL;
2537 struct list_head *tmplist;
2534 struct vme_master_resource *master_image; 2538 struct vme_master_resource *master_image;
2535 struct vme_slave_resource *slave_image; 2539 struct vme_slave_resource *slave_image;
2536 struct vme_dma_resource *dma_ctrlr; 2540 struct vme_dma_resource *dma_ctrlr;
@@ -2582,36 +2586,34 @@ static void tsi148_remove(struct pci_dev *pdev)
2582 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTM1); 2586 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTM1);
2583 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTM2); 2587 iowrite32be(0x0, bridge->base + TSI148_LCSR_INTM2);
2584 2588
2585 tsi148_irq_exit(bridge, pdev); 2589 tsi148_irq_exit(tsi148_bridge, pdev);
2586 2590
2587 vme_unregister_bridge(tsi148_bridge); 2591 vme_unregister_bridge(tsi148_bridge);
2588 2592
2589 tsi148_crcsr_exit(tsi148_bridge, pdev); 2593 tsi148_crcsr_exit(tsi148_bridge, pdev);
2590 2594
2591 /* resources are stored in link list */ 2595 /* resources are stored in link list */
2592 list_for_each(pos, &(tsi148_bridge->dma_resources)) { 2596 list_for_each_safe(pos, tmplist, &tsi148_bridge->dma_resources) {
2593 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list); 2597 dma_ctrlr = list_entry(pos, struct vme_dma_resource, list);
2594 list_del(pos); 2598 list_del(pos);
2595 kfree(dma_ctrlr); 2599 kfree(dma_ctrlr);
2596 } 2600 }
2597 2601
2598 /* resources are stored in link list */ 2602 /* resources are stored in link list */
2599 list_for_each(pos, &(tsi148_bridge->slave_resources)) { 2603 list_for_each_safe(pos, tmplist, &tsi148_bridge->slave_resources) {
2600 slave_image = list_entry(pos, struct vme_slave_resource, list); 2604 slave_image = list_entry(pos, struct vme_slave_resource, list);
2601 list_del(pos); 2605 list_del(pos);
2602 kfree(slave_image); 2606 kfree(slave_image);
2603 } 2607 }
2604 2608
2605 /* resources are stored in link list */ 2609 /* resources are stored in link list */
2606 list_for_each(pos, &(tsi148_bridge->master_resources)) { 2610 list_for_each_safe(pos, tmplist, &tsi148_bridge->master_resources) {
2607 master_image = list_entry(pos, struct vme_master_resource, 2611 master_image = list_entry(pos, struct vme_master_resource,
2608 list); 2612 list);
2609 list_del(pos); 2613 list_del(pos);
2610 kfree(master_image); 2614 kfree(master_image);
2611 } 2615 }
2612 2616
2613 tsi148_irq_exit(bridge, pdev);
2614
2615 iounmap(bridge->base); 2617 iounmap(bridge->base);
2616 2618
2617 pci_release_regions(pdev); 2619 pci_release_regions(pdev);
diff --git a/drivers/staging/vme/bridges/vme_tsi148.h b/drivers/staging/vme/bridges/vme_tsi148.h
index bda64ef85754..9f97fa8084e8 100644
--- a/drivers/staging/vme/bridges/vme_tsi148.h
+++ b/drivers/staging/vme/bridges/vme_tsi148.h
@@ -35,7 +35,7 @@
35 35
36/* Structure used to hold driver specific information */ 36/* Structure used to hold driver specific information */
37struct tsi148_driver { 37struct tsi148_driver {
38 void *base; /* Base Address of device registers */ 38 void __iomem *base; /* Base Address of device registers */
39 wait_queue_head_t dma_queue[2]; 39 wait_queue_head_t dma_queue[2];
40 wait_queue_head_t iack_queue; 40 wait_queue_head_t iack_queue;
41 void (*lm_callback[4])(int); /* Called in interrupt handler */ 41 void (*lm_callback[4])(int); /* Called in interrupt handler */
diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
index 71bbc526626c..a571173249cf 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -44,7 +44,7 @@ static DEFINE_MUTEX(vme_user_mutex);
44static char driver_name[] = "vme_user"; 44static char driver_name[] = "vme_user";
45 45
46static int bus[USER_BUS_MAX]; 46static int bus[USER_BUS_MAX];
47static int bus_num; 47static unsigned int bus_num;
48 48
49/* Currently Documentation/devices.txt defines the following for VME: 49/* Currently Documentation/devices.txt defines the following for VME:
50 * 50 *
@@ -92,7 +92,7 @@ static int bus_num;
92 * Structure to handle image related parameters. 92 * Structure to handle image related parameters.
93 */ 93 */
94typedef struct { 94typedef struct {
95 void __iomem *kern_buf; /* Buffer address in kernel space */ 95 void *kern_buf; /* Buffer address in kernel space */
96 dma_addr_t pci_buf; /* Buffer address in PCI address space */ 96 dma_addr_t pci_buf; /* Buffer address in PCI address space */
97 unsigned long long size_buf; /* Buffer size */ 97 unsigned long long size_buf; /* Buffer size */
98 struct semaphore sem; /* Semaphore for locking image */ 98 struct semaphore sem; /* Semaphore for locking image */
@@ -114,9 +114,9 @@ typedef struct {
114} driver_stats_t; 114} driver_stats_t;
115static driver_stats_t statistics; 115static driver_stats_t statistics;
116 116
117struct cdev *vme_user_cdev; /* Character device */ 117static struct cdev *vme_user_cdev; /* Character device */
118struct class *vme_user_sysfs_class; /* Sysfs class */ 118static struct class *vme_user_sysfs_class; /* Sysfs class */
119struct device *vme_user_bridge; /* Pointer to the bridge device */ 119static struct device *vme_user_bridge; /* Pointer to bridge device */
120 120
121 121
122static const int type[VME_DEVS] = { MASTER_MINOR, MASTER_MINOR, 122static const int type[VME_DEVS] = { MASTER_MINOR, MASTER_MINOR,
@@ -129,13 +129,14 @@ static const int type[VME_DEVS] = { MASTER_MINOR, MASTER_MINOR,
129 129
130static int vme_user_open(struct inode *, struct file *); 130static int vme_user_open(struct inode *, struct file *);
131static int vme_user_release(struct inode *, struct file *); 131static int vme_user_release(struct inode *, struct file *);
132static ssize_t vme_user_read(struct file *, char *, size_t, loff_t *); 132static ssize_t vme_user_read(struct file *, char __user *, size_t, loff_t *);
133static ssize_t vme_user_write(struct file *, const char *, size_t, loff_t *); 133static ssize_t vme_user_write(struct file *, const char __user *, size_t,
134 loff_t *);
134static loff_t vme_user_llseek(struct file *, loff_t, int); 135static loff_t vme_user_llseek(struct file *, loff_t, int);
135static long vme_user_unlocked_ioctl(struct file *, unsigned int, unsigned long); 136static long vme_user_unlocked_ioctl(struct file *, unsigned int, unsigned long);
136 137
137static int __init vme_user_probe(struct device *, int, int); 138static int __devinit vme_user_probe(struct device *, int, int);
138static int __exit vme_user_remove(struct device *, int, int); 139static int __devexit vme_user_remove(struct device *, int, int);
139 140
140static struct file_operations vme_user_fops = { 141static struct file_operations vme_user_fops = {
141 .open = vme_user_open, 142 .open = vme_user_open,
@@ -246,7 +247,7 @@ static ssize_t resource_to_user(int minor, char __user *buf, size_t count,
246 * page) transfers will lock the user space buffer into memory and then 247 * page) transfers will lock the user space buffer into memory and then
247 * transfer the data directly from the user space buffers out to VME. 248 * transfer the data directly from the user space buffers out to VME.
248 */ 249 */
249static ssize_t resource_from_user(unsigned int minor, const char *buf, 250static ssize_t resource_from_user(unsigned int minor, const char __user *buf,
250 size_t count, loff_t *ppos) 251 size_t count, loff_t *ppos)
251{ 252{
252 ssize_t retval; 253 ssize_t retval;
@@ -277,7 +278,7 @@ static ssize_t resource_from_user(unsigned int minor, const char *buf,
277static ssize_t buffer_to_user(unsigned int minor, char __user *buf, 278static ssize_t buffer_to_user(unsigned int minor, char __user *buf,
278 size_t count, loff_t *ppos) 279 size_t count, loff_t *ppos)
279{ 280{
280 void __iomem *image_ptr; 281 void *image_ptr;
281 ssize_t retval; 282 ssize_t retval;
282 283
283 image_ptr = image[minor].kern_buf + *ppos; 284 image_ptr = image[minor].kern_buf + *ppos;
@@ -293,10 +294,10 @@ static ssize_t buffer_to_user(unsigned int minor, char __user *buf,
293 return retval; 294 return retval;
294} 295}
295 296
296static ssize_t buffer_from_user(unsigned int minor, const char *buf, 297static ssize_t buffer_from_user(unsigned int minor, const char __user *buf,
297 size_t count, loff_t *ppos) 298 size_t count, loff_t *ppos)
298{ 299{
299 void __iomem *image_ptr; 300 void *image_ptr;
300 size_t retval; 301 size_t retval;
301 302
302 image_ptr = image[minor].kern_buf + *ppos; 303 image_ptr = image[minor].kern_buf + *ppos;
@@ -312,7 +313,7 @@ static ssize_t buffer_from_user(unsigned int minor, const char *buf,
312 return retval; 313 return retval;
313} 314}
314 315
315static ssize_t vme_user_read(struct file *file, char *buf, size_t count, 316static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,
316 loff_t *ppos) 317 loff_t *ppos)
317{ 318{
318 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev); 319 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
@@ -356,8 +357,8 @@ static ssize_t vme_user_read(struct file *file, char *buf, size_t count,
356 return retval; 357 return retval;
357} 358}
358 359
359static ssize_t vme_user_write(struct file *file, const char *buf, size_t count, 360static ssize_t vme_user_write(struct file *file, const char __user *buf,
360 loff_t *ppos) 361 size_t count, loff_t *ppos)
361{ 362{
362 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev); 363 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
363 ssize_t retval; 364 ssize_t retval;
@@ -455,6 +456,7 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
455 unsigned int minor = MINOR(inode->i_rdev); 456 unsigned int minor = MINOR(inode->i_rdev);
456 int retval; 457 int retval;
457 dma_addr_t pci_addr; 458 dma_addr_t pci_addr;
459 void __user *argp = (void __user *)arg;
458 460
459 statistics.ioctls++; 461 statistics.ioctls++;
460 462
@@ -470,11 +472,11 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
470 * to userspace as they are 472 * to userspace as they are
471 */ 473 */
472 retval = vme_master_get(image[minor].resource, 474 retval = vme_master_get(image[minor].resource,
473 &(master.enable), &(master.vme_addr), 475 &master.enable, &master.vme_addr,
474 &(master.size), &(master.aspace), 476 &master.size, &master.aspace,
475 &(master.cycle), &(master.dwidth)); 477 &master.cycle, &master.dwidth);
476 478
477 copied = copy_to_user((char *)arg, &master, 479 copied = copy_to_user(argp, &master,
478 sizeof(struct vme_master)); 480 sizeof(struct vme_master));
479 if (copied != 0) { 481 if (copied != 0) {
480 printk(KERN_WARNING "Partial copy to " 482 printk(KERN_WARNING "Partial copy to "
@@ -487,8 +489,7 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
487 489
488 case VME_SET_MASTER: 490 case VME_SET_MASTER:
489 491
490 copied = copy_from_user(&master, (char *)arg, 492 copied = copy_from_user(&master, argp, sizeof(master));
491 sizeof(master));
492 if (copied != 0) { 493 if (copied != 0) {
493 printk(KERN_WARNING "Partial copy from " 494 printk(KERN_WARNING "Partial copy from "
494 "userspace\n"); 495 "userspace\n");
@@ -514,11 +515,11 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
514 * to userspace as they are 515 * to userspace as they are
515 */ 516 */
516 retval = vme_slave_get(image[minor].resource, 517 retval = vme_slave_get(image[minor].resource,
517 &(slave.enable), &(slave.vme_addr), 518 &slave.enable, &slave.vme_addr,
518 &(slave.size), &pci_addr, &(slave.aspace), 519 &slave.size, &pci_addr, &slave.aspace,
519 &(slave.cycle)); 520 &slave.cycle);
520 521
521 copied = copy_to_user((char *)arg, &slave, 522 copied = copy_to_user(argp, &slave,
522 sizeof(struct vme_slave)); 523 sizeof(struct vme_slave));
523 if (copied != 0) { 524 if (copied != 0) {
524 printk(KERN_WARNING "Partial copy to " 525 printk(KERN_WARNING "Partial copy to "
@@ -531,8 +532,7 @@ static int vme_user_ioctl(struct inode *inode, struct file *file,
531 532
532 case VME_SET_SLAVE: 533 case VME_SET_SLAVE:
533 534
534 copied = copy_from_user(&slave, (char *)arg, 535 copied = copy_from_user(&slave, argp, sizeof(slave));
535 sizeof(slave));
536 if (copied != 0) { 536 if (copied != 0) {
537 printk(KERN_WARNING "Partial copy from " 537 printk(KERN_WARNING "Partial copy from "
538 "userspace\n"); 538 "userspace\n");
@@ -596,7 +596,7 @@ static void buf_unalloc(int num)
596static struct vme_driver vme_user_driver = { 596static struct vme_driver vme_user_driver = {
597 .name = driver_name, 597 .name = driver_name,
598 .probe = vme_user_probe, 598 .probe = vme_user_probe,
599 .remove = vme_user_remove, 599 .remove = __devexit_p(vme_user_remove),
600}; 600};
601 601
602 602
@@ -611,6 +611,7 @@ static int __init vme_user_init(void)
611 if (bus_num == 0) { 611 if (bus_num == 0) {
612 printk(KERN_ERR "%s: No cards, skipping registration\n", 612 printk(KERN_ERR "%s: No cards, skipping registration\n",
613 driver_name); 613 driver_name);
614 retval = -ENODEV;
614 goto err_nocard; 615 goto err_nocard;
615 } 616 }
616 617
@@ -629,6 +630,7 @@ static int __init vme_user_init(void)
629 if (ids == NULL) { 630 if (ids == NULL) {
630 printk(KERN_ERR "%s: Unable to allocate ID table\n", 631 printk(KERN_ERR "%s: Unable to allocate ID table\n",
631 driver_name); 632 driver_name);
633 retval = -ENOMEM;
632 goto err_id; 634 goto err_id;
633 } 635 }
634 636
@@ -652,7 +654,6 @@ static int __init vme_user_init(void)
652 654
653 return retval; 655 return retval;
654 656
655 vme_unregister_driver(&vme_user_driver);
656err_reg: 657err_reg:
657 kfree(ids); 658 kfree(ids);
658err_id: 659err_id:
@@ -665,7 +666,8 @@ err_nocard:
665 * as practical. We will therefore reserve the buffers and request the images 666 * as practical. We will therefore reserve the buffers and request the images
666 * here so that we don't have to do it later. 667 * here so that we don't have to do it later.
667 */ 668 */
668static int __init vme_user_probe(struct device *dev, int cur_bus, int cur_slot) 669static int __devinit vme_user_probe(struct device *dev, int cur_bus,
670 int cur_slot)
669{ 671{
670 int i, err; 672 int i, err;
671 char name[12]; 673 char name[12];
@@ -683,7 +685,7 @@ static int __init vme_user_probe(struct device *dev, int cur_bus, int cur_slot)
683 for (i = 0; i < VME_DEVS; i++) { 685 for (i = 0; i < VME_DEVS; i++) {
684 image[i].kern_buf = NULL; 686 image[i].kern_buf = NULL;
685 image[i].pci_buf = 0; 687 image[i].pci_buf = 0;
686 sema_init(&(image[i].sem), 1); 688 sema_init(&image[i].sem, 1);
687 image[i].device = NULL; 689 image[i].device = NULL;
688 image[i].resource = NULL; 690 image[i].resource = NULL;
689 image[i].users = 0; 691 image[i].users = 0;
@@ -727,7 +729,7 @@ static int __init vme_user_probe(struct device *dev, int cur_bus, int cur_slot)
727 } 729 }
728 image[i].size_buf = PCI_BUF_SIZE; 730 image[i].size_buf = PCI_BUF_SIZE;
729 image[i].kern_buf = vme_alloc_consistent(image[i].resource, 731 image[i].kern_buf = vme_alloc_consistent(image[i].resource,
730 image[i].size_buf, &(image[i].pci_buf)); 732 image[i].size_buf, &image[i].pci_buf);
731 if (image[i].kern_buf == NULL) { 733 if (image[i].kern_buf == NULL) {
732 printk(KERN_WARNING "Unable to allocate memory for " 734 printk(KERN_WARNING "Unable to allocate memory for "
733 "buffer\n"); 735 "buffer\n");
@@ -828,8 +830,8 @@ err_master:
828err_slave: 830err_slave:
829 while (i > SLAVE_MINOR) { 831 while (i > SLAVE_MINOR) {
830 i--; 832 i--;
831 vme_slave_free(image[i].resource);
832 buf_unalloc(i); 833 buf_unalloc(i);
834 vme_slave_free(image[i].resource);
833 } 835 }
834err_class: 836err_class:
835 cdev_del(vme_user_cdev); 837 cdev_del(vme_user_cdev);
@@ -840,7 +842,8 @@ err_dev:
840 return err; 842 return err;
841} 843}
842 844
843static int __exit vme_user_remove(struct device *dev, int cur_bus, int cur_slot) 845static int __devexit vme_user_remove(struct device *dev, int cur_bus,
846 int cur_slot)
844{ 847{
845 int i; 848 int i;
846 849
@@ -849,13 +852,15 @@ static int __exit vme_user_remove(struct device *dev, int cur_bus, int cur_slot)
849 device_destroy(vme_user_sysfs_class, MKDEV(VME_MAJOR, i)); 852 device_destroy(vme_user_sysfs_class, MKDEV(VME_MAJOR, i));
850 class_destroy(vme_user_sysfs_class); 853 class_destroy(vme_user_sysfs_class);
851 854
852 for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++) 855 for (i = MASTER_MINOR; i < (MASTER_MAX + 1); i++) {
853 kfree(image[i].kern_buf); 856 kfree(image[i].kern_buf);
857 vme_master_free(image[i].resource);
858 }
854 859
855 for (i = SLAVE_MINOR; i < (SLAVE_MAX + 1); i++) { 860 for (i = SLAVE_MINOR; i < (SLAVE_MAX + 1); i++) {
856 vme_slave_set(image[i].resource, 0, 0, 0, 0, VME_A32, 0); 861 vme_slave_set(image[i].resource, 0, 0, 0, 0, VME_A32, 0);
857 vme_slave_free(image[i].resource);
858 buf_unalloc(i); 862 buf_unalloc(i);
863 vme_slave_free(image[i].resource);
859 } 864 }
860 865
861 /* Unregister device driver */ 866 /* Unregister device driver */
diff --git a/drivers/staging/vme/vme.c b/drivers/staging/vme/vme.c
index 093fbffbf557..d9fc8644376e 100644
--- a/drivers/staging/vme/vme.c
+++ b/drivers/staging/vme/vme.c
@@ -245,7 +245,7 @@ struct vme_resource *vme_slave_request(struct device *dev,
245 } 245 }
246 246
247 /* Loop through slave resources */ 247 /* Loop through slave resources */
248 list_for_each(slave_pos, &(bridge->slave_resources)) { 248 list_for_each(slave_pos, &bridge->slave_resources) {
249 slave_image = list_entry(slave_pos, 249 slave_image = list_entry(slave_pos,
250 struct vme_slave_resource, list); 250 struct vme_slave_resource, list);
251 251
@@ -255,17 +255,17 @@ struct vme_resource *vme_slave_request(struct device *dev,
255 } 255 }
256 256
257 /* Find an unlocked and compatible image */ 257 /* Find an unlocked and compatible image */
258 mutex_lock(&(slave_image->mtx)); 258 mutex_lock(&slave_image->mtx);
259 if (((slave_image->address_attr & address) == address) && 259 if (((slave_image->address_attr & address) == address) &&
260 ((slave_image->cycle_attr & cycle) == cycle) && 260 ((slave_image->cycle_attr & cycle) == cycle) &&
261 (slave_image->locked == 0)) { 261 (slave_image->locked == 0)) {
262 262
263 slave_image->locked = 1; 263 slave_image->locked = 1;
264 mutex_unlock(&(slave_image->mtx)); 264 mutex_unlock(&slave_image->mtx);
265 allocated_image = slave_image; 265 allocated_image = slave_image;
266 break; 266 break;
267 } 267 }
268 mutex_unlock(&(slave_image->mtx)); 268 mutex_unlock(&slave_image->mtx);
269 } 269 }
270 270
271 /* No free image */ 271 /* No free image */
@@ -278,15 +278,15 @@ struct vme_resource *vme_slave_request(struct device *dev,
278 goto err_alloc; 278 goto err_alloc;
279 } 279 }
280 resource->type = VME_SLAVE; 280 resource->type = VME_SLAVE;
281 resource->entry = &(allocated_image->list); 281 resource->entry = &allocated_image->list;
282 282
283 return resource; 283 return resource;
284 284
285err_alloc: 285err_alloc:
286 /* Unlock image */ 286 /* Unlock image */
287 mutex_lock(&(slave_image->mtx)); 287 mutex_lock(&slave_image->mtx);
288 slave_image->locked = 0; 288 slave_image->locked = 0;
289 mutex_unlock(&(slave_image->mtx)); 289 mutex_unlock(&slave_image->mtx);
290err_image: 290err_image:
291err_bus: 291err_bus:
292 return NULL; 292 return NULL;
@@ -369,12 +369,12 @@ void vme_slave_free(struct vme_resource *resource)
369 } 369 }
370 370
371 /* Unlock image */ 371 /* Unlock image */
372 mutex_lock(&(slave_image->mtx)); 372 mutex_lock(&slave_image->mtx);
373 if (slave_image->locked == 0) 373 if (slave_image->locked == 0)
374 printk(KERN_ERR "Image is already free\n"); 374 printk(KERN_ERR "Image is already free\n");
375 375
376 slave_image->locked = 0; 376 slave_image->locked = 0;
377 mutex_unlock(&(slave_image->mtx)); 377 mutex_unlock(&slave_image->mtx);
378 378
379 /* Free up resource memory */ 379 /* Free up resource memory */
380 kfree(resource); 380 kfree(resource);
@@ -401,7 +401,7 @@ struct vme_resource *vme_master_request(struct device *dev,
401 } 401 }
402 402
403 /* Loop through master resources */ 403 /* Loop through master resources */
404 list_for_each(master_pos, &(bridge->master_resources)) { 404 list_for_each(master_pos, &bridge->master_resources) {
405 master_image = list_entry(master_pos, 405 master_image = list_entry(master_pos,
406 struct vme_master_resource, list); 406 struct vme_master_resource, list);
407 407
@@ -411,18 +411,18 @@ struct vme_resource *vme_master_request(struct device *dev,
411 } 411 }
412 412
413 /* Find an unlocked and compatible image */ 413 /* Find an unlocked and compatible image */
414 spin_lock(&(master_image->lock)); 414 spin_lock(&master_image->lock);
415 if (((master_image->address_attr & address) == address) && 415 if (((master_image->address_attr & address) == address) &&
416 ((master_image->cycle_attr & cycle) == cycle) && 416 ((master_image->cycle_attr & cycle) == cycle) &&
417 ((master_image->width_attr & dwidth) == dwidth) && 417 ((master_image->width_attr & dwidth) == dwidth) &&
418 (master_image->locked == 0)) { 418 (master_image->locked == 0)) {
419 419
420 master_image->locked = 1; 420 master_image->locked = 1;
421 spin_unlock(&(master_image->lock)); 421 spin_unlock(&master_image->lock);
422 allocated_image = master_image; 422 allocated_image = master_image;
423 break; 423 break;
424 } 424 }
425 spin_unlock(&(master_image->lock)); 425 spin_unlock(&master_image->lock);
426 } 426 }
427 427
428 /* Check to see if we found a resource */ 428 /* Check to see if we found a resource */
@@ -437,16 +437,16 @@ struct vme_resource *vme_master_request(struct device *dev,
437 goto err_alloc; 437 goto err_alloc;
438 } 438 }
439 resource->type = VME_MASTER; 439 resource->type = VME_MASTER;
440 resource->entry = &(allocated_image->list); 440 resource->entry = &allocated_image->list;
441 441
442 return resource; 442 return resource;
443 443
444 kfree(resource); 444 kfree(resource);
445err_alloc: 445err_alloc:
446 /* Unlock image */ 446 /* Unlock image */
447 spin_lock(&(master_image->lock)); 447 spin_lock(&master_image->lock);
448 master_image->locked = 0; 448 master_image->locked = 0;
449 spin_unlock(&(master_image->lock)); 449 spin_unlock(&master_image->lock);
450err_image: 450err_image:
451err_bus: 451err_bus:
452 return NULL; 452 return NULL;
@@ -628,12 +628,12 @@ void vme_master_free(struct vme_resource *resource)
628 } 628 }
629 629
630 /* Unlock image */ 630 /* Unlock image */
631 spin_lock(&(master_image->lock)); 631 spin_lock(&master_image->lock);
632 if (master_image->locked == 0) 632 if (master_image->locked == 0)
633 printk(KERN_ERR "Image is already free\n"); 633 printk(KERN_ERR "Image is already free\n");
634 634
635 master_image->locked = 0; 635 master_image->locked = 0;
636 spin_unlock(&(master_image->lock)); 636 spin_unlock(&master_image->lock);
637 637
638 /* Free up resource memory */ 638 /* Free up resource memory */
639 kfree(resource); 639 kfree(resource);
@@ -662,7 +662,7 @@ struct vme_resource *vme_dma_request(struct device *dev, vme_dma_route_t route)
662 } 662 }
663 663
664 /* Loop through DMA resources */ 664 /* Loop through DMA resources */
665 list_for_each(dma_pos, &(bridge->dma_resources)) { 665 list_for_each(dma_pos, &bridge->dma_resources) {
666 dma_ctrlr = list_entry(dma_pos, 666 dma_ctrlr = list_entry(dma_pos,
667 struct vme_dma_resource, list); 667 struct vme_dma_resource, list);
668 668
@@ -672,16 +672,16 @@ struct vme_resource *vme_dma_request(struct device *dev, vme_dma_route_t route)
672 } 672 }
673 673
674 /* Find an unlocked and compatible controller */ 674 /* Find an unlocked and compatible controller */
675 mutex_lock(&(dma_ctrlr->mtx)); 675 mutex_lock(&dma_ctrlr->mtx);
676 if (((dma_ctrlr->route_attr & route) == route) && 676 if (((dma_ctrlr->route_attr & route) == route) &&
677 (dma_ctrlr->locked == 0)) { 677 (dma_ctrlr->locked == 0)) {
678 678
679 dma_ctrlr->locked = 1; 679 dma_ctrlr->locked = 1;
680 mutex_unlock(&(dma_ctrlr->mtx)); 680 mutex_unlock(&dma_ctrlr->mtx);
681 allocated_ctrlr = dma_ctrlr; 681 allocated_ctrlr = dma_ctrlr;
682 break; 682 break;
683 } 683 }
684 mutex_unlock(&(dma_ctrlr->mtx)); 684 mutex_unlock(&dma_ctrlr->mtx);
685 } 685 }
686 686
687 /* Check to see if we found a resource */ 687 /* Check to see if we found a resource */
@@ -694,15 +694,15 @@ struct vme_resource *vme_dma_request(struct device *dev, vme_dma_route_t route)
694 goto err_alloc; 694 goto err_alloc;
695 } 695 }
696 resource->type = VME_DMA; 696 resource->type = VME_DMA;
697 resource->entry = &(allocated_ctrlr->list); 697 resource->entry = &allocated_ctrlr->list;
698 698
699 return resource; 699 return resource;
700 700
701err_alloc: 701err_alloc:
702 /* Unlock image */ 702 /* Unlock image */
703 mutex_lock(&(dma_ctrlr->mtx)); 703 mutex_lock(&dma_ctrlr->mtx);
704 dma_ctrlr->locked = 0; 704 dma_ctrlr->locked = 0;
705 mutex_unlock(&(dma_ctrlr->mtx)); 705 mutex_unlock(&dma_ctrlr->mtx);
706err_ctrlr: 706err_ctrlr:
707err_bus: 707err_bus:
708 return NULL; 708 return NULL;
@@ -729,9 +729,9 @@ struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource)
729 printk(KERN_ERR "Unable to allocate memory for new dma list\n"); 729 printk(KERN_ERR "Unable to allocate memory for new dma list\n");
730 return NULL; 730 return NULL;
731 } 731 }
732 INIT_LIST_HEAD(&(dma_list->entries)); 732 INIT_LIST_HEAD(&dma_list->entries);
733 dma_list->parent = ctrlr; 733 dma_list->parent = ctrlr;
734 mutex_init(&(dma_list->mtx)); 734 mutex_init(&dma_list->mtx);
735 735
736 return dma_list; 736 return dma_list;
737} 737}
@@ -880,14 +880,14 @@ int vme_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
880 return -EINVAL; 880 return -EINVAL;
881 } 881 }
882 882
883 if (!mutex_trylock(&(list->mtx))) { 883 if (!mutex_trylock(&list->mtx)) {
884 printk(KERN_ERR "Link List already submitted\n"); 884 printk(KERN_ERR "Link List already submitted\n");
885 return -EINVAL; 885 return -EINVAL;
886 } 886 }
887 887
888 retval = bridge->dma_list_add(list, src, dest, count); 888 retval = bridge->dma_list_add(list, src, dest, count);
889 889
890 mutex_unlock(&(list->mtx)); 890 mutex_unlock(&list->mtx);
891 891
892 return retval; 892 return retval;
893} 893}
@@ -903,11 +903,11 @@ int vme_dma_list_exec(struct vme_dma_list *list)
903 return -EINVAL; 903 return -EINVAL;
904 } 904 }
905 905
906 mutex_lock(&(list->mtx)); 906 mutex_lock(&list->mtx);
907 907
908 retval = bridge->dma_list_exec(list); 908 retval = bridge->dma_list_exec(list);
909 909
910 mutex_unlock(&(list->mtx)); 910 mutex_unlock(&list->mtx);
911 911
912 return retval; 912 return retval;
913} 913}
@@ -923,7 +923,7 @@ int vme_dma_list_free(struct vme_dma_list *list)
923 return -EINVAL; 923 return -EINVAL;
924 } 924 }
925 925
926 if (!mutex_trylock(&(list->mtx))) { 926 if (!mutex_trylock(&list->mtx)) {
927 printk(KERN_ERR "Link List in use\n"); 927 printk(KERN_ERR "Link List in use\n");
928 return -EINVAL; 928 return -EINVAL;
929 } 929 }
@@ -935,10 +935,10 @@ int vme_dma_list_free(struct vme_dma_list *list)
935 retval = bridge->dma_list_empty(list); 935 retval = bridge->dma_list_empty(list);
936 if (retval) { 936 if (retval) {
937 printk(KERN_ERR "Unable to empty link-list entries\n"); 937 printk(KERN_ERR "Unable to empty link-list entries\n");
938 mutex_unlock(&(list->mtx)); 938 mutex_unlock(&list->mtx);
939 return retval; 939 return retval;
940 } 940 }
941 mutex_unlock(&(list->mtx)); 941 mutex_unlock(&list->mtx);
942 kfree(list); 942 kfree(list);
943 943
944 return retval; 944 return retval;
@@ -956,20 +956,20 @@ int vme_dma_free(struct vme_resource *resource)
956 956
957 ctrlr = list_entry(resource->entry, struct vme_dma_resource, list); 957 ctrlr = list_entry(resource->entry, struct vme_dma_resource, list);
958 958
959 if (!mutex_trylock(&(ctrlr->mtx))) { 959 if (!mutex_trylock(&ctrlr->mtx)) {
960 printk(KERN_ERR "Resource busy, can't free\n"); 960 printk(KERN_ERR "Resource busy, can't free\n");
961 return -EBUSY; 961 return -EBUSY;
962 } 962 }
963 963
964 if (!(list_empty(&(ctrlr->pending)) && list_empty(&(ctrlr->running)))) { 964 if (!(list_empty(&ctrlr->pending) && list_empty(&ctrlr->running))) {
965 printk(KERN_WARNING "Resource still processing transfers\n"); 965 printk(KERN_WARNING "Resource still processing transfers\n");
966 mutex_unlock(&(ctrlr->mtx)); 966 mutex_unlock(&ctrlr->mtx);
967 return -EBUSY; 967 return -EBUSY;
968 } 968 }
969 969
970 ctrlr->locked = 0; 970 ctrlr->locked = 0;
971 971
972 mutex_unlock(&(ctrlr->mtx)); 972 mutex_unlock(&ctrlr->mtx);
973 973
974 return 0; 974 return 0;
975} 975}
@@ -1013,10 +1013,10 @@ int vme_irq_request(struct device *dev, int level, int statid,
1013 return -EINVAL; 1013 return -EINVAL;
1014 } 1014 }
1015 1015
1016 mutex_lock(&(bridge->irq_mtx)); 1016 mutex_lock(&bridge->irq_mtx);
1017 1017
1018 if (bridge->irq[level - 1].callback[statid].func) { 1018 if (bridge->irq[level - 1].callback[statid].func) {
1019 mutex_unlock(&(bridge->irq_mtx)); 1019 mutex_unlock(&bridge->irq_mtx);
1020 printk(KERN_WARNING "VME Interrupt already taken\n"); 1020 printk(KERN_WARNING "VME Interrupt already taken\n");
1021 return -EBUSY; 1021 return -EBUSY;
1022 } 1022 }
@@ -1028,7 +1028,7 @@ int vme_irq_request(struct device *dev, int level, int statid,
1028 /* Enable IRQ level */ 1028 /* Enable IRQ level */
1029 bridge->irq_set(bridge, level, 1, 1); 1029 bridge->irq_set(bridge, level, 1, 1);
1030 1030
1031 mutex_unlock(&(bridge->irq_mtx)); 1031 mutex_unlock(&bridge->irq_mtx);
1032 1032
1033 return 0; 1033 return 0;
1034} 1034}
@@ -1054,7 +1054,7 @@ void vme_irq_free(struct device *dev, int level, int statid)
1054 return; 1054 return;
1055 } 1055 }
1056 1056
1057 mutex_lock(&(bridge->irq_mtx)); 1057 mutex_lock(&bridge->irq_mtx);
1058 1058
1059 bridge->irq[level - 1].count--; 1059 bridge->irq[level - 1].count--;
1060 1060
@@ -1065,7 +1065,7 @@ void vme_irq_free(struct device *dev, int level, int statid)
1065 bridge->irq[level - 1].callback[statid].func = NULL; 1065 bridge->irq[level - 1].callback[statid].func = NULL;
1066 bridge->irq[level - 1].callback[statid].priv_data = NULL; 1066 bridge->irq[level - 1].callback[statid].priv_data = NULL;
1067 1067
1068 mutex_unlock(&(bridge->irq_mtx)); 1068 mutex_unlock(&bridge->irq_mtx);
1069} 1069}
1070EXPORT_SYMBOL(vme_irq_free); 1070EXPORT_SYMBOL(vme_irq_free);
1071 1071
@@ -1111,7 +1111,7 @@ struct vme_resource *vme_lm_request(struct device *dev)
1111 } 1111 }
1112 1112
1113 /* Loop through DMA resources */ 1113 /* Loop through DMA resources */
1114 list_for_each(lm_pos, &(bridge->lm_resources)) { 1114 list_for_each(lm_pos, &bridge->lm_resources) {
1115 lm = list_entry(lm_pos, 1115 lm = list_entry(lm_pos,
1116 struct vme_lm_resource, list); 1116 struct vme_lm_resource, list);
1117 1117
@@ -1122,14 +1122,14 @@ struct vme_resource *vme_lm_request(struct device *dev)
1122 } 1122 }
1123 1123
1124 /* Find an unlocked controller */ 1124 /* Find an unlocked controller */
1125 mutex_lock(&(lm->mtx)); 1125 mutex_lock(&lm->mtx);
1126 if (lm->locked == 0) { 1126 if (lm->locked == 0) {
1127 lm->locked = 1; 1127 lm->locked = 1;
1128 mutex_unlock(&(lm->mtx)); 1128 mutex_unlock(&lm->mtx);
1129 allocated_lm = lm; 1129 allocated_lm = lm;
1130 break; 1130 break;
1131 } 1131 }
1132 mutex_unlock(&(lm->mtx)); 1132 mutex_unlock(&lm->mtx);
1133 } 1133 }
1134 1134
1135 /* Check to see if we found a resource */ 1135 /* Check to see if we found a resource */
@@ -1142,15 +1142,15 @@ struct vme_resource *vme_lm_request(struct device *dev)
1142 goto err_alloc; 1142 goto err_alloc;
1143 } 1143 }
1144 resource->type = VME_LM; 1144 resource->type = VME_LM;
1145 resource->entry = &(allocated_lm->list); 1145 resource->entry = &allocated_lm->list;
1146 1146
1147 return resource; 1147 return resource;
1148 1148
1149err_alloc: 1149err_alloc:
1150 /* Unlock image */ 1150 /* Unlock image */
1151 mutex_lock(&(lm->mtx)); 1151 mutex_lock(&lm->mtx);
1152 lm->locked = 0; 1152 lm->locked = 0;
1153 mutex_unlock(&(lm->mtx)); 1153 mutex_unlock(&lm->mtx);
1154err_lm: 1154err_lm:
1155err_bus: 1155err_bus:
1156 return NULL; 1156 return NULL;
@@ -1270,7 +1270,7 @@ void vme_lm_free(struct vme_resource *resource)
1270 1270
1271 lm = list_entry(resource->entry, struct vme_lm_resource, list); 1271 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1272 1272
1273 mutex_lock(&(lm->mtx)); 1273 mutex_lock(&lm->mtx);
1274 1274
1275 /* XXX 1275 /* XXX
1276 * Check to see that there aren't any callbacks still attached, if 1276 * Check to see that there aren't any callbacks still attached, if
@@ -1279,7 +1279,7 @@ void vme_lm_free(struct vme_resource *resource)
1279 1279
1280 lm->locked = 0; 1280 lm->locked = 0;
1281 1281
1282 mutex_unlock(&(lm->mtx)); 1282 mutex_unlock(&lm->mtx);
1283 1283
1284 kfree(resource); 1284 kfree(resource);
1285} 1285}
@@ -1326,7 +1326,7 @@ static int vme_alloc_bus_num(void)
1326static void vme_free_bus_num(int bus) 1326static void vme_free_bus_num(int bus)
1327{ 1327{
1328 mutex_lock(&vme_bus_num_mtx); 1328 mutex_lock(&vme_bus_num_mtx);
1329 vme_bus_numbers |= ~(0x1 << bus); 1329 vme_bus_numbers &= ~(0x1 << bus);
1330 mutex_unlock(&vme_bus_num_mtx); 1330 mutex_unlock(&vme_bus_num_mtx);
1331} 1331}
1332 1332
@@ -1343,11 +1343,11 @@ int vme_register_bridge(struct vme_bridge *bridge)
1343 * specification. 1343 * specification.
1344 */ 1344 */
1345 for (i = 0; i < VME_SLOTS_MAX; i++) { 1345 for (i = 0; i < VME_SLOTS_MAX; i++) {
1346 dev = &(bridge->dev[i]); 1346 dev = &bridge->dev[i];
1347 memset(dev, 0, sizeof(struct device)); 1347 memset(dev, 0, sizeof(struct device));
1348 1348
1349 dev->parent = bridge->parent; 1349 dev->parent = bridge->parent;
1350 dev->bus = &(vme_bus_type); 1350 dev->bus = &vme_bus_type;
1351 /* 1351 /*
1352 * We save a pointer to the bridge in platform_data so that we 1352 * We save a pointer to the bridge in platform_data so that we
1353 * can get to it later. We keep driver_data for use by the 1353 * can get to it later. We keep driver_data for use by the
@@ -1366,7 +1366,7 @@ int vme_register_bridge(struct vme_bridge *bridge)
1366 i = VME_SLOTS_MAX; 1366 i = VME_SLOTS_MAX;
1367err_reg: 1367err_reg:
1368 while (i > -1) { 1368 while (i > -1) {
1369 dev = &(bridge->dev[i]); 1369 dev = &bridge->dev[i];
1370 device_unregister(dev); 1370 device_unregister(dev);
1371 } 1371 }
1372 vme_free_bus_num(bridge->num); 1372 vme_free_bus_num(bridge->num);
@@ -1381,7 +1381,7 @@ void vme_unregister_bridge(struct vme_bridge *bridge)
1381 1381
1382 1382
1383 for (i = 0; i < VME_SLOTS_MAX; i++) { 1383 for (i = 0; i < VME_SLOTS_MAX; i++) {
1384 dev = &(bridge->dev[i]); 1384 dev = &bridge->dev[i];
1385 device_unregister(dev); 1385 device_unregister(dev);
1386 } 1386 }
1387 vme_free_bus_num(bridge->num); 1387 vme_free_bus_num(bridge->num);
@@ -1418,7 +1418,7 @@ static int vme_calc_slot(struct device *dev)
1418 /* Determine slot number */ 1418 /* Determine slot number */
1419 num = 0; 1419 num = 0;
1420 while (num < VME_SLOTS_MAX) { 1420 while (num < VME_SLOTS_MAX) {
1421 if (&(bridge->dev[num]) == dev) 1421 if (&bridge->dev[num] == dev)
1422 break; 1422 break;
1423 1423
1424 num++; 1424 num++;
diff --git a/drivers/staging/vme/vme_bridge.h b/drivers/staging/vme/vme_bridge.h
index b653ec02e1fc..4c6ec31b01db 100644
--- a/drivers/staging/vme/vme_bridge.h
+++ b/drivers/staging/vme/vme_bridge.h
@@ -20,7 +20,7 @@ struct vme_master_resource {
20 vme_cycle_t cycle_attr; 20 vme_cycle_t cycle_attr;
21 vme_width_t width_attr; 21 vme_width_t width_attr;
22 struct resource bus_resource; 22 struct resource bus_resource;
23 void *kern_base; 23 void __iomem *kern_base;
24}; 24};
25 25
26struct vme_slave_resource { 26struct vme_slave_resource {
diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c
index 32d095c4d51c..951a3a8ddcb2 100644
--- a/drivers/staging/vt6655/card.c
+++ b/drivers/staging/vt6655/card.c
@@ -2058,7 +2058,7 @@ bool CARDbSoftwareReset (void *pDeviceHandler)
2058QWORD CARDqGetTSFOffset (unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2) 2058QWORD CARDqGetTSFOffset (unsigned char byRxRate, QWORD qwTSF1, QWORD qwTSF2)
2059{ 2059{
2060 QWORD qwTSFOffset; 2060 QWORD qwTSFOffset;
2061 unsigned short wRxBcnTSFOffst= 0;; 2061 unsigned short wRxBcnTSFOffst= 0;
2062 2062
2063 HIDWORD(qwTSFOffset) = 0; 2063 HIDWORD(qwTSFOffset) = 0;
2064 LODWORD(qwTSFOffset) = 0; 2064 LODWORD(qwTSFOffset) = 0;
diff --git a/drivers/staging/vt6655/iwctl.c b/drivers/staging/vt6655/iwctl.c
index 92e33999054b..5e425d1476b8 100644
--- a/drivers/staging/vt6655/iwctl.c
+++ b/drivers/staging/vt6655/iwctl.c
@@ -2073,7 +2073,7 @@ int iwctl_giwencodeext(struct net_device *dev,
2073 struct iw_point *wrq, 2073 struct iw_point *wrq,
2074 char *extra) 2074 char *extra)
2075{ 2075{
2076 return -EOPNOTSUPP;; 2076 return -EOPNOTSUPP;
2077} 2077}
2078 2078
2079int iwctl_siwmlme(struct net_device *dev, 2079int iwctl_siwmlme(struct net_device *dev,
diff --git a/drivers/staging/vt6655/wpa2.c b/drivers/staging/vt6655/wpa2.c
index 805164bed7e4..744799cfe832 100644
--- a/drivers/staging/vt6655/wpa2.c
+++ b/drivers/staging/vt6655/wpa2.c
@@ -216,7 +216,7 @@ WPA2vParseRSN (
216 m = *((unsigned short *) &(pRSN->abyRSN[4])); 216 m = *((unsigned short *) &(pRSN->abyRSN[4]));
217 217
218 if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2) 218 if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2)
219 pBSSNode->wAKMSSAuthCount = *((unsigned short *) &(pRSN->abyRSN[6+4*m]));; 219 pBSSNode->wAKMSSAuthCount = *((unsigned short *) &(pRSN->abyRSN[6+4*m]));
220 j = 0; 220 j = 0;
221 pbyOUI = &(pRSN->abyRSN[8+4*m]); 221 pbyOUI = &(pRSN->abyRSN[8+4*m]);
222 for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(unsigned char)); i++) { 222 for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(unsigned char)); i++) {
@@ -235,7 +235,7 @@ WPA2vParseRSN (
235 pBSSNode->wAKMSSAuthCount = (unsigned short)j; 235 pBSSNode->wAKMSSAuthCount = (unsigned short)j;
236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount); 236 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount);
237 237
238 n = *((unsigned short *) &(pRSN->abyRSN[6+4*m]));; 238 n = *((unsigned short *) &(pRSN->abyRSN[6+4*m]));
239 if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2) 239 if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
240 pBSSNode->sRSNCapObj.bRSNCapExist = true; 240 pBSSNode->sRSNCapObj.bRSNCapExist = true;
241 pBSSNode->sRSNCapObj.wRSNCap = *((unsigned short *) &(pRSN->abyRSN[8+4*m+4*n])); 241 pBSSNode->sRSNCapObj.wRSNCap = *((unsigned short *) &(pRSN->abyRSN[8+4*m+4*n]));
diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c
index e5add2046375..0d11147f91c1 100644
--- a/drivers/staging/vt6656/baseband.c
+++ b/drivers/staging/vt6656/baseband.c
@@ -963,7 +963,7 @@ BBvSetAntennaMode (PSDevice pDevice, BYTE byAntennaMode)
963 break; 963 break;
964 case ANT_RXB: 964 case ANT_RXB:
965 pDevice->byBBRxConf &= 0xFE; 965 pDevice->byBBRxConf &= 0xFE;
966 pDevice->byBBRxConf |= 0x02;; 966 pDevice->byBBRxConf |= 0x02;
967 break; 967 break;
968 } 968 }
969 969
diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
index 8de21aac1bff..a49053bd7c65 100644
--- a/drivers/staging/vt6656/card.c
+++ b/drivers/staging/vt6656/card.c
@@ -1092,7 +1092,7 @@ CARDbChannelSwitch (
1092 pDevice->sMgmtObj.uCurrChannel = byNewChannel; 1092 pDevice->sMgmtObj.uCurrChannel = byNewChannel;
1093 bResult = CARDbSetMediaChannel(pDevice, byNewChannel); 1093 bResult = CARDbSetMediaChannel(pDevice, byNewChannel);
1094 1094
1095 return(bResult); 1095 return bResult;
1096 } 1096 }
1097 pDevice->byChannelSwitchCount = byCount; 1097 pDevice->byChannelSwitchCount = byCount;
1098 pDevice->byNewChannel = byNewChannel; 1098 pDevice->byNewChannel = byNewChannel;
diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c
index 1f9d29636803..f4fb0c6e4eac 100644
--- a/drivers/staging/vt6656/dpc.c
+++ b/drivers/staging/vt6656/dpc.c
@@ -1608,8 +1608,8 @@ void RXvMngWorkItem(void *Context)
1608 } 1608 }
1609 } 1609 }
1610 1610
1611 pDevice->bIsRxMngWorkItemQueued = FALSE; 1611 pDevice->bIsRxMngWorkItemQueued = FALSE;
1612 spin_unlock_irq(&pDevice->lock); 1612 spin_unlock_irq(&pDevice->lock);
1613 1613
1614} 1614}
1615 1615
diff --git a/drivers/staging/vt6656/iwctl.c b/drivers/staging/vt6656/iwctl.c
index 0004be8e3957..2121205a912b 100644
--- a/drivers/staging/vt6656/iwctl.c
+++ b/drivers/staging/vt6656/iwctl.c
@@ -1883,7 +1883,7 @@ int iwctl_giwencodeext(struct net_device *dev,
1883 struct iw_point *wrq, 1883 struct iw_point *wrq,
1884 char *extra) 1884 char *extra)
1885{ 1885{
1886 return -EOPNOTSUPP;; 1886 return -EOPNOTSUPP;
1887} 1887}
1888 1888
1889int iwctl_siwmlme(struct net_device *dev, 1889int iwctl_siwmlme(struct net_device *dev,
diff --git a/drivers/staging/vt6656/power.c b/drivers/staging/vt6656/power.c
index 0c12fd36d0f9..e8c1b35e8128 100644
--- a/drivers/staging/vt6656/power.c
+++ b/drivers/staging/vt6656/power.c
@@ -192,7 +192,7 @@ BOOL PSbConsiderPowerDown(void *hDeviceContext,
192 // check if already in Doze mode 192 // check if already in Doze mode
193 ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData); 193 ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
194 if ( (byData & PSCTL_PS) != 0 ) 194 if ( (byData & PSCTL_PS) != 0 )
195 return TRUE;; 195 return TRUE;
196 196
197 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { 197 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
198 // check if in TIM wake period 198 // check if in TIM wake period
diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c
index bbdc127a987d..8f18578a5903 100644
--- a/drivers/staging/vt6656/rxtx.c
+++ b/drivers/staging/vt6656/rxtx.c
@@ -68,8 +68,7 @@
68/*--------------------- Static Classes ----------------------------*/ 68/*--------------------- Static Classes ----------------------------*/
69 69
70/*--------------------- Static Variables --------------------------*/ 70/*--------------------- Static Variables --------------------------*/
71//static int msglevel =MSG_LEVEL_DEBUG; 71static int msglevel = MSG_LEVEL_INFO;
72static int msglevel =MSG_LEVEL_INFO;
73 72
74/*--------------------- Static Functions --------------------------*/ 73/*--------------------- Static Functions --------------------------*/
75 74
diff --git a/drivers/staging/vt6656/tkip.c b/drivers/staging/vt6656/tkip.c
index a6bd533f9577..0715636cb9cb 100644
--- a/drivers/staging/vt6656/tkip.c
+++ b/drivers/staging/vt6656/tkip.c
@@ -214,13 +214,14 @@ void TKIPvMixKey(
214 /* Phase 1, step 2 */ 214 /* Phase 1, step 2 */
215 for (i=0; i<8; i++) { 215 for (i=0; i<8; i++) {
216 j = 2*(i & 1); 216 j = 2*(i & 1);
217 p1k[0] = (p1k[0] + tkip_sbox( (p1k[4] ^ ((256*pbyTKey[1+j]) + pbyTKey[j])) % 65536 )) % 65536; 217 p1k[0] = (p1k[0] + tkip_sbox((p1k[4] ^ ((256*pbyTKey[1+j]) + pbyTKey[j])) % 65536)) % 65536;
218 p1k[1] = (p1k[1] + tkip_sbox( (p1k[0] ^ ((256*pbyTKey[5+j]) + pbyTKey[4+j])) % 65536 )) % 65536; 218 p1k[1] = (p1k[1] + tkip_sbox((p1k[0] ^ ((256*pbyTKey[5+j]) + pbyTKey[4+j])) % 65536)) % 65536;
219 p1k[2] = (p1k[2] + tkip_sbox( (p1k[1] ^ ((256*pbyTKey[9+j]) + pbyTKey[8+j])) % 65536 )) % 65536; 219 p1k[2] = (p1k[2] + tkip_sbox((p1k[1] ^ ((256*pbyTKey[9+j]) + pbyTKey[8+j])) % 65536)) % 65536;
220 p1k[3] = (p1k[3] + tkip_sbox( (p1k[2] ^ ((256*pbyTKey[13+j]) + pbyTKey[12+j])) % 65536 )) % 65536; 220 p1k[3] = (p1k[3] + tkip_sbox((p1k[2] ^ ((256*pbyTKey[13+j]) + pbyTKey[12+j])) % 65536)) % 65536;
221 p1k[4] = (p1k[4] + tkip_sbox( (p1k[3] ^ (((256*pbyTKey[1+j]) + pbyTKey[j]))) % 65536 )) % 65536; 221 p1k[4] = (p1k[4] + tkip_sbox((p1k[3] ^ (((256*pbyTKey[1+j]) + pbyTKey[j]))) % 65536)) % 65536;
222 p1k[4] = (p1k[4] + i) % 65536; 222 p1k[4] = (p1k[4] + i) % 65536;
223 } 223 }
224
224 /* Phase 2, Step 1 */ 225 /* Phase 2, Step 1 */
225 ppk0 = p1k[0]; 226 ppk0 = p1k[0];
226 ppk1 = p1k[1]; 227 ppk1 = p1k[1];
@@ -230,19 +231,19 @@ void TKIPvMixKey(
230 ppk5 = (p1k[4] + tsc2) % 65536; 231 ppk5 = (p1k[4] + tsc2) % 65536;
231 232
232 /* Phase2, Step 2 */ 233 /* Phase2, Step 2 */
233 ppk0 = ppk0 + tkip_sbox( (ppk5 ^ ((256*pbyTKey[1]) + pbyTKey[0])) % 65536); 234 ppk0 = ppk0 + tkip_sbox((ppk5 ^ ((256*pbyTKey[1]) + pbyTKey[0])) % 65536);
234 ppk1 = ppk1 + tkip_sbox( (ppk0 ^ ((256*pbyTKey[3]) + pbyTKey[2])) % 65536); 235 ppk1 = ppk1 + tkip_sbox((ppk0 ^ ((256*pbyTKey[3]) + pbyTKey[2])) % 65536);
235 ppk2 = ppk2 + tkip_sbox( (ppk1 ^ ((256*pbyTKey[5]) + pbyTKey[4])) % 65536); 236 ppk2 = ppk2 + tkip_sbox((ppk1 ^ ((256*pbyTKey[5]) + pbyTKey[4])) % 65536);
236 ppk3 = ppk3 + tkip_sbox( (ppk2 ^ ((256*pbyTKey[7]) + pbyTKey[6])) % 65536); 237 ppk3 = ppk3 + tkip_sbox((ppk2 ^ ((256*pbyTKey[7]) + pbyTKey[6])) % 65536);
237 ppk4 = ppk4 + tkip_sbox( (ppk3 ^ ((256*pbyTKey[9]) + pbyTKey[8])) % 65536); 238 ppk4 = ppk4 + tkip_sbox((ppk3 ^ ((256*pbyTKey[9]) + pbyTKey[8])) % 65536);
238 ppk5 = ppk5 + tkip_sbox( (ppk4 ^ ((256*pbyTKey[11]) + pbyTKey[10])) % 65536); 239 ppk5 = ppk5 + tkip_sbox((ppk4 ^ ((256*pbyTKey[11]) + pbyTKey[10])) % 65536);
239 240
240 ppk0 = ppk0 + rotr1(ppk5 ^ ((256*pbyTKey[13]) + pbyTKey[12])); 241 ppk0 = ppk0 + rotr1(ppk5 ^ ((256*pbyTKey[13]) + pbyTKey[12]));
241 ppk1 = ppk1 + rotr1(ppk0 ^ ((256*pbyTKey[15]) + pbyTKey[14])); 242 ppk1 = ppk1 + rotr1(ppk0 ^ ((256*pbyTKey[15]) + pbyTKey[14]));
242 ppk2 = ppk2 + rotr1(ppk1); 243 ppk2 = ppk2 + rotr1(ppk1);
243 ppk3 = ppk3 + rotr1(ppk2); 244 ppk3 = ppk3 + rotr1(ppk2);
244 ppk4 = ppk4 + rotr1(ppk3); 245 ppk4 = ppk4 + rotr1(ppk3);
245 ppk5 = ppk5 + rotr1(ppk4); 246 ppk5 = ppk5 + rotr1(ppk4);
246 247
247 /* Phase 2, Step 3 */ 248 /* Phase 2, Step 3 */
248 pbyRC4Key[0] = (tsc2 >> 8) % 256; 249 pbyRC4Key[0] = (tsc2 >> 8) % 256;
diff --git a/drivers/staging/vt6656/wpa2.c b/drivers/staging/vt6656/wpa2.c
index 6d13190885d1..d4f3f7530ee4 100644
--- a/drivers/staging/vt6656/wpa2.c
+++ b/drivers/staging/vt6656/wpa2.c
@@ -215,7 +215,7 @@ WPA2vParseRSN (
215 m = *((PWORD) &(pRSN->abyRSN[4])); 215 m = *((PWORD) &(pRSN->abyRSN[4]));
216 216
217 if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2) 217 if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2)
218 pBSSNode->wAKMSSAuthCount = *((PWORD) &(pRSN->abyRSN[6+4*m]));; 218 pBSSNode->wAKMSSAuthCount = *((PWORD) &(pRSN->abyRSN[6+4*m]));
219 j = 0; 219 j = 0;
220 pbyOUI = &(pRSN->abyRSN[8+4*m]); 220 pbyOUI = &(pRSN->abyRSN[8+4*m]);
221 for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(BYTE)); i++) { 221 for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(BYTE)); i++) {
@@ -234,7 +234,7 @@ WPA2vParseRSN (
234 pBSSNode->wAKMSSAuthCount = (WORD)j; 234 pBSSNode->wAKMSSAuthCount = (WORD)j;
235 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount); 235 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount);
236 236
237 n = *((PWORD) &(pRSN->abyRSN[6+4*m]));; 237 n = *((PWORD) &(pRSN->abyRSN[6+4*m]));
238 if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2) 238 if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
239 pBSSNode->sRSNCapObj.bRSNCapExist = TRUE; 239 pBSSNode->sRSNCapObj.bRSNCapExist = TRUE;
240 pBSSNode->sRSNCapObj.wRSNCap = *((PWORD) &(pRSN->abyRSN[8+4*m+4*n])); 240 pBSSNode->sRSNCapObj.wRSNCap = *((PWORD) &(pRSN->abyRSN[8+4*m+4*n]));
diff --git a/drivers/staging/westbridge/astoria/arch/arm/mach-omap2/cyashalomap_kernel.c b/drivers/staging/westbridge/astoria/arch/arm/mach-omap2/cyashalomap_kernel.c
index a6780296888f..ad0c61db9937 100644
--- a/drivers/staging/westbridge/astoria/arch/arm/mach-omap2/cyashalomap_kernel.c
+++ b/drivers/staging/westbridge/astoria/arch/arm/mach-omap2/cyashalomap_kernel.c
@@ -2127,10 +2127,7 @@ void cy_as_hal_pll_lock_loss_handler(cy_as_hal_device_tag tag)
2127 */ 2127 */
2128void *cy_as_hal_alloc(uint32_t cnt) 2128void *cy_as_hal_alloc(uint32_t cnt)
2129{ 2129{
2130 void *ret_p; 2130 return kmalloc(cnt, GFP_ATOMIC);
2131
2132 ret_p = kmalloc(cnt, GFP_ATOMIC);
2133 return ret_p;
2134} 2131}
2135 2132
2136/* 2133/*
@@ -2150,10 +2147,7 @@ void cy_as_hal_free(void *mem_p)
2150 */ 2147 */
2151void *cy_as_hal_c_b_alloc(uint32_t cnt) 2148void *cy_as_hal_c_b_alloc(uint32_t cnt)
2152{ 2149{
2153 void *ret_p; 2150 return kmalloc(cnt, GFP_ATOMIC);
2154
2155 ret_p = kmalloc(cnt, GFP_ATOMIC);
2156 return ret_p;
2157} 2151}
2158 2152
2159/* 2153/*
diff --git a/drivers/staging/winbond/Makefile b/drivers/staging/winbond/Makefile
index 79fa2271a0c1..081d48db04cb 100644
--- a/drivers/staging/winbond/Makefile
+++ b/drivers/staging/winbond/Makefile
@@ -1,6 +1,5 @@
1w35und-y := \ 1w35und-y := \
2 mds.o \ 2 mds.o \
3 mlmetxrx.o \
4 mto.o \ 3 mto.o \
5 phy_calibration.o \ 4 phy_calibration.o \
6 reg.o \ 5 reg.o \
diff --git a/drivers/staging/winbond/core.h b/drivers/staging/winbond/core.h
index 2b87a0007319..d7b3aca5ddeb 100644
--- a/drivers/staging/winbond/core.h
+++ b/drivers/staging/winbond/core.h
@@ -4,7 +4,7 @@
4#include <linux/wireless.h> 4#include <linux/wireless.h>
5#include <linux/types.h> 5#include <linux/types.h>
6 6
7#include "wbhal_s.h" 7#include "wbhal.h"
8#include "mto.h" 8#include "mto.h"
9 9
10#include "mac_structures.h" 10#include "mac_structures.h"
diff --git a/drivers/staging/winbond/mac_structures.h b/drivers/staging/winbond/mac_structures.h
index ed3df2964065..76c63c74d50c 100644
--- a/drivers/staging/winbond/mac_structures.h
+++ b/drivers/staging/winbond/mac_structures.h
@@ -21,23 +21,11 @@
21#ifndef _MAC_Structures_H_ 21#ifndef _MAC_Structures_H_
22#define _MAC_Structures_H_ 22#define _MAC_Structures_H_
23 23
24#include <linux/skbuff.h>
25
26/*=========================================================
27// Some miscellaneous definitions
28//-----*/
29#define MAX_CHANNELS 30
30#define MAC_ADDR_LENGTH 6 24#define MAC_ADDR_LENGTH 6
31#define MAX_WEP_KEY_SIZE 16 /* 128 bits */
32#define MAX_802_11_FRAGMENT_NUMBER 10 /* By spec */
33 25
34/* ======================================================== 26/* ========================================================
35// 802.11 Frame define 27// 802.11 Frame define
36//----- */ 28//----- */
37#define MASK_PROTOCOL_VERSION_TYPE 0x0F
38#define MASK_FRAGMENT_NUMBER 0x000F
39#define SEQUENCE_NUMBER_SHIFT 4
40#define DIFFER_11_TO_3 18
41#define DOT_11_MAC_HEADER_SIZE 24 29#define DOT_11_MAC_HEADER_SIZE 24
42#define DOT_11_SNAP_SIZE 6 30#define DOT_11_SNAP_SIZE 6
43#define DOT_11_DURATION_OFFSET 2 31#define DOT_11_DURATION_OFFSET 2
@@ -47,15 +35,9 @@
47#define DOT_11_TYPE_OFFSET 30 35#define DOT_11_TYPE_OFFSET 30
48#define DOT_11_DATA_OFFSET 24 36#define DOT_11_DATA_OFFSET 24
49#define DOT_11_DA_OFFSET 4 37#define DOT_11_DA_OFFSET 4
50#define DOT_3_TYPE_ARP 0x80F3
51#define DOT_3_TYPE_IPX 0x8137
52#define DOT_3_TYPE_OFFSET 12
53
54 38
55#define ETHERNET_HEADER_SIZE 14
56#define MAX_ETHERNET_PACKET_SIZE 1514 39#define MAX_ETHERNET_PACKET_SIZE 1514
57 40
58
59/* ----- management : Type of Bits (2, 3) and Subtype of Bits (4, 5, 6, 7) */ 41/* ----- management : Type of Bits (2, 3) and Subtype of Bits (4, 5, 6, 7) */
60#define MAC_SUBTYPE_MNGMNT_ASSOC_REQUEST 0x00 42#define MAC_SUBTYPE_MNGMNT_ASSOC_REQUEST 0x00
61#define MAC_SUBTYPE_MNGMNT_ASSOC_RESPONSE 0x10 43#define MAC_SUBTYPE_MNGMNT_ASSOC_RESPONSE 0x10
@@ -69,129 +51,6 @@
69#define MAC_SUBTYPE_MNGMNT_AUTHENTICATION 0xB0 51#define MAC_SUBTYPE_MNGMNT_AUTHENTICATION 0xB0
70#define MAC_SUBTYPE_MNGMNT_DEAUTHENTICATION 0xC0 52#define MAC_SUBTYPE_MNGMNT_DEAUTHENTICATION 0xC0
71 53
72/* ----- control : Type of Bits (2, 3) and Subtype of Bits (4, 5, 6, 7) */
73#define MAC_SUBTYPE_CONTROL_PSPOLL 0xA4
74#define MAC_SUBTYPE_CONTROL_RTS 0xB4
75#define MAC_SUBTYPE_CONTROL_CTS 0xC4
76#define MAC_SUBTYPE_CONTROL_ACK 0xD4
77#define MAC_SUBTYPE_CONTROL_CFEND 0xE4
78#define MAC_SUBTYPE_CONTROL_CFEND_CFACK 0xF4
79
80/* ----- data : Type of Bits (2, 3) and Subtype of Bits (4, 5, 6, 7) */
81#define MAC_SUBTYPE_DATA 0x08
82#define MAC_SUBTYPE_DATA_CFACK 0x18
83#define MAC_SUBTYPE_DATA_CFPOLL 0x28
84#define MAC_SUBTYPE_DATA_CFACK_CFPOLL 0x38
85#define MAC_SUBTYPE_DATA_NULL 0x48
86#define MAC_SUBTYPE_DATA_CFACK_NULL 0x58
87#define MAC_SUBTYPE_DATA_CFPOLL_NULL 0x68
88#define MAC_SUBTYPE_DATA_CFACK_CFPOLL_NULL 0x78
89
90/* ----- Frame Type of Bits (2, 3) */
91#define MAC_TYPE_MANAGEMENT 0x00
92#define MAC_TYPE_CONTROL 0x04
93#define MAC_TYPE_DATA 0x08
94
95/* ----- definitions for Management Frame Element ID (1 BYTE) */
96#define ELEMENT_ID_SSID 0
97#define ELEMENT_ID_SUPPORTED_RATES 1
98#define ELEMENT_ID_FH_PARAMETER_SET 2
99#define ELEMENT_ID_DS_PARAMETER_SET 3
100#define ELEMENT_ID_CF_PARAMETER_SET 4
101#define ELEMENT_ID_TIM 5
102#define ELEMENT_ID_IBSS_PARAMETER_SET 6
103/* 7~15 reserverd */
104#define ELEMENT_ID_CHALLENGE_TEXT 16
105/* 17~31 reserved for challenge text extension */
106/* 32~255 reserved */
107/*-- 11G -- */
108#define ELEMENT_ID_ERP_INFORMATION 42
109#define ELEMENT_ID_EXTENDED_SUPPORTED_RATES 50
110
111/* -- WPA -- */
112
113#define ELEMENT_ID_RSN_WPA 221
114#ifdef _WPA2_
115#define ELEMENT_ID_RSN_WPA2 48
116#endif /* endif WPA2 */
117
118#define WLAN_MAX_PAIRWISE_CIPHER_SUITE_COUNT ((u16) 6)
119#define WLAN_MAX_AUTH_KEY_MGT_SUITE_LIST_COUNT ((u16) 2)
120
121/* ===================================================================
122* Reason Code (Table 18): indicate the reason of DisAssoc, DeAuthen
123* length of ReasonCode is 2 Octs.
124* =================================================================== */
125#define REASON_REASERED 0
126#define REASON_UNSPECIDIED 1
127#define REASON_PREAUTH_INVALID 2
128#define DEAUTH_REASON_LEFT_BSS 3
129#define DISASS_REASON_AP_INACTIVE 4
130#define DISASS_REASON_AP_BUSY 5
131#define REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
132#define REASON_CLASS3_FRAME_FROM_NONASSO_STA 7
133#define DISASS_REASON_LEFT_BSS 8
134#define REASON_NOT_AUTH_YET 9
135/* 802.11i define */
136#define REASON_INVALID_IE 13
137#define REASON_MIC_ERROR 14
138#define REASON_4WAY_HANDSHAKE_TIMEOUT 15
139#define REASON_GROUPKEY_UPDATE_TIMEOUT 16
140#define REASON_IE_DIFF_4WAY_ASSOC 17
141#define REASON_INVALID_MULTICAST_CIPHER 18
142#define REASON_INVALID_UNICAST_CIPHER 19
143#define REASON_INVALID_AKMP 20
144#define REASON_UNSUPPORTED_RSNIE_VERSION 21
145#define REASON_INVALID_RSNIE_CAPABILITY 22
146#define REASON_802_1X_AUTH_FAIL 23
147#define REASON_CIPHER_REJECT_PER_SEC_POLICY 14
148
149/*
150//===========================================================
151// enum_MMPDUResultCode --
152// Status code (2 Octs) in the MMPDU's frame body. Table.19
153//
154//===========================================================
155enum enum_MMPDUResultCode
156{
157// SUCCESS = 0, // Redefined
158 UNSPECIFIED_FAILURE = 1,
159
160 // 2 - 9 Reserved
161
162 NOT_SUPPROT_CAPABILITIES = 10,
163
164 //REASSOCIATION_DENIED
165 //
166 REASSOC_DENIED_UNABLE_CFM_ASSOC_EXIST = 11,
167
168 //ASSOCIATION_DENIED_NOT_IN_STANDARD
169 //
170 ASSOC_DENIED_REASON_NOT_IN_STANDARD = 12,
171 PEER_NOT_SUPPORT_AUTH_ALGORITHM = 13,
172 AUTH_SEQNUM_OUT_OF_EXPECT = 14,
173 AUTH_REJECT_REASON_CHALLENGE_FAIL = 15,
174 AUTH_REJECT_REASON_WAIT_TIMEOUT = 16,
175 ASSOC_DENIED_REASON_AP_BUSY = 17,
176 ASSOC_DENIED_REASON_NOT_SUPPORT_BASIC_RATE = 18
177} WB_MMPDURESULTCODE, *PWB_MMPDURESULTCODE;
178*/
179
180#define RATE_BITMAP_1M 1
181#define RATE_BITMAP_2M 2
182#define RATE_BITMAP_5dot5M 5
183#define RATE_BITMAP_6M 6
184#define RATE_BITMAP_9M 9
185#define RATE_BITMAP_11M 11
186#define RATE_BITMAP_12M 12
187#define RATE_BITMAP_18M 18
188#define RATE_BITMAP_22M 22
189#define RATE_BITMAP_24M 24
190#define RATE_BITMAP_33M 17
191#define RATE_BITMAP_36M 19
192#define RATE_BITMAP_48M 25
193#define RATE_BITMAP_54M 28
194
195#define RATE_AUTO 0 54#define RATE_AUTO 0
196#define RATE_1M 2 55#define RATE_1M 2
197#define RATE_2M 4 56#define RATE_2M 4
@@ -209,408 +68,4 @@ enum enum_MMPDUResultCode
209#define RATE_54M 108 68#define RATE_54M 108
210#define RATE_MAX 255 69#define RATE_MAX 255
211 70
212/* CAPABILITY */
213#define CAPABILITY_ESS_BIT 0x0001
214#define CAPABILITY_IBSS_BIT 0x0002
215#define CAPABILITY_CF_POLL_BIT 0x0004
216#define CAPABILITY_CF_POLL_REQ_BIT 0x0008
217#define CAPABILITY_PRIVACY_BIT 0x0010
218#define CAPABILITY_SHORT_PREAMBLE_BIT 0x0020
219#define CAPABILITY_PBCC_BIT 0x0040
220#define CAPABILITY_CHAN_AGILITY_BIT 0x0080
221#define CAPABILITY_SHORT_SLOT_TIME_BIT 0x0400
222#define CAPABILITY_DSSS_OFDM_BIT 0x2000
223
224
225struct Capability_Information_Element {
226 union {
227 u16 __attribute__ ((packed)) wValue;
228 #ifdef _BIG_ENDIAN_ /* 20060926 add by anson's endian */
229 struct _Capability {
230 /* -- 11G -- */
231 u8 Reserved3:2;
232 u8 DSSS_OFDM:1;
233 u8 Reserved2:2;
234 u8 Short_Slot_Time:1;
235 u8 Reserved1:2;
236 u8 Channel_Agility:1;
237 u8 PBCC:1;
238 u8 ShortPreamble:1;
239 u8 CF_Privacy:1;
240 u8 CF_Poll_Request:1;
241 u8 CF_Pollable:1;
242 u8 IBSS:1;
243 u8 ESS:1;
244 } __attribute__ ((packed)) Capability;
245 #else
246 struct _Capability {
247 u8 ESS:1;
248 u8 IBSS:1;
249 u8 CF_Pollable:1;
250 u8 CF_Poll_Request:1;
251 u8 CF_Privacy:1;
252 u8 ShortPreamble:1;
253 u8 PBCC:1;
254 u8 Channel_Agility:1;
255 u8 Reserved1:2;
256 /* -- 11G -- */
257 u8 Short_Slot_Time:1;
258 u8 Reserved2:2;
259 u8 DSSS_OFDM:1;
260 u8 Reserved3:2;
261 } __attribute__ ((packed)) Capability;
262 #endif
263 } __attribute__ ((packed)) ;
264} __attribute__ ((packed));
265
266struct FH_Parameter_Set_Element {
267 u8 Element_ID;
268 u8 Length;
269 u8 Dwell_Time[2];
270 u8 Hop_Set;
271 u8 Hop_Pattern;
272 u8 Hop_Index;
273};
274
275struct DS_Parameter_Set_Element {
276 u8 Element_ID;
277 u8 Length;
278 u8 Current_Channel;
279};
280
281struct Supported_Rates_Element {
282 u8 Element_ID;
283 u8 Length;
284 u8 SupportedRates[8];
285} __attribute__ ((packed));
286
287struct SSID_Element {
288 u8 Element_ID;
289 u8 Length;
290 u8 SSID[32];
291} __attribute__ ((packed)) ;
292
293struct CF_Parameter_Set_Element {
294 u8 Element_ID;
295 u8 Length;
296 u8 CFP_Count;
297 u8 CFP_Period;
298 u8 CFP_MaxDuration[2]; /* in Time Units */
299 u8 CFP_DurRemaining[2]; /* in time units */
300};
301
302struct TIM_Element {
303 u8 Element_ID;
304 u8 Length;
305 u8 DTIM_Count;
306 u8 DTIM_Period;
307 u8 Bitmap_Control;
308 u8 Partial_Virtual_Bitmap[251];
309};
310
311struct IBSS_Parameter_Set_Element {
312 u8 Element_ID;
313 u8 Length;
314 u8 ATIM_Window[2];
315};
316
317struct Challenge_Text_Element {
318 u8 Element_ID;
319 u8 Length;
320 u8 Challenge_Text[253];
321};
322
323struct PHY_Parameter_Set_Element {
324/* int aSlotTime; */
325/* int aSifsTime; */
326 s32 aCCATime;
327 s32 aRxTxTurnaroundTime;
328 s32 aTxPLCPDelay;
329 s32 RxPLCPDelay;
330 s32 aRxTxSwitchTime;
331 s32 aTxRampOntime;
332 s32 aTxRampOffTime;
333 s32 aTxRFDelay;
334 s32 aRxRFDelay;
335 s32 aAirPropagationTime;
336 s32 aMACProcessingDelay;
337 s32 aPreambleLength;
338 s32 aPLCPHeaderLength;
339 s32 aMPDUDurationFactor;
340 s32 aMPDUMaxLength;
341/* int aCWmin; */
342/* int aCWmax; */
343};
344
345/* -- 11G -- */
346struct ERP_Information_Element {
347 u8 Element_ID;
348 u8 Length;
349 #ifdef _BIG_ENDIAN_ /* 20060926 add by anson's endian */
350 u8 Reserved:5; /* 20060926 add by anson */
351 u8 Barker_Preamble_Mode:1;
352 u8 Use_Protection:1;
353 u8 NonERP_Present:1;
354 #else
355 u8 NonERP_Present:1;
356 u8 Use_Protection:1;
357 u8 Barker_Preamble_Mode:1;
358 u8 Reserved:5;
359 #endif
360};
361
362struct Extended_Supported_Rates_Element {
363 u8 Element_ID;
364 u8 Length;
365 u8 ExtendedSupportedRates[255];
366} __attribute__ ((packed));
367
368/* WPA(802.11i draft 3.0) */
369#define VERSION_WPA 1
370#ifdef _WPA2_
371#define VERSION_WPA2 1
372#endif /* end def _WPA2_ */
373/* WPA2.0 OUI=00:50:F2, the MSB is reserved for suite type */
374#define OUI_WPA 0x00F25000
375#ifdef _WPA2_
376/* for wpa2 change to 0x00ACOF04 by Ws 26/04/04 */
377#define OUI_WPA2 0x00AC0F00
378#endif /* end def _WPA2_ */
379
380#define OUI_WPA_ADDITIONAL 0x01
381#define WLAN_MIN_RSN_WPA_LENGTH 6 /* added by ws 09/10/04 */
382#ifdef _WPA2_
383#define WLAN_MIN_RSN_WPA2_LENGTH 2 /* Fix to 2 09/14/05 */
384#endif /* end def _WPA2_ */
385
386#define oui_wpa (u32)(OUI_WPA|OUI_WPA_ADDITIONAL)
387
388#define WPA_OUI_BIG ((u32) 0x01F25000)/* added by ws 09/23/04 */
389#define WPA_OUI_LITTLE ((u32) 0x01F25001)/* added by ws 09/23/04 */
390/* 20061108 For WPS. It's little endian. Big endian is 0x0050F204 */
391#define WPA_WPS_OUI cpu_to_le32(0x04F25000)
392
393/* -----WPA2----- */
394#ifdef _WPA2_
395#define WPA2_OUI_BIG ((u32)0x01AC0F00)
396#define WPA2_OUI_LITTLE ((u32)0x01AC0F01)
397#endif /* end def _WPA2_ */
398
399/* Authentication suite */
400#define OUI_AUTH_WPA_NONE 0x00 /* for WPA_NONE */
401#define OUI_AUTH_8021X 0x01
402#define OUI_AUTH_PSK 0x02
403/* Cipher suite */
404#define OUI_CIPHER_GROUP_KEY 0x00 /* added by ws 05/21/04 */
405#define OUI_CIPHER_WEP_40 0x01
406#define OUI_CIPHER_TKIP 0x02
407#define OUI_CIPHER_CCMP 0x04
408#define OUI_CIPHER_WEP_104 0x05
409
410struct suite_selector{
411 union{
412 u8 Value[4];
413 struct _SUIT_ {
414 u8 OUI[3];
415 u8 Type;
416 } SuitSelector;
417 };
418};
419
420/* -- WPA -- */
421struct RSN_Information_Element{
422 u8 Element_ID;
423 u8 Length;
424 /* WPA version 2.0 additional field, and should be 00:50:F2:01 */
425 struct suite_selector OuiWPAAdditional;
426 u16 Version;
427 struct suite_selector GroupKeySuite;
428 u16 PairwiseKeySuiteCount;
429 struct suite_selector PairwiseKeySuite[1];
430} __attribute__ ((packed));
431struct RSN_Auth_Sub_Information_Element {
432 u16 AuthKeyMngtSuiteCount;
433 struct suite_selector AuthKeyMngtSuite[1];
434} __attribute__ ((packed));
435
436/* -- WPA2 -- */
437struct RSN_Capability_Element {
438 union {
439 u16 __attribute__ ((packed)) wValue;
440 #ifdef _BIG_ENDIAN_ /* 20060927 add by anson's endian */
441 struct _RSN_Capability {
442 u16 __attribute__ ((packed)) Reserved2:8; /* 20051201 */
443 u16 __attribute__ ((packed)) Reserved1:2;
444 u16 __attribute__ ((packed)) GTK_Replay_Counter:2;
445 u16 __attribute__ ((packed)) PTK_Replay_Counter:2;
446 u16 __attribute__ ((packed)) No_Pairwise:1;
447 u16 __attribute__ ((packed)) Pre_Auth:1;
448 } __attribute__ ((packed)) RSN_Capability;
449 #else
450 struct _RSN_Capability {
451 u16 __attribute__ ((packed)) Pre_Auth:1;
452 u16 __attribute__ ((packed)) No_Pairwise:1;
453 u16 __attribute__ ((packed)) PTK_Replay_Counter:2;
454 u16 __attribute__ ((packed)) GTK_Replay_Counter:2;
455 u16 __attribute__ ((packed)) Reserved1:2;
456 u16 __attribute__ ((packed)) Reserved2:8; /* 20051201 */
457 } __attribute__ ((packed)) RSN_Capability;
458 #endif
459
460 } __attribute__ ((packed)) ;
461} __attribute__ ((packed)) ;
462
463#ifdef _WPA2_
464struct pmkid {
465 u8 pValue[16];
466};
467
468struct WPA2_RSN_Information_Element {
469 u8 Element_ID;
470 u8 Length;
471 u16 Version;
472 struct suite_selector GroupKeySuite;
473 u16 PairwiseKeySuiteCount;
474 struct suite_selector PairwiseKeySuite[1];
475
476} __attribute__ ((packed));
477
478struct WPA2_RSN_Auth_Sub_Information_Element {
479 u16 AuthKeyMngtSuiteCount;
480 struct suite_selector AuthKeyMngtSuite[1];
481} __attribute__ ((packed));
482
483
484struct PMKID_Information_Element {
485 u16 PMKID_Count;
486 struct pmkid pmkid[16];
487} __attribute__ ((packed));
488
489#endif /* enddef _WPA2_ */
490/*============================================================
491// MAC Frame structure (different type) and subfield structure
492//============================================================*/
493struct MAC_frame_control {
494/* a combination of the [Protocol Version, Control Type, Control Subtype]*/
495 u8 mac_frame_info;
496/* 20060927 add by anson's endian */
497 #ifdef _BIG_ENDIAN_
498 u8 order:1;
499 u8 WEP:1;
500 u8 more_data:1;
501 u8 pwr_mgt:1;
502 u8 retry:1;
503 u8 more_frag:1;
504 u8 from_ds:1;
505 u8 to_ds:1;
506 #else
507 u8 to_ds:1;
508 u8 from_ds:1;
509 u8 more_frag:1;
510 u8 retry:1;
511 u8 pwr_mgt:1;
512 u8 more_data:1;
513 u8 WEP:1;
514 u8 order:1;
515 #endif
516} __attribute__ ((packed));
517
518struct Management_Frame {
519/* 2B, ToDS,FromDS,MoreFrag,MoreData,Order=0 */
520 struct MAC_frame_control frame_control;
521 u16 duration;
522 u8 DA[MAC_ADDR_LENGTH]; /* Addr1 */
523 u8 SA[MAC_ADDR_LENGTH]; /* Addr2 */
524 u8 BSSID[MAC_ADDR_LENGTH]; /* Addr3 */
525 u16 Sequence_Control;
526 /* Management Frame Body <= 325 bytes */
527 /* FCS 4 bytes */
528} __attribute__ ((packed));
529
530/* SW-MAC don't Tx/Rx Control-Frame, HW-MAC do it. */
531struct Control_Frame {
532/* ToDS,FromDS,MoreFrag,Retry,MoreData,WEP,Order=0 */
533 struct MAC_frame_control frame_control;
534 u16 duration;
535 u8 RA[MAC_ADDR_LENGTH];
536 u8 TA[MAC_ADDR_LENGTH];
537 u16 FCS;
538} __attribute__ ((packed));
539
540struct Data_Frame {
541 struct MAC_frame_control frame_control;
542 u16 duration;
543 u8 Addr1[MAC_ADDR_LENGTH];
544 u8 Addr2[MAC_ADDR_LENGTH];
545 u8 Addr3[MAC_ADDR_LENGTH];
546 u16 Sequence_Control;
547 u8 Addr4[MAC_ADDR_LENGTH]; /* only exist when ToDS=FromDS=1 */
548 /* Data Frame Body <= 2312 */
549 /* FCS */
550} __attribute__ ((packed));
551
552struct Disassociation_Frame_Body {
553 u16 reasonCode;
554} __attribute__ ((packed));
555
556struct Association_Request_Frame_Body {
557 u16 capability_information;
558 u16 listenInterval;
559 u8 Current_AP_Address[MAC_ADDR_LENGTH];/* for reassociation only */
560 /* SSID (2+32 bytes) */
561 /* Supported_Rates (2+8 bytes) */
562} __attribute__ ((packed));
563
564struct Association_Response_Frame_Body {
565 u16 capability_information;
566 u16 statusCode;
567 u16 Association_ID;
568 struct Supported_Rates_Element supportedRates;
569} __attribute__ ((packed));
570
571/*struct Reassociation_Request_Frame_Body
572{
573 u16 capability_information;
574 u16 listenInterval;
575 u8 Current_AP_Address[MAC_ADDR_LENGTH];
576 // SSID (2+32 bytes)
577 // Supported_Rates (2+8 bytes)
578};*/
579/* eliminated by WS 07/22/04 comboined with associateion request frame. */
580
581struct Reassociation_Response_Frame_Body {
582 u16 capability_information;
583 u16 statusCode;
584 u16 Association_ID;
585 struct Supported_Rates_Element supportedRates;
586} __attribute__ ((packed));
587
588struct Deauthentication_Frame_Body {
589 u16 reasonCode;
590} __attribute__ ((packed));
591
592
593struct Probe_Response_Frame_Body {
594 u16 Timestamp;
595 u16 Beacon_Interval;
596 u16 Capability_Information;
597 /* SSID
598 // Supported_Rates
599 // PHY parameter Set (DS Parameters)
600 // CF parameter Set
601 // IBSS parameter Set */
602} __attribute__ ((packed));
603
604struct Authentication_Frame_Body {
605 u16 algorithmNumber;
606 u16 sequenceNumber;
607 u16 statusCode;
608 /* NB: don't include ChallengeText in this structure
609 // struct Challenge_Text_Element sChallengeTextElement;
610 // wkchen added */
611} __attribute__ ((packed));
612
613
614#endif /* _MAC_Structure_H_ */ 71#endif /* _MAC_Structure_H_ */
615
616
diff --git a/drivers/staging/winbond/mds.c b/drivers/staging/winbond/mds.c
index 9217762b1814..9cfea94bcea5 100644
--- a/drivers/staging/winbond/mds.c
+++ b/drivers/staging/winbond/mds.c
@@ -1,9 +1,7 @@
1#include "mds_f.h" 1#include "mds_f.h"
2#include "mlmetxrx_f.h"
3#include "mto.h" 2#include "mto.h"
4#include "sysdef.h" 3#include "wbhal.h"
5#include "wbhal_f.h" 4#include "wb35tx_f.h"
6#include "wblinux_f.h"
7 5
8unsigned char 6unsigned char
9Mds_initial(struct wbsoft_priv *adapter) 7Mds_initial(struct wbsoft_priv *adapter)
@@ -17,11 +15,6 @@ Mds_initial(struct wbsoft_priv *adapter)
17 return hal_get_tx_buffer(&adapter->sHwData, &pMds->pTxBuffer); 15 return hal_get_tx_buffer(&adapter->sHwData, &pMds->pTxBuffer);
18} 16}
19 17
20void
21Mds_Destroy(struct wbsoft_priv *adapter)
22{
23}
24
25static void Mds_DurationSet(struct wbsoft_priv *adapter, struct wb35_descriptor *pDes, u8 *buffer) 18static void Mds_DurationSet(struct wbsoft_priv *adapter, struct wb35_descriptor *pDes, u8 *buffer)
26{ 19{
27 struct T00_descriptor *pT00; 20 struct T00_descriptor *pT00;
@@ -350,9 +343,7 @@ static void Mds_HeaderCopy(struct wbsoft_priv *adapter, struct wb35_descriptor *
350 ctmp1 = ctmpf = CURRENT_TX_RATE_FOR_MNG; 343 ctmp1 = ctmpf = CURRENT_TX_RATE_FOR_MNG;
351 344
352 pDes->TxRate = ctmp1; 345 pDes->TxRate = ctmp1;
353 #ifdef _PE_TX_DUMP_ 346 pr_debug("Tx rate =%x\n", ctmp1);
354 printk("Tx rate =%x\n", ctmp1);
355 #endif
356 347
357 pT01->T01_modulation_type = (ctmp1%3) ? 0 : 1; 348 pT01->T01_modulation_type = (ctmp1%3) ? 0 : 1;
358 349
@@ -404,6 +395,44 @@ static void Mds_HeaderCopy(struct wbsoft_priv *adapter, struct wb35_descriptor *
404 395
405} 396}
406 397
398static void MLME_GetNextPacket(struct wbsoft_priv *adapter, struct wb35_descriptor *desc)
399{
400 desc->InternalUsed = desc->buffer_start_index + desc->buffer_number;
401 desc->InternalUsed %= MAX_DESCRIPTOR_BUFFER_INDEX;
402 desc->buffer_address[desc->InternalUsed] = adapter->sMlmeFrame.pMMPDU;
403 desc->buffer_size[desc->InternalUsed] = adapter->sMlmeFrame.len;
404 desc->buffer_total_size += adapter->sMlmeFrame.len;
405 desc->buffer_number++;
406 desc->Type = adapter->sMlmeFrame.DataType;
407}
408
409static void MLMEfreeMMPDUBuffer(struct wbsoft_priv *adapter, s8 *pData)
410{
411 int i;
412
413 /* Reclaim the data buffer */
414 for (i = 0; i < MAX_NUM_TX_MMPDU; i++) {
415 if (pData == (s8 *)&(adapter->sMlmeFrame.TxMMPDU[i]))
416 break;
417 }
418 if (adapter->sMlmeFrame.TxMMPDUInUse[i])
419 adapter->sMlmeFrame.TxMMPDUInUse[i] = false;
420 else {
421 /* Something wrong
422 PD43 Add debug code here??? */
423 }
424}
425
426static void MLME_SendComplete(struct wbsoft_priv *adapter, u8 PacketID, unsigned char SendOK)
427{
428 /* Reclaim the data buffer */
429 adapter->sMlmeFrame.len = 0;
430 MLMEfreeMMPDUBuffer(adapter, adapter->sMlmeFrame.pMMPDU);
431
432 /* Return resource */
433 adapter->sMlmeFrame.IsInUsed = PACKET_FREE_TO_USE;
434}
435
407void 436void
408Mds_Tx(struct wbsoft_priv *adapter) 437Mds_Tx(struct wbsoft_priv *adapter)
409{ 438{
@@ -430,9 +459,7 @@ Mds_Tx(struct wbsoft_priv *adapter)
430 do { 459 do {
431 FillIndex = pMds->TxFillIndex; 460 FillIndex = pMds->TxFillIndex;
432 if (pMds->TxOwner[FillIndex]) { /* Is owned by software 0:Yes 1:No */ 461 if (pMds->TxOwner[FillIndex]) { /* Is owned by software 0:Yes 1:No */
433#ifdef _PE_TX_DUMP_ 462 pr_debug("[Mds_Tx] Tx Owner is H/W.\n");
434 printk("[Mds_Tx] Tx Owner is H/W.\n");
435#endif
436 break; 463 break;
437 } 464 }
438 465
@@ -476,9 +503,7 @@ Mds_Tx(struct wbsoft_priv *adapter)
476 503
477 /* For speed up Key setting */ 504 /* For speed up Key setting */
478 if (pTxDes->EapFix) { 505 if (pTxDes->EapFix) {
479#ifdef _PE_TX_DUMP_ 506 pr_debug("35: EPA 4th frame detected. Size = %d\n", PacketSize);
480 printk("35: EPA 4th frame detected. Size = %d\n", PacketSize);
481#endif
482 pHwData->IsKeyPreSet = 1; 507 pHwData->IsKeyPreSet = 1;
483 } 508 }
484 509
@@ -492,11 +517,6 @@ Mds_Tx(struct wbsoft_priv *adapter)
492 XmitBufSize += CurrentSize; 517 XmitBufSize += CurrentSize;
493 XmitBufAddress += CurrentSize; 518 XmitBufAddress += CurrentSize;
494 519
495#ifdef _IBSS_BEACON_SEQ_STICK_
496 if ((XmitBufAddress[DOT_11_DA_OFFSET+8] & 0xfc) != MAC_SUBTYPE_MNGMNT_PROBE_REQUEST) /* +8 for USB hdr */
497#endif
498 pMds->TxToggle = true;
499
500 /* Get packet to transmit completed, 1:TESTSTA 2:MLME 3: Ndis data */ 520 /* Get packet to transmit completed, 1:TESTSTA 2:MLME 3: Ndis data */
501 MLME_SendComplete(adapter, 0, true); 521 MLME_SendComplete(adapter, 0, true);
502 522
@@ -567,9 +587,7 @@ Mds_SendComplete(struct wbsoft_priv *adapter, struct T02_descriptor *pT02)
567 pHwData->tx_retry_count[RetryCount] += RetryCount; 587 pHwData->tx_retry_count[RetryCount] += RetryCount;
568 else 588 else
569 pHwData->tx_retry_count[7] += RetryCount; 589 pHwData->tx_retry_count[7] += RetryCount;
570 #ifdef _PE_STATE_DUMP_ 590 pr_debug("dto_tx_retry_count =%d\n", pHwData->dto_tx_retry_count);
571 printk("dto_tx_retry_count =%d\n", pHwData->dto_tx_retry_count);
572 #endif
573 MTO_SetTxCount(adapter, TxRate, RetryCount); 591 MTO_SetTxCount(adapter, TxRate, RetryCount);
574 } 592 }
575 pHwData->dto_tx_frag_count += (RetryCount+1); 593 pHwData->dto_tx_frag_count += (RetryCount+1);
diff --git a/drivers/staging/winbond/mds_f.h b/drivers/staging/winbond/mds_f.h
index 7f68deae6d04..ce8be079e957 100644
--- a/drivers/staging/winbond/mds_f.h
+++ b/drivers/staging/winbond/mds_f.h
@@ -1,11 +1,10 @@
1#ifndef __WINBOND_MDS_F_H 1#ifndef __WINBOND_MDS_F_H
2#define __WINBOND_MDS_F_H 2#define __WINBOND_MDS_F_H
3 3
4#include "wbhal_s.h" 4#include "wbhal.h"
5#include "core.h" 5#include "core.h"
6 6
7unsigned char Mds_initial(struct wbsoft_priv *adapter); 7unsigned char Mds_initial(struct wbsoft_priv *adapter);
8void Mds_Destroy(struct wbsoft_priv *adapter);
9void Mds_Tx(struct wbsoft_priv *adapter); 8void Mds_Tx(struct wbsoft_priv *adapter);
10void Mds_SendComplete(struct wbsoft_priv *adapter, struct T02_descriptor *pt02); 9void Mds_SendComplete(struct wbsoft_priv *adapter, struct T02_descriptor *pt02);
11void Mds_MpduProcess(struct wbsoft_priv *adapter, struct wb35_descriptor *prxdes); 10void Mds_MpduProcess(struct wbsoft_priv *adapter, struct wb35_descriptor *prxdes);
diff --git a/drivers/staging/winbond/mds_s.h b/drivers/staging/winbond/mds_s.h
index e2de4bd23b4d..eeedf0186365 100644
--- a/drivers/staging/winbond/mds_s.h
+++ b/drivers/staging/winbond/mds_s.h
@@ -107,10 +107,6 @@ struct wb35_mds {
107 u8 TxRate[((MAX_USB_TX_DESCRIPTOR + 1) & ~0x01)][2]; /* [0] current tx rate, [1] fall back rate */ 107 u8 TxRate[((MAX_USB_TX_DESCRIPTOR + 1) & ~0x01)][2]; /* [0] current tx rate, [1] fall back rate */
108 u8 TxInfo[((MAX_USB_TX_DESCRIPTOR + 1) & ~0x01)]; /*Store information for callback function */ 108 u8 TxInfo[((MAX_USB_TX_DESCRIPTOR + 1) & ~0x01)]; /*Store information for callback function */
109 109
110 /* for scanning mechanism */
111 u8 TxToggle; /* It is TRUE if there are tx activities in some time interval */
112 u8 Reserved_[3];
113
114 /* ---- for Tx Parameter */ 110 /* ---- for Tx Parameter */
115 u16 TxFragmentThreshold; /* For frame body only */ 111 u16 TxFragmentThreshold; /* For frame body only */
116 u16 TxRTSThreshold; 112 u16 TxRTSThreshold;
diff --git a/drivers/staging/winbond/mlmetxrx.c b/drivers/staging/winbond/mlmetxrx.c
deleted file mode 100644
index 7425a23f12e8..000000000000
--- a/drivers/staging/winbond/mlmetxrx.c
+++ /dev/null
@@ -1,62 +0,0 @@
1/* ============================================================================
2 Module Name:
3 MLMETxRx.C
4
5 Description:
6 The interface between MDS (MAC Data Service) and MLME.
7
8 Revision History:
9 --------------------------------------------------------------------------
10 200209 UN20 Jennifer Xu
11 Initial Release
12 20021108 PD43 Austin Liu
13 20030117 PD43 Austin Liu
14 Deleted MLMEReturnPacket and MLMEProcThread()
15
16 Copyright (c) 1996-2002 Winbond Electronics Corp. All Rights Reserved.
17============================================================================ */
18#include "sysdef.h"
19
20#include "mds_f.h"
21
22void MLME_GetNextPacket(struct wbsoft_priv *adapter, struct wb35_descriptor *desc)
23{
24 desc->InternalUsed = desc->buffer_start_index + desc->buffer_number;
25 desc->InternalUsed %= MAX_DESCRIPTOR_BUFFER_INDEX;
26 desc->buffer_address[desc->InternalUsed] = adapter->sMlmeFrame.pMMPDU;
27 desc->buffer_size[desc->InternalUsed] = adapter->sMlmeFrame.len;
28 desc->buffer_total_size += adapter->sMlmeFrame.len;
29 desc->buffer_number++;
30 desc->Type = adapter->sMlmeFrame.DataType;
31}
32
33static void MLMEfreeMMPDUBuffer(struct wbsoft_priv *adapter, s8 *pData)
34{
35 int i;
36
37 /* Reclaim the data buffer */
38 for (i = 0; i < MAX_NUM_TX_MMPDU; i++) {
39 if (pData == (s8 *)&(adapter->sMlmeFrame.TxMMPDU[i]))
40 break;
41 }
42 if (adapter->sMlmeFrame.TxMMPDUInUse[i])
43 adapter->sMlmeFrame.TxMMPDUInUse[i] = false;
44 else {
45 /* Something wrong
46 PD43 Add debug code here??? */
47 }
48}
49
50void
51MLME_SendComplete(struct wbsoft_priv *adapter, u8 PacketID, unsigned char SendOK)
52{
53 /* Reclaim the data buffer */
54 adapter->sMlmeFrame.len = 0;
55 MLMEfreeMMPDUBuffer(adapter, adapter->sMlmeFrame.pMMPDU);
56
57 /* Return resource */
58 adapter->sMlmeFrame.IsInUsed = PACKET_FREE_TO_USE;
59}
60
61
62
diff --git a/drivers/staging/winbond/mlmetxrx_f.h b/drivers/staging/winbond/mlmetxrx_f.h
deleted file mode 100644
index 012507fc49e3..000000000000
--- a/drivers/staging/winbond/mlmetxrx_f.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/* ================================================================
2// MLMETxRx.H --
3//
4// Functions defined in MLMETxRx.c.
5//
6// Copyright (c) 2002 Winbond Electrics Corp. All Rights Reserved.
7//================================================================ */
8#ifndef _MLMETXRX_H
9#define _MLMETXRX_H
10
11#include "core.h"
12
13void MLME_GetNextPacket(struct wbsoft_priv *adapter, struct wb35_descriptor *pDes);
14
15void
16MLME_SendComplete(struct wbsoft_priv *adapter, u8 PacketID,
17 unsigned char SendOK);
18
19#ifdef _IBSS_BEACON_SEQ_STICK_
20s8 SendBCNullData(struct wbsoft_priv *adapter, u16 wIdx);
21#endif
22
23#endif
diff --git a/drivers/staging/winbond/mto.c b/drivers/staging/winbond/mto.c
index 9cd212783d61..c03e5010ca34 100644
--- a/drivers/staging/winbond/mto.c
+++ b/drivers/staging/winbond/mto.c
@@ -17,9 +17,10 @@
17 * ============================================================================ 17 * ============================================================================
18 */ 18 */
19 19
20#include "sysdef.h"
21#include "sme_api.h" 20#include "sme_api.h"
22#include "wbhal_f.h" 21#include "wbhal.h"
22#include "wb35reg_f.h"
23#include "core.h"
23 24
24/* Declare SQ3 to rate and fragmentation threshold table */ 25/* Declare SQ3 to rate and fragmentation threshold table */
25/* Declare fragmentation thresholds table */ 26/* Declare fragmentation thresholds table */
diff --git a/drivers/staging/winbond/phy_calibration.c b/drivers/staging/winbond/phy_calibration.c
index 2b375ba3812a..09844db64fe9 100644
--- a/drivers/staging/winbond/phy_calibration.c
+++ b/drivers/staging/winbond/phy_calibration.c
@@ -10,9 +10,10 @@
10 */ 10 */
11 11
12/****************** INCLUDE FILES SECTION ***********************************/ 12/****************** INCLUDE FILES SECTION ***********************************/
13#include "sysdef.h"
14#include "phy_calibration.h" 13#include "phy_calibration.h"
15#include "wbhal_f.h" 14#include "wbhal.h"
15#include "wb35reg_f.h"
16#include "core.h"
16 17
17 18
18/****************** DEBUG CONSTANT AND MACRO SECTION ************************/ 19/****************** DEBUG CONSTANT AND MACRO SECTION ************************/
diff --git a/drivers/staging/winbond/phy_calibration.h b/drivers/staging/winbond/phy_calibration.h
index 303203148839..84f6e840a47a 100644
--- a/drivers/staging/winbond/phy_calibration.h
+++ b/drivers/staging/winbond/phy_calibration.h
@@ -1,7 +1,7 @@
1#ifndef __WINBOND_PHY_CALIBRATION_H 1#ifndef __WINBOND_PHY_CALIBRATION_H
2#define __WINBOND_PHY_CALIBRATION_H 2#define __WINBOND_PHY_CALIBRATION_H
3 3
4#include "wbhal_f.h" 4#include "wbhal.h"
5 5
6#define REG_AGC_CTRL1 0x1000 6#define REG_AGC_CTRL1 0x1000
7#define REG_AGC_CTRL2 0x1004 7#define REG_AGC_CTRL2 0x1004
diff --git a/drivers/staging/winbond/reg.c b/drivers/staging/winbond/reg.c
index 990f9d4bdbbd..1b38d6d225c9 100644
--- a/drivers/staging/winbond/reg.c
+++ b/drivers/staging/winbond/reg.c
@@ -1,5 +1,6 @@
1#include "sysdef.h" 1#include "wbhal.h"
2#include "wbhal_f.h" 2#include "wb35reg_f.h"
3#include "core.h"
3 4
4/* 5/*
5 * ==================================================== 6 * ====================================================
@@ -1010,9 +1011,7 @@ void RFSynthesizer_initial(struct hw_data *pHwData)
1010 case RF_AIROHA_7230: 1011 case RF_AIROHA_7230:
1011 /* Start to fill RF parameters, PLL_ON should be pulled low. */ 1012 /* Start to fill RF parameters, PLL_ON should be pulled low. */
1012 Wb35Reg_WriteSync(pHwData, 0x03dc, 0x00000000); 1013 Wb35Reg_WriteSync(pHwData, 0x03dc, 0x00000000);
1013 #ifdef _PE_STATE_DUMP_ 1014 pr_debug("* PLL_ON low\n");
1014 printk("* PLL_ON low\n");
1015 #endif
1016 number = ARRAY_SIZE(al7230_rf_data_24); 1015 number = ARRAY_SIZE(al7230_rf_data_24);
1017 Set_ChanIndep_RfData_al7230_24(pHwData, pltmp, number); 1016 Set_ChanIndep_RfData_al7230_24(pHwData, pltmp, number);
1018 break; 1017 break;
@@ -1098,9 +1097,7 @@ void RFSynthesizer_initial(struct hw_data *pHwData)
1098 case RF_AIROHA_7230: 1097 case RF_AIROHA_7230:
1099 /* RF parameters have filled completely, PLL_ON should be pulled high */ 1098 /* RF parameters have filled completely, PLL_ON should be pulled high */
1100 Wb35Reg_WriteSync(pHwData, 0x03dc, 0x00000080); 1099 Wb35Reg_WriteSync(pHwData, 0x03dc, 0x00000080);
1101 #ifdef _PE_STATE_DUMP_ 1100 pr_debug("* PLL_ON high\n");
1102 printk("* PLL_ON high\n");
1103 #endif
1104 1101
1105 /* 2.4GHz */ 1102 /* 2.4GHz */
1106 ltmp = (1 << 31) | (0 << 30) | (24 << 24) | 0x9ABA8F; 1103 ltmp = (1 << 31) | (0 << 30) | (24 << 24) | 0x9ABA8F;
@@ -1115,9 +1112,7 @@ void RFSynthesizer_initial(struct hw_data *pHwData)
1115 1112
1116 /* 5GHz */ 1113 /* 5GHz */
1117 Wb35Reg_WriteSync(pHwData, 0x03dc, 0x00000000); 1114 Wb35Reg_WriteSync(pHwData, 0x03dc, 0x00000000);
1118 #ifdef _PE_STATE_DUMP_ 1115 pr_debug("* PLL_ON low\n");
1119 printk("* PLL_ON low\n");
1120 #endif
1121 1116
1122 number = ARRAY_SIZE(al7230_rf_data_50); 1117 number = ARRAY_SIZE(al7230_rf_data_50);
1123 Set_ChanIndep_RfData_al7230_50(pHwData, pltmp, number); 1118 Set_ChanIndep_RfData_al7230_50(pHwData, pltmp, number);
@@ -1127,9 +1122,7 @@ void RFSynthesizer_initial(struct hw_data *pHwData)
1127 msleep(5); 1122 msleep(5);
1128 1123
1129 Wb35Reg_WriteSync(pHwData, 0x03dc, 0x00000080); 1124 Wb35Reg_WriteSync(pHwData, 0x03dc, 0x00000080);
1130 #ifdef _PE_STATE_DUMP_ 1125 pr_debug("* PLL_ON high\n");
1131 printk("* PLL_ON high\n");
1132 #endif
1133 1126
1134 ltmp = (1 << 31) | (0 << 30) | (24 << 24) | 0x9ABA8F; 1127 ltmp = (1 << 31) | (0 << 30) | (24 << 24) | 0x9ABA8F;
1135 Wb35Reg_WriteSync(pHwData, 0x0864, ltmp); 1128 Wb35Reg_WriteSync(pHwData, 0x0864, ltmp);
@@ -1795,9 +1788,7 @@ void RFSynthesizer_SwitchingChannel(struct hw_data *pHwData, struct chan_info C
1795 1788
1796 /* Write to register. number must less and equal than 16 */ 1789 /* Write to register. number must less and equal than 16 */
1797 Wb35Reg_BurstWrite(pHwData, 0x0864, pltmp, number, NO_INCREMENT); 1790 Wb35Reg_BurstWrite(pHwData, 0x0864, pltmp, number, NO_INCREMENT);
1798 #ifdef _PE_STATE_DUMP_ 1791 pr_debug("Band changed\n");
1799 printk("Band changed\n");
1800 #endif
1801 } 1792 }
1802 1793
1803 if (Channel.band <= BAND_TYPE_OFDM_24) { /* channel 1 ~ 14 */ 1794 if (Channel.band <= BAND_TYPE_OFDM_24) { /* channel 1 ~ 14 */
@@ -2073,11 +2064,7 @@ void Mxx_initial(struct hw_data *pHwData)
2073 */ 2064 */
2074 2065
2075 /* M00 bit set */ 2066 /* M00 bit set */
2076 #ifdef _IBSS_BEACON_SEQ_STICK_
2077 reg->M00_MacControl = 0; /* Solve beacon sequence number stop by software */
2078 #else
2079 reg->M00_MacControl = 0x80000000; /* Solve beacon sequence number stop by hardware */ 2067 reg->M00_MacControl = 0x80000000; /* Solve beacon sequence number stop by hardware */
2080 #endif
2081 2068
2082 /* M24 disable enter power save, BB RxOn and enable NAV attack */ 2069 /* M24 disable enter power save, BB RxOn and enable NAV attack */
2083 reg->M24_MacControl = 0x08040042; 2070 reg->M24_MacControl = 0x08040042;
@@ -2336,13 +2323,6 @@ void EEPROMTxVgaAdjust(struct hw_data *pHwData)
2336 pHwData->TxVgaFor50[32].TxVgaValue = pTxVga[17] - stmp * 2 / 4; 2323 pHwData->TxVgaFor50[32].TxVgaValue = pTxVga[17] - stmp * 2 / 4;
2337 pHwData->TxVgaFor50[31].TxVgaValue = pTxVga[17] - stmp * 3 / 4; 2324 pHwData->TxVgaFor50[31].TxVgaValue = pTxVga[17] - stmp * 3 / 4;
2338 } 2325 }
2339
2340 #ifdef _PE_STATE_DUMP_
2341 printk(" TxVgaFor24 :\n");
2342 DataDmp((u8 *)pHwData->TxVgaFor24, 14 , 0);
2343 printk(" TxVgaFor50 :\n");
2344 DataDmp((u8 *)pHwData->TxVgaFor50, 70 , 0);
2345 #endif
2346} 2326}
2347 2327
2348void BBProcessor_RateChanging(struct hw_data *pHwData, u8 rate) 2328void BBProcessor_RateChanging(struct hw_data *pHwData, u8 rate)
diff --git a/drivers/staging/winbond/sysdef.h b/drivers/staging/winbond/sysdef.h
deleted file mode 100644
index d0d71f69bc8c..000000000000
--- a/drivers/staging/winbond/sysdef.h
+++ /dev/null
@@ -1,31 +0,0 @@
1/* Winbond WLAN System Configuration defines */
2
3#ifndef SYS_DEF_H
4#define SYS_DEF_H
5
6#include <linux/delay.h>
7
8#define WB_LINUX
9#define WB_LINUX_WPA_PSK
10
11#define _USE_FALLBACK_RATE_
12
13#define _WPA2_
14
15#ifndef _WPA_PSK_DEBUG
16#undef _WPA_PSK_DEBUG
17#endif
18
19/* debug print options, mark what debug you don't need */
20
21#ifdef FULL_DEBUG
22#define _PE_STATE_DUMP_
23#define _PE_TX_DUMP_
24#define _PE_RX_DUMP_
25#define _PE_OID_DUMP_
26#define _PE_DTO_DUMP_
27#define _PE_REG_DUMP_
28#define _PE_USB_INI_DUMP_
29#endif
30
31#endif
diff --git a/drivers/staging/winbond/wb35reg.c b/drivers/staging/winbond/wb35reg.c
index 770722385eeb..42ae61014522 100644
--- a/drivers/staging/winbond/wb35reg.c
+++ b/drivers/staging/winbond/wb35reg.c
@@ -1,4 +1,3 @@
1#include "sysdef.h"
2#include "wb35reg_f.h" 1#include "wb35reg_f.h"
3 2
4#include <linux/usb.h> 3#include <linux/usb.h>
@@ -140,8 +139,8 @@ unsigned char Wb35Reg_WriteSync(struct hw_data *pHwData, u16 RegisterNo, u32 Reg
140 139
141 /* Sync IoCallDriver */ 140 /* Sync IoCallDriver */
142 reg->EP0vm_state = VM_RUNNING; 141 reg->EP0vm_state = VM_RUNNING;
143 ret = usb_control_msg(pHwData->WbUsb.udev, 142 ret = usb_control_msg(pHwData->udev,
144 usb_sndctrlpipe(pHwData->WbUsb.udev, 0), 143 usb_sndctrlpipe(pHwData->udev, 0),
145 0x03, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, 144 0x03, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
146 0x0, RegisterNo, &RegisterValue, 4, HZ * 100); 145 0x0, RegisterNo, &RegisterValue, 4, HZ * 100);
147 reg->EP0vm_state = VM_STOP; 146 reg->EP0vm_state = VM_STOP;
@@ -150,9 +149,7 @@ unsigned char Wb35Reg_WriteSync(struct hw_data *pHwData, u16 RegisterNo, u32 Reg
150 Wb35Reg_EP0VM_start(pHwData); 149 Wb35Reg_EP0VM_start(pHwData);
151 150
152 if (ret < 0) { 151 if (ret < 0) {
153#ifdef _PE_REG_DUMP_ 152 pr_debug("EP0 Write register usb message sending error\n");
154 printk("EP0 Write register usb message sending error\n");
155#endif
156 pHwData->SurpriseRemove = 1; 153 pHwData->SurpriseRemove = 1;
157 return false; 154 return false;
158 } 155 }
@@ -305,8 +302,8 @@ unsigned char Wb35Reg_ReadSync(struct hw_data *pHwData, u16 RegisterNo, u32 *pRe
305 msleep(10); 302 msleep(10);
306 303
307 reg->EP0vm_state = VM_RUNNING; 304 reg->EP0vm_state = VM_RUNNING;
308 ret = usb_control_msg(pHwData->WbUsb.udev, 305 ret = usb_control_msg(pHwData->udev,
309 usb_rcvctrlpipe(pHwData->WbUsb.udev, 0), 306 usb_rcvctrlpipe(pHwData->udev, 0),
310 0x01, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 307 0x01, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
311 0x0, RegisterNo, pltmp, 4, HZ * 100); 308 0x0, RegisterNo, pltmp, 4, HZ * 100);
312 309
@@ -320,9 +317,7 @@ unsigned char Wb35Reg_ReadSync(struct hw_data *pHwData, u16 RegisterNo, u32 *pRe
320 Wb35Reg_EP0VM_start(pHwData); 317 Wb35Reg_EP0VM_start(pHwData);
321 318
322 if (ret < 0) { 319 if (ret < 0) {
323#ifdef _PE_REG_DUMP_ 320 pr_debug("EP0 Read register usb message sending error\n");
324 printk("EP0 Read register usb message sending error\n");
325#endif
326 pHwData->SurpriseRemove = 1; 321 pHwData->SurpriseRemove = 1;
327 return false; 322 return false;
328 } 323 }
@@ -432,8 +427,8 @@ void Wb35Reg_EP0VM(struct hw_data *pHwData)
432 if (reg_queue->DIRECT == 1) /* output */ 427 if (reg_queue->DIRECT == 1) /* output */
433 pBuffer = &reg_queue->VALUE; 428 pBuffer = &reg_queue->VALUE;
434 429
435 usb_fill_control_urb(urb, pHwData->WbUsb.udev, 430 usb_fill_control_urb(urb, pHwData->udev,
436 REG_DIRECTION(pHwData->WbUsb.udev, reg_queue), 431 REG_DIRECTION(pHwData->udev, reg_queue),
437 (u8 *)dr, pBuffer, cpu_to_le16(dr->wLength), 432 (u8 *)dr, pBuffer, cpu_to_le16(dr->wLength),
438 Wb35Reg_EP0VM_complete, (void *)pHwData); 433 Wb35Reg_EP0VM_complete, (void *)pHwData);
439 434
@@ -442,9 +437,7 @@ void Wb35Reg_EP0VM(struct hw_data *pHwData)
442 ret = usb_submit_urb(urb, GFP_ATOMIC); 437 ret = usb_submit_urb(urb, GFP_ATOMIC);
443 438
444 if (ret < 0) { 439 if (ret < 0) {
445#ifdef _PE_REG_DUMP_ 440 pr_debug("EP0 Irp sending error\n");
446 printk("EP0 Irp sending error\n");
447#endif
448 goto cleanup; 441 goto cleanup;
449 } 442 }
450 return; 443 return;
@@ -479,9 +472,7 @@ void Wb35Reg_EP0VM_complete(struct urb *urb)
479 spin_unlock_irq(&reg->EP0VM_spin_lock); 472 spin_unlock_irq(&reg->EP0VM_spin_lock);
480 473
481 if (reg->EP0VM_status) { 474 if (reg->EP0VM_status) {
482#ifdef _PE_REG_DUMP_ 475 pr_debug("EP0 IoCompleteRoutine return error\n");
483 printk("EP0 IoCompleteRoutine return error\n");
484#endif
485 reg->EP0vm_state = VM_STOP; 476 reg->EP0vm_state = VM_STOP;
486 pHwData->SurpriseRemove = 1; 477 pHwData->SurpriseRemove = 1;
487 } else { 478 } else {
@@ -526,9 +517,7 @@ void Wb35Reg_destroy(struct hw_data *pHwData)
526 usb_free_urb(urb); 517 usb_free_urb(urb);
527 kfree(reg_queue); 518 kfree(reg_queue);
528 } else { 519 } else {
529#ifdef _PE_REG_DUMP_ 520 pr_debug("EP0 queue release error\n");
530 printk("EP0 queue release error\n");
531#endif
532 } 521 }
533 spin_lock_irq(&reg->EP0VM_spin_lock); 522 spin_lock_irq(&reg->EP0VM_spin_lock);
534 523
diff --git a/drivers/staging/winbond/wb35reg_f.h b/drivers/staging/winbond/wb35reg_f.h
index bf23c1084199..95dc98096845 100644
--- a/drivers/staging/winbond/wb35reg_f.h
+++ b/drivers/staging/winbond/wb35reg_f.h
@@ -1,7 +1,7 @@
1#ifndef __WINBOND_WB35REG_F_H 1#ifndef __WINBOND_WB35REG_F_H
2#define __WINBOND_WB35REG_F_H 2#define __WINBOND_WB35REG_F_H
3 3
4#include "wbhal_s.h" 4#include "wbhal.h"
5 5
6/* 6/*
7 * ==================================== 7 * ====================================
diff --git a/drivers/staging/winbond/wb35reg_s.h b/drivers/staging/winbond/wb35reg_s.h
index 4eff009444b8..eb274ffdd1ba 100644
--- a/drivers/staging/winbond/wb35reg_s.h
+++ b/drivers/staging/winbond/wb35reg_s.h
@@ -5,6 +5,8 @@
5#include <linux/types.h> 5#include <linux/types.h>
6#include <asm/atomic.h> 6#include <asm/atomic.h>
7 7
8struct hw_data;
9
8/* ========================================================================= 10/* =========================================================================
9 * 11 *
10 * HAL setting function 12 * HAL setting function
@@ -49,11 +51,7 @@
49#define DEFAULT_CWMAX 1023 /* (M2C) CWmax. Its value is in the range 0-1023. */ 51#define DEFAULT_CWMAX 1023 /* (M2C) CWmax. Its value is in the range 0-1023. */
50#define DEFAULT_AID 1 /* (M34) AID. Its value is in the range 1-2007. */ 52#define DEFAULT_AID 1 /* (M34) AID. Its value is in the range 1-2007. */
51 53
52#ifdef _USE_FALLBACK_RATE_
53#define DEFAULT_RATE_RETRY_LIMIT 2 /* (M38) as named */ 54#define DEFAULT_RATE_RETRY_LIMIT 2 /* (M38) as named */
54#else
55#define DEFAULT_RATE_RETRY_LIMIT 7 /* (M38) as named */
56#endif
57 55
58#define DEFAULT_LONG_RETRY_LIMIT 7 /* (M38) LongRetryLimit. Its value is in the range 0-15. */ 56#define DEFAULT_LONG_RETRY_LIMIT 7 /* (M38) LongRetryLimit. Its value is in the range 0-15. */
59#define DEFAULT_SHORT_RETRY_LIMIT 7 /* (M38) ShortRetryLimit. Its value is in the range 0-15. */ 57#define DEFAULT_SHORT_RETRY_LIMIT 7 /* (M38) ShortRetryLimit. Its value is in the range 0-15. */
@@ -168,4 +166,75 @@ struct wb35_reg {
168 u32 SQ3_filter[MAX_SQ3_FILTER_SIZE]; 166 u32 SQ3_filter[MAX_SQ3_FILTER_SIZE];
169 u32 SQ3_index; 167 u32 SQ3_index;
170}; 168};
169
170/* =====================================================================
171 * Function declaration
172 * =====================================================================
173 */
174void hal_remove_mapping_key(struct hw_data *hw_data, u8 *mac_addr);
175void hal_remove_default_key(struct hw_data *hw_data, u32 index);
176unsigned char hal_set_mapping_key(struct hw_data *adapter, u8 *mac_addr,
177 u8 null_key, u8 wep_on, u8 *tx_tsc,
178 u8 *rx_tsc, u8 key_type, u8 key_len,
179 u8 *key_data);
180unsigned char hal_set_default_key(struct hw_data *adapter, u8 index,
181 u8 null_key, u8 wep_on, u8 *tx_tsc,
182 u8 *rx_tsc, u8 key_type, u8 key_len,
183 u8 *key_data);
184void hal_clear_all_default_key(struct hw_data *hw_data);
185void hal_clear_all_group_key(struct hw_data *hw_data);
186void hal_clear_all_mapping_key(struct hw_data *hw_data);
187void hal_clear_all_key(struct hw_data *hw_data);
188void hal_set_power_save_mode(struct hw_data *hw_data, unsigned char power_save,
189 unsigned char wakeup, unsigned char dtim);
190void hal_get_power_save_mode(struct hw_data *hw_data, u8 *in_pwr_save);
191void hal_set_slot_time(struct hw_data *hw_data, u8 type);
192
193#define hal_set_atim_window(_A, _ATM)
194
195void hal_start_bss(struct hw_data *hw_data, u8 mac_op_mode);
196
197/* 0:BSS STA 1:IBSS STA */
198void hal_join_request(struct hw_data *hw_data, u8 bss_type);
199
200void hal_stop_sync_bss(struct hw_data *hw_data);
201void hal_resume_sync_bss(struct hw_data *hw_data);
202void hal_set_aid(struct hw_data *hw_data, u16 aid);
203void hal_set_bssid(struct hw_data *hw_data, u8 *bssid);
204void hal_get_bssid(struct hw_data *hw_data, u8 *bssid);
205void hal_set_listen_interval(struct hw_data *hw_data, u16 listen_interval);
206void hal_set_cap_info(struct hw_data *hw_data, u16 capability_info);
207void hal_set_ssid(struct hw_data *hw_data, u8 *ssid, u8 ssid_len);
208void hal_start_tx0(struct hw_data *hw_data);
209
210#define hal_get_cwmin(_A) ((_A)->cwmin)
211
212void hal_set_cwmax(struct hw_data *hw_data, u16 cwin_max);
213
214#define hal_get_cwmax(_A) ((_A)->cwmax)
215
216void hal_set_rsn_wpa(struct hw_data *hw_data, u32 *rsn_ie_bitmap,
217 u32 *rsn_oui_type , unsigned char desired_auth_mode);
218void hal_set_connect_info(struct hw_data *hw_data, unsigned char bo_connect);
219u8 hal_get_est_sq3(struct hw_data *hw_data, u8 count);
220void hal_descriptor_indicate(struct hw_data *hw_data,
221 struct wb35_descriptor *des);
222u8 hal_get_antenna_number(struct hw_data *hw_data);
223u32 hal_get_bss_pk_cnt(struct hw_data *hw_data);
224
225#define hal_get_region_from_EEPROM(_A) ((_A)->reg.EEPROMRegion)
226#define hal_get_tx_buffer(_A, _B) Wb35Tx_get_tx_buffer(_A, _B)
227#define hal_software_set(_A) (_A->SoftwareSet)
228#define hal_driver_init_OK(_A) (_A->IsInitOK)
229#define hal_rssi_boundary_high(_A) (_A->RSSI_high)
230#define hal_rssi_boundary_low(_A) (_A->RSSI_low)
231#define hal_scan_interval(_A) (_A->Scan_Interval)
232
233#define PHY_DEBUG(msg, args...)
234
235/* return 100ms count */
236#define hal_get_time_count(_P) (_P->time_count / 10)
237
238#define hal_ibss_disconnect(_A) (hal_stop_sync_bss(_A))
239
171#endif 240#endif
diff --git a/drivers/staging/winbond/wb35rx.c b/drivers/staging/winbond/wb35rx.c
index 448514aada44..f118eeba396a 100644
--- a/drivers/staging/winbond/wb35rx.c
+++ b/drivers/staging/winbond/wb35rx.c
@@ -14,7 +14,6 @@
14#include <linux/slab.h> 14#include <linux/slab.h>
15 15
16#include "core.h" 16#include "core.h"
17#include "sysdef.h"
18#include "wb35rx_f.h" 17#include "wb35rx_f.h"
19 18
20static void packet_came(struct ieee80211_hw *hw, char *pRxBufferAddress, int PacketSize) 19static void packet_came(struct ieee80211_hw *hw, char *pRxBufferAddress, int PacketSize)
@@ -109,10 +108,7 @@ static u16 Wb35Rx_indicate(struct ieee80211_hw *hw)
109 108
110 /* Basic check for Rx length. Is length valid? */ 109 /* Basic check for Rx length. Is length valid? */
111 if (PacketSize > MAX_PACKET_SIZE) { 110 if (PacketSize > MAX_PACKET_SIZE) {
112#ifdef _PE_RX_DUMP_ 111 pr_debug("Serious ERROR : Rx data size too long, size =%d\n", PacketSize);
113 printk("Serious ERROR : Rx data size too long, size =%d\n", PacketSize);
114#endif
115
116 pWb35Rx->EP3vm_state = VM_STOP; 112 pWb35Rx->EP3vm_state = VM_STOP;
117 pWb35Rx->Ep3ErrorCount2++; 113 pWb35Rx->Ep3ErrorCount2++;
118 break; 114 break;
@@ -174,7 +170,7 @@ static void Wb35Rx_Complete(struct urb *urb)
174 /* The IRP is completed */ 170 /* The IRP is completed */
175 pWb35Rx->EP3vm_state = VM_COMPLETED; 171 pWb35Rx->EP3vm_state = VM_COMPLETED;
176 172
177 if (pHwData->SurpriseRemove || pHwData->HwStop) /* Must be here, or RxBufferId is invalid */ 173 if (pHwData->SurpriseRemove) /* Must be here, or RxBufferId is invalid */
178 goto error; 174 goto error;
179 175
180 if (pWb35Rx->rx_halt) 176 if (pWb35Rx->rx_halt)
@@ -186,9 +182,7 @@ static void Wb35Rx_Complete(struct urb *urb)
186 182
187 /* The URB is completed, check the result */ 183 /* The URB is completed, check the result */
188 if (pWb35Rx->EP3VM_status != 0) { 184 if (pWb35Rx->EP3VM_status != 0) {
189#ifdef _PE_USB_STATE_DUMP_ 185 pr_debug("EP3 IoCompleteRoutine return error\n");
190 printk("EP3 IoCompleteRoutine return error\n");
191#endif
192 pWb35Rx->EP3vm_state = VM_STOP; 186 pWb35Rx->EP3vm_state = VM_STOP;
193 goto error; 187 goto error;
194 } 188 }
@@ -239,7 +233,7 @@ static void Wb35Rx(struct ieee80211_hw *hw)
239 u32 RxBufferId; 233 u32 RxBufferId;
240 234
241 /* Issuing URB */ 235 /* Issuing URB */
242 if (pHwData->SurpriseRemove || pHwData->HwStop) 236 if (pHwData->SurpriseRemove)
243 goto error; 237 goto error;
244 238
245 if (pWb35Rx->rx_halt) 239 if (pWb35Rx->rx_halt)
@@ -249,9 +243,7 @@ static void Wb35Rx(struct ieee80211_hw *hw)
249 RxBufferId = pWb35Rx->RxBufferId; 243 RxBufferId = pWb35Rx->RxBufferId;
250 if (!pWb35Rx->RxOwner[RxBufferId]) { 244 if (!pWb35Rx->RxOwner[RxBufferId]) {
251 /* It's impossible to run here. */ 245 /* It's impossible to run here. */
252#ifdef _PE_RX_DUMP_ 246 pr_debug("Rx driver fifo unavailable\n");
253 printk("Rx driver fifo unavailable\n");
254#endif
255 goto error; 247 goto error;
256 } 248 }
257 249
@@ -268,8 +260,8 @@ static void Wb35Rx(struct ieee80211_hw *hw)
268 } 260 }
269 pRxBufferAddress = pWb35Rx->pDRx; 261 pRxBufferAddress = pWb35Rx->pDRx;
270 262
271 usb_fill_bulk_urb(urb, pHwData->WbUsb.udev, 263 usb_fill_bulk_urb(urb, pHwData->udev,
272 usb_rcvbulkpipe(pHwData->WbUsb.udev, 3), 264 usb_rcvbulkpipe(pHwData->udev, 3),
273 pRxBufferAddress, MAX_USB_RX_BUFFER, 265 pRxBufferAddress, MAX_USB_RX_BUFFER,
274 Wb35Rx_Complete, hw); 266 Wb35Rx_Complete, hw);
275 267
@@ -337,9 +329,7 @@ void Wb35Rx_stop(struct hw_data *pHwData)
337 /* Canceling the Irp if already sends it out. */ 329 /* Canceling the Irp if already sends it out. */
338 if (pWb35Rx->EP3vm_state == VM_RUNNING) { 330 if (pWb35Rx->EP3vm_state == VM_RUNNING) {
339 usb_unlink_urb(pWb35Rx->RxUrb); /* Only use unlink, let Wb35Rx_destroy to free them */ 331 usb_unlink_urb(pWb35Rx->RxUrb); /* Only use unlink, let Wb35Rx_destroy to free them */
340#ifdef _PE_RX_DUMP_ 332 pr_debug("EP3 Rx stop\n");
341 printk("EP3 Rx stop\n");
342#endif
343 } 333 }
344} 334}
345 335
@@ -355,8 +345,6 @@ void Wb35Rx_destroy(struct hw_data *pHwData)
355 345
356 if (pWb35Rx->RxUrb) 346 if (pWb35Rx->RxUrb)
357 usb_free_urb(pWb35Rx->RxUrb); 347 usb_free_urb(pWb35Rx->RxUrb);
358#ifdef _PE_RX_DUMP_ 348 pr_debug("Wb35Rx_destroy OK\n");
359 printk("Wb35Rx_destroy OK\n");
360#endif
361} 349}
362 350
diff --git a/drivers/staging/winbond/wb35rx_f.h b/drivers/staging/winbond/wb35rx_f.h
index 98acce517d90..1fdf65ea6041 100644
--- a/drivers/staging/winbond/wb35rx_f.h
+++ b/drivers/staging/winbond/wb35rx_f.h
@@ -2,7 +2,7 @@
2#define __WINBOND_WB35RX_F_H 2#define __WINBOND_WB35RX_F_H
3 3
4#include <net/mac80211.h> 4#include <net/mac80211.h>
5#include "wbhal_s.h" 5#include "wbhal.h"
6 6
7//==================================== 7//====================================
8// Interface function declare 8// Interface function declare
diff --git a/drivers/staging/winbond/wb35tx.c b/drivers/staging/winbond/wb35tx.c
index 2a9d05557678..44fc3fe79b79 100644
--- a/drivers/staging/winbond/wb35tx.c
+++ b/drivers/staging/winbond/wb35tx.c
@@ -13,7 +13,6 @@
13 13
14#include "wb35tx_f.h" 14#include "wb35tx_f.h"
15#include "mds_f.h" 15#include "mds_f.h"
16#include "sysdef.h"
17 16
18unsigned char 17unsigned char
19Wb35Tx_get_tx_buffer(struct hw_data * pHwData, u8 **pBuffer) 18Wb35Tx_get_tx_buffer(struct hw_data * pHwData, u8 **pBuffer)
@@ -41,7 +40,7 @@ static void Wb35Tx_complete(struct urb * pUrb)
41 pWb35Tx->TxSendIndex++; 40 pWb35Tx->TxSendIndex++;
42 pWb35Tx->TxSendIndex %= MAX_USB_TX_BUFFER_NUMBER; 41 pWb35Tx->TxSendIndex %= MAX_USB_TX_BUFFER_NUMBER;
43 42
44 if (pHwData->SurpriseRemove || pHwData->HwStop) // Let WbWlanHalt to handle surprise remove 43 if (pHwData->SurpriseRemove) // Let WbWlanHalt to handle surprise remove
45 goto error; 44 goto error;
46 45
47 if (pWb35Tx->tx_halt) 46 if (pWb35Tx->tx_halt)
@@ -74,7 +73,7 @@ static void Wb35Tx(struct wbsoft_priv *adapter)
74 u32 SendIndex; 73 u32 SendIndex;
75 74
76 75
77 if (pHwData->SurpriseRemove || pHwData->HwStop) 76 if (pHwData->SurpriseRemove)
78 goto cleanup; 77 goto cleanup;
79 78
80 if (pWb35Tx->tx_halt) 79 if (pWb35Tx->tx_halt)
@@ -89,8 +88,8 @@ static void Wb35Tx(struct wbsoft_priv *adapter)
89 // 88 //
90 // Issuing URB 89 // Issuing URB
91 // 90 //
92 usb_fill_bulk_urb(pUrb, pHwData->WbUsb.udev, 91 usb_fill_bulk_urb(pUrb, pHwData->udev,
93 usb_sndbulkpipe(pHwData->WbUsb.udev, 4), 92 usb_sndbulkpipe(pHwData->udev, 4),
94 pTxBufferAddress, pMds->TxBufferSize[ SendIndex ], 93 pTxBufferAddress, pMds->TxBufferSize[ SendIndex ],
95 Wb35Tx_complete, adapter); 94 Wb35Tx_complete, adapter);
96 95
@@ -153,16 +152,12 @@ void Wb35Tx_stop(struct hw_data * pHwData)
153 // Trying to canceling the Trp of EP2 152 // Trying to canceling the Trp of EP2
154 if (pWb35Tx->EP2vm_state == VM_RUNNING) 153 if (pWb35Tx->EP2vm_state == VM_RUNNING)
155 usb_unlink_urb( pWb35Tx->Tx2Urb ); // Only use unlink, let Wb35Tx_destrot to free them 154 usb_unlink_urb( pWb35Tx->Tx2Urb ); // Only use unlink, let Wb35Tx_destrot to free them
156 #ifdef _PE_TX_DUMP_ 155 pr_debug("EP2 Tx stop\n");
157 printk("EP2 Tx stop\n");
158 #endif
159 156
160 // Trying to canceling the Irp of EP4 157 // Trying to canceling the Irp of EP4
161 if (pWb35Tx->EP4vm_state == VM_RUNNING) 158 if (pWb35Tx->EP4vm_state == VM_RUNNING)
162 usb_unlink_urb( pWb35Tx->Tx4Urb ); // Only use unlink, let Wb35Tx_destrot to free them 159 usb_unlink_urb( pWb35Tx->Tx4Urb ); // Only use unlink, let Wb35Tx_destrot to free them
163 #ifdef _PE_TX_DUMP_ 160 pr_debug("EP4 Tx stop\n");
164 printk("EP4 Tx stop\n");
165 #endif
166} 161}
167 162
168//====================================================== 163//======================================================
@@ -182,9 +177,7 @@ void Wb35Tx_destroy(struct hw_data * pHwData)
182 if (pWb35Tx->Tx2Urb) 177 if (pWb35Tx->Tx2Urb)
183 usb_free_urb( pWb35Tx->Tx2Urb ); 178 usb_free_urb( pWb35Tx->Tx2Urb );
184 179
185 #ifdef _PE_TX_DUMP_ 180 pr_debug("Wb35Tx_destroy OK\n");
186 printk("Wb35Tx_destroy OK\n");
187 #endif
188} 181}
189 182
190void Wb35Tx_CurrentTime(struct wbsoft_priv *adapter, u32 TimeCount) 183void Wb35Tx_CurrentTime(struct wbsoft_priv *adapter, u32 TimeCount)
@@ -222,7 +215,7 @@ static void Wb35Tx_EP2VM_complete(struct urb * pUrb)
222 pWb35Tx->EP2VM_status = pUrb->status; 215 pWb35Tx->EP2VM_status = pUrb->status;
223 216
224 // For Linux 2.4. Interrupt will always trigger 217 // For Linux 2.4. Interrupt will always trigger
225 if (pHwData->SurpriseRemove || pHwData->HwStop) // Let WbWlanHalt to handle surprise remove 218 if (pHwData->SurpriseRemove) // Let WbWlanHalt to handle surprise remove
226 goto error; 219 goto error;
227 220
228 if (pWb35Tx->tx_halt) 221 if (pWb35Tx->tx_halt)
@@ -263,7 +256,7 @@ static void Wb35Tx_EP2VM(struct wbsoft_priv *adapter)
263 u32 * pltmp = (u32 *)pWb35Tx->EP2_buf; 256 u32 * pltmp = (u32 *)pWb35Tx->EP2_buf;
264 int retv; 257 int retv;
265 258
266 if (pHwData->SurpriseRemove || pHwData->HwStop) 259 if (pHwData->SurpriseRemove)
267 goto error; 260 goto error;
268 261
269 if (pWb35Tx->tx_halt) 262 if (pWb35Tx->tx_halt)
@@ -272,16 +265,14 @@ static void Wb35Tx_EP2VM(struct wbsoft_priv *adapter)
272 // 265 //
273 // Issuing URB 266 // Issuing URB
274 // 267 //
275 usb_fill_int_urb( pUrb, pHwData->WbUsb.udev, usb_rcvintpipe(pHwData->WbUsb.udev,2), 268 usb_fill_int_urb( pUrb, pHwData->udev, usb_rcvintpipe(pHwData->udev,2),
276 pltmp, MAX_INTERRUPT_LENGTH, Wb35Tx_EP2VM_complete, adapter, 32); 269 pltmp, MAX_INTERRUPT_LENGTH, Wb35Tx_EP2VM_complete, adapter, 32);
277 270
278 pWb35Tx->EP2vm_state = VM_RUNNING; 271 pWb35Tx->EP2vm_state = VM_RUNNING;
279 retv = usb_submit_urb(pUrb, GFP_ATOMIC); 272 retv = usb_submit_urb(pUrb, GFP_ATOMIC);
280 273
281 if (retv < 0) { 274 if (retv < 0) {
282 #ifdef _PE_TX_DUMP_ 275 pr_debug("EP2 Tx Irp sending error\n");
283 printk("EP2 Tx Irp sending error\n");
284 #endif
285 goto error; 276 goto error;
286 } 277 }
287 278
diff --git a/drivers/staging/winbond/wb35tx_f.h b/drivers/staging/winbond/wb35tx_f.h
index 1d3b515f83bc..018fd35e815d 100644
--- a/drivers/staging/winbond/wb35tx_f.h
+++ b/drivers/staging/winbond/wb35tx_f.h
@@ -2,7 +2,6 @@
2#define __WINBOND_WB35TX_F_H 2#define __WINBOND_WB35TX_F_H
3 3
4#include "core.h" 4#include "core.h"
5#include "wbhal_f.h"
6 5
7/* 6/*
8 * ==================================== 7 * ====================================
diff --git a/drivers/staging/winbond/wbhal_s.h b/drivers/staging/winbond/wbhal.h
index 821a1b3f1301..39e84a0d9729 100644
--- a/drivers/staging/winbond/wbhal_s.h
+++ b/drivers/staging/winbond/wbhal.h
@@ -342,9 +342,6 @@ struct wb35_descriptor { /* Skip length = 8 DWORD */
342 void *buffer_address[MAX_DESCRIPTOR_BUFFER_INDEX]; 342 void *buffer_address[MAX_DESCRIPTOR_BUFFER_INDEX];
343}; 343};
344 344
345
346#define DEFAULT_NULL_PACKET_COUNT 180000 /* 180 seconds */
347
348#define MAX_TXVGA_EEPROM 9 /* How many word(u16) of EEPROM will be used for TxVGA */ 345#define MAX_TXVGA_EEPROM 9 /* How many word(u16) of EEPROM will be used for TxVGA */
349#define MAX_RF_PARAMETER 32 346#define MAX_RF_PARAMETER 32
350 347
@@ -359,7 +356,6 @@ struct txvga_for_50 {
359 * ============================================== 356 * ==============================================
360 */ 357 */
361 358
362#include "wbusb_s.h"
363#include "wb35reg_s.h" 359#include "wb35reg_s.h"
364#include "wb35tx_s.h" 360#include "wb35tx_s.h"
365#include "wb35rx_s.h" 361#include "wb35rx_s.h"
@@ -440,7 +436,7 @@ struct hw_data {
440 * Variable for each module 436 * Variable for each module
441 * ================================================== 437 * ==================================================
442 */ 438 */
443 struct wb_usb WbUsb; /* Need WbUsb.h */ 439 struct usb_device *udev;
444 struct wb35_reg reg; /* Need Wb35Reg.h */ 440 struct wb35_reg reg; /* Need Wb35Reg.h */
445 struct wb35_tx Wb35Tx; /* Need Wb35Tx.h */ 441 struct wb35_tx Wb35Tx; /* Need Wb35Tx.h */
446 struct wb35_rx Wb35Rx; /* Need Wb35Rx.h */ 442 struct wb35_rx Wb35Rx; /* Need Wb35Rx.h */
@@ -510,16 +506,8 @@ struct hw_data {
510 u32 RxByteCountLast; 506 u32 RxByteCountLast;
511 u32 TxByteCountLast; 507 u32 TxByteCountLast;
512 508
513 atomic_t SurpriseRemoveCount;
514
515 /* For global timer */ 509 /* For global timer */
516 u32 time_count; /* TICK_TIME_100ms 1 = 100ms */ 510 u32 time_count; /* TICK_TIME_100ms 1 = 100ms */
517
518 /* For error recover */
519 u32 HwStop;
520
521 /* For avoid AP disconnect */
522 u32 NullPacketCount;
523}; 511};
524 512
525#endif 513#endif
diff --git a/drivers/staging/winbond/wbhal_f.h b/drivers/staging/winbond/wbhal_f.h
deleted file mode 100644
index fc78c14ae583..000000000000
--- a/drivers/staging/winbond/wbhal_f.h
+++ /dev/null
@@ -1,81 +0,0 @@
1/*
2 * =====================================================================
3 * Device related include
4 * =====================================================================
5*/
6#include "wb35reg_f.h"
7#include "wb35tx_f.h"
8#include "wb35rx_f.h"
9
10#include "core.h"
11
12/* =====================================================================
13 * Function declaration
14 * =====================================================================
15 */
16void hal_remove_mapping_key(struct hw_data *hw_data, u8 *mac_addr);
17void hal_remove_default_key(struct hw_data *hw_data, u32 index);
18unsigned char hal_set_mapping_key(struct hw_data *adapter, u8 *mac_addr,
19 u8 null_key, u8 wep_on, u8 *tx_tsc,
20 u8 *rx_tsc, u8 key_type, u8 key_len,
21 u8 *key_data);
22unsigned char hal_set_default_key(struct hw_data *adapter, u8 index,
23 u8 null_key, u8 wep_on, u8 *tx_tsc,
24 u8 *rx_tsc, u8 key_type, u8 key_len,
25 u8 *key_data);
26void hal_clear_all_default_key(struct hw_data *hw_data);
27void hal_clear_all_group_key(struct hw_data *hw_data);
28void hal_clear_all_mapping_key(struct hw_data *hw_data);
29void hal_clear_all_key(struct hw_data *hw_data);
30void hal_set_power_save_mode(struct hw_data *hw_data, unsigned char power_save,
31 unsigned char wakeup, unsigned char dtim);
32void hal_get_power_save_mode(struct hw_data *hw_data, u8 *in_pwr_save);
33void hal_set_slot_time(struct hw_data *hw_data, u8 type);
34
35#define hal_set_atim_window(_A, _ATM)
36
37void hal_start_bss(struct hw_data *hw_data, u8 mac_op_mode);
38
39/* 0:BSS STA 1:IBSS STA */
40void hal_join_request(struct hw_data *hw_data, u8 bss_type);
41
42void hal_stop_sync_bss(struct hw_data *hw_data);
43void hal_resume_sync_bss(struct hw_data *hw_data);
44void hal_set_aid(struct hw_data *hw_data, u16 aid);
45void hal_set_bssid(struct hw_data *hw_data, u8 *bssid);
46void hal_get_bssid(struct hw_data *hw_data, u8 *bssid);
47void hal_set_listen_interval(struct hw_data *hw_data, u16 listen_interval);
48void hal_set_cap_info(struct hw_data *hw_data, u16 capability_info);
49void hal_set_ssid(struct hw_data *hw_data, u8 *ssid, u8 ssid_len);
50void hal_start_tx0(struct hw_data *hw_data);
51
52#define hal_get_cwmin(_A) ((_A)->cwmin)
53
54void hal_set_cwmax(struct hw_data *hw_data, u16 cwin_max);
55
56#define hal_get_cwmax(_A) ((_A)->cwmax)
57
58void hal_set_rsn_wpa(struct hw_data *hw_data, u32 *rsn_ie_bitmap,
59 u32 *rsn_oui_type , unsigned char desired_auth_mode);
60void hal_set_connect_info(struct hw_data *hw_data, unsigned char bo_connect);
61u8 hal_get_est_sq3(struct hw_data *hw_data, u8 count);
62void hal_descriptor_indicate(struct hw_data *hw_data,
63 struct wb35_descriptor *des);
64u8 hal_get_antenna_number(struct hw_data *hw_data);
65u32 hal_get_bss_pk_cnt(struct hw_data *hw_data);
66
67#define hal_get_region_from_EEPROM(_A) ((_A)->reg.EEPROMRegion)
68#define hal_get_tx_buffer(_A, _B) Wb35Tx_get_tx_buffer(_A, _B)
69#define hal_software_set(_A) (_A->SoftwareSet)
70#define hal_driver_init_OK(_A) (_A->IsInitOK)
71#define hal_rssi_boundary_high(_A) (_A->RSSI_high)
72#define hal_rssi_boundary_low(_A) (_A->RSSI_low)
73#define hal_scan_interval(_A) (_A->Scan_Interval)
74
75#define PHY_DEBUG(msg, args...)
76
77/* return 100ms count */
78#define hal_get_time_count(_P) (_P->time_count / 10)
79#define hal_detect_error(_P) (_P->WbUsb.DetectCount)
80
81#define hal_ibss_disconnect(_A) (hal_stop_sync_bss(_A))
diff --git a/drivers/staging/winbond/wblinux_f.h b/drivers/staging/winbond/wblinux_f.h
deleted file mode 100644
index 0a9d214f7187..000000000000
--- a/drivers/staging/winbond/wblinux_f.h
+++ /dev/null
@@ -1,17 +0,0 @@
1#ifndef __WBLINUX_F_H
2#define __WBLINUX_F_H
3
4#include "core.h"
5#include "mds_s.h"
6
7/*
8 * ====================================================================
9 * Copyright (c) 1996-2004 Winbond Electronic Corporation
10 *
11 * wblinux_f.h
12 * ====================================================================
13 */
14int wb35_start_xmit(struct sk_buff *skb, struct net_device *netdev);
15void wb35_set_multicast(struct net_device *netdev);
16struct net_device_stats *wb35_netdev_stats(struct net_device *netdev);
17#endif
diff --git a/drivers/staging/winbond/wbusb.c b/drivers/staging/winbond/wbusb.c
index 3f60cf7e6ec1..2163d60c2eaf 100644
--- a/drivers/staging/winbond/wbusb.c
+++ b/drivers/staging/winbond/wbusb.c
@@ -14,10 +14,11 @@
14 14
15#include "core.h" 15#include "core.h"
16#include "mds_f.h" 16#include "mds_f.h"
17#include "mlmetxrx_f.h"
18#include "mto.h" 17#include "mto.h"
19#include "wbhal_f.h" 18#include "wbhal.h"
20#include "wblinux_f.h" 19#include "wb35reg_f.h"
20#include "wb35tx_f.h"
21#include "wb35rx_f.h"
21 22
22MODULE_DESCRIPTION("IS89C35 802.11bg WLAN USB Driver"); 23MODULE_DESCRIPTION("IS89C35 802.11bg WLAN USB Driver");
23MODULE_LICENSE("GPL"); 24MODULE_LICENSE("GPL");
@@ -181,10 +182,7 @@ static void hal_set_current_channel_ex(struct hw_data *pHwData, struct chan_info
181 RFSynthesizer_SwitchingChannel(pHwData, channel); /* Switch channel */ 182 RFSynthesizer_SwitchingChannel(pHwData, channel); /* Switch channel */
182 pHwData->Channel = channel.ChanNo; 183 pHwData->Channel = channel.ChanNo;
183 pHwData->band = channel.band; 184 pHwData->band = channel.band;
184#ifdef _PE_STATE_DUMP_ 185 pr_debug("Set channel is %d, band =%d\n", pHwData->Channel, pHwData->band);
185 printk("Set channel is %d, band =%d\n", pHwData->Channel,
186 pHwData->band);
187#endif
188 reg->M28_MacControl &= ~0xff; /* Clean channel information field */ 186 reg->M28_MacControl &= ~0xff; /* Clean channel information field */
189 reg->M28_MacControl |= channel.ChanNo; 187 reg->M28_MacControl |= channel.ChanNo;
190 Wb35Reg_WriteWithCallbackValue(pHwData, 0x0828, reg->M28_MacControl, 188 Wb35Reg_WriteWithCallbackValue(pHwData, 0x0828, reg->M28_MacControl,
@@ -339,10 +337,8 @@ static void hal_stop(struct hw_data *pHwData)
339static unsigned char hal_idle(struct hw_data *pHwData) 337static unsigned char hal_idle(struct hw_data *pHwData)
340{ 338{
341 struct wb35_reg *reg = &pHwData->reg; 339 struct wb35_reg *reg = &pHwData->reg;
342 struct wb_usb *pWbUsb = &pHwData->WbUsb;
343 340
344 if (!pHwData->SurpriseRemove 341 if (!pHwData->SurpriseRemove && reg->EP0vm_state != VM_STOP)
345 && (pWbUsb->DetectCount || reg->EP0vm_state != VM_STOP))
346 return false; 342 return false;
347 343
348 return true; 344 return true;
@@ -608,15 +604,6 @@ static void hal_led_control(unsigned long data)
608 } 604 }
609 break; 605 break;
610 } 606 }
611
612 /* Active send null packet to avoid AP disconnect */
613 if (pHwData->LED_LinkOn) {
614 pHwData->NullPacketCount += TimeInterval;
615 if (pHwData->NullPacketCount >=
616 DEFAULT_NULL_PACKET_COUNT) {
617 pHwData->NullPacketCount = 0;
618 }
619 }
620 } 607 }
621 608
622 pHwData->time_count += TimeInterval; 609 pHwData->time_count += TimeInterval;
@@ -651,13 +638,6 @@ static int hal_init_hardware(struct ieee80211_hw *hw)
651 638
652 SoftwareSet = hal_software_set(pHwData); 639 SoftwareSet = hal_software_set(pHwData);
653 640
654#ifdef Vendor2
655 /* Try to make sure the EEPROM contain */
656 SoftwareSet >>= 8;
657 if (SoftwareSet != 0x82)
658 return false;
659#endif
660
661 Wb35Rx_start(hw); 641 Wb35Rx_start(hw);
662 Wb35Tx_EP2VM_start(priv); 642 Wb35Tx_EP2VM_start(priv);
663 643
@@ -734,9 +714,7 @@ static int wb35_hw_init(struct ieee80211_hw *hw)
734 } 714 }
735 715
736 priv->sLocalPara.bAntennaNo = hal_get_antenna_number(pHwData); 716 priv->sLocalPara.bAntennaNo = hal_get_antenna_number(pHwData);
737#ifdef _PE_STATE_DUMP_ 717 pr_debug("Driver init, antenna no = %d\n", priv->sLocalPara.bAntennaNo);
738 printk("Driver init, antenna no = %d\n", psLOCAL->bAntennaNo);
739#endif
740 hal_get_hw_radio_off(pHwData); 718 hal_get_hw_radio_off(pHwData);
741 719
742 /* Waiting for HAL setting OK */ 720 /* Waiting for HAL setting OK */
@@ -769,7 +747,6 @@ static int wb35_probe(struct usb_interface *intf,
769 struct usb_host_interface *interface; 747 struct usb_host_interface *interface;
770 struct ieee80211_hw *dev; 748 struct ieee80211_hw *dev;
771 struct wbsoft_priv *priv; 749 struct wbsoft_priv *priv;
772 struct wb_usb *pWbUsb;
773 int nr, err; 750 int nr, err;
774 u32 ltmp; 751 u32 ltmp;
775 752
@@ -800,16 +777,13 @@ static int wb35_probe(struct usb_interface *intf,
800 777
801 priv = dev->priv; 778 priv = dev->priv;
802 779
803 pWbUsb = &priv->sHwData.WbUsb; 780 priv->sHwData.udev = udev;
804 pWbUsb->udev = udev;
805 781
806 interface = intf->cur_altsetting; 782 interface = intf->cur_altsetting;
807 endpoint = &interface->endpoint[0].desc; 783 endpoint = &interface->endpoint[0].desc;
808 784
809 if (endpoint[2].wMaxPacketSize == 512) { 785 if (endpoint[2].wMaxPacketSize == 512)
810 printk("[w35und] Working on USB 2.0\n"); 786 printk("[w35und] Working on USB 2.0\n");
811 pWbUsb->IsUsb20 = 1;
812 }
813 787
814 err = wb35_hw_init(dev); 788 err = wb35_hw_init(dev);
815 if (err) 789 if (err)
@@ -860,13 +834,9 @@ static void hal_halt(struct hw_data *pHwData)
860 834
861static void wb35_hw_halt(struct wbsoft_priv *adapter) 835static void wb35_hw_halt(struct wbsoft_priv *adapter)
862{ 836{
863 Mds_Destroy(adapter);
864
865 /* Turn off Rx and Tx hardware ability */ 837 /* Turn off Rx and Tx hardware ability */
866 hal_stop(&adapter->sHwData); 838 hal_stop(&adapter->sHwData);
867#ifdef _PE_USB_INI_DUMP_ 839 pr_debug("[w35und] Hal_stop O.K.\n");
868 printk("[w35und] Hal_stop O.K.\n");
869#endif
870 /* Waiting Irp completed */ 840 /* Waiting Irp completed */
871 msleep(100); 841 msleep(100);
872 842
diff --git a/drivers/staging/winbond/wbusb_s.h b/drivers/staging/winbond/wbusb_s.h
deleted file mode 100644
index 8961ae594c4e..000000000000
--- a/drivers/staging/winbond/wbusb_s.h
+++ /dev/null
@@ -1,18 +0,0 @@
1/* =========================================================
2 * Copyright (c) 1996-2004 Winbond Electronic Corporation
3 *
4 * Module Name:
5 * wbusb_s.h
6 * =========================================================
7 */
8#ifndef __WINBOND_WBUSB_S_H
9#define __WINBOND_WBUSB_S_H
10
11#include <linux/types.h>
12
13struct wb_usb {
14 u32 IsUsb20;
15 struct usb_device *udev;
16 u32 DetectCount;
17};
18#endif
diff --git a/drivers/staging/wlags49_h2/wl_pci.c b/drivers/staging/wlags49_h2/wl_pci.c
index 020b17adee2d..28ae9dd1b44e 100644
--- a/drivers/staging/wlags49_h2/wl_pci.c
+++ b/drivers/staging/wlags49_h2/wl_pci.c
@@ -458,7 +458,7 @@ void __devexit wl_pci_remove(struct pci_dev *pdev)
458 return; 458 return;
459 } 459 }
460 460
461 dev = (struct net_device *)pci_get_drvdata( pdev ); 461 dev = pci_get_drvdata( pdev );
462 if( dev == NULL ) { 462 if( dev == NULL ) {
463 DBG_ERROR( DbgInfo, "Could not retrieve net_device structure\n" ); 463 DBG_ERROR( DbgInfo, "Could not retrieve net_device structure\n" );
464 return; 464 return;
diff --git a/drivers/staging/wlags49_h2/wl_profile.c b/drivers/staging/wlags49_h2/wl_profile.c
index 7a1337db7aa1..a459e48c7bf0 100644
--- a/drivers/staging/wlags49_h2/wl_profile.c
+++ b/drivers/staging/wlags49_h2/wl_profile.c
@@ -248,7 +248,7 @@ void parse_config(struct net_device *dev)
248 } else { 248 } else {
249 DBG_TRACE(DbgInfo, "F/W image file found\n"); 249 DBG_TRACE(DbgInfo, "F/W image file found\n");
250#define DHF_ALLOC_SIZE 96000 /* just below 96K, let's hope it suffices for now and for the future */ 250#define DHF_ALLOC_SIZE 96000 /* just below 96K, let's hope it suffices for now and for the future */
251 cp = (char *)vmalloc(DHF_ALLOC_SIZE); 251 cp = vmalloc(DHF_ALLOC_SIZE);
252 if (cp == NULL) { 252 if (cp == NULL) {
253 DBG_ERROR(DbgInfo, "error in vmalloc\n"); 253 DBG_ERROR(DbgInfo, "error in vmalloc\n");
254 } else { 254 } else {
diff --git a/drivers/staging/wlags49_h2/wl_sysfs.c b/drivers/staging/wlags49_h2/wl_sysfs.c
index e4c8804ac37d..9b833b30ae62 100644
--- a/drivers/staging/wlags49_h2/wl_sysfs.c
+++ b/drivers/staging/wlags49_h2/wl_sysfs.c
@@ -42,7 +42,7 @@ static ssize_t show_tallies(struct device *d, struct device_attribute *attr,
42 CFG_HERMES_TALLIES_STRCT tallies; 42 CFG_HERMES_TALLIES_STRCT tallies;
43 ssize_t ret = -EINVAL; 43 ssize_t ret = -EINVAL;
44 44
45 read_lock(&dev_base_lock); 45 rcu_read_lock();
46 if (dev_isalive(dev)) { 46 if (dev_isalive(dev)) {
47 wl_lock(lp, &flags); 47 wl_lock(lp, &flags);
48 48
@@ -102,7 +102,7 @@ static ssize_t show_tallies(struct device *d, struct device_attribute *attr,
102 } 102 }
103 } 103 }
104 104
105 read_unlock(&dev_base_lock); 105 rcu_read_unlock();
106 return ret; 106 return ret;
107} 107}
108 108
diff --git a/drivers/staging/wlan-ng/p80211conv.c b/drivers/staging/wlan-ng/p80211conv.c
index 83879f9a0b7d..146f3651b6f2 100644
--- a/drivers/staging/wlan-ng/p80211conv.c
+++ b/drivers/staging/wlan-ng/p80211conv.c
@@ -148,7 +148,8 @@ int skb_ether_to_p80211(wlandevice_t *wlandev, u32 ethconv,
148 148
149 /* tack on SNAP */ 149 /* tack on SNAP */
150 e_snap = 150 e_snap =
151 (struct wlan_snap *) skb_push(skb, sizeof(struct wlan_snap)); 151 (struct wlan_snap *) skb_push(skb,
152 sizeof(struct wlan_snap));
152 e_snap->type = htons(proto); 153 e_snap->type = htons(proto);
153 if (ethconv == WLAN_ETHCONV_8021h 154 if (ethconv == WLAN_ETHCONV_8021h
154 && p80211_stt_findproto(proto)) { 155 && p80211_stt_findproto(proto)) {
@@ -161,7 +162,8 @@ int skb_ether_to_p80211(wlandevice_t *wlandev, u32 ethconv,
161 162
162 /* tack on llc */ 163 /* tack on llc */
163 e_llc = 164 e_llc =
164 (struct wlan_llc *) skb_push(skb, sizeof(struct wlan_llc)); 165 (struct wlan_llc *) skb_push(skb,
166 sizeof(struct wlan_llc));
165 e_llc->dsap = 0xAA; /* SNAP, see IEEE 802 */ 167 e_llc->dsap = 0xAA; /* SNAP, see IEEE 802 */
166 e_llc->ssap = 0xAA; 168 e_llc->ssap = 0xAA;
167 e_llc->ctl = 0x03; 169 e_llc->ctl = 0x03;
@@ -297,10 +299,12 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
297 if ((WLAN_GET_FC_TODS(fc) == 0) && (WLAN_GET_FC_FROMDS(fc) == 0)) { 299 if ((WLAN_GET_FC_TODS(fc) == 0) && (WLAN_GET_FC_FROMDS(fc) == 0)) {
298 memcpy(daddr, w_hdr->a3.a1, WLAN_ETHADDR_LEN); 300 memcpy(daddr, w_hdr->a3.a1, WLAN_ETHADDR_LEN);
299 memcpy(saddr, w_hdr->a3.a2, WLAN_ETHADDR_LEN); 301 memcpy(saddr, w_hdr->a3.a2, WLAN_ETHADDR_LEN);
300 } else if ((WLAN_GET_FC_TODS(fc) == 0) && (WLAN_GET_FC_FROMDS(fc) == 1)) { 302 } else if ((WLAN_GET_FC_TODS(fc) == 0)
303 && (WLAN_GET_FC_FROMDS(fc) == 1)) {
301 memcpy(daddr, w_hdr->a3.a1, WLAN_ETHADDR_LEN); 304 memcpy(daddr, w_hdr->a3.a1, WLAN_ETHADDR_LEN);
302 memcpy(saddr, w_hdr->a3.a3, WLAN_ETHADDR_LEN); 305 memcpy(saddr, w_hdr->a3.a3, WLAN_ETHADDR_LEN);
303 } else if ((WLAN_GET_FC_TODS(fc) == 1) && (WLAN_GET_FC_FROMDS(fc) == 0)) { 306 } else if ((WLAN_GET_FC_TODS(fc) == 1)
307 && (WLAN_GET_FC_FROMDS(fc) == 0)) {
304 memcpy(daddr, w_hdr->a3.a3, WLAN_ETHADDR_LEN); 308 memcpy(daddr, w_hdr->a3.a3, WLAN_ETHADDR_LEN);
305 memcpy(saddr, w_hdr->a3.a2, WLAN_ETHADDR_LEN); 309 memcpy(saddr, w_hdr->a3.a2, WLAN_ETHADDR_LEN);
306 } else { 310 } else {
@@ -349,7 +353,8 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
349 353
350 e_llc = (struct wlan_llc *) (skb->data + payload_offset); 354 e_llc = (struct wlan_llc *) (skb->data + payload_offset);
351 e_snap = 355 e_snap =
352 (struct wlan_snap *) (skb->data + payload_offset + sizeof(struct wlan_llc)); 356 (struct wlan_snap *) (skb->data + payload_offset +
357 sizeof(struct wlan_llc));
353 358
354 /* Test for the various encodings */ 359 /* Test for the various encodings */
355 if ((payload_length >= sizeof(struct wlan_ethhdr)) && 360 if ((payload_length >= sizeof(struct wlan_ethhdr)) &&
@@ -372,9 +377,11 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
372 /* chop off the 802.11 CRC */ 377 /* chop off the 802.11 CRC */
373 skb_trim(skb, skb->len - WLAN_CRC_LEN); 378 skb_trim(skb, skb->len - WLAN_CRC_LEN);
374 379
375 } else if ((payload_length >= sizeof(struct wlan_llc) + sizeof(struct wlan_snap)) 380 } else if ((payload_length >= sizeof(struct wlan_llc) +
376 && (e_llc->dsap == 0xaa) && (e_llc->ssap == 0xaa) 381 sizeof(struct wlan_snap))
377 && (e_llc->ctl == 0x03) 382 &&(e_llc->dsap == 0xaa)
383 && (e_llc->ssap == 0xaa)
384 && (e_llc->ctl == 0x03)
378 && 385 &&
379 (((memcmp(e_snap->oui, oui_rfc1042, WLAN_IEEE_OUI_LEN) == 0) 386 (((memcmp(e_snap->oui, oui_rfc1042, WLAN_IEEE_OUI_LEN) == 0)
380 && (ethconv == WLAN_ETHCONV_8021h) 387 && (ethconv == WLAN_ETHCONV_8021h)
@@ -406,21 +413,25 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
406 /* chop off the 802.11 CRC */ 413 /* chop off the 802.11 CRC */
407 skb_trim(skb, skb->len - WLAN_CRC_LEN); 414 skb_trim(skb, skb->len - WLAN_CRC_LEN);
408 415
409 } else if ((payload_length >= sizeof(struct wlan_llc) + sizeof(struct wlan_snap)) 416 } else if ((payload_length >= sizeof(struct wlan_llc) +
410 && (e_llc->dsap == 0xaa) && (e_llc->ssap == 0xaa) 417 sizeof(struct wlan_snap))
411 && (e_llc->ctl == 0x03)) { 418 &&(e_llc->dsap == 0xaa)
419 && (e_llc->ssap == 0xaa)
420 && (e_llc->ctl == 0x03)) {
412 pr_debug("802.1h/RFC1042 len: %d\n", payload_length); 421 pr_debug("802.1h/RFC1042 len: %d\n", payload_length);
413 /* it's an 802.1h frame || (an RFC1042 && protocol is not in STT) */ 422 /* it's an 802.1h frame || (an RFC1042 && protocol not in STT)
414 /* build a DIXII + RFC894 */ 423 build a DIXII + RFC894 */
415 424
416 /* Test for an overlength frame */ 425 /* Test for an overlength frame */
417 if ((payload_length - sizeof(struct wlan_llc) - sizeof(struct wlan_snap)) 426 if ((payload_length - sizeof(struct wlan_llc) -
418 > netdev->mtu) { 427 sizeof(struct wlan_snap))
428 > netdev->mtu) {
419 /* A bogus length ethfrm has been sent. */ 429 /* A bogus length ethfrm has been sent. */
420 /* Is someone trying an oflow attack? */ 430 /* Is someone trying an oflow attack? */
421 printk(KERN_ERR "DIXII frame too large (%ld > %d)\n", 431 printk(KERN_ERR "DIXII frame too large (%ld > %d)\n",
422 (long int)(payload_length - sizeof(struct wlan_llc) - 432 (long int)(payload_length -
423 sizeof(struct wlan_snap)), netdev->mtu); 433 sizeof(struct wlan_llc) -
434 sizeof(struct wlan_snap)), netdev->mtu);
424 return 1; 435 return 1;
425 } 436 }
426 437
diff --git a/drivers/staging/wlan-ng/p80211conv.h b/drivers/staging/wlan-ng/p80211conv.h
index eca0391c676f..ea493aa74f00 100644
--- a/drivers/staging/wlan-ng/p80211conv.h
+++ b/drivers/staging/wlan-ng/p80211conv.h
@@ -66,12 +66,14 @@
66#define P80211_FRMMETA_MAGIC 0x802110 66#define P80211_FRMMETA_MAGIC 0x802110
67 67
68#define P80211SKB_FRMMETA(s) \ 68#define P80211SKB_FRMMETA(s) \
69 (((((struct p80211_frmmeta *)((s)->cb))->magic) == P80211_FRMMETA_MAGIC) ? \ 69 (((((struct p80211_frmmeta *)((s)->cb))->magic) == \
70 P80211_FRMMETA_MAGIC) ? \
70 ((struct p80211_frmmeta *)((s)->cb)) : \ 71 ((struct p80211_frmmeta *)((s)->cb)) : \
71 (NULL)) 72 (NULL))
72 73
73#define P80211SKB_RXMETA(s) \ 74#define P80211SKB_RXMETA(s) \
74 (P80211SKB_FRMMETA((s)) ? P80211SKB_FRMMETA((s))->rx : ((struct p80211_rxmeta *)(NULL))) 75 (P80211SKB_FRMMETA((s)) ? P80211SKB_FRMMETA((s))->rx : \
76 ((struct p80211_rxmeta *)(NULL)))
75 77
76struct p80211_rxmeta { 78struct p80211_rxmeta {
77 struct wlandevice *wlandev; 79 struct wlandevice *wlandev;
diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
index b7b4a733b467..b0af292bc7e3 100644
--- a/drivers/staging/wlan-ng/p80211netdev.c
+++ b/drivers/staging/wlan-ng/p80211netdev.c
@@ -301,7 +301,8 @@ static void p80211netdev_rx_bh(unsigned long arg)
301 if (memcmp 301 if (memcmp
302 (hdr->a1, wlandev->netdev->dev_addr, 302 (hdr->a1, wlandev->netdev->dev_addr,
303 ETH_ALEN) != 0) { 303 ETH_ALEN) != 0) {
304 /* but reject anything else that isn't multicast */ 304 /* but reject anything else that
305 isn't multicast */
305 if (!(hdr->a1[0] & 0x01)) { 306 if (!(hdr->a1[0] & 0x01)) {
306 dev_kfree_skb(skb); 307 dev_kfree_skb(skb);
307 continue; 308 continue;
@@ -770,7 +771,8 @@ int wlan_setup(wlandevice_t *wlandev, struct device *physdev)
770 } 771 }
771 772
772 /* Allocate and initialize the struct device */ 773 /* Allocate and initialize the struct device */
773 netdev = alloc_netdev(sizeof(struct wireless_dev), "wlan%d", ether_setup); 774 netdev = alloc_netdev(sizeof(struct wireless_dev), "wlan%d",
775 ether_setup);
774 if (netdev == NULL) { 776 if (netdev == NULL) {
775 printk(KERN_ERR "Failed to alloc netdev.\n"); 777 printk(KERN_ERR "Failed to alloc netdev.\n");
776 wlan_free_wiphy(wiphy); 778 wlan_free_wiphy(wiphy);
diff --git a/drivers/staging/wlan-ng/p80211netdev.h b/drivers/staging/wlan-ng/p80211netdev.h
index 1ec33740f10f..85884176b661 100644
--- a/drivers/staging/wlan-ng/p80211netdev.h
+++ b/drivers/staging/wlan-ng/p80211netdev.h
@@ -94,11 +94,11 @@ typedef struct net_device netdevice_t;
94#endif 94#endif
95 95
96/*--- NSD Capabilities Flags ------------------------------*/ 96/*--- NSD Capabilities Flags ------------------------------*/
97#define P80211_NSDCAP_HARDWAREWEP 0x01 /* hardware wep engine */ 97#define P80211_NSDCAP_HARDWAREWEP 0x01 /* hardware wep engine */
98#define P80211_NSDCAP_SHORT_PREAMBLE 0x10 /* hardware supports */ 98#define P80211_NSDCAP_SHORT_PREAMBLE 0x10 /* hardware supports */
99#define P80211_NSDCAP_HWFRAGMENT 0x80 /* nsd handles frag/defrag */ 99#define P80211_NSDCAP_HWFRAGMENT 0x80 /* nsd handles frag/defrag */
100#define P80211_NSDCAP_AUTOJOIN 0x100 /* nsd does autojoin */ 100#define P80211_NSDCAP_AUTOJOIN 0x100 /* nsd does autojoin */
101#define P80211_NSDCAP_NOSCAN 0x200 /* nsd can scan */ 101#define P80211_NSDCAP_NOSCAN 0x200 /* nsd can scan */
102 102
103/* Received frame statistics */ 103/* Received frame statistics */
104typedef struct p80211_frmrx_t { 104typedef struct p80211_frmrx_t {
diff --git a/drivers/staging/wlan-ng/p80211types.h b/drivers/staging/wlan-ng/p80211types.h
index 41a99c59c6c5..9dec8596f451 100644
--- a/drivers/staging/wlan-ng/p80211types.h
+++ b/drivers/staging/wlan-ng/p80211types.h
@@ -141,14 +141,14 @@
141#define P80211DID_LSB_ITEM (12) 141#define P80211DID_LSB_ITEM (12)
142#define P80211DID_LSB_INDEX (18) 142#define P80211DID_LSB_INDEX (18)
143#define P80211DID_LSB_ISTABLE (26) 143#define P80211DID_LSB_ISTABLE (26)
144#define P80211DID_LSB_ACCESS (27) 144#define P80211DID_LSB_ACCESS (27)
145 145
146#define P80211DID_MASK_SECTION (0x0000003fUL) 146#define P80211DID_MASK_SECTION (0x0000003fUL)
147#define P80211DID_MASK_GROUP (0x0000003fUL) 147#define P80211DID_MASK_GROUP (0x0000003fUL)
148#define P80211DID_MASK_ITEM (0x0000003fUL) 148#define P80211DID_MASK_ITEM (0x0000003fUL)
149#define P80211DID_MASK_INDEX (0x000000ffUL) 149#define P80211DID_MASK_INDEX (0x000000ffUL)
150#define P80211DID_MASK_ISTABLE (0x00000001UL) 150#define P80211DID_MASK_ISTABLE (0x00000001UL)
151#define P80211DID_MASK_ACCESS (0x00000003UL) 151#define P80211DID_MASK_ACCESS (0x00000003UL)
152 152
153#define P80211DID_MK(a, m, l) ((((u32)(a)) & (m)) << (l)) 153#define P80211DID_MK(a, m, l) ((((u32)(a)) & (m)) << (l))
154 154
diff --git a/drivers/staging/wlan-ng/prism2mgmt.c b/drivers/staging/wlan-ng/prism2mgmt.c
index 04514a85d101..6675c8226cef 100644
--- a/drivers/staging/wlan-ng/prism2mgmt.c
+++ b/drivers/staging/wlan-ng/prism2mgmt.c
@@ -213,8 +213,8 @@ int prism2mgmt_scan(wlandevice_t *wlandev, void *msgp)
213 u16 wordbuf[17]; 213 u16 wordbuf[17];
214 214
215 result = hfa384x_drvr_setconfig16(hw, 215 result = hfa384x_drvr_setconfig16(hw,
216 HFA384x_RID_CNFROAMINGMODE, 216 HFA384x_RID_CNFROAMINGMODE,
217 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM); 217 HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM);
218 if (result) { 218 if (result) {
219 printk(KERN_ERR 219 printk(KERN_ERR
220 "setconfig(ROAMINGMODE) failed. result=%d\n", 220 "setconfig(ROAMINGMODE) failed. result=%d\n",
@@ -258,8 +258,8 @@ int prism2mgmt_scan(wlandevice_t *wlandev, void *msgp)
258 } 258 }
259 /* ibss options */ 259 /* ibss options */
260 result = hfa384x_drvr_setconfig16(hw, 260 result = hfa384x_drvr_setconfig16(hw,
261 HFA384x_RID_CREATEIBSS, 261 HFA384x_RID_CREATEIBSS,
262 HFA384x_CREATEIBSS_JOINCREATEIBSS); 262 HFA384x_CREATEIBSS_JOINCREATEIBSS);
263 if (result) { 263 if (result) {
264 printk(KERN_ERR "Failed to set CREATEIBSS.\n"); 264 printk(KERN_ERR "Failed to set CREATEIBSS.\n");
265 msg->resultcode.data = 265 msg->resultcode.data =
@@ -416,7 +416,8 @@ int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
416#define REQBASICRATE(N) \ 416#define REQBASICRATE(N) \
417 if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \ 417 if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \
418 req->basicrate ## N .data = item->supprates[(N)-1]; \ 418 req->basicrate ## N .data = item->supprates[(N)-1]; \
419 req->basicrate ## N .status = P80211ENUM_msgitem_status_data_ok; \ 419 req->basicrate ## N .status = \
420 P80211ENUM_msgitem_status_data_ok; \
420 } 421 }
421 422
422 REQBASICRATE(1); 423 REQBASICRATE(1);
@@ -431,7 +432,8 @@ int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
431#define REQSUPPRATE(N) \ 432#define REQSUPPRATE(N) \
432 if (count >= N) { \ 433 if (count >= N) { \
433 req->supprate ## N .data = item->supprates[(N)-1]; \ 434 req->supprate ## N .data = item->supprates[(N)-1]; \
434 req->supprate ## N .status = P80211ENUM_msgitem_status_data_ok; \ 435 req->supprate ## N .status = \
436 P80211ENUM_msgitem_status_data_ok; \
435 } 437 }
436 438
437 REQSUPPRATE(1); 439 REQSUPPRATE(1);
@@ -1102,7 +1104,7 @@ int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1102 result = hfa384x_drvr_disable(hw, 0); 1104 result = hfa384x_drvr_disable(hw, 0);
1103 if (result) { 1105 if (result) {
1104 pr_debug 1106 pr_debug
1105 ("failed to disable port 0 after sniffing, result=%d\n", 1107 ("failed to disable port 0 after sniffing, result=%d\n",
1106 result); 1108 result);
1107 goto failed; 1109 goto failed;
1108 } 1110 }
@@ -1137,7 +1139,7 @@ int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1137 result = hfa384x_drvr_enable(hw, 0); 1139 result = hfa384x_drvr_enable(hw, 0);
1138 if (result) { 1140 if (result) {
1139 pr_debug 1141 pr_debug
1140 ("failed to enable port to presniff setting, result=%d\n", 1142 ("failed to enable port to presniff setting, result=%d\n",
1141 result); 1143 result);
1142 goto failed; 1144 goto failed;
1143 } 1145 }
@@ -1161,7 +1163,7 @@ int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1161 &(hw->presniff_port_type)); 1163 &(hw->presniff_port_type));
1162 if (result) { 1164 if (result) {
1163 pr_debug 1165 pr_debug
1164 ("failed to read porttype, result=%d\n", 1166 ("failed to read porttype, result=%d\n",
1165 result); 1167 result);
1166 goto failed; 1168 goto failed;
1167 } 1169 }
@@ -1171,7 +1173,7 @@ int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1171 &(hw->presniff_wepflags)); 1173 &(hw->presniff_wepflags));
1172 if (result) { 1174 if (result) {
1173 pr_debug 1175 pr_debug
1174 ("failed to read wepflags, result=%d\n", 1176 ("failed to read wepflags, result=%d\n",
1175 result); 1177 result);
1176 goto failed; 1178 goto failed;
1177 } 1179 }
@@ -1238,8 +1240,8 @@ int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1238 1240
1239 if (result) { 1241 if (result) {
1240 pr_debug 1242 pr_debug
1241 ("failed to set wepflags=0x%04x, result=%d\n", 1243 ("failed to set wepflags=0x%04x, result=%d\n",
1242 word, result); 1244 word, result);
1243 goto failed; 1245 goto failed;
1244 } 1246 }
1245 } 1247 }
diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c
index 4f73d095c3ac..ee008e5a0cbc 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -472,9 +472,11 @@ unsigned char XGIfb_query_north_bridge_space(struct xgi_hw_device_info *pXGIhw_e
472 break; 472 break;
473 } 473 }
474 474
475 pdev = pci_find_device(PCI_VENDOR_ID_SI, nbridge_id, pdev); 475 pdev = pci_get_device(PCI_VENDOR_ID_SI, nbridge_id, pdev);
476 if (pdev) 476 if (pdev) {
477 valid_pdev = 1; 477 valid_pdev = 1;
478 pci_dev_put(pdev);
479 }
478 } 480 }
479 481
480 if (!valid_pdev) { 482 if (!valid_pdev) {
@@ -2178,8 +2180,7 @@ static int XGIfb_heap_init(void)
2178 2180
2179#ifndef AGPOFF 2181#ifndef AGPOFF
2180 if (XGIfb_queuemode == AGP_CMD_QUEUE) { 2182 if (XGIfb_queuemode == AGP_CMD_QUEUE) {
2181 agp_info = vmalloc(sizeof(*agp_info)); 2183 agp_info = vzalloc(sizeof(*agp_info));
2182 memset((void *)agp_info, 0x00, sizeof(*agp_info));
2183 agp_copy_info(agp_info); 2184 agp_copy_info(agp_info);
2184 2185
2185 agp_backend_acquire(); 2186 agp_backend_acquire();
diff --git a/drivers/staging/zram/xvmalloc.c b/drivers/staging/zram/xvmalloc.c
index 3fdbb8ada827..b64406739d05 100644
--- a/drivers/staging/zram/xvmalloc.c
+++ b/drivers/staging/zram/xvmalloc.c
@@ -187,7 +187,7 @@ static void insert_block(struct xv_pool *pool, struct page *page, u32 offset,
187 slindex = get_index_for_insert(block->size); 187 slindex = get_index_for_insert(block->size);
188 flindex = slindex / BITS_PER_LONG; 188 flindex = slindex / BITS_PER_LONG;
189 189
190 block->link.prev_page = 0; 190 block->link.prev_page = NULL;
191 block->link.prev_offset = 0; 191 block->link.prev_offset = 0;
192 block->link.next_page = pool->freelist[slindex].page; 192 block->link.next_page = pool->freelist[slindex].page;
193 block->link.next_offset = pool->freelist[slindex].offset; 193 block->link.next_offset = pool->freelist[slindex].offset;
@@ -217,7 +217,7 @@ static void remove_block_head(struct xv_pool *pool,
217 217
218 pool->freelist[slindex].page = block->link.next_page; 218 pool->freelist[slindex].page = block->link.next_page;
219 pool->freelist[slindex].offset = block->link.next_offset; 219 pool->freelist[slindex].offset = block->link.next_offset;
220 block->link.prev_page = 0; 220 block->link.prev_page = NULL;
221 block->link.prev_offset = 0; 221 block->link.prev_offset = 0;
222 222
223 if (!pool->freelist[slindex].page) { 223 if (!pool->freelist[slindex].page) {
@@ -232,7 +232,7 @@ static void remove_block_head(struct xv_pool *pool,
232 */ 232 */
233 tmpblock = get_ptr_atomic(pool->freelist[slindex].page, 233 tmpblock = get_ptr_atomic(pool->freelist[slindex].page,
234 pool->freelist[slindex].offset, KM_USER1); 234 pool->freelist[slindex].offset, KM_USER1);
235 tmpblock->link.prev_page = 0; 235 tmpblock->link.prev_page = NULL;
236 tmpblock->link.prev_offset = 0; 236 tmpblock->link.prev_offset = 0;
237 put_ptr_atomic(tmpblock, KM_USER1); 237 put_ptr_atomic(tmpblock, KM_USER1);
238 } 238 }
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index d0e9e0207539..5415712f01f8 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -527,7 +527,7 @@ int zram_init_device(struct zram *zram)
527 } 527 }
528 528
529 num_pages = zram->disksize >> PAGE_SHIFT; 529 num_pages = zram->disksize >> PAGE_SHIFT;
530 zram->table = vmalloc(num_pages * sizeof(*zram->table)); 530 zram->table = vzalloc(num_pages * sizeof(*zram->table));
531 if (!zram->table) { 531 if (!zram->table) {
532 pr_err("Error allocating zram address table\n"); 532 pr_err("Error allocating zram address table\n");
533 /* To prevent accessing table entries during cleanup */ 533 /* To prevent accessing table entries during cleanup */
@@ -535,7 +535,6 @@ int zram_init_device(struct zram *zram)
535 ret = -ENOMEM; 535 ret = -ENOMEM;
536 goto fail; 536 goto fail;
537 } 537 }
538 memset(zram->table, 0, num_pages * sizeof(*zram->table));
539 538
540 set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); 539 set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
541 540
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index cdfb1868caef..748778288d94 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -615,7 +615,6 @@ static const struct usb_device_id option_ids[] = {
615 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0004, 0xff, 0xff, 0xff) }, 615 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0004, 0xff, 0xff, 0xff) },
616 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0005, 0xff, 0xff, 0xff) }, 616 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0005, 0xff, 0xff, 0xff) },
617 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0006, 0xff, 0xff, 0xff) }, 617 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0006, 0xff, 0xff, 0xff) },
618 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0007, 0xff, 0xff, 0xff) },
619 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0008, 0xff, 0xff, 0xff) }, 618 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0008, 0xff, 0xff, 0xff) },
620 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0009, 0xff, 0xff, 0xff) }, 619 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0009, 0xff, 0xff, 0xff) },
621 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x000a, 0xff, 0xff, 0xff) }, 620 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x000a, 0xff, 0xff, 0xff) },
diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
index 020589a6bf02..2c8364e9b632 100644
--- a/drivers/video/udlfb.c
+++ b/drivers/video/udlfb.c
@@ -1128,14 +1128,13 @@ static int dlfb_realloc_framebuffer(struct dlfb_data *dev, struct fb_info *info)
1128 * But with imperfect damage info we may send pixels over USB 1128 * But with imperfect damage info we may send pixels over USB
1129 * that were, in fact, unchanged - wasting limited USB bandwidth 1129 * that were, in fact, unchanged - wasting limited USB bandwidth
1130 */ 1130 */
1131 new_back = vmalloc(new_len); 1131 new_back = vzalloc(new_len);
1132 if (!new_back) 1132 if (!new_back)
1133 pr_info("No shadow/backing buffer allcoated\n"); 1133 pr_info("No shadow/backing buffer allocated\n");
1134 else { 1134 else {
1135 if (dev->backing_buffer) 1135 if (dev->backing_buffer)
1136 vfree(dev->backing_buffer); 1136 vfree(dev->backing_buffer);
1137 dev->backing_buffer = new_back; 1137 dev->backing_buffer = new_back;
1138 memset(dev->backing_buffer, 0, new_len);
1139 } 1138 }
1140 } 1139 }
1141 1140
diff --git a/include/linux/rar_register.h b/include/linux/rar_register.h
index ffa805780f85..5c6118189363 100644
--- a/include/linux/rar_register.h
+++ b/include/linux/rar_register.h
@@ -34,11 +34,27 @@
34 34
35struct rar_device; 35struct rar_device;
36 36
37#if defined(CONFIG_RAR_REGISTER)
37int register_rar(int num, 38int register_rar(int num,
38 int (*callback)(unsigned long data), unsigned long data); 39 int (*callback)(unsigned long data), unsigned long data);
39void unregister_rar(int num); 40void unregister_rar(int num);
40int rar_get_address(int rar_index, dma_addr_t *start, dma_addr_t *end); 41int rar_get_address(int rar_index, dma_addr_t *start, dma_addr_t *end);
41int rar_lock(int rar_index); 42int rar_lock(int rar_index);
43#else
44extern void unregister_rar(int num) { }
45extern int rar_lock(int rar_index) { return -EIO; }
46
47extern inline int register_rar(int num,
48 int (*callback)(unsigned long data), unsigned long data)
49{
50 return -ENODEV;
51}
52
53extern int rar_get_address(int rar_index, dma_addr_t *start, dma_addr_t *end)
54{
55 return -ENODEV;
56}
57#endif /* RAR_REGISTER */
42 58
43#endif /* __KERNEL__ */ 59#endif /* __KERNEL__ */
44#endif /* _RAR_REGISTER_H */ 60#endif /* _RAR_REGISTER_H */