aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/intel
diff options
context:
space:
mode:
authorSara Sharon <sara.sharon@intel.com>2016-03-01 05:18:22 -0500
committerEmmanuel Grumbach <emmanuel.grumbach@intel.com>2016-03-07 06:33:00 -0500
commitafd5b1704cb15eabc4358b7b0dd7f33099408eaa (patch)
tree5e1d9e2c485d5f8aa700f857fb7faaa184cb8f38 /drivers/net/wireless/intel
parent91f66a3c672065a3aca387ca7e0028504bb8f457 (diff)
iwlwifi: refactor the code that reads the MAC address from the NVM
It makes it slightly easier to follow. Pass the pointer to the transport which allows to read WFMP_MAC_ADDR_X register only when needed and to use IWL_ERR instead of the less commonly used IWL_ERR_DEV logger macro. Signed-off-by: Sara Sharon <sara.sharon@intel.com> Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Diffstat (limited to 'drivers/net/wireless/intel')
-rw-r--r--drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c97
-rw-r--r--drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h5
-rw-r--r--drivers/net/wireless/intel/iwlwifi/mvm/nvm.c11
3 files changed, 55 insertions, 58 deletions
diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
index 348135792f3e..5e6b90da3179 100644
--- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
+++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
@@ -7,6 +7,7 @@
7 * 7 *
8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. 8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 Intel Deutschland GmbH
10 * 11 *
11 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as 13 * it under the terms of version 2 of the GNU General Public License as
@@ -69,6 +70,7 @@
69#include "iwl-drv.h" 70#include "iwl-drv.h"
70#include "iwl-modparams.h" 71#include "iwl-modparams.h"
71#include "iwl-nvm-parse.h" 72#include "iwl-nvm-parse.h"
73#include "iwl-prph.h"
72 74
73/* NVM offsets (in words) definitions */ 75/* NVM offsets (in words) definitions */
74enum wkp_nvm_offsets { 76enum wkp_nvm_offsets {
@@ -522,27 +524,11 @@ static void iwl_set_radio_cfg(const struct iwl_cfg *cfg,
522 data->valid_rx_ant = NVM_RF_CFG_RX_ANT_MSK_FAMILY_8000(radio_cfg); 524 data->valid_rx_ant = NVM_RF_CFG_RX_ANT_MSK_FAMILY_8000(radio_cfg);
523} 525}
524 526
525static void iwl_set_hw_address(const struct iwl_cfg *cfg, 527static void iwl_set_hw_address_family_8000(struct iwl_trans *trans,
526 struct iwl_nvm_data *data,
527 const __le16 *nvm_sec)
528{
529 const u8 *hw_addr = (const u8 *)(nvm_sec + HW_ADDR);
530
531 /* The byte order is little endian 16 bit, meaning 214365 */
532 data->hw_addr[0] = hw_addr[1];
533 data->hw_addr[1] = hw_addr[0];
534 data->hw_addr[2] = hw_addr[3];
535 data->hw_addr[3] = hw_addr[2];
536 data->hw_addr[4] = hw_addr[5];
537 data->hw_addr[5] = hw_addr[4];
538}
539
540static void iwl_set_hw_address_family_8000(struct device *dev,
541 const struct iwl_cfg *cfg, 528 const struct iwl_cfg *cfg,
542 struct iwl_nvm_data *data, 529 struct iwl_nvm_data *data,
543 const __le16 *mac_override, 530 const __le16 *mac_override,
544 const __le16 *nvm_hw, 531 const __le16 *nvm_hw)
545 __le32 mac_addr0, __le32 mac_addr1)
546{ 532{
547 const u8 *hw_addr; 533 const u8 *hw_addr;
548 534
@@ -568,11 +554,16 @@ static void iwl_set_hw_address_family_8000(struct device *dev,
568 memcmp(reserved_mac, hw_addr, ETH_ALEN) != 0) 554 memcmp(reserved_mac, hw_addr, ETH_ALEN) != 0)
569 return; 555 return;
570 556
571 IWL_ERR_DEV(dev, 557 IWL_ERR(trans,
572 "mac address from nvm override section is not valid\n"); 558 "mac address from nvm override section is not valid\n");
573 } 559 }
574 560
575 if (nvm_hw) { 561 if (nvm_hw) {
562 /* read the mac address from WFMP registers */
563 __le32 mac_addr0 = cpu_to_le32(iwl_trans_read_prph(trans,
564 WFMP_MAC_ADDR_0));
565 __le32 mac_addr1 = cpu_to_le32(iwl_trans_read_prph(trans,
566 WFMP_MAC_ADDR_1));
576 /* read the MAC address from HW resisters */ 567 /* read the MAC address from HW resisters */
577 hw_addr = (const u8 *)&mac_addr0; 568 hw_addr = (const u8 *)&mac_addr0;
578 data->hw_addr[0] = hw_addr[3]; 569 data->hw_addr[0] = hw_addr[3];
@@ -585,28 +576,50 @@ static void iwl_set_hw_address_family_8000(struct device *dev,
585 data->hw_addr[5] = hw_addr[0]; 576 data->hw_addr[5] = hw_addr[0];
586 577
587 if (!is_valid_ether_addr(data->hw_addr)) 578 if (!is_valid_ether_addr(data->hw_addr))
588 IWL_ERR_DEV(dev, 579 IWL_ERR(trans,
589 "mac address (%pM) from hw section is not valid\n", 580 "mac address (%pM) from hw section is not valid\n",
590 data->hw_addr); 581 data->hw_addr);
591 582
592 return; 583 return;
593 } 584 }
594 585
595 IWL_ERR_DEV(dev, "mac address is not found\n"); 586 IWL_ERR(trans, "mac address is not found\n");
587}
588
589static void iwl_set_hw_address(struct iwl_trans *trans,
590 const struct iwl_cfg *cfg,
591 struct iwl_nvm_data *data, const __le16 *nvm_hw,
592 const __le16 *mac_override)
593{
594 if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
595 const u8 *hw_addr = (const u8 *)(nvm_hw + HW_ADDR);
596
597 /* The byte order is little endian 16 bit, meaning 214365 */
598 data->hw_addr[0] = hw_addr[1];
599 data->hw_addr[1] = hw_addr[0];
600 data->hw_addr[2] = hw_addr[3];
601 data->hw_addr[3] = hw_addr[2];
602 data->hw_addr[4] = hw_addr[5];
603 data->hw_addr[5] = hw_addr[4];
604 } else {
605 iwl_set_hw_address_family_8000(trans, cfg, data,
606 mac_override, nvm_hw);
607 }
596} 608}
597 609
598struct iwl_nvm_data * 610struct iwl_nvm_data *
599iwl_parse_nvm_data(struct device *dev, const struct iwl_cfg *cfg, 611iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
600 const __le16 *nvm_hw, const __le16 *nvm_sw, 612 const __le16 *nvm_hw, const __le16 *nvm_sw,
601 const __le16 *nvm_calib, const __le16 *regulatory, 613 const __le16 *nvm_calib, const __le16 *regulatory,
602 const __le16 *mac_override, const __le16 *phy_sku, 614 const __le16 *mac_override, const __le16 *phy_sku,
603 u8 tx_chains, u8 rx_chains, bool lar_fw_supported, 615 u8 tx_chains, u8 rx_chains, bool lar_fw_supported)
604 __le32 mac_addr0, __le32 mac_addr1)
605{ 616{
617 struct device *dev = trans->dev;
606 struct iwl_nvm_data *data; 618 struct iwl_nvm_data *data;
607 u32 sku; 619 bool lar_enabled;
608 u32 radio_cfg; 620 u32 sku, radio_cfg;
609 u16 lar_config; 621 u16 lar_config;
622 const __le16 *ch_section;
610 623
611 if (cfg->device_family != IWL_DEVICE_FAMILY_8000) 624 if (cfg->device_family != IWL_DEVICE_FAMILY_8000)
612 data = kzalloc(sizeof(*data) + 625 data = kzalloc(sizeof(*data) +
@@ -645,21 +658,16 @@ iwl_parse_nvm_data(struct device *dev, const struct iwl_cfg *cfg,
645 if (cfg->device_family != IWL_DEVICE_FAMILY_8000) { 658 if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
646 /* Checking for required sections */ 659 /* Checking for required sections */
647 if (!nvm_calib) { 660 if (!nvm_calib) {
648 IWL_ERR_DEV(dev, 661 IWL_ERR(trans,
649 "Can't parse empty Calib NVM sections\n"); 662 "Can't parse empty Calib NVM sections\n");
650 kfree(data); 663 kfree(data);
651 return NULL; 664 return NULL;
652 } 665 }
653 /* in family 8000 Xtal calibration values moved to OTP */ 666 /* in family 8000 Xtal calibration values moved to OTP */
654 data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB); 667 data->xtal_calib[0] = *(nvm_calib + XTAL_CALIB);
655 data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1); 668 data->xtal_calib[1] = *(nvm_calib + XTAL_CALIB + 1);
656 } 669 lar_enabled = true;
657 670 ch_section = nvm_sw;
658 if (cfg->device_family != IWL_DEVICE_FAMILY_8000) {
659 iwl_set_hw_address(cfg, data, nvm_hw);
660
661 iwl_init_sbands(dev, cfg, data, nvm_sw,
662 tx_chains, rx_chains, lar_fw_supported);
663 } else { 671 } else {
664 u16 lar_offset = data->nvm_version < 0xE39 ? 672 u16 lar_offset = data->nvm_version < 0xE39 ?
665 NVM_LAR_OFFSET_FAMILY_8000_OLD : 673 NVM_LAR_OFFSET_FAMILY_8000_OLD :
@@ -668,16 +676,13 @@ iwl_parse_nvm_data(struct device *dev, const struct iwl_cfg *cfg,
668 lar_config = le16_to_cpup(regulatory + lar_offset); 676 lar_config = le16_to_cpup(regulatory + lar_offset);
669 data->lar_enabled = !!(lar_config & 677 data->lar_enabled = !!(lar_config &
670 NVM_LAR_ENABLED_FAMILY_8000); 678 NVM_LAR_ENABLED_FAMILY_8000);
671 679 lar_enabled = data->lar_enabled;
672 /* MAC address in family 8000 */ 680 ch_section = regulatory;
673 iwl_set_hw_address_family_8000(dev, cfg, data, mac_override,
674 nvm_hw, mac_addr0, mac_addr1);
675
676 iwl_init_sbands(dev, cfg, data, regulatory,
677 tx_chains, rx_chains,
678 lar_fw_supported && data->lar_enabled);
679 } 681 }
680 682
683 iwl_set_hw_address(trans, cfg, data, nvm_hw, mac_override);
684 iwl_init_sbands(dev, cfg, data, ch_section, tx_chains, rx_chains,
685 lar_fw_supported && lar_enabled);
681 data->calib_version = 255; 686 data->calib_version = 255;
682 687
683 return data; 688 return data;
diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h
index 4e8e0dc474d4..d704d52aa7ec 100644
--- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h
+++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.h
@@ -74,12 +74,11 @@
74 * later with iwl_free_nvm_data(). 74 * later with iwl_free_nvm_data().
75 */ 75 */
76struct iwl_nvm_data * 76struct iwl_nvm_data *
77iwl_parse_nvm_data(struct device *dev, const struct iwl_cfg *cfg, 77iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
78 const __le16 *nvm_hw, const __le16 *nvm_sw, 78 const __le16 *nvm_hw, const __le16 *nvm_sw,
79 const __le16 *nvm_calib, const __le16 *regulatory, 79 const __le16 *nvm_calib, const __le16 *regulatory,
80 const __le16 *mac_override, const __le16 *phy_sku, 80 const __le16 *mac_override, const __le16 *phy_sku,
81 u8 tx_chains, u8 rx_chains, bool lar_fw_supported, 81 u8 tx_chains, u8 rx_chains, bool lar_fw_supported);
82 __le32 mac_addr0, __le32 mac_addr1);
83 82
84/** 83/**
85 * iwl_parse_mcc_info - parse MCC (mobile country code) info coming from FW 84 * iwl_parse_mcc_info - parse MCC (mobile country code) info coming from FW
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c b/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c
index c446e0da9789..25a98401a64f 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/nvm.c
@@ -300,7 +300,6 @@ iwl_parse_nvm_sections(struct iwl_mvm *mvm)
300 struct iwl_nvm_section *sections = mvm->nvm_sections; 300 struct iwl_nvm_section *sections = mvm->nvm_sections;
301 const __le16 *hw, *sw, *calib, *regulatory, *mac_override, *phy_sku; 301 const __le16 *hw, *sw, *calib, *regulatory, *mac_override, *phy_sku;
302 bool lar_enabled; 302 bool lar_enabled;
303 __le32 mac_addr0, mac_addr1;
304 303
305 /* Checking for required sections */ 304 /* Checking for required sections */
306 if (mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) { 305 if (mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_8000) {
@@ -336,12 +335,6 @@ iwl_parse_nvm_sections(struct iwl_mvm *mvm)
336 if (WARN_ON(!mvm->cfg)) 335 if (WARN_ON(!mvm->cfg))
337 return NULL; 336 return NULL;
338 337
339 /* read the mac address from WFMP registers */
340 mac_addr0 = cpu_to_le32(iwl_trans_read_prph(mvm->trans,
341 WFMP_MAC_ADDR_0));
342 mac_addr1 = cpu_to_le32(iwl_trans_read_prph(mvm->trans,
343 WFMP_MAC_ADDR_1));
344
345 hw = (const __le16 *)sections[mvm->cfg->nvm_hw_section_num].data; 338 hw = (const __le16 *)sections[mvm->cfg->nvm_hw_section_num].data;
346 sw = (const __le16 *)sections[NVM_SECTION_TYPE_SW].data; 339 sw = (const __le16 *)sections[NVM_SECTION_TYPE_SW].data;
347 calib = (const __le16 *)sections[NVM_SECTION_TYPE_CALIBRATION].data; 340 calib = (const __le16 *)sections[NVM_SECTION_TYPE_CALIBRATION].data;
@@ -354,10 +347,10 @@ iwl_parse_nvm_sections(struct iwl_mvm *mvm)
354 fw_has_capa(&mvm->fw->ucode_capa, 347 fw_has_capa(&mvm->fw->ucode_capa,
355 IWL_UCODE_TLV_CAPA_LAR_SUPPORT); 348 IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
356 349
357 return iwl_parse_nvm_data(mvm->trans->dev, mvm->cfg, hw, sw, calib, 350 return iwl_parse_nvm_data(mvm->trans, mvm->cfg, hw, sw, calib,
358 regulatory, mac_override, phy_sku, 351 regulatory, mac_override, phy_sku,
359 mvm->fw->valid_tx_ant, mvm->fw->valid_rx_ant, 352 mvm->fw->valid_tx_ant, mvm->fw->valid_rx_ant,
360 lar_enabled, mac_addr0, mac_addr1); 353 lar_enabled);
361} 354}
362 355
363#define MAX_NVM_FILE_LEN 16384 356#define MAX_NVM_FILE_LEN 16384