qla_attr.c 37 KB

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