qla_attr.c 24 KB

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