Skip to contentSkip to conversation

mptfusion - fc transport attributes - REVISED

PATCH In review Michael Reed 2 participants 6 messages Jan 12, 2006 – Jan 14, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mptfusion - fc transport attributes - REVISED

Hello,

Attached is a patch which implements fibre channel transport attributes for LSI's MPT Fusion driver. This patch is a reissue of the patch I posted on December 16, 2005.

http://marc.theaimsgroup.com/?l=linux-scsi&m=113477868225386&w=3

The differences between this patch and the previous patch are:

- it incorporates review comments from LSI

- it bumps the driver version number to 3.03.06 from 3.03.05 at LSI's request

- it has been rebased to 2.6.15-git8 + two patches from Eric Moore, the first is referenced below,

http://marc.theaimsgroup.com/?l=linux-scsi&m=113710143317450&w=3

and the second I just posted instead of including in this patch.

http://marc.theaimsgroup.com/?l=linux-scsi&m=113710675626733&w=3

Until better integration of fc transport and scsi error recovery occurs, I continue to urge (as a temporary measure) the application of my previous scsi error recovery patch.

http://marc.theaimsgroup.com/?l=linux-scsi&m=113477788309880&w=3

Thanks,
Mike

drivers/message/fusion/mptbase.c +25 -5
diff -ru linux-2.6.15-git8/drivers/message/fusion/mptbase.c linux-2.6.15-git8-mdr/drivers/message/fusion/mptbase.c
@@ -148,7 +148,6 @@
 static int	WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
 static int	WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
 static int	GetLanConfigPages(MPT_ADAPTER *ioc);
-static int	GetFcPortPage0(MPT_ADAPTER *ioc, int portnum);
 static int	GetIoUnitPage2(MPT_ADAPTER *ioc);
 int		mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
 static int	mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
@@ -1245,6 +1244,8 @@
 	ioc->pcidev = pdev;
 	ioc->diagPending = 0;
 	spin_lock_init(&ioc->diagLock);
+	spin_lock_init(&ioc->work_lock);
+	spin_lock_init(&ioc->fc_rport_lock);
 	spin_lock_init(&ioc->initializing_hba_lock);
 
 	/* Initialize the event logging.
@@ -1268,6 +1269,10 @@
 	 */
 	INIT_LIST_HEAD(&ioc->configQ);
 
+	/* Initialize the fc rport list head.
+	 */
+	INIT_LIST_HEAD(&ioc->l.fc_rports);
+
 	/* Find lookup slot. */
 	INIT_LIST_HEAD(&ioc->list);
 	ioc->id = mpt_ids++;
@@ -1884,7 +1889,7 @@
 			 *  (FCPortPage0_t stuff)
 			 */
 			for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
-				(void) GetFcPortPage0(ioc, ii);
+				(void) mptbase_GetFcPortPage0(ioc, ii);
 			}
 
 			if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
@@ -4203,7 +4208,7 @@
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /*
- *	GetFcPortPage0 - Fetch FCPort config Page0.
+ *	mptbase_GetFcPortPage0 - Fetch FCPort config Page0.
  *	@ioc: Pointer to MPT_ADAPTER structure
  *	@portnum: IOC Port number
  *
@@ -4213,8 +4218,8 @@
  *		-EAGAIN if no msg frames currently available
  *		-EFAULT for non-successful reply or no reply (timeout)
  */
-static int
-GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
+int
+mptbase_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
 {
 	ConfigPageHeader_t	 hdr;
 	CONFIGPARMS		 cfg;
@@ -4224,6 +4229,8 @@
 	int			 data_sz;
 	int			 copy_sz;
 	int			 rc;
+	int			 count=400;
+
 
 	/* Get FCPort Page 0 header */
 	hdr.PageVersion = 0;
@@ -4247,6 +4254,8 @@
 	rc = -ENOMEM;
 	ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
 	if (ppage0_alloc) {
+
+ try_again:
 		memset((u8 *)ppage0_alloc, 0, data_sz);
 		cfg.physAddr = page0_dma;
 		cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
@@ -4278,6 +4287,16 @@
 			pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
 			pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
 
+			/* if still doing discovery, hang loose a while until finished */
+			if (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) {
+				if (count-- > 0) {
+					msleep_interruptible(100);
+					goto try_again;
+				}
+				else
+					printk(MYIOC_s_INFO_FMT "Firmware discovery not complete.\n",
+						ioc->name);
+			}
 		}
 
 		pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
@@ -6362,6 +6381,7 @@
 EXPORT_SYMBOL(mpt_free_fw_memory);
 EXPORT_SYMBOL(mptbase_sas_persist_operation);
 EXPORT_SYMBOL(mpt_alt_ioc_wait);
+EXPORT_SYMBOL(mptbase_GetFcPortPage0);
 
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
drivers/message/fusion/mptbase.h +30 -2
diff -ru linux-2.6.15-git8/drivers/message/fusion/mptbase.h linux-2.6.15-git8-mdr/drivers/message/fusion/mptbase.h
@@ -76,8 +76,8 @@
 #define COPYRIGHT	"Copyright (c) 1999-2005 " MODULEAUTHOR
 #endif
 
-#define MPT_LINUX_VERSION_COMMON	"3.03.05"
-#define MPT_LINUX_PACKAGE_NAME		"@(#)mptlinux-3.03.05"
+#define MPT_LINUX_VERSION_COMMON	"3.03.06"
+#define MPT_LINUX_PACKAGE_NAME		"@(#)mptlinux-3.03.06"
 #define WHAT_MAGIC_STRING		"@" "(" "#" ")"
 
 #define show_mptmod_ver(s,ver)  \
@@ -499,6 +499,22 @@
 	int		 isRaid;		/* bit field, 1 if RAID */
 }RaidCfgData;
 
