Merge branch 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvar...
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 21 May 2010 17:49:43 +0000 (10:49 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 21 May 2010 17:49:43 +0000 (10:49 -0700)
* 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging:
  i2c-nforce2: Remove redundant error messages on ACPI conflict
  i2c: Use <linux/io.h> instead of <asm/io.h>
  i2c-algo-pca: Fix coding style issues
  i2c-dev: Fix all coding style issues
  i2c-core: Fix some coding style issues
  i2c-gpio: Move initialization code to subsys_initcall()
  i2c-parport: Make template structure const
  i2c-dev: Remove unnecessary casts
  at24: Fall back to byte or word reads if needed
  i2c-stub: Expose the default functionality flags
  i2c/scx200_acb: Make PCI device ids constant
  i2c-i801: Fix all checkpatch warnings
  i2c-i801: All newer devices have all the optional features
  i2c-i801: Let the user disable selected driver features

513 files changed:
Documentation/filesystems/gfs2.txt
Documentation/filesystems/nilfs2.txt
Documentation/filesystems/ocfs2.txt
Documentation/filesystems/sysfs-tagging.txt [new file with mode: 0644]
MAINTAINERS
arch/alpha/kernel/pci-sysfs.c
arch/arm/mach-ep93xx/include/mach/ts72xx.h
arch/arm/mach-ep93xx/ts72xx.c
arch/arm/mach-kirkwood/common.c
arch/arm/mach-kirkwood/common.h
arch/arm/plat-orion/include/plat/orion_nand.h
arch/mips/txx9/generic/setup.c
arch/powerpc/sysdev/mv64x60_pci.c
arch/s390/kernel/ipl.c
drivers/acpi/system.c
drivers/base/Kconfig
drivers/base/class.c
drivers/base/core.c
drivers/base/cpu.c
drivers/base/dd.c
drivers/base/devtmpfs.c
drivers/base/firmware_class.c
drivers/base/module.c
drivers/base/platform.c
drivers/block/loop.c
drivers/char/Kconfig
drivers/char/Makefile
drivers/char/isicom.c
drivers/char/n_gsm.c [new file with mode: 0644]
drivers/char/serial167.c
drivers/char/tty_buffer.c
drivers/firmware/dcdbas.c
drivers/firmware/dell_rbu.c
drivers/firmware/efivars.c
drivers/gpio/gpiolib.c
drivers/gpu/drm/drm_sysfs.c
drivers/md/bitmap.c
drivers/md/md.c
drivers/message/fusion/mptbase.c
drivers/message/fusion/mptbase.h
drivers/message/fusion/mptctl.c
drivers/message/fusion/mptfc.c
drivers/message/fusion/mptsas.c
drivers/message/fusion/mptsas.h
drivers/message/fusion/mptscsih.c
drivers/message/fusion/mptspi.c
drivers/misc/c2port/core.c
drivers/misc/ds1682.c
drivers/misc/eeprom/at24.c
drivers/misc/eeprom/at25.c
drivers/misc/eeprom/eeprom.c
drivers/misc/eeprom/max6875.c
drivers/mtd/Kconfig
drivers/mtd/Makefile
drivers/mtd/chips/cfi_cmdset_0001.c
drivers/mtd/chips/cfi_cmdset_0002.c
drivers/mtd/chips/cfi_cmdset_0020.c
drivers/mtd/chips/cfi_probe.c
drivers/mtd/chips/cfi_util.c
drivers/mtd/chips/fwh_lock.h
drivers/mtd/chips/gen_probe.c
drivers/mtd/chips/jedec_probe.c
drivers/mtd/devices/Makefile
drivers/mtd/devices/block2mtd.c
drivers/mtd/devices/pmc551.c
drivers/mtd/devices/sst25l.c
drivers/mtd/ftl.c
drivers/mtd/inftlcore.c
drivers/mtd/inftlmount.c
drivers/mtd/lpddr/lpddr_cmds.c
drivers/mtd/lpddr/qinfo_probe.c
drivers/mtd/maps/Kconfig
drivers/mtd/maps/bfin-async-flash.c
drivers/mtd/maps/ceiva.c
drivers/mtd/maps/ixp2000.c
drivers/mtd/maps/ixp4xx.c
drivers/mtd/maps/pcmciamtd.c
drivers/mtd/maps/physmap.c
drivers/mtd/maps/physmap_of.c
drivers/mtd/maps/pismo.c
drivers/mtd/maps/pxa2xx-flash.c
drivers/mtd/mtd_blkdevs.c
drivers/mtd/mtdblock.c
drivers/mtd/mtdblock_ro.c
drivers/mtd/mtdchar.c
drivers/mtd/mtdconcat.c
drivers/mtd/mtdcore.c
drivers/mtd/mtdcore.h
drivers/mtd/mtdoops.c
drivers/mtd/mtdsuper.c
drivers/mtd/nand/Kconfig
drivers/mtd/nand/Makefile
drivers/mtd/nand/alauda.c
drivers/mtd/nand/atmel_nand.c
drivers/mtd/nand/au1550nd.c
drivers/mtd/nand/bcm_umi_nand.c
drivers/mtd/nand/bf5xx_nand.c
drivers/mtd/nand/cafe_nand.c
drivers/mtd/nand/davinci_nand.c
drivers/mtd/nand/denali.c [new file with mode: 0644]
drivers/mtd/nand/denali.h [new file with mode: 0644]
drivers/mtd/nand/fsl_elbc_nand.c
drivers/mtd/nand/fsl_upm.c
drivers/mtd/nand/gpio.c
drivers/mtd/nand/mpc5121_nfc.c [new file with mode: 0644]
drivers/mtd/nand/mxc_nand.c
drivers/mtd/nand/nand_base.c
drivers/mtd/nand/nand_bbt.c
drivers/mtd/nand/nand_bcm_umi.h
drivers/mtd/nand/nand_ids.c
drivers/mtd/nand/nandsim.c
drivers/mtd/nand/nomadik_nand.c
drivers/mtd/nand/nuc900_nand.c [moved from drivers/mtd/nand/w90p910_nand.c with 63% similarity]
drivers/mtd/nand/omap2.c
drivers/mtd/nand/orion_nand.c
drivers/mtd/nand/pasemi_nand.c
drivers/mtd/nand/pxa3xx_nand.c
drivers/mtd/nand/r852.c [new file with mode: 0644]
drivers/mtd/nand/r852.h [new file with mode: 0644]
drivers/mtd/nand/s3c2410.c
drivers/mtd/nand/sh_flctl.c
drivers/mtd/nand/sm_common.c [new file with mode: 0644]
drivers/mtd/nand/sm_common.h [new file with mode: 0644]
drivers/mtd/nand/socrates_nand.c
drivers/mtd/nand/tmio_nand.c
drivers/mtd/nand/ts7250.c [deleted file]
drivers/mtd/nand/txx9ndfmc.c
drivers/mtd/nftlcore.c
drivers/mtd/onenand/Kconfig
drivers/mtd/onenand/Makefile
drivers/mtd/onenand/omap2.c
drivers/mtd/onenand/onenand_base.c
drivers/mtd/onenand/samsung.c [new file with mode: 0644]
drivers/mtd/rfd_ftl.c
drivers/mtd/sm_ftl.c [new file with mode: 0644]
drivers/mtd/sm_ftl.h [new file with mode: 0644]
drivers/mtd/ssfdc.c
drivers/mtd/tests/mtd_pagetest.c
drivers/mtd/tests/mtd_readtest.c
drivers/mtd/tests/mtd_speedtest.c
drivers/mtd/tests/mtd_stresstest.c
drivers/mtd/tests/mtd_subpagetest.c
drivers/mtd/ubi/Kconfig
drivers/mtd/ubi/build.c
drivers/mtd/ubi/io.c
drivers/mtd/ubi/kapi.c
drivers/mtd/ubi/scan.c
drivers/mtd/ubi/ubi.h
drivers/mtd/ubi/vtbl.c
drivers/mtd/ubi/wl.c
drivers/net/mlx4/mlx4.h
drivers/net/netxen/netxen_nic_main.c
drivers/net/qlcnic/qlcnic_main.c
drivers/pci/hotplug/acpiphp_ibm.c
drivers/pci/pci-sysfs.c
drivers/pcmcia/cistpl.c
drivers/power/olpc_battery.c
drivers/rapidio/rio-sysfs.c
drivers/rtc/rtc-cmos.c
drivers/rtc/rtc-ds1305.c
drivers/rtc/rtc-ds1307.c
drivers/rtc/rtc-ds1511.c
drivers/rtc/rtc-ds1553.c
drivers/rtc/rtc-ds1742.c
drivers/rtc/rtc-m48t59.c
drivers/rtc/rtc-stk17ta8.c
drivers/rtc/rtc-tx4939.c
drivers/s390/cio/chp.c
drivers/s390/scsi/zfcp_aux.c
drivers/s390/scsi/zfcp_def.h
drivers/s390/scsi/zfcp_erp.c
drivers/s390/scsi/zfcp_ext.h
drivers/s390/scsi/zfcp_fc.c
drivers/s390/scsi/zfcp_fsf.c
drivers/s390/scsi/zfcp_fsf.h
drivers/s390/scsi/zfcp_qdio.c
drivers/s390/scsi/zfcp_qdio.h
drivers/s390/scsi/zfcp_scsi.c
drivers/scsi/3w-9xxx.c
drivers/scsi/3w-9xxx.h
drivers/scsi/3w-sas.c
drivers/scsi/3w-xxxx.c
drivers/scsi/3w-xxxx.h
drivers/scsi/Makefile
drivers/scsi/a2091.c
drivers/scsi/a2091.h
drivers/scsi/a3000.c
drivers/scsi/a3000.h
drivers/scsi/aacraid/aachba.c
drivers/scsi/aacraid/aacraid.h
drivers/scsi/aacraid/commsup.c
drivers/scsi/arcmsr/arcmsr_attr.c
drivers/scsi/bfa/bfa_cb_ioim_macros.h
drivers/scsi/bfa/bfa_ioim.c
drivers/scsi/bfa/bfa_os_inc.h
drivers/scsi/bfa/bfad.c
drivers/scsi/bfa/bfad_attr.c
drivers/scsi/bfa/bfad_drv.h
drivers/scsi/bfa/bfad_im.c
drivers/scsi/bfa/bfad_im.h
drivers/scsi/bnx2i/bnx2i_hwi.c
drivers/scsi/bnx2i/bnx2i_init.c
drivers/scsi/cxgb3i/cxgb3i_init.c
drivers/scsi/device_handler/scsi_dh_emc.c
drivers/scsi/fcoe/fcoe.c
drivers/scsi/fcoe/libfcoe.c
drivers/scsi/fnic/fnic.h
drivers/scsi/fnic/fnic_fcs.c
drivers/scsi/fnic/fnic_main.c
drivers/scsi/gdth.c
drivers/scsi/gvp11.c
drivers/scsi/gvp11.h
drivers/scsi/hpsa.c
drivers/scsi/hpsa_cmd.h
drivers/scsi/ibmvscsi/ibmvfc.c
drivers/scsi/ibmvscsi/ibmvfc.h
drivers/scsi/ipr.c
drivers/scsi/iscsi_tcp.c
drivers/scsi/iscsi_tcp.h
drivers/scsi/libfc/fc_disc.c
drivers/scsi/libfc/fc_elsct.c
drivers/scsi/libfc/fc_exch.c
drivers/scsi/libfc/fc_fcp.c
drivers/scsi/libfc/fc_libfc.h
drivers/scsi/libfc/fc_lport.c
drivers/scsi/libfc/fc_npiv.c
drivers/scsi/libfc/fc_rport.c
drivers/scsi/libiscsi_tcp.c
drivers/scsi/libsas/sas_ata.c
drivers/scsi/libsas/sas_scsi_host.c
drivers/scsi/lpfc/lpfc.h
drivers/scsi/lpfc/lpfc_attr.c
drivers/scsi/lpfc/lpfc_bsg.c
drivers/scsi/lpfc/lpfc_bsg.h
drivers/scsi/lpfc/lpfc_crtn.h
drivers/scsi/lpfc/lpfc_disc.h
drivers/scsi/lpfc/lpfc_els.c
drivers/scsi/lpfc/lpfc_hbadisc.c
drivers/scsi/lpfc/lpfc_hw.h
drivers/scsi/lpfc/lpfc_hw4.h
drivers/scsi/lpfc/lpfc_init.c
drivers/scsi/lpfc/lpfc_mbox.c
drivers/scsi/lpfc/lpfc_nportdisc.c
drivers/scsi/lpfc/lpfc_scsi.c
drivers/scsi/lpfc/lpfc_sli.c
drivers/scsi/lpfc/lpfc_sli.h
drivers/scsi/lpfc/lpfc_sli4.h
drivers/scsi/lpfc/lpfc_version.h
drivers/scsi/lpfc/lpfc_vport.c
drivers/scsi/mpt2sas/Kconfig
drivers/scsi/mpt2sas/mpi/mpi2.h
drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
drivers/scsi/mpt2sas/mpi/mpi2_history.txt
drivers/scsi/mpt2sas/mpi/mpi2_init.h
drivers/scsi/mpt2sas/mpi/mpi2_ioc.h
drivers/scsi/mpt2sas/mpi/mpi2_tool.h
drivers/scsi/mpt2sas/mpt2sas_base.c
drivers/scsi/mpt2sas/mpt2sas_base.h
drivers/scsi/mpt2sas/mpt2sas_config.c
drivers/scsi/mpt2sas/mpt2sas_ctl.c
drivers/scsi/mpt2sas/mpt2sas_ctl.h
drivers/scsi/mpt2sas/mpt2sas_debug.h
drivers/scsi/mpt2sas/mpt2sas_scsih.c
drivers/scsi/mpt2sas/mpt2sas_transport.c
drivers/scsi/mvme147.c
drivers/scsi/mvme147.h
drivers/scsi/mvsas/mv_64xx.c
drivers/scsi/mvsas/mv_94xx.c
drivers/scsi/mvsas/mv_init.c
drivers/scsi/mvsas/mv_sas.c
drivers/scsi/mvsas/mv_sas.h
drivers/scsi/pm8001/pm8001_hwi.c
drivers/scsi/pm8001/pm8001_sas.c
drivers/scsi/pmcraid.c
drivers/scsi/qla2xxx/Makefile
drivers/scsi/qla2xxx/qla_attr.c
drivers/scsi/qla2xxx/qla_bsg.c [new file with mode: 0644]
drivers/scsi/qla2xxx/qla_bsg.h [new file with mode: 0644]
drivers/scsi/qla2xxx/qla_dbg.c
drivers/scsi/qla2xxx/qla_dbg.h
drivers/scsi/qla2xxx/qla_def.h
drivers/scsi/qla2xxx/qla_fw.h
drivers/scsi/qla2xxx/qla_gbl.h
drivers/scsi/qla2xxx/qla_gs.c
drivers/scsi/qla2xxx/qla_init.c
drivers/scsi/qla2xxx/qla_inline.h
drivers/scsi/qla2xxx/qla_iocb.c
drivers/scsi/qla2xxx/qla_isr.c
drivers/scsi/qla2xxx/qla_mbx.c
drivers/scsi/qla2xxx/qla_nx.c [new file with mode: 0644]
drivers/scsi/qla2xxx/qla_nx.h [new file with mode: 0644]
drivers/scsi/qla2xxx/qla_os.c
drivers/scsi/qla2xxx/qla_sup.c
drivers/scsi/qla4xxx/ql4_def.h
drivers/scsi/qla4xxx/ql4_fw.h
drivers/scsi/qla4xxx/ql4_glbl.h
drivers/scsi/qla4xxx/ql4_init.c
drivers/scsi/qla4xxx/ql4_iocb.c
drivers/scsi/qla4xxx/ql4_isr.c
drivers/scsi/qla4xxx/ql4_mbx.c
drivers/scsi/qla4xxx/ql4_os.c
drivers/scsi/qla4xxx/ql4_version.h
drivers/scsi/scsi.c
drivers/scsi/scsi_debug.c
drivers/scsi/scsi_error.c
drivers/scsi/scsi_scan.c
drivers/scsi/scsi_sysfs.c
drivers/scsi/scsi_trace.c [new file with mode: 0644]
drivers/scsi/scsi_transport_fc.c
drivers/scsi/sd.c
drivers/scsi/wd33c93.c
drivers/scsi/wd33c93.h
drivers/serial/Kconfig
drivers/serial/Makefile
drivers/serial/altera_jtaguart.c [new file with mode: 0644]
drivers/serial/altera_uart.c [new file with mode: 0644]
drivers/serial/bfin_sport_uart.c
drivers/serial/bfin_sport_uart.h
drivers/serial/timbuart.c
drivers/serial/uartlite.c
drivers/staging/comedi/drivers/quatech_daqp_cs.c
drivers/staging/udlfb/udlfb.c
drivers/usb/core/sysfs.c
drivers/usb/core/usb.c
drivers/video/aty/radeon_base.c
drivers/w1/slaves/w1_ds2431.c
drivers/w1/slaves/w1_ds2433.c
drivers/w1/slaves/w1_ds2760.c
drivers/w1/w1.c
drivers/zorro/zorro-sysfs.c
fs/dlm/lock.c
fs/dlm/user.c
fs/gfs2/aops.c
fs/gfs2/bmap.c
fs/gfs2/dir.c
fs/gfs2/export.c
fs/gfs2/glock.c
fs/gfs2/incore.h
fs/gfs2/inode.c
fs/gfs2/inode.h
fs/gfs2/log.c
fs/gfs2/log.h
fs/gfs2/lops.c
fs/gfs2/main.c
fs/gfs2/meta_io.c
fs/gfs2/ops_fstype.c
fs/gfs2/quota.c
fs/gfs2/rgrp.c
fs/gfs2/super.c
fs/gfs2/sys.c
fs/gfs2/trans.c
fs/jffs2/background.c
fs/jffs2/erase.c
fs/jffs2/fs.c
fs/jffs2/gc.c
fs/jffs2/nodelist.h
fs/jffs2/nodemgmt.c
fs/jffs2/os-linux.h
fs/jffs2/scan.c
fs/jffs2/super.c
fs/jffs2/wbuf.c
fs/nilfs2/alloc.c
fs/nilfs2/alloc.h
fs/nilfs2/btree.c
fs/nilfs2/btree.h
fs/nilfs2/inode.c
fs/nilfs2/recovery.c
fs/nilfs2/segbuf.c
fs/nilfs2/segbuf.h
fs/nilfs2/segment.c
fs/nilfs2/segment.h
fs/nilfs2/super.c
fs/nilfs2/the_nilfs.c
fs/ocfs2/Makefile
fs/ocfs2/alloc.c
fs/ocfs2/alloc.h
fs/ocfs2/aops.c
fs/ocfs2/cluster/masklog.c
fs/ocfs2/cluster/masklog.h
fs/ocfs2/cluster/tcp.c
fs/ocfs2/dir.c
fs/ocfs2/dlm/dlmast.c
fs/ocfs2/dlm/dlmcommon.h
fs/ocfs2/dlm/dlmconvert.c
fs/ocfs2/dlm/dlmdomain.c
fs/ocfs2/dlm/dlmlock.c
fs/ocfs2/dlm/dlmmaster.c
fs/ocfs2/dlm/dlmrecovery.c
fs/ocfs2/dlm/dlmthread.c
fs/ocfs2/dlm/dlmunlock.c
fs/ocfs2/file.c
fs/ocfs2/inode.c
fs/ocfs2/inode.h
fs/ocfs2/journal.c
fs/ocfs2/journal.h
fs/ocfs2/localalloc.c
fs/ocfs2/localalloc.h
fs/ocfs2/mmap.c
fs/ocfs2/namei.c
fs/ocfs2/ocfs2.h
fs/ocfs2/ocfs2_fs.h
fs/ocfs2/quota_global.c
fs/ocfs2/quota_local.c
fs/ocfs2/refcounttree.c
fs/ocfs2/refcounttree.h
fs/ocfs2/reservations.c [new file with mode: 0644]
fs/ocfs2/reservations.h [new file with mode: 0644]
fs/ocfs2/resize.c
fs/ocfs2/suballoc.c
fs/ocfs2/suballoc.h
fs/ocfs2/super.c
fs/ocfs2/super.h
fs/ocfs2/xattr.c
fs/ramfs/inode.c
fs/sysfs/bin.c
fs/sysfs/dir.c
fs/sysfs/file.c
fs/sysfs/group.c
fs/sysfs/inode.c
fs/sysfs/mount.c
fs/sysfs/symlink.c
fs/sysfs/sysfs.h
fs/ubifs/io.c
fs/xfs/linux-2.6/xfs_aops.c
fs/xfs/linux-2.6/xfs_buf.c
fs/xfs/linux-2.6/xfs_buf.h
fs/xfs/linux-2.6/xfs_file.c
fs/xfs/linux-2.6/xfs_ioctl.c
fs/xfs/linux-2.6/xfs_ioctl32.c
fs/xfs/linux-2.6/xfs_iops.c
fs/xfs/linux-2.6/xfs_super.c
fs/xfs/linux-2.6/xfs_sync.c
fs/xfs/linux-2.6/xfs_trace.c
fs/xfs/linux-2.6/xfs_trace.h
fs/xfs/quota/xfs_dquot.c
fs/xfs/quota/xfs_dquot.h
fs/xfs/quota/xfs_dquot_item.c
fs/xfs/quota/xfs_qm.c
fs/xfs/quota/xfs_qm.h
fs/xfs/quota/xfs_qm_stats.c
fs/xfs/quota/xfs_qm_syscalls.c
fs/xfs/quota/xfs_quota_priv.h
fs/xfs/quota/xfs_trans_dquot.c
fs/xfs/xfs_bmap.c
fs/xfs/xfs_buf_item.c
fs/xfs/xfs_buf_item.h
fs/xfs/xfs_error.c
fs/xfs/xfs_error.h
fs/xfs/xfs_extfree_item.c
fs/xfs/xfs_inode.c
fs/xfs/xfs_inode_item.c
fs/xfs/xfs_iomap.c
fs/xfs/xfs_iomap.h
fs/xfs/xfs_log.c
fs/xfs/xfs_log.h
fs/xfs/xfs_log_priv.h
fs/xfs/xfs_log_recover.c
fs/xfs/xfs_mount.c
fs/xfs/xfs_quota.h
fs/xfs/xfs_trans.c
fs/xfs/xfs_trans.h
fs/xfs/xfs_trans_buf.c
include/linux/altera_jtaguart.h [new file with mode: 0644]
include/linux/altera_uart.h [new file with mode: 0644]
include/linux/device.h
include/linux/firmware.h
include/linux/ftrace_event.h
include/linux/gsmmux.h [new file with mode: 0644]
include/linux/interrupt.h
include/linux/jffs2.h
include/linux/kobject.h
include/linux/kref.h
include/linux/lockdep.h
include/linux/mtd/blktrans.h
include/linux/mtd/cfi.h
include/linux/mtd/flashchip.h
include/linux/mtd/map.h
include/linux/mtd/mtd.h
include/linux/mtd/mtdram.h
include/linux/mtd/nand.h
include/linux/mtd/onenand.h
include/linux/mtd/sh_flctl.h
include/linux/netlink.h
include/linux/nilfs2_fs.h
include/linux/ramfs.h
include/linux/serial_core.h
include/linux/sysfs.h
include/linux/tty.h
include/scsi/Kbuild
include/scsi/fc/fc_fcp.h
include/scsi/fc_encode.h
include/scsi/libfc.h
include/scsi/libfcoe.h
include/scsi/scsi.h
include/scsi/scsi_transport_fc.h
include/trace/events/scsi.h [new file with mode: 0644]
include/trace/ftrace.h
kernel/ksysfs.c
kernel/lockdep.c
kernel/module.c
kernel/trace/trace_output.c
kernel/user_namespace.c
lib/idr.c
lib/kobject.c
lib/kobject_uevent.c
lib/kref.c
net/bridge/br_sysfs_br.c
net/core/dev.c
net/core/net-sysfs.c
net/core/net-sysfs.h
net/netlink/af_netlink.c
scripts/checkpatch.pl
security/integrity/ima/ima_iint.c

index 5e3ab8f..0b59c02 100644 (file)
@@ -1,7 +1,7 @@
 Global File System
 ------------------
 
-http://sources.redhat.com/cluster/
+http://sources.redhat.com/cluster/wiki/
 
 GFS is a cluster file system. It allows a cluster of computers to
 simultaneously use a block device that is shared between them (with FC,
@@ -36,11 +36,11 @@ GFS2 is not on-disk compatible with previous versions of GFS, but it
 is pretty close.
 
 The following man pages can be found at the URL above:
-  fsck.gfs2    to repair a filesystem
-  gfs2_grow    to expand a filesystem online
-  gfs2_jadd    to add journals to a filesystem online
-  gfs2_tool    to manipulate, examine and tune a filesystem
+  fsck.gfs2            to repair a filesystem
+  gfs2_grow            to expand a filesystem online
+  gfs2_jadd            to add journals to a filesystem online
+  gfs2_tool            to manipulate, examine and tune a filesystem
   gfs2_quota   to examine and change quota values in a filesystem
   gfs2_convert to convert a gfs filesystem to gfs2 in-place
   mount.gfs2   to help mount(8) mount a filesystem
-  mkfs.gfs2    to make a filesystem
+  mkfs.gfs2            to make a filesystem
index cf6d0d8..d3e7673 100644 (file)
@@ -50,8 +50,8 @@ NILFS2 supports the following mount options:
 (*) == default
 
 nobarrier              Disables barriers.
-errors=continue(*)     Keep going on a filesystem error.
-errors=remount-ro      Remount the filesystem read-only on an error.
+errors=continue                Keep going on a filesystem error.
+errors=remount-ro(*)   Remount the filesystem read-only on an error.
 errors=panic           Panic and halt the machine if an error occurs.
 cp=n                   Specify the checkpoint-number of the snapshot to be
                        mounted.  Checkpoints and snapshots are listed by lscp
index c58b9f5..1f7ae14 100644 (file)
@@ -80,3 +80,10 @@ user_xattr   (*)     Enables Extended User Attributes.
 nouser_xattr           Disables Extended User Attributes.
 acl                    Enables POSIX Access Control Lists support.
 noacl          (*)     Disables POSIX Access Control Lists support.
+resv_level=2   (*)     Set how agressive allocation reservations will be.
+                       Valid values are between 0 (reservations off) to 8
+                       (maximum space for reservations).
+dir_resv_level=        (*)     By default, directory reservations will scale with file
+                       reservations - users should rarely need to change this
+                       value. If allocation reservations are turned off, this
+                       option will have no effect.
diff --git a/Documentation/filesystems/sysfs-tagging.txt b/Documentation/filesystems/sysfs-tagging.txt
new file mode 100644 (file)
index 0000000..caaaf12
--- /dev/null
@@ -0,0 +1,42 @@
+Sysfs tagging
+-------------
+
+(Taken almost verbatim from Eric Biederman's netns tagging patch
+commit msg)
+
+The problem.  Network devices show up in sysfs and with the network
+namespace active multiple devices with the same name can show up in
+the same directory, ouch!
+
+To avoid that problem and allow existing applications in network
+namespaces to see the same interface that is currently presented in
+sysfs, sysfs now has tagging directory support.
+
+By using the network namespace pointers as tags to separate out the
+the sysfs directory entries we ensure that we don't have conflicts
+in the directories and applications only see a limited set of
+the network devices.
+
+Each sysfs directory entry may be tagged with zero or one
+namespaces.  A sysfs_dirent is augmented with a void *s_ns.  If a
+directory entry is tagged, then sysfs_dirent->s_flags will have a
+flag between KOBJ_NS_TYPE_NONE and KOBJ_NS_TYPES, and s_ns will
+point to the namespace to which it belongs.
+
+Each sysfs superblock's sysfs_super_info contains an array void
+*ns[KOBJ_NS_TYPES].  When a a task in a tagging namespace
+kobj_nstype first mounts sysfs, a new superblock is created.  It
+will be differentiated from other sysfs mounts by having its
+s_fs_info->ns[kobj_nstype] set to the new namespace.  Note that
+through bind mounting and mounts propagation, a task can easily view
+the contents of other namespaces' sysfs mounts.  Therefore, when a
+namespace exits, it will call kobj_ns_exit() to invalidate any
+sysfs_dirent->s_ns pointers pointing to it.
+
+Users of this interface:
+- define a type in the kobj_ns_type enumeration.
+- call kobj_ns_type_register() with its kobj_ns_type_operations which has
+  - current_ns() which returns current's namespace
+  - netlink_ns() which returns a socket's namespace
+  - initial_ns() which returns the initial namesapce
+- call kobj_ns_exit() when an individual tag is no longer valid
index 22a49e6..a31a717 100644 (file)
@@ -131,19 +131,12 @@ L:        netdev@vger.kernel.org
 S:     Maintained
 F:     drivers/net/typhoon*
 
-3W-9XXX SATA-RAID CONTROLLER DRIVER
-M:     Adam Radford <linuxraid@amcc.com>
+3WARE SAS/SATA-RAID SCSI DRIVERS (3W-XXXX, 3W-9XXX, 3W-SAS)
+M:     Adam Radford <linuxraid@lsi.com>
 L:     linux-scsi@vger.kernel.org
-W:     http://www.amcc.com
+W:     http://www.lsi.com
 S:     Supported
-F:     drivers/scsi/3w-9xxx*
-
-3W-XXXX ATA-RAID CONTROLLER DRIVER
-M:     Adam Radford <linuxraid@amcc.com>
-L:     linux-scsi@vger.kernel.org
-W:     http://www.amcc.com
-S:     Supported
-F:     drivers/scsi/3w-xxxx*
+F:     drivers/scsi/3w-*
 
 53C700 AND 53C700-66 SCSI DRIVER
 M:     "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
@@ -4621,6 +4614,14 @@ S:       Supported
 F:     Documentation/scsi/LICENSE.qla2xxx
 F:     drivers/scsi/qla2xxx/
 
+QLOGIC QLA4XXX iSCSI DRIVER
+M:     Ravi Anand <ravi.anand@qlogic.com>
+M:     Vikas Chaudhary <vikas.chaudhary@qlogic.com>
+M:     iscsi-driver@qlogic.com
+L:     linux-scsi@vger.kernel.org
+S:     Supported
+F:     drivers/scsi/qla4xxx/
+
 QLOGIC QLA3XXX NETWORK DRIVER
 M:     Ron Mercer <ron.mercer@qlogic.com>
 M:     linux-driver@qlogic.com
@@ -4761,6 +4762,12 @@ S:       Maintained
 F:     Documentation/rfkill.txt
 F:     net/rfkill/
 
+RICOH SMARTMEDIA/XD DRIVER
+M:     Maxim Levitsky <maximlevitsky@gmail.com>
+S:     Maintained
+F:     drivers/mtd/nand/r822.c
+F:     drivers/mtd/nand/r822.h
+
 RISCOM8 DRIVER
 S:     Orphan
 F:     Documentation/serial/riscom8.txt
index d979e7c..a5fffc8 100644 (file)
@@ -53,6 +53,7 @@ static int __pci_mmap_fits(struct pci_dev *pdev, int num,
 
 /**
  * pci_mmap_resource - map a PCI resource into user memory space
+ * @filp: open sysfs file
  * @kobj: kobject for mapping
  * @attr: struct bin_attribute for the file being mapped
  * @vma: struct vm_area_struct passed into the mmap
@@ -60,7 +61,8 @@ static int __pci_mmap_fits(struct pci_dev *pdev, int num,
  *
  * Use the bus mapping routines to map a PCI resource into userspace.
  */
-static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
+static int pci_mmap_resource(struct file *filp, struct kobject *kobj,
+                            struct bin_attribute *attr,
                             struct vm_area_struct *vma, int sparse)
 {
        struct pci_dev *pdev = to_pci_dev(container_of(kobj,
@@ -89,14 +91,14 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
        return hose_mmap_page_range(pdev->sysdata, vma, mmap_type, sparse);
 }
 
-static int pci_mmap_resource_sparse(struct kobject *kobj,
+static int pci_mmap_resource_sparse(struct file *filp, struct kobject *kobj,
                                    struct bin_attribute *attr,
                                    struct vm_area_struct *vma)
 {
        return pci_mmap_resource(kobj, attr, vma, 1);
 }
 
-static int pci_mmap_resource_dense(struct kobject *kobj,
+static int pci_mmap_resource_dense(struct file *filp, struct kobject *kobj,
                                   struct bin_attribute *attr,
                                   struct vm_area_struct *vma)
 {
index 93107d8..0eabec6 100644 (file)
@@ -9,9 +9,6 @@
  * febff000    22000000        4K      model number register
  * febfe000    22400000        4K      options register
  * febfd000    22800000        4K      options register #2
- * febfc000    [67]0000000     4K      NAND data register
- * febfb000    [67]0400000     4K      NAND control register
- * febfa000    [67]0800000     4K      NAND busy register
  * febf9000    10800000        4K      TS-5620 RTC index register
  * febf8000    11700000        4K      TS-5620 RTC data register
  */
 #define TS72XX_OPTIONS2_TS9420_BOOT    0x02
 
 
-#define TS72XX_NAND1_DATA_PHYS_BASE    0x60000000
-#define TS72XX_NAND2_DATA_PHYS_BASE    0x70000000
-#define TS72XX_NAND_DATA_VIRT_BASE     0xfebfc000
-#define TS72XX_NAND_DATA_SIZE          0x00001000
-
-#define TS72XX_NAND1_CONTROL_PHYS_BASE 0x60400000
-#define TS72XX_NAND2_CONTROL_PHYS_BASE 0x70400000
-#define TS72XX_NAND_CONTROL_VIRT_BASE  0xfebfb000
-#define TS72XX_NAND_CONTROL_SIZE       0x00001000
-
-#define TS72XX_NAND1_BUSY_PHYS_BASE    0x60800000
-#define TS72XX_NAND2_BUSY_PHYS_BASE    0x70800000
-#define TS72XX_NAND_BUSY_VIRT_BASE     0xfebfa000
-#define TS72XX_NAND_BUSY_SIZE          0x00001000
-
-
 #define TS72XX_RTC_INDEX_VIRT_BASE     0xfebf9000
 #define TS72XX_RTC_INDEX_PHYS_BASE     0x10800000
 #define TS72XX_RTC_INDEX_SIZE          0x00001000
index 9553031..ae7319e 100644 (file)
  * your option) any later version.
  */
 
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/m48t86.h>
 #include <linux/mtd/physmap.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/partitions.h>
 
 #include <mach/hardware.h>
 #include <mach/ts72xx.h>
@@ -54,92 +58,162 @@ static struct map_desc ts72xx_io_desc[] __initdata = {
        }
 };
 
-static struct map_desc ts72xx_nand_io_desc[] __initdata = {
-       {
-               .virtual        = TS72XX_NAND_DATA_VIRT_BASE,
-               .pfn            = __phys_to_pfn(TS72XX_NAND1_DATA_PHYS_BASE),
-               .length         = TS72XX_NAND_DATA_SIZE,
-               .type           = MT_DEVICE,
-       }, {
-               .virtual        = TS72XX_NAND_CONTROL_VIRT_BASE,
-               .pfn            = __phys_to_pfn(TS72XX_NAND1_CONTROL_PHYS_BASE),
-               .length         = TS72XX_NAND_CONTROL_SIZE,
-               .type           = MT_DEVICE,
-       }, {
-               .virtual        = TS72XX_NAND_BUSY_VIRT_BASE,
-               .pfn            = __phys_to_pfn(TS72XX_NAND1_BUSY_PHYS_BASE),
-               .length         = TS72XX_NAND_BUSY_SIZE,
-               .type           = MT_DEVICE,
+static void __init ts72xx_map_io(void)
+{
+       ep93xx_map_io();
+       iotable_init(ts72xx_io_desc, ARRAY_SIZE(ts72xx_io_desc));
+}
+
+
+/*************************************************************************
+ * NAND flash
+ *************************************************************************/
+#define TS72XX_NAND_CONTROL_ADDR_LINE  22      /* 0xN0400000 */
+#define TS72XX_NAND_BUSY_ADDR_LINE     23      /* 0xN0800000 */
+
+static void ts72xx_nand_hwcontrol(struct mtd_info *mtd,
+                                 int cmd, unsigned int ctrl)
+{
+       struct nand_chip *chip = mtd->priv;
+
+       if (ctrl & NAND_CTRL_CHANGE) {
+               void __iomem *addr = chip->IO_ADDR_R;
+               unsigned char bits;
+
+               addr += (1 << TS72XX_NAND_CONTROL_ADDR_LINE);
+
+               bits = __raw_readb(addr) & ~0x07;
+               bits |= (ctrl & NAND_NCE) << 2; /* bit 0 -> bit 2 */
+               bits |= (ctrl & NAND_CLE);      /* bit 1 -> bit 1 */
+               bits |= (ctrl & NAND_ALE) >> 2; /* bit 2 -> bit 0 */
+
+               __raw_writeb(bits, addr);
        }
-};
 
-static struct map_desc ts72xx_alternate_nand_io_desc[] __initdata = {
+       if (cmd != NAND_CMD_NONE)
+               __raw_writeb(cmd, chip->IO_ADDR_W);
+}
+
+static int ts72xx_nand_device_ready(struct mtd_info *mtd)
+{
+       struct nand_chip *chip = mtd->priv;
+       void __iomem *addr = chip->IO_ADDR_R;
+
+       addr += (1 << TS72XX_NAND_BUSY_ADDR_LINE);
+
+       return !!(__raw_readb(addr) & 0x20);
+}
+
+static const char *ts72xx_nand_part_probes[] = { "cmdlinepart", NULL };
+
+#define TS72XX_BOOTROM_PART_SIZE       (SZ_16K)
+#define TS72XX_REDBOOT_PART_SIZE       (SZ_2M + SZ_1M)
+
+static struct mtd_partition ts72xx_nand_parts[] = {
        {
-               .virtual        = TS72XX_NAND_DATA_VIRT_BASE,
-               .pfn            = __phys_to_pfn(TS72XX_NAND2_DATA_PHYS_BASE),
-               .length         = TS72XX_NAND_DATA_SIZE,
-               .type           = MT_DEVICE,
+               .name           = "TS-BOOTROM",
+               .offset         = 0,
+               .size           = TS72XX_BOOTROM_PART_SIZE,
+               .mask_flags     = MTD_WRITEABLE,        /* force read-only */
        }, {
-               .virtual        = TS72XX_NAND_CONTROL_VIRT_BASE,
-               .pfn            = __phys_to_pfn(TS72XX_NAND2_CONTROL_PHYS_BASE),
-               .length         = TS72XX_NAND_CONTROL_SIZE,
-               .type           = MT_DEVICE,
+               .name           = "Linux",
+               .offset         = MTDPART_OFS_APPEND,
+               .size           = 0,                    /* filled in later */
        }, {
-               .virtual        = TS72XX_NAND_BUSY_VIRT_BASE,
-               .pfn            = __phys_to_pfn(TS72XX_NAND2_BUSY_PHYS_BASE),
-               .length         = TS72XX_NAND_BUSY_SIZE,
-               .type           = MT_DEVICE,
-       }
+               .name           = "RedBoot",
+               .offset         = MTDPART_OFS_APPEND,
+               .size           = MTDPART_SIZ_FULL,
+               .mask_flags     = MTD_WRITEABLE,        /* force read-only */
+       },
 };
 
-static void __init ts72xx_map_io(void)
+static void ts72xx_nand_set_parts(uint64_t size,
+                                 struct platform_nand_chip *chip)
 {
-       ep93xx_map_io();
-       iotable_init(ts72xx_io_desc, ARRAY_SIZE(ts72xx_io_desc));
+       /* Factory TS-72xx boards only come with 32MiB or 128MiB NAND options */
+       if (size == SZ_32M || size == SZ_128M) {
+               /* Set the "Linux" partition size */
+               ts72xx_nand_parts[1].size = size - TS72XX_REDBOOT_PART_SIZE;
 
-       /*
-        * The TS-7200 has NOR flash, the other models have NAND flash.
-        */
-       if (!board_is_ts7200()) {
-               if (is_ts9420_installed()) {
-                       iotable_init(ts72xx_alternate_nand_io_desc,
-                               ARRAY_SIZE(ts72xx_alternate_nand_io_desc));
-               } else {
-                       iotable_init(ts72xx_nand_io_desc,
-                               ARRAY_SIZE(ts72xx_nand_io_desc));
-               }
+               chip->partitions = ts72xx_nand_parts;
+               chip->nr_partitions = ARRAY_SIZE(ts72xx_nand_parts);
+       } else {
+               pr_warning("Unknown nand disk size:%lluMiB\n", size >> 20);
        }
 }
 
+static struct platform_nand_data ts72xx_nand_data = {
+       .chip = {
+               .nr_chips       = 1,
+               .chip_offset    = 0,
+               .chip_delay     = 15,
+               .part_probe_types = ts72xx_nand_part_probes,
+               .set_parts      = ts72xx_nand_set_parts,
+       },
+       .ctrl = {
+               .cmd_ctrl       = ts72xx_nand_hwcontrol,
+               .dev_ready      = ts72xx_nand_device_ready,
+       },
+};
+
+static struct resource ts72xx_nand_resource[] = {
+       {
+               .start          = 0,                    /* filled in later */
+               .end            = 0,                    /* filled in later */
+               .flags          = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device ts72xx_nand_flash = {
+       .name                   = "gen_nand",
+       .id                     = -1,
+       .dev.platform_data      = &ts72xx_nand_data,
+       .resource               = ts72xx_nand_resource,
+       .num_resources          = ARRAY_SIZE(ts72xx_nand_resource),
+};
+
+
 /*************************************************************************
  * NOR flash (TS-7200 only)
  *************************************************************************/
-static struct physmap_flash_data ts72xx_flash_data = {
+static struct physmap_flash_data ts72xx_nor_data = {
        .width          = 2,
 };
 
-static struct resource ts72xx_flash_resource = {
+static struct resource ts72xx_nor_resource = {
        .start          = EP93XX_CS6_PHYS_BASE,
        .end            = EP93XX_CS6_PHYS_BASE + SZ_16M - 1,
        .flags          = IORESOURCE_MEM,
 };
 
-static struct platform_device ts72xx_flash = {
-       .name           = "physmap-flash",
-       .id             = 0,
-       .dev            = {
-               .platform_data  = &ts72xx_flash_data,
-       },
-       .num_resources  = 1,
-       .resource       = &ts72xx_flash_resource,
+static struct platform_device ts72xx_nor_flash = {
+       .name                   = "physmap-flash",
+       .id                     = 0,
+       .dev.platform_data      = &ts72xx_nor_data,
+       .resource               = &ts72xx_nor_resource,
+       .num_resources          = 1,
 };
 
 static void __init ts72xx_register_flash(void)
 {
-       if (board_is_ts7200())
-               platform_device_register(&ts72xx_flash);
+       if (board_is_ts7200()) {
+               platform_device_register(&ts72xx_nor_flash);
+       } else {
+               resource_size_t start;
+
+               if (is_ts9420_installed())
+                       start = EP93XX_CS7_PHYS_BASE;
+               else
+                       start = EP93XX_CS6_PHYS_BASE;
+
+               ts72xx_nand_resource[0].start = start;
+               ts72xx_nand_resource[0].end = start + SZ_16M - 1;
+
+               platform_device_register(&ts72xx_nand_flash);
+       }
 }
 
+
 static unsigned char ts72xx_rtc_readbyte(unsigned long addr)
 {
        __raw_writeb(addr, TS72XX_RTC_INDEX_VIRT_BASE);
index f759ca2..6072eaa 100644 (file)
@@ -305,6 +305,15 @@ void __init kirkwood_nand_init(struct mtd_partition *parts, int nr_parts,
        platform_device_register(&kirkwood_nand_flash);
 }
 
+void __init kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts,
+                                  int (*dev_ready)(struct mtd_info *))
+{
+       kirkwood_clk_ctrl |= CGC_RUNIT;
+       kirkwood_nand_data.parts = parts;
+       kirkwood_nand_data.nr_parts = nr_parts;
+       kirkwood_nand_data.dev_ready = dev_ready;
+       platform_device_register(&kirkwood_nand_flash);
+}
 
 /*****************************************************************************
  * SoC RTC
index d7de434..05e8a8a 100644 (file)
@@ -16,6 +16,7 @@ struct mv643xx_eth_platform_data;
 struct mv_sata_platform_data;
 struct mvsdio_platform_data;
 struct mtd_partition;
+struct mtd_info;
 
 /*
  * Basic Kirkwood init functions used early by machine-setup.
@@ -41,6 +42,7 @@ void kirkwood_i2c_init(void);
 void kirkwood_uart0_init(void);
 void kirkwood_uart1_init(void);
 void kirkwood_nand_init(struct mtd_partition *parts, int nr_parts, int delay);
+void kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts, int (*dev_ready)(struct mtd_info *));
 
 extern int kirkwood_tclk;
 extern struct sys_timer kirkwood_timer;
index d6a4cfa..9f3c180 100644 (file)
@@ -14,6 +14,7 @@
  */
 struct orion_nand_data {
        struct mtd_partition *parts;
+       int (*dev_ready)(struct mtd_info *mtd);
        u32 nr_parts;
        u8 ale;         /* address line number connected to ALE */
        u8 cle;         /* address line number connected to CLE */
index adc6929..575d219 100644 (file)
@@ -905,7 +905,7 @@ struct txx9_sramc_sysdev {
        void __iomem *base;
 };
 
-static ssize_t txx9_sram_read(struct kobject *kobj,
+static ssize_t txx9_sram_read(struct file *filp, struct kobject *kobj,
                              struct bin_attribute *bin_attr,
                              char *buf, loff_t pos, size_t size)
 {
@@ -920,7 +920,7 @@ static ssize_t txx9_sram_read(struct kobject *kobj,
        return size;
 }
 
-static ssize_t txx9_sram_write(struct kobject *kobj,
+static ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj,
                               struct bin_attribute *bin_attr,
                               char *buf, loff_t pos, size_t size)
 {
index 1456015..198f288 100644 (file)
@@ -24,7 +24,7 @@
 #define MV64X60_VAL_LEN_MAX            11
 #define MV64X60_PCICFG_CPCI_HOTSWAP    0x68
 
-static ssize_t mv64x60_hs_reg_read(struct kobject *kobj,
+static ssize_t mv64x60_hs_reg_read(struct file *filp, struct kobject *kobj,
                                   struct bin_attribute *attr, char *buf,
                                   loff_t off, size_t count)
 {
@@ -45,7 +45,7 @@ static ssize_t mv64x60_hs_reg_read(struct kobject *kobj,
        return sprintf(buf, "0x%08x\n", v);
 }
 
-static ssize_t mv64x60_hs_reg_write(struct kobject *kobj,
+static ssize_t mv64x60_hs_reg_write(struct file *filp, struct kobject *kobj,
                                    struct bin_attribute *attr, char *buf,
                                    loff_t off, size_t count)
 {
index 72c8b0d..a689070 100644 (file)
@@ -403,8 +403,9 @@ static ssize_t sys_ipl_device_show(struct kobject *kobj,
 static struct kobj_attribute sys_ipl_device_attr =
        __ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);
 
-static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
-                                 char *buf, loff_t off, size_t count)
+static ssize_t ipl_parameter_read(struct file *filp, struct kobject *kobj,
+                                 struct bin_attribute *attr, char *buf,
+                                 loff_t off, size_t count)
 {
        return memory_read_from_buffer(buf, count, &off, IPL_PARMBLOCK_START,
                                        IPL_PARMBLOCK_SIZE);
@@ -419,8 +420,9 @@ static struct bin_attribute ipl_parameter_attr = {
        .read = &ipl_parameter_read,
 };
 
-static ssize_t ipl_scp_data_read(struct kobject *kobj, struct bin_attribute *attr,
-                                char *buf, loff_t off, size_t count)
+static ssize_t ipl_scp_data_read(struct file *filp, struct kobject *kobj,
+                                struct bin_attribute *attr, char *buf,
+                                loff_t off, size_t count)
 {
        unsigned int size = IPL_PARMBLOCK_START->ipl_info.fcp.scp_data_len;
        void *scp_data = &IPL_PARMBLOCK_START->ipl_info.fcp.scp_data;
@@ -694,7 +696,7 @@ static struct kobj_attribute sys_reipl_ccw_vmparm_attr =
 
 /* FCP reipl device attributes */
 
-static ssize_t reipl_fcp_scpdata_read(struct kobject *kobj,
+static ssize_t reipl_fcp_scpdata_read(struct file *filp, struct kobject *kobj,
                                      struct bin_attribute *attr,
                                      char *buf, loff_t off, size_t count)
 {
@@ -704,7 +706,7 @@ static ssize_t reipl_fcp_scpdata_read(struct kobject *kobj,
        return memory_read_from_buffer(buf, count, &off, scp_data, size);
 }
 
-static ssize_t reipl_fcp_scpdata_write(struct kobject *kobj,
+static ssize_t reipl_fcp_scpdata_write(struct file *filp, struct kobject *kobj,
                                       struct bin_attribute *attr,
                                       char *buf, loff_t off, size_t count)
 {
index e35525b..c79e789 100644 (file)
@@ -71,7 +71,7 @@ struct acpi_table_attr {
        struct list_head node;
 };
 
-static ssize_t acpi_table_show(struct kobject *kobj,
+static ssize_t acpi_table_show(struct file *filp, struct kobject *kobj,
                               struct bin_attribute *bin_attr, char *buf,
                               loff_t offset, size_t count)
 {
index fd52c48..ef38aff 100644 (file)
@@ -18,9 +18,9 @@ config UEVENT_HELPER_PATH
 
 config DEVTMPFS
        bool "Maintain a devtmpfs filesystem to mount at /dev"
-       depends on HOTPLUG && SHMEM && TMPFS
+       depends on HOTPLUG
        help
-         This creates a tmpfs filesystem instance early at bootup.
+         This creates a tmpfs/ramfs filesystem instance early at bootup.
          In this filesystem, the kernel driver core maintains device
          nodes with their default names and permissions for all
          registered devices with an assigned major/minor number.
@@ -33,6 +33,9 @@ config DEVTMPFS
          functional /dev without any further help. It also allows simple
          rescue systems, and reliably handles dynamic major/minor numbers.
 
+         Notice: if CONFIG_TMPFS isn't enabled, the simpler ramfs
+         file system will be used instead.
+
 config DEVTMPFS_MOUNT
        bool "Automount devtmpfs at /dev, after the kernel mounted the rootfs"
        depends on DEVTMPFS
index 9c6a0d6..8e231d0 100644 (file)
@@ -63,6 +63,14 @@ static void class_release(struct kobject *kobj)
        kfree(cp);
 }
 
+static const struct kobj_ns_type_operations *class_child_ns_type(struct kobject *kobj)
+{
+       struct class_private *cp = to_class(kobj);
+       struct class *class = cp->class;
+
+       return class->ns_type;
+}
+
 static const struct sysfs_ops class_sysfs_ops = {
        .show   = class_attr_show,
        .store  = class_attr_store,
@@ -71,6 +79,7 @@ static const struct sysfs_ops class_sysfs_ops = {
 static struct kobj_type class_ktype = {
        .sysfs_ops      = &class_sysfs_ops,
        .release        = class_release,
+       .child_ns_type  = class_child_ns_type,
 };
 
 /* Hotplug events for classes go to the class class_subsys */
index b56a0ba..9630fbd 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/notifier.h>
 #include <linux/genhd.h>
 #include <linux/kallsyms.h>
-#include <linux/semaphore.h>
 #include <linux/mutex.h>
 #include <linux/async.h>
 
@@ -132,9 +131,21 @@ static void device_release(struct kobject *kobj)
        kfree(p);
 }
 
+static const void *device_namespace(struct kobject *kobj)
+{
+       struct device *dev = to_dev(kobj);
+       const void *ns = NULL;
+
+       if (dev->class && dev->class->ns_type)
+               ns = dev->class->namespace(dev);
+
+       return ns;
+}
+
 static struct kobj_type device_ktype = {
        .release        = device_release,
        .sysfs_ops      = &dev_sysfs_ops,
+       .namespace      = device_namespace,
 };
 
 
@@ -559,10 +570,10 @@ void device_initialize(struct device *dev)
        dev->kobj.kset = devices_kset;
        kobject_init(&dev->kobj, &device_ktype);
        INIT_LIST_HEAD(&dev->dma_pools);
-       init_MUTEX(&dev->sem);
+       mutex_init(&dev->mutex);
+       lockdep_set_novalidate_class(&dev->mutex);
        spin_lock_init(&dev->devres_lock);
        INIT_LIST_HEAD(&dev->devres_head);
-       device_init_wakeup(dev, 0);
        device_pm_init(dev);
        set_dev_node(dev, -1);
 }
@@ -596,11 +607,59 @@ static struct kobject *virtual_device_parent(struct device *dev)
        return virtual_dir;
 }
 
-static struct kobject *get_device_parent(struct device *dev,
-                                        struct device *parent)
+struct class_dir {
+       struct kobject kobj;
+       struct class *class;
+};
+
+#define to_class_dir(obj) container_of(obj, struct class_dir, kobj)
+
+static void class_dir_release(struct kobject *kobj)
+{
+       struct class_dir *dir = to_class_dir(kobj);
+       kfree(dir);
+}
+
+static const
+struct kobj_ns_type_operations *class_dir_child_ns_type(struct kobject *kobj)
 {
+       struct class_dir *dir = to_class_dir(kobj);
+       return dir->class->ns_type;
+}
+
+static struct kobj_type class_dir_ktype = {
+       .release        = class_dir_release,
+       .sysfs_ops      = &kobj_sysfs_ops,
+       .child_ns_type  = class_dir_child_ns_type
+};
+
+static struct kobject *
+class_dir_create_and_add(struct class *class, struct kobject *parent_kobj)
+{
+       struct class_dir *dir;
        int retval;
 
+       dir = kzalloc(sizeof(*dir), GFP_KERNEL);
+       if (!dir)
+               return NULL;
+
+       dir->class = class;
+       kobject_init(&dir->kobj, &class_dir_ktype);
+
+       dir->kobj.kset = &class->p->class_dirs;
+
+       retval = kobject_add(&dir->kobj, parent_kobj, "%s", class->name);
+       if (retval < 0) {
+               kobject_put(&dir->kobj);
+               return NULL;
+       }
+       return &dir->kobj;
+}
+
+
+static struct kobject *get_device_parent(struct device *dev,
+                                        struct device *parent)
+{
        if (dev->class) {
                static DEFINE_MUTEX(gdp_mutex);
                struct kobject *kobj = NULL;
@@ -635,18 +694,7 @@ static struct kobject *get_device_parent(struct device *dev,
                }
 
                /* or create a new class-directory at the parent device */
-               k = kobject_create();
-               if (!k) {
-                       mutex_unlock(&gdp_mutex);
-                       return NULL;
-               }
-               k->kset = &dev->class->p->class_dirs;
-               retval = kobject_add(k, parent_kobj, "%s", dev->class->name);
-               if (retval < 0) {
-                       mutex_unlock(&gdp_mutex);
-                       kobject_put(k);
-                       return NULL;
-               }
+               k = class_dir_create_and_add(dev->class, parent_kobj);
                /* do not emit an uevent for this simple "glue" directory */
                mutex_unlock(&gdp_mutex);
                return k;
@@ -738,7 +786,7 @@ out_device:
 out_busid:
        if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
            device_is_not_partition(dev))
-               sysfs_remove_link(&dev->class->p->class_subsys.kobj,
+               sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj,
                                  dev_name(dev));
 #else
        /* link in the class directory pointing to the device */
@@ -756,7 +804,7 @@ out_busid:
        return 0;
 
 out_busid:
-       sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev_name(dev));
+       sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev));
 #endif
 
 out_subsys:
@@ -784,13 +832,13 @@ static void device_remove_class_symlinks(struct device *dev)
 
        if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
            device_is_not_partition(dev))
-               sysfs_remove_link(&dev->class->p->class_subsys.kobj,
+               sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj,
                                  dev_name(dev));
 #else
        if (dev->parent && device_is_not_partition(dev))
                sysfs_remove_link(&dev->kobj, "device");
 
-       sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev_name(dev));
+       sysfs_delete_link(&dev->class->p->class_subsys.kobj, &dev->kobj, dev_name(dev));
 #endif
 
        sysfs_remove_link(&dev->kobj, "subsystem");
@@ -1372,7 +1420,7 @@ struct device *__root_device_register(const char *name, struct module *owner)
                return ERR_PTR(err);
        }
 
-#ifdef CONFIG_MODULE   /* gotta find a "cleaner" way to do this */
+#ifdef CONFIG_MODULES  /* gotta find a "cleaner" way to do this */
        if (owner) {
                struct module_kobject *mk = &owner->mkobj;
 
@@ -1576,6 +1624,14 @@ int device_rename(struct device *dev, char *new_name)
                goto out;
        }
 
+#ifndef CONFIG_SYSFS_DEPRECATED
+       if (dev->class) {
+               error = sysfs_rename_link(&dev->class->p->class_subsys.kobj,
+                       &dev->kobj, old_device_name, new_name);
+               if (error)
+                       goto out;
+       }
+#endif
        error = kobject_rename(&dev->kobj, new_name);
        if (error)
                goto out;
@@ -1590,11 +1646,6 @@ int device_rename(struct device *dev, char *new_name)
                                                  new_class_name);
                }
        }
-#else
-       if (dev->class) {
-               error = sysfs_rename_link(&dev->class->p->class_subsys.kobj,
-                                         &dev->kobj, old_device_name, new_name);
-       }
 #endif
 
 out:
@@ -1735,10 +1786,25 @@ EXPORT_SYMBOL_GPL(device_move);
  */
 void device_shutdown(void)
 {
-       struct device *dev, *devn;
+       struct device *dev;
+
+       spin_lock(&devices_kset->list_lock);
+       /*
+        * Walk the devices list backward, shutting down each in turn.
+        * Beware that device unplug events may also start pulling
+        * devices offline, even as the system is shutting down.
+        */
+       while (!list_empty(&devices_kset->list)) {
+               dev = list_entry(devices_kset->list.prev, struct device,
+                               kobj.entry);
+               get_device(dev);
+               /*
+                * Make sure the device is off the kset list, in the
+                * event that dev->*->shutdown() doesn't remove it.
+                */
+               list_del_init(&dev->kobj.entry);
+               spin_unlock(&devices_kset->list_lock);
 
-       list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
-                               kobj.entry) {
                if (dev->bus && dev->bus->shutdown) {
                        dev_dbg(dev, "shutdown\n");
                        dev->bus->shutdown(dev);
@@ -1746,6 +1812,10 @@ void device_shutdown(void)
                        dev_dbg(dev, "shutdown\n");
                        dev->driver->shutdown(dev);
                }
+               put_device(dev);
+
+               spin_lock(&devices_kset->list_lock);
        }
+       spin_unlock(&devices_kset->list_lock);
        async_synchronize_full();
 }
index f35719a..251acea 100644 (file)
@@ -186,7 +186,7 @@ static ssize_t print_cpus_offline(struct sysdev_class *class,
        /* display offline cpus < nr_cpu_ids */
        if (!alloc_cpumask_var(&offline, GFP_KERNEL))
                return -ENOMEM;
-       cpumask_complement(offline, cpu_online_mask);
+       cpumask_andnot(offline, cpu_possible_mask, cpu_online_mask);
        n = cpulist_scnprintf(buf, len, offline);
        free_cpumask_var(offline);
 
index c89291f..503c262 100644 (file)
@@ -40,11 +40,11 @@ static void driver_bound(struct device *dev)
        pr_debug("driver: '%s': %s: bound to device '%s'\n", dev_name(dev),
                 __func__, dev->driver->name);
 
+       klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
+
        if (dev->bus)
                blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
                                             BUS_NOTIFY_BOUND_DRIVER, dev);
-
-       klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
 }
 
 static int driver_sysfs_add(struct device *dev)
index 057cf11..af06001 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/namei.h>
 #include <linux/fs.h>
 #include <linux/shmem_fs.h>
+#include <linux/ramfs.h>
 #include <linux/cred.h>
 #include <linux/sched.h>
 #include <linux/init_task.h>
@@ -45,7 +46,11 @@ __setup("devtmpfs.mount=", mount_param);
 static int dev_get_sb(struct file_system_type *fs_type, int flags,
                      const char *dev_name, void *data, struct vfsmount *mnt)
 {
+#ifdef CONFIG_TMPFS
        return get_sb_single(fs_type, flags, data, shmem_fill_super, mnt);
+#else
+       return get_sb_single(fs_type, flags, data, ramfs_fill_super, mnt);
+#endif
 }
 
 static struct file_system_type dev_fs_type = {
index 985da11..3f093b0 100644 (file)
@@ -27,6 +27,52 @@ MODULE_AUTHOR("Manuel Estrada Sainz");
 MODULE_DESCRIPTION("Multi purpose firmware loading support");
 MODULE_LICENSE("GPL");
 
+/* Builtin firmware support */
+
+#ifdef CONFIG_FW_LOADER
+
+extern struct builtin_fw __start_builtin_fw[];
+extern struct builtin_fw __end_builtin_fw[];
+
+static bool fw_get_builtin_firmware(struct firmware *fw, const char *name)
+{
+       struct builtin_fw *b_fw;
+
+       for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
+               if (strcmp(name, b_fw->name) == 0) {
+                       fw->size = b_fw->size;
+                       fw->data = b_fw->data;
+                       return true;
+               }
+       }
+
+       return false;
+}
+
+static bool fw_is_builtin_firmware(const struct firmware *fw)
+{
+       struct builtin_fw *b_fw;
+
+       for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++)
+               if (fw->data == b_fw->data)
+                       return true;
+
+       return false;
+}
+
+#else /* Module case - no builtin firmware support */
+
+static inline bool fw_get_builtin_firmware(struct firmware *fw, const char *name)
+{
+       return false;
+}
+
+static inline bool fw_is_builtin_firmware(const struct firmware *fw)
+{
+       return false;
+}
+#endif
+
 enum {
        FW_STATUS_LOADING,
        FW_STATUS_DONE,
@@ -40,7 +86,6 @@ static int loading_timeout = 60;      /* In seconds */
 static DEFINE_MUTEX(fw_lock);
 
 struct firmware_priv {
-       char *fw_id;
        struct completion completion;
        struct bin_attribute attr_data;
        struct firmware *fw;
@@ -48,18 +93,11 @@ struct firmware_priv {
        struct page **pages;
        int nr_pages;
        int page_array_size;
-       const char *vdata;
        struct timer_list timeout;
+       bool nowait;
+       char fw_id[];
 };
 
-#ifdef CONFIG_FW_LOADER
-extern struct builtin_fw __start_builtin_fw[];
-extern struct builtin_fw __end_builtin_fw[];
-#else /* Module case. Avoid ifdefs later; it'll all optimise out */
-static struct builtin_fw *__start_builtin_fw;
-static struct builtin_fw *__end_builtin_fw;
-#endif
-
 static void
 fw_load_abort(struct firmware_priv *fw_priv)
 {
@@ -100,9 +138,25 @@ firmware_timeout_store(struct class *class,
        return count;
 }
 
-static CLASS_ATTR(timeout, 0644, firmware_timeout_show, firmware_timeout_store);
+static struct class_attribute firmware_class_attrs[] = {
+       __ATTR(timeout, S_IWUSR | S_IRUGO,
+               firmware_timeout_show, firmware_timeout_store),
+       __ATTR_NULL
+};
+
+static void fw_dev_release(struct device *dev)
+{
+       struct firmware_priv *fw_priv = dev_get_drvdata(dev);
+       int i;
+
+       for (i = 0; i < fw_priv->nr_pages; i++)
+               __free_page(fw_priv->pages[i]);
+       kfree(fw_priv->pages);
+       kfree(fw_priv);
+       kfree(dev);
 
-static void fw_dev_release(struct device *dev);
+       module_put(THIS_MODULE);
+}
 
 static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
@@ -112,12 +166,15 @@ static int firmware_uevent(struct device *dev, struct kobj_uevent_env *env)
                return -ENOMEM;
        if (add_uevent_var(env, "TIMEOUT=%i", loading_timeout))
                return -ENOMEM;
+       if (add_uevent_var(env, "ASYNC=%d", fw_priv->nowait))
+               return -ENOMEM;
 
        return 0;
 }
 
 static struct class firmware_class = {
        .name           = "firmware",
+       .class_attrs    = firmware_class_attrs,
        .dev_uevent     = firmware_uevent,
        .dev_release    = fw_dev_release,
 };
@@ -130,6 +187,17 @@ static ssize_t firmware_loading_show(struct device *dev,
        return sprintf(buf, "%d\n", loading);
 }
 
+static void firmware_free_data(const struct firmware *fw)
+{
+       int i;
+       vunmap(fw->data);
+       if (fw->pages) {
+               for (i = 0; i < PFN_UP(fw->size); i++)
+                       __free_page(fw->pages[i]);
+               kfree(fw->pages);
+       }
+}
+
 /* Some architectures don't have PAGE_KERNEL_RO */
 #ifndef PAGE_KERNEL_RO
 #define PAGE_KERNEL_RO PAGE_KERNEL
@@ -162,21 +230,21 @@ static ssize_t firmware_loading_store(struct device *dev,
                        mutex_unlock(&fw_lock);
                        break;
                }
-               vfree(fw_priv->fw->data);
-               fw_priv->fw->data = NULL;
+               firmware_free_data(fw_priv->fw);
+               memset(fw_priv->fw, 0, sizeof(struct firmware));
+               /* If the pages are not owned by 'struct firmware' */
                for (i = 0; i < fw_priv->nr_pages; i++)
                        __free_page(fw_priv->pages[i]);
                kfree(fw_priv->pages);
                fw_priv->pages = NULL;
                fw_priv->page_array_size = 0;
                fw_priv->nr_pages = 0;
-               fw_priv->fw->size = 0;
                set_bit(FW_STATUS_LOADING, &fw_priv->status);
                mutex_unlock(&fw_lock);
                break;
        case 0:
                if (test_bit(FW_STATUS_LOADING, &fw_priv->status)) {
-                       vfree(fw_priv->fw->data);
+                       vunmap(fw_priv->fw->data);
                        fw_priv->fw->data = vmap(fw_priv->pages,
                                                 fw_priv->nr_pages,
                                                 0, PAGE_KERNEL_RO);
@@ -184,7 +252,10 @@ static ssize_t firmware_loading_store(struct device *dev,
                                dev_err(dev, "%s: vmap() failed\n", __func__);
                                goto err;
                        }
-                       /* Pages will be freed by vfree() */
+                       /* Pages are now owned by 'struct firmware' */
+                       fw_priv->fw->pages = fw_priv->pages;
+                       fw_priv->pages = NULL;
+
                        fw_priv->page_array_size = 0;
                        fw_priv->nr_pages = 0;
                        complete(&fw_priv->completion);
@@ -207,8 +278,9 @@ static ssize_t firmware_loading_store(struct device *dev,
 static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);
 
 static ssize_t
-firmware_data_read(struct kobject *kobj, struct bin_attribute *bin_attr,
-                  char *buffer, loff_t offset, size_t count)
+firmware_data_read(struct file *filp, struct kobject *kobj,
+                  struct bin_attribute *bin_attr, char *buffer, loff_t offset,
+                  size_t count)
 {
        struct device *dev = to_dev(kobj);
        struct firmware_priv *fw_priv = dev_get_drvdata(dev);
@@ -291,6 +363,7 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
 
 /**
  * firmware_data_write - write method for firmware
+ * @filp: open sysfs file
  * @kobj: kobject for the device
  * @bin_attr: bin_attr structure
  * @buffer: buffer being written
@@ -301,8 +374,9 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
  *     the driver as a firmware image.
  **/
 static ssize_t
-firmware_data_write(struct kobject *kobj, struct bin_attribute *bin_attr,
-                   char *buffer, loff_t offset, size_t count)
+firmware_data_write(struct file* filp, struct kobject *kobj,
+                   struct bin_attribute *bin_attr, char *buffer,
+                   loff_t offset, size_t count)
 {
        struct device *dev = to_dev(kobj);
        struct firmware_priv *fw_priv = dev_get_drvdata(dev);
@@ -353,21 +427,6 @@ static struct bin_attribute firmware_attr_data_tmpl = {
        .write = firmware_data_write,
 };
 
-static void fw_dev_release(struct device *dev)
-{
-       struct firmware_priv *fw_priv = dev_get_drvdata(dev);
-       int i;
-
-       for (i = 0; i < fw_priv->nr_pages; i++)
-               __free_page(fw_priv->pages[i]);
-       kfree(fw_priv->pages);
-       kfree(fw_priv->fw_id);
-       kfree(fw_priv);
-       kfree(dev);
-
-       module_put(THIS_MODULE);
-}
-
 static void
 firmware_class_timeout(u_long data)
 {
@@ -379,8 +438,8 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
                              struct device *device)
 {
        int retval;
-       struct firmware_priv *fw_priv = kzalloc(sizeof(*fw_priv),
-                                               GFP_KERNEL);
+       struct firmware_priv *fw_priv =
+               kzalloc(sizeof(*fw_priv) + strlen(fw_name) + 1 , GFP_KERNEL);
        struct device *f_dev = kzalloc(sizeof(*f_dev), GFP_KERNEL);
 
        *dev_p = NULL;
@@ -391,16 +450,9 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
                goto error_kfree;
        }
 
+       strcpy(fw_priv->fw_id, fw_name);
        init_completion(&fw_priv->completion);
        fw_priv->attr_data = firmware_attr_data_tmpl;
-       fw_priv->fw_id = kstrdup(fw_name, GFP_KERNEL);
-       if (!fw_priv->fw_id) {
-               dev_err(device, "%s: Firmware name allocation failed\n",
-                       __func__);
-               retval = -ENOMEM;
-               goto error_kfree;
-       }
-
        fw_priv->timeout.function = firmware_class_timeout;
        fw_priv->timeout.data = (u_long) fw_priv;
        init_timer(&fw_priv->timeout);
@@ -427,7 +479,7 @@ error_kfree:
 
 static int fw_setup_device(struct firmware *fw, struct device **dev_p,
                           const char *fw_name, struct device *device,
-                          int uevent)
+                          int uevent, bool nowait)
 {
        struct device *f_dev;
        struct firmware_priv *fw_priv;
@@ -443,6 +495,8 @@ static int fw_setup_device(struct firmware *fw, struct device **dev_p,
 
        fw_priv = dev_get_drvdata(f_dev);
 
+       fw_priv->nowait = nowait;
+
        fw_priv->fw = fw;
        sysfs_bin_attr_init(&fw_priv->attr_data);
        retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data);
@@ -470,12 +524,11 @@ out:
 
 static int
 _request_firmware(const struct firmware **firmware_p, const char *name,
-                struct device *device, int uevent)
+                struct device *device, int uevent, bool nowait)
 {
        struct device *f_dev;
        struct firmware_priv *fw_priv;
        struct firmware *firmware;
-       struct builtin_fw *builtin;
        int retval;
 
        if (!firmware_p)
@@ -489,21 +542,16 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
                goto out;
        }
 
-       for (builtin = __start_builtin_fw; builtin != __end_builtin_fw;
-            builtin++) {
-               if (strcmp(name, builtin->name))
-                       continue;
-               dev_info(device, "firmware: using built-in firmware %s\n",
-                        name);
-               firmware->size = builtin->size;
-               firmware->data = builtin->data;
+       if (fw_get_builtin_firmware(firmware, name)) {
+               dev_dbg(device, "firmware: using built-in firmware %s\n", name);
                return 0;
        }
 
        if (uevent)
-               dev_info(device, "firmware: requesting %s\n", name);
+               dev_dbg(device, "firmware: requesting %s\n", name);
 
-       retval = fw_setup_device(firmware, &f_dev, name, device, uevent);
+       retval = fw_setup_device(firmware, &f_dev, name, device,
+                                uevent, nowait);
        if (retval)
                goto error_kfree_fw;
 
@@ -560,26 +608,18 @@ request_firmware(const struct firmware **firmware_p, const char *name,
                  struct device *device)
 {
         int uevent = 1;
-        return _request_firmware(firmware_p, name, device, uevent);
+        return _request_firmware(firmware_p, name, device, uevent, false);
 }
 
 /**
  * release_firmware: - release the resource associated with a firmware image
  * @fw: firmware resource to release
  **/
-void
-release_firmware(const struct firmware *fw)
+void release_firmware(const struct firmware *fw)
 {
-       struct builtin_fw *builtin;
-
        if (fw) {
-               for (builtin = __start_builtin_fw; builtin != __end_builtin_fw;
-                    builtin++) {
-                       if (fw->data == builtin->data)
-                               goto free_fw;
-               }
-               vfree(fw->data);
-       free_fw:
+               if (!fw_is_builtin_firmware(fw))
+                       firmware_free_data(fw);
                kfree(fw);
        }
 }
@@ -606,7 +646,7 @@ request_firmware_work_func(void *arg)
                return 0;
        }
        ret = _request_firmware(&fw, fw_work->name, fw_work->device,
-               fw_work->uevent);
+               fw_work->uevent, true);
 
        fw_work->cont(fw, fw_work->context);
 
@@ -670,26 +710,12 @@ request_firmware_nowait(
        return 0;
 }
 
-static int __init
-firmware_class_init(void)
+static int __init firmware_class_init(void)
 {
-       int error;
-       error = class_register(&firmware_class);
-       if (error) {
-               printk(KERN_ERR "%s: class_register failed\n", __func__);
-               return error;
-       }
-       error = class_create_file(&firmware_class, &class_attr_timeout);
-       if (error) {
-               printk(KERN_ERR "%s: class_create_file failed\n",
-                      __func__);
-               class_unregister(&firmware_class);
-       }
-       return error;
-
+       return class_register(&firmware_class);
 }
-static void __exit
-firmware_class_exit(void)
+
+static void __exit firmware_class_exit(void)
 {
        class_unregister(&firmware_class);
 }
index f32f2f9..db930d3 100644 (file)
@@ -15,12 +15,10 @@ static char *make_driver_name(struct device_driver *drv)
 {
        char *driver_name;
 
-       driver_name = kmalloc(strlen(drv->name) + strlen(drv->bus->name) + 2,
-                             GFP_KERNEL);
+       driver_name = kasprintf(GFP_KERNEL, "%s:%s", drv->bus->name, drv->name);
        if (!driver_name)
                return NULL;
 
-       sprintf(driver_name, "%s:%s", drv->bus->name, drv->name);
        return driver_name;
 }
 
index ada6397..4d99c8b 100644 (file)
@@ -735,7 +735,7 @@ static void platform_pm_complete(struct device *dev)
 
 #ifdef CONFIG_SUSPEND
 
-static int platform_pm_suspend(struct device *dev)
+int __weak platform_pm_suspend(struct device *dev)
 {
        struct device_driver *drv = dev->driver;
        int ret = 0;
@@ -753,7 +753,7 @@ static int platform_pm_suspend(struct device *dev)
        return ret;
 }
 
-static int platform_pm_suspend_noirq(struct device *dev)
+int __weak platform_pm_suspend_noirq(struct device *dev)
 {
        struct device_driver *drv = dev->driver;
        int ret = 0;
@@ -769,7 +769,7 @@ static int platform_pm_suspend_noirq(struct device *dev)
        return ret;
 }
 
-static int platform_pm_resume(struct device *dev)
+int __weak platform_pm_resume(struct device *dev)
 {
        struct device_driver *drv = dev->driver;
        int ret = 0;
@@ -787,7 +787,7 @@ static int platform_pm_resume(struct device *dev)
        return ret;
 }
 
-static int platform_pm_resume_noirq(struct device *dev)
+int __weak platform_pm_resume_noirq(struct device *dev)
 {
        struct device_driver *drv = dev->driver;
        int ret = 0;
index 8546d12..a90e83c 100644 (file)
@@ -835,6 +835,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
 
        set_capacity(lo->lo_disk, size);
        bd_set_size(bdev, size << 9);
+       /* let user-space know about the new size */
+       kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE);
 
        set_blocksize(bdev, lo_blocksize);
 
@@ -858,6 +860,7 @@ out_clr:
        set_capacity(lo->lo_disk, 0);
        invalidate_bdev(bdev);
        bd_set_size(bdev, 0);
+       kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE);
        mapping_set_gfp_mask(mapping, lo->old_gfp_mask);
        lo->lo_state = Lo_unbound;
  out_putf:
@@ -944,8 +947,11 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
        if (bdev)
                invalidate_bdev(bdev);
        set_capacity(lo->lo_disk, 0);
-       if (bdev)
+       if (bdev) {
                bd_set_size(bdev, 0);
+               /* let user-space know about this change */
+               kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE);
+       }
        mapping_set_gfp_mask(filp->f_mapping, gfp);
        lo->lo_state = Lo_unbound;
        /* This is safe: open() is still holding a reference. */
@@ -1189,6 +1195,8 @@ static int loop_set_capacity(struct loop_device *lo, struct block_device *bdev)
        sz <<= 9;
        mutex_lock(&bdev->bd_mutex);
        bd_set_size(bdev, sz);
+       /* let user-space know about the new size */
+       kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE);
        mutex_unlock(&bdev->bd_mutex);
 
  out:
index 3141dd3..e21175b 100644 (file)
@@ -276,11 +276,19 @@ config N_HDLC
          Allows synchronous HDLC communications with tty device drivers that
          support synchronous HDLC such as the Microgate SyncLink adapter.
 
-         This driver can only be built as a module ( = code which can be
+         This driver can be built as a module ( = code which can be
          inserted in and removed from the running kernel whenever you want).
          The module will be called n_hdlc. If you want to do that, say M
          here.
 
+config N_GSM
+       tristate "GSM MUX line discipline support (EXPERIMENTAL)"
+       depends on EXPERIMENTAL
+       depends on NET
+       help
+         This line discipline provides support for the GSM MUX protocol and
+         presents the mux as a set of 61 individual tty devices.
+
 config RISCOM8
        tristate "SDL RISCom/8 card support"
        depends on SERIAL_NONSTANDARD
index f957edf..d39be4c 100644 (file)
@@ -40,6 +40,7 @@ obj-$(CONFIG_SYNCLINK)                += synclink.o
 obj-$(CONFIG_SYNCLINKMP)       += synclinkmp.o
 obj-$(CONFIG_SYNCLINK_GT)      += synclink_gt.o
 obj-$(CONFIG_N_HDLC)           += n_hdlc.o
+obj-$(CONFIG_N_GSM)            += n_gsm.o
 obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o
 obj-$(CONFIG_SX)               += sx.o generic_serial.o
 obj-$(CONFIG_RIO)              += rio/ generic_serial.o
index c1ab303..98310e1 100644 (file)
@@ -1573,11 +1573,16 @@ static int __devinit isicom_probe(struct pci_dev *pdev,
        dev_info(&pdev->dev, "ISI PCI Card(Device ID 0x%x)\n", ent->device);
 
        /* allot the first empty slot in the array */
-       for (index = 0; index < BOARD_COUNT; index++)
+       for (index = 0; index < BOARD_COUNT; index++) {
                if (isi_card[index].base == 0) {
                        board = &isi_card[index];
                        break;
                }
+       }
+       if (index == BOARD_COUNT) {
+               retval = -ENODEV;
+               goto err_disable;
+       }
 
        board->index = index;
        board->base = pci_resource_start(pdev, 3);
@@ -1624,6 +1629,7 @@ errunrr:
 errdec:
        board->base = 0;
        card_count--;
+err_disable:
        pci_disable_device(pdev);
 err:
        return retval;
diff --git a/drivers/char/n_gsm.c b/drivers/char/n_gsm.c
new file mode 100644 (file)
index 0000000..c4161d5
--- /dev/null
@@ -0,0 +1,2763 @@
+/*
+ * n_gsm.c GSM 0710 tty multiplexor
+ * Copyright (c) 2009/10 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *     * THIS IS A DEVELOPMENT SNAPSHOT IT IS NOT A FINAL RELEASE *
+ *
+ * TO DO:
+ *     Mostly done:    ioctls for setting modes/timing
+ *     Partly done:    hooks so you can pull off frames to non tty devs
+ *     Restart DLCI 0 when it closes ?
+ *     Test basic encoding
+ *     Improve the tx engine
+ *     Resolve tx side locking by adding a queue_head and routing
+ *             all control traffic via it
+ *     General tidy/document
+ *     Review the locking/move to refcounts more (mux now moved to an
+ *             alloc/free model ready)
+ *     Use newest tty open/close port helpers and install hooks
+ *     What to do about power functions ?
+ *     Termios setting and negotiation
+ *     Do we need a 'which mux are you' ioctl to correlate mux and tty sets
+ *
+ */
+
+#include <linux/types.h>
+#include <linux/major.h>
+#include <linux/errno.h>
+#include <linux/signal.h>
+#include <linux/fcntl.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/tty.h>
+#include <linux/timer.h>
+#include <linux/ctype.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/poll.h>
+#include <linux/bitops.h>
+#include <linux/file.h>
+#include <linux/uaccess.h>
+#include <linux/module.h>
+#include <linux/timer.h>
+#include <linux/tty_flip.h>
+#include <linux/tty_driver.h>
+#include <linux/serial.h>
+#include <linux/kfifo.h>
+#include <linux/skbuff.h>
+#include <linux/gsmmux.h>
+
+static int debug;
+module_param(debug, int, 0600);
+
+#define T1     (HZ/10)
+#define T2     (HZ/3)
+#define N2     3
+
+/* Use long timers for testing at low speed with debug on */
+#ifdef DEBUG_TIMING
+#define T1     HZ
+#define T2     (2 * HZ)
+#endif
+
+/* Semi-arbitary buffer size limits. 0710 is normally run with 32-64 byte
+   limits so this is plenty */
+#define MAX_MRU 512
+#define MAX_MTU 512
+
+/*
+ *     Each block of data we have queued to go out is in the form of
+ *     a gsm_msg which holds everything we need in a link layer independant
+ *     format
+ */
+
+struct gsm_msg {
+       struct gsm_msg *next;
+       u8 addr;                /* DLCI address + flags */
+       u8 ctrl;                /* Control byte + flags */
+       unsigned int len;       /* Length of data block (can be zero) */
+       unsigned char *data;    /* Points into buffer but not at the start */
+       unsigned char buffer[0];
+};
+
+/*
+ *     Each active data link has a gsm_dlci structure associated which ties
+ *     the link layer to an optional tty (if the tty side is open). To avoid
+ *     complexity right now these are only ever freed up when the mux is
+ *     shut down.
+ *
+ *     At the moment we don't free DLCI objects until the mux is torn down
+ *     this avoid object life time issues but might be worth review later.
+ */
+
+struct gsm_dlci {
+       struct gsm_mux *gsm;
+       int addr;
+       int state;
+#define DLCI_CLOSED            0
+#define DLCI_OPENING           1       /* Sending SABM not seen UA */
+#define DLCI_OPEN              2       /* SABM/UA complete */
+#define DLCI_CLOSING           3       /* Sending DISC not seen UA/DM */
+
+       /* Link layer */
+       spinlock_t lock;        /* Protects the internal state */
+       struct timer_list t1;   /* Retransmit timer for SABM and UA */
+       int retries;
+       /* Uplink tty if active */
+       struct tty_port port;   /* The tty bound to this DLCI if there is one */
+       struct kfifo *fifo;     /* Queue fifo for the DLCI */
+       struct kfifo _fifo;     /* For new fifo API porting only */
+       int adaption;           /* Adaption layer in use */
+       u32 modem_rx;           /* Our incoming virtual modem lines */
+       u32 modem_tx;           /* Our outgoing modem lines */
+       int dead;               /* Refuse re-open */
+       /* Flow control */
+       int throttled;          /* Private copy of throttle state */
+       int constipated;        /* Throttle status for outgoing */
+       /* Packetised I/O */
+       struct sk_buff *skb;    /* Frame being sent */
+       struct sk_buff_head skb_list;   /* Queued frames */
+       /* Data handling callback */
+       void (*data)(struct gsm_dlci *dlci, u8 *data, int len);
+};
+
+/* DLCI 0, 62/63 are special or reseved see gsmtty_open */
+
+#define NUM_DLCI               64
+
+/*
+ *     DLCI 0 is used to pass control blocks out of band of the data
+ *     flow (and with a higher link priority). One command can be outstanding
+ *     at a time and we use this structure to manage them. They are created
+ *     and destroyed by the user context, and updated by the receive paths
+ *     and timers
+ */
+
+struct gsm_control {
+       u8 cmd;         /* Command we are issuing */
+       u8 *data;       /* Data for the command in case we retransmit */
+       int len;        /* Length of block for retransmission */
+       int done;       /* Done flag */
+       int error;      /* Error if any */
+};
+
+/*
+ *     Each GSM mux we have is represented by this structure. If we are
+ *     operating as an ldisc then we use this structure as our ldisc
+ *     state. We need to sort out lifetimes and locking with respect
+ *     to the gsm mux array. For now we don't free DLCI objects that
+ *     have been instantiated until the mux itself is terminated.
+ *
+ *     To consider further: tty open versus mux shutdown.
+ */
+
+struct gsm_mux {
+       struct tty_struct *tty;         /* The tty our ldisc is bound to */
+       spinlock_t lock;
+
+       /* Events on the GSM channel */
+       wait_queue_head_t event;
+
+       /* Bits for GSM mode decoding */
+
+       /* Framing Layer */
+       unsigned char *buf;
+       int state;
+#define GSM_SEARCH             0
+#define GSM_START              1
+#define GSM_ADDRESS            2
+#define GSM_CONTROL            3
+#define GSM_LEN                        4
+#define GSM_DATA               5
+#define GSM_FCS                        6
+#define GSM_OVERRUN            7
+       unsigned int len;
+       unsigned int address;
+       unsigned int count;
+       int escape;
+       int encoding;
+       u8 control;
+       u8 fcs;
+       u8 *txframe;                    /* TX framing buffer */
+
+       /* Methods for the receiver side */
+       void (*receive)(struct gsm_mux *gsm, u8 ch);
+       void (*error)(struct gsm_mux *gsm, u8 ch, u8 flag);
+       /* And transmit side */
+       int (*output)(struct gsm_mux *mux, u8 *data, int len);
+
+       /* Link Layer */
+       unsigned int mru;
+       unsigned int mtu;
+       int initiator;                  /* Did we initiate connection */
+       int dead;                       /* Has the mux been shut down */
+       struct gsm_dlci *dlci[NUM_DLCI];
+       int constipated;                /* Asked by remote to shut up */
+
+       spinlock_t tx_lock;
+       unsigned int tx_bytes;          /* TX data outstanding */
+#define TX_THRESH_HI           8192
+#define TX_THRESH_LO           2048
+       struct gsm_msg *tx_head;        /* Pending data packets */
+       struct gsm_msg *tx_tail;
+
+       /* Control messages */
+       struct timer_list t2_timer;     /* Retransmit timer for commands */
+       int cretries;                   /* Command retry counter */
+       struct gsm_control *pending_cmd;/* Our current pending command */
+       spinlock_t control_lock;        /* Protects the pending command */
+
+       /* Configuration */
+       int adaption;           /* 1 or 2 supported */
+       u8 ftype;               /* UI or UIH */
+       int t1, t2;             /* Timers in 1/100th of a sec */
+       int n2;                 /* Retry count */
+
+       /* Statistics (not currently exposed) */
+       unsigned long bad_fcs;
+       unsigned long malformed;
+       unsigned long io_error;
+       unsigned long bad_size;
+       unsigned long unsupported;
+};
+
+
+/*
+ *     Mux objects - needed so that we can translate a tty index into the
+ *     relevant mux and DLCI.
+ */
+
+#define MAX_MUX                4                       /* 256 minors */
+static struct gsm_mux *gsm_mux[MAX_MUX];       /* GSM muxes */
+static spinlock_t gsm_mux_lock;
+
+/*
+ *     This section of the driver logic implements the GSM encodings
+ *     both the basic and the 'advanced'. Reliable transport is not
+ *     supported.
+ */
+
+#define CR                     0x02
+#define EA                     0x01
+#define        PF                      0x10
+
+/* I is special: the rest are ..*/
+#define RR                     0x01
+#define UI                     0x03
+#define RNR                    0x05
+#define REJ                    0x09
+#define DM                     0x0F
+#define SABM                   0x2F
+#define DISC                   0x43
+#define UA                     0x63
+#define        UIH                     0xEF
+
+/* Channel commands */
+#define CMD_NSC                        0x09
+#define CMD_TEST               0x11
+#define CMD_PSC                        0x21
+#define CMD_RLS                        0x29
+#define CMD_FCOFF              0x31
+#define CMD_PN                 0x41
+#define CMD_RPN                        0x49
+#define CMD_FCON               0x51
+#define CMD_CLD                        0x61
+#define CMD_SNC                        0x69
+#define CMD_MSC                        0x71
+
+/* Virtual modem bits */
+#define MDM_FC                 0x01
+#define MDM_RTC                        0x02
+#define MDM_RTR                        0x04
+#define MDM_IC                 0x20
+#define MDM_DV                 0x40
+
+#define GSM0_SOF               0xF9
+#define GSM1_SOF               0x7E
+#define GSM1_ESCAPE            0x7D
+#define GSM1_ESCAPE_BITS       0x20
+#define XON                    0x11
+#define XOFF                   0x13
+
+static const struct tty_port_operations gsm_port_ops;
+
+/*
+ *     CRC table for GSM 0710
+ */
+
+static const u8 gsm_fcs8[256] = {
+       0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75,
+       0x0E, 0x9F, 0xED, 0x7C, 0x09, 0x98, 0xEA, 0x7B,
+       0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, 0xF8, 0x69,
+       0x12, 0x83, 0xF1, 0x60, 0x15, 0x84, 0xF6, 0x67,
+       0x38, 0xA9, 0xDB, 0x4A, 0x3F, 0xAE, 0xDC, 0x4D,
+       0x36, 0xA7, 0xD5, 0x44, 0x31, 0xA0, 0xD2, 0x43,
+       0x24, 0xB5, 0xC7, 0x56, 0x23, 0xB2, 0xC0, 0x51,
+       0x2A, 0xBB, 0xC9, 0x58, 0x2D, 0xBC, 0xCE, 0x5F,
+       0x70, 0xE1, 0x93, 0x02, 0x77, 0xE6, 0x94, 0x05,
+       0x7E, 0xEF, 0x9D, 0x0C, 0x79, 0xE8, 0x9A, 0x0B,
+       0x6C, 0xFD, 0x8F, 0x1E, 0x6B, 0xFA, 0x88, 0x19,
+       0x62, 0xF3, 0x81, 0x10, 0x65, 0xF4, 0x86, 0x17,
+       0x48, 0xD9, 0xAB, 0x3A, 0x4F, 0xDE, 0xAC, 0x3D,
+       0x46, 0xD7, 0xA5, 0x34, 0x41, 0xD0, 0xA2, 0x33,
+       0x54, 0xC5, 0xB7, 0x26, 0x53, 0xC2, 0xB0, 0x21,
+       0x5A, 0xCB, 0xB9, 0x28, 0x5D, 0xCC, 0xBE, 0x2F,
+       0xE0, 0x71, 0x03, 0x92, 0xE7, 0x76, 0x04, 0x95,
+       0xEE, 0x7F, 0x0D, 0x9C, 0xE9, 0x78, 0x0A, 0x9B,
+       0xFC, 0x6D, 0x1F, 0x8E, 0xFB, 0x6A, 0x18, 0x89,
+       0xF2, 0x63, 0x11, 0x80, 0xF5, 0x64, 0x16, 0x87,
+       0xD8, 0x49, 0x3B, 0xAA, 0xDF, 0x4E, 0x3C, 0xAD,
+       0xD6, 0x47, 0x35, 0xA4, 0xD1, 0x40, 0x32, 0xA3,
+       0xC4, 0x55, 0x27, 0xB6, 0xC3, 0x52, 0x20, 0xB1,
+       0xCA, 0x5B, 0x29, 0xB8, 0xCD, 0x5C, 0x2E, 0xBF,
+       0x90, 0x01, 0x73, 0xE2, 0x97, 0x06, 0x74, 0xE5,
+       0x9E, 0x0F, 0x7D, 0xEC, 0x99, 0x08, 0x7A, 0xEB,
+       0x8C, 0x1D, 0x6F, 0xFE, 0x8B, 0x1A, 0x68, 0xF9,
+       0x82, 0x13, 0x61, 0xF0, 0x85, 0x14, 0x66, 0xF7,
+       0xA8, 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, 0xDD,
+       0xA6, 0x37, 0x45, 0xD4, 0xA1, 0x30, 0x42, 0xD3,
+       0xB4, 0x25, 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1,
+       0xBA, 0x2B, 0x59, 0xC8, 0xBD, 0x2C, 0x5E, 0xCF
+};
+
+#define INIT_FCS       0xFF
+#define GOOD_FCS       0xCF
+
+/**
+ *     gsm_fcs_add     -       update FCS
+ *     @fcs: Current FCS
+ *     @c: Next data
+ *
+ *     Update the FCS to include c. Uses the algorithm in the specification
+ *     notes.
+ */
+
+static inline u8 gsm_fcs_add(u8 fcs, u8 c)
+{
+       return gsm_fcs8[fcs ^ c];
+}
+
+/**
+ *     gsm_fcs_add_block       -       update FCS for a block
+ *     @fcs: Current FCS
+ *     @c: buffer of data
+ *     @len: length of buffer
+ *
+ *     Update the FCS to include c. Uses the algorithm in the specification
+ *     notes.
+ */
+
+static inline u8 gsm_fcs_add_block(u8 fcs, u8 *c, int len)
+{
+       while (len--)
+               fcs = gsm_fcs8[fcs ^ *c++];
+       return fcs;
+}
+
+/**
+ *     gsm_read_ea             -       read a byte into an EA
+ *     @val: variable holding value
+ *     c: byte going into the EA
+ *
+ *     Processes one byte of an EA. Updates the passed variable
+ *     and returns 1 if the EA is now completely read
+ */
+
+static int gsm_read_ea(unsigned int *val, u8 c)
+{
+       /* Add the next 7 bits into the value */
+       *val <<= 7;
+       *val |= c >> 1;
+       /* Was this the last byte of the EA 1 = yes*/
+       return c & EA;
+}
+
+/**
+ *     gsm_encode_modem        -       encode modem data bits
+ *     @dlci: DLCI to encode from
+ *
+ *     Returns the correct GSM encoded modem status bits (6 bit field) for
+ *     the current status of the DLCI and attached tty object
+ */
+
+static u8 gsm_encode_modem(const struct gsm_dlci *dlci)
+{
+       u8 modembits = 0;
+       /* FC is true flow control not modem bits */
+       if (dlci->throttled)
+               modembits |= MDM_FC;
+       if (dlci->modem_tx & TIOCM_DTR)
+               modembits |= MDM_RTC;
+       if (dlci->modem_tx & TIOCM_RTS)
+               modembits |= MDM_RTR;
+       if (dlci->modem_tx & TIOCM_RI)
+               modembits |= MDM_IC;
+       if (dlci->modem_tx & TIOCM_CD)
+               modembits |= MDM_DV;
+       return modembits;
+}
+
+/**
+ *     gsm_print_packet        -       display a frame for debug
+ *     @hdr: header to print before decode
+ *     @addr: address EA from the frame
+ *     @cr: C/R bit from the frame
+ *     @control: control including PF bit
+ *     @data: following data bytes
+ *     @dlen: length of data
+ *
+ *     Displays a packet in human readable format for debugging purposes. The
+ *     style is based on amateur radio LAP-B dump display.
+ */
+
+static void gsm_print_packet(const char *hdr, int addr, int cr,
+                                       u8 control, const u8 *data, int dlen)
+{
+       if (!(debug & 1))
+               return;
+
+       printk(KERN_INFO "%s %d) %c: ", hdr, addr, "RC"[cr]);
+
+       switch (control & ~PF) {
+       case SABM:
+               printk(KERN_CONT "SABM");
+               break;
+       case UA:
+               printk(KERN_CONT "UA");
+               break;
+       case DISC:
+               printk(KERN_CONT "DISC");
+               break;
+       case DM:
+               printk(KERN_CONT "DM");
+               break;
+       case UI:
+               printk(KERN_CONT "UI");
+               break;
+       case UIH:
+               printk(KERN_CONT "UIH");
+               break;
+       default:
+               if (!(control & 0x01)) {
+                       printk(KERN_CONT "I N(S)%d N(R)%d",
+                               (control & 0x0E) >> 1, (control & 0xE)>> 5);
+               } else switch (control & 0x0F) {
+               case RR:
+                       printk("RR(%d)", (control & 0xE0) >> 5);
+                       break;
+               case RNR:
+                       printk("RNR(%d)", (control & 0xE0) >> 5);
+                       break;
+               case REJ:
+                       printk("REJ(%d)", (control & 0xE0) >> 5);
+                       break;
+               default:
+                       printk(KERN_CONT "[%02X]", control);
+               }
+       }
+
+       if (control & PF)
+               printk(KERN_CONT "(P)");
+       else
+               printk(KERN_CONT "(F)");
+
+       if (dlen) {
+               int ct = 0;
+               while (dlen--) {
+                       if (ct % 8 == 0)
+                               printk(KERN_CONT "\n    ");
+                       printk(KERN_CONT "%02X ", *data++);
+                       ct++;
+               }
+       }
+       printk(KERN_CONT "\n");
+}
+
+
+/*
+ *     Link level transmission side
+ */
+
+/**
+ *     gsm_stuff_packet        -       bytestuff a packet
+ *     @ibuf: input
+ *     @obuf: output
+ *     @len: length of input
+ *
+ *     Expand a buffer by bytestuffing it. The worst case size change
+ *     is doubling and the caller is responsible for handing out
+ *     suitable sized buffers.
+ */
+
+static int gsm_stuff_frame(const u8 *input, u8 *output, int len)
+{
+       int olen = 0;
+       while (len--) {
+               if (*input == GSM1_SOF || *input == GSM1_ESCAPE
+                   || *input == XON || *input == XOFF) {
+                       *output++ = GSM1_ESCAPE;
+                       *output++ = *input++ ^ GSM1_ESCAPE_BITS;
+                       olen++;
+               } else
+                       *output++ = *input++;
+               olen++;
+       }
+       return olen;
+}
+
+static void hex_packet(const unsigned char *p, int len)
+{
+       int i;
+       for (i = 0; i < len; i++) {
+               if (i && (i % 16) == 0)
+                       printk("\n");
+               printk("%02X ", *p++);
+       }
+       printk("\n");
+}
+
+/**
+ *     gsm_send        -       send a control frame
+ *     @gsm: our GSM mux
+ *     @addr: address for control frame
+ *     @cr: command/response bit
+ *     @control:  control byte including PF bit
+ *
+ *     Format up and transmit a control frame. These do not go via the
+ *     queueing logic as they should be transmitted ahead of data when
+ *     they are needed.
+ *
+ *     FIXME: Lock versus data TX path
+ */
+
+static void gsm_send(struct gsm_mux *gsm, int addr, int cr, int control)
+{
+       int len;
+       u8 cbuf[10];
+       u8 ibuf[3];
+
+       switch (gsm->encoding) {
+       case 0:
+               cbuf[0] = GSM0_SOF;
+               cbuf[1] = (addr << 2) | (cr << 1) | EA;
+               cbuf[2] = control;
+               cbuf[3] = EA;   /* Length of data = 0 */
+               cbuf[4] = 0xFF - gsm_fcs_add_block(INIT_FCS, cbuf + 1, 3);
+               cbuf[5] = GSM0_SOF;
+               len = 6;
+               break;
+       case 1:
+       case 2:
+               /* Control frame + packing (but not frame stuffing) in mode 1 */
+               ibuf[0] = (addr << 2) | (cr << 1) | EA;
+               ibuf[1] = control;
+               ibuf[2] = 0xFF - gsm_fcs_add_block(INIT_FCS, ibuf, 2);
+               /* Stuffing may double the size worst case */
+               len = gsm_stuff_frame(ibuf, cbuf + 1, 3);
+               /* Now add the SOF markers */
+               cbuf[0] = GSM1_SOF;
+               cbuf[len + 1] = GSM1_SOF;
+               /* FIXME: we can omit the lead one in many cases */
+               len += 2;
+               break;
+       default:
+               WARN_ON(1);
+               return;
+       }
+       gsm->output(gsm, cbuf, len);
+       gsm_print_packet("-->", addr, cr, control, NULL, 0);
+}
+
+/**
+ *     gsm_response    -       send a control response
+ *     @gsm: our GSM mux
+ *     @addr: address for control frame
+ *     @control:  control byte including PF bit
+ *
+ *     Format up and transmit a link level response frame.
+ */
+
+static inline void gsm_response(struct gsm_mux *gsm, int addr, int control)
+{
+       gsm_send(gsm, addr, 0, control);
+}
+
+/**
+ *     gsm_command     -       send a control command
+ *     @gsm: our GSM mux
+ *     @addr: address for control frame
+ *     @control:  control byte including PF bit
+ *
+ *     Format up and transmit a link level command frame.
+ */
+
+static inline void gsm_command(struct gsm_mux *gsm, int addr, int control)
+{
+       gsm_send(gsm, addr, 1, control);
+}
+
+/* Data transmission */
+
+#define HDR_LEN                6       /* ADDR CTRL [LEN.2] DATA FCS */
+
+/**
+ *     gsm_data_alloc          -       allocate data frame
+ *     @gsm: GSM mux
+ *     @addr: DLCI address
+ *     @len: length excluding header and FCS
+ *     @ctrl: control byte
+ *
+ *     Allocate a new data buffer for sending frames with data. Space is left
+ *     at the front for header bytes but that is treated as an implementation
+ *     detail and not for the high level code to use
+ */
+
+static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len,
+                                                               u8 ctrl)
+{
+       struct gsm_msg *m = kmalloc(sizeof(struct gsm_msg) + len + HDR_LEN,
+                                                               GFP_ATOMIC);
+       if (m == NULL)
+               return NULL;
+       m->data = m->buffer + HDR_LEN - 1;      /* Allow for FCS */
+       m->len = len;
+       m->addr = addr;
+       m->ctrl = ctrl;
+       m->next = NULL;
+       return m;
+}
+
+/**
+ *     gsm_data_kick           -       poke the queue
+ *     @gsm: GSM Mux
+ *
+ *     The tty device has called us to indicate that room has appeared in
+ *     the transmit queue. Ram more data into the pipe if we have any
+ *
+ *     FIXME: lock against link layer control transmissions
+ */
+
+static void gsm_data_kick(struct gsm_mux *gsm)
+{
+       struct gsm_msg *msg = gsm->tx_head;
+       int len;
+       int skip_sof = 0;
+
+       /* FIXME: We need to apply this solely to data messages */
+       if (gsm->constipated)
+               return;
+
+       while (gsm->tx_head != NULL) {
+               msg = gsm->tx_head;
+               if (gsm->encoding != 0) {
+                       gsm->txframe[0] = GSM1_SOF;
+                       len = gsm_stuff_frame(msg->data,
+                                               gsm->txframe + 1, msg->len);
+                       gsm->txframe[len + 1] = GSM1_SOF;
+                       len += 2;
+               } else {
+                       gsm->txframe[0] = GSM0_SOF;
+                       memcpy(gsm->txframe + 1 , msg->data, msg->len);
+                       gsm->txframe[msg->len + 1] = GSM0_SOF;
+                       len = msg->len + 2;
+               }
+
+               if (debug & 4) {
+                       printk("gsm_data_kick: \n");
+                       hex_packet(gsm->txframe, len);
+               }
+
+               if (gsm->output(gsm, gsm->txframe + skip_sof,
+                                               len - skip_sof) < 0)
+                       break;
+               /* FIXME: Can eliminate one SOF in many more cases */
+               gsm->tx_head = msg->next;
+               if (gsm->tx_head == NULL)
+                       gsm->tx_tail = NULL;
+               gsm->tx_bytes -= msg->len;
+               kfree(msg);
+               /* For a burst of frames skip the extra SOF within the
+                  burst */
+               skip_sof = 1;
+       }
+}
+
+/**
+ *     __gsm_data_queue                -       queue a UI or UIH frame
+ *     @dlci: DLCI sending the data
+ *     @msg: message queued
+ *
+ *     Add data to the transmit queue and try and get stuff moving
+ *     out of the mux tty if not already doing so. The Caller must hold
+ *     the gsm tx lock.
+ */
+
+static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
+{
+       struct gsm_mux *gsm = dlci->gsm;
+       u8 *dp = msg->data;
+       u8 *fcs = dp + msg->len;
+
+       /* Fill in the header */
+       if (gsm->encoding == 0) {
+               if (msg->len < 128)
+                       *--dp = (msg->len << 1) | EA;
+               else {
+                       *--dp = (msg->len >> 6) | EA;
+                       *--dp = (msg->len & 127) << 1;
+               }
+       }
+
+       *--dp = msg->ctrl;
+       if (gsm->initiator)
+               *--dp = (msg->addr << 2) | 2 | EA;
+       else
+               *--dp = (msg->addr << 2) | EA;
+       *fcs = gsm_fcs_add_block(INIT_FCS, dp , msg->data - dp);
+       /* Ugly protocol layering violation */
+       if (msg->ctrl == UI || msg->ctrl == (UI|PF))
+               *fcs = gsm_fcs_add_block(*fcs, msg->data, msg->len);
+       *fcs = 0xFF - *fcs;
+
+       gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl,
+                                                       msg->data, msg->len);
+
+       /* Move the header back and adjust the length, also allow for the FCS
+          now tacked on the end */
+       msg->len += (msg->data - dp) + 1;
+       msg->data = dp;
+
+       /* Add to the actual output queue */
+       if (gsm->tx_tail)
+               gsm->tx_tail->next = msg;
+       else
+               gsm->tx_head = msg;
+       gsm->tx_tail = msg;
+       gsm->tx_bytes += msg->len;
+       gsm_data_kick(gsm);
+}
+
+/**
+ *     gsm_data_queue          -       queue a UI or UIH frame
+ *     @dlci: DLCI sending the data
+ *     @msg: message queued
+ *
+ *     Add data to the transmit queue and try and get stuff moving
+ *     out of the mux tty if not already doing so. Take the
+ *     the gsm tx lock and dlci lock.
+ */
+
+static void gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
+{
+       unsigned long flags;
+       spin_lock_irqsave(&dlci->gsm->tx_lock, flags);
+       __gsm_data_queue(dlci, msg);
+       spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags);
+}
+
+/**
+ *     gsm_dlci_data_output    -       try and push data out of a DLCI
+ *     @gsm: mux
+ *     @dlci: the DLCI to pull data from
+ *
+ *     Pull data from a DLCI and send it into the transmit queue if there
+ *     is data. Keep to the MRU of the mux. This path handles the usual tty
+ *     interface which is a byte stream with optional modem data.
+ *
+ *     Caller must hold the tx_lock of the mux.
+ */
+
+static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci)
+{
+       struct gsm_msg *msg;
+       u8 *dp;
+       int len, size;
+       int h = dlci->adaption - 1;
+
+       len = kfifo_len(dlci->fifo);
+       if (len == 0)
+               return 0;
+
+       /* MTU/MRU count only the data bits */
+       if (len > gsm->mtu)
+               len = gsm->mtu;
+
+       size = len + h;
+
+       msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype);
+       /* FIXME: need a timer or something to kick this so it can't
+          get stuck with no work outstanding and no buffer free */
+       if (msg == NULL)
+               return -ENOMEM;
+       dp = msg->data;
+       switch (dlci->adaption) {
+       case 1: /* Unstructured */
+               break;
+       case 2: /* Unstructed with modem bits. Always one byte as we never
+                  send inline break data */
+               *dp += gsm_encode_modem(dlci);
+               len--;
+               break;
+       }
+       WARN_ON(kfifo_out_locked(dlci->fifo, dp , len, &dlci->lock) != len);
+       __gsm_data_queue(dlci, msg);
+       /* Bytes of data we used up */
+       return size;
+}
+
+/**
+ *     gsm_dlci_data_output_framed  -  try and push data out of a DLCI
+ *     @gsm: mux
+ *     @dlci: the DLCI to pull data from
+ *
+ *     Pull data from a DLCI and send it into the transmit queue if there
+ *     is data. Keep to the MRU of the mux. This path handles framed data
+ *     queued as skbuffs to the DLCI.
+ *
+ *     Caller must hold the tx_lock of the mux.
+ */
+
+static int gsm_dlci_data_output_framed(struct gsm_mux *gsm,
+                                               struct gsm_dlci *dlci)
+{
+       struct gsm_msg *msg;
+       u8 *dp;
+       int len, size;
+       int last = 0, first = 0;
+       int overhead = 0;
+
+       /* One byte per frame is used for B/F flags */
+       if (dlci->adaption == 4)
+               overhead = 1;
+
+       /* dlci->skb is locked by tx_lock */
+       if (dlci->skb == NULL) {
+               dlci->skb = skb_dequeue(&dlci->skb_list);
+               if (dlci->skb == NULL)
+                       return 0;
+               first = 1;
+       }
+       len = dlci->skb->len + overhead;
+
+       /* MTU/MRU count only the data bits */
+       if (len > gsm->mtu) {
+               if (dlci->adaption == 3) {
+                       /* Over long frame, bin it */
+                       kfree_skb(dlci->skb);
+                       dlci->skb = NULL;
+                       return 0;
+               }
+               len = gsm->mtu;
+       } else
+               last = 1;
+
+       size = len + overhead;
+       msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype);
+
+       /* FIXME: need a timer or something to kick this so it can't
+          get stuck with no work outstanding and no buffer free */
+       if (msg == NULL)
+               return -ENOMEM;
+       dp = msg->data;
+
+       if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */
+               /* Flag byte to carry the start/end info */
+               *dp++ = last << 7 | first << 6 | 1;     /* EA */
+               len--;
+       }
+       memcpy(dp, skb_pull(dlci->skb, len), len);
+       __gsm_data_queue(dlci, msg);
+       if (last)
+               dlci->skb = NULL;
+       return size;
+}
+
+/**
+ *     gsm_dlci_data_sweep             -       look for data to send
+ *     @gsm: the GSM mux
+ *
+ *     Sweep the GSM mux channels in priority order looking for ones with
+ *     data to send. We could do with optimising this scan a bit. We aim
+ *     to fill the queue totally or up to TX_THRESH_HI bytes. Once we hit
+ *     TX_THRESH_LO we get called again
+ *
+ *     FIXME: We should round robin between groups and in theory you can
+ *     renegotiate DLCI priorities with optional stuff. Needs optimising.
+ */
+
+static void gsm_dlci_data_sweep(struct gsm_mux *gsm)
+{
+       int len;
+       /* Priority ordering: We should do priority with RR of the groups */
+       int i = 1;
+       unsigned long flags;
+
+       spin_lock_irqsave(&gsm->tx_lock, flags);
+       while (i < NUM_DLCI) {
+               struct gsm_dlci *dlci;
+
+               if (gsm->tx_bytes > TX_THRESH_HI)
+                       break;
+               dlci = gsm->dlci[i];
+               if (dlci == NULL || dlci->constipated) {
+                       i++;
+                       continue;
+               }
+               if (dlci->adaption < 3)
+                       len = gsm_dlci_data_output(gsm, dlci);
+               else
+                       len = gsm_dlci_data_output_framed(gsm, dlci);
+               if (len < 0)
+                       return;
+               /* DLCI empty - try the next */
+               if (len == 0)
+                       i++;
+       }
+       spin_unlock_irqrestore(&gsm->tx_lock, flags);
+}
+
+/**
+ *     gsm_dlci_data_kick      -       transmit if possible
+ *     @dlci: DLCI to kick
+ *
+ *     Transmit data from this DLCI if the queue is empty. We can't rely on
+ *     a tty wakeup except when we filled the pipe so we need to fire off
+ *     new data ourselves in other cases.
+ */
+
+static void gsm_dlci_data_kick(struct gsm_dlci *dlci)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&dlci->gsm->tx_lock, flags);
+       /* If we have nothing running then we need to fire up */
+       if (dlci->gsm->tx_bytes == 0)
+               gsm_dlci_data_output(dlci->gsm, dlci);
+       else if (dlci->gsm->tx_bytes < TX_THRESH_LO)
+               gsm_dlci_data_sweep(dlci->gsm);
+       spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags);
+}
+
+/*
+ *     Control message processing
+ */
+
+
+/**
+ *     gsm_control_reply       -       send a response frame to a control
+ *     @gsm: gsm channel
+ *     @cmd: the command to use
+ *     @data: data to follow encoded info
+ *     @dlen: length of data
+ *
+ *     Encode up and queue a UI/UIH frame containing our response.
+ */
+
+static void gsm_control_reply(struct gsm_mux *gsm, int cmd, u8 *data,
+                                       int dlen)
+{
+       struct gsm_msg *msg;
+       msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->ftype);
+       msg->data[0] = (cmd & 0xFE) << 1 | EA;  /* Clear C/R */
+       msg->data[1] = (dlen << 1) | EA;
+       memcpy(msg->data + 2, data, dlen);
+       gsm_data_queue(gsm->dlci[0], msg);
+}
+
+/**
+ *     gsm_process_modem       -       process received modem status
+ *     @tty: virtual tty bound to the DLCI
+ *     @dlci: DLCI to affect
+ *     @modem: modem bits (full EA)
+ *
+ *     Used when a modem control message or line state inline in adaption
+ *     layer 2 is processed. Sort out the local modem state and throttles
+ */
+
+static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci,
+                                                       u32 modem)
+{
+       int  mlines = 0;
+       u8 brk = modem >> 6;
+
+       /* Flow control/ready to communicate */
+       if (modem & MDM_FC) {
+               /* Need to throttle our output on this device */
+               dlci->constipated = 1;
+       }
+       if (modem & MDM_RTC) {
+               mlines |= TIOCM_DSR | TIOCM_DTR;
+               dlci->constipated = 0;
+               gsm_dlci_data_kick(dlci);
+       }
+       /* Map modem bits */
+       if (modem & MDM_RTR)
+               mlines |= TIOCM_RTS | TIOCM_CTS;
+       if (modem & MDM_IC)
+               mlines |= TIOCM_RI;
+       if (modem & MDM_DV)
+               mlines |= TIOCM_CD;
+
+       /* Carrier drop -> hangup */
+       if (tty) {
+               if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD))
+                       if (!(tty->termios->c_cflag & CLOCAL))
+                               tty_hangup(tty);
+               if (brk & 0x01)
+                       tty_insert_flip_char(tty, 0, TTY_BREAK);
+       }
+       dlci->modem_rx = mlines;
+}
+
+/**
+ *     gsm_control_modem       -       modem status received
+ *     @gsm: GSM channel
+ *     @data: data following command
+ *     @clen: command length
+ *
+ *     We have received a modem status control message. This is used by
+ *     the GSM mux protocol to pass virtual modem line status and optionally
+ *     to indicate break signals. Unpack it, convert to Linux representation
+ *     and if need be stuff a break message down the tty.
+ */
+
+static void gsm_control_modem(struct gsm_mux *gsm, u8 *data, int clen)
+{
+       unsigned int addr = 0;
+       unsigned int modem = 0;
+       struct gsm_dlci *dlci;
+       int len = clen;
+       u8 *dp = data;
+       struct tty_struct *tty;
+
+       while (gsm_read_ea(&addr, *dp++) == 0) {
+               len--;
+               if (len == 0)
+                       return;
+       }
+       /* Must be at least one byte following the EA */
+       len--;
+       if (len <= 0)
+               return;
+
+       addr >>= 1;
+       /* Closed port, or invalid ? */
+       if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL)
+               return;
+       dlci = gsm->dlci[addr];
+
+       while (gsm_read_ea(&modem, *dp++) == 0) {
+               len--;
+               if (len == 0)
+                       return;
+       }
+       tty = tty_port_tty_get(&dlci->port);
+       gsm_process_modem(tty, dlci, modem);
+       if (tty) {
+               tty_wakeup(tty);
+               tty_kref_put(tty);
+       }
+       gsm_control_reply(gsm, CMD_MSC, data, clen);
+}
+
+/**
+ *     gsm_control_rls         -       remote line status
+ *     @gsm: GSM channel
+ *     @data: data bytes
+ *     @clen: data length
+ *
+ *     The modem sends us a two byte message on the control channel whenever
+ *     it wishes to send us an error state from the virtual link. Stuff
+ *     this into the uplink tty if present
+ */
+
+static void gsm_control_rls(struct gsm_mux *gsm, u8 *data, int clen)
+{
+       struct tty_struct *tty;
+       unsigned int addr = 0 ;
+       u8 bits;
+       int len = clen;
+       u8 *dp = data;
+
+       while (gsm_read_ea(&addr, *dp++) == 0) {
+               len--;
+               if (len == 0)
+                       return;
+       }
+       /* Must be at least one byte following ea */
+       len--;
+       if (len <= 0)
+               return;
+       addr >>= 1;
+       /* Closed port, or invalid ? */
+       if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL)
+               return;
+       /* No error ? */
+       bits = *dp;
+       if ((bits & 1) == 0)
+               return;
+       /* See if we have an uplink tty */
+       tty = tty_port_tty_get(&gsm->dlci[addr]->port);
+
+       if (tty) {
+               if (bits & 2)
+                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+               if (bits & 4)
+                       tty_insert_flip_char(tty, 0, TTY_PARITY);
+               if (bits & 8)
+                       tty_insert_flip_char(tty, 0, TTY_FRAME);
+               tty_flip_buffer_push(tty);
+               tty_kref_put(tty);
+       }
+       gsm_control_reply(gsm, CMD_RLS, data, clen);
+}
+
+static void gsm_dlci_begin_close(struct gsm_dlci *dlci);
+
+/**
+ *     gsm_control_message     -       DLCI 0 control processing
+ *     @gsm: our GSM mux
+ *     @command:  the command EA
+ *     @data: data beyond the command/length EAs
+ *     @clen: length
+ *
+ *     Input processor for control messages from the other end of the link.
+ *     Processes the incoming request and queues a response frame or an
+ *     NSC response if not supported
+ */
+
+static void gsm_control_message(struct gsm_mux *gsm, unsigned int command,
+                                                       u8 *data, int clen)
+{
+       u8 buf[1];
+       switch (command) {
+       case CMD_CLD: {
+               struct gsm_dlci *dlci = gsm->dlci[0];
+               /* Modem wishes to close down */
+               if (dlci) {
+                       dlci->dead = 1;
+                       gsm->dead = 1;
+                       gsm_dlci_begin_close(dlci);
+               }
+               }
+               break;
+       case CMD_TEST:
+               /* Modem wishes to test, reply with the data */
+               gsm_control_reply(gsm, CMD_TEST, data, clen);
+               break;
+       case CMD_FCON:
+               /* Modem wants us to STFU */
+               gsm->constipated = 1;
+               gsm_control_reply(gsm, CMD_FCON, NULL, 0);
+               break;
+       case CMD_FCOFF:
+               /* Modem can accept data again */
+               gsm->constipated = 0;
+               gsm_control_reply(gsm, CMD_FCOFF, NULL, 0);
+               /* Kick the link in case it is idling */
+               gsm_data_kick(gsm);
+               break;
+       case CMD_MSC:
+               /* Out of band modem line change indicator for a DLCI */
+               gsm_control_modem(gsm, data, clen);
+               break;
+       case CMD_RLS:
+               /* Out of band error reception for a DLCI */
+               gsm_control_rls(gsm, data, clen);
+               break;
+       case CMD_PSC:
+               /* Modem wishes to enter power saving state */
+               gsm_control_reply(gsm, CMD_PSC, NULL, 0);
+               break;
+               /* Optional unsupported commands */
+       case CMD_PN:    /* Parameter negotiation */
+       case CMD_RPN:   /* Remote port negotation */
+       case CMD_SNC:   /* Service negotation command */
+       default:
+               /* Reply to bad commands with an NSC */
+               buf[0] = command;
+               gsm_control_reply(gsm, CMD_NSC, buf, 1);
+               break;
+       }
+}
+
+/**
+ *     gsm_control_response    -       process a response to our control
+ *     @gsm: our GSM mux
+ *     @command: the command (response) EA
+ *     @data: data beyond the command/length EA
+ *     @clen: length
+ *
+ *     Process a response to an outstanding command. We only allow a single
+ *     control message in flight so this is fairly easy. All the clean up
+ *     is done by the caller, we just update the fields, flag it as done
+ *     and return
+ */
+
+static void gsm_control_response(struct gsm_mux *gsm, unsigned int command,
+                                                       u8 *data, int clen)
+{
+       struct gsm_control *ctrl;
+       unsigned long flags;
+
+       spin_lock_irqsave(&gsm->control_lock, flags);
+
+       ctrl = gsm->pending_cmd;
+       /* Does the reply match our command */
+       command |= 1;
+       if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) {
+               /* Our command was replied to, kill the retry timer */
+               del_timer(&gsm->t2_timer);
+               gsm->pending_cmd = NULL;
+               /* Rejected by the other end */
+               if (command == CMD_NSC)
+                       ctrl->error = -EOPNOTSUPP;
+               ctrl->done = 1;
+               wake_up(&gsm->event);
+       }
+       spin_unlock_irqrestore(&gsm->control_lock, flags);
+}
+
+/**
+ *     gsm_control_transmit    -       send control packet
+ *     @gsm: gsm mux
+ *     @ctrl: frame to send
+ *
+ *     Send out a pending control command (called under control lock)
+ */
+
+static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl)
+{
+       struct gsm_msg *msg = gsm_data_alloc(gsm, 0, ctrl->len + 1,
+                                                       gsm->ftype|PF);
+       if (msg == NULL)
+               return;
+       msg->data[0] = (ctrl->cmd << 1) | 2 | EA;       /* command */
+       memcpy(msg->data + 1, ctrl->data, ctrl->len);
+       gsm_data_queue(gsm->dlci[0], msg);
+}
+
+/**
+ *     gsm_control_retransmit  -       retransmit a control frame
+ *     @data: pointer to our gsm object
+ *
+ *     Called off the T2 timer expiry in order to retransmit control frames
+ *     that have been lost in the system somewhere. The control_lock protects
+ *     us from colliding with another sender or a receive completion event.
+ *     In that situation the timer may still occur in a small window but
+ *     gsm->pending_cmd will be NULL and we just let the timer expire.
+ */
+
+static void gsm_control_retransmit(unsigned long data)
+{
+       struct gsm_mux *gsm = (struct gsm_mux *)data;
+       struct gsm_control *ctrl;
+       unsigned long flags;
+       spin_lock_irqsave(&gsm->control_lock, flags);
+       ctrl = gsm->pending_cmd;
+       if (ctrl) {
+               gsm->cretries--;
+               if (gsm->cretries == 0) {
+                       gsm->pending_cmd = NULL;
+                       ctrl->error = -ETIMEDOUT;
+                       ctrl->done = 1;
+                       spin_unlock_irqrestore(&gsm->control_lock, flags);
+                       wake_up(&gsm->event);
+                       return;
+               }
+               gsm_control_transmit(gsm, ctrl);
+               mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100);
+       }
+       spin_unlock_irqrestore(&gsm->control_lock, flags);
+}
+
+/**
+ *     gsm_control_send        -       send a control frame on DLCI 0
+ *     @gsm: the GSM channel
+ *     @command: command  to send including CR bit
+ *     @data: bytes of data (must be kmalloced)
+ *     @len: length of the block to send
+ *
+ *     Queue and dispatch a control command. Only one command can be
+ *     active at a time. In theory more can be outstanding but the matching
+ *     gets really complicated so for now stick to one outstanding.
+ */
+
+static struct gsm_control *gsm_control_send(struct gsm_mux *gsm,
+               unsigned int command, u8 *data, int clen)
+{
+       struct gsm_control *ctrl = kzalloc(sizeof(struct gsm_control),
+                                               GFP_KERNEL);
+       unsigned long flags;
+       if (ctrl == NULL)
+               return NULL;
+retry:
+       wait_event(gsm->event, gsm->pending_cmd == NULL);
+       spin_lock_irqsave(&gsm->control_lock, flags);
+       if (gsm->pending_cmd != NULL) {
+               spin_unlock_irqrestore(&gsm->control_lock, flags);
+               goto retry;
+       }
+       ctrl->cmd = command;
+       ctrl->data = data;
+       ctrl->len = clen;
+       gsm->pending_cmd = ctrl;
+       gsm->cretries = gsm->n2;
+       mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100);
+       gsm_control_transmit(gsm, ctrl);
+       spin_unlock_irqrestore(&gsm->control_lock, flags);
+       return ctrl;
+}
+
+/**
+ *     gsm_control_wait        -       wait for a control to finish
+ *     @gsm: GSM mux
+ *     @control: control we are waiting on
+ *
+ *     Waits for the control to complete or time out. Frees any used
+ *     resources and returns 0 for success, or an error if the remote
+ *     rejected or ignored the request.
+ */
+
+static int gsm_control_wait(struct gsm_mux *gsm, struct gsm_control *control)
+{
+       int err;
+       wait_event(gsm->event, control->done == 1);
+       err = control->error;
+       kfree(control);
+       return err;
+}
+
+
+/*
+ *     DLCI level handling: Needs krefs
+ */
+
+/*
+ *     State transitions and timers
+ */
+
+/**
+ *     gsm_dlci_close          -       a DLCI has closed
+ *     @dlci: DLCI that closed
+ *
+ *     Perform processing when moving a DLCI into closed state. If there
+ *     is an attached tty this is hung up
+ */
+
+static void gsm_dlci_close(struct gsm_dlci *dlci)
+{
+       del_timer(&dlci->t1);
+       if (debug & 8)
+               printk("DLCI %d goes closed.\n", dlci->addr);
+       dlci->state = DLCI_CLOSED;
+       if (dlci->addr != 0) {
+               struct tty_struct  *tty = tty_port_tty_get(&dlci->port);
+               if (tty) {
+                       tty_hangup(tty);
+                       tty_kref_put(tty);
+               }
+               kfifo_reset(dlci->fifo);
+       } else
+               dlci->gsm->dead = 1;
+       wake_up(&dlci->gsm->event);
+       /* A DLCI 0 close is a MUX termination so we need to kick that
+          back to userspace somehow */
+}
+
+/**
+ *     gsm_dlci_open           -       a DLCI has opened
+ *     @dlci: DLCI that opened
+ *
+ *     Perform processing when moving a DLCI into open state.
+ */
+
+static void gsm_dlci_open(struct gsm_dlci *dlci)
+{
+       /* Note that SABM UA .. SABM UA first UA lost can mean that we go
+          open -> open */
+       del_timer(&dlci->t1);
+       /* This will let a tty open continue */
+       dlci->state = DLCI_OPEN;
+       if (debug & 8)
+               printk("DLCI %d goes open.\n", dlci->addr);
+       wake_up(&dlci->gsm->event);
+}
+
+/**
+ *     gsm_dlci_t1             -       T1 timer expiry
+ *     @dlci: DLCI that opened
+ *
+ *     The T1 timer handles retransmits of control frames (essentially of
+ *     SABM and DISC). We resend the command until the retry count runs out
+ *     in which case an opening port goes back to closed and a closing port
+ *     is simply put into closed state (any further frames from the other
+ *     end will get a DM response)
+ */
+
+static void gsm_dlci_t1(unsigned long data)
+{
+       struct gsm_dlci *dlci = (struct gsm_dlci *)data;
+       struct gsm_mux *gsm = dlci->gsm;
+
+       switch (dlci->state) {
+       case DLCI_OPENING:
+               dlci->retries--;
+               if (dlci->retries) {
+                       gsm_command(dlci->gsm, dlci->addr, SABM|PF);
+                       mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100);
+               } else
+                       gsm_dlci_close(dlci);
+               break;
+       case DLCI_CLOSING:
+               dlci->retries--;
+               if (dlci->retries) {
+                       gsm_command(dlci->gsm, dlci->addr, DISC|PF);
+                       mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100);
+               } else
+                       gsm_dlci_close(dlci);
+               break;
+       }
+}
+
+/**
+ *     gsm_dlci_begin_open     -       start channel open procedure
+ *     @dlci: DLCI to open
+ *
+ *     Commence opening a DLCI from the Linux side. We issue SABM messages
+ *     to the modem which should then reply with a UA, at which point we
+ *     will move into open state. Opening is done asynchronously with retry
+ *     running off timers and the responses.
+ */
+
+static void gsm_dlci_begin_open(struct gsm_dlci *dlci)
+{
+       struct gsm_mux *gsm = dlci->gsm;
+       if (dlci->state == DLCI_OPEN || dlci->state == DLCI_OPENING)
+               return;
+       dlci->retries = gsm->n2;
+       dlci->state = DLCI_OPENING;
+       gsm_command(dlci->gsm, dlci->addr, SABM|PF);
+       mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100);
+}
+
+/**
+ *     gsm_dlci_begin_close    -       start channel open procedure
+ *     @dlci: DLCI to open
+ *
+ *     Commence closing a DLCI from the Linux side. We issue DISC messages
+ *     to the modem which should then reply with a UA, at which point we
+ *     will move into closed state. Closing is done asynchronously with retry
+ *     off timers. We may also receive a DM reply from the other end which
+ *     indicates the channel was already closed.
+ */
+
+static void gsm_dlci_begin_close(struct gsm_dlci *dlci)
+{
+       struct gsm_mux *gsm = dlci->gsm;
+       if (dlci->state == DLCI_CLOSED || dlci->state == DLCI_CLOSING)
+               return;
+       dlci->retries = gsm->n2;
+       dlci->state = DLCI_CLOSING;
+       gsm_command(dlci->gsm, dlci->addr, DISC|PF);
+       mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100);
+}
+
+/**
+ *     gsm_dlci_data           -       data arrived
+ *     @dlci: channel
+ *     @data: block of bytes received
+ *     @len: length of received block
+ *
+ *     A UI or UIH frame has arrived which contains data for a channel
+ *     other than the control channel. If the relevant virtual tty is
+ *     open we shovel the bits down it, if not we drop them.
+ */
+
+static void gsm_dlci_data(struct gsm_dlci *dlci, u8 *data, int len)
+{
+       /* krefs .. */
+       struct tty_port *port = &dlci->port;
+       struct tty_struct *tty = tty_port_tty_get(port);
+       unsigned int modem = 0;
+
+       if (debug & 16)
+               printk("%d bytes for tty %p\n", len, tty);
+       if (tty) {
+               switch (dlci->adaption)  {
+                       /* Unsupported types */
+                       /* Packetised interruptible data */
+                       case 4:
+                               break;
+                       /* Packetised uininterruptible voice/data */
+                       case 3:
+                               break;
+                       /* Asynchronous serial with line state in each frame */
+                       case 2:
+                               while (gsm_read_ea(&modem, *data++) == 0) {
+                                       len--;
+                                       if (len == 0)
+                                               return;
+                               }
+                               gsm_process_modem(tty, dlci, modem);
+                       /* Line state will go via DLCI 0 controls only */
+                       case 1:
+                       default:
+                               tty_insert_flip_string(tty, data, len);
+                               tty_flip_buffer_push(tty);
+               }
+               tty_kref_put(tty);
+       }
+}
+
+/**
+ *     gsm_dlci_control        -       data arrived on control channel
+ *     @dlci: channel
+ *     @data: block of bytes received
+ *     @len: length of received block
+ *
+ *     A UI or UIH frame has arrived which contains data for DLCI 0 the
+ *     control channel. This should contain a command EA followed by
+ *     control data bytes. The command EA contains a command/response bit
+ *     and we divide up the work accordingly.
+ */
+
+static void gsm_dlci_command(struct gsm_dlci *dlci, u8 *data, int len)
+{
+       /* See what command is involved */
+       unsigned int command = 0;
+       while (len-- > 0) {
+               if (gsm_read_ea(&command, *data++) == 1) {
+                       int clen = *data++;
+                       len--;
+                       /* FIXME: this is properly an EA */
+                       clen >>= 1;
+                       /* Malformed command ? */
+                       if (clen > len)
+                               return;
+                       if (command & 1)
+                               gsm_control_message(dlci->gsm, command,
+                                                               data, clen);
+                       else
+                               gsm_control_response(dlci->gsm, command,
+                                                               data, clen);
+                       return;
+               }
+       }
+}
+
+/*
+ *     Allocate/Free DLCI channels
+ */
+
+/**
+ *     gsm_dlci_alloc          -       allocate a DLCI
+ *     @gsm: GSM mux
+ *     @addr: address of the DLCI
+ *
+ *     Allocate and install a new DLCI object into the GSM mux.
+ *
+ *     FIXME: review locking races
+ */
+
+static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
+{
+       struct gsm_dlci *dlci = kzalloc(sizeof(struct gsm_dlci), GFP_ATOMIC);
+       if (dlci == NULL)
+               return NULL;
+       spin_lock_init(&dlci->lock);
+       dlci->fifo = &dlci->_fifo;
+       if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
+               kfree(dlci);
+               return NULL;
+       }
+
+       skb_queue_head_init(&dlci->skb_list);
+       init_timer(&dlci->t1);
+       dlci->t1.function = gsm_dlci_t1;
+       dlci->t1.data = (unsigned long)dlci;
+       tty_port_init(&dlci->port);
+       dlci->port.ops = &gsm_port_ops;
+       dlci->gsm = gsm;
+       dlci->addr = addr;
+       dlci->adaption = gsm->adaption;
+       dlci->state = DLCI_CLOSED;
+       if (addr)
+               dlci->data = gsm_dlci_data;
+       else
+               dlci->data = gsm_dlci_command;
+       gsm->dlci[addr] = dlci;
+       return dlci;
+}
+
+/**
+ *     gsm_dlci_free           -       release DLCI
+ *     @dlci: DLCI to destroy
+ *
+ *     Free up a DLCI. Currently to keep the lifetime rules sane we only
+ *     clean up DLCI objects when the MUX closes rather than as the port
+ *     is closed down on both the tty and mux levels.
+ *
+ *     Can sleep.
+ */
+static void gsm_dlci_free(struct gsm_dlci *dlci)
+{
+       struct tty_struct *tty = tty_port_tty_get(&dlci->port);
+       if (tty) {
+               tty_vhangup(tty);
+               tty_kref_put(tty);
+       }
+       del_timer_sync(&dlci->t1);
+       dlci->gsm->dlci[dlci->addr] = NULL;
+       kfifo_free(dlci->fifo);
+       kfree(dlci);
+}
+
+
+/*
+ *     LAPBish link layer logic
+ */
+
+/**
+ *     gsm_queue               -       a GSM frame is ready to process
+ *     @gsm: pointer to our gsm mux
+ *
+ *     At this point in time a frame has arrived and been demangled from
+ *     the line encoding. All the differences between the encodings have
+ *     been handled below us and the frame is unpacked into the structures.
+ *     The fcs holds the header FCS but any data FCS must be added here.
+ */
+
+static void gsm_queue(struct gsm_mux *gsm)
+{
+       struct gsm_dlci *dlci;
+       u8 cr;
+       int address;
+       /* We have to sneak a look at the packet body to do the FCS.
+          A somewhat layering violation in the spec */
+
+       if ((gsm->control & ~PF) == UI)
+               gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, gsm->len);
+       if (gsm->fcs != GOOD_FCS) {
+               gsm->bad_fcs++;
+               if (debug & 4)
+                       printk("BAD FCS %02x\n", gsm->fcs);
+               return;
+       }
+       address = gsm->address >> 1;
+       if (address >= NUM_DLCI)
+               goto invalid;
+
+       cr = gsm->address & 1;          /* C/R bit */
+
+       gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len);
+
+       cr ^= 1 - gsm->initiator;       /* Flip so 1 always means command */
+       dlci = gsm->dlci[address];
+
+       switch (gsm->control) {
+       case SABM|PF:
+               if (cr == 0)
+                       goto invalid;
+               if (dlci == NULL)
+                       dlci = gsm_dlci_alloc(gsm, address);
+               if (dlci == NULL)
+                       return;
+               if (dlci->dead)
+                       gsm_response(gsm, address, DM);
+               else {
+                       gsm_response(gsm, address, UA);
+                       gsm_dlci_open(dlci);
+               }
+               break;
+       case DISC|PF:
+               if (cr == 0)
+                       goto invalid;
+               if (dlci == NULL || dlci->state == DLCI_CLOSED) {
+                       gsm_response(gsm, address, DM);
+                       return;
+               }
+               /* Real close complete */
+               gsm_response(gsm, address, UA);
+               gsm_dlci_close(dlci);
+               break;
+       case UA:
+       case UA|PF:
+               if (cr == 0 || dlci == NULL)
+                       break;
+               switch (dlci->state) {
+               case DLCI_CLOSING:
+                       gsm_dlci_close(dlci);
+                       break;
+               case DLCI_OPENING:
+                       gsm_dlci_open(dlci);
+                       break;
+               }
+               break;
+       case DM:        /* DM can be valid unsolicited */
+       case DM|PF:
+               if (cr)
+                       goto invalid;
+               if (dlci == NULL)
+                       return;
+               gsm_dlci_close(dlci);
+               break;
+       case UI:
+       case UI|PF:
+       case UIH:
+       case UIH|PF:
+#if 0
+               if (cr)
+                       goto invalid;
+#endif
+               if (dlci == NULL || dlci->state != DLCI_OPEN) {
+                       gsm_command(gsm, address, DM|PF);
+                       return;
+               }
+               dlci->data(dlci, gsm->buf, gsm->len);
+               break;
+       default:
+               goto invalid;
+       }
+       return;
+invalid:
+       gsm->malformed++;
+       return;
+}
+
+
+/**
+ *     gsm0_receive    -       perform processing for non-transparency
+ *     @gsm: gsm data for this ldisc instance
+ *     @c: character
+ *
+ *     Receive bytes in gsm mode 0
+ */
+
+static void gsm0_receive(struct gsm_mux *gsm, unsigned char c)
+{
+       switch (gsm->state) {
+       case GSM_SEARCH:        /* SOF marker */
+               if (c == GSM0_SOF) {
+                       gsm->state = GSM_ADDRESS;
+                       gsm->address = 0;
+                       gsm->len = 0;
+                       gsm->fcs = INIT_FCS;
+               }
+               break;          /* Address EA */
+       case GSM_ADDRESS:
+               gsm->fcs = gsm_fcs_add(gsm->fcs, c);
+               if (gsm_read_ea(&gsm->address, c))
+                       gsm->state = GSM_CONTROL;
+               break;
+       case GSM_CONTROL:       /* Control Byte */
+               gsm->fcs = gsm_fcs_add(gsm->fcs, c);
+               gsm->control = c;
+               gsm->state = GSM_LEN;
+               break;
+       case GSM_LEN:           /* Length EA */
+               gsm->fcs = gsm_fcs_add(gsm->fcs, c);
+               if (gsm_read_ea(&gsm->len, c)) {
+                       if (gsm->len > gsm->mru) {
+                               gsm->bad_size++;
+                               gsm->state = GSM_SEARCH;
+                               break;
+                       }
+                       gsm->count = 0;
+                       gsm->state = GSM_DATA;
+               }
+               break;
+       case GSM_DATA:          /* Data */
+               gsm->buf[gsm->count++] = c;
+               if (gsm->count == gsm->len)
+                       gsm->state = GSM_FCS;
+               break;
+       case GSM_FCS:           /* FCS follows the packet */
+               gsm->fcs = c;
+               gsm_queue(gsm);
+               /* And then back for the next frame */
+               gsm->state = GSM_SEARCH;
+               break;
+       }
+}
+
+/**
+ *     gsm0_receive    -       perform processing for non-transparency
+ *     @gsm: gsm data for this ldisc instance
+ *     @c: character
+ *
+ *     Receive bytes in mode 1 (Advanced option)
+ */
+
+static void gsm1_receive(struct gsm_mux *gsm, unsigned char c)
+{
+       if (c == GSM1_SOF) {
+               /* EOF is only valid in frame if we have got to the data state
+                  and received at least one byte (the FCS) */
+               if (gsm->state == GSM_DATA && gsm->count) {
+                       /* Extract the FCS */
+                       gsm->count--;
+                       gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]);
+                       gsm->len = gsm->count;
+                       gsm_queue(gsm);
+                       gsm->state  = GSM_START;
+                       return;
+               }
+               /* Any partial frame was a runt so go back to start */
+               if (gsm->state != GSM_START) {
+                       gsm->malformed++;
+                       gsm->state = GSM_START;
+               }
+               /* A SOF in GSM_START means we are still reading idling or
+                  framing bytes */
+               return;
+       }
+
+       if (c == GSM1_ESCAPE) {
+               gsm->escape = 1;
+               return;
+       }
+
+       /* Only an unescaped SOF gets us out of GSM search */
+       if (gsm->state == GSM_SEARCH)
+               return;
+
+       if (gsm->escape) {
+               c ^= GSM1_ESCAPE_BITS;
+               gsm->escape = 0;
+       }
+       switch (gsm->state) {
+       case GSM_START:         /* First byte after SOF */
+               gsm->address = 0;
+               gsm->state = GSM_ADDRESS;
+               gsm->fcs = INIT_FCS;
+               /* Drop through */
+       case GSM_ADDRESS:       /* Address continuation */
+               gsm->fcs = gsm_fcs_add(gsm->fcs, c);
+               if (gsm_read_ea(&gsm->address, c))
+                       gsm->state = GSM_CONTROL;
+               break;
+       case GSM_CONTROL:       /* Control Byte */
+               gsm->fcs = gsm_fcs_add(gsm->fcs, c);
+               gsm->control = c;
+               gsm->count = 0;
+               gsm->state = GSM_DATA;
+               break;
+       case GSM_DATA:          /* Data */
+               if (gsm->count > gsm->mru ) {   /* Allow one for the FCS */
+                       gsm->state = GSM_OVERRUN;
+                       gsm->bad_size++;
+               } else
+                       gsm->buf[gsm->count++] = c;
+               break;
+       case GSM_OVERRUN:       /* Over-long - eg a dropped SOF */
+               break;
+       }
+}
+
+/**
+ *     gsm_error               -       handle tty error
+ *     @gsm: ldisc data
+ *     @data: byte received (may be invalid)
+ *     @flag: error received
+ *
+ *     Handle an error in the receipt of data for a frame. Currently we just
+ *     go back to hunting for a SOF.
+ *
+ *     FIXME: better diagnostics ?
+ */
+
+static void gsm_error(struct gsm_mux *gsm,
+                               unsigned char data, unsigned char flag)
+{
+       gsm->state = GSM_SEARCH;
+       gsm->io_error++;
+}
+
+/**
+ *     gsm_cleanup_mux         -       generic GSM protocol cleanup
+ *     @gsm: our mux
+ *
+ *     Clean up the bits of the mux which are the same for all framing
+ *     protocols. Remove the mux from the mux table, stop all the timers
+ *     and then shut down each device hanging up the channels as we go.
+ */
+
+void gsm_cleanup_mux(struct gsm_mux *gsm)
+{
+       int i;
+       struct gsm_dlci *dlci = gsm->dlci[0];
+       struct gsm_msg *txq;
+
+       gsm->dead = 1;
+
+       spin_lock(&gsm_mux_lock);
+       for (i = 0; i < MAX_MUX; i++) {
+               if (gsm_mux[i] == gsm) {
+                       gsm_mux[i] = NULL;
+                       break;
+               }
+       }
+       spin_unlock(&gsm_mux_lock);
+       WARN_ON(i == MAX_MUX);
+
+       del_timer_sync(&gsm->t2_timer);
+       /* Now we are sure T2 has stopped */
+       if (dlci) {
+               dlci->dead = 1;
+               gsm_dlci_begin_close(dlci);
+               wait_event_interruptible(gsm->event,
+                                       dlci->state == DLCI_CLOSED);
+       }
+       /* Free up any link layer users */
+       for (i = 0; i < NUM_DLCI; i++)
+               if (gsm->dlci[i])
+                       gsm_dlci_free(gsm->dlci[i]);
+       /* Now wipe the queues */
+       for (txq = gsm->tx_head; txq != NULL; txq = gsm->tx_head) {
+               gsm->tx_head = txq->next;
+               kfree(txq);
+       }
+       gsm->tx_tail = NULL;
+}
+EXPORT_SYMBOL_GPL(gsm_cleanup_mux);
+
+/**
+ *     gsm_activate_mux        -       generic GSM setup
+ *     @gsm: our mux
+ *
+ *     Set up the bits of the mux which are the same for all framing
+ *     protocols. Add the mux to the mux table so it can be opened and
+ *     finally kick off connecting to DLCI 0 on the modem.
+ */
+
+int gsm_activate_mux(struct gsm_mux *gsm)
+{
+       struct gsm_dlci *dlci;
+       int i = 0;
+
+       init_timer(&gsm->t2_timer);
+       gsm->t2_timer.function = gsm_control_retransmit;
+       gsm->t2_timer.data = (unsigned long)gsm;
+       init_waitqueue_head(&gsm->event);
+       spin_lock_init(&gsm->control_lock);
+       spin_lock_init(&gsm->tx_lock);
+
+       if (gsm->encoding == 0)
+               gsm->receive = gsm0_receive;
+       else
+               gsm->receive = gsm1_receive;
+       gsm->error = gsm_error;
+
+       spin_lock(&gsm_mux_lock);
+       for (i = 0; i < MAX_MUX; i++) {
+               if (gsm_mux[i] == NULL) {
+                       gsm_mux[i] = gsm;
+                       break;
+               }
+       }
+       spin_unlock(&gsm_mux_lock);
+       if (i == MAX_MUX)
+               return -EBUSY;
+
+       dlci = gsm_dlci_alloc(gsm, 0);
+       if (dlci == NULL)
+               return -ENOMEM;
+       gsm->dead = 0;          /* Tty opens are now permissible */
+       return 0;
+}
+EXPORT_SYMBOL_GPL(gsm_activate_mux);
+
+/**
+ *     gsm_free_mux            -       free up a mux
+ *     @mux: mux to free
+ *
+ *     Dispose of allocated resources for a dead mux. No refcounting
+ *     at present so the mux must be truely dead.
+ */
+void gsm_free_mux(struct gsm_mux *gsm)
+{
+       kfree(gsm->txframe);
+       kfree(gsm->buf);
+       kfree(gsm);
+}
+EXPORT_SYMBOL_GPL(gsm_free_mux);
+
+/**
+ *     gsm_alloc_mux           -       allocate a mux
+ *
+ *     Creates a new mux ready for activation.
+ */
+
+struct gsm_mux *gsm_alloc_mux(void)
+{
+       struct gsm_mux *gsm = kzalloc(sizeof(struct gsm_mux), GFP_KERNEL);
+       if (gsm == NULL)
+               return NULL;
+       gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL);
+       if (gsm->buf == NULL) {
+               kfree(gsm);
+               return NULL;
+       }
+       gsm->txframe = kmalloc(2 * MAX_MRU + 2, GFP_KERNEL);
+       if (gsm->txframe == NULL) {
+               kfree(gsm->buf);
+               kfree(gsm);
+               return NULL;
+       }
+       spin_lock_init(&gsm->lock);
+
+       gsm->t1 = T1;
+       gsm->t2 = T2;
+       gsm->n2 = N2;
+       gsm->ftype = UIH;
+       gsm->initiator = 0;
+       gsm->adaption = 1;
+       gsm->encoding = 1;
+       gsm->mru = 64;  /* Default to encoding 1 so these should be 64 */
+       gsm->mtu = 64;
+       gsm->dead = 1;  /* Avoid early tty opens */
+
+       return gsm;
+}
+EXPORT_SYMBOL_GPL(gsm_alloc_mux);
+
+
+
+
+/**
+ *     gsmld_output            -       write to link
+ *     @gsm: our mux
+ *     @data: bytes to output
+ *     @len: size
+ *
+ *     Write a block of data from the GSM mux to the data channel. This
+ *     will eventually be serialized from above but at the moment isn't.
+ */
+
+static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len)
+{
+       if (tty_write_room(gsm->tty) < len) {
+               set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags);
+               return -ENOSPC;
+       }
+       if (debug & 4) {
+               printk("-->%d bytes out\n", len);
+               hex_packet(data, len);
+       }
+       gsm->tty->ops->write(gsm->tty, data, len);
+       return len;
+}
+
+/**
+ *     gsmld_attach_gsm        -       mode set up
+ *     @tty: our tty structure
+ *     @gsm: our mux
+ *
+ *     Set up the MUX for basic mode and commence connecting to the
+ *     modem. Currently called from the line discipline set up but
+ *     will need moving to an ioctl path.
+ */
+
+static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
+{
+       int ret;
+
+       gsm->tty = tty_kref_get(tty);
+       gsm->output = gsmld_output;
+       ret =  gsm_activate_mux(gsm);
+       if (ret != 0)
+               tty_kref_put(gsm->tty);
+       return ret;
+}
+
+
+/**
+ *     gsmld_detach_gsm        -       stop doing 0710 mux
+ *     @tty: tty atttached to the mux
+ *     @gsm: mux
+ *
+ *     Shutdown and then clean up the resources used by the line discipline
+ */
+
+static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
+{
+       WARN_ON(tty != gsm->tty);
+       gsm_cleanup_mux(gsm);
+       tty_kref_put(gsm->tty);
+       gsm->tty = NULL;
+}
+
+static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
+                             char *fp, int count)
+{
+       struct gsm_mux *gsm = tty->disc_data;
+       const unsigned char *dp;
+       char *f;
+       int i;
+       char buf[64];
+       char flags;
+
+       if (debug & 4) {
+               printk("Inbytes %dd\n", count);
+               hex_packet(cp, count);
+       }
+
+       for (i = count, dp = cp, f = fp; i; i--, dp++) {
+               flags = *f++;
+               switch (flags) {
+               case TTY_NORMAL:
+                       gsm->receive(gsm, *dp);
+                       break;
+               case TTY_OVERRUN:
+               case TTY_BREAK:
+               case TTY_PARITY:
+               case TTY_FRAME:
+                       gsm->error(gsm, *dp, flags);
+                       break;
+               default:
+                       printk(KERN_ERR "%s: unknown flag %d\n",
+                              tty_name(tty, buf), flags);
+                       break;
+               }
+       }
+       /* FASYNC if needed ? */
+       /* If clogged call tty_throttle(tty); */
+}
+
+/**
+ *     gsmld_chars_in_buffer   -       report available bytes
+ *     @tty: tty device
+ *
+ *     Report the number of characters buffered to be delivered to user
+ *     at this instant in time.
+ *
+ *     Locking: gsm lock
+ */
+
+static ssize_t gsmld_chars_in_buffer(struct tty_struct *tty)
+{
+       return 0;
+}
+
+/**
+ *     gsmld_flush_buffer      -       clean input queue
+ *     @tty:   terminal device
+ *
+ *     Flush the input buffer. Called when the line discipline is
+ *     being closed, when the tty layer wants the buffer flushed (eg
+ *     at hangup).
+ */
+
+static void gsmld_flush_buffer(struct tty_struct *tty)
+{
+}
+
+/**
+ *     gsmld_close             -       close the ldisc for this tty
+ *     @tty: device
+ *
+ *     Called from the terminal layer when this line discipline is
+ *     being shut down, either because of a close or becsuse of a
+ *     discipline change. The function will not be called while other
+ *     ldisc methods are in progress.
+ */
+
+static void gsmld_close(struct tty_struct *tty)
+{
+       struct gsm_mux *gsm = tty->disc_data;
+
+       gsmld_detach_gsm(tty, gsm);
+
+       gsmld_flush_buffer(tty);
+       /* Do other clean up here */
+       gsm_free_mux(gsm);
+}
+
+/**
+ *     gsmld_open              -       open an ldisc
+ *     @tty: terminal to open
+ *
+ *     Called when this line discipline is being attached to the
+ *     terminal device. Can sleep. Called serialized so that no
+ *     other events will occur in parallel. No further open will occur
+ *     until a close.
+ */
+
+static int gsmld_open(struct tty_struct *tty)
+{
+       struct gsm_mux *gsm;
+
+       if (tty->ops->write == NULL)
+               return -EINVAL;
+
+       /* Attach our ldisc data */
+       gsm = gsm_alloc_mux();
+       if (gsm == NULL)
+               return -ENOMEM;
+
+       tty->disc_data = gsm;
+       tty->receive_room = 65536;
+
+       /* Attach the initial passive connection */
+       gsm->encoding = 1;
+       return gsmld_attach_gsm(tty, gsm);
+}
+
+/**
+ *     gsmld_write_wakeup      -       asynchronous I/O notifier
+ *     @tty: tty device
+ *
+ *     Required for the ptys, serial driver etc. since processes
+ *     that attach themselves to the master and rely on ASYNC
+ *     IO must be woken up
+ */
+
+static void gsmld_write_wakeup(struct tty_struct *tty)
+{
+       struct gsm_mux *gsm = tty->disc_data;
+
+       /* Queue poll */
+       clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+       gsm_data_kick(gsm);
+       if (gsm->tx_bytes < TX_THRESH_LO)
+               gsm_dlci_data_sweep(gsm);
+}
+
+/**
+ *     gsmld_read              -       read function for tty
+ *     @tty: tty device
+ *     @file: file object
+ *     @buf: userspace buffer pointer
+ *     @nr: size of I/O
+ *
+ *     Perform reads for the line discipline. We are guaranteed that the
+ *     line discipline will not be closed under us but we may get multiple
+ *     parallel readers and must handle this ourselves. We may also get
+ *     a hangup. Always called in user context, may sleep.
+ *
+ *     This code must be sure never to sleep through a hangup.
+ */
+
+static ssize_t gsmld_read(struct tty_struct *tty, struct file *file,
+                        unsigned char __user *buf, size_t nr)
+{
+       return -EOPNOTSUPP;
+}
+
+/**
+ *     gsmld_write             -       write function for tty
+ *     @tty: tty device
+ *     @file: file object
+ *     @buf: userspace buffer pointer
+ *     @nr: size of I/O
+ *
+ *     Called when the owner of the device wants to send a frame
+ *     itself (or some other control data). The data is transferred
+ *     as-is and must be properly framed and checksummed as appropriate
+ *     by userspace. Frames are either sent whole or not at all as this
+ *     avoids pain user side.
+ */
+
+static ssize_t gsmld_write(struct tty_struct *tty, struct file *file,
+                          const unsigned char *buf, size_t nr)
+{
+       int space = tty_write_room(tty);
+       if (space >= nr)
+               return tty->ops->write(tty, buf, nr);
+       set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+       return -ENOBUFS;
+}
+
+/**
+ *     gsmld_poll              -       poll method for N_GSM0710
+ *     @tty: terminal device
+ *     @file: file accessing it
+ *     @wait: poll table
+ *
+ *     Called when the line discipline is asked to poll() for data or
+ *     for special events. This code is not serialized with respect to
+ *     other events save open/close.
+ *
+ *     This code must be sure never to sleep through a hangup.
+ *     Called without the kernel lock held - fine
+ */
+
+static unsigned int gsmld_poll(struct tty_struct *tty, struct file *file,
+                                                       poll_table *wait)
+{
+       unsigned int mask = 0;
+       struct gsm_mux *gsm = tty->disc_data;
+
+       poll_wait(file, &tty->read_wait, wait);
+       poll_wait(file, &tty->write_wait, wait);
+       if (tty_hung_up_p(file))
+               mask |= POLLHUP;
+       if (!tty_is_writelocked(tty) && tty_write_room(tty) > 0)
+               mask |= POLLOUT | POLLWRNORM;
+       if (gsm->dead)
+               mask |= POLLHUP;
+       return mask;
+}
+
+static int gsmld_config(struct tty_struct *tty, struct gsm_mux *gsm,
+                                                       struct gsm_config *c)
+{
+       int need_close = 0;
+       int need_restart = 0;
+
+       /* Stuff we don't support yet - UI or I frame transport, windowing */
+       if ((c->adaption !=1 && c->adaption != 2) || c->k)
+               return -EOPNOTSUPP;
+       /* Check the MRU/MTU range looks sane */
+       if (c->mru > MAX_MRU || c->mtu > MAX_MTU || c->mru < 8 || c->mtu < 8)
+               return -EINVAL;
+       if (c->n2 < 3)
+               return -EINVAL;
+       if (c->encapsulation > 1)       /* Basic, advanced, no I */
+               return -EINVAL;
+       if (c->initiator > 1)
+               return -EINVAL;
+       if (c->i == 0 || c->i > 2)      /* UIH and UI only */
+               return -EINVAL;
+       /*
+        *      See what is needed for reconfiguration
+        */
+
+       /* Timing fields */
+       if (c->t1 != 0 && c->t1 != gsm->t1)
+               need_restart = 1;
+       if (c->t2 != 0 && c->t2 != gsm->t2)
+               need_restart = 1;
+       if (c->encapsulation != gsm->encoding)
+               need_restart = 1;
+       if (c->adaption != gsm->adaption)
+               need_restart = 1;
+       /* Requires care */
+       if (c->initiator != gsm->initiator)
+               need_close = 1;
+       if (c->mru != gsm->mru)
+               need_restart = 1;
+       if (c->mtu != gsm->mtu)
+               need_restart = 1;
+
+       /*
+        *      Close down what is needed, restart and initiate the new
+        *      configuration
+        */
+
+       if (need_close || need_restart) {
+               gsm_dlci_begin_close(gsm->dlci[0]);
+               /* This will timeout if the link is down due to N2 expiring */
+               wait_event_interruptible(gsm->event,
+                               gsm->dlci[0]->state == DLCI_CLOSED);
+               if (signal_pending(current))
+                       return -EINTR;
+       }
+       if (need_restart)
+               gsm_cleanup_mux(gsm);
+
+       gsm->initiator = c->initiator;
+       gsm->mru = c->mru;
+       gsm->encoding = c->encapsulation;
+       gsm->adaption = c->adaption;
+
+       if (c->i == 1)
+               gsm->ftype = UIH;
+       else if (c->i == 2)
+               gsm->ftype = UI;
+
+       if (c->t1)
+               gsm->t1 = c->t1;
+       if (c->t2)
+               gsm->t2 = c->t2;
+
+       /* FIXME: We need to separate activation/deactivation from adding
+          and removing from the mux array */
+       if (need_restart)
+               gsm_activate_mux(gsm);
+       if (gsm->initiator && need_close)
+               gsm_dlci_begin_open(gsm->dlci[0]);
+       return 0;
+}
+
+static int gsmld_ioctl(struct tty_struct *tty, struct file *file,
+                      unsigned int cmd, unsigned long arg)
+{
+       struct gsm_config c;
+       struct gsm_mux *gsm = tty->disc_data;
+
+       switch (cmd) {
+       case GSMIOC_GETCONF:
+               memset(&c, 0, sizeof(c));
+               c.adaption = gsm->adaption;
+               c.encapsulation = gsm->encoding;
+               c.initiator = gsm->initiator;
+               c.t1 = gsm->t1;
+               c.t2 = gsm->t2;
+               c.t3 = 0;       /* Not supported */
+               c.n2 = gsm->n2;
+               if (gsm->ftype == UIH)
+                       c.i = 1;
+               else
+                       c.i = 2;
+               printk("Ftype %d i %d\n", gsm->ftype, c.i);
+               c.mru = gsm->mru;
+               c.mtu = gsm->mtu;
+               c.k = 0;
+               if (copy_to_user((void *)arg, &c, sizeof(c)))
+                       return -EFAULT;
+               return 0;
+       case GSMIOC_SETCONF:
+               if (copy_from_user(&c, (void *)arg, sizeof(c)))
+                       return -EFAULT;
+               return gsmld_config(tty, gsm, &c);
+       default:
+               return n_tty_ioctl_helper(tty, file, cmd, arg);
+       }
+}
+
+
+/* Line discipline for real tty */
+struct tty_ldisc_ops tty_ldisc_packet = {
+       .owner           = THIS_MODULE,
+       .magic           = TTY_LDISC_MAGIC,
+       .name            = "n_gsm",
+       .open            = gsmld_open,
+       .close           = gsmld_close,
+       .flush_buffer    = gsmld_flush_buffer,
+       .chars_in_buffer = gsmld_chars_in_buffer,
+       .read            = gsmld_read,
+       .write           = gsmld_write,
+       .ioctl           = gsmld_ioctl,
+       .poll            = gsmld_poll,
+       .receive_buf     = gsmld_receive_buf,
+       .write_wakeup    = gsmld_write_wakeup
+};
+
+/*
+ *     Virtual tty side
+ */
+
+#define TX_SIZE                512
+
+static int gsmtty_modem_update(struct gsm_dlci *dlci, u8 brk)
+{
+       u8 modembits[5];
+       struct gsm_control *ctrl;
+       int len = 2;
+
+       if (brk)
+               len++;
+
+       modembits[0] = len << 1 | EA;           /* Data bytes */
+       modembits[1] = dlci->addr << 2 | 3;     /* DLCI, EA, 1 */
+       modembits[2] = gsm_encode_modem(dlci) << 1 | EA;
+       if (brk)
+               modembits[3] = brk << 4 | 2 | EA;       /* Valid, EA */
+       ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len + 1);
+       if (ctrl == NULL)
+               return -ENOMEM;
+       return gsm_control_wait(dlci->gsm, ctrl);
+}
+
+static int gsm_carrier_raised(struct tty_port *port)
+{
+       struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port);
+       /* Not yet open so no carrier info */
+       if (dlci->state != DLCI_OPEN)
+               return 0;
+       if (debug & 2)
+               return 1;
+       return dlci->modem_rx & TIOCM_CD;
+}
+
+static void gsm_dtr_rts(struct tty_port *port, int onoff)
+{
+       struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port);
+       unsigned int modem_tx = dlci->modem_tx;
+       if (onoff)
+               modem_tx |= TIOCM_DTR | TIOCM_RTS;
+       else
+               modem_tx &= ~(TIOCM_DTR | TIOCM_RTS);
+       if (modem_tx != dlci->modem_tx) {
+               dlci->modem_tx = modem_tx;
+               gsmtty_modem_update(dlci, 0);
+       }
+}
+
+static const struct tty_port_operations gsm_port_ops = {
+       .carrier_raised = gsm_carrier_raised,
+       .dtr_rts = gsm_dtr_rts,
+};
+
+
+static int gsmtty_open(struct tty_struct *tty, struct file *filp)
+{
+       struct gsm_mux *gsm;
+       struct gsm_dlci *dlci;
+       struct tty_port *port;
+       unsigned int line = tty->index;
+       unsigned int mux = line >> 6;
+
+       line = line & 0x3F;
+
+       if (mux >= MAX_MUX)
+               return -ENXIO;
+       /* FIXME: we need to lock gsm_mux for lifetimes of ttys eventually */
+       if (gsm_mux[mux] == NULL)
+               return -EUNATCH;
+       if (line == 0 || line > 61)     /* 62/63 reserved */
+               return -ECHRNG;
+       gsm = gsm_mux[mux];
+       if (gsm->dead)
+               return -EL2HLT;
+       dlci = gsm->dlci[line];
+       if (dlci == NULL)
+               dlci = gsm_dlci_alloc(gsm, line);
+       if (dlci == NULL)
+               return -ENOMEM;
+       port = &dlci->port;
+       port->count++;
+       tty->driver_data = dlci;
+       tty_port_tty_set(port, tty);
+
+       dlci->modem_rx = 0;
+       /* We could in theory open and close before we wait - eg if we get
+          a DM straight back. This is ok as that will have caused a hangup */
+       set_bit(ASYNCB_INITIALIZED, &port->flags);
+       /* Start sending off SABM messages */
+       gsm_dlci_begin_open(dlci);
+       /* And wait for virtual carrier */
+       return tty_port_block_til_ready(port, tty, filp);
+}
+
+static void gsmtty_close(struct tty_struct *tty, struct file *filp)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       if (dlci == NULL)
+               return;
+       if (tty_port_close_start(&dlci->port, tty, filp) == 0)
+               return;
+       gsm_dlci_begin_close(dlci);
+       tty_port_close_end(&dlci->port, tty);
+       tty_port_tty_set(&dlci->port, NULL);
+}
+
+static void gsmtty_hangup(struct tty_struct *tty)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       tty_port_hangup(&dlci->port);
+       gsm_dlci_begin_close(dlci);
+}
+
+static int gsmtty_write(struct tty_struct *tty, const unsigned char *buf,
+                                                                   int len)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       /* Stuff the bytes into the fifo queue */
+       int sent = kfifo_in_locked(dlci->fifo, buf, len, &dlci->lock);
+       /* Need to kick the channel */
+       gsm_dlci_data_kick(dlci);
+       return sent;
+}
+
+static int gsmtty_write_room(struct tty_struct *tty)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       return TX_SIZE - kfifo_len(dlci->fifo);
+}
+
+static int gsmtty_chars_in_buffer(struct tty_struct *tty)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       return kfifo_len(dlci->fifo);
+}
+
+static void gsmtty_flush_buffer(struct tty_struct *tty)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       /* Caution needed: If we implement reliable transport classes
+          then the data being transmitted can't simply be junked once
+          it has first hit the stack. Until then we can just blow it
+          away */
+       kfifo_reset(dlci->fifo);
+       /* Need to unhook this DLCI from the transmit queue logic */
+}
+
+static void gsmtty_wait_until_sent(struct tty_struct *tty, int timeout)
+{
+       /* The FIFO handles the queue so the kernel will do the right
+          thing waiting on chars_in_buffer before calling us. No work
+          to do here */
+}
+
+static int gsmtty_tiocmget(struct tty_struct *tty, struct file *filp)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       return dlci->modem_rx;
+}
+
+static int gsmtty_tiocmset(struct tty_struct *tty, struct file *filp,
+       unsigned int set, unsigned int clear)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       unsigned int modem_tx = dlci->modem_tx;
+
+       modem_tx &= clear;
+       modem_tx |= set;
+
+       if (modem_tx != dlci->modem_tx) {
+               dlci->modem_tx = modem_tx;
+               return gsmtty_modem_update(dlci, 0);
+       }
+       return 0;
+}
+
+
+static int gsmtty_ioctl(struct tty_struct *tty, struct file *filp,
+                       unsigned int cmd, unsigned long arg)
+{
+       return -ENOIOCTLCMD;
+}
+
+static void gsmtty_set_termios(struct tty_struct *tty, struct ktermios *old)
+{
+       /* For the moment its fixed. In actual fact the speed information
+          for the virtual channel can be propogated in both directions by
+          the RPN control message. This however rapidly gets nasty as we
+          then have to remap modem signals each way according to whether
+          our virtual cable is null modem etc .. */
+       tty_termios_copy_hw(tty->termios, old);
+}
+
+static void gsmtty_throttle(struct tty_struct *tty)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       if (tty->termios->c_cflag & CRTSCTS)
+               dlci->modem_tx &= ~TIOCM_DTR;
+       dlci->throttled = 1;
+       /* Send an MSC with DTR cleared */
+       gsmtty_modem_update(dlci, 0);
+}
+
+static void gsmtty_unthrottle(struct tty_struct *tty)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       if (tty->termios->c_cflag & CRTSCTS)
+               dlci->modem_tx |= TIOCM_DTR;
+       dlci->throttled = 0;
+       /* Send an MSC with DTR set */
+       gsmtty_modem_update(dlci, 0);
+}
+
+static int gsmtty_break_ctl(struct tty_struct *tty, int state)
+{
+       struct gsm_dlci *dlci = tty->driver_data;
+       int encode = 0; /* Off */
+
+       if (state == -1)        /* "On indefinitely" - we can't encode this
+                                   properly */
+               encode = 0x0F;
+       else if (state > 0) {
+               encode = state / 200;   /* mS to encoding */
+               if (encode > 0x0F)
+                       encode = 0x0F;  /* Best effort */
+       }
+       return gsmtty_modem_update(dlci, encode);
+}
+
+static struct tty_driver *gsm_tty_driver;
+
+/* Virtual ttys for the demux */
+static const struct tty_operations gsmtty_ops = {
+       .open                   = gsmtty_open,
+       .close                  = gsmtty_close,
+       .write                  = gsmtty_write,
+       .write_room             = gsmtty_write_room,
+       .chars_in_buffer        = gsmtty_chars_in_buffer,
+       .flush_buffer           = gsmtty_flush_buffer,
+       .ioctl                  = gsmtty_ioctl,
+       .throttle               = gsmtty_throttle,
+       .unthrottle             = gsmtty_unthrottle,
+       .set_termios            = gsmtty_set_termios,
+       .hangup                 = gsmtty_hangup,
+       .wait_until_sent        = gsmtty_wait_until_sent,
+       .tiocmget               = gsmtty_tiocmget,
+       .tiocmset               = gsmtty_tiocmset,
+       .break_ctl              = gsmtty_break_ctl,
+};
+
+
+
+static int __init gsm_init(void)
+{
+       /* Fill in our line protocol discipline, and register it */
+       int status = tty_register_ldisc(N_GSM0710, &tty_ldisc_packet);
+       if (status != 0) {
+               printk(KERN_ERR "n_gsm: can't register line discipline (err = %d)\n", status);
+               return status;
+       }
+
+       gsm_tty_driver = alloc_tty_driver(256);
+       if (!gsm_tty_driver) {
+               tty_unregister_ldisc(N_GSM0710);
+               printk(KERN_ERR "gsm_init: tty allocation failed.\n");
+               return -EINVAL;
+       }
+       gsm_tty_driver->owner   = THIS_MODULE;
+       gsm_tty_driver->driver_name     = "gsmtty";
+       gsm_tty_driver->name            = "gsmtty";
+       gsm_tty_driver->major           = 0;    /* Dynamic */
+       gsm_tty_driver->minor_start     = 0;
+       gsm_tty_driver->type            = TTY_DRIVER_TYPE_SERIAL;
+       gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL;
+       gsm_tty_driver->flags   = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV
+                                                       | TTY_DRIVER_HARDWARE_BREAK;
+       gsm_tty_driver->init_termios    = tty_std_termios;
+       /* Fixme */
+       gsm_tty_driver->init_termios.c_lflag &= ~ECHO;
+       tty_set_operations(gsm_tty_driver, &gsmtty_ops);
+
+       spin_lock_init(&gsm_mux_lock);
+
+       if (tty_register_driver(gsm_tty_driver)) {
+               put_tty_driver(gsm_tty_driver);
+               tty_unregister_ldisc(N_GSM0710);
+               printk(KERN_ERR "gsm_init: tty registration failed.\n");
+               return -EBUSY;
+       }
+       printk(KERN_INFO "gsm_init: loaded as %d,%d.\n", gsm_tty_driver->major, gsm_tty_driver->minor_start);
+       return 0;
+}
+
+static void __exit gsm_exit(void)
+{
+       int status = tty_unregister_ldisc(N_GSM0710);
+       if (status != 0)
+               printk(KERN_ERR "n_gsm: can't unregister line discipline (err = %d)\n", status);
+       tty_unregister_driver(gsm_tty_driver);
+       put_tty_driver(gsm_tty_driver);
+       printk(KERN_INFO "gsm_init: unloaded.\n");
+}
+
+module_init(gsm_init);
+module_exit(gsm_exit);
+
+
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_LDISC(N_GSM0710);
index 78a62eb..ecbe479 100644 (file)
@@ -176,23 +176,6 @@ static void config_setup(struct cyclades_port *);
 static void show_status(int);
 #endif
 
