zfcp_fsf.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #include "zfcp_ext.h"
  9. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  10. {
  11. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  12. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
  13. NULL);
  14. }
  15. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  16. unsigned long timeout)
  17. {
  18. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  19. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  20. fsf_req->timer.expires = jiffies + timeout;
  21. add_timer(&fsf_req->timer);
  22. }
  23. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  24. {
  25. BUG_ON(!fsf_req->erp_action);
  26. fsf_req->timer.function = zfcp_erp_timeout_handler;
  27. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  28. fsf_req->timer.expires = jiffies + 30 * HZ;
  29. add_timer(&fsf_req->timer);
  30. }
  31. /* association between FSF command and FSF QTCB type */
  32. static u32 fsf_qtcb_type[] = {
  33. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  34. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  35. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  36. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  37. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  38. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  39. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  40. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  43. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  44. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  46. };
  47. static const char *zfcp_act_subtable_type[] = {
  48. "unknown", "OS", "WWPN", "DID", "LUN"
  49. };
  50. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  51. {
  52. u16 subtable = table >> 16;
  53. u16 rule = table & 0xffff;
  54. if (subtable && subtable < ARRAY_SIZE(zfcp_act_subtable_type))
  55. dev_warn(&adapter->ccw_device->dev,
  56. "Access denied in subtable %s, rule %d.\n",
  57. zfcp_act_subtable_type[subtable], rule);
  58. }
  59. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  60. struct zfcp_port *port)
  61. {
  62. struct fsf_qtcb_header *header = &req->qtcb->header;
  63. dev_warn(&req->adapter->ccw_device->dev,
  64. "Access denied, cannot send command to port 0x%016Lx.\n",
  65. port->wwpn);
  66. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  67. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  68. zfcp_erp_port_access_denied(port, 55, req);
  69. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  70. }
  71. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  72. struct zfcp_unit *unit)
  73. {
  74. struct fsf_qtcb_header *header = &req->qtcb->header;
  75. dev_warn(&req->adapter->ccw_device->dev,
  76. "Access denied for unit 0x%016Lx on port 0x%016Lx.\n",
  77. unit->fcp_lun, unit->port->wwpn);
  78. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  79. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  80. zfcp_erp_unit_access_denied(unit, 59, req);
  81. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  82. }
  83. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  84. {
  85. dev_err(&req->adapter->ccw_device->dev,
  86. "Required FC class not supported by adapter, "
  87. "shutting down adapter.\n");
  88. zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
  89. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  90. }
  91. /**
  92. * zfcp_fsf_req_free - free memory used by fsf request
  93. * @fsf_req: pointer to struct zfcp_fsf_req
  94. */
  95. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  96. {
  97. if (likely(req->pool)) {
  98. mempool_free(req, req->pool);
  99. return;
  100. }
  101. if (req->qtcb) {
  102. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
  103. return;
  104. }
  105. }
  106. /**
  107. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  108. * @adapter: pointer to struct zfcp_adapter
  109. *
  110. * Never ever call this without shutting down the adapter first.
  111. * Otherwise the adapter would continue using and corrupting s390 storage.
  112. * Included BUG_ON() call to ensure this is done.
  113. * ERP is supposed to be the only user of this function.
  114. */
  115. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  116. {
  117. struct zfcp_fsf_req *req, *tmp;
  118. unsigned long flags;
  119. LIST_HEAD(remove_queue);
  120. unsigned int i;
  121. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  122. spin_lock_irqsave(&adapter->req_list_lock, flags);
  123. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  124. list_splice_init(&adapter->req_list[i], &remove_queue);
  125. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  126. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  127. list_del(&req->list);
  128. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  129. zfcp_fsf_req_complete(req);
  130. }
  131. }
  132. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  133. {
  134. struct fsf_status_read_buffer *sr_buf = req->data;
  135. struct zfcp_adapter *adapter = req->adapter;
  136. struct zfcp_port *port;
  137. int d_id = sr_buf->d_id & ZFCP_DID_MASK;
  138. unsigned long flags;
  139. read_lock_irqsave(&zfcp_data.config_lock, flags);
  140. list_for_each_entry(port, &adapter->port_list_head, list)
  141. if (port->d_id == d_id) {
  142. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  143. switch (sr_buf->status_subtype) {
  144. case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
  145. zfcp_erp_port_reopen(port, 0, 101, req);
  146. break;
  147. case FSF_STATUS_READ_SUB_ERROR_PORT:
  148. zfcp_erp_port_shutdown(port, 0, 122, req);
  149. break;
  150. }
  151. return;
  152. }
  153. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  154. }
  155. static void zfcp_fsf_bit_error_threshold(struct zfcp_fsf_req *req)
  156. {
  157. struct zfcp_adapter *adapter = req->adapter;
  158. struct fsf_status_read_buffer *sr_buf = req->data;
  159. struct fsf_bit_error_payload *err = &sr_buf->payload.bit_error;
  160. dev_warn(&adapter->ccw_device->dev,
  161. "Warning: bit error threshold data "
  162. "received for the adapter: "
  163. "link failures = %i, loss of sync errors = %i, "
  164. "loss of signal errors = %i, "
  165. "primitive sequence errors = %i, "
  166. "invalid transmission word errors = %i, "
  167. "CRC errors = %i).\n",
  168. err->link_failure_error_count,
  169. err->loss_of_sync_error_count,
  170. err->loss_of_signal_error_count,
  171. err->primitive_sequence_error_count,
  172. err->invalid_transmission_word_error_count,
  173. err->crc_error_count);
  174. dev_warn(&adapter->ccw_device->dev,
  175. "Additional bit error threshold data of the adapter: "
  176. "primitive sequence event time-outs = %i, "
  177. "elastic buffer overrun errors = %i, "
  178. "advertised receive buffer-to-buffer credit = %i, "
  179. "current receice buffer-to-buffer credit = %i, "
  180. "advertised transmit buffer-to-buffer credit = %i, "
  181. "current transmit buffer-to-buffer credit = %i).\n",
  182. err->primitive_sequence_event_timeout_count,
  183. err->elastic_buffer_overrun_error_count,
  184. err->advertised_receive_b2b_credit,
  185. err->current_receive_b2b_credit,
  186. err->advertised_transmit_b2b_credit,
  187. err->current_transmit_b2b_credit);
  188. }
  189. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
  190. struct fsf_link_down_info *link_down)
  191. {
  192. struct zfcp_adapter *adapter = req->adapter;
  193. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  194. return;
  195. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  196. if (!link_down)
  197. goto out;
  198. switch (link_down->error_code) {
  199. case FSF_PSQ_LINK_NO_LIGHT:
  200. dev_warn(&req->adapter->ccw_device->dev,
  201. "The local link is down: no light detected.\n");
  202. break;
  203. case FSF_PSQ_LINK_WRAP_PLUG:
  204. dev_warn(&req->adapter->ccw_device->dev,
  205. "The local link is down: wrap plug detected.\n");
  206. break;
  207. case FSF_PSQ_LINK_NO_FCP:
  208. dev_warn(&req->adapter->ccw_device->dev,
  209. "The local link is down: "
  210. "adjacent node on link does not support FCP.\n");
  211. break;
  212. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  213. dev_warn(&req->adapter->ccw_device->dev,
  214. "The local link is down: "
  215. "firmware update in progress.\n");
  216. break;
  217. case FSF_PSQ_LINK_INVALID_WWPN:
  218. dev_warn(&req->adapter->ccw_device->dev,
  219. "The local link is down: "
  220. "duplicate or invalid WWPN detected.\n");
  221. break;
  222. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  223. dev_warn(&req->adapter->ccw_device->dev,
  224. "The local link is down: "
  225. "no support for NPIV by Fabric.\n");
  226. break;
  227. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  228. dev_warn(&req->adapter->ccw_device->dev,
  229. "The local link is down: "
  230. "out of resource in FCP daughtercard.\n");
  231. break;
  232. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  233. dev_warn(&req->adapter->ccw_device->dev,
  234. "The local link is down: "
  235. "out of resource in Fabric.\n");
  236. break;
  237. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  238. dev_warn(&req->adapter->ccw_device->dev,
  239. "The local link is down: "
  240. "unable to login to Fabric.\n");
  241. break;
  242. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  243. dev_warn(&req->adapter->ccw_device->dev,
  244. "WWPN assignment file corrupted on adapter.\n");
  245. break;
  246. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  247. dev_warn(&req->adapter->ccw_device->dev,
  248. "Mode table corrupted on adapter.\n");
  249. break;
  250. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  251. dev_warn(&req->adapter->ccw_device->dev,
  252. "No WWPN for assignment table on adapter.\n");
  253. break;
  254. default:
  255. dev_warn(&req->adapter->ccw_device->dev,
  256. "The local link to adapter is down.\n");
  257. }
  258. out:
  259. zfcp_erp_adapter_failed(adapter, id, req);
  260. }
  261. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  262. {
  263. struct zfcp_adapter *adapter = req->adapter;
  264. struct fsf_status_read_buffer *sr_buf = req->data;
  265. struct fsf_link_down_info *ldi =
  266. (struct fsf_link_down_info *) &sr_buf->payload;
  267. switch (sr_buf->status_subtype) {
  268. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  269. dev_warn(&adapter->ccw_device->dev,
  270. "Physical link is down.\n");
  271. zfcp_fsf_link_down_info_eval(req, 38, ldi);
  272. break;
  273. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  274. dev_warn(&adapter->ccw_device->dev,
  275. "Local link is down "
  276. "due to failed FDISC login.\n");
  277. zfcp_fsf_link_down_info_eval(req, 39, ldi);
  278. break;
  279. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  280. dev_warn(&adapter->ccw_device->dev,
  281. "Local link is down "
  282. "due to firmware update on adapter.\n");
  283. zfcp_fsf_link_down_info_eval(req, 40, NULL);
  284. };
  285. }
  286. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  287. {
  288. struct zfcp_adapter *adapter = req->adapter;
  289. struct fsf_status_read_buffer *sr_buf = req->data;
  290. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  291. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
  292. mempool_free(sr_buf, adapter->pool.data_status_read);
  293. zfcp_fsf_req_free(req);
  294. return;
  295. }
  296. zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
  297. switch (sr_buf->status_type) {
  298. case FSF_STATUS_READ_PORT_CLOSED:
  299. zfcp_fsf_status_read_port_closed(req);
  300. break;
  301. case FSF_STATUS_READ_INCOMING_ELS:
  302. zfcp_fc_incoming_els(req);
  303. break;
  304. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  305. break;
  306. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  307. zfcp_fsf_bit_error_threshold(req);
  308. break;
  309. case FSF_STATUS_READ_LINK_DOWN:
  310. zfcp_fsf_status_read_link_down(req);
  311. break;
  312. case FSF_STATUS_READ_LINK_UP:
  313. dev_info(&adapter->ccw_device->dev,
  314. "Local link was replugged.\n");
  315. /* All ports should be marked as ready to run again */
  316. zfcp_erp_modify_adapter_status(adapter, 30, NULL,
  317. ZFCP_STATUS_COMMON_RUNNING,
  318. ZFCP_SET);
  319. zfcp_erp_adapter_reopen(adapter,
  320. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  321. ZFCP_STATUS_COMMON_ERP_FAILED,
  322. 102, req);
  323. break;
  324. case FSF_STATUS_READ_NOTIFICATION_LOST:
  325. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  326. zfcp_erp_adapter_access_changed(adapter, 135, req);
  327. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  328. schedule_work(&adapter->scan_work);
  329. break;
  330. case FSF_STATUS_READ_CFDC_UPDATED:
  331. zfcp_erp_adapter_access_changed(adapter, 136, req);
  332. break;
  333. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  334. adapter->adapter_features = sr_buf->payload.word[0];
  335. break;
  336. }
  337. mempool_free(sr_buf, adapter->pool.data_status_read);
  338. zfcp_fsf_req_free(req);
  339. atomic_inc(&adapter->stat_miss);
  340. schedule_work(&adapter->stat_work);
  341. }
  342. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  343. {
  344. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  345. case FSF_SQ_FCP_RSP_AVAILABLE:
  346. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  347. case FSF_SQ_NO_RETRY_POSSIBLE:
  348. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  349. return;
  350. case FSF_SQ_COMMAND_ABORTED:
  351. req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  352. break;
  353. case FSF_SQ_NO_RECOM:
  354. dev_err(&req->adapter->ccw_device->dev,
  355. "No recommendation could be given for a "
  356. "problem on the adapter.\n");
  357. zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
  358. break;
  359. }
  360. /* all non-return stats set FSFREQ_ERROR*/
  361. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  362. }
  363. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  364. {
  365. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  366. return;
  367. switch (req->qtcb->header.fsf_status) {
  368. case FSF_UNKNOWN_COMMAND:
  369. dev_err(&req->adapter->ccw_device->dev,
  370. "Command issued by the device driver (0x%x) is "
  371. "not known by the adapter.\n",
  372. req->qtcb->header.fsf_command);
  373. zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
  374. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  375. break;
  376. case FSF_ADAPTER_STATUS_AVAILABLE:
  377. zfcp_fsf_fsfstatus_qual_eval(req);
  378. break;
  379. }
  380. }
  381. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  382. {
  383. struct zfcp_adapter *adapter = req->adapter;
  384. struct fsf_qtcb *qtcb = req->qtcb;
  385. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  386. zfcp_hba_dbf_event_fsf_response(req);
  387. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  388. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  389. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  390. return;
  391. }
  392. switch (qtcb->prefix.prot_status) {
  393. case FSF_PROT_GOOD:
  394. case FSF_PROT_FSF_STATUS_PRESENTED:
  395. return;
  396. case FSF_PROT_QTCB_VERSION_ERROR:
  397. dev_err(&adapter->ccw_device->dev,
  398. "The QTCB version requested by zfcp (0x%x) is not "
  399. "supported by the FCP adapter (lowest supported "
  400. "0x%x, highest supported 0x%x).\n",
  401. FSF_QTCB_CURRENT_VERSION, psq->word[0],
  402. psq->word[1]);
  403. zfcp_erp_adapter_shutdown(adapter, 0, 117, req);
  404. break;
  405. case FSF_PROT_ERROR_STATE:
  406. case FSF_PROT_SEQ_NUMB_ERROR:
  407. zfcp_erp_adapter_reopen(adapter, 0, 98, req);
  408. req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  409. break;
  410. case FSF_PROT_UNSUPP_QTCB_TYPE:
  411. dev_err(&adapter->ccw_device->dev,
  412. "Packet header type used by the device driver is "
  413. "incompatible with that used on the adapter.\n");
  414. zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
  415. break;
  416. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  417. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  418. &adapter->status);
  419. break;
  420. case FSF_PROT_DUPLICATE_REQUEST_ID:
  421. dev_err(&adapter->ccw_device->dev,
  422. "The request identifier 0x%Lx is ambiguous.\n",
  423. (unsigned long long)qtcb->bottom.support.req_handle);
  424. zfcp_erp_adapter_shutdown(adapter, 0, 78, req);
  425. break;
  426. case FSF_PROT_LINK_DOWN:
  427. zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
  428. /* FIXME: reopening adapter now? better wait for link up */
  429. zfcp_erp_adapter_reopen(adapter, 0, 79, req);
  430. break;
  431. case FSF_PROT_REEST_QUEUE:
  432. /* All ports should be marked as ready to run again */
  433. zfcp_erp_modify_adapter_status(adapter, 28, NULL,
  434. ZFCP_STATUS_COMMON_RUNNING,
  435. ZFCP_SET);
  436. zfcp_erp_adapter_reopen(adapter,
  437. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  438. ZFCP_STATUS_COMMON_ERP_FAILED, 99, req);
  439. break;
  440. default:
  441. dev_err(&adapter->ccw_device->dev,
  442. "Transfer protocol status information"
  443. "provided by the adapter (0x%x) "
  444. "is not compatible with the device driver.\n",
  445. qtcb->prefix.prot_status);
  446. zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
  447. }
  448. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  449. }
  450. /**
  451. * zfcp_fsf_req_complete - process completion of a FSF request
  452. * @fsf_req: The FSF request that has been completed.
  453. *
  454. * When a request has been completed either from the FCP adapter,
  455. * or it has been dismissed due to a queue shutdown, this function
  456. * is called to process the completion status and trigger further
  457. * events related to the FSF request.
  458. */
  459. void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  460. {
  461. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  462. zfcp_fsf_status_read_handler(req);
  463. return;
  464. }
  465. del_timer(&req->timer);
  466. zfcp_fsf_protstatus_eval(req);
  467. zfcp_fsf_fsfstatus_eval(req);
  468. req->handler(req);
  469. if (req->erp_action)
  470. zfcp_erp_notify(req->erp_action, 0);
  471. req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  472. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  473. zfcp_fsf_req_free(req);
  474. else
  475. /* notify initiator waiting for the requests completion */
  476. /*
  477. * FIXME: Race! We must not access fsf_req here as it might have been
  478. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  479. * flag. It's an improbable case. But, we have the same paranoia for
  480. * the cleanup flag already.
  481. * Might better be handled using complete()?
  482. * (setting the flag and doing wakeup ought to be atomic
  483. * with regard to checking the flag as long as waitqueue is
  484. * part of the to be released structure)
  485. */
  486. wake_up(&req->completion_wq);
  487. }
  488. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  489. {
  490. struct fsf_qtcb_bottom_config *bottom;
  491. struct zfcp_adapter *adapter = req->adapter;
  492. struct Scsi_Host *shost = adapter->scsi_host;
  493. bottom = &req->qtcb->bottom.config;
  494. if (req->data)
  495. memcpy(req->data, bottom, sizeof(*bottom));
  496. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  497. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  498. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  499. fc_host_speed(shost) = bottom->fc_link_speed;
  500. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  501. adapter->hydra_version = bottom->adapter_type;
  502. adapter->timer_ticks = bottom->timer_interval;
  503. if (fc_host_permanent_port_name(shost) == -1)
  504. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  505. switch (bottom->fc_topology) {
  506. case FSF_TOPO_P2P:
  507. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  508. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  509. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  510. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  511. if (req->erp_action)
  512. dev_info(&adapter->ccw_device->dev,
  513. "Point-to-Point fibrechannel "
  514. "configuration detected.\n");
  515. break;
  516. case FSF_TOPO_FABRIC:
  517. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  518. if (req->erp_action)
  519. dev_info(&adapter->ccw_device->dev,
  520. "Switched fabric fibrechannel "
  521. "network detected.\n");
  522. break;
  523. case FSF_TOPO_AL:
  524. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  525. dev_err(&adapter->ccw_device->dev,
  526. "Unsupported arbitrated loop fibrechannel "
  527. "topology detected, shutting down "
  528. "adapter.\n");
  529. zfcp_erp_adapter_shutdown(adapter, 0, 127, req);
  530. return -EIO;
  531. default:
  532. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  533. dev_err(&adapter->ccw_device->dev,
  534. "The fibrechannel topology reported by the"
  535. " adapter is not known by the zfcp driver,"
  536. " shutting down adapter.\n");
  537. zfcp_erp_adapter_shutdown(adapter, 0, 128, req);
  538. return -EIO;
  539. }
  540. return 0;
  541. }
  542. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  543. {
  544. struct zfcp_adapter *adapter = req->adapter;
  545. struct fsf_qtcb *qtcb = req->qtcb;
  546. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  547. struct Scsi_Host *shost = adapter->scsi_host;
  548. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  549. return;
  550. adapter->fsf_lic_version = bottom->lic_version;
  551. adapter->adapter_features = bottom->adapter_features;
  552. adapter->connection_features = bottom->connection_features;
  553. adapter->peer_wwpn = 0;
  554. adapter->peer_wwnn = 0;
  555. adapter->peer_d_id = 0;
  556. switch (qtcb->header.fsf_status) {
  557. case FSF_GOOD:
  558. if (zfcp_fsf_exchange_config_evaluate(req))
  559. return;
  560. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  561. dev_err(&adapter->ccw_device->dev,
  562. "Maximum QTCB size (%d bytes) allowed by "
  563. "the adapter is lower than the minimum "
  564. "required by the driver (%ld bytes).\n",
  565. bottom->max_qtcb_size,
  566. sizeof(struct fsf_qtcb));
  567. zfcp_erp_adapter_shutdown(adapter, 0, 129, req);
  568. return;
  569. }
  570. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  571. &adapter->status);
  572. break;
  573. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  574. fc_host_node_name(shost) = 0;
  575. fc_host_port_name(shost) = 0;
  576. fc_host_port_id(shost) = 0;
  577. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  578. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  579. adapter->hydra_version = 0;
  580. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  581. &adapter->status);
  582. zfcp_fsf_link_down_info_eval(req, 42,
  583. &qtcb->header.fsf_status_qual.link_down_info);
  584. break;
  585. default:
  586. zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
  587. return;
  588. }
  589. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  590. adapter->hardware_version = bottom->hardware_version;
  591. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  592. min(FC_SERIAL_NUMBER_SIZE, 17));
  593. EBCASC(fc_host_serial_number(shost),
  594. min(FC_SERIAL_NUMBER_SIZE, 17));
  595. }
  596. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  597. dev_err(&adapter->ccw_device->dev,
  598. "The adapter only supports newer control block "
  599. "versions, try updated device driver.\n");
  600. zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
  601. return;
  602. }
  603. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  604. dev_err(&adapter->ccw_device->dev,
  605. "The adapter only supports older control block "
  606. "versions, consider a microcode upgrade.\n");
  607. zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
  608. }
  609. }
  610. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  611. {
  612. struct zfcp_adapter *adapter = req->adapter;
  613. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  614. struct Scsi_Host *shost = adapter->scsi_host;
  615. if (req->data)
  616. memcpy(req->data, bottom, sizeof(*bottom));
  617. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  618. fc_host_permanent_port_name(shost) = bottom->wwpn;
  619. else
  620. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  621. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  622. fc_host_supported_speeds(shost) = bottom->supported_speed;
  623. }
  624. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  625. {
  626. struct zfcp_adapter *adapter = req->adapter;
  627. struct fsf_qtcb *qtcb = req->qtcb;
  628. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  629. return;
  630. switch (qtcb->header.fsf_status) {
  631. case FSF_GOOD:
  632. zfcp_fsf_exchange_port_evaluate(req);
  633. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  634. break;
  635. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  636. zfcp_fsf_exchange_port_evaluate(req);
  637. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  638. zfcp_fsf_link_down_info_eval(req, 43,
  639. &qtcb->header.fsf_status_qual.link_down_info);
  640. break;
  641. }
  642. }
  643. static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue)
  644. {
  645. spin_lock(&queue->lock);
  646. if (atomic_read(&queue->count))
  647. return 1;
  648. spin_unlock(&queue->lock);
  649. return 0;
  650. }
  651. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  652. {
  653. long ret;
  654. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  655. spin_unlock(&req_q->lock);
  656. ret = wait_event_interruptible_timeout(adapter->request_wq,
  657. zfcp_fsf_sbal_check(req_q), 5 * HZ);
  658. if (ret > 0)
  659. return 0;
  660. spin_lock(&req_q->lock);
  661. return -EIO;
  662. }
  663. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  664. {
  665. struct zfcp_fsf_req *req;
  666. req = mempool_alloc(pool, GFP_ATOMIC);
  667. if (!req)
  668. return NULL;
  669. memset(req, 0, sizeof(*req));
  670. return req;
  671. }
  672. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  673. {
  674. struct zfcp_fsf_req_qtcb *qtcb;
  675. if (likely(pool))
  676. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  677. else
  678. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  679. GFP_ATOMIC);
  680. if (unlikely(!qtcb))
  681. return NULL;
  682. memset(qtcb, 0, sizeof(*qtcb));
  683. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  684. qtcb->fsf_req.pool = pool;
  685. return &qtcb->fsf_req;
  686. }
  687. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  688. u32 fsf_cmd, int req_flags,
  689. mempool_t *pool)
  690. {
  691. volatile struct qdio_buffer_element *sbale;
  692. struct zfcp_fsf_req *req;
  693. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  694. if (req_flags & ZFCP_REQ_NO_QTCB)
  695. req = zfcp_fsf_alloc_noqtcb(pool);
  696. else
  697. req = zfcp_fsf_alloc_qtcb(pool);
  698. if (unlikely(!req))
  699. return ERR_PTR(-EIO);
  700. if (adapter->req_no == 0)
  701. adapter->req_no++;
  702. INIT_LIST_HEAD(&req->list);
  703. init_timer(&req->timer);
  704. init_waitqueue_head(&req->completion_wq);
  705. req->adapter = adapter;
  706. req->fsf_command = fsf_cmd;
  707. req->req_id = adapter->req_no++;
  708. req->sbal_number = 1;
  709. req->sbal_first = req_q->first;
  710. req->sbal_last = req_q->first;
  711. req->sbale_curr = 1;
  712. sbale = zfcp_qdio_sbale_req(req);
  713. sbale[0].addr = (void *) req->req_id;
  714. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  715. if (likely(req->qtcb)) {
  716. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  717. req->qtcb->prefix.req_id = req->req_id;
  718. req->qtcb->prefix.ulp_info = 26;
  719. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  720. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  721. req->qtcb->header.req_handle = req->req_id;
  722. req->qtcb->header.fsf_command = req->fsf_command;
  723. req->seq_no = adapter->fsf_req_seq_no;
  724. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  725. sbale[1].addr = (void *) req->qtcb;
  726. sbale[1].length = sizeof(struct fsf_qtcb);
  727. }
  728. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  729. zfcp_fsf_req_free(req);
  730. return ERR_PTR(-EIO);
  731. }
  732. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  733. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  734. return req;
  735. }
  736. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  737. {
  738. struct zfcp_adapter *adapter = req->adapter;
  739. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  740. int idx;
  741. /* put allocated FSF request into hash table */
  742. spin_lock(&adapter->req_list_lock);
  743. idx = zfcp_reqlist_hash(req->req_id);
  744. list_add_tail(&req->list, &adapter->req_list[idx]);
  745. spin_unlock(&adapter->req_list_lock);
  746. req->issued = get_clock();
  747. if (zfcp_qdio_send(req)) {
  748. /* Queues are down..... */
  749. del_timer(&req->timer);
  750. spin_lock(&adapter->req_list_lock);
  751. zfcp_reqlist_remove(adapter, req);
  752. spin_unlock(&adapter->req_list_lock);
  753. /* undo changes in request queue made for this request */
  754. atomic_add(req->sbal_number, &req_q->count);
  755. req_q->first -= req->sbal_number;
  756. req_q->first += QDIO_MAX_BUFFERS_PER_Q;
  757. req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
  758. zfcp_erp_adapter_reopen(adapter, 0, 116, req);
  759. return -EIO;
  760. }
  761. /* Don't increase for unsolicited status */
  762. if (req->qtcb)
  763. adapter->fsf_req_seq_no++;
  764. return 0;
  765. }
  766. /**
  767. * zfcp_fsf_status_read - send status read request
  768. * @adapter: pointer to struct zfcp_adapter
  769. * @req_flags: request flags
  770. * Returns: 0 on success, ERROR otherwise
  771. */
  772. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  773. {
  774. struct zfcp_fsf_req *req;
  775. struct fsf_status_read_buffer *sr_buf;
  776. volatile struct qdio_buffer_element *sbale;
  777. int retval = -EIO;
  778. spin_lock(&adapter->req_q.lock);
  779. if (zfcp_fsf_req_sbal_get(adapter))
  780. goto out;
  781. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  782. ZFCP_REQ_NO_QTCB,
  783. adapter->pool.fsf_req_status_read);
  784. if (unlikely(IS_ERR(req))) {
  785. retval = PTR_ERR(req);
  786. goto out;
  787. }
  788. sbale = zfcp_qdio_sbale_req(req);
  789. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  790. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  791. req->sbale_curr = 2;
  792. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  793. if (!sr_buf) {
  794. retval = -ENOMEM;
  795. goto failed_buf;
  796. }
  797. memset(sr_buf, 0, sizeof(*sr_buf));
  798. req->data = sr_buf;
  799. sbale = zfcp_qdio_sbale_curr(req);
  800. sbale->addr = (void *) sr_buf;
  801. sbale->length = sizeof(*sr_buf);
  802. retval = zfcp_fsf_req_send(req);
  803. if (retval)
  804. goto failed_req_send;
  805. goto out;
  806. failed_req_send:
  807. mempool_free(sr_buf, adapter->pool.data_status_read);
  808. failed_buf:
  809. zfcp_fsf_req_free(req);
  810. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  811. out:
  812. spin_unlock(&adapter->req_q.lock);
  813. return retval;
  814. }
  815. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  816. {
  817. struct zfcp_unit *unit = req->data;
  818. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  819. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  820. return;
  821. switch (req->qtcb->header.fsf_status) {
  822. case FSF_PORT_HANDLE_NOT_VALID:
  823. if (fsq->word[0] == fsq->word[1]) {
  824. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
  825. req);
  826. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  827. }
  828. break;
  829. case FSF_LUN_HANDLE_NOT_VALID:
  830. if (fsq->word[0] == fsq->word[1]) {
  831. zfcp_erp_port_reopen(unit->port, 0, 105, req);
  832. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  833. }
  834. break;
  835. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  836. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  837. break;
  838. case FSF_PORT_BOXED:
  839. zfcp_erp_port_boxed(unit->port, 47, req);
  840. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  841. ZFCP_STATUS_FSFREQ_RETRY;
  842. break;
  843. case FSF_LUN_BOXED:
  844. zfcp_erp_unit_boxed(unit, 48, req);
  845. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  846. ZFCP_STATUS_FSFREQ_RETRY;
  847. break;
  848. case FSF_ADAPTER_STATUS_AVAILABLE:
  849. switch (fsq->word[0]) {
  850. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  851. zfcp_test_link(unit->port);
  852. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  853. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  854. break;
  855. }
  856. break;
  857. case FSF_GOOD:
  858. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  859. break;
  860. }
  861. }
  862. /**
  863. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  864. * @old_req_id: unsigned long
  865. * @adapter: pointer to struct zfcp_adapter
  866. * @unit: pointer to struct zfcp_unit
  867. * @req_flags: integer specifying the request flags
  868. * Returns: pointer to struct zfcp_fsf_req
  869. *
  870. * FIXME(design): should be watched by a timeout !!!
  871. */
  872. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  873. struct zfcp_adapter *adapter,
  874. struct zfcp_unit *unit,
  875. int req_flags)
  876. {
  877. volatile struct qdio_buffer_element *sbale;
  878. struct zfcp_fsf_req *req = NULL;
  879. spin_lock(&adapter->req_q.lock);
  880. if (!atomic_read(&adapter->req_q.count))
  881. goto out;
  882. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  883. req_flags, adapter->pool.fsf_req_abort);
  884. if (unlikely(IS_ERR(req)))
  885. goto out;
  886. if (unlikely(!(atomic_read(&unit->status) &
  887. ZFCP_STATUS_COMMON_UNBLOCKED)))
  888. goto out_error_free;
  889. sbale = zfcp_qdio_sbale_req(req);
  890. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  891. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  892. req->data = unit;
  893. req->handler = zfcp_fsf_abort_fcp_command_handler;
  894. req->qtcb->header.lun_handle = unit->handle;
  895. req->qtcb->header.port_handle = unit->port->handle;
  896. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  897. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  898. if (!zfcp_fsf_req_send(req))
  899. goto out;
  900. out_error_free:
  901. zfcp_fsf_req_free(req);
  902. req = NULL;
  903. out:
  904. spin_unlock(&adapter->req_q.lock);
  905. return req;
  906. }
  907. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  908. {
  909. struct zfcp_adapter *adapter = req->adapter;
  910. struct zfcp_send_ct *send_ct = req->data;
  911. struct zfcp_port *port = send_ct->port;
  912. struct fsf_qtcb_header *header = &req->qtcb->header;
  913. send_ct->status = -EINVAL;
  914. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  915. goto skip_fsfstatus;
  916. switch (header->fsf_status) {
  917. case FSF_GOOD:
  918. zfcp_san_dbf_event_ct_response(req);
  919. send_ct->status = 0;
  920. break;
  921. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  922. zfcp_fsf_class_not_supp(req);
  923. break;
  924. case FSF_ADAPTER_STATUS_AVAILABLE:
  925. switch (header->fsf_status_qual.word[0]){
  926. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  927. zfcp_test_link(port);
  928. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  929. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  930. break;
  931. }
  932. break;
  933. case FSF_ACCESS_DENIED:
  934. zfcp_fsf_access_denied_port(req, port);
  935. break;
  936. case FSF_PORT_BOXED:
  937. zfcp_erp_port_boxed(port, 49, req);
  938. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  939. ZFCP_STATUS_FSFREQ_RETRY;
  940. break;
  941. case FSF_PORT_HANDLE_NOT_VALID:
  942. zfcp_erp_adapter_reopen(adapter, 0, 106, req);
  943. case FSF_GENERIC_COMMAND_REJECTED:
  944. case FSF_PAYLOAD_SIZE_MISMATCH:
  945. case FSF_REQUEST_SIZE_TOO_LARGE:
  946. case FSF_RESPONSE_SIZE_TOO_LARGE:
  947. case FSF_SBAL_MISMATCH:
  948. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  949. break;
  950. }
  951. skip_fsfstatus:
  952. if (send_ct->handler)
  953. send_ct->handler(send_ct->handler_data);
  954. }
  955. static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
  956. struct scatterlist *sg_req,
  957. struct scatterlist *sg_resp, int max_sbals)
  958. {
  959. int bytes;
  960. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  961. sg_req, max_sbals);
  962. if (bytes <= 0)
  963. return -ENOMEM;
  964. req->qtcb->bottom.support.req_buf_length = bytes;
  965. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  966. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  967. sg_resp, max_sbals);
  968. if (bytes <= 0)
  969. return -ENOMEM;
  970. req->qtcb->bottom.support.resp_buf_length = bytes;
  971. return 0;
  972. }
  973. /**
  974. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  975. * @ct: pointer to struct zfcp_send_ct with data for request
  976. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  977. * @erp_action: if non-null the Generic Service request sent within ERP
  978. */
  979. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  980. struct zfcp_erp_action *erp_action)
  981. {
  982. struct zfcp_port *port = ct->port;
  983. struct zfcp_adapter *adapter = port->adapter;
  984. struct zfcp_fsf_req *req;
  985. int ret = -EIO;
  986. spin_lock(&adapter->req_q.lock);
  987. if (zfcp_fsf_req_sbal_get(adapter))
  988. goto out;
  989. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  990. ZFCP_REQ_AUTO_CLEANUP, pool);
  991. if (unlikely(IS_ERR(req))) {
  992. ret = PTR_ERR(req);
  993. goto out;
  994. }
  995. ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
  996. FSF_MAX_SBALS_PER_REQ);
  997. if (ret)
  998. goto failed_send;
  999. req->handler = zfcp_fsf_send_ct_handler;
  1000. req->qtcb->header.port_handle = port->handle;
  1001. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  1002. req->qtcb->bottom.support.timeout = ct->timeout;
  1003. req->data = ct;
  1004. zfcp_san_dbf_event_ct_request(req);
  1005. if (erp_action) {
  1006. erp_action->fsf_req = req;
  1007. req->erp_action = erp_action;
  1008. zfcp_fsf_start_erp_timer(req);
  1009. } else
  1010. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1011. ret = zfcp_fsf_req_send(req);
  1012. if (ret)
  1013. goto failed_send;
  1014. goto out;
  1015. failed_send:
  1016. zfcp_fsf_req_free(req);
  1017. if (erp_action)
  1018. erp_action->fsf_req = NULL;
  1019. out:
  1020. spin_unlock(&adapter->req_q.lock);
  1021. return ret;
  1022. }
  1023. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  1024. {
  1025. struct zfcp_send_els *send_els = req->data;
  1026. struct zfcp_port *port = send_els->port;
  1027. struct fsf_qtcb_header *header = &req->qtcb->header;
  1028. send_els->status = -EINVAL;
  1029. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1030. goto skip_fsfstatus;
  1031. switch (header->fsf_status) {
  1032. case FSF_GOOD:
  1033. zfcp_san_dbf_event_els_response(req);
  1034. send_els->status = 0;
  1035. break;
  1036. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1037. zfcp_fsf_class_not_supp(req);
  1038. break;
  1039. case FSF_ADAPTER_STATUS_AVAILABLE:
  1040. switch (header->fsf_status_qual.word[0]){
  1041. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1042. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  1043. zfcp_test_link(port);
  1044. /*fall through */
  1045. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1046. case FSF_SQ_RETRY_IF_POSSIBLE:
  1047. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1048. break;
  1049. }
  1050. break;
  1051. case FSF_ELS_COMMAND_REJECTED:
  1052. case FSF_PAYLOAD_SIZE_MISMATCH:
  1053. case FSF_REQUEST_SIZE_TOO_LARGE:
  1054. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1055. break;
  1056. case FSF_ACCESS_DENIED:
  1057. zfcp_fsf_access_denied_port(req, port);
  1058. break;
  1059. case FSF_SBAL_MISMATCH:
  1060. /* should never occure, avoided in zfcp_fsf_send_els */
  1061. /* fall through */
  1062. default:
  1063. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1064. break;
  1065. }
  1066. skip_fsfstatus:
  1067. if (send_els->handler)
  1068. send_els->handler(send_els->handler_data);
  1069. }
  1070. /**
  1071. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1072. * @els: pointer to struct zfcp_send_els with data for the command
  1073. */
  1074. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1075. {
  1076. struct zfcp_fsf_req *req;
  1077. struct zfcp_adapter *adapter = els->adapter;
  1078. struct fsf_qtcb_bottom_support *bottom;
  1079. int ret = -EIO;
  1080. if (unlikely(!(atomic_read(&els->port->status) &
  1081. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1082. return -EBUSY;
  1083. spin_lock(&adapter->req_q.lock);
  1084. if (!atomic_read(&adapter->req_q.count))
  1085. goto out;
  1086. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1087. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1088. if (unlikely(IS_ERR(req))) {
  1089. ret = PTR_ERR(req);
  1090. goto out;
  1091. }
  1092. ret = zfcp_fsf_setup_sbals(req, els->req, els->resp,
  1093. FSF_MAX_SBALS_PER_ELS_REQ);
  1094. if (ret)
  1095. goto failed_send;
  1096. bottom = &req->qtcb->bottom.support;
  1097. req->handler = zfcp_fsf_send_els_handler;
  1098. bottom->d_id = els->d_id;
  1099. bottom->service_class = FSF_CLASS_3;
  1100. bottom->timeout = 2 * R_A_TOV;
  1101. req->data = els;
  1102. zfcp_san_dbf_event_els_request(req);
  1103. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1104. ret = zfcp_fsf_req_send(req);
  1105. if (ret)
  1106. goto failed_send;
  1107. goto out;
  1108. failed_send:
  1109. zfcp_fsf_req_free(req);
  1110. out:
  1111. spin_unlock(&adapter->req_q.lock);
  1112. return ret;
  1113. }
  1114. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1115. {
  1116. volatile struct qdio_buffer_element *sbale;
  1117. struct zfcp_fsf_req *req;
  1118. struct zfcp_adapter *adapter = erp_action->adapter;
  1119. int retval = -EIO;
  1120. spin_lock(&adapter->req_q.lock);
  1121. if (!atomic_read(&adapter->req_q.count))
  1122. goto out;
  1123. req = zfcp_fsf_req_create(adapter,
  1124. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1125. ZFCP_REQ_AUTO_CLEANUP,
  1126. adapter->pool.fsf_req_erp);
  1127. if (unlikely(IS_ERR(req))) {
  1128. retval = PTR_ERR(req);
  1129. goto out;
  1130. }
  1131. sbale = zfcp_qdio_sbale_req(req);
  1132. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1133. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1134. req->qtcb->bottom.config.feature_selection =
  1135. FSF_FEATURE_CFDC |
  1136. FSF_FEATURE_LUN_SHARING |
  1137. FSF_FEATURE_NOTIFICATION_LOST |
  1138. FSF_FEATURE_UPDATE_ALERT;
  1139. req->erp_action = erp_action;
  1140. req->handler = zfcp_fsf_exchange_config_data_handler;
  1141. erp_action->fsf_req = req;
  1142. zfcp_fsf_start_erp_timer(req);
  1143. retval = zfcp_fsf_req_send(req);
  1144. if (retval) {
  1145. zfcp_fsf_req_free(req);
  1146. erp_action->fsf_req = NULL;
  1147. }
  1148. out:
  1149. spin_unlock(&adapter->req_q.lock);
  1150. return retval;
  1151. }
  1152. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1153. struct fsf_qtcb_bottom_config *data)
  1154. {
  1155. volatile struct qdio_buffer_element *sbale;
  1156. struct zfcp_fsf_req *req = NULL;
  1157. int retval = -EIO;
  1158. spin_lock(&adapter->req_q.lock);
  1159. if (zfcp_fsf_req_sbal_get(adapter))
  1160. goto out;
  1161. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1162. 0, NULL);
  1163. if (unlikely(IS_ERR(req))) {
  1164. retval = PTR_ERR(req);
  1165. goto out;
  1166. }
  1167. sbale = zfcp_qdio_sbale_req(req);
  1168. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1169. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1170. req->handler = zfcp_fsf_exchange_config_data_handler;
  1171. req->qtcb->bottom.config.feature_selection =
  1172. FSF_FEATURE_CFDC |
  1173. FSF_FEATURE_LUN_SHARING |
  1174. FSF_FEATURE_NOTIFICATION_LOST |
  1175. FSF_FEATURE_UPDATE_ALERT;
  1176. if (data)
  1177. req->data = data;
  1178. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1179. retval = zfcp_fsf_req_send(req);
  1180. out:
  1181. spin_unlock(&adapter->req_q.lock);
  1182. if (!retval)
  1183. wait_event(req->completion_wq,
  1184. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1185. zfcp_fsf_req_free(req);
  1186. return retval;
  1187. }
  1188. /**
  1189. * zfcp_fsf_exchange_port_data - request information about local port
  1190. * @erp_action: ERP action for the adapter for which port data is requested
  1191. * Returns: 0 on success, error otherwise
  1192. */
  1193. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1194. {
  1195. volatile struct qdio_buffer_element *sbale;
  1196. struct zfcp_fsf_req *req;
  1197. struct zfcp_adapter *adapter = erp_action->adapter;
  1198. int retval = -EIO;
  1199. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1200. return -EOPNOTSUPP;
  1201. spin_lock(&adapter->req_q.lock);
  1202. if (!atomic_read(&adapter->req_q.count))
  1203. goto out;
  1204. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1205. ZFCP_REQ_AUTO_CLEANUP,
  1206. adapter->pool.fsf_req_erp);
  1207. if (unlikely(IS_ERR(req))) {
  1208. retval = PTR_ERR(req);
  1209. goto out;
  1210. }
  1211. sbale = zfcp_qdio_sbale_req(req);
  1212. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1213. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1214. req->handler = zfcp_fsf_exchange_port_data_handler;
  1215. req->erp_action = erp_action;
  1216. erp_action->fsf_req = req;
  1217. zfcp_fsf_start_erp_timer(req);
  1218. retval = zfcp_fsf_req_send(req);
  1219. if (retval) {
  1220. zfcp_fsf_req_free(req);
  1221. erp_action->fsf_req = NULL;
  1222. }
  1223. out:
  1224. spin_unlock(&adapter->req_q.lock);
  1225. return retval;
  1226. }
  1227. /**
  1228. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1229. * @adapter: pointer to struct zfcp_adapter
  1230. * @data: pointer to struct fsf_qtcb_bottom_port
  1231. * Returns: 0 on success, error otherwise
  1232. */
  1233. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1234. struct fsf_qtcb_bottom_port *data)
  1235. {
  1236. volatile struct qdio_buffer_element *sbale;
  1237. struct zfcp_fsf_req *req = NULL;
  1238. int retval = -EIO;
  1239. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1240. return -EOPNOTSUPP;
  1241. spin_lock(&adapter->req_q.lock);
  1242. if (!atomic_read(&adapter->req_q.count))
  1243. goto out;
  1244. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1245. NULL);
  1246. if (unlikely(IS_ERR(req))) {
  1247. retval = PTR_ERR(req);
  1248. goto out;
  1249. }
  1250. if (data)
  1251. req->data = data;
  1252. sbale = zfcp_qdio_sbale_req(req);
  1253. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1254. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1255. req->handler = zfcp_fsf_exchange_port_data_handler;
  1256. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1257. retval = zfcp_fsf_req_send(req);
  1258. out:
  1259. spin_unlock(&adapter->req_q.lock);
  1260. if (!retval)
  1261. wait_event(req->completion_wq,
  1262. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1263. zfcp_fsf_req_free(req);
  1264. return retval;
  1265. }
  1266. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1267. {
  1268. struct zfcp_port *port = req->data;
  1269. struct fsf_qtcb_header *header = &req->qtcb->header;
  1270. struct fsf_plogi *plogi;
  1271. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1272. goto skip_fsfstatus;
  1273. switch (header->fsf_status) {
  1274. case FSF_PORT_ALREADY_OPEN:
  1275. break;
  1276. case FSF_ACCESS_DENIED:
  1277. zfcp_fsf_access_denied_port(req, port);
  1278. break;
  1279. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1280. dev_warn(&req->adapter->ccw_device->dev,
  1281. "The adapter is out of resources. The remote port "
  1282. "0x%016Lx could not be opened, disabling it.\n",
  1283. port->wwpn);
  1284. zfcp_erp_port_failed(port, 31, req);
  1285. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1286. break;
  1287. case FSF_ADAPTER_STATUS_AVAILABLE:
  1288. switch (header->fsf_status_qual.word[0]) {
  1289. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1290. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1291. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1292. break;
  1293. case FSF_SQ_NO_RETRY_POSSIBLE:
  1294. dev_warn(&req->adapter->ccw_device->dev,
  1295. "The remote port 0x%016Lx could not be "
  1296. "opened. Disabling it.\n", port->wwpn);
  1297. zfcp_erp_port_failed(port, 32, req);
  1298. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1299. break;
  1300. }
  1301. break;
  1302. case FSF_GOOD:
  1303. port->handle = header->port_handle;
  1304. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1305. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1306. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1307. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1308. &port->status);
  1309. /* check whether D_ID has changed during open */
  1310. /*
  1311. * FIXME: This check is not airtight, as the FCP channel does
  1312. * not monitor closures of target port connections caused on
  1313. * the remote side. Thus, they might miss out on invalidating
  1314. * locally cached WWPNs (and other N_Port parameters) of gone
  1315. * target ports. So, our heroic attempt to make things safe
  1316. * could be undermined by 'open port' response data tagged with
  1317. * obsolete WWPNs. Another reason to monitor potential
  1318. * connection closures ourself at least (by interpreting
  1319. * incoming ELS' and unsolicited status). It just crosses my
  1320. * mind that one should be able to cross-check by means of
  1321. * another GID_PN straight after a port has been opened.
  1322. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1323. */
  1324. if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN)
  1325. break;
  1326. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1327. if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
  1328. if (plogi->serv_param.wwpn != port->wwpn)
  1329. atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
  1330. &port->status);
  1331. else {
  1332. port->wwnn = plogi->serv_param.wwnn;
  1333. zfcp_fc_plogi_evaluate(port, plogi);
  1334. }
  1335. }
  1336. break;
  1337. case FSF_UNKNOWN_OP_SUBTYPE:
  1338. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1339. break;
  1340. }
  1341. skip_fsfstatus:
  1342. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
  1343. }
  1344. /**
  1345. * zfcp_fsf_open_port - create and send open port request
  1346. * @erp_action: pointer to struct zfcp_erp_action
  1347. * Returns: 0 on success, error otherwise
  1348. */
  1349. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1350. {
  1351. volatile struct qdio_buffer_element *sbale;
  1352. struct zfcp_adapter *adapter = erp_action->adapter;
  1353. struct zfcp_fsf_req *req;
  1354. int retval = -EIO;
  1355. spin_lock(&adapter->req_q.lock);
  1356. if (zfcp_fsf_req_sbal_get(adapter))
  1357. goto out;
  1358. req = zfcp_fsf_req_create(adapter,
  1359. FSF_QTCB_OPEN_PORT_WITH_DID,
  1360. ZFCP_REQ_AUTO_CLEANUP,
  1361. adapter->pool.fsf_req_erp);
  1362. if (unlikely(IS_ERR(req))) {
  1363. retval = PTR_ERR(req);
  1364. goto out;
  1365. }
  1366. sbale = zfcp_qdio_sbale_req(req);
  1367. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1368. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1369. req->handler = zfcp_fsf_open_port_handler;
  1370. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1371. req->data = erp_action->port;
  1372. req->erp_action = erp_action;
  1373. erp_action->fsf_req = req;
  1374. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
  1375. zfcp_fsf_start_erp_timer(req);
  1376. retval = zfcp_fsf_req_send(req);
  1377. if (retval) {
  1378. zfcp_fsf_req_free(req);
  1379. erp_action->fsf_req = NULL;
  1380. }
  1381. out:
  1382. spin_unlock(&adapter->req_q.lock);
  1383. return retval;
  1384. }
  1385. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1386. {
  1387. struct zfcp_port *port = req->data;
  1388. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1389. goto skip_fsfstatus;
  1390. switch (req->qtcb->header.fsf_status) {
  1391. case FSF_PORT_HANDLE_NOT_VALID:
  1392. zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
  1393. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1394. break;
  1395. case FSF_ADAPTER_STATUS_AVAILABLE:
  1396. break;
  1397. case FSF_GOOD:
  1398. zfcp_erp_modify_port_status(port, 33, req,
  1399. ZFCP_STATUS_COMMON_OPEN,
  1400. ZFCP_CLEAR);
  1401. break;
  1402. }
  1403. skip_fsfstatus:
  1404. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
  1405. }
  1406. /**
  1407. * zfcp_fsf_close_port - create and send close port request
  1408. * @erp_action: pointer to struct zfcp_erp_action
  1409. * Returns: 0 on success, error otherwise
  1410. */
  1411. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1412. {
  1413. volatile struct qdio_buffer_element *sbale;
  1414. struct zfcp_adapter *adapter = erp_action->adapter;
  1415. struct zfcp_fsf_req *req;
  1416. int retval = -EIO;
  1417. spin_lock(&adapter->req_q.lock);
  1418. if (zfcp_fsf_req_sbal_get(adapter))
  1419. goto out;
  1420. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1421. ZFCP_REQ_AUTO_CLEANUP,
  1422. adapter->pool.fsf_req_erp);
  1423. if (unlikely(IS_ERR(req))) {
  1424. retval = PTR_ERR(req);
  1425. goto out;
  1426. }
  1427. sbale = zfcp_qdio_sbale_req(req);
  1428. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1429. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1430. req->handler = zfcp_fsf_close_port_handler;
  1431. req->data = erp_action->port;
  1432. req->erp_action = erp_action;
  1433. req->qtcb->header.port_handle = erp_action->port->handle;
  1434. erp_action->fsf_req = req;
  1435. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
  1436. zfcp_fsf_start_erp_timer(req);
  1437. retval = zfcp_fsf_req_send(req);
  1438. if (retval) {
  1439. zfcp_fsf_req_free(req);
  1440. erp_action->fsf_req = NULL;
  1441. }
  1442. out:
  1443. spin_unlock(&adapter->req_q.lock);
  1444. return retval;
  1445. }
  1446. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1447. {
  1448. struct zfcp_port *port = req->data;
  1449. struct fsf_qtcb_header *header = &req->qtcb->header;
  1450. struct zfcp_unit *unit;
  1451. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1452. goto skip_fsfstatus;
  1453. switch (header->fsf_status) {
  1454. case FSF_PORT_HANDLE_NOT_VALID:
  1455. zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
  1456. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1457. break;
  1458. case FSF_ACCESS_DENIED:
  1459. zfcp_fsf_access_denied_port(req, port);
  1460. break;
  1461. case FSF_PORT_BOXED:
  1462. zfcp_erp_port_boxed(port, 50, req);
  1463. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1464. ZFCP_STATUS_FSFREQ_RETRY;
  1465. /* can't use generic zfcp_erp_modify_port_status because
  1466. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1467. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1468. list_for_each_entry(unit, &port->unit_list_head, list)
  1469. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1470. &unit->status);
  1471. break;
  1472. case FSF_ADAPTER_STATUS_AVAILABLE:
  1473. switch (header->fsf_status_qual.word[0]) {
  1474. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1475. /* fall through */
  1476. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1477. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1478. break;
  1479. }
  1480. break;
  1481. case FSF_GOOD:
  1482. /* can't use generic zfcp_erp_modify_port_status because
  1483. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1484. */
  1485. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1486. list_for_each_entry(unit, &port->unit_list_head, list)
  1487. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1488. &unit->status);
  1489. break;
  1490. }
  1491. skip_fsfstatus:
  1492. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  1493. }
  1494. /**
  1495. * zfcp_fsf_close_physical_port - close physical port
  1496. * @erp_action: pointer to struct zfcp_erp_action
  1497. * Returns: 0 on success
  1498. */
  1499. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1500. {
  1501. volatile struct qdio_buffer_element *sbale;
  1502. struct zfcp_adapter *adapter = erp_action->adapter;
  1503. struct zfcp_fsf_req *req;
  1504. int retval = -EIO;
  1505. spin_lock(&adapter->req_q.lock);
  1506. if (zfcp_fsf_req_sbal_get(adapter))
  1507. goto out;
  1508. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1509. ZFCP_REQ_AUTO_CLEANUP,
  1510. adapter->pool.fsf_req_erp);
  1511. if (unlikely(IS_ERR(req))) {
  1512. retval = PTR_ERR(req);
  1513. goto out;
  1514. }
  1515. sbale = zfcp_qdio_sbale_req(req);
  1516. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1517. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1518. req->data = erp_action->port;
  1519. req->qtcb->header.port_handle = erp_action->port->handle;
  1520. req->erp_action = erp_action;
  1521. req->handler = zfcp_fsf_close_physical_port_handler;
  1522. erp_action->fsf_req = req;
  1523. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  1524. &erp_action->port->status);
  1525. zfcp_fsf_start_erp_timer(req);
  1526. retval = zfcp_fsf_req_send(req);
  1527. if (retval) {
  1528. zfcp_fsf_req_free(req);
  1529. erp_action->fsf_req = NULL;
  1530. }
  1531. out:
  1532. spin_unlock(&adapter->req_q.lock);
  1533. return retval;
  1534. }
  1535. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1536. {
  1537. struct zfcp_adapter *adapter = req->adapter;
  1538. struct zfcp_unit *unit = req->data;
  1539. struct fsf_qtcb_header *header = &req->qtcb->header;
  1540. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1541. struct fsf_queue_designator *queue_designator =
  1542. &header->fsf_status_qual.fsf_queue_designator;
  1543. int exclusive, readwrite;
  1544. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1545. goto skip_fsfstatus;
  1546. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1547. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1548. ZFCP_STATUS_UNIT_SHARED |
  1549. ZFCP_STATUS_UNIT_READONLY,
  1550. &unit->status);
  1551. switch (header->fsf_status) {
  1552. case FSF_PORT_HANDLE_NOT_VALID:
  1553. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
  1554. /* fall through */
  1555. case FSF_LUN_ALREADY_OPEN:
  1556. break;
  1557. case FSF_ACCESS_DENIED:
  1558. zfcp_fsf_access_denied_unit(req, unit);
  1559. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1560. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1561. break;
  1562. case FSF_PORT_BOXED:
  1563. zfcp_erp_port_boxed(unit->port, 51, req);
  1564. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1565. ZFCP_STATUS_FSFREQ_RETRY;
  1566. break;
  1567. case FSF_LUN_SHARING_VIOLATION:
  1568. if (header->fsf_status_qual.word[0])
  1569. dev_warn(&adapter->ccw_device->dev,
  1570. "FCP-LUN 0x%Lx at the remote port "
  1571. "with WWPN 0x%Lx "
  1572. "connected to the adapter "
  1573. "is already in use in LPAR%d, CSS%d.\n",
  1574. unit->fcp_lun,
  1575. unit->port->wwpn,
  1576. queue_designator->hla,
  1577. queue_designator->cssid);
  1578. else
  1579. zfcp_act_eval_err(adapter,
  1580. header->fsf_status_qual.word[2]);
  1581. zfcp_erp_unit_access_denied(unit, 60, req);
  1582. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1583. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1584. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1585. break;
  1586. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1587. dev_warn(&adapter->ccw_device->dev,
  1588. "The adapter ran out of resources. There is no "
  1589. "handle available for unit 0x%016Lx on port 0x%016Lx.",
  1590. unit->fcp_lun, unit->port->wwpn);
  1591. zfcp_erp_unit_failed(unit, 34, req);
  1592. /* fall through */
  1593. case FSF_INVALID_COMMAND_OPTION:
  1594. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1595. break;
  1596. case FSF_ADAPTER_STATUS_AVAILABLE:
  1597. switch (header->fsf_status_qual.word[0]) {
  1598. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1599. zfcp_test_link(unit->port);
  1600. /* fall through */
  1601. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1602. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1603. break;
  1604. }
  1605. break;
  1606. case FSF_GOOD:
  1607. unit->handle = header->lun_handle;
  1608. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1609. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1610. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1611. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1612. exclusive = (bottom->lun_access_info &
  1613. FSF_UNIT_ACCESS_EXCLUSIVE);
  1614. readwrite = (bottom->lun_access_info &
  1615. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1616. if (!exclusive)
  1617. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1618. &unit->status);
  1619. if (!readwrite) {
  1620. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1621. &unit->status);
  1622. dev_info(&adapter->ccw_device->dev,
  1623. "Read-only access for unit 0x%016Lx "
  1624. "on port 0x%016Lx.\n",
  1625. unit->fcp_lun, unit->port->wwpn);
  1626. }
  1627. if (exclusive && !readwrite) {
  1628. dev_err(&adapter->ccw_device->dev,
  1629. "Exclusive access of read-only unit "
  1630. "0x%016Lx on port 0x%016Lx not "
  1631. "supported, disabling unit.\n",
  1632. unit->fcp_lun, unit->port->wwpn);
  1633. zfcp_erp_unit_failed(unit, 35, req);
  1634. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1635. zfcp_erp_unit_shutdown(unit, 0, 80, req);
  1636. } else if (!exclusive && readwrite) {
  1637. dev_err(&adapter->ccw_device->dev,
  1638. "Shared access of read-write unit "
  1639. "0x%016Lx on port 0x%016Lx not "
  1640. "supported, disabling unit.\n",
  1641. unit->fcp_lun, unit->port->wwpn);
  1642. zfcp_erp_unit_failed(unit, 36, req);
  1643. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1644. zfcp_erp_unit_shutdown(unit, 0, 81, req);
  1645. }
  1646. }
  1647. break;
  1648. }
  1649. skip_fsfstatus:
  1650. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
  1651. }
  1652. /**
  1653. * zfcp_fsf_open_unit - open unit
  1654. * @erp_action: pointer to struct zfcp_erp_action
  1655. * Returns: 0 on success, error otherwise
  1656. */
  1657. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1658. {
  1659. volatile struct qdio_buffer_element *sbale;
  1660. struct zfcp_adapter *adapter = erp_action->adapter;
  1661. struct zfcp_fsf_req *req;
  1662. int retval = -EIO;
  1663. spin_lock(&adapter->req_q.lock);
  1664. if (zfcp_fsf_req_sbal_get(adapter))
  1665. goto out;
  1666. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1667. ZFCP_REQ_AUTO_CLEANUP,
  1668. adapter->pool.fsf_req_erp);
  1669. if (unlikely(IS_ERR(req))) {
  1670. retval = PTR_ERR(req);
  1671. goto out;
  1672. }
  1673. sbale = zfcp_qdio_sbale_req(req);
  1674. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1675. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1676. req->qtcb->header.port_handle = erp_action->port->handle;
  1677. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1678. req->handler = zfcp_fsf_open_unit_handler;
  1679. req->data = erp_action->unit;
  1680. req->erp_action = erp_action;
  1681. erp_action->fsf_req = req;
  1682. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1683. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1684. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
  1685. zfcp_fsf_start_erp_timer(req);
  1686. retval = zfcp_fsf_req_send(req);
  1687. if (retval) {
  1688. zfcp_fsf_req_free(req);
  1689. erp_action->fsf_req = NULL;
  1690. }
  1691. out:
  1692. spin_unlock(&adapter->req_q.lock);
  1693. return retval;
  1694. }
  1695. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1696. {
  1697. struct zfcp_unit *unit = req->data;
  1698. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1699. goto skip_fsfstatus;
  1700. switch (req->qtcb->header.fsf_status) {
  1701. case FSF_PORT_HANDLE_NOT_VALID:
  1702. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
  1703. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1704. break;
  1705. case FSF_LUN_HANDLE_NOT_VALID:
  1706. zfcp_erp_port_reopen(unit->port, 0, 111, req);
  1707. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1708. break;
  1709. case FSF_PORT_BOXED:
  1710. zfcp_erp_port_boxed(unit->port, 52, req);
  1711. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1712. ZFCP_STATUS_FSFREQ_RETRY;
  1713. break;
  1714. case FSF_ADAPTER_STATUS_AVAILABLE:
  1715. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1716. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1717. zfcp_test_link(unit->port);
  1718. /* fall through */
  1719. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1720. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1721. break;
  1722. }
  1723. break;
  1724. case FSF_GOOD:
  1725. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1726. break;
  1727. }
  1728. skip_fsfstatus:
  1729. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
  1730. }
  1731. /**
  1732. * zfcp_fsf_close_unit - close zfcp unit
  1733. * @erp_action: pointer to struct zfcp_unit
  1734. * Returns: 0 on success, error otherwise
  1735. */
  1736. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1737. {
  1738. volatile struct qdio_buffer_element *sbale;
  1739. struct zfcp_adapter *adapter = erp_action->adapter;
  1740. struct zfcp_fsf_req *req;
  1741. int retval = -EIO;
  1742. spin_lock(&adapter->req_q.lock);
  1743. if (zfcp_fsf_req_sbal_get(adapter))
  1744. goto out;
  1745. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1746. ZFCP_REQ_AUTO_CLEANUP,
  1747. adapter->pool.fsf_req_erp);
  1748. if (unlikely(IS_ERR(req))) {
  1749. retval = PTR_ERR(req);
  1750. goto out;
  1751. }
  1752. sbale = zfcp_qdio_sbale_req(req);
  1753. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1754. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1755. req->qtcb->header.port_handle = erp_action->port->handle;
  1756. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1757. req->handler = zfcp_fsf_close_unit_handler;
  1758. req->data = erp_action->unit;
  1759. req->erp_action = erp_action;
  1760. erp_action->fsf_req = req;
  1761. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
  1762. zfcp_fsf_start_erp_timer(req);
  1763. retval = zfcp_fsf_req_send(req);
  1764. if (retval) {
  1765. zfcp_fsf_req_free(req);
  1766. erp_action->fsf_req = NULL;
  1767. }
  1768. out:
  1769. spin_unlock(&adapter->req_q.lock);
  1770. return retval;
  1771. }
  1772. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1773. {
  1774. lat_rec->sum += lat;
  1775. lat_rec->min = min(lat_rec->min, lat);
  1776. lat_rec->max = max(lat_rec->max, lat);
  1777. }
  1778. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1779. {
  1780. struct fsf_qual_latency_info *lat_inf;
  1781. struct latency_cont *lat;
  1782. struct zfcp_unit *unit = req->unit;
  1783. unsigned long flags;
  1784. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1785. switch (req->qtcb->bottom.io.data_direction) {
  1786. case FSF_DATADIR_READ:
  1787. lat = &unit->latencies.read;
  1788. break;
  1789. case FSF_DATADIR_WRITE:
  1790. lat = &unit->latencies.write;
  1791. break;
  1792. case FSF_DATADIR_CMND:
  1793. lat = &unit->latencies.cmd;
  1794. break;
  1795. default:
  1796. return;
  1797. }
  1798. spin_lock_irqsave(&unit->latencies.lock, flags);
  1799. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1800. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1801. lat->counter++;
  1802. spin_unlock_irqrestore(&unit->latencies.lock, flags);
  1803. }
  1804. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1805. {
  1806. struct scsi_cmnd *scpnt = req->data;
  1807. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1808. &(req->qtcb->bottom.io.fcp_rsp);
  1809. u32 sns_len;
  1810. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1811. unsigned long flags;
  1812. if (unlikely(!scpnt))
  1813. return;
  1814. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1815. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1816. set_host_byte(scpnt, DID_SOFT_ERROR);
  1817. set_driver_byte(scpnt, SUGGEST_RETRY);
  1818. goto skip_fsfstatus;
  1819. }
  1820. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1821. set_host_byte(scpnt, DID_ERROR);
  1822. goto skip_fsfstatus;
  1823. }
  1824. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1825. scpnt->result |= fcp_rsp_iu->scsi_status;
  1826. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1827. zfcp_fsf_req_latency(req);
  1828. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1829. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1830. set_host_byte(scpnt, DID_OK);
  1831. else {
  1832. set_host_byte(scpnt, DID_ERROR);
  1833. goto skip_fsfstatus;
  1834. }
  1835. }
  1836. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1837. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1838. fcp_rsp_iu->fcp_rsp_len;
  1839. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1840. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1841. memcpy(scpnt->sense_buffer,
  1842. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1843. }
  1844. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1845. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1846. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1847. scpnt->underflow)
  1848. set_host_byte(scpnt, DID_ERROR);
  1849. }
  1850. skip_fsfstatus:
  1851. if (scpnt->result != 0)
  1852. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1853. else if (scpnt->retries > 0)
  1854. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1855. else
  1856. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1857. scpnt->host_scribble = NULL;
  1858. (scpnt->scsi_done) (scpnt);
  1859. /*
  1860. * We must hold this lock until scsi_done has been called.
  1861. * Otherwise we may call scsi_done after abort regarding this
  1862. * command has completed.
  1863. * Note: scsi_done must not block!
  1864. */
  1865. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1866. }
  1867. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1868. {
  1869. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1870. &(req->qtcb->bottom.io.fcp_rsp);
  1871. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1872. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1873. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1874. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1875. }
  1876. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1877. {
  1878. struct zfcp_unit *unit;
  1879. struct fsf_qtcb_header *header = &req->qtcb->header;
  1880. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1881. unit = req->data;
  1882. else
  1883. unit = req->unit;
  1884. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1885. goto skip_fsfstatus;
  1886. switch (header->fsf_status) {
  1887. case FSF_HANDLE_MISMATCH:
  1888. case FSF_PORT_HANDLE_NOT_VALID:
  1889. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
  1890. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1891. break;
  1892. case FSF_FCPLUN_NOT_VALID:
  1893. case FSF_LUN_HANDLE_NOT_VALID:
  1894. zfcp_erp_port_reopen(unit->port, 0, 113, req);
  1895. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1896. break;
  1897. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1898. zfcp_fsf_class_not_supp(req);
  1899. break;
  1900. case FSF_ACCESS_DENIED:
  1901. zfcp_fsf_access_denied_unit(req, unit);
  1902. break;
  1903. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1904. dev_err(&req->adapter->ccw_device->dev,
  1905. "Invalid data direction (%d) given for unit "
  1906. "0x%016Lx on port 0x%016Lx, shutting down "
  1907. "adapter.\n",
  1908. req->qtcb->bottom.io.data_direction,
  1909. unit->fcp_lun, unit->port->wwpn);
  1910. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
  1911. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1912. break;
  1913. case FSF_CMND_LENGTH_NOT_VALID:
  1914. dev_err(&req->adapter->ccw_device->dev,
  1915. "An invalid control-data-block length field (%d) "
  1916. "was found in a command for unit 0x%016Lx on port "
  1917. "0x%016Lx. Shutting down adapter.\n",
  1918. req->qtcb->bottom.io.fcp_cmnd_length,
  1919. unit->fcp_lun, unit->port->wwpn);
  1920. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
  1921. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1922. break;
  1923. case FSF_PORT_BOXED:
  1924. zfcp_erp_port_boxed(unit->port, 53, req);
  1925. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1926. ZFCP_STATUS_FSFREQ_RETRY;
  1927. break;
  1928. case FSF_LUN_BOXED:
  1929. zfcp_erp_unit_boxed(unit, 54, req);
  1930. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1931. ZFCP_STATUS_FSFREQ_RETRY;
  1932. break;
  1933. case FSF_ADAPTER_STATUS_AVAILABLE:
  1934. if (header->fsf_status_qual.word[0] ==
  1935. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1936. zfcp_test_link(unit->port);
  1937. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1938. break;
  1939. }
  1940. skip_fsfstatus:
  1941. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1942. zfcp_fsf_send_fcp_ctm_handler(req);
  1943. else {
  1944. zfcp_fsf_send_fcp_command_task_handler(req);
  1945. req->unit = NULL;
  1946. zfcp_unit_put(unit);
  1947. }
  1948. }
  1949. /**
  1950. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1951. * @adapter: adapter where scsi command is issued
  1952. * @unit: unit where command is sent to
  1953. * @scsi_cmnd: scsi command to be sent
  1954. * @timer: timer to be started when request is initiated
  1955. * @req_flags: flags for fsf_request
  1956. */
  1957. int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  1958. struct zfcp_unit *unit,
  1959. struct scsi_cmnd *scsi_cmnd,
  1960. int use_timer, int req_flags)
  1961. {
  1962. struct zfcp_fsf_req *req;
  1963. struct fcp_cmnd_iu *fcp_cmnd_iu;
  1964. unsigned int sbtype;
  1965. int real_bytes, retval = -EIO;
  1966. if (unlikely(!(atomic_read(&unit->status) &
  1967. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1968. return -EBUSY;
  1969. spin_lock(&adapter->req_q.lock);
  1970. if (!atomic_read(&adapter->req_q.count))
  1971. goto out;
  1972. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  1973. adapter->pool.fsf_req_scsi);
  1974. if (unlikely(IS_ERR(req))) {
  1975. retval = PTR_ERR(req);
  1976. goto out;
  1977. }
  1978. zfcp_unit_get(unit);
  1979. req->unit = unit;
  1980. req->data = scsi_cmnd;
  1981. req->handler = zfcp_fsf_send_fcp_command_handler;
  1982. req->qtcb->header.lun_handle = unit->handle;
  1983. req->qtcb->header.port_handle = unit->port->handle;
  1984. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  1985. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1986. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  1987. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  1988. /*
  1989. * set depending on data direction:
  1990. * data direction bits in SBALE (SB Type)
  1991. * data direction bits in QTCB
  1992. * data direction bits in FCP_CMND IU
  1993. */
  1994. switch (scsi_cmnd->sc_data_direction) {
  1995. case DMA_NONE:
  1996. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  1997. sbtype = SBAL_FLAGS0_TYPE_READ;
  1998. break;
  1999. case DMA_FROM_DEVICE:
  2000. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2001. sbtype = SBAL_FLAGS0_TYPE_READ;
  2002. fcp_cmnd_iu->rddata = 1;
  2003. break;
  2004. case DMA_TO_DEVICE:
  2005. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2006. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2007. fcp_cmnd_iu->wddata = 1;
  2008. break;
  2009. case DMA_BIDIRECTIONAL:
  2010. default:
  2011. retval = -EIO;
  2012. goto failed_scsi_cmnd;
  2013. }
  2014. if (likely((scsi_cmnd->device->simple_tags) ||
  2015. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2016. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2017. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2018. else
  2019. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2020. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2021. fcp_cmnd_iu->add_fcp_cdb_length =
  2022. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2023. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2024. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2025. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(fcp_dl_t);
  2026. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2027. scsi_sglist(scsi_cmnd),
  2028. FSF_MAX_SBALS_PER_REQ);
  2029. if (unlikely(real_bytes < 0)) {
  2030. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2031. retval = -EIO;
  2032. else {
  2033. dev_err(&adapter->ccw_device->dev,
  2034. "SCSI request too large. "
  2035. "Shutting down unit 0x%016Lx on port "
  2036. "0x%016Lx.\n", unit->fcp_lun,
  2037. unit->port->wwpn);
  2038. zfcp_erp_unit_shutdown(unit, 0, 131, req);
  2039. retval = -EINVAL;
  2040. }
  2041. goto failed_scsi_cmnd;
  2042. }
  2043. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2044. if (use_timer)
  2045. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2046. retval = zfcp_fsf_req_send(req);
  2047. if (unlikely(retval))
  2048. goto failed_scsi_cmnd;
  2049. goto out;
  2050. failed_scsi_cmnd:
  2051. zfcp_unit_put(unit);
  2052. zfcp_fsf_req_free(req);
  2053. scsi_cmnd->host_scribble = NULL;
  2054. out:
  2055. spin_unlock(&adapter->req_q.lock);
  2056. return retval;
  2057. }
  2058. /**
  2059. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2060. * @adapter: pointer to struct zfcp-adapter
  2061. * @unit: pointer to struct zfcp_unit
  2062. * @tm_flags: unsigned byte for task management flags
  2063. * @req_flags: int request flags
  2064. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2065. */
  2066. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
  2067. struct zfcp_unit *unit,
  2068. u8 tm_flags, int req_flags)
  2069. {
  2070. volatile struct qdio_buffer_element *sbale;
  2071. struct zfcp_fsf_req *req = NULL;
  2072. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2073. if (unlikely(!(atomic_read(&unit->status) &
  2074. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2075. return NULL;
  2076. spin_lock(&adapter->req_q.lock);
  2077. if (!atomic_read(&adapter->req_q.count))
  2078. goto out;
  2079. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2080. adapter->pool.fsf_req_scsi);
  2081. if (unlikely(IS_ERR(req)))
  2082. goto out;
  2083. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2084. req->data = unit;
  2085. req->handler = zfcp_fsf_send_fcp_command_handler;
  2086. req->qtcb->header.lun_handle = unit->handle;
  2087. req->qtcb->header.port_handle = unit->port->handle;
  2088. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2089. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2090. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2091. sizeof(fcp_dl_t);
  2092. sbale = zfcp_qdio_sbale_req(req);
  2093. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2094. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2095. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2096. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2097. fcp_cmnd_iu->task_management_flags = tm_flags;
  2098. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2099. if (!zfcp_fsf_req_send(req))
  2100. goto out;
  2101. zfcp_fsf_req_free(req);
  2102. req = NULL;
  2103. out:
  2104. spin_unlock(&adapter->req_q.lock);
  2105. return req;
  2106. }
  2107. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2108. {
  2109. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2110. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2111. }
  2112. /**
  2113. * zfcp_fsf_control_file - control file upload/download
  2114. * @adapter: pointer to struct zfcp_adapter
  2115. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2116. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2117. */
  2118. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2119. struct zfcp_fsf_cfdc *fsf_cfdc)
  2120. {
  2121. volatile struct qdio_buffer_element *sbale;
  2122. struct zfcp_fsf_req *req = NULL;
  2123. struct fsf_qtcb_bottom_support *bottom;
  2124. int direction, retval = -EIO, bytes;
  2125. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2126. return ERR_PTR(-EOPNOTSUPP);
  2127. switch (fsf_cfdc->command) {
  2128. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2129. direction = SBAL_FLAGS0_TYPE_WRITE;
  2130. break;
  2131. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2132. direction = SBAL_FLAGS0_TYPE_READ;
  2133. break;
  2134. default:
  2135. return ERR_PTR(-EINVAL);
  2136. }
  2137. spin_lock(&adapter->req_q.lock);
  2138. if (zfcp_fsf_req_sbal_get(adapter))
  2139. goto out;
  2140. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2141. if (unlikely(IS_ERR(req))) {
  2142. retval = -EPERM;
  2143. goto out;
  2144. }
  2145. req->handler = zfcp_fsf_control_file_handler;
  2146. sbale = zfcp_qdio_sbale_req(req);
  2147. sbale[0].flags |= direction;
  2148. bottom = &req->qtcb->bottom.support;
  2149. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2150. bottom->option = fsf_cfdc->option;
  2151. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2152. FSF_MAX_SBALS_PER_REQ);
  2153. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2154. retval = -ENOMEM;
  2155. zfcp_fsf_req_free(req);
  2156. goto out;
  2157. }
  2158. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2159. retval = zfcp_fsf_req_send(req);
  2160. out:
  2161. spin_unlock(&adapter->req_q.lock);
  2162. if (!retval) {
  2163. wait_event(req->completion_wq,
  2164. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2165. return req;
  2166. }
  2167. return ERR_PTR(retval);
  2168. }