Re: [PATCH] scsi: csiostor: update csio_get_flash_params()

2018-07-30 Thread Martin K. Petersen


Arjun,

> + switch (density) {
> + case 0x14: /* 1MB */
> + size = 1 << 20;
> + break;

It seems a bit silly to have a switch statement for this. Why not just
do:

size = 1 << density;

?

> + case 0x15: /* 2MB */
> + size = 1 << 21;
> + break;
> + case 0x16: /* 4MB */
> + size = 1 << 22;
> + break;
> + case 0x17: /* 8MB */
> + size = 1 << 23;
> + break;
> + case 0x18: /* 16MB */
> + size = 1 << 24;
> + break;
> + case 0x19: /* 32MB */
> + size = 1 << 25;
> + break;
> + case 0x20: /* 64MB */
> + size = 1 << 26;
> + break;
> + case 0x21: /* 128MB */
> + size = 1 << 27;
> + break;
> + case 0x22: /* 256MB */
> + size = 1 << 28;
> + break;

-- 
Martin K. Petersen  Oracle Linux Engineering


[PATCH] scsi: csiostor: update csio_get_flash_params()

2018-07-27 Thread Arjun Vynipadath
- Updates csio_get_flash_params() to take care of ISSI, Macronix and
  Winbond FLASH parts.

- Assume flash part size to be 4MB if it cannot be identified

Signed-off-by: Arjun Vynipadath 
Signed-off-by: Varun Prakash 
---
 drivers/scsi/csiostor/csio_hw.c | 150 
 1 file changed, 137 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/csiostor/csio_hw.c b/drivers/scsi/csiostor/csio_hw.c
index a10cf25..618581c 100644
--- a/drivers/scsi/csiostor/csio_hw.c
+++ b/drivers/scsi/csiostor/csio_hw.c
@@ -761,27 +761,151 @@ csio_hw_fw_dload(struct csio_hw *hw, uint8_t *fw_data, 
uint32_t size)
 static int
 csio_hw_get_flash_params(struct csio_hw *hw)
 {
+   /* Table for non-Numonix supported flash parts.  Numonix parts are left
+* to the preexisting code.  All flash parts have 64KB sectors.
+*/
+   static struct flash_desc {
+   u32 vendor_and_model_id;
+   u32 size_mb;
+   } supported_flash[] = {
+   { 0x150201, 4 << 20 },   /* Spansion 4MB S25FL032P */
+   };
+
+   u32 part, manufacturer;
+   u32 density, size = 0;
+   u32 flashid = 0;
int ret;
-   uint32_t info = 0;
 
ret = csio_hw_sf1_write(hw, 1, 1, 0, SF_RD_ID);
if (!ret)
-   ret = csio_hw_sf1_read(hw, 3, 0, 1, );
+   ret = csio_hw_sf1_read(hw, 3, 0, 1, );
csio_wr_reg32(hw, 0, SF_OP_A);/* unlock SF */
-   if (ret != 0)
+   if (ret)
return ret;
 
-   if ((info & 0xff) != 0x20)  /* not a Numonix flash */
-   return -EINVAL;
-   info >>= 16;/* log2 of size */
-   if (info >= 0x14 && info < 0x18)
-   hw->params.sf_nsec = 1 << (info - 16);
-   else if (info == 0x18)
-   hw->params.sf_nsec = 64;
-   else
-   return -EINVAL;
-   hw->params.sf_size = 1 << info;
+   /* Check to see if it's one of our non-standard supported Flash parts.
+*/
+   for (part = 0; part < ARRAY_SIZE(supported_flash); part++)
+   if (supported_flash[part].vendor_and_model_id == flashid) {
+   hw->params.sf_size = supported_flash[part].size_mb;
+   hw->params.sf_nsec =
+   hw->params.sf_size / SF_SEC_SIZE;
+   goto found;
+   }
+
+   /* Decode Flash part size.  The code below looks repetative with
+* common encodings, but that's not guaranteed in the JEDEC
+* specification for the Read JADEC ID command.  The only thing that
+* we're guaranteed by the JADEC specification is where the
+* Manufacturer ID is in the returned result.  After that each
+* Manufacturer ~could~ encode things completely differently.
+* Note, all Flash parts must have 64KB sectors.
+*/
+   manufacturer = flashid & 0xff;
+   switch (manufacturer) {
+   case 0x20: { /* Micron/Numonix */
+   /* This Density -> Size decoding table is taken from Micron
+* Data Sheets.
+*/
+   density = (flashid >> 16) & 0xff;
+   switch (density) {
+   case 0x14: /* 1MB */
+   size = 1 << 20;
+   break;
+   case 0x15: /* 2MB */
+   size = 1 << 21;
+   break;
+   case 0x16: /* 4MB */
+   size = 1 << 22;
+   break;
+   case 0x17: /* 8MB */
+   size = 1 << 23;
+   break;
+   case 0x18: /* 16MB */
+   size = 1 << 24;
+   break;
+   case 0x19: /* 32MB */
+   size = 1 << 25;
+   break;
+   case 0x20: /* 64MB */
+   size = 1 << 26;
+   break;
+   case 0x21: /* 128MB */
+   size = 1 << 27;
+   break;
+   case 0x22: /* 256MB */
+   size = 1 << 28;
+   break;
+   }
+   break;
+   }
+   case 0x9d: { /* ISSI -- Integrated Silicon Solution, Inc. */
+   /* This Density -> Size decoding table is taken from ISSI
+* Data Sheets.
+*/
+   density = (flashid >> 16) & 0xff;
+   switch (density) {
+   case 0x16: /* 32 MB */
+   size = 1 << 25;
+   break;
+   case 0x17: /* 64MB */
+   size = 1 << 26;
+   break;
+   }
+   break;
+   }
+   case 0xc2: { /* Macronix */
+   /* This Density -> Size decoding table is taken from Macronix
+* Data Sheets.
+