+#define MPT_RPORT_INFO_FLAGS_REGISTERED		0x01	/* rport registered */
+#define	MPT_RPORT_INFO_FLAGS_MISSING		0x02	/* missing from DevPage0 scan */
+#define MPT_RPORT_INFO_FLAGS_MAPPED_VDEV	0x04	/* target mapped in vdev */
+
+/*
+ * data allocated for each fc rport device
+ */
+struct mptfc_rport_info
+{
+	struct list_head list;
+	struct fc_rport *rport;
+	VirtDevice	*vdev;
+	FCDevicePage0_t pg0;
+	u8		flags;
+};
+
 /*
  *  Adapter Structure - pci_dev specific. Maximum: MPT_MAX_ADAPTERS
  */
@@ -611,7 +627,18 @@
 	int 	 		 initializing_hba_lock_flag;
 	struct list_head	 list;
 	struct net_device	*netdev;
+
+	union {
 	struct list_head	 sas_topology;
+	struct list_head	 fc_rports;	/* list of wwpn / sdev target / rport ptr */
+	} l;
+
+	spinlock_t		 fc_rport_lock;	/* for all accesses of list and ri flags */
+
+	spinlock_t		 work_lock;
+	int			 work_count;
+	struct work_struct	 work_task;	/* for use by personality, i.e., fc, sas, spi, lan */
+
 	MPT_SAS_MGMT		 sas_mgmt;
 } MPT_ADAPTER;
 
@@ -999,6 +1026,7 @@
 extern int	 mpt_findImVolumes(MPT_ADAPTER *ioc);
 extern int	 mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
 extern int	 mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
+extern int	 mptbase_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum);
 extern int	 mpt_alt_ioc_wait(MPT_ADAPTER *ioc);
 
 /*
drivers/message/fusion/mptfc.c +509 -16

621 lines not on this page · raw message

drivers/message/fusion/mptsas.c +6 -6
diff -ru linux-2.6.15-git8/drivers/message/fusion/mptsas.c linux-2.6.15-git8-mdr/drivers/message/fusion/mptsas.c
@@ -257,7 +257,7 @@
 	}
 
 	rphy = dev_to_rphy(sdev->sdev_target->dev.parent);
-	list_for_each_entry(p, &hd->ioc->sas_topology, list) {
+	list_for_each_entry(p, &hd->ioc->l.sas_topology, list) {
 		for (i = 0; i < p->num_phys; i++) {
 			if (p->phy_info[i].attached.sas_address ==
 					rphy->identify.sas_address) {
@@ -994,7 +994,7 @@
 	if (error)
 		goto out_free_port_info;
 
-	list_add_tail(&port_info->list, &ioc->sas_topology);
+	list_add_tail(&port_info->list, &ioc->l.sas_topology);
 	for (i = 0; i < port_info->num_phys; i++) {
 		mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
 			(MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
@@ -1047,7 +1047,7 @@
 
 	*handle = port_info->handle;
 
-	list_add_tail(&port_info->list, &ioc->sas_topology);
+	list_add_tail(&port_info->list, &ioc->l.sas_topology);
 	for (i = 0; i < port_info->num_phys; i++) {
 		struct device *parent;
 
@@ -1079,7 +1079,7 @@
 		 * HBA phys.
 		 */
 		parent = &ioc->sh->shost_gendev;
