zfcp_fsf.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2010
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include <linux/slab.h>
  12. #include <scsi/fc/fc_els.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_fc.h"
  15. #include "zfcp_dbf.h"
  16. #include "zfcp_qdio.h"
  17. #include "zfcp_reqlist.h"
  18. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  19. {
  20. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  21. zfcp_qdio_siosl(adapter);
  22. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  23. "fsrth_1", NULL);
  24. }
  25. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  26. unsigned long timeout)
  27. {
  28. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  29. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  30. fsf_req->timer.expires = jiffies + timeout;
  31. add_timer(&fsf_req->timer);
  32. }
  33. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  34. {
  35. BUG_ON(!fsf_req->erp_action);
  36. fsf_req->timer.function = zfcp_erp_timeout_handler;
  37. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  38. fsf_req->timer.expires = jiffies + 30 * HZ;
  39. add_timer(&fsf_req->timer);
  40. }
  41. /* association between FSF command and FSF QTCB type */
  42. static u32 fsf_qtcb_type[] = {
  43. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  44. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  52. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  53. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  54. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  55. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  56. };
  57. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  58. {
  59. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  60. "operational because of an unsupported FC class\n");
  61. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  62. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  63. }
  64. /**
  65. * zfcp_fsf_req_free - free memory used by fsf request
  66. * @fsf_req: pointer to struct zfcp_fsf_req
  67. */
  68. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  69. {
  70. if (likely(req->pool)) {
  71. if (likely(req->qtcb))
  72. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  73. mempool_free(req, req->pool);
  74. return;
  75. }
  76. if (likely(req->qtcb))
  77. kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
  78. kfree(req);
  79. }
  80. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  81. {
  82. unsigned long flags;
  83. struct fsf_status_read_buffer *sr_buf = req->data;
  84. struct zfcp_adapter *adapter = req->adapter;
  85. struct zfcp_port *port;
  86. int d_id = ntoh24(sr_buf->d_id);
  87. read_lock_irqsave(&adapter->port_list_lock, flags);
  88. list_for_each_entry(port, &adapter->port_list, list)
  89. if (port->d_id == d_id) {
  90. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  91. break;
  92. }
  93. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  94. }
  95. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req,
  96. struct fsf_link_down_info *link_down)
  97. {
  98. struct zfcp_adapter *adapter = req->adapter;
  99. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  100. return;
  101. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  102. zfcp_scsi_schedule_rports_block(adapter);
  103. if (!link_down)
  104. goto out;
  105. switch (link_down->error_code) {
  106. case FSF_PSQ_LINK_NO_LIGHT:
  107. dev_warn(&req->adapter->ccw_device->dev,
  108. "There is no light signal from the local "
  109. "fibre channel cable\n");
  110. break;
  111. case FSF_PSQ_LINK_WRAP_PLUG:
  112. dev_warn(&req->adapter->ccw_device->dev,
  113. "There is a wrap plug instead of a fibre "
  114. "channel cable\n");
  115. break;
  116. case FSF_PSQ_LINK_NO_FCP:
  117. dev_warn(&req->adapter->ccw_device->dev,
  118. "The adjacent fibre channel node does not "
  119. "support FCP\n");
  120. break;
  121. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  122. dev_warn(&req->adapter->ccw_device->dev,
  123. "The FCP device is suspended because of a "
  124. "firmware update\n");
  125. break;
  126. case FSF_PSQ_LINK_INVALID_WWPN:
  127. dev_warn(&req->adapter->ccw_device->dev,
  128. "The FCP device detected a WWPN that is "
  129. "duplicate or not valid\n");
  130. break;
  131. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  132. dev_warn(&req->adapter->ccw_device->dev,
  133. "The fibre channel fabric does not support NPIV\n");
  134. break;
  135. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  136. dev_warn(&req->adapter->ccw_device->dev,
  137. "The FCP adapter cannot support more NPIV ports\n");
  138. break;
  139. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  140. dev_warn(&req->adapter->ccw_device->dev,
  141. "The adjacent switch cannot support "
  142. "more NPIV ports\n");
  143. break;
  144. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  145. dev_warn(&req->adapter->ccw_device->dev,
  146. "The FCP adapter could not log in to the "
  147. "fibre channel fabric\n");
  148. break;
  149. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  150. dev_warn(&req->adapter->ccw_device->dev,
  151. "The WWPN assignment file on the FCP adapter "
  152. "has been damaged\n");
  153. break;
  154. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  155. dev_warn(&req->adapter->ccw_device->dev,
  156. "The mode table on the FCP adapter "
  157. "has been damaged\n");
  158. break;
  159. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  160. dev_warn(&req->adapter->ccw_device->dev,
  161. "All NPIV ports on the FCP adapter have "
  162. "been assigned\n");
  163. break;
  164. default:
  165. dev_warn(&req->adapter->ccw_device->dev,
  166. "The link between the FCP adapter and "
  167. "the FC fabric is down\n");
  168. }
  169. out:
  170. zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  171. }
  172. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  173. {
  174. struct fsf_status_read_buffer *sr_buf = req->data;
  175. struct fsf_link_down_info *ldi =
  176. (struct fsf_link_down_info *) &sr_buf->payload;
  177. switch (sr_buf->status_subtype) {
  178. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  179. zfcp_fsf_link_down_info_eval(req, ldi);
  180. break;
  181. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  182. zfcp_fsf_link_down_info_eval(req, ldi);
  183. break;
  184. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  185. zfcp_fsf_link_down_info_eval(req, NULL);
  186. };
  187. }
  188. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  189. {
  190. struct zfcp_adapter *adapter = req->adapter;
  191. struct fsf_status_read_buffer *sr_buf = req->data;
  192. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  193. zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
  194. mempool_free(sr_buf, adapter->pool.status_read_data);
  195. zfcp_fsf_req_free(req);
  196. return;
  197. }
  198. zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
  199. switch (sr_buf->status_type) {
  200. case FSF_STATUS_READ_PORT_CLOSED:
  201. zfcp_fsf_status_read_port_closed(req);
  202. break;
  203. case FSF_STATUS_READ_INCOMING_ELS:
  204. zfcp_fc_incoming_els(req);
  205. break;
  206. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  207. break;
  208. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  209. dev_warn(&adapter->ccw_device->dev,
  210. "The error threshold for checksum statistics "
  211. "has been exceeded\n");
  212. zfcp_dbf_hba_berr(adapter->dbf, req);
  213. break;
  214. case FSF_STATUS_READ_LINK_DOWN:
  215. zfcp_fsf_status_read_link_down(req);
  216. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
  217. break;
  218. case FSF_STATUS_READ_LINK_UP:
  219. dev_info(&adapter->ccw_device->dev,
  220. "The local link has been restored\n");
  221. /* All ports should be marked as ready to run again */
  222. zfcp_erp_set_adapter_status(adapter,
  223. ZFCP_STATUS_COMMON_RUNNING);
  224. zfcp_erp_adapter_reopen(adapter,
  225. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  226. ZFCP_STATUS_COMMON_ERP_FAILED,
  227. "fssrh_2", req);
  228. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
  229. break;
  230. case FSF_STATUS_READ_NOTIFICATION_LOST:
  231. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  232. zfcp_cfdc_adapter_access_changed(adapter);
  233. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  234. queue_work(adapter->work_queue, &adapter->scan_work);
  235. break;
  236. case FSF_STATUS_READ_CFDC_UPDATED:
  237. zfcp_cfdc_adapter_access_changed(adapter);
  238. break;
  239. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  240. adapter->adapter_features = sr_buf->payload.word[0];
  241. break;
  242. }
  243. mempool_free(sr_buf, adapter->pool.status_read_data);
  244. zfcp_fsf_req_free(req);
  245. atomic_inc(&adapter->stat_miss);
  246. queue_work(adapter->work_queue, &adapter->stat_work);
  247. }
  248. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  249. {
  250. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  251. case FSF_SQ_FCP_RSP_AVAILABLE:
  252. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  253. case FSF_SQ_NO_RETRY_POSSIBLE:
  254. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  255. return;
  256. case FSF_SQ_COMMAND_ABORTED:
  257. break;
  258. case FSF_SQ_NO_RECOM:
  259. dev_err(&req->adapter->ccw_device->dev,
  260. "The FCP adapter reported a problem "
  261. "that cannot be recovered\n");
  262. zfcp_qdio_siosl(req->adapter);
  263. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  264. break;
  265. }
  266. /* all non-return stats set FSFREQ_ERROR*/
  267. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  268. }
  269. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  270. {
  271. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  272. return;
  273. switch (req->qtcb->header.fsf_status) {
  274. case FSF_UNKNOWN_COMMAND:
  275. dev_err(&req->adapter->ccw_device->dev,
  276. "The FCP adapter does not recognize the command 0x%x\n",
  277. req->qtcb->header.fsf_command);
  278. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  279. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  280. break;
  281. case FSF_ADAPTER_STATUS_AVAILABLE:
  282. zfcp_fsf_fsfstatus_qual_eval(req);
  283. break;
  284. }
  285. }
  286. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  287. {
  288. struct zfcp_adapter *adapter = req->adapter;
  289. struct fsf_qtcb *qtcb = req->qtcb;
  290. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  291. zfcp_dbf_hba_fsf_response(req);
  292. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  293. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  294. return;
  295. }
  296. switch (qtcb->prefix.prot_status) {
  297. case FSF_PROT_GOOD:
  298. case FSF_PROT_FSF_STATUS_PRESENTED:
  299. return;
  300. case FSF_PROT_QTCB_VERSION_ERROR:
  301. dev_err(&adapter->ccw_device->dev,
  302. "QTCB version 0x%x not supported by FCP adapter "
  303. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  304. psq->word[0], psq->word[1]);
  305. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  306. break;
  307. case FSF_PROT_ERROR_STATE:
  308. case FSF_PROT_SEQ_NUMB_ERROR:
  309. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  310. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  311. break;
  312. case FSF_PROT_UNSUPP_QTCB_TYPE:
  313. dev_err(&adapter->ccw_device->dev,
  314. "The QTCB type is not supported by the FCP adapter\n");
  315. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  316. break;
  317. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  318. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  319. &adapter->status);
  320. break;
  321. case FSF_PROT_DUPLICATE_REQUEST_ID:
  322. dev_err(&adapter->ccw_device->dev,
  323. "0x%Lx is an ambiguous request identifier\n",
  324. (unsigned long long)qtcb->bottom.support.req_handle);
  325. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  326. break;
  327. case FSF_PROT_LINK_DOWN:
  328. zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
  329. /* go through reopen to flush pending requests */
  330. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  331. break;
  332. case FSF_PROT_REEST_QUEUE:
  333. /* All ports should be marked as ready to run again */
  334. zfcp_erp_set_adapter_status(adapter,
  335. ZFCP_STATUS_COMMON_RUNNING);
  336. zfcp_erp_adapter_reopen(adapter,
  337. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  338. ZFCP_STATUS_COMMON_ERP_FAILED,
  339. "fspse_8", req);
  340. break;
  341. default:
  342. dev_err(&adapter->ccw_device->dev,
  343. "0x%x is not a valid transfer protocol status\n",
  344. qtcb->prefix.prot_status);
  345. zfcp_qdio_siosl(adapter);
  346. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  347. }
  348. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  349. }
  350. /**
  351. * zfcp_fsf_req_complete - process completion of a FSF request
  352. * @fsf_req: The FSF request that has been completed.
  353. *
  354. * When a request has been completed either from the FCP adapter,
  355. * or it has been dismissed due to a queue shutdown, this function
  356. * is called to process the completion status and trigger further
  357. * events related to the FSF request.
  358. */
  359. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  360. {
  361. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  362. zfcp_fsf_status_read_handler(req);
  363. return;
  364. }
  365. del_timer(&req->timer);
  366. zfcp_fsf_protstatus_eval(req);
  367. zfcp_fsf_fsfstatus_eval(req);
  368. req->handler(req);
  369. if (req->erp_action)
  370. zfcp_erp_notify(req->erp_action, 0);
  371. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  372. zfcp_fsf_req_free(req);
  373. else
  374. complete(&req->completion);
  375. }
  376. /**
  377. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  378. * @adapter: pointer to struct zfcp_adapter
  379. *
  380. * Never ever call this without shutting down the adapter first.
  381. * Otherwise the adapter would continue using and corrupting s390 storage.
  382. * Included BUG_ON() call to ensure this is done.
  383. * ERP is supposed to be the only user of this function.
  384. */
  385. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  386. {
  387. struct zfcp_fsf_req *req, *tmp;
  388. LIST_HEAD(remove_queue);
  389. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  390. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  391. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  392. list_del(&req->list);
  393. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  394. zfcp_fsf_req_complete(req);
  395. }
  396. }
  397. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  398. {
  399. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  400. struct zfcp_adapter *adapter = req->adapter;
  401. struct Scsi_Host *shost = adapter->scsi_host;
  402. struct fc_els_flogi *nsp, *plogi;
  403. /* adjust pointers for missing command code */
  404. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  405. - sizeof(u32));
  406. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  407. - sizeof(u32));
  408. if (req->data)
  409. memcpy(req->data, bottom, sizeof(*bottom));
  410. fc_host_port_name(shost) = nsp->fl_wwpn;
  411. fc_host_node_name(shost) = nsp->fl_wwnn;
  412. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  413. fc_host_speed(shost) = bottom->fc_link_speed;
  414. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  415. adapter->hydra_version = bottom->adapter_type;
  416. adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
  417. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  418. (u16)FSF_STATUS_READS_RECOM);
  419. if (fc_host_permanent_port_name(shost) == -1)
  420. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  421. switch (bottom->fc_topology) {
  422. case FSF_TOPO_P2P:
  423. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  424. adapter->peer_wwpn = plogi->fl_wwpn;
  425. adapter->peer_wwnn = plogi->fl_wwnn;
  426. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  427. break;
  428. case FSF_TOPO_FABRIC:
  429. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  430. break;
  431. case FSF_TOPO_AL:
  432. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  433. /* fall through */
  434. default:
  435. dev_err(&adapter->ccw_device->dev,
  436. "Unknown or unsupported arbitrated loop "
  437. "fibre channel topology detected\n");
  438. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  439. return -EIO;
  440. }
  441. zfcp_scsi_set_prot(adapter);
  442. return 0;
  443. }
  444. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  445. {
  446. struct zfcp_adapter *adapter = req->adapter;
  447. struct fsf_qtcb *qtcb = req->qtcb;
  448. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  449. struct Scsi_Host *shost = adapter->scsi_host;
  450. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  451. return;
  452. adapter->fsf_lic_version = bottom->lic_version;
  453. adapter->adapter_features = bottom->adapter_features;
  454. adapter->connection_features = bottom->connection_features;
  455. adapter->peer_wwpn = 0;
  456. adapter->peer_wwnn = 0;
  457. adapter->peer_d_id = 0;
  458. switch (qtcb->header.fsf_status) {
  459. case FSF_GOOD:
  460. if (zfcp_fsf_exchange_config_evaluate(req))
  461. return;
  462. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  463. dev_err(&adapter->ccw_device->dev,
  464. "FCP adapter maximum QTCB size (%d bytes) "
  465. "is too small\n",
  466. bottom->max_qtcb_size);
  467. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  468. return;
  469. }
  470. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  471. &adapter->status);
  472. break;
  473. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  474. fc_host_node_name(shost) = 0;
  475. fc_host_port_name(shost) = 0;
  476. fc_host_port_id(shost) = 0;
  477. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  478. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  479. adapter->hydra_version = 0;
  480. zfcp_fsf_link_down_info_eval(req,
  481. &qtcb->header.fsf_status_qual.link_down_info);
  482. break;
  483. default:
  484. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  485. return;
  486. }
  487. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  488. adapter->hardware_version = bottom->hardware_version;
  489. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  490. min(FC_SERIAL_NUMBER_SIZE, 17));
  491. EBCASC(fc_host_serial_number(shost),
  492. min(FC_SERIAL_NUMBER_SIZE, 17));
  493. }
  494. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  495. dev_err(&adapter->ccw_device->dev,
  496. "The FCP adapter only supports newer "
  497. "control block versions\n");
  498. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  499. return;
  500. }
  501. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  502. dev_err(&adapter->ccw_device->dev,
  503. "The FCP adapter only supports older "
  504. "control block versions\n");
  505. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  506. }
  507. }
  508. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  509. {
  510. struct zfcp_adapter *adapter = req->adapter;
  511. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  512. struct Scsi_Host *shost = adapter->scsi_host;
  513. if (req->data)
  514. memcpy(req->data, bottom, sizeof(*bottom));
  515. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  516. fc_host_permanent_port_name(shost) = bottom->wwpn;
  517. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  518. } else
  519. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  520. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  521. fc_host_supported_speeds(shost) = bottom->supported_speed;
  522. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  523. FC_FC4_LIST_SIZE);
  524. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  525. FC_FC4_LIST_SIZE);
  526. }
  527. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  528. {
  529. struct fsf_qtcb *qtcb = req->qtcb;
  530. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  531. return;
  532. switch (qtcb->header.fsf_status) {
  533. case FSF_GOOD:
  534. zfcp_fsf_exchange_port_evaluate(req);
  535. break;
  536. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  537. zfcp_fsf_exchange_port_evaluate(req);
  538. zfcp_fsf_link_down_info_eval(req,
  539. &qtcb->header.fsf_status_qual.link_down_info);
  540. break;
  541. }
  542. }
  543. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  544. {
  545. struct zfcp_fsf_req *req;
  546. if (likely(pool))
  547. req = mempool_alloc(pool, GFP_ATOMIC);
  548. else
  549. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  550. if (unlikely(!req))
  551. return NULL;
  552. memset(req, 0, sizeof(*req));
  553. req->pool = pool;
  554. return req;
  555. }
  556. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  557. {
  558. struct fsf_qtcb *qtcb;
  559. if (likely(pool))
  560. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  561. else
  562. qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
  563. if (unlikely(!qtcb))
  564. return NULL;
  565. memset(qtcb, 0, sizeof(*qtcb));
  566. return qtcb;
  567. }
  568. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  569. u32 fsf_cmd, u32 sbtype,
  570. mempool_t *pool)
  571. {
  572. struct zfcp_adapter *adapter = qdio->adapter;
  573. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  574. if (unlikely(!req))
  575. return ERR_PTR(-ENOMEM);
  576. if (adapter->req_no == 0)
  577. adapter->req_no++;
  578. INIT_LIST_HEAD(&req->list);
  579. init_timer(&req->timer);
  580. init_completion(&req->completion);
  581. req->adapter = adapter;
  582. req->fsf_command = fsf_cmd;
  583. req->req_id = adapter->req_no;
  584. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  585. if (likely(pool))
  586. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  587. else
  588. req->qtcb = zfcp_qtcb_alloc(NULL);
  589. if (unlikely(!req->qtcb)) {
  590. zfcp_fsf_req_free(req);
  591. return ERR_PTR(-ENOMEM);
  592. }
  593. req->seq_no = adapter->fsf_req_seq_no;
  594. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  595. req->qtcb->prefix.req_id = req->req_id;
  596. req->qtcb->prefix.ulp_info = 26;
  597. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  598. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  599. req->qtcb->header.req_handle = req->req_id;
  600. req->qtcb->header.fsf_command = req->fsf_command;
  601. }
  602. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  603. req->qtcb, sizeof(struct fsf_qtcb));
  604. return req;
  605. }
  606. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  607. {
  608. struct zfcp_adapter *adapter = req->adapter;
  609. struct zfcp_qdio *qdio = adapter->qdio;
  610. int with_qtcb = (req->qtcb != NULL);
  611. int req_id = req->req_id;
  612. zfcp_reqlist_add(adapter->req_list, req);
  613. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
  614. req->issued = get_clock();
  615. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  616. del_timer(&req->timer);
  617. /* lookup request again, list might have changed */
  618. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  619. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  620. return -EIO;
  621. }
  622. /* Don't increase for unsolicited status */
  623. if (with_qtcb)
  624. adapter->fsf_req_seq_no++;
  625. adapter->req_no++;
  626. return 0;
  627. }
  628. /**
  629. * zfcp_fsf_status_read - send status read request
  630. * @adapter: pointer to struct zfcp_adapter
  631. * @req_flags: request flags
  632. * Returns: 0 on success, ERROR otherwise
  633. */
  634. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  635. {
  636. struct zfcp_adapter *adapter = qdio->adapter;
  637. struct zfcp_fsf_req *req;
  638. struct fsf_status_read_buffer *sr_buf;
  639. int retval = -EIO;
  640. spin_lock_irq(&qdio->req_q_lock);
  641. if (zfcp_qdio_sbal_get(qdio))
  642. goto out;
  643. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
  644. adapter->pool.status_read_req);
  645. if (IS_ERR(req)) {
  646. retval = PTR_ERR(req);
  647. goto out;
  648. }
  649. sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
  650. if (!sr_buf) {
  651. retval = -ENOMEM;
  652. goto failed_buf;
  653. }
  654. memset(sr_buf, 0, sizeof(*sr_buf));
  655. req->data = sr_buf;
  656. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  657. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  658. retval = zfcp_fsf_req_send(req);
  659. if (retval)
  660. goto failed_req_send;
  661. goto out;
  662. failed_req_send:
  663. mempool_free(sr_buf, adapter->pool.status_read_data);
  664. failed_buf:
  665. zfcp_fsf_req_free(req);
  666. zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
  667. out:
  668. spin_unlock_irq(&qdio->req_q_lock);
  669. return retval;
  670. }
  671. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  672. {
  673. struct scsi_device *sdev = req->data;
  674. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  675. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  676. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  677. return;
  678. switch (req->qtcb->header.fsf_status) {
  679. case FSF_PORT_HANDLE_NOT_VALID:
  680. if (fsq->word[0] == fsq->word[1]) {
  681. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
  682. "fsafch1", req);
  683. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  684. }
  685. break;
  686. case FSF_LUN_HANDLE_NOT_VALID:
  687. if (fsq->word[0] == fsq->word[1]) {
  688. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2",
  689. req);
  690. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  691. }
  692. break;
  693. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  694. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  695. break;
  696. case FSF_PORT_BOXED:
  697. zfcp_erp_set_port_status(zfcp_sdev->port,
  698. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  699. zfcp_erp_port_reopen(zfcp_sdev->port,
  700. ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3",
  701. req);
  702. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  703. break;
  704. case FSF_LUN_BOXED:
  705. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  706. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  707. "fsafch4", req);
  708. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  709. break;
  710. case FSF_ADAPTER_STATUS_AVAILABLE:
  711. switch (fsq->word[0]) {
  712. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  713. zfcp_fc_test_link(zfcp_sdev->port);
  714. /* fall through */
  715. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  716. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  717. break;
  718. }
  719. break;
  720. case FSF_GOOD:
  721. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  722. break;
  723. }
  724. }
  725. /**
  726. * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
  727. * @scmnd: The SCSI command to abort
  728. * Returns: pointer to struct zfcp_fsf_req
  729. */
  730. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
  731. {
  732. struct zfcp_fsf_req *req = NULL;
  733. struct scsi_device *sdev = scmnd->device;
  734. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  735. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  736. unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
  737. spin_lock_irq(&qdio->req_q_lock);
  738. if (zfcp_qdio_sbal_get(qdio))
  739. goto out;
  740. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  741. SBAL_FLAGS0_TYPE_READ,
  742. qdio->adapter->pool.scsi_abort);
  743. if (IS_ERR(req)) {
  744. req = NULL;
  745. goto out;
  746. }
  747. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  748. ZFCP_STATUS_COMMON_UNBLOCKED)))
  749. goto out_error_free;
  750. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  751. req->data = zfcp_sdev;
  752. req->handler = zfcp_fsf_abort_fcp_command_handler;
  753. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  754. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  755. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  756. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  757. if (!zfcp_fsf_req_send(req))
  758. goto out;
  759. out_error_free:
  760. zfcp_fsf_req_free(req);
  761. req = NULL;
  762. out:
  763. spin_unlock_irq(&qdio->req_q_lock);
  764. return req;
  765. }
  766. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  767. {
  768. struct zfcp_adapter *adapter = req->adapter;
  769. struct zfcp_fsf_ct_els *ct = req->data;
  770. struct fsf_qtcb_header *header = &req->qtcb->header;
  771. ct->status = -EINVAL;
  772. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  773. goto skip_fsfstatus;
  774. switch (header->fsf_status) {
  775. case FSF_GOOD:
  776. zfcp_dbf_san_ct_response(req);
  777. ct->status = 0;
  778. break;
  779. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  780. zfcp_fsf_class_not_supp(req);
  781. break;
  782. case FSF_ADAPTER_STATUS_AVAILABLE:
  783. switch (header->fsf_status_qual.word[0]){
  784. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  785. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  786. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  787. break;
  788. }
  789. break;
  790. case FSF_ACCESS_DENIED:
  791. break;
  792. case FSF_PORT_BOXED:
  793. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  794. break;
  795. case FSF_PORT_HANDLE_NOT_VALID:
  796. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  797. /* fall through */
  798. case FSF_GENERIC_COMMAND_REJECTED:
  799. case FSF_PAYLOAD_SIZE_MISMATCH:
  800. case FSF_REQUEST_SIZE_TOO_LARGE:
  801. case FSF_RESPONSE_SIZE_TOO_LARGE:
  802. case FSF_SBAL_MISMATCH:
  803. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  804. break;
  805. }
  806. skip_fsfstatus:
  807. if (ct->handler)
  808. ct->handler(ct->handler_data);
  809. }
  810. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  811. struct zfcp_qdio_req *q_req,
  812. struct scatterlist *sg_req,
  813. struct scatterlist *sg_resp)
  814. {
  815. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  816. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  817. zfcp_qdio_set_sbale_last(qdio, q_req);
  818. }
  819. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  820. struct scatterlist *sg_req,
  821. struct scatterlist *sg_resp)
  822. {
  823. struct zfcp_adapter *adapter = req->adapter;
  824. u32 feat = adapter->adapter_features;
  825. int bytes;
  826. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  827. if (!zfcp_qdio_sg_one_sbale(sg_req) ||
  828. !zfcp_qdio_sg_one_sbale(sg_resp))
  829. return -EOPNOTSUPP;
  830. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  831. sg_req, sg_resp);
  832. return 0;
  833. }
  834. /* use single, unchained SBAL if it can hold the request */
  835. if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
  836. zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
  837. sg_req, sg_resp);
  838. return 0;
  839. }
  840. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
  841. if (bytes <= 0)
  842. return -EIO;
  843. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  844. req->qtcb->bottom.support.req_buf_length = bytes;
  845. zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
  846. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
  847. sg_resp);
  848. req->qtcb->bottom.support.resp_buf_length = bytes;
  849. if (bytes <= 0)
  850. return -EIO;
  851. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  852. return 0;
  853. }
  854. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  855. struct scatterlist *sg_req,
  856. struct scatterlist *sg_resp,
  857. unsigned int timeout)
  858. {
  859. int ret;
  860. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
  861. if (ret)
  862. return ret;
  863. /* common settings for ct/gs and els requests */
  864. if (timeout > 255)
  865. timeout = 255; /* max value accepted by hardware */
  866. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  867. req->qtcb->bottom.support.timeout = timeout;
  868. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  869. return 0;
  870. }
  871. /**
  872. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  873. * @ct: pointer to struct zfcp_send_ct with data for request
  874. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  875. */
  876. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  877. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  878. unsigned int timeout)
  879. {
  880. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  881. struct zfcp_fsf_req *req;
  882. int ret = -EIO;
  883. spin_lock_irq(&qdio->req_q_lock);
  884. if (zfcp_qdio_sbal_get(qdio))
  885. goto out;
  886. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  887. SBAL_FLAGS0_TYPE_WRITE_READ, pool);
  888. if (IS_ERR(req)) {
  889. ret = PTR_ERR(req);
  890. goto out;
  891. }
  892. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  893. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
  894. if (ret)
  895. goto failed_send;
  896. req->handler = zfcp_fsf_send_ct_handler;
  897. req->qtcb->header.port_handle = wka_port->handle;
  898. req->data = ct;
  899. zfcp_dbf_san_ct_request(req, wka_port->d_id);
  900. ret = zfcp_fsf_req_send(req);
  901. if (ret)
  902. goto failed_send;
  903. goto out;
  904. failed_send:
  905. zfcp_fsf_req_free(req);
  906. out:
  907. spin_unlock_irq(&qdio->req_q_lock);
  908. return ret;
  909. }
  910. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  911. {
  912. struct zfcp_fsf_ct_els *send_els = req->data;
  913. struct zfcp_port *port = send_els->port;
  914. struct fsf_qtcb_header *header = &req->qtcb->header;
  915. send_els->status = -EINVAL;
  916. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  917. goto skip_fsfstatus;
  918. switch (header->fsf_status) {
  919. case FSF_GOOD:
  920. zfcp_dbf_san_els_response(req);
  921. send_els->status = 0;
  922. break;
  923. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  924. zfcp_fsf_class_not_supp(req);
  925. break;
  926. case FSF_ADAPTER_STATUS_AVAILABLE:
  927. switch (header->fsf_status_qual.word[0]){
  928. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  929. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  930. case FSF_SQ_RETRY_IF_POSSIBLE:
  931. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  932. break;
  933. }
  934. break;
  935. case FSF_ELS_COMMAND_REJECTED:
  936. case FSF_PAYLOAD_SIZE_MISMATCH:
  937. case FSF_REQUEST_SIZE_TOO_LARGE:
  938. case FSF_RESPONSE_SIZE_TOO_LARGE:
  939. break;
  940. case FSF_ACCESS_DENIED:
  941. if (port) {
  942. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  943. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  944. }
  945. break;
  946. case FSF_SBAL_MISMATCH:
  947. /* should never occure, avoided in zfcp_fsf_send_els */
  948. /* fall through */
  949. default:
  950. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  951. break;
  952. }
  953. skip_fsfstatus:
  954. if (send_els->handler)
  955. send_els->handler(send_els->handler_data);
  956. }
  957. /**
  958. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  959. * @els: pointer to struct zfcp_send_els with data for the command
  960. */
  961. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  962. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  963. {
  964. struct zfcp_fsf_req *req;
  965. struct zfcp_qdio *qdio = adapter->qdio;
  966. int ret = -EIO;
  967. spin_lock_irq(&qdio->req_q_lock);
  968. if (zfcp_qdio_sbal_get(qdio))
  969. goto out;
  970. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  971. SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
  972. if (IS_ERR(req)) {
  973. ret = PTR_ERR(req);
  974. goto out;
  975. }
  976. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  977. zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
  978. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
  979. if (ret)
  980. goto failed_send;
  981. hton24(req->qtcb->bottom.support.d_id, d_id);
  982. req->handler = zfcp_fsf_send_els_handler;
  983. req->data = els;
  984. zfcp_dbf_san_els_request(req);
  985. ret = zfcp_fsf_req_send(req);
  986. if (ret)
  987. goto failed_send;
  988. goto out;
  989. failed_send:
  990. zfcp_fsf_req_free(req);
  991. out:
  992. spin_unlock_irq(&qdio->req_q_lock);
  993. return ret;
  994. }
  995. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  996. {
  997. struct zfcp_fsf_req *req;
  998. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  999. int retval = -EIO;
  1000. spin_lock_irq(&qdio->req_q_lock);
  1001. if (zfcp_qdio_sbal_get(qdio))
  1002. goto out;
  1003. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1004. SBAL_FLAGS0_TYPE_READ,
  1005. qdio->adapter->pool.erp_req);
  1006. if (IS_ERR(req)) {
  1007. retval = PTR_ERR(req);
  1008. goto out;
  1009. }
  1010. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1011. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1012. req->qtcb->bottom.config.feature_selection =
  1013. FSF_FEATURE_CFDC |
  1014. FSF_FEATURE_LUN_SHARING |
  1015. FSF_FEATURE_NOTIFICATION_LOST |
  1016. FSF_FEATURE_UPDATE_ALERT;
  1017. req->erp_action = erp_action;
  1018. req->handler = zfcp_fsf_exchange_config_data_handler;
  1019. erp_action->fsf_req_id = req->req_id;
  1020. zfcp_fsf_start_erp_timer(req);
  1021. retval = zfcp_fsf_req_send(req);
  1022. if (retval) {
  1023. zfcp_fsf_req_free(req);
  1024. erp_action->fsf_req_id = 0;
  1025. }
  1026. out:
  1027. spin_unlock_irq(&qdio->req_q_lock);
  1028. return retval;
  1029. }
  1030. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1031. struct fsf_qtcb_bottom_config *data)
  1032. {
  1033. struct zfcp_fsf_req *req = NULL;
  1034. int retval = -EIO;
  1035. spin_lock_irq(&qdio->req_q_lock);
  1036. if (zfcp_qdio_sbal_get(qdio))
  1037. goto out_unlock;
  1038. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1039. SBAL_FLAGS0_TYPE_READ, NULL);
  1040. if (IS_ERR(req)) {
  1041. retval = PTR_ERR(req);
  1042. goto out_unlock;
  1043. }
  1044. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1045. req->handler = zfcp_fsf_exchange_config_data_handler;
  1046. req->qtcb->bottom.config.feature_selection =
  1047. FSF_FEATURE_CFDC |
  1048. FSF_FEATURE_LUN_SHARING |
  1049. FSF_FEATURE_NOTIFICATION_LOST |
  1050. FSF_FEATURE_UPDATE_ALERT;
  1051. if (data)
  1052. req->data = data;
  1053. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1054. retval = zfcp_fsf_req_send(req);
  1055. spin_unlock_irq(&qdio->req_q_lock);
  1056. if (!retval)
  1057. wait_for_completion(&req->completion);
  1058. zfcp_fsf_req_free(req);
  1059. return retval;
  1060. out_unlock:
  1061. spin_unlock_irq(&qdio->req_q_lock);
  1062. return retval;
  1063. }
  1064. /**
  1065. * zfcp_fsf_exchange_port_data - request information about local port
  1066. * @erp_action: ERP action for the adapter for which port data is requested
  1067. * Returns: 0 on success, error otherwise
  1068. */
  1069. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1070. {
  1071. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1072. struct zfcp_fsf_req *req;
  1073. int retval = -EIO;
  1074. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1075. return -EOPNOTSUPP;
  1076. spin_lock_irq(&qdio->req_q_lock);
  1077. if (zfcp_qdio_sbal_get(qdio))
  1078. goto out;
  1079. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1080. SBAL_FLAGS0_TYPE_READ,
  1081. qdio->adapter->pool.erp_req);
  1082. if (IS_ERR(req)) {
  1083. retval = PTR_ERR(req);
  1084. goto out;
  1085. }
  1086. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1087. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1088. req->handler = zfcp_fsf_exchange_port_data_handler;
  1089. req->erp_action = erp_action;
  1090. erp_action->fsf_req_id = req->req_id;
  1091. zfcp_fsf_start_erp_timer(req);
  1092. retval = zfcp_fsf_req_send(req);
  1093. if (retval) {
  1094. zfcp_fsf_req_free(req);
  1095. erp_action->fsf_req_id = 0;
  1096. }
  1097. out:
  1098. spin_unlock_irq(&qdio->req_q_lock);
  1099. return retval;
  1100. }
  1101. /**
  1102. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1103. * @qdio: pointer to struct zfcp_qdio
  1104. * @data: pointer to struct fsf_qtcb_bottom_port
  1105. * Returns: 0 on success, error otherwise
  1106. */
  1107. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1108. struct fsf_qtcb_bottom_port *data)
  1109. {
  1110. struct zfcp_fsf_req *req = NULL;
  1111. int retval = -EIO;
  1112. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1113. return -EOPNOTSUPP;
  1114. spin_lock_irq(&qdio->req_q_lock);
  1115. if (zfcp_qdio_sbal_get(qdio))
  1116. goto out_unlock;
  1117. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1118. SBAL_FLAGS0_TYPE_READ, NULL);
  1119. if (IS_ERR(req)) {
  1120. retval = PTR_ERR(req);
  1121. goto out_unlock;
  1122. }
  1123. if (data)
  1124. req->data = data;
  1125. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1126. req->handler = zfcp_fsf_exchange_port_data_handler;
  1127. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1128. retval = zfcp_fsf_req_send(req);
  1129. spin_unlock_irq(&qdio->req_q_lock);
  1130. if (!retval)
  1131. wait_for_completion(&req->completion);
  1132. zfcp_fsf_req_free(req);
  1133. return retval;
  1134. out_unlock:
  1135. spin_unlock_irq(&qdio->req_q_lock);
  1136. return retval;
  1137. }
  1138. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1139. {
  1140. struct zfcp_port *port = req->data;
  1141. struct fsf_qtcb_header *header = &req->qtcb->header;
  1142. struct fc_els_flogi *plogi;
  1143. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1144. goto out;
  1145. switch (header->fsf_status) {
  1146. case FSF_PORT_ALREADY_OPEN:
  1147. break;
  1148. case FSF_ACCESS_DENIED:
  1149. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  1150. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1151. break;
  1152. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1153. dev_warn(&req->adapter->ccw_device->dev,
  1154. "Not enough FCP adapter resources to open "
  1155. "remote port 0x%016Lx\n",
  1156. (unsigned long long)port->wwpn);
  1157. zfcp_erp_set_port_status(port,
  1158. ZFCP_STATUS_COMMON_ERP_FAILED);
  1159. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1160. break;
  1161. case FSF_ADAPTER_STATUS_AVAILABLE:
  1162. switch (header->fsf_status_qual.word[0]) {
  1163. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1164. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1165. case FSF_SQ_NO_RETRY_POSSIBLE:
  1166. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1167. break;
  1168. }
  1169. break;
  1170. case FSF_GOOD:
  1171. port->handle = header->port_handle;
  1172. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1173. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1174. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1175. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1176. &port->status);
  1177. /* check whether D_ID has changed during open */
  1178. /*
  1179. * FIXME: This check is not airtight, as the FCP channel does
  1180. * not monitor closures of target port connections caused on
  1181. * the remote side. Thus, they might miss out on invalidating
  1182. * locally cached WWPNs (and other N_Port parameters) of gone
  1183. * target ports. So, our heroic attempt to make things safe
  1184. * could be undermined by 'open port' response data tagged with
  1185. * obsolete WWPNs. Another reason to monitor potential
  1186. * connection closures ourself at least (by interpreting
  1187. * incoming ELS' and unsolicited status). It just crosses my
  1188. * mind that one should be able to cross-check by means of
  1189. * another GID_PN straight after a port has been opened.
  1190. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1191. */
  1192. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1193. if (req->qtcb->bottom.support.els1_length >=
  1194. FSF_PLOGI_MIN_LEN)
  1195. zfcp_fc_plogi_evaluate(port, plogi);
  1196. break;
  1197. case FSF_UNKNOWN_OP_SUBTYPE:
  1198. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1199. break;
  1200. }
  1201. out:
  1202. put_device(&port->dev);
  1203. }
  1204. /**
  1205. * zfcp_fsf_open_port - create and send open port request
  1206. * @erp_action: pointer to struct zfcp_erp_action
  1207. * Returns: 0 on success, error otherwise
  1208. */
  1209. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1210. {
  1211. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1212. struct zfcp_port *port = erp_action->port;
  1213. struct zfcp_fsf_req *req;
  1214. int retval = -EIO;
  1215. spin_lock_irq(&qdio->req_q_lock);
  1216. if (zfcp_qdio_sbal_get(qdio))
  1217. goto out;
  1218. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1219. SBAL_FLAGS0_TYPE_READ,
  1220. qdio->adapter->pool.erp_req);
  1221. if (IS_ERR(req)) {
  1222. retval = PTR_ERR(req);
  1223. goto out;
  1224. }
  1225. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1226. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1227. req->handler = zfcp_fsf_open_port_handler;
  1228. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1229. req->data = port;
  1230. req->erp_action = erp_action;
  1231. erp_action->fsf_req_id = req->req_id;
  1232. get_device(&port->dev);
  1233. zfcp_fsf_start_erp_timer(req);
  1234. retval = zfcp_fsf_req_send(req);
  1235. if (retval) {
  1236. zfcp_fsf_req_free(req);
  1237. erp_action->fsf_req_id = 0;
  1238. put_device(&port->dev);
  1239. }
  1240. out:
  1241. spin_unlock_irq(&qdio->req_q_lock);
  1242. return retval;
  1243. }
  1244. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1245. {
  1246. struct zfcp_port *port = req->data;
  1247. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1248. return;
  1249. switch (req->qtcb->header.fsf_status) {
  1250. case FSF_PORT_HANDLE_NOT_VALID:
  1251. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1252. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1253. break;
  1254. case FSF_ADAPTER_STATUS_AVAILABLE:
  1255. break;
  1256. case FSF_GOOD:
  1257. zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
  1258. break;
  1259. }
  1260. }
  1261. /**
  1262. * zfcp_fsf_close_port - create and send close port request
  1263. * @erp_action: pointer to struct zfcp_erp_action
  1264. * Returns: 0 on success, error otherwise
  1265. */
  1266. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1267. {
  1268. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1269. struct zfcp_fsf_req *req;
  1270. int retval = -EIO;
  1271. spin_lock_irq(&qdio->req_q_lock);
  1272. if (zfcp_qdio_sbal_get(qdio))
  1273. goto out;
  1274. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1275. SBAL_FLAGS0_TYPE_READ,
  1276. qdio->adapter->pool.erp_req);
  1277. if (IS_ERR(req)) {
  1278. retval = PTR_ERR(req);
  1279. goto out;
  1280. }
  1281. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1282. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1283. req->handler = zfcp_fsf_close_port_handler;
  1284. req->data = erp_action->port;
  1285. req->erp_action = erp_action;
  1286. req->qtcb->header.port_handle = erp_action->port->handle;
  1287. erp_action->fsf_req_id = req->req_id;
  1288. zfcp_fsf_start_erp_timer(req);
  1289. retval = zfcp_fsf_req_send(req);
  1290. if (retval) {
  1291. zfcp_fsf_req_free(req);
  1292. erp_action->fsf_req_id = 0;
  1293. }
  1294. out:
  1295. spin_unlock_irq(&qdio->req_q_lock);
  1296. return retval;
  1297. }
  1298. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1299. {
  1300. struct zfcp_fc_wka_port *wka_port = req->data;
  1301. struct fsf_qtcb_header *header = &req->qtcb->header;
  1302. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1303. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1304. goto out;
  1305. }
  1306. switch (header->fsf_status) {
  1307. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1308. dev_warn(&req->adapter->ccw_device->dev,
  1309. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1310. /* fall through */
  1311. case FSF_ADAPTER_STATUS_AVAILABLE:
  1312. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1313. /* fall through */
  1314. case FSF_ACCESS_DENIED:
  1315. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1316. break;
  1317. case FSF_GOOD:
  1318. wka_port->handle = header->port_handle;
  1319. /* fall through */
  1320. case FSF_PORT_ALREADY_OPEN:
  1321. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1322. }
  1323. out:
  1324. wake_up(&wka_port->completion_wq);
  1325. }
  1326. /**
  1327. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1328. * @wka_port: pointer to struct zfcp_fc_wka_port
  1329. * Returns: 0 on success, error otherwise
  1330. */
  1331. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1332. {
  1333. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1334. struct zfcp_fsf_req *req;
  1335. int retval = -EIO;
  1336. spin_lock_irq(&qdio->req_q_lock);
  1337. if (zfcp_qdio_sbal_get(qdio))
  1338. goto out;
  1339. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1340. SBAL_FLAGS0_TYPE_READ,
  1341. qdio->adapter->pool.erp_req);
  1342. if (unlikely(IS_ERR(req))) {
  1343. retval = PTR_ERR(req);
  1344. goto out;
  1345. }
  1346. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1347. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1348. req->handler = zfcp_fsf_open_wka_port_handler;
  1349. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1350. req->data = wka_port;
  1351. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1352. retval = zfcp_fsf_req_send(req);
  1353. if (retval)
  1354. zfcp_fsf_req_free(req);
  1355. out:
  1356. spin_unlock_irq(&qdio->req_q_lock);
  1357. return retval;
  1358. }
  1359. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1360. {
  1361. struct zfcp_fc_wka_port *wka_port = req->data;
  1362. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1363. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1364. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1365. }
  1366. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1367. wake_up(&wka_port->completion_wq);
  1368. }
  1369. /**
  1370. * zfcp_fsf_close_wka_port - create and send close wka port request
  1371. * @wka_port: WKA port to open
  1372. * Returns: 0 on success, error otherwise
  1373. */
  1374. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1375. {
  1376. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1377. struct zfcp_fsf_req *req;
  1378. int retval = -EIO;
  1379. spin_lock_irq(&qdio->req_q_lock);
  1380. if (zfcp_qdio_sbal_get(qdio))
  1381. goto out;
  1382. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1383. SBAL_FLAGS0_TYPE_READ,
  1384. qdio->adapter->pool.erp_req);
  1385. if (unlikely(IS_ERR(req))) {
  1386. retval = PTR_ERR(req);
  1387. goto out;
  1388. }
  1389. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1390. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1391. req->handler = zfcp_fsf_close_wka_port_handler;
  1392. req->data = wka_port;
  1393. req->qtcb->header.port_handle = wka_port->handle;
  1394. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1395. retval = zfcp_fsf_req_send(req);
  1396. if (retval)
  1397. zfcp_fsf_req_free(req);
  1398. out:
  1399. spin_unlock_irq(&qdio->req_q_lock);
  1400. return retval;
  1401. }
  1402. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1403. {
  1404. struct zfcp_port *port = req->data;
  1405. struct fsf_qtcb_header *header = &req->qtcb->header;
  1406. struct scsi_device *sdev;
  1407. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1408. return;
  1409. switch (header->fsf_status) {
  1410. case FSF_PORT_HANDLE_NOT_VALID:
  1411. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1412. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1413. break;
  1414. case FSF_ACCESS_DENIED:
  1415. zfcp_cfdc_port_denied(port, &header->fsf_status_qual);
  1416. break;
  1417. case FSF_PORT_BOXED:
  1418. /* can't use generic zfcp_erp_modify_port_status because
  1419. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1420. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1421. shost_for_each_device(sdev, port->adapter->scsi_host)
  1422. if (sdev_to_zfcp(sdev)->port == port)
  1423. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1424. &sdev_to_zfcp(sdev)->status);
  1425. zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1426. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
  1427. "fscpph2", req);
  1428. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1429. break;
  1430. case FSF_ADAPTER_STATUS_AVAILABLE:
  1431. switch (header->fsf_status_qual.word[0]) {
  1432. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1433. /* fall through */
  1434. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1435. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1436. break;
  1437. }
  1438. break;
  1439. case FSF_GOOD:
  1440. /* can't use generic zfcp_erp_modify_port_status because
  1441. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1442. */
  1443. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1444. shost_for_each_device(sdev, port->adapter->scsi_host)
  1445. if (sdev_to_zfcp(sdev)->port == port)
  1446. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1447. &sdev_to_zfcp(sdev)->status);
  1448. break;
  1449. }
  1450. }
  1451. /**
  1452. * zfcp_fsf_close_physical_port - close physical port
  1453. * @erp_action: pointer to struct zfcp_erp_action
  1454. * Returns: 0 on success
  1455. */
  1456. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1457. {
  1458. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1459. struct zfcp_fsf_req *req;
  1460. int retval = -EIO;
  1461. spin_lock_irq(&qdio->req_q_lock);
  1462. if (zfcp_qdio_sbal_get(qdio))
  1463. goto out;
  1464. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1465. SBAL_FLAGS0_TYPE_READ,
  1466. qdio->adapter->pool.erp_req);
  1467. if (IS_ERR(req)) {
  1468. retval = PTR_ERR(req);
  1469. goto out;
  1470. }
  1471. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1472. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1473. req->data = erp_action->port;
  1474. req->qtcb->header.port_handle = erp_action->port->handle;
  1475. req->erp_action = erp_action;
  1476. req->handler = zfcp_fsf_close_physical_port_handler;
  1477. erp_action->fsf_req_id = req->req_id;
  1478. zfcp_fsf_start_erp_timer(req);
  1479. retval = zfcp_fsf_req_send(req);
  1480. if (retval) {
  1481. zfcp_fsf_req_free(req);
  1482. erp_action->fsf_req_id = 0;
  1483. }
  1484. out:
  1485. spin_unlock_irq(&qdio->req_q_lock);
  1486. return retval;
  1487. }
  1488. static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
  1489. {
  1490. struct zfcp_adapter *adapter = req->adapter;
  1491. struct scsi_device *sdev = req->data;
  1492. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1493. struct fsf_qtcb_header *header = &req->qtcb->header;
  1494. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1495. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1496. return;
  1497. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1498. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1499. ZFCP_STATUS_LUN_SHARED |
  1500. ZFCP_STATUS_LUN_READONLY,
  1501. &zfcp_sdev->status);
  1502. switch (header->fsf_status) {
  1503. case FSF_PORT_HANDLE_NOT_VALID:
  1504. zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1", req);
  1505. /* fall through */
  1506. case FSF_LUN_ALREADY_OPEN:
  1507. break;
  1508. case FSF_ACCESS_DENIED:
  1509. zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
  1510. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1511. break;
  1512. case FSF_PORT_BOXED:
  1513. zfcp_erp_set_port_status(zfcp_sdev->port,
  1514. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1515. zfcp_erp_port_reopen(zfcp_sdev->port,
  1516. ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2",
  1517. req);
  1518. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1519. break;
  1520. case FSF_LUN_SHARING_VIOLATION:
  1521. zfcp_cfdc_lun_shrng_vltn(sdev, &header->fsf_status_qual);
  1522. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1523. break;
  1524. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1525. dev_warn(&adapter->ccw_device->dev,
  1526. "No handle is available for LUN "
  1527. "0x%016Lx on port 0x%016Lx\n",
  1528. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1529. (unsigned long long)zfcp_sdev->port->wwpn);
  1530. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
  1531. /* fall through */
  1532. case FSF_INVALID_COMMAND_OPTION:
  1533. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1534. break;
  1535. case FSF_ADAPTER_STATUS_AVAILABLE:
  1536. switch (header->fsf_status_qual.word[0]) {
  1537. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1538. zfcp_fc_test_link(zfcp_sdev->port);
  1539. /* fall through */
  1540. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1541. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1542. break;
  1543. }
  1544. break;
  1545. case FSF_GOOD:
  1546. zfcp_sdev->lun_handle = header->lun_handle;
  1547. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1548. zfcp_cfdc_open_lun_eval(sdev, bottom);
  1549. break;
  1550. }
  1551. }
  1552. /**
  1553. * zfcp_fsf_open_lun - open LUN
  1554. * @erp_action: pointer to struct zfcp_erp_action
  1555. * Returns: 0 on success, error otherwise
  1556. */
  1557. int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
  1558. {
  1559. struct zfcp_adapter *adapter = erp_action->adapter;
  1560. struct zfcp_qdio *qdio = adapter->qdio;
  1561. struct zfcp_fsf_req *req;
  1562. int retval = -EIO;
  1563. spin_lock_irq(&qdio->req_q_lock);
  1564. if (zfcp_qdio_sbal_get(qdio))
  1565. goto out;
  1566. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1567. SBAL_FLAGS0_TYPE_READ,
  1568. adapter->pool.erp_req);
  1569. if (IS_ERR(req)) {
  1570. retval = PTR_ERR(req);
  1571. goto out;
  1572. }
  1573. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1574. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1575. req->qtcb->header.port_handle = erp_action->port->handle;
  1576. req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
  1577. req->handler = zfcp_fsf_open_lun_handler;
  1578. req->data = erp_action->sdev;
  1579. req->erp_action = erp_action;
  1580. erp_action->fsf_req_id = req->req_id;
  1581. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1582. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1583. zfcp_fsf_start_erp_timer(req);
  1584. retval = zfcp_fsf_req_send(req);
  1585. if (retval) {
  1586. zfcp_fsf_req_free(req);
  1587. erp_action->fsf_req_id = 0;
  1588. }
  1589. out:
  1590. spin_unlock_irq(&qdio->req_q_lock);
  1591. return retval;
  1592. }
  1593. static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
  1594. {
  1595. struct scsi_device *sdev = req->data;
  1596. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1597. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1598. return;
  1599. switch (req->qtcb->header.fsf_status) {
  1600. case FSF_PORT_HANDLE_NOT_VALID:
  1601. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1",
  1602. req);
  1603. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1604. break;
  1605. case FSF_LUN_HANDLE_NOT_VALID:
  1606. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2", req);
  1607. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1608. break;
  1609. case FSF_PORT_BOXED:
  1610. zfcp_erp_set_port_status(zfcp_sdev->port,
  1611. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1612. zfcp_erp_port_reopen(zfcp_sdev->port,
  1613. ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3",
  1614. req);
  1615. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1616. break;
  1617. case FSF_ADAPTER_STATUS_AVAILABLE:
  1618. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1619. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1620. zfcp_fc_test_link(zfcp_sdev->port);
  1621. /* fall through */
  1622. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1623. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1624. break;
  1625. }
  1626. break;
  1627. case FSF_GOOD:
  1628. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1629. break;
  1630. }
  1631. }
  1632. /**
  1633. * zfcp_fsf_close_LUN - close LUN
  1634. * @erp_action: pointer to erp_action triggering the "close LUN"
  1635. * Returns: 0 on success, error otherwise
  1636. */
  1637. int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
  1638. {
  1639. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1640. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
  1641. struct zfcp_fsf_req *req;
  1642. int retval = -EIO;
  1643. spin_lock_irq(&qdio->req_q_lock);
  1644. if (zfcp_qdio_sbal_get(qdio))
  1645. goto out;
  1646. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1647. SBAL_FLAGS0_TYPE_READ,
  1648. qdio->adapter->pool.erp_req);
  1649. if (IS_ERR(req)) {
  1650. retval = PTR_ERR(req);
  1651. goto out;
  1652. }
  1653. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1654. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1655. req->qtcb->header.port_handle = erp_action->port->handle;
  1656. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1657. req->handler = zfcp_fsf_close_lun_handler;
  1658. req->data = erp_action->sdev;
  1659. req->erp_action = erp_action;
  1660. erp_action->fsf_req_id = req->req_id;
  1661. zfcp_fsf_start_erp_timer(req);
  1662. retval = zfcp_fsf_req_send(req);
  1663. if (retval) {
  1664. zfcp_fsf_req_free(req);
  1665. erp_action->fsf_req_id = 0;
  1666. }
  1667. out:
  1668. spin_unlock_irq(&qdio->req_q_lock);
  1669. return retval;
  1670. }
  1671. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1672. {
  1673. lat_rec->sum += lat;
  1674. lat_rec->min = min(lat_rec->min, lat);
  1675. lat_rec->max = max(lat_rec->max, lat);
  1676. }
  1677. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1678. {
  1679. struct fsf_qual_latency_info *lat_in;
  1680. struct latency_cont *lat = NULL;
  1681. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scsi->device);
  1682. struct zfcp_blk_drv_data blktrc;
  1683. int ticks = req->adapter->timer_ticks;
  1684. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1685. blktrc.flags = 0;
  1686. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1687. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1688. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1689. blktrc.inb_usage = 0;
  1690. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1691. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1692. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1693. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1694. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1695. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1696. switch (req->qtcb->bottom.io.data_direction) {
  1697. case FSF_DATADIR_DIF_READ_STRIP:
  1698. case FSF_DATADIR_DIF_READ_CONVERT:
  1699. case FSF_DATADIR_READ:
  1700. lat = &zfcp_sdev->latencies.read;
  1701. break;
  1702. case FSF_DATADIR_DIF_WRITE_INSERT:
  1703. case FSF_DATADIR_DIF_WRITE_CONVERT:
  1704. case FSF_DATADIR_WRITE:
  1705. lat = &zfcp_sdev->latencies.write;
  1706. break;
  1707. case FSF_DATADIR_CMND:
  1708. lat = &zfcp_sdev->latencies.cmd;
  1709. break;
  1710. }
  1711. if (lat) {
  1712. spin_lock(&zfcp_sdev->latencies.lock);
  1713. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1714. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1715. lat->counter++;
  1716. spin_unlock(&zfcp_sdev->latencies.lock);
  1717. }
  1718. }
  1719. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1720. sizeof(blktrc));
  1721. }
  1722. static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
  1723. {
  1724. struct scsi_cmnd *scmnd = req->data;
  1725. struct scsi_device *sdev = scmnd->device;
  1726. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1727. struct fsf_qtcb_header *header = &req->qtcb->header;
  1728. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1729. return;
  1730. switch (header->fsf_status) {
  1731. case FSF_HANDLE_MISMATCH:
  1732. case FSF_PORT_HANDLE_NOT_VALID:
  1733. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1",
  1734. req);
  1735. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1736. break;
  1737. case FSF_FCPLUN_NOT_VALID:
  1738. case FSF_LUN_HANDLE_NOT_VALID:
  1739. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2", req);
  1740. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1741. break;
  1742. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1743. zfcp_fsf_class_not_supp(req);
  1744. break;
  1745. case FSF_ACCESS_DENIED:
  1746. zfcp_cfdc_lun_denied(sdev, &header->fsf_status_qual);
  1747. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1748. break;
  1749. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1750. dev_err(&req->adapter->ccw_device->dev,
  1751. "Incorrect direction %d, LUN 0x%016Lx on port "
  1752. "0x%016Lx closed\n",
  1753. req->qtcb->bottom.io.data_direction,
  1754. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1755. (unsigned long long)zfcp_sdev->port->wwpn);
  1756. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1757. "fssfch3", req);
  1758. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1759. break;
  1760. case FSF_CMND_LENGTH_NOT_VALID:
  1761. dev_err(&req->adapter->ccw_device->dev,
  1762. "Incorrect CDB length %d, LUN 0x%016Lx on "
  1763. "port 0x%016Lx closed\n",
  1764. req->qtcb->bottom.io.fcp_cmnd_length,
  1765. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1766. (unsigned long long)zfcp_sdev->port->wwpn);
  1767. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1768. "fssfch4", req);
  1769. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1770. break;
  1771. case FSF_PORT_BOXED:
  1772. zfcp_erp_set_port_status(zfcp_sdev->port,
  1773. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1774. zfcp_erp_port_reopen(zfcp_sdev->port,
  1775. ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5",
  1776. req);
  1777. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1778. break;
  1779. case FSF_LUN_BOXED:
  1780. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1781. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  1782. "fssfch6", req);
  1783. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1784. break;
  1785. case FSF_ADAPTER_STATUS_AVAILABLE:
  1786. if (header->fsf_status_qual.word[0] ==
  1787. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1788. zfcp_fc_test_link(zfcp_sdev->port);
  1789. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1790. break;
  1791. }
  1792. }
  1793. static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
  1794. {
  1795. struct scsi_cmnd *scpnt;
  1796. struct fcp_resp_with_ext *fcp_rsp;
  1797. unsigned long flags;
  1798. zfcp_fsf_fcp_handler_common(req);
  1799. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1800. scpnt = req->data;
  1801. if (unlikely(!scpnt)) {
  1802. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1803. return;
  1804. }
  1805. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1806. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1807. goto skip_fsfstatus;
  1808. }
  1809. switch (req->qtcb->header.fsf_status) {
  1810. case FSF_INCONSISTENT_PROT_DATA:
  1811. case FSF_INVALID_PROT_PARM:
  1812. set_host_byte(scpnt, DID_ERROR);
  1813. goto skip_fsfstatus;
  1814. case FSF_BLOCK_GUARD_CHECK_FAILURE:
  1815. zfcp_scsi_dif_sense_error(scpnt, 0x1);
  1816. goto skip_fsfstatus;
  1817. case FSF_APP_TAG_CHECK_FAILURE:
  1818. zfcp_scsi_dif_sense_error(scpnt, 0x2);
  1819. goto skip_fsfstatus;
  1820. case FSF_REF_TAG_CHECK_FAILURE:
  1821. zfcp_scsi_dif_sense_error(scpnt, 0x3);
  1822. goto skip_fsfstatus;
  1823. }
  1824. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1825. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1826. skip_fsfstatus:
  1827. zfcp_fsf_req_trace(req, scpnt);
  1828. zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
  1829. scpnt->host_scribble = NULL;
  1830. (scpnt->scsi_done) (scpnt);
  1831. /*
  1832. * We must hold this lock until scsi_done has been called.
  1833. * Otherwise we may call scsi_done after abort regarding this
  1834. * command has completed.
  1835. * Note: scsi_done must not block!
  1836. */
  1837. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1838. }
  1839. static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
  1840. {
  1841. switch (scsi_get_prot_op(scsi_cmnd)) {
  1842. case SCSI_PROT_NORMAL:
  1843. switch (scsi_cmnd->sc_data_direction) {
  1844. case DMA_NONE:
  1845. *data_dir = FSF_DATADIR_CMND;
  1846. break;
  1847. case DMA_FROM_DEVICE:
  1848. *data_dir = FSF_DATADIR_READ;
  1849. break;
  1850. case DMA_TO_DEVICE:
  1851. *data_dir = FSF_DATADIR_WRITE;
  1852. break;
  1853. case DMA_BIDIRECTIONAL:
  1854. return -EINVAL;
  1855. }
  1856. break;
  1857. case SCSI_PROT_READ_STRIP:
  1858. *data_dir = FSF_DATADIR_DIF_READ_STRIP;
  1859. break;
  1860. case SCSI_PROT_WRITE_INSERT:
  1861. *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
  1862. break;
  1863. case SCSI_PROT_READ_PASS:
  1864. *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
  1865. break;
  1866. case SCSI_PROT_WRITE_PASS:
  1867. *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
  1868. break;
  1869. default:
  1870. return -EINVAL;
  1871. }
  1872. return 0;
  1873. }
  1874. /**
  1875. * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
  1876. * @scsi_cmnd: scsi command to be sent
  1877. */
  1878. int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
  1879. {
  1880. struct zfcp_fsf_req *req;
  1881. struct fcp_cmnd *fcp_cmnd;
  1882. unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
  1883. int real_bytes, retval = -EIO, dix_bytes = 0;
  1884. struct scsi_device *sdev = scsi_cmnd->device;
  1885. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1886. struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
  1887. struct zfcp_qdio *qdio = adapter->qdio;
  1888. struct fsf_qtcb_bottom_io *io;
  1889. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1890. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1891. return -EBUSY;
  1892. spin_lock(&qdio->req_q_lock);
  1893. if (atomic_read(&qdio->req_q_free) <= 0) {
  1894. atomic_inc(&qdio->req_q_full);
  1895. goto out;
  1896. }
  1897. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1898. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  1899. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1900. sbtype, adapter->pool.scsi_req);
  1901. if (IS_ERR(req)) {
  1902. retval = PTR_ERR(req);
  1903. goto out;
  1904. }
  1905. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1906. io = &req->qtcb->bottom.io;
  1907. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1908. req->data = scsi_cmnd;
  1909. req->handler = zfcp_fsf_fcp_cmnd_handler;
  1910. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1911. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  1912. io->service_class = FSF_CLASS_3;
  1913. io->fcp_cmnd_length = FCP_CMND_LEN;
  1914. if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
  1915. io->data_block_length = scsi_cmnd->device->sector_size;
  1916. io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
  1917. }
  1918. zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction);
  1919. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1920. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
  1921. if (scsi_prot_sg_count(scsi_cmnd)) {
  1922. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  1923. scsi_prot_sg_count(scsi_cmnd));
  1924. dix_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1925. scsi_prot_sglist(scsi_cmnd));
  1926. io->prot_data_length = dix_bytes;
  1927. }
  1928. real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1929. scsi_sglist(scsi_cmnd));
  1930. if (unlikely(real_bytes < 0) || unlikely(dix_bytes < 0))
  1931. goto failed_scsi_cmnd;
  1932. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  1933. retval = zfcp_fsf_req_send(req);
  1934. if (unlikely(retval))
  1935. goto failed_scsi_cmnd;
  1936. goto out;
  1937. failed_scsi_cmnd:
  1938. zfcp_fsf_req_free(req);
  1939. scsi_cmnd->host_scribble = NULL;
  1940. out:
  1941. spin_unlock(&qdio->req_q_lock);
  1942. return retval;
  1943. }
  1944. static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
  1945. {
  1946. struct fcp_resp_with_ext *fcp_rsp;
  1947. struct fcp_resp_rsp_info *rsp_info;
  1948. zfcp_fsf_fcp_handler_common(req);
  1949. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1950. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1951. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1952. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1953. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1954. }
  1955. /**
  1956. * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
  1957. * @scmnd: SCSI command to send the task management command for
  1958. * @tm_flags: unsigned byte for task management flags
  1959. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1960. */
  1961. struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
  1962. u8 tm_flags)
  1963. {
  1964. struct zfcp_fsf_req *req = NULL;
  1965. struct fcp_cmnd *fcp_cmnd;
  1966. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
  1967. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  1968. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1969. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1970. return NULL;
  1971. spin_lock_irq(&qdio->req_q_lock);
  1972. if (zfcp_qdio_sbal_get(qdio))
  1973. goto out;
  1974. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1975. SBAL_FLAGS0_TYPE_WRITE,
  1976. qdio->adapter->pool.scsi_req);
  1977. if (IS_ERR(req)) {
  1978. req = NULL;
  1979. goto out;
  1980. }
  1981. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  1982. req->data = scmnd;
  1983. req->handler = zfcp_fsf_fcp_task_mgmt_handler;
  1984. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1985. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  1986. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  1987. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  1988. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  1989. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1990. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1991. zfcp_fc_fcp_tm(fcp_cmnd, scmnd->device, tm_flags);
  1992. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  1993. if (!zfcp_fsf_req_send(req))
  1994. goto out;
  1995. zfcp_fsf_req_free(req);
  1996. req = NULL;
  1997. out:
  1998. spin_unlock_irq(&qdio->req_q_lock);
  1999. return req;
  2000. }
  2001. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2002. {
  2003. }
  2004. /**
  2005. * zfcp_fsf_control_file - control file upload/download
  2006. * @adapter: pointer to struct zfcp_adapter
  2007. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2008. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2009. */
  2010. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2011. struct zfcp_fsf_cfdc *fsf_cfdc)
  2012. {
  2013. struct zfcp_qdio *qdio = adapter->qdio;
  2014. struct zfcp_fsf_req *req = NULL;
  2015. struct fsf_qtcb_bottom_support *bottom;
  2016. int direction, retval = -EIO, bytes;
  2017. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2018. return ERR_PTR(-EOPNOTSUPP);
  2019. switch (fsf_cfdc->command) {
  2020. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2021. direction = SBAL_FLAGS0_TYPE_WRITE;
  2022. break;
  2023. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2024. direction = SBAL_FLAGS0_TYPE_READ;
  2025. break;
  2026. default:
  2027. return ERR_PTR(-EINVAL);
  2028. }
  2029. spin_lock_irq(&qdio->req_q_lock);
  2030. if (zfcp_qdio_sbal_get(qdio))
  2031. goto out;
  2032. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
  2033. if (IS_ERR(req)) {
  2034. retval = -EPERM;
  2035. goto out;
  2036. }
  2037. req->handler = zfcp_fsf_control_file_handler;
  2038. bottom = &req->qtcb->bottom.support;
  2039. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2040. bottom->option = fsf_cfdc->option;
  2041. bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
  2042. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2043. zfcp_fsf_req_free(req);
  2044. goto out;
  2045. }
  2046. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  2047. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2048. retval = zfcp_fsf_req_send(req);
  2049. out:
  2050. spin_unlock_irq(&qdio->req_q_lock);
  2051. if (!retval) {
  2052. wait_for_completion(&req->completion);
  2053. return req;
  2054. }
  2055. return ERR_PTR(retval);
  2056. }
  2057. /**
  2058. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2059. * @adapter: pointer to struct zfcp_adapter
  2060. * @sbal_idx: response queue index of SBAL to be processed
  2061. */
  2062. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2063. {
  2064. struct zfcp_adapter *adapter = qdio->adapter;
  2065. struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
  2066. struct qdio_buffer_element *sbale;
  2067. struct zfcp_fsf_req *fsf_req;
  2068. unsigned long req_id;
  2069. int idx;
  2070. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2071. sbale = &sbal->element[idx];
  2072. req_id = (unsigned long) sbale->addr;
  2073. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2074. if (!fsf_req) {
  2075. /*
  2076. * Unknown request means that we have potentially memory
  2077. * corruption and must stop the machine immediately.
  2078. */
  2079. zfcp_qdio_siosl(adapter);
  2080. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2081. req_id, dev_name(&adapter->ccw_device->dev));
  2082. }
  2083. fsf_req->qdio_req.sbal_response = sbal_idx;
  2084. zfcp_fsf_req_complete(fsf_req);
  2085. if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
  2086. break;
  2087. }
  2088. }