0001
0002
0003
0004 #include <linux/errno.h>
0005 #include <linux/pci.h>
0006 #include <linux/slab.h>
0007
0008 #include <linux/interrupt.h>
0009 #include <linux/workqueue.h>
0010 #include <linux/spinlock.h>
0011 #include <linux/mempool.h>
0012 #include <scsi/scsi_tcq.h>
0013 #include <linux/ctype.h>
0014
0015 #include "snic_io.h"
0016 #include "snic.h"
0017 #include "cq_enet_desc.h"
0018 #include "snic_fwint.h"
0019
0020
0021
0022
0023 void
0024 snic_handle_link(struct work_struct *work)
0025 {
0026 struct snic *snic = container_of(work, struct snic, link_work);
0027
0028 if (snic->config.xpt_type == SNIC_DAS)
0029 return;
0030
0031 snic->link_status = svnic_dev_link_status(snic->vdev);
0032 snic->link_down_cnt = svnic_dev_link_down_cnt(snic->vdev);
0033 SNIC_HOST_INFO(snic->shost, "Link Event: Link %s.\n",
0034 ((snic->link_status) ? "Up" : "Down"));
0035
0036 SNIC_ASSERT_NOT_IMPL(1);
0037 }
0038
0039
0040
0041
0042
0043
0044 static int
0045 snic_ver_enc(const char *s)
0046 {
0047 int v[4] = {0};
0048 int i = 0, x = 0;
0049 char c;
0050 const char *p = s;
0051
0052
0053 if ((strlen(s) > 15) || (strlen(s) < 7))
0054 goto end;
0055
0056 while ((c = *p++)) {
0057 if (c == '.') {
0058 i++;
0059 continue;
0060 }
0061
0062 if (i > 3 || !isdigit(c))
0063 goto end;
0064
0065 v[i] = v[i] * 10 + (c - '0');
0066 }
0067
0068
0069 for (i = 3; i >= 0; i--)
0070 if (v[i] > 0xff)
0071 goto end;
0072
0073 x |= (v[0] << 24) | v[1] << 16 | v[2] << 8 | v[3];
0074
0075 end:
0076 if (x == 0) {
0077 SNIC_ERR("Invalid version string [%s].\n", s);
0078
0079 return -1;
0080 }
0081
0082 return x;
0083 }
0084
0085
0086
0087
0088
0089
0090
0091 int
0092 snic_queue_exch_ver_req(struct snic *snic)
0093 {
0094 struct snic_req_info *rqi = NULL;
0095 struct snic_host_req *req = NULL;
0096 u32 ver = 0;
0097 int ret = 0;
0098
0099 SNIC_HOST_INFO(snic->shost, "Exch Ver Req Preparing...\n");
0100
0101 rqi = snic_req_init(snic, 0);
0102 if (!rqi) {
0103 SNIC_HOST_ERR(snic->shost, "Init Exch Ver Req failed\n");
0104 ret = -ENOMEM;
0105 goto error;
0106 }
0107
0108 req = rqi_to_req(rqi);
0109
0110
0111 snic_io_hdr_enc(&req->hdr, SNIC_REQ_EXCH_VER, 0, SCSI_NO_TAG,
0112 snic->config.hid, 0, (ulong)rqi);
0113 ver = snic_ver_enc(SNIC_DRV_VERSION);
0114 req->u.exch_ver.drvr_ver = cpu_to_le32(ver);
0115 req->u.exch_ver.os_type = cpu_to_le32(SNIC_OS_LINUX);
0116
0117 snic_handle_untagged_req(snic, rqi);
0118
0119 ret = snic_queue_wq_desc(snic, req, sizeof(*req));
0120 if (ret) {
0121 snic_release_untagged_req(snic, rqi);
0122 SNIC_HOST_ERR(snic->shost,
0123 "Queuing Exch Ver Req failed, err = %d\n",
0124 ret);
0125 goto error;
0126 }
0127
0128 SNIC_HOST_INFO(snic->shost, "Exch Ver Req is issued. ret = %d\n", ret);
0129
0130 error:
0131 return ret;
0132 }
0133
0134
0135
0136
0137 void
0138 snic_io_exch_ver_cmpl_handler(struct snic *snic, struct snic_fw_req *fwreq)
0139 {
0140 struct snic_req_info *rqi = NULL;
0141 struct snic_exch_ver_rsp *exv_cmpl = &fwreq->u.exch_ver_cmpl;
0142 u8 typ, hdr_stat;
0143 u32 cmnd_id, hid, max_sgs;
0144 ulong ctx = 0;
0145 unsigned long flags;
0146
0147 SNIC_HOST_INFO(snic->shost, "Exch Ver Compl Received.\n");
0148 snic_io_hdr_dec(&fwreq->hdr, &typ, &hdr_stat, &cmnd_id, &hid, &ctx);
0149 SNIC_BUG_ON(snic->config.hid != hid);
0150 rqi = (struct snic_req_info *) ctx;
0151
0152 if (hdr_stat) {
0153 SNIC_HOST_ERR(snic->shost,
0154 "Exch Ver Completed w/ err status %d\n",
0155 hdr_stat);
0156
0157 goto exch_cmpl_end;
0158 }
0159
0160 spin_lock_irqsave(&snic->snic_lock, flags);
0161 snic->fwinfo.fw_ver = le32_to_cpu(exv_cmpl->version);
0162 snic->fwinfo.hid = le32_to_cpu(exv_cmpl->hid);
0163 snic->fwinfo.max_concur_ios = le32_to_cpu(exv_cmpl->max_concur_ios);
0164 snic->fwinfo.max_sgs_per_cmd = le32_to_cpu(exv_cmpl->max_sgs_per_cmd);
0165 snic->fwinfo.max_io_sz = le32_to_cpu(exv_cmpl->max_io_sz);
0166 snic->fwinfo.max_tgts = le32_to_cpu(exv_cmpl->max_tgts);
0167 snic->fwinfo.io_tmo = le16_to_cpu(exv_cmpl->io_timeout);
0168
0169 SNIC_HOST_INFO(snic->shost,
0170 "vers %u hid %u max_concur_ios %u max_sgs_per_cmd %u max_io_sz %u max_tgts %u fw tmo %u\n",
0171 snic->fwinfo.fw_ver,
0172 snic->fwinfo.hid,
0173 snic->fwinfo.max_concur_ios,
0174 snic->fwinfo.max_sgs_per_cmd,
0175 snic->fwinfo.max_io_sz,
0176 snic->fwinfo.max_tgts,
0177 snic->fwinfo.io_tmo);
0178
0179 SNIC_HOST_INFO(snic->shost,
0180 "HBA Capabilities = 0x%x\n",
0181 le32_to_cpu(exv_cmpl->hba_cap));
0182
0183
0184 max_sgs = snic->fwinfo.max_sgs_per_cmd;
0185 if (max_sgs && max_sgs < SNIC_MAX_SG_DESC_CNT) {
0186 snic->shost->sg_tablesize = max_sgs;
0187 SNIC_HOST_INFO(snic->shost, "Max SGs set to %d\n",
0188 snic->shost->sg_tablesize);
0189 } else if (max_sgs > snic->shost->sg_tablesize) {
0190 SNIC_HOST_INFO(snic->shost,
0191 "Target type %d Supports Larger Max SGList %d than driver's Max SG List %d.\n",
0192 snic->config.xpt_type, max_sgs,
0193 snic->shost->sg_tablesize);
0194 }
0195
0196 if (snic->shost->can_queue > snic->fwinfo.max_concur_ios)
0197 snic->shost->can_queue = snic->fwinfo.max_concur_ios;
0198
0199 snic->shost->max_sectors = snic->fwinfo.max_io_sz >> 9;
0200 if (snic->fwinfo.wait)
0201 complete(snic->fwinfo.wait);
0202
0203 spin_unlock_irqrestore(&snic->snic_lock, flags);
0204
0205 exch_cmpl_end:
0206 snic_release_untagged_req(snic, rqi);
0207
0208 SNIC_HOST_INFO(snic->shost, "Exch_cmpl Done, hdr_stat %d.\n", hdr_stat);
0209 }
0210
0211
0212
0213
0214
0215
0216 int
0217 snic_get_conf(struct snic *snic)
0218 {
0219 DECLARE_COMPLETION_ONSTACK(wait);
0220 unsigned long flags;
0221 int ret;
0222 int nr_retries = 3;
0223
0224 SNIC_HOST_INFO(snic->shost, "Retrieving snic params.\n");
0225 spin_lock_irqsave(&snic->snic_lock, flags);
0226 memset(&snic->fwinfo, 0, sizeof(snic->fwinfo));
0227 snic->fwinfo.wait = &wait;
0228 spin_unlock_irqrestore(&snic->snic_lock, flags);
0229
0230
0231 msleep(50);
0232
0233
0234
0235
0236
0237 do {
0238 ret = snic_queue_exch_ver_req(snic);
0239 if (ret)
0240 return ret;
0241
0242 wait_for_completion_timeout(&wait, msecs_to_jiffies(2000));
0243 spin_lock_irqsave(&snic->snic_lock, flags);
0244 ret = (snic->fwinfo.fw_ver != 0) ? 0 : -ETIMEDOUT;
0245 if (ret)
0246 SNIC_HOST_ERR(snic->shost,
0247 "Failed to retrieve snic params,\n");
0248
0249
0250 if (ret == 0 || nr_retries == 1)
0251 snic->fwinfo.wait = NULL;
0252
0253 spin_unlock_irqrestore(&snic->snic_lock, flags);
0254 } while (ret && --nr_retries);
0255
0256 return ret;
0257 }