All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: linux-scsi@vger.kernel.org
Cc: Matthew Wilcox <matthew@wil.cx>
Subject: [PATCH 21/21] advansys: use memcpy instead of open-coded loop
Date: Thu, 26 Jul 2007 13:22:57 -0400	[thread overview]
Message-ID: <11854705773144-git-send-email-matthew@wil.cx> (raw)
In-Reply-To: 20070726171141.GE19275@parisc-linux.org
In-Reply-To: <20070726171141.GE19275@parisc-linux.org>

Use memcpy to initialise eep_config instead of a loop.  For
AdvInitFrom38C1600EEP where we need to modify the default EEPROM
configuration, do it after the loop, and do it using the structure
definition, not by finding the right byte.  I think it was wrong for
big-endian machines.

Also delete some non-useful comments and prototypes.

Signed-off-by: Matthew Wilcox <matthew@wil.cx>
---
 drivers/scsi/advansys.c |  119 ++++++++++++++++-------------------------------
 1 files changed, 40 insertions(+), 79 deletions(-)

diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 1704427..3bb1963 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -3181,13 +3181,6 @@ do { \
 #define QHSTA_M_SGBACKUP_ERROR      0x47	/* Scatter-Gather backup error */
 
 /*
- * Default EEPROM Configuration structure defined in a_init.c.
- */
-static ADVEEP_3550_CONFIG Default_3550_EEPROM_Config;
-static ADVEEP_38C0800_CONFIG Default_38C0800_EEPROM_Config;
-static ADVEEP_38C1600_CONFIG Default_38C1600_EEPROM_Config;
-
-/*
  * DvcGetPhyAddr() flag arguments
  */
 #define ADV_IS_SCSIQ_FLAG       0x01	/* 'addr' is ASC_SCSI_REQ_Q pointer */
@@ -13341,7 +13334,6 @@ static unsigned char _adv_asc38C1600_buf[] = {
 static unsigned short _adv_asc38C1600_size = sizeof(_adv_asc38C1600_buf);	/* 0x1673 */
 static ADV_DCNT _adv_asc38C1600_chksum = 0x0604EF77UL;	/* Expanded little-endian checksum. */
 
-/* a_init.c */
 /*
  * EEPROM Configuration.
  *
@@ -15601,7 +15593,6 @@ static int __devinit AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
 	AdvPortAddr iop_base;
 	ushort warn_code;
 	ADVEEP_3550_CONFIG eep_config;
-	int i;
 
 	iop_base = asc_dvc->iop_base;
 
@@ -15618,15 +15609,12 @@ static int __devinit AdvInitFrom3550EEP(ADV_DVC_VAR *asc_dvc)
 		/*
 		 * Set EEPROM default values.
 		 */
-		for (i = 0; i < sizeof(ADVEEP_3550_CONFIG); i++) {
-			*((uchar *)&eep_config + i) =
-			    *((uchar *)&Default_3550_EEPROM_Config + i);
-		}
+		memcpy(&eep_config, &Default_3550_EEPROM_Config,
+			sizeof(ADVEEP_3550_CONFIG));
 
 		/*
-		 * Assume the 6 byte board serial number that was read
-		 * from EEPROM is correct even if the EEPROM checksum
-		 * failed.
+		 * Assume the 6 byte board serial number that was read from
+		 * EEPROM is correct even if the EEPROM checksum failed.
 		 */
 		eep_config.serial_number_word3 =
 		    AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
@@ -15755,7 +15743,6 @@ static int __devinit AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
 	AdvPortAddr iop_base;
 	ushort warn_code;
 	ADVEEP_38C0800_CONFIG eep_config;
-	int i;
 	uchar tid, termination;
 	ushort sdtr_speed = 0;
 
@@ -15775,15 +15762,12 @@ static int __devinit AdvInitFrom38C0800EEP(ADV_DVC_VAR *asc_dvc)
 		/*
 		 * Set EEPROM default values.
 		 */
-		for (i = 0; i < sizeof(ADVEEP_38C0800_CONFIG); i++) {
-			*((uchar *)&eep_config + i) =
-			    *((uchar *)&Default_38C0800_EEPROM_Config + i);
-		}
+		memcpy(&eep_config, &Default_38C0800_EEPROM_Config,
+			sizeof(ADVEEP_38C0800_CONFIG));
 
 		/*
-		 * Assume the 6 byte board serial number that was read
-		 * from EEPROM is correct even if the EEPROM checksum
-		 * failed.
+		 * Assume the 6 byte board serial number that was read from
+		 * EEPROM is correct even if the EEPROM checksum failed.
 		 */
 		eep_config.serial_number_word3 =
 		    AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
@@ -15958,7 +15942,6 @@ static int __devinit AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
 	AdvPortAddr iop_base;
 	ushort warn_code;
 	ADVEEP_38C1600_CONFIG eep_config;
-	int i;
 	uchar tid, termination;
 	ushort sdtr_speed = 0;
 
@@ -15979,68 +15962,46 @@ static int __devinit AdvInitFrom38C1600EEP(ADV_DVC_VAR *asc_dvc)
 		/*
 		 * Set EEPROM default values.
 		 */
-		for (i = 0; i < sizeof(ADVEEP_38C1600_CONFIG); i++) {
-			if (i == 1 && PCI_FUNC(pdev->devfn) != 0) {
-				/*
-				 * Set Function 1 EEPROM Word 0 MSB
-				 *
-				 * Clear the BIOS_ENABLE (bit 14) and INTAB (bit 11)
-				 * EEPROM bits.
-				 *
-				 * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60 and
-				 * old Mac system booting problem. The Expansion ROM must
-				 * be disabled in Function 1 for these systems.
-				 *
-				 */
-				*((uchar *)&eep_config + i) =
-				    ((*
-				      ((uchar *)&Default_38C1600_EEPROM_Config
-				       +
-				       i)) &
-				     (~
-				      (((ADV_EEPROM_BIOS_ENABLE |
-					 ADV_EEPROM_INTAB) >> 8) & 0xFF)));
+		memcpy(&eep_config, &Default_38C1600_EEPROM_Config,
+			sizeof(ADVEEP_38C1600_CONFIG));
 
-				/*
-				 * Set the INTAB (bit 11) if the GPIO 0 input indicates
-				 * the Function 1 interrupt line is wired to INTA.
-				 *
-				 * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
-				 *   1 - Function 1 interrupt line wired to INT A.
-				 *   0 - Function 1 interrupt line wired to INT B.
-				 *
-				 * Note: Adapter boards always have Function 0 wired to INTA.
-				 * Put all 5 GPIO bits in input mode and then read
-				 * their input values.
-				 */
-				AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL,
-						     0);
-				if (AdvReadByteRegister
-				    (iop_base, IOPB_GPIO_DATA) & 0x01) {
-					/* Function 1 interrupt wired to INTA; Set EEPROM bit. */
-					*((uchar *)&eep_config + i) |=
-					    ((ADV_EEPROM_INTAB >> 8) & 0xFF);
-				}
-			} else {
-				*((uchar *)&eep_config + i) =
-				    *((uchar *)&Default_38C1600_EEPROM_Config
-				      + i);
-			}
+		if (PCI_FUNC(pdev->devfn) != 0) {
+			u8 ints;
+			/*
+			 * Disable Bit 14 (BIOS_ENABLE) to fix SPARC Ultra 60
+			 * and old Mac system booting problem. The Expansion
+			 * ROM must be disabled in Function 1 for these systems
+			 */
+			eep_config.cfg_lsw &= ~ADV_EEPROM_BIOS_ENABLE;
+			/*
+			 * Clear the INTAB (bit 11) if the GPIO 0 input
+			 * indicates the Function 1 interrupt line is wired
+			 * to INTB.
+			 *
+			 * Set/Clear Bit 11 (INTAB) from the GPIO bit 0 input:
+			 *   1 - Function 1 interrupt line wired to INT A.
+			 *   0 - Function 1 interrupt line wired to INT B.
+			 *
+			 * Note: Function 0 is always wired to INTA.
+			 * Put all 5 GPIO bits in input mode and then read
+			 * their input values.
+			 */
+			AdvWriteByteRegister(iop_base, IOPB_GPIO_CNTL, 0);
+			ints = AdvReadByteRegister(iop_base, IOPB_GPIO_DATA);
+			if ((ints & 0x01) == 0)
+				eep_config.cfg_lsw &= ~ADV_EEPROM_INTAB;
 		}
 
 		/*
-		 * Assume the 6 byte board serial number that was read
-		 * from EEPROM is correct even if the EEPROM checksum
-		 * failed.
+		 * Assume the 6 byte board serial number that was read from
+		 * EEPROM is correct even if the EEPROM checksum failed.
 		 */
 		eep_config.serial_number_word3 =
-		    AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
-
+			AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 1);
 		eep_config.serial_number_word2 =
-		    AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
-
+			AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 2);
 		eep_config.serial_number_word1 =