-		list_for_each_entry(p, &ioc->sas_topology, list) {
+		list_for_each_entry(p, &ioc->l.sas_topology, list) {
 			for (j = 0; j < p->num_phys; j++) {
 				if (port_info->phy_info[i].identify.handle ==
 						p->phy_info[j].attached.handle)
@@ -1202,7 +1202,7 @@
 	 */
 	sh->unique_id = ioc->id;
 
-	INIT_LIST_HEAD(&ioc->sas_topology);
+	INIT_LIST_HEAD(&ioc->l.sas_topology);
 	init_MUTEX(&ioc->sas_mgmt.mutex);
 	init_completion(&ioc->sas_mgmt.done);
 
@@ -1339,7 +1339,7 @@
 
 	sas_remove_host(ioc->sh);
 
-	list_for_each_entry_safe(p, n, &ioc->sas_topology, list) {
+	list_for_each_entry_safe(p, n, &ioc->l.sas_topology, list) {
 		list_del(&p->list);
 		kfree(p);
 	}
drivers/message/fusion/mptscsih.c +25 -4
diff -ru linux-2.6.15-git8/drivers/message/fusion/mptscsih.c linux-2.6.15-git8-mdr/drivers/message/fusion/mptscsih.c
@@ -58,6 +58,7 @@
 #include <linux/workqueue.h>
 
 #include <scsi/scsi.h>
+#include <scsi/scsi_transport_fc.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_host.h>
@@ -893,6 +894,7 @@
  *		when a lun is disable by mid-layer.
  *		Do NOT access the referenced scsi_cmnd structure or
  *		members. Will cause either a paging or NULL ptr error.
+ *		(BUT, BUT, BUT, the code does reference it! - mdr)
  *      @hd: Pointer to a SCSI HOST structure
  *	@vdevice: per device private data
  *
@@ -2559,13 +2561,25 @@
 			hd->cmdPtr = NULL;
 		}
 
-		/* 7. Set flag to force DV and re-read IOC Page 3
+		/* 7. SPI: Set flag to force DV and re-read IOC Page 3
 		 */
 		if (ioc->bus_type == SPI) {
 			ioc->spi_data.forceDv = MPT_SCSICFG_NEED_DV | MPT_SCSICFG_RELOAD_IOC_PG3;
 			ddvtprintk(("Set reload IOC Pg3 Flag\n"));
 		}
 
+		/* 7. FC: Rescan for blocked rports which might have returned.
+		 */
+		else if (ioc->bus_type == FC) {
+			int work_count;
+			unsigned long flags;
+
+			spin_lock_irqsave(&ioc->work_lock,flags);
+			work_count = ++ioc->work_count;
+			spin_unlock_irqrestore(&ioc->work_lock,flags);
+			if (work_count == 1)
+				schedule_work(&ioc->work_task);
+		}
 		dtmprintk((MYIOC_s_WARN_FMT "Post-Reset complete.\n", ioc->name));
 
 	}
@@ -2589,6 +2603,8 @@
 {
 	MPT_SCSI_HOST *hd;
 	u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
+	int work_count;
+	unsigned long flags;
 
 	devtprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
 			ioc->name, event));
@@ -2610,11 +2626,18 @@
 		/* FIXME! */
 		break;
 
+	case MPI_EVENT_RESCAN:				/* 06 */
+		spin_lock_irqsave(&ioc->work_lock,flags);
+		work_count = ++ioc->work_count;
+		spin_unlock_irqrestore(&ioc->work_lock,flags);
+		if (work_count == 1)
+			schedule_work(&ioc->work_task);
+		break;
+
 		/*
 		 *  CHECKME! Don't think we need to do
 		 *  anything for these, but...
 		 */
-	case MPI_EVENT_RESCAN:				/* 06 */
 	case MPI_EVENT_LINK_STATUS_CHANGE:		/* 07 */
 	case MPI_EVENT_LOOP_STATE_CHANGE:		/* 08 */
 		/*
@@ -3954,8 +3977,6 @@
 
 /* Search IOC page 3 to determine if this is hidden physical disk
  */
-/* Search IOC page 3 to determine if this is hidden physical disk
- */
 static int
 mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id)
 {
#1 lore raw

drivers/message/fusion/mptbase.c line 4233

Quoted 3 lines
drivers/message/fusion/mptbase.c +2 -0
+	int			 count=400;
+

Please add a space before and after the '=' Same things in various other places all over the patch.

drivers/message/fusion/mptbase.c line 4291

Quoted 1 line
drivers/message/fusion/mptbase.c +1 -0
+			if (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) {

Please make sure you don't add lines longer than 80 characters.

drivers/message/fusion/mptbase.c line 4296

Quoted 5 lines
drivers/message/fusion/mptbase.c +5 -0
+				if (count-- > 0) {
+					msleep_interruptible(100);
+					goto try_again;
+				}
+				else

should be

				} else

drivers/message/fusion/mptbase.h line 503

Quoted 2 lines
drivers/message/fusion/mptbase.h +2 -0
+#define MPT_RPORT_INFO_FLAGS_REGISTERED		0x01	/* rport registered */
+#define	MPT_RPORT_INFO_FLAGS_MISSING		0x02	/* missing from DevPage0 scan */

should also use a space after the #define, and again lines longer than 80 chars (and quite a few times more later in the patch)

drivers/message/fusion/mptbase.h line 640

Quoted 11 lines
drivers/message/fusion/mptbase.h +10 -0
+
+	union {
 	struct list_head	 sas_topology;
+	struct list_head	 fc_rports;	/* list of wwpn / sdev target / rport ptr */
+	} l;
+
+	spinlock_t		 fc_rport_lock;	/* for all accesses of list and ri flags */
+
+	spinlock_t		 work_lock;
+	int			 work_count;
+	struct work_struct	 work_task;	/* for use by personality, i.e., fc, sas, spi, lan */

Please don't make this a union yet. There's too much work going on in the SAS area and this would cause conflicts all over. We can move to the union later on ones all the major pending changes have settled.

drivers/message/fusion/mptfc.c line 98

Quoted 4 lines
drivers/message/fusion/mptfc.c +4 -0
+int mptfc_slave_alloc(struct scsi_device *device);
+static int mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *));
+static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout);
+static void __devexit mptfc_remove(struct pci_dev *pdev);

