linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chad Dupuis <chad.dupuis@qlogic.com>
To: jbottomley@parallels.com
Cc: giridhar.malavali@qlogic.com, chad.dupuis@qlogic.com,
	andrew.vasquez@qlogic.com, linux-scsi@vger.kernel.org
Subject: [PATCH 02/42] qla2xxx: Add I2C BSG interface.
Date: Wed, 22 Aug 2012 14:20:56 -0400	[thread overview]
Message-ID: <1345659696-3670-3-git-send-email-chad.dupuis@qlogic.com> (raw)
In-Reply-To: <1345659696-3670-1-git-send-email-chad.dupuis@qlogic.com>

From: Joe Carnuccio <joe.carnuccio@qlogic.com>

Add BSG interface to generically access I2C attached devices.

Signed-off-by: Joe Carnuccio <joe.carnuccio@qlogic.com>
Signed-off-by: Chad Dupuis <chad.dupuis@qlogic.com>
---
 drivers/scsi/qla2xxx/qla_bsg.c |   96 ++++++++++++++++++++++++++++++++++++++++
 drivers/scsi/qla2xxx/qla_bsg.h |   10 ++++
 2 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c
index c688838..462ac70 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.c
+++ b/drivers/scsi/qla2xxx/qla_bsg.c
@@ -1560,6 +1560,96 @@ done:
 }
 
 static int