-		    AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
+			AdvReadEEPWord(iop_base, ADV_EEP_DVC_CFG_END - 3);
 
 		AdvSet38C1600EEPConfig(iop_base, &eep_config);
 	}
-- 
1.4.4.4


  parent reply	other threads:[~2007-07-26 18:00 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-26 17:11 Advansys driver Matthew Wilcox
2007-07-26 17:22 ` [PATCH 1/21] advansys: Clean up proc_info implementation Matthew Wilcox
2007-07-26 18:51   ` Jeff Garzik
2007-07-26 19:05     ` Matthew Wilcox
2007-07-26 17:22 ` [PATCH 2/21] advansys: version, copyright, etc Matthew Wilcox
2007-07-26 18:56   ` Jeff Garzik
2007-07-26 19:03     ` Matthew Wilcox
2007-07-26 19:08       ` Jeff Garzik
2007-07-26 19:16         ` Matthew Wilcox
2007-07-26 19:25         ` Christer Weinigel
2007-07-26 17:22 ` [PATCH 3/21] advansys: Convert to pci_register_driver interface Matthew Wilcox
2007-07-26 19:05   ` Jeff Garzik
2007-07-26 19:31   ` Jeff Garzik
2007-07-26 20:49     ` Matthew Wilcox
2007-07-26 21:21       ` Jeff Garzik
2007-07-27 13:48       ` Jeff Garzik
2007-07-26 17:22 ` [PATCH 4/21] advansys: restructure error handling in advansys_board_found Matthew Wilcox
2007-07-26 17:22 ` [PATCH 5/21] advansys: split advansys_init_wide_chip() out of advansys_board_found() Matthew Wilcox
2007-07-26 17:22 ` [PATCH 6/21] advansys: Move to scsi hotplug initialisation model Matthew Wilcox
2007-07-26 18:01   ` Christoph Hellwig
2007-07-26 18:04     ` Matthew Wilcox
2007-07-26 18:06       ` Matthew Wilcox
2007-07-26 18:16         ` Jeff Garzik
2007-07-26 18:29           ` Matthew Wilcox
2007-07-26 18:13       ` Jeff Garzik
2007-07-26 19:19   ` Jeff Garzik
2007-07-26 17:22 ` [PATCH 7/21] advansys: Convert to EISA driver model Matthew Wilcox
2007-07-26 19:38   ` Jeff Garzik
2007-07-26 20:37     ` Matthew Wilcox
2007-07-27 13:50       ` Jeff Garzik
2007-07-27 14:16         ` Matthew Wilcox
2007-07-27 14:55           ` Jeff Garzik
2007-07-26 17:22 ` [PATCH 8/21] advansys: Rewrite resource management Matthew Wilcox
2007-07-26 19:41   ` Jeff Garzik
2007-07-26 17:22 ` [PATCH 9/21] advansys: More PCI cleanups Matthew Wilcox
2007-07-26 19:43   ` Jeff Garzik
2007-07-26 19:50     ` Matthew Wilcox
2007-07-26 19:55       ` Jeff Garzik
2007-07-26 17:22 ` [PATCH 10/21] advansys: remove AscCompareString() Matthew Wilcox
2007-07-26 17:22 ` [PATCH 11/21] Add QUANTUM XP34301 to the blacklist Matthew Wilcox
2007-07-26 17:22 ` [PATCH 12/21] advansys: remove INQUIRY sniffing Matthew Wilcox
2007-07-26 17:22 ` [PATCH 13/21] advansys: misc reformatting Matthew Wilcox
2007-07-26 17:22 ` [PATCH 14/21] advansys: delete AscGetChipBusType Matthew Wilcox
2007-07-26 17:22 ` [PATCH 15/21] advansys: ioremap no longer needs page-aligned addresses Matthew Wilcox
2007-07-26 17:22 ` [PATCH 16/21] advansys: Stop using n_io_port in Scsi_Host structure Matthew Wilcox
2007-07-26 17:22 ` [PATCH 17/21] advansys: remove detect_called Matthew Wilcox
2007-07-26 19:48   ` Jeff Garzik
2007-07-26 17:22 ` [PATCH 18/21] advansys: Move struct device out of the cfg structures Matthew Wilcox
2007-07-26 19:49   ` Jeff Garzik
2007-07-26 20:26     ` Matthew Wilcox
2007-07-26 17:22 ` [PATCH 19/21] advansys: Remove library-style callback routines Matthew Wilcox
2007-07-26 17:22 ` [PATCH 20/21] advansys: Remove pci_slot_info Matthew Wilcox
2007-07-26 17:22 ` Matthew Wilcox [this message]
2007-07-26 19:50   ` [PATCH 21/21] advansys: use memcpy instead of open-coded loop Jeff Garzik
2007-07-27  4:58     ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11854705773144-git-send-email-matthew@wil.cx \
    --to=matthew@wil.cx \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.