qla_attr.c 25 KB

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