+qla2x00_write_i2c(struct fc_bsg_job *bsg_job)
+{
+	struct Scsi_Host *host = bsg_job->shost;
+	scsi_qla_host_t *vha = shost_priv(host);
+	struct qla_hw_data *ha = vha->hw;
+	int rval = 0;
+	uint8_t bsg[DMA_POOL_SIZE];
+	struct qla_i2c_access *i2c = (void *)bsg;
+	dma_addr_t sfp_dma;
+	uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
+	if (!sfp) {
+		bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
+		    EXT_STATUS_NO_MEMORY;
+		goto done;
+	}
+
+	sg_copy_to_buffer(bsg_job->request_payload.sg_list,
+	    bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
+
+	memcpy(sfp, i2c->buffer, i2c->length);
+	rval = qla2x00_write_sfp(vha, sfp_dma, sfp,
+	    i2c->device, i2c->offset, i2c->length, i2c->option);
+
+	if (rval) {
+		bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
+		    EXT_STATUS_MAILBOX;
+		goto dealloc;
+	}
+
+	bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
+
+dealloc:
+	dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
+
+done:
+	bsg_job->reply_len = sizeof(struct fc_bsg_reply);
+	bsg_job->reply->result = DID_OK << 16;
+	bsg_job->job_done(bsg_job);
+
+	return 0;
+}
+
+static int
+qla2x00_read_i2c(struct fc_bsg_job *bsg_job)
+{
+	struct Scsi_Host *host = bsg_job->shost;
+	scsi_qla_host_t *vha = shost_priv(host);
+	struct qla_hw_data *ha = vha->hw;
+	int rval = 0;
+	uint8_t bsg[DMA_POOL_SIZE];
+	struct qla_i2c_access *i2c = (void *)bsg;
+	dma_addr_t sfp_dma;
+	uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
+	if (!sfp) {
+		bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
+		    EXT_STATUS_NO_MEMORY;
+		goto done;
+	}
+
+	sg_copy_to_buffer(bsg_job->request_payload.sg_list,
+	    bsg_job->request_payload.sg_cnt, i2c, sizeof(*i2c));
+
+	rval = qla2x00_read_sfp(vha, sfp_dma, sfp,
+		i2c->device, i2c->offset, i2c->length, i2c->option);
+
+	if (rval) {
+		bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] =
+		    EXT_STATUS_MAILBOX;
+		goto dealloc;
+	}
+
+	memcpy(i2c->buffer, sfp, i2c->length);
+	sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
+	    bsg_job->reply_payload.sg_cnt, i2c, sizeof(*i2c));
+
+	bsg_job->reply->reply_data.vendor_reply.vendor_rsp[0] = 0;
+
+dealloc:
+	dma_pool_free(ha->s_dma_pool, sfp, sfp_dma);
+
+done:
+	bsg_job->reply_len = sizeof(struct fc_bsg_reply);
+	bsg_job->reply->reply_payload_rcv_len = sizeof(*i2c);
+	bsg_job->reply->result = DID_OK << 16;
+	bsg_job->job_done(bsg_job);
+
+	return 0;
+}
+
+static int
 qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
 {
 	switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
@@ -1596,6 +1686,12 @@ qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
 	case QL_VND_WRITE_FRU_STATUS:
 		return qla2x00_write_fru_status(bsg_job);
 
+	case QL_VND_WRITE_I2C:
+		return qla2x00_write_i2c(bsg_job);
+
+	case QL_VND_READ_I2C:
+		return qla2x00_read_i2c(bsg_job);
+
 	default:
 		bsg_job->reply->result = (DID_ERROR << 16);
 		bsg_job->job_done(bsg_job);
diff --git a/drivers/scsi/qla2xxx/qla_bsg.h b/drivers/scsi/qla2xxx/qla_bsg.h
index 70caa63..1a0ab37 100644
--- a/drivers/scsi/qla2xxx/qla_bsg.h
+++ b/drivers/scsi/qla2xxx/qla_bsg.h
@@ -19,6 +19,8 @@
 #define QL_VND_SET_FRU_VERSION	0x0B
 #define QL_VND_READ_FRU_STATUS	0x0C
 #define QL_VND_WRITE_FRU_STATUS	0x0D
+#define QL_VND_WRITE_I2C	0x10
+#define QL_VND_READ_I2C		0x11
 
 /* BSG Vendor specific subcode returns */
 #define EXT_STATUS_OK			0
@@ -183,4 +185,12 @@ struct qla_status_reg {
 	uint8_t reserved[7];
 } __packed;
 
+struct qla_i2c_access {
+	uint16_t device;
+	uint16_t offset;
+	uint16_t option;
+	uint16_t length;
+	uint8_t  buffer[0x40];
+} __packed;
+
 #endif
-- 
1.7.7


  parent reply	other threads:[~2012-08-22 18:38 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-22 18:20 [PATCH 00/42] qla2xxx: Patches for scsi "misc" branch Chad Dupuis
2012-08-22 18:20 ` [PATCH 01/42] qla2xxx: Bind to ISP8031 devices Chad Dupuis
2012-08-22 18:20 ` Chad Dupuis [this message]
2012-08-22 18:20 ` [PATCH 03/42] qla2xxx: Add check in qla82xx_watchdog for failed hardware state Chad Dupuis
2012-08-22 18:20 ` [PATCH 04/42] qla2xxx: Fix typo in qla2xxx files Chad Dupuis
2012-08-22 18:20 ` [PATCH 05/42] qla2xxx: Display mailbox failure by default Chad Dupuis
2012-08-22 18:21 ` [PATCH 06/42] qla2xxx: Use bitmap to store loop_id's for fcports Chad Dupuis
2012-08-22 18:21 ` [PATCH 07/42] qla2xxx: Implementation of bidirectional Chad Dupuis
2012-08-22 18:21 ` [PATCH 08/42] qla2xxx: Add FW DUMP SIZE sysfs attribute Chad Dupuis
2012-08-22 18:21 ` [PATCH 09/42] qla2xxx: IDC implementation for ISP83xx Chad Dupuis
2012-08-22 18:21 ` [PATCH 10/42] qla2xxx: Implemetation of mctp Chad Dupuis
2012-09-14 16:28   ` James Bottomley
2012-08-22 18:21 ` [PATCH 11/42] qla2xxx: Add bit to identify adapters for thermal temp Chad Dupuis
2012-08-22 18:21 ` [PATCH 12/42] qla2xxx: Changes for ISP83xx loopback support Chad Dupuis
2012-08-22 18:21 ` [PATCH 13/42] qla2xxx: Don't register to legacy interrupt for ISP82xx Chad Dupuis
2012-08-22 18:21 ` [PATCH 14/42] qla2xxx: Update the driver license Chad Dupuis
2012-09-14 16:36   ` James Bottomley
2012-08-22 18:21 ` [PATCH 15/42] qla2xxx: Only enable link up on the correct interrupt event Chad Dupuis
2012-08-22 18:21 ` [PATCH 16/42] qla2xxx: Fix for continuous rescan attempts in arbitrated loop topology Chad Dupuis
2012-08-22 18:21 ` [PATCH 17/42] qla2xxx: Implement beacon support for ISP83xx Chad Dupuis
2012-08-22 18:21 ` [PATCH 18/42] qla2xxx: Fix rval may be used uninitialized in this function warning Chad Dupuis
2012-08-22 18:21 ` [PATCH 19/42] qla2xxx: Perform ROM mbx cmd access only after ISP soft-reset during f/w recovery Chad Dupuis
2012-08-22 18:21 ` [PATCH 20/42] qla2xxx: Wrong PCIe(2.5Gb/s x8) speed in the kerenel message for ISP82xx Chad Dupuis
2012-08-22 18:21 ` [PATCH 21/42] qla2xxx: Dont call nic restart firmware if it is already active and running Chad Dupuis
2012-08-22 18:21 ` [PATCH 22/42] qla2xxx: Use #defines instead of hardcoded values for intr status Chad Dupuis
2012-08-22 18:21 ` [PATCH 23/42] qla2xxx: Remove setting Scsi_host->this_id during adapter probe Chad Dupuis
2012-08-22 18:21 ` [PATCH 24/42] qla2xxx: Ensure PLOGI is sent to Fabric Management-Server upon request Chad Dupuis
2012-08-22 18:21 ` [PATCH 25/42] qla2xxx: Fail initialization if unable to load RISC code Chad Dupuis
2012-08-22 18:21 ` [PATCH 26/42] qla2xxx: Do PCI fundamental reset for ISP83xx Chad Dupuis
2012-08-22 18:21 ` [PATCH 27/42] qla2xxx: Do not restrict the number of NPIV ports " Chad Dupuis
2012-08-22 18:21 ` [PATCH 28/42] qla2xxx: set idc version if function is first one to come Chad Dupuis
2012-08-22 18:21 ` [PATCH 29/42] qla2xxx: Fix description of qla2xmaxqdepth parameter Chad Dupuis
2012-08-22 18:21 ` [PATCH 30/42] qla2xxx: Fix for handling some error conditions in loopback Chad Dupuis
2012-08-22 18:21 ` [PATCH 31/42] qla2xxx: Enclose adapter related calls in adapter check in failed state handler Chad Dupuis
2012-08-22 18:21 ` [PATCH 32/42] qla2xxx: Set Maximum Read Request Size to 4K Chad Dupuis
2012-08-22 18:21 ` [PATCH 33/42] qla2xxx: Get fcal position map should not be called for p2p topology Chad Dupuis
2012-08-22 18:21 ` [PATCH 34/42] qla2xxx: Enable fw attributes for ISP24xx and above Chad Dupuis
2012-08-22 18:21 ` [PATCH 35/42] qla2xxx: Restrict nic core reset to one function for mctp Chad Dupuis
2012-08-22 18:21 ` [PATCH 36/42] qla2xxx: Fix for legacy interrupts for ISP83xx Chad Dupuis
2012-08-22 18:21 ` [PATCH 37/42] qla2xxx: T10 DIF - ISP83xx changes Chad Dupuis
2012-08-22 18:21 ` [PATCH 38/42] qla2xxx: Fix incorrect status reporting on DIF errors Chad Dupuis
2012-08-22 18:21 ` [PATCH 39/42] qla2xxx: Don't toggle RISC interrupt bits after IRQ lines are attached Chad Dupuis
2012-08-22 18:21 ` [PATCH 40/42] qla2xxx: Allow MSI interrupt registration for ISP82xx Chad Dupuis
2012-08-22 18:21 ` [PATCH 41/42] qla2xxx: Use the right field for container_of Chad Dupuis
2012-08-22 18:21 ` [PATCH 42/42] qla2xxx: Update version number to 8.04.00.07-k Chad Dupuis
2012-09-14 17:20   ` James Bottomley
2012-09-14 17:27     ` Chad Dupuis

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=1345659696-3670-3-git-send-email-chad.dupuis@qlogic.com \
    --to=chad.dupuis@qlogic.com \
    --cc=andrew.vasquez@qlogic.com \
    --cc=giridhar.malavali@qlogic.com \
    --cc=jbottomley@parallels.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).