qla_attr.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2005 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/kthread.h>
  9. #include <linux/vmalloc.h>
  10. int qla24xx_vport_disable(struct fc_vport *, bool);
  11. /* SYSFS attributes --------------------------------------------------------- */
  12. static ssize_t
  13. qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
  14. struct bin_attribute *bin_attr,
  15. char *buf, loff_t off, size_t count)
  16. {
  17. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  18. struct device, kobj)));
  19. char *rbuf = (char *)ha->fw_dump;
  20. if (ha->fw_dump_reading == 0)
  21. return 0;
  22. if (off > ha->fw_dump_len)
  23. return 0;
  24. if (off + count > ha->fw_dump_len)
  25. count = ha->fw_dump_len - off;
  26. memcpy(buf, &rbuf[off], count);
  27. return (count);
  28. }
  29. static ssize_t
  30. qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
  31. struct bin_attribute *bin_attr,
  32. char *buf, loff_t off, size_t count)
  33. {
  34. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  35. struct device, kobj)));
  36. int reading;
  37. if (off != 0)
  38. return (0);
  39. reading = simple_strtol(buf, NULL, 10);
  40. switch (reading) {
  41. case 0:
  42. if (!ha->fw_dump_reading)
  43. break;
  44. qla_printk(KERN_INFO, ha,
  45. "Firmware dump cleared on (%ld).\n", ha->host_no);
  46. ha->fw_dump_reading = 0;
  47. ha->fw_dumped = 0;
  48. break;
  49. case 1:
  50. if (ha->fw_dumped && !ha->fw_dump_reading) {
  51. ha->fw_dump_reading = 1;
  52. qla_printk(KERN_INFO, ha,
  53. "Raw firmware dump ready for read on (%ld).\n",
  54. ha->host_no);
  55. }
  56. break;
  57. case 2:
  58. qla2x00_alloc_fw_dump(ha);
  59. break;
  60. }
  61. return (count);
  62. }
  63. static struct bin_attribute sysfs_fw_dump_attr = {
  64. .attr = {
  65. .name = "fw_dump",
  66. .mode = S_IRUSR | S_IWUSR,
  67. },
  68. .size = 0,
  69. .read = qla2x00_sysfs_read_fw_dump,
  70. .write = qla2x00_sysfs_write_fw_dump,
  71. };
  72. static ssize_t
  73. qla2x00_sysfs_read_nvram(struct kobject *kobj,
  74. struct bin_attribute *bin_attr,
  75. char *buf, loff_t off, size_t count)
  76. {
  77. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  78. struct device, kobj)));
  79. int size = ha->nvram_size;
  80. char *nvram_cache = ha->nvram;
  81. if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
  82. return 0;
  83. if (off + count > size) {
  84. size -= off;
  85. count = size;
  86. }
  87. /* Read NVRAM data from cache. */
  88. memcpy(buf, &nvram_cache[off], count);
  89. return count;
  90. }
  91. static ssize_t
  92. qla2x00_sysfs_write_nvram(struct kobject *kobj,
  93. struct bin_attribute *bin_attr,
  94. char *buf, loff_t off, size_t count)
  95. {
  96. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  97. struct device, kobj)));
  98. unsigned long flags;
  99. uint16_t cnt;
  100. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
  101. return 0;
  102. /* Checksum NVRAM. */
  103. if (IS_FWI2_CAPABLE(ha)) {
  104. uint32_t *iter;
  105. uint32_t chksum;
  106. iter = (uint32_t *)buf;
  107. chksum = 0;
  108. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  109. chksum += le32_to_cpu(*iter++);
  110. chksum = ~chksum + 1;
  111. *iter = cpu_to_le32(chksum);
  112. } else {
  113. uint8_t *iter;
  114. uint8_t chksum;
  115. iter = (uint8_t *)buf;
  116. chksum = 0;
  117. for (cnt = 0; cnt < count - 1; cnt++)
  118. chksum += *iter++;
  119. chksum = ~chksum + 1;
  120. *iter = chksum;
  121. }
  122. /* Write NVRAM. */
  123. spin_lock_irqsave(&ha->hardware_lock, flags);
  124. ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
  125. ha->isp_ops->read_nvram(ha, (uint8_t *)&ha->nvram, ha->nvram_base,
  126. count);
  127. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  128. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  129. return (count);
  130. }
  131. static struct bin_attribute sysfs_nvram_attr = {
  132. .attr = {
  133. .name = "nvram",
  134. .mode = S_IRUSR | S_IWUSR,
  135. },
  136. .size = 512,
  137. .read = qla2x00_sysfs_read_nvram,
  138. .write = qla2x00_sysfs_write_nvram,
  139. };
  140. static ssize_t
  141. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  142. struct bin_attribute *bin_attr,
  143. char *buf, loff_t off, size_t count)
  144. {
  145. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  146. struct device, kobj)));
  147. if (ha->optrom_state != QLA_SREADING)
  148. return 0;
  149. if (off > ha->optrom_size)
  150. return 0;
  151. if (off + count > ha->optrom_size)
  152. count = ha->optrom_size - off;
  153. memcpy(buf, &ha->optrom_buffer[off], count);
  154. return count;
  155. }
  156. static ssize_t
  157. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  158. struct bin_attribute *bin_attr,
  159. char *buf, loff_t off, size_t count)
  160. {
  161. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  162. struct device, kobj)));
  163. if (ha->optrom_state != QLA_SWRITING)
  164. return -EINVAL;
  165. if (off > ha->optrom_size)
  166. return -ERANGE;
  167. if (off + count > ha->optrom_size)
  168. count = ha->optrom_size - off;
  169. memcpy(&ha->optrom_buffer[off], buf, count);
  170. return count;
  171. }
  172. static struct bin_attribute sysfs_optrom_attr = {
  173. .attr = {
  174. .name = "optrom",
  175. .mode = S_IRUSR | S_IWUSR,
  176. },
  177. .size = 0,
  178. .read = qla2x00_sysfs_read_optrom,
  179. .write = qla2x00_sysfs_write_optrom,
  180. };
  181. static ssize_t
  182. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  183. struct bin_attribute *bin_attr,
  184. char *buf, loff_t off, size_t count)
  185. {
  186. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  187. struct device, kobj)));
  188. int val;
  189. if (off)
  190. return 0;
  191. if (sscanf(buf, "%d", &val) != 1)
  192. return -EINVAL;
  193. switch (val) {
  194. case 0:
  195. if (ha->optrom_state != QLA_SREADING &&
  196. ha->optrom_state != QLA_SWRITING)
  197. break;
  198. ha->optrom_state = QLA_SWAITING;
  199. vfree(ha->optrom_buffer);
  200. ha->optrom_buffer = NULL;
  201. break;
  202. case 1:
  203. if (ha->optrom_state != QLA_SWAITING)
  204. break;
  205. ha->optrom_state = QLA_SREADING;
  206. ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
  207. if (ha->optrom_buffer == NULL) {
  208. qla_printk(KERN_WARNING, ha,
  209. "Unable to allocate memory for optrom retrieval "
  210. "(%x).\n", ha->optrom_size);
  211. ha->optrom_state = QLA_SWAITING;
  212. return count;
  213. }
  214. memset(ha->optrom_buffer, 0, ha->optrom_size);
  215. ha->isp_ops->read_optrom(ha, ha->optrom_buffer, 0,
  216. ha->optrom_size);
  217. break;
  218. case 2:
  219. if (ha->optrom_state != QLA_SWAITING)
  220. break;
  221. ha->optrom_state = QLA_SWRITING;
  222. ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
  223. if (ha->optrom_buffer == NULL) {
  224. qla_printk(KERN_WARNING, ha,
  225. "Unable to allocate memory for optrom update "
  226. "(%x).\n", ha->optrom_size);
  227. ha->optrom_state = QLA_SWAITING;
  228. return count;
  229. }
  230. memset(ha->optrom_buffer, 0, ha->optrom_size);
  231. break;
  232. case 3:
  233. if (ha->optrom_state != QLA_SWRITING)
  234. break;
  235. ha->isp_ops->write_optrom(ha, ha->optrom_buffer, 0,
  236. ha->optrom_size);
  237. break;
  238. }
  239. return count;
  240. }
  241. static struct bin_attribute sysfs_optrom_ctl_attr = {
  242. .attr = {
  243. .name = "optrom_ctl",
  244. .mode = S_IWUSR,
  245. },
  246. .size = 0,
  247. .write = qla2x00_sysfs_write_optrom_ctl,
  248. };
  249. static ssize_t
  250. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  251. struct bin_attribute *bin_attr,
  252. char *buf, loff_t off, size_t count)
  253. {
  254. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  255. struct device, kobj)));
  256. int size = ha->vpd_size;
  257. char *vpd_cache = ha->vpd;
  258. if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
  259. return 0;
  260. if (off + count > size) {
  261. size -= off;
  262. count = size;
  263. }
  264. /* Read NVRAM data from cache. */
  265. memcpy(buf, &vpd_cache[off], count);
  266. return count;
  267. }
  268. static ssize_t
  269. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  270. struct bin_attribute *bin_attr,
  271. char *buf, loff_t off, size_t count)
  272. {
  273. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  274. struct device, kobj)));
  275. unsigned long flags;
  276. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
  277. return 0;
  278. /* Write NVRAM. */
  279. spin_lock_irqsave(&ha->hardware_lock, flags);
  280. ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
  281. ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  282. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  283. return count;
  284. }
  285. static struct bin_attribute sysfs_vpd_attr = {
  286. .attr = {
  287. .name = "vpd",
  288. .mode = S_IRUSR | S_IWUSR,
  289. },
  290. .size = 0,
  291. .read = qla2x00_sysfs_read_vpd,
  292. .write = qla2x00_sysfs_write_vpd,
  293. };
  294. static ssize_t
  295. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  296. struct bin_attribute *bin_attr,
  297. char *buf, loff_t off, size_t count)
  298. {
  299. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  300. struct device, kobj)));
  301. uint16_t iter, addr, offset;
  302. int rval;
  303. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  304. return 0;
  305. addr = 0xa0;
  306. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  307. iter++, offset += SFP_BLOCK_SIZE) {
  308. if (iter == 4) {
  309. /* Skip to next device address. */
  310. addr = 0xa2;
  311. offset = 0;
  312. }
  313. rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
  314. SFP_BLOCK_SIZE);
  315. if (rval != QLA_SUCCESS) {
  316. qla_printk(KERN_WARNING, ha,
  317. "Unable to read SFP data (%x/%x/%x).\n", rval,
  318. addr, offset);
  319. count = 0;
  320. break;
  321. }
  322. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  323. buf += SFP_BLOCK_SIZE;
  324. }
  325. return count;
  326. }
  327. static struct bin_attribute sysfs_sfp_attr = {
  328. .attr = {
  329. .name = "sfp",
  330. .mode = S_IRUSR | S_IWUSR,
  331. },
  332. .size = SFP_DEV_SIZE * 2,
  333. .read = qla2x00_sysfs_read_sfp,
  334. };
  335. static struct sysfs_entry {
  336. char *name;
  337. struct bin_attribute *attr;
  338. int is4GBp_only;
  339. } bin_file_entries[] = {
  340. { "fw_dump", &sysfs_fw_dump_attr, },
  341. { "nvram", &sysfs_nvram_attr, },
  342. { "optrom", &sysfs_optrom_attr, },
  343. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  344. { "vpd", &sysfs_vpd_attr, 1 },
  345. { "sfp", &sysfs_sfp_attr, 1 },
  346. { NULL },
  347. };
  348. void
  349. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
  350. {
  351. struct Scsi_Host *host = ha->host;
  352. struct sysfs_entry *iter;
  353. int ret;
  354. for (iter = bin_file_entries; iter->name; iter++) {
  355. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  356. continue;
  357. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  358. iter->attr);
  359. if (ret)
  360. qla_printk(KERN_INFO, ha,
  361. "Unable to create sysfs %s binary attribute "
  362. "(%d).\n", iter->name, ret);
  363. }
  364. }
  365. void
  366. qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
  367. {
  368. struct Scsi_Host *host = ha->host;
  369. struct sysfs_entry *iter;
  370. for (iter = bin_file_entries; iter->name; iter++) {
  371. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  372. continue;
  373. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  374. iter->attr);
  375. }
  376. if (ha->beacon_blink_led == 1)
  377. ha->isp_ops->beacon_off(ha);
  378. }
  379. /* Scsi_Host attributes. */
  380. static ssize_t
  381. qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
  382. {
  383. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  384. }
  385. static ssize_t
  386. qla2x00_fw_version_show(struct class_device *cdev, char *buf)
  387. {
  388. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  389. char fw_str[30];
  390. return snprintf(buf, PAGE_SIZE, "%s\n",
  391. ha->isp_ops->fw_version_str(ha, fw_str));
  392. }
  393. static ssize_t
  394. qla2x00_serial_num_show(struct class_device *cdev, char *buf)
  395. {
  396. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  397. uint32_t sn;
  398. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  399. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  400. sn % 100000);
  401. }
  402. static ssize_t
  403. qla2x00_isp_name_show(struct class_device *cdev, char *buf)
  404. {
  405. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  406. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  407. }
  408. static ssize_t
  409. qla2x00_isp_id_show(struct class_device *cdev, char *buf)
  410. {
  411. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  412. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  413. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  414. ha->product_id[3]);
  415. }
  416. static ssize_t
  417. qla2x00_model_name_show(struct class_device *cdev, char *buf)
  418. {
  419. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  420. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  421. }
  422. static ssize_t
  423. qla2x00_model_desc_show(struct class_device *cdev, char *buf)
  424. {
  425. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  426. return snprintf(buf, PAGE_SIZE, "%s\n",
  427. ha->model_desc ? ha->model_desc: "");
  428. }
  429. static ssize_t
  430. qla2x00_pci_info_show(struct class_device *cdev, char *buf)
  431. {
  432. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  433. char pci_info[30];
  434. return snprintf(buf, PAGE_SIZE, "%s\n",
  435. ha->isp_ops->pci_info_str(ha, pci_info));
  436. }
  437. static ssize_t
  438. qla2x00_state_show(struct class_device *cdev, char *buf)
  439. {
  440. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  441. int len = 0;
  442. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  443. atomic_read(&ha->loop_state) == LOOP_DEAD)
  444. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  445. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  446. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  447. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  448. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  449. else {
  450. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  451. switch (ha->current_topology) {
  452. case ISP_CFG_NL:
  453. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  454. break;
  455. case ISP_CFG_FL:
  456. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  457. break;
  458. case ISP_CFG_N:
  459. len += snprintf(buf + len, PAGE_SIZE-len,
  460. "N_Port to N_Port\n");
  461. break;
  462. case ISP_CFG_F:
  463. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  464. break;
  465. default:
  466. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  467. break;
  468. }
  469. }
  470. return len;
  471. }
  472. static ssize_t
  473. qla2x00_zio_show(struct class_device *cdev, char *buf)
  474. {
  475. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  476. int len = 0;
  477. switch (ha->zio_mode) {
  478. case QLA_ZIO_MODE_6:
  479. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  480. break;
  481. case QLA_ZIO_DISABLED:
  482. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  483. break;
  484. }
  485. return len;
  486. }
  487. static ssize_t
  488. qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
  489. {
  490. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  491. int val = 0;
  492. uint16_t zio_mode;
  493. if (!IS_ZIO_SUPPORTED(ha))
  494. return -ENOTSUPP;
  495. if (sscanf(buf, "%d", &val) != 1)
  496. return -EINVAL;
  497. if (val)
  498. zio_mode = QLA_ZIO_MODE_6;
  499. else
  500. zio_mode = QLA_ZIO_DISABLED;
  501. /* Update per-hba values and queue a reset. */
  502. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  503. ha->zio_mode = zio_mode;
  504. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  505. }
  506. return strlen(buf);
  507. }
  508. static ssize_t
  509. qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
  510. {
  511. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  512. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  513. }
  514. static ssize_t
  515. qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
  516. size_t count)
  517. {
  518. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  519. int val = 0;
  520. uint16_t zio_timer;
  521. if (sscanf(buf, "%d", &val) != 1)
  522. return -EINVAL;
  523. if (val > 25500 || val < 100)
  524. return -ERANGE;
  525. zio_timer = (uint16_t)(val / 100);
  526. ha->zio_timer = zio_timer;
  527. return strlen(buf);
  528. }
  529. static ssize_t
  530. qla2x00_beacon_show(struct class_device *cdev, char *buf)
  531. {
  532. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  533. int len = 0;
  534. if (ha->beacon_blink_led)
  535. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  536. else
  537. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  538. return len;
  539. }
  540. static ssize_t
  541. qla2x00_beacon_store(struct class_device *cdev, const char *buf,
  542. size_t count)
  543. {
  544. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  545. int val = 0;
  546. int rval;
  547. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  548. return -EPERM;
  549. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  550. qla_printk(KERN_WARNING, ha,
  551. "Abort ISP active -- ignoring beacon request.\n");
  552. return -EBUSY;
  553. }
  554. if (sscanf(buf, "%d", &val) != 1)
  555. return -EINVAL;
  556. if (val)
  557. rval = ha->isp_ops->beacon_on(ha);
  558. else
  559. rval = ha->isp_ops->beacon_off(ha);
  560. if (rval != QLA_SUCCESS)
  561. count = 0;
  562. return count;
  563. }
  564. static ssize_t
  565. qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
  566. {
  567. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  568. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  569. ha->bios_revision[0]);
  570. }
  571. static ssize_t
  572. qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
  573. {
  574. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  575. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  576. ha->efi_revision[0]);
  577. }
  578. static ssize_t
  579. qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
  580. {
  581. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  582. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  583. ha->fcode_revision[0]);
  584. }
  585. static ssize_t
  586. qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
  587. {
  588. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  589. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  590. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  591. ha->fw_revision[3]);
  592. }
  593. static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
  594. NULL);
  595. static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  596. static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  597. static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  598. static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  599. static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  600. static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  601. static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  602. static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
  603. static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
  604. qla2x00_zio_store);
  605. static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  606. qla2x00_zio_timer_store);
  607. static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  608. qla2x00_beacon_store);
  609. static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  610. qla2x00_optrom_bios_version_show, NULL);
  611. static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  612. qla2x00_optrom_efi_version_show, NULL);
  613. static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  614. qla2x00_optrom_fcode_version_show, NULL);
  615. static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
  616. qla2x00_optrom_fw_version_show, NULL);
  617. struct class_device_attribute *qla2x00_host_attrs[] = {
  618. &class_device_attr_driver_version,
  619. &class_device_attr_fw_version,
  620. &class_device_attr_serial_num,
  621. &class_device_attr_isp_name,
  622. &class_device_attr_isp_id,
  623. &class_device_attr_model_name,
  624. &class_device_attr_model_desc,
  625. &class_device_attr_pci_info,
  626. &class_device_attr_state,
  627. &class_device_attr_zio,
  628. &class_device_attr_zio_timer,
  629. &class_device_attr_beacon,
  630. &class_device_attr_optrom_bios_version,
  631. &class_device_attr_optrom_efi_version,
  632. &class_device_attr_optrom_fcode_version,
  633. &class_device_attr_optrom_fw_version,
  634. NULL,
  635. };
  636. /* Host attributes. */
  637. static void
  638. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  639. {
  640. scsi_qla_host_t *ha = to_qla_host(shost);
  641. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  642. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  643. }
  644. static void
  645. qla2x00_get_host_speed(struct Scsi_Host *shost)
  646. {
  647. scsi_qla_host_t *ha = to_qla_host(shost);
  648. uint32_t speed = 0;
  649. switch (ha->link_data_rate) {
  650. case PORT_SPEED_1GB:
  651. speed = 1;
  652. break;
  653. case PORT_SPEED_2GB:
  654. speed = 2;
  655. break;
  656. case PORT_SPEED_4GB:
  657. speed = 4;
  658. break;
  659. }
  660. fc_host_speed(shost) = speed;
  661. }
  662. static void
  663. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  664. {
  665. scsi_qla_host_t *ha = to_qla_host(shost);
  666. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  667. switch (ha->current_topology) {
  668. case ISP_CFG_NL:
  669. port_type = FC_PORTTYPE_LPORT;
  670. break;
  671. case ISP_CFG_FL:
  672. port_type = FC_PORTTYPE_NLPORT;
  673. break;
  674. case ISP_CFG_N:
  675. port_type = FC_PORTTYPE_PTP;
  676. break;
  677. case ISP_CFG_F:
  678. port_type = FC_PORTTYPE_NPORT;
  679. break;
  680. }
  681. fc_host_port_type(shost) = port_type;
  682. }
  683. static void
  684. qla2x00_get_starget_node_name(struct scsi_target *starget)
  685. {
  686. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  687. scsi_qla_host_t *ha = to_qla_host(host);
  688. fc_port_t *fcport;
  689. u64 node_name = 0;
  690. list_for_each_entry(fcport, &ha->fcports, list) {
  691. if (starget->id == fcport->os_target_id) {
  692. node_name = wwn_to_u64(fcport->node_name);
  693. break;
  694. }
  695. }
  696. fc_starget_node_name(starget) = node_name;
  697. }
  698. static void
  699. qla2x00_get_starget_port_name(struct scsi_target *starget)
  700. {
  701. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  702. scsi_qla_host_t *ha = to_qla_host(host);
  703. fc_port_t *fcport;
  704. u64 port_name = 0;
  705. list_for_each_entry(fcport, &ha->fcports, list) {
  706. if (starget->id == fcport->os_target_id) {
  707. port_name = wwn_to_u64(fcport->port_name);
  708. break;
  709. }
  710. }
  711. fc_starget_port_name(starget) = port_name;
  712. }
  713. static void
  714. qla2x00_get_starget_port_id(struct scsi_target *starget)
  715. {
  716. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  717. scsi_qla_host_t *ha = to_qla_host(host);
  718. fc_port_t *fcport;
  719. uint32_t port_id = ~0U;
  720. list_for_each_entry(fcport, &ha->fcports, list) {
  721. if (starget->id == fcport->os_target_id) {
  722. port_id = fcport->d_id.b.domain << 16 |
  723. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  724. break;
  725. }
  726. }
  727. fc_starget_port_id(starget) = port_id;
  728. }
  729. static void
  730. qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
  731. {
  732. struct Scsi_Host *host = rport_to_shost(rport);
  733. scsi_qla_host_t *ha = to_qla_host(host);
  734. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  735. }
  736. static void
  737. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  738. {
  739. struct Scsi_Host *host = rport_to_shost(rport);
  740. scsi_qla_host_t *ha = to_qla_host(host);
  741. if (timeout)
  742. ha->port_down_retry_count = timeout;
  743. else
  744. ha->port_down_retry_count = 1;
  745. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  746. }
  747. static int
  748. qla2x00_issue_lip(struct Scsi_Host *shost)
  749. {
  750. scsi_qla_host_t *ha = to_qla_host(shost);
  751. set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
  752. return 0;
  753. }
  754. static struct fc_host_statistics *
  755. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  756. {
  757. scsi_qla_host_t *ha = to_qla_host(shost);
  758. int rval;
  759. uint16_t mb_stat[1];
  760. link_stat_t stat_buf;
  761. struct fc_host_statistics *pfc_host_stat;
  762. rval = QLA_FUNCTION_FAILED;
  763. pfc_host_stat = &ha->fc_host_stat;
  764. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  765. if (IS_FWI2_CAPABLE(ha)) {
  766. rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
  767. sizeof(stat_buf) / 4, mb_stat);
  768. } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
  769. !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
  770. !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
  771. !ha->dpc_active) {
  772. /* Must be in a 'READY' state for statistics retrieval. */
  773. rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
  774. mb_stat);
  775. }
  776. if (rval != QLA_SUCCESS)
  777. goto done;
  778. pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
  779. pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
  780. pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
  781. pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
  782. pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
  783. pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
  784. done:
  785. return pfc_host_stat;
  786. }
  787. static void
  788. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  789. {
  790. scsi_qla_host_t *ha = to_qla_host(shost);
  791. qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
  792. }
  793. static void
  794. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  795. {
  796. scsi_qla_host_t *ha = to_qla_host(shost);
  797. set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
  798. }
  799. static void
  800. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  801. {
  802. scsi_qla_host_t *ha = to_qla_host(shost);
  803. u64 node_name;
  804. if (ha->device_flags & SWITCH_FOUND)
  805. node_name = wwn_to_u64(ha->fabric_node_name);
  806. else
  807. node_name = wwn_to_u64(ha->node_name);
  808. fc_host_fabric_name(shost) = node_name;
  809. }
  810. static void
  811. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  812. {
  813. scsi_qla_host_t *ha = to_qla_host(shost);
  814. if (!ha->flags.online)
  815. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  816. else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
  817. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  818. else
  819. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  820. }
  821. static int
  822. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  823. {
  824. int ret = 0;
  825. scsi_qla_host_t *ha = (scsi_qla_host_t *) fc_vport->shost->hostdata;
  826. scsi_qla_host_t *vha;
  827. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  828. if (ret) {
  829. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  830. "status %x\n", ret));
  831. return (ret);
  832. }
  833. vha = qla24xx_create_vhost(fc_vport);
  834. if (vha == NULL) {
  835. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  836. vha));
  837. return FC_VPORT_FAILED;
  838. }
  839. if (disable) {
  840. atomic_set(&vha->vp_state, VP_OFFLINE);
  841. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  842. } else
  843. atomic_set(&vha->vp_state, VP_FAILED);
  844. /* ready to create vport */
  845. qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
  846. /* initialized vport states */
  847. atomic_set(&vha->loop_state, LOOP_DOWN);
  848. vha->vp_err_state= VP_ERR_PORTDWN;
  849. vha->vp_prev_err_state= VP_ERR_UNKWN;
  850. /* Check if physical ha port is Up */
  851. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  852. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  853. /* Don't retry or attempt login of this virtual port */
  854. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  855. vha->host_no));
  856. atomic_set(&vha->loop_state, LOOP_DEAD);
  857. if (!disable)
  858. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  859. }
  860. if (scsi_add_host(vha->host, &fc_vport->dev)) {
  861. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  862. vha->host_no, vha->vp_idx));
  863. goto vport_create_failed_2;
  864. }
  865. /* initialize attributes */
  866. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  867. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  868. fc_host_supported_classes(vha->host) =
  869. fc_host_supported_classes(ha->host);
  870. fc_host_supported_speeds(vha->host) =
  871. fc_host_supported_speeds(ha->host);
  872. qla24xx_vport_disable(fc_vport, disable);
  873. return 0;
  874. vport_create_failed_2:
  875. qla24xx_disable_vp(vha);
  876. qla24xx_deallocate_vp_id(vha);
  877. kfree(vha->port_name);
  878. kfree(vha->node_name);
  879. scsi_host_put(vha->host);
  880. return FC_VPORT_FAILED;
  881. }
  882. int
  883. qla24xx_vport_delete(struct fc_vport *fc_vport)
  884. {
  885. scsi_qla_host_t *ha = (scsi_qla_host_t *) fc_vport->shost->hostdata;
  886. scsi_qla_host_t *vha = fc_vport->dd_data;
  887. qla24xx_disable_vp(vha);
  888. qla24xx_deallocate_vp_id(vha);
  889. down(&ha->vport_sem);
  890. ha->cur_vport_count--;
  891. clear_bit(vha->vp_idx, (unsigned long *)ha->vp_idx_map);
  892. up(&ha->vport_sem);
  893. kfree(vha->node_name);
  894. kfree(vha->port_name);
  895. if (vha->timer_active) {
  896. qla2x00_vp_stop_timer(vha);
  897. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  898. "has stopped\n",
  899. vha->host_no, vha->vp_idx, vha));
  900. }
  901. fc_remove_host(vha->host);
  902. scsi_remove_host(vha->host);
  903. scsi_host_put(vha->host);
  904. return 0;
  905. }
  906. int
  907. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  908. {
  909. scsi_qla_host_t *vha = fc_vport->dd_data;
  910. if (disable)
  911. qla24xx_disable_vp(vha);
  912. else
  913. qla24xx_enable_vp(vha);
  914. return 0;
  915. }
  916. struct fc_function_template qla2xxx_transport_functions = {
  917. .show_host_node_name = 1,
  918. .show_host_port_name = 1,
  919. .show_host_supported_classes = 1,
  920. .get_host_port_id = qla2x00_get_host_port_id,
  921. .show_host_port_id = 1,
  922. .get_host_speed = qla2x00_get_host_speed,
  923. .show_host_speed = 1,
  924. .get_host_port_type = qla2x00_get_host_port_type,
  925. .show_host_port_type = 1,
  926. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  927. .show_host_symbolic_name = 1,
  928. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  929. .show_host_system_hostname = 1,
  930. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  931. .show_host_fabric_name = 1,
  932. .get_host_port_state = qla2x00_get_host_port_state,
  933. .show_host_port_state = 1,
  934. .dd_fcrport_size = sizeof(struct fc_port *),
  935. .show_rport_supported_classes = 1,
  936. .get_starget_node_name = qla2x00_get_starget_node_name,
  937. .show_starget_node_name = 1,
  938. .get_starget_port_name = qla2x00_get_starget_port_name,
  939. .show_starget_port_name = 1,
  940. .get_starget_port_id = qla2x00_get_starget_port_id,
  941. .show_starget_port_id = 1,
  942. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  943. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  944. .show_rport_dev_loss_tmo = 1,
  945. .issue_fc_host_lip = qla2x00_issue_lip,
  946. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  947. .vport_create = qla24xx_vport_create,
  948. .vport_disable = qla24xx_vport_disable,
  949. .vport_delete = qla24xx_vport_delete,
  950. };
  951. struct fc_function_template qla2xxx_transport_vport_functions = {
  952. .show_host_node_name = 1,
  953. .show_host_port_name = 1,
  954. .show_host_supported_classes = 1,
  955. .get_host_port_id = qla2x00_get_host_port_id,
  956. .show_host_port_id = 1,
  957. .get_host_speed = qla2x00_get_host_speed,
  958. .show_host_speed = 1,
  959. .get_host_port_type = qla2x00_get_host_port_type,
  960. .show_host_port_type = 1,
  961. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  962. .show_host_symbolic_name = 1,
  963. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  964. .show_host_system_hostname = 1,
  965. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  966. .show_host_fabric_name = 1,
  967. .get_host_port_state = qla2x00_get_host_port_state,
  968. .show_host_port_state = 1,
  969. .dd_fcrport_size = sizeof(struct fc_port *),
  970. .show_rport_supported_classes = 1,
  971. .get_starget_node_name = qla2x00_get_starget_node_name,
  972. .show_starget_node_name = 1,
  973. .get_starget_port_name = qla2x00_get_starget_port_name,
  974. .show_starget_port_name = 1,
  975. .get_starget_port_id = qla2x00_get_starget_port_id,
  976. .show_starget_port_id = 1,
  977. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  978. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  979. .show_rport_dev_loss_tmo = 1,
  980. .issue_fc_host_lip = qla2x00_issue_lip,
  981. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  982. };
  983. void
  984. qla2x00_init_host_attr(scsi_qla_host_t *ha)
  985. {
  986. fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
  987. fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
  988. fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
  989. fc_host_max_npiv_vports(ha->host) = MAX_NUM_VPORT_FABRIC;
  990. fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
  991. }