qla_attr.c 35 KB

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