Please try to order functions so that forward-prototypes aren't needed. (where easily possible)

drivers/message/fusion/mptfc.c line 162

Quoted 1 line
drivers/message/fusion/mptfc.c +1 -0
+	.get_starget_node_name = NULL,

no need to initialize unused memembers of static structures to zero.

drivers/message/fusion/mptfc.c line 242

Quoted 10 lines
drivers/message/fusion/mptfc.c +10 -0
+	p_p0 = p0_array =  kmalloc(data_sz,GFP_KERNEL);
+	if (!p0_array)
+		goto out;
+	memset((u8 *)p0_array, 0, data_sz);
+
+	data_sz = sizeof(FCDevicePage0_t *) * max_bus * max_targ;
+	p_pp0 = pp0_array = kmalloc(data_sz,GFP_KERNEL);
+	if (!pp0_array)
+		goto out;
+	memset((u8 *)pp0_array, 0, data_sz);

just use kzalloc in those two cases.
also please a whitespace after the , in arguments.

drivers/message/fusion/mptfc.c line 262

Quoted 3 lines
drivers/message/fusion/mptfc.c +3 -0
+		if (hdr.PageLength <= 0)
+			break;
+		else {

no need for the else here, the break already jumps out of the loop. and the lesser indentation should make the code quite a lot more readable aswell.

drivers/message/fusion/mptfc.c line 265

Quoted 3 lines
drivers/message/fusion/mptfc.c +3 -0
+			data_sz = hdr.PageLength * 4;
+			ppage0_alloc = (FCDevicePage0_t *) 
+ 					pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);

mo need to cast the return value of pci_alloc_consistent.

drivers/message/fusion/mptfc.c line 267

Quoted 2 lines
drivers/message/fusion/mptfc.c +2 -0
+			rc = -ENOMEM;
+			if (ppage0_alloc) {

just break out of the loop in the !ppage0_alloc case, reduces indentation again and makes the code fit into 80 columes.

drivers/message/fusion/mptfc.c line 268

Quoted 1 line
drivers/message/fusion/mptfc.c +1 -0
+				memset((u8 *)ppage0_alloc, 0, data_sz);

pci_alloc_consistent returns zeroed memory.

+ if ((rc = mpt_config(ioc, &cfg)) == 0) {
+ le32_to_cpus(ppage0_alloc->PortIdentifier);
+ le32_to_cpus(ppage0_alloc->WWNN.Low);
+ le32_to_cpus(ppage0_alloc->WWNN.High);
+ le32_to_cpus(ppage0_alloc->WWPN.Low);
+ le32_to_cpus(ppage0_alloc->WWPN.High);
+ le16_to_cpus(ppage0_alloc->BBCredit);
+ le16_to_cpus(ppage0_alloc->MaxRxFrameSize);

please never use leXX_to_cpus but always leXX_to_cpu and assign to a separate variable. Assigning hardware endian and host endian values to the same value defeats static typechecking with sparse.

drivers/message/fusion/mptfc.c line 369

Quoted 4 lines
drivers/message/fusion/mptfc.c +4 -0
+		ri = kmalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL);
+ 		if (!ri)
+			return;
+		memset(ri, 0, sizeof(struct mptfc_rport_info));

case use kzalloc, too.

drivers/message/fusion/mptfc.c line 660

Quoted 1 line
drivers/message/fusion/mptfc.c +1 -0
+	INIT_WORK(&ioc->work_task, mptfc_rescan_devices,(void *)ioc);
	could you calls this ioc->fc_rescan_work?  also no need for the
	void cast.

@@ -332,6 +784,7 @@
hd->scandv_wait_done = 0;
hd->last_queue_full = 0;

+ sh->transportt = mptfc_transport_template;
error = scsi_add_host (sh, &ioc->pcidev->dev); if(error) {
dprintk((KERN_ERR MYNAM
@@ -339,7 +792,11 @@
goto out_mptfc_probe;
}

- scsi_scan_host(sh);
+ for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
+ mptfc_init_host_attr(ioc,ii);
+ mptfc_GetFcDevPage0(ioc,ii,mptfc_register_dev);
+ }
+
return 0;

out_mptfc_probe:

drivers/message/fusion/mptfc.c line 61

Quoted 6 lines

+++ linux-2.6.15-git8-mdr/drivers/message/fusion/mptscsih.c 2006-01-12 16:09:08.000000000 -0600

drivers/message/fusion/mptfc.c +1 -0
@@ -58,6 +58,7 @@
 #include <linux/workqueue.h>
 
 #include <scsi/scsi.h>
+#include <scsi/scsi_transport_fc.h>

you must only use transport-class infrastructure in the per-transport files, but not in the common ones.

also don't we need a slave_destroy menthod, as in the SAS hotplug patches? And you should probably remove the scsi_scan_host call as all additions should be done through the FC transport class functionality.

#2 lore raw
Quoted 5 lines · Christoph Hellwig

drivers/message/fusion/mptbase.c line 4233

Quoted 2 lines
drivers/message/fusion/mptbase.c +2 -0
+	int			 count=400;
+

Please add a space before and after the '=' Same things in various other places all over the patch.

OK.

Quoted 4 lines

drivers/message/fusion/mptbase.c line 4291

Quoted 2 lines
drivers/message/fusion/mptbase.c +1 -0
+			if (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) {

Please make sure you don't add lines longer than 80 characters.

This driver is full of lines longer than 80 characters.... I'll see what I can do. I'm not planning on reworking the entire driver to shorten the line lengths but if there are obvious places in my patch, like above, I'll do what I can to conform.

I suspect it should be a separate patch to clean up all the white space / style/long line / other issues in this driver. :)

Quoted 10 lines

drivers/message/fusion/mptbase.c line 4296

Quoted 6 lines
drivers/message/fusion/mptbase.c +5 -0
+				if (count-- > 0) {
+					msleep_interruptible(100);
+					goto try_again;
+				}
+				else

should be

				} else

OK

Quoted 7 lines

drivers/message/fusion/mptbase.h line 503

Quoted 3 lines
drivers/message/fusion/mptbase.h +2 -0
+#define MPT_RPORT_INFO_FLAGS_REGISTERED		0x01	/* rport registered */
+#define	MPT_RPORT_INFO_FLAGS_MISSING		0x02	/* missing from DevPage0 scan */

should also use a space after the #define, and again lines longer than 80 chars (and quite a few times more later in the patch)

OK.

Quoted 17 lines

drivers/message/fusion/mptbase.h line 640

Quoted 12 lines
drivers/message/fusion/mptbase.h +2 -0
+
+	union {
	struct list_head	 sas_topology;
drivers/message/fusion/mptbase.h +8 -0
+	struct list_head	 fc_rports;	/* list of wwpn / sdev target / rport ptr */
+	} l;
+
+	spinlock_t		 fc_rport_lock;	/* for all accesses of list and ri flags */
+
+	spinlock_t		 work_lock;
+	int			 work_count;
+	struct work_struct	 work_task;	/* for use by personality, i.e., fc, sas, spi, lan */

Please don't make this a union yet. There's too much work going on in the SAS area and this would cause conflicts all over. We can move to the union later on ones all the major pending changes have settled.

OK.

Quoted 8 lines

drivers/message/fusion/mptfc.c line 98

Quoted 5 lines
drivers/message/fusion/mptfc.c +4 -0
+int mptfc_slave_alloc(struct scsi_device *device);
+static int mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *));
+static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout);
+static void __devexit mptfc_remove(struct pci_dev *pdev);

