qla_attr.c 34 KB

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