qla_attr.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 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. static 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 = shost_priv(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 = shost_priv(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 = shost_priv(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 = shost_priv(dev_to_shost(container_of(kobj,
  97. struct device, kobj)));
  98. uint16_t cnt;
  99. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
  100. return 0;
  101. /* Checksum NVRAM. */
  102. if (IS_FWI2_CAPABLE(ha)) {
  103. uint32_t *iter;
  104. uint32_t chksum;
  105. iter = (uint32_t *)buf;
  106. chksum = 0;
  107. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  108. chksum += le32_to_cpu(*iter++);
  109. chksum = ~chksum + 1;
  110. *iter = cpu_to_le32(chksum);
  111. } else {
  112. uint8_t *iter;
  113. uint8_t chksum;
  114. iter = (uint8_t *)buf;
  115. chksum = 0;
  116. for (cnt = 0; cnt < count - 1; cnt++)
  117. chksum += *iter++;
  118. chksum = ~chksum + 1;
  119. *iter = chksum;
  120. }
  121. /* Write NVRAM. */
  122. ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
  123. ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base,
  124. count);
  125. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  126. return (count);
  127. }
  128. static struct bin_attribute sysfs_nvram_attr = {
  129. .attr = {
  130. .name = "nvram",
  131. .mode = S_IRUSR | S_IWUSR,
  132. },
  133. .size = 512,
  134. .read = qla2x00_sysfs_read_nvram,
  135. .write = qla2x00_sysfs_write_nvram,
  136. };
  137. static ssize_t
  138. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  139. struct bin_attribute *bin_attr,
  140. char *buf, loff_t off, size_t count)
  141. {
  142. struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
  143. struct device, kobj)));
  144. if (ha->optrom_state != QLA_SREADING)
  145. return 0;
  146. if (off > ha->optrom_region_size)
  147. return 0;
  148. if (off + count > ha->optrom_region_size)
  149. count = ha->optrom_region_size - off;
  150. memcpy(buf, &ha->optrom_buffer[off], count);
  151. return count;
  152. }
  153. static ssize_t
  154. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  155. struct bin_attribute *bin_attr,
  156. char *buf, loff_t off, size_t count)
  157. {
  158. struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
  159. struct device, kobj)));
  160. if (ha->optrom_state != QLA_SWRITING)
  161. return -EINVAL;
  162. if (off > ha->optrom_region_size)
  163. return -ERANGE;
  164. if (off + count > ha->optrom_region_size)
  165. count = ha->optrom_region_size - off;
  166. memcpy(&ha->optrom_buffer[off], buf, count);
  167. return count;
  168. }
  169. static struct bin_attribute sysfs_optrom_attr = {
  170. .attr = {
  171. .name = "optrom",
  172. .mode = S_IRUSR | S_IWUSR,
  173. },
  174. .size = 0,
  175. .read = qla2x00_sysfs_read_optrom,
  176. .write = qla2x00_sysfs_write_optrom,
  177. };
  178. static ssize_t
  179. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  180. struct bin_attribute *bin_attr,
  181. char *buf, loff_t off, size_t count)
  182. {
  183. struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
  184. struct device, kobj)));
  185. uint32_t start = 0;
  186. uint32_t size = ha->optrom_size;
  187. int val, valid;
  188. if (off)
  189. return 0;
  190. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  191. return -EINVAL;
  192. if (start > ha->optrom_size)
  193. return -EINVAL;
  194. switch (val) {
  195. case 0:
  196. if (ha->optrom_state != QLA_SREADING &&
  197. ha->optrom_state != QLA_SWRITING)
  198. break;
  199. ha->optrom_state = QLA_SWAITING;
  200. DEBUG2(qla_printk(KERN_INFO, ha,
  201. "Freeing flash region allocation -- 0x%x bytes.\n",
  202. ha->optrom_region_size));
  203. vfree(ha->optrom_buffer);
  204. ha->optrom_buffer = NULL;
  205. break;
  206. case 1:
  207. if (ha->optrom_state != QLA_SWAITING)
  208. break;
  209. if (start & 0xfff) {
  210. qla_printk(KERN_WARNING, ha,
  211. "Invalid start region 0x%x/0x%x.\n", start, size);
  212. return -EINVAL;
  213. }
  214. ha->optrom_region_start = start;
  215. ha->optrom_region_size = start + size > ha->optrom_size ?
  216. ha->optrom_size - start : size;
  217. ha->optrom_state = QLA_SREADING;
  218. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  219. if (ha->optrom_buffer == NULL) {
  220. qla_printk(KERN_WARNING, ha,
  221. "Unable to allocate memory for optrom retrieval "
  222. "(%x).\n", ha->optrom_region_size);
  223. ha->optrom_state = QLA_SWAITING;
  224. return count;
  225. }
  226. DEBUG2(qla_printk(KERN_INFO, ha,
  227. "Reading flash region -- 0x%x/0x%x.\n",
  228. ha->optrom_region_start, ha->optrom_region_size));
  229. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  230. ha->isp_ops->read_optrom(ha, ha->optrom_buffer,
  231. ha->optrom_region_start, ha->optrom_region_size);
  232. break;
  233. case 2:
  234. if (ha->optrom_state != QLA_SWAITING)
  235. break;
  236. /*
  237. * We need to be more restrictive on which FLASH regions are
  238. * allowed to be updated via user-space. Regions accessible
  239. * via this method include:
  240. *
  241. * ISP21xx/ISP22xx/ISP23xx type boards:
  242. *
  243. * 0x000000 -> 0x020000 -- Boot code.
  244. *
  245. * ISP2322/ISP24xx type boards:
  246. *
  247. * 0x000000 -> 0x07ffff -- Boot code.
  248. * 0x080000 -> 0x0fffff -- Firmware.
  249. *
  250. * ISP25xx type boards:
  251. *
  252. * 0x000000 -> 0x07ffff -- Boot code.
  253. * 0x080000 -> 0x0fffff -- Firmware.
  254. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  255. */
  256. valid = 0;
  257. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  258. valid = 1;
  259. else if (start == (FA_BOOT_CODE_ADDR*4) ||
  260. start == (FA_RISC_CODE_ADDR*4))
  261. valid = 1;
  262. else if (IS_QLA25XX(ha) && start == (FA_VPD_NVRAM_ADDR*4))
  263. valid = 1;
  264. if (!valid) {
  265. qla_printk(KERN_WARNING, ha,
  266. "Invalid start region 0x%x/0x%x.\n", start, size);
  267. return -EINVAL;
  268. }
  269. ha->optrom_region_start = start;
  270. ha->optrom_region_size = start + size > ha->optrom_size ?
  271. ha->optrom_size - start : size;
  272. ha->optrom_state = QLA_SWRITING;
  273. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  274. if (ha->optrom_buffer == NULL) {
  275. qla_printk(KERN_WARNING, ha,
  276. "Unable to allocate memory for optrom update "
  277. "(%x).\n", ha->optrom_region_size);
  278. ha->optrom_state = QLA_SWAITING;
  279. return count;
  280. }
  281. DEBUG2(qla_printk(KERN_INFO, ha,
  282. "Staging flash region write -- 0x%x/0x%x.\n",
  283. ha->optrom_region_start, ha->optrom_region_size));
  284. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  285. break;
  286. case 3:
  287. if (ha->optrom_state != QLA_SWRITING)
  288. break;
  289. DEBUG2(qla_printk(KERN_INFO, ha,
  290. "Writing flash region -- 0x%x/0x%x.\n",
  291. ha->optrom_region_start, ha->optrom_region_size));
  292. ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
  293. ha->optrom_region_start, ha->optrom_region_size);
  294. break;
  295. default:
  296. count = -EINVAL;
  297. }
  298. return count;
  299. }
  300. static struct bin_attribute sysfs_optrom_ctl_attr = {
  301. .attr = {
  302. .name = "optrom_ctl",
  303. .mode = S_IWUSR,
  304. },
  305. .size = 0,
  306. .write = qla2x00_sysfs_write_optrom_ctl,
  307. };
  308. static ssize_t
  309. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  310. struct bin_attribute *bin_attr,
  311. char *buf, loff_t off, size_t count)
  312. {
  313. struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
  314. struct device, kobj)));
  315. int size = ha->vpd_size;
  316. char *vpd_cache = ha->vpd;
  317. if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
  318. return 0;
  319. if (off + count > size) {
  320. size -= off;
  321. count = size;
  322. }
  323. /* Read NVRAM data from cache. */
  324. memcpy(buf, &vpd_cache[off], count);
  325. return count;
  326. }
  327. static ssize_t
  328. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  329. struct bin_attribute *bin_attr,
  330. char *buf, loff_t off, size_t count)
  331. {
  332. struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
  333. struct device, kobj)));
  334. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
  335. return 0;
  336. /* Write NVRAM. */
  337. ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
  338. ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  339. return count;
  340. }
  341. static struct bin_attribute sysfs_vpd_attr = {
  342. .attr = {
  343. .name = "vpd",
  344. .mode = S_IRUSR | S_IWUSR,
  345. },
  346. .size = 0,
  347. .read = qla2x00_sysfs_read_vpd,
  348. .write = qla2x00_sysfs_write_vpd,
  349. };
  350. static ssize_t
  351. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  352. struct bin_attribute *bin_attr,
  353. char *buf, loff_t off, size_t count)
  354. {
  355. struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
  356. struct device, kobj)));
  357. uint16_t iter, addr, offset;
  358. int rval;
  359. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  360. return 0;
  361. if (ha->sfp_data)
  362. goto do_read;
  363. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  364. &ha->sfp_data_dma);
  365. if (!ha->sfp_data) {
  366. qla_printk(KERN_WARNING, ha,
  367. "Unable to allocate memory for SFP read-data.\n");
  368. return 0;
  369. }
  370. do_read:
  371. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  372. addr = 0xa0;
  373. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  374. iter++, offset += SFP_BLOCK_SIZE) {
  375. if (iter == 4) {
  376. /* Skip to next device address. */
  377. addr = 0xa2;
  378. offset = 0;
  379. }
  380. rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
  381. SFP_BLOCK_SIZE);
  382. if (rval != QLA_SUCCESS) {
  383. qla_printk(KERN_WARNING, ha,
  384. "Unable to read SFP data (%x/%x/%x).\n", rval,
  385. addr, offset);
  386. count = 0;
  387. break;
  388. }
  389. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  390. buf += SFP_BLOCK_SIZE;
  391. }
  392. return count;
  393. }
  394. static struct bin_attribute sysfs_sfp_attr = {
  395. .attr = {
  396. .name = "sfp",
  397. .mode = S_IRUSR | S_IWUSR,
  398. },
  399. .size = SFP_DEV_SIZE * 2,
  400. .read = qla2x00_sysfs_read_sfp,
  401. };
  402. static struct sysfs_entry {
  403. char *name;
  404. struct bin_attribute *attr;
  405. int is4GBp_only;
  406. } bin_file_entries[] = {
  407. { "fw_dump", &sysfs_fw_dump_attr, },
  408. { "nvram", &sysfs_nvram_attr, },
  409. { "optrom", &sysfs_optrom_attr, },
  410. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  411. { "vpd", &sysfs_vpd_attr, 1 },
  412. { "sfp", &sysfs_sfp_attr, 1 },
  413. { NULL },
  414. };
  415. void
  416. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
  417. {
  418. struct Scsi_Host *host = ha->host;
  419. struct sysfs_entry *iter;
  420. int ret;
  421. for (iter = bin_file_entries; iter->name; iter++) {
  422. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  423. continue;
  424. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  425. iter->attr);
  426. if (ret)
  427. qla_printk(KERN_INFO, ha,
  428. "Unable to create sysfs %s binary attribute "
  429. "(%d).\n", iter->name, ret);
  430. }
  431. }
  432. void
  433. qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
  434. {
  435. struct Scsi_Host *host = ha->host;
  436. struct sysfs_entry *iter;
  437. for (iter = bin_file_entries; iter->name; iter++) {
  438. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  439. continue;
  440. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  441. iter->attr);
  442. }
  443. if (ha->beacon_blink_led == 1)
  444. ha->isp_ops->beacon_off(ha);
  445. }
  446. /* Scsi_Host attributes. */
  447. static ssize_t
  448. qla2x00_drvr_version_show(struct device *dev,
  449. struct device_attribute *attr, char *buf)
  450. {
  451. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  452. }
  453. static ssize_t
  454. qla2x00_fw_version_show(struct device *dev,
  455. struct device_attribute *attr, char *buf)
  456. {
  457. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  458. char fw_str[30];
  459. return snprintf(buf, PAGE_SIZE, "%s\n",
  460. ha->isp_ops->fw_version_str(ha, fw_str));
  461. }
  462. static ssize_t
  463. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  464. char *buf)
  465. {
  466. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  467. uint32_t sn;
  468. if (IS_FWI2_CAPABLE(ha))
  469. return snprintf(buf, PAGE_SIZE, "\n");
  470. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  471. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  472. sn % 100000);
  473. }
  474. static ssize_t
  475. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  476. char *buf)
  477. {
  478. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  479. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  480. }
  481. static ssize_t
  482. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  483. char *buf)
  484. {
  485. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  486. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  487. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  488. ha->product_id[3]);
  489. }
  490. static ssize_t
  491. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  492. char *buf)
  493. {
  494. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  495. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  496. }
  497. static ssize_t
  498. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  499. char *buf)
  500. {
  501. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  502. return snprintf(buf, PAGE_SIZE, "%s\n",
  503. ha->model_desc ? ha->model_desc: "");
  504. }
  505. static ssize_t
  506. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  507. char *buf)
  508. {
  509. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  510. char pci_info[30];
  511. return snprintf(buf, PAGE_SIZE, "%s\n",
  512. ha->isp_ops->pci_info_str(ha, pci_info));
  513. }
  514. static ssize_t
  515. qla2x00_state_show(struct device *dev, struct device_attribute *attr,
  516. char *buf)
  517. {
  518. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  519. int len = 0;
  520. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  521. atomic_read(&ha->loop_state) == LOOP_DEAD)
  522. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  523. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  524. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  525. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  526. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  527. else {
  528. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  529. switch (ha->current_topology) {
  530. case ISP_CFG_NL:
  531. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  532. break;
  533. case ISP_CFG_FL:
  534. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  535. break;
  536. case ISP_CFG_N:
  537. len += snprintf(buf + len, PAGE_SIZE-len,
  538. "N_Port to N_Port\n");
  539. break;
  540. case ISP_CFG_F:
  541. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  542. break;
  543. default:
  544. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  545. break;
  546. }
  547. }
  548. return len;
  549. }
  550. static ssize_t
  551. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  552. char *buf)
  553. {
  554. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  555. int len = 0;
  556. switch (ha->zio_mode) {
  557. case QLA_ZIO_MODE_6:
  558. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  559. break;
  560. case QLA_ZIO_DISABLED:
  561. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  562. break;
  563. }
  564. return len;
  565. }
  566. static ssize_t
  567. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  568. const char *buf, size_t count)
  569. {
  570. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  571. int val = 0;
  572. uint16_t zio_mode;
  573. if (!IS_ZIO_SUPPORTED(ha))
  574. return -ENOTSUPP;
  575. if (sscanf(buf, "%d", &val) != 1)
  576. return -EINVAL;
  577. if (val)
  578. zio_mode = QLA_ZIO_MODE_6;
  579. else
  580. zio_mode = QLA_ZIO_DISABLED;
  581. /* Update per-hba values and queue a reset. */
  582. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  583. ha->zio_mode = zio_mode;
  584. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  585. }
  586. return strlen(buf);
  587. }
  588. static ssize_t
  589. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  590. char *buf)
  591. {
  592. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  593. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  594. }
  595. static ssize_t
  596. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  597. const char *buf, size_t count)
  598. {
  599. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  600. int val = 0;
  601. uint16_t zio_timer;
  602. if (sscanf(buf, "%d", &val) != 1)
  603. return -EINVAL;
  604. if (val > 25500 || val < 100)
  605. return -ERANGE;
  606. zio_timer = (uint16_t)(val / 100);
  607. ha->zio_timer = zio_timer;
  608. return strlen(buf);
  609. }
  610. static ssize_t
  611. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  612. char *buf)
  613. {
  614. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  615. int len = 0;
  616. if (ha->beacon_blink_led)
  617. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  618. else
  619. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  620. return len;
  621. }
  622. static ssize_t
  623. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  624. const char *buf, size_t count)
  625. {
  626. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  627. int val = 0;
  628. int rval;
  629. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  630. return -EPERM;
  631. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  632. qla_printk(KERN_WARNING, ha,
  633. "Abort ISP active -- ignoring beacon request.\n");
  634. return -EBUSY;
  635. }
  636. if (sscanf(buf, "%d", &val) != 1)
  637. return -EINVAL;
  638. if (val)
  639. rval = ha->isp_ops->beacon_on(ha);
  640. else
  641. rval = ha->isp_ops->beacon_off(ha);
  642. if (rval != QLA_SUCCESS)
  643. count = 0;
  644. return count;
  645. }
  646. static ssize_t
  647. qla2x00_optrom_bios_version_show(struct device *dev,
  648. struct device_attribute *attr, char *buf)
  649. {
  650. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  651. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  652. ha->bios_revision[0]);
  653. }
  654. static ssize_t
  655. qla2x00_optrom_efi_version_show(struct device *dev,
  656. struct device_attribute *attr, char *buf)
  657. {
  658. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  659. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  660. ha->efi_revision[0]);
  661. }
  662. static ssize_t
  663. qla2x00_optrom_fcode_version_show(struct device *dev,
  664. struct device_attribute *attr, char *buf)
  665. {
  666. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  667. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  668. ha->fcode_revision[0]);
  669. }
  670. static ssize_t
  671. qla2x00_optrom_fw_version_show(struct device *dev,
  672. struct device_attribute *attr, char *buf)
  673. {
  674. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  675. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  676. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  677. ha->fw_revision[3]);
  678. }
  679. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  680. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  681. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  682. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  683. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  684. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  685. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  686. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  687. static DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
  688. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  689. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  690. qla2x00_zio_timer_store);
  691. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  692. qla2x00_beacon_store);
  693. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  694. qla2x00_optrom_bios_version_show, NULL);
  695. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  696. qla2x00_optrom_efi_version_show, NULL);
  697. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  698. qla2x00_optrom_fcode_version_show, NULL);
  699. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  700. NULL);
  701. struct device_attribute *qla2x00_host_attrs[] = {
  702. &dev_attr_driver_version,
  703. &dev_attr_fw_version,
  704. &dev_attr_serial_num,
  705. &dev_attr_isp_name,
  706. &dev_attr_isp_id,
  707. &dev_attr_model_name,
  708. &dev_attr_model_desc,
  709. &dev_attr_pci_info,
  710. &dev_attr_state,
  711. &dev_attr_zio,
  712. &dev_attr_zio_timer,
  713. &dev_attr_beacon,
  714. &dev_attr_optrom_bios_version,
  715. &dev_attr_optrom_efi_version,
  716. &dev_attr_optrom_fcode_version,
  717. &dev_attr_optrom_fw_version,
  718. NULL,
  719. };
  720. /* Host attributes. */
  721. static void
  722. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  723. {
  724. scsi_qla_host_t *ha = shost_priv(shost);
  725. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  726. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  727. }
  728. static void
  729. qla2x00_get_host_speed(struct Scsi_Host *shost)
  730. {
  731. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  732. u32 speed = FC_PORTSPEED_UNKNOWN;
  733. switch (ha->link_data_rate) {
  734. case PORT_SPEED_1GB:
  735. speed = FC_PORTSPEED_1GBIT;
  736. break;
  737. case PORT_SPEED_2GB:
  738. speed = FC_PORTSPEED_2GBIT;
  739. break;
  740. case PORT_SPEED_4GB:
  741. speed = FC_PORTSPEED_4GBIT;
  742. break;
  743. case PORT_SPEED_8GB:
  744. speed = FC_PORTSPEED_8GBIT;
  745. break;
  746. }
  747. fc_host_speed(shost) = speed;
  748. }
  749. static void
  750. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  751. {
  752. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  753. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  754. switch (ha->current_topology) {
  755. case ISP_CFG_NL:
  756. port_type = FC_PORTTYPE_LPORT;
  757. break;
  758. case ISP_CFG_FL:
  759. port_type = FC_PORTTYPE_NLPORT;
  760. break;
  761. case ISP_CFG_N:
  762. port_type = FC_PORTTYPE_PTP;
  763. break;
  764. case ISP_CFG_F:
  765. port_type = FC_PORTTYPE_NPORT;
  766. break;
  767. }
  768. fc_host_port_type(shost) = port_type;
  769. }
  770. static void
  771. qla2x00_get_starget_node_name(struct scsi_target *starget)
  772. {
  773. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  774. scsi_qla_host_t *ha = shost_priv(host);
  775. fc_port_t *fcport;
  776. u64 node_name = 0;
  777. list_for_each_entry(fcport, &ha->fcports, list) {
  778. if (fcport->rport &&
  779. starget->id == fcport->rport->scsi_target_id) {
  780. node_name = wwn_to_u64(fcport->node_name);
  781. break;
  782. }
  783. }
  784. fc_starget_node_name(starget) = node_name;
  785. }
  786. static void
  787. qla2x00_get_starget_port_name(struct scsi_target *starget)
  788. {
  789. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  790. scsi_qla_host_t *ha = shost_priv(host);
  791. fc_port_t *fcport;
  792. u64 port_name = 0;
  793. list_for_each_entry(fcport, &ha->fcports, list) {
  794. if (fcport->rport &&
  795. starget->id == fcport->rport->scsi_target_id) {
  796. port_name = wwn_to_u64(fcport->port_name);
  797. break;
  798. }
  799. }
  800. fc_starget_port_name(starget) = port_name;
  801. }
  802. static void
  803. qla2x00_get_starget_port_id(struct scsi_target *starget)
  804. {
  805. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  806. scsi_qla_host_t *ha = shost_priv(host);
  807. fc_port_t *fcport;
  808. uint32_t port_id = ~0U;
  809. list_for_each_entry(fcport, &ha->fcports, list) {
  810. if (fcport->rport &&
  811. starget->id == fcport->rport->scsi_target_id) {
  812. port_id = fcport->d_id.b.domain << 16 |
  813. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  814. break;
  815. }
  816. }
  817. fc_starget_port_id(starget) = port_id;
  818. }
  819. static void
  820. qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
  821. {
  822. struct Scsi_Host *host = rport_to_shost(rport);
  823. scsi_qla_host_t *ha = shost_priv(host);
  824. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  825. }
  826. static void
  827. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  828. {
  829. struct Scsi_Host *host = rport_to_shost(rport);
  830. scsi_qla_host_t *ha = shost_priv(host);
  831. if (timeout)
  832. ha->port_down_retry_count = timeout;
  833. else
  834. ha->port_down_retry_count = 1;
  835. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  836. }
  837. static int
  838. qla2x00_issue_lip(struct Scsi_Host *shost)
  839. {
  840. scsi_qla_host_t *ha = shost_priv(shost);
  841. qla2x00_loop_reset(ha);
  842. return 0;
  843. }
  844. static struct fc_host_statistics *
  845. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  846. {
  847. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  848. int rval;
  849. struct link_statistics *stats;
  850. dma_addr_t stats_dma;
  851. struct fc_host_statistics *pfc_host_stat;
  852. pfc_host_stat = &ha->fc_host_stat;
  853. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  854. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  855. if (stats == NULL) {
  856. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  857. __func__, ha->host_no));
  858. goto done;
  859. }
  860. memset(stats, 0, DMA_POOL_SIZE);
  861. rval = QLA_FUNCTION_FAILED;
  862. if (IS_FWI2_CAPABLE(ha)) {
  863. rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
  864. } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
  865. !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
  866. !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
  867. !ha->dpc_active) {
  868. /* Must be in a 'READY' state for statistics retrieval. */
  869. rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
  870. stats_dma);
  871. }
  872. if (rval != QLA_SUCCESS)
  873. goto done_free;
  874. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  875. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  876. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  877. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  878. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  879. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  880. if (IS_FWI2_CAPABLE(ha)) {
  881. pfc_host_stat->tx_frames = stats->tx_frames;
  882. pfc_host_stat->rx_frames = stats->rx_frames;
  883. pfc_host_stat->dumped_frames = stats->dumped_frames;
  884. pfc_host_stat->nos_count = stats->nos_rcvd;
  885. }
  886. done_free:
  887. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  888. done:
  889. return pfc_host_stat;
  890. }
  891. static void
  892. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  893. {
  894. scsi_qla_host_t *ha = shost_priv(shost);
  895. qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
  896. }
  897. static void
  898. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  899. {
  900. scsi_qla_host_t *ha = shost_priv(shost);
  901. set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
  902. }
  903. static void
  904. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  905. {
  906. scsi_qla_host_t *ha = shost_priv(shost);
  907. u64 node_name;
  908. if (ha->device_flags & SWITCH_FOUND)
  909. node_name = wwn_to_u64(ha->fabric_node_name);
  910. else
  911. node_name = wwn_to_u64(ha->node_name);
  912. fc_host_fabric_name(shost) = node_name;
  913. }
  914. static void
  915. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  916. {
  917. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  918. if (!ha->flags.online)
  919. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  920. else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
  921. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  922. else
  923. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  924. }
  925. static int
  926. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  927. {
  928. int ret = 0;
  929. scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
  930. scsi_qla_host_t *vha;
  931. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  932. if (ret) {
  933. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  934. "status %x\n", ret));
  935. return (ret);
  936. }
  937. vha = qla24xx_create_vhost(fc_vport);
  938. if (vha == NULL) {
  939. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  940. vha));
  941. return FC_VPORT_FAILED;
  942. }
  943. if (disable) {
  944. atomic_set(&vha->vp_state, VP_OFFLINE);
  945. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  946. } else
  947. atomic_set(&vha->vp_state, VP_FAILED);
  948. /* ready to create vport */
  949. qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
  950. /* initialized vport states */
  951. atomic_set(&vha->loop_state, LOOP_DOWN);
  952. vha->vp_err_state= VP_ERR_PORTDWN;
  953. vha->vp_prev_err_state= VP_ERR_UNKWN;
  954. /* Check if physical ha port is Up */
  955. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  956. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  957. /* Don't retry or attempt login of this virtual port */
  958. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  959. vha->host_no));
  960. atomic_set(&vha->loop_state, LOOP_DEAD);
  961. if (!disable)
  962. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  963. }
  964. if (scsi_add_host(vha->host, &fc_vport->dev)) {
  965. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  966. vha->host_no, vha->vp_idx));
  967. goto vport_create_failed_2;
  968. }
  969. /* initialize attributes */
  970. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  971. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  972. fc_host_supported_classes(vha->host) =
  973. fc_host_supported_classes(ha->host);
  974. fc_host_supported_speeds(vha->host) =
  975. fc_host_supported_speeds(ha->host);
  976. qla24xx_vport_disable(fc_vport, disable);
  977. return 0;
  978. vport_create_failed_2:
  979. qla24xx_disable_vp(vha);
  980. qla24xx_deallocate_vp_id(vha);
  981. kfree(vha->port_name);
  982. kfree(vha->node_name);
  983. scsi_host_put(vha->host);
  984. return FC_VPORT_FAILED;
  985. }
  986. static int
  987. qla24xx_vport_delete(struct fc_vport *fc_vport)
  988. {
  989. scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
  990. scsi_qla_host_t *vha = fc_vport->dd_data;
  991. qla24xx_disable_vp(vha);
  992. qla24xx_deallocate_vp_id(vha);
  993. down(&ha->vport_sem);
  994. ha->cur_vport_count--;
  995. clear_bit(vha->vp_idx, ha->vp_idx_map);
  996. up(&ha->vport_sem);
  997. kfree(vha->node_name);
  998. kfree(vha->port_name);
  999. if (vha->timer_active) {
  1000. qla2x00_vp_stop_timer(vha);
  1001. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1002. "has stopped\n",
  1003. vha->host_no, vha->vp_idx, vha));
  1004. }
  1005. fc_remove_host(vha->host);
  1006. scsi_remove_host(vha->host);
  1007. scsi_host_put(vha->host);
  1008. return 0;
  1009. }
  1010. static int
  1011. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1012. {
  1013. scsi_qla_host_t *vha = fc_vport->dd_data;
  1014. if (disable)
  1015. qla24xx_disable_vp(vha);
  1016. else
  1017. qla24xx_enable_vp(vha);
  1018. return 0;
  1019. }
  1020. struct fc_function_template qla2xxx_transport_functions = {
  1021. .show_host_node_name = 1,
  1022. .show_host_port_name = 1,
  1023. .show_host_supported_classes = 1,
  1024. .show_host_supported_speeds = 1,
  1025. .get_host_port_id = qla2x00_get_host_port_id,
  1026. .show_host_port_id = 1,
  1027. .get_host_speed = qla2x00_get_host_speed,
  1028. .show_host_speed = 1,
  1029. .get_host_port_type = qla2x00_get_host_port_type,
  1030. .show_host_port_type = 1,
  1031. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1032. .show_host_symbolic_name = 1,
  1033. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1034. .show_host_system_hostname = 1,
  1035. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1036. .show_host_fabric_name = 1,
  1037. .get_host_port_state = qla2x00_get_host_port_state,
  1038. .show_host_port_state = 1,
  1039. .dd_fcrport_size = sizeof(struct fc_port *),
  1040. .show_rport_supported_classes = 1,
  1041. .get_starget_node_name = qla2x00_get_starget_node_name,
  1042. .show_starget_node_name = 1,
  1043. .get_starget_port_name = qla2x00_get_starget_port_name,
  1044. .show_starget_port_name = 1,
  1045. .get_starget_port_id = qla2x00_get_starget_port_id,
  1046. .show_starget_port_id = 1,
  1047. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  1048. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1049. .show_rport_dev_loss_tmo = 1,
  1050. .issue_fc_host_lip = qla2x00_issue_lip,
  1051. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1052. .vport_create = qla24xx_vport_create,
  1053. .vport_disable = qla24xx_vport_disable,
  1054. .vport_delete = qla24xx_vport_delete,
  1055. };
  1056. struct fc_function_template qla2xxx_transport_vport_functions = {
  1057. .show_host_node_name = 1,
  1058. .show_host_port_name = 1,
  1059. .show_host_supported_classes = 1,
  1060. .get_host_port_id = qla2x00_get_host_port_id,
  1061. .show_host_port_id = 1,
  1062. .get_host_speed = qla2x00_get_host_speed,
  1063. .show_host_speed = 1,
  1064. .get_host_port_type = qla2x00_get_host_port_type,
  1065. .show_host_port_type = 1,
  1066. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1067. .show_host_symbolic_name = 1,
  1068. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1069. .show_host_system_hostname = 1,
  1070. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1071. .show_host_fabric_name = 1,
  1072. .get_host_port_state = qla2x00_get_host_port_state,
  1073. .show_host_port_state = 1,
  1074. .dd_fcrport_size = sizeof(struct fc_port *),
  1075. .show_rport_supported_classes = 1,
  1076. .get_starget_node_name = qla2x00_get_starget_node_name,
  1077. .show_starget_node_name = 1,
  1078. .get_starget_port_name = qla2x00_get_starget_port_name,
  1079. .show_starget_port_name = 1,
  1080. .get_starget_port_id = qla2x00_get_starget_port_id,
  1081. .show_starget_port_id = 1,
  1082. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  1083. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1084. .show_rport_dev_loss_tmo = 1,
  1085. .issue_fc_host_lip = qla2x00_issue_lip,
  1086. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1087. };
  1088. void
  1089. qla2x00_init_host_attr(scsi_qla_host_t *ha)
  1090. {
  1091. u32 speed = FC_PORTSPEED_UNKNOWN;
  1092. fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
  1093. fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
  1094. fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
  1095. fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
  1096. fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
  1097. if (IS_QLA25XX(ha))
  1098. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1099. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1100. else if (IS_QLA24XX_TYPE(ha))
  1101. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1102. FC_PORTSPEED_1GBIT;
  1103. else if (IS_QLA23XX(ha))
  1104. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1105. else
  1106. speed = FC_PORTSPEED_1GBIT;
  1107. fc_host_supported_speeds(ha->host) = speed;
  1108. }