Please try to order functions so that forward-prototypes aren't needed. (where easily possible)

In this case, most references are needed for the scsi_host_template or the fc_function_template and I'm chosing to not move those function templates.

Quoted 5 lines

drivers/message/fusion/mptfc.c line 162

Quoted 3 lines
drivers/message/fusion/mptfc.c +1 -0
+	.get_starget_node_name = NULL,

no need to initialize unused memembers of static structures to zero.

Agreed.

Quoted 13 lines

drivers/message/fusion/mptfc.c line 242

Quoted 11 lines
drivers/message/fusion/mptfc.c +10 -0
+	p_p0 = p0_array =  kmalloc(data_sz,GFP_KERNEL);
+	if (!p0_array)
+		goto out;
+	memset((u8 *)p0_array, 0, data_sz);
+
+	data_sz = sizeof(FCDevicePage0_t *) * max_bus * max_targ;
+	p_pp0 = pp0_array = kmalloc(data_sz,GFP_KERNEL);
+	if (!pp0_array)
+		goto out;
+	memset((u8 *)pp0_array, 0, data_sz);

just use kzalloc in those two cases.

OK

Quoted 1 line

also please a whitespace after the , in arguments.

OK

Quoted 8 lines

drivers/message/fusion/mptfc.c line 262

Quoted 4 lines
drivers/message/fusion/mptfc.c +3 -0
+		if (hdr.PageLength <= 0)
+			break;
+		else {

no need for the else here, the break already jumps out of the loop. and the lesser indentation should make the code quite a lot more readable aswell.

Nice catch.

Quoted 6 lines

drivers/message/fusion/mptfc.c line 265

Quoted 4 lines
drivers/message/fusion/mptfc.c +3 -0
+			data_sz = hdr.PageLength * 4;
+			ppage0_alloc = (FCDevicePage0_t *) 
+ 					pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);

mo need to cast the return value of pci_alloc_consistent.

OK

Quoted 7 lines

drivers/message/fusion/mptfc.c line 267

