From 8f9b2d33051833a3d13f91dae3715caa9f3d4516 Mon Sep 17 00:00:00 2001 From: "Luis R. Rodriguez" Date: Fri, 30 Nov 2012 13:47:15 -0800 Subject: [PATCH] compat-drivers: add support for unified drivers Companies typically write Linux device drivers either from scratch of alternatively based on some internal unified source code tree. Typically the unified driver architecture is a mess and porting a driver to linux is always a painful task to the extent at times a full rewrite is required and at times preferred. In order to try to help with these type of unified driver strategies one possibility that has been proposed is to make the unified driver strategy an open source project and to not make many compromises on the style and requirements for Linux. The alx Linux driver [1] is not yet upstream and is undergoing changes to try to accomodate it to a format and use new technologies to help address unification attempts in both an open manner and also lead by the community. compat-drivers will support these type of driver efforts only if they adhere to the principles of never compromising Linux upstream requirements and are targetting getting upstream into the Linux kernel. Once these drivers are upstream, their respective git trees will be removed and we'll simply cherry pick the driver as we do from upstream Linux. If a compat-drivers releases contains drivers that are from a unified git repository the release will be postfixed with a "-u". [1] http://www.linuxfoundation.org/collaborate/workgroups/networking/alx Cc: Julia Lawall Cc: Adrian Chadd Signed-off-by: Luis R. Rodriguez --- Makefile | 1 + config.mk | 1 + patches/unified-drivers/README.md | 17 +++ .../network/0001-backport-alx.patch | 130 ++++++++++++++++++ .../network/0002-enable-alx.patch | 9 ++ scripts/admin-update.sh | 110 ++++++++++++++- scripts/driver-select | 9 +- scripts/unload.sh | 2 +- 8 files changed, 274 insertions(+), 5 deletions(-) create mode 100644 patches/unified-drivers/README.md create mode 100644 patches/unified-drivers/network/0001-backport-alx.patch create mode 100644 patches/unified-drivers/network/0002-enable-alx.patch diff --git a/Makefile b/Makefile index 7a5a54aa156f..e986a0915153 100644 --- a/Makefile +++ b/Makefile @@ -230,6 +230,7 @@ uninstall: @rm -rf $(KLIB)/$(KMODDIR)/drivers/net/wireless/ @rm -rf $(KLIB)/$(KMODDIR)/drivers/staging/ @rm -rf $(KLIB)/$(KMODDIR)/drivers/net/atl* + @find $(KLIB)/$(KMODDIR)/drivers/net/ -name "alx*.ko" -o -name "atl*.ko" 2>/dev/null |xargs rm -f @# Lets only remove the stuff we are sure we are providing @# on the misc directory. @rm -f $(KLIB)/$(KMODDIR)/drivers/misc/eeprom/eeprom_93cx6.ko* diff --git a/config.mk b/config.mk index 8513142fe9f9..2aefc40c040e 100644 --- a/config.mk +++ b/config.mk @@ -412,6 +412,7 @@ export CONFIG_ATL2=m export CONFIG_ATL1E=m ifndef CONFIG_COMPAT_KERNEL_2_6_28 export CONFIG_ATL1C=m +export CONFIG_ALX=m endif #CONFIG_COMPAT_KERNEL_2_6_28 ifdef CONFIG_WIRELESS_EXT diff --git a/patches/unified-drivers/README.md b/patches/unified-drivers/README.md new file mode 100644 index 000000000000..1f606908f0cb --- /dev/null +++ b/patches/unified-drivers/README.md @@ -0,0 +1,17 @@ +# compat-driver unified driver backport patches + +compat-drivers supports developers to supply a unified +driver git tree which is being used to target support +for getting the driver in line with requirements for +linux-next. Once the driver gets upstream the driver +gets removed and we cherry pick updated version of the +driver directly from linux upstream. + +The code provided on this tree must try to adhere to +conventions for targetting inclusion into linux-next. +The compat-drivers patches/unified-drivers/ directory +allows for any additional required backport delta to +be addressed for the supplied driver. This allows +development and transformation of the driver to always +be targetting linux-next and allows for backporting +to be dealt with separately. diff --git a/patches/unified-drivers/network/0001-backport-alx.patch b/patches/unified-drivers/network/0001-backport-alx.patch new file mode 100644 index 000000000000..b1aadc98f6d1 --- /dev/null +++ b/patches/unified-drivers/network/0001-backport-alx.patch @@ -0,0 +1,130 @@ +This should go into patches/01-netdev.patch + +--- a/drivers/net/ethernet/atheros/alx/alx_main.c ++++ b/drivers/net/ethernet/atheros/alx/alx_main.c +@@ -102,7 +102,11 @@ static void __alx_set_rx_mode(struct net_device *netdev) + + /* comoute mc addresses' hash value ,and put it into hash table */ + netdev_for_each_mc_addr(ha, netdev) ++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) + alx_add_mc_addr(adpt, ha->addr); ++#else ++ alx_add_mc_addr(adpt, ha->dmi_addr); ++#endif + + ALX_MEM_W32(adpt, ALX_HASH_TBL0, adpt->mc_hash[0]); + ALX_MEM_W32(adpt, ALX_HASH_TBL1, adpt->mc_hash[1]); +@@ -133,8 +137,10 @@ static int alx_set_mac_address(struct net_device *netdev, void *data) + if (!is_valid_ether_addr(addr->sa_data)) + return -EADDRNOTAVAIL; + ++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)) + if (netdev->addr_assign_type & NET_ADDR_RANDOM) + netdev->addr_assign_type ^= NET_ADDR_RANDOM; ++#endif + + memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); + memcpy(adpt->mac_addr, addr->sa_data, netdev->addr_len); +@@ -1130,6 +1136,7 @@ static int __devinit alx_init_sw(struct alx_adapter *adpt) + return err; + } + ++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) + static netdev_features_t alx_fix_features(struct net_device *netdev, + netdev_features_t features) + { +@@ -1167,6 +1174,7 @@ static int alx_set_features(struct net_device *netdev, + + return 0; + } ++#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) */ + + /* alx_change_mtu - Change the Maximum Transfer Unit */ + static int alx_change_mtu(struct net_device *netdev, int new_mtu) +@@ -1188,7 +1196,17 @@ static int alx_change_mtu(struct net_device *netdev, int new_mtu) + netdev->mtu = new_mtu; + adpt->rxbuf_size = new_mtu > ALX_DEF_RXBUF_SIZE ? + ALIGN(max_frame, 8) : ALX_DEF_RXBUF_SIZE; ++#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)) ++ if (new_mtu > (7*1024)) { ++ netdev->features &= ~NETIF_F_TSO; ++ netdev->features &= ~NETIF_F_TSO6; ++ } else { ++ netdev->features |= NETIF_F_TSO; ++ netdev->features |= NETIF_F_TSO6; ++ } ++#else + netdev_update_features(netdev); ++#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)) */ + alx_reinit(adpt); + } + +@@ -2476,8 +2494,10 @@ static const struct net_device_ops alx_netdev_ops = { + .ndo_change_mtu = alx_change_mtu, + .ndo_do_ioctl = alx_ioctl, + .ndo_tx_timeout = alx_tx_timeout, ++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) + .ndo_fix_features = alx_fix_features, + .ndo_set_features = alx_set_features, ++#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) */ + #ifdef CONFIG_NET_POLL_CONTROLLER + .ndo_poll_controller = alx_poll_controller, + #endif +@@ -2571,7 +2591,7 @@ alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) + goto err_iomap; + } + +- netdev->netdev_ops = &alx_netdev_ops; ++ netdev_attach_ops(netdev, &alx_netdev_ops); + alx_set_ethtool_ops(netdev); + netdev->irq = pdev->irq; + netdev->watchdog_timeo = ALX_WATCHDOG_TIME; +@@ -2614,12 +2634,26 @@ alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) + } + } + ++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) + netdev->hw_features = NETIF_F_SG | + NETIF_F_HW_CSUM | + NETIF_F_HW_VLAN_RX | + NETIF_F_TSO | + NETIF_F_TSO6; + netdev->features = netdev->hw_features | NETIF_F_HW_VLAN_TX; ++#else ++ netdev->features = NETIF_F_SG | ++ NETIF_F_HW_CSUM | ++ NETIF_F_HW_VLAN_RX; ++ if (adpt->hw.mac_type != alx_mac_l1c && ++ adpt->hw.mac_type != alx_mac_l2c) { ++ netdev->features = netdev->features | ++ NETIF_F_TSO | ++ NETIF_F_TSO6; ++ } ++ netdev->features = netdev->features | ++ NETIF_F_HW_VLAN_TX; ++#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)) */ + + /* read permanent mac addr from register or eFuse */ + if (alx_get_perm_macaddr(adpt, adpt->perm_addr)) { +@@ -2785,6 +2819,8 @@ static struct pci_error_handlers alx_err_handler = { + #ifdef CONFIG_PM_SLEEP + static SIMPLE_DEV_PM_OPS(alx_pm_ops, alx_suspend, alx_resume); + #define ALX_PM_OPS (&alx_pm_ops) ++compat_pci_suspend(alx_suspend) ++compat_pci_resume(alx_resume) + #else + #define ALX_PM_OPS NULL + #endif +@@ -2796,7 +2832,12 @@ static struct pci_driver alx_driver = { + .remove = __devexit_p(alx_remove), + .shutdown = alx_shutdown, + .err_handler = &alx_err_handler, ++#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)) + .driver.pm = ALX_PM_OPS, ++#elif defined(CONFIG_PM_SLEEP) ++ .suspend = alx_suspend_compat, ++ .resume = alx_resume_compat, ++#endif + }; + + diff --git a/patches/unified-drivers/network/0002-enable-alx.patch b/patches/unified-drivers/network/0002-enable-alx.patch new file mode 100644 index 000000000000..455480334fb3 --- /dev/null +++ b/patches/unified-drivers/network/0002-enable-alx.patch @@ -0,0 +1,9 @@ +Once upstream this will not be required. + +--- a/drivers/net/ethernet/atheros/Makefile ++++ b/drivers/net/ethernet/atheros/Makefile +@@ -6,3 +6,4 @@ obj-$(CONFIG_ATL1) += atlx/ + obj-$(CONFIG_ATL2) += atlx/ + obj-$(CONFIG_ATL1E) += atl1e/ + obj-$(CONFIG_ATL1C) += atl1c/ ++obj-$(CONFIG_ATLX) += alx/ diff --git a/scripts/admin-update.sh b/scripts/admin-update.sh index c3f163f2e38d..22830d767142 100755 --- a/scripts/admin-update.sh +++ b/scripts/admin-update.sh @@ -81,7 +81,7 @@ patchRefresh() { # usage() function ### usage() { - printf "Usage: $0 [refresh] [ --help | -h | -s | -n | -p | -c ] [subsystems] + printf "Usage: $0 [refresh] [ --help | -h | -s | -n | -p | -c [ -u ] [subsystems] where subsystems can be network, drm or both. Network is enabled by default.\n\n" printf "${GREEN}%10s${NORMAL} - Update all your patch offsets using quilt\n" "refresh" @@ -89,6 +89,7 @@ usage() { printf "${GREEN}%10s${NORMAL} - Apply the patches from linux-next-cherry-picks directory\n" "-n" printf "${GREEN}%10s${NORMAL} - Apply the patches from linux-next-pending directory\n" "-p" printf "${GREEN}%10s${NORMAL} - Apply the patches from crap directory\n" "-c" + printf "${GREEN}%10s${NORMAL} - Apply the patches from unified directory\n" "-u" } ### @@ -137,6 +138,13 @@ nag_crap() { printf "${RED}%10s${NORMAL} - %% of crap code\n" $(perl -e 'printf("%.4f", 100 * '$2' / '$1');') } +nag_unified() { + printf "${RED}%10s${NORMAL} - Unified driver backport changes required to backport\n" $2 + printf "${RED}%10s${NORMAL} - Unified driver backport additions required\n" $3 + printf "${RED}%10s${NORMAL} - Unified driver backport deletions required\n" $4 + printf "${RED}%10s${NORMAL} - %% of unified backport code\n" $(perl -e 'printf("%.4f", 100 * '$2' / '$1');') +} + nagometer() { CHANGES=0 @@ -165,6 +173,9 @@ nagometer() { "patches/crap") nag_crap $ORIG_CODE $CHANGES $ADD $DEL ;; + "patches/unified-drivers") + nag_unified $ORIG_CODE $CHANGES $ADD $DEL + ;; *) ;; esac @@ -198,7 +209,9 @@ copyDirectories() { # n: Include linux-next-cherry-picks/ patches (-n) # p: Include linux-next-pending/ patches (-p) # c: Include crap/ patches (-c) -# Note that the patches under patches/{subsystem} are applied by default. +# u: Include unified-drivers/ patches (-u) +# Note that the patches under patches/collateral-evolutions/{subsystem} +# are applied by default. # # If "refresh" is given as a cmdline argument, the script # uses quilt to refresh the patches. This is useful if patches @@ -210,7 +223,9 @@ copyDirectories() { # fetched in by default. ENABLE_NETWORK=1 ENABLE_DRM=1 +ENABLE_UNIFIED=0 SUBSYSTEMS= +UNIFIED_DRIVERS= EXTRA_PATCHES="patches/collateral-evolutions" REFRESH="n" @@ -245,6 +260,12 @@ if [ $# -ge 1 ]; then POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}c" shift ;; + "-u") + EXTRA_PATCHES="${EXTRA_PATCHES} patches/unified-drivers" + POSTFIX_RELEASE_TAG="${POSTFIX_RELEASE_TAG}u" + ENABLE_UNIFIED=1 + shift + ;; "refresh") REFRESH="y" shift @@ -566,6 +587,91 @@ for i in $STAGING_DRIVERS; do cp -a $GIT_TREE/$i drivers/staging/ done +UNIFIED_DRIVERS+="alx" + +unified_driver_git_tree() { + case $1 in + "alx") + echo "git://github.com/mcgrof/alx.git" + ;; + *) + ;; + esac +} + +unified_driver_linux_next_target() { + case $1 in + "alx") + echo "drivers/net/ethernet/atheros/alx" + ;; + *) + ;; + esac +} + +unified_driver_get_linux_src() { + case $1 in + "alx") + make -C $DRV_SRC/ clean + make -C $DRV_SRC/ linux-src + + TARGET_NEXT_DIR="$(unified_driver_linux_next_target $i)" + + rm -rf $TARGET_NEXT_DIR + cp -a $DRV_SRC/target/linux/src $TARGET_NEXT_DIR + ;; + *) + echo "Unsupported unified driver: $1" + exit + ;; + esac +} + +if [[ "$ENABLE_UNIFIED" == "1" ]]; then + if [ -z $UNIFIED_SRC ]; then + UNIFIED_SRC="$HOME/unified" + if [ ! -d $UNIFIED_SRC ]; then + echo "The directory $UNIFIED_SRC does not exist" + echo + echo "Please tell me where your unified drivers are located" + echo "You can do this by exporting its location as follows:" + echo + echo " export UNIFIED_SRC=$HOME/unified" + echo + echo "If you have never downloaded unified driver code you" + echo "can simply re-run this script by first creating an" + echo "empty directory for on $HOME/unified, the script" + echo "will then tell you what trees to clone. The unified" + echo "drivers that we support in compat-drivers adhear to" + echo "a policy explained in unified/README.md" + exit 1 + fi + else + if [ ! -d $UNIFIED_SRC ]; then + echo "The directory $UNIFIED_SRC does not exist" + exit + fi + fi + + for i in $UNIFIED_DRIVERS; do + DRV_SRC="$UNIFIED_SRC/$i" + + if [ ! -d $DRV_SRC ]; then + echo -e "$DRV_SRC does not exist. You can clone this tree from:" + echo + unified_driver_git_tree $i + echo + echo "You should clone this into $UNIFIED_SRC directory or" + echo "later specify where you put it using the UNIFIED_SRC" + echo "environment variable" + exit 1 + fi + + unified_driver_get_linux_src $i + done +fi + + # Finally copy MAINTAINERS file cp $GIT_TREE/MAINTAINERS ./ diff --git a/scripts/driver-select b/scripts/driver-select index 885033f6b810..7d48347471c0 100755 --- a/scripts/driver-select +++ b/scripts/driver-select @@ -39,7 +39,7 @@ SUPPORTED_80211_DRIVERS="ath5k ath9k ath9k_ap ath9k_htc carl9170 ath6kl b43 zd12 # b43 needs some more work for driver-select, the SSB stuff, plus # what if you update b44 but not b43? It will bust. -SUPPORTED_ETH_DRIVERS="atl1 atl2 atl1e atl1c" +SUPPORTED_ETH_DRIVERS="atl1 atl2 atl1e atl1c alx" SUPPORTED_DRM_DRIVERS="i915" @@ -74,7 +74,7 @@ function usage { echo -e "\t${CYAN}ti${NORMAL} < ${PURPLE} wl1251 wl12xx (SPI and SDIO)${NORMAL}>" echo -e "\nSupported group drivers: Bluetooth & Ethernet:" - echo -e "\t${CYAN}atlxx${NORMAL} < ${PURPLE} atl1 atl2 atl1e${NORMAL}>" + echo -e "\t${CYAN}atlxx${NORMAL} < ${PURPLE} atl1 atl2 atl1e alx${NORMAL}>" echo -e "\t${CYAN}bt${NORMAL} < ${PURPLE} Linux bluetooth drivers ${NORMAL}>" echo -e "\nSupported group drivers: DRM:" @@ -508,6 +508,11 @@ case $1 in disable_b44 echo -e "obj-\$(CONFIG_ATL1C) += atl1c/" > $DRIVERS_NET_ATHEROS ;; + alx) + enable_only_ethernet + disable_b44 + echo -e "obj-\$(CONFIG_ALX) += alx/" > $DRIVERS_NET_ATHEROS + ;; atlxx) select_drivers CONFIG_ATL1 CONFIG_ATL2 CONFIG_ATL1E CONFIG_ALX enable_only_ethernet diff --git a/scripts/unload.sh b/scripts/unload.sh index 67fa1508bd8d..1f3c5c38b20d 100755 --- a/scripts/unload.sh +++ b/scripts/unload.sh @@ -36,7 +36,7 @@ MODULES="$MODULES compat" # Bluetooth modules MODULES="$MODULES ath3k bcm203x bluecard_cs bnep bpa10x bt3c_cs btmrvl btmrvl_sdio btsdio" MODULES="$MODULES btusb btuart_cs cmtp dtl1_cs hidp hci_vhci hci_uart rfcomm sco bluetooth l2cap" -MODULES="$MODULES atl1 atl2 atl1e atl1c" +MODULES="$MODULES atl1 atl2 atl1e atl1c alx" echo Stoping bluetooth service.. /etc/init.d/bluetooth stop /etc/init.d/bluetooth status -- 2.30.2