blob: e406eae3e08d5e9ed0ffa4297fa259afc22c635f [file] [log] [blame]
8482e112005-04-17 15:04:54 -05001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
8482e112005-04-17 15:04:54 -05004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
8482e112005-04-17 15:04:54 -05006 */
7#include "qla_def.h"
8
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07009#include <linux/kthread.h>
7aaef272005-04-17 16:32:42 -050010#include <linux/vmalloc.h>
8482e112005-04-17 15:04:54 -050011
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070012int qla24xx_vport_disable(struct fc_vport *, bool);
13
8482e112005-04-17 15:04:54 -050014/* SYSFS attributes --------------------------------------------------------- */
15
16static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080017qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
18 struct bin_attribute *bin_attr,
19 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050020{
21 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
22 struct device, kobj)));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070023 char *rbuf = (char *)ha->fw_dump;
8482e112005-04-17 15:04:54 -050024
25 if (ha->fw_dump_reading == 0)
26 return 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070027 if (off > ha->fw_dump_len)
28 return 0;
29 if (off + count > ha->fw_dump_len)
30 count = ha->fw_dump_len - off;
8482e112005-04-17 15:04:54 -050031
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070032 memcpy(buf, &rbuf[off], count);
8482e112005-04-17 15:04:54 -050033
34 return (count);
35}
36
37static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080038qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
39 struct bin_attribute *bin_attr,
40 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050041{
42 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
43 struct device, kobj)));
44 int reading;
8482e112005-04-17 15:04:54 -050045
46 if (off != 0)
47 return (0);
48
49 reading = simple_strtol(buf, NULL, 10);
50 switch (reading) {
51 case 0:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070052 if (!ha->fw_dump_reading)
53 break;
8482e112005-04-17 15:04:54 -050054
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070055 qla_printk(KERN_INFO, ha,
56 "Firmware dump cleared on (%ld).\n", ha->host_no);
57
58 ha->fw_dump_reading = 0;
59 ha->fw_dumped = 0;
8482e112005-04-17 15:04:54 -050060 break;
61 case 1:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -070062 if (ha->fw_dumped && !ha->fw_dump_reading) {
8482e112005-04-17 15:04:54 -050063 ha->fw_dump_reading = 1;
64
8482e112005-04-17 15:04:54 -050065 qla_printk(KERN_INFO, ha,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070066 "Raw firmware dump ready for read on (%ld).\n",
8482e112005-04-17 15:04:54 -050067 ha->host_no);
8482e112005-04-17 15:04:54 -050068 }
69 break;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070070 case 2:
71 qla2x00_alloc_fw_dump(ha);
72 break;
8482e112005-04-17 15:04:54 -050073 }
74 return (count);
75}
76
77static struct bin_attribute sysfs_fw_dump_attr = {
78 .attr = {
79 .name = "fw_dump",
80 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -050081 },
82 .size = 0,
83 .read = qla2x00_sysfs_read_fw_dump,
84 .write = qla2x00_sysfs_write_fw_dump,
85};
86
87static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +080088qla2x00_sysfs_read_nvram(struct kobject *kobj,
89 struct bin_attribute *bin_attr,
90 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -050091{
92 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
93 struct device, kobj)));
8482e112005-04-17 15:04:54 -050094 unsigned long flags;
8482e112005-04-17 15:04:54 -050095
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -080096 if (!capable(CAP_SYS_ADMIN) || off != 0)
8482e112005-04-17 15:04:54 -050097 return 0;
98
99 /* Read NVRAM. */
100 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700101 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
102 ha->nvram_size);
8482e112005-04-17 15:04:54 -0500103 spin_unlock_irqrestore(&ha->hardware_lock, flags);
104
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800105 return ha->nvram_size;
8482e112005-04-17 15:04:54 -0500106}
107
108static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800109qla2x00_sysfs_write_nvram(struct kobject *kobj,
110 struct bin_attribute *bin_attr,
111 char *buf, loff_t off, size_t count)
8482e112005-04-17 15:04:54 -0500112{
113 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
114 struct device, kobj)));
8482e112005-04-17 15:04:54 -0500115 unsigned long flags;
116 uint16_t cnt;
8482e112005-04-17 15:04:54 -0500117
Andrew Vasquez459c5372005-07-06 10:31:07 -0700118 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
8482e112005-04-17 15:04:54 -0500119 return 0;
120
121 /* Checksum NVRAM. */
Andrew Vasqueze4289242007-07-19 15:05:56 -0700122 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez459c5372005-07-06 10:31:07 -0700123 uint32_t *iter;
124 uint32_t chksum;
125
126 iter = (uint32_t *)buf;
127 chksum = 0;
128 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
129 chksum += le32_to_cpu(*iter++);
130 chksum = ~chksum + 1;
131 *iter = cpu_to_le32(chksum);
132 } else {
133 uint8_t *iter;
134 uint8_t chksum;
135
136 iter = (uint8_t *)buf;
137 chksum = 0;
138 for (cnt = 0; cnt < count - 1; cnt++)
139 chksum += *iter++;
140 chksum = ~chksum + 1;
141 *iter = chksum;
142 }
8482e112005-04-17 15:04:54 -0500143
144 /* Write NVRAM. */
145 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez459c5372005-07-06 10:31:07 -0700146 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
8482e112005-04-17 15:04:54 -0500147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
148
Andrew Vasquez26b8d3482007-01-29 10:22:28 -0800149 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
150
8482e112005-04-17 15:04:54 -0500151 return (count);
152}
153
154static struct bin_attribute sysfs_nvram_attr = {
155 .attr = {
156 .name = "nvram",
157 .mode = S_IRUSR | S_IWUSR,
8482e112005-04-17 15:04:54 -0500158 },
andrew.vasquez@qlogic.com1b3f6362006-01-31 16:05:12 -0800159 .size = 512,
8482e112005-04-17 15:04:54 -0500160 .read = qla2x00_sysfs_read_nvram,
161 .write = qla2x00_sysfs_write_nvram,
162};
163
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800164static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800165qla2x00_sysfs_read_optrom(struct kobject *kobj,
166 struct bin_attribute *bin_attr,
167 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800168{
169 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
170 struct device, kobj)));
171
172 if (ha->optrom_state != QLA_SREADING)
173 return 0;
174 if (off > ha->optrom_size)
175 return 0;
176 if (off + count > ha->optrom_size)
177 count = ha->optrom_size - off;
178
179 memcpy(buf, &ha->optrom_buffer[off], count);
180
181 return count;
182}
183
184static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800185qla2x00_sysfs_write_optrom(struct kobject *kobj,
186 struct bin_attribute *bin_attr,
187 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800188{
189 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
190 struct device, kobj)));
191
192 if (ha->optrom_state != QLA_SWRITING)
193 return -EINVAL;
194 if (off > ha->optrom_size)
195 return -ERANGE;
196 if (off + count > ha->optrom_size)
197 count = ha->optrom_size - off;
198
199 memcpy(&ha->optrom_buffer[off], buf, count);
200
201 return count;
202}
203
204static struct bin_attribute sysfs_optrom_attr = {
205 .attr = {
206 .name = "optrom",
207 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800208 },
209 .size = OPTROM_SIZE_24XX,
210 .read = qla2x00_sysfs_read_optrom,
211 .write = qla2x00_sysfs_write_optrom,
212};
213
214static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800215qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
216 struct bin_attribute *bin_attr,
217 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800218{
219 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
220 struct device, kobj)));
221 int val;
222
223 if (off)
224 return 0;
225
226 if (sscanf(buf, "%d", &val) != 1)
227 return -EINVAL;
228
229 switch (val) {
230 case 0:
231 if (ha->optrom_state != QLA_SREADING &&
232 ha->optrom_state != QLA_SWRITING)
233 break;
234
235 ha->optrom_state = QLA_SWAITING;
236 vfree(ha->optrom_buffer);
237 ha->optrom_buffer = NULL;
238 break;
239 case 1:
240 if (ha->optrom_state != QLA_SWAITING)
241 break;
242
243 ha->optrom_state = QLA_SREADING;
244 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
245 if (ha->optrom_buffer == NULL) {
246 qla_printk(KERN_WARNING, ha,
247 "Unable to allocate memory for optrom retrieval "
248 "(%x).\n", ha->optrom_size);
249
250 ha->optrom_state = QLA_SWAITING;
251 return count;
252 }
253
254 memset(ha->optrom_buffer, 0, ha->optrom_size);
255 ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0,
256 ha->optrom_size);
257 break;
258 case 2:
259 if (ha->optrom_state != QLA_SWAITING)
260 break;
261
262 ha->optrom_state = QLA_SWRITING;
263 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
264 if (ha->optrom_buffer == NULL) {
265 qla_printk(KERN_WARNING, ha,
266 "Unable to allocate memory for optrom update "
267 "(%x).\n", ha->optrom_size);
268
269 ha->optrom_state = QLA_SWAITING;
270 return count;
271 }
272 memset(ha->optrom_buffer, 0, ha->optrom_size);
273 break;
274 case 3:
275 if (ha->optrom_state != QLA_SWRITING)
276 break;
277
278 ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0,
279 ha->optrom_size);
280 break;
281 }
282 return count;
283}
284
285static struct bin_attribute sysfs_optrom_ctl_attr = {
286 .attr = {
287 .name = "optrom_ctl",
288 .mode = S_IWUSR,
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800289 },
290 .size = 0,
291 .write = qla2x00_sysfs_write_optrom_ctl,
292};
293
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800294static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800295qla2x00_sysfs_read_vpd(struct kobject *kobj,
296 struct bin_attribute *bin_attr,
297 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800298{
299 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
300 struct device, kobj)));
301 unsigned long flags;
302
303 if (!capable(CAP_SYS_ADMIN) || off != 0)
304 return 0;
305
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800306 /* Read NVRAM. */
307 spin_lock_irqsave(&ha->hardware_lock, flags);
308 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size);
309 spin_unlock_irqrestore(&ha->hardware_lock, flags);
310
311 return ha->vpd_size;
312}
313
314static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800315qla2x00_sysfs_write_vpd(struct kobject *kobj,
316 struct bin_attribute *bin_attr,
317 char *buf, loff_t off, size_t count)
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800318{
319 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
320 struct device, kobj)));
321 unsigned long flags;
322
323 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
324 return 0;
325
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800326 /* Write NVRAM. */
327 spin_lock_irqsave(&ha->hardware_lock, flags);
328 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
329 spin_unlock_irqrestore(&ha->hardware_lock, flags);
330
331 return count;
332}
333
334static struct bin_attribute sysfs_vpd_attr = {
335 .attr = {
336 .name = "vpd",
337 .mode = S_IRUSR | S_IWUSR,
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -0800338 },
339 .size = 0,
340 .read = qla2x00_sysfs_read_vpd,
341 .write = qla2x00_sysfs_write_vpd,
342};
343
Andrew Vasquez88729e52006-06-23 16:10:50 -0700344static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +0800345qla2x00_sysfs_read_sfp(struct kobject *kobj,
346 struct bin_attribute *bin_attr,
347 char *buf, loff_t off, size_t count)
Andrew Vasquez88729e52006-06-23 16:10:50 -0700348{
349 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
350 struct device, kobj)));
351 uint16_t iter, addr, offset;
352 int rval;
353
354 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
355 return 0;
356
357 addr = 0xa0;
358 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
359 iter++, offset += SFP_BLOCK_SIZE) {
360 if (iter == 4) {
361 /* Skip to next device address. */
362 addr = 0xa2;
363 offset = 0;
364 }
365
366 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
367 SFP_BLOCK_SIZE);
368 if (rval != QLA_SUCCESS) {
369 qla_printk(KERN_WARNING, ha,
370 "Unable to read SFP data (%x/%x/%x).\n", rval,
371 addr, offset);
372 count = 0;
373 break;
374 }
375 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
376 buf += SFP_BLOCK_SIZE;
377 }
378
379 return count;
380}
381
382static struct bin_attribute sysfs_sfp_attr = {
383 .attr = {
384 .name = "sfp",
385 .mode = S_IRUSR | S_IWUSR,
Andrew Vasquez88729e52006-06-23 16:10:50 -0700386 },
387 .size = SFP_DEV_SIZE * 2,
388 .read = qla2x00_sysfs_read_sfp,
389};
390
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700391static struct sysfs_entry {
392 char *name;
393 struct bin_attribute *attr;
394 int is4GBp_only;
395} bin_file_entries[] = {
396 { "fw_dump", &sysfs_fw_dump_attr, },
397 { "nvram", &sysfs_nvram_attr, },
398 { "optrom", &sysfs_optrom_attr, },
399 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
400 { "vpd", &sysfs_vpd_attr, 1 },
401 { "sfp", &sysfs_sfp_attr, 1 },
Randy Dunlap46ddab72006-11-27 09:35:42 -0800402 { NULL },
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700403};
404
8482e112005-04-17 15:04:54 -0500405void
406qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
407{
408 struct Scsi_Host *host = ha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700409 struct sysfs_entry *iter;
410 int ret;
8482e112005-04-17 15:04:54 -0500411
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700412 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700413 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700414 continue;
415
416 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
417 iter->attr);
418 if (ret)
419 qla_printk(KERN_INFO, ha,
420 "Unable to create sysfs %s binary attribute "
421 "(%d).\n", iter->name, ret);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700422 }
8482e112005-04-17 15:04:54 -0500423}
424
425void
426qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
427{
428 struct Scsi_Host *host = ha->host;
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700429 struct sysfs_entry *iter;
8482e112005-04-17 15:04:54 -0500430
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700431 for (iter = bin_file_entries; iter->name; iter++) {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700432 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700433 continue;
434
Andrew Vasquez7914d002006-06-23 16:10:55 -0700435 sysfs_remove_bin_file(&host->shost_gendev.kobj,
Andrew Vasquezf1663ad2006-10-13 09:33:37 -0700436 iter->attr);
Andrew Vasquez7914d002006-06-23 16:10:55 -0700437 }
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800438
439 if (ha->beacon_blink_led == 1)
440 ha->isp_ops.beacon_off(ha);
8482e112005-04-17 15:04:54 -0500441}
442
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700443/* Scsi_Host attributes. */
444
445static ssize_t
446qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
447{
448 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
449}
450
451static ssize_t
452qla2x00_fw_version_show(struct class_device *cdev, char *buf)
453{
454 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
455 char fw_str[30];
456
457 return snprintf(buf, PAGE_SIZE, "%s\n",
458 ha->isp_ops.fw_version_str(ha, fw_str));
459}
460
461static ssize_t
462qla2x00_serial_num_show(struct class_device *cdev, char *buf)
463{
464 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
465 uint32_t sn;
466
467 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
468 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
469 sn % 100000);
470}
471
472static ssize_t
473qla2x00_isp_name_show(struct class_device *cdev, char *buf)
474{
475 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
Andrew Vasquez54333832005-11-09 15:49:04 -0800476 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700477}
478
479static ssize_t
480qla2x00_isp_id_show(struct class_device *cdev, char *buf)
481{
482 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
483 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
484 ha->product_id[0], ha->product_id[1], ha->product_id[2],
485 ha->product_id[3]);
486}
487
488static ssize_t
489qla2x00_model_name_show(struct class_device *cdev, char *buf)
490{
491 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
492 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
493}
494
495static ssize_t
496qla2x00_model_desc_show(struct class_device *cdev, char *buf)
497{
498 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
499 return snprintf(buf, PAGE_SIZE, "%s\n",
500 ha->model_desc ? ha->model_desc: "");
501}
502
503static ssize_t
504qla2x00_pci_info_show(struct class_device *cdev, char *buf)
505{
506 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
507 char pci_info[30];
508
509 return snprintf(buf, PAGE_SIZE, "%s\n",
510 ha->isp_ops.pci_info_str(ha, pci_info));
511}
512
513static ssize_t
514qla2x00_state_show(struct class_device *cdev, char *buf)
515{
516 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
517 int len = 0;
518
519 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
520 atomic_read(&ha->loop_state) == LOOP_DEAD)
521 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
522 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
523 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
524 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
525 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
526 else {
527 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
528
529 switch (ha->current_topology) {
530 case ISP_CFG_NL:
531 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
532 break;
533 case ISP_CFG_FL:
534 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
535 break;
536 case ISP_CFG_N:
537 len += snprintf(buf + len, PAGE_SIZE-len,
538 "N_Port to N_Port\n");
539 break;
540 case ISP_CFG_F:
541 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
542 break;
543 default:
544 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
545 break;
546 }
547 }
548 return len;
549}
550
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700551static ssize_t
552qla2x00_zio_show(struct class_device *cdev, char *buf)
553{
554 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
555 int len = 0;
556
557 switch (ha->zio_mode) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700558 case QLA_ZIO_MODE_6:
559 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
560 break;
561 case QLA_ZIO_DISABLED:
562 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
563 break;
564 }
565 return len;
566}
567
568static ssize_t
569qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
570{
571 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
572 int val = 0;
573 uint16_t zio_mode;
574
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800575 if (!IS_ZIO_SUPPORTED(ha))
576 return -ENOTSUPP;
577
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700578 if (sscanf(buf, "%d", &val) != 1)
579 return -EINVAL;
580
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800581 if (val)
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700582 zio_mode = QLA_ZIO_MODE_6;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -0800583 else
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700584 zio_mode = QLA_ZIO_DISABLED;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700585
586 /* Update per-hba values and queue a reset. */
587 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
588 ha->zio_mode = zio_mode;
589 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
590 }
591 return strlen(buf);
592}
593
594static ssize_t
595qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
596{
597 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
598
599 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
600}
601
602static ssize_t
603qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
604 size_t count)
605{
606 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
607 int val = 0;
608 uint16_t zio_timer;
609
610 if (sscanf(buf, "%d", &val) != 1)
611 return -EINVAL;
612 if (val > 25500 || val < 100)
613 return -ERANGE;
614
615 zio_timer = (uint16_t)(val / 100);
616 ha->zio_timer = zio_timer;
617
618 return strlen(buf);
619}
620
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800621static ssize_t
622qla2x00_beacon_show(struct class_device *cdev, char *buf)
623{
624 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
625 int len = 0;
626
627 if (ha->beacon_blink_led)
628 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
629 else
630 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
631 return len;
632}
633
634static ssize_t
635qla2x00_beacon_store(struct class_device *cdev, const char *buf,
636 size_t count)
637{
638 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
639 int val = 0;
640 int rval;
641
642 if (IS_QLA2100(ha) || IS_QLA2200(ha))
643 return -EPERM;
644
645 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
646 qla_printk(KERN_WARNING, ha,
647 "Abort ISP active -- ignoring beacon request.\n");
648 return -EBUSY;
649 }
650
651 if (sscanf(buf, "%d", &val) != 1)
652 return -EINVAL;
653
654 if (val)
655 rval = ha->isp_ops.beacon_on(ha);
656 else
657 rval = ha->isp_ops.beacon_off(ha);
658
659 if (rval != QLA_SUCCESS)
660 count = 0;
661
662 return count;
663}
664
Andrew Vasquez30c47662007-01-29 10:22:21 -0800665static ssize_t
666qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
667{
668 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
669
670 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
671 ha->bios_revision[0]);
672}
673
674static ssize_t
675qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
676{
677 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
678
679 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
680 ha->efi_revision[0]);
681}
682
683static ssize_t
684qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
685{
686 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
687
688 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
689 ha->fcode_revision[0]);
690}
691
692static ssize_t
693qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
694{
695 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
696
697 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
698 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
699 ha->fw_revision[3]);
700}
701
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700702static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
703 NULL);
704static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
705static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
706static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
707static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
708static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
709static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
710static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
711static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700712static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
713 qla2x00_zio_store);
714static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
715 qla2x00_zio_timer_store);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800716static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
717 qla2x00_beacon_store);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800718static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
719 qla2x00_optrom_bios_version_show, NULL);
720static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
721 qla2x00_optrom_efi_version_show, NULL);
722static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
723 qla2x00_optrom_fcode_version_show, NULL);
724static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
725 qla2x00_optrom_fw_version_show, NULL);
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700726
727struct class_device_attribute *qla2x00_host_attrs[] = {
728 &class_device_attr_driver_version,
729 &class_device_attr_fw_version,
730 &class_device_attr_serial_num,
731 &class_device_attr_isp_name,
732 &class_device_attr_isp_id,
733 &class_device_attr_model_name,
734 &class_device_attr_model_desc,
735 &class_device_attr_pci_info,
736 &class_device_attr_state,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -0700737 &class_device_attr_zio,
738 &class_device_attr_zio_timer,
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -0800739 &class_device_attr_beacon,
Andrew Vasquez30c47662007-01-29 10:22:21 -0800740 &class_device_attr_optrom_bios_version,
741 &class_device_attr_optrom_efi_version,
742 &class_device_attr_optrom_fcode_version,
743 &class_device_attr_optrom_fw_version,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700744 NULL,
745};
746
8482e112005-04-17 15:04:54 -0500747/* Host attributes. */
748
749static void
750qla2x00_get_host_port_id(struct Scsi_Host *shost)
751{
752 scsi_qla_host_t *ha = to_qla_host(shost);
753
754 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
755 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
756}
757
758static void
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800759qla2x00_get_host_speed(struct Scsi_Host *shost)
760{
761 scsi_qla_host_t *ha = to_qla_host(shost);
762 uint32_t speed = 0;
763
764 switch (ha->link_data_rate) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700765 case PORT_SPEED_1GB:
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800766 speed = 1;
767 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700768 case PORT_SPEED_2GB:
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800769 speed = 2;
770 break;
Andrew Vasquezd8b45212006-10-02 12:00:43 -0700771 case PORT_SPEED_4GB:
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -0800772 speed = 4;
773 break;
774 }
775 fc_host_speed(shost) = speed;
776}
777
778static void
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -0800779qla2x00_get_host_port_type(struct Scsi_Host *shost)
780{
781 scsi_qla_host_t *ha = to_qla_host(shost);
782 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
783
784 switch (ha->current_topology) {
785 case ISP_CFG_NL:
786 port_type = FC_PORTTYPE_LPORT;
787 break;
788 case ISP_CFG_FL:
789 port_type = FC_PORTTYPE_NLPORT;
790 break;
791 case ISP_CFG_N:
792 port_type = FC_PORTTYPE_PTP;
793 break;
794 case ISP_CFG_F:
795 port_type = FC_PORTTYPE_NPORT;
796 break;
797 }
798 fc_host_port_type(shost) = port_type;
799}
800
801static void
8482e112005-04-17 15:04:54 -0500802qla2x00_get_starget_node_name(struct scsi_target *starget)
803{
804 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
805 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500806 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700807 u64 node_name = 0;
8482e112005-04-17 15:04:54 -0500808
bdf79622005-04-17 15:06:53 -0500809 list_for_each_entry(fcport, &ha->fcports, list) {
810 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700811 node_name = wwn_to_u64(fcport->node_name);
bdf79622005-04-17 15:06:53 -0500812 break;
813 }
814 }
815
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700816 fc_starget_node_name(starget) = node_name;
8482e112005-04-17 15:04:54 -0500817}
818
819static void
820qla2x00_get_starget_port_name(struct scsi_target *starget)
821{
822 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
823 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500824 fc_port_t *fcport;
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700825 u64 port_name = 0;
8482e112005-04-17 15:04:54 -0500826
bdf79622005-04-17 15:06:53 -0500827 list_for_each_entry(fcport, &ha->fcports, list) {
828 if (starget->id == fcport->os_target_id) {
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700829 port_name = wwn_to_u64(fcport->port_name);
bdf79622005-04-17 15:06:53 -0500830 break;
831 }
832 }
833
Andrew Vasquezf8b02a82005-08-31 15:21:20 -0700834 fc_starget_port_name(starget) = port_name;
8482e112005-04-17 15:04:54 -0500835}
836
837static void
838qla2x00_get_starget_port_id(struct scsi_target *starget)
839{
840 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
841 scsi_qla_host_t *ha = to_qla_host(host);
bdf79622005-04-17 15:06:53 -0500842 fc_port_t *fcport;
843 uint32_t port_id = ~0U;
8482e112005-04-17 15:04:54 -0500844
bdf79622005-04-17 15:06:53 -0500845 list_for_each_entry(fcport, &ha->fcports, list) {
846 if (starget->id == fcport->os_target_id) {
847 port_id = fcport->d_id.b.domain << 16 |
848 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
849 break;
850 }
851 }
852
8482e112005-04-17 15:04:54 -0500853 fc_starget_port_id(starget) = port_id;
854}
855
856static void
857qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
858{
bdf79622005-04-17 15:06:53 -0500859 struct Scsi_Host *host = rport_to_shost(rport);
860 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500861
862 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
863}
864
865static void
866qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
867{
bdf79622005-04-17 15:06:53 -0500868 struct Scsi_Host *host = rport_to_shost(rport);
869 scsi_qla_host_t *ha = to_qla_host(host);
8482e112005-04-17 15:04:54 -0500870
871 if (timeout)
872 ha->port_down_retry_count = timeout;
873 else
874 ha->port_down_retry_count = 1;
875
876 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
877}
878
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700879static int
880qla2x00_issue_lip(struct Scsi_Host *shost)
881{
882 scsi_qla_host_t *ha = to_qla_host(shost);
883
884 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
885 return 0;
886}
887
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800888static struct fc_host_statistics *
889qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
890{
891 scsi_qla_host_t *ha = to_qla_host(shost);
892 int rval;
893 uint16_t mb_stat[1];
894 link_stat_t stat_buf;
895 struct fc_host_statistics *pfc_host_stat;
896
Andrew Vasquez178779a2007-01-29 10:22:25 -0800897 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800898 pfc_host_stat = &ha->fc_host_stat;
899 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
900
Andrew Vasqueze4289242007-07-19 15:05:56 -0700901 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800902 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
903 sizeof(stat_buf) / 4, mb_stat);
Andrew Vasquez178779a2007-01-29 10:22:25 -0800904 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
905 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
906 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
907 !ha->dpc_active) {
908 /* Must be in a 'READY' state for statistics retrieval. */
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800909 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
910 mb_stat);
911 }
Andrew Vasquez178779a2007-01-29 10:22:25 -0800912
913 if (rval != QLA_SUCCESS)
914 goto done;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800915
916 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
917 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
918 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
919 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
920 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
921 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
Andrew Vasquez178779a2007-01-29 10:22:25 -0800922done:
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -0800923 return pfc_host_stat;
924}
925
Andrew Vasquez1620f7c2006-10-02 12:00:44 -0700926static void
927qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
928{
929 scsi_qla_host_t *ha = to_qla_host(shost);
930
931 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
932}
933
Andrew Vasqueza740a3f2006-10-02 12:00:45 -0700934static void
935qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
936{
937 scsi_qla_host_t *ha = to_qla_host(shost);
938
939 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
940}
941
Andrew Vasquez90991c82006-10-02 12:00:46 -0700942static void
943qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
944{
945 scsi_qla_host_t *ha = to_qla_host(shost);
946 u64 node_name;
947
948 if (ha->device_flags & SWITCH_FOUND)
949 node_name = wwn_to_u64(ha->fabric_node_name);
950 else
951 node_name = wwn_to_u64(ha->node_name);
952
953 fc_host_fabric_name(shost) = node_name;
954}
955
Andrew Vasquez7047fcd2006-10-02 12:00:47 -0700956static void
957qla2x00_get_host_port_state(struct Scsi_Host *shost)
958{
959 scsi_qla_host_t *ha = to_qla_host(shost);
960
961 if (!ha->flags.online)
962 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
963 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
964 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
965 else
966 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
967}
968
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700969static int
970qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
971{
972 int ret = 0;
973 scsi_qla_host_t *ha = (scsi_qla_host_t *) fc_vport->shost->hostdata;
974 scsi_qla_host_t *vha;
975
976 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
977 if (ret) {
978 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
979 "status %x\n", ret));
980 return (ret);
981 }
982
983 vha = qla24xx_create_vhost(fc_vport);
984 if (vha == NULL) {
985 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
986 vha));
987 return FC_VPORT_FAILED;
988 }
989 if (disable) {
990 atomic_set(&vha->vp_state, VP_OFFLINE);
991 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
992 } else
993 atomic_set(&vha->vp_state, VP_FAILED);
994
995 /* ready to create vport */
996 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
997
998 /* initialized vport states */
999 atomic_set(&vha->loop_state, LOOP_DOWN);
1000 vha->vp_err_state= VP_ERR_PORTDWN;
1001 vha->vp_prev_err_state= VP_ERR_UNKWN;
1002 /* Check if physical ha port is Up */
1003 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1004 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1005 /* Don't retry or attempt login of this virtual port */
1006 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1007 vha->host_no));
1008 atomic_set(&vha->loop_state, LOOP_DEAD);
1009 if (!disable)
1010 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1011 }
1012
1013 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1014 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1015 vha->host_no, vha->vp_idx));
1016 goto vport_create_failed_2;
1017 }
1018
1019 /* initialize attributes */
1020 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1021 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1022 fc_host_supported_classes(vha->host) =
1023 fc_host_supported_classes(ha->host);
1024 fc_host_supported_speeds(vha->host) =
1025 fc_host_supported_speeds(ha->host);
1026
1027 qla24xx_vport_disable(fc_vport, disable);
1028
1029 return 0;
1030vport_create_failed_2:
1031 qla24xx_disable_vp(vha);
1032 qla24xx_deallocate_vp_id(vha);
1033 kfree(vha->port_name);
1034 kfree(vha->node_name);
1035 scsi_host_put(vha->host);
1036 return FC_VPORT_FAILED;
1037}
1038
1039int
1040qla24xx_vport_delete(struct fc_vport *fc_vport)
1041{
1042 scsi_qla_host_t *ha = (scsi_qla_host_t *) fc_vport->shost->hostdata;
1043 scsi_qla_host_t *vha = fc_vport->dd_data;
1044
1045 qla24xx_disable_vp(vha);
1046 qla24xx_deallocate_vp_id(vha);
1047
1048 down(&ha->vport_sem);
1049 ha->cur_vport_count--;
1050 clear_bit(vha->vp_idx, (unsigned long *)ha->vp_idx_map);
1051 up(&ha->vport_sem);
1052
1053 kfree(vha->node_name);
1054 kfree(vha->port_name);
1055
1056 if (vha->timer_active) {
1057 qla2x00_vp_stop_timer(vha);
1058 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1059 "has stopped\n",
1060 vha->host_no, vha->vp_idx, vha));
1061 }
1062
1063 fc_remove_host(vha->host);
1064
1065 scsi_remove_host(vha->host);
1066
1067 scsi_host_put(vha->host);
1068
1069 return 0;
1070}
1071
1072int
1073qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1074{
1075 scsi_qla_host_t *vha = fc_vport->dd_data;
1076
1077 if (disable)
1078 qla24xx_disable_vp(vha);
1079 else
1080 qla24xx_enable_vp(vha);
1081
1082 return 0;
1083}
1084
Andrew Vasquez1c97a122005-04-21 16:13:36 -04001085struct fc_function_template qla2xxx_transport_functions = {
8482e112005-04-17 15:04:54 -05001086
1087 .show_host_node_name = 1,
1088 .show_host_port_name = 1,
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001089 .show_host_supported_classes = 1,
1090
8482e112005-04-17 15:04:54 -05001091 .get_host_port_id = qla2x00_get_host_port_id,
1092 .show_host_port_id = 1,
andrew.vasquez@qlogic.com04414012006-01-31 16:04:51 -08001093 .get_host_speed = qla2x00_get_host_speed,
1094 .show_host_speed = 1,
andrew.vasquez@qlogic.com8d067622006-01-31 16:04:56 -08001095 .get_host_port_type = qla2x00_get_host_port_type,
1096 .show_host_port_type = 1,
Andrew Vasquez1620f7c2006-10-02 12:00:44 -07001097 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1098 .show_host_symbolic_name = 1,
Andrew Vasqueza740a3f2006-10-02 12:00:45 -07001099 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1100 .show_host_system_hostname = 1,
Andrew Vasquez90991c82006-10-02 12:00:46 -07001101 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1102 .show_host_fabric_name = 1,
Andrew Vasquez7047fcd2006-10-02 12:00:47 -07001103 .get_host_port_state = qla2x00_get_host_port_state,
1104 .show_host_port_state = 1,
8482e112005-04-17 15:04:54 -05001105
bdf79622005-04-17 15:06:53 -05001106 .dd_fcrport_size = sizeof(struct fc_port *),
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001107 .show_rport_supported_classes = 1,
8482e112005-04-17 15:04:54 -05001108
1109 .get_starget_node_name = qla2x00_get_starget_node_name,
1110 .show_starget_node_name = 1,
1111 .get_starget_port_name = qla2x00_get_starget_port_name,
1112 .show_starget_port_name = 1,
1113 .get_starget_port_id = qla2x00_get_starget_port_id,
1114 .show_starget_port_id = 1,
1115
1116 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1117 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1118 .show_rport_dev_loss_tmo = 1,
1119
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001120 .issue_fc_host_lip = qla2x00_issue_lip,
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08001121 .get_fc_host_stats = qla2x00_get_fc_host_stats,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001122
1123 .vport_create = qla24xx_vport_create,
1124 .vport_disable = qla24xx_vport_disable,
1125 .vport_delete = qla24xx_vport_delete,
1126};
1127
1128struct fc_function_template qla2xxx_transport_vport_functions = {
1129
1130 .show_host_node_name = 1,
1131 .show_host_port_name = 1,
1132 .show_host_supported_classes = 1,
1133
1134 .get_host_port_id = qla2x00_get_host_port_id,
1135 .show_host_port_id = 1,
1136 .get_host_speed = qla2x00_get_host_speed,
1137 .show_host_speed = 1,
1138 .get_host_port_type = qla2x00_get_host_port_type,
1139 .show_host_port_type = 1,
1140 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1141 .show_host_symbolic_name = 1,
1142 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1143 .show_host_system_hostname = 1,
1144 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1145 .show_host_fabric_name = 1,
1146 .get_host_port_state = qla2x00_get_host_port_state,
1147 .show_host_port_state = 1,
1148
1149 .dd_fcrport_size = sizeof(struct fc_port *),
1150 .show_rport_supported_classes = 1,
1151
1152 .get_starget_node_name = qla2x00_get_starget_node_name,
1153 .show_starget_node_name = 1,
1154 .get_starget_port_name = qla2x00_get_starget_port_name,
1155 .show_starget_port_name = 1,
1156 .get_starget_port_id = qla2x00_get_starget_port_id,
1157 .show_starget_port_id = 1,
1158
1159 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1160 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1161 .show_rport_dev_loss_tmo = 1,
1162
1163 .issue_fc_host_lip = qla2x00_issue_lip,
1164 .get_fc_host_stats = qla2x00_get_fc_host_stats,
8482e112005-04-17 15:04:54 -05001165};
1166
8482e112005-04-17 15:04:54 -05001167void
1168qla2x00_init_host_attr(scsi_qla_host_t *ha)
1169{
andrew.vasquez@qlogic.comdad9c8c2006-01-13 17:04:49 -08001170 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1171 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001172 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001173 fc_host_max_npiv_vports(ha->host) = MAX_NUM_VPORT_FABRIC;
1174 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
8482e112005-04-17 15:04:54 -05001175}