Quoted 4 lines
drivers/message/fusion/mptfc.c +2 -0
+			rc = -ENOMEM;
+			if (ppage0_alloc) {

just break out of the loop in the !ppage0_alloc case, reduces indentation again and makes the code fit into 80 columes.

OK

Quoted 4 lines

drivers/message/fusion/mptfc.c line 268

Quoted 2 lines
drivers/message/fusion/mptfc.c +1 -0
+				memset((u8 *)ppage0_alloc, 0, data_sz);

pci_alloc_consistent returns zeroed memory.

OK

Quoted 10 lines
drivers/message/fusion/mptfc.c +8 -0
+				if ((rc = mpt_config(ioc, &cfg)) == 0) {
+					le32_to_cpus(ppage0_alloc->PortIdentifier);
+					le32_to_cpus(ppage0_alloc->WWNN.Low);
+					le32_to_cpus(ppage0_alloc->WWNN.High);
+					le32_to_cpus(ppage0_alloc->WWPN.Low);
+					le32_to_cpus(ppage0_alloc->WWPN.High);
+					le16_to_cpus(ppage0_alloc->BBCredit);
+					le16_to_cpus(ppage0_alloc->MaxRxFrameSize);
Quoted 3 lines

please never use leXX_to_cpus but always leXX_to_cpu and assign to a separate variable. Assigning hardware endian and host endian values to the same value defeats static typechecking with sparse.

OK

Quoted 8 lines

drivers/message/fusion/mptfc.c line 369

Quoted 5 lines
drivers/message/fusion/mptfc.c +4 -0
+		ri = kmalloc(sizeof(struct mptfc_rport_info), GFP_KERNEL);
+ 		if (!ri)
+			return;
+		memset(ri, 0, sizeof(struct mptfc_rport_info));

case use kzalloc, too.

Quoted 4 lines

drivers/message/fusion/mptfc.c line 660

Quoted 1 line
drivers/message/fusion/mptfc.c +1 -0
+	INIT_WORK(&ioc->work_task, mptfc_rescan_devices,(void *)ioc);
	could you calls this ioc->fc_rescan_work?  also no need for the
	void cast.

I had intended to create a "generic" work_task structure that could be used by all personalities of the driver as, AFAIK, only one will own an hba. However, I understand the point and will change it. If this is important enough to me, I can make it a union later once the dust settles.

Quoted 27 lines
drivers/message/fusion/mptfc.c +6 -1
@@ -332,6 +784,7 @@
 	hd->scandv_wait_done = 0;
 	hd->last_queue_full = 0;
 
+	sh->transportt = mptfc_transport_template;
 	error = scsi_add_host (sh, &ioc->pcidev->dev);
 	if(error) {
 		dprintk((KERN_ERR MYNAM
@@ -339,7 +792,11 @@
 		goto out_mptfc_probe;
 	}
 
-	scsi_scan_host(sh);
+	for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
+		mptfc_init_host_attr(ioc,ii);
+		mptfc_GetFcDevPage0(ioc,ii,mptfc_register_dev);
+	}
+
 	return 0;
 
 out_mptfc_probe:
Quoted 5 lines

+++ linux-2.6.15-git8-mdr/drivers/message/fusion/mptscsih.c 2006-01-12 16:09:08.000000000 -0600

(quoted diff) +0 -0
@@ -58,6 +58,7 @@
 #include <linux/workqueue.h>
 
Quoted 5 lines

Review line 61

Quoted 2 lines
(quoted diff) +1 -0
 #include <scsi/scsi.h>
+#include <scsi/scsi_transport_fc.h>

you must only use transport-class infrastructure in the per-transport files, but not in the common ones.

Another good catch. This was left over from earlier code and not needed.

Quoted 6 lines

also don't we need a slave_destroy menthod, as in the SAS hotplug patches? And you should probably remove the scsi_scan_host call as all additions should be done through the FC transport class functionality.

I looked at your patch to mptsas for slave_destroy. I believe that since the fc_transport retains rport info for the case when the rport returns after destroy, that mptfc should retain its data structure.

I'll think about this for a subsequent patch. It's on my white board! (No software is ever finished!)

scsi_scan_host was a delete, not an insert point....

Quoted 1 line

A revised patch will be forthcoming.

Mike

#3 lore raw
Quoted 4 lines

This driver is full of lines longer than 80 characters.... I'll see what I can do. I'm not planning on reworking the entire driver to shorten the line lengths but if there are obvious places in my patch, like above, I'll do what I can to conform.

sure, no need to fix up existing code - just don't introduce new ones.

Quoted 1 line

I suspect it should be a separate patch to clean up all the white space / style/long line / other issues in this driver. :)

yeah, small cleanup patches are always nice, just don't mix them up with real bugfixes or new features.

Quoted 6 lines
Quoted 2 lines

Please try to order functions so that forward-prototypes aren't needed. (where easily possible)

In this case, most references are needed for the scsi_host_template or the fc_function_template and I'm chosing to not move those function templates.

ok

Quoted 8 lines
Quoted 2 lines
	could you calls this ioc->fc_rescan_work?  also no need for the
	void cast.

I had intended to create a "generic" work_task structure that could be used by all personalities of the driver as, AFAIK, only one will own an hba. However, I understand the point and will change it. If this is important enough to me, I can make it a union later once the dust settles.

ok.

Quoted 3 lines

I looked at your patch to mptsas for slave_destroy. I believe that since the fc_transport retains rport info for the case when the rport returns after destroy, that mptfc should retain its data structure.

indeed, that makes sense.

Quoted 1 line

scsi_scan_host was a delete, not an insert point....

sorry, looks like I misread the patch.

#4 lore raw

OK. I've re-based the code to work with scsi-misc and Christoph's recent patches. I've tested it on my ia64 test mule and it appears to function as did the previous patch.

Perhaps the target will now stand still for a while? :)

Attached is version 1f of the patch. Previous versions should be disregarded.

Mike

drivers/message/fusion/mptbase.c +28 -5
diff -ru scsi-misc-2.6/drivers/message/fusion/mptbase.c scsi-misc-2.6-patched/drivers/message/fusion/mptbase.c
@@ -148,7 +148,6 @@
 static int	WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
 static int	WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
 static int	GetLanConfigPages(MPT_ADAPTER *ioc);
-static int	GetFcPortPage0(MPT_ADAPTER *ioc, int portnum);
 static int	GetIoUnitPage2(MPT_ADAPTER *ioc);
 int		mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
 static int	mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
@@ -1244,6 +1243,8 @@
 	ioc->pcidev = pdev;
 	ioc->diagPending = 0;
 	spin_lock_init(&ioc->diagLock);
+	spin_lock_init(&ioc->fc_rescan_work_lock);
+	spin_lock_init(&ioc->fc_rport_lock);
 	spin_lock_init(&ioc->initializing_hba_lock);
 
 	/* Initialize the event logging.
@@ -1267,6 +1268,10 @@
 	 */
 	INIT_LIST_HEAD(&ioc->configQ);
 
+	/* Initialize the fc rport list head.
+	 */
+	INIT_LIST_HEAD(&ioc->fc_rports);
+
 	/* Find lookup slot. */
 	INIT_LIST_HEAD(&ioc->list);
 	ioc->id = mpt_ids++;
@@ -1879,7 +1884,7 @@
 			 *  (FCPortPage0_t stuff)
 			 */
 			for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
-				(void) GetFcPortPage0(ioc, ii);
+				(void) mptbase_GetFcPortPage0(ioc, ii);
 			}
 
 			if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