-#ifdef CONFIG_REMOTE_DEBUG
-static void debug_setup(void);
-void queueDebugChar(int c);
-int getDebugChar(void);
-
-#define DEBUG_PORT     1
-#define DEBUG_LEN      256
-
-typedef struct {
-       int in;
-       int out;
-       unsigned char buf[DEBUG_LEN];
-} debugq;
-
-debugq debugiq;
-#endif
-
 /*
  * I have my own version of udelay(), as it is needed when initialising
  * the chip, before the delay loop has been calibrated.  Should probably
@@ -515,11 +498,6 @@ static irqreturn_t cd2401_tx_interrupt(int irq, void *dev_id)
        /* determine the channel and change to that context */
        channel = (u_short) (base_addr[CyLICR] >> 2);
 
-#ifdef CONFIG_REMOTE_DEBUG
-       if (channel == DEBUG_PORT) {
-               panic("TxInt on debug port!!!");
-       }
-#endif
        /* validate the port number (as configured and open) */
        if ((channel < 0) || (NR_PORTS <= channel)) {
                base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
@@ -634,14 +612,6 @@ static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id)
        info->last_active = jiffies;
        save_cnt = char_count = base_addr[CyRFOC];
 
-#ifdef CONFIG_REMOTE_DEBUG
-       if (channel == DEBUG_PORT) {
-               while (char_count--) {
-                       data = base_addr[CyRDR];
-                       queueDebugChar(data);
-               }
-       } else
-#endif
                /* if there is nowhere to put the data, discard it */
        if (info->tty == 0) {
                while (char_count--) {
@@ -2195,9 +2165,7 @@ static int __init serial167_init(void)
                port_num++;
                info++;
        }
-#ifdef CONFIG_REMOTE_DEBUG
-       debug_setup();
-#endif
+
        ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
                          "cd2401_errors", cd2401_rxerr_interrupt);
        if (ret) {
@@ -2518,193 +2486,4 @@ static int __init serial167_console_init(void)
 
 console_initcall(serial167_console_init);
 
-#ifdef CONFIG_REMOTE_DEBUG
-void putDebugChar(int c)
-{
-       volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
-       unsigned long flags;
-       volatile u_char sink;
-       u_char ier;
-       int port;
-
-       local_irq_save(flags);
-
-       /* Ensure transmitter is enabled! */
-
-       port = DEBUG_PORT;
-       base_addr[CyCAR] = (u_char) port;
-       while (base_addr[CyCCR])
-               ;
-       base_addr[CyCCR] = CyENB_XMTR;
-
-       ier = base_addr[CyIER];
-       base_addr[CyIER] = CyTxMpty;
-
-       while (1) {
-               if (pcc2chip[PccSCCTICR] & 0x20) {
-                       /* We have a Tx int. Acknowledge it */
-                       sink = pcc2chip[PccTPIACKR];
-                       if ((base_addr[CyLICR] >> 2) == port) {
-                               base_addr[CyTDR] = c;
-                               base_addr[CyTEOIR] = 0;
-                               break;
-                       } else
-                               base_addr[CyTEOIR] = CyNOTRANS;
-               }
-       }
-
-       base_addr[CyIER] = ier;
-
-       local_irq_restore(flags);
-}
-
-int getDebugChar()
-{
-       volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
-       unsigned long flags;
-       volatile u_char sink;
-       u_char ier;
-       int port;
-       int i, c;
-
-       i = debugiq.out;
-       if (i != debugiq.in) {
-               c = debugiq.buf[i];
-               if (++i == DEBUG_LEN)
-                       i = 0;
-               debugiq.out = i;
-               return c;
-       }
-       /* OK, nothing in queue, wait in poll loop */
-
-       local_irq_save(flags);
-
-       /* Ensure receiver is enabled! */
-
-       port = DEBUG_PORT;
-       base_addr[CyCAR] = (u_char) port;
-#if 0
-       while (base_addr[CyCCR])
-               ;
-       base_addr[CyCCR] = CyENB_RCVR;
-#endif
-       ier = base_addr[CyIER];
-       base_addr[CyIER] = CyRxData;
-
-       while (1) {
-               if (pcc2chip[PccSCCRICR] & 0x20) {
-                       /* We have a Rx int. Acknowledge it */
-                       sink = pcc2chip[PccRPIACKR];
-                       if ((base_addr[CyLICR] >> 2) == port) {
-                               int cnt = base_addr[CyRFOC];
-                               while (cnt-- > 0) {
-                                       c = base_addr[CyRDR];
-                                       if (c == 0)
-                                               printk
-                                                   ("!! debug char is null (cnt=%d) !!",
-                                                    cnt);
-                                       else
-                                               queueDebugChar(c);
-                               }
-                               base_addr[CyREOIR] = 0;
-                               i = debugiq.out;
-                               if (i == debugiq.in)
-                                       panic("Debug input queue empty!");
-                               c = debugiq.buf[i];
-                               if (++i == DEBUG_LEN)
-                                       i = 0;
-                               debugiq.out = i;
-                               break;
-                       } else
-                               base_addr[CyREOIR] = CyNOTRANS;
-               }
-       }
-
-       base_addr[CyIER] = ier;
-
-       local_irq_restore(flags);
-
-       return (c);
-}
-
-void queueDebugChar(int c)
-{
-       int i;
-
-       i = debugiq.in;
-       debugiq.buf[i] = c;
-       if (++i == DEBUG_LEN)
-               i = 0;
-       if (i != debugiq.out)
-               debugiq.in = i;
-}
-
-static void debug_setup()
-{
-       unsigned long flags;
-       volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
-       int i, cflag;
-
-       cflag = B19200;
-
-       local_irq_save(flags);
-
-       for (i = 0; i < 4; i++) {
-               base_addr[CyCAR] = i;
-               base_addr[CyLICR] = i << 2;
-       }
-
-       debugiq.in = debugiq.out = 0;
-
-       base_addr[CyCAR] = DEBUG_PORT;
-
-       /* baud rate */
-       i = cflag & CBAUD;
-
-       base_addr[CyIER] = 0;
-
-       base_addr[CyCMR] = CyASYNC;
-       base_addr[CyLICR] = DEBUG_PORT << 2;
-       base_addr[CyLIVR] = 0x5c;
-
-       /* tx and rx baud rate */
-
-       base_addr[CyTCOR] = baud_co[i];
-       base_addr[CyTBPR] = baud_bpr[i];
-       base_addr[CyRCOR] = baud_co[i] >> 5;
-       base_addr[CyRBPR] = baud_bpr[i];
-
-       /* set line characteristics  according configuration */
-
-       base_addr[CySCHR1] = 0;
-       base_addr[CySCHR2] = 0;
-       base_addr[CySCRL] = 0;
-       base_addr[CySCRH] = 0;
-       base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
-       base_addr[CyCOR2] = 0;
-       base_addr[CyCOR3] = Cy_1_STOP;
-       base_addr[CyCOR4] = baud_cor4[i];
-       base_addr[CyCOR5] = 0;
-       base_addr[CyCOR6] = 0;
-       base_addr[CyCOR7] = 0;
-
-       write_cy_cmd(base_addr, CyINIT_CHAN);
-       write_cy_cmd(base_addr, CyENB_RCVR);
-
-       base_addr[CyCAR] = DEBUG_PORT;  /* !!! Is this needed? */
-
-       base_addr[CyRTPRL] = 2;
-       base_addr[CyRTPRH] = 0;
-
-       base_addr[CyMSVR1] = CyRTS;
-       base_addr[CyMSVR2] = CyDTR;
-
-       base_addr[CyIER] = CyRxData;
-
-       local_irq_restore(flags);
-
-}                              /* debug_setup */
-
-#endif
-
 MODULE_LICENSE("GPL");
index 7ee5216..cc1e985 100644 (file)
@@ -238,7 +238,7 @@ EXPORT_SYMBOL_GPL(tty_buffer_request_room);
  *     @size: size
  *
  *     Queue a series of bytes to the tty buffering. All the characters
- *     passed are marked as without error. Returns the number added.
+ *     passed are marked with the supplied flag. Returns the number added.
  *
  *     Locking: Called functions may take tty->buf.lock
  */
index fb09bb3..aa9bc9e 100644 (file)
@@ -149,7 +149,7 @@ static ssize_t smi_data_buf_size_store(struct device *dev,
        return count;
 }
 
-static ssize_t smi_data_read(struct kobject *kobj,
+static ssize_t smi_data_read(struct file *filp, struct kobject *kobj,
                             struct bin_attribute *bin_attr,
                             char *buf, loff_t pos, size_t count)
 {
@@ -162,7 +162,7 @@ static ssize_t smi_data_read(struct kobject *kobj,
        return ret;
 }
 
-static ssize_t smi_data_write(struct kobject *kobj,
+static ssize_t smi_data_write(struct file *filp, struct kobject *kobj,
                              struct bin_attribute *bin_attr,
                              char *buf, loff_t pos, size_t count)
 {
index 3a44602..2f452f1 100644 (file)
@@ -522,7 +522,7 @@ static ssize_t read_rbu_mono_data(char *buffer, loff_t pos, size_t count)
                        rbu_data.image_update_buffer, rbu_data.bios_image_size);
 }
 
-static ssize_t read_rbu_data(struct kobject *kobj,
+static ssize_t read_rbu_data(struct file *filp, struct kobject *kobj,
                             struct bin_attribute *bin_attr,
                             char *buffer, loff_t pos, size_t count)
 {
@@ -576,7 +576,7 @@ static void callbackfn_rbu(const struct firmware *fw, void *context)
        release_firmware(fw);
 }
 
-static ssize_t read_rbu_image_type(struct kobject *kobj,
+static ssize_t read_rbu_image_type(struct file *filp, struct kobject *kobj,
                                   struct bin_attribute *bin_attr,
                                   char *buffer, loff_t pos, size_t count)
 {
@@ -586,7 +586,7 @@ static ssize_t read_rbu_image_type(struct kobject *kobj,
        return size;
 }
 
-static ssize_t write_rbu_image_type(struct kobject *kobj,
+static ssize_t write_rbu_image_type(struct file *filp, struct kobject *kobj,
                                    struct bin_attribute *bin_attr,
                                    char *buffer, loff_t pos, size_t count)
 {
@@ -647,7 +647,7 @@ static ssize_t write_rbu_image_type(struct kobject *kobj,
        return rc;
 }
 
-static ssize_t read_rbu_packet_size(struct kobject *kobj,
+static ssize_t read_rbu_packet_size(struct file *filp, struct kobject *kobj,
                                    struct bin_attribute *bin_attr,
                                    char *buffer, loff_t pos, size_t count)
 {
@@ -660,7 +660,7 @@ static ssize_t read_rbu_packet_size(struct kobject *kobj,
        return size;
 }
 
-static ssize_t write_rbu_packet_size(struct kobject *kobj,
+static ssize_t write_rbu_packet_size(struct file *filp, struct kobject *kobj,
                                     struct bin_attribute *bin_attr,
                                     char *buffer, loff_t pos, size_t count)
 {
index 81b70bd..2a62ec6 100644 (file)
@@ -402,7 +402,7 @@ efivar_unregister(struct efivar_entry *var)
 }
 
 
-static ssize_t efivar_create(struct kobject *kobj,
+static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
                             struct bin_attribute *bin_attr,
                             char *buf, loff_t pos, size_t count)
 {
@@ -461,7 +461,7 @@ static ssize_t efivar_create(struct kobject *kobj,
        return count;
 }
 
-static ssize_t efivar_delete(struct kobject *kobj,
+static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
                             struct bin_attribute *bin_attr,
                             char *buf, loff_t pos, size_t count)
 {
index eb0c3fe..cae1b8c 100644 (file)
@@ -399,7 +399,7 @@ static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev,
                        goto free_id;
                }
 
-               pdesc->value_sd = sysfs_get_dirent(dev->kobj.sd, "value");
+               pdesc->value_sd = sysfs_get_dirent(dev->kobj.sd, NULL, "value");
                if (!pdesc->value_sd) {
                        ret = -ENODEV;
                        goto free_id;
index 25bbd30..387166d 100644 (file)
@@ -193,8 +193,9 @@ static ssize_t enabled_show(struct device *device,
                        "disabled");
 }
 
-static ssize_t edid_show(struct kobject *kobj, struct bin_attribute *attr,
-                        char *buf, loff_t off, size_t count)
+static ssize_t edid_show(struct file *filp, struct kobject *kobj,
+                        struct bin_attribute *attr, char *buf, loff_t off,
+                        size_t count)
 {
        struct device *connector_dev = container_of(kobj, struct device, kobj);
        struct drm_connector *connector = to_drm_connector(connector_dev);
index 26ac8aa..f084249 100644 (file)
@@ -1678,9 +1678,9 @@ int bitmap_create(mddev_t *mddev)
 
        bitmap->mddev = mddev;
 
-       bm = sysfs_get_dirent(mddev->kobj.sd, "bitmap");
+       bm = sysfs_get_dirent(mddev->kobj.sd, NULL, "bitmap");
        if (bm) {
-               bitmap->sysfs_can_clear = sysfs_get_dirent(bm, "can_clear");
+               bitmap->sysfs_can_clear = sysfs_get_dirent(bm, NULL, "can_clear");
                sysfs_put(bm);
        } else
                bitmap->sysfs_can_clear = NULL;