qla_attr.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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 class_device *cdev, char *buf)
  449. {
  450. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  451. }
  452. static ssize_t
  453. qla2x00_fw_version_show(struct class_device *cdev, char *buf)
  454. {
  455. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  456. char fw_str[30];
  457. return snprintf(buf, PAGE_SIZE, "%s\n",
  458. ha->isp_ops->fw_version_str(ha, fw_str));
  459. }
  460. static ssize_t
  461. qla2x00_serial_num_show(struct class_device *cdev, char *buf)
  462. {
  463. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  464. uint32_t sn;
  465. if (IS_FWI2_CAPABLE(ha))
  466. return snprintf(buf, PAGE_SIZE, "\n");
  467. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  468. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  469. sn % 100000);
  470. }
  471. static ssize_t
  472. qla2x00_isp_name_show(struct class_device *cdev, char *buf)
  473. {
  474. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  475. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  476. }
  477. static ssize_t
  478. qla2x00_isp_id_show(struct class_device *cdev, char *buf)
  479. {
  480. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  481. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  482. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  483. ha->product_id[3]);
  484. }
  485. static ssize_t
  486. qla2x00_model_name_show(struct class_device *cdev, char *buf)
  487. {
  488. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  489. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  490. }
  491. static ssize_t
  492. qla2x00_model_desc_show(struct class_device *cdev, char *buf)
  493. {
  494. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  495. return snprintf(buf, PAGE_SIZE, "%s\n",
  496. ha->model_desc ? ha->model_desc: "");
  497. }
  498. static ssize_t
  499. qla2x00_pci_info_show(struct class_device *cdev, char *buf)
  500. {
  501. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  502. char pci_info[30];
  503. return snprintf(buf, PAGE_SIZE, "%s\n",
  504. ha->isp_ops->pci_info_str(ha, pci_info));
  505. }
  506. static ssize_t
  507. qla2x00_state_show(struct class_device *cdev, char *buf)
  508. {
  509. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  510. int len = 0;
  511. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  512. atomic_read(&ha->loop_state) == LOOP_DEAD)
  513. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  514. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  515. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  516. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  517. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  518. else {
  519. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  520. switch (ha->current_topology) {
  521. case ISP_CFG_NL:
  522. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  523. break;
  524. case ISP_CFG_FL:
  525. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  526. break;
  527. case ISP_CFG_N:
  528. len += snprintf(buf + len, PAGE_SIZE-len,
  529. "N_Port to N_Port\n");
  530. break;
  531. case ISP_CFG_F:
  532. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  533. break;
  534. default:
  535. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  536. break;
  537. }
  538. }
  539. return len;
  540. }
  541. static ssize_t
  542. qla2x00_zio_show(struct class_device *cdev, char *buf)
  543. {
  544. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  545. int len = 0;
  546. switch (ha->zio_mode) {
  547. case QLA_ZIO_MODE_6:
  548. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  549. break;
  550. case QLA_ZIO_DISABLED:
  551. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  552. break;
  553. }
  554. return len;
  555. }
  556. static ssize_t
  557. qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
  558. {
  559. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  560. int val = 0;
  561. uint16_t zio_mode;
  562. if (!IS_ZIO_SUPPORTED(ha))
  563. return -ENOTSUPP;
  564. if (sscanf(buf, "%d", &val) != 1)
  565. return -EINVAL;
  566. if (val)
  567. zio_mode = QLA_ZIO_MODE_6;
  568. else
  569. zio_mode = QLA_ZIO_DISABLED;
  570. /* Update per-hba values and queue a reset. */
  571. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  572. ha->zio_mode = zio_mode;
  573. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  574. }
  575. return strlen(buf);
  576. }
  577. static ssize_t
  578. qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
  579. {
  580. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  581. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  582. }
  583. static ssize_t
  584. qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
  585. size_t count)
  586. {
  587. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  588. int val = 0;
  589. uint16_t zio_timer;
  590. if (sscanf(buf, "%d", &val) != 1)
  591. return -EINVAL;
  592. if (val > 25500 || val < 100)
  593. return -ERANGE;
  594. zio_timer = (uint16_t)(val / 100);
  595. ha->zio_timer = zio_timer;
  596. return strlen(buf);
  597. }
  598. static ssize_t
  599. qla2x00_beacon_show(struct class_device *cdev, char *buf)
  600. {
  601. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  602. int len = 0;
  603. if (ha->beacon_blink_led)
  604. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  605. else
  606. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  607. return len;
  608. }
  609. static ssize_t
  610. qla2x00_beacon_store(struct class_device *cdev, const char *buf,
  611. size_t count)
  612. {
  613. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  614. int val = 0;
  615. int rval;
  616. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  617. return -EPERM;
  618. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  619. qla_printk(KERN_WARNING, ha,
  620. "Abort ISP active -- ignoring beacon request.\n");
  621. return -EBUSY;
  622. }
  623. if (sscanf(buf, "%d", &val) != 1)
  624. return -EINVAL;
  625. if (val)
  626. rval = ha->isp_ops->beacon_on(ha);
  627. else
  628. rval = ha->isp_ops->beacon_off(ha);
  629. if (rval != QLA_SUCCESS)
  630. count = 0;
  631. return count;
  632. }
  633. static ssize_t
  634. qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
  635. {
  636. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  637. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  638. ha->bios_revision[0]);
  639. }
  640. static ssize_t
  641. qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
  642. {
  643. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  644. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  645. ha->efi_revision[0]);
  646. }
  647. static ssize_t
  648. qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
  649. {
  650. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  651. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  652. ha->fcode_revision[0]);
  653. }
  654. static ssize_t
  655. qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
  656. {
  657. scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
  658. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  659. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  660. ha->fw_revision[3]);
  661. }
  662. static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
  663. NULL);
  664. static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  665. static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  666. static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  667. static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  668. static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  669. static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  670. static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  671. static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
  672. static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
  673. qla2x00_zio_store);
  674. static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  675. qla2x00_zio_timer_store);
  676. static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  677. qla2x00_beacon_store);
  678. static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  679. qla2x00_optrom_bios_version_show, NULL);
  680. static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  681. qla2x00_optrom_efi_version_show, NULL);
  682. static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  683. qla2x00_optrom_fcode_version_show, NULL);
  684. static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
  685. qla2x00_optrom_fw_version_show, NULL);
  686. struct class_device_attribute *qla2x00_host_attrs[] = {
  687. &class_device_attr_driver_version,
  688. &class_device_attr_fw_version,
  689. &class_device_attr_serial_num,
  690. &class_device_attr_isp_name,
  691. &class_device_attr_isp_id,
  692. &class_device_attr_model_name,
  693. &class_device_attr_model_desc,
  694. &class_device_attr_pci_info,
  695. &class_device_attr_state,
  696. &class_device_attr_zio,
  697. &class_device_attr_zio_timer,
  698. &class_device_attr_beacon,
  699. &class_device_attr_optrom_bios_version,
  700. &class_device_attr_optrom_efi_version,
  701. &class_device_attr_optrom_fcode_version,
  702. &class_device_attr_optrom_fw_version,
  703. NULL,
  704. };
  705. /* Host attributes. */
  706. static void
  707. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  708. {
  709. scsi_qla_host_t *ha = shost_priv(shost);
  710. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  711. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  712. }
  713. static void
  714. qla2x00_get_host_speed(struct Scsi_Host *shost)
  715. {
  716. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  717. u32 speed = FC_PORTSPEED_UNKNOWN;
  718. switch (ha->link_data_rate) {
  719. case PORT_SPEED_1GB:
  720. speed = FC_PORTSPEED_1GBIT;
  721. break;
  722. case PORT_SPEED_2GB:
  723. speed = FC_PORTSPEED_2GBIT;
  724. break;
  725. case PORT_SPEED_4GB:
  726. speed = FC_PORTSPEED_4GBIT;
  727. break;
  728. case PORT_SPEED_8GB:
  729. speed = FC_PORTSPEED_8GBIT;
  730. break;
  731. }
  732. fc_host_speed(shost) = speed;
  733. }
  734. static void
  735. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  736. {
  737. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  738. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  739. switch (ha->current_topology) {
  740. case ISP_CFG_NL:
  741. port_type = FC_PORTTYPE_LPORT;
  742. break;
  743. case ISP_CFG_FL:
  744. port_type = FC_PORTTYPE_NLPORT;
  745. break;
  746. case ISP_CFG_N:
  747. port_type = FC_PORTTYPE_PTP;
  748. break;
  749. case ISP_CFG_F:
  750. port_type = FC_PORTTYPE_NPORT;
  751. break;
  752. }
  753. fc_host_port_type(shost) = port_type;
  754. }
  755. static void
  756. qla2x00_get_starget_node_name(struct scsi_target *starget)
  757. {
  758. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  759. scsi_qla_host_t *ha = shost_priv(host);
  760. fc_port_t *fcport;
  761. u64 node_name = 0;
  762. list_for_each_entry(fcport, &ha->fcports, list) {
  763. if (fcport->rport &&
  764. starget->id == fcport->rport->scsi_target_id) {
  765. node_name = wwn_to_u64(fcport->node_name);
  766. break;
  767. }
  768. }
  769. fc_starget_node_name(starget) = node_name;
  770. }
  771. static void
  772. qla2x00_get_starget_port_name(struct scsi_target *starget)
  773. {
  774. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  775. scsi_qla_host_t *ha = shost_priv(host);
  776. fc_port_t *fcport;
  777. u64 port_name = 0;
  778. list_for_each_entry(fcport, &ha->fcports, list) {
  779. if (fcport->rport &&
  780. starget->id == fcport->rport->scsi_target_id) {
  781. port_name = wwn_to_u64(fcport->port_name);
  782. break;
  783. }
  784. }
  785. fc_starget_port_name(starget) = port_name;
  786. }
  787. static void
  788. qla2x00_get_starget_port_id(struct scsi_target *starget)
  789. {
  790. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  791. scsi_qla_host_t *ha = shost_priv(host);
  792. fc_port_t *fcport;
  793. uint32_t port_id = ~0U;
  794. list_for_each_entry(fcport, &ha->fcports, list) {
  795. if (fcport->rport &&
  796. starget->id == fcport->rport->scsi_target_id) {
  797. port_id = fcport->d_id.b.domain << 16 |
  798. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  799. break;
  800. }
  801. }
  802. fc_starget_port_id(starget) = port_id;
  803. }
  804. static void
  805. qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
  806. {
  807. struct Scsi_Host *host = rport_to_shost(rport);
  808. scsi_qla_host_t *ha = shost_priv(host);
  809. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  810. }
  811. static void
  812. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  813. {
  814. struct Scsi_Host *host = rport_to_shost(rport);
  815. scsi_qla_host_t *ha = shost_priv(host);
  816. if (timeout)
  817. ha->port_down_retry_count = timeout;
  818. else
  819. ha->port_down_retry_count = 1;
  820. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  821. }
  822. static int
  823. qla2x00_issue_lip(struct Scsi_Host *shost)
  824. {
  825. scsi_qla_host_t *ha = shost_priv(shost);
  826. qla2x00_loop_reset(ha);
  827. return 0;
  828. }
  829. static struct fc_host_statistics *
  830. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  831. {
  832. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  833. int rval;
  834. struct link_statistics *stats;
  835. dma_addr_t stats_dma;
  836. struct fc_host_statistics *pfc_host_stat;
  837. pfc_host_stat = &ha->fc_host_stat;
  838. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  839. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  840. if (stats == NULL) {
  841. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  842. __func__, ha->host_no));
  843. goto done;
  844. }
  845. memset(stats, 0, DMA_POOL_SIZE);
  846. rval = QLA_FUNCTION_FAILED;
  847. if (IS_FWI2_CAPABLE(ha)) {
  848. rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
  849. } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
  850. !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
  851. !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
  852. !ha->dpc_active) {
  853. /* Must be in a 'READY' state for statistics retrieval. */
  854. rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
  855. stats_dma);
  856. }
  857. if (rval != QLA_SUCCESS)
  858. goto done_free;
  859. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  860. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  861. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  862. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  863. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  864. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  865. if (IS_FWI2_CAPABLE(ha)) {
  866. pfc_host_stat->tx_frames = stats->tx_frames;
  867. pfc_host_stat->rx_frames = stats->rx_frames;
  868. pfc_host_stat->dumped_frames = stats->dumped_frames;
  869. pfc_host_stat->nos_count = stats->nos_rcvd;
  870. }
  871. done_free:
  872. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  873. done:
  874. return pfc_host_stat;
  875. }
  876. static void
  877. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  878. {
  879. scsi_qla_host_t *ha = shost_priv(shost);
  880. qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
  881. }
  882. static void
  883. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  884. {
  885. scsi_qla_host_t *ha = shost_priv(shost);
  886. set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
  887. }
  888. static void
  889. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  890. {
  891. scsi_qla_host_t *ha = shost_priv(shost);
  892. u64 node_name;
  893. if (ha->device_flags & SWITCH_FOUND)
  894. node_name = wwn_to_u64(ha->fabric_node_name);
  895. else
  896. node_name = wwn_to_u64(ha->node_name);
  897. fc_host_fabric_name(shost) = node_name;
  898. }
  899. static void
  900. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  901. {
  902. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  903. if (!ha->flags.online)
  904. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  905. else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
  906. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  907. else
  908. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  909. }
  910. static int
  911. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  912. {
  913. int ret = 0;
  914. scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
  915. scsi_qla_host_t *vha;
  916. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  917. if (ret) {
  918. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  919. "status %x\n", ret));
  920. return (ret);
  921. }
  922. vha = qla24xx_create_vhost(fc_vport);
  923. if (vha == NULL) {
  924. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  925. vha));
  926. return FC_VPORT_FAILED;
  927. }
  928. if (disable) {
  929. atomic_set(&vha->vp_state, VP_OFFLINE);
  930. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  931. } else
  932. atomic_set(&vha->vp_state, VP_FAILED);
  933. /* ready to create vport */
  934. qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
  935. /* initialized vport states */
  936. atomic_set(&vha->loop_state, LOOP_DOWN);
  937. vha->vp_err_state= VP_ERR_PORTDWN;
  938. vha->vp_prev_err_state= VP_ERR_UNKWN;
  939. /* Check if physical ha port is Up */
  940. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  941. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  942. /* Don't retry or attempt login of this virtual port */
  943. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  944. vha->host_no));
  945. atomic_set(&vha->loop_state, LOOP_DEAD);
  946. if (!disable)
  947. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  948. }
  949. if (scsi_add_host(vha->host, &fc_vport->dev)) {
  950. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  951. vha->host_no, vha->vp_idx));
  952. goto vport_create_failed_2;
  953. }
  954. /* initialize attributes */
  955. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  956. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  957. fc_host_supported_classes(vha->host) =
  958. fc_host_supported_classes(ha->host);
  959. fc_host_supported_speeds(vha->host) =
  960. fc_host_supported_speeds(ha->host);
  961. qla24xx_vport_disable(fc_vport, disable);
  962. return 0;
  963. vport_create_failed_2:
  964. qla24xx_disable_vp(vha);
  965. qla24xx_deallocate_vp_id(vha);
  966. kfree(vha->port_name);
  967. kfree(vha->node_name);
  968. scsi_host_put(vha->host);
  969. return FC_VPORT_FAILED;
  970. }
  971. static int
  972. qla24xx_vport_delete(struct fc_vport *fc_vport)
  973. {
  974. scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
  975. scsi_qla_host_t *vha = fc_vport->dd_data;
  976. qla24xx_disable_vp(vha);
  977. qla24xx_deallocate_vp_id(vha);
  978. down(&ha->vport_sem);
  979. ha->cur_vport_count--;
  980. clear_bit(vha->vp_idx, ha->vp_idx_map);
  981. up(&ha->vport_sem);
  982. kfree(vha->node_name);
  983. kfree(vha->port_name);
  984. if (vha->timer_active) {
  985. qla2x00_vp_stop_timer(vha);
  986. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  987. "has stopped\n",
  988. vha->host_no, vha->vp_idx, vha));
  989. }
  990. fc_remove_host(vha->host);
  991. scsi_remove_host(vha->host);
  992. scsi_host_put(vha->host);
  993. return 0;
  994. }
  995. static int
  996. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  997. {
  998. scsi_qla_host_t *vha = fc_vport->dd_data;
  999. if (disable)
  1000. qla24xx_disable_vp(vha);
  1001. else
  1002. qla24xx_enable_vp(vha);
  1003. return 0;
  1004. }
  1005. struct fc_function_template qla2xxx_transport_functions = {
  1006. .show_host_node_name = 1,
  1007. .show_host_port_name = 1,
  1008. .show_host_supported_classes = 1,
  1009. .show_host_supported_speeds = 1,
  1010. .get_host_port_id = qla2x00_get_host_port_id,
  1011. .show_host_port_id = 1,
  1012. .get_host_speed = qla2x00_get_host_speed,
  1013. .show_host_speed = 1,
  1014. .get_host_port_type = qla2x00_get_host_port_type,
  1015. .show_host_port_type = 1,
  1016. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1017. .show_host_symbolic_name = 1,
  1018. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1019. .show_host_system_hostname = 1,
  1020. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1021. .show_host_fabric_name = 1,
  1022. .get_host_port_state = qla2x00_get_host_port_state,
  1023. .show_host_port_state = 1,
  1024. .dd_fcrport_size = sizeof(struct fc_port *),
  1025. .show_rport_supported_classes = 1,
  1026. .get_starget_node_name = qla2x00_get_starget_node_name,
  1027. .show_starget_node_name = 1,
  1028. .get_starget_port_name = qla2x00_get_starget_port_name,
  1029. .show_starget_port_name = 1,
  1030. .get_starget_port_id = qla2x00_get_starget_port_id,
  1031. .show_starget_port_id = 1,
  1032. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  1033. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1034. .show_rport_dev_loss_tmo = 1,
  1035. .issue_fc_host_lip = qla2x00_issue_lip,
  1036. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1037. .vport_create = qla24xx_vport_create,
  1038. .vport_disable = qla24xx_vport_disable,
  1039. .vport_delete = qla24xx_vport_delete,
  1040. };
  1041. struct fc_function_template qla2xxx_transport_vport_functions = {
  1042. .show_host_node_name = 1,
  1043. .show_host_port_name = 1,
  1044. .show_host_supported_classes = 1,
  1045. .get_host_port_id = qla2x00_get_host_port_id,
  1046. .show_host_port_id = 1,
  1047. .get_host_speed = qla2x00_get_host_speed,
  1048. .show_host_speed = 1,
  1049. .get_host_port_type = qla2x00_get_host_port_type,
  1050. .show_host_port_type = 1,
  1051. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1052. .show_host_symbolic_name = 1,
  1053. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1054. .show_host_system_hostname = 1,
  1055. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1056. .show_host_fabric_name = 1,
  1057. .get_host_port_state = qla2x00_get_host_port_state,
  1058. .show_host_port_state = 1,
  1059. .dd_fcrport_size = sizeof(struct fc_port *),
  1060. .show_rport_supported_classes = 1,
  1061. .get_starget_node_name = qla2x00_get_starget_node_name,
  1062. .show_starget_node_name = 1,
  1063. .get_starget_port_name = qla2x00_get_starget_port_name,
  1064. .show_starget_port_name = 1,
  1065. .get_starget_port_id = qla2x00_get_starget_port_id,
  1066. .show_starget_port_id = 1,
  1067. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  1068. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1069. .show_rport_dev_loss_tmo = 1,
  1070. .issue_fc_host_lip = qla2x00_issue_lip,
  1071. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1072. };
  1073. void
  1074. qla2x00_init_host_attr(scsi_qla_host_t *ha)
  1075. {
  1076. u32 speed = FC_PORTSPEED_UNKNOWN;
  1077. fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
  1078. fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
  1079. fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
  1080. fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
  1081. fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
  1082. if (IS_QLA25XX(ha))
  1083. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1084. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1085. else if (IS_QLA24XX_TYPE(ha))
  1086. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1087. FC_PORTSPEED_1GBIT;
  1088. else if (IS_QLA23XX(ha))
  1089. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1090. else
  1091. speed = FC_PORTSPEED_1GBIT;
  1092. fc_host_supported_speeds(ha->host) = speed;
  1093. }