@@ -4198,7 +4203,7 @@
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /*
- *	GetFcPortPage0 - Fetch FCPort config Page0.
+ *	mptbase_GetFcPortPage0 - Fetch FCPort config Page0.
  *	@ioc: Pointer to MPT_ADAPTER structure
  *	@portnum: IOC Port number
  *
@@ -4208,8 +4213,8 @@
  *		-EAGAIN if no msg frames currently available
  *		-EFAULT for non-successful reply or no reply (timeout)
  */
-static int
-GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
+int
+mptbase_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum)
 {
 	ConfigPageHeader_t	 hdr;
 	CONFIGPARMS		 cfg;
@@ -4219,6 +4224,8 @@
 	int			 data_sz;
 	int			 copy_sz;
 	int			 rc;
+	int			 count = 400;
+
 
 	/* Get FCPort Page 0 header */
 	hdr.PageVersion = 0;
@@ -4242,6 +4249,8 @@
 	rc = -ENOMEM;
 	ppage0_alloc = (FCPortPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
 	if (ppage0_alloc) {
+
+ try_again:
 		memset((u8 *)ppage0_alloc, 0, data_sz);
 		cfg.physAddr = page0_dma;
 		cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
@@ -4273,6 +4282,19 @@
 			pp0dest->DiscoveredPortsCount = le32_to_cpu(pp0dest->DiscoveredPortsCount);
 			pp0dest->MaxInitiators = le32_to_cpu(pp0dest->MaxInitiators);
 
+			/*
+			 * if still doing discovery,
+			 * hang loose a while until finished
+			 */
+			if (pp0dest->PortState == MPI_FCPORTPAGE0_PORTSTATE_UNKNOWN) {
+				if (count-- > 0) {
+					msleep_interruptible(100);
+					goto try_again;
+				}
+				printk(MYIOC_s_INFO_FMT "Firmware discovery not"
+							" complete.\n",
+						ioc->name);
+			}
 		}
 
 		pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
@@ -6357,6 +6379,7 @@
 EXPORT_SYMBOL(mpt_free_fw_memory);
 EXPORT_SYMBOL(mptbase_sas_persist_operation);
 EXPORT_SYMBOL(mpt_alt_ioc_wait);
+EXPORT_SYMBOL(mptbase_GetFcPortPage0);
 
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
drivers/message/fusion/mptbase.h +26 -2
diff -ru scsi-misc-2.6/drivers/message/fusion/mptbase.h scsi-misc-2.6-patched/drivers/message/fusion/mptbase.h
@@ -76,8 +76,8 @@
 #define COPYRIGHT	"Copyright (c) 1999-2005 " MODULEAUTHOR
 #endif
 
-#define MPT_LINUX_VERSION_COMMON	"3.03.05"
-#define MPT_LINUX_PACKAGE_NAME		"@(#)mptlinux-3.03.05"
+#define MPT_LINUX_VERSION_COMMON	"3.03.06"
+#define MPT_LINUX_PACKAGE_NAME		"@(#)mptlinux-3.03.06"
 #define WHAT_MAGIC_STRING		"@" "(" "#" ")"
 
 #define show_mptmod_ver(s,ver)  \
@@ -499,6 +499,22 @@
 	int		 isRaid;		/* bit field, 1 if RAID */
 }RaidCfgData;
 
+#define MPT_RPORT_INFO_FLAGS_REGISTERED	0x01	/* rport registered */
+#define MPT_RPORT_INFO_FLAGS_MISSING	0x02	/* missing from DevPage0 scan */
+#define MPT_RPORT_INFO_FLAGS_MAPPED_VDEV 0x04	/* target mapped in vdev */
+
+/*
+ * data allocated for each fc rport device
+ */
+struct mptfc_rport_info
+{
+	struct list_head list;
+	struct fc_rport *rport;
+	VirtDevice	*vdev;
+	FCDevicePage0_t pg0;
+	u8		flags;
+};
+
 /*
  *  Adapter Structure - pci_dev specific. Maximum: MPT_MAX_ADAPTERS
  */
@@ -614,6 +630,13 @@
 	struct list_head	 sas_topology;
 	struct mutex		 sas_topology_mutex;
 	MPT_SAS_MGMT		 sas_mgmt;
+
+	struct list_head	 fc_rports;
+	spinlock_t		 fc_rport_lock; /* list and ri flags */
+	spinlock_t		 fc_rescan_work_lock;
+	int			 fc_rescan_work_count;
+	struct work_struct	 fc_rescan_work;
+
 } MPT_ADAPTER;
 
 /*
@@ -1000,6 +1023,7 @@
 extern int	 mpt_findImVolumes(MPT_ADAPTER *ioc);
 extern int	 mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
 extern int	 mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
+extern int	 mptbase_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum);
 extern int	 mpt_alt_ioc_wait(MPT_ADAPTER *ioc);
 
 /*
drivers/message/fusion/mptfc.c +535 -16

647 lines not on this page · raw message

drivers/message/fusion/mptscsih.c +24 -4
diff -ru scsi-misc-2.6/drivers/message/fusion/mptscsih.c scsi-misc-2.6-patched/drivers/message/fusion/mptscsih.c
@@ -893,6 +893,7 @@
  *		when a lun is disable by mid-layer.
  *		Do NOT access the referenced scsi_cmnd structure or
  *		members. Will cause either a paging or NULL ptr error.
+ *		(BUT, BUT, BUT, the code does reference it! - mdr)
  *      @hd: Pointer to a SCSI HOST structure
  *	@vdevice: per device private data
  *
@@ -2557,13 +2558,25 @@
 			hd->cmdPtr = NULL;
 		}
 
-		/* 7. Set flag to force DV and re-read IOC Page 3
+		/* 7. SPI: Set flag to force DV and re-read IOC Page 3
 		 */
 		if (ioc->bus_type == SPI) {
 			ioc->spi_data.forceDv = MPT_SCSICFG_NEED_DV | MPT_SCSICFG_RELOAD_IOC_PG3;
 			ddvtprintk(("Set reload IOC Pg3 Flag\n"));
 		}
 
