qla_attr.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_target.h"
  9. #include <linux/kthread.h>
  10. #include <linux/vmalloc.h>
  11. #include <linux/slab.h>
  12. #include <linux/delay.h>
  13. static int qla24xx_vport_disable(struct fc_vport *, bool);
  14. /* SYSFS attributes --------------------------------------------------------- */
  15. static ssize_t
  16. qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
  17. struct bin_attribute *bin_attr,
  18. char *buf, loff_t off, size_t count)
  19. {
  20. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  21. struct device, kobj)));
  22. struct qla_hw_data *ha = vha->hw;
  23. int rval = 0;
  24. if (ha->fw_dump_reading == 0)
  25. return 0;
  26. if (IS_QLA82XX(ha)) {
  27. if (off < ha->md_template_size) {
  28. rval = memory_read_from_buffer(buf, count,
  29. &off, ha->md_tmplt_hdr, ha->md_template_size);
  30. return rval;
  31. }
  32. off -= ha->md_template_size;
  33. rval = memory_read_from_buffer(buf, count,
  34. &off, ha->md_dump, ha->md_dump_size);
  35. return rval;
  36. } else
  37. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  38. ha->fw_dump_len);
  39. }
  40. static ssize_t
  41. qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
  42. struct bin_attribute *bin_attr,
  43. char *buf, loff_t off, size_t count)
  44. {
  45. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  46. struct device, kobj)));
  47. struct qla_hw_data *ha = vha->hw;
  48. int reading;
  49. if (off != 0)
  50. return (0);
  51. reading = simple_strtol(buf, NULL, 10);
  52. switch (reading) {
  53. case 0:
  54. if (!ha->fw_dump_reading)
  55. break;
  56. ql_log(ql_log_info, vha, 0x705d,
  57. "Firmware dump cleared on (%ld).\n", vha->host_no);
  58. if (IS_QLA82XX(vha->hw)) {
  59. qla82xx_md_free(vha);
  60. qla82xx_md_prep(vha);
  61. }
  62. ha->fw_dump_reading = 0;
  63. ha->fw_dumped = 0;
  64. break;
  65. case 1:
  66. if (ha->fw_dumped && !ha->fw_dump_reading) {
  67. ha->fw_dump_reading = 1;
  68. ql_log(ql_log_info, vha, 0x705e,
  69. "Raw firmware dump ready for read on (%ld).\n",
  70. vha->host_no);
  71. }
  72. break;
  73. case 2:
  74. qla2x00_alloc_fw_dump(vha);
  75. break;
  76. case 3:
  77. if (IS_QLA82XX(ha)) {
  78. qla82xx_idc_lock(ha);
  79. qla82xx_set_reset_owner(vha);
  80. qla82xx_idc_unlock(ha);
  81. } else
  82. qla2x00_system_error(vha);
  83. break;
  84. case 4:
  85. if (IS_QLA82XX(ha)) {
  86. if (ha->md_tmplt_hdr)
  87. ql_dbg(ql_dbg_user, vha, 0x705b,
  88. "MiniDump supported with this firmware.\n");
  89. else
  90. ql_dbg(ql_dbg_user, vha, 0x709d,
  91. "MiniDump not supported with this firmware.\n");
  92. }
  93. break;
  94. case 5:
  95. if (IS_QLA82XX(ha))
  96. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  97. break;
  98. }
  99. return count;
  100. }
  101. static struct bin_attribute sysfs_fw_dump_attr = {
  102. .attr = {
  103. .name = "fw_dump",
  104. .mode = S_IRUSR | S_IWUSR,
  105. },
  106. .size = 0,
  107. .read = qla2x00_sysfs_read_fw_dump,
  108. .write = qla2x00_sysfs_write_fw_dump,
  109. };
  110. static ssize_t
  111. qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
  112. struct bin_attribute *bin_attr,
  113. char *buf, loff_t off, size_t count)
  114. {
  115. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  116. struct device, kobj)));
  117. struct qla_hw_data *ha = vha->hw;
  118. if (!capable(CAP_SYS_ADMIN))
  119. return 0;
  120. if (IS_NOCACHE_VPD_TYPE(ha))
  121. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  122. ha->nvram_size);
  123. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  124. ha->nvram_size);
  125. }
  126. static ssize_t
  127. qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
  128. struct bin_attribute *bin_attr,
  129. char *buf, loff_t off, size_t count)
  130. {
  131. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  132. struct device, kobj)));
  133. struct qla_hw_data *ha = vha->hw;
  134. uint16_t cnt;
  135. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  136. !ha->isp_ops->write_nvram)
  137. return -EINVAL;
  138. /* Checksum NVRAM. */
  139. if (IS_FWI2_CAPABLE(ha)) {
  140. uint32_t *iter;
  141. uint32_t chksum;
  142. iter = (uint32_t *)buf;
  143. chksum = 0;
  144. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  145. chksum += le32_to_cpu(*iter++);
  146. chksum = ~chksum + 1;
  147. *iter = cpu_to_le32(chksum);
  148. } else {
  149. uint8_t *iter;
  150. uint8_t chksum;
  151. iter = (uint8_t *)buf;
  152. chksum = 0;
  153. for (cnt = 0; cnt < count - 1; cnt++)
  154. chksum += *iter++;
  155. chksum = ~chksum + 1;
  156. *iter = chksum;
  157. }
  158. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  159. ql_log(ql_log_warn, vha, 0x705f,
  160. "HBA not online, failing NVRAM update.\n");
  161. return -EAGAIN;
  162. }
  163. /* Write NVRAM. */
  164. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  165. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  166. count);
  167. ql_dbg(ql_dbg_user, vha, 0x7060,
  168. "Setting ISP_ABORT_NEEDED\n");
  169. /* NVRAM settings take effect immediately. */
  170. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  171. qla2xxx_wake_dpc(vha);
  172. qla2x00_wait_for_chip_reset(vha);
  173. return count;
  174. }
  175. static struct bin_attribute sysfs_nvram_attr = {
  176. .attr = {
  177. .name = "nvram",
  178. .mode = S_IRUSR | S_IWUSR,
  179. },
  180. .size = 512,
  181. .read = qla2x00_sysfs_read_nvram,
  182. .write = qla2x00_sysfs_write_nvram,
  183. };
  184. static ssize_t
  185. qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
  186. struct bin_attribute *bin_attr,
  187. char *buf, loff_t off, size_t count)
  188. {
  189. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  190. struct device, kobj)));
  191. struct qla_hw_data *ha = vha->hw;
  192. if (ha->optrom_state != QLA_SREADING)
  193. return 0;
  194. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  195. ha->optrom_region_size);
  196. }
  197. static ssize_t
  198. qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
  199. struct bin_attribute *bin_attr,
  200. char *buf, loff_t off, size_t count)
  201. {
  202. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  203. struct device, kobj)));
  204. struct qla_hw_data *ha = vha->hw;
  205. if (ha->optrom_state != QLA_SWRITING)
  206. return -EINVAL;
  207. if (off > ha->optrom_region_size)
  208. return -ERANGE;
  209. if (off + count > ha->optrom_region_size)
  210. count = ha->optrom_region_size - off;
  211. memcpy(&ha->optrom_buffer[off], buf, count);
  212. return count;
  213. }
  214. static struct bin_attribute sysfs_optrom_attr = {
  215. .attr = {
  216. .name = "optrom",
  217. .mode = S_IRUSR | S_IWUSR,
  218. },
  219. .size = 0,
  220. .read = qla2x00_sysfs_read_optrom,
  221. .write = qla2x00_sysfs_write_optrom,
  222. };
  223. static ssize_t
  224. qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
  225. struct bin_attribute *bin_attr,
  226. char *buf, loff_t off, size_t count)
  227. {
  228. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  229. struct device, kobj)));
  230. struct qla_hw_data *ha = vha->hw;
  231. uint32_t start = 0;
  232. uint32_t size = ha->optrom_size;
  233. int val, valid;
  234. if (off)
  235. return -EINVAL;
  236. if (unlikely(pci_channel_offline(ha->pdev)))
  237. return -EAGAIN;
  238. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  239. return -EINVAL;
  240. if (start > ha->optrom_size)
  241. return -EINVAL;
  242. switch (val) {
  243. case 0:
  244. if (ha->optrom_state != QLA_SREADING &&
  245. ha->optrom_state != QLA_SWRITING)
  246. return -EINVAL;
  247. ha->optrom_state = QLA_SWAITING;
  248. ql_dbg(ql_dbg_user, vha, 0x7061,
  249. "Freeing flash region allocation -- 0x%x bytes.\n",
  250. ha->optrom_region_size);
  251. vfree(ha->optrom_buffer);
  252. ha->optrom_buffer = NULL;
  253. break;
  254. case 1:
  255. if (ha->optrom_state != QLA_SWAITING)
  256. return -EINVAL;
  257. ha->optrom_region_start = start;
  258. ha->optrom_region_size = start + size > ha->optrom_size ?
  259. ha->optrom_size - start : size;
  260. ha->optrom_state = QLA_SREADING;
  261. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  262. if (ha->optrom_buffer == NULL) {
  263. ql_log(ql_log_warn, vha, 0x7062,
  264. "Unable to allocate memory for optrom retrieval "
  265. "(%x).\n", ha->optrom_region_size);
  266. ha->optrom_state = QLA_SWAITING;
  267. return -ENOMEM;
  268. }
  269. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  270. ql_log(ql_log_warn, vha, 0x7063,
  271. "HBA not online, failing NVRAM update.\n");
  272. return -EAGAIN;
  273. }
  274. ql_dbg(ql_dbg_user, vha, 0x7064,
  275. "Reading flash region -- 0x%x/0x%x.\n",
  276. ha->optrom_region_start, ha->optrom_region_size);
  277. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  278. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  279. ha->optrom_region_start, ha->optrom_region_size);
  280. break;
  281. case 2:
  282. if (ha->optrom_state != QLA_SWAITING)
  283. return -EINVAL;
  284. /*
  285. * We need to be more restrictive on which FLASH regions are
  286. * allowed to be updated via user-space. Regions accessible
  287. * via this method include:
  288. *
  289. * ISP21xx/ISP22xx/ISP23xx type boards:
  290. *
  291. * 0x000000 -> 0x020000 -- Boot code.
  292. *
  293. * ISP2322/ISP24xx type boards:
  294. *
  295. * 0x000000 -> 0x07ffff -- Boot code.
  296. * 0x080000 -> 0x0fffff -- Firmware.
  297. *
  298. * ISP25xx type boards:
  299. *
  300. * 0x000000 -> 0x07ffff -- Boot code.
  301. * 0x080000 -> 0x0fffff -- Firmware.
  302. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  303. */
  304. valid = 0;
  305. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  306. valid = 1;
  307. else if (start == (ha->flt_region_boot * 4) ||
  308. start == (ha->flt_region_fw * 4))
  309. valid = 1;
  310. else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)
  311. || IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
  312. valid = 1;
  313. if (!valid) {
  314. ql_log(ql_log_warn, vha, 0x7065,
  315. "Invalid start region 0x%x/0x%x.\n", start, size);
  316. return -EINVAL;
  317. }
  318. ha->optrom_region_start = start;
  319. ha->optrom_region_size = start + size > ha->optrom_size ?
  320. ha->optrom_size - start : size;
  321. ha->optrom_state = QLA_SWRITING;
  322. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  323. if (ha->optrom_buffer == NULL) {
  324. ql_log(ql_log_warn, vha, 0x7066,
  325. "Unable to allocate memory for optrom update "
  326. "(%x)\n", ha->optrom_region_size);
  327. ha->optrom_state = QLA_SWAITING;
  328. return -ENOMEM;
  329. }
  330. ql_dbg(ql_dbg_user, vha, 0x7067,
  331. "Staging flash region write -- 0x%x/0x%x.\n",
  332. ha->optrom_region_start, ha->optrom_region_size);
  333. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  334. break;
  335. case 3:
  336. if (ha->optrom_state != QLA_SWRITING)
  337. return -EINVAL;
  338. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  339. ql_log(ql_log_warn, vha, 0x7068,
  340. "HBA not online, failing flash update.\n");
  341. return -EAGAIN;
  342. }
  343. ql_dbg(ql_dbg_user, vha, 0x7069,
  344. "Writing flash region -- 0x%x/0x%x.\n",
  345. ha->optrom_region_start, ha->optrom_region_size);
  346. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  347. ha->optrom_region_start, ha->optrom_region_size);
  348. break;
  349. default:
  350. return -EINVAL;
  351. }
  352. return count;
  353. }
  354. static struct bin_attribute sysfs_optrom_ctl_attr = {
  355. .attr = {
  356. .name = "optrom_ctl",
  357. .mode = S_IWUSR,
  358. },
  359. .size = 0,
  360. .write = qla2x00_sysfs_write_optrom_ctl,
  361. };
  362. static ssize_t
  363. qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
  364. struct bin_attribute *bin_attr,
  365. char *buf, loff_t off, size_t count)
  366. {
  367. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  368. struct device, kobj)));
  369. struct qla_hw_data *ha = vha->hw;
  370. if (unlikely(pci_channel_offline(ha->pdev)))
  371. return -EAGAIN;
  372. if (!capable(CAP_SYS_ADMIN))
  373. return -EINVAL;
  374. if (IS_NOCACHE_VPD_TYPE(ha))
  375. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  376. ha->vpd_size);
  377. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  378. }
  379. static ssize_t
  380. qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
  381. struct bin_attribute *bin_attr,
  382. char *buf, loff_t off, size_t count)
  383. {
  384. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  385. struct device, kobj)));
  386. struct qla_hw_data *ha = vha->hw;
  387. uint8_t *tmp_data;
  388. if (unlikely(pci_channel_offline(ha->pdev)))
  389. return 0;
  390. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  391. !ha->isp_ops->write_nvram)
  392. return 0;
  393. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  394. ql_log(ql_log_warn, vha, 0x706a,
  395. "HBA not online, failing VPD update.\n");
  396. return -EAGAIN;
  397. }
  398. /* Write NVRAM. */
  399. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  400. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  401. /* Update flash version information for 4Gb & above. */
  402. if (!IS_FWI2_CAPABLE(ha))
  403. return -EINVAL;
  404. tmp_data = vmalloc(256);
  405. if (!tmp_data) {
  406. ql_log(ql_log_warn, vha, 0x706b,
  407. "Unable to allocate memory for VPD information update.\n");
  408. return -ENOMEM;
  409. }
  410. ha->isp_ops->get_flash_version(vha, tmp_data);
  411. vfree(tmp_data);
  412. return count;
  413. }
  414. static struct bin_attribute sysfs_vpd_attr = {
  415. .attr = {
  416. .name = "vpd",
  417. .mode = S_IRUSR | S_IWUSR,
  418. },
  419. .size = 0,
  420. .read = qla2x00_sysfs_read_vpd,
  421. .write = qla2x00_sysfs_write_vpd,
  422. };
  423. static ssize_t
  424. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  425. struct bin_attribute *bin_attr,
  426. char *buf, loff_t off, size_t count)
  427. {
  428. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  429. struct device, kobj)));
  430. struct qla_hw_data *ha = vha->hw;
  431. uint16_t iter, addr, offset;
  432. int rval;
  433. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  434. return 0;
  435. if (ha->sfp_data)
  436. goto do_read;
  437. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  438. &ha->sfp_data_dma);
  439. if (!ha->sfp_data) {
  440. ql_log(ql_log_warn, vha, 0x706c,
  441. "Unable to allocate memory for SFP read-data.\n");
  442. return 0;
  443. }
  444. do_read:
  445. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  446. addr = 0xa0;
  447. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  448. iter++, offset += SFP_BLOCK_SIZE) {
  449. if (iter == 4) {
  450. /* Skip to next device address. */
  451. addr = 0xa2;
  452. offset = 0;
  453. }
  454. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
  455. addr, offset, SFP_BLOCK_SIZE, 0);
  456. if (rval != QLA_SUCCESS) {
  457. ql_log(ql_log_warn, vha, 0x706d,
  458. "Unable to read SFP data (%x/%x/%x).\n", rval,
  459. addr, offset);
  460. return -EIO;
  461. }
  462. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  463. buf += SFP_BLOCK_SIZE;
  464. }
  465. return count;
  466. }
  467. static struct bin_attribute sysfs_sfp_attr = {
  468. .attr = {
  469. .name = "sfp",
  470. .mode = S_IRUSR | S_IWUSR,
  471. },
  472. .size = SFP_DEV_SIZE * 2,
  473. .read = qla2x00_sysfs_read_sfp,
  474. };
  475. static ssize_t
  476. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  477. struct bin_attribute *bin_attr,
  478. char *buf, loff_t off, size_t count)
  479. {
  480. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  481. struct device, kobj)));
  482. struct qla_hw_data *ha = vha->hw;
  483. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  484. int type;
  485. uint32_t idc_control;
  486. if (off != 0)
  487. return -EINVAL;
  488. type = simple_strtol(buf, NULL, 10);
  489. switch (type) {
  490. case 0x2025c:
  491. ql_log(ql_log_info, vha, 0x706e,
  492. "Issuing ISP reset.\n");
  493. scsi_block_requests(vha->host);
  494. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  495. if (IS_QLA82XX(ha)) {
  496. ha->flags.isp82xx_no_md_cap = 1;
  497. qla82xx_idc_lock(ha);
  498. qla82xx_set_reset_owner(vha);
  499. qla82xx_idc_unlock(ha);
  500. }
  501. qla2xxx_wake_dpc(vha);
  502. qla2x00_wait_for_chip_reset(vha);
  503. scsi_unblock_requests(vha->host);
  504. break;
  505. case 0x2025d:
  506. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  507. return -EPERM;
  508. ql_log(ql_log_info, vha, 0x706f,
  509. "Issuing MPI reset.\n");
  510. if (IS_QLA83XX(ha)) {
  511. uint32_t idc_control;
  512. qla83xx_idc_lock(vha, 0);
  513. __qla83xx_get_idc_control(vha, &idc_control);
  514. idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
  515. __qla83xx_set_idc_control(vha, idc_control);
  516. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  517. QLA8XXX_DEV_NEED_RESET);
  518. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  519. qla83xx_idc_unlock(vha, 0);
  520. break;
  521. } else {
  522. /* Make sure FC side is not in reset */
  523. qla2x00_wait_for_hba_online(vha);
  524. /* Issue MPI reset */
  525. scsi_block_requests(vha->host);
  526. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  527. ql_log(ql_log_warn, vha, 0x7070,
  528. "MPI reset failed.\n");
  529. scsi_unblock_requests(vha->host);
  530. break;
  531. }
  532. case 0x2025e:
  533. if (!IS_QLA82XX(ha) || vha != base_vha) {
  534. ql_log(ql_log_info, vha, 0x7071,
  535. "FCoE ctx reset no supported.\n");
  536. return -EPERM;
  537. }
  538. ql_log(ql_log_info, vha, 0x7072,
  539. "Issuing FCoE ctx reset.\n");
  540. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  541. qla2xxx_wake_dpc(vha);
  542. qla2x00_wait_for_fcoe_ctx_reset(vha);
  543. break;
  544. case 0x2025f:
  545. if (!IS_QLA8031(ha))
  546. return -EPERM;
  547. ql_log(ql_log_info, vha, 0x70bc,
  548. "Disabling Reset by IDC control\n");
  549. qla83xx_idc_lock(vha, 0);
  550. __qla83xx_get_idc_control(vha, &idc_control);
  551. idc_control |= QLA83XX_IDC_RESET_DISABLED;
  552. __qla83xx_set_idc_control(vha, idc_control);
  553. qla83xx_idc_unlock(vha, 0);
  554. break;
  555. case 0x20260:
  556. if (!IS_QLA8031(ha))
  557. return -EPERM;
  558. ql_log(ql_log_info, vha, 0x70bd,
  559. "Enabling Reset by IDC control\n");
  560. qla83xx_idc_lock(vha, 0);
  561. __qla83xx_get_idc_control(vha, &idc_control);
  562. idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
  563. __qla83xx_set_idc_control(vha, idc_control);
  564. qla83xx_idc_unlock(vha, 0);
  565. break;
  566. }
  567. return count;
  568. }
  569. static struct bin_attribute sysfs_reset_attr = {
  570. .attr = {
  571. .name = "reset",
  572. .mode = S_IWUSR,
  573. },
  574. .size = 0,
  575. .write = qla2x00_sysfs_write_reset,
  576. };
  577. static ssize_t
  578. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  579. struct bin_attribute *bin_attr,
  580. char *buf, loff_t off, size_t count)
  581. {
  582. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  583. struct device, kobj)));
  584. struct qla_hw_data *ha = vha->hw;
  585. int rval;
  586. uint16_t actual_size;
  587. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  588. return 0;
  589. if (ha->xgmac_data)
  590. goto do_read;
  591. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  592. &ha->xgmac_data_dma, GFP_KERNEL);
  593. if (!ha->xgmac_data) {
  594. ql_log(ql_log_warn, vha, 0x7076,
  595. "Unable to allocate memory for XGMAC read-data.\n");
  596. return 0;
  597. }
  598. do_read:
  599. actual_size = 0;
  600. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  601. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  602. XGMAC_DATA_SIZE, &actual_size);
  603. if (rval != QLA_SUCCESS) {
  604. ql_log(ql_log_warn, vha, 0x7077,
  605. "Unable to read XGMAC data (%x).\n", rval);
  606. count = 0;
  607. }
  608. count = actual_size > count ? count: actual_size;
  609. memcpy(buf, ha->xgmac_data, count);
  610. return count;
  611. }
  612. static struct bin_attribute sysfs_xgmac_stats_attr = {
  613. .attr = {
  614. .name = "xgmac_stats",
  615. .mode = S_IRUSR,
  616. },
  617. .size = 0,
  618. .read = qla2x00_sysfs_read_xgmac_stats,
  619. };
  620. static ssize_t
  621. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  622. struct bin_attribute *bin_attr,
  623. char *buf, loff_t off, size_t count)
  624. {
  625. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  626. struct device, kobj)));
  627. struct qla_hw_data *ha = vha->hw;
  628. int rval;
  629. uint16_t actual_size;
  630. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  631. return 0;
  632. if (ha->dcbx_tlv)
  633. goto do_read;
  634. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  635. &ha->dcbx_tlv_dma, GFP_KERNEL);
  636. if (!ha->dcbx_tlv) {
  637. ql_log(ql_log_warn, vha, 0x7078,
  638. "Unable to allocate memory for DCBX TLV read-data.\n");
  639. return -ENOMEM;
  640. }
  641. do_read:
  642. actual_size = 0;
  643. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  644. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  645. DCBX_TLV_DATA_SIZE);
  646. if (rval != QLA_SUCCESS) {
  647. ql_log(ql_log_warn, vha, 0x7079,
  648. "Unable to read DCBX TLV (%x).\n", rval);
  649. return -EIO;
  650. }
  651. memcpy(buf, ha->dcbx_tlv, count);
  652. return count;
  653. }
  654. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  655. .attr = {
  656. .name = "dcbx_tlv",
  657. .mode = S_IRUSR,
  658. },
  659. .size = 0,
  660. .read = qla2x00_sysfs_read_dcbx_tlv,
  661. };
  662. static struct sysfs_entry {
  663. char *name;
  664. struct bin_attribute *attr;
  665. int is4GBp_only;
  666. } bin_file_entries[] = {
  667. { "fw_dump", &sysfs_fw_dump_attr, },
  668. { "nvram", &sysfs_nvram_attr, },
  669. { "optrom", &sysfs_optrom_attr, },
  670. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  671. { "vpd", &sysfs_vpd_attr, 1 },
  672. { "sfp", &sysfs_sfp_attr, 1 },
  673. { "reset", &sysfs_reset_attr, },
  674. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  675. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  676. { NULL },
  677. };
  678. void
  679. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  680. {
  681. struct Scsi_Host *host = vha->host;
  682. struct sysfs_entry *iter;
  683. int ret;
  684. for (iter = bin_file_entries; iter->name; iter++) {
  685. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  686. continue;
  687. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  688. continue;
  689. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  690. continue;
  691. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  692. iter->attr);
  693. if (ret)
  694. ql_log(ql_log_warn, vha, 0x00f3,
  695. "Unable to create sysfs %s binary attribute (%d).\n",
  696. iter->name, ret);
  697. else
  698. ql_dbg(ql_dbg_init, vha, 0x00f4,
  699. "Successfully created sysfs %s binary attribure.\n",
  700. iter->name);
  701. }
  702. }
  703. void
  704. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  705. {
  706. struct Scsi_Host *host = vha->host;
  707. struct sysfs_entry *iter;
  708. struct qla_hw_data *ha = vha->hw;
  709. for (iter = bin_file_entries; iter->name; iter++) {
  710. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  711. continue;
  712. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  713. continue;
  714. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  715. continue;
  716. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  717. iter->attr);
  718. }
  719. if (ha->beacon_blink_led == 1)
  720. ha->isp_ops->beacon_off(vha);
  721. }
  722. /* Scsi_Host attributes. */
  723. static ssize_t
  724. qla2x00_drvr_version_show(struct device *dev,
  725. struct device_attribute *attr, char *buf)
  726. {
  727. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  728. }
  729. static ssize_t
  730. qla2x00_fw_version_show(struct device *dev,
  731. struct device_attribute *attr, char *buf)
  732. {
  733. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  734. struct qla_hw_data *ha = vha->hw;
  735. char fw_str[128];
  736. return snprintf(buf, PAGE_SIZE, "%s\n",
  737. ha->isp_ops->fw_version_str(vha, fw_str));
  738. }
  739. static ssize_t
  740. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  741. char *buf)
  742. {
  743. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  744. struct qla_hw_data *ha = vha->hw;
  745. uint32_t sn;
  746. if (IS_FWI2_CAPABLE(ha)) {
  747. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  748. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  749. }
  750. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  751. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  752. sn % 100000);
  753. }
  754. static ssize_t
  755. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  756. char *buf)
  757. {
  758. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  759. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  760. }
  761. static ssize_t
  762. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  763. char *buf)
  764. {
  765. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  766. struct qla_hw_data *ha = vha->hw;
  767. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  768. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  769. ha->product_id[3]);
  770. }
  771. static ssize_t
  772. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  773. char *buf)
  774. {
  775. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  776. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  777. }
  778. static ssize_t
  779. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  780. char *buf)
  781. {
  782. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  783. return snprintf(buf, PAGE_SIZE, "%s\n",
  784. vha->hw->model_desc ? vha->hw->model_desc : "");
  785. }
  786. static ssize_t
  787. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  788. char *buf)
  789. {
  790. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  791. char pci_info[30];
  792. return snprintf(buf, PAGE_SIZE, "%s\n",
  793. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  794. }
  795. static ssize_t
  796. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  797. char *buf)
  798. {
  799. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  800. struct qla_hw_data *ha = vha->hw;
  801. int len = 0;
  802. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  803. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  804. vha->device_flags & DFLG_NO_CABLE)
  805. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  806. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  807. qla2x00_reset_active(vha))
  808. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  809. else {
  810. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  811. switch (ha->current_topology) {
  812. case ISP_CFG_NL:
  813. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  814. break;
  815. case ISP_CFG_FL:
  816. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  817. break;
  818. case ISP_CFG_N:
  819. len += snprintf(buf + len, PAGE_SIZE-len,
  820. "N_Port to N_Port\n");
  821. break;
  822. case ISP_CFG_F:
  823. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  824. break;
  825. default:
  826. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  827. break;
  828. }
  829. }
  830. return len;
  831. }
  832. static ssize_t
  833. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  834. char *buf)
  835. {
  836. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  837. int len = 0;
  838. switch (vha->hw->zio_mode) {
  839. case QLA_ZIO_MODE_6:
  840. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  841. break;
  842. case QLA_ZIO_DISABLED:
  843. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  844. break;
  845. }
  846. return len;
  847. }
  848. static ssize_t
  849. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  850. const char *buf, size_t count)
  851. {
  852. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  853. struct qla_hw_data *ha = vha->hw;
  854. int val = 0;
  855. uint16_t zio_mode;
  856. if (!IS_ZIO_SUPPORTED(ha))
  857. return -ENOTSUPP;
  858. if (sscanf(buf, "%d", &val) != 1)
  859. return -EINVAL;
  860. if (val)
  861. zio_mode = QLA_ZIO_MODE_6;
  862. else
  863. zio_mode = QLA_ZIO_DISABLED;
  864. /* Update per-hba values and queue a reset. */
  865. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  866. ha->zio_mode = zio_mode;
  867. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  868. }
  869. return strlen(buf);
  870. }
  871. static ssize_t
  872. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  873. char *buf)
  874. {
  875. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  876. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  877. }
  878. static ssize_t
  879. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  880. const char *buf, size_t count)
  881. {
  882. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  883. int val = 0;
  884. uint16_t zio_timer;
  885. if (sscanf(buf, "%d", &val) != 1)
  886. return -EINVAL;
  887. if (val > 25500 || val < 100)
  888. return -ERANGE;
  889. zio_timer = (uint16_t)(val / 100);
  890. vha->hw->zio_timer = zio_timer;
  891. return strlen(buf);
  892. }
  893. static ssize_t
  894. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  895. char *buf)
  896. {
  897. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  898. int len = 0;
  899. if (vha->hw->beacon_blink_led)
  900. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  901. else
  902. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  903. return len;
  904. }
  905. static ssize_t
  906. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  907. const char *buf, size_t count)
  908. {
  909. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  910. struct qla_hw_data *ha = vha->hw;
  911. int val = 0;
  912. int rval;
  913. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  914. return -EPERM;
  915. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  916. ql_log(ql_log_warn, vha, 0x707a,
  917. "Abort ISP active -- ignoring beacon request.\n");
  918. return -EBUSY;
  919. }
  920. if (sscanf(buf, "%d", &val) != 1)
  921. return -EINVAL;
  922. if (val)
  923. rval = ha->isp_ops->beacon_on(vha);
  924. else
  925. rval = ha->isp_ops->beacon_off(vha);
  926. if (rval != QLA_SUCCESS)
  927. count = 0;
  928. return count;
  929. }
  930. static ssize_t
  931. qla2x00_optrom_bios_version_show(struct device *dev,
  932. struct device_attribute *attr, char *buf)
  933. {
  934. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  935. struct qla_hw_data *ha = vha->hw;
  936. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  937. ha->bios_revision[0]);
  938. }
  939. static ssize_t
  940. qla2x00_optrom_efi_version_show(struct device *dev,
  941. struct device_attribute *attr, char *buf)
  942. {
  943. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  944. struct qla_hw_data *ha = vha->hw;
  945. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  946. ha->efi_revision[0]);
  947. }
  948. static ssize_t
  949. qla2x00_optrom_fcode_version_show(struct device *dev,
  950. struct device_attribute *attr, char *buf)
  951. {
  952. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  953. struct qla_hw_data *ha = vha->hw;
  954. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  955. ha->fcode_revision[0]);
  956. }
  957. static ssize_t
  958. qla2x00_optrom_fw_version_show(struct device *dev,
  959. struct device_attribute *attr, char *buf)
  960. {
  961. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  962. struct qla_hw_data *ha = vha->hw;
  963. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  964. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  965. ha->fw_revision[3]);
  966. }
  967. static ssize_t
  968. qla2x00_optrom_gold_fw_version_show(struct device *dev,
  969. struct device_attribute *attr, char *buf)
  970. {
  971. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  972. struct qla_hw_data *ha = vha->hw;
  973. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  974. return snprintf(buf, PAGE_SIZE, "\n");
  975. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
  976. ha->gold_fw_version[0], ha->gold_fw_version[1],
  977. ha->gold_fw_version[2], ha->gold_fw_version[3]);
  978. }
  979. static ssize_t
  980. qla2x00_total_isp_aborts_show(struct device *dev,
  981. struct device_attribute *attr, char *buf)
  982. {
  983. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  984. return snprintf(buf, PAGE_SIZE, "%d\n",
  985. vha->qla_stats.total_isp_aborts);
  986. }
  987. static ssize_t
  988. qla24xx_84xx_fw_version_show(struct device *dev,
  989. struct device_attribute *attr, char *buf)
  990. {
  991. int rval = QLA_SUCCESS;
  992. uint16_t status[2] = {0, 0};
  993. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  994. struct qla_hw_data *ha = vha->hw;
  995. if (!IS_QLA84XX(ha))
  996. return snprintf(buf, PAGE_SIZE, "\n");
  997. if (ha->cs84xx->op_fw_version == 0)
  998. rval = qla84xx_verify_chip(vha, status);
  999. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1000. return snprintf(buf, PAGE_SIZE, "%u\n",
  1001. (uint32_t)ha->cs84xx->op_fw_version);
  1002. return snprintf(buf, PAGE_SIZE, "\n");
  1003. }
  1004. static ssize_t
  1005. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1006. char *buf)
  1007. {
  1008. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1009. struct qla_hw_data *ha = vha->hw;
  1010. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
  1011. return snprintf(buf, PAGE_SIZE, "\n");
  1012. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1013. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1014. ha->mpi_capabilities);
  1015. }
  1016. static ssize_t
  1017. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1018. char *buf)
  1019. {
  1020. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1021. struct qla_hw_data *ha = vha->hw;
  1022. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
  1023. return snprintf(buf, PAGE_SIZE, "\n");
  1024. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1025. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1026. }
  1027. static ssize_t
  1028. qla2x00_flash_block_size_show(struct device *dev,
  1029. struct device_attribute *attr, char *buf)
  1030. {
  1031. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1032. struct qla_hw_data *ha = vha->hw;
  1033. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1034. }
  1035. static ssize_t
  1036. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1037. char *buf)
  1038. {
  1039. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1040. if (!IS_CNA_CAPABLE(vha->hw))
  1041. return snprintf(buf, PAGE_SIZE, "\n");
  1042. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1043. }
  1044. static ssize_t
  1045. qla2x00_vn_port_mac_address_show(struct device *dev,
  1046. struct device_attribute *attr, char *buf)
  1047. {
  1048. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1049. if (!IS_CNA_CAPABLE(vha->hw))
  1050. return snprintf(buf, PAGE_SIZE, "\n");
  1051. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1052. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1053. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1054. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1055. }
  1056. static ssize_t
  1057. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1058. char *buf)
  1059. {
  1060. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1061. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1062. }
  1063. static ssize_t
  1064. qla2x00_thermal_temp_show(struct device *dev,
  1065. struct device_attribute *attr, char *buf)
  1066. {
  1067. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1068. int rval = QLA_FUNCTION_FAILED;
  1069. uint16_t temp, frac;
  1070. if (!vha->hw->flags.thermal_supported)
  1071. return snprintf(buf, PAGE_SIZE, "\n");
  1072. temp = frac = 0;
  1073. if (qla2x00_reset_active(vha))
  1074. ql_log(ql_log_warn, vha, 0x707b,
  1075. "ISP reset active.\n");
  1076. else if (!vha->hw->flags.eeh_busy)
  1077. rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
  1078. if (rval != QLA_SUCCESS)
  1079. return snprintf(buf, PAGE_SIZE, "\n");
  1080. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
  1081. }
  1082. static ssize_t
  1083. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1084. char *buf)
  1085. {
  1086. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1087. int rval = QLA_FUNCTION_FAILED;
  1088. uint16_t state[5];
  1089. if (qla2x00_reset_active(vha))
  1090. ql_log(ql_log_warn, vha, 0x707c,
  1091. "ISP reset active.\n");
  1092. else if (!vha->hw->flags.eeh_busy)
  1093. rval = qla2x00_get_firmware_state(vha, state);
  1094. if (rval != QLA_SUCCESS)
  1095. memset(state, -1, sizeof(state));
  1096. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1097. state[1], state[2], state[3], state[4]);
  1098. }
  1099. static ssize_t
  1100. qla2x00_diag_requests_show(struct device *dev,
  1101. struct device_attribute *attr, char *buf)
  1102. {
  1103. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1104. if (!IS_BIDI_CAPABLE(vha->hw))
  1105. return snprintf(buf, PAGE_SIZE, "\n");
  1106. return snprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
  1107. }
  1108. static ssize_t
  1109. qla2x00_diag_megabytes_show(struct device *dev,
  1110. struct device_attribute *attr, char *buf)
  1111. {
  1112. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1113. if (!IS_BIDI_CAPABLE(vha->hw))
  1114. return snprintf(buf, PAGE_SIZE, "\n");
  1115. return snprintf(buf, PAGE_SIZE, "%llu\n",
  1116. vha->bidi_stats.transfer_bytes >> 20);
  1117. }
  1118. static ssize_t
  1119. qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
  1120. char *buf)
  1121. {
  1122. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1123. struct qla_hw_data *ha = vha->hw;
  1124. uint32_t size;
  1125. if (!ha->fw_dumped)
  1126. size = 0;
  1127. else if (IS_QLA82XX(ha))
  1128. size = ha->md_template_size + ha->md_dump_size;
  1129. else
  1130. size = ha->fw_dump_len;
  1131. return snprintf(buf, PAGE_SIZE, "%d\n", size);
  1132. }
  1133. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1134. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1135. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1136. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1137. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1138. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1139. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1140. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1141. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1142. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1143. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1144. qla2x00_zio_timer_store);
  1145. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1146. qla2x00_beacon_store);
  1147. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1148. qla2x00_optrom_bios_version_show, NULL);
  1149. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1150. qla2x00_optrom_efi_version_show, NULL);
  1151. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1152. qla2x00_optrom_fcode_version_show, NULL);
  1153. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1154. NULL);
  1155. static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
  1156. qla2x00_optrom_gold_fw_version_show, NULL);
  1157. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1158. NULL);
  1159. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1160. NULL);
  1161. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1162. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1163. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1164. NULL);
  1165. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1166. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1167. qla2x00_vn_port_mac_address_show, NULL);
  1168. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1169. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1170. static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
  1171. static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
  1172. static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
  1173. static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
  1174. struct device_attribute *qla2x00_host_attrs[] = {
  1175. &dev_attr_driver_version,
  1176. &dev_attr_fw_version,
  1177. &dev_attr_serial_num,
  1178. &dev_attr_isp_name,
  1179. &dev_attr_isp_id,
  1180. &dev_attr_model_name,
  1181. &dev_attr_model_desc,
  1182. &dev_attr_pci_info,
  1183. &dev_attr_link_state,
  1184. &dev_attr_zio,
  1185. &dev_attr_zio_timer,
  1186. &dev_attr_beacon,
  1187. &dev_attr_optrom_bios_version,
  1188. &dev_attr_optrom_efi_version,
  1189. &dev_attr_optrom_fcode_version,
  1190. &dev_attr_optrom_fw_version,
  1191. &dev_attr_84xx_fw_version,
  1192. &dev_attr_total_isp_aborts,
  1193. &dev_attr_mpi_version,
  1194. &dev_attr_phy_version,
  1195. &dev_attr_flash_block_size,
  1196. &dev_attr_vlan_id,
  1197. &dev_attr_vn_port_mac_address,
  1198. &dev_attr_fabric_param,
  1199. &dev_attr_fw_state,
  1200. &dev_attr_optrom_gold_fw_version,
  1201. &dev_attr_thermal_temp,
  1202. &dev_attr_diag_requests,
  1203. &dev_attr_diag_megabytes,
  1204. &dev_attr_fw_dump_size,
  1205. NULL,
  1206. };
  1207. /* Host attributes. */
  1208. static void
  1209. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1210. {
  1211. scsi_qla_host_t *vha = shost_priv(shost);
  1212. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1213. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1214. }
  1215. static void
  1216. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1217. {
  1218. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1219. (shost_priv(shost)))->hw;
  1220. u32 speed = FC_PORTSPEED_UNKNOWN;
  1221. switch (ha->link_data_rate) {
  1222. case PORT_SPEED_1GB:
  1223. speed = FC_PORTSPEED_1GBIT;
  1224. break;
  1225. case PORT_SPEED_2GB:
  1226. speed = FC_PORTSPEED_2GBIT;
  1227. break;
  1228. case PORT_SPEED_4GB:
  1229. speed = FC_PORTSPEED_4GBIT;
  1230. break;
  1231. case PORT_SPEED_8GB:
  1232. speed = FC_PORTSPEED_8GBIT;
  1233. break;
  1234. case PORT_SPEED_10GB:
  1235. speed = FC_PORTSPEED_10GBIT;
  1236. break;
  1237. case PORT_SPEED_16GB:
  1238. speed = FC_PORTSPEED_16GBIT;
  1239. break;
  1240. }
  1241. fc_host_speed(shost) = speed;
  1242. }
  1243. static void
  1244. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1245. {
  1246. scsi_qla_host_t *vha = shost_priv(shost);
  1247. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1248. if (vha->vp_idx) {
  1249. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1250. return;
  1251. }
  1252. switch (vha->hw->current_topology) {
  1253. case ISP_CFG_NL:
  1254. port_type = FC_PORTTYPE_LPORT;
  1255. break;
  1256. case ISP_CFG_FL:
  1257. port_type = FC_PORTTYPE_NLPORT;
  1258. break;
  1259. case ISP_CFG_N:
  1260. port_type = FC_PORTTYPE_PTP;
  1261. break;
  1262. case ISP_CFG_F:
  1263. port_type = FC_PORTTYPE_NPORT;
  1264. break;
  1265. }
  1266. fc_host_port_type(shost) = port_type;
  1267. }
  1268. static void
  1269. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1270. {
  1271. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1272. scsi_qla_host_t *vha = shost_priv(host);
  1273. fc_port_t *fcport;
  1274. u64 node_name = 0;
  1275. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1276. if (fcport->rport &&
  1277. starget->id == fcport->rport->scsi_target_id) {
  1278. node_name = wwn_to_u64(fcport->node_name);
  1279. break;
  1280. }
  1281. }
  1282. fc_starget_node_name(starget) = node_name;
  1283. }
  1284. static void
  1285. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1286. {
  1287. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1288. scsi_qla_host_t *vha = shost_priv(host);
  1289. fc_port_t *fcport;
  1290. u64 port_name = 0;
  1291. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1292. if (fcport->rport &&
  1293. starget->id == fcport->rport->scsi_target_id) {
  1294. port_name = wwn_to_u64(fcport->port_name);
  1295. break;
  1296. }
  1297. }
  1298. fc_starget_port_name(starget) = port_name;
  1299. }
  1300. static void
  1301. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1302. {
  1303. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1304. scsi_qla_host_t *vha = shost_priv(host);
  1305. fc_port_t *fcport;
  1306. uint32_t port_id = ~0U;
  1307. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1308. if (fcport->rport &&
  1309. starget->id == fcport->rport->scsi_target_id) {
  1310. port_id = fcport->d_id.b.domain << 16 |
  1311. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1312. break;
  1313. }
  1314. }
  1315. fc_starget_port_id(starget) = port_id;
  1316. }
  1317. static void
  1318. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1319. {
  1320. if (timeout)
  1321. rport->dev_loss_tmo = timeout;
  1322. else
  1323. rport->dev_loss_tmo = 1;
  1324. }
  1325. static void
  1326. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1327. {
  1328. struct Scsi_Host *host = rport_to_shost(rport);
  1329. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1330. unsigned long flags;
  1331. if (!fcport)
  1332. return;
  1333. /* Now that the rport has been deleted, set the fcport state to
  1334. FCS_DEVICE_DEAD */
  1335. qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
  1336. /*
  1337. * Transport has effectively 'deleted' the rport, clear
  1338. * all local references.
  1339. */
  1340. spin_lock_irqsave(host->host_lock, flags);
  1341. fcport->rport = fcport->drport = NULL;
  1342. *((fc_port_t **)rport->dd_data) = NULL;
  1343. spin_unlock_irqrestore(host->host_lock, flags);
  1344. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1345. return;
  1346. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1347. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1348. return;
  1349. }
  1350. }
  1351. static void
  1352. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1353. {
  1354. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1355. if (!fcport)
  1356. return;
  1357. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1358. return;
  1359. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1360. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1361. return;
  1362. }
  1363. /*
  1364. * At this point all fcport's software-states are cleared. Perform any
  1365. * final cleanup of firmware resources (PCBs and XCBs).
  1366. */
  1367. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1368. !test_bit(UNLOADING, &fcport->vha->dpc_flags)) {
  1369. if (IS_FWI2_CAPABLE(fcport->vha->hw))
  1370. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1371. fcport->loop_id, fcport->d_id.b.domain,
  1372. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1373. else
  1374. qla2x00_port_logout(fcport->vha, fcport);
  1375. }
  1376. }
  1377. static int
  1378. qla2x00_issue_lip(struct Scsi_Host *shost)
  1379. {
  1380. scsi_qla_host_t *vha = shost_priv(shost);
  1381. qla2x00_loop_reset(vha);
  1382. return 0;
  1383. }
  1384. static struct fc_host_statistics *
  1385. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1386. {
  1387. scsi_qla_host_t *vha = shost_priv(shost);
  1388. struct qla_hw_data *ha = vha->hw;
  1389. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1390. int rval;
  1391. struct link_statistics *stats;
  1392. dma_addr_t stats_dma;
  1393. struct fc_host_statistics *pfc_host_stat;
  1394. pfc_host_stat = &vha->fc_host_stat;
  1395. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1396. if (test_bit(UNLOADING, &vha->dpc_flags))
  1397. goto done;
  1398. if (unlikely(pci_channel_offline(ha->pdev)))
  1399. goto done;
  1400. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1401. if (stats == NULL) {
  1402. ql_log(ql_log_warn, vha, 0x707d,
  1403. "Failed to allocate memory for stats.\n");
  1404. goto done;
  1405. }
  1406. memset(stats, 0, DMA_POOL_SIZE);
  1407. rval = QLA_FUNCTION_FAILED;
  1408. if (IS_FWI2_CAPABLE(ha)) {
  1409. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1410. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1411. !qla2x00_reset_active(vha) && !ha->dpc_active) {
  1412. /* Must be in a 'READY' state for statistics retrieval. */
  1413. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1414. stats, stats_dma);
  1415. }
  1416. if (rval != QLA_SUCCESS)
  1417. goto done_free;
  1418. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1419. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1420. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1421. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1422. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1423. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1424. if (IS_FWI2_CAPABLE(ha)) {
  1425. pfc_host_stat->lip_count = stats->lip_cnt;
  1426. pfc_host_stat->tx_frames = stats->tx_frames;
  1427. pfc_host_stat->rx_frames = stats->rx_frames;
  1428. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1429. pfc_host_stat->nos_count = stats->nos_rcvd;
  1430. }
  1431. pfc_host_stat->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
  1432. pfc_host_stat->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
  1433. done_free:
  1434. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1435. done:
  1436. return pfc_host_stat;
  1437. }
  1438. static void
  1439. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1440. {
  1441. scsi_qla_host_t *vha = shost_priv(shost);
  1442. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1443. }
  1444. static void
  1445. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1446. {
  1447. scsi_qla_host_t *vha = shost_priv(shost);
  1448. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1449. }
  1450. static void
  1451. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1452. {
  1453. scsi_qla_host_t *vha = shost_priv(shost);
  1454. uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
  1455. 0xFF, 0xFF, 0xFF, 0xFF};
  1456. u64 fabric_name = wwn_to_u64(node_name);
  1457. if (vha->device_flags & SWITCH_FOUND)
  1458. fabric_name = wwn_to_u64(vha->fabric_node_name);
  1459. fc_host_fabric_name(shost) = fabric_name;
  1460. }
  1461. static void
  1462. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1463. {
  1464. scsi_qla_host_t *vha = shost_priv(shost);
  1465. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1466. if (!base_vha->flags.online) {
  1467. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1468. return;
  1469. }
  1470. switch (atomic_read(&base_vha->loop_state)) {
  1471. case LOOP_UPDATE:
  1472. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1473. break;
  1474. case LOOP_DOWN:
  1475. if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
  1476. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1477. else
  1478. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1479. break;
  1480. case LOOP_DEAD:
  1481. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1482. break;
  1483. case LOOP_READY:
  1484. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1485. break;
  1486. default:
  1487. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1488. break;
  1489. }
  1490. }
  1491. static int
  1492. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1493. {
  1494. int ret = 0;
  1495. uint8_t qos = 0;
  1496. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1497. scsi_qla_host_t *vha = NULL;
  1498. struct qla_hw_data *ha = base_vha->hw;
  1499. uint16_t options = 0;
  1500. int cnt;
  1501. struct req_que *req = ha->req_q_map[0];
  1502. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1503. if (ret) {
  1504. ql_log(ql_log_warn, vha, 0x707e,
  1505. "Vport sanity check failed, status %x\n", ret);
  1506. return (ret);
  1507. }
  1508. vha = qla24xx_create_vhost(fc_vport);
  1509. if (vha == NULL) {
  1510. ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
  1511. return FC_VPORT_FAILED;
  1512. }
  1513. if (disable) {
  1514. atomic_set(&vha->vp_state, VP_OFFLINE);
  1515. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1516. } else
  1517. atomic_set(&vha->vp_state, VP_FAILED);
  1518. /* ready to create vport */
  1519. ql_log(ql_log_info, vha, 0x7080,
  1520. "VP entry id %d assigned.\n", vha->vp_idx);
  1521. /* initialized vport states */
  1522. atomic_set(&vha->loop_state, LOOP_DOWN);
  1523. vha->vp_err_state= VP_ERR_PORTDWN;
  1524. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1525. /* Check if physical ha port is Up */
  1526. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1527. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1528. /* Don't retry or attempt login of this virtual port */
  1529. ql_dbg(ql_dbg_user, vha, 0x7081,
  1530. "Vport loop state is not UP.\n");
  1531. atomic_set(&vha->loop_state, LOOP_DEAD);
  1532. if (!disable)
  1533. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1534. }
  1535. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  1536. if (ha->fw_attributes & BIT_4) {
  1537. int prot = 0;
  1538. vha->flags.difdix_supported = 1;
  1539. ql_dbg(ql_dbg_user, vha, 0x7082,
  1540. "Registered for DIF/DIX type 1 and 3 protection.\n");
  1541. if (ql2xenabledif == 1)
  1542. prot = SHOST_DIX_TYPE0_PROTECTION;
  1543. scsi_host_set_prot(vha->host,
  1544. prot | SHOST_DIF_TYPE1_PROTECTION
  1545. | SHOST_DIF_TYPE2_PROTECTION
  1546. | SHOST_DIF_TYPE3_PROTECTION
  1547. | SHOST_DIX_TYPE1_PROTECTION
  1548. | SHOST_DIX_TYPE2_PROTECTION
  1549. | SHOST_DIX_TYPE3_PROTECTION);
  1550. scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
  1551. } else
  1552. vha->flags.difdix_supported = 0;
  1553. }
  1554. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1555. &ha->pdev->dev)) {
  1556. ql_dbg(ql_dbg_user, vha, 0x7083,
  1557. "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
  1558. goto vport_create_failed_2;
  1559. }
  1560. /* initialize attributes */
  1561. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1562. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1563. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1564. fc_host_supported_classes(vha->host) =
  1565. fc_host_supported_classes(base_vha->host);
  1566. fc_host_supported_speeds(vha->host) =
  1567. fc_host_supported_speeds(base_vha->host);
  1568. qlt_vport_create(vha, ha);
  1569. qla24xx_vport_disable(fc_vport, disable);
  1570. if (ha->flags.cpu_affinity_enabled) {
  1571. req = ha->req_q_map[1];
  1572. ql_dbg(ql_dbg_multiq, vha, 0xc000,
  1573. "Request queue %p attached with "
  1574. "VP[%d], cpu affinity =%d\n",
  1575. req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
  1576. goto vport_queue;
  1577. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1578. goto vport_queue;
  1579. /* Create a request queue in QoS mode for the vport */
  1580. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1581. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1582. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1583. 8) == 0) {
  1584. qos = ha->npiv_info[cnt].q_qos;
  1585. break;
  1586. }
  1587. }
  1588. if (qos) {
  1589. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1590. qos);
  1591. if (!ret)
  1592. ql_log(ql_log_warn, vha, 0x7084,
  1593. "Can't create request queue for VP[%d]\n",
  1594. vha->vp_idx);
  1595. else {
  1596. ql_dbg(ql_dbg_multiq, vha, 0xc001,
  1597. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1598. ret, qos, vha->vp_idx);
  1599. ql_dbg(ql_dbg_user, vha, 0x7085,
  1600. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1601. ret, qos, vha->vp_idx);
  1602. req = ha->req_q_map[ret];
  1603. }
  1604. }
  1605. vport_queue:
  1606. vha->req = req;
  1607. return 0;
  1608. vport_create_failed_2:
  1609. qla24xx_disable_vp(vha);
  1610. qla24xx_deallocate_vp_id(vha);
  1611. scsi_host_put(vha->host);
  1612. return FC_VPORT_FAILED;
  1613. }
  1614. static int
  1615. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1616. {
  1617. scsi_qla_host_t *vha = fc_vport->dd_data;
  1618. struct qla_hw_data *ha = vha->hw;
  1619. uint16_t id = vha->vp_idx;
  1620. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1621. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1622. msleep(1000);
  1623. qla24xx_disable_vp(vha);
  1624. vha->flags.delete_progress = 1;
  1625. fc_remove_host(vha->host);
  1626. scsi_remove_host(vha->host);
  1627. /* Allow timer to run to drain queued items, when removing vp */
  1628. qla24xx_deallocate_vp_id(vha);
  1629. if (vha->timer_active) {
  1630. qla2x00_vp_stop_timer(vha);
  1631. ql_dbg(ql_dbg_user, vha, 0x7086,
  1632. "Timer for the VP[%d] has stopped\n", vha->vp_idx);
  1633. }
  1634. /* No pending activities shall be there on the vha now */
  1635. if (ql2xextended_error_logging & ql_dbg_user)
  1636. msleep(random32()%10); /* Just to see if something falls on
  1637. * the net we have placed below */
  1638. BUG_ON(atomic_read(&vha->vref_count));
  1639. qla2x00_free_fcports(vha);
  1640. mutex_lock(&ha->vport_lock);
  1641. ha->cur_vport_count--;
  1642. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1643. mutex_unlock(&ha->vport_lock);
  1644. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1645. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1646. ql_log(ql_log_warn, vha, 0x7087,
  1647. "Queue delete failed.\n");
  1648. }
  1649. ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
  1650. scsi_host_put(vha->host);
  1651. return 0;
  1652. }
  1653. static int
  1654. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1655. {
  1656. scsi_qla_host_t *vha = fc_vport->dd_data;
  1657. if (disable)
  1658. qla24xx_disable_vp(vha);
  1659. else
  1660. qla24xx_enable_vp(vha);
  1661. return 0;
  1662. }
  1663. struct fc_function_template qla2xxx_transport_functions = {
  1664. .show_host_node_name = 1,
  1665. .show_host_port_name = 1,
  1666. .show_host_supported_classes = 1,
  1667. .show_host_supported_speeds = 1,
  1668. .get_host_port_id = qla2x00_get_host_port_id,
  1669. .show_host_port_id = 1,
  1670. .get_host_speed = qla2x00_get_host_speed,
  1671. .show_host_speed = 1,
  1672. .get_host_port_type = qla2x00_get_host_port_type,
  1673. .show_host_port_type = 1,
  1674. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1675. .show_host_symbolic_name = 1,
  1676. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1677. .show_host_system_hostname = 1,
  1678. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1679. .show_host_fabric_name = 1,
  1680. .get_host_port_state = qla2x00_get_host_port_state,
  1681. .show_host_port_state = 1,
  1682. .dd_fcrport_size = sizeof(struct fc_port *),
  1683. .show_rport_supported_classes = 1,
  1684. .get_starget_node_name = qla2x00_get_starget_node_name,
  1685. .show_starget_node_name = 1,
  1686. .get_starget_port_name = qla2x00_get_starget_port_name,
  1687. .show_starget_port_name = 1,
  1688. .get_starget_port_id = qla2x00_get_starget_port_id,
  1689. .show_starget_port_id = 1,
  1690. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1691. .show_rport_dev_loss_tmo = 1,
  1692. .issue_fc_host_lip = qla2x00_issue_lip,
  1693. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1694. .terminate_rport_io = qla2x00_terminate_rport_io,
  1695. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1696. .vport_create = qla24xx_vport_create,
  1697. .vport_disable = qla24xx_vport_disable,
  1698. .vport_delete = qla24xx_vport_delete,
  1699. .bsg_request = qla24xx_bsg_request,
  1700. .bsg_timeout = qla24xx_bsg_timeout,
  1701. };
  1702. struct fc_function_template qla2xxx_transport_vport_functions = {
  1703. .show_host_node_name = 1,
  1704. .show_host_port_name = 1,
  1705. .show_host_supported_classes = 1,
  1706. .get_host_port_id = qla2x00_get_host_port_id,
  1707. .show_host_port_id = 1,
  1708. .get_host_speed = qla2x00_get_host_speed,
  1709. .show_host_speed = 1,
  1710. .get_host_port_type = qla2x00_get_host_port_type,
  1711. .show_host_port_type = 1,
  1712. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1713. .show_host_symbolic_name = 1,
  1714. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1715. .show_host_system_hostname = 1,
  1716. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1717. .show_host_fabric_name = 1,
  1718. .get_host_port_state = qla2x00_get_host_port_state,
  1719. .show_host_port_state = 1,
  1720. .dd_fcrport_size = sizeof(struct fc_port *),
  1721. .show_rport_supported_classes = 1,
  1722. .get_starget_node_name = qla2x00_get_starget_node_name,
  1723. .show_starget_node_name = 1,
  1724. .get_starget_port_name = qla2x00_get_starget_port_name,
  1725. .show_starget_port_name = 1,
  1726. .get_starget_port_id = qla2x00_get_starget_port_id,
  1727. .show_starget_port_id = 1,
  1728. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1729. .show_rport_dev_loss_tmo = 1,
  1730. .issue_fc_host_lip = qla2x00_issue_lip,
  1731. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1732. .terminate_rport_io = qla2x00_terminate_rport_io,
  1733. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1734. .bsg_request = qla24xx_bsg_request,
  1735. .bsg_timeout = qla24xx_bsg_timeout,
  1736. };
  1737. void
  1738. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1739. {
  1740. struct qla_hw_data *ha = vha->hw;
  1741. u32 speed = FC_PORTSPEED_UNKNOWN;
  1742. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1743. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1744. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1745. fc_host_supported_classes(vha->host) = ha->tgt.enable_class_2 ?
  1746. (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
  1747. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1748. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1749. if (IS_CNA_CAPABLE(ha))
  1750. speed = FC_PORTSPEED_10GBIT;
  1751. else if (IS_QLA2031(ha))
  1752. speed = FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
  1753. FC_PORTSPEED_4GBIT;
  1754. else if (IS_QLA25XX(ha))
  1755. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1756. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1757. else if (IS_QLA24XX_TYPE(ha))
  1758. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1759. FC_PORTSPEED_1GBIT;
  1760. else if (IS_QLA23XX(ha))
  1761. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1762. else
  1763. speed = FC_PORTSPEED_1GBIT;
  1764. fc_host_supported_speeds(vha->host) = speed;
  1765. }