+		/* 7. FC: Rescan for blocked rports which might have returned.
+		 */
+		else if (ioc->bus_type == FC) {
+			int work_count;
+			unsigned long flags;
+
+			spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
+			work_count = ++ioc->fc_rescan_work_count;
+			spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
+			if (work_count == 1)
+				schedule_work(&ioc->fc_rescan_work);
+		}
 		dtmprintk((MYIOC_s_WARN_FMT "Post-Reset complete.\n", ioc->name));
 
 	}
@@ -2587,6 +2600,8 @@
 {
 	MPT_SCSI_HOST *hd;
 	u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
+	int work_count;
+	unsigned long flags;
 
 	devtprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
 			ioc->name, event));
@@ -2608,11 +2623,18 @@
 		/* FIXME! */
 		break;
 
+	case MPI_EVENT_RESCAN:				/* 06 */
+		spin_lock_irqsave(&ioc->fc_rescan_work_lock, flags);
+		work_count = ++ioc->fc_rescan_work_count;
+		spin_unlock_irqrestore(&ioc->fc_rescan_work_lock, flags);
+		if (work_count == 1)
+			schedule_work(&ioc->fc_rescan_work);
+		break;
+
 		/*
 		 *  CHECKME! Don't think we need to do
 		 *  anything for these, but...
 		 */
-	case MPI_EVENT_RESCAN:				/* 06 */
 	case MPI_EVENT_LINK_STATUS_CHANGE:		/* 07 */
 	case MPI_EVENT_LOOP_STATE_CHANGE:		/* 08 */
 		/*
@@ -3952,8 +3974,6 @@
 
 /* Search IOC page 3 to determine if this is hidden physical disk
  */
-/* Search IOC page 3 to determine if this is hidden physical disk
- */
 static int
 mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id)
 {
#5 lore raw
Quoted 8 lines · Michael Reed

OK. I've re-based the code to work with scsi-misc and Christoph's recent patches. I've tested it on my ia64 test mule and it appears to function as did the previous patch.

Perhaps the target will now stand still for a while? :)

Attached is version 1f of the patch. Previous versions should be disregarded.

looks good.